1 /* $NetBSD: fdc_pnpbios.c,v 1.14 2008/04/28 20:23:25 martin Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * PNPBIOS attachment for the PC Floppy Controller driver.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: fdc_pnpbios.c,v 1.14 2008/04/28 20:23:25 martin Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/callout.h>
44 #include <sys/device.h>
46 #include <sys/queue.h>
51 #include <machine/bus.h>
52 #include <machine/intr.h>
54 #include <dev/isa/isavar.h>
55 #include <dev/isa/isadmavar.h>
57 #include <dev/isa/fdcvar.h>
59 #include <i386/pnpbios/pnpbiosvar.h>
61 int fdc_pnpbios_match(device_t
, cfdata_t
, void *);
62 void fdc_pnpbios_attach(device_t
, device_t
, void *);
64 struct fdc_pnpbios_softc
{
65 struct fdc_softc sc_fdc
; /* base fdc device */
67 bus_space_handle_t sc_baseioh
; /* base I/O handle */
71 CFATTACH_DECL_NEW(fdc_pnpbios
, sizeof(struct fdc_pnpbios_softc
),
72 fdc_pnpbios_match
, fdc_pnpbios_attach
, NULL
, NULL
);
75 fdc_pnpbios_match(device_t parent
, cfdata_t match
, void *aux
)
77 struct pnpbiosdev_attach_args
*aa
= aux
;
79 if (strcmp(aa
->idstr
, "PNP0700") == 0)
86 fdc_pnpbios_attach(device_t parent
, device_t self
, void *aux
)
88 struct fdc_pnpbios_softc
*pdc
= device_private(self
);
89 struct fdc_softc
*fdc
= &pdc
->sc_fdc
;
90 struct pnpbiosdev_attach_args
*aa
= aux
;
98 if (pnpbios_io_map(aa
->pbt
, aa
->resc
, 0, &fdc
->sc_iot
,
100 aprint_error_dev(self
, "unable to map I/O space\n");
105 * Start accounting for "odd" pnpbios's. Some probe as 4 ports,
106 * some as 6 and some don't give the ctl port back.
109 if (pnpbios_getiosize(aa
->pbt
, aa
->resc
, 0, &size
)) {
110 aprint_error_dev(self
, "can't get iobase size\n");
116 /* Easy case. This matches right up with what the fdc code expects. */
118 fdc
->sc_ioh
= pdc
->sc_baseioh
;
121 /* Map a subregion so this all lines up with the fdc code. */
123 if (bus_space_subregion(fdc
->sc_iot
, pdc
->sc_baseioh
, 2, 4,
125 aprint_error_dev(self
,
126 "unable to subregion I/O space\n");
131 aprint_error_dev(self
, "unknown size: %d of io mapping\n", size
);
136 * XXX: This is bad. If the pnpbios claims only 1 I/O range then it's
137 * omitting the controller I/O port. (One has to exist for there to
138 * be a working fdc). Just try and force the mapping in.
141 if (aa
->resc
->numio
== 1) {
143 if (pnpbios_getiobase(aa
->pbt
, aa
->resc
, 0, 0, &base
)) {
144 aprint_error_dev(self
, "can't get iobase\n");
147 if (bus_space_map(fdc
->sc_iot
, base
+ size
+ 1, 1, 0,
148 &fdc
->sc_fdctlioh
)) {
149 aprint_error_dev(self
,
150 "unable to force map CTL I/O space\n");
153 } else if (pnpbios_io_map(aa
->pbt
, aa
->resc
, 1, &fdc
->sc_iot
,
154 &fdc
->sc_fdctlioh
)) {
155 aprint_error_dev(self
, "unable to map CTL I/O space\n");
159 if (pnpbios_getdmachan(aa
->pbt
, aa
->resc
, 0, &fdc
->sc_drq
)) {
160 aprint_error_dev(self
, "unable to get DMA channel\n");
164 pnpbios_print_devres(self
, aa
);
165 if (aa
->resc
->numio
== 1)
166 aprint_error_dev(self
,
167 "ctl io %x didn't probe. Forced attach\n",
170 fdc
->sc_ih
= pnpbios_intr_establish(aa
->pbt
, aa
->resc
, 0, IPL_BIO
,