Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Use the new ACPICA functions AcpiAttachData() a...



details:   https://anonhg.NetBSD.org/src/rev/74ac266709fa
branches:  trunk
changeset: 755496:74ac266709fa
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon Jun 07 17:13:52 2010 +0000

description:
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.

diffstat:

 sys/dev/acpi/acpi.c      |  26 +++++++++++++++++---------
 sys/dev/acpi/acpi_util.c |  36 +++++++++++++++++++++++++-----------
 sys/dev/acpi/acpi_util.h |   4 +++-
 3 files changed, 45 insertions(+), 21 deletions(-)

diffs (173 lines):

diff -r 90af6fa76e1c -r 74ac266709fa sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Mon Jun 07 16:37:07 2010 +0000
+++ b/sys/dev/acpi/acpi.c       Mon Jun 07 17:13:52 2010 +0000
@@ -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,
diff -r 90af6fa76e1c -r 74ac266709fa sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c  Mon Jun 07 16:37:07 2010 +0000
+++ b/sys/dev/acpi/acpi_util.c  Mon Jun 07 17:13:52 2010 +0000
@@ -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;
+
+       rv = AcpiGetData(handle, acpi_clean_node, (void **)&ad);
+
+       if (ACPI_FAILURE(rv))
                return NULL;
 
-       SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
+       return ad;
+}
 
-               if (ad->ad_handle == handle)
-                       return ad;
-       }
+/*
+ * Associate a device node with a handle.
+ */
+void
+acpi_set_node(struct acpi_devnode *ad)
+{
 
-       aprint_debug_dev(sc->sc_dev, "%s: failed to "
-           "find node %s\n", __func__, acpi_name(handle));
+       (void)AcpiAttachData(ad->ad_handle, acpi_clean_node, ad);
+}
 
-       return NULL;
+static void
+acpi_clean_node(ACPI_HANDLE handle, void *aux)
+{
+       /* Nothing. */
 }
 
 /*
diff -r 90af6fa76e1c -r 74ac266709fa sys/dev/acpi/acpi_util.h
--- a/sys/dev/acpi/acpi_util.h  Mon Jun 07 16:37:07 2010 +0000
+++ b/sys/dev/acpi/acpi_util.h  Mon Jun 07 17:13:52 2010 +0000
@@ -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);
 



Home | Main Index | Thread Index | Old Index