Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Add detachment routines.



details:   https://anonhg.NetBSD.org/src/rev/8949a841a874
branches:  trunk
changeset: 751285:8949a841a874
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sun Jan 31 06:10:53 2010 +0000

description:
Add detachment routines.

diffstat:

 sys/dev/acpi/acpi_bat.c    |  37 ++++++++++++++++++++++++++++++++++---
 sys/dev/acpi/acpi_button.c |  35 +++++++++++++++++++++++++++++------
 2 files changed, 63 insertions(+), 9 deletions(-)

diffs (151 lines):

diff -r d817e983b895 -r 8949a841a874 sys/dev/acpi/acpi_bat.c
--- a/sys/dev/acpi/acpi_bat.c   Sun Jan 31 03:57:01 2010 +0000
+++ b/sys/dev/acpi/acpi_bat.c   Sun Jan 31 06:10:53 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_bat.c,v 1.79 2010/01/27 22:17:28 drochner Exp $   */
+/*     $NetBSD: acpi_bat.c,v 1.80 2010/01/31 06:10:53 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.79 2010/01/27 22:17:28 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.80 2010/01/31 06:10:53 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -188,6 +188,7 @@
 
 static int         acpibat_match(device_t, cfdata_t, void *);
 static void        acpibat_attach(device_t, device_t, void *);
+static int         acpibat_detach(device_t, int);
 static int          acpibat_get_sta(device_t);
 static ACPI_OBJECT *acpibat_get_object(ACPI_HANDLE, const char *, int);
 static void         acpibat_get_info(device_t);
@@ -200,7 +201,7 @@
 static bool        acpibat_resume(device_t, pmf_qual_t);
 
 CFATTACH_DECL_NEW(acpibat, sizeof(struct acpibat_softc),
-    acpibat_match, acpibat_attach, NULL, NULL);
+    acpibat_match, acpibat_attach, acpibat_detach, NULL);
 
 /*
  * acpibat_match:
@@ -235,6 +236,7 @@
 
        sc->sc_node = aa->aa_node;
        sc->sc_present = 0;
+       sc->sc_sme = NULL;
 
        mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&sc->sc_condvar, device_xname(self));
@@ -252,6 +254,34 @@
 }
 
 /*
+ * acpibat_detach:
+ *
+ *     Autoconfiguration `detach' routine.
+ */
+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;
+
+       cv_destroy(&sc->sc_condvar);
+       mutex_destroy(&sc->sc_mutex);
+
+       if (sc->sc_sme != NULL)
+               sysmon_envsys_unregister(sc->sc_sme);
+
+       pmf_device_deregister(self);
+
+       return 0;
+}
+
+/*
  * acpibat_get_sta:
  *
  *     Evaluate whether the battery is present or absent.
@@ -694,6 +724,7 @@
 fail:
        aprint_error_dev(dv, "failed to initialize sysmon\n");
        sysmon_envsys_destroy(sc->sc_sme);
+       sc->sc_sme = NULL;
 }
 
 static void
diff -r d817e983b895 -r 8949a841a874 sys/dev/acpi/acpi_button.c
--- a/sys/dev/acpi/acpi_button.c        Sun Jan 31 03:57:01 2010 +0000
+++ b/sys/dev/acpi/acpi_button.c        Sun Jan 31 06:10:53 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_button.c,v 1.29 2010/01/30 18:35:48 jruoho Exp $  */
+/*     $NetBSD: acpi_button.c,v 1.30 2010/01/31 06:10:53 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.29 2010/01/30 18:35:48 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.30 2010/01/31 06:10:53 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -75,12 +75,12 @@
 
 static int     acpibut_match(device_t, cfdata_t, void *);
 static void    acpibut_attach(device_t, device_t, void *);
+static int     acpibut_detach(device_t, int);
+static void    acpibut_pressed_event(void *);
+static void    acpibut_notify_handler(ACPI_HANDLE, UINT32, void *);
 
 CFATTACH_DECL_NEW(acpibut, sizeof(struct acpibut_softc),
-    acpibut_match, acpibut_attach, NULL, NULL);
-
-static void    acpibut_pressed_event(void *);
-static void    acpibut_notify_handler(ACPI_HANDLE, UINT32, void *);
+    acpibut_match, acpibut_attach, acpibut_detach, NULL);
 
 /*
  * acpibut_match:
@@ -158,6 +158,29 @@
 }
 
 /*
+ * acpibut_detach:
+ *
+ *     Autoconfiguration `detach' routine.
+ */
+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);
+       sysmon_pswitch_unregister(&sc->sc_smpsw);
+
+       return 0;
+}
+
+/*
  * acpibut_pressed_event:
  *
  *     Deal with a button being pressed.



Home | Main Index | Thread Index | Old Index