| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pci.c,v 1.114 2008/03/21 07:47:43 dyoung Exp $ */ | | 1 | /* $NetBSD: pci.c,v 1.115 2008/03/23 16:40:12 cube Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1995, 1996, 1997, 1998 | | 4 | * Copyright (c) 1995, 1996, 1997, 1998 |
5 | * Christopher G. Demetriou. All rights reserved. | | 5 | * Christopher G. Demetriou. All rights reserved. |
6 | * Copyright (c) 1994 Charles M. Hannum. All rights reserved. | | 6 | * Copyright (c) 1994 Charles M. Hannum. All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -26,27 +26,27 @@ | | | @@ -26,27 +26,27 @@ |
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | /* | | 34 | /* |
35 | * PCI bus autoconfiguration. | | 35 | * PCI bus autoconfiguration. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | #include <sys/cdefs.h> | | 38 | #include <sys/cdefs.h> |
39 | __KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.114 2008/03/21 07:47:43 dyoung Exp $"); | | 39 | __KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.115 2008/03/23 16:40:12 cube Exp $"); |
40 | | | 40 | |
41 | #include "opt_pci.h" | | 41 | #include "opt_pci.h" |
42 | | | 42 | |
43 | #include <sys/param.h> | | 43 | #include <sys/param.h> |
44 | #include <sys/malloc.h> | | 44 | #include <sys/malloc.h> |
45 | #include <sys/systm.h> | | 45 | #include <sys/systm.h> |
46 | #include <sys/device.h> | | 46 | #include <sys/device.h> |
47 | | | 47 | |
48 | #include <dev/pci/pcireg.h> | | 48 | #include <dev/pci/pcireg.h> |
49 | #include <dev/pci/pcivar.h> | | 49 | #include <dev/pci/pcivar.h> |
50 | #include <dev/pci/pcidevs.h> | | 50 | #include <dev/pci/pcidevs.h> |
51 | | | 51 | |
52 | #include <uvm/uvm_extern.h> | | 52 | #include <uvm/uvm_extern.h> |
| @@ -101,27 +101,27 @@ int pci_enumerate_bus(struct pci_softc * | | | @@ -101,27 +101,27 @@ int pci_enumerate_bus(struct pci_softc * |
101 | static int | | 101 | static int |
102 | pcirescan(device_t self, const char *ifattr, const int *locators) | | 102 | pcirescan(device_t self, const char *ifattr, const int *locators) |
103 | { | | 103 | { |
104 | struct pci_softc *sc = device_private(self); | | 104 | struct pci_softc *sc = device_private(self); |
105 | | | 105 | |
106 | KASSERT(ifattr && !strcmp(ifattr, "pci")); | | 106 | KASSERT(ifattr && !strcmp(ifattr, "pci")); |
107 | KASSERT(locators); | | 107 | KASSERT(locators); |
108 | | | 108 | |
109 | pci_enumerate_bus(sc, locators, NULL, NULL); | | 109 | pci_enumerate_bus(sc, locators, NULL, NULL); |
110 | return 0; | | 110 | return 0; |
111 | } | | 111 | } |
112 | | | 112 | |
113 | static int | | 113 | static int |
114 | pcimatch(device_t parent, struct cfdata *cf, void *aux) | | 114 | pcimatch(device_t parent, cfdata_t cf, void *aux) |
115 | { | | 115 | { |
116 | struct pcibus_attach_args *pba = aux; | | 116 | struct pcibus_attach_args *pba = aux; |
117 | | | 117 | |
118 | /* Check the locators */ | | 118 | /* Check the locators */ |
119 | if (cf->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT && | | 119 | if (cf->cf_loc[PCIBUSCF_BUS] != PCIBUSCF_BUS_DEFAULT && |
120 | cf->cf_loc[PCIBUSCF_BUS] != pba->pba_bus) | | 120 | cf->cf_loc[PCIBUSCF_BUS] != pba->pba_bus) |
121 | return (0); | | 121 | return (0); |
122 | | | 122 | |
123 | /* sanity */ | | 123 | /* sanity */ |
124 | if (pba->pba_bus < 0 || pba->pba_bus > 255) | | 124 | if (pba->pba_bus < 0 || pba->pba_bus > 255) |
125 | return (0); | | 125 | return (0); |
126 | | | 126 | |
127 | /* | | 127 | /* |
| @@ -132,49 +132,51 @@ pcimatch(device_t parent, struct cfdata | | | @@ -132,49 +132,51 @@ pcimatch(device_t parent, struct cfdata |
132 | } | | 132 | } |
133 | | | 133 | |
134 | static void | | 134 | static void |
135 | pciattach(device_t parent, device_t self, void *aux) | | 135 | pciattach(device_t parent, device_t self, void *aux) |
136 | { | | 136 | { |
137 | struct pcibus_attach_args *pba = aux; | | 137 | struct pcibus_attach_args *pba = aux; |
138 | struct pci_softc *sc = device_private(self); | | 138 | struct pci_softc *sc = device_private(self); |
139 | int io_enabled, mem_enabled, mrl_enabled, mrm_enabled, mwi_enabled; | | 139 | int io_enabled, mem_enabled, mrl_enabled, mrm_enabled, mwi_enabled; |
140 | const char *sep = ""; | | 140 | const char *sep = ""; |
141 | static const int wildcard[PCICF_NLOCS] = { | | 141 | static const int wildcard[PCICF_NLOCS] = { |
142 | PCICF_DEV_DEFAULT, PCICF_FUNCTION_DEFAULT | | 142 | PCICF_DEV_DEFAULT, PCICF_FUNCTION_DEFAULT |
143 | }; | | 143 | }; |
144 | | | 144 | |
| | | 145 | sc->sc_dev = self; |
| | | 146 | |
145 | pci_attach_hook(parent, self, pba); | | 147 | pci_attach_hook(parent, self, pba); |
146 | | | 148 | |
147 | aprint_naive("\n"); | | 149 | aprint_naive("\n"); |
148 | aprint_normal("\n"); | | 150 | aprint_normal("\n"); |
149 | | | 151 | |
150 | io_enabled = (pba->pba_flags & PCI_FLAGS_IO_ENABLED); | | 152 | io_enabled = (pba->pba_flags & PCI_FLAGS_IO_ENABLED); |
151 | mem_enabled = (pba->pba_flags & PCI_FLAGS_MEM_ENABLED); | | 153 | mem_enabled = (pba->pba_flags & PCI_FLAGS_MEM_ENABLED); |
152 | mrl_enabled = (pba->pba_flags & PCI_FLAGS_MRL_OKAY); | | 154 | mrl_enabled = (pba->pba_flags & PCI_FLAGS_MRL_OKAY); |
153 | mrm_enabled = (pba->pba_flags & PCI_FLAGS_MRM_OKAY); | | 155 | mrm_enabled = (pba->pba_flags & PCI_FLAGS_MRM_OKAY); |
154 | mwi_enabled = (pba->pba_flags & PCI_FLAGS_MWI_OKAY); | | 156 | mwi_enabled = (pba->pba_flags & PCI_FLAGS_MWI_OKAY); |
155 | | | 157 | |
156 | if (io_enabled == 0 && mem_enabled == 0) { | | 158 | if (io_enabled == 0 && mem_enabled == 0) { |
157 | aprint_error_dev(self, "no spaces enabled!\n"); | | 159 | aprint_error_dev(self, "no spaces enabled!\n"); |
158 | goto fail; | | 160 | goto fail; |
159 | } | | 161 | } |
160 | | | 162 | |
161 | #define PRINT(str) \ | | 163 | #define PRINT(str) \ |
162 | do { \ | | 164 | do { \ |
163 | aprint_verbose("%s%s", sep, str); \ | | 165 | aprint_verbose("%s%s", sep, str); \ |
164 | sep = ", "; \ | | 166 | sep = ", "; \ |
165 | } while (/*CONSTCOND*/0) | | 167 | } while (/*CONSTCOND*/0) |
166 | | | 168 | |
167 | aprint_verbose_dev(self, " "); | | 169 | aprint_verbose_dev(self, ""); |
168 | | | 170 | |
169 | if (io_enabled) | | 171 | if (io_enabled) |
170 | PRINT("i/o space"); | | 172 | PRINT("i/o space"); |
171 | if (mem_enabled) | | 173 | if (mem_enabled) |
172 | PRINT("memory space"); | | 174 | PRINT("memory space"); |
173 | aprint_verbose(" enabled"); | | 175 | aprint_verbose(" enabled"); |
174 | | | 176 | |
175 | if (mrl_enabled || mrm_enabled || mwi_enabled) { | | 177 | if (mrl_enabled || mrm_enabled || mwi_enabled) { |
176 | if (mrl_enabled) | | 178 | if (mrl_enabled) |
177 | PRINT("rd/line"); | | 179 | PRINT("rd/line"); |
178 | if (mrm_enabled) | | 180 | if (mrm_enabled) |
179 | PRINT("rd/mult"); | | 181 | PRINT("rd/mult"); |
180 | if (mwi_enabled) | | 182 | if (mwi_enabled) |
| @@ -188,29 +190,29 @@ do { \ | | | @@ -188,29 +190,29 @@ do { \ |
188 | | | 190 | |
189 | sc->sc_iot = pba->pba_iot; | | 191 | sc->sc_iot = pba->pba_iot; |
190 | sc->sc_memt = pba->pba_memt; | | 192 | sc->sc_memt = pba->pba_memt; |
191 | sc->sc_dmat = pba->pba_dmat; | | 193 | sc->sc_dmat = pba->pba_dmat; |
192 | sc->sc_dmat64 = pba->pba_dmat64; | | 194 | sc->sc_dmat64 = pba->pba_dmat64; |
193 | sc->sc_pc = pba->pba_pc; | | 195 | sc->sc_pc = pba->pba_pc; |
194 | sc->sc_bus = pba->pba_bus; | | 196 | sc->sc_bus = pba->pba_bus; |
195 | sc->sc_bridgetag = pba->pba_bridgetag; | | 197 | sc->sc_bridgetag = pba->pba_bridgetag; |
196 | sc->sc_maxndevs = pci_bus_maxdevs(pba->pba_pc, pba->pba_bus); | | 198 | sc->sc_maxndevs = pci_bus_maxdevs(pba->pba_pc, pba->pba_bus); |
197 | sc->sc_intrswiz = pba->pba_intrswiz; | | 199 | sc->sc_intrswiz = pba->pba_intrswiz; |
198 | sc->sc_intrtag = pba->pba_intrtag; | | 200 | sc->sc_intrtag = pba->pba_intrtag; |
199 | sc->sc_flags = pba->pba_flags; | | 201 | sc->sc_flags = pba->pba_flags; |
200 | | | 202 | |
201 | device_pmf_driver_set_child_register(&sc->sc_dev, pci_child_register); | | 203 | device_pmf_driver_set_child_register(sc->sc_dev, pci_child_register); |
202 | | | 204 | |
203 | pcirescan(&sc->sc_dev, "pci", wildcard); | | 205 | pcirescan(sc->sc_dev, "pci", wildcard); |
204 | | | 206 | |
205 | fail: | | 207 | fail: |
206 | if (!pmf_device_register(self, NULL, NULL)) | | 208 | if (!pmf_device_register(self, NULL, NULL)) |
207 | aprint_error_dev(self, "couldn't establish power handler\n"); | | 209 | aprint_error_dev(self, "couldn't establish power handler\n"); |
208 | } | | 210 | } |
209 | | | 211 | |
210 | static int | | 212 | static int |
211 | pcidetach(device_t self, int flags) | | 213 | pcidetach(device_t self, int flags) |
212 | { | | 214 | { |
213 | int rc; | | 215 | int rc; |
214 | | | 216 | |
215 | if ((rc = config_detach_children(self, flags)) != 0) | | 217 | if ((rc = config_detach_children(self, flags)) != 0) |
216 | return rc; | | 218 | return rc; |
| @@ -351,50 +353,50 @@ pci_probe_device(struct pci_softc *sc, p | | | @@ -351,50 +353,50 @@ pci_probe_device(struct pci_softc *sc, p |
351 | pa.pa_intrpin = /* XXX */ | | 353 | pa.pa_intrpin = /* XXX */ |
352 | ((pin + pa.pa_intrswiz - 1) % 4) + 1; | | 354 | ((pin + pa.pa_intrswiz - 1) % 4) + 1; |
353 | } | | 355 | } |
354 | pa.pa_intrline = PCI_INTERRUPT_LINE(intr); | | 356 | pa.pa_intrline = PCI_INTERRUPT_LINE(intr); |
355 | | | 357 | |
356 | if (match != NULL) { | | 358 | if (match != NULL) { |
357 | ret = (*match)(&pa); | | 359 | ret = (*match)(&pa); |
358 | if (ret != 0 && pap != NULL) | | 360 | if (ret != 0 && pap != NULL) |
359 | *pap = pa; | | 361 | *pap = pa; |
360 | } else { | | 362 | } else { |
361 | locs[PCICF_DEV] = device; | | 363 | locs[PCICF_DEV] = device; |
362 | locs[PCICF_FUNCTION] = function; | | 364 | locs[PCICF_FUNCTION] = function; |
363 | | | 365 | |
364 | subdev = config_found_sm_loc(&sc->sc_dev, "pci", locs, &pa, | | 366 | subdev = config_found_sm_loc(sc->sc_dev, "pci", locs, &pa, |
365 | pciprint, config_stdsubmatch); | | 367 | pciprint, config_stdsubmatch); |
366 | sc->PCI_SC_DEVICESC(device, function) = subdev; | | 368 | sc->PCI_SC_DEVICESC(device, function) = subdev; |
367 | ret = (subdev != NULL); | | 369 | ret = (subdev != NULL); |
368 | } | | 370 | } |
369 | | | 371 | |
370 | return (ret); | | 372 | return (ret); |
371 | } | | 373 | } |
372 | | | 374 | |
373 | static void | | 375 | static void |
374 | pcidevdetached(device_t self, device_t child) | | 376 | pcidevdetached(device_t self, device_t child) |
375 | { | | 377 | { |
376 | struct pci_softc *psc = device_private(self); | | 378 | struct pci_softc *psc = device_private(self); |
377 | int d, f; | | 379 | int d, f; |
378 | | | 380 | |
379 | d = device_locator(child, PCICF_DEV); | | 381 | d = device_locator(child, PCICF_DEV); |
380 | f = device_locator(child, PCICF_FUNCTION); | | 382 | f = device_locator(child, PCICF_FUNCTION); |
381 | | | 383 | |
382 | KASSERT(psc->PCI_SC_DEVICESC(d, f) == child); | | 384 | KASSERT(psc->PCI_SC_DEVICESC(d, f) == child); |
383 | | | 385 | |
384 | psc->PCI_SC_DEVICESC(d, f) = 0; | | 386 | psc->PCI_SC_DEVICESC(d, f) = 0; |
385 | } | | 387 | } |
386 | | | 388 | |
387 | CFATTACH_DECL2(pci, sizeof(struct pci_softc), | | 389 | CFATTACH_DECL2_NEW(pci, sizeof(struct pci_softc), |
388 | pcimatch, pciattach, pcidetach, NULL, pcirescan, pcidevdetached); | | 390 | pcimatch, pciattach, pcidetach, NULL, pcirescan, pcidevdetached); |
389 | | | 391 | |
390 | int | | 392 | int |
391 | pci_get_capability(pci_chipset_tag_t pc, pcitag_t tag, int capid, | | 393 | pci_get_capability(pci_chipset_tag_t pc, pcitag_t tag, int capid, |
392 | int *offset, pcireg_t *value) | | 394 | int *offset, pcireg_t *value) |
393 | { | | 395 | { |
394 | pcireg_t reg; | | 396 | pcireg_t reg; |
395 | unsigned int ofs; | | 397 | unsigned int ofs; |
396 | | | 398 | |
397 | reg = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); | | 399 | reg = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); |
398 | if (!(reg & PCI_STATUS_CAPLIST_SUPPORT)) | | 400 | if (!(reg & PCI_STATUS_CAPLIST_SUPPORT)) |
399 | return (0); | | 401 | return (0); |
400 | | | 402 | |
| @@ -437,27 +439,27 @@ pci_find_device(struct pci_attach_args * | | | @@ -437,27 +439,27 @@ pci_find_device(struct pci_attach_args * |
437 | int (*match)(struct pci_attach_args *)) | | 439 | int (*match)(struct pci_attach_args *)) |
438 | { | | 440 | { |
439 | extern struct cfdriver pci_cd; | | 441 | extern struct cfdriver pci_cd; |
440 | device_t pcidev; | | 442 | device_t pcidev; |
441 | int i; | | 443 | int i; |
442 | static const int wildcard[2] = { | | 444 | static const int wildcard[2] = { |
443 | PCICF_DEV_DEFAULT, | | 445 | PCICF_DEV_DEFAULT, |
444 | PCICF_FUNCTION_DEFAULT | | 446 | PCICF_FUNCTION_DEFAULT |
445 | }; | | 447 | }; |
446 | | | 448 | |
447 | for (i = 0; i < pci_cd.cd_ndevs; i++) { | | 449 | for (i = 0; i < pci_cd.cd_ndevs; i++) { |
448 | pcidev = pci_cd.cd_devs[i]; | | 450 | pcidev = pci_cd.cd_devs[i]; |
449 | if (pcidev != NULL && | | 451 | if (pcidev != NULL && |
450 | pci_enumerate_bus((struct pci_softc *)pcidev, wildcard, | | 452 | pci_enumerate_bus(device_private(pcidev), wildcard, |
451 | match, pa) != 0) | | 453 | match, pa) != 0) |
452 | return (1); | | 454 | return (1); |
453 | } | | 455 | } |
454 | return (0); | | 456 | return (0); |
455 | } | | 457 | } |
456 | | | 458 | |
457 | #ifndef PCI_MACHDEP_ENUMERATE_BUS | | 459 | #ifndef PCI_MACHDEP_ENUMERATE_BUS |
458 | /* | | 460 | /* |
459 | * Generic PCI bus enumeration routine. Used unless machine-dependent | | 461 | * Generic PCI bus enumeration routine. Used unless machine-dependent |
460 | * code needs to provide something else. | | 462 | * code needs to provide something else. |
461 | */ | | 463 | */ |
462 | int | | 464 | int |
463 | pci_enumerate_bus(struct pci_softc *sc, const int *locators, | | 465 | pci_enumerate_bus(struct pci_softc *sc, const int *locators, |