Module Name:    src
Committed By:   jruoho
Date:           Thu Apr 15 07:02:24 UTC 2010

Modified Files:
        src/sys/dev/acpi: acpi.c acpi_acad.c acpi_bat.c acpi_button.c
            acpi_lid.c acpi_tz.c acpivar.h asus_acpi.c dalb_acpi.c smbus_acpi.c
            sony_acpi.c thinkpad_acpi.c vald_acpi.c valz_acpi.c
        src/sys/dev/acpi/wmi: wmi_acpi.c

Log Message:
As discussed with jmcneill@, install a global "bus notification handler"
that receives all notifications and deliver notifications to drivers via it.

Besides making the code more compact, this has several benefits:

  * Minimizes the direct interaction with ACPICA and provides a
    central place that easier to audit.

  * Drivers do not need to wonder what type of notification handler
    (ACPI_SYSTEM_NOTIFY or ACPI_DEVICE_NOTIFY) is appropriate.

  * As the "bus" handles the events, individual drivers do not need to guess
    that EBUSY is the right thing to do when removal of the notify handler
    fails upon detach.

  * This catches also "bus-specific" events. While these remain to be
    unhandled, these are required for things like PCI hotplug and docking.

  * Drivers can not go and claim handles they do not own.

  * This makes it easier to catch unhandled events.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/acpi/acpi_acad.c
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/acpi/acpi_bat.c
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/acpi/acpi_button.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/acpi/acpi_lid.c
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/acpi/acpi_tz.c
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/acpi/acpivar.h
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/acpi/asus_acpi.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/acpi/dalb_acpi.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/acpi/smbus_acpi.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/acpi/sony_acpi.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/acpi/thinkpad_acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/vald_acpi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/valz_acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/wmi/wmi_acpi.c

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.174 src/sys/dev/acpi/acpi.c:1.175
--- src/sys/dev/acpi/acpi.c:1.174	Thu Apr 15 04:03:38 2010
+++ src/sys/dev/acpi/acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.174 2010/04/15 04:03:38 jruoho Exp $	*/
+/*	$NetBSD: acpi.c,v 1.175 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.174 2010/04/15 04:03:38 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.175 2010/04/15 07:02:24 jruoho Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -175,6 +175,8 @@
 static void		acpi_rescan_capabilities(struct acpi_softc *);
 static int		acpi_print(void *aux, const char *);
 
+static void		acpi_notify_handler(ACPI_HANDLE, uint32_t, void *);
+
 static void		acpi_register_fixed_button(struct acpi_softc *, int);
 static void		acpi_deregister_fixed_button(struct acpi_softc *, int);
 static uint32_t		acpi_fixed_button_handler(void *);
@@ -449,6 +451,21 @@
 	if (ACPI_FAILURE(rv))
 		goto fail;
 
+	/*
+	 * Install global notify handlers.
+	 */
+	rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT,
+	    ACPI_SYSTEM_NOTIFY, acpi_notify_handler, NULL);
+
+	if (ACPI_FAILURE(rv))
+		goto fail;
+
+	rv = AcpiInstallNotifyHandler(ACPI_ROOT_OBJECT,
+	    ACPI_DEVICE_NOTIFY, acpi_notify_handler, NULL);
+
+	if (ACPI_FAILURE(rv))
+		goto fail;
+
 	acpi_active = 1;
 
 	/* Our current state is "awake". */
@@ -502,8 +519,21 @@
 acpi_detach(device_t self, int flags)
 {
 	struct acpi_softc *sc = device_private(self);
+	ACPI_STATUS rv;
 	int rc;
 
+	rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT,
+	    ACPI_SYSTEM_NOTIFY, acpi_notify_handler);
+
+	if (ACPI_FAILURE(rv))
+		return EBUSY;
+
+	rv = AcpiRemoveNotifyHandler(ACPI_ROOT_OBJECT,
+	    ACPI_DEVICE_NOTIFY, acpi_notify_handler);
+
+	if (ACPI_FAILURE(rv))
+		return EBUSY;
+
 	if ((rc = config_detach_children(self, flags)) != 0)
 		return rc;
 
@@ -609,10 +639,12 @@
 		if (ad == NULL)
 			return AE_NO_MEMORY;
 
+		ad->ad_device = NULL;
 		ad->ad_parent = sc->sc_dev;
-		ad->ad_devinfo = devinfo;
-		ad->ad_handle = handle;
+
 		ad->ad_type = type;
+		ad->ad_handle = handle;
+		ad->ad_devinfo = devinfo;
 
 		anu = (ACPI_NAME_UNION *)&devinfo->Name;
 		ad->ad_name[4] = '\0';
@@ -1049,6 +1081,104 @@
 }
 
 /*
+ * Notify.
+ */
+static void
+acpi_notify_handler(ACPI_HANDLE handle, uint32_t event, void *aux)
+{
+	struct acpi_softc *sc = acpi_softc;
+	struct acpi_devnode *ad;
+
+	KASSERT(sc != NULL);
+	KASSERT(aux == NULL);
+	KASSERT(acpi_active != 0);
+
+	if (acpi_suspended != 0)
+		return;
+
+	/*
+	 *  System: 0x00 - 0x7F.
+	 *  Device: 0x80 - 0xFF.
+	 */
+	switch (event) {
+
+	case ACPI_NOTIFY_BUS_CHECK:
+	case ACPI_NOTIFY_DEVICE_CHECK:
+	case ACPI_NOTIFY_DEVICE_WAKE:
+	case ACPI_NOTIFY_EJECT_REQUEST:
+	case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
+	case ACPI_NOTIFY_FREQUENCY_MISMATCH:
+	case ACPI_NOTIFY_BUS_MODE_MISMATCH:
+	case ACPI_NOTIFY_POWER_FAULT:
+	case ACPI_NOTIFY_CAPABILITIES_CHECK:
+	case ACPI_NOTIFY_DEVICE_PLD_CHECK:
+	case ACPI_NOTIFY_RESERVED:
+	case ACPI_NOTIFY_LOCALITY_UPDATE:
+		break;
+	}
+
+	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "notification 0x%02X for "
+		"%s (%p)\n", event, acpi_name(handle), handle));
+
+	/*
+	 * We deliver notifications only to drivers
+	 * that have been succesfully attached and
+	 * that have registered a handler with us.
+	 * The opaque pointer is always the device_t.
+	 */
+	SIMPLEQ_FOREACH(ad, &sc->sc_devnodes, ad_list) {
+
+		if (ad->ad_device == NULL)
+			continue;
+
+		if (ad->ad_notify == NULL)
+			continue;
+
+		if (ad->ad_handle != handle)
+			continue;
+
+		(*ad->ad_notify)(ad->ad_handle, event, ad->ad_device);
+
+		return;
+	}
+
+	aprint_debug_dev(sc->sc_dev, "unhandled notify 0x%02X "
+	    "for %s (%p)\n", event, acpi_name(handle), handle);
+}
+
+bool
+acpi_register_notify(struct acpi_devnode *ad, ACPI_NOTIFY_HANDLER notify)
+{
+	struct acpi_softc *sc = acpi_softc;
+
+	KASSERT(sc != NULL);
+	KASSERT(acpi_active != 0);
+
+	if (acpi_suspended != 0)
+		goto fail;
+
+	if (ad == NULL || notify == NULL)
+		goto fail;
+
+	ad->ad_notify = notify;
+
+	return true;
+
+fail:
+	aprint_error_dev(sc->sc_dev, "failed to register notify "
+	    "handler for %s (%p)\n", ad->ad_name, ad->ad_handle);
+
+	return false;
+}
+
+void
+acpi_deregister_notify(struct acpi_devnode *ad)
+{
+
+	ad->ad_notify = NULL;
+}
+
+/*
  * Fixed buttons.
  */
 static void

Index: src/sys/dev/acpi/acpi_acad.c
diff -u src/sys/dev/acpi/acpi_acad.c:1.42 src/sys/dev/acpi/acpi_acad.c:1.43
--- src/sys/dev/acpi/acpi_acad.c:1.42	Fri Mar  5 14:00:16 2010
+++ src/sys/dev/acpi/acpi_acad.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_acad.c,v 1.42 2010/03/05 14:00:16 jruoho Exp $	*/
+/*	$NetBSD: acpi_acad.c,v 1.43 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_acad.c,v 1.42 2010/03/05 14:00:16 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_acad.c,v 1.43 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -105,7 +105,6 @@
 {
 	struct acpiacad_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
-	ACPI_STATUS rv;
 
 	aprint_naive(": ACPI AC Adapter\n");
 	aprint_normal(": ACPI AC Adapter\n");
@@ -114,6 +113,7 @@
 	sc->sc_status = -1;
 	sc->sc_node = aa->aa_node;
 
+	acpiacad_init_envsys(self);
 	mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
 
 	sc->sc_smpsw.smpsw_name = device_xname(self);
@@ -121,12 +121,7 @@
 
 	(void)sysmon_pswitch_register(&sc->sc_smpsw);
 	(void)pmf_device_register(self, NULL, acpiacad_resume);
-
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpiacad_notify_handler, self);
-
-	if (ACPI_SUCCESS(rv))
-		acpiacad_init_envsys(self);
+	(void)acpi_register_notify(sc->sc_node, acpiacad_notify_handler);
 }
 
 /*
@@ -138,13 +133,8 @@
 acpiacad_detach(device_t self, int flags)
 {
 	struct acpiacad_softc *sc = device_private(self);
-	ACPI_STATUS rv;
-
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpiacad_notify_handler);
 
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
+	acpi_deregister_notify(sc->sc_node);
 
 	mutex_destroy(&sc->sc_mutex);
 

Index: src/sys/dev/acpi/acpi_bat.c
diff -u src/sys/dev/acpi/acpi_bat.c:1.99 src/sys/dev/acpi/acpi_bat.c:1.100
--- src/sys/dev/acpi/acpi_bat.c:1.99	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/acpi_bat.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_bat.c,v 1.99 2010/04/14 19:27:28 jruoho Exp $	*/
+/*	$NetBSD: acpi_bat.c,v 1.100 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.99 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.100 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -217,7 +217,6 @@
 {
 	struct acpibat_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
-	ACPI_STATUS rv;
 
 	aprint_naive(": ACPI Battery\n");
 	aprint_normal(": ACPI Battery\n");
@@ -234,16 +233,8 @@
 	mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(&sc->sc_condvar, device_xname(self));
 
-	if (pmf_device_register(self, NULL, acpibat_resume) != true)
-		aprint_error_dev(self, "couldn't establish power handler\n");
-
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpibat_notify_handler, self);
-
-	if (ACPI_FAILURE(rv)) {
-		aprint_error_dev(self, "couldn't install notify handler\n");
-		return;
-	}
+	(void)pmf_device_register(self, NULL, acpibat_resume);
+	(void)acpi_register_notify(sc->sc_node, acpibat_notify_handler);
 
 	sc->sc_sensor = kmem_zalloc(ACPIBAT_COUNT *
 	    sizeof(*sc->sc_sensor), KM_SLEEP);
@@ -263,13 +254,8 @@
 acpibat_detach(device_t self, int flags)
 {
 	struct acpibat_softc *sc = device_private(self);
-	ACPI_STATUS rv;
 
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpibat_notify_handler);
-
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
+	acpi_deregister_notify(sc->sc_node);
 
 	cv_destroy(&sc->sc_condvar);
 	mutex_destroy(&sc->sc_mutex);

Index: src/sys/dev/acpi/acpi_button.c
diff -u src/sys/dev/acpi/acpi_button.c:1.34 src/sys/dev/acpi/acpi_button.c:1.35
--- src/sys/dev/acpi/acpi_button.c:1.34	Fri Mar  5 14:00:16 2010
+++ src/sys/dev/acpi/acpi_button.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_button.c,v 1.34 2010/03/05 14:00:16 jruoho Exp $	*/
+/*	$NetBSD: acpi_button.c,v 1.35 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*
  * Copyright 2001, 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.34 2010/03/05 14:00:16 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.35 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -110,7 +110,6 @@
 	struct acpibut_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
 	const char *desc;
-	ACPI_STATUS rv;
 
 	sc->sc_smpsw.smpsw_name = device_xname(self);
 
@@ -130,12 +129,7 @@
 
 	(void)pmf_device_register(self, NULL, NULL);
 	(void)sysmon_pswitch_register(&sc->sc_smpsw);
-
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, acpibut_notify_handler, self);
-
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self, "failed to install notify handler\n");
+	(void)acpi_register_notify(sc->sc_node, acpibut_notify_handler);
 }
 
 /*
@@ -147,15 +141,9 @@
 acpibut_detach(device_t self, int flags)
 {
 	struct acpibut_softc *sc = device_private(self);
-	ACPI_STATUS rv;
-
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, acpibut_notify_handler);
-
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
 
 	pmf_device_deregister(self);
+	acpi_deregister_notify(sc->sc_node);
 	sysmon_pswitch_unregister(&sc->sc_smpsw);
 
 	return 0;

Index: src/sys/dev/acpi/acpi_lid.c
diff -u src/sys/dev/acpi/acpi_lid.c:1.38 src/sys/dev/acpi/acpi_lid.c:1.39
--- src/sys/dev/acpi/acpi_lid.c:1.38	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/acpi_lid.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_lid.c,v 1.38 2010/04/14 19:27:28 jruoho Exp $	*/
+/*	$NetBSD: acpi_lid.c,v 1.39 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*
  * Copyright 2001, 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.38 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_lid.c,v 1.39 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -99,7 +99,6 @@
 {
 	struct acpilid_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
-	ACPI_STATUS rv;
 
 	aprint_naive(": ACPI Lid Switch\n");
 	aprint_normal(": ACPI Lid Switch\n");
@@ -111,27 +110,16 @@
 
 	(void)pmf_device_register(self, NULL, NULL);
 	(void)sysmon_pswitch_register(&sc->sc_smpsw);
-
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, acpilid_notify_handler, self);
-
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self, "failed to register notify handler\n");
+	(void)acpi_register_notify(sc->sc_node, acpilid_notify_handler);
 }
 
 static int
 acpilid_detach(device_t self, int flags)
 {
 	struct acpilid_softc *sc = device_private(self);
-	ACPI_STATUS rv;
-
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, acpilid_notify_handler);
-
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
 
 	pmf_device_deregister(self);
+	acpi_deregister_notify(sc->sc_node);
 	sysmon_pswitch_unregister(&sc->sc_smpsw);
 
 	return 0;

Index: src/sys/dev/acpi/acpi_tz.c
diff -u src/sys/dev/acpi/acpi_tz.c:1.64 src/sys/dev/acpi/acpi_tz.c:1.65
--- src/sys/dev/acpi/acpi_tz.c:1.64	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/acpi_tz.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_tz.c,v 1.64 2010/04/14 19:27:28 jruoho Exp $ */
+/* $NetBSD: acpi_tz.c,v 1.65 2010/04/15 07:02:24 jruoho Exp $ */
 
 /*
  * Copyright (c) 2003 Jared D. McNeill <jmcne...@invisible.ca>
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.64 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.65 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -211,11 +211,7 @@
 	acpitz_get_zone(self, 1);
 	acpitz_get_status(self);
 
-	rv = AcpiInstallNotifyHandler(sc->sc_devnode->ad_handle,
-	    ACPI_DEVICE_NOTIFY, acpitz_notify_handler, self);
-
-	if (ACPI_FAILURE(rv))
-		return;
+	(void)acpi_register_notify(sc->sc_devnode, acpitz_notify_handler);
 
 	callout_init(&sc->sc_callout, CALLOUT_MPSAFE);
 	callout_setfunc(&sc->sc_callout, acpitz_tick, self);

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.47 src/sys/dev/acpi/acpivar.h:1.48
--- src/sys/dev/acpi/acpivar.h:1.47	Wed Apr 14 17:12:14 2010
+++ src/sys/dev/acpi/acpivar.h	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.47 2010/04/14 17:12:14 jruoho Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.48 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -54,9 +54,7 @@
 #include <dev/sysmon/sysmonvar.h>
 
 /*
- * acpibus_attach_args:
- *
- *	This structure is used to attach the ACPI "bus".
+ * This structure is used to attach the ACPI "bus".
  */
 struct acpibus_attach_args {
 	bus_space_tag_t aa_iot;		/* PCI I/O space tag */
@@ -73,13 +71,15 @@
 #define ACPI_DEVICE_WAKEUP		__BIT(1)
 
 /*
- * acpi_devnode:
+ * An ACPI device node.
  *
- *	An ACPI device node.
+ * Note that this is available for all nodes, meaning that e.g.
+ * the device_t (ad_device) may be NULL for unattached devices.
  */
 struct acpi_devnode {
 	device_t		 ad_device;	/* Device */
 	device_t		 ad_parent;	/* Backpointer to the parent */
+	ACPI_NOTIFY_HANDLER	 ad_notify;	/* Device notify */
 	ACPI_DEVICE_INFO	*ad_devinfo;	/* Device info */
 	ACPI_HANDLE		 ad_handle;	/* Device handle */
 	char			 ad_name[5];	/* Device name */
@@ -91,9 +91,7 @@
 };
 
 /*
- * acpi_softc:
- *
- *	Software state of the ACPI subsystem.
+ * Software state of the ACPI subsystem.
  */
 struct acpi_softc {
 	device_t sc_dev;		/* base device info */
@@ -247,6 +245,10 @@
 
 ACPI_PHYSICAL_ADDRESS	acpi_OsGetRootPointer(void);
 
+bool		acpi_register_notify(struct acpi_devnode *,
+				     ACPI_NOTIFY_HANDLER);
+void		acpi_deregister_notify(struct acpi_devnode *);
+
 ACPI_STATUS	acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
 		    void *, const struct acpi_resource_parse_ops *);
 void		acpi_resource_print(device_t, struct acpi_resources *);

Index: src/sys/dev/acpi/asus_acpi.c
diff -u src/sys/dev/acpi/asus_acpi.c:1.19 src/sys/dev/acpi/asus_acpi.c:1.20
--- src/sys/dev/acpi/asus_acpi.c:1.19	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/asus_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: asus_acpi.c,v 1.19 2010/04/14 19:27:28 jruoho Exp $ */
+/* $NetBSD: asus_acpi.c,v 1.20 2010/04/15 07:02:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: asus_acpi.c,v 1.19 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: asus_acpi.c,v 1.20 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -125,10 +125,9 @@
 {
 	struct asus_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = opaque;
-	ACPI_STATUS rv;
 
-	sc->sc_node = aa->aa_node;
 	sc->sc_dev = self;
+	sc->sc_node = aa->aa_node;
 
 	aprint_naive("\n");
 	aprint_normal("\n");
@@ -147,7 +146,7 @@
 	}
 
 	if (asus_get_fan_speed(sc, NULL) == false)
-		goto nosensors;
+		goto out;
 
 	sc->sc_sme = sysmon_envsys_create();
 
@@ -166,39 +165,32 @@
 		sysmon_envsys_destroy(sc->sc_sme);
 		sc->sc_sme = NULL;
 	}
-nosensors:
 
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, ACPI_ALL_NOTIFY,
-	    asus_notify_handler, sc);
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self, "couldn't install notify handler: %s\n",
-		    AcpiFormatException(rv));
-
-	if (!pmf_device_register(self, asus_suspend, asus_resume))
-		aprint_error_dev(self, "couldn't establish power handler\n");
+out:
+	(void)pmf_device_register(self, asus_suspend, asus_resume);
+	(void)acpi_register_notify(sc->sc_node, asus_notify_handler);
 }
 
 static int
 asus_detach(device_t self, int flags)
 {
 	struct asus_softc *sc = device_private(self);
-	ACPI_STATUS rv;
 	int i;
 
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, asus_notify_handler);
+	acpi_deregister_notify(sc->sc_node);
 
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
+	if (sc->sc_smpsw_valid != false) {
 
-	if (sc->sc_smpsw_valid)
 		for (i = 0; i < ASUS_PSW_LAST; i++)
 			sysmon_pswitch_unregister(&sc->sc_smpsw[i]);
+	}
 
-	if (sc->sc_sme)
+	if (sc->sc_sme != NULL)
 		sysmon_envsys_unregister(sc->sc_sme);
-	if (sc->sc_log)
+
+	if (sc->sc_log != NULL)
 		sysctl_teardown(&sc->sc_log);
+
 	pmf_device_deregister(self);
 
 	return 0;
@@ -207,7 +199,10 @@
 static void
 asus_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
 {
-	struct asus_softc *sc = opaque;
+	struct asus_softc *sc;
+	device_t self = opaque;
+
+	sc = device_private(self);
 
 	if (notify >= ASUS_NOTIFY_BrightnessLow &&
 	    notify <= ASUS_NOTIFY_BrightnessHigh) {

Index: src/sys/dev/acpi/dalb_acpi.c
diff -u src/sys/dev/acpi/dalb_acpi.c:1.13 src/sys/dev/acpi/dalb_acpi.c:1.14
--- src/sys/dev/acpi/dalb_acpi.c:1.13	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/dalb_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dalb_acpi.c,v 1.13 2010/04/14 19:27:28 jruoho Exp $	*/
+/*	$NetBSD: dalb_acpi.c,v 1.14 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2008 Christoph Egger <ceg...@netbsd.org>
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dalb_acpi.c,v 1.13 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dalb_acpi.c,v 1.14 2010/04/15 07:02:24 jruoho Exp $");
 
 /*
  * Direct Application Launch Button:
@@ -154,44 +154,29 @@
 {
 	struct acpi_dalb_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
-	ACPI_STATUS rv;
 
 	aprint_naive("\n");
 	aprint_normal(": Direct Application Launch Button\n");
 
-	sc->sc_node = aa->aa_node;
 	sc->sc_dev = self;
+	sc->sc_node = aa->aa_node;
 
 	config_interrupts(self, acpi_dalb_init);
 
-	/* Install notify handler */
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-		ACPI_ALL_NOTIFY, acpi_dalb_notify_handler, self);
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self,
-			"couldn't install notify handler: (%s)\n",
-			AcpiFormatException(rv));
+	(void)pmf_device_register(self, NULL, acpi_dalb_resume);
+	(void)acpi_register_notify(sc->sc_node, acpi_dalb_notify_handler);
 
 	sc->sc_smpsw_valid = false;
 	acpi_dalb_sysmon_init(sc);
-
-	if (!pmf_device_register(self, NULL, acpi_dalb_resume))
-		aprint_error_dev(self, "couldn't establish power handler\n");
 }
 
 static int
 acpi_dalb_detach(device_t self, int flags)
 {
 	struct acpi_dalb_softc *sc = device_private(self);
-	ACPI_STATUS rv;
-
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpi_dalb_notify_handler);
-
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
 
 	pmf_device_deregister(self);
+	acpi_deregister_notify(sc->sc_node);
 	sysmon_pswitch_unregister(&sc->sc_smpsw);
 
 	return 0;

Index: src/sys/dev/acpi/smbus_acpi.c
diff -u src/sys/dev/acpi/smbus_acpi.c:1.9 src/sys/dev/acpi/smbus_acpi.c:1.10
--- src/sys/dev/acpi/smbus_acpi.c:1.9	Fri Mar  5 14:00:17 2010
+++ src/sys/dev/acpi/smbus_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: smbus_acpi.c,v 1.9 2010/03/05 14:00:17 jruoho Exp $ */
+/* $NetBSD: smbus_acpi.c,v 1.10 2010/04/15 07:02:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: smbus_acpi.c,v 1.9 2010/03/05 14:00:17 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbus_acpi.c,v 1.10 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -212,14 +212,10 @@
 	if (smi_buf.Pointer != NULL)
 		ACPI_FREE(smi_buf.Pointer);
 
-	/* Install notify handler if possible */
-	rv = AcpiInstallNotifyHandler(sc->sc_devnode->ad_handle,
-		ACPI_DEVICE_NOTIFY, acpi_smbus_notify_handler, self);
-	if (ACPI_FAILURE(rv)) {
-		aprint_error(": unable to install DEVICE NOTIFY handler: %s\n",
-		    AcpiFormatException(rv));
-		sc->sc_poll_alert = 2;	/* If failed, fall-back to polling */
-	}
+	/* If failed, fall-back to polling. */
+	if (acpi_register_notify(sc->sc_devnode,
+		acpi_smbus_notify_handler) != true)
+		sc->sc_poll_alert = 2;
 
 	callout_init(&sc->sc_callout, 0);
 	callout_setfunc(&sc->sc_callout, acpi_smbus_tick, self);
@@ -280,15 +276,9 @@
 acpi_smbus_detach(device_t self, int flags)
 {
 	struct acpi_smbus_softc *sc = device_private(self);
-	ACPI_STATUS rv;
-
-	rv = AcpiRemoveNotifyHandler(sc->sc_devnode->ad_handle,
-	    ACPI_DEVICE_NOTIFY, acpi_smbus_notify_handler);
-
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
 
 	pmf_device_deregister(self);
+	acpi_deregister_notify(sc->sc_devnode);
 
 	callout_halt(&sc->sc_callout, NULL);
 	callout_destroy(&sc->sc_callout);

Index: src/sys/dev/acpi/sony_acpi.c
diff -u src/sys/dev/acpi/sony_acpi.c:1.17 src/sys/dev/acpi/sony_acpi.c:1.18
--- src/sys/dev/acpi/sony_acpi.c:1.17	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/sony_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sony_acpi.c,v 1.17 2010/04/14 19:27:28 jruoho Exp $	*/
+/*	$NetBSD: sony_acpi.c,v 1.18 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sony_acpi.c,v 1.17 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sony_acpi.c,v 1.18 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/sysctl.h>
@@ -280,16 +280,12 @@
 			sc->sc_smpsw_valid = 0;
 		}
 
-	/* Install notify handler */
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, sony_acpi_notify_handler, self);
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self,
-		    "couldn't install notify handler (%u)\n", rv);
+	(void)acpi_register_notify(sc->sc_node, sony_acpi_notify_handler);
 
 	/* Install sysctl handler */
 	rv = AcpiWalkNamespace(ACPI_TYPE_METHOD,
 	    sc->sc_node->ad_handle, 1, sony_walk_cb, NULL, sc, NULL);
+
 #ifdef DIAGNOSTIC
 	if (ACPI_FAILURE(rv))
 		aprint_error_dev(self, "Cannot walk ACPI namespace (%u)\n",

Index: src/sys/dev/acpi/thinkpad_acpi.c
diff -u src/sys/dev/acpi/thinkpad_acpi.c:1.29 src/sys/dev/acpi/thinkpad_acpi.c:1.30
--- src/sys/dev/acpi/thinkpad_acpi.c:1.29	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/thinkpad_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.29 2010/04/14 19:27:28 jruoho Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.30 2010/04/15 07:02:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.29 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.30 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -219,12 +219,7 @@
 		goto fail;
 	}
 
-	/* Install notify handler for events */
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, thinkpad_notify_handler, sc);
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self, "couldn't install notify handler: %s\n",
-		    AcpiFormatException(rv));
+	(void)acpi_register_notify(sc->sc_node, thinkpad_notify_handler);
 
 	/* Register power switches with sysmon */
 	psw = sc->sc_smpsw;
@@ -275,14 +270,9 @@
 thinkpad_detach(device_t self, int flags)
 {
 	struct thinkpad_softc *sc = device_private(self);
-	ACPI_STATUS rv;
 	int i;
 
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, thinkpad_notify_handler);
-
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
+	acpi_deregister_notify(sc->sc_node);
 
 	for (i = 0; i < TP_PSW_LAST; i++)
 		sysmon_pswitch_unregister(&sc->sc_smpsw[i]);
@@ -304,19 +294,17 @@
 static void
 thinkpad_notify_handler(ACPI_HANDLE hdl, uint32_t notify, void *opaque)
 {
-	thinkpad_softc_t *sc = (thinkpad_softc_t *)opaque;
-	device_t self = sc->sc_dev;
-	ACPI_STATUS rv;
- 
+	device_t self = opaque;
+	thinkpad_softc_t *sc;
+
+	sc = device_private(self);
+
 	if (notify != 0x80) {
 		aprint_debug_dev(self, "unknown notify 0x%02x\n", notify);
 		return;
 	}
 
-	rv = AcpiOsExecute(OSL_NOTIFY_HANDLER, thinkpad_get_hotkeys, sc);
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self, "couldn't queue hotkey handler: %s\n",
-		    AcpiFormatException(rv));
+	(void)AcpiOsExecute(OSL_NOTIFY_HANDLER, thinkpad_get_hotkeys, sc);
 }
 
 static void

Index: src/sys/dev/acpi/vald_acpi.c
diff -u src/sys/dev/acpi/vald_acpi.c:1.3 src/sys/dev/acpi/vald_acpi.c:1.4
--- src/sys/dev/acpi/vald_acpi.c:1.3	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/vald_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: vald_acpi.c,v 1.3 2010/04/14 19:27:28 jruoho Exp $ */
+/*	$NetBSD: vald_acpi.c,v 1.4 2010/04/15 07:02:24 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vald_acpi.c,v 1.3 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vald_acpi.c,v 1.4 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -235,12 +235,11 @@
 	vald_acpi_libright_set(sc, LIBRIGHT_HOLD);
 
 	/* enable vald notify */
-	AcpiEvaluateObject(sc->sc_node->ad_handle, "ENAB", NULL, NULL);
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_DEVICE_NOTIFY, vald_acpi_notify_handler, sc);
-	if (ACPI_FAILURE(rv))
-		aprint_error_dev(self, "can't install DEVICE NOTIFY handler: %s\n",
-		    AcpiFormatException(rv));
+	rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "ENAB", NULL, NULL);
+
+	if (ACPI_SUCCESS(rv))
+		(void)acpi_register_notify(sc->sc_node,
+		    vald_acpi_notify_handler);
 }
 
 /*
@@ -251,7 +250,10 @@
 static void
 vald_acpi_notify_handler(ACPI_HANDLE handle, uint32_t notify, void *context)
 {
-	struct vald_acpi_softc *sc = context;
+	struct vald_acpi_softc *sc;
+	device_t self = context;
+
+	sc = device_private(self);
 
 	switch (notify) {
 

Index: src/sys/dev/acpi/valz_acpi.c
diff -u src/sys/dev/acpi/valz_acpi.c:1.2 src/sys/dev/acpi/valz_acpi.c:1.3
--- src/sys/dev/acpi/valz_acpi.c:1.2	Wed Apr 14 19:27:28 2010
+++ src/sys/dev/acpi/valz_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: valz_acpi.c,v 1.2 2010/04/14 19:27:28 jruoho Exp $	*/
+/*	$NetBSD: valz_acpi.c,v 1.3 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*
  * Copyright (c) 2010 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: valz_acpi.c,v 1.2 2010/04/14 19:27:28 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: valz_acpi.c,v 1.3 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -102,7 +102,15 @@
 	if(!pmf_event_register(self, PMFE_DISPLAY_BRIGHTNESS_UP,
 	    valz_pmf_brightness_increase, false))
 		aprint_error_dev(self, "failed to register event handler\n");
-		
+
+	/*
+	 * XXX: This is broken.
+	 *
+	 *	It claims resources that do not belong to it.
+	 *
+	 *	It either prevents an ACPI video driver for
+	 *	receiving events or duplicates the notifications.
+	 */
 	rv = AcpiInstallNotifyHandler(sc->sc_lcd, ACPI_DEVICE_NOTIFY,
 		valz_lcd_notify_handler, sc);
 	if (ACPI_FAILURE(rv))

Index: src/sys/dev/acpi/wmi/wmi_acpi.c
diff -u src/sys/dev/acpi/wmi/wmi_acpi.c:1.3 src/sys/dev/acpi/wmi/wmi_acpi.c:1.4
--- src/sys/dev/acpi/wmi/wmi_acpi.c:1.3	Fri Apr  9 04:48:23 2010
+++ src/sys/dev/acpi/wmi/wmi_acpi.c	Thu Apr 15 07:02:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: wmi_acpi.c,v 1.3 2010/04/09 04:48:23 jruoho Exp $	*/
+/*	$NetBSD: wmi_acpi.c,v 1.4 2010/04/15 07:02:24 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Jukka Ruohonen <jruoho...@iki.fi>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.3 2010/04/09 04:48:23 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.4 2010/04/15 07:02:24 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -129,8 +129,8 @@
 
 static ACPI_STATUS acpi_wmi_guid_get(struct acpi_wmi_softc *,
                                      const char *, struct wmi_t **);
-static ACPI_STATUS acpi_wmi_event_add(struct acpi_wmi_softc *);
-static ACPI_STATUS acpi_wmi_event_del(struct acpi_wmi_softc *);
+static void	   acpi_wmi_event_add(struct acpi_wmi_softc *);
+static void	   acpi_wmi_event_del(struct acpi_wmi_softc *);
 static void        acpi_wmi_event_handler(ACPI_HANDLE, uint32_t, void *);
 static bool        acpi_wmi_suspend(device_t, const pmf_qual_t *);
 static bool        acpi_wmi_resume(device_t, const pmf_qual_t *);
@@ -178,23 +178,20 @@
 	acpi_wmi_dump(sc);
 #endif
 
-	(void)acpi_wmi_event_add(sc);
-	(void)pmf_device_register(self, acpi_wmi_suspend, acpi_wmi_resume);
+	acpi_wmi_event_add(sc);
 
 	sc->sc_child = config_found_ia(self, "acpiwmibus",
 	    NULL, acpi_wmi_print);
+
+	(void)pmf_device_register(self, acpi_wmi_suspend, acpi_wmi_resume);
 }
 
 static int
 acpi_wmi_detach(device_t self, int flags)
 {
 	struct acpi_wmi_softc *sc = device_private(self);
-	ACPI_STATUS rv;
-
-	rv = acpi_wmi_event_del(sc);
 
-	if (ACPI_FAILURE(rv))
-		return EBUSY;
+	acpi_wmi_event_del(sc);
 
 	if (sc->sc_child != NULL)
 		(void)config_detach(sc->sc_child, flags);
@@ -411,20 +408,14 @@
 /*
  * Adds internal event handler.
  */
-static ACPI_STATUS
+static void
 acpi_wmi_event_add(struct acpi_wmi_softc *sc)
 {
 	struct wmi_t *wmi;
 	ACPI_STATUS rv;
 
-	rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpi_wmi_event_handler, sc);
-
-	if (ACPI_FAILURE(rv)) {
-		aprint_error_dev(sc->sc_dev, "failed to install notify "
-		    "handler: %s\n", AcpiFormatException(rv));
-		return rv;
-	}
+	if (acpi_register_notify(sc->sc_node, acpi_wmi_event_handler) != true)
+		return;
 
 	/* Enable possible expensive events. */
 	SIMPLEQ_FOREACH(wmi, &sc->wmi_head, wmi_link) {
@@ -444,27 +435,18 @@
 			    "expensive WExx: %s\n", AcpiFormatException(rv));
 		}
 	}
-
-	return AE_OK;
 }
 
 /*
  * Removes the internal event handler.
  */
-static ACPI_STATUS
+static void
 acpi_wmi_event_del(struct acpi_wmi_softc *sc)
 {
 	struct wmi_t *wmi;
 	ACPI_STATUS rv;
 
-	rv = AcpiRemoveNotifyHandler(sc->sc_node->ad_handle,
-	    ACPI_ALL_NOTIFY, acpi_wmi_event_handler);
-
-	if (ACPI_FAILURE(rv)) {
-		aprint_debug_dev(sc->sc_dev, "failed to remove notify "
-		    "handler: %s\n", AcpiFormatException(rv));
-		return rv;
-	}
+	acpi_deregister_notify(sc->sc_node);
 
 	SIMPLEQ_FOREACH(wmi, &sc->wmi_head, wmi_link) {
 
@@ -485,8 +467,6 @@
 		aprint_error_dev(sc->sc_dev, "failed to disable "
 		    "expensive WExx: %s\n", AcpiFormatException(rv));
 	}
-
-	return AE_OK;
 }
 
 /*
@@ -538,7 +518,10 @@
 static void
 acpi_wmi_event_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
 {
-	struct acpi_wmi_softc *sc = aux;
+	struct acpi_wmi_softc *sc;
+	device_t self = aux;
+
+	sc = device_private(self);
 
 	if (sc->sc_child == NULL)
 		return;

Reply via email to