2009-12-04 00:04:29 +03:00
|
|
|
/* $NetBSD: acpi.c,v 1.137 2009/12/03 21:04:29 cegger Exp $ */
|
2003-11-01 06:45:48 +03:00
|
|
|
|
|
|
|
/*-
|
2007-02-20 01:31:05 +03:00
|
|
|
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
|
2003-11-01 06:45:48 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Charles M. Hannum of By Noon Software, Inc.
|
|
|
|
*
|
|
|
|
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
/*
|
2003-04-17 05:22:21 +04:00
|
|
|
* Copyright 2001, 2003 Wasabi Systems, Inc.
|
2001-09-28 06:09:22 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Autoconfiguration support for the Intel ACPI Component Architecture
|
|
|
|
* ACPI reference implementation.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:01:57 +03:00
|
|
|
#include <sys/cdefs.h>
|
2009-12-04 00:04:29 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.137 2009/12/03 21:04:29 cegger Exp $");
|
2003-01-06 01:33:21 +03:00
|
|
|
|
|
|
|
#include "opt_acpi.h"
|
2005-06-21 12:19:25 +04:00
|
|
|
#include "opt_pcifixup.h"
|
2001-11-13 16:01:57 +03:00
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
2007-02-19 02:39:20 +03:00
|
|
|
#include <sys/mutex.h>
|
2003-02-14 14:05:39 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
2005-12-12 18:04:50 +03:00
|
|
|
#include <sys/sysctl.h>
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
#include <dev/acpi/acpica.h>
|
|
|
|
#include <dev/acpi/acpireg.h>
|
|
|
|
#include <dev/acpi/acpivar.h>
|
|
|
|
#include <dev/acpi/acpi_osd.h>
|
2006-06-21 21:47:23 +04:00
|
|
|
#include <dev/acpi/acpi_timer.h>
|
2009-08-04 18:20:40 +04:00
|
|
|
#include <dev/acpi/acpi_wakedev.h>
|
2009-12-04 00:04:29 +03:00
|
|
|
#include <dev/acpi/acpi_pci.h>
|
2003-01-06 01:33:21 +03:00
|
|
|
#ifdef ACPIVERBOSE
|
|
|
|
#include <dev/acpi/acpidevs_data.h>
|
|
|
|
#endif
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2009-09-16 14:47:54 +04:00
|
|
|
#define _COMPONENT ACPI_TOOLS
|
|
|
|
ACPI_MODULE_NAME ("acpi")
|
|
|
|
|
2005-06-21 15:49:10 +04:00
|
|
|
#if defined(ACPI_PCI_FIXUP)
|
2006-07-04 04:30:21 +04:00
|
|
|
#error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file.
|
2005-06-21 15:49:10 +04:00
|
|
|
#endif
|
|
|
|
|
2006-07-04 04:30:21 +04:00
|
|
|
#ifdef PCI_INTR_FIXUP_DISABLED
|
2002-07-29 07:06:56 +04:00
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
#endif
|
|
|
|
|
2003-03-06 02:00:56 +03:00
|
|
|
MALLOC_DECLARE(M_ACPI);
|
|
|
|
|
2002-06-18 12:09:21 +04:00
|
|
|
#include <machine/acpi_machdep.h>
|
|
|
|
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2001-09-28 06:09:22 +04:00
|
|
|
#define ACPI_DBGR_INIT 0x01
|
|
|
|
#define ACPI_DBGR_TABLES 0x02
|
|
|
|
#define ACPI_DBGR_ENABLE 0x04
|
|
|
|
#define ACPI_DBGR_PROBE 0x08
|
|
|
|
#define ACPI_DBGR_RUNNING 0x10
|
|
|
|
|
2006-02-16 12:23:23 +03:00
|
|
|
static int acpi_dbgr = 0x00;
|
2001-09-28 06:09:22 +04:00
|
|
|
#endif
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
static ACPI_TABLE_DESC acpi_initial_tables[128];
|
|
|
|
|
2009-05-12 13:29:46 +04:00
|
|
|
static int acpi_match(device_t, cfdata_t, void *);
|
2008-03-10 23:58:38 +03:00
|
|
|
static void acpi_attach(device_t, device_t, void *);
|
|
|
|
static void acpi_childdet(device_t, device_t);
|
2009-04-08 04:23:30 +04:00
|
|
|
static int acpi_detach(device_t, int);
|
|
|
|
|
|
|
|
static int acpi_rescan(device_t, const char *, const int *);
|
|
|
|
static void acpi_rescan1(struct acpi_softc *, const char *, const int *);
|
|
|
|
static void acpi_rescan_nodes(struct acpi_softc *);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static int acpi_print(void *aux, const char *);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2006-06-15 22:05:08 +04:00
|
|
|
static int sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS);
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
extern struct cfdriver acpi_cd;
|
|
|
|
|
2008-03-27 05:51:26 +03:00
|
|
|
CFATTACH_DECL2_NEW(acpi, sizeof(struct acpi_softc),
|
2009-04-08 04:23:30 +04:00
|
|
|
acpi_match, acpi_attach, acpi_detach, NULL, acpi_rescan, acpi_childdet);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a flag we set when the ACPI subsystem is active. Machine
|
|
|
|
* dependent code may wish to skip other steps (such as attaching
|
|
|
|
* subsystems that ACPI supercedes) when ACPI is active.
|
|
|
|
*/
|
|
|
|
int acpi_active;
|
2006-07-04 04:30:21 +04:00
|
|
|
int acpi_force_load;
|
2009-01-30 15:51:03 +03:00
|
|
|
int acpi_suspended = 0;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pointer to the ACPI subsystem's state. There can be only
|
|
|
|
* one ACPI instance.
|
|
|
|
*/
|
|
|
|
struct acpi_softc *acpi_softc;
|
|
|
|
|
2003-02-14 14:05:39 +03:00
|
|
|
/*
|
|
|
|
* Locking stuff.
|
|
|
|
*/
|
2007-02-19 02:39:20 +03:00
|
|
|
static kmutex_t acpi_slock;
|
2003-02-14 14:05:39 +03:00
|
|
|
static int acpi_locked;
|
2007-02-20 01:31:05 +03:00
|
|
|
extern kmutex_t acpi_interrupt_list_mtx;
|
2003-02-14 14:05:39 +03:00
|
|
|
|
2008-05-17 19:42:25 +04:00
|
|
|
/*
|
|
|
|
* Ignored HIDs
|
|
|
|
*/
|
|
|
|
static const char * const acpi_ignored_ids[] = {
|
|
|
|
#if defined(i386) || defined(x86_64)
|
|
|
|
"PNP0000", /* AT interrupt controller is handled internally */
|
|
|
|
"PNP0200", /* AT DMA controller is handled internally */
|
2009-12-04 00:04:29 +03:00
|
|
|
"PNP0A??", /* PCI Busses are handled internally */
|
2008-05-17 19:42:25 +04:00
|
|
|
"PNP0B00", /* AT RTC is handled internally */
|
|
|
|
"PNP0C01", /* No "System Board" driver */
|
|
|
|
"PNP0C02", /* No "PnP motherboard register resources" driver */
|
|
|
|
"PNP0C0F", /* ACPI PCI link devices are handled internally */
|
|
|
|
#endif
|
|
|
|
#if defined(x86_64)
|
|
|
|
"PNP0C04", /* FPU is handled internally */
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2005-12-14 02:27:31 +03:00
|
|
|
/*
|
|
|
|
* sysctl-related information
|
|
|
|
*/
|
|
|
|
|
|
|
|
static uint64_t acpi_root_pointer; /* found as hw.acpi.root */
|
2006-06-15 22:05:08 +04:00
|
|
|
static int acpi_sleepstate = ACPI_STATE_S0;
|
2009-01-03 06:43:21 +03:00
|
|
|
static char acpi_supported_states[3 * 6 + 1] = "";
|
2005-12-12 18:04:50 +03:00
|
|
|
|
2003-02-14 14:05:39 +03:00
|
|
|
/*
|
|
|
|
* Prototypes.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void acpi_build_tree(struct acpi_softc *);
|
|
|
|
static ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static void acpi_enable_fixed_events(struct acpi_softc *);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2007-12-17 00:10:34 +03:00
|
|
|
static ACPI_TABLE_HEADER *acpi_map_rsdt(void);
|
|
|
|
static void acpi_unmap_rsdt(ACPI_TABLE_HEADER *);
|
2008-02-13 18:27:55 +03:00
|
|
|
static int is_available_state(struct acpi_softc *, int);
|
2007-12-17 00:10:34 +03:00
|
|
|
|
2009-01-30 15:51:03 +03:00
|
|
|
static bool acpi_suspend(device_t PMF_FN_PROTO);
|
|
|
|
static bool acpi_resume(device_t PMF_FN_PROTO);
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* acpi_probe:
|
|
|
|
*
|
|
|
|
* Probe for ACPI support. This is called by the
|
|
|
|
* machine-dependent ACPI front-end. All of the
|
|
|
|
* actual work is done by ACPICA.
|
|
|
|
*
|
|
|
|
* NOTE: This is not an autoconfiguration interface function.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acpi_probe(void)
|
|
|
|
{
|
|
|
|
static int beenhere;
|
2007-12-17 00:10:34 +03:00
|
|
|
ACPI_TABLE_HEADER *rsdt;
|
2001-09-28 06:09:22 +04:00
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
if (beenhere != 0)
|
|
|
|
panic("acpi_probe: ACPI has already been probed");
|
|
|
|
beenhere = 1;
|
|
|
|
|
2007-12-05 10:06:50 +03:00
|
|
|
mutex_init(&acpi_slock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
mutex_init(&acpi_interrupt_list_mtx, MUTEX_DEFAULT, IPL_NONE);
|
2003-02-14 14:05:39 +03:00
|
|
|
acpi_locked = 0;
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* Start up ACPICA.
|
|
|
|
*/
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2001-09-28 06:09:22 +04:00
|
|
|
if (acpi_dbgr & ACPI_DBGR_INIT)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiGbl_AllMethodsSerialized = FALSE;
|
|
|
|
AcpiGbl_EnableInterpreterSlack = TRUE;
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
rv = AcpiInitializeSubsystem();
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2003-11-03 20:24:22 +03:00
|
|
|
printf("ACPI: unable to initialize ACPICA: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2004-04-11 10:48:25 +04:00
|
|
|
return 0;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
rv = AcpiInitializeTables(acpi_initial_tables, 128, 0);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
2009-08-23 19:16:16 +04:00
|
|
|
#ifdef ACPI_DEBUG
|
2007-12-09 23:27:42 +03:00
|
|
|
printf("ACPI: unable to initialize ACPI tables: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
#endif
|
|
|
|
AcpiTerminate();
|
2007-12-09 23:27:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = AcpiReallocateRootTable();
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("ACPI: unable to reallocate root table: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2007-12-09 23:27:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2001-09-28 06:09:22 +04:00
|
|
|
if (acpi_dbgr & ACPI_DBGR_TABLES)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rv = AcpiLoadTables();
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2003-11-03 20:24:22 +03:00
|
|
|
printf("ACPI: unable to load tables: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2004-04-11 10:48:25 +04:00
|
|
|
return 0;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
2007-12-17 00:10:34 +03:00
|
|
|
rsdt = acpi_map_rsdt();
|
|
|
|
if (rsdt == NULL) {
|
|
|
|
printf("ACPI: unable to map RSDT\n");
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2007-12-17 00:10:34 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2007-12-15 05:19:55 +03:00
|
|
|
|
2006-07-04 04:30:21 +04:00
|
|
|
if (!acpi_force_load && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) {
|
|
|
|
printf("ACPI: BIOS implementation in listed as broken:\n");
|
|
|
|
printf("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, "
|
|
|
|
"AslId <%4.4s,%08x>\n",
|
2007-12-17 00:10:34 +03:00
|
|
|
rsdt->OemId, rsdt->OemTableId,
|
|
|
|
rsdt->OemRevision,
|
|
|
|
rsdt->AslCompilerId,
|
|
|
|
rsdt->AslCompilerRevision);
|
2006-07-04 04:30:21 +04:00
|
|
|
printf("ACPI: not used. set acpi_force_load to use anyway.\n");
|
2007-12-17 00:10:34 +03:00
|
|
|
acpi_unmap_rsdt(rsdt);
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2006-07-04 04:30:21 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-17 00:10:34 +03:00
|
|
|
acpi_unmap_rsdt(rsdt);
|
|
|
|
|
2007-12-15 05:19:55 +03:00
|
|
|
#if notyet
|
2007-12-09 23:27:42 +03:00
|
|
|
/* Install the default address space handlers. */
|
|
|
|
rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
2009-11-28 20:03:17 +03:00
|
|
|
printf("ACPI: unable to initialize SystemMemory handler: %s\n",
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2007-12-09 23:27:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
2009-11-28 20:03:17 +03:00
|
|
|
printf("ACPI: unable to initialize SystemIO handler: %s\n",
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2007-12-09 23:27:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
2009-11-28 20:03:17 +03:00
|
|
|
printf("ACPI: unable to initialize PciConfig handler: %s\n",
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2007-12-09 23:27:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rv = AcpiEnableSubsystem(~(ACPI_NO_HARDWARE_INIT|ACPI_NO_ACPI_ENABLE));
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("ACPI: unable to enable: %s\n", AcpiFormatException(rv));
|
2009-08-23 19:16:16 +04:00
|
|
|
AcpiTerminate();
|
2007-12-09 23:27:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* Looks like we have ACPI!
|
|
|
|
*/
|
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return 1;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
2006-11-26 15:30:05 +03:00
|
|
|
static int
|
|
|
|
acpi_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux)
|
|
|
|
{
|
|
|
|
struct cfattach *ca;
|
|
|
|
|
|
|
|
ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
|
|
|
|
return (ca == &acpi_ca);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
acpi_check(device_t parent, const char *ifattr)
|
|
|
|
{
|
|
|
|
return (config_search_ia(acpi_submatch, parent, ifattr, NULL) != NULL);
|
|
|
|
}
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
ACPI_PHYSICAL_ADDRESS
|
|
|
|
acpi_OsGetRootPointer(void)
|
2005-12-12 18:04:50 +03:00
|
|
|
{
|
2007-12-09 23:27:42 +03:00
|
|
|
ACPI_PHYSICAL_ADDRESS PhysicalAddress;
|
2005-12-12 18:04:50 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IA-32: Use AcpiFindRootPointer() to locate the RSDP.
|
|
|
|
*
|
|
|
|
* IA-64: Use the EFI.
|
|
|
|
*
|
|
|
|
* We let MD code handle this since there are multiple
|
|
|
|
* ways to do it.
|
|
|
|
*/
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
PhysicalAddress = acpi_md_OsGetRootPointer();
|
2005-12-12 18:04:50 +03:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
if (acpi_root_pointer == 0)
|
|
|
|
acpi_root_pointer = PhysicalAddress;
|
2005-12-12 18:04:50 +03:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
return PhysicalAddress;
|
2005-12-12 18:04:50 +03:00
|
|
|
}
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* acpi_match:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `match' routine.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2009-05-12 13:29:46 +04:00
|
|
|
acpi_match(device_t parent, cfdata_t match, void *aux)
|
2001-09-28 06:09:22 +04:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XXX Check other locators? Hard to know -- machine
|
|
|
|
* dependent code has already checked for the presence
|
|
|
|
* of ACPI by calling acpi_probe(), so I suppose we
|
|
|
|
* don't really have to do anything else.
|
|
|
|
*/
|
2004-04-11 10:48:25 +04:00
|
|
|
return 1;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
2008-03-10 23:58:38 +03:00
|
|
|
/* Remove references to child devices.
|
|
|
|
*
|
|
|
|
* XXX Need to reclaim any resources?
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
acpi_childdet(device_t self, device_t child)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = device_private(self);
|
|
|
|
struct acpi_scope *as;
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
|
2009-04-08 04:23:30 +04:00
|
|
|
if (sc->sc_apmbus == child)
|
|
|
|
sc->sc_apmbus = NULL;
|
|
|
|
|
2008-03-10 23:58:38 +03:00
|
|
|
TAILQ_FOREACH(as, &sc->sc_scopes, as_list) {
|
|
|
|
TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
|
|
|
|
if (ad->ad_device == child)
|
|
|
|
ad->ad_device = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* acpi_attach:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `attach' routine. Finish initializing
|
|
|
|
* ACPICA (some initialization was done in acpi_probe(),
|
|
|
|
* which was required to check for the presence of ACPI),
|
|
|
|
* and enable the ACPI subsystem.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2008-03-10 23:58:38 +03:00
|
|
|
acpi_attach(device_t parent, device_t self, void *aux)
|
2001-09-28 06:09:22 +04:00
|
|
|
{
|
2008-03-10 23:58:38 +03:00
|
|
|
struct acpi_softc *sc = device_private(self);
|
2001-09-28 06:09:22 +04:00
|
|
|
struct acpibus_attach_args *aa = aux;
|
|
|
|
ACPI_STATUS rv;
|
2007-12-17 00:10:34 +03:00
|
|
|
ACPI_TABLE_HEADER *rsdt;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2008-05-17 19:42:25 +04:00
|
|
|
aprint_naive("\n");
|
|
|
|
aprint_normal(": Intel ACPICA %08x\n", ACPI_CA_VERSION);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
if (acpi_softc != NULL)
|
|
|
|
panic("acpi_attach: ACPI has already been attached");
|
|
|
|
|
2003-04-18 05:31:34 +04:00
|
|
|
sysmon_power_settype("acpi");
|
|
|
|
|
2007-12-17 00:10:34 +03:00
|
|
|
rsdt = acpi_map_rsdt();
|
|
|
|
if (rsdt) {
|
2008-03-10 23:58:38 +03:00
|
|
|
aprint_verbose_dev(
|
2008-03-27 05:51:26 +03:00
|
|
|
self,
|
2008-03-10 23:58:38 +03:00
|
|
|
"X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n",
|
2007-12-17 00:10:34 +03:00
|
|
|
rsdt->OemId, rsdt->OemTableId,
|
|
|
|
rsdt->OemRevision,
|
|
|
|
rsdt->AslCompilerId, rsdt->AslCompilerRevision);
|
|
|
|
} else
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(self, "X/RSDT: Not found\n");
|
2007-12-17 00:10:34 +03:00
|
|
|
acpi_unmap_rsdt(rsdt);
|
2003-01-08 19:52:49 +03:00
|
|
|
|
2008-03-27 05:51:26 +03:00
|
|
|
sc->sc_dev = self;
|
2003-05-16 01:29:49 +04:00
|
|
|
sc->sc_quirks = acpi_find_quirks();
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
sc->sc_iot = aa->aa_iot;
|
|
|
|
sc->sc_memt = aa->aa_memt;
|
|
|
|
sc->sc_pc = aa->aa_pc;
|
|
|
|
sc->sc_pciflags = aa->aa_pciflags;
|
2002-12-28 09:14:07 +03:00
|
|
|
sc->sc_ic = aa->aa_ic;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
acpi_softc = sc;
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
/*
|
|
|
|
* Register null power management handler
|
|
|
|
*/
|
2009-01-30 15:51:03 +03:00
|
|
|
if (!pmf_device_register(self, acpi_suspend, acpi_resume))
|
2007-12-09 23:27:42 +03:00
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* Bring ACPI on-line.
|
|
|
|
*/
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2001-09-28 06:09:22 +04:00
|
|
|
if (acpi_dbgr & ACPI_DBGR_ENABLE)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
2003-10-31 20:22:28 +03:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
#define ACPI_ENABLE_PHASE1 \
|
|
|
|
(ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT)
|
|
|
|
#define ACPI_ENABLE_PHASE2 \
|
|
|
|
(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \
|
|
|
|
ACPI_NO_ADDRESS_SPACE_INIT)
|
|
|
|
|
|
|
|
rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(self, "unable to enable ACPI: %s\n",
|
2008-03-10 23:58:38 +03:00
|
|
|
AcpiFormatException(rv));
|
2007-12-09 23:27:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
acpi_md_callback();
|
|
|
|
|
|
|
|
rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(self, "unable to enable ACPI: %s\n",
|
2008-03-10 23:58:38 +03:00
|
|
|
AcpiFormatException(rv));
|
2001-09-28 06:09:22 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-03-30 19:18:55 +04:00
|
|
|
|
|
|
|
/* early EC handler initialization if ECDT table is available */
|
2008-03-27 05:51:26 +03:00
|
|
|
config_found_ia(self, "acpiecdtbus", NULL, NULL);
|
2004-03-30 19:18:55 +04:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(self,
|
2008-03-10 23:58:38 +03:00
|
|
|
"unable to initialize ACPI objects: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2003-10-31 20:22:28 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_active = 1;
|
|
|
|
|
|
|
|
/* Our current state is "awake". */
|
|
|
|
sc->sc_sleepstate = ACPI_STATE_S0;
|
|
|
|
|
2002-06-17 12:18:51 +04:00
|
|
|
/* Show SCI interrupt. */
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_verbose_dev(self, "SCI interrupting at int %d\n",
|
2008-03-10 23:58:38 +03:00
|
|
|
AcpiGbl_FADT.SciInterrupt);
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* Check for fixed-hardware features.
|
|
|
|
*/
|
|
|
|
acpi_enable_fixed_events(sc);
|
2006-06-21 21:47:23 +04:00
|
|
|
acpitimer_init();
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the namespace and build our device tree.
|
|
|
|
*/
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2001-09-28 06:09:22 +04:00
|
|
|
if (acpi_dbgr & ACPI_DBGR_PROBE)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
acpi_build_tree(sc);
|
|
|
|
|
2009-04-08 16:39:27 +04:00
|
|
|
snprintf(acpi_supported_states, sizeof(acpi_supported_states),
|
|
|
|
"%s%s%s%s%s%s",
|
2008-02-13 18:27:55 +03:00
|
|
|
is_available_state(sc, ACPI_STATE_S0) ? "S0 " : "",
|
|
|
|
is_available_state(sc, ACPI_STATE_S1) ? "S1 " : "",
|
|
|
|
is_available_state(sc, ACPI_STATE_S2) ? "S2 " : "",
|
|
|
|
is_available_state(sc, ACPI_STATE_S3) ? "S3 " : "",
|
|
|
|
is_available_state(sc, ACPI_STATE_S4) ? "S4 " : "",
|
|
|
|
is_available_state(sc, ACPI_STATE_S5) ? "S5 " : "");
|
2005-12-12 18:04:50 +03:00
|
|
|
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_DEBUGGER
|
2001-09-28 06:09:22 +04:00
|
|
|
if (acpi_dbgr & ACPI_DBGR_RUNNING)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-04-08 04:23:30 +04:00
|
|
|
static int
|
|
|
|
acpi_detach(device_t self, int flags)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
#ifdef ACPI_DEBUGGER
|
|
|
|
if (acpi_dbgr & ACPI_DBGR_RUNNING)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((rc = config_detach_children(self, flags)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
#ifdef ACPI_DEBUGGER
|
|
|
|
if (acpi_dbgr & ACPI_DBGR_PROBE)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((rc = acpitimer_detach()) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Bring ACPI on-line.
|
|
|
|
*/
|
|
|
|
#ifdef ACPI_DEBUGGER
|
|
|
|
if (acpi_dbgr & ACPI_DBGR_ENABLE)
|
|
|
|
acpi_osd_debugger();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ACPI_ENABLE_PHASE1 \
|
|
|
|
(ACPI_NO_HANDLER_INIT | ACPI_NO_EVENT_INIT)
|
|
|
|
#define ACPI_ENABLE_PHASE2 \
|
|
|
|
(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE | \
|
|
|
|
ACPI_NO_ADDRESS_SPACE_INIT)
|
|
|
|
|
|
|
|
rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
aprint_error_dev(self, "unable to enable ACPI: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
aprint_error_dev(self, "unable to enable ACPI: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* early EC handler initialization if ECDT table is available */
|
|
|
|
config_found_ia(self, "acpiecdtbus", NULL, NULL);
|
|
|
|
|
|
|
|
rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
aprint_error_dev(self,
|
|
|
|
"unable to initialize ACPI objects: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
acpi_active = 1;
|
|
|
|
|
|
|
|
acpi_enable_fixed_events(sc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pmf_device_deregister(self);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
sysmon_power_settype("acpi");
|
|
|
|
#endif
|
|
|
|
acpi_softc = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-30 15:51:03 +03:00
|
|
|
static bool
|
|
|
|
acpi_suspend(device_t dv PMF_FN_ARGS)
|
|
|
|
{
|
|
|
|
acpi_suspended = 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
acpi_resume(device_t dv PMF_FN_ARGS)
|
|
|
|
{
|
|
|
|
acpi_suspended = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-01-31 12:30:06 +03:00
|
|
|
#if 0
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* acpi_disable:
|
|
|
|
*
|
|
|
|
* Disable ACPI.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static ACPI_STATUS
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_disable(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_STATUS rv = AE_OK;
|
|
|
|
|
|
|
|
if (acpi_active) {
|
|
|
|
rv = AcpiDisable();
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_SUCCESS(rv))
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_active = 0;
|
|
|
|
}
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
2006-01-31 12:30:06 +03:00
|
|
|
#endif
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
struct acpi_make_devnode_state {
|
|
|
|
struct acpi_softc *softc;
|
|
|
|
struct acpi_scope *scope;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_build_tree:
|
|
|
|
*
|
|
|
|
* Scan relevant portions of the ACPI namespace and attach
|
|
|
|
* child devices.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_build_tree(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
static const char *scopes[] = {
|
|
|
|
"\\_PR_", /* ACPI 1.0 processor namespace */
|
|
|
|
"\\_SB_", /* system bus namespace */
|
2006-06-25 03:40:50 +04:00
|
|
|
"\\_SI_", /* system indicator namespace */
|
2001-09-28 06:09:22 +04:00
|
|
|
"\\_TZ_", /* ACPI 1.0 thermal zone namespace */
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
struct acpi_make_devnode_state state;
|
|
|
|
struct acpi_scope *as;
|
|
|
|
ACPI_HANDLE parent;
|
2003-11-03 21:07:10 +03:00
|
|
|
ACPI_STATUS rv;
|
2001-09-28 06:09:22 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
TAILQ_INIT(&sc->sc_scopes);
|
|
|
|
|
|
|
|
state.softc = sc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the namespace and build our tree.
|
|
|
|
*/
|
|
|
|
for (i = 0; scopes[i] != NULL; i++) {
|
2003-03-06 02:00:56 +03:00
|
|
|
as = malloc(sizeof(*as), M_ACPI, M_WAITOK);
|
2001-09-28 06:09:22 +04:00
|
|
|
as->as_name = scopes[i];
|
|
|
|
TAILQ_INIT(&as->as_devnodes);
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&sc->sc_scopes, as, as_list);
|
|
|
|
|
|
|
|
state.scope = as;
|
|
|
|
|
2005-05-30 00:56:02 +04:00
|
|
|
rv = AcpiGetHandle(ACPI_ROOT_OBJECT, scopes[i],
|
2003-11-03 21:07:10 +03:00
|
|
|
&parent);
|
|
|
|
if (ACPI_SUCCESS(rv)) {
|
2001-09-28 06:09:22 +04:00
|
|
|
AcpiWalkNamespace(ACPI_TYPE_ANY, parent, 100,
|
|
|
|
acpi_make_devnode, &state, NULL);
|
|
|
|
}
|
2009-04-08 04:23:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
acpi_rescan1(sc, NULL, NULL);
|
2009-08-04 18:20:40 +04:00
|
|
|
|
|
|
|
acpi_wakedev_scan(sc);
|
2009-12-04 00:04:29 +03:00
|
|
|
|
|
|
|
acpi_pcidev_scan(sc);
|
2009-04-08 04:23:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
acpi_rescan(device_t self, const char *ifattr, const int *locators)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = device_private(self);
|
|
|
|
|
|
|
|
acpi_rescan1(sc, ifattr, locators);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX share this with sys/arch/i386/pci/elan520.c */
|
|
|
|
static bool
|
|
|
|
ifattr_match(const char *snull, const char *t)
|
|
|
|
{
|
|
|
|
return (snull == NULL) || strcmp(snull, t) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_rescan1(struct acpi_softc *sc, const char *ifattr, const int *locators)
|
|
|
|
{
|
|
|
|
if (ifattr_match(ifattr, "acpinodebus"))
|
|
|
|
acpi_rescan_nodes(sc);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2009-04-08 04:23:30 +04:00
|
|
|
if (ifattr_match(ifattr, "acpiapmbus") && sc->sc_apmbus == NULL) {
|
|
|
|
sc->sc_apmbus = config_found_ia(sc->sc_dev, "acpiapmbus", NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_rescan_nodes(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
struct acpi_scope *as;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(as, &sc->sc_scopes, as_list) {
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
|
|
|
|
/* Now, for this namespace, try to attach the devices. */
|
2001-09-28 06:09:22 +04:00
|
|
|
TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
|
2009-04-08 04:23:30 +04:00
|
|
|
struct acpi_attach_args aa;
|
|
|
|
|
|
|
|
if (ad->ad_device != NULL)
|
|
|
|
continue;
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
aa.aa_node = ad;
|
|
|
|
aa.aa_iot = sc->sc_iot;
|
|
|
|
aa.aa_memt = sc->sc_memt;
|
|
|
|
aa.aa_pc = sc->sc_pc;
|
|
|
|
aa.aa_pciflags = sc->sc_pciflags;
|
2002-12-28 09:14:07 +03:00
|
|
|
aa.aa_ic = sc->sc_ic;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE) {
|
2003-01-04 08:32:15 +03:00
|
|
|
/*
|
|
|
|
* XXX We only attach devices which are:
|
|
|
|
*
|
|
|
|
* - present
|
|
|
|
* - enabled
|
|
|
|
* - functioning properly
|
|
|
|
*
|
|
|
|
* However, if enabled, it's decoding resources,
|
|
|
|
* so we should claim them, if possible.
|
|
|
|
* Requires changes to bus_space(9).
|
|
|
|
*/
|
2003-11-03 09:03:47 +03:00
|
|
|
if ((ad->ad_devinfo->Valid & ACPI_VALID_STA) ==
|
2003-10-30 22:33:24 +03:00
|
|
|
ACPI_VALID_STA &&
|
2003-11-03 09:03:47 +03:00
|
|
|
(ad->ad_devinfo->CurrentStatus &
|
2003-01-04 08:32:15 +03:00
|
|
|
(ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
|
|
|
|
ACPI_STA_DEV_OK)) !=
|
|
|
|
(ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
|
|
|
|
ACPI_STA_DEV_OK))
|
|
|
|
continue;
|
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
/*
|
|
|
|
* XXX Same problem as above...
|
|
|
|
*
|
|
|
|
* Do this check only for devices, as e.g.
|
|
|
|
* a Thermal Zone doesn't have a HID.
|
|
|
|
*/
|
|
|
|
if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE &&
|
|
|
|
(ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
|
|
|
|
continue;
|
|
|
|
|
2008-05-17 19:42:25 +04:00
|
|
|
/*
|
|
|
|
* Handled internally
|
|
|
|
*/
|
|
|
|
if (ad->ad_devinfo->Type == ACPI_TYPE_PROCESSOR ||
|
|
|
|
ad->ad_devinfo->Type == ACPI_TYPE_POWER)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip ignored HIDs
|
|
|
|
*/
|
|
|
|
if (acpi_match_hid(ad->ad_devinfo, acpi_ignored_ids))
|
|
|
|
continue;
|
|
|
|
|
2008-03-27 05:51:26 +03:00
|
|
|
ad->ad_device = config_found_ia(sc->sc_dev,
|
2006-08-06 19:46:54 +04:00
|
|
|
"acpinodebus", &aa, acpi_print);
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_ACTIVATE_DEV
|
2002-07-29 07:26:20 +04:00
|
|
|
static void
|
2003-11-03 09:03:47 +03:00
|
|
|
acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di)
|
2002-07-29 07:26:20 +04:00
|
|
|
{
|
|
|
|
ACPI_STATUS rv;
|
2009-08-18 20:41:02 +04:00
|
|
|
ACPI_DEVICE_INFO *newdi;
|
2003-11-03 09:03:47 +03:00
|
|
|
|
|
|
|
#ifdef ACPI_DEBUG
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_normal("acpi_activate_device: %s, old status=%x\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
(*di)->HardwareId.Value, (*di)->CurrentStatus);
|
2002-07-29 07:26:20 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rv = acpi_allocate_resources(handle);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_error("acpi: activate failed for %s\n",
|
2009-08-19 01:38:41 +04:00
|
|
|
(*di)->HardwareId.String);
|
2002-12-31 14:23:34 +03:00
|
|
|
} else {
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose("acpi: activated %s\n",
|
2009-08-19 01:38:41 +04:00
|
|
|
(*di)->HardwareId.String);
|
2002-07-29 07:26:20 +04:00
|
|
|
}
|
|
|
|
|
2009-08-18 20:41:02 +04:00
|
|
|
(void)AcpiGetObjectInfo(handle, &newdi);
|
2009-09-16 14:47:54 +04:00
|
|
|
ACPI_FREE(*di);
|
2009-08-18 20:41:02 +04:00
|
|
|
*di = newdi;
|
2003-11-03 09:03:47 +03:00
|
|
|
|
|
|
|
#ifdef ACPI_DEBUG
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_normal("acpi_activate_device: %s, new status=%x\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
(*di)->HardwareId.Value, (*di)->CurrentStatus);
|
2002-07-29 07:26:20 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* ACPI_ACTIVATE_DEV */
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* acpi_make_devnode:
|
|
|
|
*
|
|
|
|
* Make an ACPI devnode.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static ACPI_STATUS
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context,
|
2006-11-16 04:32:37 +03:00
|
|
|
void **status)
|
2001-09-28 06:09:22 +04:00
|
|
|
{
|
|
|
|
struct acpi_make_devnode_state *state = context;
|
2002-12-30 04:56:44 +03:00
|
|
|
#if defined(ACPI_DEBUG) || defined(ACPI_EXTRA_DEBUG)
|
2001-09-28 06:09:22 +04:00
|
|
|
struct acpi_softc *sc = state->softc;
|
2001-09-29 22:13:48 +04:00
|
|
|
#endif
|
2001-09-28 06:09:22 +04:00
|
|
|
struct acpi_scope *as = state->scope;
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
ACPI_OBJECT_TYPE type;
|
2003-11-03 09:03:47 +03:00
|
|
|
ACPI_DEVICE_INFO *devinfo;
|
2001-09-28 06:09:22 +04:00
|
|
|
ACPI_STATUS rv;
|
2007-08-08 12:52:31 +04:00
|
|
|
ACPI_NAME_UNION *anu;
|
|
|
|
int i, clear = 0;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-11-03 21:07:10 +03:00
|
|
|
rv = AcpiGetType(handle, &type);
|
|
|
|
if (ACPI_SUCCESS(rv)) {
|
2009-08-18 20:41:02 +04:00
|
|
|
rv = AcpiGetObjectInfo(handle, &devinfo);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2002-07-29 07:26:20 +04:00
|
|
|
#ifdef ACPI_DEBUG
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_normal_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"AcpiGetObjectInfo failed: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
2002-07-29 07:26:20 +04:00
|
|
|
#endif
|
|
|
|
goto out; /* XXX why return OK */
|
|
|
|
}
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
switch (type) {
|
|
|
|
case ACPI_TYPE_DEVICE:
|
2003-07-06 08:03:21 +04:00
|
|
|
#ifdef ACPI_ACTIVATE_DEV
|
2003-11-03 09:03:47 +03:00
|
|
|
if ((devinfo->Valid & (ACPI_VALID_STA|ACPI_VALID_HID)) ==
|
2003-10-30 21:13:38 +03:00
|
|
|
(ACPI_VALID_STA|ACPI_VALID_HID) &&
|
2003-11-03 09:03:47 +03:00
|
|
|
(devinfo->CurrentStatus &
|
2002-07-29 07:26:20 +04:00
|
|
|
(ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED)) ==
|
2003-11-03 09:03:47 +03:00
|
|
|
ACPI_STA_DEV_PRESENT)
|
2002-07-29 07:26:20 +04:00
|
|
|
acpi_activate_device(handle, &devinfo);
|
2003-10-30 21:13:38 +03:00
|
|
|
|
2002-07-29 07:26:20 +04:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
#endif
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
case ACPI_TYPE_PROCESSOR:
|
|
|
|
case ACPI_TYPE_THERMAL:
|
|
|
|
case ACPI_TYPE_POWER:
|
2003-03-06 02:00:56 +03:00
|
|
|
ad = malloc(sizeof(*ad), M_ACPI, M_NOWAIT|M_ZERO);
|
2001-09-28 06:09:22 +04:00
|
|
|
if (ad == NULL)
|
2004-04-11 10:48:25 +04:00
|
|
|
return AE_NO_MEMORY;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-10-30 21:13:38 +03:00
|
|
|
ad->ad_devinfo = devinfo;
|
2001-09-28 06:09:22 +04:00
|
|
|
ad->ad_handle = handle;
|
|
|
|
ad->ad_level = level;
|
|
|
|
ad->ad_scope = as;
|
|
|
|
ad->ad_type = type;
|
|
|
|
|
2007-08-08 12:52:31 +04:00
|
|
|
anu = (ACPI_NAME_UNION *)&devinfo->Name;
|
|
|
|
ad->ad_name[4] = '\0';
|
|
|
|
for (i = 3, clear = 0; i >= 0; i--) {
|
|
|
|
if (!clear && anu->Ascii[i] == '_')
|
|
|
|
ad->ad_name[i] = '\0';
|
|
|
|
else {
|
|
|
|
ad->ad_name[i] = anu->Ascii[i];
|
|
|
|
clear = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ad->ad_name[0] == '\0')
|
|
|
|
ad->ad_name[0] = '_';
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
TAILQ_INSERT_TAIL(&as->as_devnodes, ad, ad_list);
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
if (type == ACPI_TYPE_DEVICE &&
|
|
|
|
(ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
|
2001-09-28 06:09:22 +04:00
|
|
|
goto out;
|
|
|
|
|
2002-07-29 07:10:16 +04:00
|
|
|
#ifdef ACPI_EXTRA_DEBUG
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_normal_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"HID %s found in scope %s level %d\n",
|
2009-08-19 01:38:41 +04:00
|
|
|
ad->ad_devinfo->HardwareId.String,
|
2001-09-28 06:09:22 +04:00
|
|
|
as->as_name, ad->ad_level);
|
2003-11-03 09:03:47 +03:00
|
|
|
if (ad->ad_devinfo->Valid & ACPI_VALID_UID)
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_normal(" UID %s\n",
|
2009-08-19 01:38:41 +04:00
|
|
|
ad->ad_devinfo->UniqueId.String);
|
2003-11-03 09:03:47 +03:00
|
|
|
if (ad->ad_devinfo->Valid & ACPI_VALID_ADR)
|
2008-06-01 23:01:57 +04:00
|
|
|
aprint_normal(" ADR 0x%016" PRIx64 "\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
ad->ad_devinfo->Address);
|
|
|
|
if (ad->ad_devinfo->Valid & ACPI_VALID_STA)
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_normal(" STA 0x%08x\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
ad->ad_devinfo->CurrentStatus);
|
2001-09-28 06:09:22 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
2004-04-11 10:48:25 +04:00
|
|
|
return AE_OK;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_print:
|
|
|
|
*
|
2006-08-06 19:46:54 +04:00
|
|
|
* Autoconfiguration print routine for ACPI node bus.
|
2001-09-28 06:09:22 +04:00
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_print(void *aux, const char *pnp)
|
|
|
|
{
|
|
|
|
struct acpi_attach_args *aa = aux;
|
2003-11-03 21:07:10 +03:00
|
|
|
ACPI_STATUS rv;
|
2001-09-29 22:13:48 +04:00
|
|
|
|
|
|
|
if (pnp) {
|
2003-11-03 09:03:47 +03:00
|
|
|
if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
|
|
|
|
char *pnpstr =
|
2009-08-18 20:41:02 +04:00
|
|
|
aa->aa_node->ad_devinfo->HardwareId.String;
|
2008-12-07 13:53:57 +03:00
|
|
|
ACPI_BUFFER buf;
|
2003-01-06 01:33:21 +03:00
|
|
|
|
2007-08-08 12:52:31 +04:00
|
|
|
aprint_normal("%s (%s) ", aa->aa_node->ad_name,
|
|
|
|
pnpstr);
|
2008-12-07 13:53:57 +03:00
|
|
|
|
|
|
|
buf.Pointer = NULL;
|
2009-09-16 14:47:54 +04:00
|
|
|
buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
|
2008-12-07 13:53:57 +03:00
|
|
|
rv = AcpiEvaluateObject(aa->aa_node->ad_handle,
|
|
|
|
"_STR", NULL, &buf);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_SUCCESS(rv)) {
|
2008-12-07 13:53:57 +03:00
|
|
|
ACPI_OBJECT *obj = buf.Pointer;
|
|
|
|
switch (obj->Type) {
|
|
|
|
case ACPI_TYPE_STRING:
|
|
|
|
aprint_normal("[%s] ", obj->String.Pointer);
|
|
|
|
break;
|
|
|
|
case ACPI_TYPE_BUFFER:
|
|
|
|
aprint_normal("buffer %p ", obj->Buffer.Pointer);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aprint_normal("type %d ",obj->Type);
|
|
|
|
break;
|
|
|
|
}
|
2009-09-16 14:47:54 +04:00
|
|
|
ACPI_FREE(buf.Pointer);
|
2003-01-06 01:33:21 +03:00
|
|
|
}
|
|
|
|
#ifdef ACPIVERBOSE
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
|
2009-11-14 12:54:10 +03:00
|
|
|
for (i = 0; i < __arraycount(acpi_knowndevs);
|
|
|
|
i++) {
|
2003-01-06 01:33:21 +03:00
|
|
|
if (strcmp(acpi_knowndevs[i].pnp,
|
|
|
|
pnpstr) == 0) {
|
2006-02-20 15:17:49 +03:00
|
|
|
aprint_normal("[%s] ",
|
2003-01-06 01:33:21 +03:00
|
|
|
acpi_knowndevs[i].str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2003-01-06 01:33:21 +03:00
|
|
|
#endif
|
2007-12-09 23:27:42 +03:00
|
|
|
aprint_normal("at %s", pnp);
|
|
|
|
} else if (aa->aa_node->ad_devinfo->Type != ACPI_TYPE_DEVICE) {
|
2007-08-08 12:52:31 +04:00
|
|
|
aprint_normal("%s (ACPI Object Type '%s' "
|
|
|
|
"[0x%02x]) ", aa->aa_node->ad_name,
|
|
|
|
AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type),
|
|
|
|
aa->aa_node->ad_devinfo->Type);
|
2007-12-09 23:27:42 +03:00
|
|
|
aprint_normal("at %s", pnp);
|
|
|
|
} else
|
|
|
|
return 0;
|
2002-12-30 12:33:25 +03:00
|
|
|
} else {
|
2007-08-08 12:52:31 +04:00
|
|
|
aprint_normal(" (%s", aa->aa_node->ad_name);
|
2003-11-03 09:03:47 +03:00
|
|
|
if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
|
2009-08-18 20:41:02 +04:00
|
|
|
aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.String);
|
2003-11-03 09:03:47 +03:00
|
|
|
if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_UID) {
|
2005-05-30 00:56:02 +04:00
|
|
|
const char *uid;
|
2003-07-06 09:24:18 +04:00
|
|
|
|
2009-08-18 20:41:02 +04:00
|
|
|
uid = aa->aa_node->ad_devinfo->UniqueId.String;
|
2003-10-31 23:54:18 +03:00
|
|
|
if (uid[0] == '\0')
|
2003-07-06 09:24:18 +04:00
|
|
|
uid = "<null>";
|
|
|
|
aprint_normal("-%s", uid);
|
|
|
|
}
|
2002-12-31 08:59:53 +03:00
|
|
|
}
|
2007-08-08 12:52:31 +04:00
|
|
|
aprint_normal(")");
|
2001-09-29 22:13:48 +04:00
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return UNCONF;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* ACPI fixed-hardware feature handlers
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static UINT32 acpi_fixed_button_handler(void *);
|
|
|
|
static void acpi_fixed_button_pressed(void *);
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_enable_fixed_events:
|
|
|
|
*
|
|
|
|
* Enable any fixed-hardware feature handlers.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_enable_fixed_events(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
static int beenhere;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
2003-04-17 05:22:21 +04:00
|
|
|
KASSERT(beenhere == 0);
|
|
|
|
beenhere = 1;
|
|
|
|
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* Check for fixed-hardware buttons.
|
|
|
|
*/
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) == 0) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_verbose_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"fixed-feature power button present\n");
|
2008-03-27 05:51:26 +03:00
|
|
|
sc->sc_smpsw_power.smpsw_name = device_xname(sc->sc_dev);
|
2003-04-18 05:31:34 +04:00
|
|
|
sc->sc_smpsw_power.smpsw_type = PSWITCH_TYPE_POWER;
|
2003-04-17 05:22:21 +04:00
|
|
|
if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"unable to register fixed power "
|
|
|
|
"button with sysmon\n");
|
2003-04-17 05:22:21 +04:00
|
|
|
} else {
|
|
|
|
rv = AcpiInstallFixedEventHandler(
|
|
|
|
ACPI_EVENT_POWER_BUTTON,
|
|
|
|
acpi_fixed_button_handler, &sc->sc_smpsw_power);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"unable to install handler "
|
2006-02-20 15:17:49 +03:00
|
|
|
"for fixed power button: %s\n",
|
2003-11-03 21:07:10 +03:00
|
|
|
AcpiFormatException(rv));
|
2003-04-17 05:22:21 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_verbose_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"fixed-feature sleep button present\n");
|
2008-03-27 05:51:26 +03:00
|
|
|
sc->sc_smpsw_sleep.smpsw_name = device_xname(sc->sc_dev);
|
2003-04-18 05:31:34 +04:00
|
|
|
sc->sc_smpsw_sleep.smpsw_type = PSWITCH_TYPE_SLEEP;
|
2003-04-17 05:22:21 +04:00
|
|
|
if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"unable to register fixed sleep "
|
|
|
|
"button with sysmon\n");
|
2003-04-17 05:22:21 +04:00
|
|
|
} else {
|
|
|
|
rv = AcpiInstallFixedEventHandler(
|
|
|
|
ACPI_EVENT_SLEEP_BUTTON,
|
|
|
|
acpi_fixed_button_handler, &sc->sc_smpsw_sleep);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"unable to install handler "
|
2006-02-20 15:17:49 +03:00
|
|
|
"for fixed sleep button: %s\n",
|
2003-11-03 21:07:10 +03:00
|
|
|
AcpiFormatException(rv));
|
2003-04-17 05:22:21 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-04-17 05:22:21 +04:00
|
|
|
* acpi_fixed_button_handler:
|
2001-09-28 06:09:22 +04:00
|
|
|
*
|
2003-04-17 05:22:21 +04:00
|
|
|
* Event handler for the fixed buttons.
|
2001-09-28 06:09:22 +04:00
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static UINT32
|
2003-04-17 05:22:21 +04:00
|
|
|
acpi_fixed_button_handler(void *context)
|
2001-09-28 06:09:22 +04:00
|
|
|
{
|
2003-04-17 05:22:21 +04:00
|
|
|
struct sysmon_pswitch *smpsw = context;
|
2009-08-25 14:34:08 +04:00
|
|
|
ACPI_STATUS rv;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-04-17 05:22:21 +04:00
|
|
|
#ifdef ACPI_BUT_DEBUG
|
|
|
|
printf("%s: fixed button handler\n", smpsw->smpsw_name);
|
|
|
|
#endif
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
rv = AcpiOsExecute(OSL_NOTIFY_HANDLER,
|
2003-04-17 05:22:21 +04:00
|
|
|
acpi_fixed_button_pressed, smpsw);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv))
|
2003-04-17 05:22:21 +04:00
|
|
|
printf("%s: WARNING: unable to queue fixed button pressed "
|
2003-11-03 20:24:22 +03:00
|
|
|
"callback: %s\n", smpsw->smpsw_name,
|
|
|
|
AcpiFormatException(rv));
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return ACPI_INTERRUPT_HANDLED;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-04-17 05:22:21 +04:00
|
|
|
* acpi_fixed_button_pressed:
|
2001-09-28 06:09:22 +04:00
|
|
|
*
|
2003-04-17 05:22:21 +04:00
|
|
|
* Deal with a fixed button being pressed.
|
2001-09-28 06:09:22 +04:00
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2003-04-17 05:22:21 +04:00
|
|
|
acpi_fixed_button_pressed(void *context)
|
2001-09-28 06:09:22 +04:00
|
|
|
{
|
2003-04-17 05:22:21 +04:00
|
|
|
struct sysmon_pswitch *smpsw = context;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-04-17 05:22:21 +04:00
|
|
|
#ifdef ACPI_BUT_DEBUG
|
|
|
|
printf("%s: fixed button pressed, calling sysmon\n",
|
|
|
|
smpsw->smpsw_name);
|
|
|
|
#endif
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-04-18 05:31:34 +04:00
|
|
|
sysmon_pswitch_event(smpsw, PSWITCH_EVENT_PRESSED);
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* ACPI utility routines.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2001-09-29 09:34:00 +04:00
|
|
|
/*
|
|
|
|
* acpi_eval_integer:
|
|
|
|
*
|
|
|
|
* Evaluate an integer object.
|
|
|
|
*/
|
2001-09-28 06:09:22 +04:00
|
|
|
ACPI_STATUS
|
2005-05-30 00:56:02 +04:00
|
|
|
acpi_eval_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER *valp)
|
2001-09-28 06:09:22 +04:00
|
|
|
{
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_OBJECT param;
|
|
|
|
|
|
|
|
if (handle == NULL)
|
|
|
|
handle = ACPI_ROOT_OBJECT;
|
|
|
|
|
|
|
|
buf.Pointer = ¶m;
|
|
|
|
buf.Length = sizeof(param);
|
|
|
|
|
2009-11-28 20:03:17 +03:00
|
|
|
rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf,
|
|
|
|
ACPI_TYPE_INTEGER);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_SUCCESS(rv))
|
2003-10-30 23:29:54 +03:00
|
|
|
*valp = param.Integer.Value;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
2001-09-29 09:34:00 +04:00
|
|
|
|
2009-11-30 00:32:50 +03:00
|
|
|
ACPI_STATUS
|
|
|
|
acpi_eval_set_integer(ACPI_HANDLE handle, const char *path, ACPI_INTEGER arg)
|
|
|
|
{
|
|
|
|
ACPI_OBJECT param_arg;
|
|
|
|
ACPI_OBJECT_LIST param_args;
|
|
|
|
|
|
|
|
if (handle == NULL)
|
|
|
|
handle = ACPI_ROOT_OBJECT;
|
|
|
|
|
|
|
|
param_arg.Type = ACPI_TYPE_INTEGER;
|
|
|
|
param_arg.Integer.Value = arg;
|
|
|
|
|
|
|
|
param_args.Count = 1;
|
|
|
|
param_args.Pointer = ¶m_arg;
|
|
|
|
|
|
|
|
return AcpiEvaluateObject(handle, path, ¶m_args, NULL);
|
|
|
|
}
|
|
|
|
|
2001-09-29 22:13:48 +04:00
|
|
|
/*
|
|
|
|
* acpi_eval_string:
|
|
|
|
*
|
2002-03-24 06:32:14 +03:00
|
|
|
* Evaluate a (Unicode) string object.
|
2001-09-29 22:13:48 +04:00
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
2005-05-30 00:56:02 +04:00
|
|
|
acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp)
|
2001-09-29 22:13:48 +04:00
|
|
|
{
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
|
|
|
|
if (handle == NULL)
|
|
|
|
handle = ACPI_ROOT_OBJECT;
|
|
|
|
|
|
|
|
buf.Pointer = NULL;
|
2009-09-16 14:47:54 +04:00
|
|
|
buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
|
2001-09-29 22:13:48 +04:00
|
|
|
|
2003-10-30 23:29:54 +03:00
|
|
|
rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf, ACPI_TYPE_STRING);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_SUCCESS(rv)) {
|
2003-11-01 04:03:23 +03:00
|
|
|
ACPI_OBJECT *param = buf.Pointer;
|
2005-06-01 01:08:37 +04:00
|
|
|
const char *ptr = param->String.Pointer;
|
2003-10-30 23:29:54 +03:00
|
|
|
size_t len = param->String.Length;
|
2009-09-16 14:47:54 +04:00
|
|
|
if ((*stringp = ACPI_ALLOCATE(len)) == NULL)
|
2003-10-30 23:29:54 +03:00
|
|
|
rv = AE_NO_MEMORY;
|
|
|
|
else
|
|
|
|
(void)memcpy(*stringp, ptr, len);
|
2009-09-16 14:47:54 +04:00
|
|
|
ACPI_FREE(param);
|
2001-09-29 22:13:48 +04:00
|
|
|
}
|
2003-10-30 23:29:54 +03:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2001-09-29 22:13:48 +04:00
|
|
|
}
|
2002-03-24 06:32:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_eval_struct:
|
|
|
|
*
|
2003-07-02 16:23:25 +04:00
|
|
|
* Evaluate a more complex structure.
|
2009-09-16 14:47:54 +04:00
|
|
|
* Caller must free buf.Pointer by ACPI_FREE().
|
2002-03-24 06:32:14 +03:00
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
2005-05-30 00:56:02 +04:00
|
|
|
acpi_eval_struct(ACPI_HANDLE handle, const char *path, ACPI_BUFFER *bufp)
|
2002-03-24 06:32:14 +03:00
|
|
|
{
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
if (handle == NULL)
|
|
|
|
handle = ACPI_ROOT_OBJECT;
|
|
|
|
|
|
|
|
bufp->Pointer = NULL;
|
2009-09-16 14:47:54 +04:00
|
|
|
bufp->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
|
2002-03-24 06:32:14 +03:00
|
|
|
|
|
|
|
rv = AcpiEvaluateObject(handle, path, NULL, bufp);
|
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
2002-03-24 06:32:14 +03:00
|
|
|
}
|
2001-09-29 22:13:48 +04:00
|
|
|
|
2004-05-26 21:15:17 +04:00
|
|
|
/*
|
|
|
|
* acpi_foreach_package_object:
|
|
|
|
*
|
|
|
|
* Iterate over all objects in a in a packages and pass then all
|
|
|
|
* to a function. If the called function returns non AE_OK, the
|
|
|
|
* iteration is stopped and that value is returned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
2005-02-27 03:26:58 +03:00
|
|
|
acpi_foreach_package_object(ACPI_OBJECT *pkg,
|
|
|
|
ACPI_STATUS (*func)(ACPI_OBJECT *, void *),
|
2004-05-26 21:15:17 +04:00
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
ACPI_STATUS rv = AE_OK;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pkg == NULL || pkg->Type != ACPI_TYPE_PACKAGE)
|
|
|
|
return AE_BAD_PARAMETER;
|
|
|
|
|
|
|
|
for (i = 0; i < pkg->Package.Count; i++) {
|
|
|
|
rv = (*func)(&pkg->Package.Elements[i], arg);
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
acpi_name(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
static char buffer[80];
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
buf.Length = sizeof(buffer);
|
|
|
|
buf.Pointer = buffer;
|
|
|
|
|
|
|
|
rv = AcpiGetName(handle, ACPI_FULL_PATHNAME, &buf);
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return "(unknown acpi path)";
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2001-09-29 09:34:00 +04:00
|
|
|
/*
|
|
|
|
* acpi_get:
|
|
|
|
*
|
|
|
|
* Fetch data info the specified (empty) ACPI buffer.
|
2009-09-16 14:47:54 +04:00
|
|
|
* Caller must free buf.Pointer by ACPI_FREE().
|
2001-09-29 09:34:00 +04:00
|
|
|
*/
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
|
|
|
|
ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
|
|
|
|
{
|
|
|
|
buf->Pointer = NULL;
|
2009-09-16 14:47:54 +04:00
|
|
|
buf->Length = ACPI_ALLOCATE_LOCAL_BUFFER;
|
2001-09-29 09:34:00 +04:00
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return (*getit)(handle, buf);
|
2001-09-29 09:34:00 +04:00
|
|
|
}
|
2002-06-18 12:09:21 +04:00
|
|
|
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
/*
|
|
|
|
* acpi_match_hid
|
|
|
|
*
|
|
|
|
* Match given ids against _HID and _CIDs
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
acpi_match_hid(ACPI_DEVICE_INFO *ad, const char * const *ids)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
while (*ids) {
|
2003-11-03 21:51:31 +03:00
|
|
|
if (ad->Valid & ACPI_VALID_HID) {
|
2009-08-18 20:41:02 +04:00
|
|
|
if (pmatch(ad->HardwareId.String, *ids, NULL) == 2)
|
2004-04-11 10:48:25 +04:00
|
|
|
return 1;
|
2003-11-03 21:51:31 +03:00
|
|
|
}
|
2003-11-03 09:03:47 +03:00
|
|
|
|
|
|
|
if (ad->Valid & ACPI_VALID_CID) {
|
2009-08-18 20:41:02 +04:00
|
|
|
for (i = 0; i < ad->CompatibleIdList.Count; i++) {
|
|
|
|
if (pmatch(ad->CompatibleIdList.Ids[i].String, *ids, NULL) == 2)
|
2004-04-11 10:48:25 +04:00
|
|
|
return 1;
|
2003-11-03 09:03:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ids++;
|
|
|
|
}
|
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return 0;
|
2003-11-03 09:03:47 +03:00
|
|
|
}
|
|
|
|
|
2005-05-02 18:53:04 +04:00
|
|
|
/*
|
2008-07-15 20:15:28 +04:00
|
|
|
* acpi_wake_gpe_helper
|
2005-05-02 18:53:04 +04:00
|
|
|
*
|
2008-07-15 20:15:28 +04:00
|
|
|
* Set/unset GPE as both Runtime and Wake
|
2005-05-02 18:53:04 +04:00
|
|
|
*/
|
2008-07-15 20:15:28 +04:00
|
|
|
static void
|
|
|
|
acpi_wake_gpe_helper(ACPI_HANDLE handle, bool enable)
|
2005-05-02 18:53:04 +04:00
|
|
|
{
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_OBJECT *p, *elt;
|
|
|
|
|
|
|
|
rv = acpi_eval_struct(handle, METHOD_NAME__PRW, &buf);
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
return; /* just ignore */
|
|
|
|
|
|
|
|
p = buf.Pointer;
|
|
|
|
if (p->Type != ACPI_TYPE_PACKAGE || p->Package.Count < 2)
|
|
|
|
goto out; /* just ignore */
|
|
|
|
|
|
|
|
elt = p->Package.Elements;
|
|
|
|
|
|
|
|
/* TBD: package support */
|
2008-07-15 20:15:28 +04:00
|
|
|
if (enable) {
|
|
|
|
AcpiSetGpeType(NULL, elt[0].Integer.Value,
|
|
|
|
ACPI_GPE_TYPE_WAKE_RUN);
|
|
|
|
AcpiEnableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR);
|
|
|
|
} else
|
|
|
|
AcpiDisableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR);
|
2005-05-02 18:53:04 +04:00
|
|
|
|
|
|
|
out:
|
2009-09-16 14:47:54 +04:00
|
|
|
ACPI_FREE(buf.Pointer);
|
2005-05-02 18:53:04 +04:00
|
|
|
}
|
|
|
|
|
2008-07-15 20:15:28 +04:00
|
|
|
/*
|
|
|
|
* acpi_clear_wake_gpe
|
|
|
|
*
|
|
|
|
* Clear GPE as both Runtime and Wake
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_clear_wake_gpe(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
acpi_wake_gpe_helper(handle, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_set_wake_gpe
|
|
|
|
*
|
|
|
|
* Set GPE as both Runtime and Wake
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_set_wake_gpe(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
acpi_wake_gpe_helper(handle, true);
|
|
|
|
}
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
|
2002-06-18 12:09:21 +04:00
|
|
|
/*****************************************************************************
|
|
|
|
* ACPI sleep support.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
is_available_state(struct acpi_softc *sc, int state)
|
2002-06-18 12:09:21 +04:00
|
|
|
{
|
|
|
|
UINT8 type_a, type_b;
|
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return ACPI_SUCCESS(AcpiGetSleepTypeData((UINT8)state,
|
|
|
|
&type_a, &type_b));
|
2002-06-18 12:09:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_enter_sleep_state:
|
|
|
|
*
|
|
|
|
* enter to the specified sleep state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_enter_sleep_state(struct acpi_softc *sc, int state)
|
|
|
|
{
|
2007-12-09 23:27:42 +03:00
|
|
|
int err;
|
2002-06-18 12:09:21 +04:00
|
|
|
ACPI_STATUS ret = AE_OK;
|
|
|
|
|
2006-07-02 01:44:13 +04:00
|
|
|
if (state == acpi_sleepstate)
|
|
|
|
return AE_OK;
|
|
|
|
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_normal_dev(sc->sc_dev, "entering state %d\n", state);
|
2006-07-02 01:44:13 +04:00
|
|
|
|
2002-06-18 12:09:21 +04:00
|
|
|
switch (state) {
|
|
|
|
case ACPI_STATE_S0:
|
|
|
|
break;
|
|
|
|
case ACPI_STATE_S1:
|
|
|
|
case ACPI_STATE_S2:
|
|
|
|
case ACPI_STATE_S3:
|
|
|
|
case ACPI_STATE_S4:
|
|
|
|
if (!is_available_state(sc, state)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-04-20 20:26:36 +04:00
|
|
|
"ACPI S%d not available on this platform\n", state);
|
2002-06-18 12:09:21 +04:00
|
|
|
break;
|
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2009-08-04 18:20:40 +04:00
|
|
|
acpi_wakedev_commit(sc);
|
|
|
|
|
In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.
1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.
2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.
3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.
Currently, the kernel defines three suspensors,
3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,
3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.
3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.
A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.
Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.
4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.
Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.
5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.
6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
2009-09-16 20:34:49 +04:00
|
|
|
if (state != ACPI_STATE_S1 && !pmf_system_suspend(PMF_Q_NONE)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev, "aborting suspend\n");
|
2007-12-09 23:27:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-18 12:09:21 +04:00
|
|
|
ret = AcpiEnterSleepStatePrep(state);
|
|
|
|
if (ACPI_FAILURE(ret)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"failed preparing to sleep (%s)\n",
|
|
|
|
AcpiFormatException(ret));
|
2002-06-18 12:09:21 +04:00
|
|
|
break;
|
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2006-07-02 01:44:13 +04:00
|
|
|
acpi_sleepstate = state;
|
|
|
|
if (state == ACPI_STATE_S1) {
|
2002-06-18 12:09:21 +04:00
|
|
|
/* just enter the state */
|
2002-07-18 16:05:11 +04:00
|
|
|
acpi_md_OsDisableInterrupt();
|
2008-04-20 20:26:36 +04:00
|
|
|
ret = AcpiEnterSleepState((UINT8)state);
|
|
|
|
if (ACPI_FAILURE(ret))
|
|
|
|
aprint_error_dev(sc->sc_dev,
|
|
|
|
"failed to enter sleep state S1: %s\n",
|
|
|
|
AcpiFormatException(ret));
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiLeaveSleepState((UINT8)state);
|
2002-06-18 12:09:21 +04:00
|
|
|
} else {
|
2007-12-09 23:27:42 +03:00
|
|
|
err = acpi_md_sleep(state);
|
|
|
|
if (state == ACPI_STATE_S4)
|
2002-06-18 12:09:21 +04:00
|
|
|
AcpiEnable();
|
In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.
1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.
2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.
3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.
Currently, the kernel defines three suspensors,
3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,
3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.
3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.
A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.
Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.
4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.
Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.
5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.
6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
2009-09-16 20:34:49 +04:00
|
|
|
pmf_system_bus_resume(PMF_Q_NONE);
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiLeaveSleepState((UINT8)state);
|
In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together. Start solidifying some temporary API changes.
1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
#include it from <sys/pmf.h> instead of <sys/device.h> to break the
circular dependency between <sys/device.h> and <sys/pmf.h>.
2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
suspend/resume call. Start to replace instances of PMF_FN_PROTO,
PMF_FN_ARGS, et cetera, with a pmf_qual_t.
3. Introduce the notion of a "suspensor," an entity that holds a
device in suspension. More than one suspensor may hold a device
at once. A device stays suspended as long as at least one
suspensor holds it. A device resumes when the last suspensor
releases it.
Currently, the kernel defines three suspensors,
3a the system-suspensor: for system suspension, initiated
by 'sysctl -w machdep.sleep_state=3', by lid closure, by
power-button press, et cetera,
3b the drvctl-suspensor: for device suspension by /dev/drvctl
ioctl, e.g., drvctl -S sip0.
3c the system self-suspensor: for device drivers that suspend
themselves and their children. Several drivers for network
interfaces put the network device to sleep while it is not
administratively up, that is, after the kernel calls if_stop(,
1). The self-suspensor should not be used directly. See
the description of suspensor delegates, below.
A suspensor can have one or more "delegates". A suspensor can
release devices that its delegates hold suspended. Right now,
only the system self-suspensor has delegates. For each device
that a self-suspending driver attaches, it creates the device's
self-suspensor, a delegate of the system self-suspensor.
Suspensors stop a system-wide suspend/resume cycle from waking
devices that the operator put to sleep with drvctl before the cycle.
They also help self-suspension to work more simply, safely, and in
accord with expectations.
4. Add the notion of device activation level, devact_level_t,
and a routine for checking the current activation level,
device_activation(). Current activation levels are DEVACT_LEVEL_BUS,
DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
indicate that the device's bus is active, that the bus and device are
active, and that the bus, device, and the functions of the device's
class (network, audio) are active.
Suspend/resume calls can be qualified with a devact_level_t.
The power-management framework treats a devact_level_t that
qualifies a device suspension as the device's current activation
level; it only runs hooks to reduce the activation level from
the presumed current level to the fully suspended state. The
framework treats a devact_level_t qualifying device resumption
as the target activation level; it only runs hooks to raise the
activation level to the target.
5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
drivers.
6. Temporarily add an unused power-management workqueue that I will
remove or replace, soon.
2009-09-16 20:34:49 +04:00
|
|
|
pmf_system_resume(PMF_Q_NONE);
|
2002-06-18 12:09:21 +04:00
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2002-06-18 12:09:21 +04:00
|
|
|
break;
|
|
|
|
case ACPI_STATE_S5:
|
2003-08-17 07:45:19 +04:00
|
|
|
ret = AcpiEnterSleepStatePrep(ACPI_STATE_S5);
|
|
|
|
if (ACPI_FAILURE(ret)) {
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev,
|
2008-03-10 23:58:38 +03:00
|
|
|
"failed preparing to sleep (%s)\n",
|
|
|
|
AcpiFormatException(ret));
|
2003-08-17 07:45:19 +04:00
|
|
|
break;
|
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
DELAY(1000000);
|
2006-07-02 01:44:13 +04:00
|
|
|
acpi_sleepstate = state;
|
2002-07-18 16:05:11 +04:00
|
|
|
acpi_md_OsDisableInterrupt();
|
2002-06-18 12:09:21 +04:00
|
|
|
AcpiEnterSleepState(ACPI_STATE_S5);
|
2008-03-27 05:51:26 +03:00
|
|
|
aprint_error_dev(sc->sc_dev, "WARNING powerdown failed!\n");
|
2002-06-18 12:09:21 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-07-02 01:44:13 +04:00
|
|
|
acpi_sleepstate = ACPI_STATE_S0;
|
2004-04-11 10:48:25 +04:00
|
|
|
return ret;
|
2002-06-18 12:09:21 +04:00
|
|
|
}
|
2002-07-29 07:06:56 +04:00
|
|
|
|
2006-07-04 04:30:21 +04:00
|
|
|
#if defined(ACPI_ACTIVATE_DEV)
|
2002-07-29 07:06:56 +04:00
|
|
|
/* XXX This very incomplete */
|
2006-07-04 04:30:21 +04:00
|
|
|
ACPI_STATUS
|
2002-07-29 07:06:56 +04:00
|
|
|
acpi_allocate_resources(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
ACPI_BUFFER bufp, bufc, bufn;
|
|
|
|
ACPI_RESOURCE *resp, *resc, *resn;
|
|
|
|
ACPI_RESOURCE_IRQ *irq;
|
2006-07-04 04:30:21 +04:00
|
|
|
ACPI_RESOURCE_EXTENDED_IRQ *xirq;
|
2002-07-29 07:06:56 +04:00
|
|
|
ACPI_STATUS rv;
|
|
|
|
uint delta;
|
|
|
|
|
|
|
|
rv = acpi_get(handle, &bufp, AcpiGetPossibleResources);
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
goto out;
|
|
|
|
rv = acpi_get(handle, &bufc, AcpiGetCurrentResources);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bufn.Length = 1000;
|
2003-03-06 02:00:56 +03:00
|
|
|
bufn.Pointer = resn = malloc(bufn.Length, M_ACPI, M_WAITOK);
|
2002-07-29 07:06:56 +04:00
|
|
|
resp = bufp.Pointer;
|
|
|
|
resc = bufc.Pointer;
|
2006-02-26 21:46:04 +03:00
|
|
|
while (resc->Type != ACPI_RESOURCE_TYPE_END_TAG &&
|
|
|
|
resp->Type != ACPI_RESOURCE_TYPE_END_TAG) {
|
|
|
|
while (resc->Type != resp->Type && resp->Type != ACPI_RESOURCE_TYPE_END_TAG)
|
2002-07-29 07:06:56 +04:00
|
|
|
resp = ACPI_NEXT_RESOURCE(resp);
|
2006-02-26 21:46:04 +03:00
|
|
|
if (resp->Type == ACPI_RESOURCE_TYPE_END_TAG)
|
2002-07-29 07:06:56 +04:00
|
|
|
break;
|
|
|
|
/* Found identical Id */
|
2006-01-29 06:12:22 +03:00
|
|
|
resn->Type = resc->Type;
|
|
|
|
switch (resc->Type) {
|
|
|
|
case ACPI_RESOURCE_TYPE_IRQ:
|
2002-07-29 07:06:56 +04:00
|
|
|
memcpy(&resn->Data, &resp->Data,
|
|
|
|
sizeof(ACPI_RESOURCE_IRQ));
|
|
|
|
irq = (ACPI_RESOURCE_IRQ *)&resn->Data;
|
|
|
|
irq->Interrupts[0] =
|
|
|
|
((ACPI_RESOURCE_IRQ *)&resp->Data)->
|
2006-01-29 06:12:22 +03:00
|
|
|
Interrupts[irq->InterruptCount-1];
|
|
|
|
irq->InterruptCount = 1;
|
|
|
|
resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
|
2002-07-29 07:06:56 +04:00
|
|
|
break;
|
2006-07-04 04:30:21 +04:00
|
|
|
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
|
|
|
|
memcpy(&resn->Data, &resp->Data,
|
|
|
|
sizeof(ACPI_RESOURCE_EXTENDED_IRQ));
|
|
|
|
xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data;
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* XXX not duplicating the interrupt logic above
|
|
|
|
* because its not clear what it accomplishes.
|
|
|
|
*/
|
|
|
|
xirq->Interrupts[0] =
|
|
|
|
((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)->
|
|
|
|
Interrupts[irq->NumberOfInterrupts-1];
|
|
|
|
xirq->NumberOfInterrupts = 1;
|
|
|
|
#endif
|
|
|
|
resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
|
|
|
|
break;
|
2006-01-29 06:12:22 +03:00
|
|
|
case ACPI_RESOURCE_TYPE_IO:
|
2002-07-29 07:06:56 +04:00
|
|
|
memcpy(&resn->Data, &resp->Data,
|
|
|
|
sizeof(ACPI_RESOURCE_IO));
|
|
|
|
resn->Length = resp->Length;
|
|
|
|
break;
|
|
|
|
default:
|
2006-01-29 06:12:22 +03:00
|
|
|
printf("acpi_allocate_resources: res=%d\n", resc->Type);
|
2002-07-29 07:06:56 +04:00
|
|
|
rv = AE_BAD_DATA;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
resc = ACPI_NEXT_RESOURCE(resc);
|
|
|
|
resn = ACPI_NEXT_RESOURCE(resn);
|
2006-06-20 16:31:19 +04:00
|
|
|
resp = ACPI_NEXT_RESOURCE(resp);
|
2002-07-29 07:06:56 +04:00
|
|
|
delta = (UINT8 *)resn - (UINT8 *)bufn.Pointer;
|
2004-04-10 15:48:10 +04:00
|
|
|
if (delta >=
|
2006-01-29 06:12:22 +03:00
|
|
|
bufn.Length-ACPI_RS_SIZE(ACPI_RESOURCE_DATA)) {
|
2002-07-29 07:06:56 +04:00
|
|
|
bufn.Length *= 2;
|
|
|
|
bufn.Pointer = realloc(bufn.Pointer, bufn.Length,
|
2003-03-06 02:00:56 +03:00
|
|
|
M_ACPI, M_WAITOK);
|
2002-07-29 07:06:56 +04:00
|
|
|
resn = (ACPI_RESOURCE *)((UINT8 *)bufn.Pointer + delta);
|
|
|
|
}
|
|
|
|
}
|
2006-02-26 21:46:04 +03:00
|
|
|
if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) {
|
2002-07-29 07:06:56 +04:00
|
|
|
printf("acpi_allocate_resources: resc not exhausted\n");
|
|
|
|
rv = AE_BAD_DATA;
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
2006-02-26 21:46:04 +03:00
|
|
|
resn->Type = ACPI_RESOURCE_TYPE_END_TAG;
|
2002-07-29 07:06:56 +04:00
|
|
|
rv = AcpiSetCurrentResources(handle, &bufn);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("acpi_allocate_resources: AcpiSetCurrentResources %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
}
|
|
|
|
|
|
|
|
out3:
|
2003-03-06 02:00:56 +03:00
|
|
|
free(bufn.Pointer, M_ACPI);
|
2002-07-29 07:06:56 +04:00
|
|
|
out2:
|
2009-09-16 14:47:54 +04:00
|
|
|
ACPI_FREE(bufc.Pointer);
|
2002-07-29 07:06:56 +04:00
|
|
|
out1:
|
2009-09-16 14:47:54 +04:00
|
|
|
ACPI_FREE(bufp.Pointer);
|
2002-07-29 07:06:56 +04:00
|
|
|
out:
|
|
|
|
return rv;
|
|
|
|
}
|
2006-07-04 04:30:21 +04:00
|
|
|
#endif /* ACPI_ACTIVATE_DEV */
|
2005-12-14 02:27:31 +03:00
|
|
|
|
|
|
|
SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
|
|
|
|
{
|
|
|
|
const struct sysctlnode *node;
|
2006-06-15 22:05:08 +04:00
|
|
|
const struct sysctlnode *ssnode;
|
2005-12-14 02:27:31 +03:00
|
|
|
|
|
|
|
if (sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "hw", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_HW, CTL_EOL) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sysctl_createv(clog, 0, NULL, &node,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "acpi", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_HW, CTL_CREATE, CTL_EOL) != 0)
|
|
|
|
return;
|
|
|
|
|
2008-02-13 18:27:55 +03:00
|
|
|
sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READONLY,
|
|
|
|
CTLTYPE_QUAD, "root",
|
|
|
|
SYSCTL_DESCR("ACPI root pointer"),
|
|
|
|
NULL, 0, &acpi_root_pointer, sizeof(acpi_root_pointer),
|
|
|
|
CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
|
|
|
|
sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READONLY,
|
|
|
|
CTLTYPE_STRING, "supported_states",
|
|
|
|
SYSCTL_DESCR("Supported ACPI system states"),
|
|
|
|
NULL, 0, acpi_supported_states, 0,
|
|
|
|
CTL_HW, node->sysctl_num, CTL_CREATE, CTL_EOL);
|
2006-06-15 22:05:08 +04:00
|
|
|
|
|
|
|
/* ACPI sleepstate sysctl */
|
|
|
|
if (sysctl_createv(NULL, 0, NULL, &node,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "machdep", NULL,
|
|
|
|
NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL) != 0)
|
|
|
|
return;
|
|
|
|
if (sysctl_createv(NULL, 0, &node, &ssnode,
|
|
|
|
CTLFLAG_READWRITE, CTLTYPE_INT, "sleep_state",
|
|
|
|
NULL, sysctl_hw_acpi_sleepstate, 0, NULL, 0, CTL_CREATE,
|
|
|
|
CTL_EOL) != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS)
|
|
|
|
{
|
|
|
|
int error, t;
|
|
|
|
struct sysctlnode node;
|
|
|
|
|
|
|
|
node = *rnode;
|
|
|
|
t = acpi_sleepstate;
|
|
|
|
node.sysctl_data = &t;
|
|
|
|
error = sysctl_lookup(SYSCTLFN_CALL(&node));
|
|
|
|
if (error || newp == NULL)
|
|
|
|
return error;
|
|
|
|
|
2006-07-02 01:44:13 +04:00
|
|
|
if (acpi_softc == NULL)
|
|
|
|
return ENOSYS;
|
2006-06-15 22:05:08 +04:00
|
|
|
|
2006-07-02 01:44:13 +04:00
|
|
|
acpi_enter_sleep_state(acpi_softc, t);
|
2006-06-15 22:05:08 +04:00
|
|
|
|
|
|
|
return 0;
|
2005-12-14 02:27:31 +03:00
|
|
|
}
|
2007-12-17 00:10:34 +03:00
|
|
|
|
|
|
|
static ACPI_TABLE_HEADER *
|
|
|
|
acpi_map_rsdt(void)
|
|
|
|
{
|
|
|
|
ACPI_PHYSICAL_ADDRESS paddr;
|
|
|
|
ACPI_TABLE_RSDP *rsdp;
|
|
|
|
|
|
|
|
paddr = AcpiOsGetRootPointer();
|
|
|
|
if (paddr == 0) {
|
|
|
|
printf("ACPI: couldn't get root pointer\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rsdp = AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_RSDP));
|
|
|
|
if (rsdp == NULL) {
|
|
|
|
printf("ACPI: couldn't map RSDP\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (rsdp->Revision > 1 && rsdp->XsdtPhysicalAddress)
|
|
|
|
paddr = (ACPI_PHYSICAL_ADDRESS)rsdp->XsdtPhysicalAddress;
|
|
|
|
else
|
|
|
|
paddr = (ACPI_PHYSICAL_ADDRESS)rsdp->RsdtPhysicalAddress;
|
|
|
|
AcpiOsUnmapMemory(rsdp, sizeof(ACPI_TABLE_RSDP));
|
|
|
|
|
|
|
|
return AcpiOsMapMemory(paddr, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_unmap_rsdt(ACPI_TABLE_HEADER *rsdt)
|
|
|
|
{
|
|
|
|
if (rsdt == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AcpiOsUnmapMemory(rsdt, sizeof(ACPI_TABLE_HEADER));
|
|
|
|
}
|