Home | History | Annotate | Line # | Download | only in dev
fd.c revision 1.35
      1  1.35        pk /*	$NetBSD: fd.c,v 1.35 1996/06/16 23:28:18 pk Exp $	*/
      2   1.1        pk 
      3   1.1        pk /*-
      4   1.1        pk  * Copyright (c) 1993, 1994, 1995 Charles Hannum.
      5   1.1        pk  * Copyright (c) 1995 Paul Kranenburg.
      6   1.1        pk  * Copyright (c) 1990 The Regents of the University of California.
      7   1.1        pk  * All rights reserved.
      8   1.1        pk  *
      9   1.1        pk  * This code is derived from software contributed to Berkeley by
     10   1.1        pk  * Don Ahn.
     11   1.1        pk  *
     12   1.1        pk  * Redistribution and use in source and binary forms, with or without
     13   1.1        pk  * modification, are permitted provided that the following conditions
     14   1.1        pk  * are met:
     15   1.1        pk  * 1. Redistributions of source code must retain the above copyright
     16   1.1        pk  *    notice, this list of conditions and the following disclaimer.
     17   1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     19   1.1        pk  *    documentation and/or other materials provided with the distribution.
     20   1.1        pk  * 3. All advertising materials mentioning features or use of this software
     21   1.1        pk  *    must display the following acknowledgement:
     22   1.1        pk  *	This product includes software developed by the University of
     23   1.1        pk  *	California, Berkeley and its contributors.
     24   1.1        pk  * 4. Neither the name of the University nor the names of its contributors
     25   1.1        pk  *    may be used to endorse or promote products derived from this software
     26   1.1        pk  *    without specific prior written permission.
     27   1.1        pk  *
     28   1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29   1.1        pk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30   1.1        pk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31   1.1        pk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32   1.1        pk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33   1.1        pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34   1.1        pk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35   1.1        pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36   1.1        pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37   1.1        pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38   1.1        pk  * SUCH DAMAGE.
     39   1.1        pk  *
     40   1.1        pk  *	@(#)fd.c	7.4 (Berkeley) 5/25/91
     41   1.1        pk  */
     42   1.1        pk 
     43   1.1        pk #include <sys/param.h>
     44   1.1        pk #include <sys/systm.h>
     45   1.1        pk #include <sys/kernel.h>
     46   1.1        pk #include <sys/file.h>
     47   1.1        pk #include <sys/ioctl.h>
     48   1.1        pk #include <sys/device.h>
     49   1.1        pk #include <sys/disklabel.h>
     50   1.1        pk #include <sys/dkstat.h>
     51   1.1        pk #include <sys/disk.h>
     52   1.1        pk #include <sys/buf.h>
     53   1.1        pk #include <sys/uio.h>
     54  1.19   thorpej #include <sys/stat.h>
     55   1.1        pk #include <sys/syslog.h>
     56   1.1        pk #include <sys/queue.h>
     57  1.30  christos #include <sys/conf.h>
     58  1.24  christos 
     59  1.24  christos #include <dev/cons.h>
     60   1.1        pk 
     61   1.1        pk #include <machine/cpu.h>
     62   1.1        pk #include <machine/autoconf.h>
     63  1.30  christos #include <machine/conf.h>
     64  1.30  christos 
     65   1.2        pk #include <sparc/sparc/auxreg.h>
     66   1.1        pk #include <sparc/dev/fdreg.h>
     67   1.2        pk #include <sparc/dev/fdvar.h>
     68   1.1        pk 
     69   1.1        pk #define FDUNIT(dev)	(minor(dev) / 8)
     70   1.1        pk #define FDTYPE(dev)	(minor(dev) % 8)
     71   1.1        pk 
     72   1.1        pk #define b_cylin b_resid
     73   1.1        pk 
     74   1.2        pk #define FD_DEBUG
     75   1.2        pk #ifdef FD_DEBUG
     76   1.2        pk int	fdc_debug = 0;
     77   1.2        pk #endif
     78   1.2        pk 
     79   1.1        pk enum fdc_state {
     80   1.1        pk 	DEVIDLE = 0,
     81   1.1        pk 	MOTORWAIT,
     82   1.1        pk 	DOSEEK,
     83   1.1        pk 	SEEKWAIT,
     84   1.1        pk 	SEEKTIMEDOUT,
     85   1.1        pk 	SEEKCOMPLETE,
     86   1.1        pk 	DOIO,
     87   1.2        pk 	IOCOMPLETE,
     88   1.1        pk 	IOTIMEDOUT,
     89   1.1        pk 	DORESET,
     90   1.1        pk 	RESETCOMPLETE,
     91   1.1        pk 	RESETTIMEDOUT,
     92   1.1        pk 	DORECAL,
     93   1.1        pk 	RECALWAIT,
     94   1.1        pk 	RECALTIMEDOUT,
     95   1.1        pk 	RECALCOMPLETE,
     96   1.1        pk };
     97   1.1        pk 
     98   1.1        pk /* software state, per controller */
     99   1.1        pk struct fdc_softc {
    100  1.14        pk 	struct device	sc_dev;		/* boilerplate */
    101   1.1        pk 	struct intrhand sc_sih;
    102   1.1        pk 	struct intrhand sc_hih;
    103   1.1        pk 	caddr_t		sc_reg;
    104   1.1        pk 	struct fd_softc *sc_fd[4];	/* pointers to children */
    105   1.1        pk 	TAILQ_HEAD(drivehead, fd_softc) sc_drives;
    106   1.1        pk 	enum fdc_state	sc_state;
    107   1.2        pk 	int		sc_flags;
    108   1.2        pk #define FDC_82077		0x01
    109   1.2        pk #define FDC_NEEDHEADSETTLE	0x02
    110   1.2        pk #define FDC_EIS			0x04
    111   1.2        pk 	int		sc_errors;		/* number of retries so far */
    112   1.6        pk 	int		sc_overruns;		/* number of DMA overruns */
    113   1.2        pk 	int		sc_cfg;			/* current configuration */
    114   1.2        pk 	struct fdcio	sc_io;
    115   1.2        pk #define sc_reg_msr	sc_io.fdcio_reg_msr
    116   1.2        pk #define sc_reg_fifo	sc_io.fdcio_reg_fifo
    117   1.2        pk #define sc_reg_dor	sc_io.fdcio_reg_dor
    118   1.2        pk #define sc_reg_drs	sc_io.fdcio_reg_msr
    119   1.2        pk #define sc_istate	sc_io.fdcio_istate
    120   1.2        pk #define sc_data		sc_io.fdcio_data
    121   1.2        pk #define sc_tc		sc_io.fdcio_tc
    122   1.2        pk #define sc_nstat	sc_io.fdcio_nstat
    123   1.2        pk #define sc_status	sc_io.fdcio_status
    124   1.3        pk #define sc_intrcnt	sc_io.fdcio_intrcnt
    125   1.1        pk };
    126   1.1        pk 
    127   1.2        pk #ifndef FDC_C_HANDLER
    128   1.2        pk extern	struct fdcio	*fdciop;
    129   1.2        pk #endif
    130   1.2        pk 
    131   1.1        pk /* controller driver configuration */
    132   1.1        pk int	fdcmatch __P((struct device *, void *, void *));
    133   1.1        pk void	fdcattach __P((struct device *, struct device *, void *));
    134   1.1        pk 
    135  1.26   thorpej struct cfattach fdc_ca = {
    136  1.26   thorpej 	sizeof(struct fdc_softc), fdcmatch, fdcattach
    137  1.26   thorpej };
    138  1.24  christos 
    139  1.26   thorpej struct cfdriver fdc_cd = {
    140  1.26   thorpej 	NULL, "fdc", DV_DULL
    141   1.1        pk };
    142   1.1        pk 
    143  1.24  christos __inline struct fd_type *fd_dev_to_type __P((struct fd_softc *, dev_t));
    144  1.24  christos 
    145   1.1        pk /*
    146   1.1        pk  * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how
    147   1.1        pk  * we tell them apart.
    148   1.1        pk  */
    149   1.1        pk struct fd_type {
    150   1.1        pk 	int	sectrac;	/* sectors per track */
    151   1.1        pk 	int	heads;		/* number of heads */
    152   1.1        pk 	int	seccyl;		/* sectors per cylinder */
    153   1.1        pk 	int	secsize;	/* size code for sectors */
    154   1.1        pk 	int	datalen;	/* data len when secsize = 0 */
    155   1.1        pk 	int	steprate;	/* step rate and head unload time */
    156   1.1        pk 	int	gap1;		/* gap len between sectors */
    157   1.1        pk 	int	gap2;		/* formatting gap */
    158   1.1        pk 	int	tracks;		/* total num of tracks */
    159   1.1        pk 	int	size;		/* size of disk in sectors */
    160   1.1        pk 	int	step;		/* steps per cylinder */
    161   1.1        pk 	int	rate;		/* transfer speed code */
    162   1.1        pk 	char	*name;
    163   1.1        pk };
    164   1.1        pk 
    165   1.1        pk /* The order of entries in the following table is important -- BEWARE! */
    166   1.1        pk struct fd_type fd_types[] = {
    167   1.1        pk 	{ 18,2,36,2,0xff,0xcf,0x1b,0x6c,80,2880,1,FDC_500KBPS,"1.44MB"    }, /* 1.44MB diskette */
    168   1.1        pk 	{ 15,2,30,2,0xff,0xdf,0x1b,0x54,80,2400,1,FDC_500KBPS,"1.2MB"    }, /* 1.2 MB AT-diskettes */
    169   1.1        pk 	{  9,2,18,2,0xff,0xdf,0x23,0x50,40, 720,2,FDC_300KBPS,"360KB/AT" }, /* 360kB in 1.2MB drive */
    170   1.1        pk 	{  9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,1,FDC_250KBPS,"360KB/PC" }, /* 360kB PC diskettes */
    171   1.1        pk 	{  9,2,18,2,0xff,0xdf,0x2a,0x50,80,1440,1,FDC_250KBPS,"720KB"    }, /* 3.5" 720kB diskette */
    172   1.1        pk 	{  9,2,18,2,0xff,0xdf,0x23,0x50,80,1440,1,FDC_300KBPS,"720KB/x"  }, /* 720kB in 1.2MB drive */
    173   1.1        pk 	{  9,2,18,2,0xff,0xdf,0x2a,0x50,40, 720,2,FDC_250KBPS,"360KB/x"  }, /* 360kB in 720kB drive */
    174   1.1        pk };
    175   1.1        pk 
    176   1.1        pk /* software state, per disk (with up to 4 disks per ctlr) */
    177   1.1        pk struct fd_softc {
    178  1.16   thorpej 	struct device	sc_dv;		/* generic device info */
    179  1.16   thorpej 	struct disk	sc_dk;		/* generic disk info */
    180   1.1        pk 
    181   1.1        pk 	struct fd_type *sc_deftype;	/* default type descriptor */
    182   1.1        pk 	struct fd_type *sc_type;	/* current type descriptor */
    183   1.1        pk 
    184   1.1        pk 	daddr_t	sc_blkno;	/* starting block number */
    185   1.1        pk 	int sc_bcount;		/* byte count left */
    186   1.1        pk 	int sc_skip;		/* bytes already transferred */
    187   1.1        pk 	int sc_nblks;		/* number of blocks currently tranferring */
    188   1.1        pk 	int sc_nbytes;		/* number of bytes currently tranferring */
    189   1.1        pk 
    190   1.1        pk 	int sc_drive;		/* physical unit number */
    191   1.1        pk 	int sc_flags;
    192   1.1        pk #define	FD_OPEN		0x01		/* it's open */
    193   1.1        pk #define	FD_MOTOR	0x02		/* motor should be on */
    194   1.1        pk #define	FD_MOTOR_WAIT	0x04		/* motor coming up */
    195   1.1        pk 	int sc_cylin;		/* where we think the head is */
    196   1.1        pk 
    197  1.20   thorpej 	void	*sc_sdhook;	/* shutdownhook cookie */
    198  1.20   thorpej 
    199   1.1        pk 	TAILQ_ENTRY(fd_softc) sc_drivechain;
    200   1.1        pk 	int sc_ops;		/* I/O ops since last switch */
    201   1.1        pk 	struct buf sc_q;	/* head of buf chain */
    202   1.1        pk };
    203   1.1        pk 
    204   1.1        pk /* floppy driver configuration */
    205   1.1        pk int	fdmatch __P((struct device *, void *, void *));
    206   1.1        pk void	fdattach __P((struct device *, struct device *, void *));
    207   1.1        pk 
    208  1.26   thorpej struct cfattach fd_ca = {
    209  1.26   thorpej 	sizeof(struct fd_softc), fdmatch, fdattach
    210  1.26   thorpej };
    211  1.26   thorpej 
    212  1.26   thorpej struct cfdriver fd_cd = {
    213  1.26   thorpej 	NULL, "fd", DV_DISK
    214   1.1        pk };
    215   1.1        pk 
    216  1.19   thorpej void fdgetdisklabel __P((dev_t));
    217   1.1        pk int fd_get_parms __P((struct fd_softc *));
    218   1.1        pk void fdstrategy __P((struct buf *));
    219   1.1        pk void fdstart __P((struct fd_softc *));
    220  1.24  christos int fdprint __P((void *, char *));
    221   1.1        pk 
    222   1.1        pk struct dkdriver fddkdriver = { fdstrategy };
    223   1.1        pk 
    224   1.1        pk struct	fd_type *fd_nvtotype __P((char *, int, int));
    225  1.12        pk void	fd_set_motor __P((struct fdc_softc *fdc));
    226   1.1        pk void	fd_motor_off __P((void *arg));
    227   1.1        pk void	fd_motor_on __P((void *arg));
    228   1.1        pk int	fdcresult __P((struct fdc_softc *fdc));
    229   1.1        pk int	out_fdc __P((struct fdc_softc *fdc, u_char x));
    230   1.1        pk void	fdcstart __P((struct fdc_softc *fdc));
    231   1.1        pk void	fdcstatus __P((struct device *dv, int n, char *s));
    232  1.12        pk void	fdc_reset __P((struct fdc_softc *fdc));
    233   1.1        pk void	fdctimeout __P((void *arg));
    234   1.1        pk void	fdcpseudointr __P((void *arg));
    235   1.2        pk #ifdef FDC_C_HANDLER
    236   1.1        pk int	fdchwintr __P((struct fdc_softc *));
    237   1.2        pk #else
    238   1.2        pk void	fdchwintr __P((void));
    239   1.2        pk #endif
    240   1.1        pk int	fdcswintr __P((struct fdc_softc *));
    241   1.1        pk void	fdcretry __P((struct fdc_softc *fdc));
    242   1.1        pk void	fdfinish __P((struct fd_softc *fd, struct buf *bp));
    243  1.19   thorpej void	fd_do_eject __P((void));
    244  1.19   thorpej void	fd_mountroot_hook __P((struct device *));
    245  1.24  christos static void fdconf __P((struct fdc_softc *));
    246   1.1        pk 
    247   1.2        pk #if PIL_FDSOFT == 4
    248   1.1        pk #define IE_FDSOFT	IE_L4
    249   1.2        pk #else
    250   1.2        pk #error 4
    251   1.2        pk #endif
    252   1.1        pk 
    253  1.23        pk #define OBP_FDNAME	(CPU_ISSUN4M ? "SUNW,fdtwo" : "fd")
    254  1.10        pk 
    255   1.1        pk int
    256   1.1        pk fdcmatch(parent, match, aux)
    257   1.1        pk 	struct device *parent;
    258   1.1        pk 	void *match, *aux;
    259   1.1        pk {
    260   1.1        pk 	register struct confargs *ca = aux;
    261   1.1        pk 	register struct romaux *ra = &ca->ca_ra;
    262   1.1        pk 
    263  1.23        pk 	/*
    264  1.23        pk 	 * Floppy doesn't exist on sun4.
    265  1.23        pk 	 */
    266  1.23        pk 	if (CPU_ISSUN4)
    267  1.23        pk 		return (0);
    268  1.23        pk 
    269  1.23        pk 	/*
    270  1.23        pk 	 * Floppy controller is on mainbus on sun4c.
    271  1.23        pk 	 */
    272  1.23        pk 	if ((CPU_ISSUN4C) && (ca->ca_bustype != BUS_MAIN))
    273  1.23        pk 		return (0);
    274  1.23        pk 
    275  1.23        pk 	/*
    276  1.23        pk 	 * Floppy controller is on obio on sun4m.
    277  1.23        pk 	 */
    278  1.23        pk 	if ((CPU_ISSUN4M) && (ca->ca_bustype != BUS_OBIO))
    279  1.23        pk 		return (0);
    280  1.23        pk 
    281  1.10        pk 	/* Sun PROMs call the controller an "fd" or "SUNW,fdtwo" */
    282  1.10        pk 	if (strcmp(OBP_FDNAME, ra->ra_name))
    283   1.1        pk 		return (0);
    284  1.23        pk 
    285  1.23        pk 	if (ca->ca_ra.ra_vaddr &&
    286  1.23        pk 	    probeget(ca->ca_ra.ra_vaddr, 1) == -1) {
    287  1.23        pk 		return (0);
    288   1.5        pk 	}
    289   1.1        pk 
    290  1.23        pk 	return (1);
    291   1.1        pk }
    292   1.1        pk 
    293   1.1        pk /*
    294   1.1        pk  * Arguments passed between fdcattach and fdprobe.
    295   1.1        pk  */
    296   1.1        pk struct fdc_attach_args {
    297   1.1        pk 	int fa_drive;
    298  1.31        pk 	struct bootpath *fa_bootpath;
    299   1.1        pk 	struct fd_type *fa_deftype;
    300   1.1        pk };
    301   1.1        pk 
    302   1.1        pk /*
    303   1.1        pk  * Print the location of a disk drive (called just before attaching the
    304   1.1        pk  * the drive).  If `fdc' is not NULL, the drive was found but was not
    305   1.1        pk  * in the system config file; print the drive name as well.
    306   1.1        pk  * Return QUIET (config_find ignores this if the device was configured) to
    307   1.1        pk  * avoid printing `fdN not configured' messages.
    308   1.1        pk  */
    309   1.1        pk int
    310   1.1        pk fdprint(aux, fdc)
    311   1.1        pk 	void *aux;
    312   1.1        pk 	char *fdc;
    313   1.1        pk {
    314   1.1        pk 	register struct fdc_attach_args *fa = aux;
    315   1.1        pk 
    316   1.1        pk 	if (!fdc)
    317   1.1        pk 		printf(" drive %d", fa->fa_drive);
    318   1.1        pk 	return QUIET;
    319   1.1        pk }
    320   1.1        pk 
    321   1.1        pk static void
    322   1.1        pk fdconf(fdc)
    323   1.1        pk 	struct fdc_softc *fdc;
    324   1.1        pk {
    325   1.1        pk 	int	vroom;
    326   1.1        pk 
    327   1.1        pk 	if (out_fdc(fdc, NE7CMD_DUMPREG) || fdcresult(fdc) != 10)
    328   1.1        pk 		return;
    329   1.1        pk 
    330   1.1        pk 	/*
    331   1.1        pk 	 * dumpreg[7] seems to be a motor-off timeout; set it to whatever
    332   1.1        pk 	 * the PROM thinks is appropriate.
    333   1.1        pk 	 */
    334   1.1        pk 	if ((vroom = fdc->sc_status[7]) == 0)
    335   1.1        pk 		vroom = 0x64;
    336   1.1        pk 
    337   1.1        pk 	/* Configure controller to use FIFO and Implied Seek */
    338   1.1        pk 	out_fdc(fdc, NE7CMD_CFG);
    339   1.1        pk 	out_fdc(fdc, vroom);
    340   1.2        pk 	out_fdc(fdc, fdc->sc_cfg);
    341   1.1        pk 	out_fdc(fdc, 0); /* PRETRK */
    342   1.1        pk 	/* No result phase */
    343   1.1        pk }
    344   1.1        pk 
    345   1.1        pk void
    346   1.1        pk fdcattach(parent, self, aux)
    347   1.1        pk 	struct device *parent, *self;
    348   1.1        pk 	void *aux;
    349   1.1        pk {
    350   1.1        pk 	register struct confargs *ca = aux;
    351   1.1        pk 	struct fdc_softc *fdc = (void *)self;
    352   1.1        pk 	struct fdc_attach_args fa;
    353  1.23        pk 	struct bootpath *bp;
    354  1.24  christos 	int pri;
    355   1.8        pk 	char code;
    356   1.1        pk 
    357   1.1        pk 	if (ca->ca_ra.ra_vaddr)
    358   1.1        pk 		fdc->sc_reg = (caddr_t)ca->ca_ra.ra_vaddr;
    359   1.1        pk 	else
    360  1.15        pk 		fdc->sc_reg = (caddr_t)mapiodev(ca->ca_ra.ra_reg, 0,
    361   1.1        pk 						ca->ca_ra.ra_len,
    362   1.1        pk 						ca->ca_bustype);
    363   1.1        pk 
    364   1.2        pk 	fdc->sc_state = DEVIDLE;
    365   1.2        pk 	fdc->sc_istate = ISTATE_IDLE;
    366   1.2        pk 	fdc->sc_flags |= FDC_EIS;
    367   1.2        pk 	TAILQ_INIT(&fdc->sc_drives);
    368   1.2        pk 
    369   1.1        pk 	pri = ca->ca_ra.ra_intr[0].int_pri;
    370   1.2        pk #ifdef FDC_C_HANDLER
    371   1.1        pk 	fdc->sc_hih.ih_fun = (void *)fdchwintr;
    372   1.1        pk 	fdc->sc_hih.ih_arg = fdc;
    373   1.1        pk 	intr_establish(pri, &fdc->sc_hih);
    374   1.2        pk #else
    375   1.2        pk 	fdciop = &fdc->sc_io;
    376   1.2        pk 	intr_fasttrap(pri, fdchwintr);
    377   1.2        pk #endif
    378   1.1        pk 	fdc->sc_sih.ih_fun = (void *)fdcswintr;
    379   1.1        pk 	fdc->sc_sih.ih_arg = fdc;
    380   1.2        pk 	intr_establish(PIL_FDSOFT, &fdc->sc_sih);
    381   1.1        pk 
    382   1.8        pk 	/* Assume a 82077 */
    383   1.8        pk 	fdc->sc_reg_msr = &((struct fdreg_77 *)fdc->sc_reg)->fd_msr;
    384   1.8        pk 	fdc->sc_reg_fifo = &((struct fdreg_77 *)fdc->sc_reg)->fd_fifo;
    385   1.8        pk 	fdc->sc_reg_dor = &((struct fdreg_77 *)fdc->sc_reg)->fd_dor;
    386   1.8        pk 
    387   1.8        pk 	code = '7';
    388   1.8        pk 	if (*fdc->sc_reg_dor == NE7_RQM) {
    389   1.8        pk 		/*
    390   1.8        pk 		 * This hack from Chris Torek: apparently DOR really
    391   1.8        pk 		 * addresses MSR/DRS on a 82072.
    392   1.8        pk 		 * We used to rely on the VERSION command to tell the
    393   1.8        pk 		 * difference (which did not work).
    394   1.8        pk 		 */
    395   1.8        pk 		*fdc->sc_reg_dor = FDC_250KBPS;
    396   1.8        pk 		if (*fdc->sc_reg_dor == NE7_RQM)
    397   1.8        pk 			code = '2';
    398   1.5        pk 	}
    399   1.8        pk 	if (code == '7') {
    400   1.1        pk 		fdc->sc_flags |= FDC_82077;
    401   1.1        pk 	} else {
    402   1.8        pk 		fdc->sc_reg_msr = &((struct fdreg_72 *)fdc->sc_reg)->fd_msr;
    403   1.8        pk 		fdc->sc_reg_fifo = &((struct fdreg_72 *)fdc->sc_reg)->fd_fifo;
    404   1.8        pk 		fdc->sc_reg_dor = 0;
    405   1.1        pk 	}
    406   1.1        pk 
    407   1.8        pk #ifdef FD_DEBUG
    408   1.8        pk 	if (out_fdc(fdc, NE7CMD_VERSION) == 0 &&
    409   1.8        pk 	    fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x90) {
    410   1.8        pk 		if (fdc_debug)
    411   1.8        pk 			printf("[version cmd]");
    412   1.8        pk 	}
    413   1.8        pk #endif
    414   1.8        pk 
    415   1.2        pk 	/*
    416   1.2        pk 	 * Configure controller; enable FIFO, Implied seek, no POLL mode?.
    417   1.6        pk 	 * Note: CFG_EFIFO is active-low, initial threshold value: 8
    418   1.2        pk 	 */
    419   1.6        pk 	fdc->sc_cfg = CFG_EIS|/*CFG_EFIFO|*/CFG_POLL|(8 & CFG_THRHLD_MASK);
    420   1.1        pk 	fdconf(fdc);
    421   1.1        pk 
    422   1.1        pk 	if (fdc->sc_flags & FDC_82077) {
    423   1.1        pk 		/* Lock configuration across soft resets. */
    424   1.1        pk 		out_fdc(fdc, NE7CMD_LOCK | CFG_LOCK);
    425   1.1        pk 		if (fdcresult(fdc) != 1)
    426   1.1        pk 			printf(" CFGLOCK: unexpected response");
    427   1.1        pk 	}
    428   1.3        pk 
    429  1.14        pk 	evcnt_attach(&fdc->sc_dev, "intr", &fdc->sc_intrcnt);
    430   1.1        pk 
    431   1.8        pk 	printf(" pri %d, softpri %d: chip 8207%c\n", pri, PIL_FDSOFT, code);
    432   1.1        pk 
    433  1.10        pk 	/*
    434  1.10        pk 	 * Controller and drives are represented by one and the same
    435  1.10        pk 	 * Openprom node, so we can as well check for the floppy boots here.
    436  1.10        pk 	 */
    437  1.31        pk 	fa.fa_bootpath = 0;
    438  1.23        pk 	if ((bp = ca->ca_ra.ra_bp) && strcmp(bp->name, OBP_FDNAME) == 0) {
    439  1.35        pk 
    440  1.23        pk 		switch (ca->ca_bustype) {
    441  1.23        pk 		case BUS_MAIN:
    442  1.35        pk 			/*
    443  1.35        pk 			 * We can get the bootpath in several different
    444  1.35        pk 			 * formats! The faked v1 bootpath looks like /fd@0,0.
    445  1.35        pk 			 * The v2 bootpath is either just /fd0, in which case
    446  1.35        pk 			 * `bp->val[0]' will have been set to -1, or /fd@x,y
    447  1.35        pk 			 * where <x,y> is the prom address specifier.
    448  1.35        pk 			 */
    449  1.35        pk 			if (((bp->val[0] == ca->ca_ra.ra_iospace) &&
    450  1.35        pk 			     (bp->val[1] == (int)ca->ca_ra.ra_paddr)) ||
    451  1.35        pk 
    452  1.35        pk 			    ((bp->val[0] == -1) &&	/* v2: /fd0 */
    453  1.23        pk 			     (bp->val[1] == 0)) ||
    454  1.35        pk 
    455  1.35        pk 			    ((bp->val[0] == 0) &&	/* v1: /fd@0,0 */
    456  1.35        pk 			     (bp->val[1] == 0))
    457  1.35        pk 			   )
    458  1.31        pk 				fa.fa_bootpath = bp;
    459  1.23        pk 			break;
    460  1.23        pk 
    461  1.23        pk 		case BUS_OBIO:
    462  1.35        pk 			/*
    463  1.35        pk 			 * floppy controller on obio (such as on the sun4m),
    464  1.35        pk 			 * e.g.: `/obio0/SUNW,fdtwo@0,700000'.
    465  1.35        pk 			 * We use "slot, offset" to determine if this is the
    466  1.35        pk 			 * right one.
    467  1.35        pk 			 */
    468  1.23        pk 			if ((bp->val[0] == ca->ca_slot) &&
    469  1.23        pk 			    (bp->val[1] == ca->ca_offset))
    470  1.31        pk 				fa.fa_bootpath = bp;
    471  1.23        pk 			break;
    472  1.23        pk 		}
    473  1.29        pk 
    474  1.19   thorpej 	}
    475  1.10        pk 
    476   1.1        pk 	/* physical limit: four drives per controller. */
    477   1.1        pk 	for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
    478   1.1        pk 		fa.fa_deftype = NULL;		/* unknown */
    479   1.1        pk 	fa.fa_deftype = &fd_types[0];		/* XXX */
    480   1.1        pk 		(void)config_found(self, (void *)&fa, fdprint);
    481   1.1        pk 	}
    482  1.16   thorpej 
    483  1.16   thorpej 	bootpath_store(1, NULL);
    484   1.1        pk }
    485   1.1        pk 
    486   1.1        pk int
    487   1.1        pk fdmatch(parent, match, aux)
    488   1.1        pk 	struct device *parent;
    489   1.1        pk 	void *match, *aux;
    490   1.1        pk {
    491   1.1        pk 	struct fdc_softc *fdc = (void *)parent;
    492   1.1        pk 	struct fdc_attach_args *fa = aux;
    493   1.1        pk 	int drive = fa->fa_drive;
    494  1.33        pk 	int n, ok;
    495   1.1        pk 
    496   1.8        pk 	if (drive > 0)
    497   1.8        pk 		/* XXX - for now, punt > 1 drives */
    498   1.8        pk 		return 0;
    499   1.8        pk 
    500   1.1        pk 	if (fdc->sc_flags & FDC_82077) {
    501   1.1        pk 		/* select drive and turn on motor */
    502   1.1        pk 		*fdc->sc_reg_dor = drive | FDO_FRST | FDO_MOEN(drive);
    503   1.1        pk 		/* wait for motor to spin up */
    504   1.1        pk 		delay(250000);
    505   1.1        pk 	} else {
    506   1.1        pk 		auxregbisc(AUXIO_FDS, 0);
    507   1.1        pk 	}
    508   1.1        pk 	fdc->sc_nstat = 0;
    509   1.1        pk 	out_fdc(fdc, NE7CMD_RECAL);
    510   1.1        pk 	out_fdc(fdc, drive);
    511   1.1        pk 	/* wait for recalibrate */
    512  1.33        pk 	for (n = 0; n < 10000; n++) {
    513  1.33        pk 		delay(1000);
    514   1.2        pk 		if ((*fdc->sc_reg_msr & (NE7_RQM|NE7_DIO|NE7_CB)) == NE7_RQM) {
    515   1.2        pk 			/* wait a bit longer till device *really* is ready */
    516   1.2        pk 			delay(100000);
    517   1.2        pk 			if (out_fdc(fdc, NE7CMD_SENSEI))
    518   1.2        pk 				break;
    519   1.7        pk 			if (fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x80)
    520   1.2        pk 				/*
    521   1.2        pk 				 * Got `invalid command'; we interpret it
    522   1.2        pk 				 * to mean that the re-calibrate hasn't in
    523   1.2        pk 				 * fact finished yet
    524   1.2        pk 				 */
    525   1.2        pk 				continue;
    526   1.1        pk 			break;
    527   1.1        pk 		}
    528   1.1        pk 	}
    529   1.1        pk 	n = fdc->sc_nstat;
    530   1.1        pk #ifdef FD_DEBUG
    531   1.2        pk 	if (fdc_debug) {
    532   1.1        pk 		int i;
    533   1.2        pk 		printf("fdprobe: %d stati:", n);
    534   1.1        pk 		for (i = 0; i < n; i++)
    535   1.1        pk 			printf(" %x", fdc->sc_status[i]);
    536   1.1        pk 		printf("\n");
    537   1.1        pk 	}
    538   1.1        pk #endif
    539  1.33        pk 	ok = (n == 2 && (fdc->sc_status[0] & 0xf8) == 0x20) ? 1 : 0;
    540  1.33        pk 
    541   1.1        pk 	/* turn off motor */
    542   1.1        pk 	if (fdc->sc_flags & FDC_82077) {
    543   1.1        pk 		/* select drive and turn on motor */
    544   1.1        pk 		*fdc->sc_reg_dor = FDO_FRST;
    545   1.1        pk 	} else {
    546   1.1        pk 		auxregbisc(0, AUXIO_FDS);
    547   1.1        pk 	}
    548   1.1        pk 
    549  1.33        pk 	return ok;
    550   1.1        pk }
    551   1.1        pk 
    552   1.1        pk /*
    553   1.1        pk  * Controller is working, and drive responded.  Attach it.
    554   1.1        pk  */
    555   1.1        pk void
    556   1.1        pk fdattach(parent, self, aux)
    557   1.1        pk 	struct device *parent, *self;
    558   1.1        pk 	void *aux;
    559   1.1        pk {
    560   1.1        pk 	struct fdc_softc *fdc = (void *)parent;
    561   1.1        pk 	struct fd_softc *fd = (void *)self;
    562   1.1        pk 	struct fdc_attach_args *fa = aux;
    563   1.1        pk 	struct fd_type *type = fa->fa_deftype;
    564   1.1        pk 	int drive = fa->fa_drive;
    565   1.1        pk 
    566   1.1        pk 	/* XXX Allow `flags' to override device type? */
    567   1.1        pk 
    568   1.1        pk 	if (type)
    569   1.1        pk 		printf(": %s %d cyl, %d head, %d sec\n", type->name,
    570   1.1        pk 		    type->tracks, type->heads, type->sectrac);
    571   1.1        pk 	else
    572   1.1        pk 		printf(": density unknown\n");
    573   1.1        pk 
    574   1.1        pk 	fd->sc_cylin = -1;
    575   1.1        pk 	fd->sc_drive = drive;
    576   1.1        pk 	fd->sc_deftype = type;
    577   1.1        pk 	fdc->sc_fd[drive] = fd;
    578  1.16   thorpej 
    579  1.16   thorpej 	/*
    580  1.16   thorpej 	 * Initialize and attach the disk structure.
    581  1.16   thorpej 	 */
    582  1.16   thorpej 	fd->sc_dk.dk_name = fd->sc_dv.dv_xname;
    583   1.1        pk 	fd->sc_dk.dk_driver = &fddkdriver;
    584  1.16   thorpej 	disk_attach(&fd->sc_dk);
    585  1.10        pk 
    586  1.13        pk 	/*
    587  1.13        pk 	 * We're told if we're the boot device in fdcattach().
    588  1.13        pk 	 */
    589  1.31        pk 	if (fa->fa_bootpath)
    590  1.31        pk 		fa->fa_bootpath->dev = &fd->sc_dv;
    591  1.13        pk 
    592  1.19   thorpej 	/*
    593  1.19   thorpej 	 * Establish a mountroot_hook anyway in case we booted
    594  1.19   thorpej 	 * with RB_ASKNAME and get selected as the boot device.
    595  1.19   thorpej 	 */
    596  1.19   thorpej 	mountroot_hook_establish(fd_mountroot_hook, &fd->sc_dv);
    597  1.20   thorpej 
    598  1.20   thorpej 	/* Make sure the drive motor gets turned off at shutdown time. */
    599  1.20   thorpej 	fd->sc_sdhook = shutdownhook_establish(fd_motor_off, fd);
    600  1.19   thorpej 
    601   1.1        pk 	/* XXX Need to do some more fiddling with sc_dk. */
    602  1.16   thorpej 	dk_establish(&fd->sc_dk, &fd->sc_dv);
    603   1.1        pk }
    604   1.1        pk 
    605  1.24  christos __inline struct fd_type *
    606   1.1        pk fd_dev_to_type(fd, dev)
    607   1.1        pk 	struct fd_softc *fd;
    608   1.1        pk 	dev_t dev;
    609   1.1        pk {
    610   1.1        pk 	int type = FDTYPE(dev);
    611   1.1        pk 
    612   1.1        pk 	if (type > (sizeof(fd_types) / sizeof(fd_types[0])))
    613   1.1        pk 		return NULL;
    614   1.1        pk 	return type ? &fd_types[type - 1] : fd->sc_deftype;
    615   1.1        pk }
    616   1.1        pk 
    617   1.1        pk void
    618   1.1        pk fdstrategy(bp)
    619   1.1        pk 	register struct buf *bp;	/* IO operation to perform */
    620   1.1        pk {
    621   1.1        pk 	struct fd_softc *fd;
    622   1.1        pk 	int unit = FDUNIT(bp->b_dev);
    623   1.1        pk 	int sz;
    624   1.1        pk  	int s;
    625   1.1        pk 
    626   1.1        pk 	/* Valid unit, controller, and request? */
    627  1.26   thorpej 	if (unit >= fd_cd.cd_ndevs ||
    628  1.26   thorpej 	    (fd = fd_cd.cd_devs[unit]) == 0 ||
    629   1.1        pk 	    bp->b_blkno < 0 ||
    630   1.1        pk 	    (bp->b_bcount % FDC_BSIZE) != 0) {
    631   1.1        pk 		bp->b_error = EINVAL;
    632   1.1        pk 		goto bad;
    633   1.1        pk 	}
    634   1.1        pk 
    635   1.1        pk 	/* If it's a null transfer, return immediately. */
    636   1.1        pk 	if (bp->b_bcount == 0)
    637   1.1        pk 		goto done;
    638   1.1        pk 
    639   1.1        pk 	sz = howmany(bp->b_bcount, FDC_BSIZE);
    640   1.1        pk 
    641   1.1        pk 	if (bp->b_blkno + sz > fd->sc_type->size) {
    642   1.1        pk 		sz = fd->sc_type->size - bp->b_blkno;
    643   1.1        pk 		if (sz == 0) {
    644   1.1        pk 			/* If exactly at end of disk, return EOF. */
    645   1.1        pk 			bp->b_resid = bp->b_bcount;
    646   1.1        pk 			goto done;
    647   1.1        pk 		}
    648   1.1        pk 		if (sz < 0) {
    649   1.1        pk 			/* If past end of disk, return EINVAL. */
    650   1.1        pk 			bp->b_error = EINVAL;
    651   1.1        pk 			goto bad;
    652   1.1        pk 		}
    653   1.1        pk 		/* Otherwise, truncate request. */
    654   1.1        pk 		bp->b_bcount = sz << DEV_BSHIFT;
    655   1.1        pk 	}
    656   1.1        pk 
    657   1.1        pk  	bp->b_cylin = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE) / fd->sc_type->seccyl;
    658   1.1        pk 
    659   1.1        pk #ifdef FD_DEBUG
    660   1.2        pk 	if (fdc_debug > 1)
    661  1.29        pk 	    printf("fdstrategy: b_blkno %d b_bcount %ld blkno %d cylin %ld\n",
    662   1.2        pk 		    bp->b_blkno, bp->b_bcount, fd->sc_blkno, bp->b_cylin);
    663   1.1        pk #endif
    664   1.1        pk 
    665   1.1        pk 	/* Queue transfer on drive, activate drive and controller if idle. */
    666   1.1        pk 	s = splbio();
    667   1.1        pk 	disksort(&fd->sc_q, bp);
    668   1.1        pk 	untimeout(fd_motor_off, fd); /* a good idea */
    669   1.1        pk 	if (!fd->sc_q.b_active)
    670   1.1        pk 		fdstart(fd);
    671   1.1        pk #ifdef DIAGNOSTIC
    672   1.1        pk 	else {
    673  1.16   thorpej 		struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
    674   1.1        pk 		if (fdc->sc_state == DEVIDLE) {
    675   1.1        pk 			printf("fdstrategy: controller inactive\n");
    676   1.1        pk 			fdcstart(fdc);
    677   1.1        pk 		}
    678   1.1        pk 	}
    679   1.1        pk #endif
    680   1.1        pk 	splx(s);
    681   1.1        pk 	return;
    682   1.1        pk 
    683   1.1        pk bad:
    684   1.1        pk 	bp->b_flags |= B_ERROR;
    685   1.1        pk done:
    686   1.1        pk 	/* Toss transfer; we're done early. */
    687   1.1        pk 	biodone(bp);
    688   1.1        pk }
    689   1.1        pk 
    690   1.1        pk void
    691   1.1        pk fdstart(fd)
    692   1.1        pk 	struct fd_softc *fd;
    693   1.1        pk {
    694  1.16   thorpej 	struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
    695   1.1        pk 	int active = fdc->sc_drives.tqh_first != 0;
    696   1.1        pk 
    697   1.1        pk 	/* Link into controller queue. */
    698   1.1        pk 	fd->sc_q.b_active = 1;
    699   1.1        pk 	TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
    700   1.1        pk 
    701   1.1        pk 	/* If controller not already active, start it. */
    702   1.1        pk 	if (!active)
    703   1.1        pk 		fdcstart(fdc);
    704   1.1        pk }
    705   1.1        pk 
    706   1.1        pk void
    707   1.1        pk fdfinish(fd, bp)
    708   1.1        pk 	struct fd_softc *fd;
    709   1.1        pk 	struct buf *bp;
    710   1.1        pk {
    711  1.16   thorpej 	struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
    712   1.1        pk 
    713   1.1        pk 	/*
    714   1.1        pk 	 * Move this drive to the end of the queue to give others a `fair'
    715   1.1        pk 	 * chance.  We only force a switch if N operations are completed while
    716   1.1        pk 	 * another drive is waiting to be serviced, since there is a long motor
    717   1.1        pk 	 * startup delay whenever we switch.
    718   1.1        pk 	 */
    719   1.1        pk 	if (fd->sc_drivechain.tqe_next && ++fd->sc_ops >= 8) {
    720   1.1        pk 		fd->sc_ops = 0;
    721   1.1        pk 		TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
    722   1.1        pk 		if (bp->b_actf) {
    723   1.1        pk 			TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
    724   1.1        pk 		} else
    725   1.1        pk 			fd->sc_q.b_active = 0;
    726   1.1        pk 	}
    727   1.1        pk 	bp->b_resid = fd->sc_bcount;
    728   1.1        pk 	fd->sc_skip = 0;
    729   1.1        pk 	fd->sc_q.b_actf = bp->b_actf;
    730  1.16   thorpej 
    731   1.1        pk 	biodone(bp);
    732   1.1        pk 	/* turn off motor 5s from now */
    733   1.1        pk 	timeout(fd_motor_off, fd, 5 * hz);
    734   1.1        pk 	fdc->sc_state = DEVIDLE;
    735   1.1        pk }
    736   1.1        pk 
    737   1.1        pk void
    738  1.12        pk fdc_reset(fdc)
    739  1.12        pk 	struct fdc_softc *fdc;
    740  1.12        pk {
    741  1.12        pk 	if (fdc->sc_flags & FDC_82077) {
    742  1.12        pk 		*fdc->sc_reg_dor = FDO_MOEN(0);
    743  1.12        pk 	}
    744  1.12        pk 
    745  1.12        pk 	*fdc->sc_reg_drs = DRS_RESET;
    746  1.12        pk 	delay(10);
    747  1.12        pk 	*fdc->sc_reg_drs = 0;
    748  1.12        pk #ifdef FD_DEBUG
    749  1.12        pk 	if (fdc_debug)
    750  1.12        pk 		printf("fdc reset\n");
    751  1.12        pk #endif
    752  1.12        pk }
    753  1.12        pk 
    754  1.12        pk void
    755  1.12        pk fd_set_motor(fdc)
    756   1.1        pk 	struct fdc_softc *fdc;
    757   1.1        pk {
    758   1.1        pk 	struct fd_softc *fd;
    759   1.1        pk 	u_char status;
    760   1.1        pk 	int n;
    761   1.1        pk 
    762   1.1        pk 	if (fdc->sc_flags & FDC_82077) {
    763  1.12        pk 		status = FDO_FRST | FDO_FDMAEN;
    764  1.24  christos 		if ((fd = fdc->sc_drives.tqh_first) != NULL)
    765  1.12        pk 			status |= fd->sc_drive;
    766  1.12        pk 
    767   1.1        pk 		for (n = 0; n < 4; n++)
    768   1.1        pk 			if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
    769   1.1        pk 				status |= FDO_MOEN(n);
    770   1.1        pk 		*fdc->sc_reg_dor = status;
    771   1.1        pk 	} else {
    772   1.1        pk 		int on = 0;
    773   1.1        pk 
    774   1.1        pk 		for (n = 0; n < 4; n++)
    775   1.1        pk 			if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
    776   1.1        pk 				on = 1;
    777   1.1        pk 		if (on) {
    778   1.1        pk 			auxregbisc(AUXIO_FDS, 0);
    779   1.1        pk 		} else {
    780   1.1        pk 			auxregbisc(0, AUXIO_FDS);
    781   1.1        pk 		}
    782   1.1        pk 	}
    783   1.1        pk }
    784   1.1        pk 
    785   1.1        pk void
    786   1.1        pk fd_motor_off(arg)
    787   1.1        pk 	void *arg;
    788   1.1        pk {
    789   1.1        pk 	struct fd_softc *fd = arg;
    790   1.1        pk 	int s;
    791   1.1        pk 
    792   1.1        pk 	s = splbio();
    793   1.1        pk 	fd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
    794  1.16   thorpej 	fd_set_motor((struct fdc_softc *)fd->sc_dv.dv_parent);
    795   1.1        pk 	splx(s);
    796   1.1        pk }
    797   1.1        pk 
    798   1.1        pk void
    799   1.1        pk fd_motor_on(arg)
    800   1.1        pk 	void *arg;
    801   1.1        pk {
    802   1.1        pk 	struct fd_softc *fd = arg;
    803  1.16   thorpej 	struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent;
    804   1.1        pk 	int s;
    805   1.1        pk 
    806   1.1        pk 	s = splbio();
    807   1.1        pk 	fd->sc_flags &= ~FD_MOTOR_WAIT;
    808   1.1        pk 	if ((fdc->sc_drives.tqh_first == fd) && (fdc->sc_state == MOTORWAIT))
    809   1.1        pk 		(void) fdcswintr(fdc);
    810   1.1        pk 	splx(s);
    811   1.1        pk }
    812   1.1        pk 
    813   1.1        pk int
    814   1.1        pk fdcresult(fdc)
    815   1.1        pk 	struct fdc_softc *fdc;
    816   1.1        pk {
    817   1.1        pk 	u_char i;
    818   1.1        pk 	int j = 100000,
    819   1.1        pk 	    n = 0;
    820   1.1        pk 
    821   1.1        pk 	for (; j; j--) {
    822   1.1        pk 		i = *fdc->sc_reg_msr & (NE7_DIO | NE7_RQM | NE7_CB);
    823   1.1        pk 		if (i == NE7_RQM)
    824   1.1        pk 			return (fdc->sc_nstat = n);
    825   1.1        pk 		if (i == (NE7_DIO | NE7_RQM | NE7_CB)) {
    826   1.1        pk 			if (n >= sizeof(fdc->sc_status)) {
    827   1.1        pk 				log(LOG_ERR, "fdcresult: overrun\n");
    828   1.1        pk 				return -1;
    829   1.1        pk 			}
    830   1.2        pk 			fdc->sc_status[n++] = *fdc->sc_reg_fifo;
    831   1.1        pk 		}
    832   1.1        pk 	}
    833   1.1        pk 	log(LOG_ERR, "fdcresult: timeout\n");
    834   1.1        pk 	return (fdc->sc_nstat = -1);
    835   1.1        pk }
    836   1.1        pk 
    837   1.1        pk int
    838   1.1        pk out_fdc(fdc, x)
    839   1.1        pk 	struct fdc_softc *fdc;
    840   1.1        pk 	u_char x;
    841   1.1        pk {
    842   1.1        pk 	int i = 100000;
    843   1.1        pk 
    844   1.2        pk 	while (((*fdc->sc_reg_msr & (NE7_DIO|NE7_RQM)) != NE7_RQM) && i-- > 0);
    845   1.1        pk 	if (i <= 0)
    846   1.1        pk 		return -1;
    847   1.1        pk 
    848   1.2        pk 	*fdc->sc_reg_fifo = x;
    849   1.1        pk 	return 0;
    850   1.1        pk }
    851   1.1        pk 
    852   1.1        pk int
    853  1.24  christos fdopen(dev, flags, fmt, p)
    854   1.1        pk 	dev_t dev;
    855  1.19   thorpej 	int flags, fmt;
    856  1.19   thorpej 	struct proc *p;
    857   1.1        pk {
    858  1.19   thorpej  	int unit, pmask;
    859   1.1        pk 	struct fd_softc *fd;
    860   1.1        pk 	struct fd_type *type;
    861   1.1        pk 
    862   1.1        pk 	unit = FDUNIT(dev);
    863  1.26   thorpej 	if (unit >= fd_cd.cd_ndevs)
    864   1.1        pk 		return ENXIO;
    865  1.26   thorpej 	fd = fd_cd.cd_devs[unit];
    866   1.1        pk 	if (fd == 0)
    867   1.1        pk 		return ENXIO;
    868   1.1        pk 	type = fd_dev_to_type(fd, dev);
    869   1.1        pk 	if (type == NULL)
    870   1.1        pk 		return ENXIO;
    871   1.1        pk 
    872   1.1        pk 	if ((fd->sc_flags & FD_OPEN) != 0 &&
    873   1.1        pk 	    fd->sc_type != type)
    874   1.1        pk 		return EBUSY;
    875   1.1        pk 
    876   1.1        pk 	fd->sc_type = type;
    877   1.1        pk 	fd->sc_cylin = -1;
    878   1.1        pk 	fd->sc_flags |= FD_OPEN;
    879   1.1        pk 
    880  1.19   thorpej 	/*
    881  1.19   thorpej 	 * Only update the disklabel if we're not open anywhere else.
    882  1.19   thorpej 	 */
    883  1.19   thorpej 	if (fd->sc_dk.dk_openmask == 0)
    884  1.19   thorpej 		fdgetdisklabel(dev);
    885  1.19   thorpej 
    886  1.19   thorpej 	pmask = (1 << DISKPART(dev));
    887  1.19   thorpej 
    888  1.19   thorpej 	switch (fmt) {
    889  1.19   thorpej 	case S_IFCHR:
    890  1.19   thorpej 		fd->sc_dk.dk_copenmask |= pmask;
    891  1.19   thorpej 		break;
    892  1.19   thorpej 
    893  1.19   thorpej 	case S_IFBLK:
    894  1.19   thorpej 		fd->sc_dk.dk_bopenmask |= pmask;
    895  1.19   thorpej 		break;
    896  1.19   thorpej 	}
    897  1.19   thorpej 	fd->sc_dk.dk_openmask =
    898  1.19   thorpej 	    fd->sc_dk.dk_copenmask | fd->sc_dk.dk_bopenmask;
    899  1.19   thorpej 
    900   1.1        pk 	return 0;
    901   1.1        pk }
    902   1.1        pk 
    903   1.1        pk int
    904  1.19   thorpej fdclose(dev, flags, fmt, p)
    905   1.1        pk 	dev_t dev;
    906  1.19   thorpej 	int flags, fmt;
    907  1.19   thorpej 	struct proc *p;
    908   1.1        pk {
    909  1.26   thorpej 	struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
    910  1.19   thorpej 	int pmask = (1 << DISKPART(dev));
    911   1.1        pk 
    912   1.1        pk 	fd->sc_flags &= ~FD_OPEN;
    913  1.19   thorpej 
    914  1.19   thorpej 	switch (fmt) {
    915  1.19   thorpej 	case S_IFCHR:
    916  1.19   thorpej 		fd->sc_dk.dk_copenmask &= ~pmask;
    917  1.19   thorpej 		break;
    918  1.19   thorpej 
    919  1.19   thorpej 	case S_IFBLK:
    920  1.19   thorpej 		fd->sc_dk.dk_bopenmask &= ~pmask;
    921  1.19   thorpej 		break;
    922  1.19   thorpej 	}
    923  1.29        pk 	fd->sc_dk.dk_openmask =
    924  1.19   thorpej 	    fd->sc_dk.dk_copenmask | fd->sc_dk.dk_bopenmask;
    925  1.19   thorpej 
    926   1.1        pk 	return 0;
    927   1.9        pk }
    928   1.9        pk 
    929   1.9        pk int
    930  1.24  christos fdread(dev, uio, flag)
    931   1.9        pk         dev_t dev;
    932   1.9        pk         struct uio *uio;
    933  1.24  christos 	int flag;
    934   1.9        pk {
    935   1.9        pk 
    936   1.9        pk         return (physio(fdstrategy, NULL, dev, B_READ, minphys, uio));
    937   1.9        pk }
    938   1.9        pk 
    939   1.9        pk int
    940  1.24  christos fdwrite(dev, uio, flag)
    941   1.9        pk         dev_t dev;
    942   1.9        pk         struct uio *uio;
    943  1.24  christos 	int flag;
    944   1.9        pk {
    945   1.9        pk 
    946   1.9        pk         return (physio(fdstrategy, NULL, dev, B_WRITE, minphys, uio));
    947   1.1        pk }
    948   1.1        pk 
    949   1.1        pk void
    950   1.1        pk fdcstart(fdc)
    951   1.1        pk 	struct fdc_softc *fdc;
    952   1.1        pk {
    953   1.1        pk 
    954   1.1        pk #ifdef DIAGNOSTIC
    955   1.1        pk 	/* only got here if controller's drive queue was inactive; should
    956   1.1        pk 	   be in idle state */
    957   1.1        pk 	if (fdc->sc_state != DEVIDLE) {
    958   1.1        pk 		printf("fdcstart: not idle\n");
    959   1.1        pk 		return;
    960   1.1        pk 	}
    961   1.1        pk #endif
    962   1.1        pk 	(void) fdcswintr(fdc);
    963   1.1        pk }
    964   1.1        pk 
    965   1.1        pk void
    966   1.1        pk fdcstatus(dv, n, s)
    967   1.1        pk 	struct device *dv;
    968   1.1        pk 	int n;
    969   1.1        pk 	char *s;
    970   1.1        pk {
    971   1.1        pk 	struct fdc_softc *fdc = (void *)dv->dv_parent;
    972   1.1        pk #if 0
    973   1.1        pk 	/*
    974   1.1        pk 	 * A 82072 seems to return <invalid command> on
    975   1.1        pk 	 * gratuitous Sense Interrupt commands.
    976   1.1        pk 	 */
    977   1.1        pk 	if (n == 0 && (fdc->sc_flags & FDC_82077)) {
    978   1.1        pk 		out_fdc(fdc, NE7CMD_SENSEI);
    979   1.1        pk 		(void) fdcresult(fdc);
    980   1.1        pk 		n = 2;
    981   1.1        pk 	}
    982   1.1        pk #endif
    983   1.1        pk 
    984   1.1        pk 	/* Just print last status */
    985   1.1        pk 	n = fdc->sc_nstat;
    986   1.1        pk 
    987   1.1        pk 	printf("%s: %s: state %d", dv->dv_xname, s, fdc->sc_state);
    988   1.1        pk 
    989   1.1        pk 	switch (n) {
    990   1.1        pk 	case 0:
    991   1.1        pk 		printf("\n");
    992   1.1        pk 		break;
    993   1.1        pk 	case 2:
    994  1.27        pk 		printf(" (st0 %b cyl %d)\n",
    995  1.30  christos 		    fdc->sc_status[0], NE7_ST0BITS,
    996   1.1        pk 		    fdc->sc_status[1]);
    997   1.1        pk 		break;
    998   1.1        pk 	case 7:
    999  1.27        pk 		printf(" (st0 %b st1 %b st2 %b cyl %d head %d sec %d)\n",
   1000  1.30  christos 		    fdc->sc_status[0], NE7_ST0BITS,
   1001  1.30  christos 		    fdc->sc_status[1], NE7_ST1BITS,
   1002  1.30  christos 		    fdc->sc_status[2], NE7_ST2BITS,
   1003   1.1        pk 		    fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
   1004   1.1        pk 		break;
   1005   1.1        pk #ifdef DIAGNOSTIC
   1006   1.1        pk 	default:
   1007   1.2        pk 		printf(" fdcstatus: weird size: %d\n", n);
   1008   1.1        pk 		break;
   1009   1.1        pk #endif
   1010   1.1        pk 	}
   1011   1.1        pk }
   1012   1.1        pk 
   1013   1.1        pk void
   1014   1.1        pk fdctimeout(arg)
   1015   1.1        pk 	void *arg;
   1016   1.1        pk {
   1017   1.1        pk 	struct fdc_softc *fdc = arg;
   1018   1.1        pk 	struct fd_softc *fd = fdc->sc_drives.tqh_first;
   1019   1.1        pk 	int s;
   1020   1.1        pk 
   1021   1.1        pk 	s = splbio();
   1022  1.16   thorpej 	fdcstatus(&fd->sc_dv, 0, "timeout");
   1023   1.1        pk 
   1024   1.1        pk 	if (fd->sc_q.b_actf)
   1025   1.1        pk 		fdc->sc_state++;
   1026   1.1        pk 	else
   1027   1.1        pk 		fdc->sc_state = DEVIDLE;
   1028   1.1        pk 
   1029   1.1        pk 	(void) fdcswintr(fdc);
   1030   1.1        pk 	splx(s);
   1031   1.1        pk }
   1032   1.1        pk 
   1033   1.2        pk void
   1034   1.2        pk fdcpseudointr(arg)
   1035   1.2        pk 	void *arg;
   1036   1.2        pk {
   1037   1.2        pk 	struct fdc_softc *fdc = arg;
   1038   1.2        pk 	int s;
   1039   1.2        pk 
   1040   1.2        pk 	/* Just ensure it has the right spl. */
   1041   1.2        pk 	s = splbio();
   1042   1.2        pk 	(void) fdcswintr(fdc);
   1043   1.2        pk 	splx(s);
   1044   1.2        pk }
   1045   1.2        pk 
   1046   1.2        pk 
   1047   1.2        pk #ifdef FDC_C_HANDLER
   1048   1.1        pk /*
   1049   1.1        pk  * hardware interrupt entry point: must be converted to `fast'
   1050   1.1        pk  * (in-window) handler.
   1051   1.1        pk  */
   1052   1.1        pk int
   1053   1.1        pk fdchwintr(fdc)
   1054   1.1        pk 	struct fdc_softc *fdc;
   1055   1.1        pk {
   1056   1.1        pk 	struct buf *bp;
   1057   1.1        pk 	int read;
   1058   1.1        pk 
   1059   1.2        pk 	switch (fdc->sc_istate) {
   1060   1.2        pk 	case ISTATE_SENSEI:
   1061   1.1        pk 		out_fdc(fdc, NE7CMD_SENSEI);
   1062   1.1        pk 		fdcresult(fdc);
   1063   1.2        pk 		fdc->sc_istate = ISTATE_IDLE;
   1064   1.1        pk 		ienab_bis(IE_FDSOFT);
   1065   1.1        pk 		return 1;
   1066   1.2        pk 	case ISTATE_IDLE:
   1067   1.2        pk 	case ISTATE_SPURIOUS:
   1068   1.2        pk 		auxregbisc(0, AUXIO_FDS);	/* Does this help? */
   1069   1.1        pk 		fdcresult(fdc);
   1070   1.2        pk 		fdc->sc_istate = ISTATE_SPURIOUS;
   1071   1.2        pk 		printf("fdc: stray hard interrupt... ");
   1072   1.1        pk 		ienab_bis(IE_FDSOFT);
   1073   1.1        pk 		return 1;
   1074   1.2        pk 	case ISTATE_DMA:
   1075   1.2        pk 		break;
   1076   1.2        pk 	default:
   1077   1.2        pk 		printf("fdc: goofed ...\n");
   1078   1.2        pk 		return 1;
   1079   1.1        pk 	}
   1080   1.1        pk 
   1081   1.1        pk 	read = bp->b_flags & B_READ;
   1082   1.1        pk 	for (;;) {
   1083   1.1        pk 		register int msr;
   1084   1.1        pk 
   1085   1.1        pk 		msr = *fdc->sc_reg_msr;
   1086   1.1        pk 
   1087   1.1        pk 		if ((msr & NE7_RQM) == 0)
   1088   1.1        pk 			break;
   1089   1.1        pk 
   1090   1.1        pk 		if ((msr & NE7_NDM) == 0) {
   1091   1.1        pk 			fdcresult(fdc);
   1092   1.2        pk 			fdc->sc_istate = ISTATE_IDLE;
   1093   1.1        pk 			ienab_bis(IE_FDSOFT);
   1094   1.1        pk 			printf("fdc: overrun: tc = %d\n", fdc->sc_tc);
   1095   1.1        pk 			break;
   1096   1.1        pk 		}
   1097   1.1        pk 
   1098   1.1        pk 		if (msr & NE7_DIO) {
   1099   1.1        pk #ifdef DIAGNOSTIC
   1100   1.1        pk 			if (!read)
   1101   1.1        pk 				printf("fdxfer: false read\n");
   1102   1.1        pk #endif
   1103   1.2        pk 			*fdc->sc_data++ = *fdc->sc_reg_fifo;
   1104   1.1        pk 		} else {
   1105   1.1        pk #ifdef DIAGNOSTIC
   1106   1.1        pk 			if (read)
   1107   1.1        pk 				printf("fdxfer: false write\n");
   1108   1.1        pk #endif
   1109   1.2        pk 			*fdc->sc_reg_fifo = *fdc->sc_data++;
   1110   1.1        pk 		}
   1111   1.1        pk 		if (--fdc->sc_tc == 0) {
   1112   1.1        pk 			auxregbisc(AUXIO_FTC, 0);
   1113   1.2        pk 			fdc->sc_istate = ISTATE_IDLE;
   1114   1.1        pk 			delay(10);
   1115   1.1        pk 			auxregbisc(0, AUXIO_FTC);
   1116   1.1        pk 			fdcresult(fdc);
   1117   1.1        pk 			ienab_bis(IE_FDSOFT);
   1118   1.1        pk 			break;
   1119   1.1        pk 		}
   1120   1.1        pk 	}
   1121   1.1        pk 	return 1;
   1122   1.1        pk }
   1123   1.2        pk #endif
   1124   1.1        pk 
   1125   1.1        pk int
   1126   1.1        pk fdcswintr(fdc)
   1127   1.1        pk 	struct fdc_softc *fdc;
   1128   1.1        pk {
   1129   1.1        pk #define	st0	fdc->sc_status[0]
   1130   1.1        pk #define	st1	fdc->sc_status[1]
   1131   1.1        pk #define	cyl	fdc->sc_status[1]
   1132   1.2        pk #define OUT_FDC(fdc, c, s) \
   1133   1.2        pk     do { if (out_fdc(fdc, (c))) { (fdc)->sc_state = (s); goto loop; } } while(0)
   1134   1.2        pk 
   1135   1.1        pk 	struct fd_softc *fd;
   1136   1.1        pk 	struct buf *bp;
   1137  1.24  christos 	int read, head, sec, nblks;
   1138   1.1        pk 	struct fd_type *type;
   1139   1.1        pk 
   1140  1.12        pk 
   1141   1.2        pk 	if (fdc->sc_istate != ISTATE_IDLE) {
   1142   1.2        pk 		/* Trouble... */
   1143  1.12        pk 		printf("fdc: spurious interrupt: state %d, istate=%d\n",
   1144  1.12        pk 			fdc->sc_state, fdc->sc_istate);
   1145   1.2        pk 		fdc->sc_istate = ISTATE_IDLE;
   1146  1.12        pk 		if (fdc->sc_state == RESETCOMPLETE ||
   1147  1.12        pk 		    fdc->sc_state == RESETTIMEDOUT) {
   1148  1.12        pk 			panic("fdcintr: spurious interrupt can't be cleared");
   1149  1.12        pk 		}
   1150   1.2        pk 		goto doreset;
   1151   1.2        pk 	}
   1152   1.2        pk 
   1153  1.12        pk loop:
   1154   1.1        pk 	/* Is there a drive for the controller to do a transfer with? */
   1155   1.1        pk 	fd = fdc->sc_drives.tqh_first;
   1156   1.1        pk 	if (fd == NULL) {
   1157   1.1        pk 		fdc->sc_state = DEVIDLE;
   1158   1.1        pk  		return 0;
   1159   1.1        pk 	}
   1160   1.1        pk 
   1161   1.1        pk 	/* Is there a transfer to this drive?  If not, deactivate drive. */
   1162   1.1        pk 	bp = fd->sc_q.b_actf;
   1163   1.1        pk 	if (bp == NULL) {
   1164   1.1        pk 		fd->sc_ops = 0;
   1165   1.1        pk 		TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
   1166   1.1        pk 		fd->sc_q.b_active = 0;
   1167   1.1        pk 		goto loop;
   1168   1.1        pk 	}
   1169   1.1        pk 
   1170   1.1        pk 	switch (fdc->sc_state) {
   1171   1.1        pk 	case DEVIDLE:
   1172   1.1        pk 		fdc->sc_errors = 0;
   1173   1.1        pk 		fd->sc_skip = 0;
   1174   1.1        pk 		fd->sc_bcount = bp->b_bcount;
   1175   1.1        pk 		fd->sc_blkno = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE);
   1176   1.1        pk 		untimeout(fd_motor_off, fd);
   1177   1.1        pk 		if ((fd->sc_flags & FD_MOTOR_WAIT) != 0) {
   1178   1.1        pk 			fdc->sc_state = MOTORWAIT;
   1179   1.1        pk 			return 1;
   1180   1.1        pk 		}
   1181   1.1        pk 		if ((fd->sc_flags & FD_MOTOR) == 0) {
   1182   1.1        pk 			/* Turn on the motor, being careful about pairing. */
   1183   1.1        pk 			struct fd_softc *ofd = fdc->sc_fd[fd->sc_drive ^ 1];
   1184   1.1        pk 			if (ofd && ofd->sc_flags & FD_MOTOR) {
   1185   1.1        pk 				untimeout(fd_motor_off, ofd);
   1186   1.1        pk 				ofd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
   1187   1.1        pk 			}
   1188   1.1        pk 			fd->sc_flags |= FD_MOTOR | FD_MOTOR_WAIT;
   1189  1.12        pk 			fd_set_motor(fdc);
   1190   1.1        pk 			fdc->sc_state = MOTORWAIT;
   1191   1.2        pk 			if (fdc->sc_flags & FDC_82077) { /* XXX */
   1192   1.2        pk 				/* Allow .25s for motor to stabilize. */
   1193   1.2        pk 				timeout(fd_motor_on, fd, hz / 4);
   1194   1.2        pk 			} else {
   1195   1.2        pk 				fd->sc_flags &= ~FD_MOTOR_WAIT;
   1196   1.2        pk 				goto loop;
   1197   1.2        pk 			}
   1198   1.1        pk 			return 1;
   1199   1.1        pk 		}
   1200   1.1        pk 		/* Make sure the right drive is selected. */
   1201  1.12        pk 		fd_set_motor(fdc);
   1202   1.1        pk 
   1203   1.1        pk 		/* fall through */
   1204   1.1        pk 	case DOSEEK:
   1205   1.1        pk 	doseek:
   1206   1.2        pk 		if (fdc->sc_flags & FDC_EIS) {
   1207   1.2        pk 			fd->sc_cylin = bp->b_cylin;
   1208   1.2        pk 			/* We use implied seek */
   1209   1.2        pk 			goto doio;
   1210   1.2        pk 		}
   1211   1.2        pk 
   1212   1.1        pk 		if (fd->sc_cylin == bp->b_cylin)
   1213   1.1        pk 			goto doio;
   1214   1.1        pk 
   1215   1.2        pk 		/* specify command */
   1216   1.2        pk 		OUT_FDC(fdc, NE7CMD_SPECIFY, SEEKTIMEDOUT);
   1217   1.2        pk 		OUT_FDC(fdc, fd->sc_type->steprate, SEEKTIMEDOUT);
   1218   1.2        pk 		OUT_FDC(fdc, 6, SEEKTIMEDOUT);	/* XXX head load time == 6ms */
   1219   1.2        pk 
   1220   1.2        pk 		fdc->sc_istate = ISTATE_SENSEI;
   1221   1.2        pk 		/* seek function */
   1222   1.2        pk 		OUT_FDC(fdc, NE7CMD_SEEK, SEEKTIMEDOUT);
   1223   1.2        pk 		OUT_FDC(fdc, fd->sc_drive, SEEKTIMEDOUT); /* drive number */
   1224   1.2        pk 		OUT_FDC(fdc, bp->b_cylin * fd->sc_type->step, SEEKTIMEDOUT);
   1225   1.1        pk 
   1226   1.1        pk 		fd->sc_cylin = -1;
   1227   1.1        pk 		fdc->sc_state = SEEKWAIT;
   1228   1.1        pk 		fdc->sc_nstat = 0;
   1229  1.18   thorpej 
   1230  1.18   thorpej 		fd->sc_dk.dk_seek++;
   1231  1.18   thorpej 		disk_busy(&fd->sc_dk);
   1232  1.18   thorpej 
   1233   1.1        pk 		timeout(fdctimeout, fdc, 4 * hz);
   1234   1.1        pk 		return 1;
   1235   1.1        pk 
   1236   1.1        pk 	case DOIO:
   1237   1.1        pk 	doio:
   1238   1.1        pk 		type = fd->sc_type;
   1239   1.1        pk 		sec = fd->sc_blkno % type->seccyl;
   1240   1.1        pk 		nblks = type->seccyl - sec;
   1241   1.1        pk 		nblks = min(nblks, fd->sc_bcount / FDC_BSIZE);
   1242   1.1        pk 		nblks = min(nblks, FDC_MAXIOSIZE / FDC_BSIZE);
   1243   1.1        pk 		fd->sc_nblks = nblks;
   1244   1.1        pk 		fd->sc_nbytes = nblks * FDC_BSIZE;
   1245   1.1        pk 		head = sec / type->sectrac;
   1246   1.1        pk 		sec -= head * type->sectrac;
   1247   1.1        pk #ifdef DIAGNOSTIC
   1248   1.1        pk 		{int block;
   1249   1.1        pk 		 block = (fd->sc_cylin * type->heads + head) * type->sectrac + sec;
   1250   1.1        pk 		 if (block != fd->sc_blkno) {
   1251   1.1        pk 			 printf("fdcintr: block %d != blkno %d\n", block, fd->sc_blkno);
   1252   1.1        pk #ifdef DDB
   1253   1.1        pk 			 Debugger();
   1254   1.1        pk #endif
   1255   1.1        pk 		 }}
   1256   1.1        pk #endif
   1257   1.1        pk 		read = bp->b_flags & B_READ;
   1258   1.1        pk 
   1259   1.1        pk 		/* Setup for pseudo DMA */
   1260   1.2        pk 		fdc->sc_data = bp->b_data + fd->sc_skip;
   1261   1.1        pk 		fdc->sc_tc = fd->sc_nbytes;
   1262   1.1        pk 
   1263   1.1        pk 		*fdc->sc_reg_drs = type->rate;
   1264   1.1        pk #ifdef FD_DEBUG
   1265   1.2        pk 		if (fdc_debug > 1)
   1266   1.2        pk 			printf("fdcintr: %s drive %d track %d head %d sec %d nblks %d\n",
   1267   1.2        pk 				read ? "read" : "write", fd->sc_drive,
   1268   1.2        pk 				fd->sc_cylin, head, sec, nblks);
   1269   1.1        pk #endif
   1270   1.2        pk 		fdc->sc_state = IOCOMPLETE;
   1271   1.2        pk 		fdc->sc_istate = ISTATE_DMA;
   1272   1.1        pk 		fdc->sc_nstat = 0;
   1273   1.1        pk 		if (read)
   1274   1.2        pk 			OUT_FDC(fdc, NE7CMD_READ, IOTIMEDOUT);	/* READ */
   1275   1.1        pk 		else
   1276   1.2        pk 			OUT_FDC(fdc, NE7CMD_WRITE, IOTIMEDOUT);	/* WRITE */
   1277   1.2        pk 		OUT_FDC(fdc, (head << 2) | fd->sc_drive, IOTIMEDOUT);
   1278   1.2        pk 		OUT_FDC(fdc, fd->sc_cylin, IOTIMEDOUT);	/* track */
   1279   1.2        pk 		OUT_FDC(fdc, head, IOTIMEDOUT);
   1280   1.2        pk 		OUT_FDC(fdc, sec + 1, IOTIMEDOUT);	/* sector +1 */
   1281   1.2        pk 		OUT_FDC(fdc, type->secsize, IOTIMEDOUT);/* sector size */
   1282   1.2        pk 		OUT_FDC(fdc, type->sectrac, IOTIMEDOUT);/* sectors/track */
   1283   1.2        pk 		OUT_FDC(fdc, type->gap1, IOTIMEDOUT);	/* gap1 size */
   1284   1.2        pk 		OUT_FDC(fdc, type->datalen, IOTIMEDOUT);/* data length */
   1285  1.18   thorpej 
   1286  1.18   thorpej 		disk_busy(&fd->sc_dk);
   1287  1.18   thorpej 
   1288   1.1        pk 		/* allow 2 seconds for operation */
   1289   1.1        pk 		timeout(fdctimeout, fdc, 2 * hz);
   1290   1.1        pk 		return 1;				/* will return later */
   1291   1.1        pk 
   1292   1.1        pk 	case SEEKWAIT:
   1293   1.1        pk 		untimeout(fdctimeout, fdc);
   1294   1.1        pk 		fdc->sc_state = SEEKCOMPLETE;
   1295   1.2        pk 		if (fdc->sc_flags & FDC_NEEDHEADSETTLE) {
   1296   1.2        pk 			/* allow 1/50 second for heads to settle */
   1297   1.2        pk 			timeout(fdcpseudointr, fdc, hz / 50);
   1298   1.2        pk 			return 1;		/* will return later */
   1299   1.2        pk 		}
   1300   1.2        pk 
   1301   1.1        pk 	case SEEKCOMPLETE:
   1302  1.18   thorpej 		disk_unbusy(&fd->sc_dk, 0);	/* no data on seek */
   1303  1.18   thorpej 
   1304   1.1        pk 		/* Make sure seek really happened. */
   1305   1.1        pk 		if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 ||
   1306   1.1        pk 		    cyl != bp->b_cylin * fd->sc_type->step) {
   1307   1.1        pk #ifdef FD_DEBUG
   1308   1.2        pk 			if (fdc_debug)
   1309  1.16   thorpej 				fdcstatus(&fd->sc_dv, 2, "seek failed");
   1310   1.1        pk #endif
   1311   1.1        pk 			fdcretry(fdc);
   1312   1.1        pk 			goto loop;
   1313   1.1        pk 		}
   1314   1.1        pk 		fd->sc_cylin = bp->b_cylin;
   1315   1.1        pk 		goto doio;
   1316   1.1        pk 
   1317   1.1        pk 	case IOTIMEDOUT:
   1318   1.1        pk 		auxregbisc(AUXIO_FTC, 0);
   1319   1.1        pk 		delay(10);
   1320   1.1        pk 		auxregbisc(0, AUXIO_FTC);
   1321   1.1        pk 		(void)fdcresult(fdc);
   1322   1.1        pk 	case SEEKTIMEDOUT:
   1323   1.1        pk 	case RECALTIMEDOUT:
   1324   1.1        pk 	case RESETTIMEDOUT:
   1325   1.1        pk 		fdcretry(fdc);
   1326   1.1        pk 		goto loop;
   1327   1.1        pk 
   1328   1.1        pk 	case IOCOMPLETE: /* IO DONE, post-analyze */
   1329   1.1        pk 		untimeout(fdctimeout, fdc);
   1330  1.18   thorpej 
   1331  1.18   thorpej 		disk_unbusy(&fd->sc_dk, (bp->b_bcount - bp->b_resid));
   1332  1.18   thorpej 
   1333   1.1        pk 		if (fdc->sc_nstat != 7 || (st0 & 0xf8) != 0 || st1 != 0) {
   1334   1.1        pk #ifdef FD_DEBUG
   1335   1.2        pk 			if (fdc_debug) {
   1336  1.16   thorpej 				fdcstatus(&fd->sc_dv, 7,
   1337   1.2        pk 					bp->b_flags & B_READ
   1338   1.2        pk 					? "read failed" : "write failed");
   1339   1.2        pk 				printf("blkno %d nblks %d tc %d\n",
   1340   1.2        pk 				       fd->sc_blkno, fd->sc_nblks, fdc->sc_tc);
   1341   1.2        pk 			}
   1342   1.1        pk #endif
   1343   1.6        pk 			if (fdc->sc_nstat == 7 &&
   1344   1.6        pk 			    (st1 & ST1_OVERRUN) == ST1_OVERRUN) {
   1345   1.6        pk 
   1346   1.6        pk 				/*
   1347   1.6        pk 				 * Silently retry overruns if no other
   1348   1.6        pk 				 * error bit is set. Adjust threshold.
   1349   1.6        pk 				 */
   1350   1.2        pk 				int thr = fdc->sc_cfg & CFG_THRHLD_MASK;
   1351   1.6        pk 				if (thr < 15) {
   1352   1.6        pk 					thr++;
   1353   1.6        pk 					fdc->sc_cfg &= ~CFG_THRHLD_MASK;
   1354   1.6        pk 					fdc->sc_cfg |= (thr & CFG_THRHLD_MASK);
   1355   1.2        pk #ifdef FD_DEBUG
   1356   1.6        pk 					if (fdc_debug)
   1357   1.6        pk 						printf("fdc: %d -> threshold\n", thr);
   1358   1.2        pk #endif
   1359   1.6        pk 					fdconf(fdc);
   1360   1.6        pk 					fdc->sc_overruns = 0;
   1361   1.6        pk 				}
   1362  1.34        pk 				if (++fdc->sc_overruns < 3) {
   1363  1.34        pk 					fdc->sc_state = DOIO;
   1364   1.6        pk 					goto loop;
   1365  1.34        pk 				}
   1366   1.2        pk 			}
   1367   1.1        pk 			fdcretry(fdc);
   1368   1.1        pk 			goto loop;
   1369   1.1        pk 		}
   1370   1.1        pk 		if (fdc->sc_errors) {
   1371   1.1        pk 			diskerr(bp, "fd", "soft error", LOG_PRINTF,
   1372   1.1        pk 			    fd->sc_skip / FDC_BSIZE, (struct disklabel *)NULL);
   1373   1.1        pk 			printf("\n");
   1374   1.1        pk 			fdc->sc_errors = 0;
   1375   1.6        pk 		} else {
   1376  1.12        pk 			if (--fdc->sc_overruns < -20) {
   1377   1.6        pk 				int thr = fdc->sc_cfg & CFG_THRHLD_MASK;
   1378   1.6        pk 				if (thr > 0) {
   1379   1.6        pk 					thr--;
   1380   1.6        pk 					fdc->sc_cfg &= ~CFG_THRHLD_MASK;
   1381   1.6        pk 					fdc->sc_cfg |= (thr & CFG_THRHLD_MASK);
   1382   1.6        pk #ifdef FD_DEBUG
   1383   1.6        pk 					if (fdc_debug)
   1384   1.6        pk 						printf("fdc: %d -> threshold\n", thr);
   1385   1.6        pk #endif
   1386   1.6        pk 					fdconf(fdc);
   1387   1.6        pk 				}
   1388   1.6        pk 				fdc->sc_overruns = 0;
   1389   1.6        pk 			}
   1390   1.1        pk 		}
   1391   1.1        pk 		fd->sc_blkno += fd->sc_nblks;
   1392   1.1        pk 		fd->sc_skip += fd->sc_nbytes;
   1393   1.1        pk 		fd->sc_bcount -= fd->sc_nbytes;
   1394   1.1        pk 		if (fd->sc_bcount > 0) {
   1395   1.1        pk 			bp->b_cylin = fd->sc_blkno / fd->sc_type->seccyl;
   1396   1.1        pk 			goto doseek;
   1397   1.1        pk 		}
   1398   1.1        pk 		fdfinish(fd, bp);
   1399   1.1        pk 		goto loop;
   1400   1.1        pk 
   1401   1.1        pk 	case DORESET:
   1402   1.2        pk 	doreset:
   1403   1.1        pk 		/* try a reset, keep motor on */
   1404  1.12        pk 		fd_set_motor(fdc);
   1405   1.1        pk 		delay(100);
   1406  1.12        pk 		fdc_reset(fdc);
   1407  1.12        pk 		fdc->sc_nstat = 0;
   1408  1.12        pk 		fdc->sc_istate = ISTATE_SENSEI;
   1409   1.1        pk 		fdc->sc_state = RESETCOMPLETE;
   1410   1.1        pk 		timeout(fdctimeout, fdc, hz / 2);
   1411   1.1        pk 		return 1;			/* will return later */
   1412   1.1        pk 
   1413   1.1        pk 	case RESETCOMPLETE:
   1414   1.1        pk 		untimeout(fdctimeout, fdc);
   1415  1.12        pk 		fdconf(fdc);
   1416   1.1        pk 
   1417   1.1        pk 		/* fall through */
   1418   1.1        pk 	case DORECAL:
   1419   1.1        pk 		fdc->sc_state = RECALWAIT;
   1420   1.2        pk 		fdc->sc_istate = ISTATE_SENSEI;
   1421   1.1        pk 		fdc->sc_nstat = 0;
   1422   1.2        pk 		/* recalibrate function */
   1423   1.2        pk 		OUT_FDC(fdc, NE7CMD_RECAL, RECALTIMEDOUT);
   1424   1.2        pk 		OUT_FDC(fdc, fd->sc_drive, RECALTIMEDOUT);
   1425   1.1        pk 		timeout(fdctimeout, fdc, 5 * hz);
   1426   1.1        pk 		return 1;			/* will return later */
   1427   1.1        pk 
   1428   1.1        pk 	case RECALWAIT:
   1429   1.1        pk 		untimeout(fdctimeout, fdc);
   1430   1.1        pk 		fdc->sc_state = RECALCOMPLETE;
   1431   1.2        pk 		if (fdc->sc_flags & FDC_NEEDHEADSETTLE) {
   1432   1.2        pk 			/* allow 1/30 second for heads to settle */
   1433   1.2        pk 			timeout(fdcpseudointr, fdc, hz / 30);
   1434   1.2        pk 			return 1;		/* will return later */
   1435   1.2        pk 		}
   1436   1.1        pk 
   1437   1.1        pk 	case RECALCOMPLETE:
   1438   1.1        pk 		if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) {
   1439   1.1        pk #ifdef FD_DEBUG
   1440   1.2        pk 			if (fdc_debug)
   1441  1.16   thorpej 				fdcstatus(&fd->sc_dv, 2, "recalibrate failed");
   1442   1.1        pk #endif
   1443   1.1        pk 			fdcretry(fdc);
   1444   1.1        pk 			goto loop;
   1445   1.1        pk 		}
   1446   1.1        pk 		fd->sc_cylin = 0;
   1447   1.1        pk 		goto doseek;
   1448   1.1        pk 
   1449   1.1        pk 	case MOTORWAIT:
   1450   1.1        pk 		if (fd->sc_flags & FD_MOTOR_WAIT)
   1451   1.1        pk 			return 1;		/* time's not up yet */
   1452   1.1        pk 		goto doseek;
   1453   1.1        pk 
   1454   1.1        pk 	default:
   1455  1.16   thorpej 		fdcstatus(&fd->sc_dv, 0, "stray interrupt");
   1456   1.1        pk 		return 1;
   1457   1.1        pk 	}
   1458   1.1        pk #ifdef DIAGNOSTIC
   1459   1.1        pk 	panic("fdcintr: impossible");
   1460   1.1        pk #endif
   1461   1.1        pk #undef	st0
   1462   1.1        pk #undef	st1
   1463   1.1        pk #undef	cyl
   1464   1.1        pk }
   1465   1.1        pk 
   1466   1.1        pk void
   1467   1.1        pk fdcretry(fdc)
   1468   1.1        pk 	struct fdc_softc *fdc;
   1469   1.1        pk {
   1470   1.1        pk 	struct fd_softc *fd;
   1471   1.1        pk 	struct buf *bp;
   1472   1.1        pk 
   1473   1.1        pk 	fd = fdc->sc_drives.tqh_first;
   1474   1.1        pk 	bp = fd->sc_q.b_actf;
   1475   1.6        pk 
   1476   1.6        pk 	fdc->sc_overruns = 0;
   1477   1.1        pk 
   1478   1.1        pk 	switch (fdc->sc_errors) {
   1479   1.1        pk 	case 0:
   1480   1.1        pk 		/* try again */
   1481   1.2        pk 		fdc->sc_state =
   1482  1.22   thorpej 			(fdc->sc_flags & FDC_EIS) ? DOIO : DOSEEK;
   1483   1.1        pk 		break;
   1484   1.1        pk 
   1485   1.1        pk 	case 1: case 2: case 3:
   1486   1.1        pk 		/* didn't work; try recalibrating */
   1487   1.1        pk 		fdc->sc_state = DORECAL;
   1488   1.1        pk 		break;
   1489   1.1        pk 
   1490   1.1        pk 	case 4:
   1491   1.1        pk 		/* still no go; reset the bastard */
   1492   1.1        pk 		fdc->sc_state = DORESET;
   1493   1.1        pk 		break;
   1494   1.1        pk 
   1495   1.1        pk 	default:
   1496   1.1        pk 		diskerr(bp, "fd", "hard error", LOG_PRINTF,
   1497   1.1        pk 		    fd->sc_skip / FDC_BSIZE, (struct disklabel *)NULL);
   1498  1.24  christos 
   1499  1.27        pk 		printf(" (st0 %b st1 %b st2 %b cyl %d head %d sec %d)\n",
   1500  1.30  christos 		    fdc->sc_status[0], NE7_ST0BITS,
   1501  1.30  christos 		    fdc->sc_status[1], NE7_ST1BITS,
   1502  1.30  christos 		    fdc->sc_status[2], NE7_ST2BITS,
   1503   1.1        pk 		    fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
   1504   1.1        pk 
   1505   1.1        pk 		bp->b_flags |= B_ERROR;
   1506   1.1        pk 		bp->b_error = EIO;
   1507   1.1        pk 		fdfinish(fd, bp);
   1508   1.1        pk 	}
   1509   1.1        pk 	fdc->sc_errors++;
   1510   1.1        pk }
   1511   1.1        pk 
   1512   1.1        pk int
   1513   1.1        pk fdsize(dev)
   1514   1.1        pk 	dev_t dev;
   1515   1.1        pk {
   1516   1.1        pk 
   1517   1.1        pk 	/* Swapping to floppies would not make sense. */
   1518   1.1        pk 	return -1;
   1519   1.1        pk }
   1520   1.1        pk 
   1521   1.1        pk int
   1522  1.24  christos fddump(dev, blkno, va, size)
   1523  1.24  christos 	dev_t dev;
   1524  1.24  christos 	daddr_t blkno;
   1525  1.24  christos 	caddr_t va;
   1526  1.24  christos 	size_t size;
   1527   1.1        pk {
   1528   1.1        pk 
   1529   1.1        pk 	/* Not implemented. */
   1530   1.1        pk 	return EINVAL;
   1531   1.1        pk }
   1532   1.1        pk 
   1533   1.1        pk int
   1534  1.24  christos fdioctl(dev, cmd, addr, flag, p)
   1535   1.1        pk 	dev_t dev;
   1536   1.1        pk 	u_long cmd;
   1537   1.1        pk 	caddr_t addr;
   1538   1.1        pk 	int flag;
   1539  1.24  christos 	struct proc *p;
   1540   1.1        pk {
   1541  1.26   thorpej 	struct fd_softc *fd = fd_cd.cd_devs[FDUNIT(dev)];
   1542   1.1        pk 	int error;
   1543   1.1        pk 
   1544   1.1        pk 	switch (cmd) {
   1545   1.1        pk 	case DIOCGDINFO:
   1546  1.16   thorpej 		*(struct disklabel *)addr = *(fd->sc_dk.dk_label);
   1547   1.1        pk 		return 0;
   1548   1.1        pk 
   1549   1.1        pk 	case DIOCWLABEL:
   1550   1.1        pk 		if ((flag & FWRITE) == 0)
   1551   1.1        pk 			return EBADF;
   1552   1.1        pk 		/* XXX do something */
   1553   1.1        pk 		return 0;
   1554   1.1        pk 
   1555   1.1        pk 	case DIOCWDINFO:
   1556   1.1        pk 		if ((flag & FWRITE) == 0)
   1557   1.1        pk 			return EBADF;
   1558   1.1        pk 
   1559  1.16   thorpej 		error = setdisklabel(fd->sc_dk.dk_label,
   1560  1.11        pk 				    (struct disklabel *)addr, 0,
   1561  1.16   thorpej 				    fd->sc_dk.dk_cpulabel);
   1562   1.1        pk 		if (error)
   1563   1.1        pk 			return error;
   1564   1.1        pk 
   1565  1.11        pk 		error = writedisklabel(dev, fdstrategy,
   1566  1.16   thorpej 				       fd->sc_dk.dk_label,
   1567  1.16   thorpej 				       fd->sc_dk.dk_cpulabel);
   1568   1.1        pk 		return error;
   1569  1.21   thorpej 
   1570  1.21   thorpej 	case DIOCLOCK:
   1571  1.21   thorpej 		/*
   1572  1.21   thorpej 		 * Nothing to do here, really.
   1573  1.21   thorpej 		 */
   1574  1.21   thorpej 		return 0;
   1575   1.1        pk 
   1576  1.13        pk 	case DIOCEJECT:
   1577  1.19   thorpej 		fd_do_eject();
   1578  1.17        pk 		return 0;
   1579  1.16   thorpej 
   1580   1.1        pk #ifdef DEBUG
   1581   1.1        pk 	case _IO('f', 100):
   1582   1.1        pk 		{
   1583   1.1        pk 		int i;
   1584   1.1        pk 		struct fdc_softc *fdc = (struct fdc_softc *)
   1585  1.16   thorpej 					fd->sc_dv.dv_parent;
   1586   1.1        pk 
   1587   1.1        pk 		out_fdc(fdc, NE7CMD_DUMPREG);
   1588   1.1        pk 		fdcresult(fdc);
   1589   1.1        pk 		printf("dumpreg(%d regs): <", fdc->sc_nstat);
   1590   1.1        pk 		for (i = 0; i < fdc->sc_nstat; i++)
   1591   1.1        pk 			printf(" %x", fdc->sc_status[i]);
   1592   1.1        pk 		printf(">\n");
   1593   1.1        pk 		}
   1594   1.1        pk 
   1595   1.1        pk 		return 0;
   1596   1.1        pk 	case _IOW('f', 101, int):
   1597  1.16   thorpej 		((struct fdc_softc *)fd->sc_dv.dv_parent)->sc_cfg &=
   1598   1.2        pk 			~CFG_THRHLD_MASK;
   1599  1.16   thorpej 		((struct fdc_softc *)fd->sc_dv.dv_parent)->sc_cfg |=
   1600   1.2        pk 			(*(int *)addr & CFG_THRHLD_MASK);
   1601  1.24  christos 		fdconf((struct fdc_softc *) fd->sc_dv.dv_parent);
   1602   1.1        pk 		return 0;
   1603   1.1        pk 	case _IO('f', 102):
   1604   1.1        pk 		{
   1605   1.1        pk 		int i;
   1606   1.1        pk 		struct fdc_softc *fdc = (struct fdc_softc *)
   1607  1.16   thorpej 					fd->sc_dv.dv_parent;
   1608   1.1        pk 		out_fdc(fdc, NE7CMD_SENSEI);
   1609   1.1        pk 		fdcresult(fdc);
   1610   1.1        pk 		printf("sensei(%d regs): <", fdc->sc_nstat);
   1611   1.1        pk 		for (i=0; i< fdc->sc_nstat; i++)
   1612   1.1        pk 			printf(" 0x%x", fdc->sc_status[i]);
   1613   1.1        pk 		}
   1614   1.1        pk 		printf(">\n");
   1615   1.1        pk 		return 0;
   1616   1.1        pk #endif
   1617   1.1        pk 	default:
   1618   1.1        pk 		return ENOTTY;
   1619   1.1        pk 	}
   1620   1.1        pk 
   1621   1.1        pk #ifdef DIAGNOSTIC
   1622   1.1        pk 	panic("fdioctl: impossible");
   1623   1.1        pk #endif
   1624  1.19   thorpej }
   1625  1.19   thorpej 
   1626  1.19   thorpej void
   1627  1.19   thorpej fdgetdisklabel(dev)
   1628  1.19   thorpej 	dev_t dev;
   1629  1.19   thorpej {
   1630  1.19   thorpej 	int unit = FDUNIT(dev), i;
   1631  1.26   thorpej 	struct fd_softc *fd = fd_cd.cd_devs[unit];
   1632  1.19   thorpej 	struct disklabel *lp = fd->sc_dk.dk_label;
   1633  1.19   thorpej 	struct cpu_disklabel *clp = fd->sc_dk.dk_cpulabel;
   1634  1.19   thorpej 
   1635  1.19   thorpej 	bzero(lp, sizeof(struct disklabel));
   1636  1.19   thorpej 	bzero(lp, sizeof(struct cpu_disklabel));
   1637  1.19   thorpej 
   1638  1.19   thorpej 	lp->d_type = DTYPE_FLOPPY;
   1639  1.19   thorpej 	lp->d_secsize = FDC_BSIZE;
   1640  1.19   thorpej 	lp->d_secpercyl = fd->sc_type->seccyl;
   1641  1.19   thorpej 	lp->d_nsectors = fd->sc_type->sectrac;
   1642  1.19   thorpej 	lp->d_ncylinders = fd->sc_type->tracks;
   1643  1.19   thorpej 	lp->d_ntracks = fd->sc_type->heads;	/* Go figure... */
   1644  1.19   thorpej 	lp->d_rpm = 3600;	/* XXX like it matters... */
   1645  1.19   thorpej 
   1646  1.19   thorpej 	strncpy(lp->d_typename, "floppy", sizeof(lp->d_typename));
   1647  1.19   thorpej 	strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
   1648  1.19   thorpej 	lp->d_interleave = 1;
   1649  1.19   thorpej 
   1650  1.19   thorpej 	lp->d_partitions[RAW_PART].p_offset = 0;
   1651  1.19   thorpej 	lp->d_partitions[RAW_PART].p_size = lp->d_secpercyl * lp->d_ncylinders;
   1652  1.19   thorpej 	lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
   1653  1.19   thorpej 	lp->d_npartitions = RAW_PART + 1;
   1654  1.19   thorpej 
   1655  1.19   thorpej 	lp->d_magic = DISKMAGIC;
   1656  1.19   thorpej 	lp->d_magic2 = DISKMAGIC;
   1657  1.19   thorpej 	lp->d_checksum = dkcksum(lp);
   1658  1.19   thorpej 
   1659  1.19   thorpej 	/*
   1660  1.19   thorpej 	 * Call the generic disklabel extraction routine.  If there's
   1661  1.19   thorpej 	 * not a label there, fake it.
   1662  1.19   thorpej 	 */
   1663  1.19   thorpej 	if (readdisklabel(dev, fdstrategy, lp, clp) != NULL) {
   1664  1.19   thorpej 		strncpy(lp->d_packname, "default label",
   1665  1.19   thorpej 		    sizeof(lp->d_packname));
   1666  1.19   thorpej 		/*
   1667  1.19   thorpej 		 * Reset the partition info; it might have gotten
   1668  1.19   thorpej 		 * trashed in readdisklabel().
   1669  1.19   thorpej 		 *
   1670  1.19   thorpej 		 * XXX Why do we have to do this?  readdisklabel()
   1671  1.19   thorpej 		 * should be safe...
   1672  1.19   thorpej 		 */
   1673  1.19   thorpej 		for (i = 0; i < MAXPARTITIONS; ++i) {
   1674  1.19   thorpej 			lp->d_partitions[i].p_offset = 0;
   1675  1.19   thorpej 			if (i == RAW_PART) {
   1676  1.19   thorpej 				lp->d_partitions[i].p_size =
   1677  1.19   thorpej 				    lp->d_secpercyl * lp->d_ncylinders;
   1678  1.19   thorpej 				lp->d_partitions[i].p_fstype = FS_BSDFFS;
   1679  1.19   thorpej 			} else {
   1680  1.19   thorpej 				lp->d_partitions[i].p_size = 0;
   1681  1.19   thorpej 				lp->d_partitions[i].p_fstype = FS_UNUSED;
   1682  1.19   thorpej 			}
   1683  1.19   thorpej 		}
   1684  1.19   thorpej 		lp->d_npartitions = RAW_PART + 1;
   1685  1.19   thorpej 	}
   1686  1.19   thorpej }
   1687  1.19   thorpej 
   1688  1.19   thorpej void
   1689  1.19   thorpej fd_do_eject()
   1690  1.19   thorpej {
   1691  1.19   thorpej 
   1692  1.19   thorpej 	auxregbisc(AUXIO_FDS, AUXIO_FEJ);
   1693  1.19   thorpej 	delay(10);
   1694  1.19   thorpej 	auxregbisc(AUXIO_FEJ, AUXIO_FDS);
   1695  1.19   thorpej }
   1696  1.19   thorpej 
   1697  1.19   thorpej /* ARGSUSED */
   1698  1.19   thorpej void
   1699  1.19   thorpej fd_mountroot_hook(dev)
   1700  1.19   thorpej 	struct device *dev;
   1701  1.19   thorpej {
   1702  1.19   thorpej 	int c;
   1703  1.19   thorpej 
   1704  1.19   thorpej 	fd_do_eject();
   1705  1.19   thorpej 	printf("Insert filesystem floppy and press return.");
   1706  1.19   thorpej 	for (;;) {
   1707  1.19   thorpej 		c = cngetc();
   1708  1.19   thorpej 		if ((c == '\r') || (c == '\n')) {
   1709  1.19   thorpej 			printf("\n");
   1710  1.19   thorpej 			return;
   1711  1.19   thorpej 		}
   1712  1.19   thorpej 	}
   1713   1.1        pk }
   1714