From: deraadt Date: Wed, 9 Feb 2022 23:54:32 +0000 (+0000) Subject: Move x86-only stubs used by kern/subr_suspend.c into dev/acpi/acpi_x86.c X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5d4cdd1c5663491423cc278cfe62d2eee2537837;p=openbsd Move x86-only stubs used by kern/subr_suspend.c into dev/acpi/acpi_x86.c for sharing between i386 and amd64. ok mlarkin kettenis --- diff --git a/sys/arch/amd64/amd64/acpi_machdep.c b/sys/arch/amd64/amd64/acpi_machdep.c index 77678779e9e..75c0b5d0482 100644 --- a/sys/arch/amd64/amd64/acpi_machdep.c +++ b/sys/arch/amd64/amd64/acpi_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_machdep.c,v 1.95 2022/02/08 17:25:10 deraadt Exp $ */ +/* $OpenBSD: acpi_machdep.c,v 1.96 2022/02/09 23:54:32 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -572,54 +572,6 @@ resume_mp(void) } #endif /* MULTIPROCESSOR */ -void -display_suspend(void *v) -{ -#if NWSDISPLAY > 0 - struct acpi_softc *sc = v; - - /* - * Temporarily release the lock to prevent the X server from - * blocking on setting the display brightness. - */ - rw_exit_write(&sc->sc_lck); - wsdisplay_suspend(); - rw_enter_write(&sc->sc_lck); -#endif /* NWSDISPLAY > 0 */ -} - -void -display_resume(void *v) -{ -#if NWSDISPLAY > 0 - struct acpi_softc *sc = v; - - rw_exit_write(&sc->sc_lck); - wsdisplay_resume(); - rw_enter_write(&sc->sc_lck); -#endif /* NWSDISPLAY > 0 */ -} - -void -suspend_finish(void *v) -{ - struct acpi_softc *sc = v; - extern int lid_action; - - acpi_record_event(sc, APM_NORMAL_RESUME); - acpi_indicator(sc, ACPI_SST_WORKING); - - /* If we woke up but all the lids are closed, go back to sleep */ - if (acpibtn_numopenlids() == 0 && lid_action != 0) - acpi_addtask(sc, acpi_sleep_task, sc, sc->sc_state); -} - -void -disable_lid_wakeups(void *v) -{ - acpibtn_disable_psw(); /* disable _LID for wakeup */ -} - #endif /* ! SMALL_KERNEL */ bus_dma_tag_t diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 7a5d40bf4cd..dbf462083ad 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $OpenBSD: files.amd64,v 1.104 2019/09/07 13:46:19 kettenis Exp $ +# $OpenBSD: files.amd64,v 1.105 2022/02/09 23:54:34 deraadt Exp $ maxpartitions 16 maxusers 2 16 128 @@ -236,6 +236,7 @@ include "dev/acpi/files.acpi" attach acpi at bios file arch/amd64/amd64/acpi_machdep.c acpi file arch/amd64/amd64/acpi_wakecode.S acpi & !small_kernel +file dev/acpi/acpi_x86.c acpi & suspend & !small_kernel device acpipci attach acpipci at acpi diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386 index 8ca2b68c46b..a68573d2ceb 100644 --- a/sys/arch/i386/conf/files.i386 +++ b/sys/arch/i386/conf/files.i386 @@ -1,4 +1,4 @@ -# $OpenBSD: files.i386,v 1.247 2022/01/02 05:32:00 jsg Exp $ +# $OpenBSD: files.i386,v 1.248 2022/02/09 23:54:34 deraadt Exp $ # # new style config file for i386 architecture # @@ -381,6 +381,7 @@ include "dev/acpi/files.acpi" attach acpi at bios file arch/i386/i386/acpi_machdep.c acpi file arch/i386/i386/acpi_wakecode.S acpi & !small_kernel +file dev/acpi/acpi_x86.c acpi & suspend & !small_kernel # # IPMI diff --git a/sys/arch/i386/i386/acpi_machdep.c b/sys/arch/i386/i386/acpi_machdep.c index 34166834b9d..75c5b9f875d 100644 --- a/sys/arch/i386/i386/acpi_machdep.c +++ b/sys/arch/i386/i386/acpi_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_machdep.c,v 1.77 2022/02/08 17:25:11 deraadt Exp $ */ +/* $OpenBSD: acpi_machdep.c,v 1.78 2022/02/09 23:54:34 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * @@ -525,54 +525,6 @@ resume_mp(void) } #endif /* MULTIPROCESSOR */ -void -display_suspend(void *v) -{ -#if NWSDISPLAY > 0 - struct acpi_softc *sc = v; - - /* - * Temporarily release the lock to prevent the X server from - * blocking on setting the display brightness. - */ - rw_exit_write(&sc->sc_lck); - wsdisplay_suspend(); - rw_enter_write(&sc->sc_lck); -#endif /* NWSDISPLAY > 0 */ -} - -void -display_resume(void *v) -{ -#if NWSDISPLAY > 0 - struct acpi_softc *sc = v; - - rw_exit_write(&sc->sc_lck); - wsdisplay_resume(); - rw_enter_write(&sc->sc_lck); -#endif /* NWSDISPLAY > 0 */ -} - -void -suspend_finish(void *v) -{ - struct acpi_softc *sc = v; - extern int lid_action; - - acpi_record_event(sc, APM_NORMAL_RESUME); - acpi_indicator(sc, ACPI_SST_WORKING); - - /* If we woke up but all the lids are closed, go back to sleep */ - if (acpibtn_numopenlids() == 0 && lid_action != 0) - acpi_addtask(sc, acpi_sleep_task, sc, sc->sc_state); -} - -void -disable_lid_wakeups(void *v) -{ - acpibtn_disable_psw(); /* disable _LID for wakeup */ -} - #endif /* ! SMALL_KERNEL */ bus_dma_tag_t diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index ebcd047d397..8cd83651f1c 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.410 2022/02/08 17:25:12 deraadt Exp $ */ +/* $OpenBSD: acpi.c,v 1.411 2022/02/09 23:54:34 deraadt Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert * Copyright (c) 2005 Jordan Hargrave @@ -3518,86 +3518,6 @@ acpikqfilter(dev_t dev, struct knote *kn) return (0); } -int -sleep_showstate(void *v, int sleepmode) -{ - struct acpi_softc *sc = v; - - switch (sleepmode) { - case SLEEP_SUSPEND: - sc->sc_state = ACPI_STATE_S3; - break; - case SLEEP_HIBERNATE: - sc->sc_state = ACPI_STATE_S4; - break; - default: - return (EOPNOTSUPP); - } - - if (sc->sc_sleeptype[sc->sc_state].slp_typa == -1 || - sc->sc_sleeptype[sc->sc_state].slp_typb == -1) { - printf("%s: state S%d unavailable\n", - sc->sc_dev.dv_xname, sc->sc_state); - return (EOPNOTSUPP); - } - - /* 1st suspend AML step: _TTS(tostate) */ - if (aml_node_setval(sc, sc->sc_tts, sc->sc_state) != 0) - return (EINVAL); - acpi_indicator(sc, ACPI_SST_WAKING); /* blink */ - return 0; -} - -int -sleep_setstate(void *v) -{ - struct acpi_softc *sc = v; - - /* 2nd suspend AML step: _PTS(tostate) */ - if (aml_node_setval(sc, sc->sc_pts, sc->sc_state) != 0) - return (EINVAL); - acpi_indicator(sc, ACPI_SST_WAKING); /* blink */ - return 0; -} - -void -gosleep(void *v) -{ - struct acpi_softc *sc = v; - - acpibtn_enable_psw(); /* enable _LID for wakeup */ - acpi_indicator(v, ACPI_SST_SLEEPING); - - /* 3rd suspend AML step: _GTS(tostate) */ - aml_node_setval(sc, sc->sc_gts, sc->sc_state); - - /* Clear fixed event status */ - acpi_write_pmreg(sc, ACPIREG_PM1_STS, 0, ACPI_PM1_ALL_STS); - - /* Enable wake GPEs */ - acpi_disable_allgpes(sc); - acpi_enable_wakegpes(sc, sc->sc_state); - - /* Sleep */ - acpi_sleep_cpu(sc, sc->sc_state); - sc->sc_state = ACPI_STATE_S0; - /* Resume */ - - acpi_resume_cpu(sc, sc->sc_state); -} - -int -sleep_resume(void *v) -{ - struct acpi_softc *sc = v; - - /* 3rd resume AML step: _TTS(runstate) */ - if (aml_node_setval(sc, sc->sc_tts, sc->sc_state) != 0) - return (EINVAL); - acpi_indicator(sc, ACPI_SST_WAKING); /* blink */ - return 0; -} - #else /* SMALL_KERNEL */ int diff --git a/sys/dev/acpi/acpi_x86.c b/sys/dev/acpi/acpi_x86.c new file mode 100644 index 00000000000..c7040d822bb --- /dev/null +++ b/sys/dev/acpi/acpi_x86.c @@ -0,0 +1,197 @@ +/* $OpenBSD: acpi_x86.c,v 1.1 2022/02/09 23:54:34 deraadt Exp $ */ +/* + * Copyright (c) 2005 Thorsten Lockert + * Copyright (c) 2005 Jordan Hargrave + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HIBERNATE +#include +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#define APMUNIT(dev) (minor(dev)&0xf0) +#define APMDEV(dev) (minor(dev)&0x0f) +#define APMDEV_NORMAL 0 +#define APMDEV_CTL 8 + +#include "wd.h" +#include "wsdisplay.h" +#include "softraid.h" + +int +sleep_showstate(void *v, int sleepmode) +{ + struct acpi_softc *sc = v; + + switch (sleepmode) { + case SLEEP_SUSPEND: + sc->sc_state = ACPI_STATE_S3; + break; + case SLEEP_HIBERNATE: + sc->sc_state = ACPI_STATE_S4; + break; + default: + return (EOPNOTSUPP); + } + + if (sc->sc_sleeptype[sc->sc_state].slp_typa == -1 || + sc->sc_sleeptype[sc->sc_state].slp_typb == -1) { + printf("%s: state S%d unavailable\n", + sc->sc_dev.dv_xname, sc->sc_state); + return (EOPNOTSUPP); + } + + /* 1st suspend AML step: _TTS(tostate) */ + if (aml_node_setval(sc, sc->sc_tts, sc->sc_state) != 0) + return (EINVAL); + acpi_indicator(sc, ACPI_SST_WAKING); /* blink */ + return 0; +} + +int +sleep_setstate(void *v) +{ + struct acpi_softc *sc = v; + + /* 2nd suspend AML step: _PTS(tostate) */ + if (aml_node_setval(sc, sc->sc_pts, sc->sc_state) != 0) + return (EINVAL); + acpi_indicator(sc, ACPI_SST_WAKING); /* blink */ + return 0; +} + +void +gosleep(void *v) +{ + struct acpi_softc *sc = v; + + acpibtn_enable_psw(); /* enable _LID for wakeup */ + acpi_indicator(v, ACPI_SST_SLEEPING); + + /* 3rd suspend AML step: _GTS(tostate) */ + aml_node_setval(sc, sc->sc_gts, sc->sc_state); + + /* Clear fixed event status */ + acpi_write_pmreg(sc, ACPIREG_PM1_STS, 0, ACPI_PM1_ALL_STS); + + /* Enable wake GPEs */ + acpi_disable_allgpes(sc); + acpi_enable_wakegpes(sc, sc->sc_state); + + /* Sleep */ + acpi_sleep_cpu(sc, sc->sc_state); + sc->sc_state = ACPI_STATE_S0; + /* Resume */ + + acpi_resume_cpu(sc, sc->sc_state); +} + +int +sleep_resume(void *v) +{ + struct acpi_softc *sc = v; + + /* 3rd resume AML step: _TTS(runstate) */ + if (aml_node_setval(sc, sc->sc_tts, sc->sc_state) != 0) + return (EINVAL); + acpi_indicator(sc, ACPI_SST_WAKING); /* blink */ + return 0; +} + +void +suspend_finish(void *v) +{ + struct acpi_softc *sc = v; + extern int lid_action; + + acpi_record_event(sc, APM_NORMAL_RESUME); + acpi_indicator(sc, ACPI_SST_WORKING); + + /* If we woke up but all the lids are closed, go back to sleep */ + if (acpibtn_numopenlids() == 0 && lid_action != 0) + acpi_addtask(sc, acpi_sleep_task, sc, sc->sc_state); +} + +void +disable_lid_wakeups(void *v) +{ + acpibtn_disable_psw(); /* disable _LID for wakeup */ + +} + +void +display_suspend(void *v) +{ +#if NWSDISPLAY > 0 + struct acpi_softc *sc = v; + + /* + * Temporarily release the lock to prevent the X server from + * blocking on setting the display brightness. + */ + rw_exit_write(&sc->sc_lck); + wsdisplay_suspend(); + rw_enter_write(&sc->sc_lck); +#endif /* NWSDISPLAY > 0 */ +} + +void +display_resume(void *v) +{ +#if NWSDISPLAY > 0 + struct acpi_softc *sc = v; + + rw_exit_write(&sc->sc_lck); + wsdisplay_resume(); + rw_enter_write(&sc->sc_lck); +#endif /* NWSDISPLAY > 0 */ +}