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>
|
2003-02-15 01:46:22 +00:00
|
|
|
#include <sys/fcntl.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
#include <sys/malloc.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.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>
|
2003-12-09 06:29:57 +00:00
|
|
|
#include <sys/sbuf.h>
|
2004-03-19 07:05:01 +00:00
|
|
|
#include <sys/smp.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
#include <machine/clock.h>
|
|
|
|
#include <machine/resource.h>
|
2003-11-15 19:18:29 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
2001-08-30 00:50:58 +00:00
|
|
|
#include <isa/isavar.h>
|
2004-06-29 01:33:35 +00:00
|
|
|
#include <isa/pnpvar.h>
|
2001-08-30 00:50:58 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include "acpi.h"
|
|
|
|
#include <dev/acpica/acpivar.h>
|
|
|
|
#include <dev/acpica/acpiio.h>
|
2003-10-25 05:03:25 +00:00
|
|
|
#include <contrib/dev/acpica/acnamesp.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
MALLOC_DEFINE(M_ACPIDEV, "acpidev", "ACPI devices");
|
|
|
|
|
2003-08-28 16:06:30 +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
|
|
|
static d_open_t acpiopen;
|
|
|
|
static d_close_t acpiclose;
|
|
|
|
static d_ioctl_t acpiioctl;
|
|
|
|
|
|
|
|
static struct cdevsw acpi_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = acpiopen,
|
|
|
|
.d_close = acpiclose,
|
|
|
|
.d_ioctl = acpiioctl,
|
|
|
|
.d_name = "acpi",
|
2000-10-28 06:59:48 +00:00
|
|
|
};
|
|
|
|
|
2004-06-30 15:10:02 +00:00
|
|
|
/* Global mutex for locking access to the ACPI subsystem. */
|
2001-06-29 20:29:59 +00:00
|
|
|
struct mtx acpi_mutex;
|
|
|
|
|
2004-06-30 04:49:54 +00:00
|
|
|
/* Bitmap of device quirks. */
|
2004-06-30 15:10:02 +00:00
|
|
|
int acpi_quirks;
|
2004-06-30 04:49:54 +00:00
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
/* Local pools for managing system resources for ACPI child devices. */
|
2004-06-30 15:10:02 +00:00
|
|
|
struct rman acpi_rman_io, acpi_rman_mem;
|
2004-06-13 22:52:30 +00:00
|
|
|
|
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);
|
2004-06-05 07:25:58 +00:00
|
|
|
static int acpi_shutdown(device_t dev);
|
2003-08-28 16:06:30 +00:00
|
|
|
static device_t acpi_add_child(device_t bus, int order, const char *name,
|
|
|
|
int unit);
|
2000-10-28 06:59:48 +00:00
|
|
|
static int acpi_print_child(device_t bus, device_t child);
|
2003-08-28 16:06:30 +00:00
|
|
|
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);
|
2004-06-13 22:52:30 +00:00
|
|
|
static struct resource_list *acpi_get_rlist(device_t dev, device_t child);
|
2003-08-28 16:06:30 +00:00
|
|
|
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);
|
2003-12-18 03:25:22 +00:00
|
|
|
static uint32_t acpi_isa_get_logicalid(device_t dev);
|
|
|
|
static int acpi_isa_get_compatid(device_t dev, uint32_t *cids, int count);
|
2004-06-29 19:00:36 +00:00
|
|
|
static char *acpi_device_id_probe(device_t bus, device_t dev, char **ids);
|
|
|
|
static ACPI_STATUS acpi_device_eval_obj(device_t bus, device_t dev,
|
|
|
|
ACPI_STRING pathname, ACPI_OBJECT_LIST *parameters,
|
|
|
|
ACPI_BUFFER *ret);
|
2004-07-15 16:29:08 +00:00
|
|
|
static ACPI_STATUS acpi_device_scan_cb(ACPI_HANDLE h, UINT32 level,
|
|
|
|
void *context, void **retval);
|
|
|
|
static ACPI_STATUS acpi_device_scan_children(device_t bus, device_t dev,
|
|
|
|
int max_depth, acpi_scan_cb_t user_fn, void *arg);
|
2003-08-28 16:06:30 +00:00
|
|
|
static int acpi_isa_pnp_probe(device_t bus, device_t child,
|
2004-07-15 16:29:08 +00:00
|
|
|
struct isa_pnp_id *ids);
|
2000-10-28 06:59:48 +00:00
|
|
|
static void acpi_probe_children(device_t bus);
|
2004-06-14 04:01:12 +00:00
|
|
|
static int acpi_probe_order(ACPI_HANDLE handle, int *order);
|
2003-08-28 16:06:30 +00:00
|
|
|
static ACPI_STATUS acpi_probe_child(ACPI_HANDLE handle, UINT32 level,
|
2004-07-15 16:29:08 +00:00
|
|
|
void *context, void **status);
|
2004-06-29 19:00:36 +00:00
|
|
|
static BOOLEAN acpi_MatchHid(ACPI_HANDLE h, const char *hid);
|
2000-10-28 06:59:48 +00:00
|
|
|
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);
|
2004-06-30 16:08:03 +00:00
|
|
|
static int acpi_wake_sleep_prep(ACPI_HANDLE handle, int sstate);
|
|
|
|
static int acpi_wake_run_prep(ACPI_HANDLE handle, int sstate);
|
|
|
|
static int acpi_wake_prep_walk(int sstate);
|
2004-05-28 06:28:55 +00:00
|
|
|
static int acpi_wake_sysctl_walk(device_t dev);
|
|
|
|
static int acpi_wake_set_sysctl(SYSCTL_HANDLER_ARGS);
|
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);
|
2003-04-11 16:53:56 +00:00
|
|
|
static int acpi_supported_sleep_state_sysctl(SYSCTL_HANDLER_ARGS);
|
2001-01-13 21:28:57 +00:00
|
|
|
static int acpi_sleep_state_sysctl(SYSCTL_HANDLER_ARGS);
|
2001-11-01 16:34:07 +00:00
|
|
|
static int acpi_pm_func(u_long cmd, void *arg, ...);
|
2004-03-27 16:26:00 +00:00
|
|
|
static int acpi_child_location_str_method(device_t acdev, device_t child,
|
|
|
|
char *buf, size_t buflen);
|
|
|
|
static int acpi_child_pnpinfo_str_method(device_t acdev, device_t child,
|
|
|
|
char *buf, size_t buflen);
|
|
|
|
|
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),
|
2004-06-05 07:25:58 +00:00
|
|
|
DEVMETHOD(device_shutdown, acpi_shutdown),
|
2003-11-19 20:27:06 +00:00
|
|
|
DEVMETHOD(device_detach, bus_generic_detach),
|
2000-10-28 06:59:48 +00:00
|
|
|
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),
|
2004-06-13 22:52:30 +00:00
|
|
|
DEVMETHOD(bus_get_resource_list, acpi_get_rlist),
|
|
|
|
DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
|
|
|
|
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
2000-10-28 06:59:48 +00:00
|
|
|
DEVMETHOD(bus_alloc_resource, acpi_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, acpi_release_resource),
|
2004-03-31 17:35:28 +00:00
|
|
|
DEVMETHOD(bus_child_pnpinfo_str, acpi_child_pnpinfo_str_method),
|
|
|
|
DEVMETHOD(bus_child_location_str, acpi_child_location_str_method),
|
2000-10-28 06:59:48 +00:00
|
|
|
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),
|
|
|
|
|
2004-06-29 19:00:36 +00:00
|
|
|
/* ACPI bus */
|
|
|
|
DEVMETHOD(acpi_id_probe, acpi_device_id_probe),
|
|
|
|
DEVMETHOD(acpi_evaluate_object, acpi_device_eval_obj),
|
2004-07-15 16:29:08 +00:00
|
|
|
DEVMETHOD(acpi_scan_children, acpi_device_scan_children),
|
2004-06-29 19:00:36 +00:00
|
|
|
|
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);
|
2004-04-08 16:45:12 +00:00
|
|
|
MODULE_VERSION(acpi, 1);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-04-14 17:48:33 +00:00
|
|
|
static const char* sleep_state_names[] = {
|
|
|
|
"S0", "S1", "S2", "S3", "S4", "S5", "NONE"};
|
|
|
|
|
2003-09-26 21:22:10 +00:00
|
|
|
SYSCTL_NODE(_debug, OID_AUTO, acpi, CTLFLAG_RW, NULL, "ACPI debugging");
|
|
|
|
static char acpi_ca_version[12];
|
|
|
|
SYSCTL_STRING(_debug_acpi, OID_AUTO, acpi_ca_version, CTLFLAG_RD,
|
|
|
|
acpi_ca_version, 0, "Version of Intel ACPI-CA");
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-03-18 18:42:22 +00:00
|
|
|
/*
|
|
|
|
* Allow override of whether methods execute in parallel or not.
|
2004-03-30 07:35:18 +00:00
|
|
|
* Enable this for serial behavior, which fixes "AE_ALREADY_EXISTS"
|
|
|
|
* errors for AML that really can't handle parallel method execution.
|
|
|
|
* It is off by default since this breaks recursive methods and
|
|
|
|
* some IBMs use such code.
|
2004-03-18 18:42:22 +00:00
|
|
|
*/
|
2004-03-30 07:35:18 +00:00
|
|
|
static int acpi_serialize_methods;
|
2004-03-18 18:42:22 +00:00
|
|
|
TUNABLE_INT("hw.acpi.serialize_methods", &acpi_serialize_methods);
|
|
|
|
|
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.
|
2003-08-28 16:06:30 +00:00
|
|
|
* It also cannot be unloaded, since the entire system bus heirarchy hangs
|
|
|
|
* off it.
|
2001-07-30 08:59:43 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
acpi_modevent(struct module *mod, int event, void *junk)
|
|
|
|
{
|
2004-06-29 19:00:36 +00:00
|
|
|
switch (event) {
|
2001-07-30 08:59:43 +00:00
|
|
|
case MOD_LOAD:
|
2002-11-24 02:27:07 +00:00
|
|
|
if (!cold) {
|
|
|
|
printf("The ACPI driver cannot be loaded after boot.\n");
|
2003-08-28 16:06:30 +00:00
|
|
|
return (EPERM);
|
2002-11-24 02:27:07 +00:00
|
|
|
}
|
2001-07-30 08:59:43 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2001-11-01 16:34:07 +00:00
|
|
|
if (!cold && power_pm_get_type() == POWER_PM_TYPE_ACPI)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (EBUSY);
|
2001-11-01 16:34:07 +00:00
|
|
|
break;
|
2001-07-30 08:59:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2001-07-30 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
2004-01-26 19:29:04 +00:00
|
|
|
* Perform early initialization.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2004-01-26 19:29:04 +00:00
|
|
|
ACPI_STATUS
|
|
|
|
acpi_Startup(void)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2002-08-29 01:52:27 +00:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2004-01-26 19:29:04 +00:00
|
|
|
char *debugpoint;
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2004-06-30 04:49:54 +00:00
|
|
|
static int started = 0;
|
|
|
|
int error, val;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-01-28 07:48:03 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
2004-01-26 19:29:04 +00:00
|
|
|
if (started)
|
2004-06-30 04:49:54 +00:00
|
|
|
return_VALUE (0);
|
2004-01-26 19:29:04 +00:00
|
|
|
started = 1;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +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
|
|
|
|
2004-03-18 18:42:22 +00:00
|
|
|
/*
|
|
|
|
* Set the globals from our tunables. This is needed because ACPI-CA
|
2004-05-25 02:47:35 +00:00
|
|
|
* uses UINT8 for some values and we have no tunable_byte.
|
2004-03-18 18:42:22 +00:00
|
|
|
*/
|
2004-05-25 02:47:35 +00:00
|
|
|
AcpiGbl_AllMethodsSerialized = (UINT8)acpi_serialize_methods;
|
2004-03-18 18:42:22 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Start up the ACPI CA subsystem. */
|
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();
|
2003-08-28 16:06:30 +00:00
|
|
|
freeenv(debugpoint);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
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));
|
2004-03-03 03:02:17 +00:00
|
|
|
return_VALUE (error);
|
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();
|
2003-08-28 16:06:30 +00:00
|
|
|
freeenv(debugpoint);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
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));
|
2004-06-30 04:49:54 +00:00
|
|
|
AcpiTerminate();
|
|
|
|
return_VALUE (error);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2004-03-03 03:02:17 +00:00
|
|
|
|
2004-06-30 04:49:54 +00:00
|
|
|
/* Set up any quirks we have for this system. */
|
|
|
|
acpi_table_quirks(&acpi_quirks);
|
|
|
|
|
|
|
|
/* If the user manually set the disabled hint to 0, override any quirk. */
|
|
|
|
if (resource_int_value("acpi", 0, "disabled", &val) == 0 && val == 0)
|
|
|
|
acpi_quirks &= ~ACPI_Q_BROKEN;
|
|
|
|
if (acpi_quirks & ACPI_Q_BROKEN) {
|
|
|
|
printf("ACPI disabled by blacklist. Contact your BIOS vendor.\n");
|
|
|
|
AcpiTerminate();
|
2004-03-04 04:42:59 +00:00
|
|
|
return_VALUE (AE_ERROR);
|
2004-06-30 04:49:54 +00:00
|
|
|
}
|
2004-03-03 03:02:17 +00:00
|
|
|
|
|
|
|
return_VALUE (AE_OK);
|
2004-01-26 19:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect ACPI, perform early initialisation
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
|
|
|
if (!cold)
|
|
|
|
return_VOID;
|
|
|
|
|
|
|
|
/* Check that we haven't been disabled with a hint. */
|
|
|
|
if (resource_disabled("acpi", 0))
|
|
|
|
return_VOID;
|
|
|
|
|
|
|
|
/* Make sure we're not being doubly invoked. */
|
|
|
|
if (device_find_child(parent, "acpi", 0) != NULL)
|
|
|
|
return_VOID;
|
|
|
|
|
|
|
|
/* Initialize ACPI-CA. */
|
|
|
|
if (ACPI_FAILURE(acpi_Startup()))
|
|
|
|
return_VOID;
|
|
|
|
|
2004-03-04 04:42:59 +00:00
|
|
|
snprintf(acpi_ca_version, sizeof(acpi_ca_version), "%#x", ACPI_CA_VERSION);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Attach the actual ACPI device. */
|
2000-10-28 06:59:48 +00:00
|
|
|
if ((child = BUS_ADD_CHILD(parent, 0, "acpi", 0)) == NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
device_printf(parent, "ACPI: could not attach\n");
|
|
|
|
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];
|
|
|
|
int error;
|
2004-01-09 21:04:28 +00:00
|
|
|
struct sbuf sb;
|
|
|
|
ACPI_STATUS status;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
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 &&
|
2003-08-28 16:06:30 +00:00
|
|
|
power_pm_get_type() != POWER_PM_TYPE_ACPI) {
|
|
|
|
|
2001-11-01 16:34:07 +00:00
|
|
|
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))) {
|
2003-08-28 16:06:30 +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 {
|
2004-01-09 21:04:28 +00:00
|
|
|
sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
|
|
|
|
sbuf_bcat(&sb, th.OemId, 6);
|
|
|
|
sbuf_trim(&sb);
|
|
|
|
sbuf_putc(&sb, ' ');
|
|
|
|
sbuf_bcat(&sb, th.OemTableId, 8);
|
|
|
|
sbuf_trim(&sb);
|
|
|
|
sbuf_finish(&sb);
|
|
|
|
device_set_desc_copy(dev, sbuf_data(&sb));
|
|
|
|
sbuf_delete(&sb);
|
2001-06-29 20:29:59 +00:00
|
|
|
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;
|
2004-05-06 08:04:34 +00:00
|
|
|
int error, state;
|
2001-09-07 02:57:29 +00:00
|
|
|
UINT32 flags;
|
2004-05-06 08:04:34 +00:00
|
|
|
UINT8 TypeA, TypeB;
|
2002-10-31 20:23:41 +00:00
|
|
|
char *env;
|
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-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
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;
|
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
/* Initialize resource manager. */
|
|
|
|
acpi_rman_io.rm_type = RMAN_ARRAY;
|
|
|
|
acpi_rman_io.rm_start = 0;
|
|
|
|
acpi_rman_io.rm_end = 0xffff;
|
|
|
|
acpi_rman_io.rm_descr = "I/O ports";
|
|
|
|
if (rman_init(&acpi_rman_io) != 0)
|
|
|
|
panic("acpi rman_init IO ports failed");
|
|
|
|
acpi_rman_mem.rm_type = RMAN_ARRAY;
|
|
|
|
acpi_rman_mem.rm_start = 0;
|
|
|
|
acpi_rman_mem.rm_end = ~0ul;
|
|
|
|
acpi_rman_mem.rm_descr = "I/O memory addresses";
|
|
|
|
if (rman_init(&acpi_rman_mem) != 0)
|
|
|
|
panic("acpi rman_init memory failed");
|
|
|
|
|
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();
|
2003-08-28 16:06:30 +00:00
|
|
|
freeenv(debugpoint);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Install the default address space handlers. */
|
2001-06-29 20:29:59 +00:00
|
|
|
error = ENXIO;
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
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
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
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
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
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.
|
|
|
|
*
|
2003-08-28 16:06:30 +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.
|
2001-09-07 02:57:29 +00:00
|
|
|
*
|
|
|
|
* For these devices, we set ACPI_NO_DEVICE_INIT and ACPI_NO_OBJECT_INIT).
|
2000-10-28 06:59:48 +00:00
|
|
|
*
|
2003-08-28 16:06:30 +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();
|
2003-08-28 16:06:30 +00:00
|
|
|
freeenv(debugpoint);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
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))) {
|
2003-08-28 16:06:30 +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
|
|
|
}
|
|
|
|
|
2003-07-20 00:48:38 +00:00
|
|
|
/*
|
|
|
|
* Call the ECDT probe function to provide EC functionality before
|
|
|
|
* the namespace has been evaluated.
|
|
|
|
*/
|
|
|
|
acpi_ec_ecdt_probe(dev);
|
|
|
|
|
2002-07-30 19:35:32 +00:00
|
|
|
if (ACPI_FAILURE(status = AcpiInitializeObjects(flags))) {
|
2003-08-28 16:06:30 +00:00
|
|
|
device_printf(dev, "Could not initialize ACPI objects: %s\n",
|
|
|
|
AcpiFormatException(status));
|
2002-07-30 19:35:32 +00:00
|
|
|
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, "");
|
2003-04-11 16:53:56 +00:00
|
|
|
SYSCTL_ADD_PROC(&sc->acpi_sysctl_ctx, SYSCTL_CHILDREN(sc->acpi_sysctl_tree),
|
|
|
|
OID_AUTO, "supported_sleep_state", CTLTYPE_STRING | CTLFLAG_RD,
|
|
|
|
0, 0, acpi_supported_sleep_state_sysctl, "A", "");
|
2001-01-13 21:28:57 +00:00
|
|
|
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");
|
2003-08-08 03:19:22 +00:00
|
|
|
|
|
|
|
/*
|
2004-05-29 05:34:04 +00:00
|
|
|
* Default to 1 second before sleeping to give some machines time to
|
2003-08-08 03:19:22 +00:00
|
|
|
* stabilize.
|
|
|
|
*/
|
2004-05-29 05:34:04 +00:00
|
|
|
sc->acpi_sleep_delay = 1;
|
2001-10-29 18:09:43 +00:00
|
|
|
if (bootverbose)
|
|
|
|
sc->acpi_verbose = 1;
|
2002-10-31 20:23:41 +00:00
|
|
|
if ((env = getenv("hw.acpi.verbose")) && strcmp(env, "0")) {
|
|
|
|
sc->acpi_verbose = 1;
|
|
|
|
freeenv(env);
|
|
|
|
}
|
|
|
|
|
2003-09-15 06:29:31 +00:00
|
|
|
/* Only enable S4BIOS by default if the FACS says it is available. */
|
|
|
|
if (AcpiGbl_FACS->S4Bios_f != 0)
|
2004-06-30 04:49:54 +00:00
|
|
|
sc->acpi_s4bios = 1;
|
2003-09-15 06:29:31 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
2004-05-06 08:04:34 +00:00
|
|
|
* Dispatch the default sleep state to devices. The lid switch is set
|
|
|
|
* to NONE by default to avoid surprising users.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2004-05-06 08:04:34 +00:00
|
|
|
sc->acpi_power_button_sx = ACPI_STATE_S5;
|
|
|
|
sc->acpi_lid_switch_sx = ACPI_S_STATES_MAX + 1;
|
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
|
|
|
|
2004-05-06 08:04:34 +00:00
|
|
|
/* Pick the first valid sleep state for the sleep button default. */
|
|
|
|
sc->acpi_sleep_button_sx = ACPI_S_STATES_MAX + 1;
|
|
|
|
for (state = ACPI_STATE_S1; state < ACPI_STATE_S5; state++)
|
|
|
|
if (ACPI_SUCCESS(AcpiGetSleepTypeData(state, &TypeA, &TypeB))) {
|
|
|
|
sc->acpi_sleep_button_sx = state;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2004-06-14 04:37:45 +00:00
|
|
|
/* Register our shutdown handler. */
|
2003-08-28 16:06:30 +00:00
|
|
|
EVENTHANDLER_REGISTER(shutdown_final, acpi_shutdown_final, sc,
|
|
|
|
SHUTDOWN_PRI_LAST);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register our acpi event handlers.
|
|
|
|
* XXX should be configurable eg. via userland policy manager.
|
|
|
|
*/
|
2003-08-28 16:06:30 +00:00
|
|
|
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);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Flag our initial states. */
|
2000-10-28 06:59:48 +00:00
|
|
|
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
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Create the control device */
|
2003-02-15 01:46:22 +00:00
|
|
|
sc->acpi_dev_t = make_dev(&acpi_cdevsw, 0, UID_ROOT, GID_WHEEL, 0644,
|
2003-08-28 16:06:30 +00:00
|
|
|
"acpi");
|
2000-10-28 06:59:48 +00:00
|
|
|
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) {
|
2003-08-28 16:06:30 +00:00
|
|
|
if (strcmp(debugpoint, "running") == 0)
|
2002-04-17 13:06:36 +00:00
|
|
|
acpi_EnterDebugger();
|
|
|
|
freeenv(debugpoint);
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
#endif
|
2001-10-26 17:43:05 +00:00
|
|
|
|
2002-10-31 17:58:39 +00:00
|
|
|
#ifdef ACPI_USE_THREADS
|
2003-08-28 16:06:30 +00:00
|
|
|
if ((error = acpi_task_thread_init()))
|
2001-12-22 16:05:41 +00:00
|
|
|
goto out;
|
|
|
|
#endif
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if ((error = acpi_machdep_init(dev)))
|
2001-10-26 17:43:05 +00:00
|
|
|
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;
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (error);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2004-06-05 07:25:58 +00:00
|
|
|
static int
|
|
|
|
acpi_shutdown(device_t dev)
|
|
|
|
{
|
|
|
|
|
2004-06-05 09:56:04 +00:00
|
|
|
/* Allow children to shutdown first. */
|
|
|
|
bus_generic_shutdown(dev);
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* Enable any GPEs that are able to power-on the system (i.e., RTC). */
|
|
|
|
acpi_wake_prep_walk(ACPI_STATE_S5);
|
|
|
|
|
2004-06-05 07:25:58 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if ((ad = malloc(sizeof(*ad), M_ACPIDEV, M_NOWAIT | M_ZERO)) == NULL)
|
|
|
|
return (NULL);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
resource_list_init(&ad->ad_rl);
|
2004-05-27 18:38:45 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
child = device_add_child_ordered(bus, order, name, unit);
|
|
|
|
if (child != NULL)
|
|
|
|
device_set_ivars(child, ad);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (child);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_print_child(device_t bus, device_t child)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
struct acpi_device *adev = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &adev->ad_rl;
|
2000-10-28 06:59:48 +00:00
|
|
|
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);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return (retval);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2004-03-31 17:35:28 +00:00
|
|
|
/* Location hint for devctl(8) */
|
|
|
|
static int
|
2004-03-31 17:21:14 +00:00
|
|
|
acpi_child_location_str_method(device_t cbdev, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
struct acpi_device *dinfo = device_get_ivars(child);
|
|
|
|
|
|
|
|
if (dinfo->ad_handle)
|
2004-07-13 18:59:49 +00:00
|
|
|
snprintf(buf, buflen, "handle=%s", acpi_name(dinfo->ad_handle));
|
2004-03-31 17:21:14 +00:00
|
|
|
else
|
2004-07-13 18:59:49 +00:00
|
|
|
snprintf(buf, buflen, "unknown");
|
2004-03-31 17:21:14 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-03-31 17:35:28 +00:00
|
|
|
/* PnP information for devctl(8) */
|
|
|
|
static int
|
2004-03-31 17:21:14 +00:00
|
|
|
acpi_child_pnpinfo_str_method(device_t cbdev, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
ACPI_BUFFER adbuf = {ACPI_ALLOCATE_BUFFER, NULL};
|
2004-03-31 17:35:28 +00:00
|
|
|
ACPI_DEVICE_INFO *adinfo;
|
|
|
|
struct acpi_device *dinfo = device_get_ivars(child);
|
2004-03-31 17:21:14 +00:00
|
|
|
char *end;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = AcpiGetObjectInfo(dinfo->ad_handle, &adbuf);
|
|
|
|
adinfo = (ACPI_DEVICE_INFO *) adbuf.Pointer;
|
|
|
|
if (error)
|
2004-07-13 18:59:49 +00:00
|
|
|
snprintf(buf, buflen, "unknown");
|
2004-03-31 17:21:14 +00:00
|
|
|
else
|
2004-07-13 18:59:49 +00:00
|
|
|
snprintf(buf, buflen, "_HID=%s _UID=%lu",
|
2004-03-31 17:35:28 +00:00
|
|
|
(adinfo->Valid & ACPI_VALID_HID) ?
|
2004-07-13 18:59:49 +00:00
|
|
|
adinfo->HardwareId.Value : "none",
|
2004-03-31 17:35:28 +00:00
|
|
|
(adinfo->Valid & ACPI_VALID_UID) ?
|
|
|
|
strtoul(adinfo->UniqueId.Value, &end, 10) : 0);
|
2004-03-31 17:21:14 +00:00
|
|
|
if (adinfo)
|
|
|
|
AcpiOsFree(adinfo);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* 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");
|
2003-08-28 16:06:30 +00:00
|
|
|
return (ENOENT);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* ACPI and ISA compatibility ivars */
|
2000-10-28 06:59:48 +00:00
|
|
|
switch(index) {
|
|
|
|
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;
|
2004-06-30 16:08:03 +00:00
|
|
|
case ACPI_IVAR_FLAGS:
|
|
|
|
*(int *)result = ad->ad_flags;
|
|
|
|
break;
|
2001-09-07 02:57:29 +00:00
|
|
|
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:
|
2003-08-28 16:06:30 +00:00
|
|
|
return (ENOENT);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (0);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2003-08-28 16:06:30 +00:00
|
|
|
return (ENOENT);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(index) {
|
|
|
|
case ACPI_IVAR_HANDLE:
|
|
|
|
ad->ad_handle = (ACPI_HANDLE)value;
|
|
|
|
break;
|
|
|
|
case ACPI_IVAR_MAGIC:
|
2003-08-28 16:06:30 +00:00
|
|
|
ad->ad_magic = (int)value;
|
2000-10-28 06:59:48 +00:00
|
|
|
break;
|
|
|
|
case ACPI_IVAR_PRIVATE:
|
|
|
|
ad->ad_private = (void *)value;
|
|
|
|
break;
|
2004-06-30 16:08:03 +00:00
|
|
|
case ACPI_IVAR_FLAGS:
|
|
|
|
ad->ad_flags = (int)value;
|
|
|
|
break;
|
2000-10-28 06:59:48 +00:00
|
|
|
default:
|
2002-08-12 22:36:18 +00:00
|
|
|
panic("bad ivar write request (%d)", index);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (ENOENT);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Handle child resource allocation/removal
|
|
|
|
*/
|
2004-06-13 22:52:30 +00:00
|
|
|
static struct resource_list *
|
|
|
|
acpi_get_rlist(device_t dev, device_t child)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2004-06-13 22:52:30 +00:00
|
|
|
struct acpi_device *ad;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
ad = device_get_ivars(child);
|
|
|
|
return (&ad->ad_rl);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource *
|
|
|
|
acpi_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
2004-06-13 22:52:30 +00:00
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2004-06-23 17:21:02 +00:00
|
|
|
ACPI_RESOURCE ares;
|
2000-10-28 06:59:48 +00:00
|
|
|
struct acpi_device *ad = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &ad->ad_rl;
|
2004-06-13 22:52:30 +00:00
|
|
|
struct resource_list_entry *rle;
|
|
|
|
struct resource *res;
|
|
|
|
struct rman *rm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an allocation of the "default" range for a given RID, and
|
|
|
|
* we know what the resources for this device are (i.e., they're on the
|
|
|
|
* child's resource list), use those start/end values.
|
|
|
|
*/
|
|
|
|
if (start == 0UL && end == ~0UL) {
|
|
|
|
rle = resource_list_find(rl, type, *rid);
|
|
|
|
if (rle == NULL)
|
|
|
|
return (NULL);
|
|
|
|
start = rle->start;
|
|
|
|
end = rle->end;
|
|
|
|
count = rle->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we don't manage this address, pass the request up to the parent. */
|
|
|
|
rle = acpi_sysres_find(type, start);
|
|
|
|
if (rle == NULL) {
|
2004-06-23 17:21:02 +00:00
|
|
|
res = BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type, rid,
|
|
|
|
start, end, count, flags);
|
|
|
|
} else {
|
2004-06-13 22:52:30 +00:00
|
|
|
|
2004-06-23 17:21:02 +00:00
|
|
|
/* We only handle memory and IO resources through rman. */
|
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
rm = &acpi_rman_io;
|
|
|
|
break;
|
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
rm = &acpi_rman_mem;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("acpi_alloc_resource: invalid res type %d", type);
|
|
|
|
}
|
2004-06-13 22:52:30 +00:00
|
|
|
|
2004-06-23 17:21:02 +00:00
|
|
|
/* If we do know it, allocate it from the local pool. */
|
|
|
|
res = rman_reserve_resource(rm, start, end, count, flags & ~RF_ACTIVE,
|
|
|
|
child);
|
|
|
|
if (res == NULL)
|
|
|
|
return (NULL);
|
2004-06-13 22:52:30 +00:00
|
|
|
|
2004-06-27 13:04:19 +00:00
|
|
|
/* Copy the bus tag and handle from the pre-allocated resource. */
|
2004-06-23 17:21:02 +00:00
|
|
|
rman_set_bustag(res, rman_get_bustag(rle->res));
|
2004-06-28 03:36:37 +00:00
|
|
|
rman_set_bushandle(res, rman_get_start(res));
|
2004-06-23 17:21:02 +00:00
|
|
|
|
|
|
|
/* If requested, activate the resource using the parent's method. */
|
|
|
|
if (flags & RF_ACTIVE)
|
|
|
|
if (bus_activate_resource(child, type, *rid, res) != 0) {
|
|
|
|
rman_release_resource(res);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-06-23 17:21:02 +00:00
|
|
|
if (res != NULL && device_get_parent(child) == bus)
|
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
/*
|
|
|
|
* Since bus_config_intr() takes immediate effect, we cannot
|
|
|
|
* configure the interrupt associated with a device when we
|
|
|
|
* parse the resources but have to defer it until a driver
|
|
|
|
* actually allocates the interrupt via bus_alloc_resource().
|
|
|
|
*
|
|
|
|
* XXX: Should we handle the lookup failing?
|
|
|
|
*/
|
|
|
|
if (ACPI_SUCCESS(acpi_lookup_irq_resource(child, *rid, res, &ares)))
|
|
|
|
acpi_config_intr(child, &ares);
|
|
|
|
break;
|
2004-06-13 22:52:30 +00:00
|
|
|
}
|
|
|
|
return (res);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-13 22:52:30 +00:00
|
|
|
acpi_release_resource(device_t bus, device_t child, int type, int rid,
|
|
|
|
struct resource *r)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2004-06-13 22:52:30 +00:00
|
|
|
int ret;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
/*
|
|
|
|
* If we know about this address, deactivate it and release it to the
|
|
|
|
* local pool. If we don't, pass this request up to the parent.
|
|
|
|
*/
|
|
|
|
if (acpi_sysres_find(type, rman_get_start(r)) == NULL) {
|
|
|
|
if (rman_get_flags(r) & RF_ACTIVE) {
|
|
|
|
ret = bus_deactivate_resource(child, type, rid, r);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
ret = rman_release_resource(r);
|
|
|
|
} else
|
|
|
|
ret = BUS_RELEASE_RESOURCE(device_get_parent(bus), child, type, rid, r);
|
|
|
|
|
|
|
|
return (ret);
|
2003-11-15 19:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate an IO port or memory resource, given its GAS. */
|
|
|
|
struct resource *
|
|
|
|
acpi_bus_alloc_gas(device_t dev, int *rid, ACPI_GENERIC_ADDRESS *gas)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (gas == NULL || !ACPI_VALID_ADDRESS(gas->Address) ||
|
|
|
|
gas->RegisterBitWidth < 8)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
switch (gas->AddressSpaceId) {
|
|
|
|
case ACPI_ADR_SPACE_SYSTEM_MEMORY:
|
|
|
|
type = SYS_RES_MEMORY;
|
|
|
|
break;
|
|
|
|
case ACPI_ADR_SPACE_SYSTEM_IO:
|
|
|
|
type = SYS_RES_IOPORT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_set_resource(dev, type, *rid, gas->Address, gas->RegisterBitWidth / 8);
|
2004-03-17 17:50:55 +00:00
|
|
|
return (bus_alloc_resource_any(dev, type, rid, RF_ACTIVE));
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2004-06-29 01:33:35 +00:00
|
|
|
/* Probe _HID and _CID for compatible ISA PNP ids. */
|
2003-12-18 03:25:22 +00:00
|
|
|
static uint32_t
|
2001-09-07 02:57:29 +00:00
|
|
|
acpi_isa_get_logicalid(device_t dev)
|
2001-08-30 00:50:58 +00:00
|
|
|
{
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_DEVICE_INFO *devinfo;
|
|
|
|
ACPI_BUFFER buf;
|
2001-08-30 00:50:58 +00:00
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_STATUS error;
|
|
|
|
u_int32_t pnpid;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
2001-08-30 00:50:58 +00:00
|
|
|
|
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;
|
2003-12-23 18:47:31 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
ACPI_LOCK;
|
2001-09-07 02:57:29 +00:00
|
|
|
|
2003-07-13 22:57:16 +00:00
|
|
|
/* Fetch and validate the HID. */
|
2001-09-07 02:57:29 +00:00
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
2003-12-23 18:47:31 +00:00
|
|
|
goto out;
|
2003-07-13 22:57:16 +00:00
|
|
|
error = AcpiGetObjectInfo(h, &buf);
|
|
|
|
if (ACPI_FAILURE(error))
|
2003-12-23 18:47:31 +00:00
|
|
|
goto out;
|
2003-12-18 03:25:22 +00:00
|
|
|
devinfo = (ACPI_DEVICE_INFO *)buf.Pointer;
|
2001-08-30 00:50:58 +00:00
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
if ((devinfo->Valid & ACPI_VALID_HID) != 0)
|
|
|
|
pnpid = PNP_EISAID(devinfo->HardwareId.Value);
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2003-12-23 18:47:31 +00:00
|
|
|
out:
|
|
|
|
if (buf.Pointer != NULL)
|
|
|
|
AcpiOsFree(buf.Pointer);
|
2001-09-07 02:57:29 +00:00
|
|
|
ACPI_UNLOCK;
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (pnpid);
|
2001-09-07 02:57:29 +00:00
|
|
|
}
|
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
static int
|
|
|
|
acpi_isa_get_compatid(device_t dev, uint32_t *cids, int count)
|
2003-03-06 14:40:15 +00:00
|
|
|
{
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_DEVICE_INFO *devinfo;
|
|
|
|
ACPI_BUFFER buf;
|
2003-03-06 14:40:15 +00:00
|
|
|
ACPI_HANDLE h;
|
|
|
|
ACPI_STATUS error;
|
2003-12-18 03:25:22 +00:00
|
|
|
uint32_t *pnpid;
|
|
|
|
int valid, i;
|
2003-03-06 14:40:15 +00:00
|
|
|
ACPI_LOCK_DECL;
|
|
|
|
|
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
pnpid = cids;
|
|
|
|
valid = 0;
|
2003-12-23 18:47:31 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
|
2003-03-06 14:40:15 +00:00
|
|
|
ACPI_LOCK;
|
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
/* Fetch and validate the CID */
|
2003-03-06 14:40:15 +00:00
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
2003-12-23 18:47:31 +00:00
|
|
|
goto out;
|
2003-12-18 03:25:22 +00:00
|
|
|
error = AcpiGetObjectInfo(h, &buf);
|
|
|
|
if (ACPI_FAILURE(error))
|
2003-12-23 18:47:31 +00:00
|
|
|
goto out;
|
2003-12-18 03:25:22 +00:00
|
|
|
devinfo = (ACPI_DEVICE_INFO *)buf.Pointer;
|
|
|
|
if ((devinfo->Valid & ACPI_VALID_CID) == 0)
|
2003-03-06 14:40:15 +00:00
|
|
|
goto out;
|
2003-12-18 03:25:22 +00:00
|
|
|
|
|
|
|
if (devinfo->CompatibilityId.Count < count)
|
|
|
|
count = devinfo->CompatibilityId.Count;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (strncmp(devinfo->CompatibilityId.Id[i].Value, "PNP", 3) != 0)
|
|
|
|
continue;
|
|
|
|
*pnpid++ = PNP_EISAID(devinfo->CompatibilityId.Id[i].Value);
|
|
|
|
valid++;
|
|
|
|
}
|
2003-03-06 14:40:15 +00:00
|
|
|
|
|
|
|
out:
|
2003-12-23 18:47:31 +00:00
|
|
|
if (buf.Pointer != NULL)
|
|
|
|
AcpiOsFree(buf.Pointer);
|
2003-03-06 14:40:15 +00:00
|
|
|
ACPI_UNLOCK;
|
2003-12-18 03:25:22 +00:00
|
|
|
return_VALUE (valid);
|
2003-03-06 14:40:15 +00:00
|
|
|
}
|
|
|
|
|
2004-06-29 19:00:36 +00:00
|
|
|
static char *
|
|
|
|
acpi_device_id_probe(device_t bus, device_t dev, char **ids)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
h = acpi_get_handle(dev);
|
|
|
|
if (ids == NULL || h == NULL || acpi_get_type(dev) != ACPI_TYPE_DEVICE)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* Try to match one of the array of IDs with a HID or CID. */
|
|
|
|
for (i = 0; ids[i] != NULL; i++) {
|
|
|
|
if (acpi_MatchHid(h, ids[i]))
|
|
|
|
return (ids[i]);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_device_eval_obj(device_t bus, device_t dev, ACPI_STRING pathname,
|
|
|
|
ACPI_OBJECT_LIST *parameters, ACPI_BUFFER *ret)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
|
|
|
|
2004-07-15 16:29:08 +00:00
|
|
|
if (dev == NULL)
|
|
|
|
h = ACPI_ROOT_OBJECT;
|
|
|
|
else if ((h = acpi_get_handle(dev)) == NULL)
|
2004-06-29 19:00:36 +00:00
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
return (AcpiEvaluateObject(h, pathname, parameters, ret));
|
|
|
|
}
|
|
|
|
|
2004-07-15 16:29:08 +00:00
|
|
|
/* Callback arg for our implementation of walking the namespace. */
|
|
|
|
struct acpi_device_scan_ctx {
|
|
|
|
acpi_scan_cb_t user_fn;
|
|
|
|
void *arg;
|
|
|
|
ACPI_HANDLE parent;
|
|
|
|
};
|
|
|
|
|
2004-06-29 19:00:36 +00:00
|
|
|
static ACPI_STATUS
|
2004-07-15 16:29:08 +00:00
|
|
|
acpi_device_scan_cb(ACPI_HANDLE h, UINT32 level, void *arg, void **retval)
|
|
|
|
{
|
|
|
|
struct acpi_device_scan_ctx *ctx;
|
|
|
|
device_t dev, old_dev;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
ACPI_OBJECT_TYPE type;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip this device if we think we'll have trouble with it or it is
|
|
|
|
* the parent where the scan began.
|
|
|
|
*/
|
|
|
|
ctx = (struct acpi_device_scan_ctx *)arg;
|
|
|
|
if (acpi_avoid(h) || h == ctx->parent)
|
|
|
|
return (AE_OK);
|
|
|
|
|
|
|
|
/* If this is not a valid device type (e.g., a method), skip it. */
|
|
|
|
if (ACPI_FAILURE(AcpiGetType(h, &type)))
|
|
|
|
return (AE_OK);
|
|
|
|
if (type != ACPI_TYPE_DEVICE && type != ACPI_TYPE_PROCESSOR &&
|
|
|
|
type != ACPI_TYPE_THERMAL && type != ACPI_TYPE_POWER)
|
|
|
|
return (AE_OK);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the user function with the current device. If it is unchanged
|
|
|
|
* afterwards, return. Otherwise, we update the handle to the new dev.
|
|
|
|
*/
|
|
|
|
old_dev = acpi_get_device(h);
|
|
|
|
dev = old_dev;
|
|
|
|
status = ctx->user_fn(h, &dev, level, ctx->arg);
|
|
|
|
if (ACPI_FAILURE(status) || old_dev == dev)
|
|
|
|
return (status);
|
|
|
|
|
|
|
|
/* Remove the old child and its connection to the handle. */
|
|
|
|
if (old_dev != NULL) {
|
|
|
|
device_delete_child(device_get_parent(old_dev), old_dev);
|
|
|
|
AcpiDetachData(h, acpi_fake_objhandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recreate the handle association if the user created a device. */
|
|
|
|
if (dev != NULL)
|
|
|
|
AcpiAttachData(h, acpi_fake_objhandler, dev);
|
|
|
|
|
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
|
|
|
acpi_device_scan_children(device_t bus, device_t dev, int max_depth,
|
|
|
|
acpi_scan_cb_t user_fn, void *arg)
|
2004-06-29 19:00:36 +00:00
|
|
|
{
|
|
|
|
ACPI_HANDLE h;
|
2004-07-15 16:29:08 +00:00
|
|
|
struct acpi_device_scan_ctx ctx;
|
2004-06-29 19:00:36 +00:00
|
|
|
|
2004-07-15 16:29:08 +00:00
|
|
|
if (acpi_disabled("children"))
|
|
|
|
return (AE_OK);
|
|
|
|
|
|
|
|
if (dev == NULL)
|
|
|
|
h = ACPI_ROOT_OBJECT;
|
|
|
|
else if ((h = acpi_get_handle(dev)) == NULL)
|
2004-06-29 19:00:36 +00:00
|
|
|
return (AE_BAD_PARAMETER);
|
2004-07-15 16:29:08 +00:00
|
|
|
ctx.user_fn = user_fn;
|
|
|
|
ctx.arg = arg;
|
|
|
|
ctx.parent = h;
|
|
|
|
return (AcpiWalkNamespace(ACPI_TYPE_ANY, h, max_depth,
|
|
|
|
acpi_device_scan_cb, &ctx, NULL));
|
2004-06-29 19:00:36 +00:00
|
|
|
}
|
|
|
|
|
2001-09-07 02:57:29 +00:00
|
|
|
static int
|
|
|
|
acpi_isa_pnp_probe(device_t bus, device_t child, struct isa_pnp_id *ids)
|
|
|
|
{
|
2003-12-18 03:25:22 +00:00
|
|
|
int result, cid_count, i;
|
|
|
|
uint32_t lid, cids[8];
|
2001-09-07 02:57:29 +00:00
|
|
|
|
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;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Scan the supplied IDs for a match */
|
2003-03-06 14:40:15 +00:00
|
|
|
lid = acpi_isa_get_logicalid(child);
|
2003-12-18 03:25:22 +00:00
|
|
|
cid_count = acpi_isa_get_compatid(child, cids, 8);
|
2001-08-30 00:50:58 +00:00
|
|
|
while (ids && ids->ip_id) {
|
2003-12-18 03:25:22 +00:00
|
|
|
if (lid == ids->ip_id) {
|
2001-08-30 00:50:58 +00:00
|
|
|
result = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-12-18 03:25:22 +00:00
|
|
|
for (i = 0; i < cid_count; i++) {
|
|
|
|
if (cids[i] == ids->ip_id) {
|
|
|
|
result = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2001-08-30 00:50:58 +00:00
|
|
|
ids++;
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2001-08-30 00:50:58 +00:00
|
|
|
out:
|
2003-12-18 03:25:22 +00:00
|
|
|
return_VALUE (result);
|
2001-08-30 00:50:58 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Scan relevant portions of the ACPI namespace and attach child devices.
|
|
|
|
*
|
2003-08-28 16:06:30 +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)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_HANDLE parent;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
int i;
|
2004-06-13 22:52:30 +00:00
|
|
|
static char *scopes[] = {"\\_PR_", "\\_TZ_", "\\_SI", "\\_SB_", NULL};
|
2000-10-28 06:59:48 +00:00
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Scan the namespace and insert placeholders for all the devices that
|
2004-07-13 17:57:41 +00:00
|
|
|
* we find. We also probe/attach any early devices.
|
2000-10-28 06:59:48 +00:00
|
|
|
*
|
|
|
|
* Note that we use AcpiWalkNamespace rather than AcpiGetDevices because
|
2003-08-28 16:06:30 +00:00
|
|
|
* 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.)
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2001-08-26 22:50:15 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "namespace scan\n"));
|
2003-08-28 16:06:30 +00:00
|
|
|
for (i = 0; scopes[i] != NULL; i++) {
|
|
|
|
status = AcpiGetHandle(ACPI_ROOT_OBJECT, scopes[i], &parent);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100, acpi_probe_child,
|
|
|
|
bus, NULL);
|
|
|
|
}
|
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2004-07-13 17:57:41 +00:00
|
|
|
/* Create any static children by calling device identify methods. */
|
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "device identify routines\n"));
|
|
|
|
bus_generic_probe(bus);
|
|
|
|
|
|
|
|
/* Probe/attach all children, created staticly and from the namespace. */
|
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
|
|
|
|
2004-05-28 06:28:55 +00:00
|
|
|
/* Attach wake sysctls. */
|
2004-05-28 06:29:30 +00:00
|
|
|
acpi_wake_sysctl_walk(bus);
|
2004-05-28 06:28:55 +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
|
|
|
}
|
|
|
|
|
2004-06-14 04:01:12 +00:00
|
|
|
/*
|
|
|
|
* Determine the probe order for a given device and return non-zero if it
|
|
|
|
* should be attached immediately.
|
|
|
|
*/
|
2004-06-13 22:52:30 +00:00
|
|
|
static int
|
2004-06-14 04:01:12 +00:00
|
|
|
acpi_probe_order(ACPI_HANDLE handle, int *order)
|
2004-06-13 22:52:30 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2004-06-14 04:01:12 +00:00
|
|
|
/*
|
|
|
|
* 1. I/O port and memory system resource holders
|
|
|
|
* 2. Embedded controllers (to handle early accesses)
|
|
|
|
*/
|
2004-06-13 22:52:30 +00:00
|
|
|
ret = 0;
|
|
|
|
if (acpi_MatchHid(handle, "PNP0C01") || acpi_MatchHid(handle, "PNP0C02")) {
|
|
|
|
*order = 1;
|
|
|
|
ret = 1;
|
2004-06-14 04:01:12 +00:00
|
|
|
} else if (acpi_MatchHid(handle, "PNP0C09")) {
|
2004-06-13 22:52:30 +00:00
|
|
|
*order = 2;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
2004-06-14 04:01:12 +00:00
|
|
|
/* Always probe/attach immediately if we're debugging. */
|
|
|
|
ACPI_DEBUG_EXEC(ret = 1);
|
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
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;
|
2004-06-13 22:52:30 +00:00
|
|
|
device_t child, bus;
|
|
|
|
int order, probe_now;
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Skip this device if we think we'll have trouble with it. */
|
2000-12-08 09:16:20 +00:00
|
|
|
if (acpi_avoid(handle))
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2004-06-13 22:52:30 +00:00
|
|
|
bus = (device_t)context;
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetType(handle, &type))) {
|
2004-06-29 19:00:36 +00:00
|
|
|
switch (type) {
|
2000-10-28 06:59:48 +00:00
|
|
|
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;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
|
|
|
* Create a placeholder device for this node. Sort the placeholder
|
2004-06-14 04:01:12 +00:00
|
|
|
* so that the probe/attach passes will run breadth-first. Orders
|
|
|
|
* less than 10 are reserved for special objects (i.e., system
|
|
|
|
* resources). Larger values are used for all other devices.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_DEBUG_PRINT((ACPI_DB_OBJECTS, "scanning '%s'\n",
|
|
|
|
acpi_name(handle)));
|
2004-06-14 04:01:12 +00:00
|
|
|
order = (level + 1) * 10;
|
|
|
|
probe_now = acpi_probe_order(handle, &order);
|
2004-06-13 22:52:30 +00:00
|
|
|
child = BUS_ADD_CHILD(bus, order, NULL, -1);
|
2001-08-30 00:50:58 +00:00
|
|
|
if (child == NULL)
|
|
|
|
break;
|
2004-06-13 17:29:35 +00:00
|
|
|
|
|
|
|
/* Associate the handle with the device_t and vice versa. */
|
2000-10-28 06:59:48 +00:00
|
|
|
acpi_set_handle(child, handle);
|
2004-06-13 17:29:35 +00:00
|
|
|
AcpiAttachData(handle, acpi_fake_objhandler, child);
|
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).
|
|
|
|
*/
|
2003-08-28 16:06:30 +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.
|
|
|
|
*/
|
2004-03-31 17:23:46 +00:00
|
|
|
acpi_parse_resources(child, handle, &acpi_res_parse_set, NULL);
|
2001-08-30 00:50:58 +00:00
|
|
|
|
2004-06-14 03:52:19 +00:00
|
|
|
/* If order was overridden, probe/attach now rather than later. */
|
2004-06-13 22:52:30 +00:00
|
|
|
if (probe_now)
|
|
|
|
device_probe_and_attach(child);
|
2000-12-08 09:16:20 +00:00
|
|
|
break;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return_ACPI_STATUS (AE_OK);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2004-06-13 17:29:35 +00:00
|
|
|
/*
|
|
|
|
* AcpiAttachData() requires an object handler but never uses it. This is a
|
|
|
|
* placeholder object handler so we can store a device_t in an ACPI_HANDLE.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_fake_objhandler(ACPI_HANDLE h, UINT32 fn, void *data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
static void
|
|
|
|
acpi_shutdown_final(void *arg, int howto)
|
|
|
|
{
|
2004-04-26 08:49:11 +00:00
|
|
|
ACPI_STATUS status;
|
2001-06-29 20:29:59 +00:00
|
|
|
|
2004-03-19 07:05:01 +00:00
|
|
|
/*
|
2004-06-24 00:48:45 +00:00
|
|
|
* XXX Shutdown code should only run on the BSP (cpuid 0).
|
|
|
|
* Some chipsets do not power off the system correctly if called from
|
|
|
|
* an AP.
|
2004-03-19 07:05:01 +00:00
|
|
|
*/
|
2003-08-28 16:06:30 +00:00
|
|
|
if ((howto & RB_POWEROFF) != 0) {
|
2004-04-26 05:25:06 +00:00
|
|
|
status = AcpiEnterSleepStatePrep(ACPI_STATE_S5);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
printf("AcpiEnterSleepStatePrep failed - %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
return;
|
|
|
|
}
|
2003-07-20 00:52:57 +00:00
|
|
|
printf("Powering system off using ACPI\n");
|
2004-06-24 00:48:45 +00:00
|
|
|
ACPI_DISABLE_IRQS();
|
|
|
|
status = AcpiEnterSleepState(ACPI_STATE_S5);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
printf("ACPI power-off failed - %s\n", AcpiFormatException(status));
|
|
|
|
} else {
|
|
|
|
DELAY(1000000);
|
|
|
|
printf("ACPI power-off failed - timeout\n");
|
|
|
|
}
|
2002-05-19 15:12:40 +00:00
|
|
|
} else {
|
2003-07-20 00:52:57 +00:00
|
|
|
printf("Shutting down ACPI\n");
|
2002-05-19 15:12:40 +00:00
|
|
|
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
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
|
|
|
/* Enable and clear fixed events and install handlers. */
|
2003-08-28 16:06:30 +00:00
|
|
|
if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->PwrButton == 0) {
|
2003-08-15 02:10:38 +00:00
|
|
|
AcpiClearEvent(ACPI_EVENT_POWER_BUTTON);
|
2001-06-29 20:29:59 +00:00
|
|
|
AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON,
|
2004-02-11 02:57:33 +00:00
|
|
|
acpi_event_power_button_sleep, sc);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (first_time)
|
2003-09-18 05:12:45 +00:00
|
|
|
device_printf(sc->acpi_dev, "Power Button (fixed)\n");
|
2001-06-29 20:29:59 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->SleepButton == 0) {
|
2003-08-15 02:10:38 +00:00
|
|
|
AcpiClearEvent(ACPI_EVENT_SLEEP_BUTTON);
|
2001-06-29 20:29:59 +00:00
|
|
|
AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON,
|
2004-02-11 02:57:33 +00:00
|
|
|
acpi_event_sleep_button_sleep, sc);
|
2003-08-28 16:06:30 +00:00
|
|
|
if (first_time)
|
2003-09-18 05:12:45 +00:00
|
|
|
device_printf(sc->acpi_dev, "Sleep Button (fixed)\n");
|
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)
|
|
|
|
{
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_DEVICE_INFO *devinfo;
|
2001-06-28 06:17:16 +00:00
|
|
|
ACPI_HANDLE h;
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_BUFFER buf;
|
2001-06-28 06:17:16 +00:00
|
|
|
ACPI_STATUS error;
|
2003-12-18 03:25:22 +00:00
|
|
|
int ret;
|
2001-06-29 20:29:59 +00:00
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
ret = FALSE;
|
2001-06-28 06:17:16 +00:00
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (FALSE);
|
2003-12-18 03:25:22 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
2003-07-13 22:57:16 +00:00
|
|
|
error = AcpiGetObjectInfo(h, &buf);
|
|
|
|
if (ACPI_FAILURE(error))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (FALSE);
|
2003-12-18 03:25:22 +00:00
|
|
|
devinfo = (ACPI_DEVICE_INFO *)buf.Pointer;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* If no _STA method, must be present */
|
2003-12-18 03:25:22 +00:00
|
|
|
if ((devinfo->Valid & ACPI_VALID_STA) == 0)
|
|
|
|
ret = TRUE;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* Return true for 'present' and 'functioning' */
|
2003-12-18 03:25:22 +00:00
|
|
|
if ((devinfo->CurrentStatus & 0x9) == 0x9)
|
|
|
|
ret = TRUE;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
return (ret);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2002-02-23 05:21:56 +00:00
|
|
|
/*
|
|
|
|
* Returns true if the battery is actually present and inserted.
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
acpi_BatteryIsPresent(device_t dev)
|
|
|
|
{
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_DEVICE_INFO *devinfo;
|
2002-02-23 05:21:56 +00:00
|
|
|
ACPI_HANDLE h;
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_BUFFER buf;
|
2002-02-23 05:21:56 +00:00
|
|
|
ACPI_STATUS error;
|
2003-12-18 03:25:22 +00:00
|
|
|
int ret;
|
2002-02-23 05:21:56 +00:00
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
ret = FALSE;
|
2002-02-23 05:21:56 +00:00
|
|
|
if ((h = acpi_get_handle(dev)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (FALSE);
|
2003-12-18 03:25:22 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
2003-07-13 22:57:16 +00:00
|
|
|
error = AcpiGetObjectInfo(h, &buf);
|
|
|
|
if (ACPI_FAILURE(error))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (FALSE);
|
2003-12-18 03:25:22 +00:00
|
|
|
devinfo = (ACPI_DEVICE_INFO *)buf.Pointer;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* If no _STA method, must be present */
|
2003-12-18 03:25:22 +00:00
|
|
|
if ((devinfo->Valid & ACPI_VALID_STA) == 0)
|
|
|
|
ret = TRUE;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
/* Return true for 'present' and 'functioning' */
|
2003-12-18 03:25:22 +00:00
|
|
|
if ((devinfo->CurrentStatus & 0x19) == 0x19)
|
|
|
|
ret = TRUE;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
return (ret);
|
2002-02-23 05:21:56 +00:00
|
|
|
}
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
/*
|
2004-06-13 22:52:30 +00:00
|
|
|
* Match a HID string against a handle
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2004-06-29 19:00:36 +00:00
|
|
|
static BOOLEAN
|
|
|
|
acpi_MatchHid(ACPI_HANDLE h, const char *hid)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2003-12-18 03:25:22 +00:00
|
|
|
ACPI_DEVICE_INFO *devinfo;
|
|
|
|
ACPI_BUFFER buf;
|
2000-10-28 06:59:48 +00:00
|
|
|
ACPI_STATUS error;
|
2003-12-18 03:25:22 +00:00
|
|
|
int ret, i;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2001-06-29 20:29:59 +00:00
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
ret = FALSE;
|
2004-06-13 22:52:30 +00:00
|
|
|
if (hid == NULL || h == NULL)
|
|
|
|
return (ret);
|
2003-12-18 03:25:22 +00:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
2003-07-13 22:57:16 +00:00
|
|
|
error = AcpiGetObjectInfo(h, &buf);
|
|
|
|
if (ACPI_FAILURE(error))
|
2004-06-13 22:52:30 +00:00
|
|
|
return (ret);
|
2003-12-18 03:25:22 +00:00
|
|
|
devinfo = (ACPI_DEVICE_INFO *)buf.Pointer;
|
|
|
|
|
2003-12-26 15:42:13 +00:00
|
|
|
if ((devinfo->Valid & ACPI_VALID_HID) != 0 &&
|
|
|
|
strcmp(hid, devinfo->HardwareId.Value) == 0)
|
2003-12-18 03:25:22 +00:00
|
|
|
ret = TRUE;
|
2003-12-26 15:42:13 +00:00
|
|
|
else if ((devinfo->Valid & ACPI_VALID_CID) != 0) {
|
2003-12-18 03:25:22 +00:00
|
|
|
for (i = 0; i < devinfo->CompatibilityId.Count; i++) {
|
|
|
|
if (strcmp(hid, devinfo->CompatibilityId.Id[i].Value) == 0) {
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2003-12-18 03:25:22 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
return (ret);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Walk back up the tree to the root */
|
2001-06-28 06:17:16 +00:00
|
|
|
for (;;) {
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiGetHandle(parent, path, &r);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
2001-06-28 06:17:16 +00:00
|
|
|
*result = r;
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_OK);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
if (status != AE_NOT_FOUND)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_OK);
|
2002-02-23 05:21:56 +00:00
|
|
|
if (ACPI_FAILURE(AcpiGetParent(parent, &r)))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_NOT_FOUND);
|
2001-06-28 06:17:16 +00:00
|
|
|
parent = r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-21 00:36:15 +00:00
|
|
|
/* Find the difference between two PM tick counts. */
|
|
|
|
uint32_t
|
|
|
|
acpi_TimerDelta(uint32_t end, uint32_t start)
|
|
|
|
{
|
|
|
|
uint32_t delta;
|
|
|
|
|
|
|
|
if (end >= start)
|
|
|
|
delta = end - start;
|
|
|
|
else if (AcpiGbl_FADT->TmrValExt == 0)
|
2004-04-21 00:38:54 +00:00
|
|
|
delta = ((0x00FFFFFF - start) + end + 1) & 0x00FFFFFF;
|
2004-04-21 00:36:15 +00:00
|
|
|
else
|
|
|
|
delta = ((0xFFFFFFFF - start) + end + 1);
|
|
|
|
return (delta);
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* 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)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (NULL);
|
2001-06-28 06:17:16 +00:00
|
|
|
buf->Length = size;
|
|
|
|
buf->Pointer = (void *)(buf + 1);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (buf);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2004-03-03 18:34:42 +00:00
|
|
|
ACPI_STATUS
|
2004-03-09 05:41:28 +00:00
|
|
|
acpi_SetInteger(ACPI_HANDLE handle, char *path, UINT32 number)
|
2004-03-03 18:34:42 +00:00
|
|
|
{
|
|
|
|
ACPI_OBJECT arg1;
|
|
|
|
ACPI_OBJECT_LIST args;
|
|
|
|
|
|
|
|
ACPI_ASSERTLOCK;
|
|
|
|
|
|
|
|
arg1.Type = ACPI_TYPE_INTEGER;
|
|
|
|
arg1.Integer.Value = number;
|
|
|
|
args.Count = 1;
|
|
|
|
args.Pointer = &arg1;
|
|
|
|
|
|
|
|
return (AcpiEvaluateObject(handle, path, &args, NULL));
|
|
|
|
}
|
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
/*
|
|
|
|
* Evaluate a path that should return an integer.
|
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
2004-03-09 05:41:28 +00:00
|
|
|
acpi_GetInteger(ACPI_HANDLE handle, char *path, UINT32 *number)
|
2001-06-28 06:17:16 +00:00
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_STATUS status;
|
2001-06-28 06:17:16 +00:00
|
|
|
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);
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(handle, path, NULL, &buf);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
|
|
|
if (param.Type == ACPI_TYPE_INTEGER)
|
2001-06-28 06:17:16 +00:00
|
|
|
*number = param.Integer.Value;
|
2003-08-28 16:06:30 +00:00
|
|
|
else
|
|
|
|
status = AE_TYPE;
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
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.
|
|
|
|
*/
|
2003-08-28 16:06:30 +00:00
|
|
|
if (status == AE_BUFFER_OVERFLOW) {
|
2002-02-23 05:21:56 +00:00
|
|
|
if ((buf.Pointer = AcpiOsAllocate(buf.Length)) == NULL) {
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AE_NO_MEMORY;
|
2001-09-06 23:16:55 +00:00
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEvaluateObject(handle, path, NULL, &buf);
|
|
|
|
if (ACPI_SUCCESS(status))
|
|
|
|
status = acpi_ConvertBufferToInteger(&buf, number);
|
2003-09-04 15:55:41 +00:00
|
|
|
AcpiOsFree(buf.Pointer);
|
2001-09-06 23:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
return (status);
|
2001-06-28 06:17:16 +00:00
|
|
|
}
|
|
|
|
|
2001-12-22 16:05:41 +00:00
|
|
|
ACPI_STATUS
|
2004-03-09 05:41:28 +00:00
|
|
|
acpi_ConvertBufferToInteger(ACPI_BUFFER *bufp, UINT32 *number)
|
2001-12-22 16:05:41 +00:00
|
|
|
{
|
|
|
|
ACPI_OBJECT *p;
|
2004-03-09 05:44:47 +00:00
|
|
|
UINT8 *val;
|
2001-12-22 16:05:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
p = (ACPI_OBJECT *)bufp->Pointer;
|
|
|
|
if (p->Type == ACPI_TYPE_INTEGER) {
|
|
|
|
*number = p->Integer.Value;
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_OK);
|
2001-12-22 16:05:41 +00:00
|
|
|
}
|
|
|
|
if (p->Type != ACPI_TYPE_BUFFER)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_TYPE);
|
2001-12-22 16:05:41 +00:00
|
|
|
if (p->Buffer.Length > sizeof(int))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_BAD_DATA);
|
|
|
|
|
2001-12-22 16:05:41 +00:00
|
|
|
*number = 0;
|
2004-03-09 05:44:47 +00:00
|
|
|
val = p->Buffer.Pointer;
|
2001-12-22 16:05:41 +00:00
|
|
|
for (i = 0; i < p->Buffer.Length; i++)
|
2004-03-09 05:44:47 +00:00
|
|
|
*number += val[i] << (i * 8);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_OK);
|
2001-12-22 16:05:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_ForeachPackageObject(ACPI_OBJECT *pkg,
|
|
|
|
void (*func)(ACPI_OBJECT *comp, void *arg), void *arg)
|
2001-06-28 06:17:16 +00:00
|
|
|
{
|
|
|
|
ACPI_OBJECT *comp;
|
|
|
|
int i;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (pkg == NULL || pkg->Type != ACPI_TYPE_PACKAGE)
|
|
|
|
return (AE_BAD_PARAMETER);
|
2001-06-28 06:17:16 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Iterate over components */
|
|
|
|
i = 0;
|
|
|
|
comp = pkg->Package.Elements;
|
|
|
|
for (; i < pkg->Package.Count; i++, comp++)
|
2001-06-28 06:17:16 +00:00
|
|
|
func(comp, arg);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
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) {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Range check */
|
2001-07-30 08:59:43 +00:00
|
|
|
if (rp > (ACPI_RESOURCE *)((u_int8_t *)buf->Pointer + buf->Length))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
|
|
|
|
/* Check for terminator */
|
|
|
|
if (rp->Id == ACPI_RSTYPE_END_TAG || rp->Length == 0)
|
|
|
|
return (AE_NOT_FOUND);
|
2004-02-19 18:20:03 +00:00
|
|
|
rp = ACPI_NEXT_RESOURCE(rp);
|
2001-07-05 07:14:30 +00:00
|
|
|
}
|
|
|
|
if (resp != NULL)
|
2001-07-30 08:59:43 +00:00
|
|
|
*resp = rp;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (AE_OK);
|
2001-07-30 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Initialise the buffer if necessary. */
|
2001-07-30 08:59:43 +00:00
|
|
|
if (buf->Pointer == NULL) {
|
|
|
|
buf->Length = ACPI_INITIAL_RESOURCE_BUFFER_SIZE;
|
|
|
|
if ((buf->Pointer = AcpiOsAllocate(buf->Length)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_NO_MEMORY);
|
2001-07-30 08:59:43 +00:00
|
|
|
rp = (ACPI_RESOURCE *)buf->Pointer;
|
|
|
|
rp->Id = ACPI_RSTYPE_END_TAG;
|
|
|
|
rp->Length = 0;
|
|
|
|
}
|
|
|
|
if (res == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_OK);
|
2001-07-30 08:59:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 (;;) {
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Range check, don't go outside the buffer */
|
2001-07-30 08:59:43 +00:00
|
|
|
if (rp >= (ACPI_RESOURCE *)((u_int8_t *)buf->Pointer + buf->Length))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_BAD_PARAMETER);
|
|
|
|
if (rp->Id == ACPI_RSTYPE_END_TAG || rp->Length == 0)
|
2001-07-30 08:59:43 +00:00
|
|
|
break;
|
2004-02-19 18:20:03 +00:00
|
|
|
rp = ACPI_NEXT_RESOURCE(rp);
|
2001-07-30 08:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_NO_MEMORY);
|
2001-07-30 08:59:43 +00:00
|
|
|
bcopy(buf->Pointer, newp, buf->Length);
|
2003-08-28 16:06:30 +00:00
|
|
|
rp = (ACPI_RESOURCE *)((u_int8_t *)newp +
|
2001-08-03 08:38:11 +00:00
|
|
|
((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;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Insert the new resource. */
|
2001-07-30 08:59:43 +00:00
|
|
|
bcopy(res, rp, res->Length + ACPI_RESOURCE_LENGTH_NO_DATA);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* And add the terminator. */
|
2004-02-19 18:20:03 +00:00
|
|
|
rp = ACPI_NEXT_RESOURCE(rp);
|
2001-07-30 08:59:43 +00:00
|
|
|
rp->Id = ACPI_RSTYPE_END_TAG;
|
|
|
|
rp->Length = 0;
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return (AE_OK);
|
2001-07-05 07:14:30 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2004-03-03 18:34:42 +00:00
|
|
|
|
|
|
|
return (acpi_SetInteger(ACPI_ROOT_OBJECT, "_PIC", model));
|
2002-09-06 16:08:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2003-08-28 16:06:30 +00:00
|
|
|
* Currently we support S1-S5 but S4 is only S4BIOS
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
2003-09-09 04:09:25 +00:00
|
|
|
/* Avoid reentry if already attempting to suspend. */
|
2001-11-23 05:57:03 +00:00
|
|
|
if (sc->acpi_sstate != ACPI_STATE_S0)
|
2003-09-09 04:09:25 +00:00
|
|
|
return_ACPI_STATUS (AE_BAD_PARAMETER);
|
2001-11-23 05:57:03 +00:00
|
|
|
|
2003-09-09 04:09:25 +00:00
|
|
|
/* We recently woke up so don't suspend again for a while. */
|
2001-12-09 18:02:36 +00:00
|
|
|
if (sc->acpi_sleep_disabled)
|
2003-09-09 04:09:25 +00:00
|
|
|
return_ACPI_STATUS (AE_OK);
|
2001-12-09 18:02:36 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
switch (state) {
|
|
|
|
case ACPI_STATE_S1:
|
2001-07-20 06:07:34 +00:00
|
|
|
case ACPI_STATE_S2:
|
|
|
|
case ACPI_STATE_S3:
|
|
|
|
case ACPI_STATE_S4:
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiGetSleepTypeData((UINT8)state, &TypeA, &TypeB);
|
2003-09-09 04:09:25 +00:00
|
|
|
if (status == AE_NOT_FOUND) {
|
|
|
|
device_printf(sc->acpi_dev,
|
|
|
|
"Sleep state S%d not supported by BIOS\n", state);
|
|
|
|
break;
|
|
|
|
} else if (ACPI_FAILURE(status)) {
|
2003-08-28 16:06:30 +00:00
|
|
|
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;
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* Enable any GPEs as appropriate and requested by the user. */
|
|
|
|
acpi_wake_prep_walk(state);
|
2004-05-27 18:38:45 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* Inform all devices that we are going to sleep. */
|
2000-10-28 06:59:48 +00:00
|
|
|
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);
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (AE_ERROR);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2001-11-28 12:09:42 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEnterSleepStatePrep(state);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
2001-11-28 12:09:42 +00:00
|
|
|
device_printf(sc->acpi_dev, "AcpiEnterSleepStatePrep failed - %s\n",
|
|
|
|
AcpiFormatException(status));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (sc->acpi_sleep_delay > 0)
|
2002-08-25 06:13:53 +00:00
|
|
|
DELAY(sc->acpi_sleep_delay * 1000000);
|
|
|
|
|
2001-07-20 06:07:34 +00:00
|
|
|
if (state != ACPI_STATE_S1) {
|
|
|
|
acpi_sleep_machdep(sc, state);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* AcpiEnterSleepState() may be incomplete, unlock if locked. */
|
2003-08-15 02:10:38 +00:00
|
|
|
if (AcpiGbl_MutexInfo[ACPI_MTX_HARDWARE].OwnerId !=
|
|
|
|
ACPI_MUTEX_NOT_ACQUIRED) {
|
|
|
|
|
2002-07-22 12:52:54 +00:00
|
|
|
AcpiUtReleaseMutex(ACPI_MTX_HARDWARE);
|
|
|
|
}
|
2001-07-20 06:07:34 +00:00
|
|
|
|
|
|
|
/* Re-enable ACPI hardware on wakeup from sleep state 4. */
|
2003-08-28 16:06:30 +00:00
|
|
|
if (state == ACPI_STATE_S4)
|
2001-11-15 15:12:08 +00:00
|
|
|
AcpiEnable();
|
2001-07-20 06:07:34 +00:00
|
|
|
} else {
|
2003-08-28 16:06:30 +00:00
|
|
|
status = AcpiEnterSleepState((UINT8)state);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
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
|
|
|
}
|
2004-06-30 16:08:03 +00:00
|
|
|
|
|
|
|
/* Resume devices, re-enable GPEs and fixed events. */
|
|
|
|
acpi_wake_prep_walk(state);
|
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;
|
2003-09-09 04:09:25 +00:00
|
|
|
case ACPI_STATE_S0:
|
2000-10-28 06:59:48 +00:00
|
|
|
default:
|
|
|
|
status = AE_BAD_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2001-12-09 18:02:36 +00:00
|
|
|
|
2003-09-09 04:09:25 +00:00
|
|
|
/* Disable a second sleep request for a short period */
|
2001-12-09 18:02:36 +00:00
|
|
|
if (sc->acpi_sleep_disabled)
|
|
|
|
timeout(acpi_sleep_enable, (caddr_t)sc, hz * ACPI_MINIMUM_AWAKETIME);
|
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_ACPI_STATUS (status);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2004-05-27 18:38:45 +00:00
|
|
|
/* Initialize a device's wake GPE. */
|
|
|
|
int
|
|
|
|
acpi_wake_init(device_t dev, int type)
|
|
|
|
{
|
|
|
|
struct acpi_prw_data prw;
|
|
|
|
|
|
|
|
/* Evaluate _PRW to find the GPE. */
|
|
|
|
if (acpi_parse_prw(acpi_get_handle(dev), &prw) != 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/* Set the requested type for the GPE (runtime, wake, or both). */
|
|
|
|
if (ACPI_FAILURE(AcpiSetGpeType(prw.gpe_handle, prw.gpe_bit, type))) {
|
|
|
|
device_printf(dev, "set GPE type failed\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable or disable the device's wake GPE. */
|
|
|
|
int
|
|
|
|
acpi_wake_set_enable(device_t dev, int enable)
|
|
|
|
{
|
|
|
|
struct acpi_prw_data prw;
|
|
|
|
ACPI_HANDLE handle;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
int flags;
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* Make sure the device supports waking the system and get the GPE. */
|
2004-05-27 18:38:45 +00:00
|
|
|
handle = acpi_get_handle(dev);
|
|
|
|
if (acpi_parse_prw(handle, &prw) != 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
flags = acpi_get_flags(dev);
|
2004-05-27 18:38:45 +00:00
|
|
|
if (enable) {
|
|
|
|
status = AcpiEnableGpe(prw.gpe_handle, prw.gpe_bit, ACPI_NOT_ISR);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev, "enable wake failed\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2004-06-30 16:08:03 +00:00
|
|
|
acpi_set_flags(dev, flags | ACPI_FLAG_WAKE_ENABLED);
|
2004-05-27 18:38:45 +00:00
|
|
|
} else {
|
|
|
|
status = AcpiDisableGpe(prw.gpe_handle, prw.gpe_bit, ACPI_NOT_ISR);
|
|
|
|
if (ACPI_FAILURE(status)) {
|
|
|
|
device_printf(dev, "disable wake failed\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2004-06-30 16:08:03 +00:00
|
|
|
acpi_set_flags(dev, flags & ~ACPI_FLAG_WAKE_ENABLED);
|
2004-05-27 18:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
static int
|
|
|
|
acpi_wake_sleep_prep(ACPI_HANDLE handle, int sstate)
|
2004-05-27 18:38:45 +00:00
|
|
|
{
|
|
|
|
struct acpi_prw_data prw;
|
2004-06-30 16:08:03 +00:00
|
|
|
device_t dev;
|
2004-05-28 07:04:09 +00:00
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* Check that this is a wake-capable device and get its GPE. */
|
2004-05-27 18:38:45 +00:00
|
|
|
if (acpi_parse_prw(handle, &prw) != 0)
|
|
|
|
return (ENXIO);
|
2004-06-30 16:08:03 +00:00
|
|
|
dev = acpi_get_device(handle);
|
2004-05-27 18:38:45 +00:00
|
|
|
|
|
|
|
/*
|
2004-06-30 16:08:03 +00:00
|
|
|
* The destination sleep state must be less than (i.e., higher power)
|
|
|
|
* or equal to the value specified by _PRW. If this GPE cannot be
|
|
|
|
* enabled for the next sleep state, then disable it. If it can and
|
|
|
|
* the user requested it be enabled, turn on any required power resources
|
|
|
|
* and set _PSW.
|
2004-05-27 18:38:45 +00:00
|
|
|
*/
|
2004-06-30 16:08:03 +00:00
|
|
|
if (sstate > prw.lowest_wake) {
|
|
|
|
AcpiDisableGpe(prw.gpe_handle, prw.gpe_bit, ACPI_NOT_ISR);
|
2004-05-27 18:38:45 +00:00
|
|
|
if (bootverbose)
|
2004-06-30 16:08:03 +00:00
|
|
|
device_printf(dev, "wake_prep disabled wake for %s (S%d)\n",
|
|
|
|
acpi_name(handle), sstate);
|
|
|
|
} else if (dev && (acpi_get_flags(dev) & ACPI_FLAG_WAKE_ENABLED) != 0) {
|
|
|
|
acpi_pwr_wake_enable(handle, 1);
|
2004-05-28 07:04:09 +00:00
|
|
|
acpi_SetInteger(handle, "_PSW", 1);
|
2004-06-30 16:08:03 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "wake_prep enabled for %s (S%d)\n",
|
|
|
|
acpi_name(handle), sstate);
|
2004-05-27 18:38:45 +00:00
|
|
|
}
|
|
|
|
|
2004-05-28 07:04:09 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
static int
|
|
|
|
acpi_wake_run_prep(ACPI_HANDLE handle, int sstate)
|
2004-05-28 07:04:09 +00:00
|
|
|
{
|
|
|
|
struct acpi_prw_data prw;
|
2004-06-30 16:08:03 +00:00
|
|
|
device_t dev;
|
2004-05-28 07:04:09 +00:00
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/*
|
|
|
|
* Check that this is a wake-capable device and get its GPE. Return
|
|
|
|
* now if the user didn't enable this device for wake.
|
|
|
|
*/
|
2004-05-28 07:04:09 +00:00
|
|
|
if (acpi_parse_prw(handle, &prw) != 0)
|
|
|
|
return (ENXIO);
|
2004-06-30 16:08:03 +00:00
|
|
|
dev = acpi_get_device(handle);
|
|
|
|
if (dev == NULL || (acpi_get_flags(dev) & ACPI_FLAG_WAKE_ENABLED) == 0)
|
|
|
|
return (0);
|
2004-05-28 07:04:09 +00:00
|
|
|
|
|
|
|
/*
|
2004-06-30 16:08:03 +00:00
|
|
|
* If this GPE couldn't be enabled for the previous sleep state, it was
|
|
|
|
* disabled before going to sleep so re-enable it. If it was enabled,
|
|
|
|
* clear _PSW and turn off any power resources it used.
|
2004-05-28 07:04:09 +00:00
|
|
|
*/
|
2004-06-30 16:08:03 +00:00
|
|
|
if (sstate > prw.lowest_wake) {
|
2004-05-28 07:04:09 +00:00
|
|
|
AcpiEnableGpe(prw.gpe_handle, prw.gpe_bit, ACPI_NOT_ISR);
|
2004-06-30 16:08:03 +00:00
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "run_prep re-enabled %s\n", acpi_name(handle));
|
|
|
|
} else {
|
|
|
|
acpi_SetInteger(handle, "_PSW", 0);
|
|
|
|
acpi_pwr_wake_enable(handle, 0);
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(dev, "run_prep cleaned up for %s\n",
|
|
|
|
acpi_name(handle));
|
|
|
|
}
|
|
|
|
|
2004-05-27 18:38:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ACPI_STATUS
|
2004-06-30 16:08:03 +00:00
|
|
|
acpi_wake_prep(ACPI_HANDLE handle, UINT32 level, void *context, void **status)
|
2004-05-27 18:38:45 +00:00
|
|
|
{
|
2004-06-30 16:08:03 +00:00
|
|
|
int sstate;
|
2004-05-27 18:38:45 +00:00
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* If suspending, run the sleep prep function, otherwise wake. */
|
|
|
|
sstate = *(int *)context;
|
|
|
|
if (AcpiGbl_SystemAwakeAndRunning)
|
|
|
|
acpi_wake_sleep_prep(handle, sstate);
|
|
|
|
else
|
|
|
|
acpi_wake_run_prep(handle, sstate);
|
2004-05-27 18:38:45 +00:00
|
|
|
return (AE_OK);
|
|
|
|
}
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* Walk the tree rooted at acpi0 to prep devices for suspend/resume. */
|
2004-05-27 18:38:45 +00:00
|
|
|
static int
|
2004-06-30 16:08:03 +00:00
|
|
|
acpi_wake_prep_walk(int sstate)
|
2004-05-27 18:38:45 +00:00
|
|
|
{
|
|
|
|
ACPI_HANDLE sb_handle;
|
|
|
|
|
|
|
|
if (ACPI_SUCCESS(AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &sb_handle)))
|
2004-06-30 16:08:03 +00:00
|
|
|
AcpiWalkNamespace(ACPI_TYPE_DEVICE, sb_handle, 100,
|
|
|
|
acpi_wake_prep, &sstate, NULL);
|
2004-05-27 18:38:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-05-28 06:28:55 +00:00
|
|
|
/* Walk the tree rooted at acpi0 to attach per-device wake sysctls. */
|
|
|
|
static int
|
|
|
|
acpi_wake_sysctl_walk(device_t dev)
|
|
|
|
{
|
|
|
|
int error, i, numdevs;
|
|
|
|
device_t *devlist;
|
|
|
|
device_t child;
|
2004-06-30 16:08:03 +00:00
|
|
|
ACPI_STATUS status;
|
2004-05-28 06:28:55 +00:00
|
|
|
|
|
|
|
error = device_get_children(dev, &devlist, &numdevs);
|
|
|
|
if (error != 0 || numdevs == 0)
|
|
|
|
return (error);
|
|
|
|
for (i = 0; i < numdevs; i++) {
|
|
|
|
child = devlist[i];
|
2004-06-30 16:08:03 +00:00
|
|
|
acpi_wake_sysctl_walk(child);
|
2004-05-28 06:28:55 +00:00
|
|
|
if (!device_is_attached(child))
|
|
|
|
continue;
|
2004-06-30 16:08:03 +00:00
|
|
|
status = AcpiEvaluateObject(acpi_get_handle(child), "_PRW", NULL, NULL);
|
|
|
|
if (ACPI_SUCCESS(status)) {
|
2004-05-28 06:28:55 +00:00
|
|
|
SYSCTL_ADD_PROC(device_get_sysctl_ctx(child),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(child)), OID_AUTO,
|
|
|
|
"wake", CTLTYPE_INT | CTLFLAG_RW, child, 0,
|
|
|
|
acpi_wake_set_sysctl, "I", "Device set to wake the system");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(devlist, M_TEMP);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable or disable wake from userland. */
|
|
|
|
static int
|
|
|
|
acpi_wake_set_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int enable, error;
|
|
|
|
device_t dev;
|
|
|
|
|
|
|
|
dev = (device_t)arg1;
|
2004-06-30 16:08:03 +00:00
|
|
|
enable = (acpi_get_flags(dev) & ACPI_FLAG_WAKE_ENABLED) ? 1 : 0;
|
2004-05-28 06:28:55 +00:00
|
|
|
|
|
|
|
error = sysctl_handle_int(oidp, &enable, 0, req);
|
|
|
|
if (error != 0 || req->newptr == NULL)
|
|
|
|
return (error);
|
|
|
|
if (enable != 0 && enable != 1)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
return (acpi_wake_set_enable(dev, enable));
|
|
|
|
}
|
|
|
|
|
2004-05-27 18:38:45 +00:00
|
|
|
/* Parse a device's _PRW into a structure. */
|
2004-06-30 16:08:03 +00:00
|
|
|
int
|
2004-05-27 18:38:45 +00:00
|
|
|
acpi_parse_prw(ACPI_HANDLE h, struct acpi_prw_data *prw)
|
|
|
|
{
|
|
|
|
ACPI_STATUS status;
|
|
|
|
ACPI_BUFFER prw_buffer;
|
|
|
|
ACPI_OBJECT *res, *res2;
|
2004-06-30 16:08:03 +00:00
|
|
|
int error, i, power_count;
|
2004-05-27 18:38:45 +00:00
|
|
|
|
|
|
|
if (h == NULL || prw == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The _PRW object (7.2.9) is only required for devices that have the
|
|
|
|
* ability to wake the system from a sleeping state.
|
|
|
|
*/
|
|
|
|
error = EINVAL;
|
|
|
|
prw_buffer.Pointer = NULL;
|
|
|
|
prw_buffer.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiEvaluateObject(h, "_PRW", NULL, &prw_buffer);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return (ENOENT);
|
|
|
|
res = (ACPI_OBJECT *)prw_buffer.Pointer;
|
|
|
|
if (res == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
if (!ACPI_PKG_VALID(res, 2))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 less than (i.e., higher power) or equal to this value.
|
|
|
|
*/
|
|
|
|
if (acpi_PkgInt32(res, 1, &prw->lowest_wake) != 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
prw->gpe_handle = NULL;
|
|
|
|
prw->gpe_bit = res->Package.Elements[0].Integer.Value;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case ACPI_TYPE_PACKAGE:
|
|
|
|
/*
|
|
|
|
* 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}
|
|
|
|
*/
|
|
|
|
res2 = &res->Package.Elements[0];
|
|
|
|
if (!ACPI_PKG_VALID(res2, 2))
|
|
|
|
goto out;
|
|
|
|
prw->gpe_handle = acpi_GetReference(NULL, &res2->Package.Elements[0]);
|
|
|
|
if (prw->gpe_handle == NULL)
|
|
|
|
goto out;
|
|
|
|
if (acpi_PkgInt32(res2, 1, &prw->gpe_bit) != 0)
|
|
|
|
goto out;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2004-06-30 16:08:03 +00:00
|
|
|
/* Elements 2 to N of the _PRW object are power resources. */
|
|
|
|
power_count = res->Package.Count - 2;
|
|
|
|
if (power_count > ACPI_PRW_MAX_POWERRES) {
|
|
|
|
printf("ACPI device %s has too many power resources\n", acpi_name(h));
|
|
|
|
power_count = 0;
|
|
|
|
}
|
|
|
|
prw->power_res_count = power_count;
|
|
|
|
for (i = 0; i < power_count; i++)
|
|
|
|
prw->power_res[i] = res->Package.Elements[i];
|
2004-05-27 18:38:45 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (prw_buffer.Pointer != NULL)
|
|
|
|
AcpiOsFree(prw_buffer.Pointer);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
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 |
|
2003-08-28 16:06:30 +00:00
|
|
|
ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT;
|
|
|
|
if (!sc->acpi_enabled)
|
2000-10-28 06:59:48 +00:00
|
|
|
status = AcpiEnableSubsystem(flags);
|
2003-08-28 16:06:30 +00:00
|
|
|
else
|
2000-10-28 06:59:48 +00:00
|
|
|
status = AE_OK;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
if (status == AE_OK)
|
|
|
|
sc->acpi_enabled = 1;
|
2003-08-28 16:06:30 +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
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
if (sc->acpi_enabled)
|
2000-10-28 06:59:48 +00:00
|
|
|
status = AcpiDisable();
|
2003-08-28 16:06:30 +00:00
|
|
|
else
|
2000-10-28 06:59:48 +00:00
|
|
|
status = AE_OK;
|
2003-08-28 16:06:30 +00:00
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
if (status == AE_OK)
|
|
|
|
sc->acpi_enabled = 0;
|
2003-08-28 16:06:30 +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-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
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-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
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
|
2004-02-11 02:57:33 +00:00
|
|
|
acpi_event_power_button_sleep(void *context)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
2004-02-11 02:57:33 +00:00
|
|
|
acpi_event_power_button_wake(void *context)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
2004-02-11 02:57:33 +00:00
|
|
|
acpi_event_sleep_button_sleep(void *context)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
return_VALUE (ACPI_INTERRUPT_HANDLED);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT32
|
2004-02-11 02:57:33 +00:00
|
|
|
acpi_event_sleep_button_wake(void *context)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2003-08-28 16:06:30 +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)))
|
2003-08-28 16:06:30 +00:00
|
|
|
return (buf.buffer.Pointer);
|
|
|
|
|
|
|
|
return ("(unknown path)");
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-28 16:06:30 +00:00
|
|
|
/* 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);
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (0);
|
2000-12-08 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2004-03-03 03:02:17 +00:00
|
|
|
if ((env = getenv("debug.acpi.disabled")) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2004-03-03 03:02:17 +00:00
|
|
|
if (strcmp(env, "all") == 0) {
|
2002-04-24 17:49:21 +00:00
|
|
|
freeenv(env);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (1);
|
2002-04-17 13:06:36 +00:00
|
|
|
}
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2004-03-03 03:02:17 +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 (;;) {
|
2004-03-03 03:02:17 +00:00
|
|
|
while (*cp != '\0' && isspace(*cp))
|
2000-12-08 09:16:20 +00:00
|
|
|
cp++;
|
2004-03-03 03:02:17 +00:00
|
|
|
if (*cp == '\0')
|
2000-12-08 09:16:20 +00:00
|
|
|
break;
|
|
|
|
len = 0;
|
2004-03-03 03:02:17 +00:00
|
|
|
while (cp[len] != '\0' && !isspace(cp[len]))
|
2000-12-08 09:16:20 +00:00
|
|
|
len++;
|
2004-03-03 03:02:17 +00:00
|
|
|
if (strncmp(cp, subsys, len) == 0) {
|
2002-04-24 17:49:21 +00:00
|
|
|
freeenv(env);
|
2003-08-28 16:06:30 +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);
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (0);
|
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
|
2003-08-28 16:06:30 +00:00
|
|
|
* 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
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
TAILQ_ENTRY(acpi_ioctl_hook) link;
|
|
|
|
u_long cmd;
|
|
|
|
acpi_ioctl_fn fn;
|
|
|
|
void *arg;
|
2000-12-08 09:16:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static TAILQ_HEAD(,acpi_ioctl_hook) acpi_ioctl_hooks;
|
|
|
|
static int acpi_ioctl_hooks_initted;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register an ioctl handler.
|
|
|
|
*/
|
|
|
|
int
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_register_ioctl(u_long cmd, acpi_ioctl_fn fn, void *arg)
|
2000-12-08 09:16:20 +00:00
|
|
|
{
|
|
|
|
struct acpi_ioctl_hook *hp;
|
|
|
|
|
|
|
|
if ((hp = malloc(sizeof(*hp), M_ACPIDEV, M_NOWAIT)) == NULL)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (ENOMEM);
|
2000-12-08 09:16:20 +00:00
|
|
|
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);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2000-12-08 09:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deregister an ioctl handler.
|
|
|
|
*/
|
|
|
|
void
|
2003-08-28 16:06:30 +00:00
|
|
|
acpi_deregister_ioctl(u_long cmd, acpi_ioctl_fn fn)
|
2000-12-08 09:16:20 +00:00
|
|
|
{
|
|
|
|
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
|
2004-06-16 09:47:26 +00:00
|
|
|
acpiopen(struct cdev *dev, int flag, int fmt, d_thread_t *td)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
acpiclose(struct cdev *dev, int flag, int fmt, d_thread_t *td)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
return (0);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
acpiioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, d_thread_t *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;
|
2002-10-16 17:28:53 +00:00
|
|
|
ACPI_LOCK_DECL;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-15 01:46:22 +00:00
|
|
|
/*
|
2003-08-28 16:06:30 +00:00
|
|
|
* Core ioctls are not permitted for non-writable user.
|
2003-02-15 01:46:22 +00:00
|
|
|
* Currently, other ioctls just fetch information.
|
|
|
|
* Not changing system behavior.
|
|
|
|
*/
|
2004-06-29 19:00:36 +00:00
|
|
|
if ((flag & FWRITE) == 0)
|
2003-08-28 16:06:30 +00:00
|
|
|
return (EPERM);
|
2003-02-15 01:46:22 +00:00
|
|
|
|
2003-08-28 16:06:30 +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;
|
2003-09-15 06:29:31 +00:00
|
|
|
if (state >= ACPI_STATE_S0 && state <= ACPI_S_STATES_MAX) {
|
|
|
|
if (ACPI_FAILURE(acpi_SetSleepState(sc, state)))
|
|
|
|
error = EINVAL;
|
|
|
|
} else {
|
2000-10-28 06:59:48 +00:00
|
|
|
error = EINVAL;
|
2003-09-15 06:29:31 +00:00
|
|
|
}
|
2000-10-28 06:59:48 +00:00
|
|
|
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;
|
2003-08-28 16:06:30 +00:00
|
|
|
return (error);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2003-04-11 16:53:56 +00:00
|
|
|
static int
|
|
|
|
acpi_supported_sleep_state_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
char sleep_state[4];
|
|
|
|
char buf[16];
|
|
|
|
int error;
|
|
|
|
UINT8 state, TypeA, TypeB;
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
2004-05-06 08:04:34 +00:00
|
|
|
for (state = ACPI_STATE_S1; state < ACPI_S_STATES_MAX + 1; state++) {
|
2003-04-11 16:53:56 +00:00
|
|
|
if (ACPI_SUCCESS(AcpiGetSleepTypeData(state, &TypeA, &TypeB))) {
|
|
|
|
sprintf(sleep_state, "S%d ", state);
|
|
|
|
strcat(buf, sleep_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
|
2003-08-28 16:06:30 +00:00
|
|
|
return (error);
|
2003-04-11 16:53:56 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2004-05-06 08:04:34 +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) {
|
2003-08-28 16:06:30 +00:00
|
|
|
new_state = ACPI_STATE_S0;
|
|
|
|
for (; 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
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
if (new_state <= ACPI_S_STATES_MAX + 1) {
|
|
|
|
if (new_state != old_state)
|
2001-11-30 16:06:00 +00:00
|
|
|
*(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
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
|
|
|
|
return (error);
|
2001-01-13 21:28:57 +00:00
|
|
|
}
|
|
|
|
|
2003-10-25 05:03:25 +00:00
|
|
|
/* Inform devctl(4) when we receive a Notify. */
|
|
|
|
void
|
|
|
|
acpi_UserNotify(const char *subsystem, ACPI_HANDLE h, uint8_t notify)
|
|
|
|
{
|
|
|
|
char notify_buf[16];
|
|
|
|
ACPI_BUFFER handle_buf;
|
|
|
|
ACPI_STATUS status;
|
|
|
|
|
|
|
|
if (subsystem == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
handle_buf.Pointer = NULL;
|
|
|
|
handle_buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiNsHandleToPathname(h, &handle_buf);
|
|
|
|
if (ACPI_FAILURE(status))
|
|
|
|
return;
|
|
|
|
snprintf(notify_buf, sizeof(notify_buf), "notify=0x%02x", notify);
|
|
|
|
devctl_notify("ACPI", subsystem, handle_buf.Pointer, notify_buf);
|
|
|
|
AcpiOsFree(handle_buf.Pointer);
|
|
|
|
}
|
|
|
|
|
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},
|
2003-09-26 04:32:40 +00:00
|
|
|
{"ACPI_ALL_COMPONENTS", ACPI_ALL_COMPONENTS},
|
2001-08-26 22:50:15 +00:00
|
|
|
|
2001-06-28 06:17:16 +00:00
|
|
|
{"ACPI_AC_ADAPTER", ACPI_AC_ADAPTER},
|
|
|
|
{"ACPI_BATTERY", ACPI_BATTERY},
|
2004-03-03 03:02:17 +00:00
|
|
|
{"ACPI_BUS", ACPI_BUS},
|
2001-06-28 06:17:16 +00:00
|
|
|
{"ACPI_BUTTON", ACPI_BUTTON},
|
2004-03-03 03:02:17 +00:00
|
|
|
{"ACPI_EC", ACPI_EC},
|
|
|
|
{"ACPI_FAN", ACPI_FAN},
|
|
|
|
{"ACPI_POWERRES", ACPI_POWERRES},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_PROCESSOR", ACPI_PROCESSOR},
|
2001-06-29 20:29:59 +00:00
|
|
|
{"ACPI_THERMAL", ACPI_THERMAL},
|
2004-03-03 03:02:17 +00:00
|
|
|
{"ACPI_TIMER", ACPI_TIMER},
|
2002-02-23 05:21:56 +00:00
|
|
|
{"ACPI_ALL_DRIVERS", ACPI_ALL_DRIVERS},
|
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_ERROR", ACPI_LV_ERROR},
|
2003-05-01 18:51:43 +00:00
|
|
|
{"ACPI_LV_WARN", ACPI_LV_WARN},
|
|
|
|
{"ACPI_LV_INIT", ACPI_LV_INIT},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_LV_DEBUG_OBJECT", ACPI_LV_DEBUG_OBJECT},
|
2003-05-01 18:51:43 +00:00
|
|
|
{"ACPI_LV_INFO", ACPI_LV_INFO},
|
2001-08-26 22:50:15 +00:00
|
|
|
{"ACPI_LV_ALL_EXCEPTIONS", ACPI_LV_ALL_EXCEPTIONS},
|
2002-08-29 01:52:27 +00:00
|
|
|
|
|
|
|
/* Trace verbosity level 1 [Standard Trace Level] */
|
2003-09-26 04:32:40 +00:00
|
|
|
{"ACPI_LV_INIT_NAMES", ACPI_LV_INIT_NAMES},
|
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},
|
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)) {
|
2003-08-28 16:06:30 +00:00
|
|
|
if (set)
|
2000-12-08 09:16:20 +00:00
|
|
|
*flag |= tag[i].value;
|
2003-08-28 16:06:30 +00:00
|
|
|
else
|
2000-12-08 09:16:20 +00:00
|
|
|
*flag &= ~tag[i].value;
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2004-05-06 02:05:45 +00:00
|
|
|
char *layer, *level;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2003-09-26 21:22:10 +00:00
|
|
|
if (cold) {
|
|
|
|
AcpiDbgLayer = 0;
|
|
|
|
AcpiDbgLevel = 0;
|
|
|
|
}
|
2002-11-24 02:27:07 +00:00
|
|
|
|
2004-05-06 02:05:45 +00:00
|
|
|
layer = getenv("debug.acpi.layer");
|
|
|
|
level = getenv("debug.acpi.level");
|
|
|
|
if (layer == NULL && level == NULL)
|
|
|
|
return;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2004-05-06 02:05:45 +00:00
|
|
|
printf("ACPI set debug");
|
|
|
|
if (layer != NULL) {
|
|
|
|
if (strcmp("NONE", layer) != 0)
|
|
|
|
printf(" layer '%s'", layer);
|
|
|
|
acpi_parse_debug(layer, &dbg_layer[0], &AcpiDbgLayer);
|
|
|
|
freeenv(layer);
|
|
|
|
}
|
|
|
|
if (level != NULL) {
|
|
|
|
if (strcmp("NONE", level) != 0)
|
|
|
|
printf(" level '%s'", level);
|
|
|
|
acpi_parse_debug(level, &dbg_level[0], &AcpiDbgLevel);
|
|
|
|
freeenv(level);
|
2003-09-26 21:22:10 +00:00
|
|
|
}
|
2004-05-06 02:05:45 +00:00
|
|
|
printf("\n");
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
2003-08-28 16:06:30 +00:00
|
|
|
SYSINIT(acpi_debugging, SI_SUB_TUNABLES, SI_ORDER_ANY, acpi_set_debugging,
|
|
|
|
NULL);
|
2003-09-26 21:22:10 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_debug_sysctl(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
2003-12-09 06:29:57 +00:00
|
|
|
int error, *dbg;
|
2003-09-26 21:22:10 +00:00
|
|
|
struct debugtag *tag;
|
2003-12-09 06:29:57 +00:00
|
|
|
struct sbuf sb;
|
2003-09-26 21:22:10 +00:00
|
|
|
|
2003-12-09 06:29:57 +00:00
|
|
|
if (sbuf_new(&sb, NULL, 128, SBUF_AUTOEXTEND) == NULL)
|
|
|
|
return (ENOMEM);
|
2003-09-26 21:22:10 +00:00
|
|
|
if (strcmp(oidp->oid_arg1, "debug.acpi.layer") == 0) {
|
|
|
|
tag = &dbg_layer[0];
|
|
|
|
dbg = &AcpiDbgLayer;
|
|
|
|
} else {
|
|
|
|
tag = &dbg_level[0];
|
|
|
|
dbg = &AcpiDbgLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get old values if this is a get request. */
|
|
|
|
if (*dbg == 0) {
|
2003-12-09 06:29:57 +00:00
|
|
|
sbuf_cpy(&sb, "NONE");
|
2003-09-26 21:22:10 +00:00
|
|
|
} else if (req->newptr == NULL) {
|
|
|
|
for (; tag->name != NULL; tag++) {
|
2003-12-09 06:29:57 +00:00
|
|
|
if ((*dbg & tag->value) == tag->value)
|
|
|
|
sbuf_printf(&sb, "%s ", tag->name);
|
2003-09-26 21:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-09 06:29:57 +00:00
|
|
|
sbuf_trim(&sb);
|
|
|
|
sbuf_finish(&sb);
|
2003-09-26 21:22:10 +00:00
|
|
|
|
2004-05-06 02:05:45 +00:00
|
|
|
/* Copy out the old values to the user. */
|
|
|
|
error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb));
|
2003-12-09 06:29:57 +00:00
|
|
|
sbuf_delete(&sb);
|
2003-09-26 21:22:10 +00:00
|
|
|
|
|
|
|
/* If the user is setting a string, parse it. */
|
|
|
|
if (error == 0 && req->newptr != NULL) {
|
|
|
|
*dbg = 0;
|
|
|
|
setenv((char *)oidp->oid_arg1, (char *)req->newptr);
|
|
|
|
acpi_set_debugging(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
SYSCTL_PROC(_debug_acpi, OID_AUTO, layer, CTLFLAG_RW | CTLTYPE_STRING,
|
|
|
|
"debug.acpi.layer", 0, acpi_debug_sysctl, "A", "");
|
|
|
|
SYSCTL_PROC(_debug_acpi, OID_AUTO, level, CTLFLAG_RW | CTLTYPE_STRING,
|
|
|
|
"debug.acpi.level", 0, acpi_debug_sysctl, "A", "");
|
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)
|
|
|
|
{
|
2003-08-28 16:06:30 +00:00
|
|
|
if (!cold || resource_disabled("acpi", 0))
|
2002-11-24 02:27:07 +00:00
|
|
|
return;
|
2002-08-30 11:11:07 +00:00
|
|
|
|
2002-11-24 02:27:07 +00:00
|
|
|
power_pm_register(POWER_PM_TYPE_ACPI, acpi_pm_func, NULL);
|
2001-11-01 16:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(power, SI_SUB_KLD, SI_ORDER_ANY, acpi_pm_register, 0);
|