Index: head/sys/dev/acpica/acpi_acad.c =================================================================== --- head/sys/dev/acpica/acpi_acad.c (revision 131281) +++ head/sys/dev/acpica/acpi_acad.c (revision 131282) @@ -1,278 +1,282 @@ /*- * Copyright (c) 2000 Takanori Watanabe * 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 #include #include #include #include #include #include "acpi.h" #include #include +#include +#include /* Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_AC_ADAPTER ACPI_MODULE_NAME("AC_ADAPTER") /* Number of times to retry initialization before giving up. */ #define ACPI_ACAD_RETRY_MAX 6 #define ACPI_DEVICE_CHECK_PNP 0x00 #define ACPI_DEVICE_CHECK_EXISTENCE 0x01 #define ACPI_POWERSOURCE_STAT_CHANGE 0x80 struct acpi_acad_softc { int status; int initializing; }; static void acpi_acad_get_status(void *); static void acpi_acad_notify_handler(ACPI_HANDLE, UINT32, void *); static int acpi_acad_probe(device_t); static int acpi_acad_attach(device_t); static int acpi_acad_ioctl(u_long, caddr_t, void *); static int acpi_acad_sysctl(SYSCTL_HANDLER_ARGS); static void acpi_acad_init_acline(void *arg); static device_method_t acpi_acad_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_acad_probe), DEVMETHOD(device_attach, acpi_acad_attach), {0, 0} }; static driver_t acpi_acad_driver = { "acpi_acad", acpi_acad_methods, sizeof(struct acpi_acad_softc), }; static devclass_t acpi_acad_devclass; DRIVER_MODULE(acpi_acad, acpi, acpi_acad_driver, acpi_acad_devclass, 0, 0); MODULE_DEPEND(acpi_acad, acpi, 1, 1, 1); static void acpi_acad_get_status(void *context) { struct acpi_acad_softc *sc; device_t dev; ACPI_HANDLE h; int newstatus; dev = context; sc = device_get_softc(dev); h = acpi_get_handle(dev); if (ACPI_FAILURE(acpi_GetInteger(h, "_PSR", &newstatus))) { sc->status = -1; return; } if (sc->status != newstatus) { sc->status = newstatus; /* Set system power profile based on AC adapter status */ power_profile_set_state(sc->status ? POWER_PROFILE_PERFORMANCE : POWER_PROFILE_ECONOMY); ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "%s Line\n", sc->status ? "On" : "Off"); acpi_UserNotify("ACAD", h, sc->status); } } static void acpi_acad_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context) { device_t dev; dev = (device_t)context; switch (notify) { case ACPI_DEVICE_CHECK_PNP: case ACPI_DEVICE_CHECK_EXISTENCE: case ACPI_POWERSOURCE_STAT_CHANGE: /* Temporarily. It is better to notify policy manager */ AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_get_status, context); break; default: device_printf(dev, "unknown notify %#x\n", notify); break; } } static int acpi_acad_probe(device_t dev) { - if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("acad") && - acpi_MatchHid(acpi_get_handle(dev), "ACPI0003")) { - device_set_desc(dev, "AC Adapter"); - return (0); - } - return (ENXIO); + static char *acad_ids[] = { "ACPI0003", NULL }; + + if (acpi_disabled("acad") || + ACPI_ID_PROBE(device_get_parent(dev), dev, acad_ids) == NULL) + return (ENXIO); + + device_set_desc(dev, "AC Adapter"); + return (0); } static int acpi_acad_attach(device_t dev) { struct acpi_acad_softc *sc; struct acpi_softc *acpi_sc; ACPI_HANDLE handle; int error; sc = device_get_softc(dev); if (sc == NULL) return (ENXIO); handle = acpi_get_handle(dev); error = acpi_register_ioctl(ACPIIO_ACAD_GET_STATUS, acpi_acad_ioctl, dev); if (error != 0) return (error); if (device_get_unit(dev) == 0) { acpi_sc = acpi_device_get_parent_softc(dev); SYSCTL_ADD_PROC(&acpi_sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO, "acline", CTLTYPE_INT | CTLFLAG_RD, &sc->status, 0, acpi_acad_sysctl, "I", ""); } /* Get initial status after whole system is up. */ sc->status = -1; sc->initializing = 0; /* * Also install a system notify handler even though this is not * required by the specification. The Casio FIVA needs this. */ AcpiInstallNotifyHandler(handle, ACPI_SYSTEM_NOTIFY, acpi_acad_notify_handler, dev); AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY, acpi_acad_notify_handler, dev); AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_acad_init_acline, dev); return (0); } static int acpi_acad_ioctl(u_long cmd, caddr_t addr, void *arg) { struct acpi_acad_softc *sc; device_t dev; dev = (device_t)arg; sc = device_get_softc(dev); if (sc == NULL) return (ENXIO); /* * No security check required: information retrieval only. If * new functions are added here, a check might be required. */ switch (cmd) { case ACPIIO_ACAD_GET_STATUS: acpi_acad_get_status(dev); *(int *)addr = sc->status; break; default: break; } return (0); } static int acpi_acad_sysctl(SYSCTL_HANDLER_ARGS) { int val, error; if (acpi_acad_get_acline(&val) != 0) return (ENXIO); val = *(u_int *)oidp->oid_arg1; error = sysctl_handle_int(oidp, &val, 0, req); return (error); } static void acpi_acad_init_acline(void *arg) { struct acpi_acad_softc *sc; device_t dev; int retry, status; dev = (device_t)arg; sc = device_get_softc(dev); if (sc->initializing) return; sc->initializing = 1; ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "acline initialization start\n"); status = 0; for (retry = 0; retry < ACPI_ACAD_RETRY_MAX; retry++) { acpi_acad_get_status(dev); if (status != sc->status) break; AcpiOsSleep(10, 0); } sc->initializing = 0; ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "acline initialization done, tried %d times\n", retry + 1); } /* * Public interfaces. */ int acpi_acad_get_acline(int *status) { struct acpi_acad_softc *sc; device_t dev; dev = devclass_get_device(acpi_acad_devclass, 0); if (dev == NULL) return (ENXIO); sc = device_get_softc(dev); if (sc == NULL) return (ENXIO); acpi_acad_get_status(dev); *status = sc->status; return (0); } Index: head/sys/dev/acpica/acpi_button.c =================================================================== --- head/sys/dev/acpica/acpi_button.c (revision 131281) +++ head/sys/dev/acpica/acpi_button.c (revision 131282) @@ -1,279 +1,281 @@ /*- * Copyright (c) 2000 Mitsaru IWASAKI * 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 /* Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BUTTON ACPI_MODULE_NAME("BUTTON") struct acpi_button_softc { device_t button_dev; ACPI_HANDLE button_handle; boolean_t button_type; #define ACPI_POWER_BUTTON 0 #define ACPI_SLEEP_BUTTON 1 boolean_t fixed; }; #define ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP 0x80 #define ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP 0x02 static int acpi_button_probe(device_t dev); static int acpi_button_attach(device_t dev); static int acpi_button_suspend(device_t dev); static int acpi_button_resume(device_t dev); static void acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context); static ACPI_STATUS acpi_button_fixed_handler(void *context); static void acpi_button_notify_sleep(void *arg); static void acpi_button_notify_wakeup(void *arg); +static char *btn_ids[] = { + "PNP0C0C", "ACPI_FPB", "PNP0C0E", "ACPI_FSB", + NULL +}; + static device_method_t acpi_button_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_button_probe), DEVMETHOD(device_attach, acpi_button_attach), DEVMETHOD(device_suspend, acpi_button_suspend), DEVMETHOD(device_shutdown, acpi_button_suspend), DEVMETHOD(device_resume, acpi_button_resume), {0, 0} }; static driver_t acpi_button_driver = { "acpi_button", acpi_button_methods, sizeof(struct acpi_button_softc), }; static devclass_t acpi_button_devclass; DRIVER_MODULE(acpi_button, acpi, acpi_button_driver, acpi_button_devclass, 0, 0); MODULE_DEPEND(acpi_button, acpi, 1, 1, 1); static int acpi_button_probe(device_t dev) { - struct acpi_button_softc *sc; - ACPI_HANDLE h; - int ret = ENXIO; + struct acpi_button_softc *sc; + char *str; - h = acpi_get_handle(dev); + if (acpi_disabled("button") || + (str = ACPI_ID_PROBE(device_get_parent(dev), dev, btn_ids)) == NULL) + return (ENXIO); + sc = device_get_softc(dev); - if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("button")) { - if (acpi_MatchHid(h, "PNP0C0C")) { - device_set_desc(dev, "Power Button"); - sc->button_type = ACPI_POWER_BUTTON; - ret = 0; - } else if (acpi_MatchHid(h, "ACPI_FPB")) { - device_set_desc(dev, "Power Button (fixed)"); - sc->button_type = ACPI_POWER_BUTTON; - sc->fixed = 1; - ret = 0; - } else if (acpi_MatchHid(h, "PNP0C0E")) { - device_set_desc(dev, "Sleep Button"); - sc->button_type = ACPI_SLEEP_BUTTON; - ret = 0; - } else if (acpi_MatchHid(h, "ACPI_FSB")) { - device_set_desc(dev, "Sleep Button (fixed)"); - sc->button_type = ACPI_SLEEP_BUTTON; - sc->fixed = 1; - ret = 0; - } + if (strcmp(str, "PNP0C0C") == 0) { + device_set_desc(dev, "Power Button"); + sc->button_type = ACPI_POWER_BUTTON; + } else if (strcmp(str, "ACPI_FPB") == 0) { + device_set_desc(dev, "Power Button (fixed)"); + sc->button_type = ACPI_POWER_BUTTON; + sc->fixed = 1; + } else if (strcmp(str, "PNP0C0E") == 0) { + device_set_desc(dev, "Sleep Button"); + sc->button_type = ACPI_SLEEP_BUTTON; + } else if (strcmp(str, "ACPI_FSB") == 0) { + device_set_desc(dev, "Sleep Button (fixed)"); + sc->button_type = ACPI_SLEEP_BUTTON; + sc->fixed = 1; } - return (ret); + + return (0); } static int acpi_button_attach(device_t dev) { struct acpi_button_softc *sc; ACPI_STATUS status; int event; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = device_get_softc(dev); sc->button_dev = dev; sc->button_handle = acpi_get_handle(dev); event = (sc->button_type == ACPI_SLEEP_BUTTON) ? ACPI_EVENT_SLEEP_BUTTON : ACPI_EVENT_POWER_BUTTON; /* * Install the new handler. We could remove any fixed handlers added * from the FADT once we have a duplicate from the AML but some systems * only return events on one or the other so we have to keep both. */ if (sc->fixed) { AcpiClearEvent(event); status = AcpiInstallFixedEventHandler(event, acpi_button_fixed_handler, sc); } else { /* * If a system does not get lid events, it may make sense to change * the type to ACPI_ALL_NOTIFY. Some systems generate both a wake * and runtime notify in that case though. */ status = AcpiInstallNotifyHandler(sc->button_handle, ACPI_DEVICE_NOTIFY, acpi_button_notify_handler, sc); } if (ACPI_FAILURE(status)) { device_printf(sc->button_dev, "couldn't install notify handler - %s\n", AcpiFormatException(status)); return_VALUE (ENXIO); } /* Enable the GPE for wake/runtime. */ acpi_wake_init(dev, ACPI_GPE_TYPE_WAKE_RUN); acpi_wake_set_enable(dev, 1); return_VALUE (0); } static int acpi_button_suspend(device_t dev) { struct acpi_softc *acpi_sc; acpi_sc = acpi_device_get_parent_softc(dev); acpi_wake_sleep_prep(dev, acpi_sc->acpi_sstate); return (0); } static int acpi_button_resume(device_t dev) { acpi_wake_run_prep(dev); return (0); } static void acpi_button_notify_sleep(void *arg) { struct acpi_button_softc *sc; struct acpi_softc *acpi_sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = (struct acpi_button_softc *)arg; acpi_sc = acpi_device_get_parent_softc(sc->button_dev); if (acpi_sc == NULL) return_VOID; acpi_UserNotify("Button", sc->button_handle, sc->button_type); switch (sc->button_type) { case ACPI_POWER_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "power button pressed\n"); acpi_event_power_button_sleep(acpi_sc); break; case ACPI_SLEEP_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "sleep button pressed\n"); acpi_event_sleep_button_sleep(acpi_sc); break; default: break; /* unknown button type */ } } static void acpi_button_notify_wakeup(void *arg) { struct acpi_button_softc *sc; struct acpi_softc *acpi_sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = (struct acpi_button_softc *)arg; acpi_sc = acpi_device_get_parent_softc(sc->button_dev); if (acpi_sc == NULL) return_VOID; acpi_UserNotify("Button", sc->button_handle, sc->button_type); switch (sc->button_type) { case ACPI_POWER_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "wakeup by power button\n"); acpi_event_power_button_wake(acpi_sc); break; case ACPI_SLEEP_BUTTON: ACPI_VPRINT(sc->button_dev, acpi_sc, "wakeup by sleep button\n"); acpi_event_sleep_button_wake(acpi_sc); break; default: break; /* unknown button type */ } } static void acpi_button_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context) { struct acpi_button_softc *sc; ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify); sc = (struct acpi_button_softc *)context; switch (notify) { case ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP: AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_button_notify_sleep, sc); break; case ACPI_NOTIFY_BUTTON_PRESSED_FOR_WAKEUP: AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_button_notify_wakeup, sc); break; default: device_printf(sc->button_dev, "unknown notify %#x\n", notify); break; } } static ACPI_STATUS acpi_button_fixed_handler(void *context) { struct acpi_button_softc *sc = (struct acpi_button_softc *)context; ACPI_FUNCTION_TRACE_PTR((char *)(uintptr_t)__func__, context); if (context == NULL) return_ACPI_STATUS (AE_BAD_PARAMETER); acpi_button_notify_handler(sc->button_handle, ACPI_NOTIFY_BUTTON_PRESSED_FOR_SLEEP, sc); return_ACPI_STATUS (AE_OK); } Index: head/sys/dev/acpica/acpi_cmbat.c =================================================================== --- head/sys/dev/acpica/acpi_cmbat.c (revision 131281) +++ head/sys/dev/acpica/acpi_cmbat.c (revision 131282) @@ -1,663 +1,664 @@ /*- * Copyright (c) 2000 Munehiro Matsuda * Copyright (c) 2000 Takanori Watanabe * 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 "opt_acpi.h" #include #include #include #include #include #include #include #include #include "acpi.h" #include #include MALLOC_DEFINE(M_ACPICMBAT, "acpicmbat", "ACPI control method battery data"); /* Number of times to retry initialization before giving up. */ #define ACPI_CMBAT_RETRY_MAX 6 /* Check the battery once a minute. */ #define CMBAT_POLLRATE (60 * hz) /* Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BATTERY ACPI_MODULE_NAME("BATTERY") #define ACPI_BATTERY_BST_CHANGE 0x80 #define ACPI_BATTERY_BIF_CHANGE 0x81 struct acpi_cmbat_softc { device_t dev; struct acpi_bif bif; struct acpi_bst bst; struct timespec bif_lastupdated; struct timespec bst_lastupdated; int bif_updating; int bst_updating; int present; int cap; int min; int full_charge_time; int initializing; }; static struct timespec acpi_cmbat_info_lastupdated; /* XXX: devclass_get_maxunit() don't give us the current allocated units. */ static int acpi_cmbat_units = 0; static int acpi_cmbat_info_expired(struct timespec *); static void acpi_cmbat_info_updated(struct timespec *); static void acpi_cmbat_get_bst(void *); static void acpi_cmbat_get_bif(void *); static void acpi_cmbat_notify_handler(ACPI_HANDLE, UINT32, void *); static int acpi_cmbat_probe(device_t); static int acpi_cmbat_attach(device_t); static int acpi_cmbat_resume(device_t); static int acpi_cmbat_ioctl(u_long, caddr_t, void *); static int acpi_cmbat_is_bst_valid(struct acpi_bst*); static int acpi_cmbat_is_bif_valid(struct acpi_bif*); static int acpi_cmbat_get_total_battinfo(struct acpi_battinfo *); static void acpi_cmbat_init_battery(void *); static device_method_t acpi_cmbat_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_cmbat_probe), DEVMETHOD(device_attach, acpi_cmbat_attach), DEVMETHOD(device_resume, acpi_cmbat_resume), {0, 0} }; static driver_t acpi_cmbat_driver = { "acpi_cmbat", acpi_cmbat_methods, sizeof(struct acpi_cmbat_softc), }; static devclass_t acpi_cmbat_devclass; DRIVER_MODULE(acpi_cmbat, acpi, acpi_cmbat_driver, acpi_cmbat_devclass, 0, 0); MODULE_DEPEND(acpi_cmbat, acpi, 1, 1, 1); static int acpi_cmbat_info_expired(struct timespec *lastupdated) { struct timespec curtime; if (lastupdated == NULL) return (1); if (!timespecisset(lastupdated)) return (1); getnanotime(&curtime); timespecsub(&curtime, lastupdated); return (curtime.tv_sec < 0 || curtime.tv_sec > acpi_battery_get_info_expire()); } static void acpi_cmbat_info_updated(struct timespec *lastupdated) { if (lastupdated != NULL) getnanotime(lastupdated); } static void acpi_cmbat_get_bst(void *context) { device_t dev; struct acpi_cmbat_softc *sc; ACPI_STATUS as; ACPI_OBJECT *res; ACPI_HANDLE h; ACPI_BUFFER bst_buffer; dev = context; sc = device_get_softc(dev); h = acpi_get_handle(dev); if (!acpi_cmbat_info_expired(&sc->bst_lastupdated)) return; if (sc->bst_updating) return; sc->bst_updating = 1; bst_buffer.Pointer = NULL; bst_buffer.Length = ACPI_ALLOCATE_BUFFER; as = AcpiEvaluateObject(h, "_BST", NULL, &bst_buffer); if (ACPI_FAILURE(as)) { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "error fetching current battery status -- %s\n", AcpiFormatException(as)); goto end; } res = (ACPI_OBJECT *)bst_buffer.Pointer; if (!ACPI_PKG_VALID(res, 4)) { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery status corrupted\n"); goto end; } if (acpi_PkgInt32(res, 0, &sc->bst.state) != 0) goto end; if (acpi_PkgInt32(res, 1, &sc->bst.rate) != 0) goto end; if (acpi_PkgInt32(res, 2, &sc->bst.cap) != 0) goto end; if (acpi_PkgInt32(res, 3, &sc->bst.volt) != 0) goto end; acpi_cmbat_info_updated(&sc->bst_lastupdated); end: if (bst_buffer.Pointer != NULL) AcpiOsFree(bst_buffer.Pointer); sc->bst_updating = 0; } static void acpi_cmbat_get_bif(void *context) { device_t dev; struct acpi_cmbat_softc *sc; ACPI_STATUS as; ACPI_OBJECT *res; ACPI_HANDLE h; ACPI_BUFFER bif_buffer; dev = context; sc = device_get_softc(dev); h = acpi_get_handle(dev); if (!acpi_cmbat_info_expired(&sc->bif_lastupdated)) return; if (sc->bif_updating) return; sc->bif_updating = 1; bif_buffer.Pointer = NULL; bif_buffer.Length = ACPI_ALLOCATE_BUFFER; as = AcpiEvaluateObject(h, "_BIF", NULL, &bif_buffer); if (ACPI_FAILURE(as)) { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "error fetching current battery info -- %s\n", AcpiFormatException(as)); goto end; } res = (ACPI_OBJECT *)bif_buffer.Pointer; if (!ACPI_PKG_VALID(res, 13)) { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery info corrupted\n"); goto end; } if (acpi_PkgInt32(res, 0, &sc->bif.units) != 0) goto end; if (acpi_PkgInt32(res, 1, &sc->bif.dcap) != 0) goto end; if (acpi_PkgInt32(res, 2, &sc->bif.lfcap) != 0) goto end; if (acpi_PkgInt32(res, 3, &sc->bif.btech) != 0) goto end; if (acpi_PkgInt32(res, 4, &sc->bif.dvol) != 0) goto end; if (acpi_PkgInt32(res, 5, &sc->bif.wcap) != 0) goto end; if (acpi_PkgInt32(res, 6, &sc->bif.lcap) != 0) goto end; if (acpi_PkgInt32(res, 7, &sc->bif.gra1) != 0) goto end; if (acpi_PkgInt32(res, 8, &sc->bif.gra2) != 0) goto end; if (acpi_PkgStr(res, 9, sc->bif.model, ACPI_CMBAT_MAXSTRLEN) != 0) goto end; if (acpi_PkgStr(res, 10, sc->bif.serial, ACPI_CMBAT_MAXSTRLEN) != 0) goto end; if (acpi_PkgStr(res, 11, sc->bif.type, ACPI_CMBAT_MAXSTRLEN) != 0) goto end; if (acpi_PkgStr(res, 12, sc->bif.oeminfo, ACPI_CMBAT_MAXSTRLEN) != 0) goto end; acpi_cmbat_info_updated(&sc->bif_lastupdated); end: if (bif_buffer.Pointer != NULL) AcpiOsFree(bif_buffer.Pointer); sc->bif_updating = 0; } static void acpi_cmbat_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context) { device_t dev; struct acpi_cmbat_softc *sc; dev = (device_t)context; if ((sc = device_get_softc(dev)) == NULL) return; acpi_UserNotify("CMBAT", h, notify); switch (notify) { case ACPI_NOTIFY_DEVICE_CHECK: case ACPI_BATTERY_BST_CHANGE: timespecclear(&sc->bst_lastupdated); break; case ACPI_NOTIFY_BUS_CHECK: case ACPI_BATTERY_BIF_CHANGE: timespecclear(&sc->bif_lastupdated); AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_get_bif, dev); break; default: break; } } static int acpi_cmbat_probe(device_t dev) { - if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("cmbat") - && acpi_MatchHid(acpi_get_handle(dev), "PNP0C0A")) { + static char *cmbat_ids[] = { "PNP0C0A", NULL }; - device_set_desc(dev, "Control Method Battery"); - return (0); - } - return (ENXIO); + if (acpi_disabled("cmbat") || + ACPI_ID_PROBE(device_get_parent(dev), dev, cmbat_ids) == NULL) + return (ENXIO); + + device_set_desc(dev, "Control Method Battery"); + return (0); } static int acpi_cmbat_attach(device_t dev) { int error; ACPI_HANDLE handle; struct acpi_cmbat_softc *sc; if ((sc = device_get_softc(dev)) == NULL) return (ENXIO); handle = acpi_get_handle(dev); /* * Install a system notify handler in addition to the device notify. * Toshiba notebook uses this alternate notify for its battery. */ AcpiInstallNotifyHandler(handle, ACPI_SYSTEM_NOTIFY, acpi_cmbat_notify_handler, dev); AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY, acpi_cmbat_notify_handler, dev); sc->bif_updating = sc->bst_updating = 0; sc->dev = dev; timespecclear(&sc->bif_lastupdated); timespecclear(&sc->bst_lastupdated); if (acpi_cmbat_units == 0) { error = acpi_register_ioctl(ACPIIO_CMBAT_GET_BIF, acpi_cmbat_ioctl, NULL); if (error != 0) return (error); error = acpi_register_ioctl(ACPIIO_CMBAT_GET_BST, acpi_cmbat_ioctl, NULL); if (error != 0) return (error); } error = acpi_battery_register(ACPI_BATT_TYPE_CMBAT, acpi_cmbat_units); if (error != 0) return (error); acpi_cmbat_units++; timespecclear(&acpi_cmbat_info_lastupdated); sc->initializing = 0; AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_init_battery, dev); return (0); } static int acpi_cmbat_resume(device_t dev) { AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_cmbat_init_battery, dev); return (0); } static int acpi_cmbat_ioctl(u_long cmd, caddr_t addr, void *arg) { device_t dev; union acpi_battery_ioctl_arg *ioctl_arg; struct acpi_cmbat_softc *sc; struct acpi_bif *bifp; struct acpi_bst *bstp; ioctl_arg = (union acpi_battery_ioctl_arg *)addr; dev = devclass_get_device(acpi_cmbat_devclass, ioctl_arg->unit); if (dev == NULL) return (ENXIO); sc = device_get_softc(dev); if (sc == NULL) return (ENXIO); /* * No security check required: information retrieval only. If * new functions are added here, a check might be required. */ switch (cmd) { case ACPIIO_CMBAT_GET_BIF: acpi_cmbat_get_bif(dev); bifp = &ioctl_arg->bif; bifp->units = sc->bif.units; bifp->dcap = sc->bif.dcap; bifp->lfcap = sc->bif.lfcap; bifp->btech = sc->bif.btech; bifp->dvol = sc->bif.dvol; bifp->wcap = sc->bif.wcap; bifp->lcap = sc->bif.lcap; bifp->gra1 = sc->bif.gra1; bifp->gra2 = sc->bif.gra2; strncpy(bifp->model, sc->bif.model, sizeof(sc->bif.model)); strncpy(bifp->serial, sc->bif.serial, sizeof(sc->bif.serial)); strncpy(bifp->type, sc->bif.type, sizeof(sc->bif.type)); strncpy(bifp->oeminfo, sc->bif.oeminfo, sizeof(sc->bif.oeminfo)); break; case ACPIIO_CMBAT_GET_BST: bstp = &ioctl_arg->bst; if (acpi_BatteryIsPresent(dev)) { acpi_cmbat_get_bst(dev); bstp->state = sc->bst.state; bstp->rate = sc->bst.rate; bstp->cap = sc->bst.cap; bstp->volt = sc->bst.volt; } else { bstp->state = ACPI_BATT_STAT_NOT_PRESENT; } break; default: break; } return (0); } static int acpi_cmbat_is_bst_valid(struct acpi_bst *bst) { if (bst->state >= ACPI_BATT_STAT_MAX || bst->cap == 0xffffffff || bst->volt == 0xffffffff) return (0); else return (1); } static int acpi_cmbat_is_bif_valid(struct acpi_bif *bif) { if (bif->lfcap == 0) return (0); else return (1); } static int acpi_cmbat_get_total_battinfo(struct acpi_battinfo *battinfo) { int i; int error; int batt_stat; int valid_rate, valid_units; int cap, min; int total_cap, total_min, total_full; device_t dev; struct acpi_cmbat_softc *sc; static int bat_units = 0; static struct acpi_cmbat_softc **bat = NULL; cap = min = -1; batt_stat = ACPI_BATT_STAT_NOT_PRESENT; error = 0; /* Allocate array of softc pointers */ if (bat_units != acpi_cmbat_units) { if (bat != NULL) { free(bat, M_ACPICMBAT); bat = NULL; } bat_units = 0; } if (bat == NULL) { bat_units = acpi_cmbat_units; bat = malloc(sizeof(struct acpi_cmbat_softc *) * bat_units, M_ACPICMBAT, M_NOWAIT); if (bat == NULL) { error = ENOMEM; goto out; } /* Collect softc pointers */ for (i = 0; i < acpi_cmbat_units; i++) { if ((dev = devclass_get_device(acpi_cmbat_devclass, i)) == NULL) { error = ENXIO; goto out; } if ((sc = device_get_softc(dev)) == NULL) { error = ENXIO; goto out; } bat[i] = sc; } } /* Get battery status, valid rate and valid units */ batt_stat = valid_rate = valid_units = 0; for (i = 0; i < acpi_cmbat_units; i++) { bat[i]->present = acpi_BatteryIsPresent(bat[i]->dev); if (!bat[i]->present) continue; acpi_cmbat_get_bst(bat[i]->dev); /* If battery not installed, we get strange values */ if (!acpi_cmbat_is_bst_valid(&(bat[i]->bst)) || !acpi_cmbat_is_bif_valid(&(bat[i]->bif))) { bat[i]->present = 0; continue; } valid_units++; bat[i]->cap = 100 * bat[i]->bst.cap / bat[i]->bif.lfcap; batt_stat |= bat[i]->bst.state; if (bat[i]->bst.rate > 0) { /* * XXX Hack to calculate total battery time. * Systems with 2 or more battries, they may get used * one by one, thus bst.rate is set only to the one * in use. For remaining batteries bst.rate = 0, which * makes it impossible to calculate remaining time. * Some other systems may need sum of bst.rate in * dis-charging state. * There for we sum up the bst.rate that is valid * (in dis-charging state), and use the sum to * calcutate remaining batteries' time. */ if (bat[i]->bst.state & ACPI_BATT_STAT_DISCHARG) valid_rate += bat[i]->bst.rate; } } /* Calculate total battery capacity and time */ total_cap = total_min = total_full = 0; for (i = 0; i < acpi_cmbat_units; i++) { if (!bat[i]->present) continue; if (valid_rate > 0) { /* Use the sum of bst.rate */ bat[i]->min = 60 * bat[i]->bst.cap / valid_rate; } else if (bat[i]->full_charge_time > 0) { bat[i]->min = (bat[i]->full_charge_time * bat[i]->cap) / 100; } else { /* Couldn't find valid rate and full battery time */ bat[i]->min = 0; } total_min += bat[i]->min; total_cap += bat[i]->cap; total_full += bat[i]->full_charge_time; } /* Battery life */ if (valid_units == 0) { cap = -1; batt_stat = ACPI_BATT_STAT_NOT_PRESENT; } else { cap = total_cap / valid_units; } /* Battery time */ if (valid_units == 0) { min = -1; } else if (valid_rate == 0 || (batt_stat & ACPI_BATT_STAT_CHARGING)) { if (total_full == 0) min = -1; else min = (total_full * cap) / 100; } else { min = total_min; } acpi_cmbat_info_updated(&acpi_cmbat_info_lastupdated); out: battinfo->cap = cap; battinfo->min = min; battinfo->state = batt_stat; return (error); } static void acpi_cmbat_init_battery(void *arg) { int retry; device_t dev = (device_t)arg; struct acpi_cmbat_softc *sc = device_get_softc(dev); if (sc->initializing) return; sc->initializing = 1; ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization start\n"); for (retry = 0; retry < ACPI_CMBAT_RETRY_MAX; retry++, AcpiOsSleep(10, 0)) { sc->present = acpi_BatteryIsPresent(dev); if (!sc->present) continue; timespecclear(&sc->bst_lastupdated); timespecclear(&sc->bif_lastupdated); acpi_cmbat_get_bst(dev); if (!acpi_cmbat_is_bst_valid(&sc->bst)) continue; acpi_cmbat_get_bif(dev); if (!acpi_cmbat_is_bif_valid(&sc->bif)) continue; break; } sc->initializing = 0; if (retry == ACPI_CMBAT_RETRY_MAX) { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization failed, giving up\n"); } else { ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev), "battery initialization done, tried %d times\n", retry + 1); } } /* * Public interfaces. */ int acpi_cmbat_get_battinfo(int unit, struct acpi_battinfo *battinfo) { int error; device_t dev; struct acpi_cmbat_softc *sc; if (unit == -1) return (acpi_cmbat_get_total_battinfo(battinfo)); if (acpi_cmbat_info_expired(&acpi_cmbat_info_lastupdated)) { error = acpi_cmbat_get_total_battinfo(battinfo); if (error) goto out; } error = 0; if (unit >= acpi_cmbat_units) { error = ENXIO; goto out; } if ((dev = devclass_get_device(acpi_cmbat_devclass, unit)) == NULL) { error = ENXIO; goto out; } if ((sc = device_get_softc(dev)) == NULL) { error = ENXIO; goto out; } if (!sc->present) { battinfo->cap = -1; battinfo->min = -1; battinfo->state = ACPI_BATT_STAT_NOT_PRESENT; } else { battinfo->cap = sc->cap; battinfo->min = sc->min; battinfo->state = sc->bst.state; } out: return (error); } Index: head/sys/dev/acpica/acpi_ec.c =================================================================== --- head/sys/dev/acpica/acpi_ec.c (revision 131281) +++ head/sys/dev/acpica/acpi_ec.c (revision 131282) @@ -1,1002 +1,1004 @@ /*- * Copyright (c) 2003 Nate Lawson * 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$ */ /****************************************************************************** * * 1. Copyright Notice * * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights * reserved. * * 2. License * * 2.1. This is your license from Intel Corp. under its intellectual property * rights. You may have additional license terms from the party that provided * you this software, covering your right to use that party's intellectual * property rights. * * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a * copy of the source code appearing in this file ("Covered Code") an * irrevocable, perpetual, worldwide license under Intel's copyrights in the * base code distributed originally by Intel ("Original Intel Code") to copy, * make derivatives, distribute, use and display any portion of the Covered * Code in any form, with the right to sublicense such rights; and * * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent * license (with the right to sublicense), under only those claims of Intel * patents that are infringed by the Original Intel Code, to make, use, sell, * offer to sell, and import the Covered Code and derivative works thereof * solely to the minimum extent necessary to exercise the above copyright * license, and in no event shall the patent license extend to any additions * to or modifications of the Original Intel Code. No other license or right * is granted directly or by implication, estoppel or otherwise; * * The above copyright and patent license is granted only if the following * conditions are met: * * 3. Conditions * * 3.1. Redistribution of Source with Rights to Further Distribute Source. * Redistribution of source code of any substantial portion of the Covered * Code or modification with rights to further distribute source must include * the above Copyright Notice, the above License, this list of Conditions, * and the following Disclaimer and Export Compliance provision. In addition, * Licensee must cause all Covered Code to which Licensee contributes to * contain a file documenting the changes Licensee made to create that Covered * Code and the date of any change. Licensee must include in that file the * documentation of any changes made by any predecessor Licensee. Licensee * must include a prominent statement that the modification is derived, * directly or indirectly, from Original Intel Code. * * 3.2. Redistribution of Source with no Rights to Further Distribute Source. * Redistribution of source code of any substantial portion of the Covered * Code or modification without rights to further distribute source must * include the following Disclaimer and Export Compliance provision in the * documentation and/or other materials provided with distribution. In * addition, Licensee may not authorize further sublicense of source of any * portion of the Covered Code, and must include terms to the effect that the * license from Licensee to its licensee is limited to the intellectual * property embodied in the software Licensee provides to its licensee, and * not to intellectual property embodied in modifications its licensee may * make. * * 3.3. Redistribution of Executable. Redistribution in executable form of any * substantial portion of the Covered Code or modification must reproduce the * above Copyright Notice, and the following Disclaimer and Export Compliance * provision in the documentation and/or other materials provided with the * distribution. * * 3.4. Intel retains all right, title, and interest in and to the Original * Intel Code. * * 3.5. Neither the name Intel nor any other trademark owned or controlled by * Intel shall be used in advertising or otherwise to promote the sale, use or * other dealings in products derived from or relating to the Covered Code * without prior written authorization from Intel. * * 4. Disclaimer and Export Compliance * * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A * PARTICULAR PURPOSE. * * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY * LIMITED REMEDY. * * 4.3. Licensee shall not export, either directly or indirectly, any of this * software or system incorporating such software without first obtaining any * required license or other approval from the U. S. Department of Commerce or * any other agency or department of the United States Government. In the * event Licensee exports any such software from the United States or * re-exports any such software from a foreign destination, Licensee shall * ensure that the distribution and export/re-export of the software is in * compliance with all laws, regulations, orders, or other restrictions of the * U.S. Export Administration Regulations. Licensee agrees that neither it nor * any of its subsidiaries will export/re-export any technical data, process, * software, or service, directly or indirectly, to any country for which the * United States government or any agency thereof requires an export license, * other governmental approval, or letter of assurance, without first obtaining * such license, approval or letter. * *****************************************************************************/ #include __FBSDID("$FreeBSD$"); #include "opt_acpi.h" #include #include #include #include #include #include #include #include #include "acpi.h" #include /* * Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_EC ACPI_MODULE_NAME("EC") /* * EC_COMMAND: * ----------- */ typedef UINT8 EC_COMMAND; #define EC_COMMAND_UNKNOWN ((EC_COMMAND) 0x00) #define EC_COMMAND_READ ((EC_COMMAND) 0x80) #define EC_COMMAND_WRITE ((EC_COMMAND) 0x81) #define EC_COMMAND_BURST_ENABLE ((EC_COMMAND) 0x82) #define EC_COMMAND_BURST_DISABLE ((EC_COMMAND) 0x83) #define EC_COMMAND_QUERY ((EC_COMMAND) 0x84) /* * EC_STATUS: * ---------- * The encoding of the EC status register is illustrated below. * Note that a set bit (1) indicates the property is TRUE * (e.g. if bit 0 is set then the output buffer is full). * +-+-+-+-+-+-+-+-+ * |7|6|5|4|3|2|1|0| * +-+-+-+-+-+-+-+-+ * | | | | | | | | * | | | | | | | +- Output Buffer Full? * | | | | | | +--- Input Buffer Full? * | | | | | +----- * | | | | +------- Data Register is Command Byte? * | | | +--------- Burst Mode Enabled? * | | +----------- SCI Event? * | +------------- SMI Event? * +--------------- * */ typedef UINT8 EC_STATUS; #define EC_FLAG_OUTPUT_BUFFER ((EC_STATUS) 0x01) #define EC_FLAG_INPUT_BUFFER ((EC_STATUS) 0x02) #define EC_FLAG_BURST_MODE ((EC_STATUS) 0x10) #define EC_FLAG_SCI ((EC_STATUS) 0x20) /* * EC_EVENT: * --------- */ typedef UINT8 EC_EVENT; #define EC_EVENT_UNKNOWN ((EC_EVENT) 0x00) #define EC_EVENT_OUTPUT_BUFFER_FULL ((EC_EVENT) 0x01) #define EC_EVENT_INPUT_BUFFER_EMPTY ((EC_EVENT) 0x02) #define EC_EVENT_SCI ((EC_EVENT) 0x20) /* * Register access primitives */ #define EC_GET_DATA(sc) \ bus_space_read_1((sc)->ec_data_tag, (sc)->ec_data_handle, 0) #define EC_SET_DATA(sc, v) \ bus_space_write_1((sc)->ec_data_tag, (sc)->ec_data_handle, 0, (v)) #define EC_GET_CSR(sc) \ bus_space_read_1((sc)->ec_csr_tag, (sc)->ec_csr_handle, 0) #define EC_SET_CSR(sc, v) \ bus_space_write_1((sc)->ec_csr_tag, (sc)->ec_csr_handle, 0, (v)) /* Embedded Controller Boot Resources Table (ECDT) */ typedef struct { ACPI_TABLE_HEADER header; ACPI_GENERIC_ADDRESS control; ACPI_GENERIC_ADDRESS data; UINT32 uid; UINT8 gpe_bit; char ec_id[0]; } ACPI_TABLE_ECDT; /* Additional params to pass from the probe routine */ struct acpi_ec_params { int glk; int gpe_bit; ACPI_HANDLE gpe_handle; int uid; }; /* Indicate that this device has already been probed via ECDT. */ #define DEV_ECDT(x) (acpi_get_magic(x) == (int)&acpi_ec_devclass) /* * Driver softc. */ struct acpi_ec_softc { device_t ec_dev; ACPI_HANDLE ec_handle; int ec_uid; ACPI_HANDLE ec_gpehandle; UINT8 ec_gpebit; UINT8 ec_csrvalue; int ec_data_rid; struct resource *ec_data_res; bus_space_tag_t ec_data_tag; bus_space_handle_t ec_data_handle; int ec_csr_rid; struct resource *ec_csr_res; bus_space_tag_t ec_csr_tag; bus_space_handle_t ec_csr_handle; int ec_glk; int ec_glkhandle; struct mtx ec_mtx; int ec_polldelay; }; /* * XXX * I couldn't find it in the spec but other implementations also use a * value of 1 ms for the time to acquire global lock. */ #define EC_LOCK_TIMEOUT 1000 /* * Start with an interval of 1 us for status poll loop. This delay * will be dynamically adjusted based on the actual time waited. */ #define EC_POLL_DELAY 1 /* Total time in ms spent in the poll loop waiting for a response. */ #define EC_POLL_TIMEOUT 100 #define EVENT_READY(event, status) \ (((event) == EC_EVENT_OUTPUT_BUFFER_FULL && \ ((status) & EC_FLAG_OUTPUT_BUFFER) != 0) || \ ((event) == EC_EVENT_INPUT_BUFFER_EMPTY && \ ((status) & EC_FLAG_INPUT_BUFFER) == 0)) static int ec_poll_timeout = EC_POLL_TIMEOUT; TUNABLE_INT("hw.acpi.ec.poll_timeout", &ec_poll_timeout); static __inline ACPI_STATUS EcLock(struct acpi_ec_softc *sc) { ACPI_STATUS status = AE_OK; /* Always acquire this EC's mutex. */ mtx_lock(&sc->ec_mtx); /* If _GLK is non-zero, also acquire the global lock. */ if (sc->ec_glk) { status = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT, &sc->ec_glkhandle); if (ACPI_FAILURE(status)) mtx_unlock(&sc->ec_mtx); } return (status); } static __inline void EcUnlock(struct acpi_ec_softc *sc) { if (sc->ec_glk) AcpiReleaseGlobalLock(sc->ec_glkhandle); mtx_unlock(&sc->ec_mtx); } static uint32_t EcGpeHandler(void *Context); static ACPI_STATUS EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function, void *Context, void **return_Context); static ACPI_STATUS EcSpaceHandler(UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 width, ACPI_INTEGER *Value, void *Context, void *RegionContext); static ACPI_STATUS EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event); static ACPI_STATUS EcCommand(struct acpi_ec_softc *sc, EC_COMMAND cmd); static ACPI_STATUS EcRead(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data); static ACPI_STATUS EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data); static int acpi_ec_probe(device_t dev); static int acpi_ec_attach(device_t dev); static device_method_t acpi_ec_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_ec_probe), DEVMETHOD(device_attach, acpi_ec_attach), {0, 0} }; static driver_t acpi_ec_driver = { "acpi_ec", acpi_ec_methods, sizeof(struct acpi_ec_softc), }; static devclass_t acpi_ec_devclass; DRIVER_MODULE(acpi_ec, acpi, acpi_ec_driver, acpi_ec_devclass, 0, 0); MODULE_DEPEND(acpi_ec, acpi, 1, 1, 1); /* * Look for an ECDT and if we find one, set up default GPE and * space handlers to catch attempts to access EC space before * we have a real driver instance in place. * TODO: if people report invalid ECDTs, add a tunable to disable them. */ void acpi_ec_ecdt_probe(device_t parent) { ACPI_TABLE_ECDT *ecdt; ACPI_STATUS status; device_t child; ACPI_HANDLE h; struct acpi_ec_params *params; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); /* Find and validate the ECDT. */ status = AcpiGetFirmwareTable("ECDT", 1, ACPI_LOGICAL_ADDRESSING, (ACPI_TABLE_HEADER **)&ecdt); if (ACPI_FAILURE(status) || ecdt->control.RegisterBitWidth != 8 || ecdt->data.RegisterBitWidth != 8) { return; } /* Create the child device with the given unit number. */ child = BUS_ADD_CHILD(parent, 0, "acpi_ec", ecdt->uid); if (child == NULL) { printf("%s: can't add child\n", __func__); return; } /* Find and save the ACPI handle for this device. */ status = AcpiGetHandle(NULL, ecdt->ec_id, &h); if (ACPI_FAILURE(status)) { device_delete_child(parent, child); printf("%s: can't get handle\n", __func__); return; } acpi_set_handle(child, h); /* Set the data and CSR register addresses. */ bus_set_resource(child, SYS_RES_IOPORT, 0, ecdt->data.Address, /*count*/1); bus_set_resource(child, SYS_RES_IOPORT, 1, ecdt->control.Address, /*count*/1); /* * Store values for the probe/attach routines to use. Store the * ECDT GPE bit and set the global lock flag according to _GLK. * Note that it is not perfectly correct to be evaluating a method * before initializing devices, but in practice this function * should be safe to call at this point. */ params = malloc(sizeof(struct acpi_ec_params), M_TEMP, M_WAITOK | M_ZERO); params->gpe_handle = NULL; params->gpe_bit = ecdt->gpe_bit; params->uid = ecdt->uid; acpi_GetInteger(h, "_GLK", ¶ms->glk); acpi_set_private(child, params); acpi_set_magic(child, (int)&acpi_ec_devclass); /* Finish the attach process. */ if (device_probe_and_attach(child) != 0) device_delete_child(parent, child); } static int acpi_ec_probe(device_t dev) { ACPI_BUFFER buf; ACPI_HANDLE h; ACPI_OBJECT *obj; ACPI_STATUS status; device_t peer; char desc[64]; int ret; struct acpi_ec_params *params; + static char *ec_ids[] = { "PNP0C09", NULL }; /* Check that this is a device and that EC is not disabled. */ if (acpi_get_type(dev) != ACPI_TYPE_DEVICE || acpi_disabled("ec")) return (ENXIO); /* * If probed via ECDT, set description and continue. Otherwise, * we can access the namespace and make sure this is not a * duplicate probe. */ ret = ENXIO; params = NULL; buf.Pointer = NULL; buf.Length = ACPI_ALLOCATE_BUFFER; if (DEV_ECDT(dev)) { params = acpi_get_private(dev); ret = 0; - } else if (acpi_MatchHid(acpi_get_handle(dev), "PNP0C09")) { + } else if (!acpi_disabled("ec") && + ACPI_ID_PROBE(device_get_parent(dev), dev, ec_ids)) { params = malloc(sizeof(struct acpi_ec_params), M_TEMP, M_WAITOK | M_ZERO); h = acpi_get_handle(dev); /* * Read the unit ID to check for duplicate attach and the * global lock value to see if we should acquire it when * accessing the EC. */ status = acpi_GetInteger(h, "_UID", ¶ms->uid); if (ACPI_FAILURE(status)) params->uid = 0; status = acpi_GetInteger(h, "_GLK", ¶ms->glk); if (ACPI_FAILURE(status)) params->glk = 0; /* * Evaluate the _GPE method to find the GPE bit used by the EC to * signal status (SCI). If it's a package, it contains a reference * and GPE bit, similar to _PRW. */ status = AcpiEvaluateObject(h, "_GPE", NULL, &buf); if (ACPI_FAILURE(status)) { device_printf(dev, "can't evaluate _GPE - %s\n", AcpiFormatException(status)); return (ENXIO); } obj = (ACPI_OBJECT *)buf.Pointer; if (obj == NULL) return (ENXIO); switch (obj->Type) { case ACPI_TYPE_INTEGER: params->gpe_handle = NULL; params->gpe_bit = obj->Integer.Value; break; case ACPI_TYPE_PACKAGE: if (!ACPI_PKG_VALID(obj, 2)) goto out; params->gpe_handle = acpi_GetReference(NULL, &obj->Package.Elements[0]); if (params->gpe_handle == NULL || acpi_PkgInt32(obj, 1, ¶ms->gpe_bit) != 0) goto out; break; default: device_printf(dev, "_GPE has invalid type %d\n", obj->Type); goto out; } /* Store the values we got from the namespace for attach. */ acpi_set_private(dev, params); /* * Check for a duplicate probe. This can happen when a probe * via ECDT succeeded already. If this is a duplicate, disable * this device. */ peer = devclass_get_device(acpi_ec_devclass, params->uid); if (peer == NULL || !device_is_alive(peer)) ret = 0; else device_disable(dev); } out: if (ret == 0) { snprintf(desc, sizeof(desc), "Embedded Controller: GPE %#x%s%s", params->gpe_bit, (params->glk) ? ", GLK" : "", DEV_ECDT(dev) ? ", ECDT" : ""); device_set_desc_copy(dev, desc); } if (ret > 0 && params) free(params, M_TEMP); if (buf.Pointer) AcpiOsFree(buf.Pointer); return (ret); } static int acpi_ec_attach(device_t dev) { struct acpi_ec_softc *sc; struct acpi_ec_params *params; ACPI_STATUS Status; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); /* Fetch/initialize softc (assumes softc is pre-zeroed). */ sc = device_get_softc(dev); params = acpi_get_private(dev); sc->ec_dev = dev; sc->ec_handle = acpi_get_handle(dev); sc->ec_polldelay = EC_POLL_DELAY; mtx_init(&sc->ec_mtx, "ACPI embedded controller", NULL, MTX_DEF); /* Retrieve previously probed values via device ivars. */ sc->ec_glk = params->glk; sc->ec_gpebit = params->gpe_bit; sc->ec_gpehandle = params->gpe_handle; sc->ec_uid = params->uid; free(params, M_TEMP); /* Attach bus resources for data and command/status ports. */ sc->ec_data_rid = 0; sc->ec_data_res = bus_alloc_resource_any(sc->ec_dev, SYS_RES_IOPORT, &sc->ec_data_rid, RF_ACTIVE); if (sc->ec_data_res == NULL) { device_printf(dev, "can't allocate data port\n"); goto error; } sc->ec_data_tag = rman_get_bustag(sc->ec_data_res); sc->ec_data_handle = rman_get_bushandle(sc->ec_data_res); sc->ec_csr_rid = 1; sc->ec_csr_res = bus_alloc_resource_any(sc->ec_dev, SYS_RES_IOPORT, &sc->ec_csr_rid, RF_ACTIVE); if (sc->ec_csr_res == NULL) { device_printf(dev, "can't allocate command/status port\n"); goto error; } sc->ec_csr_tag = rman_get_bustag(sc->ec_csr_res); sc->ec_csr_handle = rman_get_bushandle(sc->ec_csr_res); /* * Install a handler for this EC's GPE bit. We want edge-triggered * behavior. */ ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching GPE handler\n")); Status = AcpiInstallGpeHandler(sc->ec_gpehandle, sc->ec_gpebit, ACPI_GPE_EDGE_TRIGGERED, &EcGpeHandler, sc); if (ACPI_FAILURE(Status)) { device_printf(dev, "can't install GPE handler for %s - %s\n", acpi_name(sc->ec_handle), AcpiFormatException(Status)); goto error; } /* * Install address space handler */ ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "attaching address space handler\n")); Status = AcpiInstallAddressSpaceHandler(sc->ec_handle, ACPI_ADR_SPACE_EC, &EcSpaceHandler, &EcSpaceSetup, sc); if (ACPI_FAILURE(Status)) { device_printf(dev, "can't install address space handler for %s - %s\n", acpi_name(sc->ec_handle), AcpiFormatException(Status)); goto error; } /* Enable runtime GPEs for the handler. */ Status = AcpiSetGpeType(sc->ec_gpehandle, sc->ec_gpebit, ACPI_GPE_TYPE_RUNTIME); if (ACPI_FAILURE(Status)) { device_printf(dev, "AcpiSetGpeType failed: %s\n", AcpiFormatException(Status)); goto error; } Status = AcpiEnableGpe(sc->ec_gpehandle, sc->ec_gpebit, ACPI_NOT_ISR); if (ACPI_FAILURE(Status)) { device_printf(dev, "AcpiEnableGpe failed: %s\n", AcpiFormatException(Status)); goto error; } ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "acpi_ec_attach complete\n")); return (0); error: AcpiRemoveGpeHandler(sc->ec_gpehandle, sc->ec_gpebit, &EcGpeHandler); AcpiRemoveAddressSpaceHandler(sc->ec_handle, ACPI_ADR_SPACE_EC, EcSpaceHandler); if (sc->ec_csr_res) bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_csr_rid, sc->ec_csr_res); if (sc->ec_data_res) bus_release_resource(sc->ec_dev, SYS_RES_IOPORT, sc->ec_data_rid, sc->ec_data_res); mtx_destroy(&sc->ec_mtx); return (ENXIO); } static void EcGpeQueryHandler(void *Context) { struct acpi_ec_softc *sc = (struct acpi_ec_softc *)Context; UINT8 Data; ACPI_STATUS Status; EC_STATUS EcStatus; char qxx[5]; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); KASSERT(Context != NULL, ("EcGpeQueryHandler called with NULL")); Status = EcLock(sc); if (ACPI_FAILURE(Status)) { ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "GpeQuery lock error: %s\n", AcpiFormatException(Status)); return; } /* * If the EC_SCI bit of the status register is not set, then pass * it along to any potential waiters as it may be an IBE/OBF event. */ EcStatus = EC_GET_CSR(sc); if ((EcStatus & EC_EVENT_SCI) == 0) { sc->ec_csrvalue = EcStatus; wakeup(&sc->ec_csrvalue); EcUnlock(sc); goto re_enable; } /* * Send a query command to the EC to find out which _Qxx call it * wants to make. This command clears the SCI bit and also the * interrupt source since we are edge-triggered. */ Status = EcCommand(sc, EC_COMMAND_QUERY); if (ACPI_FAILURE(Status)) { EcUnlock(sc); ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "GPE query failed - %s\n", AcpiFormatException(Status)); goto re_enable; } Data = EC_GET_DATA(sc); EcUnlock(sc); /* Ignore the value for "no outstanding event". (13.3.5) */ if (Data == 0) goto re_enable; /* Evaluate _Qxx to respond to the controller. */ sprintf(qxx, "_Q%02x", Data); strupr(qxx); Status = AcpiEvaluateObject(sc->ec_handle, qxx, NULL, NULL); if (ACPI_FAILURE(Status) && Status != AE_NOT_FOUND) { ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "evaluation of GPE query method %s failed - %s\n", qxx, AcpiFormatException(Status)); } re_enable: /* Re-enable the GPE event so we'll get future requests. */ Status = AcpiEnableGpe(sc->ec_gpehandle, sc->ec_gpebit, ACPI_NOT_ISR); if (ACPI_FAILURE(Status)) printf("EcGpeQueryHandler: AcpiEnableEvent failed\n"); } /* * Handle a GPE. Currently we only handle SCI events as others must * be handled by polling in EcWaitEvent(). This is because some ECs * treat events as level when they should be edge-triggered. */ static uint32_t EcGpeHandler(void *Context) { struct acpi_ec_softc *sc = Context; ACPI_STATUS Status; KASSERT(Context != NULL, ("EcGpeHandler called with NULL")); /* Disable further GPEs while we handle this one. */ AcpiDisableGpe(sc->ec_gpehandle, sc->ec_gpebit, ACPI_NOT_ISR); /* Schedule the GPE query handler. */ Status = AcpiOsQueueForExecution(OSD_PRIORITY_GPE, EcGpeQueryHandler, Context); if (ACPI_FAILURE(Status)) { printf("Queuing GPE query handler failed.\n"); Status = AcpiEnableGpe(sc->ec_gpehandle, sc->ec_gpebit, ACPI_NOT_ISR); if (ACPI_FAILURE(Status)) printf("EcGpeHandler: AcpiEnableEvent failed\n"); } return (0); } static ACPI_STATUS EcSpaceSetup(ACPI_HANDLE Region, UINT32 Function, void *Context, void **RegionContext) { ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); /* * If deactivating a region, always set the output to NULL. Otherwise, * just pass the context through. */ if (Function == ACPI_REGION_DEACTIVATE) *RegionContext = NULL; else *RegionContext = Context; return_ACPI_STATUS (AE_OK); } static ACPI_STATUS EcSpaceHandler(UINT32 Function, ACPI_PHYSICAL_ADDRESS Address, UINT32 width, ACPI_INTEGER *Value, void *Context, void *RegionContext) { struct acpi_ec_softc *sc = (struct acpi_ec_softc *)Context; ACPI_STATUS Status; UINT8 EcAddr, EcData; int i; ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, (UINT32)Address); if (width % 8 != 0 || Value == NULL || Context == NULL) return_ACPI_STATUS (AE_BAD_PARAMETER); if (Address + (width / 8) - 1 > 0xFF) return_ACPI_STATUS (AE_BAD_ADDRESS); if (Function == ACPI_READ) *Value = 0; EcAddr = Address; Status = AE_ERROR; /* Perform the transaction(s), based on width. */ for (i = 0; i < width; i += 8, EcAddr++) { Status = EcLock(sc); if (ACPI_FAILURE(Status)) break; switch (Function) { case ACPI_READ: Status = EcRead(sc, EcAddr, &EcData); if (ACPI_SUCCESS(Status)) *Value |= ((ACPI_INTEGER)EcData) << i; break; case ACPI_WRITE: EcData = (UINT8)((*Value) >> i); Status = EcWrite(sc, EcAddr, &EcData); break; default: device_printf(sc->ec_dev, "invalid EcSpaceHandler function %d\n", Function); Status = AE_BAD_PARAMETER; break; } EcUnlock(sc); if (ACPI_FAILURE(Status)) break; } return_ACPI_STATUS (Status); } static ACPI_STATUS EcWaitEvent(struct acpi_ec_softc *sc, EC_EVENT Event) { EC_STATUS EcStatus; ACPI_STATUS Status; int i, period, retval; static int EcDbgMaxDelay; mtx_assert(&sc->ec_mtx, MA_OWNED); Status = AE_NO_HARDWARE_RESPONSE; /* * Wait for 1 us before checking the CSR. Testing shows about * 50% of requests complete in 1 us and 90% of them complete * in 5 us or less. */ AcpiOsStall(1); /* * If we're up and running, wait up to 1 ms. Otherwise, burn the entire * timeout value with delays since msleep() is a no-op. */ period = 1000 / sc->ec_polldelay; if (cold) period *= ec_poll_timeout; /* * Poll the EC status register to detect completion of the last * command in chunks of ec_polldelay. */ for (i = 0; i < period; i++) { EcStatus = EC_GET_CSR(sc); if (EVENT_READY(Event, EcStatus)) { Status = AE_OK; break; } AcpiOsStall(sc->ec_polldelay); } /* Scale poll delay by the amount of time actually waited. */ period = i * sc->ec_polldelay; if (period <= 5) sc->ec_polldelay = 1; else if (period <= 20) sc->ec_polldelay = 5; else if (period <= 100) sc->ec_polldelay = 10; else sc->ec_polldelay = 100; /* * If we still don't have a response and we're up and running, wait up * to ec_poll_timeout ms for completion, sleeping for chunks of 10 ms. */ if (!cold && Status != AE_OK) { retval = -1; for (i = 0; i < ec_poll_timeout / 10; i++) { if (retval != 0) EcStatus = EC_GET_CSR(sc); else EcStatus = sc->ec_csrvalue; if (EVENT_READY(Event, EcStatus)) { Status = AE_OK; break; } retval = msleep(&sc->ec_csrvalue, &sc->ec_mtx, PZERO, "ecpoll", 10/*ms*/); } } /* Calculate new delay and print it if it exceeds the max. */ if (period == 1000) period += i * 10000; if (period > EcDbgMaxDelay) { EcDbgMaxDelay = period; ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "info: new max delay is %d us\n", period); } return (Status); } static ACPI_STATUS EcCommand(struct acpi_ec_softc *sc, EC_COMMAND cmd) { ACPI_STATUS Status; EC_EVENT Event; mtx_assert(&sc->ec_mtx, MA_OWNED); /* Decide what to wait for based on command type. */ switch (cmd) { case EC_COMMAND_READ: case EC_COMMAND_WRITE: case EC_COMMAND_BURST_DISABLE: Event = EC_EVENT_INPUT_BUFFER_EMPTY; break; case EC_COMMAND_QUERY: case EC_COMMAND_BURST_ENABLE: Event = EC_EVENT_OUTPUT_BUFFER_FULL; break; default: ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "EcCommand: Invalid command %#x\n", cmd); return (AE_BAD_PARAMETER); } /* Run the command and wait for the chosen event. */ EC_SET_CSR(sc, cmd); Status = EcWaitEvent(sc, Event); if (ACPI_FAILURE(Status)) { ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "EcCommand: no response to %#x\n", cmd); } return (Status); } static ACPI_STATUS EcRead(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data) { ACPI_STATUS Status; mtx_assert(&sc->ec_mtx, MA_OWNED); #ifdef notyet /* If we can't start burst mode, continue anyway. */ EcCommand(sc, EC_COMMAND_BURST_ENABLE); #endif Status = EcCommand(sc, EC_COMMAND_READ); if (ACPI_FAILURE(Status)) return (Status); EC_SET_DATA(sc, Address); Status = EcWaitEvent(sc, EC_EVENT_OUTPUT_BUFFER_FULL); if (ACPI_FAILURE(Status)) { ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "EcRead: Failed waiting for EC to send data.\n"); return (Status); } *Data = EC_GET_DATA(sc); #ifdef notyet if (sc->ec_burstactive) { Status = EcCommand(sc, EC_COMMAND_BURST_DISABLE); if (ACPI_FAILURE(Status)) return (Status); } #endif return (AE_OK); } static ACPI_STATUS EcWrite(struct acpi_ec_softc *sc, UINT8 Address, UINT8 *Data) { ACPI_STATUS Status; mtx_assert(&sc->ec_mtx, MA_OWNED); #ifdef notyet /* If we can't start burst mode, continue anyway. */ EcCommand(sc, EC_COMMAND_BURST_ENABLE); #endif Status = EcCommand(sc, EC_COMMAND_WRITE); if (ACPI_FAILURE(Status)) return (Status); EC_SET_DATA(sc, Address); Status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY); if (ACPI_FAILURE(Status)) { ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "EcRead: Failed waiting for EC to process address\n"); return (Status); } EC_SET_DATA(sc, *Data); Status = EcWaitEvent(sc, EC_EVENT_INPUT_BUFFER_EMPTY); if (ACPI_FAILURE(Status)) { ACPI_VPRINT(sc->ec_dev, acpi_device_get_parent_softc(sc->ec_dev), "EcWrite: Failed waiting for EC to process data\n"); return (Status); } #ifdef notyet if (sc->ec_burstactive) { Status = EcCommand(sc, EC_COMMAND_BURST_DISABLE); if (ACPI_FAILURE(Status)) return (Status); } #endif return (AE_OK); } Index: head/sys/dev/acpica/acpi_isab.c =================================================================== --- head/sys/dev/acpica/acpi_isab.c (revision 131281) +++ head/sys/dev/acpica/acpi_isab.c (revision 131282) @@ -1,131 +1,129 @@ /*- * Copyright (c) 2003 John Baldwin * 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$"); /* * ISA Bridge driver for Generic ISA Bus Devices. See section 10.7 of the * ACPI 2.0a specification for details on this device. */ #include "opt_acpi.h" #include #include #include #include #include #include "acpi.h" #include #include /* Hooks for the ACPI CA debugging infrastructure. */ #define _COMPONENT ACPI_BUS ACPI_MODULE_NAME("ISA_ACPI") struct acpi_isab_softc { device_t ap_dev; ACPI_HANDLE ap_handle; }; static int acpi_isab_probe(device_t bus); static int acpi_isab_attach(device_t bus); static int acpi_isab_read_ivar(device_t dev, device_t child, int which, uintptr_t *result); static device_method_t acpi_isab_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_isab_probe), DEVMETHOD(device_attach, acpi_isab_attach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD(device_suspend, bus_generic_suspend), DEVMETHOD(device_resume, bus_generic_resume), /* Bus interface */ DEVMETHOD(bus_print_child, bus_generic_print_child), DEVMETHOD(bus_read_ivar, acpi_isab_read_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), {0, 0} }; static driver_t acpi_isab_driver = { "isab", acpi_isab_methods, sizeof(struct acpi_isab_softc), }; DRIVER_MODULE(acpi_isab, acpi, acpi_isab_driver, isab_devclass, 0, 0); MODULE_DEPEND(acpi_isab, acpi, 1, 1, 1); static int acpi_isab_probe(device_t dev) { - ACPI_HANDLE h; + static char *isa_ids[] = { "PNP0A05", "PNP0A06", NULL }; - h = acpi_get_handle(dev); - if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && - !acpi_disabled("isa") && - devclass_get_device(isab_devclass, 0) == dev && - (acpi_MatchHid(h, "PNP0A05") || acpi_MatchHid(h, "PNP0A06"))) { - device_set_desc(dev, "ACPI Generic ISA bridge"); - return (0); - } - return (ENXIO); + if (acpi_disabled("isab") || + ACPI_ID_PROBE(device_get_parent(dev), dev, isa_ids) == NULL || + devclass_get_device(isab_devclass, 0) != dev) + return (ENXIO); + + device_set_desc(dev, "ACPI Generic ISA bridge"); + return (0); } static int acpi_isab_attach(device_t dev) { struct acpi_isab_softc *sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = device_get_softc(dev); sc->ap_dev = dev; sc->ap_handle = acpi_get_handle(dev); return (isab_attach(dev)); } static int acpi_isab_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) { struct acpi_isab_softc *sc = device_get_softc(dev); switch (which) { case ACPI_IVAR_HANDLE: *result = (uintptr_t)sc->ap_handle; return (0); } return (ENOENT); } Index: head/sys/dev/acpica/acpi_lid.c =================================================================== --- head/sys/dev/acpica/acpi_lid.c (revision 131281) +++ head/sys/dev/acpica/acpi_lid.c (revision 131282) @@ -1,195 +1,196 @@ /*- * Copyright (c) 2000 Takanori Watanabe * Copyright (c) 2000 Mitsuru IWASAKI * 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 "acpi.h" #include /* Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BUTTON ACPI_MODULE_NAME("LID") struct acpi_lid_softc { device_t lid_dev; ACPI_HANDLE lid_handle; int lid_status; /* open or closed */ }; static int acpi_lid_probe(device_t dev); static int acpi_lid_attach(device_t dev); static int acpi_lid_suspend(device_t dev); static int acpi_lid_resume(device_t dev); static void acpi_lid_notify_status_changed(void *arg); static void acpi_lid_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context); static device_method_t acpi_lid_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_lid_probe), DEVMETHOD(device_attach, acpi_lid_attach), DEVMETHOD(device_suspend, acpi_lid_suspend), DEVMETHOD(device_resume, acpi_lid_resume), {0, 0} }; static driver_t acpi_lid_driver = { "acpi_lid", acpi_lid_methods, sizeof(struct acpi_lid_softc), }; static devclass_t acpi_lid_devclass; DRIVER_MODULE(acpi_lid, acpi, acpi_lid_driver, acpi_lid_devclass, 0, 0); MODULE_DEPEND(acpi_lid, acpi, 1, 1, 1); static int acpi_lid_probe(device_t dev) { - if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("lid") && - acpi_MatchHid(acpi_get_handle(dev), "PNP0C0D")) { + static char *lid_ids[] = { "PNP0C0D", NULL }; - device_set_desc(dev, "Control Method Lid Switch"); - return (0); - } - return (ENXIO); + if (acpi_disabled("lid") || + ACPI_ID_PROBE(device_get_parent(dev), dev, lid_ids) == NULL) + return (ENXIO); + + device_set_desc(dev, "Control Method Lid Switch"); + return (0); } static int acpi_lid_attach(device_t dev) { struct acpi_lid_softc *sc; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = device_get_softc(dev); sc->lid_dev = dev; sc->lid_handle = acpi_get_handle(dev); /* * If a system does not get lid events, it may make sense to change * the type to ACPI_ALL_NOTIFY. Some systems generate both a wake and * runtime notify in that case though. */ AcpiInstallNotifyHandler(sc->lid_handle, ACPI_DEVICE_NOTIFY, acpi_lid_notify_handler, sc); /* Enable the GPE for wake/runtime. */ acpi_wake_init(dev, ACPI_GPE_TYPE_WAKE_RUN); acpi_wake_set_enable(dev, 1); return_VALUE (0); } static int acpi_lid_suspend(device_t dev) { struct acpi_softc *acpi_sc; acpi_sc = acpi_device_get_parent_softc(dev); acpi_wake_sleep_prep(dev, acpi_sc->acpi_sstate); return (0); } static int acpi_lid_resume(device_t dev) { acpi_wake_run_prep(dev); return (0); } static void acpi_lid_notify_status_changed(void *arg) { struct acpi_lid_softc *sc; struct acpi_softc *acpi_sc; ACPI_STATUS status; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = (struct acpi_lid_softc *)arg; /* * Evaluate _LID and check the return value, update lid status. * Zero: The lid is closed * Non-zero: The lid is open */ status = acpi_GetInteger(sc->lid_handle, "_LID", &sc->lid_status); if (ACPI_FAILURE(status)) return_VOID; acpi_sc = acpi_device_get_parent_softc(sc->lid_dev); if (acpi_sc == NULL) return_VOID; ACPI_VPRINT(sc->lid_dev, acpi_sc, "Lid %s\n", sc->lid_status ? "opened" : "closed"); acpi_UserNotify("Lid", sc->lid_handle, sc->lid_status); if (sc->lid_status == 0) EVENTHANDLER_INVOKE(acpi_sleep_event, acpi_sc->acpi_lid_switch_sx); else EVENTHANDLER_INVOKE(acpi_wakeup_event, acpi_sc->acpi_lid_switch_sx); return_VOID; } /* XXX maybe not here */ #define ACPI_NOTIFY_STATUS_CHANGED 0x80 static void acpi_lid_notify_handler(ACPI_HANDLE h, UINT32 notify, void *context) { struct acpi_lid_softc *sc; ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify); sc = (struct acpi_lid_softc *)context; switch (notify) { case ACPI_NOTIFY_STATUS_CHANGED: AcpiOsQueueForExecution(OSD_PRIORITY_LO, acpi_lid_notify_status_changed, sc); break; default: device_printf(sc->lid_dev, "unknown notify %#x\n", notify); break; } return_VOID; } Index: head/sys/dev/acpica/acpi_pcib_acpi.c =================================================================== --- head/sys/dev/acpica/acpi_pcib_acpi.c (revision 131281) +++ head/sys/dev/acpica/acpi_pcib_acpi.c (revision 131282) @@ -1,312 +1,312 @@ /*- * 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 #include "acpi.h" #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 uint32_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, uint32_t data, int bytes); static int acpi_pcib_acpi_route_interrupt(device_t pcib, device_t dev, int pin); 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); 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, acpi_pcib_acpi_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); MODULE_DEPEND(acpi_pcib, acpi, 1, 1, 1); static int acpi_pcib_acpi_probe(device_t dev) { + static char *pcib_ids[] = { "PNP0A03", NULL }; - if (acpi_get_type(dev) == ACPI_TYPE_DEVICE && !acpi_disabled("pci") && - acpi_MatchHid(acpi_get_handle(dev), "PNP0A03")) { + if (acpi_disabled("pcib") || + ACPI_ID_PROBE(device_get_parent(dev), dev, pcib_ids) == NULL) + return (ENXIO); - if (pci_cfgregopen() == 0) - return (ENXIO); - device_set_desc(dev, "ACPI Host-PCI bridge"); - return (0); - } - return (ENXIO); + if (pci_cfgregopen() == 0) + return (ENXIO); + device_set_desc(dev, "ACPI Host-PCI bridge"); + return (0); } 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_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 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_GetInteger(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, "couldn't find _ADR\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, "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); } /* * 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; } 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 uint32_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, 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; /* Find the bridge softc. */ sc = device_get_softc(pcib); return (acpi_pcib_route_interrupt(pcib, dev, pin, &sc->ap_prt)); } 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) { /* * If no memory preference is given, use upper 256MB slot most * bioses use for their memory window. Typically other bridges * before us get in the way to assert their preferences on memory. * Hardcoding like this sucks, so a more MD/MI way needs to be * found to do it. */ if (type == SYS_RES_MEMORY && start == 0UL && end == ~0UL) start = 0xf0000000; return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); } Index: head/sys/dev/acpica/acpi_resource.c =================================================================== --- head/sys/dev/acpica/acpi_resource.c (revision 131281) +++ head/sys/dev/acpica/acpi_resource.c (revision 131282) @@ -1,747 +1,746 @@ /*- * 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 "acpi.h" #include /* Hooks for the ACPI CA debugging infrastructure */ #define _COMPONENT ACPI_BUS ACPI_MODULE_NAME("RESOURCE") struct lookup_irq_request { ACPI_RESOURCE *acpi_res; struct resource *res; int counter; int rid; int found; }; static ACPI_STATUS acpi_lookup_irq_handler(ACPI_RESOURCE *res, void *context) { struct lookup_irq_request *req; u_int irqnum, irq; switch (res->Id) { case ACPI_RSTYPE_IRQ: case ACPI_RSTYPE_EXT_IRQ: if (res->Id == ACPI_RSTYPE_IRQ) { irqnum = res->Data.Irq.NumberOfInterrupts; irq = res->Data.Irq.Interrupts[0]; } else { irqnum = res->Data.ExtendedIrq.NumberOfInterrupts; irq = res->Data.ExtendedIrq.Interrupts[0]; } if (irqnum != 1) break; req = (struct lookup_irq_request *)context; if (req->counter != req->rid) { req->counter++; break; } req->found = 1; KASSERT(irq == rman_get_start(req->res), ("IRQ resources do not match")); bcopy(res, req->acpi_res, sizeof(ACPI_RESOURCE)); return (AE_CTRL_TERMINATE); } return (AE_OK); } ACPI_STATUS acpi_lookup_irq_resource(device_t dev, int rid, struct resource *res, ACPI_RESOURCE *acpi_res) { struct lookup_irq_request req; ACPI_STATUS status; req.acpi_res = acpi_res; req.res = res; req.counter = 0; req.rid = rid; req.found = 0; status = AcpiWalkResources(acpi_get_handle(dev), "_CRS", acpi_lookup_irq_handler, &req); if (ACPI_SUCCESS(status) && req.found == 0) status = AE_NOT_FOUND; return (status); } void acpi_config_intr(device_t dev, ACPI_RESOURCE *res) { u_int irq; int pol, trig; switch (res->Id) { case ACPI_RSTYPE_IRQ: KASSERT(res->Data.Irq.NumberOfInterrupts == 1, ("%s: multiple interrupts", __func__)); irq = res->Data.Irq.Interrupts[0]; trig = res->Data.Irq.EdgeLevel; pol = res->Data.Irq.ActiveHighLow; break; case ACPI_RSTYPE_EXT_IRQ: KASSERT(res->Data.ExtendedIrq.NumberOfInterrupts == 1, ("%s: multiple interrupts", __func__)); irq = res->Data.ExtendedIrq.Interrupts[0]; trig = res->Data.ExtendedIrq.EdgeLevel; pol = res->Data.ExtendedIrq.ActiveHighLow; break; default: panic("%s: bad resource type %u", __func__, res->Id); } BUS_CONFIG_INTR(dev, irq, (trig == ACPI_EDGE_SENSITIVE) ? INTR_TRIGGER_EDGE : INTR_TRIGGER_LEVEL, (pol == ACPI_ACTIVE_HIGH) ? INTR_POLARITY_HIGH : INTR_POLARITY_LOW); } /* * Fetch a device's resources and associate them with the device. * * Note that it might be nice to also locate ACPI-specific resource items, such * as GPE bits. * * We really need to split the resource-fetching code out from the * resource-parsing code, since we may want to use the parsing * code for _PRS someday. */ ACPI_STATUS acpi_parse_resources(device_t dev, ACPI_HANDLE handle, struct acpi_parse_resource_set *set, void *arg) { ACPI_BUFFER buf; ACPI_RESOURCE *res; char *curr, *last; ACPI_STATUS status; void *context; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); /* * Special-case some devices that abuse _PRS/_CRS to mean * something other than "I consume this resource". * * XXX do we really need this? It's only relevant once * we start always-allocating these resources, and even * then, the only special-cased device is likely to be * the PCI interrupt link. */ /* Fetch the device's current resources. */ buf.Length = ACPI_ALLOCATE_BUFFER; if (ACPI_FAILURE((status = AcpiGetCurrentResources(handle, &buf)))) { if (status != AE_NOT_FOUND) printf("can't fetch resources for %s - %s\n", acpi_name(handle), AcpiFormatException(status)); return_ACPI_STATUS (status); } ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "%s - got %ld bytes of resources\n", acpi_name(handle), (long)buf.Length)); set->set_init(dev, arg, &context); /* Iterate through the resources */ curr = buf.Pointer; last = (char *)buf.Pointer + buf.Length; while (curr < last) { res = (ACPI_RESOURCE *)curr; curr += res->Length; /* Handle the individual resource types */ switch(res->Id) { case ACPI_RSTYPE_END_TAG: ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n")); curr = last; break; case ACPI_RSTYPE_FIXED_IO: if (res->Data.FixedIo.RangeLength <= 0) break; ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedIo 0x%x/%d\n", res->Data.FixedIo.BaseAddress, res->Data.FixedIo.RangeLength)); set->set_ioport(dev, context, res->Data.FixedIo.BaseAddress, res->Data.FixedIo.RangeLength); break; case ACPI_RSTYPE_IO: if (res->Data.Io.RangeLength <= 0) break; if (res->Data.Io.MinBaseAddress == res->Data.Io.MaxBaseAddress) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x/%d\n", res->Data.Io.MinBaseAddress, res->Data.Io.RangeLength)); set->set_ioport(dev, context, res->Data.Io.MinBaseAddress, res->Data.Io.RangeLength); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Io 0x%x-0x%x/%d\n", res->Data.Io.MinBaseAddress, res->Data.Io.MaxBaseAddress, res->Data.Io.RangeLength)); set->set_iorange(dev, context, res->Data.Io.MinBaseAddress, res->Data.Io.MaxBaseAddress, res->Data.Io.RangeLength, res->Data.Io.Alignment); } break; case ACPI_RSTYPE_FIXED_MEM32: if (res->Data.FixedMemory32.RangeLength <= 0) break; ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "FixedMemory32 0x%x/%d\n", res->Data.FixedMemory32.RangeBaseAddress, res->Data.FixedMemory32.RangeLength)); set->set_memory(dev, context, res->Data.FixedMemory32.RangeBaseAddress, res->Data.FixedMemory32.RangeLength); break; case ACPI_RSTYPE_MEM32: if (res->Data.Memory32.RangeLength <= 0) break; if (res->Data.Memory32.MinBaseAddress == res->Data.Memory32.MaxBaseAddress) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x/%d\n", res->Data.Memory32.MinBaseAddress, res->Data.Memory32.RangeLength)); set->set_memory(dev, context, res->Data.Memory32.MinBaseAddress, res->Data.Memory32.RangeLength); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory32 0x%x-0x%x/%d\n", res->Data.Memory32.MinBaseAddress, res->Data.Memory32.MaxBaseAddress, res->Data.Memory32.RangeLength)); set->set_memoryrange(dev, context, res->Data.Memory32.MinBaseAddress, res->Data.Memory32.MaxBaseAddress, res->Data.Memory32.RangeLength, res->Data.Memory32.Alignment); } break; case ACPI_RSTYPE_MEM24: if (res->Data.Memory24.RangeLength <= 0) break; if (res->Data.Memory24.MinBaseAddress == res->Data.Memory24.MaxBaseAddress) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x/%d\n", res->Data.Memory24.MinBaseAddress, res->Data.Memory24.RangeLength)); set->set_memory(dev, context, res->Data.Memory24.MinBaseAddress, res->Data.Memory24.RangeLength); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Memory24 0x%x-0x%x/%d\n", res->Data.Memory24.MinBaseAddress, res->Data.Memory24.MaxBaseAddress, res->Data.Memory24.RangeLength)); set->set_memoryrange(dev, context, res->Data.Memory24.MinBaseAddress, res->Data.Memory24.MaxBaseAddress, res->Data.Memory24.RangeLength, res->Data.Memory24.Alignment); } break; case ACPI_RSTYPE_IRQ: /* * from 1.0b 6.4.2 * "This structure is repeated for each separate interrupt * required" */ set->set_irq(dev, context, res->Data.Irq.Interrupts, res->Data.Irq.NumberOfInterrupts, res->Data.Irq.EdgeLevel, res->Data.Irq.ActiveHighLow); break; case ACPI_RSTYPE_DMA: /* * from 1.0b 6.4.3 * "This structure is repeated for each separate dma channel * required" */ set->set_drq(dev, context, res->Data.Dma.Channels, res->Data.Dma.NumberOfChannels); break; case ACPI_RSTYPE_START_DPF: ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "start dependant functions\n")); set->set_start_dependant(dev, context, res->Data.StartDpf.CompatibilityPriority); break; case ACPI_RSTYPE_END_DPF: ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "end dependant functions\n")); set->set_end_dependant(dev, context); break; case ACPI_RSTYPE_ADDRESS32: if (res->Data.Address32.AddressLength <= 0) break; if (res->Data.Address32.ProducerConsumer != ACPI_CONSUMER) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "ignored Address32 %s producer\n", res->Data.Address32.ResourceType == ACPI_IO_RANGE ? "IO" : "Memory")); break; } if (res->Data.Address32.ResourceType != ACPI_MEMORY_RANGE && res->Data.Address32.ResourceType != ACPI_IO_RANGE) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "ignored Address32 for non-memory, non-I/O\n")); break; } if (res->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED && res->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED) { if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address32/Memory 0x%x/%d\n", res->Data.Address32.MinAddressRange, res->Data.Address32.AddressLength)); set->set_memory(dev, context, res->Data.Address32.MinAddressRange, res->Data.Address32.AddressLength); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address32/IO 0x%x/%d\n", res->Data.Address32.MinAddressRange, res->Data.Address32.AddressLength)); set->set_ioport(dev, context, res->Data.Address32.MinAddressRange, res->Data.Address32.AddressLength); } } else { if (res->Data.Address32.ResourceType == ACPI_MEMORY_RANGE) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address32/Memory 0x%x-0x%x/%d\n", res->Data.Address32.MinAddressRange, res->Data.Address32.MaxAddressRange, res->Data.Address32.AddressLength)); set->set_memoryrange(dev, context, res->Data.Address32.MinAddressRange, res->Data.Address32.MaxAddressRange, res->Data.Address32.AddressLength, res->Data.Address32.Granularity); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address32/IO 0x%x-0x%x/%d\n", res->Data.Address32.MinAddressRange, res->Data.Address32.MaxAddressRange, res->Data.Address32.AddressLength)); set->set_iorange(dev, context, res->Data.Address32.MinAddressRange, res->Data.Address32.MaxAddressRange, res->Data.Address32.AddressLength, res->Data.Address32.Granularity); } } break; case ACPI_RSTYPE_ADDRESS16: if (res->Data.Address16.AddressLength <= 0) break; if (res->Data.Address16.ProducerConsumer != ACPI_CONSUMER) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "ignored Address16 %s producer\n", res->Data.Address16.ResourceType == ACPI_IO_RANGE ? "IO" : "Memory")); break; } if (res->Data.Address16.ResourceType != ACPI_MEMORY_RANGE && res->Data.Address16.ResourceType != ACPI_IO_RANGE) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "ignored Address16 for non-memory, non-I/O\n")); break; } if (res->Data.Address16.MinAddressFixed == ACPI_ADDRESS_FIXED && res->Data.Address16.MaxAddressFixed == ACPI_ADDRESS_FIXED) { if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address16/Memory 0x%x/%d\n", res->Data.Address16.MinAddressRange, res->Data.Address16.AddressLength)); set->set_memory(dev, context, res->Data.Address16.MinAddressRange, res->Data.Address16.AddressLength); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address16/IO 0x%x/%d\n", res->Data.Address16.MinAddressRange, res->Data.Address16.AddressLength)); set->set_ioport(dev, context, res->Data.Address16.MinAddressRange, res->Data.Address16.AddressLength); } } else { if (res->Data.Address16.ResourceType == ACPI_MEMORY_RANGE) { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address16/Memory 0x%x-0x%x/%d\n", res->Data.Address16.MinAddressRange, res->Data.Address16.MaxAddressRange, res->Data.Address16.AddressLength)); set->set_memoryrange(dev, context, res->Data.Address16.MinAddressRange, res->Data.Address16.MaxAddressRange, res->Data.Address16.AddressLength, res->Data.Address16.Granularity); } else { ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "Address16/IO 0x%x-0x%x/%d\n", res->Data.Address16.MinAddressRange, res->Data.Address16.MaxAddressRange, res->Data.Address16.AddressLength)); set->set_iorange(dev, context, res->Data.Address16.MinAddressRange, res->Data.Address16.MaxAddressRange, res->Data.Address16.AddressLength, res->Data.Address16.Granularity); } } break; case ACPI_RSTYPE_ADDRESS64: ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "unimplemented Address64 resource\n")); break; case ACPI_RSTYPE_EXT_IRQ: /* XXX special handling? */ set->set_irq(dev, context,res->Data.ExtendedIrq.Interrupts, res->Data.ExtendedIrq.NumberOfInterrupts, res->Data.ExtendedIrq.EdgeLevel, res->Data.ExtendedIrq.ActiveHighLow); break; case ACPI_RSTYPE_VENDOR: ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "unimplemented VendorSpecific resource\n")); break; default: break; } } AcpiOsFree(buf.Pointer); set->set_done(dev, context); return_ACPI_STATUS (AE_OK); } /* * Resource-set vectors used to attach _CRS-derived resources * to an ACPI device. */ static void acpi_res_set_init(device_t dev, void *arg, void **context); static void acpi_res_set_done(device_t dev, void *context); static void acpi_res_set_ioport(device_t dev, void *context, u_int32_t base, u_int32_t length); static void acpi_res_set_iorange(device_t dev, void *context, u_int32_t low, u_int32_t high, u_int32_t length, u_int32_t align); static void acpi_res_set_memory(device_t dev, void *context, u_int32_t base, u_int32_t length); static void acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low, u_int32_t high, u_int32_t length, u_int32_t align); static void acpi_res_set_irq(device_t dev, void *context, u_int32_t *irq, int count, int trig, int pol); static void acpi_res_set_drq(device_t dev, void *context, u_int32_t *drq, int count); static void acpi_res_set_start_dependant(device_t dev, void *context, int preference); static void acpi_res_set_end_dependant(device_t dev, void *context); struct acpi_parse_resource_set acpi_res_parse_set = { acpi_res_set_init, acpi_res_set_done, acpi_res_set_ioport, acpi_res_set_iorange, acpi_res_set_memory, acpi_res_set_memoryrange, acpi_res_set_irq, acpi_res_set_drq, acpi_res_set_start_dependant, acpi_res_set_end_dependant }; struct acpi_res_context { int ar_nio; int ar_nmem; int ar_nirq; int ar_ndrq; void *ar_parent; }; static void acpi_res_set_init(device_t dev, void *arg, void **context) { struct acpi_res_context *cp; if ((cp = AcpiOsAllocate(sizeof(*cp))) != NULL) { bzero(cp, sizeof(*cp)); cp->ar_parent = arg; *context = cp; } } static void acpi_res_set_done(device_t dev, void *context) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; AcpiOsFree(cp); } static void acpi_res_set_ioport(device_t dev, void *context, u_int32_t base, u_int32_t length) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; bus_set_resource(dev, SYS_RES_IOPORT, cp->ar_nio++, base, length); } static void acpi_res_set_iorange(device_t dev, void *context, u_int32_t low, u_int32_t high, u_int32_t length, u_int32_t align) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; device_printf(dev, "I/O range not supported\n"); } static void acpi_res_set_memory(device_t dev, void *context, u_int32_t base, u_int32_t length) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; bus_set_resource(dev, SYS_RES_MEMORY, cp->ar_nmem++, base, length); } static void acpi_res_set_memoryrange(device_t dev, void *context, u_int32_t low, u_int32_t high, u_int32_t length, u_int32_t align) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; device_printf(dev, "memory range not supported\n"); } static void acpi_res_set_irq(device_t dev, void *context, u_int32_t *irq, int count, int trig, int pol) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL || irq == NULL) return; /* This implements no resource relocation. */ if (count != 1) return; bus_set_resource(dev, SYS_RES_IRQ, cp->ar_nirq++, *irq, 1); } static void acpi_res_set_drq(device_t dev, void *context, u_int32_t *drq, int count) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL || drq == NULL) return; /* This implements no resource relocation. */ if (count != 1) return; bus_set_resource(dev, SYS_RES_DRQ, cp->ar_ndrq++, *drq, 1); } static void acpi_res_set_start_dependant(device_t dev, void *context, int preference) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; device_printf(dev, "dependant functions not supported\n"); } static void acpi_res_set_end_dependant(device_t dev, void *context) { struct acpi_res_context *cp = (struct acpi_res_context *)context; if (cp == NULL) return; device_printf(dev, "dependant functions not supported\n"); } /* * Resource-owning placeholders for IO and memory pseudo-devices. * * This code allocates system resource objects that will be owned by ACPI * child devices. Really, the acpi parent device should have the resources * but this would significantly affect the device probe code. */ static int acpi_sysres_probe(device_t dev); static int acpi_sysres_attach(device_t dev); static device_method_t acpi_sysres_methods[] = { /* Device interface */ DEVMETHOD(device_probe, acpi_sysres_probe), DEVMETHOD(device_attach, acpi_sysres_attach), {0, 0} }; static driver_t acpi_sysres_driver = { "acpi_sysresource", acpi_sysres_methods, 0, }; static devclass_t acpi_sysres_devclass; DRIVER_MODULE(acpi_sysresource, acpi, acpi_sysres_driver, acpi_sysres_devclass, 0, 0); MODULE_DEPEND(acpi_sysresource, acpi, 1, 1, 1); static int acpi_sysres_probe(device_t dev) { - ACPI_HANDLE h; + static char *sysres_ids[] = { "PNP0C01", "PNP0C02", NULL }; - h = acpi_get_handle(dev); if (acpi_disabled("sysresource") || - (!acpi_MatchHid(h, "PNP0C01") && !acpi_MatchHid(h, "PNP0C02"))) + ACPI_ID_PROBE(device_get_parent(dev), dev, sysres_ids) == NULL) return (ENXIO); device_set_desc(dev, "System Resource"); device_quiet(dev); return (-100); } static int acpi_sysres_attach(device_t dev) { device_t gparent; struct resource *res; struct rman *rm; struct resource_list_entry *rle; struct resource_list *rl; /* * Pre-allocate/manage all memory and IO resources. We detect duplicates * by setting rle->res to the resource we got from the parent. We can't * ignore them since rman can't handle duplicates. */ rl = BUS_GET_RESOURCE_LIST(device_get_parent(dev), dev); SLIST_FOREACH(rle, rl, link) { if (rle->res != NULL) { device_printf(dev, "duplicate resource for %lx\n", rle->start); continue; } /* Only memory and IO resources are valid here. */ switch (rle->type) { case SYS_RES_IOPORT: rm = &acpi_rman_io; break; case SYS_RES_MEMORY: rm = &acpi_rman_mem; break; default: continue; } /* Pre-allocate resource and add to our rman pool. */ gparent = device_get_parent(device_get_parent(dev)); res = BUS_ALLOC_RESOURCE(gparent, dev, rle->type, &rle->rid, rle->start, rle->start + rle->count - 1, rle->count, 0); if (res != NULL) { rman_manage_region(rm, rman_get_start(res), rman_get_end(res)); rle->res = res; } } return (0); } struct resource_list_entry * acpi_sysres_find(int type, u_long addr) { device_t *devs; int i, numdevs; struct resource_list *rl; struct resource_list_entry *rle; /* We only consider IO and memory resources for our pool. */ rle = NULL; if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) return (rle); /* Find all the sysresource devices. */ if (devclass_get_devices(acpi_sysres_devclass, &devs, &numdevs) != 0) return (rle); /* Check each device for a resource that contains "addr". */ for (i = 0; i < numdevs && rle == NULL; i++) { rl = BUS_GET_RESOURCE_LIST(device_get_parent(devs[i]), devs[i]); if (rl == NULL) continue; SLIST_FOREACH(rle, rl, link) { if (type == rle->type && addr >= rle->start && addr < rle->start + rle->count) break; } } free(devs, M_TEMP); return (rle); }