xref: /freebsd/sys/dev/acpica/acpi_pcib_acpi.c (revision 24c93a6fc44ae2e84396c1cec18276736c905a0c)
115e32d5dSMike Smith /*-
215e32d5dSMike Smith  * Copyright (c) 2000 Michael Smith
315e32d5dSMike Smith  * Copyright (c) 2000 BSDi
415e32d5dSMike Smith  * All rights reserved.
515e32d5dSMike Smith  *
615e32d5dSMike Smith  * Redistribution and use in source and binary forms, with or without
715e32d5dSMike Smith  * modification, are permitted provided that the following conditions
815e32d5dSMike Smith  * are met:
915e32d5dSMike Smith  * 1. Redistributions of source code must retain the above copyright
1015e32d5dSMike Smith  *    notice, this list of conditions and the following disclaimer.
1115e32d5dSMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
1215e32d5dSMike Smith  *    notice, this list of conditions and the following disclaimer in the
1315e32d5dSMike Smith  *    documentation and/or other materials provided with the distribution.
1415e32d5dSMike Smith  *
1515e32d5dSMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1615e32d5dSMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1715e32d5dSMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1815e32d5dSMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1915e32d5dSMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2015e32d5dSMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2115e32d5dSMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2215e32d5dSMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2315e32d5dSMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2415e32d5dSMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2515e32d5dSMike Smith  * SUCH DAMAGE.
2615e32d5dSMike Smith  */
27dad97feeSDavid E. O'Brien 
28dad97feeSDavid E. O'Brien #include <sys/cdefs.h>
29dad97feeSDavid E. O'Brien __FBSDID("$FreeBSD$");
30dad97feeSDavid E. O'Brien 
3115e32d5dSMike Smith #include "opt_acpi.h"
3215e32d5dSMike Smith #include <sys/param.h>
3315e32d5dSMike Smith #include <sys/bus.h>
344fa387b6SMike Smith #include <sys/kernel.h>
35e3aa81b8SNate Lawson #include <sys/malloc.h>
36fe12f24bSPoul-Henning Kamp #include <sys/module.h>
37fd492ee0SWarner Losh #include <sys/sysctl.h>
3815e32d5dSMike Smith 
39129d3046SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
40129d3046SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
41129d3046SJung-uk Kim 
4215e32d5dSMike Smith #include <dev/acpica/acpivar.h>
4315e32d5dSMike Smith 
4415e32d5dSMike Smith #include <machine/pci_cfgreg.h>
45cace7a2aSWarner Losh #include <dev/pci/pcivar.h>
46cace7a2aSWarner Losh #include <dev/pci/pcib_private.h>
4715e32d5dSMike Smith #include "pcib_if.h"
4815e32d5dSMike Smith 
492ccfc932SJohn Baldwin #include <dev/acpica/acpi_pcibvar.h>
502ccfc932SJohn Baldwin 
51e3aa81b8SNate Lawson /* Hooks for the ACPI CA debugging infrastructure. */
52e71b6381SMike Smith #define _COMPONENT	ACPI_BUS
532ccfc932SJohn Baldwin ACPI_MODULE_NAME("PCI_ACPI")
540ae55423SMike Smith 
552ccfc932SJohn Baldwin struct acpi_hpcib_softc {
5615e32d5dSMike Smith     device_t		ap_dev;
5715e32d5dSMike Smith     ACPI_HANDLE		ap_handle;
58d4b9ff91SNate Lawson     int			ap_flags;
5915e32d5dSMike Smith 
6015e32d5dSMike Smith     int			ap_segment;	/* analagous to Alpha 'hose' */
6115e32d5dSMike Smith     int			ap_bus;		/* bios-assigned bus number */
624fa387b6SMike Smith 
634fa387b6SMike Smith     ACPI_BUFFER		ap_prt;		/* interrupt routing table */
6415e32d5dSMike Smith };
6515e32d5dSMike Smith 
662ccfc932SJohn Baldwin static int		acpi_pcib_acpi_probe(device_t bus);
672ccfc932SJohn Baldwin static int		acpi_pcib_acpi_attach(device_t bus);
68e3aa81b8SNate Lawson static int		acpi_pcib_read_ivar(device_t dev, device_t child,
69e3aa81b8SNate Lawson 			    int which, uintptr_t *result);
70e3aa81b8SNate Lawson static int		acpi_pcib_write_ivar(device_t dev, device_t child,
71e3aa81b8SNate Lawson 			    int which, uintptr_t value);
721496d4a9SWarner Losh static uint32_t		acpi_pcib_read_config(device_t dev, u_int bus,
731496d4a9SWarner Losh 			    u_int slot, u_int func, u_int reg, int bytes);
741496d4a9SWarner Losh static void		acpi_pcib_write_config(device_t dev, u_int bus,
751496d4a9SWarner Losh 			    u_int slot, u_int func, u_int reg, uint32_t data,
761496d4a9SWarner Losh 			    int bytes);
772ccfc932SJohn Baldwin static int		acpi_pcib_acpi_route_interrupt(device_t pcib,
782ccfc932SJohn Baldwin 			    device_t dev, int pin);
798964299aSJohn Baldwin static int		acpi_pcib_alloc_msi(device_t pcib, device_t dev,
808964299aSJohn Baldwin 			    int count, int maxcount, int *irqs);
81e706f7f0SJohn Baldwin static int		acpi_pcib_map_msi(device_t pcib, device_t dev,
82e706f7f0SJohn Baldwin 			    int irq, uint64_t *addr, uint32_t *data);
838964299aSJohn Baldwin static int		acpi_pcib_alloc_msix(device_t pcib, device_t dev,
84e706f7f0SJohn Baldwin 			    int *irq);
85cd8b53edSWarner Losh static struct resource *acpi_pcib_acpi_alloc_resource(device_t dev,
86cd8b53edSWarner Losh 			    device_t child, int type, int *rid,
87cd8b53edSWarner Losh 			    u_long start, u_long end, u_long count,
88cd8b53edSWarner Losh 			    u_int flags);
8915e32d5dSMike Smith 
902ccfc932SJohn Baldwin static device_method_t acpi_pcib_acpi_methods[] = {
9115e32d5dSMike Smith     /* Device interface */
922ccfc932SJohn Baldwin     DEVMETHOD(device_probe,		acpi_pcib_acpi_probe),
932ccfc932SJohn Baldwin     DEVMETHOD(device_attach,		acpi_pcib_acpi_attach),
9415e32d5dSMike Smith     DEVMETHOD(device_shutdown,		bus_generic_shutdown),
9515e32d5dSMike Smith     DEVMETHOD(device_suspend,		bus_generic_suspend),
967d23a9b3SJohn Baldwin     DEVMETHOD(device_resume,		bus_generic_resume),
9715e32d5dSMike Smith 
9815e32d5dSMike Smith     /* Bus interface */
9915e32d5dSMike Smith     DEVMETHOD(bus_print_child,		bus_generic_print_child),
10015e32d5dSMike Smith     DEVMETHOD(bus_read_ivar,		acpi_pcib_read_ivar),
10115e32d5dSMike Smith     DEVMETHOD(bus_write_ivar,		acpi_pcib_write_ivar),
102cd8b53edSWarner Losh     DEVMETHOD(bus_alloc_resource,	acpi_pcib_acpi_alloc_resource),
103d2c9344fSJohn Baldwin     DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
10415e32d5dSMike Smith     DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
10515e32d5dSMike Smith     DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
10615e32d5dSMike Smith     DEVMETHOD(bus_deactivate_resource,	bus_generic_deactivate_resource),
10715e32d5dSMike Smith     DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
10815e32d5dSMike Smith     DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
10915e32d5dSMike Smith 
11015e32d5dSMike Smith     /* pcib interface */
1112ccfc932SJohn Baldwin     DEVMETHOD(pcib_maxslots,		pcib_maxslots),
11215e32d5dSMike Smith     DEVMETHOD(pcib_read_config,		acpi_pcib_read_config),
11315e32d5dSMike Smith     DEVMETHOD(pcib_write_config,	acpi_pcib_write_config),
1142ccfc932SJohn Baldwin     DEVMETHOD(pcib_route_interrupt,	acpi_pcib_acpi_route_interrupt),
1158964299aSJohn Baldwin     DEVMETHOD(pcib_alloc_msi,		acpi_pcib_alloc_msi),
1169bf4c9c1SJohn Baldwin     DEVMETHOD(pcib_release_msi,		pcib_release_msi),
1178964299aSJohn Baldwin     DEVMETHOD(pcib_alloc_msix,		acpi_pcib_alloc_msix),
1189bf4c9c1SJohn Baldwin     DEVMETHOD(pcib_release_msix,	pcib_release_msix),
119e706f7f0SJohn Baldwin     DEVMETHOD(pcib_map_msi,		acpi_pcib_map_msi),
12062508c53SJohn Baldwin     DEVMETHOD(pcib_power_for_sleep,	acpi_pcib_power_for_sleep),
12115e32d5dSMike Smith 
12215e32d5dSMike Smith     {0, 0}
12315e32d5dSMike Smith };
12415e32d5dSMike Smith 
12504dda605SJohn Baldwin static devclass_t pcib_devclass;
12615e32d5dSMike Smith 
12704dda605SJohn Baldwin DEFINE_CLASS_0(pcib, acpi_pcib_acpi_driver, acpi_pcib_acpi_methods,
12804dda605SJohn Baldwin     sizeof(struct acpi_hpcib_softc));
1292ccfc932SJohn Baldwin DRIVER_MODULE(acpi_pcib, acpi, acpi_pcib_acpi_driver, pcib_devclass, 0, 0);
13064278df5SNate Lawson MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1);
13115e32d5dSMike Smith 
13215e32d5dSMike Smith static int
1332ccfc932SJohn Baldwin acpi_pcib_acpi_probe(device_t dev)
13415e32d5dSMike Smith {
13592488a57SJung-uk Kim     ACPI_DEVICE_INFO	*devinfo;
13692488a57SJung-uk Kim     ACPI_HANDLE		h;
13792488a57SJung-uk Kim     int			root;
13815e32d5dSMike Smith 
13992488a57SJung-uk Kim     if (acpi_disabled("pcib") || (h = acpi_get_handle(dev)) == NULL ||
14092488a57SJung-uk Kim 	ACPI_FAILURE(AcpiGetObjectInfo(h, &devinfo)))
14192488a57SJung-uk Kim 	return (ENXIO);
14292488a57SJung-uk Kim     root = (devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0;
14392488a57SJung-uk Kim     AcpiOsFree(devinfo);
14492488a57SJung-uk Kim     if (!root || pci_cfgregopen() == 0)
1455fcc8a58SNate Lawson 	return (ENXIO);
14615e32d5dSMike Smith 
1472ccfc932SJohn Baldwin     device_set_desc(dev, "ACPI Host-PCI bridge");
14815e32d5dSMike Smith     return (0);
14915e32d5dSMike Smith }
15015e32d5dSMike Smith 
15115e32d5dSMike Smith static int
1522ccfc932SJohn Baldwin acpi_pcib_acpi_attach(device_t dev)
15315e32d5dSMike Smith {
1542ccfc932SJohn Baldwin     struct acpi_hpcib_softc	*sc;
15515e32d5dSMike Smith     ACPI_STATUS			status;
1560668724bSJohn Baldwin     static int bus0_seen = 0;
1578b149b51SJohn Baldwin     u_int addr, slot, func, busok;
1589debb532SJohn Baldwin     uint8_t busno;
1590ae55423SMike Smith 
160b4a05238SPeter Wemm     ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
16115e32d5dSMike Smith 
16215e32d5dSMike Smith     sc = device_get_softc(dev);
16315e32d5dSMike Smith     sc->ap_dev = dev;
16415e32d5dSMike Smith     sc->ap_handle = acpi_get_handle(dev);
16515e32d5dSMike Smith 
16615e32d5dSMike Smith     /*
1670668724bSJohn Baldwin      * Get our segment number by evaluating _SEG
1680668724bSJohn Baldwin      * It's OK for this to not exist.
1690668724bSJohn Baldwin      */
1700668724bSJohn Baldwin     status = acpi_GetInteger(sc->ap_handle, "_SEG", &sc->ap_segment);
1710668724bSJohn Baldwin     if (ACPI_FAILURE(status)) {
1720668724bSJohn Baldwin 	if (status != AE_NOT_FOUND) {
1730668724bSJohn Baldwin 	    device_printf(dev, "could not evaluate _SEG - %s\n",
1740668724bSJohn Baldwin 		AcpiFormatException(status));
1750668724bSJohn Baldwin 	    return_VALUE (ENXIO);
1760668724bSJohn Baldwin 	}
1770668724bSJohn Baldwin 	/* If it's not found, assume 0. */
1780668724bSJohn Baldwin 	sc->ap_segment = 0;
1790668724bSJohn Baldwin     }
1800668724bSJohn Baldwin 
1810668724bSJohn Baldwin     /*
1829debb532SJohn Baldwin      * Get our base bus number by evaluating _BBN.
183c1b1f787SMike Smith      * If this doesn't work, we assume we're bus number 0.
18415e32d5dSMike Smith      *
18515e32d5dSMike Smith      * XXX note that it may also not exist in the case where we are
18615e32d5dSMike Smith      *     meant to use a private configuration space mechanism for this bus,
18715e32d5dSMike Smith      *     so we should dig out our resources and check to see if we have
18815e32d5dSMike Smith      *     anything like that.  How do we do this?
189042283a6SMike Smith      * XXX If we have the requisite information, and if we don't think the
190042283a6SMike Smith      *     default PCI configuration space handlers can deal with this bus,
191042283a6SMike Smith      *     we should attach our own handler.
192042283a6SMike Smith      * XXX invoke _REG on this for the PCI config space address space?
1939debb532SJohn Baldwin      * XXX It seems many BIOS's with multiple Host-PCI bridges do not set
1949debb532SJohn Baldwin      *     _BBN correctly.  They set _BBN to zero for all bridges.  Thus,
1950668724bSJohn Baldwin      *     if _BBN is zero and PCI bus 0 already exists, we try to read our
1969debb532SJohn Baldwin      *     bus number from the configuration registers at address _ADR.
1970668724bSJohn Baldwin      *     We only do this for domain/segment 0 in the hopes that this is
1980668724bSJohn Baldwin      *     only needed for old single-domain machines.
19915e32d5dSMike Smith      */
200c310653eSNate Lawson     status = acpi_GetInteger(sc->ap_handle, "_BBN", &sc->ap_bus);
2019debb532SJohn Baldwin     if (ACPI_FAILURE(status)) {
20215e32d5dSMike Smith 	if (status != AE_NOT_FOUND) {
2039debb532SJohn Baldwin 	    device_printf(dev, "could not evaluate _BBN - %s\n",
2049debb532SJohn Baldwin 		AcpiFormatException(status));
205c1b1f787SMike Smith 	    return_VALUE (ENXIO);
206c1b1f787SMike Smith 	} else {
207e3aa81b8SNate Lawson 	    /* If it's not found, assume 0. */
20815e32d5dSMike Smith 	    sc->ap_bus = 0;
20915e32d5dSMike Smith 	}
2108745ec57SJohn Baldwin     }
2119debb532SJohn Baldwin 
2129debb532SJohn Baldwin     /*
2130668724bSJohn Baldwin      * If this is segment 0, the bus is zero, and PCI bus 0 already
2140668724bSJohn Baldwin      * exists, read the bus number via PCI config space.
2159debb532SJohn Baldwin      */
2169debb532SJohn Baldwin     busok = 1;
2170668724bSJohn Baldwin     if (sc->ap_segment == 0 && sc->ap_bus == 0 && bus0_seen) {
2188745ec57SJohn Baldwin 	busok = 0;
219c310653eSNate Lawson 	status = acpi_GetInteger(sc->ap_handle, "_ADR", &addr);
2209debb532SJohn Baldwin 	if (ACPI_FAILURE(status)) {
2219debb532SJohn Baldwin 	    if (status != AE_NOT_FOUND) {
2229debb532SJohn Baldwin 		device_printf(dev, "could not evaluate _ADR - %s\n",
2239debb532SJohn Baldwin 		    AcpiFormatException(status));
2249debb532SJohn Baldwin 		return_VALUE (ENXIO);
2258745ec57SJohn Baldwin 	    } else
226e3aa81b8SNate Lawson 		device_printf(dev, "couldn't find _ADR\n");
2279debb532SJohn Baldwin 	} else {
2289debb532SJohn Baldwin 	    /* XXX: We assume bus 0. */
229e0a93586SJohn Baldwin 	    slot = ACPI_ADR_PCI_SLOT(addr);
230e0a93586SJohn Baldwin 	    func = ACPI_ADR_PCI_FUNC(addr);
2319debb532SJohn Baldwin 	    if (bootverbose)
2329debb532SJohn Baldwin 		device_printf(dev, "reading config registers from 0:%d:%d\n",
2339debb532SJohn Baldwin 		    slot, func);
2348745ec57SJohn Baldwin 	    if (host_pcib_get_busno(pci_cfgregread, 0, slot, func, &busno) == 0)
235e3aa81b8SNate Lawson 		device_printf(dev, "couldn't read bus number from cfg space\n");
2368745ec57SJohn Baldwin 	    else {
2379debb532SJohn Baldwin 		sc->ap_bus = busno;
2388745ec57SJohn Baldwin 		busok = 1;
2399debb532SJohn Baldwin 	    }
2409debb532SJohn Baldwin 	}
2419debb532SJohn Baldwin     }
2429debb532SJohn Baldwin 
2439debb532SJohn Baldwin     /*
2449debb532SJohn Baldwin      * If nothing else worked, hope that ACPI at least lays out the
2459debb532SJohn Baldwin      * host-PCI bridges in order and that as a result our unit number
2469debb532SJohn Baldwin      * is actually our bus number.  There are several reasons this
2479debb532SJohn Baldwin      * might not be true.
2489debb532SJohn Baldwin      */
2499debb532SJohn Baldwin     if (busok == 0) {
2509debb532SJohn Baldwin 	sc->ap_bus = device_get_unit(dev);
2519debb532SJohn Baldwin 	device_printf(dev, "trying bus number %d\n", sc->ap_bus);
252c1b1f787SMike Smith     }
25315e32d5dSMike Smith 
2540668724bSJohn Baldwin     /* If this is bus 0 on segment 0, note that it has been seen already. */
2550668724bSJohn Baldwin     if (sc->ap_segment == 0 && sc->ap_bus == 0)
2560668724bSJohn Baldwin 	    bus0_seen = 1;
25715e32d5dSMike Smith 
2582ccfc932SJohn Baldwin     return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_bus));
25915e32d5dSMike Smith }
26015e32d5dSMike Smith 
2614fa387b6SMike Smith /*
2624fa387b6SMike Smith  * Support for standard PCI bridge ivars.
2634fa387b6SMike Smith  */
26415e32d5dSMike Smith static int
26515e32d5dSMike Smith acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
26615e32d5dSMike Smith {
2672ccfc932SJohn Baldwin     struct acpi_hpcib_softc	*sc = device_get_softc(dev);
26815e32d5dSMike Smith 
26915e32d5dSMike Smith     switch (which) {
27055aaf894SMarius Strobl     case PCIB_IVAR_DOMAIN:
271*24c93a6fSJohn Baldwin 	*result = sc->ap_segment;
27255aaf894SMarius Strobl 	return (0);
27315e32d5dSMike Smith     case PCIB_IVAR_BUS:
27415e32d5dSMike Smith 	*result = sc->ap_bus;
27515e32d5dSMike Smith 	return (0);
2762ccfc932SJohn Baldwin     case ACPI_IVAR_HANDLE:
2772ccfc932SJohn Baldwin 	*result = (uintptr_t)sc->ap_handle;
2782ccfc932SJohn Baldwin 	return (0);
279d4b9ff91SNate Lawson     case ACPI_IVAR_FLAGS:
280d4b9ff91SNate Lawson 	*result = (uintptr_t)sc->ap_flags;
281d4b9ff91SNate Lawson 	return (0);
28215e32d5dSMike Smith     }
28315e32d5dSMike Smith     return (ENOENT);
28415e32d5dSMike Smith }
28515e32d5dSMike Smith 
28615e32d5dSMike Smith static int
28715e32d5dSMike Smith acpi_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
28815e32d5dSMike Smith {
2892ccfc932SJohn Baldwin     struct acpi_hpcib_softc	*sc = device_get_softc(dev);
29015e32d5dSMike Smith 
29115e32d5dSMike Smith     switch (which) {
29255aaf894SMarius Strobl     case PCIB_IVAR_DOMAIN:
29355aaf894SMarius Strobl 	return (EINVAL);
29415e32d5dSMike Smith     case PCIB_IVAR_BUS:
29515e32d5dSMike Smith 	sc->ap_bus = value;
29615e32d5dSMike Smith 	return (0);
297d4b9ff91SNate Lawson     case ACPI_IVAR_HANDLE:
298d4b9ff91SNate Lawson 	sc->ap_handle = (ACPI_HANDLE)value;
299d4b9ff91SNate Lawson 	return (0);
300d4b9ff91SNate Lawson     case ACPI_IVAR_FLAGS:
301d4b9ff91SNate Lawson 	sc->ap_flags = (int)value;
302d4b9ff91SNate Lawson 	return (0);
30315e32d5dSMike Smith     }
30415e32d5dSMike Smith     return (ENOENT);
30515e32d5dSMike Smith }
30615e32d5dSMike Smith 
307e3aa81b8SNate Lawson static uint32_t
3081496d4a9SWarner Losh acpi_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func,
3091496d4a9SWarner Losh     u_int reg, int bytes)
31015e32d5dSMike Smith {
31115e32d5dSMike Smith     return (pci_cfgregread(bus, slot, func, reg, bytes));
31215e32d5dSMike Smith }
31315e32d5dSMike Smith 
31415e32d5dSMike Smith static void
3151496d4a9SWarner Losh acpi_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func,
3161496d4a9SWarner Losh     u_int reg, uint32_t data, int bytes)
31715e32d5dSMike Smith {
31815e32d5dSMike Smith     pci_cfgregwrite(bus, slot, func, reg, data, bytes);
31915e32d5dSMike Smith }
32015e32d5dSMike Smith 
32115e32d5dSMike Smith static int
3222ccfc932SJohn Baldwin acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin)
32315e32d5dSMike Smith {
3245e1ba6d4SJohn Baldwin     struct acpi_hpcib_softc *sc = device_get_softc(pcib);
3254fa387b6SMike Smith 
3265e1ba6d4SJohn Baldwin     return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt));
32715e32d5dSMike Smith }
328cd8b53edSWarner Losh 
3298964299aSJohn Baldwin static int
3308964299aSJohn Baldwin acpi_pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount,
3318964299aSJohn Baldwin     int *irqs)
3328964299aSJohn Baldwin {
3338964299aSJohn Baldwin 	device_t bus;
3348964299aSJohn Baldwin 
3358964299aSJohn Baldwin 	bus = device_get_parent(pcib);
3368964299aSJohn Baldwin 	return (PCIB_ALLOC_MSI(device_get_parent(bus), dev, count, maxcount,
3378964299aSJohn Baldwin 	    irqs));
3388964299aSJohn Baldwin }
3398964299aSJohn Baldwin 
3408964299aSJohn Baldwin static int
341e706f7f0SJohn Baldwin acpi_pcib_alloc_msix(device_t pcib, device_t dev, int *irq)
3428964299aSJohn Baldwin {
3438964299aSJohn Baldwin 	device_t bus;
3448964299aSJohn Baldwin 
3458964299aSJohn Baldwin 	bus = device_get_parent(pcib);
346e706f7f0SJohn Baldwin 	return (PCIB_ALLOC_MSIX(device_get_parent(bus), dev, irq));
347e706f7f0SJohn Baldwin }
348e706f7f0SJohn Baldwin 
349e706f7f0SJohn Baldwin static int
350e706f7f0SJohn Baldwin acpi_pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr,
351e706f7f0SJohn Baldwin     uint32_t *data)
352e706f7f0SJohn Baldwin {
353e706f7f0SJohn Baldwin 	device_t bus;
354e706f7f0SJohn Baldwin 
355e706f7f0SJohn Baldwin 	bus = device_get_parent(pcib);
356e706f7f0SJohn Baldwin 	return (PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data));
3578964299aSJohn Baldwin }
3588964299aSJohn Baldwin 
3595b8c4719SNate Lawson static u_long acpi_host_mem_start = 0x80000000;
360b0e1e474SDag-Erling Smørgrav TUNABLE_ULONG("hw.acpi.host_mem_start", &acpi_host_mem_start);
361fd492ee0SWarner Losh 
362cd8b53edSWarner Losh struct resource *
363cd8b53edSWarner Losh acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid,
364cd8b53edSWarner Losh     u_long start, u_long end, u_long count, u_int flags)
365cd8b53edSWarner Losh {
366cd8b53edSWarner Losh     /*
3675cee9db3SWarner Losh      * If no memory preference is given, use upper 32MB slot most
368cd8b53edSWarner Losh      * bioses use for their memory window.  Typically other bridges
369cd8b53edSWarner Losh      * before us get in the way to assert their preferences on memory.
370cd8b53edSWarner Losh      * Hardcoding like this sucks, so a more MD/MI way needs to be
371dfbaec0aSWarner Losh      * found to do it.  This is typically only used on older laptops
3725cee9db3SWarner Losh      * that don't have pci busses behind pci bridge, so assuming > 32MB
373dfbaec0aSWarner Losh      * is liekly OK.
374cd8b53edSWarner Losh      */
375cd8b53edSWarner Losh     if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL)
376fd492ee0SWarner Losh 	start = acpi_host_mem_start;
377dca20690SWarner Losh     if (type == SYS_RES_IOPORT && start == 0UL && end == ~0UL)
378dca20690SWarner Losh 	start = 0x1000;
379cd8b53edSWarner Losh     return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
380cd8b53edSWarner Losh 	count, flags));
381cd8b53edSWarner Losh }
382