Get rid of PCI_MAP_FIXUP and opt_pci.h
[dragonfly.git] / sys / bus / pci / i386 / pci_bus.c
1 /*-
2  * Copyright (c) 1997, Stefan Esser <se@kfreebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/i386/pci/pci_bus.c,v 1.128.8.1 2009/04/15 03:14:26 kensmith Exp $
27  */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/bus.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/module.h>
35 #include <sys/sysctl.h>
36
37 #include <bus/pci/pcivar.h>
38 #include <bus/pci/pcireg.h>
39 #include <bus/pci/pcib_private.h>
40 #include <bus/isa/isavar.h>
41 #include <machine/md_var.h>
42
43 #include "legacyvar.h"
44 #include "pci_cfgreg.h"
45
46 #include "pcib_if.h"
47
48 static int      pcibios_pcib_route_interrupt(device_t pcib, device_t dev,
49     int pin);
50
51 int
52 legacy_pcib_maxslots(device_t dev)
53 {
54         return 31;
55 }
56
57 /* read configuration space register */
58
59 u_int32_t
60 legacy_pcib_read_config(device_t dev, int bus, int slot, int func,
61                         int reg, int bytes)
62 {
63         return(pci_cfgregread(bus, slot, func, reg, bytes));
64 }
65
66 /* write configuration space register */
67
68 void
69 legacy_pcib_write_config(device_t dev, int bus, int slot, int func,
70                          int reg, u_int32_t data, int bytes)
71 {
72         pci_cfgregwrite(bus, slot, func, reg, data, bytes);
73 }
74
75 /* Pass MSI requests up to the nexus. */
76
77 static int
78 legacy_pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount,
79     int *irqs)
80 {
81         device_t bus;
82
83         bus = device_get_parent(pcib);
84         return (PCIB_ALLOC_MSI(device_get_parent(bus), dev, count, maxcount,
85             irqs));
86 }
87
88 static int
89 legacy_pcib_alloc_msix(device_t pcib, device_t dev, int *irq)
90 {
91         device_t bus;
92
93         bus = device_get_parent(pcib);
94         return (PCIB_ALLOC_MSIX(device_get_parent(bus), dev, irq));
95 }
96
97 static int
98 legacy_pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr,
99     uint32_t *data)
100 {
101         device_t bus;
102
103         bus = device_get_parent(pcib);
104         return (PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data));
105 }
106
107 static const char *
108 legacy_pcib_is_host_bridge(int bus, int slot, int func,
109                           uint32_t id, uint8_t class, uint8_t subclass,
110                           uint8_t *busnum)
111 {
112         const char *s = NULL;
113         static uint8_t pxb[4];  /* hack for 450nx */
114
115         *busnum = 0;
116
117         switch (id) {
118         case 0x12258086:
119                 s = "Intel 824?? host to PCI bridge";
120                 /* XXX This is a guess */
121                 /* *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x41, 1); */
122                 *busnum = bus;
123                 break;
124         case 0x71208086:
125                 s = "Intel 82810 (i810 GMCH) Host To Hub bridge";
126                 break;
127         case 0x71228086:
128                 s = "Intel 82810-DC100 (i810-DC100 GMCH) Host To Hub bridge";
129                 break;
130         case 0x71248086:
131                 s = "Intel 82810E (i810E GMCH) Host To Hub bridge";
132                 break;
133         case 0x11308086:
134                 s = "Intel 82815 (i815 GMCH) Host To Hub bridge";
135                 break;
136         case 0x71808086:
137                 s = "Intel 82443LX (440 LX) host to PCI bridge";
138                 break;
139         case 0x71908086:
140                 s = "Intel 82443BX (440 BX) host to PCI bridge";
141                 break;
142         case 0x71928086:
143                 s = "Intel 82443BX host to PCI bridge (AGP disabled)";
144                 break;
145         case 0x71948086:
146                 s = "Intel 82443MX host to PCI bridge";
147                 break;
148         case 0x71a08086:
149                 s = "Intel 82443GX host to PCI bridge";
150                 break;
151         case 0x71a18086:
152                 s = "Intel 82443GX host to AGP bridge";
153                 break;
154         case 0x71a28086:
155                 s = "Intel 82443GX host to PCI bridge (AGP disabled)";
156                 break;
157         case 0x84c48086:
158                 s = "Intel 82454KX/GX (Orion) host to PCI bridge";
159                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x4a, 1);
160                 break;
161         case 0x84ca8086:
162                 /*
163                  * For the 450nx chipset, there is a whole bundle of
164                  * things pretending to be host bridges. The MIOC will
165                  * be seen first and isn't really a pci bridge (the
166                  * actual busses are attached to the PXB's). We need to
167                  * read the registers of the MIOC to figure out the
168                  * bus numbers for the PXB channels.
169                  *
170                  * Since the MIOC doesn't have a pci bus attached, we
171                  * pretend it wasn't there.
172                  */
173                 pxb[0] = legacy_pcib_read_config(0, bus, slot, func,
174                                                 0xd0, 1); /* BUSNO[0] */
175                 pxb[1] = legacy_pcib_read_config(0, bus, slot, func,
176                                                 0xd1, 1) + 1;   /* SUBA[0]+1 */
177                 pxb[2] = legacy_pcib_read_config(0, bus, slot, func,
178                                                 0xd3, 1); /* BUSNO[1] */
179                 pxb[3] = legacy_pcib_read_config(0, bus, slot, func,
180                                                 0xd4, 1) + 1;   /* SUBA[1]+1 */
181                 return NULL;
182         case 0x84cb8086:
183                 switch (slot) {
184                 case 0x12:
185                         s = "Intel 82454NX PXB#0, Bus#A";
186                         *busnum = pxb[0];
187                         break;
188                 case 0x13:
189                         s = "Intel 82454NX PXB#0, Bus#B";
190                         *busnum = pxb[1];
191                         break;
192                 case 0x14:
193                         s = "Intel 82454NX PXB#1, Bus#A";
194                         *busnum = pxb[2];
195                         break;
196                 case 0x15:
197                         s = "Intel 82454NX PXB#1, Bus#B";
198                         *busnum = pxb[3];
199                         break;
200                 }
201                 break;
202
203                 /* AMD -- vendor 0x1022 */
204         case 0x30001022:
205                 s = "AMD Elan SC520 host to PCI bridge";
206 #ifdef CPU_ELAN
207                 init_AMD_Elan_sc520();
208 #else
209                 kprintf(
210 "*** WARNING: missing CPU_ELAN -- timekeeping may be wrong\n");
211 #endif
212                 break;
213         case 0x70061022:
214                 s = "AMD-751 host to PCI bridge";
215                 break;
216         case 0x700e1022:
217                 s = "AMD-761 host to PCI bridge";
218                 break;
219
220                 /* SiS -- vendor 0x1039 */
221         case 0x04961039:
222                 s = "SiS 85c496";
223                 break;
224         case 0x04061039:
225                 s = "SiS 85c501";
226                 break;
227         case 0x06011039:
228                 s = "SiS 85c601";
229                 break;
230         case 0x55911039:
231                 s = "SiS 5591 host to PCI bridge";
232                 break;
233         case 0x00011039:
234                 s = "SiS 5591 host to AGP bridge";
235                 break;
236
237                 /* VLSI -- vendor 0x1004 */
238         case 0x00051004:
239                 s = "VLSI 82C592 Host to PCI bridge";
240                 break;
241
242                 /* XXX Here is MVP3, I got the datasheet but NO M/B to test it  */
243                 /* totally. Please let me know if anything wrong.            -F */
244                 /* XXX need info on the MVP3 -- any takers? */
245         case 0x05981106:
246                 s = "VIA 82C598MVP (Apollo MVP3) host bridge";
247                 break;
248
249                 /* AcerLabs -- vendor 0x10b9 */
250                 /* Funny : The datasheet told me vendor id is "10b8",sub-vendor */
251                 /* id is '10b9" but the register always shows "10b9". -Foxfair  */
252         case 0x154110b9:
253                 s = "AcerLabs M1541 (Aladdin-V) PCI host bridge";
254                 break;
255
256                 /* OPTi -- vendor 0x1045 */
257         case 0xc7011045:
258                 s = "OPTi 82C700 host to PCI bridge";
259                 break;
260         case 0xc8221045:
261                 s = "OPTi 82C822 host to PCI Bridge";
262                 break;
263
264                 /* ServerWorks -- vendor 0x1166 */
265         case 0x00051166:
266                 s = "ServerWorks NB6536 2.0HE host to PCI bridge";
267                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
268                 break;
269
270         case 0x00061166:
271                 /* FALLTHROUGH */
272         case 0x00081166:
273                 /* FALLTHROUGH */
274         case 0x02011166:
275                 /* FALLTHROUGH */
276         case 0x010f1014: /* IBM re-badged ServerWorks chipset */
277                 s = "ServerWorks host to PCI bridge";
278                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
279                 break;
280
281         case 0x00091166:
282                 s = "ServerWorks NB6635 3.0LE host to PCI bridge";
283                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
284                 break;
285
286         case 0x00101166:
287                 s = "ServerWorks CIOB30 host to PCI bridge";
288                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
289                 break;
290
291         case 0x00111166:
292                 /* FALLTHROUGH */
293         case 0x03021014: /* IBM re-badged ServerWorks chipset */
294                 s = "ServerWorks CMIC-HE host to PCI-X bridge";
295                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
296                 break;
297
298                 /* XXX unknown chipset, but working */
299         case 0x00171166:
300                 /* FALLTHROUGH */
301         case 0x01011166:
302                 s = "ServerWorks host to PCI bridge(unknown chipset)";
303                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0x44, 1);
304                 break;
305
306                 /* Compaq/HP -- vendor 0x0e11 */
307         case 0x60100e11:
308                 s = "Compaq/HP Model 6010 HotPlug PCI Bridge";
309                 *busnum = legacy_pcib_read_config(0, bus, slot, func, 0xc8, 1);
310                 break;
311
312                 /* Integrated Micro Solutions -- vendor 0x10e0 */
313         case 0x884910e0:
314                 s = "Integrated Micro Solutions VL Bridge";
315                 break;
316
317         default:
318                 if (class == PCIC_BRIDGE && subclass == PCIS_BRIDGE_HOST)
319                         s = "Host to PCI bridge";
320                 break;
321         }
322
323         return s;
324 }
325
326 /*
327  * Scan the first pci bus for host-pci bridges and add pcib instances
328  * to the nexus for each bridge.
329  */
330 static int
331 legacy_pcib_identify(driver_t *driver, device_t parent)
332 {
333         int bus, slot, func;
334         u_int8_t  hdrtype;
335         int found = 0;
336         int pcifunchigh;
337         int found824xx = 0;
338         int found_orion = 0;
339         device_t child;
340         devclass_t pci_devclass;
341
342         if (pci_cfgregopen() == 0)
343                 return ENXIO;
344         /*
345          * Check to see if we haven't already had a PCI bus added
346          * via some other means.  If we have, bail since otherwise
347          * we're going to end up duplicating it.
348          */
349         if ((pci_devclass = devclass_find("pci")) &&
350             devclass_get_device(pci_devclass, 0))
351                 return ENXIO;
352
353         bus = 0;
354 retry:
355         for (slot = 0; slot <= PCI_SLOTMAX; slot++) {
356                 func = 0;
357                 hdrtype = legacy_pcib_read_config(0, bus, slot, func,
358                                                  PCIR_HDRTYPE, 1);
359                 /*
360                  * When enumerating bus devices, the standard says that
361                  * one should check the header type and ignore the slots whose
362                  * header types that the software doesn't know about.  We use
363                  * this to filter out devices.
364                  */
365                 if ((hdrtype & PCIM_HDRTYPE) > PCI_MAXHDRTYPE)
366                         continue;
367                 if ((hdrtype & PCIM_MFDEV) &&
368                     (!found_orion || hdrtype != 0xff))
369                         pcifunchigh = PCI_FUNCMAX;
370                 else
371                         pcifunchigh = 0;
372                 for (func = 0; func <= pcifunchigh; func++) {
373                         /*
374                          * Read the IDs and class from the device.
375                          */
376                         u_int32_t id;
377                         u_int8_t class, subclass, busnum;
378                         const char *s;
379                         device_t *devs;
380                         int ndevs, i;
381
382                         id = legacy_pcib_read_config(0, bus, slot, func,
383                                                     PCIR_DEVVENDOR, 4);
384                         if (id == -1)
385                                 continue;
386                         class = legacy_pcib_read_config(0, bus, slot, func,
387                                                        PCIR_CLASS, 1);
388                         subclass = legacy_pcib_read_config(0, bus, slot, func,
389                                                           PCIR_SUBCLASS, 1);
390
391                         s = legacy_pcib_is_host_bridge(bus, slot, func,
392                                                       id, class, subclass,
393                                                       &busnum);
394                         if (s == NULL)
395                                 continue;
396
397                         /*
398                          * Check to see if the physical bus has already
399                          * been seen.  Eg: hybrid 32 and 64 bit host
400                          * bridges to the same logical bus.
401                          */
402                         if (device_get_children(parent, &devs, &ndevs) == 0) {
403                                 for (i = 0; s != NULL && i < ndevs; i++) {
404                                         if (strcmp(device_get_name(devs[i]),
405                                             "pcib") != 0)
406                                                 continue;
407                                         if (legacy_get_pcibus(devs[i]) == busnum)
408                                                 s = NULL;
409                                 }
410                                 kfree(devs, M_TEMP);
411                         }
412
413                         if (s == NULL)
414                                 continue;
415
416                         /*
417                          * Add at priority 100 to make sure we
418                          * go after any motherboard resources
419                          */
420                         child = BUS_ADD_CHILD(parent, parent, 100 + busnum,
421                                               "pcib", busnum);
422                         device_set_desc(child, s);
423                         legacy_set_pcibus(child, busnum);
424
425                         found = 1;
426                         if (id == 0x12258086)
427                                 found824xx = 1;
428                         if (id == 0x84c48086)
429                                 found_orion = 1;
430                 }
431         }
432         if (found824xx && bus == 0) {
433                 bus++;
434                 goto retry;
435         }
436
437         /*
438          * Make sure we add at least one bridge since some old
439          * hardware doesn't actually have a host-pci bridge device.
440          * Note that pci_cfgregopen() thinks we have PCI devices..
441          */
442         if (!found) {
443                 if (bootverbose)
444                         kprintf(
445         "legacy_pcib_identify: no bridge found, adding pcib0 anyway\n");
446                 child = BUS_ADD_CHILD(parent, parent, 100, "pcib", 0);
447                 legacy_set_pcibus(child, 0);
448         }
449         return 0;
450 }
451
452 static int
453 legacy_pcib_probe(device_t dev)
454 {
455         if (pci_cfgregopen() == 0)
456                 return ENXIO;
457         return -100;
458 }
459
460 static int
461 legacy_pcib_attach(device_t dev)
462 {
463         device_t pir;
464         int bus;
465
466         /*
467          * Look for a PCI BIOS interrupt routing table as that will be
468          * our method of routing interrupts if we have one.
469          */
470         bus = pcib_get_bus(dev);
471         if (pci_pir_probe(bus, 0)) {
472                 pir = BUS_ADD_CHILD(device_get_parent(dev), device_get_parent(dev), 0, "pir", 0);
473                 if (pir != NULL)
474                         device_probe_and_attach(pir);
475         }
476         device_add_child(dev, "pci", bus);
477         return bus_generic_attach(dev);
478 }
479
480 int
481 legacy_pcib_read_ivar(device_t dev, device_t child, int which,
482     uintptr_t *result)
483 {
484
485         switch (which) {
486         case  PCIB_IVAR_DOMAIN:
487                 *result = 0;
488                 return 0;
489         case  PCIB_IVAR_BUS:
490                 *result = legacy_get_pcibus(dev);
491                 return 0;
492         }
493         return ENOENT;
494 }
495
496 int
497 legacy_pcib_write_ivar(device_t dev, device_t child, int which,
498     uintptr_t value)
499 {
500
501         switch (which) {
502         case  PCIB_IVAR_DOMAIN:
503                 return EINVAL;
504         case  PCIB_IVAR_BUS:
505                 legacy_set_pcibus(dev, value);
506                 return 0;
507         }
508         return ENOENT;
509 }
510
511 SYSCTL_DECL(_hw_pci);
512
513 static unsigned long legacy_host_mem_start = 0x80000000;
514 /* XXX need TUNABLE_ULONG */
515 TUNABLE_INT("hw.pci.host_mem_start", (int *)&legacy_host_mem_start);
516 SYSCTL_ULONG(_hw_pci, OID_AUTO, host_mem_start, CTLFLAG_RD,
517     &legacy_host_mem_start, 0x80000000,
518     "Limit the host bridge memory to being above this address.  Must be\n\
519 set at boot via a tunable.");
520
521 struct resource *
522 legacy_pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
523     u_long start, u_long end, u_long count, u_int flags)
524 {
525     /*
526      * If no memory preference is given, use upper 32MB slot most
527      * bioses use for their memory window.  Typically other bridges
528      * before us get in the way to assert their preferences on memory.
529      * Hardcoding like this sucks, so a more MD/MI way needs to be
530      * found to do it.  This is typically only used on older laptops
531      * that don't have pci busses behind pci bridge, so assuming > 32MB
532      * is liekly OK.
533      *
534      * However, this can cause problems for other chipsets, so we make
535      * this tunable by hw.pci.host_mem_start.
536      */
537     if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL)
538         start = legacy_host_mem_start;
539     if (type == SYS_RES_IOPORT && start == 0UL && end == ~0UL)
540         start = 0x1000;
541     return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
542         count, flags));
543 }
544
545 static device_method_t legacy_pcib_methods[] = {
546         /* Device interface */
547         DEVMETHOD(device_identify,      legacy_pcib_identify),
548         DEVMETHOD(device_probe,         legacy_pcib_probe),
549         DEVMETHOD(device_attach,        legacy_pcib_attach),
550         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
551         DEVMETHOD(device_suspend,       bus_generic_suspend),
552         DEVMETHOD(device_resume,        bus_generic_resume),
553
554         /* Bus interface */
555         DEVMETHOD(bus_print_child,      bus_generic_print_child),
556         DEVMETHOD(bus_read_ivar,        legacy_pcib_read_ivar),
557         DEVMETHOD(bus_write_ivar,       legacy_pcib_write_ivar),
558         DEVMETHOD(bus_alloc_resource,   legacy_pcib_alloc_resource),
559         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
560         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
561         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
562         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
563         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
564
565         /* pcib interface */
566         DEVMETHOD(pcib_maxslots,        legacy_pcib_maxslots),
567         DEVMETHOD(pcib_read_config,     legacy_pcib_read_config),
568         DEVMETHOD(pcib_write_config,    legacy_pcib_write_config),
569         DEVMETHOD(pcib_route_interrupt, pcibios_pcib_route_interrupt),
570         DEVMETHOD(pcib_alloc_msi,       legacy_pcib_alloc_msi),
571         DEVMETHOD(pcib_release_msi,     pcib_release_msi),
572         DEVMETHOD(pcib_alloc_msix,      legacy_pcib_alloc_msix),
573         DEVMETHOD(pcib_release_msix,    pcib_release_msix),
574         DEVMETHOD(pcib_map_msi,         legacy_pcib_map_msi),
575         { 0, 0 }
576 };
577
578 static devclass_t hostb_devclass;
579
580 DEFINE_CLASS_0(pcib, legacy_pcib_driver, legacy_pcib_methods, 1);
581 DRIVER_MODULE(pcib, legacy, legacy_pcib_driver, hostb_devclass, 0, 0);
582
583
584 /*
585  * Install placeholder to claim the resources owned by the
586  * PCI bus interface.  This could be used to extract the
587  * config space registers in the extreme case where the PnP
588  * ID is available and the PCI BIOS isn't, but for now we just
589  * eat the PnP ID and do nothing else.
590  *
591  * XXX we should silence this probe, as it will generally confuse
592  * people.
593  */
594 static struct isa_pnp_id pcibus_pnp_ids[] = {
595         { 0x030ad041 /* PNP0A03 */, "PCI Bus" },
596         { 0 }
597 };
598
599 static int
600 pcibus_pnp_probe(device_t dev)
601 {
602         int result;
603
604         if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, pcibus_pnp_ids)) <= 0)
605                 device_quiet(dev);
606         return(result);
607 }
608
609 static int
610 pcibus_pnp_attach(device_t dev)
611 {
612         return(0);
613 }
614
615 static device_method_t pcibus_pnp_methods[] = {
616         /* Device interface */
617         DEVMETHOD(device_probe,         pcibus_pnp_probe),
618         DEVMETHOD(device_attach,        pcibus_pnp_attach),
619         DEVMETHOD(device_detach,        bus_generic_detach),
620         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
621         DEVMETHOD(device_suspend,       bus_generic_suspend),
622         DEVMETHOD(device_resume,        bus_generic_resume),
623         { 0, 0 }
624 };
625
626 static devclass_t pcibus_pnp_devclass;
627
628 DEFINE_CLASS_0(pcibus_pnp, pcibus_pnp_driver, pcibus_pnp_methods, 1);
629 DRIVER_MODULE(pcibus_pnp, isa, pcibus_pnp_driver, pcibus_pnp_devclass, 0, 0);
630
631
632 /*
633  * Provide a PCI-PCI bridge driver for PCI busses behind PCI-PCI bridges
634  * that appear in the PCIBIOS Interrupt Routing Table to use the routing
635  * table for interrupt routing when possible.
636  */
637 static int      pcibios_pcib_probe(device_t bus);
638
639 static device_method_t pcibios_pcib_pci_methods[] = {
640         /* Device interface */
641         DEVMETHOD(device_probe,         pcibios_pcib_probe),
642         DEVMETHOD(device_attach,        pcib_attach),
643         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
644         DEVMETHOD(device_suspend,       bus_generic_suspend),
645         DEVMETHOD(device_resume,        bus_generic_resume),
646
647         /* Bus interface */
648         DEVMETHOD(bus_print_child,      bus_generic_print_child),
649         DEVMETHOD(bus_read_ivar,        pcib_read_ivar),
650         DEVMETHOD(bus_write_ivar,       pcib_write_ivar),
651         DEVMETHOD(bus_alloc_resource,   pcib_alloc_resource),
652         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
653         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
654         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
655         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
656         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
657
658         /* pcib interface */
659         DEVMETHOD(pcib_maxslots,        pcib_maxslots),
660         DEVMETHOD(pcib_read_config,     pcib_read_config),
661         DEVMETHOD(pcib_write_config,    pcib_write_config),
662         DEVMETHOD(pcib_route_interrupt, pcibios_pcib_route_interrupt),
663         DEVMETHOD(pcib_alloc_msi,       pcib_alloc_msi),
664         DEVMETHOD(pcib_release_msi,     pcib_release_msi),
665         DEVMETHOD(pcib_alloc_msix,      pcib_alloc_msix),
666         DEVMETHOD(pcib_release_msix,    pcib_release_msix),
667         DEVMETHOD(pcib_map_msi,         pcib_map_msi),
668
669         {0, 0}
670 };
671
672 static devclass_t pcib_devclass;
673
674 DEFINE_CLASS_0(pcib, pcibios_pcib_driver, pcibios_pcib_pci_methods,
675     sizeof(struct pcib_softc));
676 DRIVER_MODULE(pcibios_pcib, pci, pcibios_pcib_driver, pcib_devclass, 0, 0);
677
678 static int
679 pcibios_pcib_probe(device_t dev)
680 {
681         int bus;
682
683         if ((pci_get_class(dev) != PCIC_BRIDGE) ||
684             (pci_get_subclass(dev) != PCIS_BRIDGE_PCI))
685                 return (ENXIO);
686         bus = pci_read_config(dev, PCIR_SECBUS_1, 1);
687         if (bus == 0)
688                 return (ENXIO);
689         if (!pci_pir_probe(bus, 1))
690                 return (ENXIO);
691         device_set_desc(dev, "PCIBIOS PCI-PCI bridge");
692         return (-2000);
693 }
694
695 static int
696 pcibios_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
697 {
698         return (pci_pir_route_interrupt(pci_get_bus(dev), pci_get_slot(dev),
699                 pci_get_function(dev), pin));
700 }