2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following 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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Host to PCI and PCI to PCI bridge drivers that use the MP Table to route
31 * interrupts from PCI devices to I/O APICs.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
44 #include <dev/pci/pcireg.h>
45 #include <dev/pci/pcivar.h>
46 #include <dev/pci/pcib_private.h>
47 #include <x86/mptable.h>
48 #include <x86/legacyvar.h>
49 #include <machine/pci_cfgreg.h>
53 /* Host to PCI bridge driver. */
56 mptable_hostb_probe(device_t dev)
59 if (pci_cfgregopen() == 0)
61 if (mptable_pci_probe_table(pcib_get_bus(dev)) != 0)
63 device_set_desc(dev, "MPTable Host-PCI bridge");
68 mptable_hostb_attach(device_t dev)
72 mptable_pci_host_res_init(dev);
74 device_add_child(dev, "pci", -1);
75 return (bus_generic_attach(dev));
80 mptable_is_isa_range(rman_res_t start, rman_res_t end)
85 if ((start & 0xfc00) != (end & 0xfc00))
89 return (start >= 0x100 && end <= 0x3ff);
93 mptable_is_vga_range(rman_res_t start, rman_res_t end)
97 if ((start & 0xfc00) != (end & 0xfc00))
101 return (pci_is_vga_ioport_range(start, end));
104 static struct resource *
105 mptable_hostb_alloc_resource(device_t dev, device_t child, int type, int *rid,
106 rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
108 struct mptable_hostb_softc *sc;
111 if (type == PCI_RES_BUS)
112 return (pci_domain_alloc_bus(0, child, rid, start, end, count,
115 sc = device_get_softc(dev);
116 if (type == SYS_RES_IOPORT && start + count - 1 == end) {
117 if (mptable_is_isa_range(start, end)) {
118 switch (sc->sc_decodes_isa_io) {
122 return (bus_generic_alloc_resource(dev, child,
123 type, rid, start, end, count, flags));
128 if (mptable_is_vga_range(start, end)) {
129 switch (sc->sc_decodes_vga_io) {
133 return (bus_generic_alloc_resource(dev, child,
134 type, rid, start, end, count, flags));
140 start = hostb_alloc_start(type, start, end, count);
141 return (pcib_host_res_alloc(&sc->sc_host_res, child, type, rid, start,
146 mptable_hostb_adjust_resource(device_t dev, device_t child, int type,
147 struct resource *r, rman_res_t start, rman_res_t end)
149 struct mptable_hostb_softc *sc;
152 if (type == PCI_RES_BUS)
153 return (pci_domain_adjust_bus(0, child, r, start, end));
155 sc = device_get_softc(dev);
156 return (pcib_host_res_adjust(&sc->sc_host_res, child, type, r, start,
161 static device_method_t mptable_hostb_methods[] = {
162 /* Device interface */
163 DEVMETHOD(device_probe, mptable_hostb_probe),
164 DEVMETHOD(device_attach, mptable_hostb_attach),
165 DEVMETHOD(device_shutdown, bus_generic_shutdown),
166 DEVMETHOD(device_suspend, bus_generic_suspend),
167 DEVMETHOD(device_resume, bus_generic_resume),
170 DEVMETHOD(bus_read_ivar, legacy_pcib_read_ivar),
171 DEVMETHOD(bus_write_ivar, legacy_pcib_write_ivar),
173 DEVMETHOD(bus_alloc_resource, mptable_hostb_alloc_resource),
174 DEVMETHOD(bus_adjust_resource, mptable_hostb_adjust_resource),
176 DEVMETHOD(bus_alloc_resource, legacy_pcib_alloc_resource),
177 DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource),
179 #if defined(NEW_PCIB) && defined(PCI_RES_BUS)
180 DEVMETHOD(bus_release_resource, legacy_pcib_release_resource),
182 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
184 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
185 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
186 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
187 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
190 DEVMETHOD(pcib_maxslots, legacy_pcib_maxslots),
191 DEVMETHOD(pcib_read_config, legacy_pcib_read_config),
192 DEVMETHOD(pcib_write_config, legacy_pcib_write_config),
193 DEVMETHOD(pcib_route_interrupt, mptable_pci_route_interrupt),
194 DEVMETHOD(pcib_alloc_msi, legacy_pcib_alloc_msi),
195 DEVMETHOD(pcib_release_msi, pcib_release_msi),
196 DEVMETHOD(pcib_alloc_msix, legacy_pcib_alloc_msix),
197 DEVMETHOD(pcib_release_msix, pcib_release_msix),
198 DEVMETHOD(pcib_map_msi, legacy_pcib_map_msi),
203 static devclass_t hostb_devclass;
205 DEFINE_CLASS_0(pcib, mptable_hostb_driver, mptable_hostb_methods,
206 sizeof(struct mptable_hostb_softc));
207 DRIVER_MODULE(mptable_pcib, legacy, mptable_hostb_driver, hostb_devclass, 0, 0);
209 /* PCI to PCI bridge driver. */
212 mptable_pcib_probe(device_t dev)
216 if ((pci_get_class(dev) != PCIC_BRIDGE) ||
217 (pci_get_subclass(dev) != PCIS_BRIDGE_PCI))
219 bus = pci_read_config(dev, PCIR_SECBUS_1, 1);
222 if (mptable_pci_probe_table(bus) != 0)
224 device_set_desc(dev, "MPTable PCI-PCI bridge");
228 static device_method_t mptable_pcib_pci_methods[] = {
229 /* Device interface */
230 DEVMETHOD(device_probe, mptable_pcib_probe),
233 DEVMETHOD(pcib_route_interrupt, mptable_pci_route_interrupt),
238 static devclass_t pcib_devclass;
240 DEFINE_CLASS_1(pcib, mptable_pcib_driver, mptable_pcib_pci_methods,
241 sizeof(struct pcib_softc), pcib_driver);
242 DRIVER_MODULE(mptable_pcib, pci, mptable_pcib_driver, pcib_devclass, 0, 0);