pciide.c revision 1.7 1 1.7 thorpej /* $NetBSD: pciide.c,v 1.7 1998/06/08 06:55:57 thorpej 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 int pciide_match __P((struct device *, struct cfdata *, void *));
87 1.1 cgd void pciide_attach __P((struct device *, struct device *, void *));
88 1.1 cgd
89 1.1 cgd struct cfattach pciide_ca = {
90 1.1 cgd sizeof(struct pciide_softc), pciide_match, pciide_attach
91 1.1 cgd };
92 1.1 cgd
93 1.5 cgd int pciide_map_channel_compat __P((struct pciide_softc *,
94 1.5 cgd struct pci_attach_args *, int));
95 1.6 cgd const char *pciide_compat_channel_probe __P((struct pciide_softc *,
96 1.5 cgd struct pci_attach_args *, int));
97 1.6 cgd int pciide_probe_wdc __P((struct pciide_channel *));
98 1.5 cgd int pciide_map_channel_native __P((struct pciide_softc *,
99 1.5 cgd struct pci_attach_args *, int));
100 1.5 cgd int pciide_print __P((void *, const char *pnp));
101 1.1 cgd int pciide_compat_intr __P((void *));
102 1.1 cgd int pciide_pci_intr __P((void *));
103 1.1 cgd
104 1.6 cgd #define PCIIDE_PROBE_WDC_DELAY 100 /* 100us each */
105 1.6 cgd #define PCIIDE_PROBE_WDC_NDELAY 10000 /* wait up to 1s */
106 1.6 cgd
107 1.1 cgd int
108 1.1 cgd pciide_match(parent, match, aux)
109 1.1 cgd struct device *parent;
110 1.1 cgd struct cfdata *match;
111 1.1 cgd void *aux;
112 1.1 cgd {
113 1.1 cgd struct pci_attach_args *pa = aux;
114 1.1 cgd
115 1.1 cgd /*
116 1.1 cgd * Check the ID register to see that it's a PCI IDE controller.
117 1.1 cgd * If it is, we assume that we can deal with it; it _should_
118 1.1 cgd * work in a standardized way...
119 1.1 cgd */
120 1.1 cgd if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
121 1.1 cgd PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {
122 1.1 cgd return (1);
123 1.1 cgd }
124 1.1 cgd
125 1.1 cgd return (0);
126 1.1 cgd }
127 1.1 cgd
128 1.1 cgd void
129 1.1 cgd pciide_attach(parent, self, aux)
130 1.1 cgd struct device *parent, *self;
131 1.1 cgd void *aux;
132 1.1 cgd {
133 1.1 cgd struct pci_attach_args *pa = aux;
134 1.1 cgd pci_chipset_tag_t pc = pa->pa_pc;
135 1.1 cgd struct pciide_softc *sc = (struct pciide_softc *)self;
136 1.1 cgd struct pciide_attach_args aa;
137 1.1 cgd struct pciide_channel *cp;
138 1.1 cgd pcireg_t class, interface, csr;
139 1.1 cgd pci_intr_handle_t intrhandle;
140 1.1 cgd const char *intrstr;
141 1.1 cgd char devinfo[256];
142 1.1 cgd int i;
143 1.1 cgd
144 1.1 cgd pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
145 1.1 cgd printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
146 1.1 cgd
147 1.1 cgd if ((pa->pa_flags & PCI_FLAGS_IO_ENABLED) == 0) {
148 1.1 cgd csr = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
149 1.1 cgd printf("%s: device disabled (at %s)\n", sc->sc_dev.dv_xname,
150 1.1 cgd (csr & PCI_COMMAND_IO_ENABLE) == 0 ? "device" : "bridge");
151 1.1 cgd return;
152 1.1 cgd }
153 1.1 cgd
154 1.1 cgd class = pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG);
155 1.1 cgd interface = PCI_INTERFACE(class);
156 1.1 cgd
157 1.1 cgd /*
158 1.1 cgd * Set up PCI interrupt.
159 1.1 cgd *
160 1.1 cgd * If mapping fails, that's (probably) because there's no pin
161 1.1 cgd * set to intr, which is (probably) because it's a compat-only
162 1.1 cgd * device (or hard-wired in compatibility-only mode). Native-PCI
163 1.1 cgd * channels will complain later if the interrupt was needed.
164 1.1 cgd *
165 1.1 cgd * If establishment fails, that's (probably) some other problem.
166 1.1 cgd */
167 1.1 cgd if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
168 1.1 cgd pa->pa_intrline, &intrhandle) == 0) {
169 1.1 cgd intrstr = pci_intr_string(pa->pa_pc, intrhandle);
170 1.1 cgd sc->sc_pci_ih = pci_intr_establish(pa->pa_pc, intrhandle,
171 1.1 cgd IPL_BIO, pciide_pci_intr, sc);
172 1.1 cgd
173 1.1 cgd if (sc->sc_pci_ih != NULL) {
174 1.1 cgd printf("%s: using %s for native-PCI interrupt\n",
175 1.1 cgd sc->sc_dev.dv_xname,
176 1.1 cgd intrstr ? intrstr : "unknown interrupt");
177 1.1 cgd } else {
178 1.1 cgd printf("%s: couldn't establish native-PCI interrupt",
179 1.1 cgd sc->sc_dev.dv_xname);
180 1.1 cgd if (intrstr != NULL)
181 1.1 cgd printf(" at %s", intrstr);
182 1.1 cgd printf("\n");
183 1.1 cgd }
184 1.1 cgd }
185 1.1 cgd
186 1.2 cgd /*
187 1.2 cgd * Map DMA registers, if DMA is supported.
188 1.2 cgd *
189 1.5 cgd * Note that sc_dma_ok is the right variable to test to see if
190 1.5 cgd * DMA can * be done. If the interface doesn't support DMA,
191 1.5 cgd * sc_dma_ok * will never be non-zero. If the DMA regs couldn't
192 1.5 cgd * be mapped, it'll be zero. I.e., sc_dma_ok will only be
193 1.5 cgd * non-zero if the interface supports DMA and the registers
194 1.5 cgd * could be mapped.
195 1.4 cgd *
196 1.4 cgd * XXX Note that despite the fact that the Bus Master IDE specs
197 1.4 cgd * XXX say that "The bus master IDE functoin uses 16 bytes of IO
198 1.4 cgd * XXX space," some controllers (at least the United
199 1.4 cgd * XXX Microelectronics UM8886BF) place it in memory space.
200 1.4 cgd * XXX eventually, we should probably read the register and check
201 1.4 cgd * XXX which type it is. Either that or 'quirk' certain devices.
202 1.2 cgd */
203 1.2 cgd if (interface & PCIIDE_INTERFACE_BUS_MASTER_DMA) {
204 1.5 cgd sc->sc_dma_ok = (pci_mapreg_map(pa,
205 1.2 cgd PCIIDE_REG_BUS_MASTER_DMA, PCI_MAPREG_TYPE_IO, 0,
206 1.2 cgd &sc->sc_dma_iot, &sc->sc_dma_ioh, NULL, NULL) == 0);
207 1.3 cgd printf("%s: bus-master DMA support present, but unused (%s)\n",
208 1.2 cgd sc->sc_dev.dv_xname,
209 1.5 cgd sc->sc_dma_ok ? "no driver support" :
210 1.5 cgd "couldn't map registers");
211 1.1 cgd }
212 1.1 cgd
213 1.1 cgd for (i = 0; i < PCIIDE_NUM_CHANNELS; i++) {
214 1.2 cgd cp = &sc->sc_channels[i];
215 1.2 cgd
216 1.2 cgd printf("%s: %s channel %s to %s mode\n",
217 1.2 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(i),
218 1.2 cgd (interface & PCIIDE_INTERFACE_SETTABLE(i)) ?
219 1.2 cgd "configured" : "wired",
220 1.2 cgd (interface & PCIIDE_INTERFACE_PCI(i)) ? "native-PCI" :
221 1.2 cgd "compatibility");
222 1.1 cgd
223 1.5 cgd if (interface & PCIIDE_INTERFACE_PCI(i))
224 1.5 cgd cp->hw_ok = pciide_map_channel_native(sc, pa, i);
225 1.5 cgd else
226 1.5 cgd cp->hw_ok = pciide_map_channel_compat(sc, pa, i);
227 1.5 cgd if (!cp->hw_ok)
228 1.5 cgd continue;
229 1.5 cgd
230 1.5 cgd aa.channel = i;
231 1.5 cgd aa.cmd_iot = cp->cmd_iot;
232 1.5 cgd aa.cmd_ioh = cp->cmd_ioh;
233 1.5 cgd aa.ctl_iot = cp->ctl_iot;
234 1.5 cgd aa.ctl_ioh = cp->ctl_ioh;
235 1.5 cgd aa.ihandp = &cp->ihand;
236 1.5 cgd aa.ihandargp = &cp->ihandarg;
237 1.5 cgd cp->dev = config_found(self, &aa, pciide_print);
238 1.2 cgd
239 1.5 cgd /*
240 1.5 cgd * Note that if the 'wdc' device isn't configured,
241 1.5 cgd * the controller's resources are still marked as
242 1.5 cgd * being in use. This is a feature.
243 1.5 cgd */
244 1.5 cgd }
245 1.5 cgd }
246 1.5 cgd
247 1.5 cgd int
248 1.5 cgd pciide_map_channel_compat(sc, pa, chan)
249 1.5 cgd struct pciide_softc *sc;
250 1.5 cgd struct pci_attach_args *pa;
251 1.5 cgd int chan;
252 1.5 cgd {
253 1.5 cgd struct pciide_channel *cp = &sc->sc_channels[chan];
254 1.6 cgd const char *probe_fail_reason;
255 1.5 cgd int rv = 1;
256 1.5 cgd
257 1.5 cgd cp->compat = 1;
258 1.5 cgd
259 1.5 cgd cp->cmd_iot = pa->pa_iot;
260 1.5 cgd if (bus_space_map(cp->cmd_iot, PCIIDE_COMPAT_CMD_BASE(chan),
261 1.5 cgd PCIIDE_COMPAT_CMD_SIZE, 0, &cp->cmd_ioh) != 0) {
262 1.5 cgd printf("%s: couldn't map %s channel cmd regs\n",
263 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
264 1.5 cgd rv = 0;
265 1.5 cgd }
266 1.5 cgd
267 1.5 cgd cp->ctl_iot = pa->pa_iot;
268 1.5 cgd if (bus_space_map(cp->ctl_iot, PCIIDE_COMPAT_CTL_BASE(chan),
269 1.5 cgd PCIIDE_COMPAT_CTL_SIZE, 0, &cp->ctl_ioh) != 0) {
270 1.5 cgd printf("%s: couldn't map %s channel ctl 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 /*
276 1.5 cgd * If we weren't able to map the device successfully,
277 1.5 cgd * we just give up now. Something else has already
278 1.5 cgd * occupied those ports, indicating that the device has
279 1.5 cgd * (probably) been completely disabled (by some nonstandard
280 1.5 cgd * mechanism).
281 1.5 cgd *
282 1.5 cgd * XXX If we successfully map some ports, but not others,
283 1.5 cgd * XXX it might make sense to unmap the ones that we mapped.
284 1.5 cgd */
285 1.5 cgd if (rv == 0)
286 1.5 cgd goto out;
287 1.5 cgd
288 1.5 cgd /*
289 1.5 cgd * If we were able to map the device successfully, try to
290 1.5 cgd * make sure that there's a wdc there and that it's
291 1.5 cgd * attributable to us.
292 1.5 cgd *
293 1.5 cgd * If there's not, then we assume that there's the device
294 1.5 cgd * has been disabled and that other devices are free to use
295 1.5 cgd * its ports.
296 1.5 cgd */
297 1.6 cgd probe_fail_reason = pciide_compat_channel_probe(sc, pa, chan);
298 1.6 cgd if (probe_fail_reason != NULL) {
299 1.6 cgd printf("%s: %s channel ignored (%s)\n", sc->sc_dev.dv_xname,
300 1.6 cgd PCIIDE_CHANNEL_NAME(chan), probe_fail_reason);
301 1.5 cgd rv = 0;
302 1.5 cgd
303 1.5 cgd bus_space_unmap(cp->cmd_iot, cp->cmd_ioh,
304 1.5 cgd PCIIDE_COMPAT_CMD_SIZE);
305 1.5 cgd bus_space_unmap(cp->ctl_iot, cp->ctl_ioh,
306 1.5 cgd PCIIDE_COMPAT_CTL_SIZE);
307 1.5 cgd
308 1.5 cgd goto out;
309 1.5 cgd }
310 1.5 cgd
311 1.5 cgd /*
312 1.5 cgd * If we're here, we were able to map the device successfully
313 1.5 cgd * and it really looks like there's a controller there.
314 1.5 cgd *
315 1.5 cgd * Unless those conditions are true, we don't map the
316 1.5 cgd * compatibility interrupt. The spec indicates that if a
317 1.5 cgd * channel is configured for compatibility mode and the PCI
318 1.5 cgd * device's I/O space is enabled, the channel will be enabled.
319 1.5 cgd * Hoewver, some devices seem to be able to disable invididual
320 1.5 cgd * compatibility channels (via non-standard mechanisms). If
321 1.5 cgd * the channel is disabled, the interrupt line can (probably)
322 1.5 cgd * be used by other devices (and may be assigned to other
323 1.5 cgd * devices by the BIOS). If we mapped the interrupt we might
324 1.5 cgd * conflict with another interrupt assignment.
325 1.5 cgd */
326 1.5 cgd cp->ih = pciide_machdep_compat_intr_establish(&sc->sc_dev, pa,
327 1.5 cgd chan, pciide_compat_intr, cp);
328 1.5 cgd if (cp->ih == NULL) {
329 1.5 cgd printf("%s: no compatibility interrupt for use by %s channel\n",
330 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
331 1.5 cgd rv = 0;
332 1.5 cgd }
333 1.5 cgd
334 1.5 cgd out:
335 1.5 cgd return (rv);
336 1.5 cgd }
337 1.5 cgd
338 1.6 cgd const char *
339 1.5 cgd pciide_compat_channel_probe(sc, pa, chan)
340 1.5 cgd struct pciide_softc *sc;
341 1.5 cgd struct pci_attach_args *pa;
342 1.5 cgd {
343 1.6 cgd pcireg_t csr;
344 1.6 cgd const char *failreason = NULL;
345 1.6 cgd
346 1.6 cgd /*
347 1.6 cgd * Check to see if something appears to be there.
348 1.6 cgd */
349 1.6 cgd if (!pciide_probe_wdc(&sc->sc_channels[chan])) {
350 1.6 cgd failreason = "not responding; disabled or no drives?";
351 1.6 cgd goto out;
352 1.6 cgd }
353 1.5 cgd
354 1.5 cgd /*
355 1.6 cgd * Now, make sure it's actually attributable to this PCI IDE
356 1.6 cgd * channel by trying to access the channel again while the
357 1.6 cgd * PCI IDE controller's I/O space is disabled. (If the
358 1.6 cgd * channel no longer appears to be there, it belongs to
359 1.6 cgd * this controller.) YUCK!
360 1.5 cgd */
361 1.6 cgd csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
362 1.6 cgd pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
363 1.6 cgd csr & ~PCI_COMMAND_IO_ENABLE);
364 1.6 cgd if (pciide_probe_wdc(&sc->sc_channels[chan]))
365 1.6 cgd failreason = "other hardware responding at addresses";
366 1.6 cgd pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, csr);
367 1.6 cgd
368 1.6 cgd out:
369 1.6 cgd return (failreason);
370 1.6 cgd }
371 1.6 cgd
372 1.6 cgd int
373 1.6 cgd pciide_probe_wdc(cp)
374 1.6 cgd struct pciide_channel *cp;
375 1.6 cgd {
376 1.6 cgd u_int8_t st0, st1;
377 1.6 cgd int timeout;
378 1.6 cgd
379 1.6 cgd /*
380 1.6 cgd * Sanity check to see if the wdc channel responds at all.
381 1.6 cgd * (Modeled on wdc_init_controller() and wdc_reset() in wdc.c.)
382 1.6 cgd *
383 1.6 cgd * Reset the channel, and make sure that it responds sanely
384 1.6 cgd * after it's been reset.
385 1.6 cgd */
386 1.6 cgd
387 1.6 cgd /* Reset the channel. */
388 1.6 cgd bus_space_write_1(cp->ctl_iot, cp->ctl_ioh, wd_aux_ctlr,
389 1.6 cgd WDCTL_RST | WDCTL_IDS);
390 1.6 cgd delay(1000);
391 1.6 cgd bus_space_write_1(cp->ctl_iot, cp->ctl_ioh, wd_aux_ctlr,
392 1.6 cgd WDCTL_IDS);
393 1.6 cgd delay(1000);
394 1.6 cgd (void)bus_space_read_1(cp->cmd_iot, cp->cmd_ioh, wd_error);
395 1.6 cgd
396 1.6 cgd timeout = 0;
397 1.6 cgd while (timeout++ < PCIIDE_PROBE_WDC_NDELAY) {
398 1.6 cgd st0 = bus_space_read_1(cp->cmd_iot, cp->cmd_ioh, wd_status);
399 1.6 cgd bus_space_write_1(cp->cmd_iot, cp->cmd_ioh, wd_sdh,
400 1.6 cgd WDSD_IBM | 0x10);
401 1.6 cgd st1 = bus_space_read_1(cp->cmd_iot, cp->cmd_ioh, wd_status);
402 1.6 cgd
403 1.6 cgd if ((st0 & WDCS_BSY) == 0 || (st1 & WDCS_BSY) == 0)
404 1.6 cgd return (1);
405 1.6 cgd
406 1.6 cgd delay(PCIIDE_PROBE_WDC_DELAY);
407 1.6 cgd }
408 1.6 cgd /* timed out; nothing there */
409 1.6 cgd
410 1.6 cgd return (0);
411 1.5 cgd }
412 1.5 cgd
413 1.5 cgd int
414 1.5 cgd pciide_map_channel_native(sc, pa, chan)
415 1.5 cgd struct pciide_softc *sc;
416 1.5 cgd struct pci_attach_args *pa;
417 1.5 cgd int chan;
418 1.5 cgd {
419 1.5 cgd struct pciide_channel *cp = &sc->sc_channels[chan];
420 1.5 cgd int rv = 1;
421 1.5 cgd
422 1.5 cgd cp->compat = 0;
423 1.5 cgd
424 1.5 cgd if (pci_mapreg_map(pa, PCIIDE_REG_CMD_BASE(chan), PCI_MAPREG_TYPE_IO,
425 1.5 cgd 0, &cp->cmd_iot, &cp->cmd_ioh, NULL, NULL) != 0) {
426 1.5 cgd printf("%s: couldn't map %s channel cmd regs\n",
427 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
428 1.5 cgd rv = 0;
429 1.5 cgd }
430 1.5 cgd
431 1.5 cgd if (pci_mapreg_map(pa, PCIIDE_REG_CTL_BASE(chan), PCI_MAPREG_TYPE_IO,
432 1.5 cgd 0, &cp->ctl_iot, &cp->ctl_ioh, NULL, NULL) != 0) {
433 1.5 cgd printf("%s: couldn't map %s channel ctl regs\n",
434 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
435 1.5 cgd rv = 0;
436 1.5 cgd }
437 1.5 cgd
438 1.5 cgd if ((cp->ih = sc->sc_pci_ih) == NULL) {
439 1.5 cgd printf("%s: no native-PCI interrupt for use by %s channel\n",
440 1.5 cgd sc->sc_dev.dv_xname, PCIIDE_CHANNEL_NAME(chan));
441 1.5 cgd rv = 0;
442 1.1 cgd }
443 1.5 cgd
444 1.5 cgd return (rv);
445 1.1 cgd }
446 1.1 cgd
447 1.1 cgd int
448 1.1 cgd pciide_print(aux, pnp)
449 1.1 cgd void *aux;
450 1.1 cgd const char *pnp;
451 1.1 cgd {
452 1.1 cgd struct pciide_attach_args *aa = aux;
453 1.1 cgd
454 1.1 cgd /* only 'wdc's can attach to 'pciide's; easy. */
455 1.1 cgd if (pnp)
456 1.1 cgd printf("wdc at %s", pnp);
457 1.1 cgd printf(" channel %d", aa->channel);
458 1.1 cgd return (UNCONF);
459 1.1 cgd }
460 1.1 cgd
461 1.1 cgd int
462 1.1 cgd pciide_compat_intr(arg)
463 1.1 cgd void *arg;
464 1.1 cgd {
465 1.1 cgd struct pciide_channel *cp = arg;
466 1.1 cgd
467 1.1 cgd #ifdef DIAGNOSTIC
468 1.1 cgd /* should only be called for a compat channel */
469 1.1 cgd if (cp->compat == 0)
470 1.1 cgd panic("pciide compat intr called for non-compat chan %p\n", cp);
471 1.1 cgd #endif
472 1.1 cgd /* if there's no handler, that probably means no dev attached */
473 1.1 cgd if (cp->ihand == NULL)
474 1.1 cgd return (0);
475 1.1 cgd
476 1.1 cgd return ((*cp->ihand)(cp->ihandarg));
477 1.1 cgd }
478 1.1 cgd
479 1.1 cgd int
480 1.1 cgd pciide_pci_intr(arg)
481 1.1 cgd void *arg;
482 1.1 cgd {
483 1.1 cgd struct pciide_softc *sc = arg;
484 1.1 cgd struct pciide_channel *cp;
485 1.1 cgd int i, rv, crv;
486 1.1 cgd
487 1.1 cgd rv = 0;
488 1.1 cgd for (i = 0; i < PCIIDE_NUM_CHANNELS; i++) {
489 1.2 cgd cp = &sc->sc_channels[i];
490 1.1 cgd
491 1.1 cgd /* If a compat channel or there's no handler, skip. */
492 1.1 cgd if (cp->compat || cp->ihand == NULL)
493 1.1 cgd continue;
494 1.1 cgd
495 1.1 cgd crv = ((*cp->ihand)(cp->ihandarg));
496 1.1 cgd if (crv == 0)
497 1.1 cgd ; /* leave rv alone */
498 1.1 cgd else if (crv == 1)
499 1.1 cgd rv = 1; /* claim the intr */
500 1.1 cgd else if (rv == 0) /* crv should be -1 in this case */
501 1.1 cgd rv = crv; /* if we've done no better, take it */
502 1.1 cgd }
503 1.1 cgd return (rv);
504 1.1 cgd }
505