From: cheloha Date: Tue, 8 Nov 2022 14:46:51 +0000 (+0000) Subject: amd64: add delay_fini() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=040db72ba29053e5c7f852cb645ec9cb932011b4;p=openbsd amd64: add delay_fini() Not all of the clocks with a delay(9) implementation necessarily keep ticking across suspend/resume. We need a clean way to reverse delay_init() during suspend when those clocks stop ticking. Hence, delay_fini(). delay_fini() resets delay_func() to i8254_delay() if the given function pointer is the active delay(9) implementation. ok mlarkin@ --- diff --git a/sys/arch/amd64/amd64/machdep.c b/sys/arch/amd64/amd64/machdep.c index b733ce6575f..06acb920ebe 100644 --- a/sys/arch/amd64/amd64/machdep.c +++ b/sys/arch/amd64/amd64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.282 2022/10/30 17:43:39 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.283 2022/11/08 14:46:51 cheloha Exp $ */ /* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */ /*- @@ -2073,12 +2073,22 @@ check_context(const struct reg *regs, struct trapframe *tf) return 0; } +int amd64_delay_quality; + void delay_init(void(*fn)(int), int fn_quality) { - static int cur_quality = 0; - if (fn_quality > cur_quality) { + if (fn_quality > amd64_delay_quality) { delay_func = fn; - cur_quality = fn_quality; + amd64_delay_quality = fn_quality; + } +} + +void +delay_fini(void (*fn)(int)) +{ + if (fn == delay_func) { + delay_func = i8254_delay; + amd64_delay_quality = 0; } } diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 1a8c6ddb7b9..d5ce2f5d717 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.151 2022/09/20 14:28:27 robert Exp $ */ +/* $OpenBSD: cpu.h,v 1.152 2022/11/08 14:46:51 cheloha Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -360,6 +360,7 @@ void signotify(struct proc *); * We need a machine-independent name for this. */ extern void (*delay_func)(int); +void delay_fini(void (*)(int)); void delay_init(void (*)(int), int); struct timeval;