Module Name:    src
Committed By:   thorpej
Date:           Fri Feb  5 17:12:43 UTC 2021

Modified Files:
        src/sys/dev/acpi: acpi_util.c acpi_util.h

Log Message:
ACPI device handle implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/acpi/acpi_util.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.23 src/sys/dev/acpi/acpi_util.c:1.24
--- src/sys/dev/acpi/acpi_util.c:1.23	Wed Jan 27 05:11:54 2021
+++ src/sys/dev/acpi/acpi_util.c	Fri Feb  5 17:12:43 2021
@@ -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

Index: src/sys/dev/acpi/acpi_util.h
diff -u src/sys/dev/acpi/acpi_util.h:1.10 src/sys/dev/acpi/acpi_util.h:1.11
--- src/sys/dev/acpi/acpi_util.h:1.10	Tue Jan 26 00:19:53 2021
+++ src/sys/dev/acpi/acpi_util.h	Fri Feb  5 17:12:43 2021
@@ -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);

Reply via email to