--- linux/kernel/blk_drv/hd.c 2018/04/24 18:03:22 1.1.1.3 +++ linux/kernel/blk_drv/hd.c 2018/04/24 18:04:38 1.1.1.4 @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -44,7 +45,7 @@ static int reset = 0; * This struct defines the HD's and their types. */ struct hd_i_struct { - int head,sect,cyl,wpcom,lzone,ctl; + unsigned int head,sect,cyl,wpcom,lzone,ctl; }; #ifdef HD_TYPE struct hd_i_struct hd_info[] = { HD_TYPE }; @@ -57,9 +58,9 @@ static int NR_HD = 0; static struct hd_struct { long start_sect; long nr_sects; -} hd[5*MAX_HD]={{0,0},}; +} hd[MAX_HD<<6]={{0,0},}; -static int hd_sizes[5*MAX_HD] = {0, }; +static int hd_sizes[MAX_HD<<6] = {0, }; #define port_read(port,buf,nr) \ __asm__("cld;rep;insw"::"d" (port),"D" (buf),"c" (nr):"cx","di") @@ -70,14 +71,40 @@ __asm__("cld;rep;outsw"::"d" (port),"S" extern void hd_interrupt(void); extern void rd_load(void); +static unsigned int current_minor; + +static void check_partition(unsigned int dev) +{ + int minor, i; + struct buffer_head *bh; + struct partition *p; + + if (!(bh = bread(dev,0))) { + printk("Unable to read partition table of device %04x\n",dev); + return; + } + minor = current_minor; + if (*(unsigned short *) (bh->b_data+510) == 0xAA55) { + p = 0x1BE + (void *)bh->b_data; + for (i=0 ; i<4 ; i++,p++) { + hd[i+minor].start_sect = p->start_sect; + hd[i+minor].nr_sects = p->nr_sects; + } + if (p->nr_sects && p->sys_ind == EXTENDED_PARTITION) { + current_minor += 4; + check_partition(i+minor); + } + } else + printk("Bad partition table on dev %04x\n",dev); + brelse(bh); +} + /* This may be used only once, enforced by 'static int callable' */ int sys_setup(void * BIOS) { static int callable = 1; int i,drive; unsigned char cmos_disks; - struct partition *p; - struct buffer_head * bh; if (!callable) return -1; @@ -98,8 +125,8 @@ int sys_setup(void * BIOS) NR_HD=1; #endif for (i=0 ; ib_data[510] != 0x55 || (unsigned char) - bh->b_data[511] != 0xAA) { - printk("Bad partition table on drive %d\n\r",drive); - panic(""); - } - p = 0x1BE + (void *)bh->b_data; - for (i=1;i<5;i++,p++) { - hd[i+5*drive].start_sect = p->start_sect; - hd[i+5*drive].nr_sects = p->nr_sects; - } - brelse(bh); + current_minor = 1+(drive<<6); + check_partition(0x0300+(drive<<6)); } - for (i=0 ; i<5*MAX_HD ; i++) + for (i=0 ; i<(MAX_HD<<6) ; i++) hd_sizes[i] = hd[i].nr_sects>>1 ; blk_size[MAJOR_NR] = hd_sizes; if (NR_HD) printk("Partition table%s ok.\n\r",(NR_HD>1)?"s":""); rd_load(); - init_swapping(); mount_root(); return (0); } @@ -169,7 +181,11 @@ static int controller_ready(void) { int retries = 100000; - while (--retries && (inb_p(HD_STATUS)&0xc0)!=0x40); + while (--retries && (inb_p(HD_STATUS)&0x80)) + /* nothing */; + if (!retries) + printk("controller_ready: status = %02x\n\r", + (unsigned char) inb_p(HD_STATUS)); return (retries); } @@ -188,12 +204,14 @@ static void hd_out(unsigned int drive,un unsigned int head,unsigned int cyl,unsigned int cmd, void (*intr_addr)(void)) { - register int port asm("dx"); + unsigned short port; if (drive>1 || head>15) panic("Trying to write bad sector"); - if (!controller_ready()) - panic("HD controller not ready"); + if (reset || !controller_ready()) { + reset = 1; + return; + } SET_INTR(intr_addr); outb_p(hd_info[drive].ctl,HD_CMD); port=HD_DATA; @@ -217,7 +235,7 @@ static int drive_busy(void) if (c == (READY_STAT | SEEK_STAT)) return 0; } - printk("HD controller times out\n\r"); + printk("HD controller times out, c=%02x\n\r",c); return(1); } @@ -252,6 +270,8 @@ repeat: if (i < NR_HD) { hd_out(i,hd_info[i].sect,hd_info[i].sect,hd_info[i].head-1, hd_info[i].cyl,WIN_SPECIFY,&reset_hd); + if (reset) + goto repeat; } else do_hd_request(); } @@ -315,7 +335,7 @@ static void recal_intr(void) do_hd_request(); } -void hd_times_out(void) +static void hd_times_out(void) { if (!CURRENT) return; @@ -337,16 +357,16 @@ void do_hd_request(void) INIT_REQUEST; dev = MINOR(CURRENT->dev); block = CURRENT->sector; - if (dev >= 5*NR_HD || block+2 > hd[dev].nr_sects) { + if (dev >= (NR_HD<<6) || block+2 > hd[dev].nr_sects) { end_request(0); goto repeat; } block += hd[dev].start_sect; - dev /= 5; - __asm__("divl %4":"=a" (block),"=d" (sec):"0" (block),"1" (0), - "r" (hd_info[dev].sect)); - __asm__("divl %4":"=a" (cyl),"=d" (head):"0" (block),"1" (0), - "r" (hd_info[dev].head)); + dev >>= 6; + sec = block % hd_info[dev].sect; + block /= hd_info[dev].sect; + head = block % hd_info[dev].head; + cyl = block / hd_info[dev].head; sec++; nsect = CURRENT->nr_sectors; if (reset) { @@ -358,10 +378,14 @@ void do_hd_request(void) recalibrate = 0; hd_out(dev,hd_info[CURRENT_DEV].sect,0,0,0, WIN_RESTORE,&recal_intr); + if (reset) + goto repeat; return; } if (CURRENT->cmd == WRITE) { hd_out(dev,nsect,sec,head,cyl,WIN_WRITE,&write_intr); + if (reset) + goto repeat; for(i=0 ; i<10000 && !(r=inb_p(HD_STATUS)&DRQ_STAT) ; i++) /* nothing */ ; if (!r) { @@ -371,6 +395,8 @@ void do_hd_request(void) port_write(HD_DATA,CURRENT->buffer,256); } else if (CURRENT->cmd == READ) { hd_out(dev,nsect,sec,head,cyl,WIN_READ,&read_intr); + if (reset) + goto repeat; } else panic("unknown hd-command"); } @@ -378,7 +404,8 @@ void do_hd_request(void) void hd_init(void) { blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST; - set_intr_gate(0x2E,&hd_interrupt); + set_trap_gate(0x2E,&hd_interrupt); outb_p(inb_p(0x21)&0xfb,0x21); outb(inb_p(0xA1)&0xbf,0xA1); + timer_table[HD_TIMER].fn = hd_times_out; }