Exemple #1
0
/*
1.函数内部需要注意:while(1),while(-1)都会执行循环体,只有while(0)时才跳出循环体
2.目前只能处理读写数据长度为SECTOR_SIZE整数倍的请求,否则会出错
*/
static void hd_rdwt(MESSAGE *message){
    int hd_index=HD_INDEX(message->device);
    int hd_part_index=HD_PART_INDEX(message->device);

    u64 position=message->position;
#ifdef DEBUG_HD
    printl("position=%d\n",position);
#endif
    assert((position>>SECTOR_SIZE_SHIFT)<(1<<31),"");
    assert(position%SECTOR_SIZE==0,"hd readwrite start position must be the multiple of SECTOR_SIZE");//读取的起始位置必须在扇区的起始位置

    HD_COMMAND hd_command;
    u32 base=get_part_info(&hd_info[hd_index],hd_part_index)->base;
    u32 sector_index=base+(u32)(position>>SECTOR_SIZE_SHIFT);
    int sector_length=(message->length+SECTOR_SIZE-1)/SECTOR_SIZE;
    int cmd=(message->type==INFO_FS_READ)?ATA_READ:ATA_WRITE;
    set_command(&hd_command,hd_index,0,0,sector_length,sector_index,cmd);
    hd_command_out(&hd_command);

    int bytes_left=message->length;
#ifdef DEBUG_HD
    printl("sector_index=%d sector_length=%d bytes_left=%d\n",sector_index,sector_length,bytes_left);
#endif
    void *la=(void *)va2la(message->source_pid,message->arg_pointer);
#ifdef DEBUG_HD
    printl("source_pid=%d la[0]=%d\n",message->source_pid,*(int*)la);
#endif
//此处需要注意:while(1),while(-1)都会执行循环体,只有while(0)时才跳出循环体
    while(bytes_left>0){
        int bytes=min(SECTOR_SIZE,bytes_left);
        if(message->type==INFO_FS_READ){
            interrupt_wait();
            port_read(REG_P_DATA,hdbuf,SECTOR_SIZE);
            memcpy(la,(void *)va2la(TASK_HD,hdbuf),bytes);
        }else{
            if(!wait_for(STATUS_DRQ_MASK,STATUS_DRQ,HD_TIME_OUT))
                panic("hd writing error!\n");
            /* printl("bytes=%d",bytes); */
            port_write(REG_P_DATA,la,bytes);
            /* printl("test1"); */
            interrupt_wait();
            /* printl("test2"); */
        }
        bytes_left-=bytes;
        la+=bytes;
        /* printl("(bytes_left>0)=%d\n",bytes_left>0); */
    }
#ifdef DEBUG_HD
    printl("hd_rdwt ok!\n");
#endif
}
Exemple #2
0
static void hd_ioctl(MESSAGE *message){
    int hd_index=HD_INDEX(message->device);
    int hd_part_index=HD_PART_INDEX(message->device);

    struct s_hd_info *hdi=&hd_info[hd_index];

#ifdef DEBUG_HD
    printl("hd_index=%d hd_part_index=%d\n",hd_index,hd_part_index);
#endif

    if(message->subtype==DIOCTL_GET_PART_INFO){
        void *dest=va2la(message->source_pid,message->arg_pointer);
        /* void *src=va2la(TASK_HD, */
        /*     hd_part_index<=HD_PART_PRIM_COUNT? */
        /*                 &hdi->primary[hd_part_index]: */
        /*                 &hdi->logical[hd_part_index-HD_PART_LOGICAL_MIN]); */
        void *src=va2la(TASK_HD,get_part_info(&hdi[hd_index],hd_part_index));
        
        memcpy(dest,src,sizeof(struct s_hd_part_info));
    }else{
        assert(FALSE,"unknown message subtype in hd_ioctl");
    }
}
Exemple #3
0
HI_S32 find_part_from_devname(char *media_name, char *bootargs, 
			      char *devname, HI_U64 *start, HI_U64 *size)
{
	HI_U8 partnum = 0;
	char *tmp;

	if (!(tmp = strstr(bootargs, "blkdevparts=")))
		return HI_FAILURE;
	tmp += strlen("blkdevparts=");

	if (!strstr(bootargs, media_name))
		return HI_FAILURE;

	if (!(tmp = strstr(devname, "mmcblk0p")))
		return HI_FAILURE;
	tmp += strlen("mmcblk0p");
	partnum = (HI_U8)strtol(tmp, NULL, 10);

	if (get_part_info(partnum, start, size))
		return HI_FAILURE;

	return HI_SUCCESS;
}