2 * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
3 * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
4 * Copyright (c) 2000 BSDi
5 * Copyright (c) 2001 - 2003 Thomas Moestl <tmm@FreeBSD.org>
6 * Copyright (c) 2009 by Marius Strobl <marius@FreeBSD.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from: FreeBSD: src/sys/dev/pci/pci_pci.c,v 1.3 2000/12/13
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include "opt_ofw_pci.h"
40 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/libkern.h>
44 #include <sys/module.h>
46 #include <dev/ofw/ofw_bus.h>
47 #include <dev/ofw/openfirm.h>
49 #include <machine/bus.h>
51 #include <dev/pci/pcireg.h>
52 #include <dev/pci/pcivar.h>
53 #include <dev/pci/pcib_private.h>
57 #include <sparc64/pci/ofw_pci.h>
58 #include <sparc64/pci/ofw_pcib_subr.h>
60 static device_probe_t ofw_pcib_probe;
61 static device_attach_t ofw_pcib_attach;
63 static device_method_t ofw_pcib_methods[] = {
64 /* Device interface */
65 DEVMETHOD(device_probe, ofw_pcib_probe),
66 DEVMETHOD(device_attach, ofw_pcib_attach),
67 DEVMETHOD(device_shutdown, bus_generic_shutdown),
68 DEVMETHOD(device_suspend, bus_generic_suspend),
69 DEVMETHOD(device_resume, bus_generic_resume),
72 DEVMETHOD(bus_print_child, bus_generic_print_child),
73 DEVMETHOD(bus_read_ivar, pcib_read_ivar),
74 DEVMETHOD(bus_write_ivar, pcib_write_ivar),
75 DEVMETHOD(bus_alloc_resource, pcib_alloc_resource),
76 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
77 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
78 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
79 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
80 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
83 DEVMETHOD(pcib_maxslots, pcib_maxslots),
84 DEVMETHOD(pcib_read_config, pcib_read_config),
85 DEVMETHOD(pcib_write_config, pcib_write_config),
86 DEVMETHOD(pcib_route_interrupt, ofw_pcib_gen_route_interrupt),
87 DEVMETHOD(pcib_alloc_msi, pcib_alloc_msi),
88 DEVMETHOD(pcib_release_msi, pcib_release_msi),
89 DEVMETHOD(pcib_alloc_msix, pcib_alloc_msix),
90 DEVMETHOD(pcib_release_msix, pcib_release_msix),
91 DEVMETHOD(pcib_map_msi, pcib_map_msi),
93 /* ofw_bus interface */
94 DEVMETHOD(ofw_bus_get_node, ofw_pcib_gen_get_node),
99 static devclass_t pcib_devclass;
101 DEFINE_CLASS_0(pcib, ofw_pcib_driver, ofw_pcib_methods,
102 sizeof(struct ofw_pcib_gen_softc));
103 EARLY_DRIVER_MODULE(ofw_pcib, pci, ofw_pcib_driver, pcib_devclass, 0, 0,
105 MODULE_DEPEND(ofw_pcib, pci, 1, 1, 1);
108 ofw_pcib_probe(device_t dev)
110 char desc[sizeof("OFW PCIe-PCIe bridge")];
111 const char *dtype, *pbdtype;
113 #define ISDTYPE(dtype, type) \
114 (((dtype) != NULL) && strcmp((dtype), (type)) == 0)
116 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
117 (pci_get_subclass(dev) == PCIS_BRIDGE_PCI) &&
118 ofw_bus_get_node(dev) != 0) {
119 dtype = ofw_bus_get_type(dev);
120 pbdtype = ofw_bus_get_type(device_get_parent(
121 device_get_parent(dev)));
122 snprintf(desc, sizeof(desc), "OFW PCI%s-PCI%s bridge",
123 ISDTYPE(pbdtype, OFW_TYPE_PCIE) ? "e" : "",
124 ISDTYPE(dtype, OFW_TYPE_PCIE) ? "e" : "");
125 device_set_desc_copy(dev, desc);
135 ofw_pcib_attach(device_t dev)
137 struct ofw_pcib_gen_softc *sc;
139 sc = device_get_softc(dev);
142 switch (pci_get_devid(dev)) {
144 * The ALi M5249 found in Fire-based machines by definition must me
145 * subtractive as they have a ISA bridge on their secondary side but
146 * don't indicate this in the class code although the ISA I/O range
147 * isn't included in their bridge decode.
150 sc->ops_pcib_sc.flags |= PCIB_SUBTRACTIVE;
154 ofw_pcib_gen_setup(dev);
155 pcib_attach_common(dev);
156 device_add_child(dev, "pci", -1);
157 return (bus_generic_attach(dev));