Module Name:    src
Committed By:   jruoho
Date:           Mon Jun  7 17:13:52 UTC 2010

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

Log Message:
Use the new ACPICA functions AcpiAttachData() and AcpiGetData() to associate
all "struct acpi_devnodes" to their corresponding ACPI_HANDLEs. Anywhere in
the acpi(4) subtree, the node-structure can be obtained from a handle via
acpi_get_node(). The idea is similar to e.g. device_private().

Benefits: (a) simplifies code, (b) avoids issues with locking as ACPICA does
the serialization for us, (c) avoids the need to access the glocal softc, and
(d) avoids the O(n) loop required to search for a handle from the node queue.


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.2 -r1.3 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.c
diff -u src/sys/dev/acpi/acpi.c:1.201 src/sys/dev/acpi/acpi.c:1.202
--- src/sys/dev/acpi/acpi.c:1.201	Mon Jun  7 13:04:31 2010
+++ src/sys/dev/acpi/acpi.c	Mon Jun  7 17:13:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.201 2010/06/07 13:04:31 jruoho Exp $	*/
+/*	$NetBSD: acpi.c,v 1.202 2010/06/07 17:13:52 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.201 2010/06/07 13:04:31 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.202 2010/06/07 17:13:52 jruoho Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -217,11 +217,13 @@
 
 int acpi_verbose_loaded = 0;
 
-/* acpiverbose support */
+/*
+ * Support for ACPIVERBOSE.
+ */
 void
 acpi_null(void)
 {
-	/* Nothing to do */
+	/* Nothing to do. */
 }
 
 void
@@ -234,30 +236,34 @@
 	if (module_autoload("acpiverbose", MODULE_CLASS_MISC) == 0)
 		acpi_verbose_loaded++;
 	mutex_exit(&module_lock);
-}  
+}
 
-void acpi_print_devnodes_stub(struct acpi_softc *sc)
+void
+acpi_print_devnodes_stub(struct acpi_softc *sc)
 {
 	acpi_load_verbose();
 	if (acpi_verbose_loaded)
 		acpi_print_devnodes(sc);
 }
 
-void acpi_print_tree_stub(struct acpi_devnode *ad, uint32_t level)
+void
+acpi_print_tree_stub(struct acpi_devnode *ad, uint32_t level)
 {
 	acpi_load_verbose();
 	if (acpi_verbose_loaded)
 		acpi_print_tree(ad, level);
 }
 
-void acpi_print_dev_stub(const char *pnpstr)
+void
+acpi_print_dev_stub(const char *pnpstr)
 {
 	acpi_load_verbose();
 	if (acpi_verbose_loaded)
 		acpi_print_dev(pnpstr);
 }
 
-void acpi_wmidump_stub(void *arg)
+void
+acpi_wmidump_stub(void *arg)
 {
 	acpi_load_verbose();
 	if (acpi_verbose_loaded)
@@ -748,6 +754,8 @@
 		SIMPLEQ_INIT(&ad->ad_child_head);
 		SIMPLEQ_INSERT_TAIL(&sc->ad_head, ad, ad_list);
 
+		acpi_set_node(ad);
+
 		if (ad->ad_parent != NULL) {
 
 			SIMPLEQ_INSERT_TAIL(&ad->ad_parent->ad_child_head,

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.4 src/sys/dev/acpi/acpi_util.c:1.5
--- src/sys/dev/acpi/acpi_util.c:1.4	Tue Apr 27 08:15:07 2010
+++ src/sys/dev/acpi/acpi_util.c	Mon Jun  7 17:13:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.4 2010/04/27 08:15:07 jruoho Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.5 2010/06/07 17:13:52 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.4 2010/04/27 08:15:07 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.5 2010/06/07 17:13:52 jruoho Exp $");
 
 #include <sys/param.h>
 
@@ -75,6 +75,8 @@
 #define _COMPONENT		ACPI_BUS_COMPONENT
 ACPI_MODULE_NAME		("acpi_util")
 
+static void	acpi_clean_node(ACPI_HANDLE, void *);
+
 /*
  * Evaluate an integer object.
  */
@@ -266,22 +268,34 @@
 struct acpi_devnode *
 acpi_get_node(ACPI_HANDLE handle)
 {
-	struct acpi_softc *sc = acpi_softc; /* XXX. */
 	struct acpi_devnode *ad;
+	ACPI_STATUS rv;
 
-	if (sc == NULL || handle == NULL)
+	if (handle == NULL)
 		return NULL;
 
-	SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
+	rv = AcpiGetData(handle, acpi_clean_node, (void **)&ad);
 
-		if (ad->ad_handle == handle)
-			return ad;
-	}
+	if (ACPI_FAILURE(rv))
+		return NULL;
+
+	return ad;
+}
 
-	aprint_debug_dev(sc->sc_dev, "%s: failed to "
-	    "find node %s\n", __func__, acpi_name(handle));
+/*
+ * Associate a device node with a handle.
+ */
+void
+acpi_set_node(struct acpi_devnode *ad)
+{
 
-	return NULL;
+	(void)AcpiAttachData(ad->ad_handle, acpi_clean_node, ad);
+}
+
+static void
+acpi_clean_node(ACPI_HANDLE handle, void *aux)
+{
+	/* Nothing. */
 }
 
 /*

Index: src/sys/dev/acpi/acpi_util.h
diff -u src/sys/dev/acpi/acpi_util.h:1.2 src/sys/dev/acpi/acpi_util.h:1.3
--- src/sys/dev/acpi/acpi_util.h:1.2	Sat Apr 24 06:57:10 2010
+++ src/sys/dev/acpi/acpi_util.h	Mon Jun  7 17:13:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.h,v 1.2 2010/04/24 06:57:10 jruoho Exp $ */
+/*	$NetBSD: acpi_util.h,v 1.3 2010/06/07 17:13:52 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -78,7 +78,9 @@
 			ACPI_STATUS (*)(ACPI_OBJECT *, void *), void *);
 ACPI_STATUS	acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
 			ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
+
 struct acpi_devnode *acpi_get_node(ACPI_HANDLE handle);
+void		     acpi_set_node(struct acpi_devnode *ad);
 
 const char*	acpi_name(ACPI_HANDLE);
 

Reply via email to