summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2021-02-05 17:12:43 +0000
committerthorpej <thorpej@NetBSD.org>2021-02-05 17:12:43 +0000
commit37aee2b1ad601f86a16700f1055fa3679d4ddfdc (patch)
tree42836937cdd600e44f5e0fcb94a16497ce279b60 /sys/dev
parentc213e0343e70be313bd6f99fbc9ba13ce89542e9 (diff)
ACPI device handle implementation.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/acpi/acpi_util.c73
-rw-r--r--sys/dev/acpi/acpi_util.h8
2 files changed, 78 insertions, 3 deletions
diff --git a/sys/dev/acpi/acpi_util.c b/sys/dev/acpi/acpi_util.c
index eecee328938..88139b2b0e6 100644
--- a/sys/dev/acpi/acpi_util.c
+++ b/sys/dev/acpi/acpi_util.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $ */
+/* $NetBSD: acpi_util.c,v 1.24 2021/02/05 17:12:43 thorpej Exp $ */
/*-
* Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.24 2021/02/05 17:12:43 thorpej Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -88,6 +88,75 @@ static const char * const acpicpu_ids[] = {
};
/*
+ * ACPI device handle support.
+ */
+
+static device_call_t
+acpi_devhandle_lookup_device_call(devhandle_t handle, const char *name,
+ devhandle_t *call_handlep)
+{
+ __link_set_decl(acpi_device_calls, struct device_call_descriptor);
+ struct device_call_descriptor * const *desc;
+
+ __link_set_foreach(desc, acpi_device_calls) {
+ if (strcmp((*desc)->name, name) == 0) {
+ return (*desc)->call;
+ }
+ }
+ return NULL;
+}
+
+static const struct devhandle_impl acpi_devhandle_impl = {
+ .type = DEVHANDLE_TYPE_ACPI,
+ .lookup_device_call = acpi_devhandle_lookup_device_call,
+};
+
+devhandle_t
+devhandle_from_acpi(ACPI_HANDLE const hdl)
+{
+ devhandle_t handle = {
+ .impl = &acpi_devhandle_impl,
+ .pointer = hdl,
+ };
+
+ return handle;
+}
+
+ACPI_HANDLE
+devhandle_to_acpi(devhandle_t const handle)
+{
+ KASSERT(devhandle_type(handle) == DEVHANDLE_TYPE_ACPI);
+
+ return handle.pointer;
+}
+
+static int
+acpi_device_enumerate_children(device_t dev, devhandle_t call_handle, void *v)
+{
+ struct device_enumerate_children_args *args = v;
+ ACPI_HANDLE hdl = devhandle_to_acpi(call_handle);
+ struct acpi_devnode *devnode, *ad;
+
+ devnode = acpi_match_node(hdl);
+ KASSERT(devnode != NULL);
+
+ SIMPLEQ_FOREACH(ad, &devnode->ad_child_head, ad_child_list) {
+ if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE ||
+ !acpi_device_present(ad->ad_handle)) {
+ continue;
+ }
+ if (!args->callback(dev, devhandle_from_acpi(ad->ad_handle),
+ args->callback_arg)) {
+ break;
+ }
+ }
+
+ return 0;
+}
+ACPI_DEVICE_CALL_REGISTER("device-enumerate-children",
+ acpi_device_enumerate_children)
+
+/*
* Evaluate an integer object.
*/
ACPI_STATUS
diff --git a/sys/dev/acpi/acpi_util.h b/sys/dev/acpi/acpi_util.h
index 652e912674d..f8b93c6a130 100644
--- a/sys/dev/acpi/acpi_util.h
+++ b/sys/dev/acpi/acpi_util.h
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_util.h,v 1.10 2021/01/26 00:19:53 jmcneill Exp $ */
+/* $NetBSD: acpi_util.h,v 1.11 2021/02/05 17:12:43 thorpej Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -67,6 +67,12 @@
#ifndef _SYS_DEV_ACPI_ACPI_UTIL_H
#define _SYS_DEV_ACPI_ACPI_UTIL_H
+devhandle_t devhandle_from_acpi(ACPI_HANDLE);
+ACPI_HANDLE devhandle_to_acpi(devhandle_t);
+
+#define ACPI_DEVICE_CALL_REGISTER(_n_, _c_) \
+ DEVICE_CALL_REGISTER(acpi_device_calls, _n_, _c_)
+
ACPI_STATUS acpi_eval_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
ACPI_STATUS acpi_eval_set_integer(ACPI_HANDLE handle, const char *path,
ACPI_INTEGER arg);