diff options
author | Tobias Heider <tobhe@cvs.openbsd.org> | 2023-07-08 14:44:44 +0000 |
---|---|---|
committer | Tobias Heider <tobhe@cvs.openbsd.org> | 2023-07-08 14:44:44 +0000 |
commit | 8163e19f9a6ab10accf9bbc5f6656b7800ef3dd6 (patch) | |
tree | 3cc0ded9ba8eb3293000071826f221153acc367c /sys/arch | |
parent | 013bd17c801c00548e1f5ca78fb83833c1404040 (diff) |
Adds request_sleep(), a MI way of sending the machine to sleep in
a safe thread. Support is limited to amd64, i386 and arm64 at the
moment, macppc gets only an empty stub.
feedback from kettenis@
tested by bluhm@
ok phessler@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/arm64/dev/aplsmc.c | 5 | ||||
-rw-r--r-- | sys/arch/arm64/dev/apm.c | 51 | ||||
-rw-r--r-- | sys/arch/macppc/dev/apm.c | 8 |
3 files changed, 47 insertions, 17 deletions
diff --git a/sys/arch/arm64/dev/aplsmc.c b/sys/arch/arm64/dev/aplsmc.c index 63d45d3697e..4b8d8cc2a03 100644 --- a/sys/arch/arm64/dev/aplsmc.c +++ b/sys/arch/arm64/dev/aplsmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aplsmc.c,v 1.23 2023/05/29 04:24:39 deraadt Exp $ */ +/* $OpenBSD: aplsmc.c,v 1.24 2023/07/08 14:44:43 tobhe Exp $ */ /* * Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org> * @@ -366,7 +366,6 @@ aplsmc_handle_notification(struct aplsmc_softc *sc, uint64_t data) extern int allowpowerdown; #ifdef SUSPEND extern int cpu_suspended; - extern void suspend(void); if (cpu_suspended) { switch (SMC_EV_TYPE(data)) { @@ -433,7 +432,7 @@ aplsmc_handle_notification(struct aplsmc_softc *sc, uint64_t data) } case 1: #ifdef SUSPEND - suspend(); + request_sleep(SLEEP_SUSPEND); #endif break; case 2: diff --git a/sys/arch/arm64/dev/apm.c b/sys/arch/arm64/dev/apm.c index 2ccc8229914..903b35535be 100644 --- a/sys/arch/arm64/dev/apm.c +++ b/sys/arch/arm64/dev/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.23 2023/07/05 08:26:56 tobhe Exp $ */ +/* $OpenBSD: apm.c,v 1.24 2023/07/08 14:44:43 tobhe Exp $ */ /*- * Copyright (c) 2001 Alexander Guy. All rights reserved. @@ -57,10 +57,13 @@ #endif #ifdef SUSPEND -struct taskq *suspend_taskq; +struct taskq *sleep_taskq; struct task suspend_task; void do_suspend(void *); -void suspend(void); +#ifdef HIBERNATE +struct task hibernate_task; +void do_hibernate(void *); +#endif #endif struct apm_softc { @@ -128,8 +131,11 @@ void apmattach(struct device *parent, struct device *self, void *aux) { #ifdef SUSPEND - suspend_taskq = taskq_create("suspend", 1, IPL_NONE, 0); + sleep_taskq = taskq_create("sleep", 1, IPL_NONE, 0); task_set(&suspend_task, do_suspend, NULL); +#ifdef HIBERNATE + task_set(&hibernate_task, do_hibernate, NULL); +#endif #endif acpiapm_open = apmopen; @@ -224,7 +230,7 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) error = EBADF; break; } - suspend(); + error = request_sleep(SLEEP_SUSPEND); break; #ifdef HIBERNATE case APM_IOC_HIBERNATE: @@ -234,11 +240,7 @@ apmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) error = EBADF; break; } - if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL) { - error = EOPNOTSUPP; - break; - } - sleep_state(NULL, SLEEP_HIBERNATE); + error = request_sleep(SLEEP_HIBERNATE); break; #endif #endif @@ -358,11 +360,34 @@ do_suspend(void *v) sleep_state(v, SLEEP_SUSPEND); } +#ifdef HIBERNATE void -suspend(void) +do_hibernate(void *v) +{ + sleep_state(v, SLEEP_HIBERNATE); +} +#endif + +int +request_sleep(int sleepmode) { - if (suspend_taskq) - task_add(suspend_taskq, &suspend_task); + if (sleep_taskq == NULL) + return EINVAL; + + switch (sleepmode) { + case SLEEP_SUSPEND: + task_add(sleep_taskq, &suspend_task); + break; +#ifdef HIBERNATE + case SLEEP_HIBERNATE: + if (get_hibernate_io_function(swdevt[0].sw_dev) == NULL) + return EOPNOTSUPP; + task_add(sleep_taskq, &hibernate_task); + break; +#endif + } + + return 0; } #ifdef MULTIPROCESSOR diff --git a/sys/arch/macppc/dev/apm.c b/sys/arch/macppc/dev/apm.c index 9082d868f96..d64203d8fad 100644 --- a/sys/arch/macppc/dev/apm.c +++ b/sys/arch/macppc/dev/apm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apm.c,v 1.34 2022/10/23 03:43:03 gkoehler Exp $ */ +/* $OpenBSD: apm.c,v 1.35 2023/07/08 14:44:43 tobhe Exp $ */ /*- * Copyright (c) 2001 Alexander Guy. All rights reserved. @@ -337,6 +337,12 @@ apmkqfilter(dev_t dev, struct knote *kn) #ifdef SUSPEND +int +request_sleep(int sleepmode) +{ + return EOPNOTSUPP; +} + #ifdef MULTIPROCESSOR void |