BSD 4_4 release
[unix-history] / usr / src / sys / i386 / isa / fd.c
index cec6aae..b02e778 100644 (file)
@@ -1,39 +1,63 @@
-#include "fd.h"
-#if NFD > 0
 /*-
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Don Ahn.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * Don Ahn.
  *
- * %sccs.include.386.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  *
  *
- *     @(#)fd.c        5.4 (Berkeley) %G%
+ *     @(#)fd.c        8.1 (Berkeley) 6/11/93
  */
 
  */
 
-/****************************************************************************/
-/*                               fd driver                                  */
-/****************************************************************************/
-#include "param.h"
-#include "dkbad.h"
-#include "systm.h"
-#include "conf.h"
-#include "file.h"
-#include "dir.h"
-#include "user.h"
-#include "ioctl.h"
-#include "disk.h"
-#include "buf.h"
-#include "vm.h"
-#include "uio.h"
-#include "machine/pte.h"
-#include "machine/isa/isa_device.h"
-#include "machine/isa/fdreg.h"
-#include "icu.h"
+#include "fd.h"
+#if NFD > 0
+/*
+ * This driver assumed that NFD == 2. Now it works for NFD == 1 or NFD == 2
+ * It will probably not work for NFD > 2.
+ */
+#include <sys/param.h>
+#include <sys/dkbad.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <sys/buf.h>
+#include <sys/uio.h>
+
+#include <i386/isa/isa_device.h>
+#include <i386/isa/fdreg.h>
+#include <i386/isa/icu.h>
 
 #define        FDUNIT(s)       ((s)&1)
 #define        FDTYPE(s)       (((s)>>1)&7)
 
 #define        FDUNIT(s)       ((s)&1)
 #define        FDTYPE(s)       (((s)>>1)&7)
+#define FDMOTOR(u)     (fd_unit[(u)].motor ? (1 << (4 + (u))) : 0)
 
 #define b_cylin b_resid
 #define b_step b_resid
 
 #define b_cylin b_resid
 #define b_step b_resid
@@ -112,7 +136,7 @@ struct isa_device *dev;
 }
 
 int
 }
 
 int
-fdsize(dev)
+Fdsize(dev)
 dev_t  dev;
 {
        return(2400);
 dev_t  dev;
 {
        return(2400);
@@ -121,10 +145,10 @@ dev_t     dev;
 /****************************************************************************/
 /*                               fdstrategy                                 */
 /****************************************************************************/
 /****************************************************************************/
 /*                               fdstrategy                                 */
 /****************************************************************************/
-fdstrategy(bp)
+Fdstrategy(bp)
        register struct buf *bp;        /* IO operation to perform */
 {
        register struct buf *bp;        /* IO operation to perform */
 {
-       register struct buf *dp,*dp0,*dp1;
+       register struct buf *dp;
        long nblocks,blknum;
        int     unit, type, s;
 
        long nblocks,blknum;
        int     unit, type, s;
 
@@ -155,16 +179,21 @@ printf("fdstrat%d, blk = %d, bcount = %d, addr = %x|",
                        bp->b_error = ENOSPC;
                        bp->b_flags |= B_ERROR;
                }
                        bp->b_error = ENOSPC;
                        bp->b_flags |= B_ERROR;
                }
+#ifdef FDTEST
+printf("fdstrat%d, too big\n");
+#endif 
                goto bad;
        }
        bp->b_cylin = blknum / (fd_types[type].sectrac * 2);
        dp = &fd_unit[unit].head;
                goto bad;
        }
        bp->b_cylin = blknum / (fd_types[type].sectrac * 2);
        dp = &fd_unit[unit].head;
-       dp0 = &fd_unit[0].head;
-       dp1 = &fd_unit[1].head;
        dp->b_step = (fd_types[fd_unit[unit].type].steptrac);
        s = splbio();
        disksort(dp, bp);
        dp->b_step = (fd_types[fd_unit[unit].type].steptrac);
        s = splbio();
        disksort(dp, bp);
-       if ((dp0->b_active == 0)&&(dp1->b_active == 0)) {
+       if ((fd_unit[0].head.b_active == 0)
+#if NFD > 1
+           && (fd_unit[1].head.b_active == 0)
+#endif
+           ) {
 #ifdef FDDEBUG
 printf("T|");
 #endif
 #ifdef FDDEBUG
 printf("T|");
 #endif
@@ -187,10 +216,11 @@ bad:
 set_motor(unit,reset)
 int unit,reset;
 {
 set_motor(unit,reset)
 int unit,reset;
 {
-       int m0,m1;
-       m0 = fd_unit[0].motor;
-       m1 = fd_unit[1].motor;
-       outb(fdc+fdout,unit | (reset ? 0 : 0xC)  | (m0 ? 16 : 0) | (m1 ? 32 : 0));
+       outb(fdc+fdout,unit | (reset ? 0 : 0xC)  | FDMOTOR(0) 
+#if NFD > 1
+            | FDMOTOR(1)
+#endif
+            );
 }
 
 fd_turnoff(unit)
 }
 
 fd_turnoff(unit)
@@ -227,7 +257,7 @@ dump_stat()
                fd_status[i] = in_fdc();
                if (fd_status[i] < 0) break;
        }
                fd_status[i] = in_fdc();
                if (fd_status[i] < 0) break;
        }
-printf("FD bad status :%X %X %X %X %X %X %X\n",
+printf("FD bad status :%lx %lx %lx %lx %lx %lx %lx\n",
        fd_status[0], fd_status[1], fd_status[2], fd_status[3],
        fd_status[4], fd_status[5], fd_status[6] );
 }
        fd_status[0], fd_status[1], fd_status[2], fd_status[3],
        fd_status[4], fd_status[5], fd_status[6] );
 }
@@ -244,7 +274,7 @@ int x;
                if (r==(NE7_DIO|NE7_RQM)) {
                        dump_stat(); /* error: direction. eat up output */
 #ifdef FDOTHER
                if (r==(NE7_DIO|NE7_RQM)) {
                        dump_stat(); /* error: direction. eat up output */
 #ifdef FDOTHER
-printf("%X\n",x);
+printf("%lx\n",x);
 #endif
                }
                /* printf("Error r = %d:",r); */
 #endif
                }
                /* printf("Error r = %d:",r); */
@@ -273,7 +303,7 @@ check_fdc()
 /****************************************************************************/
 /*                           fdopen/fdclose                                 */
 /****************************************************************************/
 /****************************************************************************/
 /*                           fdopen/fdclose                                 */
 /****************************************************************************/
-fdopen(dev, flags)
+Fdopen(dev, flags)
        dev_t   dev;
        int     flags;
 {
        dev_t   dev;
        int     flags;
 {
@@ -281,6 +311,7 @@ fdopen(dev, flags)
        int type = FDTYPE(minor(dev));
        int s;
 
        int type = FDTYPE(minor(dev));
        int s;
 
+       printf("fdopen %x %d %d\n", minor(dev), unit, type);
        /* check bounds */
        if (unit >= NFD) return(ENXIO);
        if (type >= NUMTYPES) return(ENXIO);
        /* check bounds */
        if (unit >= NFD) return(ENXIO);
        if (type >= NUMTYPES) return(ENXIO);
@@ -292,9 +323,10 @@ fdopen(dev, flags)
        return 0;
 }
 
        return 0;
 }
 
-fdclose(dev)
+Fdclose(dev, flags)
        dev_t dev;
 {
        dev_t dev;
 {
+       return (0);
 }
 
 /****************************************************************************/
 }
 
 /****************************************************************************/
@@ -303,22 +335,22 @@ fdclose(dev)
 /*
  * Routines to do raw IO for a unit.
  */
 /*
  * Routines to do raw IO for a unit.
  */
-fdread(dev, uio)                       /* character read routine */
+Fdread(dev, uio)                       /* character read routine */
 dev_t dev;
 struct uio *uio;
 {
        int unit = FDUNIT(minor(dev)) ;
        if (unit >= NFD) return(ENXIO);
 dev_t dev;
 struct uio *uio;
 {
        int unit = FDUNIT(minor(dev)) ;
        if (unit >= NFD) return(ENXIO);
-       return(physio(fdstrategy,&fd_unit[unit].rhead,dev,B_READ,minphys,uio));
+       return(physio(Fdstrategy,&fd_unit[unit].rhead,dev,B_READ,minphys,uio));
 }
 
 }
 
-fdwrite(dev, uio)                      /* character write routine */
+Fdwrite(dev, uio)                      /* character write routine */
 dev_t dev;
 struct uio *uio;
 {
        int unit = FDUNIT(minor(dev)) ;
        if (unit >= NFD) return(ENXIO);
 dev_t dev;
 struct uio *uio;
 {
        int unit = FDUNIT(minor(dev)) ;
        if (unit >= NFD) return(ENXIO);
-       return(physio(fdstrategy,&fd_unit[unit].rhead,dev,B_WRITE,minphys,uio));
+       return(physio(Fdstrategy,&fd_unit[unit].rhead,dev,B_WRITE,minphys,uio));
 }
 
 /****************************************************************************/
 }
 
 /****************************************************************************/
@@ -331,7 +363,7 @@ int unit;
        int s;
 
 #ifdef FDTEST
        int s;
 
 #ifdef FDTEST
-printf("st%d|",unit);
+printf("fd%d|",unit);
 #endif 
        s = splbio();
        if (!fd_unit[unit].motor) {
 #endif 
        s = splbio();
        if (!fd_unit[unit].motor) {
@@ -362,7 +394,7 @@ printf("Seek %d %d\n", bp->b_cylin, dp->b_step);
                out_fdc(15);    /* Seek function */
                out_fdc(unit);  /* Drive number */
                out_fdc(bp->b_cylin * dp->b_step);
                out_fdc(15);    /* Seek function */
                out_fdc(unit);  /* Drive number */
                out_fdc(bp->b_cylin * dp->b_step);
-               } else fdintr(0);
+               } else fdintr(0xff);
        }
        splx(s);
 }
        }
        splx(s);
 }
@@ -379,12 +411,12 @@ int x;
        out_fdc(0x4);
        out_fdc(fd_drive);
        i = in_fdc();
        out_fdc(0x4);
        out_fdc(fd_drive);
        i = in_fdc();
-       printf("Timeout drive status %X\n",i);
+       printf("Timeout drive status %lx\n",i);
 
        out_fdc(0x8);
        i = in_fdc();
        j = in_fdc();
 
        out_fdc(0x8);
        i = in_fdc();
        j = in_fdc();
-       printf("ST0 = %X, PCN = %X\n",i,j);
+       printf("ST0 = %lx, PCN = %lx\n",i,j);
 
        if (bp) badtrans(dp,bp);
 }
 
        if (bp) badtrans(dp,bp);
 }
@@ -392,8 +424,7 @@ int x;
 /****************************************************************************/
 /*                                 fdintr                                   */
 /****************************************************************************/
 /****************************************************************************/
 /*                                 fdintr                                   */
 /****************************************************************************/
-fdintr(vec)
-int vec;
+fdintr(unit)
 {
        register struct buf *dp,*bp;
        struct buf *dpother;
 {
        register struct buf *dp,*bp;
        struct buf *dpother;
@@ -402,7 +433,7 @@ int vec;
        struct fd_type *ft;
 
 #ifdef FDTEST
        struct fd_type *ft;
 
 #ifdef FDTEST
-       printf("state %d, vec %d, dr %d|",fd_state,vec,fd_drive);
+       printf("state %d, unit %d, dr %d|",fd_state,unit,fd_drive);
 #endif
 
        dp = &fd_unit[fd_drive].head;
 #endif
 
        dp = &fd_unit[fd_drive].head;
@@ -413,12 +444,12 @@ int vec;
        switch (fd_state) {
        case 1 : /* SEEK DONE, START DMA */
                /* Make sure seek really happened*/
        switch (fd_state) {
        case 1 : /* SEEK DONE, START DMA */
                /* Make sure seek really happened*/
-               if (vec) {
+               if (unit != 0xff) {
                        out_fdc(0x8);
                        i = in_fdc();
                        cyl = in_fdc();
                        if (!(i&0x20) || (cyl != bp->b_cylin*dp->b_step)) {
                        out_fdc(0x8);
                        i = in_fdc();
                        cyl = in_fdc();
                        if (!(i&0x20) || (cyl != bp->b_cylin*dp->b_step)) {
-printf("Stray int ST0 = %X, PCN = %X:",i,cyl);
+printf("Stray int ST0 = %lx, PCN = %lx:",i,cyl);
                                return;
                        }
                }
                                return;
                        }
                }
@@ -504,7 +535,7 @@ printf("Seek|");
                                out_fdc(fd_drive);/* Drive number */
                                out_fdc(bp->b_cylin * dp->b_step);
                                break;
                                out_fdc(fd_drive);/* Drive number */
                                out_fdc(bp->b_cylin * dp->b_step);
                                break;
-                       } else fdintr(0);
+                       } else fdintr(0xff);
                }
                break;
        case 3:
                }
                break;
        case 3:
@@ -541,13 +572,13 @@ printf("Seek %d %d\n", bp->b_cylin, dp->b_step);
                out_fdc(0x8);
                i = in_fdc();
                sec = in_fdc();
                out_fdc(0x8);
                i = in_fdc();
                sec = in_fdc();
-               printf("ST0 = %X, PCN = %X\n",i,sec);
+               printf("ST0 = %lx, PCN = %lx\n",i,sec);
                out_fdc(0x4A); 
                out_fdc(fd_drive);
                for(i=0;i<7;i++) {
                        fd_status[i] = in_fdc();
                }
                out_fdc(0x4A); 
                out_fdc(fd_drive);
                for(i=0;i<7;i++) {
                        fd_status[i] = in_fdc();
                }
-       printf("intr status :%X %X %X %X %X %X %X ",
+       printf("intr status :%lx %lx %lx %lx %lx %lx %lx ",
                fd_status[0], fd_status[1], fd_status[2], fd_status[3],
                fd_status[4], fd_status[5], fd_status[6] );
                break;
                fd_status[0], fd_status[1], fd_status[2], fd_status[3],
                fd_status[4], fd_status[5], fd_status[6] );
                break;
@@ -561,12 +592,12 @@ retry:
        case 4:
                fd_retry++;
                fd_state = 5;
        case 4:
                fd_retry++;
                fd_state = 5;
-               fdintr(0);
+               fdintr(0xff);
                return;
        case 5: case 6: case 7:
                break;
        default:
                return;
        case 5: case 6: case 7:
                break;
        default:
-               printf("FD err %X %X %X %X %X %X %X\n",
+               printf("FD err %lx %lx %lx %lx %lx %lx %lx\n",
                fd_status[0], fd_status[1], fd_status[2], fd_status[3],
                fd_status[4], fd_status[5], fd_status[6] );
                badtrans(dp,bp);
                fd_status[0], fd_status[1], fd_status[2], fd_status[3],
                fd_status[4], fd_status[5], fd_status[6] );
                badtrans(dp,bp);
@@ -574,7 +605,7 @@ retry:
        }
        fd_state = 1;
        fd_retry++;
        }
        fd_state = 1;
        fd_retry++;
-       fdintr(0);
+       fdintr(0xff);
 }
 
 badtrans(dp,bp)
 }
 
 badtrans(dp,bp)
@@ -602,28 +633,39 @@ struct buf *dp,*bp;
 nextstate(dp)
 struct buf *dp;
 {
 nextstate(dp)
 struct buf *dp;
 {
-       struct buf *dpother;
        
        
-       dpother = &fd_unit[fd_drive ? 0 : 1].head;
-       if (dp->b_actf) fdstart(fd_drive);
-       else if (dpother->b_actf) {
+       if (dp->b_actf) 
+               fdstart(fd_drive);
+       else {
+#if NFD > 1
+               struct buf *dpother;
+
+               dpother = &fd_unit[fd_drive ? 0 : 1].head;
+
+               if (dpother->b_actf) {
 #ifdef FDTEST
 printf("switch|");
 #endif
 #ifdef FDTEST
 printf("switch|");
 #endif
-               untimeout(fd_turnoff,fd_drive);
-               timeout(fd_turnoff,fd_drive,5*hz);
-               fd_drive = 1 - fd_drive;
-               dp->b_active = 0;
-               dpother->b_active = 1;
-               fdstart(fd_drive);
-       } else {
+                       untimeout(fd_turnoff,fd_drive);
+                       timeout(fd_turnoff,fd_drive,5*hz);
+                       fd_drive = 1 - fd_drive;
+                       dp->b_active = 0;
+                       dpother->b_active = 1;
+                       fdstart(fd_drive);
+               } else 
+#endif
+               {
 #ifdef FDTEST
 printf("off|");
 #endif
 #ifdef FDTEST
 printf("off|");
 #endif
-               untimeout(fd_turnoff,fd_drive);
-               timeout(fd_turnoff,fd_drive,5*hz);
-               fd_state = 0;
-               dp->b_active = 0;
+                       untimeout(fd_turnoff,fd_drive);
+                       timeout(fd_turnoff,fd_drive,5*hz);
+                       fd_state = 0;
+                       dp->b_active = 0;
+               }
        }
 }
        }
 }
+
+Fdioctl() {}
+Fddump() {}
 #endif
 #endif