2005-06-20 16:21:36 +04:00
|
|
|
/* $NetBSD: acpi.c,v 1.72 2005/06/20 12:21:36 sekiya Exp $ */
|
2003-11-01 06:45:48 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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>
|
2005-06-20 16:21:36 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.72 2005/06/20 12:21:36 sekiya Exp $");
|
2003-01-06 01:33:21 +03:00
|
|
|
|
|
|
|
#include "opt_acpi.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>
|
2003-02-14 14:05:39 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.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>
|
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
|
|
|
|
2003-04-17 05:22:21 +04:00
|
|
|
#ifdef ACPI_PCI_FIXUP
|
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
|
|
|
|
|
|
|
|
int acpi_dbgr = 0x00;
|
|
|
|
#endif
|
|
|
|
|
2004-05-01 16:03:27 +04:00
|
|
|
static int acpi_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void acpi_attach(struct device *, struct device *, void *);
|
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
|
|
|
|
|
|
|
extern struct cfdriver acpi_cd;
|
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(acpi, sizeof(struct acpi_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
acpi_match, acpi_attach, NULL, NULL);
|
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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static struct simplelock acpi_slock;
|
|
|
|
static int acpi_locked;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void acpi_shutdown(void *);
|
|
|
|
static ACPI_STATUS acpi_disable(struct acpi_softc *sc);
|
|
|
|
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 *);
|
2003-04-17 05:22:21 +04:00
|
|
|
#ifdef ACPI_PCI_FIXUP
|
2004-05-01 16:03:27 +04:00
|
|
|
void acpi_pci_fixup(struct acpi_softc *);
|
2002-07-29 07:26:20 +04:00
|
|
|
#endif
|
2003-07-06 08:03:21 +04:00
|
|
|
#if defined(ACPI_PCI_FIXUP) || defined(ACPI_ACTIVATE_DEV)
|
2004-05-01 16:03:27 +04:00
|
|
|
static ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE handle);
|
2002-07-29 07:06:56 +04:00
|
|
|
#endif
|
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;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
if (beenhere != 0)
|
|
|
|
panic("acpi_probe: ACPI has already been probed");
|
|
|
|
beenhere = 1;
|
|
|
|
|
2003-02-14 14:05:39 +03:00
|
|
|
simple_lock_init(&acpi_slock);
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Looks like we have ACPI!
|
|
|
|
*/
|
|
|
|
|
2004-04-11 10:48:25 +04:00
|
|
|
return 1;
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_match:
|
|
|
|
*
|
|
|
|
* Autoconfiguration `match' routine.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static int
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_match(struct device *parent, struct cfdata *match, void *aux)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_attach(struct device *parent, struct device *self, void *aux)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = (void *) self;
|
|
|
|
struct acpibus_attach_args *aa = aux;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
if (acpi_softc != NULL)
|
|
|
|
panic("acpi_attach: ACPI has already been attached");
|
|
|
|
|
2003-04-18 05:31:34 +04:00
|
|
|
sysmon_power_settype("acpi");
|
|
|
|
|
2003-07-02 15:54:43 +04:00
|
|
|
printf("%s: using Intel ACPI CA subsystem version %08x\n",
|
|
|
|
sc->sc_dev.dv_xname, ACPI_CA_VERSION);
|
|
|
|
|
2003-01-08 19:52:49 +03:00
|
|
|
printf("%s: X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
2003-10-31 23:54:18 +03:00
|
|
|
AcpiGbl_XSDT->OemId, AcpiGbl_XSDT->OemTableId,
|
|
|
|
AcpiGbl_XSDT->OemRevision,
|
|
|
|
AcpiGbl_XSDT->AslCompilerId, AcpiGbl_XSDT->AslCompilerRevision);
|
2003-01-08 19:52:49 +03:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
|
|
rv = AcpiEnableSubsystem(0);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2003-11-03 20:24:22 +03:00
|
|
|
printf("%s: unable to enable ACPI: %s\n",
|
|
|
|
sc->sc_dev.dv_xname, 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 */
|
2004-03-31 15:19:39 +04:00
|
|
|
#if NACPIEC > 0
|
2004-03-30 19:18:55 +04:00
|
|
|
acpiec_early_attach(&sc->sc_dev);
|
2004-03-31 15:19:39 +04:00
|
|
|
#endif
|
2004-03-30 19:18:55 +04:00
|
|
|
|
2003-10-31 20:22:28 +03:00
|
|
|
rv = AcpiInitializeObjects(0);
|
2003-11-03 21:07:10 +03:00
|
|
|
if (ACPI_FAILURE(rv)) {
|
2003-11-03 20:24:22 +03:00
|
|
|
printf("%s: unable to initialize ACPI objects: %s\n",
|
|
|
|
sc->sc_dev.dv_xname, 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. */
|
|
|
|
if (AcpiGbl_FADT != NULL)
|
2003-01-13 04:24:11 +03:00
|
|
|
printf("%s: SCI interrupting at int %d\n",
|
2002-06-17 12:18:51 +04:00
|
|
|
sc->sc_dev.dv_xname, AcpiGbl_FADT->SciInt);
|
2001-09-28 06:09:22 +04:00
|
|
|
/*
|
|
|
|
* Check for fixed-hardware features.
|
|
|
|
*/
|
|
|
|
acpi_enable_fixed_events(sc);
|
|
|
|
|
2002-07-29 07:06:56 +04:00
|
|
|
/*
|
|
|
|
* Fix up PCI devices.
|
|
|
|
*/
|
2003-04-17 05:22:21 +04:00
|
|
|
#ifdef ACPI_PCI_FIXUP
|
2003-05-16 01:29:49 +04:00
|
|
|
if ((sc->sc_quirks & (ACPI_QUIRK_BADPCI | ACPI_QUIRK_BADIRQ)) == 0)
|
|
|
|
acpi_pci_fixup(sc);
|
2002-07-29 07:06:56 +04:00
|
|
|
#endif
|
2004-04-10 15:48:10 +04:00
|
|
|
|
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
|
2003-01-07 21:46:48 +03:00
|
|
|
acpi_md_callback((struct device *)sc);
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_build_tree(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a shutdown hook that disables certain ACPI
|
|
|
|
* events that might happen and confuse us while we're
|
|
|
|
* trying to shut down.
|
|
|
|
*/
|
|
|
|
sc->sc_sdhook = shutdownhook_establish(acpi_shutdown, sc);
|
|
|
|
if (sc->sc_sdhook == NULL)
|
|
|
|
printf("%s: WARNING: unable to register shutdown hook\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acpi_shutdown:
|
|
|
|
*
|
|
|
|
* Shutdown hook for ACPI -- disable some events that
|
|
|
|
* might confuse us.
|
|
|
|
*/
|
2004-05-01 16:03:27 +04:00
|
|
|
static void
|
2001-09-28 06:09:22 +04:00
|
|
|
acpi_shutdown(void *arg)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = arg;
|
2003-11-03 21:07:10 +03:00
|
|
|
ACPI_STATUS rv;
|
2001-09-28 06:09:22 +04:00
|
|
|
|
2003-11-03 21:07:10 +03:00
|
|
|
rv = acpi_disable(sc);
|
|
|
|
if (ACPI_FAILURE(rv))
|
|
|
|
printf("%s: WARNING: unable to disable ACPI: %s\n",
|
|
|
|
sc->sc_dev.dv_xname, AcpiFormatException(rv));
|
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;
|
|
|
|
|
2004-06-07 19:33:17 +04:00
|
|
|
#ifdef ACPI_DISABLE_ON_POWEROFF
|
2001-09-28 06:09:22 +04:00
|
|
|
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-06-07 19:33:17 +04:00
|
|
|
#endif
|
2004-04-11 10:48:25 +04:00
|
|
|
return rv;
|
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 */
|
|
|
|
"\\_SI_", /* system idicator namespace */
|
|
|
|
"\\_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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Same problem as above...
|
|
|
|
*/
|
2003-11-03 09:03:47 +03:00
|
|
|
if ((ad->ad_devinfo->Valid & ACPI_VALID_HID)
|
2003-01-04 08:32:15 +03:00
|
|
|
== 0)
|
|
|
|
continue;
|
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
|
|
|
|
ad->ad_device = config_found(&sc->sc_dev,
|
|
|
|
&aa, acpi_print);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2004-04-10 15:48:10 +04:00
|
|
|
printf("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)) {
|
2003-11-03 09:03:47 +03:00
|
|
|
printf("acpi: activate failed for %s\n",
|
|
|
|
(*di)->HardwareId.Value);
|
2002-12-31 14:23:34 +03:00
|
|
|
} else {
|
2003-11-03 09:03:47 +03:00
|
|
|
printf("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
|
2004-04-10 15:48:10 +04:00
|
|
|
printf("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,
|
|
|
|
void **status)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
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
|
2003-11-03 20:24:22 +03:00
|
|
|
printf("%s: AcpiGetObjectInfo failed: %s\n",
|
|
|
|
sc->sc_dev.dv_xname, 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;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&as->as_devnodes, ad, ad_list);
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
if ((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
|
2001-09-28 06:09:22 +04:00
|
|
|
printf("%s: HID %s found in scope %s level %d\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
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)
|
2001-09-28 06:09:22 +04:00
|
|
|
printf(" UID %s\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
ad->ad_devinfo->UniqueId.Value);
|
|
|
|
if (ad->ad_devinfo->Valid & ACPI_VALID_ADR)
|
2001-09-28 06:09:22 +04:00
|
|
|
printf(" ADR 0x%016qx\n",
|
2003-11-03 09:03:47 +03:00
|
|
|
ad->ad_devinfo->Address);
|
|
|
|
if (ad->ad_devinfo->Valid & ACPI_VALID_STA)
|
2001-09-28 06:09:22 +04:00
|
|
|
printf(" 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:
|
|
|
|
*
|
|
|
|
* Autoconfiguration print routine.
|
|
|
|
*/
|
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;
|
2003-01-06 01:33:21 +03:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
aprint_normal("%s ", pnpstr);
|
2003-11-03 21:07:10 +03:00
|
|
|
rv = acpi_eval_string(aa->aa_node->ad_handle,
|
|
|
|
"_STR", &str);
|
|
|
|
if (ACPI_SUCCESS(rv)) {
|
2003-01-06 01:33:21 +03:00
|
|
|
aprint_normal("[%s] ", str);
|
|
|
|
AcpiOsFree(str);
|
|
|
|
}
|
|
|
|
#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) {
|
|
|
|
printf("[%s] ",
|
|
|
|
acpi_knowndevs[i].str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2003-01-06 01:33:21 +03:00
|
|
|
#endif
|
|
|
|
} else {
|
2003-01-09 13:35:29 +03:00
|
|
|
aprint_normal("ACPI Object Type '%s' (0x%02x) ",
|
2003-11-03 09:03:47 +03:00
|
|
|
AcpiUtGetTypeName(aa->aa_node->ad_devinfo->Type),
|
|
|
|
aa->aa_node->ad_devinfo->Type);
|
2001-09-29 22:13:48 +04:00
|
|
|
}
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("at %s", pnp);
|
2002-12-30 12:33:25 +03:00
|
|
|
} else {
|
2003-11-03 09:03:47 +03:00
|
|
|
if (aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID) {
|
|
|
|
aprint_normal(" (%s", aa->aa_node->ad_devinfo->HardwareId.Value);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
aprint_normal(")");
|
2002-12-31 08:59:53 +03:00
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->PwrButton == 0) {
|
2003-04-17 05:22:21 +04:00
|
|
|
printf("%s: fixed-feature power button present\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_smpsw_power.smpsw_name = sc->sc_dev.dv_xname;
|
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) {
|
|
|
|
printf("%s: unable to register fixed power button "
|
|
|
|
"with sysmon\n", sc->sc_dev.dv_xname);
|
|
|
|
} 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)) {
|
2003-04-17 05:22:21 +04:00
|
|
|
printf("%s: unable to install handler for "
|
2003-11-03 21:07:10 +03:00
|
|
|
"fixed power button: %s\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
AcpiFormatException(rv));
|
2003-04-17 05:22:21 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-28 06:09:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->SleepButton == 0) {
|
2003-04-17 05:22:21 +04:00
|
|
|
printf("%s: fixed-feature sleep button present\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
sc->sc_smpsw_sleep.smpsw_name = sc->sc_dev.dv_xname;
|
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) {
|
|
|
|
printf("%s: unable to register fixed sleep button "
|
|
|
|
"with sysmon\n", sc->sc_dev.dv_xname);
|
|
|
|
} 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)) {
|
2003-04-17 05:22:21 +04:00
|
|
|
printf("%s: unable to install handler for "
|
2003-11-03 21:07:10 +03:00
|
|
|
"fixed sleep button: %s\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
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
|
|
|
|
2003-04-17 05:22:21 +04:00
|
|
|
rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
|
|
|
|
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
|
|
|
/*
|
|
|
|
* acpi_set_wake_gpe
|
|
|
|
*
|
|
|
|
* Set GPE as both Runtime and Wake
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_set_wake_gpe(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
AcpiSetGpeType(NULL, elt[0].Integer.Value, ACPI_GPE_TYPE_WAKE_RUN);
|
|
|
|
AcpiEnableGpe(NULL, elt[0].Integer.Value, ACPI_NOT_ISR);
|
|
|
|
|
|
|
|
out:
|
|
|
|
AcpiOsFree(buf.Pointer);
|
|
|
|
}
|
|
|
|
|
2003-11-03 09:03:47 +03:00
|
|
|
|
2002-06-18 12:09:21 +04:00
|
|
|
/*****************************************************************************
|
|
|
|
* ACPI sleep support.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_available_state(struct acpi_softc *sc, int state)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
ACPI_STATUS ret = AE_OK;
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
printf("acpi: cannot enter the sleep state (%d).\n",
|
|
|
|
state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = AcpiEnterSleepStatePrep(state);
|
|
|
|
if (ACPI_FAILURE(ret)) {
|
|
|
|
printf("acpi: failed preparing to sleep (%s)\n",
|
|
|
|
AcpiFormatException(ret));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (state==ACPI_STATE_S1) {
|
|
|
|
/* just enter the state */
|
2002-07-18 16:05:11 +04:00
|
|
|
acpi_md_OsDisableInterrupt();
|
2002-06-18 12:09:21 +04:00
|
|
|
AcpiEnterSleepState((UINT8)state);
|
|
|
|
AcpiUtReleaseMutex(ACPI_MTX_HARDWARE);
|
|
|
|
} else {
|
|
|
|
/* XXX: powerhooks(9) framework is too poor to
|
|
|
|
* support ACPI sleep state...
|
|
|
|
*/
|
|
|
|
dopowerhooks(PWR_SOFTSUSPEND);
|
|
|
|
s = splhigh();
|
|
|
|
dopowerhooks(PWR_SUSPEND);
|
|
|
|
acpi_md_sleep(state);
|
|
|
|
dopowerhooks(PWR_RESUME);
|
|
|
|
splx(s);
|
|
|
|
dopowerhooks(PWR_SOFTRESUME);
|
|
|
|
if (state==ACPI_STATE_S4)
|
|
|
|
AcpiEnable();
|
|
|
|
}
|
|
|
|
AcpiLeaveSleepState((UINT8)state);
|
|
|
|
break;
|
|
|
|
case ACPI_STATE_S5:
|
2003-08-17 07:45:19 +04:00
|
|
|
ret = AcpiEnterSleepStatePrep(ACPI_STATE_S5);
|
|
|
|
if (ACPI_FAILURE(ret)) {
|
|
|
|
printf("acpi: failed preparing to sleep (%s)\n",
|
|
|
|
AcpiFormatException(ret));
|
|
|
|
break;
|
|
|
|
}
|
2002-07-18 16:05:11 +04:00
|
|
|
acpi_md_OsDisableInterrupt();
|
2002-06-18 12:09:21 +04:00
|
|
|
AcpiEnterSleepState(ACPI_STATE_S5);
|
|
|
|
printf("WARNING: powerdown failed!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2003-04-17 05:22:21 +04:00
|
|
|
#ifdef ACPI_PCI_FIXUP
|
2002-07-29 07:06:56 +04:00
|
|
|
ACPI_STATUS acpi_pci_fixup_bus(ACPI_HANDLE, UINT32, void *, void **);
|
|
|
|
/*
|
|
|
|
* acpi_pci_fixup:
|
|
|
|
*
|
|
|
|
* Set up PCI devices that BIOS didn't handle right.
|
|
|
|
* Iterate through all devices and try to get the _PTR
|
|
|
|
* (PCI Routing Table). If it exists then make sure all
|
|
|
|
* interrupt links that it uses are working.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
acpi_pci_fixup(struct acpi_softc *sc)
|
|
|
|
{
|
|
|
|
ACPI_HANDLE parent;
|
2003-11-03 21:07:10 +03:00
|
|
|
ACPI_STATUS rv;
|
2002-07-29 07:06:56 +04:00
|
|
|
|
|
|
|
#ifdef ACPI_DEBUG
|
|
|
|
printf("acpi_pci_fixup starts:\n");
|
|
|
|
#endif
|
2003-11-03 21:07:10 +03:00
|
|
|
rv = AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &parent);
|
|
|
|
if (ACPI_FAILURE(rv))
|
2002-07-29 07:06:56 +04:00
|
|
|
return;
|
|
|
|
sc->sc_pci_bus = 0;
|
|
|
|
AcpiWalkNamespace(ACPI_TYPE_DEVICE, parent, 100,
|
|
|
|
acpi_pci_fixup_bus, sc, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint
|
|
|
|
acpi_get_intr(ACPI_HANDLE handle)
|
|
|
|
{
|
|
|
|
ACPI_BUFFER ret;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_RESOURCE *res;
|
|
|
|
ACPI_RESOURCE_IRQ *irq;
|
|
|
|
uint intr;
|
|
|
|
|
|
|
|
intr = -1;
|
|
|
|
rv = acpi_get(handle, &ret, AcpiGetCurrentResources);
|
|
|
|
if (ACPI_FAILURE(rv))
|
2004-04-11 10:48:25 +04:00
|
|
|
return intr;
|
2002-07-29 07:06:56 +04:00
|
|
|
for (res = ret.Pointer; res->Id != ACPI_RSTYPE_END_TAG;
|
|
|
|
res = ACPI_NEXT_RESOURCE(res)) {
|
|
|
|
if (res->Id == ACPI_RSTYPE_IRQ) {
|
|
|
|
irq = (ACPI_RESOURCE_IRQ *)&res->Data;
|
|
|
|
if (irq->NumberOfInterrupts == 1)
|
|
|
|
intr = irq->Interrupts[0];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-07-02 16:23:25 +04:00
|
|
|
AcpiOsFree(ret.Pointer);
|
2004-04-11 10:48:25 +04:00
|
|
|
return intr;
|
2002-07-29 07:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
acpi_pci_set_line(int bus, int dev, int pin, int line)
|
|
|
|
{
|
|
|
|
ACPI_STATUS err;
|
|
|
|
ACPI_PCI_ID pid;
|
|
|
|
UINT32 intr, id, bhlc;
|
|
|
|
int func, nfunc;
|
|
|
|
|
|
|
|
pid.Bus = bus;
|
|
|
|
pid.Device = dev;
|
|
|
|
pid.Function = 0;
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2002-07-29 07:06:56 +04:00
|
|
|
err = AcpiOsReadPciConfiguration(&pid, PCI_BHLC_REG, &bhlc, 32);
|
|
|
|
if (err)
|
|
|
|
return;
|
|
|
|
if (PCI_HDRTYPE_MULTIFN(bhlc))
|
|
|
|
nfunc = 8;
|
|
|
|
else
|
|
|
|
nfunc = 1;
|
|
|
|
|
|
|
|
for (func = 0; func < nfunc; func++) {
|
|
|
|
pid.Function = func;
|
|
|
|
|
|
|
|
err = AcpiOsReadPciConfiguration(&pid, PCI_ID_REG, &id, 32);
|
|
|
|
if (err || PCI_VENDOR(id) == PCI_VENDOR_INVALID ||
|
|
|
|
PCI_VENDOR(id) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = AcpiOsReadPciConfiguration(&pid, PCI_INTERRUPT_REG,
|
|
|
|
&intr, 32);
|
|
|
|
if (err) {
|
|
|
|
printf("AcpiOsReadPciConfiguration failed %d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pin == PCI_INTERRUPT_PIN(intr) &&
|
|
|
|
line != PCI_INTERRUPT_LINE(intr)) {
|
|
|
|
#ifdef ACPI_DEBUG
|
|
|
|
printf("acpi fixup pci intr: %d:%d:%d %c: %d -> %d\n",
|
|
|
|
bus, dev, func,
|
|
|
|
pin + '@', PCI_INTERRUPT_LINE(intr),
|
|
|
|
line);
|
|
|
|
#endif
|
|
|
|
intr &= ~(PCI_INTERRUPT_LINE_MASK <<
|
|
|
|
PCI_INTERRUPT_LINE_SHIFT);
|
|
|
|
intr |= line << PCI_INTERRUPT_LINE_SHIFT;
|
|
|
|
err = AcpiOsWritePciConfiguration(&pid,
|
|
|
|
PCI_INTERRUPT_REG, intr, 32);
|
|
|
|
if (err) {
|
|
|
|
printf("AcpiOsWritePciConfiguration failed"
|
|
|
|
" %d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
acpi_pci_fixup_bus(ACPI_HANDLE handle, UINT32 level, void *context,
|
|
|
|
void **status)
|
|
|
|
{
|
|
|
|
struct acpi_softc *sc = context;
|
|
|
|
ACPI_STATUS rv;
|
|
|
|
ACPI_BUFFER buf;
|
|
|
|
UINT8 *Buffer;
|
|
|
|
ACPI_PCI_ROUTING_TABLE *PrtElement;
|
|
|
|
ACPI_HANDLE link;
|
|
|
|
uint line;
|
2003-01-07 21:46:48 +03:00
|
|
|
ACPI_INTEGER val;
|
2002-07-29 07:06:56 +04:00
|
|
|
|
|
|
|
rv = acpi_get(handle, &buf, AcpiGetIrqRoutingTable);
|
|
|
|
if (ACPI_FAILURE(rv))
|
2004-04-11 10:48:25 +04:00
|
|
|
return AE_OK;
|
2002-07-29 07:06:56 +04:00
|
|
|
|
2003-01-07 21:46:48 +03:00
|
|
|
/*
|
|
|
|
* If at level 1, this is a PCI root bus. Try the _BBN method
|
|
|
|
* to get the right PCI bus numbering for the following
|
|
|
|
* busses (this is a depth-first walk). It may fail,
|
|
|
|
* for example if there's only one root bus, but that
|
|
|
|
* case should be ok, so we'll ignore that.
|
|
|
|
*/
|
|
|
|
if (level == 1) {
|
2004-03-23 17:07:42 +03:00
|
|
|
rv = acpi_eval_integer(handle, METHOD_NAME__BBN, &val);
|
2003-01-07 21:46:48 +03:00
|
|
|
if (!ACPI_FAILURE(rv)) {
|
|
|
|
#ifdef ACPI_DEBUG
|
|
|
|
printf("%s: fixup: _BBN success, bus # was %d now %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_pci_bus,
|
|
|
|
ACPI_LOWORD(val));
|
|
|
|
#endif
|
|
|
|
sc->sc_pci_bus = ACPI_LOWORD(val);
|
|
|
|
}
|
|
|
|
}
|
2004-04-10 15:48:10 +04:00
|
|
|
|
2003-01-07 21:46:48 +03:00
|
|
|
|
2002-07-29 07:06:56 +04:00
|
|
|
#ifdef ACPI_DEBUG
|
2003-01-07 21:46:48 +03:00
|
|
|
printf("%s: fixing up PCI bus %d at level %u\n", sc->sc_dev.dv_xname,
|
|
|
|
sc->sc_pci_bus, level);
|
2002-07-29 07:06:56 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (Buffer = buf.Pointer; ; Buffer += PrtElement->Length) {
|
|
|
|
PrtElement = (ACPI_PCI_ROUTING_TABLE *)Buffer;
|
|
|
|
if (PrtElement->Length == 0)
|
|
|
|
break;
|
2003-01-07 21:46:48 +03:00
|
|
|
if (PrtElement->Source[0] == 0)
|
2002-07-29 07:06:56 +04:00
|
|
|
continue;
|
|
|
|
|
2004-03-23 17:07:42 +03:00
|
|
|
rv = AcpiGetHandle(NULL, PrtElement->Source, &link);
|
|
|
|
if (ACPI_FAILURE(rv))
|
2002-07-29 07:06:56 +04:00
|
|
|
continue;
|
|
|
|
line = acpi_get_intr(link);
|
2005-06-20 16:21:36 +04:00
|
|
|
if (line < 1) {
|
2002-12-31 14:23:34 +03:00
|
|
|
printf("%s: fixing up intr link %s\n",
|
|
|
|
sc->sc_dev.dv_xname, PrtElement->Source);
|
2002-07-29 07:06:56 +04:00
|
|
|
rv = acpi_allocate_resources(link);
|
|
|
|
if (ACPI_FAILURE(rv)) {
|
|
|
|
printf("%s: interrupt allocation failed %s\n",
|
|
|
|
sc->sc_dev.dv_xname, PrtElement->Source);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
line = acpi_get_intr(link);
|
|
|
|
if (line == -1) {
|
|
|
|
printf("%s: get intr failed %s\n",
|
|
|
|
sc->sc_dev.dv_xname, PrtElement->Source);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
acpi_pci_set_line(sc->sc_pci_bus, PrtElement->Address >> 16,
|
|
|
|
PrtElement->Pin + 1, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_pci_bus++;
|
|
|
|
|
2003-07-02 16:23:25 +04:00
|
|
|
AcpiOsFree(buf.Pointer);
|
2004-04-11 10:48:25 +04:00
|
|
|
return AE_OK;
|
2002-07-29 07:06:56 +04:00
|
|
|
}
|
2002-07-29 07:26:20 +04:00
|
|
|
#endif /* ACPI_PCI_FIXUP */
|
2002-07-29 07:06:56 +04:00
|
|
|
|
2003-07-06 08:03:21 +04:00
|
|
|
#if defined(ACPI_PCI_FIXUP) || defined(ACPI_ACTIVATE_DEV)
|
2002-07-29 07:06:56 +04:00
|
|
|
/* XXX This very incomplete */
|
2004-05-01 16:03:27 +04:00
|
|
|
static 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;
|
|
|
|
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;
|
|
|
|
while (resc->Id != ACPI_RSTYPE_END_TAG &&
|
|
|
|
resp->Id != ACPI_RSTYPE_END_TAG) {
|
|
|
|
while (resc->Id != resp->Id && resp->Id != ACPI_RSTYPE_END_TAG)
|
|
|
|
resp = ACPI_NEXT_RESOURCE(resp);
|
|
|
|
if (resp->Id == ACPI_RSTYPE_END_TAG)
|
|
|
|
break;
|
|
|
|
/* Found identical Id */
|
|
|
|
resn->Id = resc->Id;
|
|
|
|
switch (resc->Id) {
|
|
|
|
case ACPI_RSTYPE_IRQ:
|
|
|
|
memcpy(&resn->Data, &resp->Data,
|
|
|
|
sizeof(ACPI_RESOURCE_IRQ));
|
|
|
|
irq = (ACPI_RESOURCE_IRQ *)&resn->Data;
|
|
|
|
irq->Interrupts[0] =
|
|
|
|
((ACPI_RESOURCE_IRQ *)&resp->Data)->
|
|
|
|
Interrupts[irq->NumberOfInterrupts-1];
|
|
|
|
irq->NumberOfInterrupts = 1;
|
|
|
|
resn->Length = ACPI_SIZEOF_RESOURCE(ACPI_RESOURCE_IRQ);
|
|
|
|
break;
|
|
|
|
case ACPI_RSTYPE_IO:
|
|
|
|
memcpy(&resn->Data, &resp->Data,
|
|
|
|
sizeof(ACPI_RESOURCE_IO));
|
|
|
|
resn->Length = resp->Length;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("acpi_allocate_resources: res=%d\n", resc->Id);
|
|
|
|
rv = AE_BAD_DATA;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
resc = ACPI_NEXT_RESOURCE(resc);
|
|
|
|
resn = ACPI_NEXT_RESOURCE(resn);
|
|
|
|
delta = (UINT8 *)resn - (UINT8 *)bufn.Pointer;
|
2004-04-10 15:48:10 +04:00
|
|
|
if (delta >=
|
2002-12-31 14:23:34 +03:00
|
|
|
bufn.Length-ACPI_SIZEOF_RESOURCE(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resc->Id != ACPI_RSTYPE_END_TAG) {
|
|
|
|
printf("acpi_allocate_resources: resc not exhausted\n");
|
|
|
|
rv = AE_BAD_DATA;
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
resn->Id = ACPI_RSTYPE_END_TAG;
|
|
|
|
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;
|
|
|
|
}
|
2002-07-29 07:26:20 +04:00
|
|
|
#endif /* ACPI_PCI_FIXUP || ACPI_ACTIVATE_DEV */
|