2008-12-07 13:53:57 +03:00
|
|
|
/* $NetBSD: acpi.c,v 1.121 2008/12/07 10:53:57 mlelstv 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>
|
2008-12-07 13:53:57 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.121 2008/12/07 10:53:57 mlelstv 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>
|
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
|
|
|
|
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];
|
|
|
|
|
2008-03-10 23:58:38 +03:00
|
|
|
static int acpi_match(device_t, struct cfdata *, void *);
|
|
|
|
static void acpi_attach(device_t, device_t, void *);
|
|
|
|
static void acpi_childdet(device_t, device_t);
|
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),
|
2008-03-10 23:58:38 +03:00
|
|
|
acpi_match, acpi_attach, NULL, NULL, NULL, 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;
|
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 */
|
|
|
|
"PNP0A??", /* Busses aren't enumerated with ACPI yet */
|
|
|
|
"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;
|
2008-02-13 18:27:55 +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
|
|
|
|
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)) {
|
|
|
|
printf("ACPI: unable to initialize ACPI tables: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = AcpiReallocateRootTable();
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("ACPI: unable to reallocate root table: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
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));
|
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");
|
|
|
|
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);
|
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)) {
|
|
|
|
printf("ACPI: unable to initialise SystemMemory handler: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("ACPI: unable to initialise SystemIO handler: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
|
|
|
|
ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("ACPI: unabled to initialise PciConfig handler: %s\n",
|
|
|
|
AcpiFormatException(rv));
|
|
|
|
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));
|
|
|
|
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
|
2008-03-10 23:58:38 +03:00
|
|
|
acpi_match(device_t parent, struct cfdata *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;
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
if (!pmf_device_register(self, NULL, NULL))
|
|
|
|
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);
|
|
|
|
|
2008-02-13 18:27:55 +03:00
|
|
|
sprintf(acpi_supported_states, "%s%s%s%s%s%s",
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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_attach_args aa;
|
|
|
|
struct acpi_make_devnode_state state;
|
|
|
|
struct acpi_scope *as;
|
|
|
|
struct acpi_devnode *ad;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, for this namespace, try and attach the devices. */
|
|
|
|
TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2008-03-27 05:51:26 +03:00
|
|
|
config_found_ia(sc->sc_dev, "acpiapmbus", NULL, NULL);
|
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;
|
2003-11-01 22:24:42 +03:00
|
|
|
ACPI_BUFFER buf;
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
|
|
|
|
#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",
|
2003-11-03 09:03:47 +03:00
|
|
|
(*di)->HardwareId.Value);
|
2002-12-31 14:23:34 +03:00
|
|
|
} else {
|
2007-02-10 00:55:00 +03:00
|
|
|
aprint_verbose("acpi: activated %s\n",
|
|
|
|
(*di)->HardwareId.Value);
|
2002-07-29 07:26:20 +04:00
|
|
|
}
|
|
|
|
|
2003-11-01 22:24:42 +03:00
|
|
|
(void)AcpiGetObjectInfo(handle, &buf);
|
2003-11-03 09:03:47 +03:00
|
|
|
AcpiOsFree(*di);
|
|
|
|
*di = buf.Pointer;
|
|
|
|
|
|
|
|
#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-10-31 23:54:18 +03:00
|
|
|
ACPI_BUFFER buf;
|
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)) {
|
2003-11-03 09:03:47 +03:00
|
|
|
buf.Pointer = NULL;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
2003-10-31 23:54:18 +03:00
|
|
|
rv = AcpiGetObjectInfo(handle, &buf);
|
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 */
|
|
|
|
}
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
devinfo = buf.Pointer;
|
|
|
|
|
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",
|
2003-11-03 09:03:47 +03:00
|
|
|
ad->ad_devinfo->HardwareId.Value,
|
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",
|
2003-11-03 09:03:47 +03:00
|
|
|
ad->ad_devinfo->UniqueId.Value);
|
|
|
|
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 =
|
|
|
|
aa->aa_node->ad_devinfo->HardwareId.Value;
|
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;
|
|
|
|
buf.Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
AcpiOsFree(buf.Pointer);
|
2003-01-06 01:33:21 +03:00
|
|
|
}
|
|
|
|
#ifdef ACPIVERBOSE
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(acpi_knowndevs) /
|
|
|
|
sizeof(acpi_knowndevs[0]); i++) {
|
|
|
|
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) {
|
2007-08-08 12:52:31 +04:00
|
|
|
aprint_normal(", %s", aa->aa_node->ad_devinfo->HardwareId.Value);
|
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
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
uid = aa->aa_node->ad_devinfo->UniqueId.Value;
|
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;
|
|
|
|
int 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);
|
|
|
|
|
2003-10-30 23:29:54 +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
|
|
|
|
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;
|
2003-02-14 14:05:39 +03:00
|
|
|
buf.Length = ACPI_ALLOCATE_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;
|
|
|
|
if ((*stringp = AcpiOsAllocate(len)) == NULL)
|
|
|
|
rv = AE_NO_MEMORY;
|
|
|
|
else
|
|
|
|
(void)memcpy(*stringp, ptr, len);
|
|
|
|
AcpiOsFree(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.
|
|
|
|
* Caller must free buf.Pointer by AcpiOsFree().
|
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;
|
2003-02-14 14:05:39 +03:00
|
|
|
bufp->Length = ACPI_ALLOCATE_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.
|
2003-07-02 16:23:25 +04:00
|
|
|
* Caller must free buf.Pointer by AcpiOsFree().
|
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;
|
2003-07-02 16:23:25 +04:00
|
|
|
buf->Length = ACPI_ALLOCATE_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) {
|
|
|
|
if (pmatch(ad->HardwareId.Value, *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) {
|
|
|
|
for (i = 0; i < ad->CompatibilityId.Count; i++) {
|
2003-11-03 21:51:31 +03:00
|
|
|
if (pmatch(ad->CompatibilityId.Id[i].Value, *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:
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
Use device_t and its accessors throughout. Use aprint_*_dev().
Improve PMF-ability.
Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().
Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).
In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.
In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.
In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).
rtw(4) improvements:
Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.
Remove activate() methods:
Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.
Make ath at cardbus resume with crypto functions intact:
Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.
Honor this property in cardbus_child_suspend().
Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?
Miscellaneous ath(4) changes:
Warn if ath(4) tries to write crypto keys to suspended
hardware.
Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.
Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.
Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
2008-03-12 21:02:21 +03:00
|
|
|
if (state != ACPI_STATE_S1 && !pmf_system_suspend(PMF_F_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();
|
Use device_t and its accessors throughout. Use aprint_*_dev().
Improve PMF-ability.
Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().
Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).
In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.
In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.
In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).
rtw(4) improvements:
Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.
Remove activate() methods:
Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.
Make ath at cardbus resume with crypto functions intact:
Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.
Honor this property in cardbus_child_suspend().
Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?
Miscellaneous ath(4) changes:
Warn if ath(4) tries to write crypto keys to suspended
hardware.
Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.
Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.
Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
2008-03-12 21:02:21 +03:00
|
|
|
pmf_system_bus_resume(PMF_F_NONE);
|
2007-12-09 23:27:42 +03:00
|
|
|
AcpiLeaveSleepState((UINT8)state);
|
Use device_t and its accessors throughout. Use aprint_*_dev().
Improve PMF-ability.
Add a 'flags' argument to suspend/resume handlers and
callers such as pmf_system_suspend().
Define a flag, PMF_F_SELF, which indicates to PMF that a
device is suspending/resuming itself. Add helper routines,
pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
that call pmf_device_suspend(dev, PMF_F_SELF) and
pmf_device_resume(dev, PMF_F_SELF), respectively. Use
PMF_F_SELF to suspend/resume self in ath(4), audio(4),
rtw(4), and sip(4).
In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
callbacks, provided by the bus front-end, with
self-suspension/resumption. Also, clean up the bus
front-ends. Make sure that the interrupt handler is
disestablished during suspension. Get rid of driver-private
flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
device_is_active()/device_has_power() calls, instead.
In the network-class suspend handler, call if_stop(, 0)
instead of if_stop(, 1), because the latter is superfluous
(bus- and driver-suspension hooks will 'disable' the NIC),
and it may cause recursion.
In the network-class resume handler, prevent infinite
recursion through if_init() by getting out early if we are
self-suspending (PMF_F_SELF).
rtw(4) improvements:
Destroy rtw(4) callouts when we detach it. Make rtw at
pci detachable. Print some more information with the "rx
frame too long" warning.
Remove activate() methods:
Get rid of rtw_activate() and ath_activate(). The device
activate() methods are not good for much these days.
Make ath at cardbus resume with crypto functions intact:
Introduce a boolean device property, "pmf-powerdown". If
pmf-powerdown is present and false, it indicates that a
bus back-end should not remove power from a device.
Honor this property in cardbus_child_suspend().
Set this property to 'false' in ath_attach(), since removing
power from an ath at cardbus seems to lobotomize the WPA
crypto engine. XXX Should the pmf-powerdown property
propagate toward the root of the device tree?
Miscellaneous ath(4) changes:
Warn if ath(4) tries to write crypto keys to suspended
hardware.
Reduce differences between FreeBSD and NetBSD in ath(4)
multicast filter setup.
Make ath_printrxbuf() print an rx descriptor's status &
key index, to help debug crypto errors.
Shorten a staircase in ath_ioctl(). Don't check for
ieee80211_ioctl() return code ERESTART, it never happens.
2008-03-12 21:02:21 +03:00
|
|
|
pmf_system_resume(PMF_F_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:
|
2003-07-02 16:23:25 +04:00
|
|
|
AcpiOsFree(bufc.Pointer);
|
2002-07-29 07:06:56 +04:00
|
|
|
out1:
|
2003-07-02 16:23:25 +04:00
|
|
|
AcpiOsFree(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));
|
|
|
|
}
|