Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Refactor slightly: we need to expose the functi...



details:   https://anonhg.NetBSD.org/src/rev/2ef9b756f4dd
branches:  trunk
changeset: 755491:2ef9b756f4dd
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon Jun 07 14:07:25 2010 +0000

description:
Refactor slightly: we need to expose the function that turns individual
power resource on or off.

diffstat:

 sys/dev/acpi/acpi_power.c |  99 +++++++++++++++++++++-------------------------
 sys/dev/acpi/acpi_power.h |  17 ++++---
 2 files changed, 54 insertions(+), 62 deletions(-)

diffs (189 lines):

diff -r ac9c9d41e742 -r 2ef9b756f4dd sys/dev/acpi/acpi_power.c
--- a/sys/dev/acpi/acpi_power.c Mon Jun 07 13:57:20 2010 +0000
+++ b/sys/dev/acpi/acpi_power.c Mon Jun 07 14:07:25 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_power.c,v 1.15 2010/06/07 13:04:31 jruoho Exp $ */
+/* $NetBSD: acpi_power.c,v 1.16 2010/06/07 14:07:25 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.15 2010/06/07 13:04:31 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.16 2010/06/07 14:07:25 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -108,8 +108,6 @@
 static ACPI_STATUS      acpi_power_get_indirect(struct acpi_devnode *);
 static ACPI_STATUS      acpi_power_switch(struct acpi_devnode *,
                                                   int, bool);
-static ACPI_STATUS      acpi_power_res_on(ACPI_OBJECT *, void *);
-static ACPI_STATUS      acpi_power_res_off(ACPI_OBJECT *, void *);
 static ACPI_STATUS      acpi_power_res_ref(struct acpi_power_res *,
                                            ACPI_HANDLE);
 static ACPI_STATUS      acpi_power_res_deref(struct acpi_power_res *,
@@ -454,88 +452,81 @@
 static ACPI_STATUS
 acpi_power_switch(struct acpi_devnode *ad, int state, bool on)
 {
-       ACPI_OBJECT *pkg;
-       ACPI_STATUS rv;
+       ACPI_OBJECT *elm, *pkg;
+       ACPI_STATUS rv = AE_OK;
+       ACPI_HANDLE hdl;
+       uint32_t i, n;
 
+       /*
+        * For each element in the _PRx package, fetch
+        * the reference handle, search for this handle
+        * from the power resource queue, and turn the
+        * resource behind the handle on or off.
+        */
        pkg = acpi_power_pkg_get(ad->ad_handle, state);
 
        if (pkg == NULL)
                return AE_CTRL_CONTINUE;
 
-       if (on != false)
-               rv = acpi_foreach_package_object(pkg, acpi_power_res_on, ad);
-       else
-               rv = acpi_foreach_package_object(pkg, acpi_power_res_off, ad);
+       n = pkg->Package.Count;
+
+       for (i = 0; i < n; i++) {
 
-       if (rv == AE_CTRL_CONTINUE)
-               rv = AE_ERROR;
+               elm = &pkg->Package.Elements[i];
+               rv = acpi_eval_reference_handle(elm, &hdl);
+
+               if (ACPI_FAILURE(rv))
+                       continue;
+
+               (void)acpi_power_res(hdl, ad->ad_handle, on);
+       }
 
        ACPI_FREE(pkg);
 
        return rv;
 }
 
-static ACPI_STATUS
-acpi_power_res_on(ACPI_OBJECT *elm, void *arg)
+ACPI_STATUS
+acpi_power_res(ACPI_HANDLE hdl, ACPI_HANDLE ref, bool on)
 {
-       struct acpi_devnode *ad = arg;
        struct acpi_power_res *res;
-       ACPI_HANDLE hdl;
+       const char *str;
        ACPI_STATUS rv;
 
        /*
-        * For each element in the _PRx package, first
-        * fetch the reference handle and then search
-        * for this handle from the power resource list.
+        * Search for the resource.
         */
-       rv = acpi_eval_reference_handle(elm, &hdl);
-
-       if (ACPI_FAILURE(rv))
-               return rv;
-
        res = acpi_power_res_get(hdl);
 
        if (res == NULL)
                return AE_NOT_FOUND;
 
        /*
-        * Reference the resource.
+        * (De)reference the resource.
         */
-       rv = acpi_power_res_ref(res, ad->ad_handle);
+       switch (on) {
+
+       case true:
+               rv = acpi_power_res_ref(res, ref);
+               str = "_ON";
+               break;
+
+       case false:
+               rv = acpi_power_res_deref(res, ref);
+               str = "_OFF";
+               break;
+
+       default:
+               return AE_BAD_PARAMETER;
+       }
 
        if (ACPI_FAILURE(rv))
                return rv;
 
        /*
-        * Turn the resource on.
+        * Turn the resource on or off.
         */
-       return AcpiEvaluateObject(res->res_handle, "_ON", NULL, NULL);
-}
-
-static ACPI_STATUS
-acpi_power_res_off(ACPI_OBJECT *elm, void *arg)
-{
-       struct acpi_devnode *ad = arg;
-       struct acpi_power_res *res;
-       ACPI_HANDLE hdl;
-       ACPI_STATUS rv;
-
-       rv = acpi_eval_reference_handle(elm, &hdl);
-
-       if (ACPI_FAILURE(rv))
-               return rv;
-
-       res = acpi_power_res_get(hdl);
-
-       if (res == NULL)
-               return AE_NOT_FOUND;
-
-       rv = acpi_power_res_deref(res, ad->ad_handle);
-
-       if (ACPI_FAILURE(rv))
-               return rv;
-
-       return AcpiEvaluateObject(res->res_handle, "_OFF", NULL, NULL);
+       return AcpiEvaluateObject(res->res_handle, str, NULL, NULL);
 }
 
 static ACPI_STATUS
diff -r ac9c9d41e742 -r 2ef9b756f4dd sys/dev/acpi/acpi_power.h
--- a/sys/dev/acpi/acpi_power.h Mon Jun 07 13:57:20 2010 +0000
+++ b/sys/dev/acpi/acpi_power.h Mon Jun 07 14:07:25 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_power.h,v 1.4 2010/06/07 13:04:31 jruoho Exp $ */
+/* $NetBSD: acpi_power.h,v 1.5 2010/06/07 14:07:25 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -34,12 +34,13 @@
 
 #define ACPI_STATE_ERROR       -1
 
-bool   acpi_power_register(struct acpi_devnode *);
-void   acpi_power_deregister(struct acpi_devnode *);
-void   acpi_power_deregister_from_handle(ACPI_HANDLE);
-bool   acpi_power_get(struct acpi_devnode *, int *);
-bool   acpi_power_set(struct acpi_devnode *, int);
-bool   acpi_power_set_from_handle(ACPI_HANDLE, int);
-void   acpi_power_add(struct acpi_devnode *);
+bool           acpi_power_register(struct acpi_devnode *);
+void           acpi_power_deregister(struct acpi_devnode *);
+void           acpi_power_deregister_from_handle(ACPI_HANDLE);
+bool           acpi_power_get(struct acpi_devnode *, int *);
+bool           acpi_power_set(struct acpi_devnode *, int);
+bool           acpi_power_set_from_handle(ACPI_HANDLE, int);
+ACPI_STATUS    acpi_power_res(ACPI_HANDLE, ACPI_HANDLE, bool);
+void           acpi_power_add(struct acpi_devnode *);
 
 #endif /* !_SYS_DEV_ACPI_ACPI_POWER_H */



Home | Main Index | Thread Index | Old Index