Module Name: src Committed By: jruoho Date: Mon Jun 7 14:07:25 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_power.c acpi_power.h Log Message: Refactor slightly: we need to expose the function that turns individual power resource on or off. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/dev/acpi/acpi_power.c cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/acpi_power.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_power.c diff -u src/sys/dev/acpi/acpi_power.c:1.15 src/sys/dev/acpi/acpi_power.c:1.16 --- src/sys/dev/acpi/acpi_power.c:1.15 Mon Jun 7 13:04:31 2010 +++ src/sys/dev/acpi/acpi_power.c Mon Jun 7 14:07:25 2010 @@ -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; - if (rv == AE_CTRL_CONTINUE) - rv = AE_ERROR; + for (i = 0; i < n; i++) { + + 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) { - if (ACPI_FAILURE(rv)) - return rv; + case true: + rv = acpi_power_res_ref(res, ref); + str = "_ON"; + break; + + case false: + rv = acpi_power_res_deref(res, ref); + str = "_OFF"; + break; - /* - * Turn the resource on. - */ - 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); + default: + return AE_BAD_PARAMETER; + } if (ACPI_FAILURE(rv)) return rv; - return AcpiEvaluateObject(res->res_handle, "_OFF", NULL, NULL); + /* + * Turn the resource on or off. + */ + return AcpiEvaluateObject(res->res_handle, str, NULL, NULL); } static ACPI_STATUS Index: src/sys/dev/acpi/acpi_power.h diff -u src/sys/dev/acpi/acpi_power.h:1.4 src/sys/dev/acpi/acpi_power.h:1.5 --- src/sys/dev/acpi/acpi_power.h:1.4 Mon Jun 7 13:04:31 2010 +++ src/sys/dev/acpi/acpi_power.h Mon Jun 7 14:07:25 2010 @@ -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 */