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