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> 2915e32d5dSMike Smith #include "opt_acpi.h" 3082cb5c3bSJohn Baldwin #include "opt_pci.h" 3182cb5c3bSJohn Baldwin 3215e32d5dSMike Smith #include <sys/param.h> 3315e32d5dSMike Smith #include <sys/bus.h> 344fa387b6SMike Smith #include <sys/kernel.h> 3534ff71eeSJohn Baldwin #include <sys/limits.h> 36e3aa81b8SNate Lawson #include <sys/malloc.h> 37fe12f24bSPoul-Henning Kamp #include <sys/module.h> 3883c41143SJohn Baldwin #include <sys/rman.h> 39fd492ee0SWarner Losh #include <sys/sysctl.h> 4015e32d5dSMike Smith 41129d3046SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h> 42129d3046SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h> 43129d3046SJung-uk Kim 4415e32d5dSMike Smith #include <dev/acpica/acpivar.h> 4515e32d5dSMike Smith 4615e32d5dSMike Smith #include <machine/pci_cfgreg.h> 474edef187SJohn Baldwin #include <dev/pci/pcireg.h> 48cace7a2aSWarner Losh #include <dev/pci/pcivar.h> 49cace7a2aSWarner Losh #include <dev/pci/pcib_private.h> 5015e32d5dSMike Smith #include "pcib_if.h" 5115e32d5dSMike Smith 522ccfc932SJohn Baldwin #include <dev/acpica/acpi_pcibvar.h> 532ccfc932SJohn Baldwin 54e3aa81b8SNate Lawson /* Hooks for the ACPI CA debugging infrastructure. */ 55e71b6381SMike Smith #define _COMPONENT ACPI_BUS 562ccfc932SJohn Baldwin ACPI_MODULE_NAME("PCI_ACPI") 570ae55423SMike Smith 582ccfc932SJohn Baldwin struct acpi_hpcib_softc { 5915e32d5dSMike Smith device_t ap_dev; 6015e32d5dSMike Smith ACPI_HANDLE ap_handle; 616f4acaf4SJeff Roberson bus_dma_tag_t ap_dma_tag; 62d4b9ff91SNate Lawson int ap_flags; 6328586889SWarner Losh uint32_t ap_osc_ctl; 6415e32d5dSMike Smith 650d95597cSJohn Baldwin int ap_segment; /* PCI domain */ 6615e32d5dSMike Smith int ap_bus; /* bios-assigned bus number */ 670d95597cSJohn Baldwin int ap_addr; /* device/func of PCI-Host bridge */ 684fa387b6SMike Smith 694fa387b6SMike Smith ACPI_BUFFER ap_prt; /* interrupt routing table */ 7034ff71eeSJohn Baldwin struct pcib_host_resources ap_host_res; 7115e32d5dSMike Smith }; 7215e32d5dSMike Smith 732ccfc932SJohn Baldwin static int acpi_pcib_acpi_probe(device_t bus); 742ccfc932SJohn Baldwin static int acpi_pcib_acpi_attach(device_t bus); 75e3aa81b8SNate Lawson static int acpi_pcib_read_ivar(device_t dev, device_t child, 76e3aa81b8SNate Lawson int which, uintptr_t *result); 77e3aa81b8SNate Lawson static int acpi_pcib_write_ivar(device_t dev, device_t child, 78e3aa81b8SNate Lawson int which, uintptr_t value); 791496d4a9SWarner Losh static uint32_t acpi_pcib_read_config(device_t dev, u_int bus, 801496d4a9SWarner Losh u_int slot, u_int func, u_int reg, int bytes); 811496d4a9SWarner Losh static void acpi_pcib_write_config(device_t dev, u_int bus, 821496d4a9SWarner Losh u_int slot, u_int func, u_int reg, uint32_t data, 831496d4a9SWarner Losh int bytes); 842ccfc932SJohn Baldwin static int acpi_pcib_acpi_route_interrupt(device_t pcib, 852ccfc932SJohn Baldwin device_t dev, int pin); 868964299aSJohn Baldwin static int acpi_pcib_alloc_msi(device_t pcib, device_t dev, 878964299aSJohn Baldwin int count, int maxcount, int *irqs); 88e706f7f0SJohn Baldwin static int acpi_pcib_map_msi(device_t pcib, device_t dev, 89e706f7f0SJohn Baldwin int irq, uint64_t *addr, uint32_t *data); 908964299aSJohn Baldwin static int acpi_pcib_alloc_msix(device_t pcib, device_t dev, 91e706f7f0SJohn Baldwin int *irq); 92cd8b53edSWarner Losh static struct resource *acpi_pcib_acpi_alloc_resource(device_t dev, 93cd8b53edSWarner Losh device_t child, int type, int *rid, 942dd1bdf1SJustin Hibbits rman_res_t start, rman_res_t end, rman_res_t count, 95cd8b53edSWarner Losh u_int flags); 9634ff71eeSJohn Baldwin static int acpi_pcib_acpi_adjust_resource(device_t dev, 97fef01f04SJohn Baldwin device_t child, struct resource *r, 982dd1bdf1SJustin Hibbits rman_res_t start, rman_res_t end); 994edef187SJohn Baldwin static int acpi_pcib_acpi_release_resource(device_t dev, 1009dbf5b0eSJohn Baldwin device_t child, struct resource *r); 101c2d4fef6SJohn Baldwin static int acpi_pcib_acpi_activate_resource(device_t dev, 1022baed46eSJohn Baldwin device_t child, struct resource *r); 103c2d4fef6SJohn Baldwin static int acpi_pcib_acpi_deactivate_resource(device_t dev, 1042baed46eSJohn Baldwin device_t child, struct resource *r); 10528586889SWarner Losh static int acpi_pcib_request_feature(device_t pcib, device_t dev, 10628586889SWarner Losh enum pci_feature feature); 1076f4acaf4SJeff Roberson static bus_dma_tag_t acpi_pcib_get_dma_tag(device_t bus, device_t child); 10815e32d5dSMike Smith 1092ccfc932SJohn Baldwin static device_method_t acpi_pcib_acpi_methods[] = { 11015e32d5dSMike Smith /* Device interface */ 1112ccfc932SJohn Baldwin DEVMETHOD(device_probe, acpi_pcib_acpi_probe), 1122ccfc932SJohn Baldwin DEVMETHOD(device_attach, acpi_pcib_acpi_attach), 11315e32d5dSMike Smith DEVMETHOD(device_shutdown, bus_generic_shutdown), 11415e32d5dSMike Smith DEVMETHOD(device_suspend, bus_generic_suspend), 1157d23a9b3SJohn Baldwin DEVMETHOD(device_resume, bus_generic_resume), 11615e32d5dSMike Smith 11715e32d5dSMike Smith /* Bus interface */ 11815e32d5dSMike Smith DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar), 11915e32d5dSMike Smith DEVMETHOD(bus_write_ivar, acpi_pcib_write_ivar), 120cd8b53edSWarner Losh DEVMETHOD(bus_alloc_resource, acpi_pcib_acpi_alloc_resource), 12134ff71eeSJohn Baldwin DEVMETHOD(bus_adjust_resource, acpi_pcib_acpi_adjust_resource), 1224edef187SJohn Baldwin DEVMETHOD(bus_release_resource, acpi_pcib_acpi_release_resource), 123c2d4fef6SJohn Baldwin DEVMETHOD(bus_activate_resource, acpi_pcib_acpi_activate_resource), 124c2d4fef6SJohn Baldwin DEVMETHOD(bus_deactivate_resource, acpi_pcib_acpi_deactivate_resource), 12515e32d5dSMike Smith DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 12615e32d5dSMike Smith DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 1278d791e5aSJohn Baldwin DEVMETHOD(bus_get_cpus, acpi_pcib_get_cpus), 1286f4acaf4SJeff Roberson DEVMETHOD(bus_get_dma_tag, acpi_pcib_get_dma_tag), 12915e32d5dSMike Smith 13015e32d5dSMike Smith /* pcib interface */ 1312ccfc932SJohn Baldwin DEVMETHOD(pcib_maxslots, pcib_maxslots), 13215e32d5dSMike Smith DEVMETHOD(pcib_read_config, acpi_pcib_read_config), 13315e32d5dSMike Smith DEVMETHOD(pcib_write_config, acpi_pcib_write_config), 1342ccfc932SJohn Baldwin DEVMETHOD(pcib_route_interrupt, acpi_pcib_acpi_route_interrupt), 1358964299aSJohn Baldwin DEVMETHOD(pcib_alloc_msi, acpi_pcib_alloc_msi), 1369bf4c9c1SJohn Baldwin DEVMETHOD(pcib_release_msi, pcib_release_msi), 1378964299aSJohn Baldwin DEVMETHOD(pcib_alloc_msix, acpi_pcib_alloc_msix), 1389bf4c9c1SJohn Baldwin DEVMETHOD(pcib_release_msix, pcib_release_msix), 139e706f7f0SJohn Baldwin DEVMETHOD(pcib_map_msi, acpi_pcib_map_msi), 14062508c53SJohn Baldwin DEVMETHOD(pcib_power_for_sleep, acpi_pcib_power_for_sleep), 14128586889SWarner Losh DEVMETHOD(pcib_request_feature, acpi_pcib_request_feature), 14215e32d5dSMike Smith 1434b7ec270SMarius Strobl DEVMETHOD_END 14415e32d5dSMike Smith }; 14515e32d5dSMike Smith 14604dda605SJohn Baldwin DEFINE_CLASS_0(pcib, acpi_pcib_acpi_driver, acpi_pcib_acpi_methods, 14704dda605SJohn Baldwin sizeof(struct acpi_hpcib_softc)); 148916a5d8aSJohn Baldwin DRIVER_MODULE(acpi_pcib, acpi, acpi_pcib_acpi_driver, 0, 0); 14964278df5SNate Lawson MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1); 15015e32d5dSMike Smith 15115e32d5dSMike Smith static int 1522ccfc932SJohn Baldwin acpi_pcib_acpi_probe(device_t dev) 15315e32d5dSMike Smith { 15492488a57SJung-uk Kim ACPI_DEVICE_INFO *devinfo; 15592488a57SJung-uk Kim ACPI_HANDLE h; 15692488a57SJung-uk Kim int root; 15715e32d5dSMike Smith 15892488a57SJung-uk Kim if (acpi_disabled("pcib") || (h = acpi_get_handle(dev)) == NULL || 15992488a57SJung-uk Kim ACPI_FAILURE(AcpiGetObjectInfo(h, &devinfo))) 16092488a57SJung-uk Kim return (ENXIO); 16192488a57SJung-uk Kim root = (devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0; 16292488a57SJung-uk Kim AcpiOsFree(devinfo); 16392488a57SJung-uk Kim if (!root || pci_cfgregopen() == 0) 1645fcc8a58SNate Lawson return (ENXIO); 16515e32d5dSMike Smith 1662ccfc932SJohn Baldwin device_set_desc(dev, "ACPI Host-PCI bridge"); 16715e32d5dSMike Smith return (0); 16815e32d5dSMike Smith } 16915e32d5dSMike Smith 17034ff71eeSJohn Baldwin static ACPI_STATUS 17134ff71eeSJohn Baldwin acpi_pcib_producer_handler(ACPI_RESOURCE *res, void *context) 17234ff71eeSJohn Baldwin { 17334ff71eeSJohn Baldwin struct acpi_hpcib_softc *sc; 17434ff71eeSJohn Baldwin UINT64 length, min, max; 17534ff71eeSJohn Baldwin u_int flags; 17634ff71eeSJohn Baldwin int error, type; 17734ff71eeSJohn Baldwin 17834ff71eeSJohn Baldwin sc = context; 17934ff71eeSJohn Baldwin switch (res->Type) { 18034ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_START_DEPENDENT: 18134ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_END_DEPENDENT: 18234ff71eeSJohn Baldwin panic("host bridge has depenedent resources"); 18334ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_ADDRESS16: 18434ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_ADDRESS32: 18534ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_ADDRESS64: 18634ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 18734ff71eeSJohn Baldwin if (res->Data.Address.ProducerConsumer != ACPI_PRODUCER) 18834ff71eeSJohn Baldwin break; 18934ff71eeSJohn Baldwin switch (res->Type) { 19034ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_ADDRESS16: 1917cf3e94aSJung-uk Kim min = res->Data.Address16.Address.Minimum; 1927cf3e94aSJung-uk Kim max = res->Data.Address16.Address.Maximum; 1937cf3e94aSJung-uk Kim length = res->Data.Address16.Address.AddressLength; 19434ff71eeSJohn Baldwin break; 19534ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_ADDRESS32: 1967cf3e94aSJung-uk Kim min = res->Data.Address32.Address.Minimum; 1977cf3e94aSJung-uk Kim max = res->Data.Address32.Address.Maximum; 1987cf3e94aSJung-uk Kim length = res->Data.Address32.Address.AddressLength; 19934ff71eeSJohn Baldwin break; 20034ff71eeSJohn Baldwin case ACPI_RESOURCE_TYPE_ADDRESS64: 2017cf3e94aSJung-uk Kim min = res->Data.Address64.Address.Minimum; 2027cf3e94aSJung-uk Kim max = res->Data.Address64.Address.Maximum; 2037cf3e94aSJung-uk Kim length = res->Data.Address64.Address.AddressLength; 20434ff71eeSJohn Baldwin break; 20534ff71eeSJohn Baldwin default: 20634ff71eeSJohn Baldwin KASSERT(res->Type == 20734ff71eeSJohn Baldwin ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64, 20834ff71eeSJohn Baldwin ("should never happen")); 2097cf3e94aSJung-uk Kim min = res->Data.ExtAddress64.Address.Minimum; 2107cf3e94aSJung-uk Kim max = res->Data.ExtAddress64.Address.Maximum; 2117cf3e94aSJung-uk Kim length = res->Data.ExtAddress64.Address.AddressLength; 21234ff71eeSJohn Baldwin break; 21334ff71eeSJohn Baldwin } 214e9f91b2bSJohn Baldwin if (length == 0) 215e9f91b2bSJohn Baldwin break; 216e9f91b2bSJohn Baldwin if (min + length - 1 != max && 217e9f91b2bSJohn Baldwin (res->Data.Address.MinAddressFixed != ACPI_ADDRESS_FIXED || 218e9f91b2bSJohn Baldwin res->Data.Address.MaxAddressFixed != ACPI_ADDRESS_FIXED)) 21934ff71eeSJohn Baldwin break; 22034ff71eeSJohn Baldwin flags = 0; 22134ff71eeSJohn Baldwin switch (res->Data.Address.ResourceType) { 22234ff71eeSJohn Baldwin case ACPI_MEMORY_RANGE: 22334ff71eeSJohn Baldwin type = SYS_RES_MEMORY; 22434ff71eeSJohn Baldwin if (res->Type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64) { 22534ff71eeSJohn Baldwin if (res->Data.Address.Info.Mem.Caching == 22634ff71eeSJohn Baldwin ACPI_PREFETCHABLE_MEMORY) 22734ff71eeSJohn Baldwin flags |= RF_PREFETCHABLE; 22834ff71eeSJohn Baldwin } else { 22934ff71eeSJohn Baldwin /* 23034ff71eeSJohn Baldwin * XXX: Parse prefetch flag out of 23134ff71eeSJohn Baldwin * TypeSpecific. 23234ff71eeSJohn Baldwin */ 23334ff71eeSJohn Baldwin } 23434ff71eeSJohn Baldwin break; 23534ff71eeSJohn Baldwin case ACPI_IO_RANGE: 23634ff71eeSJohn Baldwin type = SYS_RES_IOPORT; 23734ff71eeSJohn Baldwin break; 23834ff71eeSJohn Baldwin case ACPI_BUS_NUMBER_RANGE: 23934ff71eeSJohn Baldwin type = PCI_RES_BUS; 24034ff71eeSJohn Baldwin break; 24134ff71eeSJohn Baldwin default: 24234ff71eeSJohn Baldwin return (AE_OK); 24334ff71eeSJohn Baldwin } 24434ff71eeSJohn Baldwin 24534ff71eeSJohn Baldwin if (min + length - 1 != max) 24634ff71eeSJohn Baldwin device_printf(sc->ap_dev, 24734ff71eeSJohn Baldwin "Length mismatch for %d range: %jx vs %jx\n", type, 2480c10b85aSJung-uk Kim (uintmax_t)(max - min + 1), (uintmax_t)length); 24934ff71eeSJohn Baldwin #ifdef __i386__ 25034ff71eeSJohn Baldwin if (min > ULONG_MAX) { 25134ff71eeSJohn Baldwin device_printf(sc->ap_dev, 25234ff71eeSJohn Baldwin "Ignoring %d range above 4GB (%#jx-%#jx)\n", 25334ff71eeSJohn Baldwin type, (uintmax_t)min, (uintmax_t)max); 25434ff71eeSJohn Baldwin break; 25534ff71eeSJohn Baldwin } 25634ff71eeSJohn Baldwin if (max > ULONG_MAX) { 25734ff71eeSJohn Baldwin device_printf(sc->ap_dev, 25834ff71eeSJohn Baldwin "Truncating end of %d range above 4GB (%#jx-%#jx)\n", 25934ff71eeSJohn Baldwin type, (uintmax_t)min, (uintmax_t)max); 26034ff71eeSJohn Baldwin max = ULONG_MAX; 26134ff71eeSJohn Baldwin } 26234ff71eeSJohn Baldwin #endif 26334ff71eeSJohn Baldwin error = pcib_host_res_decodes(&sc->ap_host_res, type, min, max, 26434ff71eeSJohn Baldwin flags); 26534ff71eeSJohn Baldwin if (error) 26634ff71eeSJohn Baldwin panic("Failed to manage %d range (%#jx-%#jx): %d", 26734ff71eeSJohn Baldwin type, (uintmax_t)min, (uintmax_t)max, error); 26834ff71eeSJohn Baldwin break; 26934ff71eeSJohn Baldwin default: 27034ff71eeSJohn Baldwin break; 27134ff71eeSJohn Baldwin } 27234ff71eeSJohn Baldwin return (AE_OK); 27334ff71eeSJohn Baldwin } 27434ff71eeSJohn Baldwin 275f6c2774fSJohn Baldwin static bool 276f6c2774fSJohn Baldwin get_decoded_bus_range(struct acpi_hpcib_softc *sc, rman_res_t *startp, 27722a6678bSJohn Baldwin rman_res_t *endp) 2784edef187SJohn Baldwin { 2794edef187SJohn Baldwin struct resource_list_entry *rle; 2804edef187SJohn Baldwin 2814edef187SJohn Baldwin rle = resource_list_find(&sc->ap_host_res.hr_rl, PCI_RES_BUS, 0); 2824edef187SJohn Baldwin if (rle == NULL) 283f6c2774fSJohn Baldwin return (false); 2844edef187SJohn Baldwin *startp = rle->start; 28522a6678bSJohn Baldwin *endp = rle->end; 286f6c2774fSJohn Baldwin return (true); 2874edef187SJohn Baldwin } 2884edef187SJohn Baldwin 28928586889SWarner Losh static int 2902ccfc932SJohn Baldwin acpi_pcib_acpi_attach(device_t dev) 29115e32d5dSMike Smith { 2922ccfc932SJohn Baldwin struct acpi_hpcib_softc *sc; 29315e32d5dSMike Smith ACPI_STATUS status; 2940668724bSJohn Baldwin static int bus0_seen = 0; 2950d95597cSJohn Baldwin u_int slot, func, busok; 2964edef187SJohn Baldwin struct resource *bus_res; 29722a6678bSJohn Baldwin rman_res_t end, start; 2984edef187SJohn Baldwin int rid; 2996f4acaf4SJeff Roberson int error, domain; 3009debb532SJohn Baldwin uint8_t busno; 3010ae55423SMike Smith 302b4a05238SPeter Wemm ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 30315e32d5dSMike Smith 30415e32d5dSMike Smith sc = device_get_softc(dev); 30515e32d5dSMike Smith sc->ap_dev = dev; 30615e32d5dSMike Smith sc->ap_handle = acpi_get_handle(dev); 30715e32d5dSMike Smith 30815e32d5dSMike Smith /* 3098f4c2e52SJohn Baldwin * Don't attach if we're not really there. 3108f4c2e52SJohn Baldwin */ 3118f4c2e52SJohn Baldwin if (!acpi_DeviceIsPresent(dev)) 3128f4c2e52SJohn Baldwin return (ENXIO); 3138f4c2e52SJohn Baldwin 314ba190493SAndrew Turner acpi_pcib_osc(dev, &sc->ap_osc_ctl, 0); 315508c21b6SJohn Baldwin 3168f4c2e52SJohn Baldwin /* 3170d95597cSJohn Baldwin * Get our segment number by evaluating _SEG. 3180668724bSJohn Baldwin * It's OK for this to not exist. 3190668724bSJohn Baldwin */ 3200668724bSJohn Baldwin status = acpi_GetInteger(sc->ap_handle, "_SEG", &sc->ap_segment); 3210668724bSJohn Baldwin if (ACPI_FAILURE(status)) { 3220668724bSJohn Baldwin if (status != AE_NOT_FOUND) { 3230668724bSJohn Baldwin device_printf(dev, "could not evaluate _SEG - %s\n", 3240668724bSJohn Baldwin AcpiFormatException(status)); 3250668724bSJohn Baldwin return_VALUE (ENXIO); 3260668724bSJohn Baldwin } 3270668724bSJohn Baldwin /* If it's not found, assume 0. */ 3280668724bSJohn Baldwin sc->ap_segment = 0; 3290668724bSJohn Baldwin } 3300668724bSJohn Baldwin 3310d95597cSJohn Baldwin /* 3320d95597cSJohn Baldwin * Get the address (device and function) of the associated 3330d95597cSJohn Baldwin * PCI-Host bridge device from _ADR. Assume we don't have one if 3340d95597cSJohn Baldwin * it doesn't exist. 3350d95597cSJohn Baldwin */ 3360d95597cSJohn Baldwin status = acpi_GetInteger(sc->ap_handle, "_ADR", &sc->ap_addr); 3370d95597cSJohn Baldwin if (ACPI_FAILURE(status)) { 338109abf74SYuri if (status != AE_NOT_FOUND) 3390d95597cSJohn Baldwin device_printf(dev, "could not evaluate _ADR - %s\n", 3400d95597cSJohn Baldwin AcpiFormatException(status)); 3410d95597cSJohn Baldwin sc->ap_addr = -1; 3420d95597cSJohn Baldwin } 3430d95597cSJohn Baldwin 34434ff71eeSJohn Baldwin /* 34534ff71eeSJohn Baldwin * Determine which address ranges this bridge decodes and setup 34634ff71eeSJohn Baldwin * resource managers for those ranges. 34734ff71eeSJohn Baldwin */ 34834ff71eeSJohn Baldwin if (pcib_host_res_init(sc->ap_dev, &sc->ap_host_res) != 0) 34934ff71eeSJohn Baldwin panic("failed to init hostb resources"); 35034ff71eeSJohn Baldwin if (!acpi_disabled("hostres")) { 35134ff71eeSJohn Baldwin status = AcpiWalkResources(sc->ap_handle, "_CRS", 35234ff71eeSJohn Baldwin acpi_pcib_producer_handler, sc); 35334ff71eeSJohn Baldwin if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) 35434ff71eeSJohn Baldwin device_printf(sc->ap_dev, "failed to parse resources: %s\n", 35534ff71eeSJohn Baldwin AcpiFormatException(status)); 35634ff71eeSJohn Baldwin } 35734ff71eeSJohn Baldwin 3580668724bSJohn Baldwin /* 3599debb532SJohn Baldwin * Get our base bus number by evaluating _BBN. 360c1b1f787SMike Smith * If this doesn't work, we assume we're bus number 0. 36115e32d5dSMike Smith * 36215e32d5dSMike Smith * XXX note that it may also not exist in the case where we are 36315e32d5dSMike Smith * meant to use a private configuration space mechanism for this bus, 36415e32d5dSMike Smith * so we should dig out our resources and check to see if we have 36515e32d5dSMike Smith * anything like that. How do we do this? 366042283a6SMike Smith * XXX If we have the requisite information, and if we don't think the 367042283a6SMike Smith * default PCI configuration space handlers can deal with this bus, 368042283a6SMike Smith * we should attach our own handler. 369042283a6SMike Smith * XXX invoke _REG on this for the PCI config space address space? 3709debb532SJohn Baldwin * XXX It seems many BIOS's with multiple Host-PCI bridges do not set 3719debb532SJohn Baldwin * _BBN correctly. They set _BBN to zero for all bridges. Thus, 3720668724bSJohn Baldwin * if _BBN is zero and PCI bus 0 already exists, we try to read our 3739debb532SJohn Baldwin * bus number from the configuration registers at address _ADR. 3740668724bSJohn Baldwin * We only do this for domain/segment 0 in the hopes that this is 3750668724bSJohn Baldwin * only needed for old single-domain machines. 37615e32d5dSMike Smith */ 377c310653eSNate Lawson status = acpi_GetInteger(sc->ap_handle, "_BBN", &sc->ap_bus); 3789debb532SJohn Baldwin if (ACPI_FAILURE(status)) { 37915e32d5dSMike Smith if (status != AE_NOT_FOUND) { 3809debb532SJohn Baldwin device_printf(dev, "could not evaluate _BBN - %s\n", 3819debb532SJohn Baldwin AcpiFormatException(status)); 3828f4c2e52SJohn Baldwin return (ENXIO); 383c1b1f787SMike Smith } else { 384e3aa81b8SNate Lawson /* If it's not found, assume 0. */ 38515e32d5dSMike Smith sc->ap_bus = 0; 38615e32d5dSMike Smith } 3878745ec57SJohn Baldwin } 3889debb532SJohn Baldwin 3899debb532SJohn Baldwin /* 3900668724bSJohn Baldwin * If this is segment 0, the bus is zero, and PCI bus 0 already 3910668724bSJohn Baldwin * exists, read the bus number via PCI config space. 3929debb532SJohn Baldwin */ 3939debb532SJohn Baldwin busok = 1; 3940668724bSJohn Baldwin if (sc->ap_segment == 0 && sc->ap_bus == 0 && bus0_seen) { 3958745ec57SJohn Baldwin busok = 0; 3960d95597cSJohn Baldwin if (sc->ap_addr != -1) { 3979debb532SJohn Baldwin /* XXX: We assume bus 0. */ 3980d95597cSJohn Baldwin slot = ACPI_ADR_PCI_SLOT(sc->ap_addr); 3990d95597cSJohn Baldwin func = ACPI_ADR_PCI_FUNC(sc->ap_addr); 4009debb532SJohn Baldwin if (bootverbose) 4019debb532SJohn Baldwin device_printf(dev, "reading config registers from 0:%d:%d\n", 4029debb532SJohn Baldwin slot, func); 4038745ec57SJohn Baldwin if (host_pcib_get_busno(pci_cfgregread, 0, slot, func, &busno) == 0) 404e3aa81b8SNate Lawson device_printf(dev, "couldn't read bus number from cfg space\n"); 4058745ec57SJohn Baldwin else { 4069debb532SJohn Baldwin sc->ap_bus = busno; 4078745ec57SJohn Baldwin busok = 1; 4089debb532SJohn Baldwin } 4099debb532SJohn Baldwin } 4109debb532SJohn Baldwin } 4119debb532SJohn Baldwin 4124edef187SJohn Baldwin /* 4134edef187SJohn Baldwin * If nothing else worked, hope that ACPI at least lays out the 4144edef187SJohn Baldwin * Host-PCI bridges in order and that as a result the next free 4154edef187SJohn Baldwin * bus number is our bus number. 4164edef187SJohn Baldwin */ 4174edef187SJohn Baldwin if (busok == 0) { 4184edef187SJohn Baldwin /* 4194edef187SJohn Baldwin * If we have a region of bus numbers, use the first 4204edef187SJohn Baldwin * number for our bus. 4214edef187SJohn Baldwin */ 422f6c2774fSJohn Baldwin if (get_decoded_bus_range(sc, &start, &end)) 4234edef187SJohn Baldwin sc->ap_bus = start; 4244edef187SJohn Baldwin else { 4254edef187SJohn Baldwin rid = 0; 4264edef187SJohn Baldwin bus_res = pci_domain_alloc_bus(sc->ap_segment, dev, &rid, 0, 4274edef187SJohn Baldwin PCI_BUSMAX, 1, 0); 4284edef187SJohn Baldwin if (bus_res == NULL) { 4294edef187SJohn Baldwin device_printf(dev, 4304edef187SJohn Baldwin "could not allocate bus number\n"); 4314edef187SJohn Baldwin pcib_host_res_free(dev, &sc->ap_host_res); 4324edef187SJohn Baldwin return (ENXIO); 4334edef187SJohn Baldwin } 4344edef187SJohn Baldwin sc->ap_bus = rman_get_start(bus_res); 4359dbf5b0eSJohn Baldwin pci_domain_release_bus(sc->ap_segment, dev, bus_res); 4364edef187SJohn Baldwin } 4374edef187SJohn Baldwin } else { 438a1eff92bSJohn Baldwin /* 43922a6678bSJohn Baldwin * If there is a decoded bus range, assume the bus number is 44022a6678bSJohn Baldwin * the first value in the range. Warn if _BBN doesn't match. 441a1eff92bSJohn Baldwin */ 442f6c2774fSJohn Baldwin if (get_decoded_bus_range(sc, &start, &end)) { 44322a6678bSJohn Baldwin if (sc->ap_bus != start) { 444a1eff92bSJohn Baldwin device_printf(dev, 44522a6678bSJohn Baldwin "WARNING: BIOS configured bus number (%d) is " 44622a6678bSJohn Baldwin "not within decoded bus number range " 44722a6678bSJohn Baldwin "(%ju - %ju).\n", 44822a6678bSJohn Baldwin sc->ap_bus, (uintmax_t)start, (uintmax_t)end); 44922a6678bSJohn Baldwin device_printf(dev, 45022a6678bSJohn Baldwin "Using range start (%ju) as bus number.\n", 45122a6678bSJohn Baldwin (uintmax_t)start); 45222a6678bSJohn Baldwin sc->ap_bus = start; 45322a6678bSJohn Baldwin } 454a1eff92bSJohn Baldwin } 4554edef187SJohn Baldwin } 45615e32d5dSMike Smith 4570668724bSJohn Baldwin /* If this is bus 0 on segment 0, note that it has been seen already. */ 4580668724bSJohn Baldwin if (sc->ap_segment == 0 && sc->ap_bus == 0) 4590668724bSJohn Baldwin bus0_seen = 1; 46015e32d5dSMike Smith 46167e7d085SJohn Baldwin acpi_pcib_fetch_prt(dev, &sc->ap_prt); 46267e7d085SJohn Baldwin 4636f4acaf4SJeff Roberson error = bus_dma_tag_create(bus_get_dma_tag(dev), 1, 4646f4acaf4SJeff Roberson 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, 4656f4acaf4SJeff Roberson NULL, NULL, BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED, 4666f4acaf4SJeff Roberson BUS_SPACE_MAXSIZE, 0, NULL, NULL, &sc->ap_dma_tag); 4676f4acaf4SJeff Roberson if (error != 0) 4686f4acaf4SJeff Roberson goto errout; 4696f4acaf4SJeff Roberson error = bus_get_domain(dev, &domain); 4706f4acaf4SJeff Roberson if (error == 0) 4716f4acaf4SJeff Roberson error = bus_dma_tag_set_domain(sc->ap_dma_tag, domain); 4726f4acaf4SJeff Roberson /* Don't fail to attach if the domain can't be queried or set. */ 4736f4acaf4SJeff Roberson error = 0; 4746f4acaf4SJeff Roberson 475723da5d9SJohn Baldwin bus_identify_children(dev); 47667e7d085SJohn Baldwin if (device_add_child(dev, "pci", -1) == NULL) { 4776f4acaf4SJeff Roberson bus_dma_tag_destroy(sc->ap_dma_tag); 4786f4acaf4SJeff Roberson sc->ap_dma_tag = NULL; 4796f4acaf4SJeff Roberson error = ENXIO; 4806f4acaf4SJeff Roberson goto errout; 4816f4acaf4SJeff Roberson } 48218250ec6SJohn Baldwin bus_attach_children(dev); 48318250ec6SJohn Baldwin return (0); 4846f4acaf4SJeff Roberson 4856f4acaf4SJeff Roberson errout: 48667e7d085SJohn Baldwin device_printf(device_get_parent(dev), "couldn't attach pci bus\n"); 487a1eff92bSJohn Baldwin pcib_host_res_free(dev, &sc->ap_host_res); 4886f4acaf4SJeff Roberson return (error); 48915e32d5dSMike Smith } 49015e32d5dSMike Smith 4914fa387b6SMike Smith /* 4924fa387b6SMike Smith * Support for standard PCI bridge ivars. 4934fa387b6SMike Smith */ 49415e32d5dSMike Smith static int 49515e32d5dSMike Smith acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 49615e32d5dSMike Smith { 4972ccfc932SJohn Baldwin struct acpi_hpcib_softc *sc = device_get_softc(dev); 49815e32d5dSMike Smith 49915e32d5dSMike Smith switch (which) { 50055aaf894SMarius Strobl case PCIB_IVAR_DOMAIN: 50124c93a6fSJohn Baldwin *result = sc->ap_segment; 50255aaf894SMarius Strobl return (0); 50315e32d5dSMike Smith case PCIB_IVAR_BUS: 50415e32d5dSMike Smith *result = sc->ap_bus; 50515e32d5dSMike Smith return (0); 5062ccfc932SJohn Baldwin case ACPI_IVAR_HANDLE: 5072ccfc932SJohn Baldwin *result = (uintptr_t)sc->ap_handle; 5082ccfc932SJohn Baldwin return (0); 509d4b9ff91SNate Lawson case ACPI_IVAR_FLAGS: 510d4b9ff91SNate Lawson *result = (uintptr_t)sc->ap_flags; 511d4b9ff91SNate Lawson return (0); 51215e32d5dSMike Smith } 51315e32d5dSMike Smith return (ENOENT); 51415e32d5dSMike Smith } 51515e32d5dSMike Smith 51615e32d5dSMike Smith static int 51715e32d5dSMike Smith acpi_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 51815e32d5dSMike Smith { 5192ccfc932SJohn Baldwin struct acpi_hpcib_softc *sc = device_get_softc(dev); 52015e32d5dSMike Smith 52115e32d5dSMike Smith switch (which) { 52255aaf894SMarius Strobl case PCIB_IVAR_DOMAIN: 52355aaf894SMarius Strobl return (EINVAL); 52415e32d5dSMike Smith case PCIB_IVAR_BUS: 52515e32d5dSMike Smith sc->ap_bus = value; 52615e32d5dSMike Smith return (0); 527d4b9ff91SNate Lawson case ACPI_IVAR_HANDLE: 528d4b9ff91SNate Lawson sc->ap_handle = (ACPI_HANDLE)value; 529d4b9ff91SNate Lawson return (0); 530d4b9ff91SNate Lawson case ACPI_IVAR_FLAGS: 531d4b9ff91SNate Lawson sc->ap_flags = (int)value; 532d4b9ff91SNate Lawson return (0); 53315e32d5dSMike Smith } 53415e32d5dSMike Smith return (ENOENT); 53515e32d5dSMike Smith } 53615e32d5dSMike Smith 537e3aa81b8SNate Lawson static uint32_t 5381496d4a9SWarner Losh acpi_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, 5391496d4a9SWarner Losh u_int reg, int bytes) 54015e32d5dSMike Smith { 5411587a9dbSJohn Baldwin struct acpi_hpcib_softc *sc = device_get_softc(dev); 5421587a9dbSJohn Baldwin 5431587a9dbSJohn Baldwin return (pci_cfgregread(sc->ap_segment, bus, slot, func, reg, bytes)); 54415e32d5dSMike Smith } 54515e32d5dSMike Smith 54615e32d5dSMike Smith static void 5471496d4a9SWarner Losh acpi_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func, 5481496d4a9SWarner Losh u_int reg, uint32_t data, int bytes) 54915e32d5dSMike Smith { 5501587a9dbSJohn Baldwin struct acpi_hpcib_softc *sc = device_get_softc(dev); 5511587a9dbSJohn Baldwin 5521587a9dbSJohn Baldwin pci_cfgregwrite(sc->ap_segment, bus, slot, func, reg, data, bytes); 55315e32d5dSMike Smith } 55415e32d5dSMike Smith 55515e32d5dSMike Smith static int 5562ccfc932SJohn Baldwin acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin) 55715e32d5dSMike Smith { 5585e1ba6d4SJohn Baldwin struct acpi_hpcib_softc *sc = device_get_softc(pcib); 5594fa387b6SMike Smith 5605e1ba6d4SJohn Baldwin return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt)); 56115e32d5dSMike Smith } 562cd8b53edSWarner Losh 5638964299aSJohn Baldwin static int 5648964299aSJohn Baldwin acpi_pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, 5658964299aSJohn Baldwin int *irqs) 5668964299aSJohn Baldwin { 5678964299aSJohn Baldwin device_t bus; 5688964299aSJohn Baldwin 5698964299aSJohn Baldwin bus = device_get_parent(pcib); 5708964299aSJohn Baldwin return (PCIB_ALLOC_MSI(device_get_parent(bus), dev, count, maxcount, 5718964299aSJohn Baldwin irqs)); 5728964299aSJohn Baldwin } 5738964299aSJohn Baldwin 5748964299aSJohn Baldwin static int 575e706f7f0SJohn Baldwin acpi_pcib_alloc_msix(device_t pcib, device_t dev, int *irq) 5768964299aSJohn Baldwin { 5778964299aSJohn Baldwin device_t bus; 5788964299aSJohn Baldwin 5798964299aSJohn Baldwin bus = device_get_parent(pcib); 580e706f7f0SJohn Baldwin return (PCIB_ALLOC_MSIX(device_get_parent(bus), dev, irq)); 581e706f7f0SJohn Baldwin } 582e706f7f0SJohn Baldwin 583e706f7f0SJohn Baldwin static int 584e706f7f0SJohn Baldwin acpi_pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, 585e706f7f0SJohn Baldwin uint32_t *data) 586e706f7f0SJohn Baldwin { 5870d95597cSJohn Baldwin struct acpi_hpcib_softc *sc; 5880d95597cSJohn Baldwin device_t bus, hostb; 5890d95597cSJohn Baldwin int error; 590e706f7f0SJohn Baldwin 591e706f7f0SJohn Baldwin bus = device_get_parent(pcib); 5920d95597cSJohn Baldwin error = PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data); 5930d95597cSJohn Baldwin if (error) 5940d95597cSJohn Baldwin return (error); 5950d95597cSJohn Baldwin 596af0d1ee9SNeel Natu sc = device_get_softc(pcib); 5970d95597cSJohn Baldwin if (sc->ap_addr == -1) 5980d95597cSJohn Baldwin return (0); 5990d95597cSJohn Baldwin /* XXX: Assumes all bridges are on bus 0. */ 6000d95597cSJohn Baldwin hostb = pci_find_dbsf(sc->ap_segment, 0, ACPI_ADR_PCI_SLOT(sc->ap_addr), 6010d95597cSJohn Baldwin ACPI_ADR_PCI_FUNC(sc->ap_addr)); 6020d95597cSJohn Baldwin if (hostb != NULL) 6030d95597cSJohn Baldwin pci_ht_map_msi(hostb, *addr); 6040d95597cSJohn Baldwin return (0); 6058964299aSJohn Baldwin } 6068964299aSJohn Baldwin 607cd8b53edSWarner Losh struct resource * 608cd8b53edSWarner Losh acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid, 6092dd1bdf1SJustin Hibbits rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) 610cd8b53edSWarner Losh { 61134ff71eeSJohn Baldwin struct acpi_hpcib_softc *sc; 6125d0d779bSJohn Baldwin struct resource *res; 61338d7a61bSJohn Baldwin 61438d7a61bSJohn Baldwin #if defined(__i386__) || defined(__amd64__) 61538d7a61bSJohn Baldwin start = hostb_alloc_start(type, start, end, count); 61638d7a61bSJohn Baldwin #endif 61734ff71eeSJohn Baldwin 61834ff71eeSJohn Baldwin sc = device_get_softc(dev); 6194edef187SJohn Baldwin if (type == PCI_RES_BUS) 6204edef187SJohn Baldwin return (pci_domain_alloc_bus(sc->ap_segment, child, rid, start, end, 6214edef187SJohn Baldwin count, flags)); 6225d0d779bSJohn Baldwin res = pcib_host_res_alloc(&sc->ap_host_res, child, type, rid, start, end, 6235d0d779bSJohn Baldwin count, flags); 624a74d6952SJohn Baldwin 625a74d6952SJohn Baldwin /* 626a74d6952SJohn Baldwin * XXX: If this is a request for a specific range, assume it is 627a74d6952SJohn Baldwin * correct and pass it up to the parent. What we probably want to 628a74d6952SJohn Baldwin * do long-term is explicitly trust any firmware-configured 629a74d6952SJohn Baldwin * resources during the initial bus scan on boot and then disable 630a74d6952SJohn Baldwin * this after that. 631a74d6952SJohn Baldwin */ 6325d0d779bSJohn Baldwin if (res == NULL && start + count - 1 == end) 633a74d6952SJohn Baldwin res = bus_generic_alloc_resource(dev, child, type, rid, start, end, 634a74d6952SJohn Baldwin count, flags); 6355d0d779bSJohn Baldwin return (res); 636cd8b53edSWarner Losh } 63734ff71eeSJohn Baldwin 63834ff71eeSJohn Baldwin int 639fef01f04SJohn Baldwin acpi_pcib_acpi_adjust_resource(device_t dev, device_t child, 6402dd1bdf1SJustin Hibbits struct resource *r, rman_res_t start, rman_res_t end) 64134ff71eeSJohn Baldwin { 64234ff71eeSJohn Baldwin struct acpi_hpcib_softc *sc; 64334ff71eeSJohn Baldwin 64434ff71eeSJohn Baldwin sc = device_get_softc(dev); 645fef01f04SJohn Baldwin if (rman_get_type(r) == PCI_RES_BUS) 6464edef187SJohn Baldwin return (pci_domain_adjust_bus(sc->ap_segment, child, r, start, 6474edef187SJohn Baldwin end)); 648fef01f04SJohn Baldwin return (pcib_host_res_adjust(&sc->ap_host_res, child, r, start, end)); 64934ff71eeSJohn Baldwin } 6504edef187SJohn Baldwin 6514edef187SJohn Baldwin int 6529dbf5b0eSJohn Baldwin acpi_pcib_acpi_release_resource(device_t dev, device_t child, 6534edef187SJohn Baldwin struct resource *r) 6544edef187SJohn Baldwin { 6554edef187SJohn Baldwin struct acpi_hpcib_softc *sc; 6564edef187SJohn Baldwin 6574edef187SJohn Baldwin sc = device_get_softc(dev); 6589dbf5b0eSJohn Baldwin if (rman_get_type(r) == PCI_RES_BUS) 6599dbf5b0eSJohn Baldwin return (pci_domain_release_bus(sc->ap_segment, child, r)); 6609dbf5b0eSJohn Baldwin return (bus_generic_release_resource(dev, child, r)); 6614edef187SJohn Baldwin } 662c2d4fef6SJohn Baldwin 663c2d4fef6SJohn Baldwin int 6642baed46eSJohn Baldwin acpi_pcib_acpi_activate_resource(device_t dev, device_t child, 665c2d4fef6SJohn Baldwin struct resource *r) 666c2d4fef6SJohn Baldwin { 667c2d4fef6SJohn Baldwin struct acpi_hpcib_softc *sc; 668c2d4fef6SJohn Baldwin 669c2d4fef6SJohn Baldwin sc = device_get_softc(dev); 6702baed46eSJohn Baldwin if (rman_get_type(r) == PCI_RES_BUS) 6712baed46eSJohn Baldwin return (pci_domain_activate_bus(sc->ap_segment, child, r)); 6722baed46eSJohn Baldwin return (bus_generic_activate_resource(dev, child, r)); 673c2d4fef6SJohn Baldwin } 674c2d4fef6SJohn Baldwin 675c2d4fef6SJohn Baldwin int 6762baed46eSJohn Baldwin acpi_pcib_acpi_deactivate_resource(device_t dev, device_t child, 6772baed46eSJohn Baldwin struct resource *r) 678c2d4fef6SJohn Baldwin { 679c2d4fef6SJohn Baldwin struct acpi_hpcib_softc *sc; 680c2d4fef6SJohn Baldwin 681c2d4fef6SJohn Baldwin sc = device_get_softc(dev); 6822baed46eSJohn Baldwin if (rman_get_type(r) == PCI_RES_BUS) 6832baed46eSJohn Baldwin return (pci_domain_deactivate_bus(sc->ap_segment, child, r)); 6842baed46eSJohn Baldwin return (bus_generic_deactivate_resource(dev, child, r)); 685c2d4fef6SJohn Baldwin } 68628586889SWarner Losh 68728586889SWarner Losh static int 68828586889SWarner Losh acpi_pcib_request_feature(device_t pcib, device_t dev, enum pci_feature feature) 68928586889SWarner Losh { 69028586889SWarner Losh uint32_t osc_ctl; 69128586889SWarner Losh struct acpi_hpcib_softc *sc; 69228586889SWarner Losh 6931ffd07bdSJohn Baldwin sc = device_get_softc(pcib); 69428586889SWarner Losh 69528586889SWarner Losh switch (feature) { 69628586889SWarner Losh case PCI_FEATURE_HP: 69728586889SWarner Losh osc_ctl = PCIM_OSC_CTL_PCIE_HP; 69828586889SWarner Losh break; 69928586889SWarner Losh case PCI_FEATURE_AER: 70028586889SWarner Losh osc_ctl = PCIM_OSC_CTL_PCIE_AER; 70128586889SWarner Losh break; 70228586889SWarner Losh default: 70328586889SWarner Losh return (EINVAL); 70428586889SWarner Losh } 70528586889SWarner Losh 706*b714eacbSAndrew Turner return (acpi_pcib_osc(pcib, &sc->ap_osc_ctl, osc_ctl)); 70728586889SWarner Losh } 7086f4acaf4SJeff Roberson 7096f4acaf4SJeff Roberson static bus_dma_tag_t 7106f4acaf4SJeff Roberson acpi_pcib_get_dma_tag(device_t bus, device_t child) 7116f4acaf4SJeff Roberson { 7126f4acaf4SJeff Roberson struct acpi_hpcib_softc *sc; 7136f4acaf4SJeff Roberson 7146f4acaf4SJeff Roberson sc = device_get_softc(bus); 7156f4acaf4SJeff Roberson 7166f4acaf4SJeff Roberson return (sc->ap_dma_tag); 7176f4acaf4SJeff Roberson } 718