pciide.c revision 1.6 1 1.6 cgd /* $NetBSD: pciide.c,v 1.6 1998/03/12 23:34:29 cgd Exp $ */
2 1.1 cgd
3 1.1 cgd /*
4 1.1 cgd * Copyright (c) 1996, 1998 Christopher G. Demetriou. All rights reserved.
5 1.1 cgd *
6 1.1 cgd * Redistribution and use in source and binary forms, with or without
7 1.1 cgd * modification, are permitted provided that the following conditions
8 1.1 cgd * are met:
9 1.1 cgd * 1. Redistributions of source code must retain the above copyright
10 1.1 cgd * notice, this list of conditions and the following disclaimer.
11 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer in the
13 1.1 cgd * documentation and/or other materials provided with the distribution.
14 1.1 cgd * 3. All advertising materials mentioning features or use of this software
15 1.1 cgd * must display the following acknowledgement:
16 1.1 cgd * This product includes software developed by Christopher G. Demetriou
17 1.1 cgd * for the NetBSD Project.
18 1.1 cgd * 4. The name of the author may not be used to endorse or promote products
19 1.1 cgd * derived from this software without specific prior written permission
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 cgd * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 cgd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 cgd * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 cgd * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 cgd * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 cgd * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 cgd * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 cgd * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 cgd * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 cgd */
32 1.1 cgd
33 1.1 cgd /*
34 1.1 cgd * PCI IDE controller driver.
35 1.1 cgd *
36 1.1 cgd * Author: Christopher G. Demetriou, March 2, 1998 (derived from NetBSD
37 1.1 cgd * sys/dev/pci/ppb.c, revision 1.16).
38 1.1 cgd *
39 1.2 cgd * See "PCI IDE Controller Specification, Revision 1.0 3/4/94" and
40 1.2 cgd * "Programming Interface for Bus Master IDE Controller, Revision 1.0
41 1.2 cgd * 5/16/94" from the PCI SIG.
42 1.1 cgd *
43 1.2 cgd * XXX Does not yet support DMA (but does map the Bus Master DMA regs).
44 1.1 cgd *
45 1.1 cgd * XXX Does not support serializing the two channels for broken (at least
46 1.1 cgd * XXX according to linux and freebsd) controllers, e.g. CMD PCI0640.
47 1.1 cgd */
48 1.1 cgd
49 1.1 cgd #include <sys/param.h>
50 1.1 cgd #include <sys/systm.h>
51 1.1 cgd #include <sys/device.h>
52 1.1 cgd
53 1.1 cgd #include <dev/pci/pcireg.h>
54 1.1 cgd #include <dev/pci/pcivar.h>
55 1.1 cgd #include <dev/pci/pciidereg.h>
56 1.1 cgd #include <dev/pci/pciidevar.h>
57 1.6 cgd #include <dev/ic/wdcreg.h>
58 1.1 cgd
59 1.1 cgd struct pciide_softc {
60 1.1 cgd struct device sc_dev;
61 1.1 cgd
62 1.1 cgd void *sc_pci_ih; /* PCI interrupt handle */
63 1.5 cgd int sc_dma_ok; /* bus-master DMA info */
64 1.2 cgd bus_space_tag_t sc_dma_iot;
65 1.2 cgd bus_space_handle_t sc_dma_ioh;
66 1.1 cgd
67 1.1 cgd struct pciide_channel { /* per-channel data */
68 1.1 cgd /* internal bookkeeping */
69 1.5 cgd int hw_ok; /* hardware mapped & OK? */
70 1.1 cgd struct device *dev; /* 'wdc' dev attached */
71 1.1 cgd int compat; /* is it compat? */
72 1.1 cgd void *ih; /* compat or pci handle */
73 1.1 cgd
74 1.1 cgd /* used by wdc attachment (read-only after init) */
75 1.1 cgd bus_space_tag_t cmd_iot, ctl_iot;
76 1.1 cgd bus_space_handle_t cmd_ioh, ctl_ioh;
77 1.1 cgd
78 1.1 cgd /* filled in by wdc attachment (written by wdc attach) */
79 1.1 cgd int (*ihand) __P((void *));
80 1.1 cgd void *ihandarg;
81 1.2 cgd } sc_channels[PCIIDE_NUM_CHANNELS];
82 1.1 cgd };
83 1.1 cgd
84 1.1 cgd #define PCIIDE_CHANNEL_NAME(chan) ((chan) == 0 ? "primary" : "secondary")
85 1.1 cgd
86 1.1 cgd #ifdef __BROKEN_INDIRECT_CONFIG
87 1.1 cgd int pciide_match __P((struct device *, void *, void *));
88 1.1 cgd #else
89 1.1 cgd int pciide_match __P((struct device *, struct cfdata *, void *));
90 1.1 cgd #endif
91 1.1 cgd void pciide_attach __P((struct device *, struct device *, void *));
92 1.1 cgd
93 1.1 cgd struct cfattach pciide_ca = {
94 1.1 cgd sizeof(struct pciide_softc), pciide_match, pciide_attach
95 1.1 cgd };
96 1.1 cgd
97 1.5 cgd int pciide_map_channel_compat __P((struct pciide_softc *,
98 1.5 cgd struct pci_attach_args *, int));
99 1.6 cgd const char *pciide_compat_channel_probe __P((struct pciide_softc *,
100 1.5 cgd struct pci_attach_args *, int));
101 1.6 cgd int pciide_probe_wdc __P((struct pciide_channel *));
102 1.5 cgd int pciide_map_channel_native __P((struct pciide_softc *,
103 1.5 cgd struct pci_attach_args *, int));
104 1.5 cgd int pciide_print __P((void *, const char *pnp));
105 1.1 cgd int pciide_compat_intr __P((void *));
106 1.1 cgd int pciide_pci_intr __P((void *));
107 1.1 cgd
108 1.6 cgd #define PCIIDE_PROBE_WDC_DELAY 100 /* 100us each */
109 1.6 cgd #define PCIIDE_PROBE_WDC_NDELAY 10000 /* wait up to 1s */
110 1.6 cgd
111 1.1 cgd int
112 1.1 cgd pciide_match(parent, match, aux)
113 1.1 cgd struct device *parent;
114 1.1 cgd #ifdef __BROKEN_INDIRECT_CONFIG
115 1.1 cgd void *match;
116 1.1 cgd #else
117 1.1 cgd struct cfdata *match;
118 1.1 cgd #endif
119 1.1 cgd void *aux;
120 1.1 cgd {
121 1.1 cgd struct pci_attach_args *pa = aux;
122 1.1 cgd
123 1.1 cgd /*
124 1.1 cgd * Check the ID register to see that it's a PCI IDE controller.
125 1.1 cgd * If it is, we assume that we can deal with it; it _should_
126 1.1 cgd * work in a standardized way...
127 1.1 cgd */
128 1.1 cgd if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
129 1.1 cgd PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
130 1.1 cgd return (1);
131 1.1 cgd }
132 1.1 cgd
133 1.1 cgd return (0);
134 1.1 cgd }
135 1.1 cgd
136 1.1 cgd void
137 1.1 cgd pciide_attach(parent, self, aux)
138 1.1 cgd struct device *parent, *self;
139 1.1 cgd void *aux;
140 1.1 cgd {
141 1.1 cgd struct pci_attach_args *pa = aux;
142 1.1 cgd pci_chipset_tag_t pc = pa->pa_pc;
143 1.1 cgd struct pciide_softc *sc = (struct pciide_softc *)self;
144 1.1 cgd struct pciide_attach_args aa;
145 1.1 cgd struct pciide_channel *cp;
146 1.1 cgd pcireg_t class, interface, csr;
147 1.1 cgd pci_intr_handle_t intrhandle;
148 1.1 cgd const char *intrstr;
149 1.1 cgd char devinfo[256];
150 1.1 cgd int i;
151 1.1 cgd
152 1.1 cgd pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
153 1.1 cgd printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
154 1.1 cgd
155 1.1 cgd if ((pa->pa_flags & PCI_FLAGS_IO_ENABLED) == 0) {
156 1.1 cgd csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
157 1.1 cgd printf("%s: device disabled (at %s)\n", sc->sc_dev.dv_xname,
158 1.1 cgd (csr & PCI_COMMAND_IO_ENABLE) == 0 ? "device" : "bridge");
159 1.1 cgd return;
160 1.1 cgd }
161 1.1 cgd
162 1.1 cgd class = pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG);
163 1.1 cgd interface = PCI_INTERFACE(class);
164 1.1 cgd
165 1.1 cgd /*
166 1.1 cgd * Set up PCI interrupt.
167 1.1 cgd *
168 1.1 cgd * If mapping fails, that's (probably) because there's no pin
169 1.1 cgd * set to intr, which is (probably) because it's a compat-only
170 1.1 cgd * device (or hard-wired in compatibility-only mode). Native-PCI
171 1.1 cgd * channels will complain later if the interrupt was needed.
172 1.1 cgd *
173 1.1 cgd * If establishment fails, that's (probably) some other problem.
174 1.1 cgd */
175 1.1 cgd if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
176 1.1 cgd pa->pa_intrline, &intrhandle) == 0) {
177 1.1 cgd intrstr = pci_intr_string(pa->pa_pc, intrhandle);
178 1.1 cgd sc->sc_pci_ih = pci_intr_establish(pa->pa_pc, intrhandle,
179 1.1 cgd IPL_BIO, pciide_pci_intr, sc);
180 1.1 cgd
181 1.1 cgd if (sc->sc_pci_ih != NULL) {
182 1.1 cgd printf("%s: using %s for native-PCI interrupt\n",
183 1.1 cgd sc->sc_dev.dv_xname,
184 1.1 cgd intrstr ? intrstr : "unknown interrupt");
185 1.1 cgd } else {
186 1.1 cgd printf("%s: couldn't establish native-PCI interrupt",
187 1.1 cgd sc->sc_dev.dv_xname);
188 1.1 cgd if (intrstr != NULL)
189 1.1 cgd printf(" at %s", intrstr);
190 1.1 cgd printf("\n");
191 1.1 cgd }
192 1.1 cgd }
193 1.1 cgd
194 1.2 cgd /*
195 1.2 cgd * Map DMA registers, if DMA is supported.
196 1.2 cgd *
197 1.5 cgd * Note that sc_dma_ok is the right variable to test to see if
198 1.5 cgd * DMA can * be done. If the interface doesn't support DMA,
199 1.5 cgd * sc_dma_ok * will never be non-zero. If the DMA regs couldn't
200 1.5 cgd * be mapped, it'll be zero. I.e., sc_dma_ok will only be
201 1.5 cgd * non-zero if the interface supports DMA and the registers
202 1.5 cgd * could be mapped.
203 1.4 cgd *
204 1.4 cgd * XXX Note that despite the fact that the Bus Master IDE specs
205 1.4 cgd * XXX say that "The bus master IDE functoin uses 16 bytes of IO
206 1.4 cgd * XXX space," some controllers (at least the United
207 1.4 cgd * XXX Microelectronics UM8886BF) place it in memory space.
208 1.4 cgd * XXX eventually, we should probably read the register and check
209 1.4 cgd * XXX which type it is. Either that or 'quirk' certain devices.
210 1.2 cgd */
211 1.2 cgd if (interface & PCIIDE_INTERFACE_BUS_MASTER_DMA) {
212 1.5 cgd sc->sc_dma_ok = (pci_mapreg_map(pa,
213 1.2 cgd PCIIDE_REG_BUS_MASTER_DMA, PCI_MAPREG_TYPE_IO, 0,
214 1.2 cgd &sc->sc_dma_iot, &sc->sc_dma_ioh, NULL, NULL) == 0);
215 1.3 cgd printf("%s: bus-master DMA support present, but unused (%s)\n",
216 1.2 cgd sc->sc_dev.dv_xname,
217 1.5 cgd sc->sc_dma_ok ? "no driver support" :
218 1.5 cgd "couldn't map registers");
219 1.1 cgd }
220 1.1 cgd
221 1.1 cgd for (i = 0; i < PCIIDE_NUM_CHANNELS; i++) {
222 1.2 cgd cp = &sc->sc_channels[i];
223 1.2 cgd
224 1.2 cgd printf("%s: %s channel %s to %s mode\n",
225 1.2 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(i),
226 1.2 cgd (interface & PCIIDE_INTERFACE_SETTABLE(i)) ?
227 1.2 cgd "configured" : "wired",
228 1.2 cgd (interface & PCIIDE_INTERFACE_PCI(i)) ? "native-PCI" :
229 1.2 cgd "compatibility");
230 1.1 cgd
231 1.5 cgd if (interface & PCIIDE_INTERFACE_PCI(i))
232 1.5 cgd cp->hw_ok = pciide_map_channel_native(sc, pa, i);
233 1.5 cgd else
234 1.5 cgd cp->hw_ok = pciide_map_channel_compat(sc, pa, i);
235 1.5 cgd if (!cp->hw_ok)
236 1.5 cgd continue;
237 1.5 cgd
238 1.5 cgd aa.channel = i;
239 1.5 cgd aa.cmd_iot = cp->cmd_iot;
240 1.5 cgd aa.cmd_ioh = cp->cmd_ioh;
241 1.5 cgd aa.ctl_iot = cp->ctl_iot;
242 1.5 cgd aa.ctl_ioh = cp->ctl_ioh;
243 1.5 cgd aa.ihandp = &cp->ihand;
244 1.5 cgd aa.ihandargp = &cp->ihandarg;
245 1.5 cgd cp->dev = config_found(self, &aa, pciide_print);
246 1.2 cgd
247 1.5 cgd /*
248 1.5 cgd * Note that if the 'wdc' device isn't configured,
249 1.5 cgd * the controller's resources are still marked as
250 1.5 cgd * being in use. This is a feature.
251 1.5 cgd */
252 1.5 cgd }
253 1.5 cgd }
254 1.5 cgd
255 1.5 cgd int
256 1.5 cgd pciide_map_channel_compat(sc, pa, chan)
257 1.5 cgd struct pciide_softc *sc;
258 1.5 cgd struct pci_attach_args *pa;
259 1.5 cgd int chan;
260 1.5 cgd {
261 1.5 cgd struct pciide_channel *cp = &sc->sc_channels[chan];
262 1.6 cgd const char *probe_fail_reason;
263 1.5 cgd int rv = 1;
264 1.5 cgd
265 1.5 cgd cp->compat = 1;
266 1.5 cgd
267 1.5 cgd cp->cmd_iot = pa->pa_iot;
268 1.5 cgd if (bus_space_map(cp->cmd_iot, PCIIDE_COMPAT_CMD_BASE(chan),
269 1.5 cgd PCIIDE_COMPAT_CMD_SIZE, 0, &cp->cmd_ioh) != 0) {
270 1.5 cgd printf("%s: couldn't map %s channel cmd regs\n",
271 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
272 1.5 cgd rv = 0;
273 1.5 cgd }
274 1.5 cgd
275 1.5 cgd cp->ctl_iot = pa->pa_iot;
276 1.5 cgd if (bus_space_map(cp->ctl_iot, PCIIDE_COMPAT_CTL_BASE(chan),
277 1.5 cgd PCIIDE_COMPAT_CTL_SIZE, 0, &cp->ctl_ioh) != 0) {
278 1.5 cgd printf("%s: couldn't map %s channel ctl regs\n",
279 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
280 1.5 cgd rv = 0;
281 1.5 cgd }
282 1.5 cgd
283 1.5 cgd /*
284 1.5 cgd * If we weren't able to map the device successfully,
285 1.5 cgd * we just give up now. Something else has already
286 1.5 cgd * occupied those ports, indicating that the device has
287 1.5 cgd * (probably) been completely disabled (by some nonstandard
288 1.5 cgd * mechanism).
289 1.5 cgd *
290 1.5 cgd * XXX If we successfully map some ports, but not others,
291 1.5 cgd * XXX it might make sense to unmap the ones that we mapped.
292 1.5 cgd */
293 1.5 cgd if (rv == 0)
294 1.5 cgd goto out;
295 1.5 cgd
296 1.5 cgd /*
297 1.5 cgd * If we were able to map the device successfully, try to
298 1.5 cgd * make sure that there's a wdc there and that it's
299 1.5 cgd * attributable to us.
300 1.5 cgd *
301 1.5 cgd * If there's not, then we assume that there's the device
302 1.5 cgd * has been disabled and that other devices are free to use
303 1.5 cgd * its ports.
304 1.5 cgd */
305 1.6 cgd probe_fail_reason = pciide_compat_channel_probe(sc, pa, chan);
306 1.6 cgd if (probe_fail_reason != NULL) {
307 1.6 cgd printf("%s: %s channel ignored (%s)\n", sc->sc_dev.dv_xname,
308 1.6 cgd PCIIDE_CHANNEL_NAME(chan), probe_fail_reason);
309 1.5 cgd rv = 0;
310 1.5 cgd
311 1.5 cgd bus_space_unmap(cp->cmd_iot, cp->cmd_ioh,
312 1.5 cgd PCIIDE_COMPAT_CMD_SIZE);
313 1.5 cgd bus_space_unmap(cp->ctl_iot, cp->ctl_ioh,
314 1.5 cgd PCIIDE_COMPAT_CTL_SIZE);
315 1.5 cgd
316 1.5 cgd goto out;
317 1.5 cgd }
318 1.5 cgd
319 1.5 cgd /*
320 1.5 cgd * If we're here, we were able to map the device successfully
321 1.5 cgd * and it really looks like there's a controller there.
322 1.5 cgd *
323 1.5 cgd * Unless those conditions are true, we don't map the
324 1.5 cgd * compatibility interrupt. The spec indicates that if a
325 1.5 cgd * channel is configured for compatibility mode and the PCI
326 1.5 cgd * device's I/O space is enabled, the channel will be enabled.
327 1.5 cgd * Hoewver, some devices seem to be able to disable invididual
328 1.5 cgd * compatibility channels (via non-standard mechanisms). If
329 1.5 cgd * the channel is disabled, the interrupt line can (probably)
330 1.5 cgd * be used by other devices (and may be assigned to other
331 1.5 cgd * devices by the BIOS). If we mapped the interrupt we might
332 1.5 cgd * conflict with another interrupt assignment.
333 1.5 cgd */
334 1.5 cgd cp->ih = pciide_machdep_compat_intr_establish(&sc->sc_dev, pa,
335 1.5 cgd chan, pciide_compat_intr, cp);
336 1.5 cgd if (cp->ih == NULL) {
337 1.5 cgd printf("%s: no compatibility interrupt for use by %s channel\n",
338 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
339 1.5 cgd rv = 0;
340 1.5 cgd }
341 1.5 cgd
342 1.5 cgd out:
343 1.5 cgd return (rv);
344 1.5 cgd }
345 1.5 cgd
346 1.6 cgd const char *
347 1.5 cgd pciide_compat_channel_probe(sc, pa, chan)
348 1.5 cgd struct pciide_softc *sc;
349 1.5 cgd struct pci_attach_args *pa;
350 1.5 cgd {
351 1.6 cgd pcireg_t csr;
352 1.6 cgd const char *failreason = NULL;
353 1.6 cgd
354 1.6 cgd /*
355 1.6 cgd * Check to see if something appears to be there.
356 1.6 cgd */
357 1.6 cgd if (!pciide_probe_wdc(&sc->sc_channels[chan])) {
358 1.6 cgd failreason = "not responding; disabled or no drives?";
359 1.6 cgd goto out;
360 1.6 cgd }
361 1.5 cgd
362 1.5 cgd /*
363 1.6 cgd * Now, make sure it's actually attributable to this PCI IDE
364 1.6 cgd * channel by trying to access the channel again while the
365 1.6 cgd * PCI IDE controller's I/O space is disabled. (If the
366 1.6 cgd * channel no longer appears to be there, it belongs to
367 1.6 cgd * this controller.) YUCK!
368 1.5 cgd */
369 1.6 cgd csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
370 1.6 cgd pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
371 1.6 cgd csr & ~PCI_COMMAND_IO_ENABLE);
372 1.6 cgd if (pciide_probe_wdc(&sc->sc_channels[chan]))
373 1.6 cgd failreason = "other hardware responding at addresses";
374 1.6 cgd pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, csr);
375 1.6 cgd
376 1.6 cgd out:
377 1.6 cgd return (failreason);
378 1.6 cgd }
379 1.6 cgd
380 1.6 cgd int
381 1.6 cgd pciide_probe_wdc(cp)
382 1.6 cgd struct pciide_channel *cp;
383 1.6 cgd {
384 1.6 cgd u_int8_t st0, st1;
385 1.6 cgd int timeout;
386 1.6 cgd
387 1.6 cgd /*
388 1.6 cgd * Sanity check to see if the wdc channel responds at all.
389 1.6 cgd * (Modeled on wdc_init_controller() and wdc_reset() in wdc.c.)
390 1.6 cgd *
391 1.6 cgd * Reset the channel, and make sure that it responds sanely
392 1.6 cgd * after it's been reset.
393 1.6 cgd */
394 1.6 cgd
395 1.6 cgd /* Reset the channel. */
396 1.6 cgd bus_space_write_1(cp->ctl_iot, cp->ctl_ioh, wd_aux_ctlr,
397 1.6 cgd WDCTL_RST | WDCTL_IDS);
398 1.6 cgd delay(1000);
399 1.6 cgd bus_space_write_1(cp->ctl_iot, cp->ctl_ioh, wd_aux_ctlr,
400 1.6 cgd WDCTL_IDS);
401 1.6 cgd delay(1000);
402 1.6 cgd (void)bus_space_read_1(cp->cmd_iot, cp->cmd_ioh, wd_error);
403 1.6 cgd
404 1.6 cgd timeout = 0;
405 1.6 cgd while (timeout++ < PCIIDE_PROBE_WDC_NDELAY) {
406 1.6 cgd st0 = bus_space_read_1(cp->cmd_iot, cp->cmd_ioh, wd_status);
407 1.6 cgd bus_space_write_1(cp->cmd_iot, cp->cmd_ioh, wd_sdh,
408 1.6 cgd WDSD_IBM | 0x10);
409 1.6 cgd st1 = bus_space_read_1(cp->cmd_iot, cp->cmd_ioh, wd_status);
410 1.6 cgd
411 1.6 cgd if ((st0 & WDCS_BSY) == 0 || (st1 & WDCS_BSY) == 0)
412 1.6 cgd return (1);
413 1.6 cgd
414 1.6 cgd delay(PCIIDE_PROBE_WDC_DELAY);
415 1.6 cgd }
416 1.6 cgd /* timed out; nothing there */
417 1.6 cgd
418 1.6 cgd return (0);
419 1.5 cgd }
420 1.5 cgd
421 1.5 cgd int
422 1.5 cgd pciide_map_channel_native(sc, pa, chan)
423 1.5 cgd struct pciide_softc *sc;
424 1.5 cgd struct pci_attach_args *pa;
425 1.5 cgd int chan;
426 1.5 cgd {
427 1.5 cgd struct pciide_channel *cp = &sc->sc_channels[chan];
428 1.5 cgd int rv = 1;
429 1.5 cgd
430 1.5 cgd cp->compat = 0;
431 1.5 cgd
432 1.5 cgd if (pci_mapreg_map(pa, PCIIDE_REG_CMD_BASE(chan), PCI_MAPREG_TYPE_IO,
433 1.5 cgd 0, &cp->cmd_iot, &cp->cmd_ioh, NULL, NULL) != 0) {
434 1.5 cgd printf("%s: couldn't map %s channel cmd regs\n",
435 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
436 1.5 cgd rv = 0;
437 1.5 cgd }
438 1.5 cgd
439 1.5 cgd if (pci_mapreg_map(pa, PCIIDE_REG_CTL_BASE(chan), PCI_MAPREG_TYPE_IO,
440 1.5 cgd 0, &cp->ctl_iot, &cp->ctl_ioh, NULL, NULL) != 0) {
441 1.5 cgd printf("%s: couldn't map %s channel ctl regs\n",
442 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
443 1.5 cgd rv = 0;
444 1.5 cgd }
445 1.5 cgd
446 1.5 cgd if ((cp->ih = sc->sc_pci_ih) == NULL) {
447 1.5 cgd printf("%s: no native-PCI interrupt for use by %s channel\n",
448 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
449 1.5 cgd rv = 0;
450 1.1 cgd }
451 1.5 cgd
452 1.5 cgd return (rv);
453 1.1 cgd }
454 1.1 cgd
455 1.1 cgd int
456 1.1 cgd pciide_print(aux, pnp)
457 1.1 cgd void *aux;
458 1.1 cgd const char *pnp;
459 1.1 cgd {
460 1.1 cgd struct pciide_attach_args *aa = aux;
461 1.1 cgd
462 1.1 cgd /* only 'wdc's can attach to 'pciide's; easy. */
463 1.1 cgd if (pnp)
464 1.1 cgd printf("wdc at %s", pnp);
465 1.1 cgd printf(" channel %d", aa->channel);
466 1.1 cgd return (UNCONF);
467 1.1 cgd }
468 1.1 cgd
469 1.1 cgd int
470 1.1 cgd pciide_compat_intr(arg)
471 1.1 cgd void *arg;
472 1.1 cgd {
473 1.1 cgd struct pciide_channel *cp = arg;
474 1.1 cgd
475 1.1 cgd #ifdef DIAGNOSTIC
476 1.1 cgd /* should only be called for a compat channel */
477 1.1 cgd if (cp->compat == 0)
478 1.1 cgd panic("pciide compat intr called for non-compat chan %p\n", cp);
479 1.1 cgd #endif
480 1.1 cgd /* if there's no handler, that probably means no dev attached */
481 1.1 cgd if (cp->ihand == NULL)
482 1.1 cgd return (0);
483 1.1 cgd
484 1.1 cgd return ((*cp->ihand)(cp->ihandarg));
485 1.1 cgd }
486 1.1 cgd
487 1.1 cgd int
488 1.1 cgd pciide_pci_intr(arg)
489 1.1 cgd void *arg;
490 1.1 cgd {
491 1.1 cgd struct pciide_softc *sc = arg;
492 1.1 cgd struct pciide_channel *cp;
493 1.1 cgd int i, rv, crv;
494 1.1 cgd
495 1.1 cgd rv = 0;
496 1.1 cgd for (i = 0; i < PCIIDE_NUM_CHANNELS; i++) {
497 1.2 cgd cp = &sc->sc_channels[i];
498 1.1 cgd
499 1.1 cgd /* If a compat channel or there's no handler, skip. */
500 1.1 cgd if (cp->compat || cp->ihand == NULL)
501 1.1 cgd continue;
502 1.1 cgd
503 1.1 cgd crv = ((*cp->ihand)(cp->ihandarg));
504 1.1 cgd if (crv == 0)
505 1.1 cgd ; /* leave rv alone */
506 1.1 cgd else if (crv == 1)
507 1.1 cgd rv = 1; /* claim the intr */
508 1.1 cgd else if (rv == 0) /* crv should be -1 in this case */
509 1.1 cgd rv = crv; /* if we've done no better, take it */
510 1.1 cgd }
511 1.1 cgd return (rv);
512 1.1 cgd }
513