2000-10-28 06:59:48 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Takanori Watanabe <takawata@jp.freebsd.org>
|
|
|
|
* Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
|
2001-06-29 20:29:59 +00:00
|
|
|
* Copyright (c) 2000, 2001 Michael Smith
|
2000-10-28 06:59:48 +00:00
|
|
|
* 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 <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
2001-03-28 09:17:56 +00:00
|
|
|
#include <sys/lock.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <sys/malloc.h>
|
2000-12-12 14:20:27 +00:00
|
|
|
#include <sys/mutex.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/ctype.h>
|
2001-11-06 15:00:30 +00:00
|
|
|
#include <sys/linker.h>
|
2001-11-01 16:34:07 +00:00
|
|
|
#include <sys/power.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
#include <isa/isavar.h>
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include "acpi.h"
|
|
|
|
|
2001-11-06 15:00:30 +00:00
|
|
|
#include <dev/acpica/acpica_support.h>
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <dev/acpica/acpiio.h>
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_ACPIDEV, "acpidev", "ACPI devices");
|
|
|
|
|
2000-12-08 09:16:20 +00:00
|
|
|
/*
|
|
|
|
* Hooks for the ACPI CA debugging infrastructure
|
|
|
|
*/
|
2001-06-29 20:29:59 +00:00
|
|
|
#define _COMPONENT ACPI_BUS
|
2002-02-23 05:21:56 +00:00
|
|
|
ACPI_MODULE_NAME("ACPI")
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Character device
|
|
|
|
*/
|
|
|
|
|
|
|
|
static d_open_t acpiopen;
|
|
|
|
static d_close_t acpiclose;
|
|
|
|
static d_ioctl_t acpiioctl;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 152
|
|
|
|
static struct cdevsw acpi_cdevsw = {
|
|
|
|
acpiopen,
|
|
|
|
acpiclose,
|
|
|
|
noread,
|
|
|
|
nowrite,
|
|
|
|
acpiioctl,
|
|
|
|
nopoll,
|
|
|
|
nommap,
|
|
|
|
nostrategy,
|
|
|
|
"acpi",
|
|
|
|
CDEV_MAJOR,
|
|
|
|
nodump,
|
|
|
|
nopsize,
|
2001-04-02 23:36:36 +00:00
|
|
|
0
|
2000-10-28 06:59:48 +00:00
|
|
|
};
|
|
|
|
|
2001-01-13 21:28:57 +00:00
|
|
|
static const char* sleep_state_names[] = {
|
2001-11-15 11:59:25 +00:00
|
|
|
"S0", "S1", "S2", "S3", "S4", "S5", "NONE"};
|
2001-01-13 21:28:57 +00:00
|
|
|
|
2001-05-29 20:13:42 +00:00
|
|
|
/* this has to be static, as the softc is gone when we need it */
|
|
|
|
static int acpi_off_state = ACPI_STATE_S5;
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
struct mtx acpi_mutex;
|
|
|
|
|
2001-07-30 08:59:43 +00:00
|
|
|
static int acpi_modevent(struct module *mod, int event, void *junk);
|
2000-10-28 06:59:48 +00:00
|
|
|
static void acpi_identify(driver_t *driver, device_t parent);
|
|
|
|
static int acpi_probe(device_t dev);
|
|
|
|
static int acpi_attach(device_t dev);
|
|
|
|
static device_t acpi_add_child(device_t bus, int order, const char *name, int unit);
|
|
|
|
static int acpi_print_child(device_t bus, device_t child);
|
|
|
|
static int acpi_read_ivar(device_t dev, device_t child, int index, uintptr_t *result);
|
|
|
|
static int acpi_write_ivar(device_t dev, device_t child, int index, uintptr_t value);
|
|
|
|
static int acpi_set_resource(device_t dev, device_t child, int type, int rid, u_long start,
|
|
|
|
u_long count);
|
|
|
|
static int acpi_get_resource(device_t dev, device_t child, int type, int rid, u_long *startp,
|
|
|
|
u_long *countp);
|
|
|
|
static struct resource *acpi_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
|
|
|
u_long start, u_long end, u_long count, u_int flags);
|
|
|
|
static int acpi_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r);
|
2001-09-07 02:57:29 +00:00
|
|
|
static u_int32_t acpi_isa_get_logicalid(device_t dev);
|
2001-08-30 00:50:58 +00:00
|
|
|
static int acpi_isa_pnp_probe(device_t bus, device_t child, struct isa_pnp_id *ids);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
static void acpi_probe_children(device_t bus);
|
|
|
|
static ACPI_STATUS acpi_probe_child(ACPI_HANDLE handle, UINT32 level, void *context, void **status);
|
|
|
|
|
|
|
|
static void acpi_shutdown_pre_sync(void *arg, int howto);
|
|
|
|
static void acpi_shutdown_final(void *arg, int howto);
|
|
|
|
|
2001-01-10 18:01:51 +00:00
|
|
|
static void acpi_enable_fixed_events(struct acpi_softc *sc);
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static void acpi_system_eventhandler_sleep(void *arg, int state);
|
|
|
|
static void acpi_system_eventhandler_wakeup(void *arg, int state);
|
2001-01-13 21:28:57 +00:00
|
|
|
static int acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-11-01 16:34:07 +00:00
|
|
|
static int acpi_pm_func(u_long cmd, void *arg, ...);
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static device_method_t acpi_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_identify, acpi_identify),
|
|
|
|
DEVMETHOD(device_probe, acpi_probe),
|
|
|
|
DEVMETHOD(device_attach, acpi_attach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_add_child, acpi_add_child),
|
|
|
|
DEVMETHOD(bus_print_child, acpi_print_child),
|
|
|
|
DEVMETHOD(bus_read_ivar, acpi_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, acpi_write_ivar),
|
|
|
|
DEVMETHOD(bus_set_resource, acpi_set_resource),
|
|
|
|
DEVMETHOD(bus_get_resource, acpi_get_resource),
|
|
|
|
DEVMETHOD(bus_alloc_resource, acpi_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, acpi_release_resource),
|
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
|
|
|
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),
|
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
/* ISA emulation */
|
|
|
|
DEVMETHOD(isa_pnp_probe, acpi_isa_pnp_probe),
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t acpi_driver = {
|
|
|
|
"acpi",
|
|
|
|
acpi_methods,
|
|
|
|
sizeof(struct acpi_softc),
|
|
|
|
};
|
|
|
|
|
2002-01-08 06:46:01 +00:00
|
|
|
static devclass_t acpi_devclass;
|
2001-07-30 08:59:43 +00:00
|
|
|
DRIVER_MODULE(acpi, nexus, acpi_driver, acpi_devclass, acpi_modevent, 0);
|
2001-09-01 22:41:53 +00:00
|
|
|
MODULE_VERSION(acpi, 100);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, acpi_debug_layer, CTLFLAG_RW, &AcpiDbgLayer, 0, "");
|
|
|
|
SYSCTL_INT(_debug, OID_AUTO, acpi_debug_level, CTLFLAG_RW, &AcpiDbgLevel, 0, "");
|
2001-09-01 22:41:53 +00:00
|
|
|
static int acpi_ca_version = ACPI_CA_VERSION;
|
2001-09-02 06:28:20 +00:00
|
|
|
SYSCTL_INT(_debug, OID_AUTO, acpi_ca_version, CTLFLAG_RD, &acpi_ca_version, 0, "");
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-07-30 08:59:43 +00:00
|
|
|
/*
|
|
|
|
* ACPI can only be loaded as a module by the loader; activating it after
|
|
|
|
* system bootstrap time is not useful, and can be fatal to the system.
|
|
|
|
* It also cannot be unloaded, since the entire system bus heirarchy hangs off it.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_modevent(struct module *mod, int event, void *junk)
|
|
|
|
{
|
|
|
|
switch(event) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
if (!cold)
|
|
|
|
return(EPERM);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2001-11-01 16:34:07 +00:00
|
|
|
if (!cold && power_pm_get_type() == POWER_PM_TYPE_ACPI)
|
|
|
|
return(EBUSY);
|
|
|
|
break;
|
2001-07-30 08:59:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Detect ACPI, perform early initialisation
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
2000-12-01 10:18:57 +00:00
|
|
|
device_t child;
|
|
|
|
int error;
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
char *debugpoint;
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-31 11:54:10 +00:00
|
|
|
if(!cold){
|
|
|
|
printf("Don't load this driver from userland!!\n");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2001-09-07 02:57:29 +00:00
|
|
|
/*
|
|
|
|
* Check that we haven't been disabled with a hint.
|
|
|
|
*/
|
|
|
|
if (!resource_int_value("acpi", 0, "disabled", &error) &&
|
|
|
|
(error != 0))
|
|
|
|
return_VOID;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Make sure we're not being doubly invoked.
|
|
|
|
*/
|
|
|
|
if (device_find_child(parent, "acpi", 0) != NULL)
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
/* initialise the ACPI mutex */
|
2002-04-04 21:03:38 +00:00
|
|
|
mtx_init(&acpi_mutex, "ACPI global lock", NULL, MTX_DEF);
|
2001-06-29 20:29:59 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
2001-05-29 20:13:42 +00:00
|
|
|
* Start up the ACPI CA subsystem.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
debugpoint = getenv("debug.acpi.debugger");
|
|
|
|
if (debugpoint) {
|
|
|
|
if (!strcmp(debugpoint, "init"))
|
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(error = AcpiInitializeSubsystem())) {
|
2001-07-21 10:24:37 +00:00
|
|
|
printf("ACPI: initialisation failed: %s\n", AcpiFormatException(error));
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
debugpoint = getenv("debug.acpi.debugger");
|
|
|
|
if (debugpoint) {
|
|
|
|
if (!strcmp(debugpoint, "tables"))
|
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2001-11-06 15:00:30 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(error = AcpiLoadTables())) {
|
2001-07-21 10:24:37 +00:00
|
|
|
printf("ACPI: table load failed: %s\n", AcpiFormatException(error));
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the actual ACPI device.
|
|
|
|
*/
|
|
|
|
if ((child = BUS_ADD_CHILD(parent, 0, "acpi", 0)) == NULL) {
|
|
|
|
device_printf(parent, "ACPI: could not attach\n");
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fetch some descriptive data from ACPI to put in our attach message
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_probe(device_t dev)
|
|
|
|
{
|
|
|
|
ACPI_TABLE_HEADER th;
|
|
|
|
char buf[20];
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_STATUS status;
|
2000-10-28 06:59:48 +00:00
|
|
|
int error;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-11-01 16:34:07 +00:00
|
|
|
|
|
|
|
if (power_pm_get_type() != POWER_PM_TYPE_NONE &&
|
|
|
|
power_pm_get_type() != POWER_PM_TYPE_ACPI) {
|
|
|
|
device_printf(dev, "Other PM system enabled.\n");
|
|
|
|
return_VALUE(ENXIO);
|
|
|
|
}
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_LOCK;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiGetTableHeader(ACPI_TABLE_XSDT, 1, &th))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(dev, "couldn't get XSDT header: %s\n", AcpiFormatException(status));
|
2001-06-29 20:29:59 +00:00
|
|
|
error = ENXIO;
|
|
|
|
} else {
|
|
|
|
sprintf(buf, "%.6s %.8s", th.OemId, th.OemTableId);
|
|
|
|
device_set_desc_copy(dev, buf);
|
|
|
|
error = 0;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_UNLOCK;
|
|
|
|
return_VALUE(error);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc;
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_STATUS status;
|
2000-10-28 06:59:48 +00:00
|
|
|
int error;
|
2001-09-07 02:57:29 +00:00
|
|
|
UINT32 flags;
|
|
|
|
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
char *debugpoint;
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_LOCK;
|
2000-10-28 06:59:48 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
bzero(sc, sizeof(*sc));
|
|
|
|
sc->acpi_dev = dev;
|
|
|
|
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
debugpoint = getenv("debug.acpi.debugger");
|
|
|
|
if (debugpoint) {
|
|
|
|
if (!strcmp(debugpoint, "spaces"))
|
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install the default address space handlers.
|
|
|
|
*/
|
2001-06-29 20:29:59 +00:00
|
|
|
error = ENXIO;
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
2001-05-29 20:13:42 +00:00
|
|
|
ACPI_ADR_SPACE_SYSTEM_MEMORY,
|
2000-10-28 06:59:48 +00:00
|
|
|
ACPI_DEFAULT_HANDLER,
|
2002-02-23 05:21:56 +00:00
|
|
|
NULL, NULL))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(dev, "could not initialise SystemMemory handler: %s\n", AcpiFormatException(status));
|
2001-06-29 20:29:59 +00:00
|
|
|
goto out;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
2001-05-29 20:13:42 +00:00
|
|
|
ACPI_ADR_SPACE_SYSTEM_IO,
|
2000-10-28 06:59:48 +00:00
|
|
|
ACPI_DEFAULT_HANDLER,
|
2002-02-23 05:21:56 +00:00
|
|
|
NULL, NULL))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(dev, "could not initialise SystemIO handler: %s\n", AcpiFormatException(status));
|
2001-06-29 20:29:59 +00:00
|
|
|
goto out;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
2001-05-29 20:13:42 +00:00
|
|
|
ACPI_ADR_SPACE_PCI_CONFIG,
|
2000-10-28 06:59:48 +00:00
|
|
|
ACPI_DEFAULT_HANDLER,
|
2002-02-23 05:21:56 +00:00
|
|
|
NULL, NULL))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(dev, "could not initialise PciConfig handler: %s\n", AcpiFormatException(status));
|
2001-06-29 20:29:59 +00:00
|
|
|
goto out;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bring ACPI fully online.
|
|
|
|
*
|
2001-09-07 02:57:29 +00:00
|
|
|
* Note that some systems (specifically, those with namespace evaluation issues
|
|
|
|
* that require the avoidance of parts of the namespace) must avoid running _INI
|
|
|
|
* and _STA on everything, as well as dodging the final object init pass.
|
|
|
|
*
|
|
|
|
* For these devices, we set ACPI_NO_DEVICE_INIT and ACPI_NO_OBJECT_INIT).
|
2000-10-28 06:59:48 +00:00
|
|
|
*
|
2001-09-07 02:57:29 +00:00
|
|
|
* XXX We should arrange for the object init pass after we have attached all our
|
|
|
|
* child devices, but on many systems it works here.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
debugpoint = getenv("debug.acpi.debugger");
|
|
|
|
if (debugpoint) {
|
|
|
|
if (!strcmp(debugpoint, "enable"))
|
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2001-09-07 02:57:29 +00:00
|
|
|
flags = 0;
|
2002-04-17 13:06:36 +00:00
|
|
|
if (testenv("debug.acpi.avoid"))
|
2001-09-07 02:57:29 +00:00
|
|
|
flags = ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT;
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiEnableSubsystem(flags))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(dev, "could not enable ACPI: %s\n", AcpiFormatException(status));
|
2001-06-29 20:29:59 +00:00
|
|
|
goto out;
|
2002-07-30 19:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ACPI_FAILURE(status = AcpiInitializeObjects(flags))) {
|
|
|
|
device_printf(dev, "could not initialize ACPI objects: %s\n", AcpiFormatException(status));
|
|
|
|
goto out;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-13 21:28:57 +00:00
|
|
|
/*
|
|
|
|
* Setup our sysctl tree.
|
|
|
|
*
|
|
|
|
* XXX: This doesn't check to make sure that none of these fail.
|
|
|
|
*/
|
|
|
|
sysctl_ctx_init(&sc->acpi_sysctl_ctx);
|
|
|
|
sc->acpi_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_sysctl_ctx,
|
|
|
|
SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO,
|
|
|
|
device_get_name(dev), CTLFLAG_RD, 0, "");
|
|
|
|
SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "power_button_state", CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
&sc->acpi_power_button_sx, 0, acpi_sleep_state_sysctl, "A", "");
|
|
|
|
SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "sleep_button_state", CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
&sc->acpi_sleep_button_sx, 0, acpi_sleep_state_sysctl, "A", "");
|
|
|
|
SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "lid_switch_state", CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
&sc->acpi_lid_switch_sx, 0, acpi_sleep_state_sysctl, "A", "");
|
2001-10-26 17:43:05 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "standby_state", CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
&sc->acpi_standby_sx, 0, acpi_sleep_state_sysctl, "A", "");
|
|
|
|
SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "suspend_state", CTLTYPE_STRING | CTLFLAG_RW,
|
|
|
|
&sc->acpi_suspend_sx, 0, acpi_sleep_state_sysctl, "A", "");
|
2002-08-25 06:13:53 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "sleep_delay", CTLFLAG_RD | CTLFLAG_RW,
|
|
|
|
&sc->acpi_sleep_delay, 0, "sleep delay");
|
2001-11-06 15:00:30 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "s4bios", CTLFLAG_RD | CTLFLAG_RW,
|
|
|
|
&sc->acpi_s4bios, 0, "S4BIOS mode");
|
2001-10-29 18:09:43 +00:00
|
|
|
SYSCTL_ADD_INT(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "verbose", CTLFLAG_RD | CTLFLAG_RW,
|
|
|
|
&sc->acpi_verbose, 0, "verbose mode");
|
2002-08-28 18:46:09 +00:00
|
|
|
sc->acpi_sleep_delay = 0;
|
2001-11-30 16:06:00 +00:00
|
|
|
sc->acpi_s4bios = 1;
|
2001-10-29 18:09:43 +00:00
|
|
|
if (bootverbose)
|
|
|
|
sc->acpi_verbose = 1;
|
2001-01-13 21:28:57 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Dispatch the default sleep state to devices.
|
|
|
|
* TBD: should be configured from userland policy manager.
|
|
|
|
*/
|
|
|
|
sc->acpi_power_button_sx = ACPI_POWER_BUTTON_DEFAULT_SX;
|
|
|
|
sc->acpi_sleep_button_sx = ACPI_SLEEP_BUTTON_DEFAULT_SX;
|
|
|
|
sc->acpi_lid_switch_sx = ACPI_LID_SWITCH_DEFAULT_SX;
|
2001-10-26 17:43:05 +00:00
|
|
|
sc->acpi_standby_sx = ACPI_STATE_S1;
|
|
|
|
sc->acpi_suspend_sx = ACPI_STATE_S3;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-01-10 18:01:51 +00:00
|
|
|
acpi_enable_fixed_events(sc);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the namespace and attach/initialise children.
|
|
|
|
*/
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
debugpoint = getenv("debug.acpi.debugger");
|
|
|
|
if (debugpoint) {
|
|
|
|
if (!strcmp(debugpoint, "probe"))
|
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register our shutdown handlers
|
|
|
|
*/
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_pre_sync, acpi_shutdown_pre_sync, sc, SHUTDOWN_PRI_LAST);
|
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, acpi_shutdown_final, sc, SHUTDOWN_PRI_LAST);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register our acpi event handlers.
|
|
|
|
* XXX should be configurable eg. via userland policy manager.
|
|
|
|
*/
|
|
|
|
EVENTHANDLER_REGISTER(acpi_sleep_event, acpi_system_eventhandler_sleep, sc, ACPI_EVENT_PRI_LAST);
|
|
|
|
EVENTHANDLER_REGISTER(acpi_wakeup_event, acpi_system_eventhandler_wakeup, sc, ACPI_EVENT_PRI_LAST);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flag our initial states.
|
|
|
|
*/
|
|
|
|
sc->acpi_enabled = 1;
|
|
|
|
sc->acpi_sstate = ACPI_STATE_S0;
|
2001-12-09 18:02:36 +00:00
|
|
|
sc->acpi_sleep_disabled = 0;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the control device
|
|
|
|
*/
|
|
|
|
sc->acpi_dev_t = make_dev(&acpi_cdevsw, 0, 0, 5, 0660, "acpi");
|
|
|
|
sc->acpi_dev_t->si_drv1 = sc;
|
|
|
|
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2002-04-17 13:06:36 +00:00
|
|
|
debugpoint = getenv("debug.acpi.debugger");
|
|
|
|
if (debugpoint) {
|
|
|
|
if (!strcmp(debugpoint, "running"))
|
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2001-12-22 16:05:41 +00:00
|
|
|
#if defined(ACPI_MAX_THREADS) && ACPI_MAX_THREADS > 0
|
|
|
|
if ((error = acpi_task_thread_init())) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-10-26 17:43:05 +00:00
|
|
|
if ((error = acpi_machdep_init(dev))) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2001-11-01 16:34:07 +00:00
|
|
|
/* Register ACPI again to pass the correct argument of pm_func. */
|
|
|
|
power_pm_register(POWER_PM_TYPE_ACPI, acpi_pm_func, sc);
|
|
|
|
|
2002-09-06 17:01:06 +00:00
|
|
|
if (!acpi_disabled("bus"))
|
|
|
|
acpi_probe_children(dev);
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
error = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
ACPI_UNLOCK;
|
|
|
|
return_VALUE(error);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a new device being added
|
|
|
|
*/
|
|
|
|
static device_t
|
|
|
|
acpi_add_child(device_t bus, int order, const char *name, int unit)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad;
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
if ((ad = malloc(sizeof(*ad), M_ACPIDEV, M_NOWAIT)) == NULL)
|
|
|
|
return(NULL);
|
|
|
|
bzero(ad, sizeof(*ad));
|
|
|
|
|
|
|
|
resource_list_init(&ad->ad_rl);
|
|
|
|
|
|
|
|
child = device_add_child_ordered(bus, order, name, unit);
|
|
|
|
if (child != NULL)
|
|
|
|
device_set_ivars(child, ad);
|
|
|
|
return(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_print_child(device_t bus, device_t child)
|
|
|
|
{
|
|
|
|
struct acpi_device *adev = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &adev->ad_rl;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
retval += bus_print_child_header(bus, child);
|
2002-09-04 03:11:20 +00:00
|
|
|
retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
|
|
|
|
retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
|
|
|
|
retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
|
|
|
|
retval += resource_list_print_type(rl, "drq", SYS_RES_DRQ, "%ld");
|
2000-10-28 06:59:48 +00:00
|
|
|
retval += bus_print_child_footer(bus, child);
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle per-device ivars
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad;
|
|
|
|
|
|
|
|
if ((ad = device_get_ivars(child)) == NULL) {
|
|
|
|
printf("device has no ivars\n");
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(index) {
|
|
|
|
/* ACPI ivars */
|
|
|
|
case ACPI_IVAR_HANDLE:
|
|
|
|
*(ACPI_HANDLE *)result = ad->ad_handle;
|
|
|
|
break;
|
|
|
|
case ACPI_IVAR_MAGIC:
|
|
|
|
*(int *)result = ad->ad_magic;
|
|
|
|
break;
|
|
|
|
case ACPI_IVAR_PRIVATE:
|
|
|
|
*(void **)result = ad->ad_private;
|
|
|
|
break;
|
|
|
|
|
2001-09-07 02:57:29 +00:00
|
|
|
/* ISA compatibility */
|
|
|
|
case ISA_IVAR_VENDORID:
|
|
|
|
case ISA_IVAR_SERIAL:
|
|
|
|
case ISA_IVAR_COMPATID:
|
|
|
|
*(int *)result = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISA_IVAR_LOGICALID:
|
|
|
|
*(int *)result = acpi_isa_get_logicalid(child);
|
|
|
|
break;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
default:
|
2002-08-12 22:36:18 +00:00
|
|
|
panic("bad ivar read request (%d)", index);
|
2000-10-28 06:59:48 +00:00
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_write_ivar(device_t dev, device_t child, int index, uintptr_t value)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad;
|
|
|
|
|
|
|
|
if ((ad = device_get_ivars(child)) == NULL) {
|
|
|
|
printf("device has no ivars\n");
|
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(index) {
|
|
|
|
/* ACPI ivars */
|
|
|
|
case ACPI_IVAR_HANDLE:
|
|
|
|
ad->ad_handle = (ACPI_HANDLE)value;
|
|
|
|
break;
|
|
|
|
case ACPI_IVAR_MAGIC:
|
|
|
|
ad->ad_magic = (int )value;
|
|
|
|
break;
|
|
|
|
case ACPI_IVAR_PRIVATE:
|
|
|
|
ad->ad_private = (void *)value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-08-12 22:36:18 +00:00
|
|
|
panic("bad ivar write request (%d)", index);
|
2000-10-28 06:59:48 +00:00
|
|
|
return(ENOENT);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle child resource allocation/removal
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_set_resource(device_t dev, device_t child, int type, int rid, u_long start, u_long count)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &ad->ad_rl;
|
|
|
|
|
|
|
|
resource_list_add(rl, type, rid, start, start + count -1, count);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_get_resource(device_t dev, device_t child, int type, int rid, u_long *startp, u_long *countp)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &ad->ad_rl;
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (!rle)
|
|
|
|
return(ENOENT);
|
|
|
|
|
|
|
|
if (startp)
|
|
|
|
*startp = rle->start;
|
|
|
|
if (countp)
|
|
|
|
*countp = rle->count;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource *
|
|
|
|
acpi_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &ad->ad_rl;
|
|
|
|
|
|
|
|
return(resource_list_alloc(rl, bus, child, type, rid, start, end, count, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_release_resource(device_t bus, device_t child, int type, int rid, struct resource *r)
|
|
|
|
{
|
|
|
|
struct acpi_device *ad = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &ad->ad_rl;
|
|
|
|
|
|
|
|
return(resource_list_release(rl, bus, child, type, rid, r));
|
|
|
|
}
|
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
/*
|
|
|
|
* Handle ISA-like devices probing for a PnP ID to match.
|
|
|
|
*/
|
|
|
|
#define PNP_EISAID(s) \
|
|
|
|
((((s[0] - '@') & 0x1f) << 2) \
|
|
|
|
| (((s[1] - '@') & 0x18) >> 3) \
|
|
|
|
| (((s[1] - '@') & 0x07) << 13) \
|
|
|
|
| (((s[2] - '@') & 0x1f) << 8) \
|
|
|
|
| (PNP_HEXTONUM(s[4]) << 16) \
|
|
|
|
| (PNP_HEXTONUM(s[3]) << 20) \
|
|
|
|
| (PNP_HEXTONUM(s[6]) << 24) \
|
|
|
|
| (PNP_HEXTONUM(s[5]) << 28))
|
|
|
|
|
2001-09-07 02:57:29 +00:00
|
|
|
static u_int32_t
|
|
|
|
acpi_isa_get_logicalid(device_t dev)
|
2001-08-30 00:50:58 +00:00
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_DEVICE_INFO devinfo;
|
|
|
|
ACPI_STATUS error;
|
|
|
|
u_int32_t pnpid;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-08-30 00:50:58 +00:00
|
|
|
|
2001-09-07 02:57:29 +00:00
|
|
|
pnpid = 0;
|
2001-08-30 00:50:58 +00:00
|
|
|
ACPI_LOCK;
|
2001-09-07 02:57:29 +00:00
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
/* fetch and validate the HID */
|
2001-09-07 02:57:29 +00:00
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
2001-08-30 00:50:58 +00:00
|
|
|
goto out;
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(error = AcpiGetObjectInfo(h, &devinfo)))
|
2001-08-30 00:50:58 +00:00
|
|
|
goto out;
|
|
|
|
if (!(devinfo.Valid & ACPI_VALID_HID))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
pnpid = PNP_EISAID(devinfo.HardwareId);
|
2001-09-07 02:57:29 +00:00
|
|
|
out:
|
|
|
|
ACPI_UNLOCK;
|
|
|
|
return_VALUE(pnpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_isa_pnp_probe(device_t bus, device_t child, struct isa_pnp_id *ids)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
u_int32_t pnpid;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-09-07 02:57:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ISA-style drivers attached to ACPI may persist and
|
|
|
|
* probe manually if we return ENOENT. We never want
|
|
|
|
* that to happen, so don't ever return it.
|
|
|
|
*/
|
|
|
|
result = ENXIO;
|
|
|
|
|
|
|
|
/* scan the supplied IDs for a match */
|
|
|
|
pnpid = acpi_isa_get_logicalid(child);
|
2001-08-30 00:50:58 +00:00
|
|
|
while (ids && ids->ip_id) {
|
|
|
|
if (pnpid == ids->ip_id) {
|
|
|
|
result = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ids++;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return_VALUE(result);
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Scan relevant portions of the ACPI namespace and attach child devices.
|
|
|
|
*
|
2001-07-07 10:20:17 +00:00
|
|
|
* Note that we only expect to find devices in the \_PR_, \_TZ_, \_SI_ and \_SB_ scopes,
|
|
|
|
* and \_PR_ and \_TZ_ become obsolete in the ACPI 2.0 spec.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_probe_children(device_t bus)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE parent;
|
2001-07-07 10:20:17 +00:00
|
|
|
static char *scopes[] = {"\\_PR_", "\\_TZ_", "\\_SI", "\\_SB_", NULL};
|
2000-10-28 06:59:48 +00:00
|
|
|
int i;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Create any static children by calling device identify methods.
|
|
|
|
*/
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "device identify routines\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
bus_generic_probe(bus);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the namespace and insert placeholders for all the devices that
|
|
|
|
* we find.
|
|
|
|
*
|
|
|
|
* Note that we use AcpiWalkNamespace rather than AcpiGetDevices because
|
|
|
|
* we want to create nodes for all devices, not just those that are currently
|
|
|
|
* present. (This assumes that we don't want to create/remove devices as they
|
|
|
|
* appear, which might be smarter.)
|
|
|
|
*/
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "namespace scan\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
for (i = 0; scopes[i] != NULL; i++)
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetHandle(ACPI_ROOT_OBJECT, scopes[i], &parent)))
|
2000-10-28 06:59:48 +00:00
|
|
|
AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100, acpi_probe_child, bus, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan all of the child devices we have created and let them probe/attach.
|
|
|
|
*/
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "first bus_generic_attach\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
bus_generic_attach(bus);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some of these children may have attached others as part of their attach
|
|
|
|
* process (eg. the root PCI bus driver), so rescan.
|
|
|
|
*/
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "second bus_generic_attach\n"));
|
2000-10-28 06:59:48 +00:00
|
|
|
bus_generic_attach(bus);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "done attaching children\n"));
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate a child device and determine whether we might attach a device to
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_probe_child(ACPI_HANDLE handle, UINT32 level, void *context, void **status)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT_TYPE type;
|
|
|
|
device_t child, bus = (device_t)context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip this device if we think we'll have trouble with it.
|
|
|
|
*/
|
|
|
|
if (acpi_avoid(handle))
|
|
|
|
return_ACPI_STATUS(AE_OK);
|
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetType(handle, &type))) {
|
2000-10-28 06:59:48 +00:00
|
|
|
switch(type) {
|
|
|
|
case ACPI_TYPE_DEVICE:
|
|
|
|
case ACPI_TYPE_PROCESSOR:
|
|
|
|
case ACPI_TYPE_THERMAL:
|
|
|
|
case ACPI_TYPE_POWER:
|
2000-12-08 09:16:20 +00:00
|
|
|
if (acpi_disabled("children"))
|
|
|
|
break;
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Create a placeholder device for this node. Sort the placeholder
|
|
|
|
* so that the probe/attach passes will run breadth-first.
|
|
|
|
*/
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "scanning '%s'\n", acpi_name(handle)));
|
2000-10-28 06:59:48 +00:00
|
|
|
child = BUS_ADD_CHILD(bus, level * 10, NULL, -1);
|
2001-08-30 00:50:58 +00:00
|
|
|
if (child == NULL)
|
|
|
|
break;
|
2000-10-28 06:59:48 +00:00
|
|
|
acpi_set_handle(child, handle);
|
2001-08-30 00:50:58 +00:00
|
|
|
|
2001-09-15 04:14:31 +00:00
|
|
|
/*
|
|
|
|
* Check that the device is present. If it's not present,
|
|
|
|
* leave it disabled (so that we have a device_t attached to
|
|
|
|
* the handle, but we don't probe it).
|
|
|
|
*/
|
2001-09-17 15:11:55 +00:00
|
|
|
if ((type == ACPI_TYPE_DEVICE) && (!acpi_DeviceIsPresent(child))) {
|
2001-09-15 04:14:31 +00:00
|
|
|
device_disable(child);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
/*
|
|
|
|
* Get the device's resource settings and attach them.
|
|
|
|
* Note that if the device has _PRS but no _CRS, we need
|
|
|
|
* to decide when it's appropriate to try to configure the
|
|
|
|
* device. Ignore the return value here; it's OK for the
|
|
|
|
* device not to have any resources.
|
|
|
|
*/
|
|
|
|
acpi_parse_resources(child, handle, &acpi_res_parse_set);
|
|
|
|
|
|
|
|
/* if we're debugging, probe/attach now rather than later */
|
2002-02-23 05:21:56 +00:00
|
|
|
ACPI_DEBUG_EXEC(device_probe_and_attach(child));
|
2000-12-08 09:16:20 +00:00
|
|
|
break;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-08 09:16:20 +00:00
|
|
|
return_ACPI_STATUS(AE_OK);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_shutdown_pre_sync(void *arg, int howto)
|
|
|
|
{
|
2001-06-29 20:29:59 +00:00
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
2000-12-08 09:16:20 +00:00
|
|
|
* Disable all ACPI events before soft off, otherwise the system
|
2000-10-28 06:59:48 +00:00
|
|
|
* will be turned on again on some laptops.
|
|
|
|
*
|
|
|
|
* XXX this should probably be restricted to masking some events just
|
|
|
|
* before powering down, since we may still need ACPI during the
|
|
|
|
* shutdown process.
|
|
|
|
*/
|
|
|
|
acpi_Disable((struct acpi_softc *)arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_shutdown_final(void *arg, int howto)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2000-12-19 15:45:11 +00:00
|
|
|
if (howto & RB_POWEROFF) {
|
2000-10-28 06:59:48 +00:00
|
|
|
printf("Power system off using ACPI...\n");
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiEnterSleepStatePrep(acpi_off_state))) {
|
2001-11-28 12:09:42 +00:00
|
|
|
printf("AcpiEnterSleepStatePrep failed - %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
return;
|
|
|
|
}
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiEnterSleepState(acpi_off_state))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
printf("ACPI power-off failed - %s\n", AcpiFormatException(status));
|
2000-10-28 06:59:48 +00:00
|
|
|
} else {
|
|
|
|
DELAY(1000000);
|
|
|
|
printf("ACPI power-off failed - timeout\n");
|
|
|
|
}
|
2002-05-19 15:12:40 +00:00
|
|
|
} else {
|
|
|
|
printf("Terminate ACPI\n");
|
|
|
|
AcpiTerminate();
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-10 18:01:51 +00:00
|
|
|
static void
|
|
|
|
acpi_enable_fixed_events(struct acpi_softc *sc)
|
|
|
|
{
|
2001-06-29 20:29:59 +00:00
|
|
|
static int first_time = 1;
|
2001-01-10 18:01:51 +00:00
|
|
|
#define MSGFORMAT "%s button is handled as a fixed feature programming model.\n"
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
|
|
|
/* Enable and clear fixed events and install handlers. */
|
|
|
|
if ((AcpiGbl_FADT != NULL) && (AcpiGbl_FADT->PwrButton == 0)) {
|
2001-10-04 23:21:09 +00:00
|
|
|
AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, ACPI_EVENT_FIXED, 0);
|
2001-06-29 20:29:59 +00:00
|
|
|
AcpiClearEvent(ACPI_EVENT_POWER_BUTTON, ACPI_EVENT_FIXED);
|
|
|
|
AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON,
|
|
|
|
acpi_eventhandler_power_button_for_sleep, sc);
|
|
|
|
if (first_time) {
|
|
|
|
device_printf(sc->acpi_dev, MSGFORMAT, "power");
|
2001-01-10 18:01:51 +00:00
|
|
|
}
|
2001-06-29 20:29:59 +00:00
|
|
|
}
|
|
|
|
if ((AcpiGbl_FADT != NULL) && (AcpiGbl_FADT->SleepButton == 0)) {
|
2001-10-04 23:21:09 +00:00
|
|
|
AcpiEnableEvent(ACPI_EVENT_SLEEP_BUTTON, ACPI_EVENT_FIXED, 0);
|
2001-06-29 20:29:59 +00:00
|
|
|
AcpiClearEvent(ACPI_EVENT_SLEEP_BUTTON, ACPI_EVENT_FIXED);
|
|
|
|
AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON,
|
|
|
|
acpi_eventhandler_sleep_button_for_sleep, sc);
|
|
|
|
if (first_time) {
|
|
|
|
device_printf(sc->acpi_dev, MSGFORMAT, "sleep");
|
2001-01-10 18:01:51 +00:00
|
|
|
}
|
2001-06-29 20:29:59 +00:00
|
|
|
}
|
2001-01-10 18:01:51 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
first_time = 0;
|
2001-01-10 18:01:51 +00:00
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Returns true if the device is actually present and should
|
|
|
|
* be attached to. This requires the present, enabled, UI-visible
|
|
|
|
* and diagnostics-passed bits to be set.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
acpi_DeviceIsPresent(device_t dev)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_DEVICE_INFO devinfo;
|
|
|
|
ACPI_STATUS error;
|
2001-06-29 20:29:59 +00:00
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
|
|
|
return(FALSE);
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(error = AcpiGetObjectInfo(h, &devinfo)))
|
2001-06-28 06:17:16 +00:00
|
|
|
return(FALSE);
|
2001-10-04 23:21:09 +00:00
|
|
|
/* if no _STA method, must be present */
|
|
|
|
if (!(devinfo.Valid & ACPI_VALID_STA))
|
|
|
|
return(TRUE);
|
|
|
|
/* return true for 'present' and 'functioning' */
|
|
|
|
if ((devinfo.CurrentStatus & 0x9) == 0x9)
|
2001-06-28 06:17:16 +00:00
|
|
|
return(TRUE);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
/*
|
|
|
|
* Returns true if the battery is actually present and inserted.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
acpi_BatteryIsPresent(device_t dev)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_DEVICE_INFO devinfo;
|
|
|
|
ACPI_STATUS error;
|
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
|
|
|
return(FALSE);
|
|
|
|
if (ACPI_FAILURE(error = AcpiGetObjectInfo(h, &devinfo)))
|
|
|
|
return(FALSE);
|
|
|
|
/* if no _STA method, must be present */
|
|
|
|
if (!(devinfo.Valid & ACPI_VALID_STA))
|
|
|
|
return(TRUE);
|
|
|
|
/* return true for 'present' and 'functioning' */
|
|
|
|
if ((devinfo.CurrentStatus & 0x19) == 0x19)
|
|
|
|
return(TRUE);
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Match a HID string against a device
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
acpi_MatchHid(device_t dev, char *hid)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_DEVICE_INFO devinfo;
|
|
|
|
ACPI_STATUS error;
|
2001-10-04 08:31:17 +00:00
|
|
|
int cid;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2000-12-05 00:19:10 +00:00
|
|
|
if (hid == NULL)
|
2000-10-28 06:59:48 +00:00
|
|
|
return(FALSE);
|
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
|
|
|
return(FALSE);
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(error = AcpiGetObjectInfo(h, &devinfo)))
|
2000-10-28 06:59:48 +00:00
|
|
|
return(FALSE);
|
2000-12-05 00:19:10 +00:00
|
|
|
if ((devinfo.Valid & ACPI_VALID_HID) && !strcmp(hid, devinfo.HardwareId))
|
2000-10-28 06:59:48 +00:00
|
|
|
return(TRUE);
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(error = acpi_EvaluateInteger(h, "_CID", &cid)))
|
2001-10-04 08:31:17 +00:00
|
|
|
return(FALSE);
|
|
|
|
if (cid == PNP_EISAID(hid))
|
|
|
|
return(TRUE);
|
2000-10-28 06:59:48 +00:00
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Return the handle of a named object within our scope, ie. that of (parent)
|
|
|
|
* or one if its parents.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_GetHandleInScope(ACPI_HANDLE parent, char *path, ACPI_HANDLE *result)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE r;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/* walk back up the tree to the root */
|
|
|
|
for (;;) {
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(status = AcpiGetHandle(parent, path, &r))) {
|
2001-06-28 06:17:16 +00:00
|
|
|
*result = r;
|
|
|
|
return(AE_OK);
|
|
|
|
}
|
|
|
|
if (status != AE_NOT_FOUND)
|
|
|
|
return(AE_OK);
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(AcpiGetParent(parent, &r)))
|
2001-06-28 06:17:16 +00:00
|
|
|
return(AE_NOT_FOUND);
|
|
|
|
parent = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a buffer with a preset data size.
|
|
|
|
*/
|
|
|
|
ACPI_BUFFER *
|
|
|
|
acpi_AllocBuffer(int size)
|
|
|
|
{
|
|
|
|
ACPI_BUFFER *buf;
|
|
|
|
|
|
|
|
if ((buf = malloc(size + sizeof(*buf), M_ACPIDEV, M_NOWAIT)) == NULL)
|
|
|
|
return(NULL);
|
|
|
|
buf->Length = size;
|
|
|
|
buf->Pointer = (void *)(buf + 1);
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate a path that should return an integer.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int *number)
|
|
|
|
{
|
|
|
|
ACPI_STATUS error;
|
|
|
|
ACPI_BUFFER buf;
|
2001-12-22 16:05:41 +00:00
|
|
|
ACPI_OBJECT param;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
if (handle == NULL)
|
|
|
|
handle = ACPI_ROOT_OBJECT;
|
2001-09-06 23:16:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Assume that what we've been pointed at is an Integer object, or
|
|
|
|
* a method that will return an Integer.
|
|
|
|
*/
|
2001-06-28 06:17:16 +00:00
|
|
|
buf.Pointer = ¶m;
|
|
|
|
buf.Length = sizeof(param);
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(error = AcpiEvaluateObject(handle, path, NULL, &buf))) {
|
2001-06-28 06:17:16 +00:00
|
|
|
if (param.Type == ACPI_TYPE_INTEGER) {
|
|
|
|
*number = param.Integer.Value;
|
|
|
|
} else {
|
|
|
|
error = AE_TYPE;
|
|
|
|
}
|
|
|
|
}
|
2001-09-06 23:16:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In some applications, a method that's expected to return an Integer
|
|
|
|
* may instead return a Buffer (probably to simplify some internal
|
|
|
|
* arithmetic). We'll try to fetch whatever it is, and if it's a Buffer,
|
|
|
|
* convert it into an Integer as best we can.
|
|
|
|
*
|
|
|
|
* This is a hack.
|
|
|
|
*/
|
|
|
|
if (error == AE_BUFFER_OVERFLOW) {
|
2002-02-23 05:21:56 +00:00
|
|
|
if ((buf.Pointer = AcpiOsAllocate(buf.Length)) == NULL) {
|
2001-09-06 23:16:55 +00:00
|
|
|
error = AE_NO_MEMORY;
|
|
|
|
} else {
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(error = AcpiEvaluateObject(handle, path, NULL, &buf))) {
|
2001-12-22 16:05:41 +00:00
|
|
|
error = acpi_ConvertBufferToInteger(&buf, number);
|
2001-09-06 23:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2001-12-22 16:05:41 +00:00
|
|
|
ACPI_STATUS
|
|
|
|
acpi_ConvertBufferToInteger(ACPI_BUFFER *bufp, int *number)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
p = (ACPI_OBJECT *)bufp->Pointer;
|
|
|
|
if (p->Type == ACPI_TYPE_INTEGER) {
|
|
|
|
*number = p->Integer.Value;
|
|
|
|
return(AE_OK);
|
|
|
|
}
|
|
|
|
if (p->Type != ACPI_TYPE_BUFFER)
|
|
|
|
return(AE_TYPE);
|
|
|
|
if (p->Buffer.Length > sizeof(int))
|
|
|
|
return(AE_BAD_DATA);
|
|
|
|
*number = 0;
|
|
|
|
for (i = 0; i < p->Buffer.Length; i++)
|
|
|
|
*number += (*(p->Buffer.Pointer + i) << (i * 8));
|
|
|
|
return(AE_OK);
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Iterate over the elements of an a package object, calling the supplied
|
|
|
|
* function for each element.
|
|
|
|
*
|
|
|
|
* XXX possible enhancement might be to abort traversal on error.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_ForeachPackageObject(ACPI_OBJECT *pkg, void (* func)(ACPI_OBJECT *comp, void *arg), void *arg)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT *comp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((pkg == NULL) || (pkg->Type != ACPI_TYPE_PACKAGE))
|
|
|
|
return(AE_BAD_PARAMETER);
|
|
|
|
|
|
|
|
/* iterate over components */
|
|
|
|
for (i = 0, comp = pkg->Package.Elements; i < pkg->Package.Count; i++, comp++)
|
|
|
|
func(comp, arg);
|
|
|
|
|
|
|
|
return(AE_OK);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2001-07-05 07:14:30 +00:00
|
|
|
/*
|
|
|
|
* Find the (index)th resource object in a set.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
2001-07-30 08:59:43 +00:00
|
|
|
acpi_FindIndexedResource(ACPI_BUFFER *buf, int index, ACPI_RESOURCE **resp)
|
2001-07-05 07:14:30 +00:00
|
|
|
{
|
2001-07-30 08:59:43 +00:00
|
|
|
ACPI_RESOURCE *rp;
|
2001-07-05 07:14:30 +00:00
|
|
|
int i;
|
|
|
|
|
2001-07-30 08:59:43 +00:00
|
|
|
rp = (ACPI_RESOURCE *)buf->Pointer;
|
2001-07-05 07:14:30 +00:00
|
|
|
i = index;
|
2001-07-30 08:59:43 +00:00
|
|
|
while (i-- > 0) {
|
|
|
|
/* range check */
|
|
|
|
if (rp > (ACPI_RESOURCE *)((u_int8_t *)buf->Pointer + buf->Length))
|
2001-07-05 07:14:30 +00:00
|
|
|
return(AE_BAD_PARAMETER);
|
2001-07-30 08:59:43 +00:00
|
|
|
/* check for terminator */
|
|
|
|
if ((rp->Id == ACPI_RSTYPE_END_TAG) ||
|
|
|
|
(rp->Length == 0))
|
|
|
|
return(AE_NOT_FOUND);
|
|
|
|
rp = ACPI_RESOURCE_NEXT(rp);
|
2001-07-05 07:14:30 +00:00
|
|
|
}
|
|
|
|
if (resp != NULL)
|
2001-07-30 08:59:43 +00:00
|
|
|
*resp = rp;
|
|
|
|
return(AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append an ACPI_RESOURCE to an ACPI_BUFFER.
|
|
|
|
*
|
|
|
|
* Given a pointer to an ACPI_RESOURCE structure, expand the ACPI_BUFFER
|
|
|
|
* provided to contain it. If the ACPI_BUFFER is empty, allocate a sensible
|
|
|
|
* backing block. If the ACPI_RESOURCE is NULL, return an empty set of
|
|
|
|
* resources.
|
|
|
|
*/
|
|
|
|
#define ACPI_INITIAL_RESOURCE_BUFFER_SIZE 512
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_AppendBufferResource(ACPI_BUFFER *buf, ACPI_RESOURCE *res)
|
|
|
|
{
|
|
|
|
ACPI_RESOURCE *rp;
|
|
|
|
void *newp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the buffer if necessary.
|
|
|
|
*/
|
|
|
|
if (buf->Pointer == NULL) {
|
|
|
|
buf->Length = ACPI_INITIAL_RESOURCE_BUFFER_SIZE;
|
|
|
|
if ((buf->Pointer = AcpiOsAllocate(buf->Length)) == NULL)
|
|
|
|
return(AE_NO_MEMORY);
|
|
|
|
rp = (ACPI_RESOURCE *)buf->Pointer;
|
|
|
|
rp->Id = ACPI_RSTYPE_END_TAG;
|
|
|
|
rp->Length = 0;
|
|
|
|
}
|
|
|
|
if (res == NULL)
|
|
|
|
return(AE_OK);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the current buffer looking for the terminator.
|
|
|
|
* This will either find the terminator or hit the end
|
|
|
|
* of the buffer and return an error.
|
|
|
|
*/
|
|
|
|
rp = (ACPI_RESOURCE *)buf->Pointer;
|
|
|
|
for (;;) {
|
|
|
|
/* range check, don't go outside the buffer */
|
|
|
|
if (rp >= (ACPI_RESOURCE *)((u_int8_t *)buf->Pointer + buf->Length))
|
|
|
|
return(AE_BAD_PARAMETER);
|
|
|
|
if ((rp->Id == ACPI_RSTYPE_END_TAG) ||
|
|
|
|
(rp->Length == 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rp = ACPI_RESOURCE_NEXT(rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the size of the buffer and expand if required.
|
|
|
|
*
|
|
|
|
* Required size is:
|
|
|
|
* size of existing resources before terminator +
|
|
|
|
* size of new resource and header +
|
|
|
|
* size of terminator.
|
|
|
|
*
|
|
|
|
* Note that this loop should really only run once, unless
|
|
|
|
* for some reason we are stuffing a *really* huge resource.
|
|
|
|
*/
|
|
|
|
while ((((u_int8_t *)rp - (u_int8_t *)buf->Pointer) +
|
|
|
|
res->Length + ACPI_RESOURCE_LENGTH_NO_DATA +
|
|
|
|
ACPI_RESOURCE_LENGTH) >= buf->Length) {
|
|
|
|
if ((newp = AcpiOsAllocate(buf->Length * 2)) == NULL)
|
|
|
|
return(AE_NO_MEMORY);
|
|
|
|
bcopy(buf->Pointer, newp, buf->Length);
|
2001-08-03 08:38:11 +00:00
|
|
|
rp = (ACPI_RESOURCE *)((u_int8_t *)newp +
|
|
|
|
((u_int8_t *)rp - (u_int8_t *)buf->Pointer));
|
2001-07-30 08:59:43 +00:00
|
|
|
AcpiOsFree(buf->Pointer);
|
|
|
|
buf->Pointer = newp;
|
|
|
|
buf->Length += buf->Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert the new resource.
|
|
|
|
*/
|
|
|
|
bcopy(res, rp, res->Length + ACPI_RESOURCE_LENGTH_NO_DATA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And add the terminator.
|
|
|
|
*/
|
|
|
|
rp = ACPI_RESOURCE_NEXT(rp);
|
|
|
|
rp->Id = ACPI_RSTYPE_END_TAG;
|
|
|
|
rp->Length = 0;
|
|
|
|
|
2001-07-05 07:14:30 +00:00
|
|
|
return(AE_OK);
|
|
|
|
}
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2002-09-06 16:08:08 +00:00
|
|
|
/*
|
|
|
|
* Set interrupt model.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_SetIntrModel(int model)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT_LIST ArgList;
|
|
|
|
ACPI_OBJECT Arg;
|
|
|
|
|
|
|
|
Arg.Type = ACPI_TYPE_INTEGER;
|
|
|
|
Arg.Integer.Value = model;
|
|
|
|
ArgList.Count = 1;
|
|
|
|
ArgList.Pointer = &Arg;
|
|
|
|
return (AcpiEvaluateObject(ACPI_ROOT_OBJECT, "_PIC", &ArgList, NULL));
|
|
|
|
}
|
|
|
|
|
2001-12-09 18:02:36 +00:00
|
|
|
#define ACPI_MINIMUM_AWAKETIME 5
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_sleep_enable(void *arg)
|
|
|
|
{
|
|
|
|
((struct acpi_softc *)arg)->acpi_sleep_disabled = 0;
|
|
|
|
}
|
2001-03-07 15:22:14 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Set the system sleep state
|
|
|
|
*
|
|
|
|
* Currently we only support S1 and S5
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_SetSleepState(struct acpi_softc *sc, int state)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status = AE_OK;
|
2001-07-22 19:13:54 +00:00
|
|
|
UINT8 TypeA;
|
|
|
|
UINT8 TypeB;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, state);
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-11-23 05:57:03 +00:00
|
|
|
if (sc->acpi_sstate != ACPI_STATE_S0)
|
|
|
|
return_ACPI_STATUS(AE_BAD_PARAMETER); /* avoid reentry */
|
|
|
|
|
2001-12-09 18:02:36 +00:00
|
|
|
if (sc->acpi_sleep_disabled)
|
|
|
|
return_ACPI_STATUS(AE_OK);
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
switch (state) {
|
|
|
|
case ACPI_STATE_S0: /* XXX only for testing */
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiEnterSleepState((UINT8)state))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(sc->acpi_dev, "AcpiEnterSleepState failed - %s\n", AcpiFormatException(status));
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_STATE_S1:
|
2001-07-20 06:07:34 +00:00
|
|
|
case ACPI_STATE_S2:
|
|
|
|
case ACPI_STATE_S3:
|
|
|
|
case ACPI_STATE_S4:
|
2002-07-09 17:54:02 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiGetSleepTypeData((UINT8)state, &TypeA, &TypeB))) {
|
|
|
|
device_printf(sc->acpi_dev, "AcpiGetSleepTypeData failed - %s\n", AcpiFormatException(status));
|
2001-07-22 19:13:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-22 12:52:54 +00:00
|
|
|
sc->acpi_sstate = state;
|
|
|
|
sc->acpi_sleep_disabled = 1;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Inform all devices that we are going to sleep.
|
|
|
|
*/
|
|
|
|
if (DEVICE_SUSPEND(root_bus) != 0) {
|
|
|
|
/*
|
|
|
|
* Re-wake the system.
|
|
|
|
*
|
|
|
|
* XXX note that a better two-pass approach with a 'veto' pass
|
|
|
|
* followed by a "real thing" pass would be better, but the
|
|
|
|
* current bus interface does not provide for this.
|
|
|
|
*/
|
|
|
|
DEVICE_RESUME(root_bus);
|
2000-12-08 09:16:20 +00:00
|
|
|
return_ACPI_STATUS(AE_ERROR);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-11-28 12:09:42 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiEnterSleepStatePrep(state))) {
|
2001-11-28 12:09:42 +00:00
|
|
|
device_printf(sc->acpi_dev, "AcpiEnterSleepStatePrep failed - %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-08-25 06:13:53 +00:00
|
|
|
if (sc->acpi_sleep_delay > 0) {
|
|
|
|
DELAY(sc->acpi_sleep_delay * 1000000);
|
|
|
|
}
|
|
|
|
|
2001-07-20 06:07:34 +00:00
|
|
|
if (state != ACPI_STATE_S1) {
|
|
|
|
acpi_sleep_machdep(sc, state);
|
|
|
|
|
2002-07-22 12:52:54 +00:00
|
|
|
/* AcpiEnterSleepState() maybe incompleted, unlock here if locked. */
|
|
|
|
if (AcpiGbl_AcpiMutexInfo[ACPI_MTX_HARDWARE].OwnerId != ACPI_MUTEX_NOT_ACQUIRED) {
|
|
|
|
AcpiUtReleaseMutex(ACPI_MTX_HARDWARE);
|
|
|
|
}
|
2001-07-20 06:07:34 +00:00
|
|
|
|
|
|
|
/* Re-enable ACPI hardware on wakeup from sleep state 4. */
|
2001-11-15 15:12:08 +00:00
|
|
|
if (state == ACPI_STATE_S4) {
|
|
|
|
AcpiEnable();
|
2001-07-20 06:07:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiEnterSleepState((UINT8)state))) {
|
2001-07-21 10:24:37 +00:00
|
|
|
device_printf(sc->acpi_dev, "AcpiEnterSleepState failed - %s\n", AcpiFormatException(status));
|
2001-07-20 06:07:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-08-31 05:36:48 +00:00
|
|
|
AcpiLeaveSleepState((UINT8)state);
|
2000-10-28 06:59:48 +00:00
|
|
|
DEVICE_RESUME(root_bus);
|
|
|
|
sc->acpi_sstate = ACPI_STATE_S0;
|
2001-01-10 18:01:51 +00:00
|
|
|
acpi_enable_fixed_events(sc);
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_STATE_S5:
|
|
|
|
/*
|
|
|
|
* Shut down cleanly and power off. This will call us back through the
|
|
|
|
* shutdown handlers.
|
|
|
|
*/
|
|
|
|
shutdown_nice(RB_POWEROFF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
status = AE_BAD_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2001-12-09 18:02:36 +00:00
|
|
|
|
|
|
|
if (sc->acpi_sleep_disabled)
|
|
|
|
timeout(acpi_sleep_enable, (caddr_t)sc, hz * ACPI_MINIMUM_AWAKETIME);
|
|
|
|
|
2000-12-08 09:16:20 +00:00
|
|
|
return_ACPI_STATUS(status);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable/Disable ACPI
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_Enable(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
u_int32_t flags;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
flags = ACPI_NO_ADDRESS_SPACE_INIT | ACPI_NO_HARDWARE_INIT |
|
|
|
|
ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT;
|
|
|
|
if (!sc->acpi_enabled) {
|
|
|
|
status = AcpiEnableSubsystem(flags);
|
|
|
|
} else {
|
|
|
|
status = AE_OK;
|
|
|
|
}
|
|
|
|
if (status == AE_OK)
|
|
|
|
sc->acpi_enabled = 1;
|
2000-12-08 09:16:20 +00:00
|
|
|
return_ACPI_STATUS(status);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_Disable(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
if (sc->acpi_enabled) {
|
|
|
|
status = AcpiDisable();
|
|
|
|
} else {
|
|
|
|
status = AE_OK;
|
|
|
|
}
|
|
|
|
if (status == AE_OK)
|
|
|
|
sc->acpi_enabled = 0;
|
2000-12-08 09:16:20 +00:00
|
|
|
return_ACPI_STATUS(status);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPI Event Handlers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* System Event Handlers (registered by EVENTHANDLER_REGISTER) */
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_system_eventhandler_sleep(void *arg, int state)
|
|
|
|
{
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, state);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_LOCK;
|
2001-06-24 02:37:38 +00:00
|
|
|
if (state >= ACPI_STATE_S0 && state <= ACPI_S_STATES_MAX)
|
2000-12-08 09:16:20 +00:00
|
|
|
acpi_SetSleepState((struct acpi_softc *)arg, state);
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_UNLOCK;
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_system_eventhandler_wakeup(void *arg, int state)
|
|
|
|
{
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, state);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/* Well, what to do? :-) */
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_LOCK;
|
|
|
|
ACPI_UNLOCK;
|
|
|
|
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ACPICA Event Handlers (FixedEvent, also called from button notify handler)
|
|
|
|
*/
|
|
|
|
UINT32
|
|
|
|
acpi_eventhandler_power_button_for_sleep(void *context)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = (struct acpi_softc *)context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
EVENTHANDLER_INVOKE(acpi_sleep_event, sc->acpi_power_button_sx);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
return_VALUE(ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
|
|
|
acpi_eventhandler_power_button_for_wakeup(void *context)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = (struct acpi_softc *)context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
EVENTHANDLER_INVOKE(acpi_wakeup_event, sc->acpi_power_button_sx);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
return_VALUE(ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
|
|
|
acpi_eventhandler_sleep_button_for_sleep(void *context)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = (struct acpi_softc *)context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
EVENTHANDLER_INVOKE(acpi_sleep_event, sc->acpi_sleep_button_sx);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
return_VALUE(ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
|
|
|
acpi_eventhandler_sleep_button_for_wakeup(void *context)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = (struct acpi_softc *)context;
|
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
EVENTHANDLER_INVOKE(acpi_wakeup_event, sc->acpi_sleep_button_sx);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
return_VALUE(ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX This is kinda ugly, and should not be here.
|
|
|
|
*/
|
|
|
|
struct acpi_staticbuf {
|
|
|
|
ACPI_BUFFER buffer;
|
|
|
|
char data[512];
|
|
|
|
};
|
|
|
|
|
|
|
|
char *
|
|
|
|
acpi_name(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
static struct acpi_staticbuf buf;
|
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
buf.buffer.Length = 512;
|
|
|
|
buf.buffer.Pointer = &buf.data[0];
|
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf.buffer)))
|
2000-10-28 06:59:48 +00:00
|
|
|
return(buf.buffer.Pointer);
|
|
|
|
return("(unknown path)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging/bug-avoidance. Avoid trying to fetch info on various
|
|
|
|
* parts of the namespace.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acpi_avoid(ACPI_HANDLE handle)
|
|
|
|
{
|
2002-05-09 21:13:37 +00:00
|
|
|
char *cp, *env, *np;
|
2000-10-28 06:59:48 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
np = acpi_name(handle);
|
|
|
|
if (*np == '\\')
|
|
|
|
np++;
|
2002-05-09 21:13:37 +00:00
|
|
|
if ((env = getenv("debug.acpi.avoid")) == NULL)
|
2000-10-28 06:59:48 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
/* scan the avoid list checking for a match */
|
2002-05-09 21:13:37 +00:00
|
|
|
cp = env;
|
2000-10-28 06:59:48 +00:00
|
|
|
for (;;) {
|
|
|
|
while ((*cp != 0) && isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
if (*cp == 0)
|
|
|
|
break;
|
|
|
|
len = 0;
|
|
|
|
while ((cp[len] != 0) && !isspace(cp[len]))
|
|
|
|
len++;
|
2002-04-17 13:06:36 +00:00
|
|
|
if (!strncmp(cp, np, len)) {
|
2002-05-09 21:13:37 +00:00
|
|
|
freeenv(env);
|
2000-12-08 09:16:20 +00:00
|
|
|
return(1);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
2000-12-08 09:16:20 +00:00
|
|
|
cp += len;
|
|
|
|
}
|
2002-05-09 21:13:37 +00:00
|
|
|
freeenv(env);
|
2000-12-08 09:16:20 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging/bug-avoidance. Disable ACPI subsystem components.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acpi_disabled(char *subsys)
|
|
|
|
{
|
2002-04-24 17:49:21 +00:00
|
|
|
char *cp, *env;
|
2000-12-08 09:16:20 +00:00
|
|
|
int len;
|
|
|
|
|
2002-04-24 17:49:21 +00:00
|
|
|
if ((env = getenv("debug.acpi.disable")) == NULL)
|
2000-12-08 09:16:20 +00:00
|
|
|
return(0);
|
2002-04-24 17:49:21 +00:00
|
|
|
if (!strcmp(env, "all")) {
|
|
|
|
freeenv(env);
|
2000-12-08 09:16:20 +00:00
|
|
|
return(1);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
2000-12-08 09:16:20 +00:00
|
|
|
|
|
|
|
/* scan the disable list checking for a match */
|
2002-04-24 17:49:21 +00:00
|
|
|
cp = env;
|
2000-12-08 09:16:20 +00:00
|
|
|
for (;;) {
|
|
|
|
while ((*cp != 0) && isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
if (*cp == 0)
|
|
|
|
break;
|
|
|
|
len = 0;
|
|
|
|
while ((cp[len] != 0) && !isspace(cp[len]))
|
|
|
|
len++;
|
2002-04-17 13:06:36 +00:00
|
|
|
if (!strncmp(cp, subsys, len)) {
|
2002-04-24 17:49:21 +00:00
|
|
|
freeenv(env);
|
2000-10-28 06:59:48 +00:00
|
|
|
return(1);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
cp += len;
|
|
|
|
}
|
2002-04-24 17:49:21 +00:00
|
|
|
freeenv(env);
|
2000-10-28 06:59:48 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-07-22 12:52:54 +00:00
|
|
|
/*
|
|
|
|
* Device wake capability enable/disable.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_device_enable_wake_capability(ACPI_HANDLE h, int enable)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT_LIST ArgList;
|
|
|
|
ACPI_OBJECT Arg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TBD: All Power Resources referenced by elements 2 through N
|
|
|
|
* of the _PRW object are put into the ON state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enable/disable device wake function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ArgList.Count = 1;
|
|
|
|
ArgList.Pointer = &Arg;
|
|
|
|
|
|
|
|
Arg.Type = ACPI_TYPE_INTEGER;
|
|
|
|
Arg.Integer.Value = enable;
|
|
|
|
|
|
|
|
(void)AcpiEvaluateObject(h, "_PSW", &ArgList, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
acpi_device_enable_wake_event(ACPI_HANDLE h)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
ACPI_BUFFER prw_buffer;
|
|
|
|
ACPI_OBJECT *res;
|
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
|
|
|
if ((sc = devclass_get_softc(acpi_devclass, 0)) == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _PRW object is only required for devices that have the ability
|
|
|
|
* to wake the system from a system sleeping state.
|
|
|
|
*/
|
|
|
|
prw_buffer.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(h, "_PRW", NULL, &prw_buffer);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = (ACPI_OBJECT *)prw_buffer.Pointer;
|
|
|
|
if (res == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count < 2)) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The element 1 of the _PRW object:
|
|
|
|
* The lowest power system sleeping state that can be entered
|
|
|
|
* while still providing wake functionality.
|
|
|
|
* The sleeping state being entered must be greater or equal to
|
|
|
|
* the power state declared in element 1 of the _PRW object.
|
|
|
|
*/
|
|
|
|
if (res->Package.Elements[1].Type != ACPI_TYPE_INTEGER) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->acpi_sstate > res->Package.Elements[1].Integer.Value) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The element 0 of the _PRW object:
|
|
|
|
*/
|
|
|
|
switch(res->Package.Elements[0].Type) {
|
|
|
|
case ACPI_TYPE_INTEGER:
|
|
|
|
/*
|
|
|
|
* If the data type of this package element is numeric, then this
|
|
|
|
* _PRW package element is the bit index in the GPEx_EN, in the
|
|
|
|
* GPE blocks described in the FADT, of the enable bit that is
|
|
|
|
* enabled for the wake event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
status = AcpiEnableEvent(res->Package.Elements[0].Integer.Value,
|
|
|
|
ACPI_EVENT_GPE, ACPI_EVENT_WAKE_ENABLE);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
printf("%s: EnableEvent Failed\n", __func__);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPI_TYPE_PACKAGE:
|
|
|
|
/* XXX TBD */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the data type of this package element is a package, then this
|
|
|
|
* _PRW package element is itself a package containing two
|
|
|
|
* elements. The first is an object reference to the GPE Block
|
|
|
|
* device that contains the GPE that will be triggered by the wake
|
|
|
|
* event. The second element is numeric and it contains the bit
|
|
|
|
* index in the GPEx_EN, in the GPE Block referenced by the
|
|
|
|
* first element in the package, of the enable bit that is enabled for
|
|
|
|
* the wake event.
|
|
|
|
* For example, if this field is a package then it is of the form:
|
|
|
|
* Package() {\_SB.PCI0.ISA.GPE, 2}
|
|
|
|
*/
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (prw_buffer.Pointer != NULL)
|
|
|
|
AcpiOsFree(prw_buffer.Pointer);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Control interface.
|
|
|
|
*
|
2000-12-08 09:16:20 +00:00
|
|
|
* We multiplex ioctls for all participating ACPI devices here. Individual
|
|
|
|
* drivers wanting to be accessible via /dev/acpi should use the register/deregister
|
|
|
|
* interface to make their handlers visible.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2000-12-08 09:16:20 +00:00
|
|
|
struct acpi_ioctl_hook
|
|
|
|
{
|
|
|
|
TAILQ_ENTRY(acpi_ioctl_hook) link;
|
|
|
|
u_long cmd;
|
|
|
|
int (* fn)(u_long cmd, caddr_t addr, void *arg);
|
|
|
|
void *arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static TAILQ_HEAD(,acpi_ioctl_hook) acpi_ioctl_hooks;
|
|
|
|
static int acpi_ioctl_hooks_initted;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register an ioctl handler.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acpi_register_ioctl(u_long cmd, int (* fn)(u_long cmd, caddr_t addr, void *arg), void *arg)
|
|
|
|
{
|
|
|
|
struct acpi_ioctl_hook *hp;
|
|
|
|
|
|
|
|
if ((hp = malloc(sizeof(*hp), M_ACPIDEV, M_NOWAIT)) == NULL)
|
|
|
|
return(ENOMEM);
|
|
|
|
hp->cmd = cmd;
|
|
|
|
hp->fn = fn;
|
|
|
|
hp->arg = arg;
|
|
|
|
if (acpi_ioctl_hooks_initted == 0) {
|
|
|
|
TAILQ_INIT(&acpi_ioctl_hooks);
|
|
|
|
acpi_ioctl_hooks_initted = 1;
|
|
|
|
}
|
|
|
|
TAILQ_INSERT_TAIL(&acpi_ioctl_hooks, hp, link);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deregister an ioctl handler.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_deregister_ioctl(u_long cmd, int (* fn)(u_long cmd, caddr_t addr, void *arg))
|
|
|
|
{
|
|
|
|
struct acpi_ioctl_hook *hp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(hp, &acpi_ioctl_hooks, link)
|
|
|
|
if ((hp->cmd == cmd) && (hp->fn == fn))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (hp != NULL) {
|
|
|
|
TAILQ_REMOVE(&acpi_ioctl_hooks, hp, link);
|
|
|
|
free(hp, M_ACPIDEV);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
acpiopen(dev_t dev, int flag, int fmt, struct thread *td)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
acpiclose(dev_t dev, int flag, int fmt, struct thread *td)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
acpiioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2000-12-08 09:16:20 +00:00
|
|
|
struct acpi_softc *sc;
|
|
|
|
struct acpi_ioctl_hook *hp;
|
|
|
|
int error, xerror, state;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_LOCK;
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
error = state = 0;
|
|
|
|
sc = dev->si_drv1;
|
|
|
|
|
2000-12-08 09:16:20 +00:00
|
|
|
/*
|
|
|
|
* Scan the list of registered ioctls, looking for handlers.
|
|
|
|
*/
|
|
|
|
if (acpi_ioctl_hooks_initted) {
|
|
|
|
TAILQ_FOREACH(hp, &acpi_ioctl_hooks, link) {
|
|
|
|
if (hp->cmd == cmd) {
|
|
|
|
xerror = hp->fn(cmd, addr, hp->arg);
|
|
|
|
if (xerror != 0)
|
|
|
|
error = xerror;
|
2000-12-24 19:12:10 +00:00
|
|
|
goto out;
|
2000-12-08 09:16:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Core system ioctls.
|
|
|
|
*/
|
2000-10-28 06:59:48 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case ACPIIO_ENABLE:
|
2000-12-08 09:16:20 +00:00
|
|
|
if (ACPI_FAILURE(acpi_Enable(sc)))
|
2000-10-28 06:59:48 +00:00
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPIIO_DISABLE:
|
2000-12-08 09:16:20 +00:00
|
|
|
if (ACPI_FAILURE(acpi_Disable(sc)))
|
2000-10-28 06:59:48 +00:00
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACPIIO_SETSLPSTATE:
|
|
|
|
if (!sc->acpi_enabled) {
|
|
|
|
error = ENXIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
state = *(int *)addr;
|
2001-06-24 02:37:38 +00:00
|
|
|
if (state >= ACPI_STATE_S0 && state <= ACPI_S_STATES_MAX) {
|
2000-10-28 06:59:48 +00:00
|
|
|
acpi_SetSleepState(sc, state);
|
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2000-12-08 09:16:20 +00:00
|
|
|
if (error == 0)
|
|
|
|
error = EINVAL;
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-12-24 19:12:10 +00:00
|
|
|
|
|
|
|
out:
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_UNLOCK;
|
2000-10-28 06:59:48 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2001-01-13 21:28:57 +00:00
|
|
|
static int
|
|
|
|
acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
char sleep_state[10];
|
|
|
|
int error;
|
|
|
|
u_int new_state, old_state;
|
|
|
|
|
|
|
|
old_state = *(u_int *)oidp->oid_arg1;
|
2001-11-15 11:59:25 +00:00
|
|
|
if (old_state > ACPI_S_STATES_MAX+1) {
|
2001-01-13 21:28:57 +00:00
|
|
|
strcpy(sleep_state, "unknown");
|
2001-06-29 20:29:59 +00:00
|
|
|
} else {
|
2001-11-15 11:59:25 +00:00
|
|
|
bzero(sleep_state, sizeof(sleep_state));
|
2001-01-13 21:28:57 +00:00
|
|
|
strncpy(sleep_state, sleep_state_names[old_state],
|
2001-06-29 20:29:59 +00:00
|
|
|
sizeof(sleep_state_names[old_state]));
|
|
|
|
}
|
2001-01-13 21:28:57 +00:00
|
|
|
error = sysctl_handle_string(oidp, sleep_state, sizeof(sleep_state), req);
|
|
|
|
if (error == 0 && req->newptr != NULL) {
|
2001-11-15 11:59:25 +00:00
|
|
|
for (new_state = ACPI_STATE_S0; new_state <= ACPI_S_STATES_MAX+1; new_state++) {
|
2001-01-13 21:28:57 +00:00
|
|
|
if (strncmp(sleep_state, sleep_state_names[new_state],
|
2001-06-29 20:29:59 +00:00
|
|
|
sizeof(sleep_state)) == 0)
|
2001-01-13 21:28:57 +00:00
|
|
|
break;
|
2001-06-29 20:29:59 +00:00
|
|
|
}
|
2001-11-30 16:06:00 +00:00
|
|
|
if (new_state <= ACPI_S_STATES_MAX+1) {
|
|
|
|
if (new_state != old_state) {
|
|
|
|
*(u_int *)oidp->oid_arg1 = new_state;
|
|
|
|
}
|
2001-06-29 20:29:59 +00:00
|
|
|
} else {
|
2001-01-13 21:28:57 +00:00
|
|
|
error = EINVAL;
|
2001-06-29 20:29:59 +00:00
|
|
|
}
|
2001-01-13 21:28:57 +00:00
|
|
|
}
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#ifdef ACPI_DEBUG
|
2000-12-08 09:16:20 +00:00
|
|
|
/*
|
|
|
|
* Support for parsing debug options from the kernel environment.
|
|
|
|
*
|
|
|
|
* Bits may be set in the AcpiDbgLayer and AcpiDbgLevel debug registers
|
|
|
|
* by specifying the names of the bits in the debug.acpi.layer and
|
|
|
|
* debug.acpi.level environment variables. Bits may be unset by
|
|
|
|
* prefixing the bit name with !.
|
|
|
|
*/
|
2000-10-28 06:59:48 +00:00
|
|
|
struct debugtag
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
UINT32 value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct debugtag dbg_layer[] = {
|
2001-06-28 06:17:16 +00:00
|
|
|
{"ACPI_UTILITIES", ACPI_UTILITIES},
|
|
|
|
{"ACPI_HARDWARE", ACPI_HARDWARE},
|
|
|
|
{"ACPI_EVENTS", ACPI_EVENTS},
|
|
|
|
{"ACPI_TABLES", ACPI_TABLES},
|
|
|
|
{"ACPI_NAMESPACE", ACPI_NAMESPACE},
|
|
|
|
{"ACPI_PARSER", ACPI_PARSER},
|
|
|
|
{"ACPI_DISPATCHER", ACPI_DISPATCHER},
|
|
|
|
{"ACPI_EXECUTER", ACPI_EXECUTER},
|
|
|
|
{"ACPI_RESOURCES", ACPI_RESOURCES},
|
2002-08-29 01:52:27 +00:00
|
|
|
{"ACPI_CA_DEBUGGER", ACPI_CA_DEBUGGER},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_OS_SERVICES", ACPI_OS_SERVICES},
|
2002-08-29 01:52:27 +00:00
|
|
|
{"ACPI_CA_DISASSEMBLER", ACPI_CA_DISASSEMBLER},
|
2001-08-26 22:50:15 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
{"ACPI_BUS", ACPI_BUS},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_SYSTEM", ACPI_SYSTEM},
|
2001-06-29 20:29:59 +00:00
|
|
|
{"ACPI_POWER", ACPI_POWER},
|
|
|
|
{"ACPI_EC", ACPI_EC},
|
2001-06-28 06:17:16 +00:00
|
|
|
{"ACPI_AC_ADAPTER", ACPI_AC_ADAPTER},
|
|
|
|
{"ACPI_BATTERY", ACPI_BATTERY},
|
|
|
|
{"ACPI_BUTTON", ACPI_BUTTON},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_PROCESSOR", ACPI_PROCESSOR},
|
2001-06-29 20:29:59 +00:00
|
|
|
{"ACPI_THERMAL", ACPI_THERMAL},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_FAN", ACPI_FAN},
|
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
{"ACPI_ALL_DRIVERS", ACPI_ALL_DRIVERS},
|
2001-06-28 06:17:16 +00:00
|
|
|
{"ACPI_ALL_COMPONENTS", ACPI_ALL_COMPONENTS},
|
2000-10-28 06:59:48 +00:00
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct debugtag dbg_level[] = {
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_LV_OK", ACPI_LV_OK},
|
|
|
|
{"ACPI_LV_INFO", ACPI_LV_INFO},
|
|
|
|
{"ACPI_LV_WARN", ACPI_LV_WARN},
|
|
|
|
{"ACPI_LV_ERROR", ACPI_LV_ERROR},
|
|
|
|
{"ACPI_LV_FATAL", ACPI_LV_FATAL},
|
|
|
|
{"ACPI_LV_DEBUG_OBJECT", ACPI_LV_DEBUG_OBJECT},
|
|
|
|
{"ACPI_LV_ALL_EXCEPTIONS", ACPI_LV_ALL_EXCEPTIONS},
|
2002-08-29 01:52:27 +00:00
|
|
|
|
|
|
|
/* Trace verbosity level 1 [Standard Trace Level] */
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_LV_PARSE", ACPI_LV_PARSE},
|
|
|
|
{"ACPI_LV_LOAD", ACPI_LV_LOAD},
|
2002-08-29 01:52:27 +00:00
|
|
|
{"ACPI_LV_DISPATCH", ACPI_LV_DISPATCH},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_LV_EXEC", ACPI_LV_EXEC},
|
|
|
|
{"ACPI_LV_NAMES", ACPI_LV_NAMES},
|
|
|
|
{"ACPI_LV_OPREGION", ACPI_LV_OPREGION},
|
|
|
|
{"ACPI_LV_BFIELD", ACPI_LV_BFIELD},
|
|
|
|
{"ACPI_LV_TABLES", ACPI_LV_TABLES},
|
|
|
|
{"ACPI_LV_VALUES", ACPI_LV_VALUES},
|
|
|
|
{"ACPI_LV_OBJECTS", ACPI_LV_OBJECTS},
|
|
|
|
{"ACPI_LV_RESOURCES", ACPI_LV_RESOURCES},
|
|
|
|
{"ACPI_LV_USER_REQUESTS", ACPI_LV_USER_REQUESTS},
|
|
|
|
{"ACPI_LV_PACKAGE", ACPI_LV_PACKAGE},
|
|
|
|
{"ACPI_LV_INIT", ACPI_LV_INIT},
|
2002-08-29 01:52:27 +00:00
|
|
|
{"ACPI_LV_VERBOSITY1", ACPI_LV_VERBOSITY1},
|
|
|
|
|
|
|
|
/* Trace verbosity level 2 [Function tracing and memory allocation] */
|
|
|
|
{"ACPI_LV_ALLOCATIONS", ACPI_LV_ALLOCATIONS},
|
|
|
|
{"ACPI_LV_FUNCTIONS", ACPI_LV_FUNCTIONS},
|
|
|
|
{"ACPI_LV_OPTIMIZATIONS", ACPI_LV_OPTIMIZATIONS},
|
|
|
|
{"ACPI_LV_VERBOSITY2", ACPI_LV_VERBOSITY2},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_LV_ALL", ACPI_LV_ALL},
|
2002-08-29 01:52:27 +00:00
|
|
|
|
|
|
|
/* Trace verbosity level 3 [Threading, I/O, and Interrupts] */
|
|
|
|
{"ACPI_LV_MUTEX", ACPI_LV_MUTEX},
|
|
|
|
{"ACPI_LV_THREADS", ACPI_LV_THREADS},
|
|
|
|
{"ACPI_LV_IO", ACPI_LV_IO},
|
|
|
|
{"ACPI_LV_INTERRUPTS", ACPI_LV_INTERRUPTS},
|
|
|
|
{"ACPI_LV_VERBOSITY3", ACPI_LV_VERBOSITY3},
|
|
|
|
|
|
|
|
/* Exceptionally verbose output -- also used in the global "DebugLevel" */
|
2002-07-09 17:54:02 +00:00
|
|
|
{"ACPI_LV_AML_DISASSEMBLE", ACPI_LV_AML_DISASSEMBLE},
|
|
|
|
{"ACPI_LV_VERBOSE_INFO", ACPI_LV_VERBOSE_INFO},
|
|
|
|
{"ACPI_LV_FULL_TABLES", ACPI_LV_FULL_TABLES},
|
|
|
|
{"ACPI_LV_EVENTS", ACPI_LV_EVENTS},
|
|
|
|
{"ACPI_LV_VERBOSE", ACPI_LV_VERBOSE},
|
2000-10-28 06:59:48 +00:00
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_parse_debug(char *cp, struct debugtag *tag, UINT32 *flag)
|
|
|
|
{
|
|
|
|
char *ep;
|
|
|
|
int i, l;
|
2000-12-08 09:16:20 +00:00
|
|
|
int set;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
while (*cp) {
|
|
|
|
if (isspace(*cp)) {
|
|
|
|
cp++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ep = cp;
|
|
|
|
while (*ep && !isspace(*ep))
|
|
|
|
ep++;
|
2000-12-08 09:16:20 +00:00
|
|
|
if (*cp == '!') {
|
|
|
|
set = 0;
|
|
|
|
cp++;
|
|
|
|
if (cp == ep)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
set = 1;
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
l = ep - cp;
|
|
|
|
for (i = 0; tag[i].name != NULL; i++) {
|
|
|
|
if (!strncmp(cp, tag[i].name, l)) {
|
2000-12-08 09:16:20 +00:00
|
|
|
if (set) {
|
|
|
|
*flag |= tag[i].value;
|
|
|
|
} else {
|
|
|
|
*flag &= ~tag[i].value;
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
printf("ACPI_DEBUG: set '%s'\n", tag[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cp = ep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-05-29 20:13:42 +00:00
|
|
|
acpi_set_debugging(void *junk)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2002-04-19 23:36:38 +00:00
|
|
|
char *cp;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
|
|
|
AcpiDbgLayer = 0;
|
|
|
|
AcpiDbgLevel = 0;
|
2002-04-19 23:36:38 +00:00
|
|
|
if ((cp = getenv("debug.acpi.layer")) != NULL) {
|
2000-10-28 06:59:48 +00:00
|
|
|
acpi_parse_debug(cp, &dbg_layer[0], &AcpiDbgLayer);
|
2002-04-19 23:36:38 +00:00
|
|
|
freeenv(cp);
|
|
|
|
}
|
|
|
|
if ((cp = getenv("debug.acpi.level")) != NULL) {
|
2000-10-28 06:59:48 +00:00
|
|
|
acpi_parse_debug(cp, &dbg_level[0], &AcpiDbgLevel);
|
2002-04-19 23:36:38 +00:00
|
|
|
freeenv(cp);
|
|
|
|
}
|
2000-12-08 09:16:20 +00:00
|
|
|
|
|
|
|
printf("ACPI debug layer 0x%x debug level 0x%x\n", AcpiDbgLayer, AcpiDbgLevel);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-05-29 20:13:42 +00:00
|
|
|
SYSINIT(acpi_debugging, SI_SUB_TUNABLES, SI_ORDER_ANY, acpi_set_debugging, NULL);
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2001-11-01 16:34:07 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_pm_func(u_long cmd, void *arg, ...)
|
|
|
|
{
|
|
|
|
int state, acpi_state;
|
|
|
|
int error;
|
|
|
|
struct acpi_softc *sc;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
|
|
|
case POWER_CMD_SUSPEND:
|
|
|
|
sc = (struct acpi_softc *)arg;
|
|
|
|
if (sc == NULL) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start(ap, arg);
|
|
|
|
state = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case POWER_SLEEP_STATE_STANDBY:
|
|
|
|
acpi_state = sc->acpi_standby_sx;
|
|
|
|
break;
|
|
|
|
case POWER_SLEEP_STATE_SUSPEND:
|
|
|
|
acpi_state = sc->acpi_suspend_sx;
|
|
|
|
break;
|
|
|
|
case POWER_SLEEP_STATE_HIBERNATE:
|
|
|
|
acpi_state = ACPI_STATE_S4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
acpi_SetSleepState(sc, acpi_state);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_pm_register(void *arg)
|
|
|
|
{
|
2002-08-30 11:11:07 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
if (!resource_int_value("acpi", 0, "disabled", &error) &&
|
|
|
|
(error != 0))
|
|
|
|
return;
|
2001-11-01 16:34:07 +00:00
|
|
|
|
|
|
|
power_pm_register(POWER_PM_TYPE_ACPI, acpi_pm_func, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(power, SI_SUB_KLD, SI_ORDER_ANY, acpi_pm_register, 0);
|
|
|
|
|