2000-02-07 23:16:47 +03:00
|
|
|
/* $NetBSD: fd.c,v 1.30 2000/02/07 20:16:54 thorpej Exp $ */
|
1998-08-15 08:22:45 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
1999-03-16 19:30:16 +03:00
|
|
|
* by Charles M. Hannum and Minoura Makoto.
|
1998-08-15 08:22:45 +04:00
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Don Ahn.
|
|
|
|
*
|
|
|
|
* 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 7.4 (Berkeley) 5/25/91
|
|
|
|
*/
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
#include "rnd.h"
|
1998-07-05 02:18:13 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
|
1996-05-05 16:17:03 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/dkstat.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/queue.h>
|
1999-03-16 19:30:16 +03:00
|
|
|
#include <sys/fdio.h>
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
1999-03-24 08:50:49 +03:00
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
#include <machine/bus.h>
|
1996-05-05 16:17:03 +04:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
#include <arch/x68k/dev/intiovar.h>
|
|
|
|
#include <arch/x68k/dev/dmacvar.h>
|
|
|
|
#include <arch/x68k/dev/fdreg.h>
|
|
|
|
#include <arch/x68k/dev/opmreg.h> /* for CT1 access */
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1997-07-17 06:12:50 +04:00
|
|
|
#include "locators.h"
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
#ifdef FDDEBUG
|
1996-10-13 07:29:05 +04:00
|
|
|
#define DPRINTF(x) if (fddebug) printf x
|
1996-05-05 16:17:03 +04:00
|
|
|
int fddebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define FDUNIT(dev) (minor(dev) / 8)
|
|
|
|
#define FDTYPE(dev) (minor(dev) % 8)
|
|
|
|
|
|
|
|
enum fdc_state {
|
|
|
|
DEVIDLE = 0,
|
|
|
|
MOTORWAIT,
|
|
|
|
DOSEEK,
|
|
|
|
SEEKWAIT,
|
|
|
|
SEEKTIMEDOUT,
|
|
|
|
SEEKCOMPLETE,
|
|
|
|
DOIO,
|
|
|
|
IOCOMPLETE,
|
|
|
|
IOTIMEDOUT,
|
|
|
|
DORESET,
|
|
|
|
RESETCOMPLETE,
|
|
|
|
RESETTIMEDOUT,
|
|
|
|
DORECAL,
|
|
|
|
RECALWAIT,
|
|
|
|
RECALTIMEDOUT,
|
|
|
|
RECALCOMPLETE,
|
|
|
|
DOCOPY,
|
|
|
|
DOIOHALF,
|
|
|
|
COPYCOMPLETE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* software state, per controller */
|
|
|
|
struct fdc_softc {
|
|
|
|
struct device sc_dev; /* boilerplate */
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
bus_space_tag_t sc_iot; /* intio i/o space identifier */
|
|
|
|
bus_space_handle_t sc_ioh; /* intio io handle */
|
|
|
|
bus_dma_tag_t sc_dmat; /* intio dma tag */
|
|
|
|
bus_dmamap_t sc_dmamap; /* dma map */
|
|
|
|
u_int8_t *sc_addr; /* physical address */
|
|
|
|
struct dmac_channel_stat *sc_dmachan; /* intio dma channel */
|
|
|
|
struct dmac_dma_xfer *sc_xfer; /* dma transfer */
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
struct fd_softc *sc_fd[4]; /* pointers to children */
|
|
|
|
TAILQ_HEAD(drivehead, fd_softc) sc_drives;
|
|
|
|
enum fdc_state sc_state;
|
|
|
|
int sc_errors; /* number of retries so far */
|
|
|
|
u_char sc_status[7]; /* copy of registers */
|
|
|
|
} fdc_softc;
|
|
|
|
|
1997-10-12 18:44:12 +04:00
|
|
|
bdev_decl(fd);
|
|
|
|
cdev_decl(fd);
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
int fdcintr __P((void*));
|
|
|
|
void fdcreset __P((struct fdc_softc *));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
/* controller driver configuration */
|
1998-08-04 20:51:51 +04:00
|
|
|
int fdcprobe __P((struct device *, struct cfdata *, void *));
|
1996-05-05 16:17:03 +04:00
|
|
|
void fdcattach __P((struct device *, struct device *, void *));
|
1997-10-11 01:42:38 +04:00
|
|
|
int fdprint __P((void *, const char *));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
struct cfattach fdc_ca = {
|
|
|
|
sizeof(struct fdc_softc), fdcprobe, fdcattach
|
|
|
|
};
|
|
|
|
|
1998-06-30 15:59:09 +04:00
|
|
|
extern struct cfdriver fdc_cd;
|
|
|
|
|
1996-05-05 16:17:03 +04:00
|
|
|
/*
|
|
|
|
* Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how
|
|
|
|
* we tell them apart.
|
|
|
|
*/
|
|
|
|
struct fd_type {
|
|
|
|
int sectrac; /* sectors per track */
|
|
|
|
int heads; /* number of heads */
|
|
|
|
int seccyl; /* sectors per cylinder */
|
|
|
|
int secsize; /* size code for sectors */
|
|
|
|
int datalen; /* data len when secsize = 0 */
|
|
|
|
int steprate; /* step rate and head unload time */
|
|
|
|
int gap1; /* gap len between sectors */
|
|
|
|
int gap2; /* formatting gap */
|
1999-03-16 19:30:16 +03:00
|
|
|
int cyls; /* total num of cylinders */
|
1996-05-05 16:17:03 +04:00
|
|
|
int size; /* size of disk in sectors */
|
|
|
|
int step; /* steps per cylinder */
|
|
|
|
int rate; /* transfer speed code */
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The order of entries in the following table is important -- BEWARE! */
|
|
|
|
struct fd_type fd_types[] = {
|
|
|
|
{ 8,2,16,3,0xff,0xdf,0x35,0x74,77,1232,1,FDC_500KBPS, "1.2MB/[1024bytes/sector]" }, /* 1.2 MB japanese format */
|
|
|
|
{ 18,2,36,2,0xff,0xcf,0x1b,0x6c,80,2880,1,FDC_500KBPS,"1.44MB" }, /* 1.44MB diskette */
|
|
|
|
{ 15,2,30,2,0xff,0xdf,0x1b,0x54,80,2400,1,FDC_500KBPS, "1.2MB" }, /* 1.2 MB AT-diskettes */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x23,0x50,40, 720,2,FDC_300KBPS, "360KB/AT" }, /* 360kB in 1.2MB drive */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,1,FDC_250KBPS, "360KB/PC" }, /* 360kB PC diskettes */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,80,1440,1,FDC_250KBPS, "720KB" }, /* 3.5" 720kB diskette */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x23,0x50,80,1440,1,FDC_300KBPS, "720KB/x" }, /* 720kB in 1.2MB drive */
|
|
|
|
{ 9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,2,FDC_250KBPS, "360KB/x" }, /* 360kB in 720kB drive */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* software state, per disk (with up to 4 disks per ctlr) */
|
|
|
|
struct fd_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct disk sc_dk;
|
|
|
|
|
|
|
|
struct fd_type *sc_deftype; /* default type descriptor */
|
|
|
|
struct fd_type *sc_type; /* current type descriptor */
|
|
|
|
|
|
|
|
daddr_t sc_blkno; /* starting block number */
|
|
|
|
int sc_bcount; /* byte count left */
|
1999-03-16 19:30:16 +03:00
|
|
|
int sc_opts; /* user-set options */
|
1996-05-05 16:17:03 +04:00
|
|
|
int sc_skip; /* bytes already transferred */
|
|
|
|
int sc_nblks; /* number of blocks currently tranferring */
|
|
|
|
int sc_nbytes; /* number of bytes currently tranferring */
|
|
|
|
|
|
|
|
int sc_drive; /* physical unit number */
|
|
|
|
int sc_flags;
|
|
|
|
#define FD_BOPEN 0x01 /* it's open */
|
|
|
|
#define FD_COPEN 0x02 /* it's open */
|
|
|
|
#define FD_OPEN (FD_BOPEN|FD_COPEN) /* it's open */
|
|
|
|
#define FD_MOTOR 0x04 /* motor should be on */
|
|
|
|
#define FD_MOTOR_WAIT 0x08 /* motor coming up */
|
|
|
|
#define FD_ALIVE 0x10 /* alive */
|
|
|
|
int sc_cylin; /* where we think the head is */
|
|
|
|
|
|
|
|
TAILQ_ENTRY(fd_softc) sc_drivechain;
|
|
|
|
int sc_ops; /* I/O ops since last switch */
|
2000-01-22 02:39:55 +03:00
|
|
|
struct buf_queue sc_q; /* pending I/O requests */
|
|
|
|
int sc_active; /* number of active I/O operations */
|
1996-05-05 16:17:03 +04:00
|
|
|
u_char *sc_copybuf; /* for secsize >=3 */
|
|
|
|
u_char sc_part; /* for secsize >=3 */
|
|
|
|
#define SEC_P10 0x02 /* first part */
|
|
|
|
#define SEC_P01 0x01 /* second part */
|
|
|
|
#define SEC_P11 0x03 /* both part */
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rndsource_element_t rnd_source;
|
|
|
|
#endif
|
1996-05-05 16:17:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* floppy driver configuration */
|
1998-08-04 20:51:51 +04:00
|
|
|
int fdprobe __P((struct device *, struct cfdata *, void *));
|
1996-05-05 16:17:03 +04:00
|
|
|
void fdattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach fd_ca = {
|
|
|
|
sizeof(struct fd_softc), fdprobe, fdattach
|
|
|
|
};
|
|
|
|
|
1998-01-12 23:52:29 +03:00
|
|
|
extern struct cfdriver fd_cd;
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
void fdstrategy __P((struct buf *));
|
1997-10-11 01:42:38 +04:00
|
|
|
void fdstart __P((struct fd_softc *fd));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
struct dkdriver fddkdriver = { fdstrategy };
|
|
|
|
|
|
|
|
void fd_set_motor __P((struct fdc_softc *fdc, int reset));
|
|
|
|
void fd_motor_off __P((void *arg));
|
|
|
|
void fd_motor_on __P((void *arg));
|
|
|
|
int fdcresult __P((struct fdc_softc *fdc));
|
1999-03-16 19:30:16 +03:00
|
|
|
int out_fdc __P((bus_space_tag_t, bus_space_handle_t, u_char x));
|
1996-05-05 16:17:03 +04:00
|
|
|
void fdcstart __P((struct fdc_softc *fdc));
|
|
|
|
void fdcstatus __P((struct device *dv, int n, char *s));
|
|
|
|
void fdctimeout __P((void *arg));
|
|
|
|
void fdcpseudointr __P((void *arg));
|
|
|
|
void fdcretry __P((struct fdc_softc *fdc));
|
|
|
|
void fdfinish __P((struct fd_softc *fd, struct buf *bp));
|
1997-10-11 01:42:38 +04:00
|
|
|
__inline struct fd_type *fd_dev_to_type __P((struct fd_softc *, dev_t));
|
|
|
|
static int fdcpoll __P((struct fdc_softc *));
|
1996-05-05 16:17:03 +04:00
|
|
|
static int fdgetdisklabel __P((struct fd_softc *, dev_t));
|
1999-03-16 19:30:16 +03:00
|
|
|
static void fd_do_eject __P((struct fdc_softc *, int));
|
1997-10-11 01:42:38 +04:00
|
|
|
|
1996-07-08 20:32:12 +04:00
|
|
|
void fd_mountroot_hook __P((struct device *));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1997-10-12 18:44:12 +04:00
|
|
|
/* dma transfer routines */
|
1999-03-16 19:30:16 +03:00
|
|
|
__inline static void fdc_dmastart __P((struct fdc_softc*, int,
|
|
|
|
caddr_t, vsize_t));
|
|
|
|
static int fdcdmaintr __P((void*));
|
|
|
|
static int fdcdmaerrintr __P((void*));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1997-10-11 01:42:38 +04:00
|
|
|
__inline static void
|
1999-03-16 19:30:16 +03:00
|
|
|
fdc_dmastart(fdc, read, addr, count)
|
|
|
|
struct fdc_softc *fdc;
|
1996-05-05 16:17:03 +04:00
|
|
|
int read;
|
|
|
|
caddr_t addr;
|
1998-08-22 18:38:36 +04:00
|
|
|
vsize_t count;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
int error;
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1996-05-21 19:31:55 +04:00
|
|
|
DPRINTF(("fdc_dmastart: (%s, addr = %p, count = %d\n",
|
1998-08-22 18:38:36 +04:00
|
|
|
read ? "read" : "write", (caddr_t) addr, count));
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
error = bus_dmamap_load(fdc->sc_dmat, fdc->sc_dmamap, addr, count,
|
|
|
|
0, BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
panic ("fdc_dmastart: cannot load dmamap");
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_dmamap_sync(fdc->sc_dmat, fdc->sc_dmamap, 0, count,
|
|
|
|
read?BUS_DMASYNC_PREREAD:BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
fdc->sc_xfer = dmac_prepare_xfer(fdc->sc_dmachan, fdc->sc_dmat,
|
|
|
|
fdc->sc_dmamap,
|
|
|
|
(read?
|
|
|
|
DMAC_OCR_DIR_DTM:DMAC_OCR_DIR_MTD),
|
|
|
|
(DMAC_SCR_MAC_COUNT_UP|
|
|
|
|
DMAC_SCR_DAC_NO_COUNT),
|
|
|
|
(u_int8_t*) (fdc->sc_addr +
|
|
|
|
fddata)); /* XXX */
|
1997-10-11 01:42:38 +04:00
|
|
|
#if defined(M68040) || defined(M68060)
|
1999-03-16 19:30:16 +03:00
|
|
|
if (mmutype == MMU_68040)
|
|
|
|
dma_cachectl(addr, count);
|
1996-05-05 16:17:03 +04:00
|
|
|
#endif
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
dmac_start_xfer(fdc->sc_dmachan->ch_softc, fdc->sc_xfer);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
static int
|
|
|
|
fdcdmaintr(arg)
|
|
|
|
void *arg;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_softc *fdc = arg;
|
|
|
|
|
|
|
|
bus_dmamap_unload(fdc->sc_dmat, fdc->sc_dmamap);
|
|
|
|
|
|
|
|
return 0;
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
static int
|
|
|
|
fdcdmaerrintr(dummy)
|
|
|
|
void *dummy;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
DPRINTF(("fdcdmaerrintr\n"));
|
|
|
|
|
|
|
|
return 0;
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
1998-08-04 20:51:51 +04:00
|
|
|
/* ARGSUSED */
|
1996-05-05 16:17:03 +04:00
|
|
|
int
|
1998-08-04 20:51:51 +04:00
|
|
|
fdcprobe(parent, cf, aux)
|
1996-05-05 16:17:03 +04:00
|
|
|
struct device *parent;
|
1998-08-04 20:51:51 +04:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
struct intio_attach_args *ia = aux;
|
|
|
|
|
|
|
|
if (strcmp(ia->ia_name, "fdc") != 0)
|
1996-05-05 16:17:03 +04:00
|
|
|
return 0;
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
|
|
|
|
ia->ia_addr = FDC_ADDR;
|
|
|
|
if (ia->ia_intr == INTIOCF_INTR_DEFAULT)
|
|
|
|
ia->ia_intr = FDC_INTR;
|
|
|
|
if (ia->ia_dma == INTIOCF_DMA_DEFAULT)
|
|
|
|
ia->ia_dma = FDC_DMA;
|
|
|
|
if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT)
|
|
|
|
ia->ia_dmaintr = FDC_DMAINTR;
|
|
|
|
|
1999-03-24 17:07:38 +03:00
|
|
|
if ((ia->ia_intr & 0x03) != 0)
|
1999-03-16 19:30:16 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
ia->ia_size = 0x2000;
|
|
|
|
if (intio_map_allocate_region (parent, ia, INTIO_MAP_TESTONLY))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* builtin device; always there */
|
1996-05-05 16:17:03 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arguments passed between fdcattach and fdprobe.
|
|
|
|
*/
|
|
|
|
struct fdc_attach_args {
|
|
|
|
int fa_drive;
|
|
|
|
struct fd_type *fa_deftype;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the location of a disk drive (called just before attaching the
|
|
|
|
* the drive). If `fdc' is not NULL, the drive was found but was not
|
|
|
|
* in the system config file; print the drive name as well.
|
|
|
|
* Return QUIET (config_find ignores this if the device was configured) to
|
|
|
|
* avoid printing `fdN not configured' messages.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
fdprint(aux, fdc)
|
|
|
|
void *aux;
|
1996-08-28 01:53:46 +04:00
|
|
|
const char *fdc;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
register struct fdc_attach_args *fa = aux;
|
|
|
|
|
|
|
|
if (!fdc)
|
1996-10-13 07:29:05 +04:00
|
|
|
printf(" drive %d", fa->fa_drive);
|
1996-05-05 16:17:03 +04:00
|
|
|
return QUIET;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)self;
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
|
|
|
struct intio_attach_args *ia = aux;
|
1996-05-05 16:17:03 +04:00
|
|
|
struct fdc_attach_args fa;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
iot = ia->ia_bst;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Re-map the I/O space. */
|
|
|
|
bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh);
|
|
|
|
|
|
|
|
fdc->sc_iot = iot;
|
|
|
|
fdc->sc_ioh = ioh;
|
|
|
|
fdc->sc_addr = (void*) ia->ia_addr;
|
|
|
|
|
|
|
|
fdc->sc_dmat = ia->ia_dmat;
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
TAILQ_INIT(&fdc->sc_drives);
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
/* Initialize DMAC channel */
|
|
|
|
fdc->sc_dmachan = dmac_alloc_channel(parent, ia->ia_dma, "fdc",
|
|
|
|
ia->ia_dmaintr, fdcdmaintr, fdc,
|
|
|
|
ia->ia_dmaintr+1, fdcdmaerrintr,
|
|
|
|
fdc);
|
|
|
|
if (bus_dmamap_create(fdc->sc_dmat, FDC_MAXIOSIZE, 16, 0xf000, 0,
|
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
|
|
|
|
&fdc->sc_dmamap)) {
|
|
|
|
printf("%s: can't set up intio DMA map\n",
|
|
|
|
fdc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intio_intr_establish(ia->ia_intr, "fdc", fdcintr, fdc))
|
|
|
|
panic ("Could not establish interrupt (duplicated vector?).");
|
|
|
|
intio_set_ivec(ia->ia_intr);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
/* reset */
|
1999-03-16 19:30:16 +03:00
|
|
|
intio_disable_intr(SICILIAN_INTR_FDD);
|
|
|
|
intio_enable_intr(SICILIAN_INTR_FDC);
|
1996-05-05 16:17:03 +04:00
|
|
|
fdcresult(fdc);
|
1999-03-16 19:30:16 +03:00
|
|
|
fdcreset(fdc);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
printf("%s: uPD72065 FDC\n", fdc->sc_dev.dv_xname);
|
|
|
|
out_fdc(iot, ioh, NE7CMD_SPECIFY);/* specify command */
|
|
|
|
out_fdc(iot, ioh, 0xd0);
|
|
|
|
out_fdc(iot, ioh, 0x10);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
/* physical limit: four drives per controller. */
|
|
|
|
for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
|
|
|
|
(void)config_found(self, (void *)&fa, fdprint);
|
|
|
|
}
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
intio_enable_intr(SICILIAN_INTR_FDC);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-03-16 19:30:16 +03:00
|
|
|
fdcreset(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdsts, NE7CMD_RESET);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fdcpoll(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
int i = 25000, n;
|
1996-05-05 16:17:03 +04:00
|
|
|
while (--i > 0) {
|
1999-03-16 19:30:16 +03:00
|
|
|
if ((intio_get_sicilian_intr() & SICILIAN_STAT_FDC)) {
|
|
|
|
out_fdc(fdc->sc_iot, fdc->sc_ioh, NE7CMD_SENSEI);
|
|
|
|
n = fdcresult(fdc);
|
1996-05-05 16:17:03 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-08-04 20:51:51 +04:00
|
|
|
fdprobe(parent, cf, aux)
|
1996-05-05 16:17:03 +04:00
|
|
|
struct device *parent;
|
1998-08-04 20:51:51 +04:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)parent;
|
|
|
|
struct fd_type *type;
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_attach_args *fa = aux;
|
|
|
|
int drive = fa->fa_drive;
|
|
|
|
bus_space_tag_t iot = fdc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = fdc->sc_ioh;
|
1996-05-05 16:17:03 +04:00
|
|
|
int n;
|
|
|
|
int found = 0;
|
|
|
|
int i;
|
|
|
|
|
1997-07-17 06:12:50 +04:00
|
|
|
if (cf->cf_loc[FDCCF_UNIT] != FDCCF_UNIT_DEFAULT &&
|
|
|
|
cf->cf_loc[FDCCF_UNIT] != drive)
|
1996-05-05 16:17:03 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
type = &fd_types[0]; /* XXX 1.2MB */
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
intio_disable_intr(SICILIAN_INTR_FDC);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
/* select drive and turn on motor */
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(iot, ioh, fdctl, 0x80 | (type->rate << 4)| drive);
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc_force_ready(FDCRDY);
|
|
|
|
fdcpoll(fdc);
|
|
|
|
|
|
|
|
retry:
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_RECAL);
|
|
|
|
out_fdc(iot, ioh, drive);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
i = 25000;
|
|
|
|
while (--i > 0) {
|
1999-03-16 19:30:16 +03:00
|
|
|
if ((intio_get_sicilian_intr() & SICILIAN_STAT_FDC)) {
|
|
|
|
out_fdc(iot, ioh, NE7CMD_SENSEI);
|
1996-05-05 16:17:03 +04:00
|
|
|
n = fdcresult(fdc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FDDEBUG
|
|
|
|
{
|
|
|
|
int i;
|
1999-03-16 19:30:16 +03:00
|
|
|
DPRINTF(("fdprobe: status"));
|
1996-05-05 16:17:03 +04:00
|
|
|
for (i = 0; i < n; i++)
|
1999-03-16 19:30:16 +03:00
|
|
|
DPRINTF((" %x", fdc->sc_status[i]));
|
|
|
|
DPRINTF(("\n"));
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (n == 2) {
|
|
|
|
if ((fdc->sc_status[0] & 0xf0) == 0x20) {
|
|
|
|
found = 1;
|
|
|
|
} else if ((fdc->sc_status[0] & 0xf0) == 0xc0) {
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* turn off motor */
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh,
|
|
|
|
fdctl, (type->rate << 4)| drive);
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc_force_ready(FDCSTBY);
|
|
|
|
if (!found) {
|
1999-03-16 19:30:16 +03:00
|
|
|
intio_enable_intr(SICILIAN_INTR_FDC);
|
1996-05-05 16:17:03 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
/*
|
|
|
|
* Controller is working, and drive responded. Attach it.
|
|
|
|
*/
|
1996-05-05 16:17:03 +04:00
|
|
|
void
|
|
|
|
fdattach(parent, self, aux)
|
1999-03-16 19:30:16 +03:00
|
|
|
struct device *parent, *self;
|
1996-05-05 16:17:03 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)parent;
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fd_softc *fd = (void *)self;
|
1996-05-05 16:17:03 +04:00
|
|
|
struct fdc_attach_args *fa = aux;
|
|
|
|
struct fd_type *type = &fd_types[0]; /* XXX 1.2MB */
|
1999-03-16 19:30:16 +03:00
|
|
|
int drive = fa->fa_drive;
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
fd->sc_flags = 0;
|
|
|
|
|
|
|
|
if (type)
|
1999-03-16 19:30:16 +03:00
|
|
|
printf(": %s, %d cyl, %d head, %d sec\n", type->name,
|
|
|
|
type->cyls, type->heads, type->sectrac);
|
1996-05-05 16:17:03 +04:00
|
|
|
else
|
1996-10-13 07:29:05 +04:00
|
|
|
printf(": density unknown\n");
|
1996-05-05 16:17:03 +04:00
|
|
|
|
2000-01-22 02:39:55 +03:00
|
|
|
BUFQ_INIT(&fd->sc_q);
|
1996-05-05 16:17:03 +04:00
|
|
|
fd->sc_cylin = -1;
|
|
|
|
fd->sc_drive = drive;
|
|
|
|
fd->sc_deftype = type;
|
|
|
|
fdc->sc_fd[drive] = fd;
|
|
|
|
|
|
|
|
fd->sc_copybuf = (u_char *)malloc(NBPG, M_DEVBUF, M_WAITOK);
|
|
|
|
if (fd->sc_copybuf == 0)
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("fdprobe: WARNING!! malloc() failed.\n");
|
1996-05-05 16:17:03 +04:00
|
|
|
fd->sc_flags |= FD_ALIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
|
|
|
fd->sc_dk.dk_name = fd->sc_dev.dv_xname;
|
|
|
|
fd->sc_dk.dk_driver = &fddkdriver;
|
|
|
|
disk_attach(&fd->sc_dk);
|
1996-07-08 20:32:12 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Establish a mountroot_hook anyway in case we booted
|
|
|
|
* with RB_ASKNAME and get selected as the boot device.
|
|
|
|
*/
|
1997-01-31 05:15:54 +03:00
|
|
|
mountroothook_establish(fd_mountroot_hook, &fd->sc_dev);
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
#if NRND > 0
|
1999-03-18 19:15:53 +03:00
|
|
|
rnd_attach_source(&fd->rnd_source, fd->sc_dev.dv_xname,
|
|
|
|
RND_TYPE_DISK, 0);
|
1999-03-16 19:30:16 +03:00
|
|
|
#endif
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
1997-10-11 01:42:38 +04:00
|
|
|
__inline struct fd_type *
|
1996-05-05 16:17:03 +04:00
|
|
|
fd_dev_to_type(fd, dev)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
int type = FDTYPE(dev);
|
|
|
|
|
|
|
|
if (type > (sizeof(fd_types) / sizeof(fd_types[0])))
|
|
|
|
return NULL;
|
|
|
|
return &fd_types[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdstrategy(bp)
|
|
|
|
register struct buf *bp; /* IO operation to perform */
|
|
|
|
{
|
|
|
|
struct fd_softc *fd;
|
|
|
|
int unit = FDUNIT(bp->b_dev);
|
|
|
|
int sz;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
if (unit >= fd_cd.cd_ndevs ||
|
|
|
|
(fd = fd_cd.cd_devs[unit]) == 0 ||
|
|
|
|
bp->b_blkno < 0 ||
|
|
|
|
(bp->b_bcount % FDC_BSIZE) != 0) {
|
1999-03-16 19:30:16 +03:00
|
|
|
DPRINTF(("fdstrategy: unit=%d, blkno=%d, bcount=%d\n", unit,
|
|
|
|
bp->b_blkno, bp->b_bcount));
|
1996-05-05 16:17:03 +04:00
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If it's a null transfer, return immediately. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
sz = howmany(bp->b_bcount, FDC_BSIZE);
|
|
|
|
|
|
|
|
if (bp->b_blkno + sz > (fd->sc_type->size << (fd->sc_type->secsize - 2))) {
|
|
|
|
sz = (fd->sc_type->size << (fd->sc_type->secsize - 2)) - bp->b_blkno;
|
|
|
|
if (sz == 0) {
|
|
|
|
/* If exactly at end of disk, return EOF. */
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (sz < 0) {
|
|
|
|
/* If past end of disk, return EINVAL. */
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
/* Otherwise, truncate request. */
|
|
|
|
bp->b_bcount = sz << DEV_BSHIFT;
|
|
|
|
}
|
|
|
|
|
2000-02-07 23:16:47 +03:00
|
|
|
bp->b_rawblkno = bp->b_blkno;
|
2000-01-22 02:39:55 +03:00
|
|
|
bp->b_cylinder = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE)
|
1996-05-05 16:17:03 +04:00
|
|
|
/ (fd->sc_type->seccyl * (1 << (fd->sc_type->secsize - 2)));
|
|
|
|
|
1996-05-21 19:31:55 +04:00
|
|
|
DPRINTF(("fdstrategy: %s b_blkno %d b_bcount %ld cylin %ld\n",
|
1996-05-05 16:17:03 +04:00
|
|
|
bp->b_flags & B_READ ? "read" : "write",
|
2000-01-22 02:39:55 +03:00
|
|
|
bp->b_blkno, bp->b_bcount, bp->b_cylinder));
|
1996-05-05 16:17:03 +04:00
|
|
|
/* Queue transfer on drive, activate drive and controller if idle. */
|
|
|
|
s = splbio();
|
2000-01-22 02:39:55 +03:00
|
|
|
disksort_cylinder(&fd->sc_q, bp);
|
1996-05-05 16:17:03 +04:00
|
|
|
untimeout(fd_motor_off, fd); /* a good idea */
|
2000-01-22 02:39:55 +03:00
|
|
|
if (fd->sc_active == 0)
|
1996-05-05 16:17:03 +04:00
|
|
|
fdstart(fd);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
else {
|
1998-08-04 20:51:51 +04:00
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
1996-05-05 16:17:03 +04:00
|
|
|
if (fdc->sc_state == DEVIDLE) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("fdstrategy: controller inactive\n");
|
1996-05-05 16:17:03 +04:00
|
|
|
fdcstart(fdc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
/* Toss transfer; we're done early. */
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdstart(fd)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
|
|
|
int active = fdc->sc_drives.tqh_first != 0;
|
|
|
|
|
|
|
|
/* Link into controller queue. */
|
2000-01-22 02:39:55 +03:00
|
|
|
fd->sc_active = 1;
|
1996-05-05 16:17:03 +04:00
|
|
|
TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
|
|
|
|
/* If controller not already active, start it. */
|
|
|
|
if (!active)
|
|
|
|
fdcstart(fdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdfinish(fd, bp)
|
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move this drive to the end of the queue to give others a `fair'
|
|
|
|
* chance. We only force a switch if N operations are completed while
|
|
|
|
* another drive is waiting to be serviced, since there is a long motor
|
|
|
|
* startup delay whenever we switch.
|
|
|
|
*/
|
|
|
|
if (fd->sc_drivechain.tqe_next && ++fd->sc_ops >= 8) {
|
|
|
|
fd->sc_ops = 0;
|
|
|
|
TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
|
2000-01-22 02:39:55 +03:00
|
|
|
if (BUFQ_NEXT(bp) != NULL) {
|
1996-05-05 16:17:03 +04:00
|
|
|
TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
|
|
|
|
} else
|
2000-01-22 02:39:55 +03:00
|
|
|
fd->sc_active = 0;
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
bp->b_resid = fd->sc_bcount;
|
|
|
|
fd->sc_skip = 0;
|
2000-01-22 02:39:55 +03:00
|
|
|
BUFQ_REMOVE(&fd->sc_q, bp);
|
1999-03-16 19:30:16 +03:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rnd_add_uint32(&fd->rnd_source, bp->b_blkno);
|
|
|
|
#endif
|
|
|
|
|
1996-05-05 16:17:03 +04:00
|
|
|
biodone(bp);
|
|
|
|
/* turn off motor 5s from now */
|
|
|
|
timeout(fd_motor_off, fd, 5 * hz);
|
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-12 18:44:12 +04:00
|
|
|
fdread(dev, uio, flags)
|
1996-05-05 16:17:03 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1997-10-12 18:44:12 +04:00
|
|
|
int flags;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(fdstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-12 18:44:12 +04:00
|
|
|
fdwrite(dev, uio, flags)
|
1996-05-05 16:17:03 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1997-10-12 18:44:12 +04:00
|
|
|
int flags;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return (physio(fdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_set_motor(fdc, reset)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
int reset;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
DPRINTF(("fd_set_motor:\n"));
|
|
|
|
for (n = 0; n < 4; n++)
|
|
|
|
if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR)) {
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdctl,
|
|
|
|
0x80 | (fd->sc_type->rate << 4)| n);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_motor_off(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd = arg;
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_softc *fdc = (struct fdc_softc*) fd->sc_dev.dv_parent;
|
1996-05-05 16:17:03 +04:00
|
|
|
int s;
|
|
|
|
|
|
|
|
DPRINTF(("fd_motor_off:\n"));
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
fd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1 (fdc->sc_iot, fdc->sc_ioh, fdctl,
|
|
|
|
(fd->sc_type->rate << 4) | fd->sc_drive);
|
1996-05-05 16:17:03 +04:00
|
|
|
#if 0
|
1999-03-16 19:30:16 +03:00
|
|
|
fd_set_motor(fdc, 0); /* XXX */
|
1996-05-05 16:17:03 +04:00
|
|
|
#endif
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fd_motor_on(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd = arg;
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
DPRINTF(("fd_motor_on:\n"));
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
fd->sc_flags &= ~FD_MOTOR_WAIT;
|
|
|
|
if ((fdc->sc_drives.tqh_first == fd) && (fdc->sc_state == MOTORWAIT))
|
1999-03-16 19:30:16 +03:00
|
|
|
(void) fdcintr(fdc);
|
1996-05-05 16:17:03 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdcresult(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_tag_t iot = fdc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = fdc->sc_ioh;
|
1996-05-05 16:17:03 +04:00
|
|
|
u_char i;
|
|
|
|
int j = 100000,
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
for (; j; j--) {
|
1999-03-16 19:30:16 +03:00
|
|
|
i = bus_space_read_1(iot, ioh, fdsts) &
|
|
|
|
(NE7_DIO | NE7_RQM | NE7_CB);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
if (i == NE7_RQM)
|
|
|
|
return n;
|
|
|
|
if (i == (NE7_DIO | NE7_RQM | NE7_CB)) {
|
|
|
|
if (n >= sizeof(fdc->sc_status)) {
|
|
|
|
log(LOG_ERR, "fdcresult: overrun\n");
|
|
|
|
return -1;
|
|
|
|
}
|
1999-03-16 19:30:16 +03:00
|
|
|
fdc->sc_status[n++] =
|
|
|
|
bus_space_read_1(iot, ioh, fddata);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
1999-03-16 19:30:16 +03:00
|
|
|
delay(10);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
log(LOG_ERR, "fdcresult: timeout\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, x)
|
|
|
|
bus_space_tag_t iot;
|
|
|
|
bus_space_handle_t ioh;
|
1996-05-05 16:17:03 +04:00
|
|
|
u_char x;
|
|
|
|
{
|
|
|
|
int i = 100000;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
while ((bus_space_read_1(iot, ioh, fdsts) & NE7_DIO) && i-- > 0);
|
1996-05-05 16:17:03 +04:00
|
|
|
if (i <= 0)
|
|
|
|
return -1;
|
1999-03-16 19:30:16 +03:00
|
|
|
while ((bus_space_read_1(iot, ioh, fdsts) & NE7_RQM) == 0 && i-- > 0);
|
1996-05-05 16:17:03 +04:00
|
|
|
if (i <= 0)
|
|
|
|
return -1;
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(iot, ioh, fddata, x);
|
1996-05-05 16:17:03 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-12 18:44:12 +04:00
|
|
|
fdopen(dev, flags, mode, p)
|
1996-05-05 16:17:03 +04:00
|
|
|
dev_t dev;
|
1997-10-12 18:44:12 +04:00
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
struct fd_softc *fd;
|
|
|
|
struct fd_type *type;
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_softc *fdc;
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
unit = FDUNIT(dev);
|
|
|
|
if (unit >= fd_cd.cd_ndevs)
|
|
|
|
return ENXIO;
|
|
|
|
fd = fd_cd.cd_devs[unit];
|
|
|
|
if (fd == 0)
|
|
|
|
return ENXIO;
|
|
|
|
type = fd_dev_to_type(fd, dev);
|
|
|
|
if (type == NULL)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
if ((fd->sc_flags & FD_OPEN) != 0 &&
|
|
|
|
fd->sc_type != type)
|
|
|
|
return EBUSY;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
fdc = (void *)fd->sc_dev.dv_parent;
|
1996-05-05 16:17:03 +04:00
|
|
|
if ((fd->sc_flags & FD_OPEN) == 0) {
|
|
|
|
/* Lock eject button */
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout,
|
|
|
|
0x40 | ( 1 << unit));
|
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout, 0x40);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fd->sc_type = type;
|
|
|
|
fd->sc_cylin = -1;
|
|
|
|
|
1997-10-12 18:44:12 +04:00
|
|
|
switch (mode) {
|
1996-05-05 16:17:03 +04:00
|
|
|
case S_IFCHR:
|
|
|
|
fd->sc_flags |= FD_COPEN;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
fd->sc_flags |= FD_BOPEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fdgetdisklabel(fd, dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-12 18:44:12 +04:00
|
|
|
fdclose(dev, flags, mode, p)
|
1996-05-05 16:17:03 +04:00
|
|
|
dev_t dev;
|
1997-10-12 18:44:12 +04:00
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
int unit = FDUNIT(dev);
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fd_softc *fd = fd_cd.cd_devs[unit];
|
|
|
|
struct fdc_softc *fdc = (void *)fd->sc_dev.dv_parent;
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
DPRINTF(("fdclose %d\n", unit));
|
|
|
|
|
1997-10-12 18:44:12 +04:00
|
|
|
switch (mode) {
|
1996-05-05 16:17:03 +04:00
|
|
|
case S_IFCHR:
|
|
|
|
fd->sc_flags &= ~FD_COPEN;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
fd->sc_flags &= ~FD_BOPEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd->sc_flags & FD_OPEN) == 0) {
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout,
|
|
|
|
( 1 << unit));
|
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout, 0);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcstart(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
/* only got here if controller's drive queue was inactive; should
|
|
|
|
be in idle state */
|
|
|
|
if (fdc->sc_state != DEVIDLE) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("fdcstart: not idle\n");
|
1996-05-05 16:17:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
1999-03-16 19:30:16 +03:00
|
|
|
(void) fdcintr(fdc);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcstatus(dv, n, s)
|
|
|
|
struct device *dv;
|
|
|
|
int n;
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = (void *)dv->dv_parent;
|
1997-02-05 19:35:47 +03:00
|
|
|
char bits[64];
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
if (n == 0) {
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(fdc->sc_iot, fdc->sc_ioh, NE7CMD_SENSEI);
|
1996-05-05 16:17:03 +04:00
|
|
|
(void) fdcresult(fdc);
|
|
|
|
n = 2;
|
|
|
|
}
|
|
|
|
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("%s: %s: state %d", dv->dv_xname, s, fdc->sc_state);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("\n");
|
1996-05-05 16:17:03 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
1997-02-05 19:35:47 +03:00
|
|
|
printf(" (st0 %s cyl %d)\n",
|
|
|
|
bitmask_snprintf(fdc->sc_status[0], NE7_ST0BITS,
|
|
|
|
bits, sizeof(bits)), fdc->sc_status[1]);
|
1996-05-05 16:17:03 +04:00
|
|
|
break;
|
|
|
|
case 7:
|
1997-02-05 19:35:47 +03:00
|
|
|
printf(" (st0 %s", bitmask_snprintf(fdc->sc_status[0],
|
|
|
|
NE7_ST0BITS, bits, sizeof(bits)));
|
|
|
|
printf(" st1 %s", bitmask_snprintf(fdc->sc_status[1],
|
|
|
|
NE7_ST1BITS, bits, sizeof(bits)));
|
|
|
|
printf(" st2 %s", bitmask_snprintf(fdc->sc_status[2],
|
|
|
|
NE7_ST2BITS, bits, sizeof(bits)));
|
|
|
|
printf(" cyl %d head %d sec %d)\n",
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
|
|
|
|
break;
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
default:
|
1996-10-13 07:29:05 +04:00
|
|
|
printf(" fdcstatus: weird size: %d\n", n);
|
1996-05-05 16:17:03 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdctimeout(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct fdc_softc *fdc = arg;
|
|
|
|
struct fd_softc *fd = fdc->sc_drives.tqh_first;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
fdcstatus(&fd->sc_dev, 0, "timeout");
|
|
|
|
|
2000-01-22 02:39:55 +03:00
|
|
|
if (BUFQ_FIRST(&fd->sc_q) != NULL)
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_state++;
|
|
|
|
else
|
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
(void) fdcintr(fdc);
|
1996-05-05 16:17:03 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
#if 0
|
1996-05-05 16:17:03 +04:00
|
|
|
void
|
|
|
|
fdcpseudointr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
int s;
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_softc *fdc = arg;
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
/* just ensure it has the right spl */
|
|
|
|
s = splbio();
|
1999-03-16 19:30:16 +03:00
|
|
|
(void) fdcintr(fdc);
|
1996-05-05 16:17:03 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
1999-03-16 19:30:16 +03:00
|
|
|
#endif
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
int
|
1999-03-16 19:30:16 +03:00
|
|
|
fdcintr(arg)
|
|
|
|
void *arg;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_softc *fdc = arg;
|
1996-05-05 16:17:03 +04:00
|
|
|
#define st0 fdc->sc_status[0]
|
|
|
|
#define cyl fdc->sc_status[1]
|
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_tag_t iot = fdc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = fdc->sc_ioh;
|
1996-05-05 16:17:03 +04:00
|
|
|
int read, head, sec, pos, i, sectrac, nblks;
|
|
|
|
int tmp;
|
|
|
|
struct fd_type *type;
|
|
|
|
|
|
|
|
loop:
|
|
|
|
fd = fdc->sc_drives.tqh_first;
|
|
|
|
if (fd == NULL) {
|
|
|
|
DPRINTF(("fdcintr: set DEVIDLE\n"));
|
|
|
|
if (fdc->sc_state == DEVIDLE) {
|
1999-03-16 19:30:16 +03:00
|
|
|
if (intio_get_sicilian_intr() & SICILIAN_STAT_FDC) {
|
|
|
|
out_fdc(iot, ioh, NE7CMD_SENSEI);
|
|
|
|
if ((tmp = fdcresult(fdc)) != 2 ||
|
|
|
|
(st0 & 0xf8) != 0x20) {
|
1996-05-05 16:17:03 +04:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no drives waiting; end */
|
|
|
|
fdc->sc_state = DEVIDLE;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is there a transfer to this drive? If not, deactivate drive. */
|
2000-01-22 02:39:55 +03:00
|
|
|
bp = BUFQ_FIRST(&fd->sc_q);
|
1996-05-05 16:17:03 +04:00
|
|
|
if (bp == NULL) {
|
|
|
|
fd->sc_ops = 0;
|
|
|
|
TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
|
2000-01-22 02:39:55 +03:00
|
|
|
fd->sc_active = 0;
|
1996-05-05 16:17:03 +04:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fdc->sc_state) {
|
|
|
|
case DEVIDLE:
|
|
|
|
DPRINTF(("fdcintr: in DEVIDLE\n"));
|
|
|
|
fdc->sc_errors = 0;
|
|
|
|
fd->sc_skip = 0;
|
|
|
|
fd->sc_bcount = bp->b_bcount;
|
|
|
|
fd->sc_blkno = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE);
|
|
|
|
untimeout(fd_motor_off, fd);
|
|
|
|
if ((fd->sc_flags & FD_MOTOR_WAIT) != 0) {
|
|
|
|
fdc->sc_state = MOTORWAIT;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((fd->sc_flags & FD_MOTOR) == 0) {
|
1996-08-11 19:32:49 +04:00
|
|
|
/* Turn on the motor */
|
|
|
|
/* being careful about other drives. */
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
struct fd_softc *ofd = fdc->sc_fd[i];
|
|
|
|
if (ofd && ofd->sc_flags & FD_MOTOR) {
|
|
|
|
untimeout(fd_motor_off, ofd);
|
|
|
|
ofd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
|
|
|
|
break;
|
|
|
|
}
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
fd->sc_flags |= FD_MOTOR | FD_MOTOR_WAIT;
|
|
|
|
fd_set_motor(fdc, 0);
|
|
|
|
fdc->sc_state = MOTORWAIT;
|
|
|
|
/* allow .5s for motor to stabilize */
|
|
|
|
timeout(fd_motor_on, fd, hz / 2);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Make sure the right drive is selected. */
|
|
|
|
fd_set_motor(fdc, 0);
|
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
case DOSEEK:
|
|
|
|
doseek:
|
|
|
|
DPRINTF(("fdcintr: in DOSEEK\n"));
|
2000-01-22 02:39:55 +03:00
|
|
|
if (fd->sc_cylin == bp->b_cylinder)
|
1996-05-05 16:17:03 +04:00
|
|
|
goto doio;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_SPECIFY);/* specify command */
|
|
|
|
out_fdc(iot, ioh, 0xd0); /* XXX const */
|
|
|
|
out_fdc(iot, ioh, 0x10);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_SEEK); /* seek function */
|
|
|
|
out_fdc(iot, ioh, fd->sc_drive); /* drive number */
|
2000-01-22 02:39:55 +03:00
|
|
|
out_fdc(iot, ioh, bp->b_cylinder * fd->sc_type->step);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
fd->sc_cylin = -1;
|
|
|
|
fdc->sc_state = SEEKWAIT;
|
|
|
|
|
|
|
|
fd->sc_dk.dk_seek++;
|
|
|
|
disk_busy(&fd->sc_dk);
|
|
|
|
|
|
|
|
timeout(fdctimeout, fdc, 4 * hz);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case DOIO:
|
|
|
|
doio:
|
|
|
|
DPRINTF(("fdcintr: DOIO: "));
|
|
|
|
type = fd->sc_type;
|
|
|
|
sectrac = type->sectrac;
|
|
|
|
pos = fd->sc_blkno % (sectrac * (1 << (type->secsize - 2)));
|
|
|
|
sec = pos / (1 << (type->secsize - 2));
|
|
|
|
if (type->secsize == 2) {
|
|
|
|
fd->sc_part = SEC_P11;
|
|
|
|
nblks = (sectrac - sec) << (type->secsize - 2);
|
|
|
|
nblks = min(nblks, fd->sc_bcount / FDC_BSIZE);
|
|
|
|
DPRINTF(("nblks(0)"));
|
|
|
|
} else if ((fd->sc_blkno % 2) == 0) {
|
|
|
|
if (fd->sc_bcount & 0x00000200) {
|
|
|
|
if (fd->sc_bcount == FDC_BSIZE) {
|
|
|
|
fd->sc_part = SEC_P10;
|
|
|
|
nblks = 1;
|
|
|
|
DPRINTF(("nblks(1)"));
|
|
|
|
} else {
|
|
|
|
fd->sc_part = SEC_P11;
|
|
|
|
nblks = (sectrac - sec) * 2;
|
|
|
|
nblks = min(nblks, fd->sc_bcount
|
|
|
|
/ FDC_BSIZE - 1);
|
|
|
|
DPRINTF(("nblks(2)"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fd->sc_part = SEC_P11;
|
|
|
|
nblks = (sectrac - sec)
|
|
|
|
<< (type->secsize - 2);
|
|
|
|
nblks = min(nblks, fd->sc_bcount / FDC_BSIZE);
|
|
|
|
DPRINTF(("nblks(3)"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fd->sc_part = SEC_P01;
|
|
|
|
nblks = 1;
|
|
|
|
DPRINTF(("nblks(4)"));
|
|
|
|
}
|
|
|
|
nblks = min(nblks, FDC_MAXIOSIZE / FDC_BSIZE);
|
|
|
|
DPRINTF((" %d\n", nblks));
|
|
|
|
fd->sc_nblks = nblks;
|
|
|
|
fd->sc_nbytes = nblks * FDC_BSIZE;
|
|
|
|
head = (fd->sc_blkno
|
|
|
|
% (type->seccyl * (1 << (type->secsize - 2))))
|
|
|
|
/ (type->sectrac * (1 << (type->secsize - 2)));
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
{int block;
|
|
|
|
block = ((fd->sc_cylin * type->heads + head) * type->sectrac
|
|
|
|
+ sec) * (1 << (type->secsize - 2));
|
|
|
|
block += (fd->sc_part == SEC_P01) ? 1 : 0;
|
|
|
|
if (block != fd->sc_blkno) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("C H R N: %d %d %d %d\n", fd->sc_cylin, head, sec, type->secsize);
|
|
|
|
printf("fdcintr: doio: block %d != blkno %d\n", block, fd->sc_blkno);
|
1996-05-05 16:17:03 +04:00
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
}}
|
|
|
|
#endif
|
|
|
|
read = bp->b_flags & B_READ;
|
|
|
|
DPRINTF(("fdcintr: %s drive %d track %d head %d sec %d nblks %d, skip %d\n",
|
|
|
|
read ? "read" : "write", fd->sc_drive, fd->sc_cylin,
|
|
|
|
head, sec, nblks, fd->sc_skip));
|
|
|
|
DPRINTF(("C H R N: %d %d %d %d\n", fd->sc_cylin, head, sec,
|
|
|
|
type->secsize));
|
|
|
|
|
|
|
|
if (fd->sc_part != SEC_P11)
|
|
|
|
goto docopy;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
fdc_dmastart(fdc,
|
|
|
|
read, bp->b_data + fd->sc_skip, fd->sc_nbytes);
|
1996-05-05 16:17:03 +04:00
|
|
|
if (read)
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_READ); /* READ */
|
1996-05-05 16:17:03 +04:00
|
|
|
else
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_WRITE); /* WRITE */
|
|
|
|
out_fdc(iot, ioh, (head << 2) | fd->sc_drive);
|
2000-01-22 02:39:55 +03:00
|
|
|
out_fdc(iot, ioh, bp->b_cylinder); /* cylinder */
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, head);
|
|
|
|
out_fdc(iot, ioh, sec + 1); /* sector +1 */
|
|
|
|
out_fdc(iot, ioh, type->secsize); /* sector size */
|
|
|
|
out_fdc(iot, ioh, type->sectrac); /* sectors/track */
|
|
|
|
out_fdc(iot, ioh, type->gap1); /* gap1 size */
|
|
|
|
out_fdc(iot, ioh, type->datalen); /* data length */
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_state = IOCOMPLETE;
|
|
|
|
|
|
|
|
disk_busy(&fd->sc_dk);
|
|
|
|
|
|
|
|
/* allow 2 seconds for operation */
|
|
|
|
timeout(fdctimeout, fdc, 2 * hz);
|
|
|
|
return 1; /* will return later */
|
|
|
|
|
|
|
|
case DOCOPY:
|
|
|
|
docopy:
|
|
|
|
DPRINTF(("fdcintr: DOCOPY:\n"));
|
1999-03-16 19:30:16 +03:00
|
|
|
fdc_dmastart(fdc, B_READ, fd->sc_copybuf, 1024);
|
|
|
|
out_fdc(iot, ioh, NE7CMD_READ); /* READ */
|
|
|
|
out_fdc(iot, ioh, (head << 2) | fd->sc_drive);
|
2000-01-22 02:39:55 +03:00
|
|
|
out_fdc(iot, ioh, bp->b_cylinder); /* cylinder */
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, head);
|
|
|
|
out_fdc(iot, ioh, sec + 1); /* sector +1 */
|
|
|
|
out_fdc(iot, ioh, type->secsize); /* sector size */
|
|
|
|
out_fdc(iot, ioh, type->sectrac); /* sectors/track */
|
|
|
|
out_fdc(iot, ioh, type->gap1); /* gap1 size */
|
|
|
|
out_fdc(iot, ioh, type->datalen); /* data length */
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_state = COPYCOMPLETE;
|
|
|
|
/* allow 2 seconds for operation */
|
|
|
|
timeout(fdctimeout, fdc, 2 * hz);
|
|
|
|
return 1; /* will return later */
|
|
|
|
|
|
|
|
case DOIOHALF:
|
|
|
|
doiohalf:
|
|
|
|
DPRINTF((" DOIOHALF:\n"));
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
type = fd->sc_type;
|
|
|
|
sectrac = type->sectrac;
|
|
|
|
pos = fd->sc_blkno % (sectrac * (1 << (type->secsize - 2)));
|
|
|
|
sec = pos / (1 << (type->secsize - 2));
|
|
|
|
head = (fd->sc_blkno
|
|
|
|
% (type->seccyl * (1 << (type->secsize - 2))))
|
|
|
|
/ (type->sectrac * (1 << (type->secsize - 2)));
|
|
|
|
{int block;
|
|
|
|
block = ((fd->sc_cylin * type->heads + head) * type->sectrac + sec)
|
|
|
|
* (1 << (type->secsize - 2));
|
|
|
|
block += (fd->sc_part == SEC_P01) ? 1 : 0;
|
|
|
|
if (block != fd->sc_blkno) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("fdcintr: block %d != blkno %d\n", block, fd->sc_blkno);
|
1996-05-05 16:17:03 +04:00
|
|
|
#ifdef DDB
|
|
|
|
Debugger();
|
|
|
|
#endif
|
|
|
|
}}
|
|
|
|
#endif
|
1999-03-24 17:07:38 +03:00
|
|
|
if ((read = bp->b_flags & B_READ)) {
|
1996-05-05 16:17:03 +04:00
|
|
|
bcopy(fd->sc_copybuf
|
|
|
|
+ (fd->sc_part & SEC_P01 ? FDC_BSIZE : 0),
|
|
|
|
bp->b_data + fd->sc_skip,
|
|
|
|
FDC_BSIZE);
|
|
|
|
fdc->sc_state = IOCOMPLETE;
|
|
|
|
goto iocomplete2;
|
|
|
|
} else {
|
|
|
|
bcopy(bp->b_data + fd->sc_skip,
|
|
|
|
fd->sc_copybuf
|
|
|
|
+ (fd->sc_part & SEC_P01 ? FDC_BSIZE : 0),
|
|
|
|
FDC_BSIZE);
|
1999-03-16 19:30:16 +03:00
|
|
|
fdc_dmastart(fdc, read, fd->sc_copybuf, 1024);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_WRITE); /* WRITE */
|
|
|
|
out_fdc(iot, ioh, (head << 2) | fd->sc_drive);
|
2000-01-22 02:39:55 +03:00
|
|
|
out_fdc(iot, ioh, bp->b_cylinder); /* cylinder */
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, head);
|
|
|
|
out_fdc(iot, ioh, sec + 1); /* sector +1 */
|
|
|
|
out_fdc(iot, ioh, fd->sc_type->secsize); /* sector size */
|
|
|
|
out_fdc(iot, ioh, sectrac); /* sectors/track */
|
|
|
|
out_fdc(iot, ioh, fd->sc_type->gap1); /* gap1 size */
|
|
|
|
out_fdc(iot, ioh, fd->sc_type->datalen); /* data length */
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_state = IOCOMPLETE;
|
|
|
|
/* allow 2 seconds for operation */
|
|
|
|
timeout(fdctimeout, fdc, 2 * hz);
|
|
|
|
return 1; /* will return later */
|
|
|
|
|
|
|
|
case SEEKWAIT:
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
fdc->sc_state = SEEKCOMPLETE;
|
|
|
|
/* allow 1/50 second for heads to settle */
|
1999-03-16 19:30:16 +03:00
|
|
|
#if 0
|
|
|
|
timeout(fdcpseudointr, fdc, hz / 50);
|
|
|
|
#endif
|
1996-05-05 16:17:03 +04:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
case SEEKCOMPLETE:
|
|
|
|
/* Make sure seek really happened */
|
|
|
|
DPRINTF(("fdcintr: SEEKCOMPLETE: FDC status = %x\n",
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_read_1(fdc->sc_iot, fdc->sc_ioh, fdsts)));
|
|
|
|
out_fdc(iot, ioh, NE7CMD_SENSEI);
|
1996-05-05 16:17:03 +04:00
|
|
|
tmp = fdcresult(fdc);
|
|
|
|
if ((st0 & 0xf8) == 0xc0) {
|
|
|
|
DPRINTF(("fdcintr: first seek!\n"));
|
|
|
|
fdc->sc_state = DORECAL;
|
|
|
|
goto loop;
|
1999-03-16 19:30:16 +03:00
|
|
|
} else if (tmp != 2 ||
|
|
|
|
(st0 & 0xf8) != 0x20 ||
|
2000-01-22 02:39:55 +03:00
|
|
|
cyl != bp->b_cylinder) {
|
1996-05-05 16:17:03 +04:00
|
|
|
#ifdef FDDEBUG
|
|
|
|
fdcstatus(&fd->sc_dev, 2, "seek failed");
|
|
|
|
#endif
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
2000-01-22 02:39:55 +03:00
|
|
|
fd->sc_cylin = bp->b_cylinder;
|
1996-05-05 16:17:03 +04:00
|
|
|
goto doio;
|
|
|
|
|
|
|
|
case IOTIMEDOUT:
|
|
|
|
#if 0
|
|
|
|
isa_dmaabort(fdc->sc_drq);
|
|
|
|
#endif
|
|
|
|
case SEEKTIMEDOUT:
|
|
|
|
case RECALTIMEDOUT:
|
|
|
|
case RESETTIMEDOUT:
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
case IOCOMPLETE: /* IO DONE, post-analyze */
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
DPRINTF(("fdcintr: in IOCOMPLETE\n"));
|
|
|
|
if ((tmp = fdcresult(fdc)) != 7 || (st0 & 0xf8) != 0) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("fdcintr: resnum=%d, st0=%x\n", tmp, st0);
|
1996-05-05 16:17:03 +04:00
|
|
|
#if 0
|
|
|
|
isa_dmaabort(fdc->sc_drq);
|
|
|
|
#endif
|
|
|
|
fdcstatus(&fd->sc_dev, 7, bp->b_flags & B_READ ?
|
|
|
|
"read failed" : "write failed");
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("blkno %d nblks %d\n",
|
1996-05-05 16:17:03 +04:00
|
|
|
fd->sc_blkno, fd->sc_nblks);
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
isa_dmadone(bp->b_flags & B_READ, bp->b_data + fd->sc_skip,
|
|
|
|
nblks * FDC_BSIZE, fdc->sc_drq);
|
|
|
|
#endif
|
|
|
|
iocomplete2:
|
|
|
|
if (fdc->sc_errors) {
|
1999-03-16 19:30:16 +03:00
|
|
|
diskerr(bp, "fd", "soft error (corrected)", LOG_PRINTF,
|
1996-05-05 16:17:03 +04:00
|
|
|
fd->sc_skip / FDC_BSIZE, (struct disklabel *)NULL);
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("\n");
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_errors = 0;
|
|
|
|
}
|
|
|
|
fd->sc_blkno += fd->sc_nblks;
|
|
|
|
fd->sc_skip += fd->sc_nbytes;
|
|
|
|
fd->sc_bcount -= fd->sc_nbytes;
|
|
|
|
DPRINTF(("fd->sc_bcount = %d\n", fd->sc_bcount));
|
|
|
|
if (fd->sc_bcount > 0) {
|
2000-01-22 02:39:55 +03:00
|
|
|
bp->b_cylinder = fd->sc_blkno
|
1996-05-05 16:17:03 +04:00
|
|
|
/ (fd->sc_type->seccyl
|
|
|
|
* (1 << (fd->sc_type->secsize - 2)));
|
|
|
|
goto doseek;
|
|
|
|
}
|
|
|
|
fdfinish(fd, bp);
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
case COPYCOMPLETE: /* IO DONE, post-analyze */
|
|
|
|
DPRINTF(("fdcintr: COPYCOMPLETE:"));
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
if ((tmp = fdcresult(fdc)) != 7 || (st0 & 0xf8) != 0) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("fdcintr: resnum=%d, st0=%x\n", tmp, st0);
|
1996-05-05 16:17:03 +04:00
|
|
|
#if 0
|
|
|
|
isa_dmaabort(fdc->sc_drq);
|
|
|
|
#endif
|
|
|
|
fdcstatus(&fd->sc_dev, 7, bp->b_flags & B_READ ?
|
|
|
|
"read failed" : "write failed");
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("blkno %d nblks %d\n",
|
1996-05-05 16:17:03 +04:00
|
|
|
fd->sc_blkno, fd->sc_nblks);
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
goto doiohalf;
|
|
|
|
|
|
|
|
case DORESET:
|
|
|
|
DPRINTF(("fdcintr: in DORESET\n"));
|
|
|
|
/* try a reset, keep motor on */
|
|
|
|
fd_set_motor(fdc, 1);
|
|
|
|
DELAY(100);
|
|
|
|
fd_set_motor(fdc, 0);
|
|
|
|
fdc->sc_state = RESETCOMPLETE;
|
|
|
|
timeout(fdctimeout, fdc, hz / 2);
|
|
|
|
return 1; /* will return later */
|
|
|
|
|
|
|
|
case RESETCOMPLETE:
|
|
|
|
DPRINTF(("fdcintr: in RESETCOMPLETE\n"));
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
/* clear the controller output buffer */
|
|
|
|
for (i = 0; i < 4; i++) {
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_SENSEI);
|
1996-05-05 16:17:03 +04:00
|
|
|
(void) fdcresult(fdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fall through */
|
|
|
|
case DORECAL:
|
|
|
|
DPRINTF(("fdcintr: in DORECAL\n"));
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_RECAL); /* recalibrate function */
|
|
|
|
out_fdc(iot, ioh, fd->sc_drive);
|
1996-05-05 16:17:03 +04:00
|
|
|
fdc->sc_state = RECALWAIT;
|
|
|
|
timeout(fdctimeout, fdc, 5 * hz);
|
|
|
|
return 1; /* will return later */
|
|
|
|
|
|
|
|
case RECALWAIT:
|
|
|
|
DPRINTF(("fdcintr: in RECALWAIT\n"));
|
|
|
|
untimeout(fdctimeout, fdc);
|
|
|
|
fdc->sc_state = RECALCOMPLETE;
|
|
|
|
/* allow 1/30 second for heads to settle */
|
1999-03-16 19:30:16 +03:00
|
|
|
#if 0
|
|
|
|
timeout(fdcpseudointr, fdc, hz / 30);
|
|
|
|
#endif
|
1996-05-05 16:17:03 +04:00
|
|
|
return 1; /* will return later */
|
|
|
|
|
|
|
|
case RECALCOMPLETE:
|
|
|
|
DPRINTF(("fdcintr: in RECALCOMPLETE\n"));
|
1999-03-16 19:30:16 +03:00
|
|
|
out_fdc(iot, ioh, NE7CMD_SENSEI);
|
1996-05-05 16:17:03 +04:00
|
|
|
tmp = fdcresult(fdc);
|
|
|
|
if ((st0 & 0xf8) == 0xc0) {
|
|
|
|
DPRINTF(("fdcintr: first seek!\n"));
|
|
|
|
fdc->sc_state = DORECAL;
|
|
|
|
goto loop;
|
|
|
|
} else if (tmp != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) {
|
|
|
|
#ifdef FDDEBUG
|
|
|
|
fdcstatus(&fd->sc_dev, 2, "recalibrate failed");
|
|
|
|
#endif
|
|
|
|
fdcretry(fdc);
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
fd->sc_cylin = 0;
|
|
|
|
goto doseek;
|
|
|
|
|
|
|
|
case MOTORWAIT:
|
|
|
|
if (fd->sc_flags & FD_MOTOR_WAIT)
|
|
|
|
return 1; /* time's not up yet */
|
|
|
|
goto doseek;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fdcstatus(&fd->sc_dev, 0, "stray interrupt");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("fdcintr: impossible");
|
|
|
|
#endif
|
|
|
|
#undef st0
|
|
|
|
#undef cyl
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fdcretry(fdc)
|
|
|
|
struct fdc_softc *fdc;
|
|
|
|
{
|
|
|
|
struct fd_softc *fd;
|
|
|
|
struct buf *bp;
|
1997-04-02 21:10:41 +04:00
|
|
|
char bits[64];
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
DPRINTF(("fdcretry:\n"));
|
|
|
|
fd = fdc->sc_drives.tqh_first;
|
2000-01-22 02:39:55 +03:00
|
|
|
bp = BUFQ_FIRST(&fd->sc_q);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
switch (fdc->sc_errors) {
|
|
|
|
case 0:
|
|
|
|
/* try again */
|
|
|
|
fdc->sc_state = SEEKCOMPLETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: case 2: case 3:
|
|
|
|
/* didn't work; try recalibrating */
|
|
|
|
fdc->sc_state = DORECAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
/* still no go; reset the bastard */
|
|
|
|
fdc->sc_state = DORESET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
diskerr(bp, "fd", "hard error", LOG_PRINTF,
|
|
|
|
fd->sc_skip, (struct disklabel *)NULL);
|
1997-02-05 19:35:47 +03:00
|
|
|
printf(" (st0 %s", bitmask_snprintf(fdc->sc_status[0],
|
|
|
|
NE7_ST0BITS, bits,
|
|
|
|
sizeof(bits)));
|
|
|
|
printf(" st1 %s", bitmask_snprintf(fdc->sc_status[1],
|
|
|
|
NE7_ST1BITS, bits,
|
|
|
|
sizeof(bits)));
|
|
|
|
printf(" st2 %s", bitmask_snprintf(fdc->sc_status[2],
|
|
|
|
NE7_ST2BITS, bits,
|
|
|
|
sizeof(bits)));
|
|
|
|
printf(" cyl %d head %d sec %d)\n",
|
|
|
|
fdc->sc_status[3],
|
|
|
|
fdc->sc_status[4],
|
|
|
|
fdc->sc_status[5]);
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = EIO;
|
|
|
|
fdfinish(fd, bp);
|
|
|
|
}
|
|
|
|
fdc->sc_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fdsize(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Swapping to floppies would not make sense. */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Not implemented. */
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-10-12 18:44:12 +04:00
|
|
|
fdioctl(dev, cmd, addr, flag, p)
|
1996-05-05 16:17:03 +04:00
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t addr;
|
|
|
|
int flag;
|
1997-10-12 18:44:12 +04:00
|
|
|
struct proc *p;
|
1996-05-05 16:17:03 +04:00
|
|
|
{
|
|
|
|
struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fdc_softc *fdc = (void*) fd->sc_dev.dv_parent;
|
1996-05-05 16:17:03 +04:00
|
|
|
int unit = FDUNIT(dev);
|
1999-02-08 19:33:16 +03:00
|
|
|
int part = DISKPART(dev);
|
1996-05-05 16:17:03 +04:00
|
|
|
struct disklabel buffer;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
DPRINTF(("fdioctl:\n"));
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
|
|
|
#if 1
|
|
|
|
*(struct disklabel *)addr = *(fd->sc_dk.dk_label);
|
|
|
|
return(0);
|
|
|
|
#else
|
1999-03-16 19:30:16 +03:00
|
|
|
memset(&buffer, 0, sizeof(buffer));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
buffer.d_secpercyl = fd->sc_type->seccyl;
|
|
|
|
buffer.d_type = DTYPE_FLOPPY;
|
|
|
|
buffer.d_secsize = 128 << fd->sc_type->secsize;
|
|
|
|
|
|
|
|
if (readdisklabel(dev, fdstrategy, &buffer, NULL) != NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
*(struct disklabel *)addr = buffer;
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case DIOCGPART:
|
|
|
|
((struct partinfo *)addr)->disklab = fd->sc_dk.dk_label;
|
|
|
|
((struct partinfo *)addr)->part =
|
1999-02-08 19:33:16 +03:00
|
|
|
&fd->sc_dk.dk_label->d_partitions[part];
|
1996-05-05 16:17:03 +04:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
/* XXX do something */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EBADF;
|
|
|
|
|
|
|
|
error = setdisklabel(&buffer, (struct disklabel *)addr, 0, NULL);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error = writedisklabel(dev, fdstrategy, &buffer, NULL);
|
|
|
|
return error;
|
|
|
|
|
|
|
|
case DIOCLOCK:
|
|
|
|
/*
|
|
|
|
* Nothing to do here, really.
|
|
|
|
*/
|
|
|
|
return 0; /* XXX */
|
|
|
|
|
|
|
|
case DIOCEJECT:
|
1999-02-08 19:33:16 +03:00
|
|
|
if (*(int *)addr == 0) {
|
|
|
|
/*
|
|
|
|
* Don't force eject: check that we are the only
|
|
|
|
* partition open. If so, unlock it.
|
|
|
|
*/
|
|
|
|
if ((fd->sc_dk.dk_openmask & ~(1 << part)) != 0 ||
|
|
|
|
fd->sc_dk.dk_bopenmask + fd->sc_dk.dk_copenmask !=
|
|
|
|
fd->sc_dk.dk_openmask) {
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case ODIOCEJECT:
|
1999-03-16 19:30:16 +03:00
|
|
|
fd_do_eject(fdc, unit);
|
1996-05-05 16:17:03 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("fdioctl: impossible");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-03-16 19:30:16 +03:00
|
|
|
fd_do_eject(fdc, unit)
|
|
|
|
struct fdc_softc *fdc;
|
1996-05-05 16:17:03 +04:00
|
|
|
int unit;
|
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout,
|
|
|
|
0x20 | ( 1 << unit));
|
1996-05-05 16:17:03 +04:00
|
|
|
DELAY(1); /* XXX */
|
1999-03-16 19:30:16 +03:00
|
|
|
bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout, 0x20);
|
1996-05-05 16:17:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build disk label. For now we only create a label from what we know
|
|
|
|
* from 'sc'.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
fdgetdisklabel(sc, dev)
|
|
|
|
struct fd_softc *sc;
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
struct disklabel *lp;
|
|
|
|
int part;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
DPRINTF(("fdgetdisklabel()\n"));
|
1996-05-05 16:17:03 +04:00
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
lp = sc->sc_dk.dk_label;
|
|
|
|
bzero(lp, sizeof(struct disklabel));
|
|
|
|
|
|
|
|
lp->d_secsize = 128 << sc->sc_type->secsize;
|
|
|
|
lp->d_ntracks = sc->sc_type->heads;
|
|
|
|
lp->d_nsectors = sc->sc_type->sectrac;
|
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
lp->d_ncylinders = sc->sc_type->size / lp->d_secpercyl;
|
|
|
|
lp->d_secperunit = sc->sc_type->size;
|
|
|
|
|
|
|
|
lp->d_type = DTYPE_FLOPPY;
|
|
|
|
lp->d_rpm = 300; /* XXX */
|
|
|
|
lp->d_interleave = 1; /* FIXME: is this OK? */
|
|
|
|
lp->d_bbsize = 0;
|
|
|
|
lp->d_sbsize = 0;
|
|
|
|
lp->d_npartitions = part + 1;
|
|
|
|
#define STEP_DELAY 6000 /* 6ms (6000us) delay after stepping */
|
|
|
|
lp->d_trkseek = STEP_DELAY; /* XXX */
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
lp->d_partitions[part].p_size = lp->d_secperunit;
|
|
|
|
lp->d_partitions[part].p_fstype = FS_UNUSED;
|
|
|
|
lp->d_partitions[part].p_fsize = 1024;
|
|
|
|
lp->d_partitions[part].p_frag = 8;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1999-03-24 17:07:38 +03:00
|
|
|
#include <dev/cons.h>
|
|
|
|
|
1997-10-12 18:44:12 +04:00
|
|
|
/*
|
|
|
|
* Mountroot hook: prompt the user to enter the root file system
|
|
|
|
* floppy.
|
|
|
|
*/
|
1996-07-08 20:32:12 +04:00
|
|
|
void
|
|
|
|
fd_mountroot_hook(dev)
|
|
|
|
struct device *dev;
|
|
|
|
{
|
1999-03-16 19:30:16 +03:00
|
|
|
struct fd_softc *fd = (void*) dev;
|
|
|
|
struct fdc_softc *fdc = (void*) fd->sc_dev.dv_parent;
|
1996-07-08 20:32:12 +04:00
|
|
|
int c;
|
|
|
|
|
1999-03-16 19:30:16 +03:00
|
|
|
fd_do_eject(fdc, dev->dv_unit);
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("Insert filesystem floppy and press return.");
|
1996-07-08 20:32:12 +04:00
|
|
|
for (;;) {
|
|
|
|
c = cngetc();
|
|
|
|
if ((c == '\r') || (c == '\n')) {
|
1996-10-13 07:29:05 +04:00
|
|
|
printf("\n");
|
1997-10-12 18:44:12 +04:00
|
|
|
break;
|
1996-07-08 20:32:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|