diff options
| author | jruoho <jruoho@NetBSD.org> | 2010-04-15 07:02:24 +0000 |
|---|---|---|
| committer | jruoho <jruoho@NetBSD.org> | 2010-04-15 07:02:24 +0000 |
| commit | 55052eca77bc7caa38b193c610f705f324cd9b4f (patch) | |
| tree | f057571a49507ebe2735928796ae1d73fb36ef09 /sys/dev/acpi | |
| parent | b97f222512fef8b0e9d7603661444b3d441250b4 (diff) | |
As discussed with jmcneill@, install a global "bus notification handler"
that receives all notifications and deliver notifications to drivers via it.
Diffstat (limited to 'sys/dev/acpi')
| -rw-r--r-- | sys/dev/acpi/acpi.c | 138 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_acad.c | 20 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_bat.c | 24 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_button.c | 20 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_lid.c | 20 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_tz.c | 10 | ||||
| -rw-r--r-- | sys/dev/acpi/acpivar.h | 20 | ||||
| -rw-r--r-- | sys/dev/acpi/asus_acpi.c | 41 | ||||
| -rw-r--r-- | sys/dev/acpi/dalb_acpi.c | 27 | ||||
| -rw-r--r-- | sys/dev/acpi/smbus_acpi.c | 24 | ||||
| -rw-r--r-- | sys/dev/acpi/sony_acpi.c | 12 | ||||
| -rw-r--r-- | sys/dev/acpi/thinkpad_acpi.c | 32 | ||||
| -rw-r--r-- | sys/dev/acpi/vald_acpi.c | 20 | ||||
| -rw-r--r-- | sys/dev/acpi/valz_acpi.c | 14 | ||||
| -rw-r--r-- | sys/dev/acpi/wmi/wmi_acpi.c | 51 |
15 files changed, 250 insertions, 223 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 6a795835642..8333c93d561 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -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_nodes(struct acpi_softc *); 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 @@ acpi_attach(device_t parent, device_t self, void *aux) 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 @@ static int 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 @@ acpi_make_devnode(ACPI_HANDLE handle, uint32_t level, 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 @@ acpi_print(void *aux, const char *pnp) } /* + * 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 diff --git a/sys/dev/acpi/acpi_acad.c b/sys/dev/acpi/acpi_acad.c index d39232eac2a..51dbbca5e61 100644 --- a/sys/dev/acpi/acpi_acad.c +++ b/sys/dev/acpi/acpi_acad.c @@ -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 @@ acpiacad_attach(device_t parent, device_t self, void *aux) { 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 @@ acpiacad_attach(device_t parent, device_t self, void *aux) 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 @@ acpiacad_attach(device_t parent, device_t self, void *aux) (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 @@ static int 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); diff --git a/sys/dev/acpi/acpi_bat.c b/sys/dev/acpi/acpi_bat.c index ac1c4c8c4df..581f787a37b 100644 --- a/sys/dev/acpi/acpi_bat.c +++ b/sys/dev/acpi/acpi_bat.c @@ -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 @@ acpibat_attach(device_t parent, device_t self, void *aux) { 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 @@ acpibat_attach(device_t parent, device_t self, void *aux) 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 @@ static int 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); diff --git a/sys/dev/acpi/acpi_button.c b/sys/dev/acpi/acpi_button.c index ecce7e35e4b..74fd2586478 100644 --- a/sys/dev/acpi/acpi_button.c +++ b/sys/dev/acpi/acpi_button.c @@ -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 @@ acpibut_attach(device_t parent, device_t self, void *aux) 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 @@ acpibut_attach(device_t parent, device_t self, void *aux) (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 @@ static int 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; diff --git a/sys/dev/acpi/acpi_lid.c b/sys/dev/acpi/acpi_lid.c index af0f6383a51..d941537d6fb 100644 --- a/sys/dev/acpi/acpi_lid.c +++ b/sys/dev/acpi/acpi_lid.c @@ -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 @@ acpilid_attach(device_t parent, device_t self, void *aux) { 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 @@ acpilid_attach(device_t parent, device_t self, void *aux) (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; diff --git a/sys/dev/acpi/acpi_tz.c b/sys/dev/acpi/acpi_tz.c index aaced888bc0..d983aa8cdd7 100644 --- a/sys/dev/acpi/acpi_tz.c +++ b/sys/dev/acpi/acpi_tz.c @@ -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 <jmcneill@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_attach(device_t parent, device_t self, void *aux) 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); diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 895f344f7c8..f80b3d7c298 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -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 @@ struct acpibus_attach_args { #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 @@ struct acpi_devnode { }; /* - * 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 @@ int acpi_check(device_t, const char *); 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 *); diff --git a/sys/dev/acpi/asus_acpi.c b/sys/dev/acpi/asus_acpi.c index 22e3af3cd81..c0eb6354abf 100644 --- a/sys/dev/acpi/asus_acpi.c +++ b/sys/dev/acpi/asus_acpi.c @@ -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 <jmcneill@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 @@ asus_attach(device_t parent, device_t self, void *opaque) { 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 @@ asus_attach(device_t parent, device_t self, void *opaque) } if (asus_get_fan_speed(sc, NULL) == false) - goto nosensors; + goto out; sc->sc_sme = sysmon_envsys_create(); @@ -166,39 +165,32 @@ asus_attach(device_t parent, device_t self, void *opaque) 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 @@ asus_detach(device_t self, int flags) 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) { diff --git a/sys/dev/acpi/dalb_acpi.c b/sys/dev/acpi/dalb_acpi.c index f64e7186004..31f1f72319b 100644 --- a/sys/dev/acpi/dalb_acpi.c +++ b/sys/dev/acpi/dalb_acpi.c @@ -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 <cegger@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 @@ acpi_dalb_attach(device_t parent, device_t self, void *aux) { 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; diff --git a/sys/dev/acpi/smbus_acpi.c b/sys/dev/acpi/smbus_acpi.c index b90f6a2b627..2d7d85ce66f 100644 --- a/sys/dev/acpi/smbus_acpi.c +++ b/sys/dev/acpi/smbus_acpi.c @@ -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 @@ acpi_smbus_attach(device_t parent, device_t self, void *aux) 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 @@ static int 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); diff --git a/sys/dev/acpi/sony_acpi.c b/sys/dev/acpi/sony_acpi.c index 227578bc3dd..0a5f4bd4fa1 100644 --- a/sys/dev/acpi/sony_acpi.c +++ b/sys/dev/acpi/sony_acpi.c @@ -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 @@ sony_acpi_attach(device_t parent, device_t self, void *aux) 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", diff --git a/sys/dev/acpi/thinkpad_acpi.c b/sys/dev/acpi/thinkpad_acpi.c index b7d286eae01..7d590dbe2f5 100644 --- a/sys/dev/acpi/thinkpad_acpi.c +++ b/sys/dev/acpi/thinkpad_acpi.c @@ -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 <jmcneill@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 @@ thinkpad_attach(device_t parent, device_t self, void *opaque) 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 @@ static int 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 @@ thinkpad_detach(device_t self, int flags) 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 diff --git a/sys/dev/acpi/vald_acpi.c b/sys/dev/acpi/vald_acpi.c index a9723102ba1..424ddf0da07 100644 --- a/sys/dev/acpi/vald_acpi.c +++ b/sys/dev/acpi/vald_acpi.c @@ -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_attach(device_t parent, device_t self, void *aux) 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 @@ vald_acpi_attach(device_t parent, device_t self, void *aux) 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) { diff --git a/sys/dev/acpi/valz_acpi.c b/sys/dev/acpi/valz_acpi.c index 4c424aedd5e..f6e8f5d85c5 100644 --- a/sys/dev/acpi/valz_acpi.c +++ b/sys/dev/acpi/valz_acpi.c @@ -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 @@ valz_attach(device_t parent, device_t self, void *aux) 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)) diff --git a/sys/dev/acpi/wmi/wmi_acpi.c b/sys/dev/acpi/wmi/wmi_acpi.c index a33fb9b5ad2..0a10522f61f 100644 --- a/sys/dev/acpi/wmi/wmi_acpi.c +++ b/sys/dev/acpi/wmi/wmi_acpi.c @@ -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 <jruohonen@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 void acpi_wmi_dump(struct acpi_wmi_softc *); 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_attach(device_t parent, device_t self, void *aux) 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 @@ acpi_wmi_guid_match(device_t self, const char *guid) /* * 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 @@ acpi_wmi_event_add(struct acpi_wmi_softc *sc) "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 @@ acpi_wmi_event_del(struct acpi_wmi_softc *sc) aprint_error_dev(sc->sc_dev, "failed to disable " "expensive WExx: %s\n", AcpiFormatException(rv)); } - - return AE_OK; } /* @@ -538,7 +518,10 @@ acpi_wmi_event_get(device_t self, uint32_t event, ACPI_BUFFER *obuf) 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; |
