2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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.
26 * $FreeBSD: src/sys/i386/isa/pcibus.c,v 1.57.2.11 2002/11/13 21:40:40 peter Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
33 #include <sys/kernel.h>
35 #include <pci/pcivar.h>
36 #include <pci/pcireg.h>
37 #include <i386/isa/pcibus.h>
38 #include <machine/pci_cfgreg.h>
39 #include <machine/md_var.h>
45 static devclass_t pcib_devclass;
48 nexus_pcib_is_host_bridge(pcicfgregs *cfg,
49 u_int32_t id, u_int8_t class, u_int8_t subclass,
53 static u_int8_t pxb[4]; /* hack for 450nx */
59 s = "Intel 824?? host to PCI bridge";
60 /* XXX This is a guess */
61 /* *busnum = pci_cfgread(cfg, 0x41, 1); */
65 s = "Intel 82810 (i810 GMCH) Host To Hub bridge";
68 s = "Intel 82810-DC100 (i810-DC100 GMCH) Host To Hub bridge";
71 s = "Intel 82810E (i810E GMCH) Host To Hub bridge";
74 s = "Intel 82443LX (440 LX) host to PCI bridge";
77 s = "Intel 82443BX (440 BX) host to PCI bridge";
80 s = "Intel 82443BX host to PCI bridge (AGP disabled)";
83 s = "Intel 82443MX host to PCI bridge";
86 s = "Intel 82443GX host to PCI bridge";
89 s = "Intel 82443GX host to AGP bridge";
92 s = "Intel 82443GX host to PCI bridge (AGP disabled)";
95 s = "Intel 82454KX/GX (Orion) host to PCI bridge";
96 *busnum = pci_cfgread(cfg, 0x4a, 1);
100 * For the 450nx chipset, there is a whole bundle of
101 * things pretending to be host bridges. The MIOC will
102 * be seen first and isn't really a pci bridge (the
103 * actual busses are attached to the PXB's). We need to
104 * read the registers of the MIOC to figure out the
105 * bus numbers for the PXB channels.
107 * Since the MIOC doesn't have a pci bus attached, we
108 * pretend it wasn't there.
110 pxb[0] = pci_cfgread(cfg, 0xd0, 1); /* BUSNO[0] */
111 pxb[1] = pci_cfgread(cfg, 0xd1, 1) + 1; /* SUBA[0]+1 */
112 pxb[2] = pci_cfgread(cfg, 0xd3, 1); /* BUSNO[1] */
113 pxb[3] = pci_cfgread(cfg, 0xd4, 1) + 1; /* SUBA[1]+1 */
118 s = "Intel 82454NX PXB#0, Bus#A";
122 s = "Intel 82454NX PXB#0, Bus#B";
126 s = "Intel 82454NX PXB#1, Bus#A";
130 s = "Intel 82454NX PXB#1, Bus#B";
136 s = "Intel 82845 Host to PCI bridge";
139 /* AMD -- vendor 0x1022 */
141 s = "AMD Elan SC520 host to PCI bridge";
143 init_AMD_Elan_sc520();
145 printf("*** WARNING: kernel option CPU_ELAN missing");
146 printf("-- timekeeping may be wrong\n");
150 s = "AMD-751 host to PCI bridge";
153 s = "AMD-761 host to PCI bridge";
156 /* SiS -- vendor 0x1039 */
167 s = "SiS 5591 host to PCI bridge";
170 s = "SiS 5591 host to AGP bridge";
173 /* VLSI -- vendor 0x1004 */
175 s = "VLSI 82C592 Host to PCI bridge";
178 /* XXX Here is MVP3, I got the datasheet but NO M/B to test it */
179 /* totally. Please let me know if anything wrong. -F */
180 /* XXX need info on the MVP3 -- any takers? */
182 s = "VIA 82C598MVP (Apollo MVP3) host bridge";
185 /* AcerLabs -- vendor 0x10b9 */
186 /* Funny : The datasheet told me vendor id is "10b8",sub-vendor */
187 /* id is '10b9" but the register always shows "10b9". -Foxfair */
189 s = "AcerLabs M1541 (Aladdin-V) PCI host bridge";
192 /* OPTi -- vendor 0x1045 */
194 s = "OPTi 82C822 host to PCI Bridge";
197 /* ServerWorks -- vendor 0x1166 */
199 s = "ServerWorks NB6536 2.0HE host to PCI bridge";
200 *busnum = pci_cfgread(cfg, 0x44, 1);
206 s = "ServerWorks host to PCI bridge";
207 *busnum = pci_cfgread(cfg, 0x44, 1);
211 s = "ServerWorks NB6635 3.0LE host to PCI bridge";
212 *busnum = pci_cfgread(cfg, 0x44, 1);
216 s = "ServerWorks CIOB30 host to PCI bridge";
217 *busnum = pci_cfgread(cfg, 0x44, 1);
220 /* XXX unknown chipset, but working */
224 s = "ServerWorks host to PCI bridge(unknown chipset)";
225 *busnum = pci_cfgread(cfg, 0x44, 1);
228 /* Integrated Micro Solutions -- vendor 0x10e0 */
230 s = "Integrated Micro Solutions VL Bridge";
234 if (class == PCIC_BRIDGE && subclass == PCIS_BRIDGE_HOST)
235 s = "Host to PCI bridge";
243 * Scan the first pci bus for host-pci bridges and add pcib instances
244 * to the nexus for each bridge.
247 nexus_pcib_identify(driver_t *driver, device_t parent)
256 if (pci_cfgregopen() == 0)
261 for (probe.slot = 0; probe.slot <= PCI_SLOTMAX; probe.slot++) {
263 hdrtype = pci_cfgread(&probe, PCIR_HEADERTYPE, 1);
264 if (hdrtype & PCIM_MFDEV && (!found_orion || hdrtype != 0xff) )
269 probe.func <= pcifunchigh;
272 * Read the IDs and class from the device.
275 u_int8_t class, subclass, busnum;
279 id = pci_cfgread(&probe, PCIR_DEVVENDOR, 4);
282 class = pci_cfgread(&probe, PCIR_CLASS, 1);
283 subclass = pci_cfgread(&probe, PCIR_SUBCLASS, 1);
285 s = nexus_pcib_is_host_bridge(&probe, id,
290 * Add at priority 100 to make sure we
291 * go after any motherboard resources
293 child = BUS_ADD_CHILD(parent, 100,
295 device_set_desc(child, s);
297 if (id == 0x12258086)
299 if (id == 0x84c48086)
304 if (found824xx && probe.bus == 0) {
310 * Make sure we add at least one bridge since some old
311 * hardware doesn't actually have a host-pci bridge device.
312 * Note that pci_cfgregopen() thinks we have PCI devices..
317 "nexus_pcib_identify: no bridge found, adding pcib0 anyway\n");
318 BUS_ADD_CHILD(parent, 100, "pcib", 0);
323 nexus_pcib_probe(device_t dev)
325 if (pci_cfgregopen() != 0) {
326 device_add_child(dev, "pci", device_get_unit(dev));
332 /* route interrupt */
335 nexus_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
337 return(pci_cfgintr(pci_get_bus(dev), pci_get_slot(dev), pin));
340 static device_method_t nexus_pcib_methods[] = {
341 /* Device interface */
342 DEVMETHOD(device_identify, nexus_pcib_identify),
343 DEVMETHOD(device_probe, nexus_pcib_probe),
344 DEVMETHOD(device_attach, bus_generic_attach),
345 DEVMETHOD(device_shutdown, bus_generic_shutdown),
346 DEVMETHOD(device_suspend, bus_generic_suspend),
347 DEVMETHOD(device_resume, bus_generic_resume),
350 DEVMETHOD(bus_print_child, bus_generic_print_child),
351 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
352 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
353 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
354 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
355 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
356 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
359 DEVMETHOD(pci_route_interrupt, nexus_pcib_route_interrupt),
363 static driver_t nexus_pcib_driver = {
369 DRIVER_MODULE(pcib, nexus, nexus_pcib_driver, pcib_devclass, 0, 0);