diff options
| author | thorpej <thorpej@NetBSD.org> | 2003-04-17 01:22:21 +0000 |
|---|---|---|
| committer | thorpej <thorpej@NetBSD.org> | 2003-04-17 01:22:21 +0000 |
| commit | 59ea64b6f022264a70cba0329917c822b2af7a7b (patch) | |
| tree | c05190dd43d97ce62319d31deb40d96052bf3ea8 /sys/dev/acpi | |
| parent | b0f79c65ce645bb1a568b453d485eb67704d647b (diff) | |
* Don't do the ACPI_PCI_FIXUP unless it is explicitly enabled in
the kernel config file. That code makes a total mess of any
system with multiple PCI busses.
* Rework the way buttons are handled; register them with sysmon,
and let it take the appropriate action. This lets us gracefully
shut down when the power button is pressed.
Diffstat (limited to 'sys/dev/acpi')
| -rw-r--r-- | sys/dev/acpi/acpi.c | 127 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_button.c | 65 | ||||
| -rw-r--r-- | sys/dev/acpi/acpivar.h | 10 | ||||
| -rw-r--r-- | sys/dev/acpi/files.acpi | 6 |
4 files changed, 108 insertions, 100 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 42698aef517..e3410e6bef9 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,7 +1,7 @@ -/* $NetBSD: acpi.c,v 1.33 2003/03/05 23:00:56 christos Exp $ */ +/* $NetBSD: acpi.c,v 1.34 2003/04/17 01:22:21 thorpej Exp $ */ /* - * Copyright 2001 Wasabi Systems, Inc. + * Copyright 2001, 2003 Wasabi Systems, Inc. * All rights reserved. * * Written by Jason R. Thorpe for Wasabi Systems, Inc. @@ -41,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.33 2003/03/05 23:00:56 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.34 2003/04/17 01:22:21 thorpej Exp $"); #include "opt_acpi.h" @@ -60,15 +60,11 @@ __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.33 2003/03/05 23:00:56 christos Exp $"); #include <dev/acpi/acpidevs_data.h> #endif -#ifndef ACPI_PCI_FIXUP -#define ACPI_PCI_FIXUP 1 -#endif - #ifndef ACPI_ACTIVATE_DEV #define ACPI_ACTIVATE_DEV 0 #endif -#if ACPI_PCI_FIXUP +#ifdef ACPI_PCI_FIXUP #include <dev/acpi/acpica/Subsystem/acnamesp.h> /* AcpiNsGetNodeByPath() */ #include <dev/pci/pcidevs.h> #endif @@ -125,10 +121,10 @@ void acpi_build_tree(struct acpi_softc *); ACPI_STATUS acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **); void acpi_enable_fixed_events(struct acpi_softc *); -#if ACPI_PCI_FIXUP +#ifdef ACPI_PCI_FIXUP void acpi_pci_fixup(struct acpi_softc *); #endif -#if ACPI_PCI_FIXUP || ACPI_ACTIVATE_DEV +#if defined(ACPI_PCI_FIXUP) || ACPI_ACTIVATE_DEV ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE handle); #endif @@ -291,14 +287,6 @@ acpi_attach(struct device *parent, struct device *self, void *aux) } acpi_active = 1; - /* - * Set up the default sleep state to enter when various - * switches are activated. - */ - sc->sc_switch_sleep[ACPI_SWITCH_POWERBUTTON] = ACPI_STATE_S5; - sc->sc_switch_sleep[ACPI_SWITCH_SLEEPBUTTON] = ACPI_STATE_S1; - sc->sc_switch_sleep[ACPI_SWITCH_LID] = ACPI_STATE_S1; - /* Our current state is "awake". */ sc->sc_sleepstate = ACPI_STATE_S0; @@ -314,7 +302,7 @@ acpi_attach(struct device *parent, struct device *self, void *aux) /* * Fix up PCI devices. */ -#if ACPI_PCI_FIXUP +#ifdef ACPI_PCI_FIXUP acpi_pci_fixup(sc); #endif @@ -640,8 +628,8 @@ acpi_print(void *aux, const char *pnp) * ACPI fixed-hardware feature handlers *****************************************************************************/ -UINT32 acpi_fixed_power_button_handler(void *); -UINT32 acpi_fixed_sleep_button_handler(void *); +UINT32 acpi_fixed_button_handler(void *); +void acpi_fixed_button_pressed(void *); /* * acpi_enable_fixed_events: @@ -654,67 +642,94 @@ acpi_enable_fixed_events(struct acpi_softc *sc) static int beenhere; ACPI_STATUS rv; + KASSERT(beenhere == 0); + beenhere = 1; + /* * Check for fixed-hardware buttons. */ if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->PwrButton == 0) { - if (beenhere == 0) - printf("%s: fixed-feature power button present\n", - sc->sc_dev.dv_xname); - rv = AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON, - acpi_fixed_power_button_handler, sc); - if (rv != AE_OK) - printf("%s: unable to install handler for fixed " - "power button: %d\n", sc->sc_dev.dv_xname, rv); + printf("%s: fixed-feature power button present\n", + sc->sc_dev.dv_xname); + sc->sc_smpsw_power.smpsw_name = sc->sc_dev.dv_xname; + sc->sc_smpsw_power.smpsw_type = SMPSW_TYPE_POWER; + if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) { + printf("%s: unable to register fixed power button " + "with sysmon\n", sc->sc_dev.dv_xname); + } else { + rv = AcpiInstallFixedEventHandler( + ACPI_EVENT_POWER_BUTTON, + acpi_fixed_button_handler, &sc->sc_smpsw_power); + if (rv != AE_OK) { + printf("%s: unable to install handler for " + "fixed power button: %d\n", + sc->sc_dev.dv_xname, rv); + } + } } if (AcpiGbl_FADT != NULL && AcpiGbl_FADT->SleepButton == 0) { - if (beenhere == 0) - printf("%s: fixed-feature sleep button present\n", - sc->sc_dev.dv_xname); - rv = AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON, - acpi_fixed_sleep_button_handler, sc); - if (rv != AE_OK) - printf("%s: unable to install handler for fixed " - "power button: %d\n", sc->sc_dev.dv_xname, rv); + printf("%s: fixed-feature sleep button present\n", + sc->sc_dev.dv_xname); + sc->sc_smpsw_sleep.smpsw_name = sc->sc_dev.dv_xname; + sc->sc_smpsw_sleep.smpsw_type = SMPSW_TYPE_SLEEP; + if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) { + printf("%s: unable to register fixed sleep button " + "with sysmon\n", sc->sc_dev.dv_xname); + } else { + rv = AcpiInstallFixedEventHandler( + ACPI_EVENT_SLEEP_BUTTON, + acpi_fixed_button_handler, &sc->sc_smpsw_sleep); + if (rv != AE_OK) { + printf("%s: unable to install handler for " + "fixed sleep button: %d\n", + sc->sc_dev.dv_xname, rv); + } + } } - - beenhere = 1; } /* - * acpi_fixed_power_button_handler: + * acpi_fixed_button_handler: * - * Fixed event handler for the power button. + * Event handler for the fixed buttons. */ UINT32 -acpi_fixed_power_button_handler(void *context) +acpi_fixed_button_handler(void *context) { - struct acpi_softc *sc = context; + struct sysmon_pswitch *smpsw = context; + int rv; - /* XXX XXX XXX */ +#ifdef ACPI_BUT_DEBUG + printf("%s: fixed button handler\n", smpsw->smpsw_name); +#endif - printf("%s: fixed power button pressed\n", sc->sc_dev.dv_xname); + rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO, + acpi_fixed_button_pressed, smpsw); + if (rv != AE_OK) + printf("%s: WARNING: unable to queue fixed button pressed " + "callback: %d\n", smpsw->smpsw_name, rv); return (ACPI_INTERRUPT_HANDLED); } /* - * acpi_fixed_sleep_button_handler: + * acpi_fixed_button_pressed: * - * Fixed event handler for the sleep button. + * Deal with a fixed button being pressed. */ -UINT32 -acpi_fixed_sleep_button_handler(void *context) +void +acpi_fixed_button_pressed(void *context) { - struct acpi_softc *sc = context; + struct sysmon_pswitch *smpsw = context; - /* XXX XXX XXX */ - - printf("%s: fixed sleep button pressed\n", sc->sc_dev.dv_xname); +#ifdef ACPI_BUT_DEBUG + printf("%s: fixed button pressed, calling sysmon\n", + smpsw->smpsw_name); +#endif - return (ACPI_INTERRUPT_HANDLED); + sysmon_pswitch_event(smpsw, SMPSW_EVENT_PRESSED); } /***************************************************************************** @@ -986,7 +1001,7 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state) return (ret); } -#if ACPI_PCI_FIXUP +#ifdef ACPI_PCI_FIXUP ACPI_STATUS acpi_pci_fixup_bus(ACPI_HANDLE, UINT32, void *, void **); /* * acpi_pci_fixup: @@ -1193,7 +1208,7 @@ acpi_pci_fixup_bus(ACPI_HANDLE handle, UINT32 level, void *context, } #endif /* ACPI_PCI_FIXUP */ -#if ACPI_PCI_FIXUP || ACPI_ACTIVATE_DEV +#if defined(ACPI_PCI_FIXUP) || ACPI_ACTIVATE_DEV /* XXX This very incomplete */ ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE handle) diff --git a/sys/dev/acpi/acpi_button.c b/sys/dev/acpi/acpi_button.c index d9396fd1d3b..beee1228a98 100644 --- a/sys/dev/acpi/acpi_button.c +++ b/sys/dev/acpi/acpi_button.c @@ -1,7 +1,8 @@ -/* $NetBSD: acpi_button.c,v 1.6 2002/10/02 16:33:36 thorpej Exp $ */ +#define ACPI_BUT_DEBUG +/* $NetBSD: acpi_button.c,v 1.7 2003/04/17 01:22:21 thorpej Exp $ */ /* - * Copyright 2001 Wasabi Systems, Inc. + * Copyright 2001, 2003 Wasabi Systems, Inc. * All rights reserved. * * Written by Jason R. Thorpe for Wasabi Systems, Inc. @@ -40,7 +41,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.6 2002/10/02 16:33:36 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.7 2003/04/17 01:22:21 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -50,16 +51,15 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.6 2002/10/02 16:33:36 thorpej Exp #include <dev/acpi/acpireg.h> #include <dev/acpi/acpivar.h> +#include <dev/sysmon/sysmonvar.h> + struct acpibut_softc { struct device sc_dev; /* base device glue */ struct acpi_devnode *sc_node; /* our ACPI devnode */ - int sc_buttype; /* button type */ + struct sysmon_pswitch sc_smpsw; /* our sysmon glue */ int sc_flags; /* see below */ }; -#define ACPIBUT_TYPE_POWER 0 -#define ACPIBUT_TYPE_SLEEP 1 - #define ACPIBUT_F_VERBOSE 0x01 /* verbose events */ int acpibut_match(struct device *, struct cfdata *, void *); @@ -68,8 +68,7 @@ void acpibut_attach(struct device *, struct device *, void *); CFATTACH_DECL(acpibut, sizeof(struct acpibut_softc), acpibut_match, acpibut_attach, NULL, NULL); -void acpibut_pressed_for_sleep(void *); -void acpibut_pressed_for_wakeup(void *); +void acpibut_pressed_event(void *); void acpibut_notify_handler(ACPI_HANDLE, UINT32, void *context); /* @@ -105,11 +104,13 @@ acpibut_attach(struct device *parent, struct device *self, void *aux) const char *desc; ACPI_STATUS rv; + sc->sc_smpsw.smpsw_name = sc->sc_dev.dv_xname; + if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0C") == 0) { - sc->sc_buttype = ACPIBUT_TYPE_POWER; + sc->sc_smpsw.smpsw_type = SMPSW_TYPE_POWER; desc = "Power"; } else if (strcmp(aa->aa_node->ad_devinfo.HardwareId, "PNP0C0E") == 0) { - sc->sc_buttype = ACPIBUT_TYPE_SLEEP; + sc->sc_smpsw.smpsw_type = SMPSW_TYPE_SLEEP; desc = "Sleep"; } else { printf("\n"); @@ -120,6 +121,12 @@ acpibut_attach(struct device *parent, struct device *self, void *aux) sc->sc_node = aa->aa_node; + if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) { + printf("%s: unable to register with sysmon\n", + sc->sc_dev.dv_xname); + return; + } + rv = AcpiInstallNotifyHandler(sc->sc_node->ad_handle, ACPI_DEVICE_NOTIFY, acpibut_notify_handler, sc); if (rv != AE_OK) { @@ -135,41 +142,19 @@ acpibut_attach(struct device *parent, struct device *self, void *aux) } /* - * acpibut_pressed_for_sleep: - * - * Deal with a button being pressed for sleep. - */ -void -acpibut_pressed_for_sleep(void *arg) -{ - struct acpibut_softc *sc = arg; - - if (sc->sc_flags & ACPIBUT_F_VERBOSE) - printf("%s: button pressed for sleep\n", - sc->sc_dev.dv_xname); - - /* - * XXX Perform the appropriate action. - */ -} - -/* - * acpibut_pressed_for_wakeup: + * acpibut_pressed_event: * - * Deal with a button being pressed for wakeup. + * Deal with a button being pressed. */ void -acpibut_pressed_for_wakeup(void *arg) +acpibut_pressed_event(void *arg) { struct acpibut_softc *sc = arg; if (sc->sc_flags & ACPIBUT_F_VERBOSE) - printf("%s: button pressed for wakeup\n", - sc->sc_dev.dv_xname); + printf("%s: button pressed\n", sc->sc_dev.dv_xname); - /* - * XXX Perform the appropriate action. - */ + sysmon_pswitch_event(&sc->sc_smpsw, SMPSW_EVENT_PRESSED); } /* @@ -193,10 +178,10 @@ acpibut_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context) sc->sc_dev.dv_xname); #endif rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO, - acpibut_pressed_for_sleep, sc); + acpibut_pressed_event, sc); if (rv != AE_OK) printf("%s: WARNING: unable to queue button pressed " - "event: %d\n", sc->sc_dev.dv_xname, rv); + "callback: %d\n", sc->sc_dev.dv_xname, rv); break; /* XXX ACPI_NOTIFY_DeviceWake?? */ diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index 38bb8589f68..8400813bc11 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: acpivar.h,v 1.9 2003/02/14 11:05:40 tshiozak Exp $ */ +/* $NetBSD: acpivar.h,v 1.10 2003/04/17 01:22:21 thorpej Exp $ */ /* * Copyright 2001 Wasabi Systems, Inc. @@ -47,6 +47,8 @@ #include <dev/acpi/acpica.h> +#include <dev/sysmon/sysmonvar.h> + /* * acpibus_attach_args: * @@ -115,6 +117,12 @@ struct acpi_softc { void *sc_sdhook; /* shutdown hook */ /* + * Power switch handlers for fixed-feature buttons. + */ + struct sysmon_pswitch sc_smpsw_power; + struct sysmon_pswitch sc_smpsw_sleep; + + /* * Sleep state to transition to when a given * switch is activated. */ diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index b9fc95f17fd..a58333d7b98 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $NetBSD: files.acpi,v 1.16 2003/01/12 01:15:50 christos Exp $ +# $NetBSD: files.acpi,v 1.17 2003/04/17 01:22:21 thorpej Exp $ include "dev/acpi/acpica/files.acpica" @@ -16,12 +16,12 @@ attach acpiec at acpi file dev/acpi/acpi_ec.c acpiec # ACPI Lid Switch -device acpilid +device acpilid: sysmon_power attach acpilid at acpi file dev/acpi/acpi_lid.c acpilid # ACPI Button -device acpibut +device acpibut: sysmon_power attach acpibut at acpi file dev/acpi/acpi_button.c acpibut |
