diff --git a/sys/dev/acpica/acpi_pcib.c b/sys/dev/acpica/acpi_pcib.c index ac274a4cd39e..81f3a0bb76c0 100644 --- a/sys/dev/acpica/acpi_pcib.c +++ b/sys/dev/acpica/acpi_pcib.c @@ -1,339 +1,339 @@ /*- * Copyright (c) 2000 Michael Smith * Copyright (c) 2000 BSDi * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_acpi.h" #include #include #include #include #include "acpi.h" #include #include #include -#include -#include +#include +#include #include "pcib_if.h" /* * Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BUS ACPI_MODULE_NAME("PCI") int acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno) { device_t child; ACPI_STATUS status; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); /* * Don't attach if we're not really there. * * XXX: This isn't entirely correct since we may be a PCI bus * on a hot-plug docking station, etc. */ if (!acpi_DeviceIsPresent(dev)) return_VALUE(ENXIO); /* * Get the PCI interrupt routing table for this bus. */ prt->Length = ACPI_ALLOCATE_BUFFER; status = AcpiGetIrqRoutingTable(acpi_get_handle(dev), prt); if (ACPI_FAILURE(status)) /* This is not an error, but it may reduce functionality. */ device_printf(dev, "could not get PCI interrupt routing table for %s - %s\n", acpi_name(acpi_get_handle(dev)), AcpiFormatException(status)); /* * Attach the PCI bus proper. */ if ((child = device_add_child(dev, "pci", busno)) == NULL) { device_printf(device_get_parent(dev), "couldn't attach pci bus\n"); return_VALUE(ENXIO); } /* * Now go scan the bus. */ acpi_pci_link_config(dev, prt, busno); return_VALUE(bus_generic_attach(dev)); } int acpi_pcib_resume(device_t dev, ACPI_BUFFER *prt, int busno) { acpi_pci_link_resume(dev, prt, busno); return (bus_generic_resume(dev)); } /* * Route an interrupt for a child of the bridge. * * XXX clean up error messages * * XXX this function is somewhat bulky */ int acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin, ACPI_BUFFER *prtbuf) { ACPI_PCI_ROUTING_TABLE *prt; ACPI_HANDLE lnkdev; ACPI_BUFFER crsbuf, prsbuf; ACPI_RESOURCE *crsres, *prsres, resbuf; ACPI_DEVICE_INFO devinfo; ACPI_BUFFER buf = {sizeof(devinfo), &devinfo}; ACPI_STATUS status; u_int8_t *prtp; int interrupt; int i; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); crsbuf.Pointer = NULL; prsbuf.Pointer = NULL; interrupt = 255; /* ACPI numbers pins 0-3, not 1-4 like the BIOS */ pin--; prtp = prtbuf->Pointer; if (prtp == NULL) /* didn't get routing table */ goto out; /* scan the table looking for this device */ for (;;) { prt = (ACPI_PCI_ROUTING_TABLE *)prtp; if (prt->Length == 0) /* end of table */ goto out; /* * Compare the slot number (high word of Address) and pin number * (note that ACPI uses 0 for INTA) to check for a match. * * Note that the low word of the Address field (function number) * is required by the specification to be 0xffff. We don't risk * checking it here. */ if ((((prt->Address & 0xffff0000) >> 16) == pci_get_slot(dev)) && (prt->Pin == pin)) { if (bootverbose) device_printf(pcib, "matched entry for %d.%d.INT%c (source %s)\n", pci_get_bus(dev), pci_get_slot(dev), 'A' + pin, prt->Source); break; } /* skip to next entry */ prtp += prt->Length; } /* * If source is empty/NULL, the source index is the global IRQ number. */ if ((prt->Source == NULL) || (prt->Source[0] == '\0')) { if (bootverbose) device_printf(pcib, "device is hardwired to IRQ %d\n", prt->SourceIndex); interrupt = prt->SourceIndex; goto out; } /* * We have to find the source device (PCI interrupt link device) */ if (ACPI_FAILURE(AcpiGetHandle(ACPI_ROOT_OBJECT, prt->Source, &lnkdev))) { device_printf(pcib, "couldn't find PCI interrupt link device %s\n", prt->Source); goto out; } /* * Verify that this is a PCI link device, and that it's present. */ if (ACPI_FAILURE(AcpiGetObjectInfo(lnkdev, &buf))) { device_printf(pcib, "couldn't validate PCI interrupt link device %s\n", prt->Source); goto out; } if (!(devinfo.Valid & ACPI_VALID_HID) || strcmp("PNP0C0F", devinfo.HardwareId.Value)) { device_printf(pcib, "PCI interrupt link device %s has wrong _HID (%s)\n", prt->Source, devinfo.HardwareId.Value); goto out; } if (devinfo.Valid & ACPI_VALID_STA && (devinfo.CurrentStatus & 0x9) != 0x9) { device_printf(pcib, "PCI interrupt link device %s not present\n", prt->Source); goto out; } /* * Get the current and possible resources for the interrupt link device. */ crsbuf.Length = ACPI_ALLOCATE_BUFFER; if (ACPI_FAILURE(status = AcpiGetCurrentResources(lnkdev, &crsbuf))) { device_printf(pcib, "couldn't get PCI interrupt link device _CRS data - %s\n", AcpiFormatException(status)); goto out; /* this is fatal */ } prsbuf.Length = ACPI_ALLOCATE_BUFFER; if (ACPI_FAILURE(status = AcpiGetPossibleResources(lnkdev, &prsbuf))) { device_printf(pcib, "couldn't get PCI interrupt link device _PRS data - %s\n", AcpiFormatException(status)); /* this is not fatal, since it may be hardwired */ } ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "got %ld bytes for %s._CRS\n", (long)crsbuf.Length, acpi_name(lnkdev))); ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "got %ld bytes for %s._PRS\n", (long)prsbuf.Length, acpi_name(lnkdev))); /* * The interrupt may already be routed, so check _CRS first. We don't check the * 'decoding' bit in the _STA result, since there's nothing in the spec that * mandates it be set, however some BIOS' will set it if the decode is active. * * The Source Index points to the particular resource entry we're interested in. */ if (ACPI_FAILURE(acpi_FindIndexedResource(&crsbuf, prt->SourceIndex, &crsres))) { device_printf(pcib, "_CRS buffer corrupt, cannot route interrupt\n"); goto out; } /* type-check the resource we've got */ if (crsres->Id != ACPI_RSTYPE_IRQ) { /* XXX ACPI_RSTYPE_EXT_IRQ */ device_printf(pcib, "_CRS resource entry has unsupported type %d\n", crsres->Id); goto out; } /* if there's more than one interrupt, we are confused */ if (crsres->Data.Irq.NumberOfInterrupts > 1) { device_printf(pcib, "device has too many interrupts (%d)\n", crsres->Data.Irq.NumberOfInterrupts); goto out; } /* * If there's only one interrupt, and it's not zero, then we're already routed. * * Note that we could also check the 'decoding' bit in _STA, but can't depend on * it since it's not part of the spec. * * XXX check ASL examples to see if this is an acceptable set of tests */ if ((crsres->Data.Irq.NumberOfInterrupts == 1) && (crsres->Data.Irq.Interrupts[0] != 0)) { device_printf(pcib, "slot %d INT%c is routed to irq %d\n", pci_get_slot(dev), 'A' + pin, crsres->Data.Irq.Interrupts[0]); interrupt = crsres->Data.Irq.Interrupts[0]; goto out; } /* * There isn't an interrupt, so we have to look at _PRS to get one. * Get the set of allowed interrupts from the _PRS resource indexed by SourceIndex. */ if (prsbuf.Pointer == NULL) { device_printf(pcib, "device has no routed interrupt and no _PRS on PCI interrupt link device\n"); goto out; } if (ACPI_FAILURE(acpi_FindIndexedResource(&prsbuf, prt->SourceIndex, &prsres))) { device_printf(pcib, "_PRS buffer corrupt, cannot route interrupt\n"); goto out; } /* type-check the resource we've got */ if (prsres->Id != ACPI_RSTYPE_IRQ) { /* XXX ACPI_RSTYPE_EXT_IRQ */ device_printf(pcib, "_PRS resource entry has unsupported type %d\n", prsres->Id); goto out; } /* there has to be at least one interrupt available */ if (prsres->Data.Irq.NumberOfInterrupts < 1) { device_printf(pcib, "device has no interrupts\n"); goto out; } /* * Pick an interrupt to use. Note that a more scientific approach than just * taking the first one available would be desirable. * * The PCI BIOS $PIR table offers "preferred PCI interrupts", but ACPI doesn't * seem to offer a similar mechanism, so picking a "good" interrupt here is a * difficult task. * * Build a resource buffer and pass it to AcpiSetCurrentResources to route the * new interrupt. */ device_printf(pcib, "possible interrupts:"); for (i = 0; i < prsres->Data.Irq.NumberOfInterrupts; i++) printf(" %d", prsres->Data.Irq.Interrupts[i]); printf("\n"); if (crsbuf.Pointer != NULL) /* should never happen */ AcpiOsFree(crsbuf.Pointer); crsbuf.Pointer = NULL; resbuf.Id = ACPI_RSTYPE_IRQ; resbuf.Length = ACPI_SIZEOF_RESOURCE(ACPI_RESOURCE_IRQ); resbuf.Data.Irq = prsres->Data.Irq; /* structure copy other fields */ resbuf.Data.Irq.NumberOfInterrupts = 1; resbuf.Data.Irq.Interrupts[0] = prsres->Data.Irq.Interrupts[0]; /* just take first... */ if (ACPI_FAILURE(status = acpi_AppendBufferResource(&crsbuf, &resbuf))) { device_printf(pcib, "couldn't route interrupt %d via %s, interrupt resource build failed - %s\n", prsres->Data.Irq.Interrupts[0], acpi_name(lnkdev), AcpiFormatException(status)); goto out; } if (ACPI_FAILURE(status = AcpiSetCurrentResources(lnkdev, &crsbuf))) { device_printf(pcib, "couldn't route interrupt %d via %s - %s\n", prsres->Data.Irq.Interrupts[0], acpi_name(lnkdev), AcpiFormatException(status)); goto out; } /* successful, return the interrupt we just routed */ device_printf(pcib, "slot %d INT%c routed to irq %d via %s\n", pci_get_slot(dev), 'A' + pin, prsres->Data.Irq.Interrupts[0], acpi_name(lnkdev)); interrupt = prsres->Data.Irq.Interrupts[0]; out: if (crsbuf.Pointer != NULL) AcpiOsFree(crsbuf.Pointer); if (prsbuf.Pointer != NULL) AcpiOsFree(prsbuf.Pointer); /* XXX APIC_IO interrupt mapping? */ return_VALUE(interrupt); } diff --git a/sys/dev/acpica/acpi_pcib_acpi.c b/sys/dev/acpica/acpi_pcib_acpi.c index ba6e42ee02a8..637d7fb94dab 100644 --- a/sys/dev/acpica/acpi_pcib_acpi.c +++ b/sys/dev/acpica/acpi_pcib_acpi.c @@ -1,291 +1,291 @@ /*- * Copyright (c) 2000 Michael Smith * Copyright (c) 2000 BSDi * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_acpi.h" #include #include #include #include #include "acpi.h" #include #include -#include -#include +#include +#include #include "pcib_if.h" #include /* * Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BUS ACPI_MODULE_NAME("PCI_ACPI") struct acpi_hpcib_softc { device_t ap_dev; ACPI_HANDLE ap_handle; int ap_segment; /* analagous to Alpha 'hose' */ int ap_bus; /* bios-assigned bus number */ ACPI_BUFFER ap_prt; /* interrupt routing table */ }; static int acpi_pcib_acpi_probe(device_t bus); static int acpi_pcib_acpi_attach(device_t bus); static int acpi_pcib_acpi_resume(device_t bus); static int acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result); static int acpi_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value); static u_int32_t acpi_pcib_read_config(device_t dev, int bus, int slot, int func, int reg, int bytes); static void acpi_pcib_write_config(device_t dev, int bus, int slot, int func, int reg, u_int32_t data, int bytes); static int acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin); static device_method_t acpi_pcib_acpi_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_pcib_acpi_probe), DEVMETHOD(device_attach, acpi_pcib_acpi_attach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, acpi_pcib_acpi_resume), /* Bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar), DEVMETHOD(bus_write_ivar, acpi_pcib_write_ivar), DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), DEVMETHOD(bus_release_resource, bus_generic_release_resource), DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), /* pcib interface */ DEVMETHOD(pcib_maxslots, pcib_maxslots), DEVMETHOD(pcib_read_config, acpi_pcib_read_config), DEVMETHOD(pcib_write_config, acpi_pcib_write_config), DEVMETHOD(pcib_route_interrupt, acpi_pcib_acpi_route_interrupt), {0, 0} }; static driver_t acpi_pcib_acpi_driver = { "pcib", acpi_pcib_acpi_methods, sizeof(struct acpi_hpcib_softc), }; DRIVER_MODULE(acpi_pcib, acpi, acpi_pcib_acpi_driver, pcib_devclass, 0, 0); static int acpi_pcib_acpi_probe(device_t dev) { if ((acpi_get_type(dev) == ACPI_TYPE_DEVICE) && !acpi_disabled("pci") && acpi_MatchHid(dev, "PNP0A03")) { if (!pci_cfgregopen()) return(ENXIO); /* * Set device description */ device_set_desc(dev, "ACPI Host-PCI bridge"); return(0); } return(ENXIO); } static int acpi_pcib_acpi_attach(device_t dev) { struct acpi_hpcib_softc *sc; ACPI_STATUS status; u_int addr, slot, func, busok; uint8_t busno; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = device_get_softc(dev); sc->ap_dev = dev; sc->ap_handle = acpi_get_handle(dev); /* * Get our base bus number by evaluating _BBN. * If this doesn't work, we assume we're bus number 0. * * XXX note that it may also not exist in the case where we are * meant to use a private configuration space mechanism for this bus, * so we should dig out our resources and check to see if we have * anything like that. How do we do this? * XXX If we have the requisite information, and if we don't think the * default PCI configuration space handlers can deal with this bus, * we should attach our own handler. * XXX invoke _REG on this for the PCI config space address space? * XXX It seems many BIOS's with multiple Host-PCI bridges do not set * _BBN correctly. They set _BBN to zero for all bridges. Thus, * if _BBN is zero and pcib0 already exists, we try to read our * bus number from the configuration registers at address _ADR. */ status = acpi_EvaluateInteger(sc->ap_handle, "_BBN", &sc->ap_bus); if (ACPI_FAILURE(status)) { if (status != AE_NOT_FOUND) { device_printf(dev, "could not evaluate _BBN - %s\n", AcpiFormatException(status)); return_VALUE(ENXIO); } else { /* if it's not found, assume 0 */ sc->ap_bus = 0; } } /* * If the bus is zero and pcib0 already exists, read the bus number * via PCI config space. */ busok = 1; if (sc->ap_bus == 0 && devclass_get_device(pcib_devclass, 0) != dev) { busok = 0; status = acpi_EvaluateInteger(sc->ap_handle, "_ADR", &addr); if (ACPI_FAILURE(status)) { if (status != AE_NOT_FOUND) { device_printf(dev, "could not evaluate _ADR - %s\n", AcpiFormatException(status)); return_VALUE(ENXIO); } else device_printf(dev, "could not determine config space address\n"); } else { /* XXX: We assume bus 0. */ slot = addr >> 16; func = addr & 0xffff; if (bootverbose) device_printf(dev, "reading config registers from 0:%d:%d\n", slot, func); if (host_pcib_get_busno(pci_cfgregread, 0, slot, func, &busno) == 0) device_printf(dev, "could not read bus number from config space\n"); else { sc->ap_bus = busno; busok = 1; } } } /* * If nothing else worked, hope that ACPI at least lays out the * host-PCI bridges in order and that as a result our unit number * is actually our bus number. There are several reasons this * might not be true. */ if (busok == 0) { sc->ap_bus = device_get_unit(dev); device_printf(dev, "trying bus number %d\n", sc->ap_bus); } /* * Get our segment number by evaluating _SEG * It's OK for this to not exist. */ if (ACPI_FAILURE(status = acpi_EvaluateInteger(sc->ap_handle, "_SEG", &sc->ap_segment))) { if (status != AE_NOT_FOUND) { device_printf(dev, "could not evaluate _SEG - %s\n", AcpiFormatException(status)); return_VALUE(ENXIO); } /* if it's not found, assume 0 */ sc->ap_segment = 0; } return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_bus)); } static int acpi_pcib_acpi_resume(device_t dev) { struct acpi_hpcib_softc *sc = device_get_softc(dev); return (acpi_pcib_resume(dev, &sc->ap_prt, sc->ap_bus)); } /* * Support for standard PCI bridge ivars. */ static int acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct acpi_hpcib_softc *sc = device_get_softc(dev); switch (which) { case PCIB_IVAR_BUS: *result = sc->ap_bus; return(0); case ACPI_IVAR_HANDLE: *result = (uintptr_t)sc->ap_handle; return(0); } return(ENOENT); } static int acpi_pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value) { struct acpi_hpcib_softc *sc = device_get_softc(dev); switch (which) { case PCIB_IVAR_BUS: sc->ap_bus = value; return(0); } return(ENOENT); } static u_int32_t acpi_pcib_read_config(device_t dev, int bus, int slot, int func, int reg, int bytes) { return(pci_cfgregread(bus, slot, func, reg, bytes)); } static void acpi_pcib_write_config(device_t dev, int bus, int slot, int func, int reg, u_int32_t data, int bytes) { pci_cfgregwrite(bus, slot, func, reg, data, bytes); } static int acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin) { struct acpi_hpcib_softc *sc; /* find the bridge softc */ sc = device_get_softc(pcib); return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt)); } diff --git a/sys/dev/acpica/acpi_pcib_pci.c b/sys/dev/acpica/acpi_pcib_pci.c index 5909e65d8d4d..dff2450fa70a 100644 --- a/sys/dev/acpica/acpi_pcib_pci.c +++ b/sys/dev/acpica/acpi_pcib_pci.c @@ -1,166 +1,166 @@ /*- * Copyright (c) 2000 Michael Smith * Copyright (c) 2000 BSDi * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_acpi.h" #include #include #include #include #include "acpi.h" #include #include #include -#include -#include -#include +#include +#include +#include #include "pcib_if.h" /* * Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BUS ACPI_MODULE_NAME("PCI_PCI") struct acpi_pcib_softc { struct pcib_softc ap_pcibsc; ACPI_HANDLE ap_handle; ACPI_BUFFER ap_prt; /* interrupt routing table */ }; struct acpi_pcib_lookup_info { UINT32 address; ACPI_HANDLE handle; }; static int acpi_pcib_pci_probe(device_t bus); static int acpi_pcib_pci_attach(device_t bus); static int acpi_pcib_pci_resume(device_t bus); static int acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result); static int acpi_pcib_pci_route_interrupt(device_t pcib, device_t dev, int pin); static device_method_t acpi_pcib_pci_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_pcib_pci_probe), DEVMETHOD(device_attach, acpi_pcib_pci_attach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, acpi_pcib_pci_resume), /* Bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar), DEVMETHOD(bus_write_ivar, pcib_write_ivar), DEVMETHOD(bus_alloc_resource, pcib_alloc_resource), DEVMETHOD(bus_release_resource, bus_generic_release_resource), DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), /* pcib interface */ DEVMETHOD(pcib_maxslots, pcib_maxslots), DEVMETHOD(pcib_read_config, pcib_read_config), DEVMETHOD(pcib_write_config, pcib_write_config), DEVMETHOD(pcib_route_interrupt, acpi_pcib_pci_route_interrupt), {0, 0} }; static driver_t acpi_pcib_pci_driver = { "pcib", acpi_pcib_pci_methods, sizeof(struct acpi_pcib_softc), }; DRIVER_MODULE(acpi_pcib, pci, acpi_pcib_pci_driver, pcib_devclass, 0, 0); static int acpi_pcib_pci_probe(device_t dev) { if ((pci_get_class(dev) != PCIC_BRIDGE) || (pci_get_subclass(dev) != PCIS_BRIDGE_PCI) || acpi_disabled("pci")) return (ENXIO); if (acpi_get_handle(dev) == NULL) return (ENXIO); if (!pci_cfgregopen()) return (ENXIO); device_set_desc(dev, "ACPI PCI-PCI bridge"); return (-1000); } static int acpi_pcib_pci_attach(device_t dev) { struct acpi_pcib_softc *sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); pcib_attach_common(dev); sc = device_get_softc(dev); sc->ap_handle = acpi_get_handle(dev); return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.secbus)); } static int acpi_pcib_pci_resume(device_t dev) { struct acpi_pcib_softc *sc = device_get_softc(dev); return (acpi_pcib_resume(dev, &sc->ap_prt, sc->ap_pcibsc.secbus)); } static int acpi_pcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct acpi_pcib_softc *sc = device_get_softc(dev); switch (which) { case ACPI_IVAR_HANDLE: *result = (uintptr_t)sc->ap_handle; return(0); } return(pcib_read_ivar(dev, child, which, result)); } static int acpi_pcib_pci_route_interrupt(device_t pcib, device_t dev, int pin) { struct acpi_pcib_softc *sc; sc = device_get_softc(pcib); return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt)); } diff --git a/sys/dev/acpica/acpi_timer.c b/sys/dev/acpica/acpi_timer.c index 576ce59b5968..61edc055b785 100644 --- a/sys/dev/acpica/acpi_timer.c +++ b/sys/dev/acpica/acpi_timer.c @@ -1,390 +1,390 @@ /*- * Copyright (c) 2000, 2001 Michael Smith * Copyright (c) 2000 BSDi * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include "opt_acpi.h" #include #include #include #include #if __FreeBSD_version >= 500000 #include #else #include #endif #include #include #include #include "acpi.h" #include -#include +#include /* * A timecounter based on the free-running ACPI timer. * * Based on the i386-only mp_clock.c by . */ /* * Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_SYSTEM ACPI_MODULE_NAME("TIMER") static device_t acpi_timer_dev; struct resource *acpi_timer_reg; static u_int acpi_timer_frequency = 14318182/4; static void acpi_timer_identify(driver_t *driver, device_t parent); static int acpi_timer_probe(device_t dev); static int acpi_timer_attach(device_t dev); static unsigned acpi_timer_get_timecount(struct timecounter *tc); static unsigned acpi_timer_get_timecount_safe(struct timecounter *tc); static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS); static void acpi_timer_test(void); static u_int32_t read_counter(void); static int test_counter(void); /* * Driver hung off ACPI. */ static device_method_t acpi_timer_methods[] = { DEVMETHOD(device_identify, acpi_timer_identify), DEVMETHOD(device_probe, acpi_timer_probe), DEVMETHOD(device_attach, acpi_timer_attach), {0, 0} }; static driver_t acpi_timer_driver = { "acpi_timer", acpi_timer_methods, 0, }; static devclass_t acpi_timer_devclass; DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0); /* * Timecounter. */ static struct timecounter acpi_timer_timecounter = { acpi_timer_get_timecount_safe, 0, 0xffffff, 0, "ACPI", 1000 }; static u_int32_t read_counter() { bus_space_handle_t bsh; bus_space_tag_t bst; u_int32_t tv; bsh = rman_get_bushandle(acpi_timer_reg); bst = rman_get_bustag(acpi_timer_reg); tv = bus_space_read_4(bst, bsh, 0); bus_space_barrier(bst, bsh, 0, 4, BUS_SPACE_BARRIER_READ); return (tv); } #define N 2000 static int test_counter() { int min, max, n, delta; unsigned last, this; min = 10000000; max = 0; last = read_counter(); for (n = 0; n < N; n++) { this = read_counter(); delta = (this - last) & 0xffffff; if (delta > max) max = delta; else if (delta < min) min = delta; last = this; } if (max - min > 2) n = 0; else if (min < 0 || max == 0) n = 0; else n = 1; if (bootverbose) printf("ACPI timer looks %s min = %d, max = %d, width = %d\n", n ? "GOOD" : "BAD ", min, max, max - min); return (n); } /* * Locate the ACPI timer using the FADT, set up and allocate the I/O resources * we will be using. */ static void acpi_timer_identify(driver_t *driver, device_t parent) { device_t dev; char desc[40]; u_long rlen, rstart; int i, j, rid, rtype; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); if (acpi_disabled("timer")) return_VOID; if (AcpiGbl_FADT == NULL) return_VOID; if ((dev = BUS_ADD_CHILD(parent, 0, "acpi_timer", 0)) == NULL) { device_printf(parent, "could not add acpi_timer0\n"); return_VOID; } acpi_timer_dev = dev; rid = 0; rlen = AcpiGbl_FADT->PmTmLen; rtype = (AcpiGbl_FADT->XPmTmrBlk.AddressSpaceId) ? SYS_RES_IOPORT : SYS_RES_MEMORY; rstart = AcpiGbl_FADT->XPmTmrBlk.Address; bus_set_resource(dev, rtype, rid, rstart, rlen); acpi_timer_reg = bus_alloc_resource(dev, rtype, &rid, 0, ~0, 1, RF_ACTIVE); if (acpi_timer_reg == NULL) { device_printf(dev, "couldn't allocate I/O resource (%s 0x%lx)\n", (rtype == SYS_RES_IOPORT) ? "port" : "mem", rstart); return_VOID; } if (testenv("debug.acpi.timer_test")) acpi_timer_test(); acpi_timer_timecounter.tc_frequency = acpi_timer_frequency; j = 0; for(i = 0; i < 10; i++) j += test_counter(); if (j == 10) { acpi_timer_timecounter.tc_name = "ACPI-fast"; acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount; } else { acpi_timer_timecounter.tc_name = "ACPI-safe"; acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount_safe; } tc_init(&acpi_timer_timecounter); sprintf(desc, "%d-bit timer at 3.579545MHz", (AcpiGbl_FADT->TmrValExt) ? 32 : 24); device_set_desc_copy(dev, desc); return_VOID; } static int acpi_timer_probe(device_t dev) { if (dev == acpi_timer_dev) return(0); return(ENXIO); } static int acpi_timer_attach(device_t dev) { return(0); } /* * Fetch current time value from reliable hardware. */ static unsigned acpi_timer_get_timecount(struct timecounter *tc) { return (read_counter()); } /* * Fetch current time value from hardware that may not correctly * latch the counter. */ static unsigned acpi_timer_get_timecount_safe(struct timecounter *tc) { unsigned u1, u2, u3; u2 = read_counter(); u3 = read_counter(); do { u1 = u2; u2 = u3; u3 = read_counter(); } while (u1 > u2 || u2 > u3 || (u3 - u1) > 15); return (u2); } /* * Timecounter freqency adjustment interface. */ static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS) { int error; u_int freq; if (acpi_timer_timecounter.tc_frequency == 0) return (EOPNOTSUPP); freq = acpi_timer_frequency; error = sysctl_handle_int(oidp, &freq, sizeof(freq), req); if (error == 0 && req->newptr != NULL) { acpi_timer_frequency = freq; acpi_timer_timecounter.tc_frequency = acpi_timer_frequency; } return (error); } SYSCTL_PROC(_machdep, OID_AUTO, acpi_timer_freq, CTLTYPE_INT | CTLFLAG_RW, 0, sizeof(u_int), acpi_timer_sysctl_freq, "I", ""); /* * Test harness for verifying ACPI timer behaviour. * Boot with debug.acpi.timer_test set to invoke this. */ static void acpi_timer_test(void) { u_int32_t u1, u2, u3; u1 = read_counter(); u2 = read_counter(); u3 = read_counter(); device_printf(acpi_timer_dev, "timer test in progress, reboot to quit.\n"); for (;;) { /* * The failure case is where u3 > u1, but u2 does not fall between the two, * ie. it contains garbage. */ if (u3 > u1) { if ((u2 < u1) || (u2 > u3)) device_printf(acpi_timer_dev, "timer is not monotonic: 0x%08x,0x%08x,0x%08x\n", u1, u2, u3); } u1 = u2; u2 = u3; u3 = read_counter(); } } /* * Chipset workaround driver hung off PCI. * * Some ACPI timers are known or believed to suffer from implementation * problems which can lead to erroneous values being read from the timer. * * Since we can't trust unknown chipsets, we default to a timer-read * routine which compensates for the most common problem (as detailed * in the excerpt from the Intel PIIX4 datasheet below). * * When we detect a known-functional chipset, we disable the workaround * to improve speed. * * ] 20. ACPI Timer Errata * ] * ] Problem: The power management timer may return improper result when * ] read. Although the timer value settles properly after incrementing, * ] while incrementing there is a 3nS window every 69.8nS where the * ] timer value is indeterminate (a 4.2% chance that the data will be * ] incorrect when read). As a result, the ACPI free running count up * ] timer specification is violated due to erroneous reads. Implication: * ] System hangs due to the "inaccuracy" of the timer when used by * ] software for time critical events and delays. * ] * ] Workaround: Read the register twice and compare. * ] Status: This will not be fixed in the PIIX4 or PIIX4E, it is fixed * ] in the PIIX4M. * * The counter is in other words not latched to the PCI bus clock when * read. Notice the workaround isn't: We need to read until we have * three monotonic samples and then use the middle one, otherwise we are * not protected against the fact that the bits can be wrong in two * directions. If we only cared about monosity two reads would be enough. */ #if 0 static int acpi_timer_pci_probe(device_t dev); static device_method_t acpi_timer_pci_methods[] = { DEVMETHOD(device_probe, acpi_timer_pci_probe), {0, 0} }; static driver_t acpi_timer_pci_driver = { "acpi_timer_pci", acpi_timer_pci_methods, 0, }; devclass_t acpi_timer_pci_devclass; DRIVER_MODULE(acpi_timer_pci, pci, acpi_timer_pci_driver, acpi_timer_pci_devclass, 0, 0); /* * Look at PCI devices going past; if we detect one we know contains * a functional ACPI timer device, enable the faster timecounter read * routine. */ static int acpi_timer_pci_probe(device_t dev) { int vendor, device, revid; vendor = pci_get_vendor(dev); device = pci_get_device(dev); revid = pci_get_revid(dev); if (((vendor == 0x8086) && (device == 0x7113) && (revid >= 0x03)) || /* PIIX4M */ ((vendor == 0x8086) && (device == 0x719b)) || /* i440MX */ 0) { acpi_timer_timecounter.tc_get_timecount = acpi_timer_get_timecount; acpi_timer_timecounter.tc_name = "ACPI-fast"; if (bootverbose) device_printf(acpi_timer_dev, "functional ACPI timer detected, enabling fast timecount interface\n"); } return(ENXIO); /* we never match anything */ } #endif