Index: head/sys/dev/acpi_support/atk0110.c =================================================================== --- head/sys/dev/acpi_support/atk0110.c (revision 252275) +++ head/sys/dev/acpi_support/atk0110.c (revision 252276) @@ -1,358 +1,358 @@ /* $NetBSD: atk0110.c,v 1.4 2010/02/11 06:54:57 cnst Exp $ */ /* $OpenBSD: atk0110.c,v 1.1 2009/07/23 01:38:16 cnst Exp $ */ /* * Copyright (c) 2009, 2010 Constantine A. Murenin * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include /* * ASUSTeK AI Booster (ACPI ASOC ATK0110). * * This code was originally written for OpenBSD after the techniques * described in the Linux's asus_atk0110.c and FreeBSD's Takanori Watanabe's * acpi_aiboost.c were verified to be accurate on the actual hardware kindly * provided by Sam Fourman Jr. It was subsequently ported from OpenBSD to * DragonFly BSD, to NetBSD's sysmon_envsys(9) and to FreeBSD's sysctl(9). * * -- Constantine A. Murenin */ #define _COMPONENT ACPI_OEM ACPI_MODULE_NAME("aibs"); ACPI_SERIAL_DECL(aibs, "aibs"); #define AIBS_MORE_SENSORS #define AIBS_VERBOSE enum aibs_type { AIBS_VOLT, AIBS_TEMP, AIBS_FAN }; struct aibs_sensor { ACPI_INTEGER v; ACPI_INTEGER i; ACPI_INTEGER l; ACPI_INTEGER h; enum aibs_type t; }; struct aibs_softc { struct device *sc_dev; ACPI_HANDLE sc_ah; struct aibs_sensor *sc_asens_volt; struct aibs_sensor *sc_asens_temp; struct aibs_sensor *sc_asens_fan; }; static int aibs_probe(device_t); static int aibs_attach(device_t); static int aibs_detach(device_t); static int aibs_sysctl(SYSCTL_HANDLER_ARGS); static void aibs_attach_sif(struct aibs_softc *, enum aibs_type); static device_method_t aibs_methods[] = { DEVMETHOD(device_probe, aibs_probe), DEVMETHOD(device_attach, aibs_attach), DEVMETHOD(device_detach, aibs_detach), { NULL, NULL } }; static driver_t aibs_driver = { "aibs", aibs_methods, sizeof(struct aibs_softc) }; static devclass_t aibs_devclass; DRIVER_MODULE(aibs, acpi, aibs_driver, aibs_devclass, NULL, NULL); MODULE_DEPEND(aibs, acpi, 1, 1, 1); static char* aibs_hids[] = { "ATK0110", NULL }; static int aibs_probe(device_t dev) { if (acpi_disabled("aibs") || ACPI_ID_PROBE(device_get_parent(dev), dev, aibs_hids) == NULL) return ENXIO; device_set_desc(dev, "ASUSTeK AI Booster (ACPI ASOC ATK0110)"); return 0; } static int aibs_attach(device_t dev) { struct aibs_softc *sc = device_get_softc(dev); sc->sc_dev = dev; sc->sc_ah = acpi_get_handle(dev); aibs_attach_sif(sc, AIBS_VOLT); aibs_attach_sif(sc, AIBS_TEMP); aibs_attach_sif(sc, AIBS_FAN); return 0; } static void aibs_attach_sif(struct aibs_softc *sc, enum aibs_type st) { ACPI_STATUS s; ACPI_BUFFER b; ACPI_OBJECT *bp, *o; int i, n; const char *node; char name[] = "?SIF"; struct aibs_sensor *as; struct sysctl_oid *so; switch (st) { case AIBS_VOLT: node = "volt"; name[0] = 'V'; break; case AIBS_TEMP: node = "temp"; name[0] = 'T'; break; case AIBS_FAN: node = "fan"; name[0] = 'F'; break; default: return; } b.Length = ACPI_ALLOCATE_BUFFER; s = AcpiEvaluateObjectTyped(sc->sc_ah, name, NULL, &b, ACPI_TYPE_PACKAGE); if (ACPI_FAILURE(s)) { device_printf(sc->sc_dev, "%s not found\n", name); return; } bp = b.Pointer; o = bp->Package.Elements; if (o[0].Type != ACPI_TYPE_INTEGER) { device_printf(sc->sc_dev, "%s[0]: invalid type\n", name); AcpiOsFree(b.Pointer); return; } n = o[0].Integer.Value; if (bp->Package.Count - 1 < n) { device_printf(sc->sc_dev, "%s: invalid package\n", name); AcpiOsFree(b.Pointer); return; } else if (bp->Package.Count - 1 > n) { int on = n; #ifdef AIBS_MORE_SENSORS n = bp->Package.Count - 1; #endif device_printf(sc->sc_dev, "%s: malformed package: %i/%i" ", assume %i\n", name, on, bp->Package.Count - 1, n); } if (n < 1) { device_printf(sc->sc_dev, "%s: no members in the package\n", name); AcpiOsFree(b.Pointer); return; } as = malloc(sizeof(*as) * n, M_DEVBUF, M_NOWAIT | M_ZERO); if (as == NULL) { device_printf(sc->sc_dev, "%s: malloc fail\n", name); AcpiOsFree(b.Pointer); return; } switch (st) { case AIBS_VOLT: sc->sc_asens_volt = as; break; case AIBS_TEMP: sc->sc_asens_temp = as; break; case AIBS_FAN: sc->sc_asens_fan = as; break; } /* sysctl subtree for sensors of this type */ so = SYSCTL_ADD_NODE(device_get_sysctl_ctx(sc->sc_dev), SYSCTL_CHILDREN(device_get_sysctl_tree(sc->sc_dev)), st, node, CTLFLAG_RD, NULL, NULL); for (i = 0, o++; i < n; i++, o++) { ACPI_OBJECT *oi; char si[3]; const char *desc; /* acpica5 automatically evaluates the referenced package */ if (o[0].Type != ACPI_TYPE_PACKAGE) { device_printf(sc->sc_dev, "%s: %i: not a package: %i type\n", name, i, o[0].Type); continue; } oi = o[0].Package.Elements; if (o[0].Package.Count != 5 || oi[0].Type != ACPI_TYPE_INTEGER || oi[1].Type != ACPI_TYPE_STRING || oi[2].Type != ACPI_TYPE_INTEGER || oi[3].Type != ACPI_TYPE_INTEGER || oi[4].Type != ACPI_TYPE_INTEGER) { device_printf(sc->sc_dev, "%s: %i: invalid package\n", name, i); continue; } as[i].i = oi[0].Integer.Value; desc = oi[1].String.Pointer; as[i].l = oi[2].Integer.Value; as[i].h = oi[3].Integer.Value; as[i].t = st; #ifdef AIBS_VERBOSE device_printf(sc->sc_dev, "%c%i: " "0x%08"PRIx64" %20s %5"PRIi64" / %5"PRIi64" " "0x%"PRIx64"\n", name[0], i, - as[i].i, desc, (int64_t)as[i].l, (int64_t)as[i].h, - oi[4].Integer.Value); + (uint64_t)as[i].i, desc, (int64_t)as[i].l, + (int64_t)as[i].h, (uint64_t)oi[4].Integer.Value); #endif snprintf(si, sizeof(si), "%i", i); SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->sc_dev), SYSCTL_CHILDREN(so), i, si, CTLTYPE_INT | CTLFLAG_RD, sc, st, aibs_sysctl, st == AIBS_TEMP ? "IK" : "I", desc); } AcpiOsFree(b.Pointer); } static int aibs_detach(device_t dev) { struct aibs_softc *sc = device_get_softc(dev); if (sc->sc_asens_volt != NULL) free(sc->sc_asens_volt, M_DEVBUF); if (sc->sc_asens_temp != NULL) free(sc->sc_asens_temp, M_DEVBUF); if (sc->sc_asens_fan != NULL) free(sc->sc_asens_fan, M_DEVBUF); return 0; } #ifdef AIBS_VERBOSE #define ddevice_printf(x...) device_printf(x) #else #define ddevice_printf(x...) #endif static int aibs_sysctl(SYSCTL_HANDLER_ARGS) { struct aibs_softc *sc = arg1; enum aibs_type st = arg2; int i = oidp->oid_number; ACPI_STATUS rs; ACPI_OBJECT p, *bp; ACPI_OBJECT_LIST mp; ACPI_BUFFER b; char *name; struct aibs_sensor *as; ACPI_INTEGER v, l, h; int so[3]; switch (st) { case AIBS_VOLT: name = "RVLT"; as = sc->sc_asens_volt; break; case AIBS_TEMP: name = "RTMP"; as = sc->sc_asens_temp; break; case AIBS_FAN: name = "RFAN"; as = sc->sc_asens_fan; break; default: return ENOENT; } if (as == NULL) return ENOENT; l = as[i].l; h = as[i].h; p.Type = ACPI_TYPE_INTEGER; p.Integer.Value = as[i].i; mp.Count = 1; mp.Pointer = &p; b.Length = ACPI_ALLOCATE_BUFFER; ACPI_SERIAL_BEGIN(aibs); rs = AcpiEvaluateObjectTyped(sc->sc_ah, name, &mp, &b, ACPI_TYPE_INTEGER); if (ACPI_FAILURE(rs)) { ddevice_printf(sc->sc_dev, "%s: %i: evaluation failed\n", name, i); ACPI_SERIAL_END(aibs); return EIO; } bp = b.Pointer; v = bp->Integer.Value; AcpiOsFree(b.Pointer); ACPI_SERIAL_END(aibs); switch (st) { case AIBS_VOLT: break; case AIBS_TEMP: v += 2732; l += 2732; h += 2732; break; case AIBS_FAN: break; } so[0] = v; so[1] = l; so[2] = h; return sysctl_handle_opaque(oidp, &so, sizeof(so), req); } Index: head/sys/dev/acpica/acpi_pcib_acpi.c =================================================================== --- head/sys/dev/acpica/acpi_pcib_acpi.c (revision 252275) +++ head/sys/dev/acpica/acpi_pcib_acpi.c (revision 252276) @@ -1,562 +1,562 @@ /*- * 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. */ #include __FBSDID("$FreeBSD$"); #include "opt_acpi.h" #include #include #include #include #include #include #include #include #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_flags; int ap_segment; /* PCI domain */ int ap_bus; /* bios-assigned bus number */ int ap_addr; /* device/func of PCI-Host bridge */ ACPI_BUFFER ap_prt; /* interrupt routing table */ #ifdef NEW_PCIB struct pcib_host_resources ap_host_res; #endif }; static int acpi_pcib_acpi_probe(device_t bus); static int acpi_pcib_acpi_attach(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 uint32_t acpi_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int bytes); static void acpi_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, uint32_t data, int bytes); static int acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin); static int acpi_pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs); static int acpi_pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data); static int acpi_pcib_alloc_msix(device_t pcib, device_t dev, int *irq); static struct resource *acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags); #ifdef NEW_PCIB static int acpi_pcib_acpi_adjust_resource(device_t dev, device_t child, int type, struct resource *r, u_long start, u_long end); #endif 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, bus_generic_resume), /* Bus interface */ DEVMETHOD(bus_read_ivar, acpi_pcib_read_ivar), DEVMETHOD(bus_write_ivar, acpi_pcib_write_ivar), DEVMETHOD(bus_alloc_resource, acpi_pcib_acpi_alloc_resource), #ifdef NEW_PCIB DEVMETHOD(bus_adjust_resource, acpi_pcib_acpi_adjust_resource), #else DEVMETHOD(bus_adjust_resource, bus_generic_adjust_resource), #endif 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), DEVMETHOD(pcib_alloc_msi, acpi_pcib_alloc_msi), DEVMETHOD(pcib_release_msi, pcib_release_msi), DEVMETHOD(pcib_alloc_msix, acpi_pcib_alloc_msix), DEVMETHOD(pcib_release_msix, pcib_release_msix), DEVMETHOD(pcib_map_msi, acpi_pcib_map_msi), DEVMETHOD(pcib_power_for_sleep, acpi_pcib_power_for_sleep), DEVMETHOD_END }; static devclass_t pcib_devclass; DEFINE_CLASS_0(pcib, acpi_pcib_acpi_driver, acpi_pcib_acpi_methods, sizeof(struct acpi_hpcib_softc)); DRIVER_MODULE(acpi_pcib, acpi, acpi_pcib_acpi_driver, pcib_devclass, 0, 0); MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1); static int acpi_pcib_acpi_probe(device_t dev) { ACPI_DEVICE_INFO *devinfo; ACPI_HANDLE h; int root; if (acpi_disabled("pcib") || (h = acpi_get_handle(dev)) == NULL || ACPI_FAILURE(AcpiGetObjectInfo(h, &devinfo))) return (ENXIO); root = (devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0; AcpiOsFree(devinfo); if (!root || pci_cfgregopen() == 0) return (ENXIO); device_set_desc(dev, "ACPI Host-PCI bridge"); return (0); } #ifdef NEW_PCIB static ACPI_STATUS acpi_pcib_producer_handler(ACPI_RESOURCE *res, void *context) { struct acpi_hpcib_softc *sc; UINT64 length, min, max; u_int flags; int error, type; sc = context; switch (res->Type) { case ACPI_RESOURCE_TYPE_START_DEPENDENT: case ACPI_RESOURCE_TYPE_END_DEPENDENT: panic("host bridge has depenedent resources"); case ACPI_RESOURCE_TYPE_ADDRESS16: case ACPI_RESOURCE_TYPE_ADDRESS32: case ACPI_RESOURCE_TYPE_ADDRESS64: case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: if (res->Data.Address.ProducerConsumer != ACPI_PRODUCER) break; switch (res->Type) { case ACPI_RESOURCE_TYPE_ADDRESS16: min = res->Data.Address16.Minimum; max = res->Data.Address16.Maximum; length = res->Data.Address16.AddressLength; break; case ACPI_RESOURCE_TYPE_ADDRESS32: min = res->Data.Address32.Minimum; max = res->Data.Address32.Maximum; length = res->Data.Address32.AddressLength; break; case ACPI_RESOURCE_TYPE_ADDRESS64: min = res->Data.Address64.Minimum; max = res->Data.Address64.Maximum; length = res->Data.Address64.AddressLength; break; default: KASSERT(res->Type == ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64, ("should never happen")); min = res->Data.ExtAddress64.Minimum; max = res->Data.ExtAddress64.Maximum; length = res->Data.ExtAddress64.AddressLength; break; } if (length == 0) break; if (min + length - 1 != max && (res->Data.Address.MinAddressFixed != ACPI_ADDRESS_FIXED || res->Data.Address.MaxAddressFixed != ACPI_ADDRESS_FIXED)) break; flags = 0; switch (res->Data.Address.ResourceType) { case ACPI_MEMORY_RANGE: type = SYS_RES_MEMORY; if (res->Type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64) { if (res->Data.Address.Info.Mem.Caching == ACPI_PREFETCHABLE_MEMORY) flags |= RF_PREFETCHABLE; } else { /* * XXX: Parse prefetch flag out of * TypeSpecific. */ } break; case ACPI_IO_RANGE: type = SYS_RES_IOPORT; break; #ifdef PCI_RES_BUS case ACPI_BUS_NUMBER_RANGE: type = PCI_RES_BUS; break; #endif default: return (AE_OK); } if (min + length - 1 != max) device_printf(sc->ap_dev, "Length mismatch for %d range: %jx vs %jx\n", type, - (uintmax_t)max - min + 1, (uintmax_t)length); + (uintmax_t)(max - min + 1), (uintmax_t)length); #ifdef __i386__ if (min > ULONG_MAX) { device_printf(sc->ap_dev, "Ignoring %d range above 4GB (%#jx-%#jx)\n", type, (uintmax_t)min, (uintmax_t)max); break; } if (max > ULONG_MAX) { device_printf(sc->ap_dev, "Truncating end of %d range above 4GB (%#jx-%#jx)\n", type, (uintmax_t)min, (uintmax_t)max); max = ULONG_MAX; } #endif error = pcib_host_res_decodes(&sc->ap_host_res, type, min, max, flags); if (error) panic("Failed to manage %d range (%#jx-%#jx): %d", type, (uintmax_t)min, (uintmax_t)max, error); break; default: break; } return (AE_OK); } #endif static int acpi_pcib_acpi_attach(device_t dev) { struct acpi_hpcib_softc *sc; ACPI_STATUS status; static int bus0_seen = 0; u_int 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 segment number by evaluating _SEG. * It's OK for this to not exist. */ status = acpi_GetInteger(sc->ap_handle, "_SEG", &sc->ap_segment); if (ACPI_FAILURE(status)) { 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; } /* * Get the address (device and function) of the associated * PCI-Host bridge device from _ADR. Assume we don't have one if * it doesn't exist. */ status = acpi_GetInteger(sc->ap_handle, "_ADR", &sc->ap_addr); if (ACPI_FAILURE(status)) { device_printf(dev, "could not evaluate _ADR - %s\n", AcpiFormatException(status)); sc->ap_addr = -1; } #ifdef NEW_PCIB /* * Determine which address ranges this bridge decodes and setup * resource managers for those ranges. */ if (pcib_host_res_init(sc->ap_dev, &sc->ap_host_res) != 0) panic("failed to init hostb resources"); if (!acpi_disabled("hostres")) { status = AcpiWalkResources(sc->ap_handle, "_CRS", acpi_pcib_producer_handler, sc); if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) device_printf(sc->ap_dev, "failed to parse resources: %s\n", AcpiFormatException(status)); } #endif /* * 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 PCI bus 0 already exists, we try to read our * bus number from the configuration registers at address _ADR. * We only do this for domain/segment 0 in the hopes that this is * only needed for old single-domain machines. */ status = acpi_GetInteger(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 this is segment 0, the bus is zero, and PCI bus 0 already * exists, read the bus number via PCI config space. */ busok = 1; if (sc->ap_segment == 0 && sc->ap_bus == 0 && bus0_seen) { busok = 0; if (sc->ap_addr != -1) { /* XXX: We assume bus 0. */ slot = ACPI_ADR_PCI_SLOT(sc->ap_addr); func = ACPI_ADR_PCI_FUNC(sc->ap_addr); 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, "couldn't read bus number from cfg 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); } /* If this is bus 0 on segment 0, note that it has been seen already. */ if (sc->ap_segment == 0 && sc->ap_bus == 0) bus0_seen = 1; return (acpi_pcib_attach(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_DOMAIN: *result = sc->ap_segment; return (0); case PCIB_IVAR_BUS: *result = sc->ap_bus; return (0); case ACPI_IVAR_HANDLE: *result = (uintptr_t)sc->ap_handle; return (0); case ACPI_IVAR_FLAGS: *result = (uintptr_t)sc->ap_flags; 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_DOMAIN: return (EINVAL); case PCIB_IVAR_BUS: sc->ap_bus = value; return (0); case ACPI_IVAR_HANDLE: sc->ap_handle = (ACPI_HANDLE)value; return (0); case ACPI_IVAR_FLAGS: sc->ap_flags = (int)value; return (0); } return (ENOENT); } static uint32_t acpi_pcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, int bytes) { return (pci_cfgregread(bus, slot, func, reg, bytes)); } static void acpi_pcib_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, uint32_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 = device_get_softc(pcib); return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt)); } static int acpi_pcib_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs) { device_t bus; bus = device_get_parent(pcib); return (PCIB_ALLOC_MSI(device_get_parent(bus), dev, count, maxcount, irqs)); } static int acpi_pcib_alloc_msix(device_t pcib, device_t dev, int *irq) { device_t bus; bus = device_get_parent(pcib); return (PCIB_ALLOC_MSIX(device_get_parent(bus), dev, irq)); } static int acpi_pcib_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data) { struct acpi_hpcib_softc *sc; device_t bus, hostb; int error; bus = device_get_parent(pcib); error = PCIB_MAP_MSI(device_get_parent(bus), dev, irq, addr, data); if (error) return (error); sc = device_get_softc(pcib); if (sc->ap_addr == -1) return (0); /* XXX: Assumes all bridges are on bus 0. */ hostb = pci_find_dbsf(sc->ap_segment, 0, ACPI_ADR_PCI_SLOT(sc->ap_addr), ACPI_ADR_PCI_FUNC(sc->ap_addr)); if (hostb != NULL) pci_ht_map_msi(hostb, *addr); return (0); } struct resource * acpi_pcib_acpi_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { #ifdef NEW_PCIB struct acpi_hpcib_softc *sc; struct resource *res; #endif #if defined(__i386__) || defined(__amd64__) start = hostb_alloc_start(type, start, end, count); #endif #ifdef NEW_PCIB sc = device_get_softc(dev); res = pcib_host_res_alloc(&sc->ap_host_res, child, type, rid, start, end, count, flags); /* * XXX: If this is a request for a specific range, assume it is * correct and pass it up to the parent. What we probably want to * do long-term is explicitly trust any firmware-configured * resources during the initial bus scan on boot and then disable * this after that. */ if (res == NULL && start + count - 1 == end) res = bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags); return (res); #else return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); #endif } #ifdef NEW_PCIB int acpi_pcib_acpi_adjust_resource(device_t dev, device_t child, int type, struct resource *r, u_long start, u_long end) { struct acpi_hpcib_softc *sc; sc = device_get_softc(dev); return (pcib_host_res_adjust(&sc->ap_host_res, child, type, r, start, end)); } #endif Index: head/usr.sbin/acpi/acpidb/acpidb.c =================================================================== --- head/usr.sbin/acpi/acpidb/acpidb.c (revision 252275) +++ head/usr.sbin/acpi/acpidb/acpidb.c (revision 252276) @@ -1,508 +1,508 @@ /*- * Copyright (c) 2000-2002 Mitsuru IWASAKI * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * Dummy DSDT Table Header */ static ACPI_TABLE_HEADER dummy_dsdt_table = { "DSDT", 123, 1, 123, "OEMID", "OEMTBLID", 1, "CRID", 1 }; /* * Region space I/O routines on virtual machine */ static int aml_debug_prompt = 1; struct ACPIRegionContent { TAILQ_ENTRY(ACPIRegionContent) links; int regtype; ACPI_PHYSICAL_ADDRESS addr; UINT8 value; }; TAILQ_HEAD(ACPIRegionContentList, ACPIRegionContent); static struct ACPIRegionContentList RegionContentList; static int aml_simulation_initialized = 0; ACPI_PHYSICAL_ADDRESS AeLocalGetRootPointer(void); void AeTableOverride(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER **); static void aml_simulation_init(void); static int aml_simulate_regcontent_add(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 value); static int aml_simulate_regcontent_read(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep); static int aml_simulate_regcontent_write(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep); static UINT64 aml_simulate_prompt(char *msg, UINT64 def_val); static void aml_simulation_regload(const char *dumpfile); static void aml_simulation_regdump(const char *dumpfile); /* Stubs to simplify linkage to the ACPI CA core subsystem. */ ACPI_PHYSICAL_ADDRESS AeLocalGetRootPointer(void) { return (0); } void AeTableOverride(ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable) { } static void aml_simulation_init(void) { aml_simulation_initialized = 1; TAILQ_INIT(&RegionContentList); aml_simulation_regload("region.ini"); } static int aml_simulate_regcontent_add(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 value) { struct ACPIRegionContent *rc; rc = malloc(sizeof(struct ACPIRegionContent)); if (rc == NULL) { return (-1); /* malloc fail */ } rc->regtype = regtype; rc->addr = addr; rc->value = value; TAILQ_INSERT_TAIL(&RegionContentList, rc, links); return (0); } static int aml_simulate_regcontent_read(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep) { struct ACPIRegionContent *rc; if (!aml_simulation_initialized) { aml_simulation_init(); } TAILQ_FOREACH(rc, &RegionContentList, links) { if (rc->regtype == regtype && rc->addr == addr) { *valuep = rc->value; return (1); /* found */ } } *valuep = 0; return (aml_simulate_regcontent_add(regtype, addr, *valuep)); } static int aml_simulate_regcontent_write(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep) { struct ACPIRegionContent *rc; if (!aml_simulation_initialized) { aml_simulation_init(); } TAILQ_FOREACH(rc, &RegionContentList, links) { if (rc->regtype == regtype && rc->addr == addr) { rc->value = *valuep; return (1); /* exists */ } } return (aml_simulate_regcontent_add(regtype, addr, *valuep)); } static UINT64 aml_simulate_prompt(char *msg, UINT64 def_val) { char buf[16], *ep; UINT64 val; val = def_val; printf("DEBUG"); if (msg != NULL) { printf("%s", msg); } - printf("(default: 0x%jx ", val); - printf(" / %ju) >>", val); + printf("(default: 0x%jx ", (uintmax_t)val); + printf(" / %ju) >>", (uintmax_t)val); fflush(stdout); bzero(buf, sizeof buf); while (1) { if (read(0, buf, sizeof buf) == 0) { continue; } if (buf[0] == '\n') { break; /* use default value */ } if (buf[0] == '0' && buf[1] == 'x') { val = strtoq(buf, &ep, 16); } else { val = strtoq(buf, &ep, 10); } break; } return (val); } static void aml_simulation_regload(const char *dumpfile) { char buf[256], *np, *ep; struct ACPIRegionContent rc; FILE *fp; if (!aml_simulation_initialized) { return; } if ((fp = fopen(dumpfile, "r")) == NULL) { return; } while (fgets(buf, sizeof buf, fp) != NULL) { np = buf; /* reading region type */ rc.regtype = strtoq(np, &ep, 10); if (np == ep) { continue; } np = ep; /* reading address */ rc.addr = strtoq(np, &ep, 16); if (np == ep) { continue; } np = ep; /* reading value */ rc.value = strtoq(np, &ep, 16); if (np == ep) { continue; } aml_simulate_regcontent_write(rc.regtype, rc.addr, &rc.value); } fclose(fp); } static void aml_simulation_regdump(const char *dumpfile) { struct ACPIRegionContent *rc; FILE *fp; if (!aml_simulation_initialized) { return; } if ((fp = fopen(dumpfile, "w")) == NULL) { warn("%s", dumpfile); return; } while (!TAILQ_EMPTY(&RegionContentList)) { rc = TAILQ_FIRST(&RegionContentList); fprintf(fp, "%d 0x%jx 0x%x\n", rc->regtype, (uintmax_t)rc->addr, rc->value); TAILQ_REMOVE(&RegionContentList, rc, links); free(rc); } fclose(fp); TAILQ_INIT(&RegionContentList); } /* * Space handlers on virtual machine */ static ACPI_STATUS aml_vm_space_handler( UINT32 SpaceID, UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 BitWidth, UINT64 *Value, int Prompt) { int state; UINT8 val; UINT64 value, i; char msg[256]; static const char *space_names[] = { "SYSTEM_MEMORY", "SYSTEM_IO", "PCI_CONFIG", "EC", "SMBUS", "CMOS", "PCI_BAR_TARGET"}; switch (Function) { case ACPI_READ: value = 0; for (i = 0; (i * 8) < BitWidth; i++) { state = aml_simulate_regcontent_read(SpaceID, Address + i, &val); if (state == -1) { return (AE_NO_MEMORY); } value |= val << (i * 8); } *Value = value; if (Prompt) { sprintf(msg, "[read (%s, %2d, 0x%jx)]", space_names[SpaceID], BitWidth, (uintmax_t)Address); *Value = aml_simulate_prompt(msg, value); if (*Value != value) { return(aml_vm_space_handler(SpaceID, ACPI_WRITE, Address, BitWidth, Value, 0)); } } break; case ACPI_WRITE: value = *Value; if (Prompt) { sprintf(msg, "[write(%s, %2d, 0x%jx)]", space_names[SpaceID], BitWidth, (uintmax_t)Address); value = aml_simulate_prompt(msg, *Value); } *Value = value; for (i = 0; (i * 8) < BitWidth; i++) { val = value & 0xff; state = aml_simulate_regcontent_write(SpaceID, Address + i, &val); if (state == -1) { return (AE_NO_MEMORY); } value = value >> 8; } } return (AE_OK); } #define DECLARE_VM_SPACE_HANDLER(name, id); \ static ACPI_STATUS \ aml_vm_space_handler_##name ( \ UINT32 Function, \ ACPI_PHYSICAL_ADDRESS Address, \ UINT32 BitWidth, \ UINT64 *Value) \ { \ return (aml_vm_space_handler(id, Function, Address, \ BitWidth, Value, aml_debug_prompt)); \ } DECLARE_VM_SPACE_HANDLER(system_memory, ACPI_ADR_SPACE_SYSTEM_MEMORY); DECLARE_VM_SPACE_HANDLER(system_io, ACPI_ADR_SPACE_SYSTEM_IO); DECLARE_VM_SPACE_HANDLER(pci_config, ACPI_ADR_SPACE_PCI_CONFIG); DECLARE_VM_SPACE_HANDLER(ec, ACPI_ADR_SPACE_EC); DECLARE_VM_SPACE_HANDLER(smbus, ACPI_ADR_SPACE_SMBUS); DECLARE_VM_SPACE_HANDLER(cmos, ACPI_ADR_SPACE_CMOS); DECLARE_VM_SPACE_HANDLER(pci_bar_target,ACPI_ADR_SPACE_PCI_BAR_TARGET); /* * Load DSDT data file and invoke debugger */ static int load_dsdt(const char *dsdtfile) { char filetmp[PATH_MAX]; u_int8_t *code; struct stat sb; int fd, fd2; int error; fd = open(dsdtfile, O_RDONLY, 0); if (fd == -1) { perror("open"); return (-1); } if (fstat(fd, &sb) == -1) { perror("fstat"); close(fd); return (-1); } code = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0); if (code == NULL) { perror("mmap"); return (-1); } if ((error = AcpiInitializeSubsystem()) != AE_OK) { return (-1); } /* * make sure DSDT data contains table header or not. */ if (strncmp((char *)code, "DSDT", 4) == 0) { strncpy(filetmp, dsdtfile, sizeof(filetmp)); } else { mode_t mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); dummy_dsdt_table.Length = sizeof(ACPI_TABLE_HEADER) + sb.st_size; snprintf(filetmp, sizeof(filetmp), "%s.tmp", dsdtfile); fd2 = open(filetmp, O_WRONLY | O_CREAT | O_TRUNC, mode); if (fd2 == -1) { perror("open"); return (-1); } write(fd2, &dummy_dsdt_table, sizeof(ACPI_TABLE_HEADER)); write(fd2, code, sb.st_size); close(fd2); } /* * Install the virtual machine version of address space handlers. */ if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_MEMORY, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_memory, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise SystemMemory handler: %d\n", error); return (-1); } if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_IO, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_io, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise SystemIO handler: %d\n", error); return (-1); } if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_PCI_CONFIG, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_config, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise PciConfig handler: %d\n", error); return (-1); } if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_EC, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_ec, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise EC handler: %d\n", error); return (-1); } if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SMBUS, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_smbus, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise SMBUS handler: %d\n", error); return (-1); } if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_CMOS, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_cmos, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise CMOS handler: %d\n", error); return (-1); } if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_PCI_BAR_TARGET, (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_bar_target, NULL, NULL)) != AE_OK) { fprintf(stderr, "could not initialise PCI BAR TARGET handler: %d\n", error); return (-1); } AcpiDbGetTableFromFile(filetmp, NULL); AcpiDbInitialize(); AcpiGbl_DebuggerConfiguration = 0; AcpiDbUserCommands(':', NULL); if (strcmp(dsdtfile, filetmp) != 0) { unlink(filetmp); } return (0); } static void usage(const char *progname) { printf("usage: %s dsdt_file\n", progname); exit(1); } int main(int argc, char *argv[]) { char *progname; progname = argv[0]; if (argc == 1) { usage(progname); } AcpiDbgLevel = ACPI_DEBUG_DEFAULT; /* * Match kernel options for the interpreter. Global variable names * can be found in acglobal.h. */ AcpiGbl_EnableInterpreterSlack = TRUE; aml_simulation_regload("region.ini"); if (load_dsdt(argv[1]) == 0) { aml_simulation_regdump("region.dmp"); } return (0); } Index: head/usr.sbin/acpi/acpidump/acpi.c =================================================================== --- head/usr.sbin/acpi/acpidump/acpi.c (revision 252275) +++ head/usr.sbin/acpi/acpidump/acpi.c (revision 252276) @@ -1,1588 +1,1588 @@ /*- * Copyright (c) 1998 Doug Rabson * Copyright (c) 2000 Mitsuru IWASAKI * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include "acpidump.h" #define BEGIN_COMMENT "/*\n" #define END_COMMENT " */\n" static void acpi_print_string(char *s, size_t length); static void acpi_print_gas(ACPI_GENERIC_ADDRESS *gas); static int acpi_get_fadt_revision(ACPI_TABLE_FADT *fadt); static void acpi_handle_fadt(ACPI_TABLE_HEADER *fadt); static void acpi_print_cpu(u_char cpu_id); static void acpi_print_cpu_uid(uint32_t uid, char *uid_string); static void acpi_print_local_apic(uint32_t apic_id, uint32_t flags); static void acpi_print_io_apic(uint32_t apic_id, uint32_t int_base, uint64_t apic_addr); static void acpi_print_mps_flags(uint16_t flags); static void acpi_print_intr(uint32_t intr, uint16_t mps_flags); static void acpi_print_local_nmi(u_int lint, uint16_t mps_flags); static void acpi_print_madt(ACPI_SUBTABLE_HEADER *mp); static void acpi_handle_madt(ACPI_TABLE_HEADER *sdp); static void acpi_handle_ecdt(ACPI_TABLE_HEADER *sdp); static void acpi_handle_hpet(ACPI_TABLE_HEADER *sdp); static void acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp); static void acpi_handle_slit(ACPI_TABLE_HEADER *sdp); static void acpi_print_srat_cpu(uint32_t apic_id, uint32_t proximity_domain, uint32_t flags); static void acpi_print_srat_memory(ACPI_SRAT_MEM_AFFINITY *mp); static void acpi_print_srat(ACPI_SUBTABLE_HEADER *srat); static void acpi_handle_srat(ACPI_TABLE_HEADER *sdp); static void acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp); static void acpi_print_sdt(ACPI_TABLE_HEADER *sdp); static void acpi_print_fadt(ACPI_TABLE_HEADER *sdp); static void acpi_print_facs(ACPI_TABLE_FACS *facs); static void acpi_print_dsdt(ACPI_TABLE_HEADER *dsdp); static ACPI_TABLE_HEADER *acpi_map_sdt(vm_offset_t pa); static void acpi_print_rsd_ptr(ACPI_TABLE_RSDP *rp); static void acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp); static void acpi_walk_subtables(ACPI_TABLE_HEADER *table, void *first, void (*action)(ACPI_SUBTABLE_HEADER *)); /* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */ static int addr_size; /* Strings used in the TCPA table */ static const char *tcpa_event_type_strings[] = { "PREBOOT Certificate", "POST Code", "Unused", "No Action", "Separator", "Action", "Event Tag", "S-CRTM Contents", "S-CRTM Version", "CPU Microcode", "Platform Config Flags", "Table of Devices", "Compact Hash", "IPL", "IPL Partition Data", "Non-Host Code", "Non-Host Config", "Non-Host Info" }; static const char *TCPA_pcclient_strings[] = { "", "SMBIOS", "BIS Certificate", "POST BIOS ROM Strings", "ESCD", "CMOS", "NVRAM", "Option ROM Execute", "Option ROM Configurateion", "", "Option ROM Microcode Update ", "S-CRTM Version String", "S-CRTM Contents", "POST Contents", "Table of Devices", }; #define PRINTFLAG_END() printflag_end() static char pf_sep = '{'; static void printflag_end(void) { if (pf_sep != '{') { printf("}"); pf_sep = '{'; } printf("\n"); } static void printflag(uint64_t var, uint64_t mask, const char *name) { if (var & mask) { printf("%c%s", pf_sep, name); pf_sep = ','; } } static void acpi_print_string(char *s, size_t length) { int c; /* Trim trailing spaces and NULLs */ while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) length--; while (length--) { c = *s++; putchar(c); } } static void acpi_print_gas(ACPI_GENERIC_ADDRESS *gas) { switch(gas->SpaceId) { case ACPI_GAS_MEMORY: printf("0x%08lx:%u[%u] (Memory)", (u_long)gas->Address, gas->BitOffset, gas->BitWidth); break; case ACPI_GAS_IO: printf("0x%02lx:%u[%u] (IO)", (u_long)gas->Address, gas->BitOffset, gas->BitWidth); break; case ACPI_GAS_PCI: printf("%x:%x+0x%x (PCI)", (uint16_t)(gas->Address >> 32), (uint16_t)((gas->Address >> 16) & 0xffff), (uint16_t)gas->Address); break; /* XXX How to handle these below? */ case ACPI_GAS_EMBEDDED: printf("0x%x:%u[%u] (EC)", (uint16_t)gas->Address, gas->BitOffset, gas->BitWidth); break; case ACPI_GAS_SMBUS: printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas->Address, gas->BitOffset, gas->BitWidth); break; case ACPI_GAS_CMOS: case ACPI_GAS_PCIBAR: case ACPI_GAS_DATATABLE: case ACPI_GAS_FIXED: default: printf("0x%08lx (?)", (u_long)gas->Address); break; } } /* The FADT revision indicates whether we use the DSDT or X_DSDT addresses. */ static int acpi_get_fadt_revision(ACPI_TABLE_FADT *fadt) { int fadt_revision; /* Set the FADT revision separately from the RSDP version. */ if (addr_size == 8) { fadt_revision = 2; /* * A few systems (e.g., IBM T23) have an RSDP that claims * revision 2 but the 64 bit addresses are invalid. If * revision 2 and the 32 bit address is non-zero but the * 32 and 64 bit versions don't match, prefer the 32 bit * version for all subsequent tables. */ if (fadt->Facs != 0 && (fadt->XFacs & 0xffffffff) != fadt->Facs) fadt_revision = 1; } else fadt_revision = 1; return (fadt_revision); } static void acpi_handle_fadt(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_HEADER *dsdp; ACPI_TABLE_FACS *facs; ACPI_TABLE_FADT *fadt; int fadt_revision; fadt = (ACPI_TABLE_FADT *)sdp; acpi_print_fadt(sdp); fadt_revision = acpi_get_fadt_revision(fadt); if (fadt_revision == 1) facs = (ACPI_TABLE_FACS *)acpi_map_sdt(fadt->Facs); else facs = (ACPI_TABLE_FACS *)acpi_map_sdt(fadt->XFacs); if (memcmp(facs->Signature, ACPI_SIG_FACS, 4) != 0 || facs->Length < 64) errx(1, "FACS is corrupt"); acpi_print_facs(facs); if (fadt_revision == 1) dsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->Dsdt); else dsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->XDsdt); if (acpi_checksum(dsdp, dsdp->Length)) errx(1, "DSDT is corrupt"); acpi_print_dsdt(dsdp); } static void acpi_walk_subtables(ACPI_TABLE_HEADER *table, void *first, void (*action)(ACPI_SUBTABLE_HEADER *)) { ACPI_SUBTABLE_HEADER *subtable; char *end; subtable = first; end = (char *)table + table->Length; while ((char *)subtable < end) { printf("\n"); action(subtable); subtable = (ACPI_SUBTABLE_HEADER *)((char *)subtable + subtable->Length); } } static void acpi_print_cpu(u_char cpu_id) { printf("\tACPI CPU="); if (cpu_id == 0xff) printf("ALL\n"); else printf("%d\n", (u_int)cpu_id); } static void acpi_print_cpu_uid(uint32_t uid, char *uid_string) { printf("\tUID=%d", uid); if (uid_string != NULL) printf(" (%s)", uid_string); printf("\n"); } static void acpi_print_local_apic(uint32_t apic_id, uint32_t flags) { printf("\tFlags={"); if (flags & ACPI_MADT_ENABLED) printf("ENABLED"); else printf("DISABLED"); printf("}\n"); printf("\tAPIC ID=%d\n", apic_id); } static void acpi_print_io_apic(uint32_t apic_id, uint32_t int_base, uint64_t apic_addr) { printf("\tAPIC ID=%d\n", apic_id); printf("\tINT BASE=%d\n", int_base); printf("\tADDR=0x%016jx\n", (uintmax_t)apic_addr); } static void acpi_print_mps_flags(uint16_t flags) { printf("\tFlags={Polarity="); switch (flags & ACPI_MADT_POLARITY_MASK) { case ACPI_MADT_POLARITY_CONFORMS: printf("conforming"); break; case ACPI_MADT_POLARITY_ACTIVE_HIGH: printf("active-hi"); break; case ACPI_MADT_POLARITY_ACTIVE_LOW: printf("active-lo"); break; default: printf("0x%x", flags & ACPI_MADT_POLARITY_MASK); break; } printf(", Trigger="); switch (flags & ACPI_MADT_TRIGGER_MASK) { case ACPI_MADT_TRIGGER_CONFORMS: printf("conforming"); break; case ACPI_MADT_TRIGGER_EDGE: printf("edge"); break; case ACPI_MADT_TRIGGER_LEVEL: printf("level"); break; default: printf("0x%x", (flags & ACPI_MADT_TRIGGER_MASK) >> 2); } printf("}\n"); } static void acpi_print_intr(uint32_t intr, uint16_t mps_flags) { printf("\tINTR=%d\n", intr); acpi_print_mps_flags(mps_flags); } static void acpi_print_local_nmi(u_int lint, uint16_t mps_flags) { printf("\tLINT Pin=%d\n", lint); acpi_print_mps_flags(mps_flags); } static const char *apic_types[] = { "Local APIC", "IO APIC", "INT Override", "NMI", "Local APIC NMI", "Local APIC Override", "IO SAPIC", "Local SAPIC", "Platform Interrupt", "Local X2APIC", "Local X2APIC NMI" }; static const char *platform_int_types[] = { "0 (unknown)", "PMI", "INIT", "Corrected Platform Error" }; static void acpi_print_madt(ACPI_SUBTABLE_HEADER *mp) { ACPI_MADT_LOCAL_APIC *lapic; ACPI_MADT_IO_APIC *ioapic; ACPI_MADT_INTERRUPT_OVERRIDE *over; ACPI_MADT_NMI_SOURCE *nmi; ACPI_MADT_LOCAL_APIC_NMI *lapic_nmi; ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic_over; ACPI_MADT_IO_SAPIC *iosapic; ACPI_MADT_LOCAL_SAPIC *lsapic; ACPI_MADT_INTERRUPT_SOURCE *isrc; ACPI_MADT_LOCAL_X2APIC *x2apic; ACPI_MADT_LOCAL_X2APIC_NMI *x2apic_nmi; if (mp->Type < sizeof(apic_types) / sizeof(apic_types[0])) printf("\tType=%s\n", apic_types[mp->Type]); else printf("\tType=%d (unknown)\n", mp->Type); switch (mp->Type) { case ACPI_MADT_TYPE_LOCAL_APIC: lapic = (ACPI_MADT_LOCAL_APIC *)mp; acpi_print_cpu(lapic->ProcessorId); acpi_print_local_apic(lapic->Id, lapic->LapicFlags); break; case ACPI_MADT_TYPE_IO_APIC: ioapic = (ACPI_MADT_IO_APIC *)mp; acpi_print_io_apic(ioapic->Id, ioapic->GlobalIrqBase, ioapic->Address); break; case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: over = (ACPI_MADT_INTERRUPT_OVERRIDE *)mp; printf("\tBUS=%d\n", (u_int)over->Bus); printf("\tIRQ=%d\n", (u_int)over->SourceIrq); acpi_print_intr(over->GlobalIrq, over->IntiFlags); break; case ACPI_MADT_TYPE_NMI_SOURCE: nmi = (ACPI_MADT_NMI_SOURCE *)mp; acpi_print_intr(nmi->GlobalIrq, nmi->IntiFlags); break; case ACPI_MADT_TYPE_LOCAL_APIC_NMI: lapic_nmi = (ACPI_MADT_LOCAL_APIC_NMI *)mp; acpi_print_cpu(lapic_nmi->ProcessorId); acpi_print_local_nmi(lapic_nmi->Lint, lapic_nmi->IntiFlags); break; case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: lapic_over = (ACPI_MADT_LOCAL_APIC_OVERRIDE *)mp; printf("\tLocal APIC ADDR=0x%016jx\n", (uintmax_t)lapic_over->Address); break; case ACPI_MADT_TYPE_IO_SAPIC: iosapic = (ACPI_MADT_IO_SAPIC *)mp; acpi_print_io_apic(iosapic->Id, iosapic->GlobalIrqBase, iosapic->Address); break; case ACPI_MADT_TYPE_LOCAL_SAPIC: lsapic = (ACPI_MADT_LOCAL_SAPIC *)mp; acpi_print_cpu(lsapic->ProcessorId); acpi_print_local_apic(lsapic->Id, lsapic->LapicFlags); printf("\tAPIC EID=%d\n", (u_int)lsapic->Eid); if (mp->Length > __offsetof(ACPI_MADT_LOCAL_SAPIC, Uid)) acpi_print_cpu_uid(lsapic->Uid, lsapic->UidString); break; case ACPI_MADT_TYPE_INTERRUPT_SOURCE: isrc = (ACPI_MADT_INTERRUPT_SOURCE *)mp; if (isrc->Type < sizeof(platform_int_types) / sizeof(platform_int_types[0])) printf("\tType=%s\n", platform_int_types[isrc->Type]); else printf("\tType=%d (unknown)\n", isrc->Type); printf("\tAPIC ID=%d\n", (u_int)isrc->Id); printf("\tAPIC EID=%d\n", (u_int)isrc->Eid); printf("\tSAPIC Vector=%d\n", (u_int)isrc->IoSapicVector); acpi_print_intr(isrc->GlobalIrq, isrc->IntiFlags); break; case ACPI_MADT_TYPE_LOCAL_X2APIC: x2apic = (ACPI_MADT_LOCAL_X2APIC *)mp; acpi_print_cpu_uid(x2apic->Uid, NULL); acpi_print_local_apic(x2apic->LocalApicId, x2apic->LapicFlags); break; case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI: x2apic_nmi = (ACPI_MADT_LOCAL_X2APIC_NMI *)mp; acpi_print_cpu_uid(x2apic_nmi->Uid, NULL); acpi_print_local_nmi(x2apic_nmi->Lint, x2apic_nmi->IntiFlags); break; } } static void acpi_handle_madt(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_MADT *madt; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); madt = (ACPI_TABLE_MADT *)sdp; printf("\tLocal APIC ADDR=0x%08x\n", madt->Address); printf("\tFlags={"); if (madt->Flags & ACPI_MADT_PCAT_COMPAT) printf("PC-AT"); printf("}\n"); acpi_walk_subtables(sdp, (madt + 1), acpi_print_madt); printf(END_COMMENT); } static void acpi_handle_hpet(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_HPET *hpet; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); hpet = (ACPI_TABLE_HPET *)sdp; printf("\tHPET Number=%d\n", hpet->Sequence); printf("\tADDR="); acpi_print_gas(&hpet->Address); printf("\tHW Rev=0x%x\n", hpet->Id & ACPI_HPET_ID_HARDWARE_REV_ID); printf("\tComparators=%d\n", (hpet->Id & ACPI_HPET_ID_COMPARATORS) >> 8); printf("\tCounter Size=%d\n", hpet->Id & ACPI_HPET_ID_COUNT_SIZE_CAP ? 1 : 0); printf("\tLegacy IRQ routing capable={"); if (hpet->Id & ACPI_HPET_ID_LEGACY_CAPABLE) printf("TRUE}\n"); else printf("FALSE}\n"); printf("\tPCI Vendor ID=0x%04x\n", hpet->Id >> 16); printf("\tMinimal Tick=%d\n", hpet->MinimumTick); printf(END_COMMENT); } static void acpi_handle_ecdt(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_ECDT *ecdt; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); ecdt = (ACPI_TABLE_ECDT *)sdp; printf("\tEC_CONTROL="); acpi_print_gas(&ecdt->Control); printf("\n\tEC_DATA="); acpi_print_gas(&ecdt->Data); printf("\n\tUID=%#x, ", ecdt->Uid); printf("GPE_BIT=%#x\n", ecdt->Gpe); printf("\tEC_ID=%s\n", ecdt->Id); printf(END_COMMENT); } static void acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_MCFG *mcfg; ACPI_MCFG_ALLOCATION *alloc; u_int i, entries; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); mcfg = (ACPI_TABLE_MCFG *)sdp; entries = (sdp->Length - sizeof(ACPI_TABLE_MCFG)) / sizeof(ACPI_MCFG_ALLOCATION); alloc = (ACPI_MCFG_ALLOCATION *)(mcfg + 1); for (i = 0; i < entries; i++, alloc++) { printf("\n"); - printf("\tBase Address=0x%016jx\n", alloc->Address); + printf("\tBase Address=0x%016jx\n", (uintmax_t)alloc->Address); printf("\tSegment Group=0x%04x\n", alloc->PciSegment); printf("\tStart Bus=%d\n", alloc->StartBusNumber); printf("\tEnd Bus=%d\n", alloc->EndBusNumber); } printf(END_COMMENT); } static void acpi_handle_slit(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_SLIT *slit; UINT64 i, j; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); slit = (ACPI_TABLE_SLIT *)sdp; - printf("\tLocality Count=%jd\n", slit->LocalityCount); + printf("\tLocality Count=%ju\n", (uintmax_t)slit->LocalityCount); printf("\n\t "); for (i = 0; i < slit->LocalityCount; i++) - printf(" %3jd", i); + printf(" %3ju", (uintmax_t)i); printf("\n\t +"); for (i = 0; i < slit->LocalityCount; i++) printf("----"); printf("\n"); for (i = 0; i < slit->LocalityCount; i++) { - printf("\t %3jd |", i); + printf("\t %3ju |", (uintmax_t)i); for (j = 0; j < slit->LocalityCount; j++) printf(" %3d", slit->Entry[i * slit->LocalityCount + j]); printf("\n"); } printf(END_COMMENT); } static void acpi_print_srat_cpu(uint32_t apic_id, uint32_t proximity_domain, uint32_t flags) { printf("\tFlags={"); if (flags & ACPI_SRAT_CPU_ENABLED) printf("ENABLED"); else printf("DISABLED"); printf("}\n"); printf("\tAPIC ID=%d\n", apic_id); printf("\tProximity Domain=%d\n", proximity_domain); } static char * acpi_tcpa_evname(struct TCPAevent *event) { struct TCPApc_event *pc_event; char *eventname = NULL; pc_event = (struct TCPApc_event *)(event + 1); switch(event->event_type) { case PREBOOT: case POST_CODE: case UNUSED: case NO_ACTION: case SEPARATOR: case SCRTM_CONTENTS: case SCRTM_VERSION: case CPU_MICROCODE: case PLATFORM_CONFIG_FLAGS: case TABLE_OF_DEVICES: case COMPACT_HASH: case IPL: case IPL_PARTITION_DATA: case NONHOST_CODE: case NONHOST_CONFIG: case NONHOST_INFO: asprintf(&eventname, "%s", tcpa_event_type_strings[event->event_type]); break; case ACTION: eventname = calloc(event->event_size + 1, sizeof(char)); memcpy(eventname, pc_event, event->event_size); break; case EVENT_TAG: switch (pc_event->event_id) { case SMBIOS: case BIS_CERT: case CMOS: case NVRAM: case OPTION_ROM_EXEC: case OPTION_ROM_CONFIG: case S_CRTM_VERSION: case POST_BIOS_ROM: case ESCD: case OPTION_ROM_MICROCODE: case S_CRTM_CONTENTS: case POST_CONTENTS: asprintf(&eventname, "%s", TCPA_pcclient_strings[pc_event->event_id]); break; default: asprintf(&eventname, "", pc_event->event_id); break; } break; default: asprintf(&eventname, "", event->event_type); break; } return eventname; } static void acpi_print_tcpa(struct TCPAevent *event) { int i; char *eventname; eventname = acpi_tcpa_evname(event); printf("\t%d", event->pcr_index); printf(" 0x"); for (i = 0; i < 20; i++) printf("%02x", event->pcr_value[i]); printf(" [%s]\n", eventname ? eventname : ""); free(eventname); } static void acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp) { struct TCPAbody *tcpa; struct TCPAevent *event; uintmax_t len, paddr; unsigned char *vaddr = NULL; unsigned char *vend = NULL; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); tcpa = (struct TCPAbody *) sdp; switch (tcpa->platform_class) { case ACPI_TCPA_BIOS_CLIENT: len = tcpa->client.log_max_len; paddr = tcpa->client.log_start_addr; break; case ACPI_TCPA_BIOS_SERVER: len = tcpa->server.log_max_len; paddr = tcpa->server.log_start_addr; break; default: printf("XXX"); printf(END_COMMENT); return; } printf("\tClass %u Base Address 0x%jx Length %ju\n\n", tcpa->platform_class, paddr, len); if (len == 0) { printf("\tEmpty TCPA table\n"); printf(END_COMMENT); return; } if(sdp->Revision == 1){ printf("\tOLD TCPA spec log found. Dumping not supported.\n"); printf(END_COMMENT); return; } vaddr = (unsigned char *)acpi_map_physical(paddr, len); vend = vaddr + len; while (vaddr != NULL) { if ((vaddr + sizeof(struct TCPAevent) >= vend)|| (vaddr + sizeof(struct TCPAevent) < vaddr)) break; event = (struct TCPAevent *)(void *)vaddr; if (vaddr + event->event_size >= vend) break; if (vaddr + event->event_size < vaddr) break; if (event->event_type == 0 && event->event_size == 0) break; #if 0 { unsigned int i, j, k; printf("\n\tsize %d\n\t\t%p ", event->event_size, vaddr); for (j = 0, i = 0; i < sizeof(struct TCPAevent) + event->event_size; i++) { printf("%02x ", vaddr[i]); if ((i+1) % 8 == 0) { for (k = 0; k < 8; k++) printf("%c", isprint(vaddr[j+k]) ? vaddr[j+k] : '.'); printf("\n\t\t%p ", &vaddr[i + 1]); j = i + 1; } } printf("\n"); } #endif acpi_print_tcpa(event); vaddr += sizeof(struct TCPAevent) + event->event_size; } printf(END_COMMENT); } static const char * devscope_type2str(int type) { static char typebuf[16]; switch (type) { case 1: return ("PCI Endpoint Device"); case 2: return ("PCI Sub-Hierarchy"); case 3: return ("IOAPIC"); case 4: return ("HPET"); default: snprintf(typebuf, sizeof(typebuf), "%d", type); return (typebuf); } } static int acpi_handle_dmar_devscope(void *addr, int remaining) { char sep; int pathlen; ACPI_DMAR_PCI_PATH *path, *pathend; ACPI_DMAR_DEVICE_SCOPE *devscope = addr; if (remaining < (int)sizeof(ACPI_DMAR_DEVICE_SCOPE)) return (-1); if (remaining < devscope->Length) return (-1); printf("\n"); printf("\t\tType=%s\n", devscope_type2str(devscope->EntryType)); printf("\t\tLength=%d\n", devscope->Length); printf("\t\tEnumerationId=%d\n", devscope->EnumerationId); printf("\t\tStartBusNumber=%d\n", devscope->Bus); path = (ACPI_DMAR_PCI_PATH *)(devscope + 1); pathlen = devscope->Length - sizeof(ACPI_DMAR_DEVICE_SCOPE); pathend = path + pathlen / sizeof(ACPI_DMAR_PCI_PATH); if (path < pathend) { sep = '{'; printf("\t\tPath="); do { printf("%c%d:%d", sep, path->Device, path->Function); sep=','; path++; } while (path < pathend); printf("}\n"); } return (devscope->Length); } static void acpi_handle_dmar_drhd(ACPI_DMAR_HARDWARE_UNIT *drhd) { char *cp; int remaining, consumed; printf("\n"); printf("\tType=DRHD\n"); printf("\tLength=%d\n", drhd->Header.Length); #define PRINTFLAG(var, flag) printflag((var), ACPI_DMAR_## flag, #flag) printf("\tFlags="); PRINTFLAG(drhd->Flags, INCLUDE_ALL); PRINTFLAG_END(); #undef PRINTFLAG printf("\tSegment=%d\n", drhd->Segment); - printf("\tAddress=0x%0jx\n", drhd->Address); + printf("\tAddress=0x%0jx\n", (uintmax_t)drhd->Address); remaining = drhd->Header.Length - sizeof(ACPI_DMAR_HARDWARE_UNIT); if (remaining > 0) printf("\tDevice Scope:"); while (remaining > 0) { cp = (char *)drhd + drhd->Header.Length - remaining; consumed = acpi_handle_dmar_devscope(cp, remaining); if (consumed <= 0) break; else remaining -= consumed; } } static void acpi_handle_dmar_rmrr(ACPI_DMAR_RESERVED_MEMORY *rmrr) { char *cp; int remaining, consumed; printf("\n"); printf("\tType=RMRR\n"); printf("\tLength=%d\n", rmrr->Header.Length); printf("\tSegment=%d\n", rmrr->Segment); - printf("\tBaseAddress=0x%0jx\n", rmrr->BaseAddress); - printf("\tLimitAddress=0x%0jx\n", rmrr->EndAddress); + printf("\tBaseAddress=0x%0jx\n", (uintmax_t)rmrr->BaseAddress); + printf("\tLimitAddress=0x%0jx\n", (uintmax_t)rmrr->EndAddress); remaining = rmrr->Header.Length - sizeof(ACPI_DMAR_RESERVED_MEMORY); if (remaining > 0) printf("\tDevice Scope:"); while (remaining > 0) { cp = (char *)rmrr + rmrr->Header.Length - remaining; consumed = acpi_handle_dmar_devscope(cp, remaining); if (consumed <= 0) break; else remaining -= consumed; } } static void acpi_handle_dmar_atsr(ACPI_DMAR_ATSR *atsr) { char *cp; int remaining, consumed; printf("\n"); printf("\tType=ATSR\n"); printf("\tLength=%d\n", atsr->Header.Length); #define PRINTFLAG(var, flag) printflag((var), ACPI_DMAR_## flag, #flag) printf("\tFlags="); PRINTFLAG(atsr->Flags, ALL_PORTS); PRINTFLAG_END(); #undef PRINTFLAG printf("\tSegment=%d\n", atsr->Segment); remaining = atsr->Header.Length - sizeof(ACPI_DMAR_ATSR); if (remaining > 0) printf("\tDevice Scope:"); while (remaining > 0) { cp = (char *)atsr + atsr->Header.Length - remaining; consumed = acpi_handle_dmar_devscope(cp, remaining); if (consumed <= 0) break; else remaining -= consumed; } } static void acpi_handle_dmar_rhsa(ACPI_DMAR_RHSA *rhsa) { printf("\n"); printf("\tType=RHSA\n"); printf("\tLength=%d\n", rhsa->Header.Length); - printf("\tBaseAddress=0x%0jx\n", rhsa->BaseAddress); + printf("\tBaseAddress=0x%0jx\n", (uintmax_t)rhsa->BaseAddress); printf("\tProximityDomain=0x%08x\n", rhsa->ProximityDomain); } static int acpi_handle_dmar_remapping_structure(void *addr, int remaining) { ACPI_DMAR_HEADER *hdr = addr; if (remaining < (int)sizeof(ACPI_DMAR_HEADER)) return (-1); if (remaining < hdr->Length) return (-1); switch (hdr->Type) { case ACPI_DMAR_TYPE_HARDWARE_UNIT: acpi_handle_dmar_drhd(addr); break; case ACPI_DMAR_TYPE_RESERVED_MEMORY: acpi_handle_dmar_rmrr(addr); break; case ACPI_DMAR_TYPE_ATSR: acpi_handle_dmar_atsr(addr); break; case ACPI_DMAR_HARDWARE_AFFINITY: acpi_handle_dmar_rhsa(addr); break; default: printf("\n"); printf("\tType=%d\n", hdr->Type); printf("\tLength=%d\n", hdr->Length); break; } return (hdr->Length); } #ifndef ACPI_DMAR_X2APIC_OPT_OUT #define ACPI_DMAR_X2APIC_OPT_OUT (0x2) #endif static void acpi_handle_dmar(ACPI_TABLE_HEADER *sdp) { char *cp; int remaining, consumed; ACPI_TABLE_DMAR *dmar; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); dmar = (ACPI_TABLE_DMAR *)sdp; printf("\tHost Address Width=%d\n", dmar->Width + 1); #define PRINTFLAG(var, flag) printflag((var), ACPI_DMAR_## flag, #flag) printf("\tFlags="); PRINTFLAG(dmar->Flags, INTR_REMAP); PRINTFLAG(dmar->Flags, X2APIC_OPT_OUT); PRINTFLAG_END(); #undef PRINTFLAG remaining = sdp->Length - sizeof(ACPI_TABLE_DMAR); while (remaining > 0) { cp = (char *)sdp + sdp->Length - remaining; consumed = acpi_handle_dmar_remapping_structure(cp, remaining); if (consumed <= 0) break; else remaining -= consumed; } printf(END_COMMENT); } static void acpi_print_srat_memory(ACPI_SRAT_MEM_AFFINITY *mp) { printf("\tFlags={"); if (mp->Flags & ACPI_SRAT_MEM_ENABLED) printf("ENABLED"); else printf("DISABLED"); if (mp->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) printf(",HOT_PLUGGABLE"); if (mp->Flags & ACPI_SRAT_MEM_NON_VOLATILE) printf(",NON_VOLATILE"); printf("}\n"); printf("\tBase Address=0x%016jx\n", (uintmax_t)mp->BaseAddress); printf("\tLength=0x%016jx\n", (uintmax_t)mp->Length); printf("\tProximity Domain=%d\n", mp->ProximityDomain); } static const char *srat_types[] = { "CPU", "Memory", "X2APIC" }; static void acpi_print_srat(ACPI_SUBTABLE_HEADER *srat) { ACPI_SRAT_CPU_AFFINITY *cpu; ACPI_SRAT_X2APIC_CPU_AFFINITY *x2apic; if (srat->Type < sizeof(srat_types) / sizeof(srat_types[0])) printf("\tType=%s\n", srat_types[srat->Type]); else printf("\tType=%d (unknown)\n", srat->Type); switch (srat->Type) { case ACPI_SRAT_TYPE_CPU_AFFINITY: cpu = (ACPI_SRAT_CPU_AFFINITY *)srat; acpi_print_srat_cpu(cpu->ApicId, cpu->ProximityDomainHi[2] << 24 | cpu->ProximityDomainHi[1] << 16 | cpu->ProximityDomainHi[0] << 0 | cpu->ProximityDomainLo, cpu->Flags); break; case ACPI_SRAT_TYPE_MEMORY_AFFINITY: acpi_print_srat_memory((ACPI_SRAT_MEM_AFFINITY *)srat); break; case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: x2apic = (ACPI_SRAT_X2APIC_CPU_AFFINITY *)srat; acpi_print_srat_cpu(x2apic->ApicId, x2apic->ProximityDomain, x2apic->Flags); break; } } static void acpi_handle_srat(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_SRAT *srat; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); srat = (ACPI_TABLE_SRAT *)sdp; printf("\tTable Revision=%d\n", srat->TableRevision); acpi_walk_subtables(sdp, (srat + 1), acpi_print_srat); printf(END_COMMENT); } static void acpi_print_sdt(ACPI_TABLE_HEADER *sdp) { printf(" "); acpi_print_string(sdp->Signature, ACPI_NAME_SIZE); printf(": Length=%d, Revision=%d, Checksum=%d,\n", sdp->Length, sdp->Revision, sdp->Checksum); printf("\tOEMID="); acpi_print_string(sdp->OemId, ACPI_OEM_ID_SIZE); printf(", OEM Table ID="); acpi_print_string(sdp->OemTableId, ACPI_OEM_TABLE_ID_SIZE); printf(", OEM Revision=0x%x,\n", sdp->OemRevision); printf("\tCreator ID="); acpi_print_string(sdp->AslCompilerId, ACPI_NAME_SIZE); printf(", Creator Revision=0x%x\n", sdp->AslCompilerRevision); } static void acpi_print_rsdt(ACPI_TABLE_HEADER *rsdp) { ACPI_TABLE_RSDT *rsdt; ACPI_TABLE_XSDT *xsdt; int i, entries; u_long addr; rsdt = (ACPI_TABLE_RSDT *)rsdp; xsdt = (ACPI_TABLE_XSDT *)rsdp; printf(BEGIN_COMMENT); acpi_print_sdt(rsdp); entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; printf("\tEntries={ "); for (i = 0; i < entries; i++) { if (i > 0) printf(", "); switch (addr_size) { case 4: addr = le32toh(rsdt->TableOffsetEntry[i]); break; case 8: addr = le64toh(xsdt->TableOffsetEntry[i]); break; default: addr = 0; } assert(addr != 0); printf("0x%08lx", addr); } printf(" }\n"); printf(END_COMMENT); } static const char *acpi_pm_profiles[] = { "Unspecified", "Desktop", "Mobile", "Workstation", "Enterprise Server", "SOHO Server", "Appliance PC" }; static void acpi_print_fadt(ACPI_TABLE_HEADER *sdp) { ACPI_TABLE_FADT *fadt; const char *pm; fadt = (ACPI_TABLE_FADT *)sdp; printf(BEGIN_COMMENT); acpi_print_sdt(sdp); printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->Facs, fadt->Dsdt); printf("\tINT_MODEL=%s\n", fadt->Model ? "APIC" : "PIC"); if (fadt->PreferredProfile >= sizeof(acpi_pm_profiles) / sizeof(char *)) pm = "Reserved"; else pm = acpi_pm_profiles[fadt->PreferredProfile]; printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->PreferredProfile); printf("\tSCI_INT=%d\n", fadt->SciInterrupt); printf("\tSMI_CMD=0x%x, ", fadt->SmiCommand); printf("ACPI_ENABLE=0x%x, ", fadt->AcpiEnable); printf("ACPI_DISABLE=0x%x, ", fadt->AcpiDisable); printf("S4BIOS_REQ=0x%x\n", fadt->S4BiosRequest); printf("\tPSTATE_CNT=0x%x\n", fadt->PstateControl); printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", fadt->Pm1aEventBlock, fadt->Pm1aEventBlock + fadt->Pm1EventLength - 1); if (fadt->Pm1bEventBlock != 0) printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", fadt->Pm1bEventBlock, fadt->Pm1bEventBlock + fadt->Pm1EventLength - 1); printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", fadt->Pm1aControlBlock, fadt->Pm1aControlBlock + fadt->Pm1ControlLength - 1); if (fadt->Pm1bControlBlock != 0) printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", fadt->Pm1bControlBlock, fadt->Pm1bControlBlock + fadt->Pm1ControlLength - 1); if (fadt->Pm2ControlBlock != 0) printf("\tPM2_CNT_BLK=0x%x-0x%x\n", fadt->Pm2ControlBlock, fadt->Pm2ControlBlock + fadt->Pm2ControlLength - 1); printf("\tPM_TMR_BLK=0x%x-0x%x\n", fadt->PmTimerBlock, fadt->PmTimerBlock + fadt->PmTimerLength - 1); if (fadt->Gpe0Block != 0) printf("\tGPE0_BLK=0x%x-0x%x\n", fadt->Gpe0Block, fadt->Gpe0Block + fadt->Gpe0BlockLength - 1); if (fadt->Gpe1Block != 0) printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", fadt->Gpe1Block, fadt->Gpe1Block + fadt->Gpe1BlockLength - 1, fadt->Gpe1Base); if (fadt->CstControl != 0) printf("\tCST_CNT=0x%x\n", fadt->CstControl); printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n", fadt->C2Latency, fadt->C3Latency); printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", fadt->FlushSize, fadt->FlushStride); printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", fadt->DutyOffset, fadt->DutyWidth); printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", fadt->DayAlarm, fadt->MonthAlarm, fadt->Century); #define PRINTFLAG(var, flag) printflag((var), ACPI_FADT_## flag, #flag) printf("\tIAPC_BOOT_ARCH="); PRINTFLAG(fadt->BootFlags, LEGACY_DEVICES); PRINTFLAG(fadt->BootFlags, 8042); PRINTFLAG(fadt->BootFlags, NO_VGA); PRINTFLAG(fadt->BootFlags, NO_MSI); PRINTFLAG(fadt->BootFlags, NO_ASPM); PRINTFLAG_END(); printf("\tFlags="); PRINTFLAG(fadt->Flags, WBINVD); PRINTFLAG(fadt->Flags, WBINVD_FLUSH); PRINTFLAG(fadt->Flags, C1_SUPPORTED); PRINTFLAG(fadt->Flags, C2_MP_SUPPORTED); PRINTFLAG(fadt->Flags, POWER_BUTTON); PRINTFLAG(fadt->Flags, SLEEP_BUTTON); PRINTFLAG(fadt->Flags, FIXED_RTC); PRINTFLAG(fadt->Flags, S4_RTC_WAKE); PRINTFLAG(fadt->Flags, 32BIT_TIMER); PRINTFLAG(fadt->Flags, DOCKING_SUPPORTED); PRINTFLAG(fadt->Flags, RESET_REGISTER); PRINTFLAG(fadt->Flags, SEALED_CASE); PRINTFLAG(fadt->Flags, HEADLESS); PRINTFLAG(fadt->Flags, SLEEP_TYPE); PRINTFLAG(fadt->Flags, PCI_EXPRESS_WAKE); PRINTFLAG(fadt->Flags, PLATFORM_CLOCK); PRINTFLAG(fadt->Flags, S4_RTC_VALID); PRINTFLAG(fadt->Flags, REMOTE_POWER_ON); PRINTFLAG(fadt->Flags, APIC_CLUSTER); PRINTFLAG(fadt->Flags, APIC_PHYSICAL); PRINTFLAG_END(); #undef PRINTFLAG if (fadt->Flags & ACPI_FADT_RESET_REGISTER) { printf("\tRESET_REG="); acpi_print_gas(&fadt->ResetRegister); printf(", RESET_VALUE=%#x\n", fadt->ResetValue); } if (acpi_get_fadt_revision(fadt) > 1) { printf("\tX_FACS=0x%08lx, ", (u_long)fadt->XFacs); printf("X_DSDT=0x%08lx\n", (u_long)fadt->XDsdt); printf("\tX_PM1a_EVT_BLK="); acpi_print_gas(&fadt->XPm1aEventBlock); if (fadt->XPm1bEventBlock.Address != 0) { printf("\n\tX_PM1b_EVT_BLK="); acpi_print_gas(&fadt->XPm1bEventBlock); } printf("\n\tX_PM1a_CNT_BLK="); acpi_print_gas(&fadt->XPm1aControlBlock); if (fadt->XPm1bControlBlock.Address != 0) { printf("\n\tX_PM1b_CNT_BLK="); acpi_print_gas(&fadt->XPm1bControlBlock); } if (fadt->XPm2ControlBlock.Address != 0) { printf("\n\tX_PM2_CNT_BLK="); acpi_print_gas(&fadt->XPm2ControlBlock); } printf("\n\tX_PM_TMR_BLK="); acpi_print_gas(&fadt->XPmTimerBlock); if (fadt->XGpe0Block.Address != 0) { printf("\n\tX_GPE0_BLK="); acpi_print_gas(&fadt->XGpe0Block); } if (fadt->XGpe1Block.Address != 0) { printf("\n\tX_GPE1_BLK="); acpi_print_gas(&fadt->XGpe1Block); } printf("\n"); } printf(END_COMMENT); } static void acpi_print_facs(ACPI_TABLE_FACS *facs) { printf(BEGIN_COMMENT); printf(" FACS:\tLength=%u, ", facs->Length); printf("HwSig=0x%08x, ", facs->HardwareSignature); printf("Firm_Wake_Vec=0x%08x\n", facs->FirmwareWakingVector); printf("\tGlobal_Lock="); if (facs->GlobalLock != 0) { if (facs->GlobalLock & ACPI_GLOCK_PENDING) printf("PENDING,"); if (facs->GlobalLock & ACPI_GLOCK_OWNED) printf("OWNED"); } printf("\n"); printf("\tFlags="); if (facs->Flags & ACPI_FACS_S4_BIOS_PRESENT) printf("S4BIOS"); printf("\n"); if (facs->XFirmwareWakingVector != 0) { printf("\tX_Firm_Wake_Vec=%08lx\n", (u_long)facs->XFirmwareWakingVector); } printf("\tVersion=%u\n", facs->Version); printf(END_COMMENT); } static void acpi_print_dsdt(ACPI_TABLE_HEADER *dsdp) { printf(BEGIN_COMMENT); acpi_print_sdt(dsdp); printf(END_COMMENT); } int acpi_checksum(void *p, size_t length) { uint8_t *bp; uint8_t sum; bp = p; sum = 0; while (length--) sum += *bp++; return (sum); } static ACPI_TABLE_HEADER * acpi_map_sdt(vm_offset_t pa) { ACPI_TABLE_HEADER *sp; sp = acpi_map_physical(pa, sizeof(ACPI_TABLE_HEADER)); sp = acpi_map_physical(pa, sp->Length); return (sp); } static void acpi_print_rsd_ptr(ACPI_TABLE_RSDP *rp) { printf(BEGIN_COMMENT); printf(" RSD PTR: OEM="); acpi_print_string(rp->OemId, ACPI_OEM_ID_SIZE); printf(", ACPI_Rev=%s (%d)\n", rp->Revision < 2 ? "1.0x" : "2.0x", rp->Revision); if (rp->Revision < 2) { printf("\tRSDT=0x%08x, cksum=%u\n", rp->RsdtPhysicalAddress, rp->Checksum); } else { printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n", (u_long)rp->XsdtPhysicalAddress, rp->Length, rp->ExtendedChecksum); } printf(END_COMMENT); } static void acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp) { ACPI_TABLE_HEADER *sdp; ACPI_TABLE_RSDT *rsdt; ACPI_TABLE_XSDT *xsdt; vm_offset_t addr; int entries, i; acpi_print_rsdt(rsdp); rsdt = (ACPI_TABLE_RSDT *)rsdp; xsdt = (ACPI_TABLE_XSDT *)rsdp; entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; for (i = 0; i < entries; i++) { switch (addr_size) { case 4: addr = le32toh(rsdt->TableOffsetEntry[i]); break; case 8: addr = le64toh(xsdt->TableOffsetEntry[i]); break; default: assert((addr = 0)); } sdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(addr); if (acpi_checksum(sdp, sdp->Length)) { warnx("RSDT entry %d (sig %.4s) is corrupt", i, sdp->Signature); continue; } if (!memcmp(sdp->Signature, ACPI_SIG_FADT, 4)) acpi_handle_fadt(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_MADT, 4)) acpi_handle_madt(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_HPET, 4)) acpi_handle_hpet(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_ECDT, 4)) acpi_handle_ecdt(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_MCFG, 4)) acpi_handle_mcfg(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_SLIT, 4)) acpi_handle_slit(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_SRAT, 4)) acpi_handle_srat(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_TCPA, 4)) acpi_handle_tcpa(sdp); else if (!memcmp(sdp->Signature, ACPI_SIG_DMAR, 4)) acpi_handle_dmar(sdp); else { printf(BEGIN_COMMENT); acpi_print_sdt(sdp); printf(END_COMMENT); } } } ACPI_TABLE_HEADER * sdt_load_devmem(void) { ACPI_TABLE_RSDP *rp; ACPI_TABLE_HEADER *rsdp; rp = acpi_find_rsd_ptr(); if (!rp) errx(1, "Can't find ACPI information"); if (tflag) acpi_print_rsd_ptr(rp); if (rp->Revision < 2) { rsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(rp->RsdtPhysicalAddress); if (memcmp(rsdp->Signature, "RSDT", 4) != 0 || acpi_checksum(rsdp, rsdp->Length) != 0) errx(1, "RSDT is corrupted"); addr_size = sizeof(uint32_t); } else { rsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(rp->XsdtPhysicalAddress); if (memcmp(rsdp->Signature, "XSDT", 4) != 0 || acpi_checksum(rsdp, rsdp->Length) != 0) errx(1, "XSDT is corrupted"); addr_size = sizeof(uint64_t); } return (rsdp); } /* Write the DSDT to a file, concatenating any SSDTs (if present). */ static int write_dsdt(int fd, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdt) { ACPI_TABLE_HEADER sdt; ACPI_TABLE_HEADER *ssdt; uint8_t sum; /* Create a new checksum to account for the DSDT and any SSDTs. */ sdt = *dsdt; if (rsdt != NULL) { sdt.Checksum = 0; sum = acpi_checksum(dsdt + 1, dsdt->Length - sizeof(ACPI_TABLE_HEADER)); ssdt = sdt_from_rsdt(rsdt, ACPI_SIG_SSDT, NULL); while (ssdt != NULL) { sdt.Length += ssdt->Length - sizeof(ACPI_TABLE_HEADER); sum += acpi_checksum(ssdt + 1, ssdt->Length - sizeof(ACPI_TABLE_HEADER)); ssdt = sdt_from_rsdt(rsdt, ACPI_SIG_SSDT, ssdt); } sum += acpi_checksum(&sdt, sizeof(ACPI_TABLE_HEADER)); sdt.Checksum -= sum; } /* Write out the DSDT header and body. */ write(fd, &sdt, sizeof(ACPI_TABLE_HEADER)); write(fd, dsdt + 1, dsdt->Length - sizeof(ACPI_TABLE_HEADER)); /* Write out any SSDTs (if present.) */ if (rsdt != NULL) { ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); while (ssdt != NULL) { write(fd, ssdt + 1, ssdt->Length - sizeof(ACPI_TABLE_HEADER)); ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); } } return (0); } void dsdt_save_file(char *outfile, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) { int fd; mode_t mode; assert(outfile != NULL); mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); if (fd == -1) { perror("dsdt_save_file"); return; } write_dsdt(fd, rsdt, dsdp); close(fd); } void aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) { char buf[PATH_MAX], tmpstr[PATH_MAX]; const char *tmpdir; char *tmpext; FILE *fp; size_t len; int fd; tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) tmpdir = _PATH_TMP; strncpy(tmpstr, tmpdir, sizeof(tmpstr)); if (realpath(tmpstr, buf) == NULL) { perror("realpath tmp dir"); return; } strncpy(tmpstr, buf, sizeof(tmpstr)); strncat(tmpstr, "/acpidump.", sizeof(tmpstr) - strlen(buf)); len = strlen(tmpstr); tmpext = tmpstr + len; strncpy(tmpext, "XXXXXX", sizeof(tmpstr) - len); fd = mkstemp(tmpstr); if (fd < 0) { perror("iasl tmp file"); return; } write_dsdt(fd, rsdt, dsdp); close(fd); /* Run iasl -d on the temp file */ if (fork() == 0) { close(STDOUT_FILENO); if (vflag == 0) close(STDERR_FILENO); execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL); err(1, "exec"); } wait(NULL); unlink(tmpstr); /* Dump iasl's output to stdout */ strncpy(tmpext, "dsl", sizeof(tmpstr) - len); fp = fopen(tmpstr, "r"); unlink(tmpstr); if (fp == NULL) { perror("iasl tmp file (read)"); return; } while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) fwrite(buf, 1, len, stdout); fclose(fp); } void sdt_print_all(ACPI_TABLE_HEADER *rsdp) { acpi_handle_rsdt(rsdp); } /* Fetch a table matching the given signature via the RSDT. */ ACPI_TABLE_HEADER * sdt_from_rsdt(ACPI_TABLE_HEADER *rsdp, const char *sig, ACPI_TABLE_HEADER *last) { ACPI_TABLE_HEADER *sdt; ACPI_TABLE_RSDT *rsdt; ACPI_TABLE_XSDT *xsdt; vm_offset_t addr; int entries, i; rsdt = (ACPI_TABLE_RSDT *)rsdp; xsdt = (ACPI_TABLE_XSDT *)rsdp; entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; for (i = 0; i < entries; i++) { switch (addr_size) { case 4: addr = le32toh(rsdt->TableOffsetEntry[i]); break; case 8: addr = le64toh(xsdt->TableOffsetEntry[i]); break; default: assert((addr = 0)); } sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(addr); if (last != NULL) { if (sdt == last) last = NULL; continue; } if (memcmp(sdt->Signature, sig, strlen(sig))) continue; if (acpi_checksum(sdt, sdt->Length)) errx(1, "RSDT entry %d is corrupt", i); return (sdt); } return (NULL); } ACPI_TABLE_HEADER * dsdt_from_fadt(ACPI_TABLE_FADT *fadt) { ACPI_TABLE_HEADER *sdt; /* Use the DSDT address if it is version 1, otherwise use XDSDT. */ if (acpi_get_fadt_revision(fadt) == 1) sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->Dsdt); else sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->XDsdt); if (acpi_checksum(sdt, sdt->Length)) errx(1, "DSDT is corrupt\n"); return (sdt); }