Module Name: src Committed By: jruoho Date: Sat Apr 24 06:57:11 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_power.c acpi_util.c acpi_util.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/acpi_power.c cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/acpi_util.c cvs rdiff -u -r1.1 -r1.2 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_power.c diff -u src/sys/dev/acpi/acpi_power.c:1.6 src/sys/dev/acpi/acpi_power.c:1.7 --- src/sys/dev/acpi/acpi_power.c:1.6 Sat Apr 24 06:31:44 2010 +++ src/sys/dev/acpi/acpi_power.c Sat Apr 24 06:57:10 2010 @@ -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 Index: src/sys/dev/acpi/acpi_util.c diff -u src/sys/dev/acpi/acpi_util.c:1.2 src/sys/dev/acpi/acpi_util.c:1.3 --- src/sys/dev/acpi/acpi_util.c:1.2 Thu Apr 15 04:03:39 2010 +++ src/sys/dev/acpi/acpi_util.c Sat Apr 24 06:57:10 2010 @@ -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; Index: src/sys/dev/acpi/acpi_util.h diff -u src/sys/dev/acpi/acpi_util.h:1.1 src/sys/dev/acpi/acpi_util.h:1.2 --- src/sys/dev/acpi/acpi_util.h:1.1 Wed Apr 14 17:12:14 2010 +++ src/sys/dev/acpi/acpi_util.h Sat Apr 24 06:57:10 2010 @@ -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);