fdc_pnpbios.c revision 1.2.4.1 1 1.2.4.1 nathanw /* $NetBSD: fdc_pnpbios.c,v 1.2.4.1 2002/01/08 00:25:44 nathanw Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.1 thorpej * must display the following acknowledgement:
20 1.1 thorpej * This product includes software developed by the NetBSD
21 1.1 thorpej * Foundation, Inc. and its contributors.
22 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 thorpej * contributors may be used to endorse or promote products derived
24 1.1 thorpej * from this software without specific prior written permission.
25 1.1 thorpej *
26 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej /*
40 1.1 thorpej * PNPBIOS attachment for the PC Floppy Controller driver.
41 1.1 thorpej */
42 1.2.4.1 nathanw
43 1.2.4.1 nathanw #include <sys/cdefs.h>
44 1.2.4.1 nathanw __KERNEL_RCSID(0, "$NetBSD: fdc_pnpbios.c,v 1.2.4.1 2002/01/08 00:25:44 nathanw Exp $");
45 1.1 thorpej
46 1.1 thorpej #include "rnd.h"
47 1.1 thorpej
48 1.1 thorpej #include <sys/param.h>
49 1.1 thorpej #include <sys/systm.h>
50 1.1 thorpej #include <sys/callout.h>
51 1.1 thorpej #include <sys/device.h>
52 1.1 thorpej #include <sys/buf.h>
53 1.1 thorpej #include <sys/queue.h>
54 1.1 thorpej #if NRND > 0
55 1.1 thorpej #include <sys/rnd.h>
56 1.1 thorpej #endif
57 1.1 thorpej
58 1.1 thorpej #include <machine/bus.h>
59 1.1 thorpej #include <machine/intr.h>
60 1.1 thorpej
61 1.1 thorpej #include <dev/isa/isavar.h>
62 1.1 thorpej #include <dev/isa/isadmavar.h>
63 1.1 thorpej
64 1.1 thorpej #include <dev/isa/fdcvar.h>
65 1.1 thorpej
66 1.1 thorpej #include <i386/pnpbios/pnpbiosvar.h>
67 1.1 thorpej
68 1.1 thorpej int fdc_pnpbios_match(struct device *, struct cfdata *, void *);
69 1.1 thorpej void fdc_pnpbios_attach(struct device *, struct device *, void *);
70 1.1 thorpej
71 1.2 jmc struct fdc_pnpbios_softc {
72 1.2 jmc struct fdc_softc sc_fdc; /* base fdc device */
73 1.2 jmc
74 1.2 jmc bus_space_handle_t sc_baseioh; /* base I/O handle */
75 1.2 jmc };
76 1.2 jmc
77 1.2 jmc
78 1.1 thorpej struct cfattach fdc_pnpbios_ca = {
79 1.2 jmc sizeof(struct fdc_pnpbios_softc), fdc_pnpbios_match,
80 1.1 thorpej fdc_pnpbios_attach,
81 1.1 thorpej };
82 1.1 thorpej
83 1.1 thorpej int
84 1.1 thorpej fdc_pnpbios_match(struct device *parent,
85 1.1 thorpej struct cfdata *match,
86 1.1 thorpej void *aux)
87 1.1 thorpej {
88 1.1 thorpej struct pnpbiosdev_attach_args *aa = aux;
89 1.1 thorpej
90 1.1 thorpej if (strcmp(aa->idstr, "PNP0700") == 0)
91 1.1 thorpej return (1);
92 1.1 thorpej
93 1.1 thorpej return (0);
94 1.1 thorpej }
95 1.1 thorpej
96 1.1 thorpej void
97 1.1 thorpej fdc_pnpbios_attach(struct device *parent,
98 1.1 thorpej struct device *self,
99 1.1 thorpej void *aux)
100 1.1 thorpej {
101 1.1 thorpej struct fdc_softc *fdc = (void *) self;
102 1.2 jmc struct fdc_pnpbios_softc *pdc = (void *) self;
103 1.1 thorpej struct pnpbiosdev_attach_args *aa = aux;
104 1.2 jmc int size, base;
105 1.2 jmc
106 1.1 thorpej printf("\n");
107 1.1 thorpej
108 1.1 thorpej fdc->sc_ic = aa->ic;
109 1.1 thorpej
110 1.2 jmc if (pnpbios_io_map(aa->pbt, aa->resc, 0, &fdc->sc_iot,
111 1.2 jmc &pdc->sc_baseioh)) {
112 1.1 thorpej printf("%s: unable to map I/O space\n", fdc->sc_dev.dv_xname);
113 1.1 thorpej return;
114 1.1 thorpej }
115 1.1 thorpej
116 1.2 jmc /*
117 1.2 jmc * Start accounting for "odd" pnpbios's. Some probe as 4 ports,
118 1.2 jmc * some as 6 and some don't give the ctl port back.
119 1.2 jmc */
120 1.2 jmc
121 1.2 jmc if (pnpbios_getiosize(aa->pbt, aa->resc, 0, &size)) {
122 1.2 jmc printf("%s: can't get iobase size\n", fdc->sc_dev.dv_xname);
123 1.2 jmc return;
124 1.2 jmc }
125 1.2 jmc
126 1.2 jmc switch (size) {
127 1.2 jmc
128 1.2 jmc /* Easy case. This matches right up with what the fdc code expects. */
129 1.2 jmc case 4:
130 1.2 jmc fdc->sc_ioh = pdc->sc_baseioh;
131 1.2 jmc break;
132 1.2 jmc
133 1.2 jmc /* Map a subregion so this all lines up with the fdc code. */
134 1.2 jmc case 6:
135 1.2 jmc if (bus_space_subregion(fdc->sc_iot, pdc->sc_baseioh, 2, 4,
136 1.2 jmc &fdc->sc_ioh)) {
137 1.2 jmc printf("%s: unable to subregion I/O space\n",
138 1.2 jmc fdc->sc_dev.dv_xname);
139 1.2 jmc return;
140 1.2 jmc }
141 1.2 jmc break;
142 1.2 jmc default:
143 1.2 jmc printf ("%s: unknown size: %d of io mapping\n",
144 1.2 jmc fdc->sc_dev.dv_xname, size);
145 1.2 jmc return;
146 1.2 jmc }
147 1.2 jmc
148 1.2 jmc /*
149 1.2 jmc * XXX: This is bad. If the pnpbios claims only 1 I/O range then it's
150 1.2 jmc * omitting the controller I/O port. (One has to exist for there to
151 1.2 jmc * be a working fdc). Just try and force the mapping in.
152 1.2 jmc */
153 1.2 jmc
154 1.2 jmc if (aa->resc->numio == 1) {
155 1.2 jmc
156 1.2 jmc if (pnpbios_getiobase(aa->pbt, aa->resc, 0, 0, &base)) {
157 1.2 jmc printf ("%s: can't get iobase\n",
158 1.2 jmc fdc->sc_dev.dv_xname);
159 1.2 jmc return;
160 1.2 jmc }
161 1.2 jmc if (bus_space_map(fdc->sc_iot, base + size + 1, 1, 0,
162 1.2 jmc &fdc->sc_fdctlioh)) {
163 1.2 jmc printf("%s: unable to force map CTL I/O space\n",
164 1.2 jmc fdc->sc_dev.dv_xname);
165 1.2 jmc return;
166 1.2 jmc }
167 1.2 jmc } else if (pnpbios_io_map(aa->pbt, aa->resc, 1, &fdc->sc_iot,
168 1.2 jmc &fdc->sc_fdctlioh)) {
169 1.2 jmc printf("%s: unable to map CTL I/O space\n",
170 1.1 thorpej fdc->sc_dev.dv_xname);
171 1.1 thorpej return;
172 1.1 thorpej }
173 1.1 thorpej
174 1.1 thorpej if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &fdc->sc_drq)) {
175 1.1 thorpej printf("%s: unable to get DMA channel\n",
176 1.1 thorpej fdc->sc_dev.dv_xname);
177 1.1 thorpej return;
178 1.1 thorpej }
179 1.1 thorpej
180 1.1 thorpej pnpbios_print_devres(self, aa);
181 1.2 jmc if (aa->resc->numio == 1)
182 1.2 jmc printf("%s: ctl io %x didn't probe. Forced attach\n",
183 1.2 jmc fdc->sc_dev.dv_xname, base + size + 1);
184 1.1 thorpej
185 1.1 thorpej fdc->sc_ih = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_BIO,
186 1.1 thorpej fdcintr, fdc);
187 1.1 thorpej
188 1.1 thorpej fdcattach(fdc);
189 1.1 thorpej }
190