Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Add utility function acpi_get_node().



details:   https://anonhg.NetBSD.org/src/rev/7dbe1b3f9e38
branches:  trunk
changeset: 754232:7dbe1b3f9e38
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sat Apr 24 06:57:10 2010 +0000

description:
Add utility function acpi_get_node().

This retrieves a struct acpi_devnode from a handle. Since this requires
accessing the global softc, it is better to do it in one place alone. The
same goes for possible locking of the node-queue; it is better not to
publicize such a lock for generic device drivers.

diffstat:

 sys/dev/acpi/acpi_power.c |  34 ++++++++--------------------------
 sys/dev/acpi/acpi_util.c  |  28 ++++++++++++++++++++++++++--
 sys/dev/acpi/acpi_util.h  |   3 ++-
 3 files changed, 36 insertions(+), 29 deletions(-)

diffs (134 lines):

diff -r bc52526baace -r 7dbe1b3f9e38 sys/dev/acpi/acpi_power.c
--- a/sys/dev/acpi/acpi_power.c Sat Apr 24 06:31:44 2010 +0000
+++ b/sys/dev/acpi/acpi_power.c Sat Apr 24 06:57:10 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_power.c,v 1.6 2010/04/24 06:31:44 jruoho Exp $ */
+/* $NetBSD: acpi_power.c,v 1.7 2010/04/24 06:57:10 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.6 2010/04/24 06:31:44 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.7 2010/04/24 06:57:10 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -243,20 +243,12 @@
 void
 acpi_power_deregister_from_handle(ACPI_HANDLE hdl)
 {
-       struct acpi_softc *sc = acpi_softc; /* XXX. */
-       struct acpi_devnode *ad;
+       struct acpi_devnode *ad = acpi_get_node(hdl);
 
-       if (sc == NULL)
+       if (ad == NULL)
                return;
 
-       SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
-
-               if (ad->ad_handle == hdl)
-                       return acpi_power_deregister(ad);
-       }
-
-       aprint_error_dev(sc->sc_dev, "%s: failed to "
-           "find node %s\n", __func__, acpi_xname(hdl));
+       acpi_power_deregister(ad);
 }
 
 /*
@@ -460,22 +452,12 @@
 bool
 acpi_power_set_from_handle(ACPI_HANDLE hdl, int state)
 {
-       struct acpi_softc *sc = acpi_softc; /* XXX. */
-       struct acpi_devnode *ad;
+       struct acpi_devnode *ad = acpi_get_node(hdl);
 
-       if (sc == NULL)
+       if (ad == NULL)
                return false;
 
-       SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
-
-               if (ad->ad_handle == hdl)
-                       return acpi_power_set(ad, state);
-       }
-
-       aprint_error_dev(sc->sc_dev, "%s: failed to "
-           "find node %s\n", __func__, acpi_xname(hdl));
-
-       return false;
+       return acpi_power_set(ad, state);
 }
 
 static ACPI_STATUS
diff -r bc52526baace -r 7dbe1b3f9e38 sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c  Sat Apr 24 06:31:44 2010 +0000
+++ b/sys/dev/acpi/acpi_util.c  Sat Apr 24 06:57:10 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.c,v 1.2 2010/04/15 04:03:39 jruoho Exp $ */
+/*     $NetBSD: acpi_util.c,v 1.3 2010/04/24 06:57:10 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.2 2010/04/15 04:03:39 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.3 2010/04/24 06:57:10 jruoho Exp $");
 
 #include <sys/param.h>
 
@@ -258,6 +258,30 @@
 }
 
 /*
+ * Get a device node from a handle.
+ */
+struct acpi_devnode *
+acpi_get_node(ACPI_HANDLE handle)
+{
+       struct acpi_softc *sc = acpi_softc; /* XXX. */
+       struct acpi_devnode *ad;
+
+       if (sc == NULL || handle == NULL)
+               return NULL;
+
+       SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
+
+               if (ad->ad_handle == handle)
+                       return ad;
+       }
+
+       aprint_debug_dev(sc->sc_dev, "%s: failed to "
+           "find node %s\n", __func__, acpi_name(handle));
+
+       return NULL;
+}
+
+/*
  * Return a complete pathname from a handle.
  *
  * Note that the function uses static data storage;
diff -r bc52526baace -r 7dbe1b3f9e38 sys/dev/acpi/acpi_util.h
--- a/sys/dev/acpi/acpi_util.h  Sat Apr 24 06:31:44 2010 +0000
+++ b/sys/dev/acpi/acpi_util.h  Sat Apr 24 06:57:10 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.h,v 1.1 2010/04/14 17:12:14 jruoho Exp $ */
+/*     $NetBSD: acpi_util.h,v 1.2 2010/04/24 06:57:10 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -78,6 +78,7 @@
                        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);
 
 const char*    acpi_name(ACPI_HANDLE);
 



Home | Main Index | Thread Index | Old Index