--- Net2/arch/i386/isa/fd.c 2018/04/24 18:07:01 1.1.1.3 +++ Net2/arch/i386/isa/fd.c 2018/04/24 18:11:56 1.1.1.4 @@ -37,7 +37,7 @@ */ #include "fd.h" -#if NFD > 0 +#if NFDC > 0 #include "param.h" #include "dkbad.h" @@ -51,8 +51,6 @@ #include "i386/isa/fdreg.h" #include "i386/isa/icu.h" #include "i386/isa/rtc.h" -#undef NFD -#define NFD 2 #define FDUNIT(s) ((s>>3)&1) #define FDTYPE(s) ((s)&7) @@ -60,7 +58,7 @@ #define b_cylin b_resid #define b_step b_resid #define FDBLK 512 -#define NUMTYPES 4 +#define NUMTYPES 4+1 struct fd_type { int sectrac; /* sectors per track */ @@ -74,6 +72,7 @@ struct fd_type { }; struct fd_type fd_types[NUMTYPES] = { + { 0 }, /* non-existant */ { 18,2,0xFF,0x1B,80,2880,1,0 }, /* 1.44 meg HD 3.5in floppy */ { 15,2,0xFF,0x1B,80,2400,1,0 }, /* 1.2 meg HD floppy */ { 9,2,0xFF,0x23,40,720,2,1 }, /* 360k floppy in 1.2meg drive */ @@ -107,17 +106,18 @@ static int fd_status[7]; /****************************************************************************/ /* autoconfiguration stuff */ /****************************************************************************/ -int fdprobe(), fdattach(), fd_turnoff(); +int fdprobe(struct isa_device *); +int fdattach(struct isa_device *); +int fd_turnoff(int); -struct isa_driver fddriver = { - fdprobe, fdattach, "fd", +struct isa_driver fdcdriver = { + fdprobe, fdattach, "fdc", }; /* * probe for existance of controller */ -fdprobe(dev) -struct isa_device *dev; +fdprobe(struct isa_device *dev) { fdc = dev->id_iobase; @@ -128,69 +128,67 @@ struct isa_device *dev; } out_fdc(0xDF); out_fdc(2); - return 1; + return 8; } /* * wire controller into system, look for floppy units */ -fdattach(dev) -struct isa_device *dev; +fdattach(struct isa_device *dev) { - int i, hdr; - unsigned fdt,st0, cyl; + unsigned fdt, unit, fddrive, fdunit; + extern struct isa_device isa_biotab_fdc[]; + struct isa_device *fdutab; + unsigned st0, cyl; fd_dmachan = dev->id_drq; fdt = rtcin(RTC_FDISKETTE); - hdr = 0; - - /* check for each floppy drive */ - for (i = 0; i < NFD; i++) { + unit = dev->id_unit; + if (unit >= NFDC) + return; + + for (fdutab = isa_biotab_fdc; fdutab->id_driver != 0; fdutab++) { + fdunit = fdutab->id_unit; + if (fdunit >= NFD) + continue; + fddrive = fdutab->id_physid; + if (fddrive == 1) + fdt <<= 4; + /* is there a unit? */ - if ((fdt & 0xf0) == RTCFDT_NONE) + if ((fdt & 0xf0) == RTCFDT_NONE) { + /*printf("fd%d: on fdc%d slave %d\n", fddrive, + dev->id_unit, fdunit);*/ continue; + } -#ifdef notyet - /* select it */ - fd_turnon(i); + fd_turnon(fddrive); DELAY(10000); out_fdc(NE7CMD_RECAL); /* Recalibrate Function */ - out_fdc(i); - DELAY(10000); - - /* anything responding */ - out_fdc(NE7CMD_SENSEI); + out_fdc(fddrive); + DELAY(30000); + out_fdc(NE7CMD_SENSEI); /* anything responding */ st0 = in_fdc(); cyl = in_fdc(); if (st0 & 0xd0) continue; -#endif - /* yes, announce it */ - if (!hdr) - printf(" drives "); - else - printf(", "); - printf("%d: ", i); - if ((fdt & 0xf0) == RTCFDT_12M) { - printf("1.2M"); - fd_unit[i].type = 1; + printf("fd%d at fdc%d slave %d: <1.2M>\n", fddrive, + dev->id_unit, fdunit); + fd_unit[fdunit].type = 2; } if ((fdt & 0xf0) == RTCFDT_144M) { - printf("1.44M"); - fd_unit[i].type = 0; + printf("fd%d at fdc%d slave %d: <1.44M>\n", fddrive, + dev->id_unit, fdunit); + fd_unit[fdunit].type = 1; } - fdt <<= 4; - fd_turnoff(i); - hdr = 1; - } + outb(fdc+fdctl,0); /* Set transfer to 500kbps */ - /* Set transfer to 500kbps */ - outb(fdc+fdctl,0); - fd_turnoff(0); + fd_turnoff(fddrive); + } } int @@ -213,6 +211,11 @@ fdstrategy(bp) unit = FDUNIT(minor(bp->b_dev)); /*type = FDTYPE(minor(bp->b_dev));*/ type = fd_unit[unit].type; + if(type == 0) { + bp->b_error = EINVAL; + bp->b_flags |= B_ERROR; + goto bad; + } #ifdef FDTEST printf("fdstrat%d, blk = %d, bcount = %d, addr = %x|", @@ -327,13 +330,14 @@ Fdopen(dev, flags) int flags; { int unit = FDUNIT(minor(dev)); - /*int type = FDTYPE(minor(dev));*/ + int type = fd_unit[unit].type; int s; fdopenf = 1; /* check bounds */ if (unit >= NFD) return(ENXIO); - /*if (type >= NUMTYPES) return(ENXIO);*/ + if (type >= NUMTYPES || type==0) + return ENXIO; /* Set proper disk type, only allow one type */ return 0;