Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi Add some basic ACPI probing framework. This is...
details: https://anonhg.NetBSD.org/src/rev/676cfb24c473
branches: trunk
changeset: 515535:676cfb24c473
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Sep 28 02:09:22 2001 +0000
description:
Add some basic ACPI probing framework. This is far from complete,
it is merely a work in progress.
diffstat:
sys/dev/acpi/acpi.c | 617 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/acpi/acpi_osd.h | 48 +++
sys/dev/acpi/acpireg.h | 93 +++++++
sys/dev/acpi/acpivar.h | 140 ++++++++++
sys/dev/acpi/files.acpi | 24 +
5 files changed, 922 insertions(+), 0 deletions(-)
diffs (truncated from 942 to 300 lines):
diff -r 01064d4f9eaf -r 676cfb24c473 sys/dev/acpi/acpi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi.c Fri Sep 28 02:09:22 2001 +0000
@@ -0,0 +1,617 @@
+/* $NetBSD: acpi.c,v 1.1 2001/09/28 02:09:22 thorpej Exp $ */
+
+/*
+ * Copyright 2001 Wasabi Systems, Inc.
+ * 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.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+
+#include <dev/acpi/acpica.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpi_osd.h>
+
+#ifdef ENABLE_DEBUGGER
+#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
+
+int acpi_match(struct device *, struct cfdata *, void *);
+void acpi_attach(struct device *, struct device *, void *);
+
+int acpi_print(void *aux, const char *);
+
+extern struct cfdriver acpi_cd;
+
+struct cfattach acpi_ca = {
+ sizeof(struct acpi_softc), acpi_match, acpi_attach,
+};
+
+/*
+ * 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;
+
+void acpi_shutdown(void *);
+ACPI_STATUS acpi_disable(struct acpi_softc *sc);
+void acpi_build_tree(struct acpi_softc *);
+ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **);
+
+void acpi_system_notify_handler(ACPI_HANDLE, UINT32, void *);
+
+void acpi_enable_fixed_events(struct acpi_softc *);
+
+/*
+ * 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;
+
+ /*
+ * Start up ACPICA.
+ */
+#ifdef ENABLE_DEBUGGER
+ if (acpi_dbgr & ACPI_DBGR_INIT)
+ acpi_osd_debugger();
+#endif
+
+ rv = AcpiInitializeSubsystem();
+ if (rv != AE_OK) {
+ printf("ACPI: unable to initialize ACPICA: %d\n", rv);
+ return (0);
+ }
+
+#ifdef ENABLE_DEBUGGER
+ if (acpi_dbgr & ACPI_DBGR_TABLES)
+ acpi_osd_debugger();
+#endif
+
+ rv = AcpiLoadTables();
+ if (rv != AE_OK) {
+ printf("ACPI: unable to load tables: %d\n", rv);
+ return (0);
+ }
+
+ /*
+ * Looks like we have ACPI!
+ */
+
+ return (1);
+}
+
+/*
+ * acpi_match:
+ *
+ * Autoconfiguration `match' routine.
+ */
+int
+acpi_match(struct device *parent, struct cfdata *match, void *aux)
+{
+ struct acpibus_attach_args *aa = aux;
+
+ if (strcmp(aa->aa_busname, acpi_cd.cd_name) != 0)
+ return (0);
+
+ /*
+ * 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.
+ */
+ return (1);
+}
+
+/*
+ * 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.
+ */
+void
+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");
+
+ sc->sc_iot = aa->aa_iot;
+ sc->sc_memt = aa->aa_memt;
+ sc->sc_pc = aa->aa_pc;
+ sc->sc_pciflags = aa->aa_pciflags;
+
+ acpi_softc = sc;
+
+ /*
+ * Install the default address space handlers.
+ */
+
+ rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
+ ACPI_ADR_SPACE_SYSTEM_MEMORY, ACPI_DEFAULT_HANDLER, NULL, NULL);
+ if (rv != AE_OK) {
+ printf("%s: unable to install SYSTEM MEMORY handler: %d\n",
+ sc->sc_dev.dv_xname, rv);
+ return;
+ }
+
+ rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
+ ACPI_ADR_SPACE_SYSTEM_IO, ACPI_DEFAULT_HANDLER, NULL, NULL);
+ if (rv != AE_OK) {
+ printf("%s: unable to install SYSTEM IO handler: %d\n",
+ sc->sc_dev.dv_xname, rv);
+ return;
+ }
+
+ rv = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
+ ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
+ if (rv != AE_OK) {
+ printf("%s: unable to install PCI CONFIG handler: %d\n",
+ sc->sc_dev.dv_xname, rv);
+ return;
+ }
+
+ /*
+ * Bring ACPI on-line.
+ *
+ * Note that we request that _STA (device init) and _INI (object init)
+ * methods not be run.
+ *
+ * XXX We need to arrange for the object init pass after we have
+ * XXX attached all of our children.
+ */
+#ifdef ENABLE_DEBUGGER
+ if (acpi_dbgr & ACPI_DBGR_ENABLE)
+ acpi_osd_debugger();
+#endif
+ rv = AcpiEnableSubsystem(ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT);
+ if (rv != AE_OK) {
+ printf("%s: unable to enable ACPI: %d\n",
+ sc->sc_dev.dv_xname, rv);
+ return;
+ }
+ acpi_active = 1;
+
+ /*
+ * Set up the default sleep state to enter when various
+ * switches are activated.
+ */
+ sc->sc_switch_sleep[ACPI_SWITCH_POWERBUTTON] = ACPI_STATE_S5;
+ sc->sc_switch_sleep[ACPI_SWITCH_SLEEPBUTTON] = ACPI_STATE_S1;
+ sc->sc_switch_sleep[ACPI_SWITCH_LID] = ACPI_STATE_S1;
+
+ /* Our current state is "awake". */
+ sc->sc_sleepstate = ACPI_STATE_S0;
+
+ /*
+ * We want to install a single system notify handler.
+ */
+ rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
+ acpi_system_notify_handler, sc);
+ if (rv != AE_OK)
+ printf("%s: WARNING: unable to install system notify "
+ "handler: %d\n", sc->sc_dev.dv_xname, rv);
+
+ /*
+ * Check for fixed-hardware features.
+ */
+ acpi_enable_fixed_events(sc);
+
+ /*
+ * Scan the namespace and build our device tree.
+ */
+#ifdef ENABLE_DEBUGGER
+ if (acpi_dbgr & ACPI_DBGR_PROBE)
+ acpi_osd_debugger();
+#endif
+ 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);
+
+#ifdef ENABLE_DEBUGGER
+ if (acpi_dbgr & ACPI_DBGR_RUNNING)
+ acpi_osd_debugger();
+#endif
+}
+
+/*
+ * acpi_shutdown:
Home |
Main Index |
Thread Index |
Old Index