Module Name:    src
Committed By:   bouyer
Date:           Sat Sep  5 11:34:26 UTC 2009

Modified Files:
        src/sys/dev/acpi [netbsd-5]: acpi.c acpi_button.c acpi_lid.c files.acpi
Added Files:
        src/sys/dev/acpi [netbsd-5]: acpi_wakedev.c acpi_wakedev.h

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #896):
        sys/dev/acpi/acpi_button.c: revision 1.27 via patch
        sys/dev/acpi/acpi_wakedev.h: revision 1.1 via patch
        sys/dev/acpi/acpi_wakedev.c: revision 1.1 via patch
        sys/dev/acpi/files.acpi: revision 1.55 via patch
        sys/dev/acpi/acpi.c: revision 1.127 via patch
        sys/dev/acpi/acpi_lid.c: revision 1.27 via patch
add hw.wake.* sysctl subtree for toggling which devices are allowed to
restore the system from sleep. set/clear wake GPEs as specified before
entering sleep.
by default, the following devices are enabled for wake:
 - sleep/power buttons
 - lid switch
 - pc kbd controller
reviewed by: joerg


To generate a diff of this commit:
cvs rdiff -u -r1.120.4.1 -r1.120.4.2 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.25 -r1.25.24.1 src/sys/dev/acpi/acpi_button.c
cvs rdiff -u -r1.26 -r1.26.4.1 src/sys/dev/acpi/acpi_lid.c
cvs rdiff -u -r0 -r1.2.4.2 src/sys/dev/acpi/acpi_wakedev.c
cvs rdiff -u -r0 -r1.1.4.2 src/sys/dev/acpi/acpi_wakedev.h
cvs rdiff -u -r1.52.8.1 -r1.52.8.2 src/sys/dev/acpi/files.acpi

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.c
diff -u src/sys/dev/acpi/acpi.c:1.120.4.1 src/sys/dev/acpi/acpi.c:1.120.4.2
--- src/sys/dev/acpi/acpi.c:1.120.4.1	Mon Feb  2 20:37:34 2009
+++ src/sys/dev/acpi/acpi.c	Sat Sep  5 11:34:26 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.120.4.1 2009/02/02 20:37:34 snj Exp $	*/
+/*	$NetBSD: acpi.c,v 1.120.4.2 2009/09/05 11:34:26 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.120.4.1 2009/02/02 20:37:34 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.120.4.2 2009/09/05 11:34:26 bouyer Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -89,6 +89,7 @@
 #include <dev/acpi/acpivar.h>
 #include <dev/acpi/acpi_osd.h>
 #include <dev/acpi/acpi_timer.h>
+#include <dev/acpi/acpi_wakedev.h>
 #ifdef ACPIVERBOSE
 #include <dev/acpi/acpidevs_data.h>
 #endif
@@ -669,6 +670,8 @@
 			    "acpinodebus", &aa, acpi_print);
 		}
 	}
+	acpi_wakedev_scan(sc);
+
 	config_found_ia(sc->sc_dev, "acpiapmbus", NULL, NULL);
 }
 
@@ -1265,6 +1268,8 @@
 			break;
 		}
 
+		acpi_wakedev_commit(sc);
+
 		if (state != ACPI_STATE_S1 && !pmf_system_suspend(PMF_F_NONE)) {
 			aprint_error_dev(sc->sc_dev, "aborting suspend\n");
 			break;

Index: src/sys/dev/acpi/acpi_button.c
diff -u src/sys/dev/acpi/acpi_button.c:1.25 src/sys/dev/acpi/acpi_button.c:1.25.24.1
--- src/sys/dev/acpi/acpi_button.c:1.25	Sun Dec  9 20:27:52 2007
+++ src/sys/dev/acpi/acpi_button.c	Sat Sep  5 11:34:26 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_button.c,v 1.25 2007/12/09 20:27:52 jmcneill Exp $	*/
+/*	$NetBSD: acpi_button.c,v 1.25.24.1 2009/09/05 11:34:26 bouyer Exp $	*/
 
 /*
  * Copyright 2001, 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.25 2007/12/09 20:27:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.25.24.1 2009/09/05 11:34:26 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -145,8 +145,6 @@
 		return;
 	}
 
-	acpi_set_wake_gpe(sc->sc_node->ad_handle);
-
 #ifdef ACPI_BUT_DEBUG
 	/* Display the current state when it changes. */
 	sc->sc_flags = ACPIBUT_F_VERBOSE;

Index: src/sys/dev/acpi/acpi_lid.c
diff -u src/sys/dev/acpi/acpi_lid.c:1.26 src/sys/dev/acpi/acpi_lid.c:1.26.4.1
--- src/sys/dev/acpi/acpi_lid.c:1.26	Tue Jul 15 16:19:37 2008
+++ src/sys/dev/acpi/acpi_lid.c	Sat Sep  5 11:34:26 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_lid.c,v 1.26 2008/07/15 16:19:37 dyoung Exp $	*/
+/*	$NetBSD: acpi_lid.c,v 1.26.4.1 2009/09/05 11:34:26 bouyer Exp $	*/
 
 /*
  * Copyright 2001, 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.26 2008/07/15 16:19:37 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.26.4.1 2009/09/05 11:34:26 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -124,8 +124,6 @@
 		return;
 	}
 
-	acpi_set_wake_gpe(sc->sc_node->ad_handle);
-
 	if (!pmf_device_register(self, acpilid_suspend, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
 }
@@ -136,8 +134,6 @@
 	struct acpilid_softc *sc = device_private(self);
 	ACPI_STATUS rv;
 
-	acpi_clear_wake_gpe(sc->sc_node->ad_handle);
-
 	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
 	    ACPI_DEVICE_NOTIFY, acpilid_notify_handler);
 	if (ACPI_FAILURE(rv)) {

Index: src/sys/dev/acpi/files.acpi
diff -u src/sys/dev/acpi/files.acpi:1.52.8.1 src/sys/dev/acpi/files.acpi:1.52.8.2
--- src/sys/dev/acpi/files.acpi:1.52.8.1	Sun Aug 30 03:01:26 2009
+++ src/sys/dev/acpi/files.acpi	Sat Sep  5 11:34:26 2009
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.52.8.1 2009/08/30 03:01:26 snj Exp $
+#	$NetBSD: files.acpi,v 1.52.8.2 2009/09/05 11:34:26 bouyer Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -19,6 +19,7 @@
 file	dev/acpi/acpi_pci_link.c	acpi
 file	dev/acpi/acpi_quirks.c		acpi
 file	dev/acpi/acpi_timer.c		acpi
+file	dev/acpi/acpi_wakedev.c		acpi
 
 # ACPI/apm emulation.
 attach  apm at acpiapmbus with acpiapm: sysmon_envsys

Added files:

Index: src/sys/dev/acpi/acpi_wakedev.c
diff -u /dev/null src/sys/dev/acpi/acpi_wakedev.c:1.2.4.2
--- /dev/null	Sat Sep  5 11:34:27 2009
+++ src/sys/dev/acpi/acpi_wakedev.c	Sat Sep  5 11:34:26 2009
@@ -0,0 +1,189 @@
+/* $NetBSD: acpi_wakedev.c,v 1.2.4.2 2009/09/05 11:34:26 bouyer Exp $ */
+
+/*-
+ * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: acpi_wakedev.c,v 1.2.4.2 2009/09/05 11:34:26 bouyer Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/device.h>
+#include <sys/queue.h>
+#include <sys/sysctl.h>
+
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpi_wakedev.h>
+
+struct acpi_wakedev;
+
+static TAILQ_HEAD(, acpi_wakedev) acpi_wakedevlist =
+    TAILQ_HEAD_INITIALIZER(acpi_wakedevlist);;
+static int acpi_wakedev_node = -1;
+
+struct acpi_wakedev {
+	struct acpi_devnode	*aw_node;
+	int			aw_enabled;
+	struct sysctllog	*aw_sysctllog;
+	TAILQ_ENTRY(acpi_wakedev) aw_list;
+};
+
+static const char * const acpi_wakedev_default[] = {
+	"PNP0C0C",	/* power button */
+	"PNP0C0E",	/* sleep button */
+	"PNP0C0D",	/* lid switch */
+	"PNP03??",	/* PC KBD port */
+	NULL,
+};
+
+SYSCTL_SETUP(sysctl_acpi_wakedev_setup, "sysctl hw.wake subtree setup")
+{
+	const struct sysctlnode *rnode;
+	int err;
+
+	err = sysctl_createv(NULL, 0, NULL, NULL,
+	    CTLFLAG_PERMANENT,
+	    CTLTYPE_NODE, "hw", NULL,
+	    NULL, 0, NULL, 0, CTL_HW, CTL_EOL);
+	if (err)
+		return;
+	err = sysctl_createv(NULL, 0, NULL, &rnode,
+	    CTLFLAG_PERMANENT,
+	    CTLTYPE_NODE, "wake", NULL,
+	    NULL, 0, NULL, 0,
+	    CTL_HW, CTL_CREATE, CTL_EOL);
+	if (err)
+		return;
+	acpi_wakedev_node = rnode->sysctl_num;
+}
+
+static void
+acpi_wakedev_sysctl_add(struct acpi_wakedev *aw)
+{
+	int err;
+
+	if (acpi_wakedev_node == -1)
+		return;
+
+	err = sysctl_createv(&aw->aw_sysctllog, 0, NULL, NULL,
+	    CTLFLAG_READWRITE, CTLTYPE_INT, aw->aw_node->ad_name,
+	    NULL, NULL, 0, &aw->aw_enabled, 0,
+	    CTL_HW, acpi_wakedev_node, CTL_CREATE, CTL_EOL);
+	if (err)
+		printf("acpi_wakedev_sysctl_add: "
+		    "sysctl_createv(hw.wake.%s) failed. (%d)\n",
+		    aw->aw_node->ad_name, err);
+}
+
+static bool
+acpi_wakedev_add(struct acpi_softc *sc, struct acpi_devnode *ad)
+{
+	struct acpi_wakedev *aw;
+	ACPI_HANDLE hdl;
+
+	if (ACPI_FAILURE(AcpiGetHandle(ad->ad_handle, "_PRW", &hdl)))
+		return false;
+
+	aw = kmem_alloc(sizeof(*aw), KM_SLEEP);
+	if (aw == NULL) {
+		aprint_error("acpi_wakedev_add: kmem_alloc failed\n");
+		return false;
+	}
+	aw->aw_node = ad;
+	aw->aw_sysctllog = NULL;
+	if (acpi_match_hid(ad->ad_devinfo, acpi_wakedev_default))
+		aw->aw_enabled = 1;
+	else
+		aw->aw_enabled = 0;
+
+	TAILQ_INSERT_TAIL(&acpi_wakedevlist, aw, aw_list);
+
+	acpi_wakedev_sysctl_add(aw);
+
+	return true;
+}
+
+static void
+acpi_wakedev_print(struct acpi_wakedev *aw)
+{
+	aprint_debug(" %s", aw->aw_node->ad_name);
+}
+
+int
+acpi_wakedev_scan(struct acpi_softc *sc)
+{
+	struct acpi_scope *as;
+	struct acpi_devnode *ad;
+	struct acpi_wakedev *aw;
+	ACPI_DEVICE_INFO *di;
+	int count = 0;
+
+#define ACPI_STA_DEV_VALID	\
+	(ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|ACPI_STA_DEV_OK)
+
+	TAILQ_FOREACH(as, &sc->sc_scopes, as_list)
+		TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) {
+			di = ad->ad_devinfo;
+			if (di->Type != ACPI_TYPE_DEVICE)
+				continue;
+			if ((di->Valid & ACPI_VALID_STA) != 0 &&
+			    (di->CurrentStatus & ACPI_STA_DEV_VALID) !=
+			     ACPI_STA_DEV_VALID)
+				continue;
+			if (acpi_wakedev_add(sc, ad) == true)
+				++count;
+		}
+
+#undef ACPI_STA_DEV_VALID
+
+	if (count == 0)
+		return 0;
+
+	aprint_debug_dev(sc->sc_dev, "wakeup devices:");
+	TAILQ_FOREACH(aw, &acpi_wakedevlist, aw_list)
+		acpi_wakedev_print(aw);
+	aprint_debug("\n");
+
+	return count;
+}
+
+void
+acpi_wakedev_commit(struct acpi_softc *sc)
+{
+	struct acpi_wakedev *aw;
+
+	TAILQ_FOREACH(aw, &acpi_wakedevlist, aw_list) {
+		if (aw->aw_enabled) {
+			aprint_debug_dev(sc->sc_dev, "set wake GPE (%s)\n",
+			    aw->aw_node->ad_name);
+			acpi_set_wake_gpe(aw->aw_node->ad_handle);
+		} else
+			acpi_clear_wake_gpe(aw->aw_node->ad_handle);
+	}
+}

Index: src/sys/dev/acpi/acpi_wakedev.h
diff -u /dev/null src/sys/dev/acpi/acpi_wakedev.h:1.1.4.2
--- /dev/null	Sat Sep  5 11:34:27 2009
+++ src/sys/dev/acpi/acpi_wakedev.h	Sat Sep  5 11:34:26 2009
@@ -0,0 +1,35 @@
+/* $NetBSD: acpi_wakedev.h,v 1.1.4.2 2009/09/05 11:34:26 bouyer Exp $ */
+
+/*-
+ * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_DEV_ACPI_ACPI_WAKEDEV_H
+#define _SYS_DEV_ACPI_ACPI_WAKEDEV_H
+
+int	acpi_wakedev_scan(struct acpi_softc *);
+void	acpi_wakedev_commit(struct acpi_softc *);
+
+#endif /* !_SYS_DEV_ACPI_ACPI_WAKEDEV_H */

Reply via email to