Nuke device_ptr_t, USBBASEDEVICE, USBDEVNAME(), USBDEVUNIT(), USBGETSOFTC(),
[dragonfly.git] / sys / bus / pci / pci_pcib.c
1 /*
2  * Copyright (c) 2004, Joerg Sonnenberger <joerg@bec.de>
3  * All rights reserved.
4  * Copyright (c) 1994,1995 Stefan Esser.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $DragonFly: src/sys/bus/pci/pci_pcib.c,v 1.7 2007/06/08 13:52:09 sephe Exp $
30  */
31
32 #include "opt_pci.h"
33
34 #include <sys/param.h>
35 #include <sys/bus.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
39 #include <sys/rman.h>
40 #include <sys/systm.h>
41
42 #include <bus/pci/pcivar.h>
43 #include <bus/pci/pcireg.h>
44 #include "pcib_if.h"
45 #include "pcib_private.h"
46
47 static devclass_t pcib_devclass;
48
49 /*
50  * Attach a pci bus device to a motherboard or pci-to-pci bridge bus.
51  * Due to probe recursion it is possible for pci-to-pci bridges (such as
52  * on the DELL2550) to attach before all the motherboard bridges have
53  * attached.  We must call device_add_child() with the secondary id
54  * rather then -1 in order to ensure that we do not accidently use
55  * a motherboard PCI id, otherwise the device probe will believe that
56  * the later motherboard bridge bus has already been probed and refuse
57  * to probe it.  The result: disappearing busses!
58  *
59  * Bridges will cause recursions or duplicate attach attempts.  If
60  * we have already attached this bus we don't do it again!
61  *
62  * NOTE THE DEVICE TOPOLOGY!    
63  *
64  *      [pcibX]->[pciX]->[pciX.Y]
65  *                       [pcibZ]
66  *
67  * When attaching a new bus device note that the PCI methods are
68  * based in the parent device, but the device ivars for those methods
69  * are based in our sub-device.  The PCI accessor functions all assume
70  * you are passing-in the sub-device.
71  */
72 void
73 pcib_attach_common(device_t dev)
74 {
75     struct pcib_softc   *sc;
76     uint8_t             iolow;
77
78     sc = device_get_softc(dev);
79     sc->dev = dev;
80
81     /*
82      * Get current bridge configuration.
83      */
84     sc->command   = pci_read_config(dev, PCIR_COMMAND, 1);
85     sc->secbus    = pci_read_config(dev, PCIR_SECBUS_1, 1);
86     sc->subbus    = pci_read_config(dev, PCIR_SUBBUS_1, 1);
87     sc->secstat   = pci_read_config(dev, PCIR_SECSTAT_1, 2);
88     sc->bridgectl = pci_read_config(dev, PCIR_BRIDGECTL_1, 2);
89     sc->seclat    = pci_read_config(dev, PCIR_SECLAT_1, 1);
90
91     /*
92      * Determine current I/O decode.
93      */
94     if (sc->command & PCIM_CMD_PORTEN) {
95         iolow = pci_read_config(dev, PCIR_IOBASEL_1, 1);
96         if ((iolow & PCIM_BRIO_MASK) == PCIM_BRIO_32) {
97             sc->iobase = PCI_PPBIOBASE(pci_read_config(dev, PCIR_IOBASEH_1, 2),
98                                        pci_read_config(dev, PCIR_IOBASEL_1, 1));
99         } else {
100             sc->iobase = PCI_PPBIOBASE(0, pci_read_config(dev, PCIR_IOBASEL_1, 1));
101         }
102
103         iolow = pci_read_config(dev, PCIR_IOLIMITL_1, 1);
104         if ((iolow & PCIM_BRIO_MASK) == PCIM_BRIO_32) {
105             sc->iolimit = PCI_PPBIOLIMIT(pci_read_config(dev, PCIR_IOLIMITH_1, 2),
106                                          pci_read_config(dev, PCIR_IOLIMITL_1, 1));
107         } else {
108             sc->iolimit = PCI_PPBIOLIMIT(0, pci_read_config(dev, PCIR_IOLIMITL_1, 1));
109         }
110     }
111
112     /*
113      * Determine current memory decode.
114      */
115     if (sc->command & PCIM_CMD_MEMEN) {
116         sc->membase   = PCI_PPBMEMBASE(0, pci_read_config(dev, PCIR_MEMBASE_1, 2));
117         sc->memlimit  = PCI_PPBMEMLIMIT(0, pci_read_config(dev, PCIR_MEMLIMIT_1, 2));
118         sc->pmembase  = PCI_PPBMEMBASE((pci_addr_t)pci_read_config(dev, PCIR_PMBASEH_1, 4),
119                                        pci_read_config(dev, PCIR_PMBASEL_1, 2));
120         sc->pmemlimit = PCI_PPBMEMLIMIT((pci_addr_t)pci_read_config(dev, PCIR_PMLIMITH_1, 4),
121                                         pci_read_config(dev, PCIR_PMLIMITL_1, 2));
122     }
123
124     /*
125      * Quirk handling.
126      */
127     switch (pci_get_devid(dev)) {
128     case 0x12258086:            /* Intel 82454KX/GX (Orion) */
129         {
130             uint8_t     supbus;
131
132             supbus = pci_read_config(dev, 0x41, 1);
133             if (supbus != 0xff) {
134                 sc->secbus = supbus + 1;
135                 sc->subbus = supbus + 1;
136             }
137             break;
138         }
139
140     /*
141      * The i82380FB mobile docking controller is a PCI-PCI bridge,
142      * and it is a subtractive bridge.  However, the ProgIf is wrong
143      * so the normal setting of PCIB_SUBTRACTIVE bit doesn't
144      * happen.  There's also a Toshiba bridge that behaves this
145      * way.
146      */
147     case 0x124b8086:            /* Intel 82380FB Mobile */
148     case 0x060513d7:            /* Toshiba ???? */
149         sc->flags |= PCIB_SUBTRACTIVE;
150         break;
151     }
152
153     /*
154      * Intel 815, 845 and other chipsets say they are PCI-PCI bridges,
155      * but have a ProgIF of 0x80.  The 82801 family (AA, AB, BAM/CAM,
156      * BA/CA/DB and E) PCI bridges are HUB-PCI bridges, in Intelese.
157      * This means they act as if they were subtractively decoding
158      * bridges and pass all transactions.  Mark them and real ProgIf 1
159      * parts as subtractive.
160      */
161     if ((pci_get_devid(dev) & 0xff00ffff) == 0x24008086 ||
162       pci_read_config(dev, PCIR_PROGIF, 1) == 1)
163         sc->flags |= PCIB_SUBTRACTIVE;
164         
165     if (bootverbose) {
166         device_printf(dev, "  secondary bus     %d\n", sc->secbus);
167         device_printf(dev, "  subordinate bus   %d\n", sc->subbus);
168         device_printf(dev, "  I/O decode        0x%x-0x%x\n", sc->iobase, sc->iolimit);
169         device_printf(dev, "  memory decode     0x%x-0x%x\n", sc->membase, sc->memlimit);
170         device_printf(dev, "  prefetched decode 0x%x-0x%x\n", sc->pmembase, sc->pmemlimit);
171         if (sc->flags & PCIB_SUBTRACTIVE)
172             device_printf(dev, "  Subtractively decoded bridge.\n");
173     }
174
175     /*
176      * XXX If the secondary bus number is zero, we should assign a bus number
177      *     since the BIOS hasn't, then initialise the bridge.
178      */
179
180     /*
181      * XXX If the subordinate bus number is less than the secondary bus number,
182      *     we should pick a better value.  One sensible alternative would be to
183      *     pick 255; the only tradeoff here is that configuration transactions
184      *     would be more widely routed than absolutely necessary.
185      */
186 }
187
188 /*
189  * Called with the bridge candidate, which is under a PCI slot device.
190  * Note that the ivars are stored in the candidate.
191  */
192 static const char *
193 pci_match_bridge(device_t dev)
194 {
195         switch (pci_get_devid(dev)) {
196         /* Intel -- vendor 0x8086 */
197         case 0x71818086:
198                 return ("Intel 82443LX (440 LX) PCI-PCI (AGP) bridge");
199         case 0x71918086:
200                 return ("Intel 82443BX (440 BX) PCI-PCI (AGP) bridge");
201         case 0x71A18086:
202                 return ("Intel 82443GX (440 GX) PCI-PCI (AGP) bridge");
203         case 0x84cb8086:
204                 return ("Intel 82454NX PCI Expander Bridge");
205         case 0x11318086:
206                 return ("Intel 82801BA/BAM (ICH2) PCI-PCI (AGP) bridge");
207         case 0x124b8086:
208                 return ("Intel 82380FB mobile PCI to PCI bridge");
209         case 0x24188086:
210                 return ("Intel 82801AA (ICH) Hub to PCI bridge");
211         case 0x24288086:
212                 return ("Intel 82801AB (ICH0) Hub to PCI bridge");
213         case 0x244e8086:
214                 return ("Intel 82801BA/CA/DB/EB/FB (ICH2/3/4/5/6) Hub to PCI bridge");
215         case 0x1a318086:
216                 return ("Intel 82845 PCI-PCI (AGP) bridge");
217         
218         /* VLSI -- vendor 0x1004 */
219         case 0x01021004:
220                 return ("VLSI 82C534 Eagle II PCI Bus bridge");
221         case 0x01031004:
222                 return ("VLSI 82C538 Eagle II PCI Docking bridge");
223
224         /* VIA Technologies -- vendor 0x1106 */
225         case 0x83051106:
226                 return ("VIA 8363 (Apollo KT133) PCI-PCI (AGP) bridge");
227         case 0x85981106:
228                 return ("VIA 82C598MVP (Apollo MVP3) PCI-PCI (AGP) bridge");
229         /* Exclude the ACPI function of VT82Cxxx series */
230         case 0x30401106:
231         case 0x30501106:
232         case 0x30571106:
233                 return NULL;
234
235         /* AcerLabs -- vendor 0x10b9 */
236         /* Funny : The datasheet told me vendor id is "10b8",sub-vendor */
237         /* id is '10b9" but the register always shows "10b9". -Foxfair  */
238         case 0x524710b9:
239                 return ("AcerLabs M5247 PCI-PCI(AGP Supported) bridge");
240         case 0x524310b9:/* 5243 seems like 5247, need more info to divide*/
241                 return ("AcerLabs M5243 PCI-PCI bridge");
242
243         /* AMD -- vendor 0x1022 */
244         case 0x70071022:
245                 return ("AMD-751 PCI-PCI (1x/2x AGP) bridge");
246         case 0x700f1022:
247                 return ("AMD-761 PCI-PCI (4x AGP) bridge");
248
249         /* DEC -- vendor 0x1011 */
250         case 0x00011011:
251                 return ("DEC 21050 PCI-PCI bridge");
252         case 0x00211011:
253                 return ("DEC 21052 PCI-PCI bridge");
254         case 0x00221011:
255                 return ("DEC 21150 PCI-PCI bridge");
256         case 0x00241011:
257                 return ("DEC 21152 PCI-PCI bridge");
258         case 0x00251011:
259                 return ("DEC 21153 PCI-PCI bridge");
260         case 0x00261011:
261                 return ("DEC 21154 PCI-PCI bridge");
262
263         /* NVIDIA -- vendor 0x10de */
264         case 0x006c10de:
265         case 0x01e810de:
266                 return ("NVIDIA nForce2 PCI-PCI bridge");
267
268         /* Others */
269         case 0x00221014:
270                 return ("IBM 82351 PCI-PCI bridge");
271         /* UMC United Microelectronics 0x1060 */
272         case 0x88811060:
273                 return ("UMC UM8881 HB4 486 PCI Chipset");
274         };
275
276         if (pci_get_class(dev) == PCIC_BRIDGE
277             && pci_get_subclass(dev) == PCIS_BRIDGE_PCI) {
278                 return pci_bridge_type(dev);
279         }
280
281         return NULL;
282 }
283
284 /*
285  * bus/pci/i386/pcibus.c added "pcib" devices under "pci" (slot) devices,
286  * causing us to probe and attach here.
287  *
288  * Note that the parent "pci" device has stored ivars in our device.  We
289  * are both a "pci" device and potentially a "pcib" device.
290  */
291 static int
292 pcib_probe(device_t dev)
293 {
294         const char *desc;
295
296         desc = pci_match_bridge(dev);
297         if (desc) {
298                 device_set_desc_copy(dev, desc);
299                 return -1000;
300         }
301
302         return ENXIO;
303 }
304
305 /*
306  * Note that the "pci" device ivars are stored in the ivar data field
307  * for our device.  The "pcib" device ivars are stored in the softc
308  * structure.
309  */
310 int
311 pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
312 {
313         struct pcib_softc *sc = device_get_softc(dev);
314
315         switch (which) {
316         case PCIB_IVAR_BUS:
317                 *result = sc->secbus;
318                 return (0);
319         }
320         return (ENOENT);
321 }
322
323 int
324 pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
325 {
326         struct pcib_softc *sc = device_get_softc(dev);
327
328         switch (which) {
329         case PCIB_IVAR_BUS:
330                 sc->secbus = value;
331                 return (0);
332         }
333         return (ENOENT);
334 }
335
336 int
337 pcib_attach(device_t dev)
338 {
339         struct pcib_softc *sc;
340
341         pcib_attach_common(dev);
342         sc = device_get_softc(dev);
343         /*chipset_attach(dev, device_get_unit(dev));*/
344
345         /*
346          * The pcib unit is not really under our control because
347          * we have are not (XXX) using the identify interface to
348          * assign the bridge driver, instead letting subr_bus do
349          * it via the probe mechanism.  However, we *do* directly
350          * create the "pci" children and we can control the unit
351          * number we assign for those.  We assign the secondary bus
352          * id as the unit number.
353          */
354         if (sc->secbus != 0) {
355                 if (devclass_find_unit("pci", sc->secbus)) {
356                         device_printf(dev, "Duplicate secondary bus %d, "
357                                            "cannot attach bridge\n",
358                                            sc->secbus);
359
360                 } else {
361                         device_add_child(dev, "pci", sc->secbus);
362                         bus_generic_attach(dev);
363                 }
364         } 
365         return 0;
366 }
367
368 /*
369  * Is the prefetch window open (eg, can we allocate memory in it?)
370  */
371 static int
372 pcib_is_prefetch_open(struct pcib_softc *sc)
373 {
374         return (sc->pmembase > 0 && sc->pmembase < sc->pmemlimit);
375 }
376
377 /*
378  * Is the nonprefetch window open (eg, can we allocate memory in it?)
379  */
380 static int
381 pcib_is_nonprefetch_open(struct pcib_softc *sc)
382 {
383         return (sc->membase > 0 && sc->membase < sc->memlimit);
384 }
385
386 /*
387  * Is the io window open (eg, can we allocate ports in it?)
388  */
389 static int
390 pcib_is_io_open(struct pcib_softc *sc)
391 {
392         return (sc->iobase > 0 && sc->iobase < sc->iolimit);
393 }
394
395 /*
396  * We have to trap resource allocation requests and ensure that the bridge
397  * is set up to, or capable of handling them.
398  */
399 struct resource *
400 pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, 
401                     u_long start, u_long end, u_long count, u_int flags)
402 {
403         struct pcib_softc *sc = device_get_softc(dev);
404         int ok;
405
406         /*
407          * Fail the allocation for this range if it's not supported.
408          */
409         switch (type) {
410         case SYS_RES_IOPORT:
411                 ok = 0;
412                 if (!pcib_is_io_open(sc))
413                         break;
414                 ok = (start >= sc->iobase && end <= sc->iolimit);
415                 if ((sc->flags & PCIB_SUBTRACTIVE) == 0) {
416                         if (!ok) {
417                                 if (start < sc->iobase)
418                                         start = sc->iobase;
419                                 if (end > sc->iolimit)
420                                         end = sc->iolimit;
421                                 if (start < end)
422                                         ok = 1;
423                         }
424                 } else {
425                         ok = 1;
426 #ifdef PCI_MAP_FIXUP
427                         if (start < sc->iobase && end > sc->iolimit) {
428                                 start = sc->iobase;
429                                 end = sc->iolimit;
430                         }
431 #endif                  
432                 }
433                 if (end < start) {
434                         device_printf(dev, "ioport: end (%lx) < start (%lx)\n", end, start);
435                         start = 0;
436                         end = 0;
437                         ok = 0;
438                 }
439                 if (!ok) {
440                         device_printf(dev, "device %s requested unsupported I/O "
441                             "range 0x%lx-0x%lx (decoding 0x%x-0x%x)\n",
442                             device_get_nameunit(child), start, end,
443                             sc->iobase, sc->iolimit);
444                         return (NULL);
445                 }
446                 if (bootverbose)
447                         device_printf(dev, "device %s requested decoded I/O range 0x%lx-0x%lx\n",
448                             device_get_nameunit(child), start, end);
449                 break;
450
451         case SYS_RES_MEMORY:
452                 ok = 0;
453                 if (pcib_is_nonprefetch_open(sc))
454                         ok = ok || (start >= sc->membase && end <= sc->memlimit);
455                 if (pcib_is_prefetch_open(sc))
456                         ok = ok || (start >= sc->pmembase && end <= sc->pmemlimit);
457                 if ((sc->flags & PCIB_SUBTRACTIVE) == 0) {
458                         if (!ok) {
459                                 ok = 1;
460                                 if (flags & RF_PREFETCHABLE) {
461                                         if (pcib_is_prefetch_open(sc)) {
462                                                 if (start < sc->pmembase)
463                                                         start = sc->pmembase;
464                                                 if (end > sc->pmemlimit)
465                                                         end = sc->pmemlimit;
466                                         } else {
467                                                 ok = 0;
468                                         }
469                                 } else {        /* non-prefetchable */
470                                         if (pcib_is_nonprefetch_open(sc)) {
471                                                 if (start < sc->membase)
472                                                         start = sc->membase;
473                                                 if (end > sc->memlimit)
474                                                         end = sc->memlimit;
475                                         } else {
476                                                 ok = 0;
477                                         }
478                                 }
479                         }
480                 } else if (!ok) {
481                         ok = 1; /* subtractive bridge: always ok */
482 #ifdef PCI_MAP_FIXUP
483                         if (pcib_is_nonprefetch_open(sc)) {
484                                 if (start < sc->membase && end > sc->memlimit) {
485                                         start = sc->membase;
486                                         end = sc->memlimit;
487                                 }
488                         }
489                         if (pcib_is_prefetch_open(sc)) {
490                                 if (start < sc->pmembase && end > sc->pmemlimit) {
491                                         start = sc->pmembase;
492                                         end = sc->pmemlimit;
493                                 }
494                         }
495 #endif
496                 }
497                 if (end < start) {
498                         device_printf(dev, "memory: end (%lx) < start (%lx)\n", end, start);
499                         start = 0;
500                         end = 0;
501                         ok = 0;
502                 }
503                 if (!ok && bootverbose)
504                         device_printf(dev,
505                             "device %s requested unsupported memory range "
506                             "0x%lx-0x%lx (decoding 0x%x-0x%x, 0x%x-0x%x)\n",
507                             device_get_nameunit(child), start, end,
508                             sc->membase, sc->memlimit, sc->pmembase,
509                             sc->pmemlimit);
510                 if (!ok)
511                         return (NULL);
512                 if (bootverbose)
513                         device_printf(dev,"device %s requested decoded memory range 0x%lx-0x%lx\n",
514                             device_get_nameunit(child), start, end);
515                 break;
516
517         default:
518                 break;
519         }
520         /*
521          * Bridge is OK decoding this resource, so pass it up.
522          */
523         return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags));
524 }
525
526 int
527 pcib_maxslots(device_t dev)
528 {
529         return (31);
530 }
531
532 u_int32_t
533 pcib_read_config(device_t dev, int b, int s, int f,
534                  int reg, int width)
535 {
536         /*
537          * Pass through to the next ppb up the chain (i.e. our
538          * grandparent).
539          *
540          * [pcibX]->[pciX]->[pciX.Y]
541          *                  [pcibY]
542          *   ^
543          * getting back to this point.
544          */
545         return PCIB_READ_CONFIG(device_get_parent(device_get_parent(dev)),
546                                 b, s, f, reg, width);
547 }
548
549 void
550 pcib_write_config(device_t dev, int b, int s, int f,
551                   int reg, uint32_t val, int width)
552 {
553         /*
554          * Pass through to the next ppb up the chain (i.e. our
555          * grandparent).
556          */
557         PCIB_WRITE_CONFIG(device_get_parent(device_get_parent(dev)),
558                                 b, s, f, reg, val, width);      
559 }
560
561 /*
562  * Route an interrupt across a PCI bridge.
563  *
564  * pcib - is the pci bridge device
565  * dev  - is the device
566  */
567 int
568 pcib_route_interrupt(device_t pcib, device_t dev, int pin)
569 {
570         device_t        bus;
571         int             parent_intpin;
572         int             intnum;
573
574         /*      
575          *
576          * The PCI standard defines a swizzle of the child-side device/intpin
577          * to the parent-side intpin as follows.
578          *
579          * device = device on child bus
580          * child_intpin = intpin on child bus slot (0-3)
581          * parent_intpin = intpin on parent bus slot (0-3)
582          *
583          * parent_intpin = (device + child_intpin) % 4
584          */
585         parent_intpin = (pci_get_slot(pcib) + (pin - 1)) % 4;
586
587         /*
588          * Our parent is a PCI bus.  Its parent must export the pci interface
589          * which includes the ability to route interrupts.
590          */
591         bus = device_get_parent(pcib);
592         intnum = PCIB_ROUTE_INTERRUPT(device_get_parent(bus), pcib,
593             parent_intpin + 1);
594         device_printf(pcib, "routed slot %d INT%c to irq %d\n",
595             pci_get_slot(dev), 'A' + pin - 1, intnum);
596         return(intnum);
597 }
598
599 /*
600  * Try to read the bus number of a host-PCI bridge using appropriate config
601  * registers.
602  */
603 int
604 host_pcib_get_busno(pci_read_config_fn read_config, int bus, int slot, int func,
605     uint8_t *busnum)
606 {
607         uint32_t id;
608
609         id = read_config(bus, slot, func, PCIR_DEVVENDOR, 4);
610         if (id == 0xffffffff)
611                 return (0);
612
613         switch (id) {
614         case 0x12258086:
615                 /* Intel 824?? */
616                 /* XXX This is a guess */
617                 /* *busnum = read_config(bus, slot, func, 0x41, 1); */
618                 *busnum = bus;
619                 break;
620         case 0x84c48086:
621                 /* Intel 82454KX/GX (Orion) */
622                 *busnum = read_config(bus, slot, func, 0x4a, 1);
623                 break;
624         case 0x84ca8086:
625                 /*
626                  * For the 450nx chipset, there is a whole bundle of
627                  * things pretending to be host bridges. The MIOC will 
628                  * be seen first and isn't really a pci bridge (the
629                  * actual busses are attached to the PXB's). We need to 
630                  * read the registers of the MIOC to figure out the
631                  * bus numbers for the PXB channels.
632                  *
633                  * Since the MIOC doesn't have a pci bus attached, we
634                  * pretend it wasn't there.
635                  */
636                 return (0);
637         case 0x84cb8086:
638                 switch (slot) {
639                 case 0x12:
640                         /* Intel 82454NX PXB#0, Bus#A */
641                         *busnum = read_config(bus, 0x10, func, 0xd0, 1);
642                         break;
643                 case 0x13:
644                         /* Intel 82454NX PXB#0, Bus#B */
645                         *busnum = read_config(bus, 0x10, func, 0xd1, 1) + 1;
646                         break;
647                 case 0x14:
648                         /* Intel 82454NX PXB#1, Bus#A */
649                         *busnum = read_config(bus, 0x10, func, 0xd3, 1);
650                         break;
651                 case 0x15:
652                         /* Intel 82454NX PXB#1, Bus#B */
653                         *busnum = read_config(bus, 0x10, func, 0xd4, 1) + 1;
654                         break;
655                 }
656                 break;
657
658                 /* ServerWorks -- vendor 0x1166 */
659         case 0x00051166:
660         case 0x00061166:
661         case 0x00081166:
662         case 0x00091166:
663         case 0x00101166:
664         case 0x00111166:
665         case 0x00171166:
666         case 0x01011166:
667         case 0x010f1014:
668         case 0x02011166:
669         case 0x03021014:
670                 *busnum = read_config(bus, slot, func, 0x44, 1);
671                 break;
672         default:
673                 /* Don't know how to read bus number. */
674                 return 0;
675         }
676
677         return 1;
678 }
679
680 static device_method_t pcib_methods[] = {
681         /* Device interface */
682         DEVMETHOD(device_probe,         pcib_probe),
683         DEVMETHOD(device_attach,        pcib_attach),
684         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
685         DEVMETHOD(device_suspend,       bus_generic_suspend),
686         DEVMETHOD(device_resume,        bus_generic_resume),
687
688         /* Bus interface */
689         DEVMETHOD(bus_print_child,      bus_generic_print_child),
690         DEVMETHOD(bus_read_ivar,        pcib_read_ivar),
691         DEVMETHOD(bus_write_ivar,       pcib_write_ivar),
692         DEVMETHOD(bus_alloc_resource,   pcib_alloc_resource),
693         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
694         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
695         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
696         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
697         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
698
699         /* pcib interface */
700         DEVMETHOD(pcib_maxslots,        pcib_maxslots),
701         DEVMETHOD(pcib_read_config,     pcib_read_config),
702         DEVMETHOD(pcib_write_config,    pcib_write_config),
703         DEVMETHOD(pcib_route_interrupt, pcib_route_interrupt),
704
705         { 0, 0 }
706 };
707
708 static driver_t pcib_driver = {
709         "pcib",
710         pcib_methods,
711         sizeof(struct pcib_softc)
712 };
713
714 DRIVER_MODULE(pcib, pci, pcib_driver, pcib_devclass, 0, 0);