Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi ACPI device handle implementation.
details: https://anonhg.NetBSD.org/src/rev/cd0dc144d960
branches: trunk
changeset: 951531:cd0dc144d960
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Feb 05 17:12:43 2021 +0000
description:
ACPI device handle implementation.
diffstat:
sys/dev/acpi/acpi_util.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-
sys/dev/acpi/acpi_util.h | 8 ++++-
2 files changed, 78 insertions(+), 3 deletions(-)
diffs (116 lines):
diff -r c63283819474 -r cd0dc144d960 sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c Fri Feb 05 17:03:35 2021 +0000
+++ b/sys/dev/acpi/acpi_util.c Fri Feb 05 17:12:43 2021 +0000
@@ -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 @@
};
/*
+ * 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 -r c63283819474 -r cd0dc144d960 sys/dev/acpi/acpi_util.h
--- a/sys/dev/acpi/acpi_util.h Fri Feb 05 17:03:35 2021 +0000
+++ b/sys/dev/acpi/acpi_util.h Fri Feb 05 17:12:43 2021 +0000
@@ -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);
Home |
Main Index |
Thread Index |
Old Index