Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi As discussed with jmcneill@, install a global "...
details: https://anonhg.NetBSD.org/src/rev/36abfcadb9e6
branches: trunk
changeset: 753987:36abfcadb9e6
user: jruoho <jruoho%NetBSD.org@localhost>
date: Thu Apr 15 07:02:24 2010 +0000
description:
As discussed with jmcneill@, install a global "bus notification handler"
that receives all notifications and deliver notifications to drivers via it.
diffstat:
sys/dev/acpi/acpi.c | 138 +++++++++++++++++++++++++++++++++++++++++-
sys/dev/acpi/acpi_acad.c | 20 +----
sys/dev/acpi/acpi_bat.c | 24 +-----
sys/dev/acpi/acpi_button.c | 20 +----
sys/dev/acpi/acpi_lid.c | 20 +----
sys/dev/acpi/acpi_tz.c | 10 +--
sys/dev/acpi/acpivar.h | 20 +++--
sys/dev/acpi/asus_acpi.c | 41 +++++-------
sys/dev/acpi/dalb_acpi.c | 27 +------
sys/dev/acpi/smbus_acpi.c | 24 ++-----
sys/dev/acpi/sony_acpi.c | 12 +--
sys/dev/acpi/thinkpad_acpi.c | 32 +++------
sys/dev/acpi/vald_acpi.c | 20 +++--
sys/dev/acpi/valz_acpi.c | 14 +++-
sys/dev/acpi/wmi/wmi_acpi.c | 51 +++++----------
15 files changed, 250 insertions(+), 223 deletions(-)
diffs (truncated from 1066 to 300 lines):
diff -r 002b0e145293 -r 36abfcadb9e6 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c Thu Apr 15 05:27:45 2010 +0000
+++ b/sys/dev/acpi/acpi.c Thu Apr 15 07:02:24 2010 +0000
@@ -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_type = type;
+ ad->ad_handle = handle;
ad->ad_devinfo = devinfo;
- ad->ad_handle = handle;
- ad->ad_type = type;
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
diff -r 002b0e145293 -r 36abfcadb9e6 sys/dev/acpi/acpi_acad.c
--- a/sys/dev/acpi/acpi_acad.c Thu Apr 15 05:27:45 2010 +0000
+++ b/sys/dev/acpi/acpi_acad.c Thu Apr 15 07:02:24 2010 +0000
@@ -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);
diff -r 002b0e145293 -r 36abfcadb9e6 sys/dev/acpi/acpi_bat.c
--- a/sys/dev/acpi/acpi_bat.c Thu Apr 15 05:27:45 2010 +0000
+++ b/sys/dev/acpi/acpi_bat.c Thu Apr 15 07:02:24 2010 +0000
@@ -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 @@
Home |
Main Index |
Thread Index |
Old Index