Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi Introduce acpiwmibus, a pseudo-bus to which the...
details: https://anonhg.NetBSD.org/src/rev/643eec04fbc4
branches: trunk
changeset: 750507:643eec04fbc4
user: jruoho <jruoho%NetBSD.org@localhost>
date: Sun Jan 03 17:53:15 2010 +0000
description:
Introduce acpiwmibus, a pseudo-bus to which the child WMI devices attach.
Multiple WMI mapper devices are supported, but each one can have only one
child device.
All exposed functions now require the parent mapper device as a parameter.
ok pgoyette@, jmcneill@
diffstat:
sys/dev/acpi/files.acpi | 5 +-
sys/dev/acpi/wmi_acpi.c | 227 +++++++++++++++++++++++++-------------------
sys/dev/acpi/wmi_acpivar.h | 16 +-
3 files changed, 140 insertions(+), 108 deletions(-)
diffs (truncated from 655 to 300 lines):
diff -r 1570a183d874 -r 643eec04fbc4 sys/dev/acpi/files.acpi
--- a/sys/dev/acpi/files.acpi Sun Jan 03 17:08:45 2010 +0000
+++ b/sys/dev/acpi/files.acpi Sun Jan 03 17:53:15 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.acpi,v 1.63 2009/12/03 21:04:29 cegger Exp $
+# $NetBSD: files.acpi,v 1.64 2010/01/03 17:53:15 jruoho Exp $
include "dev/acpi/acpica/files.acpica"
@@ -9,6 +9,7 @@
define acpiapmbus { }
define acpinodebus { }
define acpiecdtbus { }
+define acpiwmibus { }
device acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, sysmon_power, sysmon_taskq
attach acpi at acpibus
@@ -150,6 +151,6 @@
file dev/acpi/wb_acpi.c wb_acpi
# ACPI-WMI Mapper
-device acpiwmi
+device acpiwmi: acpiwmibus
attach acpiwmi at acpinodebus
file dev/acpi/wmi_acpi.c acpiwmi
diff -r 1570a183d874 -r 643eec04fbc4 sys/dev/acpi/wmi_acpi.c
--- a/sys/dev/acpi/wmi_acpi.c Sun Jan 03 17:08:45 2010 +0000
+++ b/sys/dev/acpi/wmi_acpi.c Sun Jan 03 17:53:15 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wmi_acpi.c,v 1.3 2009/11/29 21:32:50 cegger Exp $ */
+/* $NetBSD: wmi_acpi.c,v 1.4 2010/01/03 17:53:15 jruoho Exp $ */
/*-
* Copyright (c) 2009 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.3 2009/11/29 21:32:50 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.4 2010/01/03 17:53:15 jruoho Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -36,6 +36,7 @@
#include <dev/acpi/acpivar.h>
#include <dev/acpi/wmi_acpivar.h>
+
/*
* This implements something called "Microsoft Windows Management
* Instrumentation" (WMI). This subset of ACPI is desribed in:
@@ -45,6 +46,7 @@
* (Obtained on Thu Feb 12 18:21:44 EET 2009.)
*/
struct guid_t {
+
/*
* The GUID itself. The used format is the usual 32-16-16-64-bit
* representation. All except the fourth field are in native byte
@@ -73,22 +75,21 @@
} __packed;
struct wmi_t {
- struct guid_t guid;
- ACPI_HANDLE handle;
- bool eevent;
+ struct guid_t guid;
+ bool eevent;
- SIMPLEQ_ENTRY(wmi_t) wmi_link;
+ SIMPLEQ_ENTRY(wmi_t) wmi_link;
};
struct acpi_wmi_softc {
device_t sc_dev;
+ device_t sc_child;
+ ACPI_NOTIFY_HANDLER sc_handler;
struct acpi_devnode *sc_node;
- struct wmi_t *sc_wmi;
+
+ SIMPLEQ_HEAD(, wmi_t) wmi_head;
};
-static SIMPLEQ_HEAD(, wmi_t) wmi_head =
- SIMPLEQ_HEAD_INITIALIZER(wmi_head);
-
#define ACPI_WMI_FLAG_EXPENSIVE 0x01
#define ACPI_WMI_FLAG_METHOD 0x02
#define ACPI_WMI_FLAG_STRING 0x04
@@ -111,15 +112,17 @@
static int acpi_wmi_match(device_t, cfdata_t, void *);
static void acpi_wmi_attach(device_t, device_t, void *);
-static bool acpi_wmi_init(ACPI_HANDLE, const char * const);
-static bool acpi_wmi_add(ACPI_OBJECT *, ACPI_HANDLE);
-static void acpi_wmi_del(void);
+static int acpi_wmi_print(void *, const char *);
+static bool acpi_wmi_init(struct acpi_wmi_softc *);
+static bool acpi_wmi_add(struct acpi_wmi_softc *, ACPI_OBJECT *);
+static void acpi_wmi_del(struct acpi_wmi_softc *);
#ifdef ACPIVERBOSE
-static void acpi_wmi_dump(const char * const);
+static void acpi_wmi_dump(struct acpi_wmi_softc *);
#endif
-static ACPI_STATUS acpi_wmi_guid_get(const u_char * const, struct wmi_t **);
+static ACPI_STATUS acpi_wmi_guid_get(struct acpi_wmi_softc *,
+ const u_char * const, struct wmi_t **);
static void acpi_wmi_event_add(struct acpi_wmi_softc *);
static void acpi_wmi_event_del(struct acpi_wmi_softc *);
static void acpi_wmi_event_handler(ACPI_HANDLE, uint32_t, void *);
@@ -128,8 +131,6 @@
static ACPI_STATUS acpi_wmi_enable(const ACPI_HANDLE, const char * const,
const bool, const bool);
-static ACPI_NOTIFY_HANDLER wmi_handler;
-
const char * const acpi_wmi_ids[] = {
"PNP0C14",
NULL
@@ -154,44 +155,51 @@
{
struct acpi_wmi_softc *sc = device_private(self);
struct acpi_attach_args *aa = aux;
- const char *xname;
sc->sc_dev = self;
sc->sc_node = aa->aa_node;
+ sc->sc_handler = NULL;
aprint_naive("\n");
aprint_normal(": ACPI WMI Interface\n");
- wmi_handler = NULL;
- xname = device_xname(sc->sc_dev);
-
- if (acpi_wmi_init(sc->sc_node->ad_handle, xname) != true)
+ if (acpi_wmi_init(sc) != true)
return;
#ifdef ACPIVERBOSE
- acpi_wmi_dump(xname);
+ acpi_wmi_dump(sc);
#endif
- /*
- * Add internal event handler. If the user-driver
- * registers an external event handler with us, we
- * will forward events through this.
- */
+
acpi_wmi_event_add(sc);
if (pmf_device_register(sc->sc_dev,
acpi_wmi_suspend, acpi_wmi_resume) != true)
aprint_error_dev(self, "failed to register power handler\n");
+
+ /* Attach a child device to the pseudo-bus. */
+ sc->sc_child = config_found_ia(self, "acpiwmibus",
+ NULL, acpi_wmi_print);
+}
+
+static int
+acpi_wmi_print(void *aux, const char *pnp)
+{
+
+ if (pnp != NULL)
+ aprint_normal("acpiwmibus at %s", pnp);
+
+ return UNCONF;
}
static bool
-acpi_wmi_init(ACPI_HANDLE hdl, const char * const xname)
+acpi_wmi_init(struct acpi_wmi_softc *sc)
{
ACPI_OBJECT *obj;
ACPI_BUFFER buf;
ACPI_STATUS rv;
uint32_t len;
- rv = acpi_eval_struct(hdl, "_WDG", &buf);
+ rv = acpi_eval_struct(sc->sc_node->ad_handle, "_WDG", &buf);
if (ACPI_FAILURE(rv))
goto fail;
@@ -214,11 +222,11 @@
goto fail;
}
- return acpi_wmi_add(obj, hdl);
+ return acpi_wmi_add(sc, obj);
fail:
- aprint_error("%s: failed to evaluate _WDG: %s\n",
- xname, AcpiFormatException(rv));
+ aprint_error_dev(sc->sc_dev, "failed to evaluate _WDG: %s\n",
+ AcpiFormatException(rv));
if (buf.Pointer != NULL)
AcpiOsFree(buf.Pointer);
@@ -227,7 +235,7 @@
}
static bool
-acpi_wmi_add(ACPI_OBJECT *obj, ACPI_HANDLE hdl)
+acpi_wmi_add(struct acpi_wmi_softc *sc, ACPI_OBJECT *obj)
{
struct wmi_t *wmi;
size_t i, n, offset, siz;
@@ -235,6 +243,8 @@
siz = sizeof(struct guid_t);
n = obj->Buffer.Length / siz;
+ SIMPLEQ_INIT(&sc->wmi_head);
+
for (i = offset = 0; i < n; ++i) {
if ((wmi = kmem_zalloc(sizeof(*wmi), KM_NOSLEEP)) == NULL)
@@ -242,12 +252,10 @@
ACPI_MEMCPY(&wmi->guid, obj->Buffer.Pointer + offset, siz);
- wmi->handle = hdl;
wmi->eevent = false;
-
offset = offset + siz;
- SIMPLEQ_INSERT_TAIL(&wmi_head, wmi, wmi_link);
+ SIMPLEQ_INSERT_TAIL(&sc->wmi_head, wmi, wmi_link);
}
AcpiOsFree(obj);
@@ -256,23 +264,23 @@
fail:
AcpiOsFree(obj);
- acpi_wmi_del();
+ acpi_wmi_del(sc);
return false;
}
static void
-acpi_wmi_del(void)
+acpi_wmi_del(struct acpi_wmi_softc *sc)
{
struct wmi_t *wmi;
- if (SIMPLEQ_EMPTY(&wmi_head))
+ if (SIMPLEQ_EMPTY(&sc->wmi_head))
return;
- while (SIMPLEQ_FIRST(&wmi_head) != NULL) {
+ while (SIMPLEQ_FIRST(&sc->wmi_head) != NULL) {
- wmi = SIMPLEQ_FIRST(&wmi_head);
- SIMPLEQ_REMOVE_HEAD(&wmi_head, wmi_link);
+ wmi = SIMPLEQ_FIRST(&sc->wmi_head);
+ SIMPLEQ_REMOVE_HEAD(&sc->wmi_head, wmi_link);
KASSERT(wmi != NULL);
@@ -282,15 +290,15 @@
#ifdef ACPIVERBOSE
static void
-acpi_wmi_dump(const char * const xname)
+acpi_wmi_dump(struct acpi_wmi_softc *sc)
{
struct wmi_t *wmi;
- KASSERT(!(SIMPLEQ_EMPTY(&wmi_head)));
+ KASSERT(!(SIMPLEQ_EMPTY(&sc->wmi_head)));
- SIMPLEQ_FOREACH(wmi, &wmi_head, wmi_link) {
+ SIMPLEQ_FOREACH(wmi, &sc->wmi_head, wmi_link) {
- aprint_normal("%s: {%08X-%04X-%04X-", xname,
+ aprint_normal_dev(sc->sc_dev, "{%08X-%04X-%04X-",
wmi->guid.data1, wmi->guid.data2, wmi->guid.data3);
aprint_normal("%02X%02X-%02X%02X%02X%02X%02X%02X} ",
@@ -306,7 +314,8 @@
#endif
static ACPI_STATUS
-acpi_wmi_guid_get(const u_char * const src, struct wmi_t **out)
+acpi_wmi_guid_get(struct acpi_wmi_softc *sc,
+ const u_char * const src, struct wmi_t **out)
{
struct wmi_t *wmi;
struct guid_t *guid;
@@ -315,7 +324,7 @@
const char *ptr;
uint8_t i;
- if (ACPI_STRLEN(src) != 36)
+ if (sc == NULL || src == NULL || ACPI_STRLEN(src) != 36)
return AE_BAD_PARAMETER;
Home |
Main Index |
Thread Index |
Old Index