BSD 4_4 release
[unix-history] / usr / src / sys / i386 / isa / fd.c
index db99e01..b02e778 100644 (file)
@@ -1,32 +1,63 @@
 /*-
 /*-
- * 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.redist.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.
  *
  *
- *     @(#)fd.c        7.5 (Berkeley) %G%
+ * 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        8.1 (Berkeley) 6/11/93
  */
 
 #include "fd.h"
 #if NFD > 0
  */
 
 #include "fd.h"
 #if NFD > 0
-
-#include "param.h"
-#include "dkbad.h"
-#include "systm.h"
-#include "conf.h"
-#include "file.h"
-#include "ioctl.h"
-#include "buf.h"
-#include "uio.h"
-#include "i386/isa/isa_device.h"
-#include "i386/isa/fdreg.h"
-#include "i386/isa/icu.h"
+/*
+ * 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
@@ -117,7 +148,7 @@ dev_t       dev;
 Fdstrategy(bp)
        register struct buf *bp;        /* IO operation to perform */
 {
 Fdstrategy(bp)
        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;
 
@@ -148,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
@@ -180,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)
@@ -274,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);
@@ -288,6 +326,7 @@ Fdopen(dev, flags)
 Fdclose(dev, flags)
        dev_t dev;
 {
 Fdclose(dev, flags)
        dev_t dev;
 {
+       return (0);
 }
 
 /****************************************************************************/
 }
 
 /****************************************************************************/
@@ -324,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) {
@@ -594,28 +633,36 @@ 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;
+               }
        }
 }
 
        }
 }