2 * Copyright (c) 1990 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Libretto PCMCIA floppy support by David Horwitt (dhorwitt@ucsd.edu)
9 * aided by the Linux floppy driver modifications from David Bateman
10 * (dbateman@eng.uts.edu.au).
12 * Copyright (c) 1993, 1994 by
13 * jc@irbs.UUCP (John Capo)
14 * vak@zebub.msk.su (Serge Vakulenko)
15 * ache@astral.msk.su (Andrew A. Chernov)
17 * Copyright (c) 1993, 1994, 1995 by
18 * joerg_wunsch@uriah.sax.de (Joerg Wunsch)
19 * dufault@hda.com (Peter Dufault)
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. All advertising materials mentioning features or use of this software
30 * must display the following acknowledgement:
31 * This product includes software developed by the University of
32 * California, Berkeley and its contributors.
33 * 4. Neither the name of the University nor the names of its contributors
34 * may be used to endorse or promote products derived from this software
35 * without specific prior written permission.
37 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * from: @(#)fd.c 7.4 (Berkeley) 5/25/91
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
65 #include <sys/disklabel.h>
66 #include <sys/devicestat.h>
67 #include <sys/fcntl.h>
68 #include <sys/malloc.h>
69 #include <sys/module.h>
71 #include <sys/syslog.h>
74 #include <machine/bus.h>
77 #include <machine/clock.h>
78 #include <machine/ioctl_fd.h>
79 #include <machine/resource.h>
80 #include <machine/stdarg.h>
82 #include <isa/isavar.h>
84 #include <pc98/pc98/pc98.h>
85 #include <pc98/pc98/pc98_machdep.h>
86 #include <pc98/pc98/epsonio.h>
87 #include <pc98/pc98/fdreg.h>
90 #include <isa/isareg.h>
91 #include <isa/fdreg.h>
98 #warning "fix FDC_YE! - newbus casualty"
101 /* misuse a flag to identify format operation */
102 #define B_FORMAT B_XXX
104 /* configuration flags */
105 #define FDC_PRETEND_D0 (1 << 0) /* pretend drive 0 to be there */
107 #define FDC_IS_PCMCIA (1 << 1) /* if successful probe, then it's
111 /* internally used only, not really from CMOS: */
112 #define RTCFDT_144M_PRETENDED 0x1000
114 /* error returns for fd_cmd() */
116 #define FD_NOT_VALID -2
117 #define FDC_ERRMAX 100 /* do not log more */
121 #define NUMDENS NUMTYPES
124 #define NUMDENS (NUMTYPES - 6)
127 /* These defines (-1) must match index for fd_types */
128 #define F_TAPE_TYPE 0x020 /* bit for fd_types to indicate tape */
129 #define NO_TYPE 0 /* must match NO_TYPE in ft.c */
145 #define FDT_NONE 0 /* none present */
146 #define FDT_12M 1 /* 1M/640K FDD */
147 #define FDT_144M 2 /* 1.44M/1M/640K FDD */
149 #define FD_1480in5_25 9
150 #define FD_1440in5_25 10
151 #define FD_820in5_25 11
152 #define FD_800in5_25 12
153 #define FD_720in5_25 13
154 #define FD_360in5_25 14
158 static struct fd_type fd_types[NUMTYPES] =
161 { 21,2,0xFF,0x04,82,3444,1,2,2,0x0C,2 }, /* 1.72M in 3mode */
162 { 18,2,0xFF,0x1B,82,2952,1,2,2,0x54,1 }, /* 1.48M in 3mode */
163 { 18,2,0xFF,0x1B,80,2880,1,2,2,0x54,1 }, /* 1.44M in 3mode */
164 { 15,2,0xFF,0x1B,80,2400,1,0,2,0x54,1 }, /* 1.2M */
165 { 10,2,0xFF,0x10,82,1640,1,1,2,0x30,1 }, /* 820K */
166 { 10,2,0xFF,0x10,80,1600,1,1,2,0x30,1 }, /* 800K */
167 { 9,2,0xFF,0x20,80,1440,1,1,2,0x50,1 }, /* 720K */
168 { 9,2,0xFF,0x20,40, 720,2,1,2,0x50,1 }, /* 360K */
170 { 8,2,0xFF,0x2A,80,1280,1,1,2,0x50,1 }, /* 640K */
171 { 8,3,0xFF,0x35,77,1232,1,0,2,0x74,1 }, /* 1.23M 1024/sec */
172 { 8,3,0xFF,0x35,80,1280,1,0,2,0x74,1 }, /* 1.28M 1024/sec */
173 { 9,3,0xFF,0x35,82,1476,1,0,2,0x47,1 }, /* 1.48M 1024/sec 9sec */
175 { 10,3,0xFF,0x1B,82,1640,1,2,2,0x54,1 }, /* 1.64M in 3mode - Reserve */
178 { 21,2,0xFF,0x04,82,3444,1,FDC_500KBPS,2,0x0C,2 }, /* 1.72M in HD 3.5in */
179 { 18,2,0xFF,0x1B,82,2952,1,FDC_500KBPS,2,0x6C,1 }, /* 1.48M in HD 3.5in */
180 { 18,2,0xFF,0x1B,80,2880,1,FDC_500KBPS,2,0x6C,1 }, /* 1.44M in HD 3.5in */
181 { 15,2,0xFF,0x1B,80,2400,1,FDC_500KBPS,2,0x54,1 }, /* 1.2M in HD 5.25/3.5 */
182 { 10,2,0xFF,0x10,82,1640,1,FDC_250KBPS,2,0x2E,1 }, /* 820K in HD 3.5in */
183 { 10,2,0xFF,0x10,80,1600,1,FDC_250KBPS,2,0x2E,1 }, /* 800K in HD 3.5in */
184 { 9,2,0xFF,0x20,80,1440,1,FDC_250KBPS,2,0x50,1 }, /* 720K in HD 3.5in */
185 { 9,2,0xFF,0x2A,40, 720,1,FDC_250KBPS,2,0x50,1 }, /* 360K in DD 5.25in */
187 { 18,2,0xFF,0x02,82,2952,1,FDC_500KBPS,2,0x02,2 }, /* 1.48M in HD 5.25in */
188 { 18,2,0xFF,0x02,80,2880,1,FDC_500KBPS,2,0x02,2 }, /* 1.44M in HD 5.25in */
189 { 10,2,0xFF,0x10,82,1640,1,FDC_300KBPS,2,0x2E,1 }, /* 820K in HD 5.25in */
190 { 10,2,0xFF,0x10,80,1600,1,FDC_300KBPS,2,0x2E,1 }, /* 800K in HD 5.25in */
191 { 9,2,0xFF,0x20,80,1440,1,FDC_300KBPS,2,0x50,1 }, /* 720K in HD 5.25in */
192 { 9,2,0xFF,0x23,40, 720,2,FDC_300KBPS,2,0x50,1 }, /* 360K in HD 5.25in */
196 #ifdef PC98 /* XXX Should be used PC/AT also */
198 static int fd_typesizes[NUMDENS] = {
199 1720, 1480, 1440, 1200, 820, 800, 720, 360,
201 640, 1232, 1280, 1476,
208 #define DRVS_PER_CTLR 4 /* 4 floppies */
210 #define DRVS_PER_CTLR 2 /* 2 floppies */
213 /***********************************************************************\
214 * Per controller structure. *
215 \***********************************************************************/
216 static devclass_t fdc_devclass;
218 /***********************************************************************\
219 * Per drive structure. *
220 * N per controller (DRVS_PER_CTLR) *
221 \***********************************************************************/
223 struct fdc_data *fdc; /* pointer to controller structure */
224 int fdsu; /* this units number on this controller */
225 int type; /* Drive type (FD_1440...) */
226 struct fd_type *ft; /* pointer to the type descriptor */
228 #define FD_OPEN 0x01 /* it's open */
229 #define FD_ACTIVE 0x02 /* it's active */
230 #define FD_MOTOR 0x04 /* motor should be on */
231 #define FD_MOTOR_WAIT 0x08 /* motor coming up */
234 #define FD_NO_TRACK -2
235 int track; /* where we think the head is */
236 int options; /* user configurable options, see ioctl_fd.h */
237 struct callout_handle toffhandle;
238 struct callout_handle tohandle;
239 struct devstat device_stats;
246 static devclass_t fd_devclass;
249 typedef unsigned int nrd_t;
251 #define P_NRD_ADDRH 0xc24
252 #define P_NRD_ADDRM 0xc22
253 #define P_NRD_ADDRL 0xc20
254 #define P_NRD_CHECK 0xc20
255 #define P_NRD_DATA 0xc26
256 #define P_NRD_LED 0xc36
257 #define B_NRD_CHK 0x80
258 #define B_NRD_LED 0x40
259 #define A_NRD_INFO 0x2
260 #define A_NRD_BASE 0x400
261 #define NRD_STATUS 0x0
262 #define NRD_ST0_HD 0x04
264 static fdu_t nrdu=-1;
266 static nrd_t nrdblkn=0;
267 static nrd_t nrdaddr=0x0;
269 #define nrd_check_ready() ({ \
270 (epson_inb(P_NRD_CHECK) & B_NRD_CHK) ? 0 : 1; \
272 #define nrd_LED_on() epson_outb(P_NRD_LED, B_NRD_LED)
273 #define nrd_LED_off() epson_outb(P_NRD_LED, ~B_NRD_LED)
274 #define nrd_trac() ((int)(nrd_info(nrdaddr) & 0xff))
275 #define nrd_head() ((int)((nrd_info(nrdaddr) >> 8) & 0xff))
276 #define nrd_sec() ((int)(nrd_info(nrdaddr + 2) & 0xff))
277 #define nrd_secsize() ((int)((nrd_info(A_NRD_INFO) >> 8) & 0xff))
278 #define nrd_addrset(p) nrd_addr((nrd_t)((nrd_t)p+A_NRD_BASE))
284 epson_outb(P_NRD_ADDRH, (u_char)((addr >> 16) & 0x1f));
285 epson_outb(P_NRD_ADDRM, (u_char)((addr >> 8) & 0xff));
286 epson_outb(P_NRD_ADDRL, (u_char)(addr & 0xff));
289 static inline u_short
297 tmp = (short)inw(P_NRD_DATA);
299 return ((u_short)tmp);
301 #endif /* EPSON_NRDISK */
303 /***********************************************************************\
304 * Throughout this file the following conventions will be used: *
305 * fd is a pointer to the fd_data struct for the drive in question *
306 * fdc is a pointer to the fdc_data struct for the controller *
307 * fdu is the floppy drive unit number *
308 * fdcu is the floppy controller unit number *
309 * fdsu is the floppy drive unit number on that controller. (sub-unit) *
310 \***********************************************************************/
314 static int yeattach(struct isa_device *);
317 /* needed for ft driver, thus exported */
318 int in_fdc(struct fdc_data *);
319 int out_fdc(struct fdc_data *, int);
321 /* internal functions */
322 static void fdc_add_device(device_t, const char *, int);
323 static void fdc_intr(void *);
324 static void set_motor(struct fdc_data *, int, int);
327 static timeout_t fd_turnoff;
328 static timeout_t fd_motor_on;
329 static void fd_turnon(struct fd_data *);
330 static void fdc_reset(fdc_p);
331 static int fd_in(struct fdc_data *, int *);
332 static void fdstart(struct fdc_data *);
333 static timeout_t fd_iotimeout;
334 static timeout_t fd_pseudointr;
335 static int fdstate(struct fdc_data *);
336 static int retrier(struct fdc_data *);
337 static int fdformat(dev_t, struct fd_formb *, struct proc *);
339 static int enable_fifo(fdc_p fdc);
341 static int fifo_threshold = 8; /* XXX: should be accessible via sysctl */
347 #define SEEKCOMPLETE 3
349 #define RECALCOMPLETE 5
355 #define IOTIMEDOUT 11
356 #define RESETCOMPLETE 12
362 static char const * const fdstates[] =
382 /* CAUTION: fd_debug causes huge amounts of logging output */
383 static int volatile fd_debug = 0;
384 #define TRACE0(arg) if(fd_debug) printf(arg)
385 #define TRACE1(arg1, arg2) if(fd_debug) printf(arg1, arg2)
386 #else /* FDC_DEBUG */
388 #define TRACE1(arg1, arg2)
389 #endif /* FDC_DEBUG */
393 #include <sys/select.h>
394 #include <sys/module.h>
395 #include <pccard/cardinfo.h>
396 #include <pccard/driver.h>
397 #include <pccard/slot.h>
400 * PC-Card (PCMCIA) specific code.
402 static int yeinit(struct pccard_devinfo *); /* init device */
403 static void yeunload(struct pccard_devinfo *); /* Disable driver */
404 static int yeintr(struct pccard_devinfo *); /* Interrupt handler */
406 PCCARD_MODULE(fdc, yeinit, yeunload, yeintr, 0, bio_imask);
409 * this is the secret PIO data port (offset from base)
411 #define FDC_YE_DATAPORT 6
414 * Initialize the device - called from Slot manager.
416 static int yeinit(struct pccard_devinfo *devi)
418 fdc_p fdc = &fdc_data[devi->isahd.id_unit];
420 /* validate unit number. */
421 if (devi->isahd.id_unit >= NFDC)
423 fdc->baseport = devi->isahd.id_iobase;
427 outb(fdc->baseport+FDOUT, 0);
429 outb(fdc->baseport+FDOUT, FDO_FRST);
434 if (yeattach(&devi->isahd) == 0)
441 * yeunload - unload the driver and clear the table.
443 * This is usually called when the card is ejected, but
444 * can be caused by a modunload of a controller driver.
445 * The idea is to reset the driver's view of the device
446 * and ensure that any driver entry points such as
447 * read and write do not hang.
449 static void yeunload(struct pccard_devinfo *devi)
451 if (fd_data[devi->isahd.id_unit].type == NO_TYPE)
455 * this prevents Fdopen() and fdstrategy() from attempting
456 * to access unloaded controller
458 fd_data[devi->isahd.id_unit].type = NO_TYPE;
460 printf("fdc%d: unload\n", devi->isahd.id_unit);
464 * yeintr - Shared interrupt called from
465 * front end of PC-Card handler.
467 static int yeintr(struct pccard_devinfo *devi)
469 fdintr((fdcu_t)devi->isahd.id_unit);
472 #endif /* NCARD > 0 */
475 static d_open_t Fdopen; /* NOTE, not fdopen */
476 static d_close_t fdclose;
477 static d_ioctl_t fdioctl;
478 static d_strategy_t fdstrategy;
483 static struct cdevsw fd_cdevsw = {
487 /* write */ physwrite,
491 /* strategy */ fdstrategy,
493 /* maj */ CDEV_MAJOR,
497 /* bmaj */ BDEV_MAJOR
501 fdc_err(struct fdc_data *fdc, const char *s)
505 if (fdc->fdc_errs < FDC_ERRMAX) {
506 device_print_prettyname(fdc->fdc_dev);
508 } else if (fdc->fdc_errs == FDC_ERRMAX) {
509 device_print_prettyname(fdc->fdc_dev);
510 printf("too many errors, not logging any more\n");
518 * fd_cmd: Send a command to the chip. Takes a varargs with this structure:
520 * # of output bytes, output bytes as ints ...,
521 * # of input bytes, input bytes as ints ...
524 fd_cmd(struct fdc_data *fdc, int n_out, ...)
532 cmd = (u_char)(va_arg(ap, int));
535 for (n = 0; n < n_out; n++)
537 if (out_fdc(fdc, va_arg(ap, int)) < 0)
540 snprintf(msg, sizeof(msg),
541 "cmd %x failed at out byte %d of %d\n",
543 return fdc_err(fdc, msg);
546 n_in = va_arg(ap, int);
547 for (n = 0; n < n_in; n++)
549 int *ptr = va_arg(ap, int *);
550 if (fd_in(fdc, ptr) < 0)
553 snprintf(msg, sizeof(msg),
554 "cmd %02x failed at in byte %d of %d\n",
556 return fdc_err(fdc, msg);
564 enable_fifo(fdc_p fdc)
568 if ((fdc->flags & FDC_HAS_FIFO) == 0) {
572 * Cannot use fd_cmd the normal way here, since
573 * this might be an invalid command. Thus we send the
574 * first byte, and check for an early turn of data directon.
577 if (out_fdc(fdc, I8207X_CONFIGURE) < 0)
578 return fdc_err(fdc, "Enable FIFO failed\n");
580 /* If command is invalid, return */
582 while ((i = inb(fdc->baseport + FDSTS) & (NE7_DIO | NE7_RQM))
583 != NE7_RQM && j-- > 0)
584 if (i == (NE7_DIO | NE7_RQM)) {
590 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0) {
592 return fdc_err(fdc, "Enable FIFO failed\n");
594 fdc->flags |= FDC_HAS_FIFO;
598 I8207X_CONFIGURE, 0, (fifo_threshold - 1) & 0xf, 0, 0) < 0)
599 return fdc_err(fdc, "Re-enable FIFO failed\n");
604 fd_sense_drive_status(fdc_p fdc, int *st3p)
608 if (fd_cmd(fdc, 2, NE7CMD_SENSED, fdc->fdu, 1, &st3))
610 return fdc_err(fdc, "Sense Drive Status failed\n");
619 fd_sense_int(fdc_p fdc, int *st0p, int *cylp)
624 if (fdc->fdu == nrdu) {
625 if (fdc->fd->track >= 0) nrdaddr = (fdc->fd->track + 1) * 8;
627 *st0p = nrd_head() ? NRD_ST0_HD : NRD_STATUS;
631 #endif /* EPSON_NRDISK */
632 ret = fd_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
635 "sense intr err reading stat reg 0\n");
642 if ((st0 & NE7_ST0_IC) == NE7_ST0_IC_IV) {
644 * There doesn't seem to have been an interrupt.
649 if (fd_in(fdc, &cyl) < 0) {
650 return fdc_err(fdc, "can't get cyl num\n");
658 #endif /* EPSON_NRDISK */
664 fd_read_status(fdc_p fdc, int fdsu)
668 for (i = 0; i < 7; i++) {
670 * XXX types are poorly chosen. Only bytes can by read
671 * from the hardware, but fdc->status[] wants u_ints and
672 * fd_in() gives ints.
677 if (fdc->fdu == nrdu) {
679 case 0: fdc->status[i] = nrd_head()
680 ? NRD_ST0_HD : NRD_STATUS; break;
681 case 1: fdc->status[i] = NRD_STATUS; break;
682 case 2: fdc->status[i] = NRD_STATUS; break;
683 case 3: fdc->status[i] = nrd_trac(); break;
684 case 4: fdc->status[i] = nrd_head(); break;
685 case 5: fdc->status[i] = nrdsec; break;
686 case 6: fdc->status[i] = nrd_secsize(); break;
691 #endif /* EPSON_NRDISK */
692 ret = fd_in(fdc, &status);
693 fdc->status[i] = status;
698 #endif /* EPSON_NRDISK */
702 fdc->flags |= FDC_STAT_VALID;
704 fdc->flags &= ~FDC_STAT_VALID;
709 /****************************************************************************/
710 /* autoconfiguration stuff */
711 /****************************************************************************/
713 static int pc98_trans = 0; /* 0 : HD , 1 : DD , 2 : 1.44 */
714 static int pc98_trans_prev = 0;
716 static void set_density(fdc_p fdc)
718 /* always motor on */
719 outb(IO_FDPORT, (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
721 outb(fdc->baseport + FDOUT, FDO_RST | FDO_DMAE);
722 /* in the case of note W, always inhibit 100ms timer */
725 static int pc98_fd_check_ready(fdu_t fdu)
727 fd_p fd = devclass_get_softc(fd_devclass, fdu);
728 struct fdc_data *fdc = fd->fdc;
733 if (nrd_check_ready()) return 0;
737 while (retry++ < 30000) {
738 set_motor(fdc, fd->fdsu, TURNON);
739 out_fdc(fdc, NE7CMD_SENSED); /* Sense Drive Status */
741 out_fdc(fdc, fdu); /* Drive number */
743 if ((in_fdc(fdc) & NE7_ST3_RD)){
744 outb(fdc->baseport + FDOUT,
745 FDO_DMAE | FDO_MTON);
755 fdc_probe(device_t dev)
757 int error, i, ic_type;
758 struct fdc_data *fdc;
759 char myname[8]; /* better be long enough */
761 fdc = device_get_softc(dev);
762 bzero(fdc, sizeof *fdc);
764 fdc->rid_ioport = fdc->rid_irq = fdc->rid_drq = 0;
765 fdc->res_ioport = fdc->res_irq = fdc->res_drq = 0;
767 fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
768 &fdc->rid_ioport, 0ul, ~0ul,
769 IO_FDCSIZE, RF_ACTIVE);
770 if (fdc->res_ioport == 0) {
771 device_print_prettyname(dev);
772 printf("cannot reserve I/O port range\n");
776 fdc->baseport = fdc->res_ioport->r_start;
778 fdc->res_irq = bus_alloc_resource(dev, SYS_RES_IRQ,
779 &fdc->rid_irq, 0ul, ~0ul, 1,
781 if (fdc->res_irq == 0) {
782 device_print_prettyname(dev);
783 printf("cannot reserve interrupt line\n");
787 fdc->res_drq = bus_alloc_resource(dev, SYS_RES_DRQ,
788 &fdc->rid_drq, 0ul, ~0ul, 1,
790 if (fdc->res_drq == 0) {
791 device_print_prettyname(dev);
792 printf("cannot reserve DMA request line\n");
796 fdc->dmachan = fdc->res_drq->r_start;
797 error = BUS_SETUP_INTR(device_get_parent(dev), dev, fdc->res_irq,
798 INTR_TYPE_BIO, fdc_intr, fdc, &fdc->fdc_intr);
801 /* First - lets reset the floppy controller */
802 outb(fdc->baseport + FDOUT, 0);
804 outb(fdc->baseport + FDOUT, FDO_FRST);
807 /* see if it can handle a command */
809 if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
810 NE7_SPEC_2(2, 0), 0)) {
815 if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
816 NE7_SPEC_2(2, 0), 0)) {
823 if (fd_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type) == 0) {
824 ic_type = (u_char)ic_type;
827 device_set_desc(dev, "NEC 765 or clone");
828 fdc->fdct = FDC_NE765;
831 device_set_desc(dev, "Intel 82077 or clone");
832 fdc->fdct = FDC_I82077;
835 device_set_desc(dev, "NEC 72065B or clone");
836 fdc->fdct = FDC_NE72065;
839 device_set_desc(dev, "generic floppy controller");
840 fdc->fdct = FDC_UNKNOWN;
846 snprintf(myname, sizeof(myname), "%s%d", device_get_name(dev),
847 device_get_unit(dev));
848 for (i = resource_query_string(-1, "at", myname); i != -1;
849 i = resource_query_string(i, "at", myname))
850 fdc_add_device(dev, resource_query_name(i),
851 resource_query_unit(i));
854 * don't succeed on probe; wait
855 * for PCCARD subsystem to do it
857 if (dev->id_flags & FDC_IS_PCMCIA)
864 BUS_TEARDOWN_INTR(device_get_parent(dev), dev, fdc->res_irq,
866 if (fdc->res_irq != 0) {
867 bus_deactivate_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
869 bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
872 if (fdc->res_ioport != 0) {
873 bus_deactivate_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
875 bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
878 if (fdc->res_drq != 0) {
879 bus_deactivate_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
881 bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
888 * Aped dfr@freebsd.org's isa_add_device().
891 fdc_add_device(device_t dev, const char *name, int unit)
896 ivar = malloc(sizeof *ivar, M_DEVBUF /* XXX */, M_NOWAIT);
899 if (resource_int_value(name, unit, "drive", ivar) == 0)
901 child = device_add_child(dev, name, unit, ivar);
904 if (resource_int_value(name, unit, "disabled", &disabled) == 0)
905 device_disable(child);
909 fdc_attach(device_t dev)
911 struct fdc_data *fdc = device_get_softc(dev);
912 fdcu_t fdcu = device_get_unit(dev);
915 fdc->flags |= FDC_ATTACHED;
917 /* Acquire the DMA channel forever, The driver will do the rest */
918 /* XXX should integrate with rman */
919 isa_dma_acquire(fdc->dmachan);
920 isa_dmainit(fdc->dmachan, 128 << 3 /* XXX max secsize */);
921 fdc->state = DEVIDLE;
924 /* reset controller, turn motor off, clear fdout mirror reg */
927 /* reset controller, turn motor off, clear fdout mirror reg */
928 outb(fdc->baseport + FDOUT, ((fdc->fdout = 0)));
930 bufq_init(&fdc->head);
932 #ifdef FIFO_BEFORE_MOTORON
933 /* Hmm, this doesn't work here - is set_motor() magic? -Peter */
934 if (fdc->fdct != FDC_NE765 && fdc->fdct != FDC_UNKNOWN
935 && enable_fifo(fdc) == 0) {
936 device_print_prettyname(dev);
937 printf("FIFO enabled, %d bytes threshold\n", fifo_threshold);
941 * Probe and attach any children as were configured above.
943 return (bus_generic_attach(dev));
947 fdc_print_child(device_t me, device_t child)
951 retval += bus_print_child_header(me, child);
952 retval += printf(" on %s drive %d\n", device_get_nameunit(me),
953 *(int *)device_get_ivars(child));
959 fd_probe(device_t dev)
964 struct fdc_data *fdc;
966 #ifndef FIFO_BEFORE_MOTORON
967 static int fd_fifo = 0;
970 fdsu = *(int *)device_get_ivars(dev); /* xxx cheat a bit... */
971 fd = device_get_softc(dev);
972 fdc = device_get_softc(device_get_parent(dev));
974 bzero(fd, sizeof *fd);
978 fd->fdu = device_get_unit(dev);
981 /* look up what bios thinks we have */
983 case 0: case 1: case 2: case 3:
984 if ((PC98_SYSTEM_PARAMETER(0x5ae) >> fd->fdu) & 0x01)
987 else if ((PC98_SYSTEM_PARAMETER(0x55c) >> fd->fdu) & 0x01) {
989 switch (epson_machine_id) {
990 case 0x20: case 0x27:
991 if ((PC98_SYSTEM_PARAMETER(0x488) >> fd->fdu) & 0x01) {
992 if (nrd_check_ready()) {
1001 #else /* !EPSON_NRDISK */
1002 else if ((PC98_SYSTEM_PARAMETER(0x55c) >> fd->fdu) & 0x01) {
1004 switch (epson_machine_id) {
1005 case 0x20: case 0x27:
1006 if ((PC98_SYSTEM_PARAMETER(0x488) >> fd->fdu) & 0x01)
1010 #endif /* EPSON_NRDISK */
1019 /* look up what bios thinks we have */
1022 if (device_get_flags(fdc->fdc_dev) & FDC_PRETEND_D0)
1023 fdt = RTCFDT_144M | RTCFDT_144M_PRETENDED;
1025 fdt = (rtcin(RTC_FDISKETTE) & 0xf0);
1028 fdt = ((rtcin(RTC_FDISKETTE) << 4) & 0xf0);
1036 /* is there a unit? */
1038 if (fdt == FDT_NONE)
1041 if (fdt == RTCFDT_NONE)
1047 set_motor(fdc, fdsu, TURNON);
1048 DELAY(1000000); /* 1 sec */
1050 #ifndef FIFO_BEFORE_MOTORON
1051 if (fd_fifo == 0 && fdc->fdct != FDC_NE765 && fdc->fdct != FDC_UNKNOWN
1052 && enable_fifo(fdc) == 0) {
1053 device_print_prettyname(device_get_parent(dev));
1054 printf("FIFO enabled, %d bytes threshold\n", fifo_threshold);
1059 if ((fd_cmd(fdc, 2, NE7CMD_SENSED, fdsu, 1, &st3) == 0)
1060 && (st3 & NE7_ST3_T0)) {
1061 /* if at track 0, first seek inwards */
1062 /* seek some steps: */
1063 fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0);
1064 DELAY(300000); /* ...wait a moment... */
1065 fd_sense_int(fdc, 0, 0); /* make ctrlr happy */
1068 /* If we're at track 0 first seek inwards. */
1069 if ((fd_sense_drive_status(fdc, &st3) == 0) && (st3 & NE7_ST3_T0)) {
1070 /* Seek some steps... */
1071 if (fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
1072 /* ...wait a moment... */
1074 /* make ctrlr happy: */
1075 fd_sense_int(fdc, 0, 0);
1079 for (i = 0; i < 2; i++) {
1081 * we must recalibrate twice, just in case the
1082 * heads have been beyond cylinder 76, since most
1083 * FDCs still barf when attempting to recalibrate
1084 * more than 77 steps
1087 if (fd_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
1088 /* a second being enough for full stroke seek*/
1089 DELAY(i == 0 ? 1000000 : 300000);
1091 /* anything responding? */
1092 if (fd_sense_int(fdc, &st0, 0) == 0 &&
1093 (st0 & NE7_ST0_EC) == 0)
1094 break; /* already probed succesfully */
1098 set_motor(fdc, fdsu, TURNOFF);
1100 if (st0 & NE7_ST0_EC) /* no track 0 -> no drive present */
1104 fd->track = FD_NO_TRACK;
1108 callout_handle_init(&fd->toffhandle);
1109 callout_handle_init(&fd->tohandle);
1114 /* Check 3mode I/F */
1116 outb(0x4be, (fd->fdu << 5) | 0x10);
1117 if (!(inb(0x4be) & 0x01)) {
1118 device_set_desc(dev, "1.44M FDD");
1123 printf("Warning: can't control 3mode I/F, "
1124 "fallback to 2mode.\n"
1129 if (fd->fdu == nrdu) {
1130 device_set_desc(dev, "EPSON RAM DRIVE");
1134 device_set_desc(dev, "1M/640K FDD");
1144 device_set_desc(dev, "1200-KB 5.25\" drive");
1147 case RTCFDT_144M | RTCFDT_144M_PRETENDED:
1148 device_set_desc(dev, "config-pretended 1440-MB 3.5\" drive");
1152 device_set_desc(dev, "1440-KB 3.5\" drive");
1157 device_set_desc(dev, "2880-KB 3.5\" drive (in 1440-KB mode)");
1161 device_set_desc(dev, "360-KB 5.25\" drive");
1165 printf("720-KB 3.5\" drive");
1176 fd_attach(device_t dev)
1186 fd = device_get_softc(dev);
1188 make_dev(&fd_cdevsw, (fd->fdu << 6),
1189 UID_ROOT, GID_OPERATOR, 0640, "rfd%d", fd->fdu);
1191 for (i = 1; i < 1 + NUMDENS; i++) {
1193 * XXX this and the lookup in Fdopen() should be
1197 /* XXX any types are OK for PC-98 */
1205 if (i != FD_720 && i != FD_800 && i != FD_820)
1209 if (i != FD_360 && i != FD_720 && i != FD_800
1210 && i != FD_820 && i != FD_1200
1211 && i != FD_1440 && i != FD_1480)
1215 if (i != FD_720 && i != FD_800 && i != FD_820
1216 && i != FD_1200 && i != FD_1440
1217 && i != FD_1480 && i != FD_1720)
1223 typesize = fd_typesizes[i - 1];
1225 typesize = fd_types[i - 1].size / 2;
1227 * XXX all these conversions give bloated code and
1230 if (typesize == 1476)
1232 if (typesize == 1722)
1235 typemynor = mynor | i;
1237 devfs_add_devswf(&fd_cdevsw, typemynor, DV_BLK,
1238 UID_ROOT, GID_OPERATOR, 0640,
1239 "fd%d.%d", fd->fdu, typesize);
1241 devfs_add_devswf(&fd_cdevsw, typemynor, DV_CHR,
1242 UID_ROOT, GID_OPERATOR, 0640,
1243 "rfd%d.%d", fd->fdu, typesize);
1246 for (i = 0; i < MAXPARTITIONS; i++) {
1247 fd->bdevs[1 + NUMDENS + i] = devfs_makelink(fd->bdevs[0],
1248 "fd%d%c", fd->fdu, 'a' + i);
1249 fd->cdevs[1 + NUMDENS + i] =
1250 devfs_makelink(fd->cdevs[0],
1251 "rfd%d%c", fd->fdu, 'a' + i);
1255 * Export the drive to the devstat interface.
1257 devstat_add_entry(&fd->device_stats, device_get_name(dev),
1258 device_get_unit(dev), 512, DEVSTAT_NO_ORDERED_TAGS,
1259 DEVSTAT_TYPE_FLOPPY | DEVSTAT_TYPE_IF_OTHER,
1260 DEVSTAT_PRIORITY_FD);
1266 * this is a subset of fdattach() optimized for the Y-E Data
1267 * PCMCIA floppy drive.
1269 static int yeattach(struct isa_device *dev)
1271 fdcu_t fdcu = dev->id_unit;
1272 fdc_p fdc = fdc_data + fdcu;
1273 fdsu_t fdsu = 0; /* assume 1 drive per YE controller */
1284 * the FDC_PCMCIA flag is used to to indicate special PIO is used
1287 fdc->flags = FDC_ATTACHED|FDC_PCMCIA;
1288 fdc->state = DEVIDLE;
1289 /* reset controller, turn motor off, clear fdout mirror reg */
1290 outb(fdc->baseport + FDOUT, ((fdc->fdout = 0)));
1291 bufq_init(&fdc->head);
1293 * assume 2 drives/ "normal" controller
1297 printf("fdu %d >= NFD\n",fdu);
1302 set_motor(fdcu, fdsu, TURNON);
1303 DELAY(1000000); /* 1 sec */
1304 fdc->fdct = FDC_NE765;
1306 if ((fd_cmd(fdcu, 2, NE7CMD_SENSED, fdsu, 1, &st3) == 0) &&
1307 (st3 & NE7_ST3_T0)) {
1308 /* if at track 0, first seek inwards */
1309 /* seek some steps: */
1310 (void)fd_cmd(fdcu, 3, NE7CMD_SEEK, fdsu, 10, 0);
1311 DELAY(300000); /* ...wait a moment... */
1312 (void)fd_sense_int(fdc, 0, 0); /* make ctrlr happy */
1315 /* If we're at track 0 first seek inwards. */
1316 if ((fd_sense_drive_status(fdc, &st3) == 0) && (st3 & NE7_ST3_T0)) {
1317 /* Seek some steps... */
1318 if (fd_cmd(fdcu, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
1319 /* ...wait a moment... */
1321 /* make ctrlr happy: */
1322 (void)fd_sense_int(fdc, 0, 0);
1326 for(i = 0; i < 2; i++) {
1328 * we must recalibrate twice, just in case the
1329 * heads have been beyond cylinder 76, since most
1330 * FDCs still barf when attempting to recalibrate
1331 * more than 77 steps
1334 if (fd_cmd(fdcu, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
1335 /* a second being enough for full stroke seek*/
1336 DELAY(i == 0? 1000000: 300000);
1338 /* anything responding? */
1339 if (fd_sense_int(fdc, &st0, 0) == 0 &&
1340 (st0 & NE7_ST0_EC) == 0)
1341 break; /* already probed succesfully */
1345 set_motor(fdcu, fdsu, TURNOFF);
1347 if (st0 & NE7_ST0_EC) /* no track 0 -> no drive present */
1350 fd->track = FD_NO_TRACK;
1354 printf("fdc%d: 1.44MB 3.5in PCMCIA\n", fdcu);
1359 fd->bdevs[0] = devfs_add_devswf(&fd_cdevsw, mynor, DV_BLK,
1360 UID_ROOT, GID_OPERATOR, 0640,
1362 fd->cdevs[0] = devfs_add_devswf(&fd_cdevsw, mynor, DV_CHR,
1363 UID_ROOT, GID_OPERATOR, 0640,
1366 * XXX this and the lookup in Fdopen() should be
1369 typemynor = mynor | FD_1440;
1370 typesize = fd_types[FD_1440 - 1].size / 2;
1372 * XXX all these conversions give bloated code and
1375 if (typesize == 1476)
1377 if (typesize == 1722)
1379 fd->bdevs[FD_1440] = devfs_add_devswf(&fd_cdevsw, typemynor,
1380 DV_BLK, UID_ROOT, GID_OPERATOR,
1381 0640, "fd%d.%d", fdu, typesize);
1382 fd->cdevs[FD_1440] = devfs_add_devswf(&fd_cdevsw, typemynor,
1383 DV_CHR, UID_ROOT, GID_OPERATOR,
1384 0640,"rfd%d.%d", fdu, typesize);
1385 for (i = 0; i < MAXPARTITIONS; i++) {
1386 fd->bdevs[1 + NUMDENS + i] = devfs_makelink(fd->bdevs[0],
1387 "fd%d%c", fdu, 'a' + i);
1388 fd->cdevs[1 + NUMDENS + i] = devfs_makelink(fd->cdevs[0],
1389 "rfd%d%c", fdu, 'a' + i);
1396 /****************************************************************************/
1397 /* motor control stuff */
1398 /* remember to not deselect the drive we're working on */
1399 /****************************************************************************/
1401 set_motor(struct fdc_data *fdc, int fdsu, int turnon)
1403 int fdout = fdc->fdout;
1404 int needspecify = 0;
1407 outb(IO_FDPORT, (pc98_trans != 1 ? FDP_FDDEXC : 0)|FDP_PORTEXC);
1409 fdout = FDO_DMAE|FDO_MTON;
1412 fdout &= ~FDO_FDSEL;
1413 fdout |= (FDO_MOEN0 << fdsu) + fdsu;
1415 fdout &= ~(FDO_MOEN0 << fdsu);
1418 && (fdout & (FDO_MOEN0+FDO_MOEN1+FDO_MOEN2+FDO_MOEN3)) == 0)
1419 /* gonna turn off the last drive, put FDC to bed */
1420 fdout &= ~ (FDO_FRST|FDO_FDMAEN);
1422 /* make sure controller is selected and specified */
1423 if((fdout & (FDO_FRST|FDO_FDMAEN)) == 0)
1425 fdout |= (FDO_FRST|FDO_FDMAEN);
1429 outb(fdc->baseport+FDOUT, fdout);
1431 TRACE1("[0x%x->FDOUT]", fdout);
1436 * special case: since we have just woken up the FDC
1437 * from its sleep, we silently assume the command will
1438 * be accepted, and do not test for a timeout
1441 (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
1442 NE7_SPEC_1(4, 240), NE7_SPEC_2(2, 0),
1445 (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
1446 NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
1449 if (fdc->flags & FDC_HAS_FIFO)
1450 (void) enable_fifo(fdc);
1455 fd_turnoff(void *xfd)
1460 TRACE1("[fd%d: turnoff]", fd->fdu);
1463 * Don't turn off the motor yet if the drive is active.
1464 * XXX shouldn't even schedule turnoff until drive is inactive
1465 * and nothing is queued on it.
1467 if (fd->fdc->state != DEVIDLE && fd->fdc->fdu == fd->fdu) {
1468 fd->toffhandle = timeout(fd_turnoff, fd, 4 * hz);
1473 fd->flags &= ~FD_MOTOR;
1474 set_motor(fd->fdc, fd->fdsu, TURNOFF);
1479 fd_motor_on(void *xfd)
1485 fd->flags &= ~FD_MOTOR_WAIT;
1486 if((fd->fdc->fd == fd) && (fd->fdc->state == MOTORWAIT))
1496 if(!(fd->flags & FD_MOTOR))
1498 fd->flags |= (FD_MOTOR + FD_MOTOR_WAIT);
1499 set_motor(fd->fdc, fd->fdsu, TURNON);
1500 timeout(fd_motor_on, fd, hz); /* in 1 sec its ok */
1505 fdc_reset(fdc_p fdc)
1507 /* Try a reset, keep motor on */
1510 if (pc98_machine_type & M_EPSON_PC98)
1511 outb(fdc->baseport + FDOUT, 0xe8);
1513 outb(fdc->baseport + FDOUT, 0xd8);
1515 outb(fdc->baseport + FDOUT, 0x18);
1518 outb(fdc->baseport + FDOUT, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
1519 TRACE1("[0x%x->FDOUT]", fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
1521 /* enable FDC, but defer interrupts a moment */
1522 outb(fdc->baseport + FDOUT, fdc->fdout & ~FDO_FDMAEN);
1523 TRACE1("[0x%x->FDOUT]", fdc->fdout & ~FDO_FDMAEN);
1525 outb(fdc->baseport + FDOUT, fdc->fdout);
1526 TRACE1("[0x%x->FDOUT]", fdc->fdout);
1529 /* XXX after a reset, silently believe the FDC will accept commands */
1531 (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
1532 NE7_SPEC_1(4, 240), NE7_SPEC_2(2, 0),
1535 (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
1536 NE7_SPEC_1(3, 240), NE7_SPEC_2(2, 0),
1539 if (fdc->flags & FDC_HAS_FIFO)
1540 (void) enable_fifo(fdc);
1543 /****************************************************************************/
1545 /****************************************************************************/
1547 in_fdc(struct fdc_data *fdc)
1549 int baseport = fdc->baseport;
1551 while ((i = inb(baseport+FDSTS) & (NE7_DIO|NE7_RQM))
1552 != (NE7_DIO|NE7_RQM) && j-- > 0)
1554 return fdc_err(fdc, "ready for output in input\n");
1556 return fdc_err(fdc, bootverbose? "input ready timeout\n": 0);
1558 i = inb(baseport+FDDATA);
1559 TRACE1("[FDDATA->0x%x]", (unsigned char)i);
1561 #else /* !FDC_DEBUG */
1562 return inb(baseport+FDDATA);
1563 #endif /* FDC_DEBUG */
1567 * fd_in: Like in_fdc, but allows you to see if it worked.
1570 fd_in(struct fdc_data *fdc, int *ptr)
1572 int baseport = fdc->baseport;
1574 while ((i = inb(baseport+FDSTS) & (NE7_DIO|NE7_RQM))
1575 != (NE7_DIO|NE7_RQM) && j-- > 0)
1577 return fdc_err(fdc, "ready for output in input\n");
1579 return fdc_err(fdc, bootverbose? "input ready timeout\n": 0);
1581 i = inb(baseport+FDDATA);
1582 TRACE1("[FDDATA->0x%x]", (unsigned char)i);
1585 #else /* !FDC_DEBUG */
1586 i = inb(baseport+FDDATA);
1590 #endif /* FDC_DEBUG */
1594 out_fdc(struct fdc_data *fdc, int x)
1596 int baseport = fdc->baseport;
1599 /* Check that the direction bit is set */
1601 while ((inb(baseport+FDSTS) & NE7_DIO) && i-- > 0);
1602 if (i <= 0) return fdc_err(fdc, "direction bit not set\n");
1604 /* Check that the floppy controller is ready for a command */
1606 while ((inb(baseport+FDSTS) & NE7_RQM) == 0 && i-- > 0);
1608 return fdc_err(fdc, bootverbose? "output ready timeout\n": 0);
1610 /* Send the command and return */
1611 outb(baseport+FDDATA, x);
1612 TRACE1("[0x%x->FDDATA]", x);
1616 /****************************************************************************/
1617 /* fdopen/fdclose */
1618 /****************************************************************************/
1620 Fdopen(dev_t dev, int flags, int mode, struct proc *p)
1622 fdu_t fdu = FDUNIT(minor(dev));
1623 int type = FDTYPE(minor(dev));
1628 if ((fd = devclass_get_softc(fd_devclass, fdu)) == 0)
1631 if ((fdc == NULL) || (fd->type == NO_TYPE))
1637 type = FD_1200; /* XXX backward compatibility */
1639 ; /* XXX any types are OK for PC-98 */
1641 if (pc98_fd_check_ready(fdu) == -1)
1648 * For each type of basic drive, make sure we are trying
1649 * to open a type it can do,
1651 if (type != fd->type) {
1664 type = FD_1480in5_25;
1667 type = FD_1440in5_25;
1670 type = FD_820in5_25;
1673 type = FD_800in5_25;
1676 type = FD_720in5_25;
1679 type = FD_360in5_25;
1686 if ( type != FD_1720
1699 fd->ft = fd_types + type - 1;
1700 fd->flags |= FD_OPEN;
1701 device_busy(fd->dev);
1702 device_busy(fd->fdc->fdc_dev);
1707 fdclose(dev_t dev, int flags, int mode, struct proc *p)
1709 fdu_t fdu = FDUNIT(minor(dev));
1712 fd = devclass_get_softc(fd_devclass, fdu);
1713 fd->flags &= ~FD_OPEN;
1714 fd->options &= ~FDOPT_NORETRY;
1719 /****************************************************************************/
1721 /****************************************************************************/
1723 fdstrategy(struct buf *bp)
1725 unsigned nblocks, blknum, cando;
1732 fdu = FDUNIT(minor(bp->b_dev));
1733 fd = devclass_get_softc(fd_devclass, fdu);
1735 panic("fdstrategy: buf for nonexistent device (%#lx, %#lx)",
1736 (u_long)major(bp->b_dev), (u_long)minor(bp->b_dev));
1739 if (fd->type == NO_TYPE) {
1740 bp->b_error = ENXIO;
1741 bp->b_flags |= B_ERROR;
1743 * I _refuse_ to use a goto
1750 fdblk = 128 << (fd->ft->secsize);
1751 if (!(bp->b_flags & B_FORMAT)) {
1752 if (bp->b_blkno < 0) {
1754 "fd%d: fdstrat: bad request blkno = %lu, bcount = %ld\n",
1755 fdu, (u_long)bp->b_blkno, bp->b_bcount);
1756 bp->b_error = EINVAL;
1757 bp->b_flags |= B_ERROR;
1760 if ((bp->b_bcount % fdblk) != 0) {
1761 bp->b_error = EINVAL;
1762 bp->b_flags |= B_ERROR;
1768 * Set up block calculations.
1770 if (bp->b_blkno > 20000000) {
1772 * Reject unreasonably high block number, prevent the
1773 * multiplication below from overflowing.
1775 bp->b_error = EINVAL;
1776 bp->b_flags |= B_ERROR;
1779 blknum = (unsigned) bp->b_blkno * DEV_BSIZE/fdblk;
1780 nblocks = fd->ft->size;
1782 if (blknum + (bp->b_bcount / fdblk) > nblocks) {
1783 if (blknum <= nblocks) {
1784 cando = (nblocks - blknum) * fdblk;
1785 bp->b_resid = bp->b_bcount - cando;
1787 goto bad; /* not actually bad but EOF */
1789 bp->b_error = EINVAL;
1790 bp->b_flags |= B_ERROR;
1794 bp->b_pblkno = bp->b_blkno;
1796 bufqdisksort(&fdc->head, bp);
1797 untimeout(fd_turnoff, fd, fd->toffhandle); /* a good idea */
1799 /* Tell devstat we are starting on the transaction */
1800 devstat_start_transaction(&fd->device_stats);
1810 /***************************************************************\
1812 * We have just queued something.. if the controller is not busy *
1813 * then simulate the case where it has just finished a command *
1814 * So that it (the interrupt routine) looks on the queue for more*
1815 * work to do and picks up what we just added. *
1816 * If the controller is already busy, we need do nothing, as it *
1817 * will pick up our work when the present work completes *
1818 \***************************************************************/
1820 fdstart(struct fdc_data *fdc)
1825 if(fdc->state == DEVIDLE)
1833 fd_iotimeout(void *xfdc)
1839 TRACE1("fd%d[fd_iotimeout()]", fdc->fdu);
1842 * Due to IBM's brain-dead design, the FDC has a faked ready
1843 * signal, hardwired to ready == true. Thus, any command
1844 * issued if there's no diskette in the drive will _never_
1845 * complete, and must be aborted by resetting the FDC.
1846 * Many thanks, Big Blue!
1847 * The FDC must not be reset directly, since that would
1848 * interfere with the state machine. Instead, pretend that
1849 * the command completed but was invalid. The state machine
1850 * will reset the FDC and retry once.
1853 fdc->status[0] = NE7_ST0_IC_IV;
1854 fdc->flags &= ~FDC_STAT_VALID;
1855 fdc->state = IOTIMEDOUT;
1860 /* just ensure it has the right spl */
1862 fd_pseudointr(void *xfdc)
1871 /***********************************************************************\
1873 * keep calling the state machine until it returns a 0 *
1874 * ALWAYS called at SPLBIO *
1875 \***********************************************************************/
1877 fdc_intr(void *xfdc)
1886 * magic pseudo-DMA initialization for YE FDC. Sets count and
1889 #define SET_BCDR(wr,cnt,port) outb(port,(((cnt)-1) & 0xff)); \
1890 outb(port+1,((wr ? 0x80 : 0) | ((((cnt)-1) >> 8) & 0x7f)))
1893 * fdcpio(): perform programmed IO read/write for YE PCMCIA floppy
1895 static int fdcpio(fdcu_t fdcu, long flags, caddr_t addr, u_int count)
1897 u_char *cptr = (u_char *)addr;
1898 fdc_p fdc = &fdc_data[fdcu];
1899 int io = fdc->baseport;
1901 if (flags & B_READ) {
1902 if (fdc->state != PIOREAD) {
1903 fdc->state = PIOREAD;
1906 SET_BCDR(0,count,io);
1907 insb(io+FDC_YE_DATAPORT,cptr,count);
1909 outsb(io+FDC_YE_DATAPORT,cptr,count);
1910 SET_BCDR(0,count,io);
1916 /***********************************************************************\
1917 * The controller state machine. *
1918 * if it returns a non zero value, it should be called again immediatly *
1919 \***********************************************************************/
1923 int read, format, head, i, sec = 0, sectrac, st0, cyl, st3;
1924 unsigned blknum = 0, b_cylinder = 0;
1925 fdu_t fdu = fdc->fdu;
1927 register struct buf *bp;
1928 struct fd_formb *finfo = NULL;
1933 bp = bufq_first(&fdc->head);
1935 bufq_remove(&fdc->head, bp);
1940 /***********************************************\
1941 * nothing left for this controller to do *
1942 * Force into the IDLE state, *
1943 \***********************************************/
1944 fdc->state = DEVIDLE;
1946 device_print_prettyname(fdc->fdc_dev);
1947 printf("unexpected valid fd pointer\n");
1951 TRACE1("[fdc%d IDLE]", fdc->fdcu);
1954 fdu = FDUNIT(minor(bp->b_dev));
1955 fd = devclass_get_softc(fd_devclass, fdu);
1956 fdblk = 128 << fd->ft->secsize;
1957 if (fdc->fd && (fd != fdc->fd)) {
1958 device_print_prettyname(fd->dev);
1959 printf("confused fd pointers\n");
1961 read = bp->b_flags & B_READ;
1962 format = bp->b_flags & B_FORMAT;
1964 finfo = (struct fd_formb *)bp->b_data;
1965 fd->skip = (char *)&(finfo->fd_formb_cylno(0))
1968 if (fdc->state == DOSEEK || fdc->state == SEEKCOMPLETE) {
1969 blknum = (unsigned) bp->b_pblkno * DEV_BSIZE/fdblk +
1971 b_cylinder = blknum / (fd->ft->sectrac * fd->ft->heads);
1973 TRACE1("fd%d", fdu);
1974 TRACE1("[%s]", fdstates[fdc->state]);
1975 TRACE1("(0x%x)", fd->flags);
1976 untimeout(fd_turnoff, fd, fd->toffhandle);
1977 fd->toffhandle = timeout(fd_turnoff, fd, 4 * hz);
1981 case FINDWORK: /* we have found new work */
1987 pc98_trans = fd->ft->trans;
1988 if (pc98_trans_prev != pc98_trans) {
1991 for (i = 0; i < 10; i++) {
1995 pc98_trans_prev = pc98_trans;
1997 if (pc98_trans != fd->pc98_trans) {
1998 if (fd->type == FD_1440) {
1999 outb(0x4be, (fdu << 5) | 0x10 | (pc98_trans >> 1));
2003 fd->pc98_trans = pc98_trans;
2006 outb(fdc->baseport+FDCTL, fd->ft->trans);
2008 TRACE1("[0x%x->FDCTL]", fd->ft->trans);
2009 /*******************************************************\
2010 * If the next drive has a motor startup pending, then *
2011 * it will start up in its own good time *
2012 \*******************************************************/
2013 if(fd->flags & FD_MOTOR_WAIT) {
2014 fdc->state = MOTORWAIT;
2015 return (0); /* come back later */
2017 /*******************************************************\
2018 * Maybe if it's not starting, it SHOULD be starting *
2019 \*******************************************************/
2022 if (!(fd->flags & FD_MOTOR))
2024 fdc->state = MOTORWAIT;
2028 else /* at least make sure we are selected */
2030 set_motor(fdcu, fd->fdsu, TURNON);
2033 #else /* !EPSON_NRDISK */
2034 if (!(fd->flags & FD_MOTOR))
2036 fdc->state = MOTORWAIT;
2040 else /* at least make sure we are selected */
2042 set_motor(fdc, fd->fdsu, TURNON);
2045 if (fdc->flags & FDC_NEEDS_RESET) {
2046 fdc->state = RESETCTLR;
2047 fdc->flags &= ~FDC_NEEDS_RESET;
2049 fdc->state = DOSEEK;
2052 if (b_cylinder == (unsigned)fd->track)
2054 fdc->state = SEEKCOMPLETE;
2058 pc98_fd_check_ready(fdu);
2060 if (fd_cmd(fdc, 3, NE7CMD_SEEK,
2061 fd->fdsu, b_cylinder * fd->ft->steptrac,
2065 * seek command not accepted, looks like
2066 * the FDC went off to the Saints...
2068 fdc->retry = 6; /* try a reset */
2069 return(retrier(fdc));
2071 fd->track = FD_NO_TRACK;
2072 fdc->state = SEEKWAIT;
2073 return(0); /* will return later */
2075 /* allow heads to settle */
2076 timeout(fd_pseudointr, fdc, hz / 16);
2077 fdc->state = SEEKCOMPLETE;
2078 return(0); /* will return later */
2079 case SEEKCOMPLETE : /* SEEK DONE, START DMA */
2080 /* Make sure seek really happened*/
2081 if(fd->track == FD_NO_TRACK) {
2082 int descyl = b_cylinder * fd->ft->steptrac;
2085 * This might be a "ready changed" interrupt,
2086 * which cannot really happen since the
2087 * RDY pin is hardwired to + 5 volts. This
2088 * generally indicates a "bouncing" intr
2089 * line, so do one of the following:
2091 * When running on an enhanced FDC that is
2092 * known to not go stuck after responding
2093 * with INVALID, fetch all interrupt states
2094 * until seeing either an INVALID or a
2095 * real interrupt condition.
2097 * When running on a dumb old NE765, give
2098 * up immediately. The controller will
2099 * provide up to four dummy RC interrupt
2100 * conditions right after reset (for the
2101 * corresponding four drives), so this is
2102 * our only chance to get notice that it
2103 * was not the FDC that caused the interrupt.
2105 if (fd_sense_int(fdc, &st0, &cyl)
2108 if(fdc->fdct == FDC_NE765
2109 && (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
2110 return 0; /* hope for a real intr */
2111 } while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
2116 * seek to cyl 0 requested; make sure we are
2119 if (fd_sense_drive_status(fdc, &st3))
2122 if (fdu == nrdu) st3 = NE7_ST3_T0;
2123 #endif /* EPSON_NRDISK */
2124 if ((st3 & NE7_ST3_T0) == 0) {
2126 "fd%d: Seek to cyl 0, but not really there (ST3 = %b)\n",
2127 fdu, st3, NE7_ST3BITS);
2134 return (retrier(fdc));
2138 if (fdu == nrdu) cyl = descyl;
2141 if (cyl != descyl) {
2143 "fd%d: Seek to cyl %d failed; am at cyl %d (ST0 = 0x%x)\n",
2144 fdu, descyl, cyl, st0);
2147 return (retrier(fdc));
2151 fd->track = b_cylinder;
2154 #endif /* EPSON_NRDISK */
2156 if (!(fdc->flags & FDC_PCMCIA))
2158 isa_dmastart(bp->b_flags, bp->b_data+fd->skip,
2159 format ? bp->b_bcount : fdblk, fdc->dmachan);
2160 sectrac = fd->ft->sectrac;
2161 sec = blknum % (sectrac * fd->ft->heads);
2162 head = sec / sectrac;
2163 sec = sec % sectrac + 1;
2164 fd->hddrv = ((head&1)<<2)+fdu;
2168 /* make sure the drive is writable */
2169 if(fd_sense_drive_status(fdc, &st3) != 0)
2171 /* stuck controller? */
2172 isa_dmadone(bp->b_flags, bp->b_data + fd->skip,
2173 format ? bp->b_bcount : fdblk,
2175 fdc->retry = 6; /* reset the beast */
2176 return (retrier(fdc));
2178 if(st3 & NE7_ST3_WP)
2181 * XXX YES! this is ugly.
2182 * in order to force the current operation
2183 * to fail, we will have to fake an FDC
2184 * error - all error handling is done
2187 fdc->status[0] = NE7_ST0_IC_AT;
2188 fdc->status[1] = NE7_ST1_NW;
2190 fdc->status[3] = fd->track;
2191 fdc->status[4] = head;
2192 fdc->status[5] = sec;
2193 fdc->retry = 8; /* break out immediately */
2194 fdc->state = IOTIMEDOUT; /* not really... */
2201 if (fdc->flags & FDC_PCMCIA)
2202 (void)fdcpio(fdcu,bp->b_flags,
2203 bp->b_data+fd->skip,
2207 if(fd_cmd(fdc, 6, NE7CMD_FORMAT, head << 2 | fdu,
2208 finfo->fd_formb_secshift,
2209 finfo->fd_formb_nsecs,
2210 finfo->fd_formb_gaplen,
2211 finfo->fd_formb_fillbyte, 0)) {
2212 /* controller fell over */
2213 isa_dmadone(bp->b_flags, bp->b_data + fd->skip,
2214 format ? bp->b_bcount : fdblk,
2217 return (retrier(fdc));
2221 if (fdc->flags & FDC_PCMCIA) {
2223 * this seems to be necessary even when
2226 SET_BCDR(1,fdblk,fdc->baseport);
2229 * perform the write pseudo-DMA before
2230 * the WRITE command is sent
2233 (void)fdcpio(fdcu,bp->b_flags,
2234 bp->b_data+fd->skip,
2239 (read ? NE7CMD_READ : NE7CMD_WRITE),
2240 head << 2 | fdu, /* head & unit */
2241 fd->track, /* track */
2243 sec, /* sector + 1 */
2244 fd->ft->secsize, /* sector size */
2245 sectrac, /* sectors/track */
2246 fd->ft->gap, /* gap size */
2247 fd->ft->datalen, /* data length */
2249 /* the beast is sleeping again */
2250 isa_dmadone(bp->b_flags, bp->b_data + fd->skip,
2251 format ? bp->b_bcount : fdblk,
2254 return (retrier(fdc));
2258 if (fdc->flags & FDC_PCMCIA)
2260 * if this is a read, then simply await interrupt
2261 * before performing PIO
2263 if (read && !fdcpio(fdcu,bp->b_flags,
2264 bp->b_data+fd->skip,fdblk)) {
2265 fd->tohandle = timeout(fd_iotimeout,
2267 return(0); /* will return later */
2271 * write (or format) operation will fall through and
2272 * await completion interrupt
2275 fdc->state = IOCOMPLETE;
2276 fd->tohandle = timeout(fd_iotimeout, fdc, hz);
2277 return (0); /* will return later */
2281 nrdblkn = (nrd_t)((unsigned long)bp->b_blkno*DEV_BSIZE/fdblk
2284 nrd_addrset(fdblk * nrdblkn);
2285 while (!nrd_check_ready()) DELAY(1);
2286 if (read) epson_insw(P_NRD_DATA,
2287 bp->b_data + fd->skip,
2288 fdblk / sizeof(short));
2289 else epson_outsw(P_NRD_DATA,
2290 bp->b_data + fd->skip,
2291 (format ? bp->b_bcount : fdblk)
2294 blknum = (unsigned long)bp->b_blkno*DEV_BSIZE/fdblk
2296 sectrac = fd->ft->sectrac;
2297 sec = blknum % (sectrac * fd->ft->heads);
2298 head = sec / sectrac;
2299 sec = sec % sectrac + 1;
2300 fd->hddrv = ((head&1)<<2)+fdu;
2302 if (nrdsec++ >= nrd_sec())
2303 nrdaddr = (nrd_t)(fd->track * 8 + head * 4);
2305 fdc->state = IOCOMPLETE;
2311 * actually perform the PIO read. The IOCOMPLETE case
2312 * removes the timeout for us.
2314 (void)fdcpio(fdcu,bp->b_flags,bp->b_data+fd->skip,fdblk);
2315 fdc->state = IOCOMPLETE;
2318 case IOCOMPLETE: /* IO DONE, post-analyze */
2321 untimeout(fd_iotimeout, fdc, fd->tohandle);
2323 untimeout(fd_iotimeout, fdc, fd->tohandle);
2326 if (fd_read_status(fdc, fd->fdsu)) {
2327 isa_dmadone(bp->b_flags, bp->b_data + fd->skip,
2328 format ? bp->b_bcount : fdblk,
2331 fdc->retry = 6; /* force a reset */
2332 return (retrier(fdc));
2335 fdc->state = IOTIMEDOUT;
2342 #endif /* EPSON_NRDISK */
2344 if (!(fdc->flags & FDC_PCMCIA))
2346 isa_dmadone(bp->b_flags, bp->b_data + fd->skip,
2347 format ? bp->b_bcount : fdblk, fdc->dmachan);
2351 #endif /* EPSON_NRDISK */
2352 if (fdc->status[0] & NE7_ST0_IC) {
2353 if ((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
2354 && fdc->status[1] & NE7_ST1_OR) {
2356 * DMA overrun. Someone hogged the bus
2357 * and didn't release it in time for the
2358 * next FDC transfer.
2359 * Just restart it, don't increment retry
2362 fdc->state = SEEKCOMPLETE;
2365 else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_IV
2367 fdc->retry = 6; /* force a reset */
2368 else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
2369 && fdc->status[2] & NE7_ST2_WC
2371 fdc->retry = 3; /* force recalibrate */
2372 return (retrier(fdc));
2376 if (!format && fd->skip < bp->b_bcount - bp->b_resid) {
2377 /* set up next transfer */
2378 fdc->state = DOSEEK;
2383 devstat_end_transaction_buf(&fd->device_stats, bp);
2387 fdc->state = FINDWORK;
2393 fdc->state = RESETCOMPLETE;
2397 * Discard all the results from the reset so that they
2398 * can't cause an unexpected interrupt later.
2400 for (i = 0; i < 4; i++)
2401 (void)fd_sense_int(fdc, &st0, &cyl);
2402 fdc->state = STARTRECAL;
2406 pc98_fd_check_ready(fdu);
2408 if(fd_cmd(fdc, 2, NE7CMD_RECAL, fdu, 0)) {
2411 return (retrier(fdc));
2413 fdc->state = RECALWAIT;
2414 return (0); /* will return later */
2416 /* allow heads to settle */
2417 timeout(fd_pseudointr, fdc, hz / 8);
2418 fdc->state = RECALCOMPLETE;
2419 return (0); /* will return later */
2423 * See SEEKCOMPLETE for a comment on this:
2425 if (fd_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
2427 if(fdc->fdct == FDC_NE765
2428 && (st0 & NE7_ST0_IC) == NE7_ST0_IC_RC)
2429 return 0; /* hope for a real intr */
2430 } while ((st0 & NE7_ST0_IC) == NE7_ST0_IC_RC);
2433 st0 = NE7_ST0_IC_NT;
2437 if ((st0 & NE7_ST0_IC) != NE7_ST0_IC_NT || cyl != 0)
2441 * a recalibrate from beyond cylinder 77
2442 * will "fail" due to the FDC limitations;
2443 * since people used to complain much about
2444 * the failure message, try not logging
2445 * this one if it seems to be the first
2448 printf("fd%d: recal failed ST0 %b cyl %d\n",
2449 fdu, st0, NE7_ST0BITS, cyl);
2450 if(fdc->retry < 3) fdc->retry = 3;
2451 return (retrier(fdc));
2454 /* Seek (probably) necessary */
2455 fdc->state = DOSEEK;
2456 return (1); /* will return immediatly */
2458 if(fd->flags & FD_MOTOR_WAIT)
2460 return (0); /* time's not up yet */
2462 if (fdc->flags & FDC_NEEDS_RESET) {
2463 fdc->state = RESETCTLR;
2464 fdc->flags &= ~FDC_NEEDS_RESET;
2467 * If all motors were off, then the controller was
2468 * reset, so it has lost track of the current
2469 * cylinder. Recalibrate to handle this case.
2470 * But first, discard the results of the reset.
2472 fdc->state = RESETCOMPLETE;
2474 return (1); /* will return immediatly */
2476 device_print_prettyname(fdc->fdc_dev);
2477 printf("unexpected FD int->");
2478 if (fd_read_status(fdc, fd->fdsu) == 0)
2479 printf("FDC status :%x %x %x %x %x %x %x ",
2488 printf("No status available ");
2489 if (fd_sense_int(fdc, &st0, &cyl) != 0)
2491 printf("[controller is dead now]\n");
2494 printf("ST0 = %x, PCN = %x\n", st0, cyl);
2497 /*XXX confusing: some branches return immediately, others end up here*/
2498 return (1); /* Come back immediatly to new state */
2502 retrier(struct fdc_data *fdc)
2504 register struct buf *bp;
2510 /* XXX shouldn't this be cached somewhere? */
2511 fdu = FDUNIT(minor(bp->b_dev));
2512 fd = devclass_get_softc(fd_devclass, fdu);
2513 if (fd->options & FDOPT_NORETRY)
2516 switch (fdc->retry) {
2517 case 0: case 1: case 2:
2518 fdc->state = SEEKCOMPLETE;
2520 case 3: case 4: case 5:
2521 fdc->state = STARTRECAL;
2524 fdc->state = RESETCTLR;
2531 dev_t sav_b_dev = bp->b_dev;
2533 bp->b_dev = makedev(major(bp->b_dev),
2534 (FDUNIT(minor(bp->b_dev))<<3)|RAW_PART);
2535 diskerr(bp, "hard error", LOG_PRINTF,
2536 fdc->fd->skip / DEV_BSIZE,
2537 (struct disklabel *)NULL);
2538 bp->b_dev = sav_b_dev;
2539 if (fdc->flags & FDC_STAT_VALID)
2542 " (ST0 %b ST1 %b ST2 %b cyl %u hd %u sec %u)\n",
2543 fdc->status[0], NE7_ST0BITS,
2544 fdc->status[1], NE7_ST1BITS,
2545 fdc->status[2], NE7_ST2BITS,
2546 fdc->status[3], fdc->status[4],
2550 printf(" (No status)\n");
2552 bp->b_flags |= B_ERROR;
2554 bp->b_resid += bp->b_bcount - fdc->fd->skip;
2557 devstat_end_transaction_buf(&fdc->fd->device_stats, bp);
2559 fdc->state = FINDWORK;
2560 fdc->flags |= FDC_NEEDS_RESET;
2570 fdformat(dev, finfo, p)
2572 struct fd_formb *finfo;
2582 fdu = FDUNIT(minor(dev));
2583 fd = devclass_get_softc(fd_devclass, fdu);
2584 fdblk = 128 << fd->ft->secsize;
2586 /* set up a buffer header for fdstrategy() */
2587 bp = (struct buf *)malloc(sizeof(struct buf), M_TEMP, M_NOWAIT);
2591 * keep the process from being swapped
2594 bzero((void *)bp, sizeof(struct buf));
2596 BUF_LOCK(bp, LK_EXCLUSIVE);
2597 bp->b_flags = B_PHYS | B_FORMAT;
2600 * calculate a fake blkno, so fdstrategy() would initiate a
2601 * seek to the requested cylinder
2603 bp->b_blkno = (finfo->cyl * (fd->ft->sectrac * fd->ft->heads)
2604 + finfo->head * fd->ft->sectrac) * fdblk / DEV_BSIZE;
2606 bp->b_bcount = sizeof(struct fd_idfield_data) * finfo->fd_formb_nsecs;
2607 bp->b_data = (caddr_t)finfo;
2609 /* now do the format */
2611 BUF_STRATEGY(bp, 0);
2613 /* ...and wait for it to complete */
2615 while(!(bp->b_flags & B_DONE)) {
2616 rv = tsleep((caddr_t)bp, PRIBIO, "fdform", 20 * hz);
2617 if (rv == EWOULDBLOCK)
2622 if (rv == EWOULDBLOCK) {
2627 if (bp->b_flags & B_ERROR)
2630 * allow the process to be swapped
2640 * TODO: don't allocate buffer on stack.
2644 fdioctl(dev, cmd, addr, flag, p)
2651 fdu_t fdu = FDUNIT(minor(dev));
2652 fd_p fd = devclass_get_softc(fd_devclass, fdu);
2655 struct fd_type *fdt;
2656 struct disklabel *dl;
2657 char buffer[DEV_BSIZE];
2660 fdblk = 128 << fd->ft->secsize;
2663 pc98_fd_check_ready(fdu);
2667 bzero(buffer, sizeof (buffer));
2668 dl = (struct disklabel *)buffer;
2669 dl->d_secsize = fdblk;
2671 dl->d_secpercyl = fdt->size / fdt->tracks;
2672 dl->d_type = DTYPE_FLOPPY;
2674 if (readdisklabel(dkmodpart(dev, RAW_PART), dl)
2680 *(struct disklabel *)addr = *dl;
2684 if ((flag & FWRITE) == 0)
2689 if ((flag & FWRITE) == 0)
2694 if ((flag & FWRITE) == 0) {
2699 dl = (struct disklabel *)addr;
2701 if ((error = setdisklabel((struct disklabel *)buffer, dl,
2705 error = writedisklabel(dev, (struct disklabel *)buffer);
2708 if ((flag & FWRITE) == 0)
2709 error = EBADF; /* must be opened for writing */
2710 else if (((struct fd_formb *)addr)->format_version !=
2712 error = EINVAL; /* wrong version of formatting prog */
2714 error = fdformat(dev, (struct fd_formb *)addr, p);
2717 case FD_GTYPE: /* get drive type */
2718 *(struct fd_type *)addr = *fd->ft;
2721 case FD_STYPE: /* set drive type */
2722 /* this is considered harmful; only allow for superuser */
2725 *fd->ft = *(struct fd_type *)addr;
2728 case FD_GOPTS: /* get drive options */
2729 *(int *)addr = fd->options;
2732 case FD_SOPTS: /* set drive options */
2733 fd->options = *(int *)addr;
2743 static device_method_t fdc_methods[] = {
2744 /* Device interface */
2745 DEVMETHOD(device_probe, fdc_probe),
2746 DEVMETHOD(device_attach, fdc_attach),
2747 DEVMETHOD(device_detach, bus_generic_detach),
2748 DEVMETHOD(device_shutdown, bus_generic_shutdown),
2749 DEVMETHOD(device_suspend, bus_generic_suspend),
2750 DEVMETHOD(device_resume, bus_generic_resume),
2753 DEVMETHOD(bus_print_child, fdc_print_child),
2754 /* Our children never use any other bus interface methods. */
2759 static driver_t fdc_driver = {
2762 sizeof(struct fdc_data)
2765 DRIVER_MODULE(fdc, isa, fdc_driver, fdc_devclass, 0, 0);
2767 static device_method_t fd_methods[] = {
2768 /* Device interface */
2769 DEVMETHOD(device_probe, fd_probe),
2770 DEVMETHOD(device_attach, fd_attach),
2771 DEVMETHOD(device_detach, bus_generic_detach),
2772 DEVMETHOD(device_shutdown, bus_generic_shutdown),
2773 DEVMETHOD(device_suspend, bus_generic_suspend), /* XXX */
2774 DEVMETHOD(device_resume, bus_generic_resume), /* XXX */
2779 static driver_t fd_driver = {
2782 sizeof(struct fd_data)
2785 DEV_DRIVER_MODULE(fd, fdc, fd_driver, fd_devclass, fd_cdevsw, 0, 0);
2787 #endif /* NFDC > 0 */
2790 * Hello emacs, these are the
2793 * c-continued-statement-offset: 8
2794 * c-continued-brace-offset: 0
2795 * c-brace-offset: -8
2796 * c-brace-imaginary-offset: 0
2797 * c-argdecl-indent: 8
2798 * c-label-offset: -8
2799 * c++-hanging-braces: 1
2800 * c++-access-specifier-offset: -8
2801 * c++-empty-arglist-indent: 8
2802 * c++-friend-offset: 0