Module Name: src Committed By: jruoho Date: Sun Jan 31 06:10:53 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_bat.c acpi_button.c Log Message: Add detachment routines. To generate a diff of this commit: cvs rdiff -u -r1.79 -r1.80 src/sys/dev/acpi/acpi_bat.c cvs rdiff -u -r1.29 -r1.30 src/sys/dev/acpi/acpi_button.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_bat.c diff -u src/sys/dev/acpi/acpi_bat.c:1.79 src/sys/dev/acpi/acpi_bat.c:1.80 --- src/sys/dev/acpi/acpi_bat.c:1.79 Wed Jan 27 22:17:28 2010 +++ src/sys/dev/acpi/acpi_bat.c Sun Jan 31 06:10:53 2010 @@ -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 Index: src/sys/dev/acpi/acpi_button.c diff -u src/sys/dev/acpi/acpi_button.c:1.29 src/sys/dev/acpi/acpi_button.c:1.30 --- src/sys/dev/acpi/acpi_button.c:1.29 Sat Jan 30 18:35:48 2010 +++ src/sys/dev/acpi/acpi_button.c Sun Jan 31 06:10:53 2010 @@ -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,13 +75,13 @@ static int acpibut_match(device_t, cfdata_t, void *); static void acpibut_attach(device_t, device_t, void *); - -CFATTACH_DECL_NEW(acpibut, sizeof(struct acpibut_softc), - acpibut_match, acpibut_attach, NULL, NULL); - +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, 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.