From 35d27a0f39e3f560673f0a6e1029236bd30dbf15 Mon Sep 17 00:00:00 2001 From: Mike Smith Date: Fri, 30 Oct 1998 05:41:15 +0000 Subject: [PATCH] Add the ability to specify where on the at_shutdown queue a handler is installed. Remove cpu_power_down, and replace it with an entry at the end of the SHUTDOWN_FINAL queue in the only place it's used (APM). Submitted by: Some ideas from Bruce Walter --- sys/alpha/alpha/machdep.c | 11 +---------- sys/alpha/include/md_var.h | 3 +-- sys/amd64/amd64/machdep.c | 16 +-------------- sys/amd64/include/md_var.h | 3 +-- sys/i386/apm/apm.c | 13 ++++++++---- sys/i386/bios/apm.c | 13 ++++++++---- sys/i386/i386/machdep.c | 16 +-------------- sys/i386/include/apm_bios.h | 3 +-- sys/i386/include/md_var.h | 3 +-- sys/kern/kern_shutdown.c | 38 +++++++++++++++++++++++++++++++----- sys/powerpc/include/md_var.h | 3 +-- sys/sys/systm.h | 6 +++++- 12 files changed, 64 insertions(+), 64 deletions(-) diff --git a/sys/alpha/alpha/machdep.c b/sys/alpha/alpha/machdep.c index 6d35e8a4f371..93744448e726 100644 --- a/sys/alpha/alpha/machdep.c +++ b/sys/alpha/alpha/machdep.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: machdep.c,v 1.17 1998/10/14 10:08:35 peter Exp $ + * $Id: machdep.c,v 1.18 1998/10/15 22:00:54 dfr Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -1389,15 +1389,6 @@ cpu_halt(void) alpha_pal_halt(); } -/* - * Turn the power off. - */ -void -cpu_power_down(void) -{ - alpha_pal_halt(); /* XXX */ -} - /* * Clear registers on exec */ diff --git a/sys/alpha/include/md_var.h b/sys/alpha/include/md_var.h index b3925f7474c4..c8db0523ed91 100644 --- a/sys/alpha/include/md_var.h +++ b/sys/alpha/include/md_var.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: md_var.h,v 1.3 1998/09/14 22:43:24 jdp Exp $ + * $Id: md_var.h,v 1.4 1998/09/26 12:22:53 dfr Exp $ */ #ifndef _MACHINE_MD_VAR_H_ @@ -44,7 +44,6 @@ struct proc; struct reg; struct cam_sim; -void cpu_power_down __P((void)); void cpu_halt __P((void)); void cpu_reset __P((void)); int is_physical_memory __P((vm_offset_t addr)); diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 06db0703bc20..fd58e5a6b9cb 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.312 1998/10/09 00:31:06 msmith Exp $ + * $Id: machdep.c,v 1.313 1998/10/09 23:36:26 peter Exp $ */ #include "apm.h" @@ -109,9 +109,6 @@ #include #endif -#if NAPM > 0 -#include -#endif #include #include #include @@ -793,17 +790,6 @@ cpu_halt(void) __asm__ ("hlt"); } -/* - * Turn the power off. - */ -void -cpu_power_down(void) -{ -#if NAPM > 0 - apm_power_off(); -#endif -} - /* * Clear registers on exec */ diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h index a56526678345..82a43348e905 100644 --- a/sys/amd64/include/md_var.h +++ b/sys/amd64/include/md_var.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: md_var.h,v 1.25 1998/09/14 22:43:40 jdp Exp $ + * $Id: md_var.h,v 1.26 1998/09/25 17:34:49 peter Exp $ */ #ifndef _MACHINE_MD_VAR_H_ @@ -62,7 +62,6 @@ struct fpreg; void bcopyb __P((const void *from, void *to, size_t len)); void busdma_swi __P((void)); void cpu_halt __P((void)); -void cpu_power_down __P((void)); void cpu_reset __P((void)); void cpu_switch_load_fs __P((void)) __asm(__STRING(cpu_switch_load_fs)); void cpu_switch_load_gs __P((void)) __asm(__STRING(cpu_switch_load_gs)); diff --git a/sys/i386/apm/apm.c b/sys/i386/apm/apm.c index c871151c7ae0..ffe4b0a95b3a 100644 --- a/sys/i386/apm/apm.c +++ b/sys/i386/apm/apm.c @@ -15,7 +15,7 @@ * * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * - * $Id: apm.c,v 1.73 1998/07/06 06:29:03 imp Exp $ + * $Id: apm.c,v 1.74 1998/09/28 03:41:12 jlemon Exp $ */ #include "opt_devfs.h" @@ -29,6 +29,7 @@ #endif /*DEVFS*/ #include #include +#include #include #include #include @@ -245,12 +246,13 @@ apm_display(int newstate) /* * Turn off the entire system. */ -void -apm_power_off(void) +static void +apm_power_off(int howto, void *junk) { u_long eax, ebx, ecx, edx; - if (!apm_softc.active) + /* Not halting, or not active */ + if (!(howto & RB_HALT) || !apm_softc.active) return; eax = (APM_BIOS << 8) | APM_SETPWSTATE; ebx = PMDV_ALLDEV; @@ -903,6 +905,9 @@ apmattach(struct isa_device *dvp) apm_event_enable(); + /* Power the system off using APM */ + at_shutdown_pri(apm_power_off, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_LAST); + sc->initialized = 1; #ifdef DEVFS diff --git a/sys/i386/bios/apm.c b/sys/i386/bios/apm.c index c871151c7ae0..ffe4b0a95b3a 100644 --- a/sys/i386/bios/apm.c +++ b/sys/i386/bios/apm.c @@ -15,7 +15,7 @@ * * Sep, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * - * $Id: apm.c,v 1.73 1998/07/06 06:29:03 imp Exp $ + * $Id: apm.c,v 1.74 1998/09/28 03:41:12 jlemon Exp $ */ #include "opt_devfs.h" @@ -29,6 +29,7 @@ #endif /*DEVFS*/ #include #include +#include #include #include #include @@ -245,12 +246,13 @@ apm_display(int newstate) /* * Turn off the entire system. */ -void -apm_power_off(void) +static void +apm_power_off(int howto, void *junk) { u_long eax, ebx, ecx, edx; - if (!apm_softc.active) + /* Not halting, or not active */ + if (!(howto & RB_HALT) || !apm_softc.active) return; eax = (APM_BIOS << 8) | APM_SETPWSTATE; ebx = PMDV_ALLDEV; @@ -903,6 +905,9 @@ apmattach(struct isa_device *dvp) apm_event_enable(); + /* Power the system off using APM */ + at_shutdown_pri(apm_power_off, NULL, SHUTDOWN_FINAL, SHUTDOWN_PRI_LAST); + sc->initialized = 1; #ifdef DEVFS diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index 06db0703bc20..fd58e5a6b9cb 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.312 1998/10/09 00:31:06 msmith Exp $ + * $Id: machdep.c,v 1.313 1998/10/09 23:36:26 peter Exp $ */ #include "apm.h" @@ -109,9 +109,6 @@ #include #endif -#if NAPM > 0 -#include -#endif #include #include #include @@ -793,17 +790,6 @@ cpu_halt(void) __asm__ ("hlt"); } -/* - * Turn the power off. - */ -void -cpu_power_down(void) -{ -#if NAPM > 0 - apm_power_off(); -#endif -} - /* * Clear registers on exec */ diff --git a/sys/i386/include/apm_bios.h b/sys/i386/include/apm_bios.h index 616e36a2e894..43028b370113 100644 --- a/sys/i386/include/apm_bios.h +++ b/sys/i386/include/apm_bios.h @@ -12,7 +12,7 @@ * * Aug, 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) * - * $Id: apm_bios.h,v 1.19 1997/11/12 04:12:51 jdp Exp $ + * $Id: apm_bios.h,v 1.20 1998/07/06 06:29:05 imp Exp $ */ #ifndef _MACHINE_APM_BIOS_H_ @@ -160,7 +160,6 @@ struct apmhook *apm_hook_establish (int apmh, struct apmhook *); void apm_hook_disestablish (int apmh, struct apmhook *); void apm_cpu_idle(void); void apm_cpu_busy(void); -void apm_power_off(void); #endif /* KERNEL */ diff --git a/sys/i386/include/md_var.h b/sys/i386/include/md_var.h index a56526678345..82a43348e905 100644 --- a/sys/i386/include/md_var.h +++ b/sys/i386/include/md_var.h @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: md_var.h,v 1.25 1998/09/14 22:43:40 jdp Exp $ + * $Id: md_var.h,v 1.26 1998/09/25 17:34:49 peter Exp $ */ #ifndef _MACHINE_MD_VAR_H_ @@ -62,7 +62,6 @@ struct fpreg; void bcopyb __P((const void *from, void *to, size_t len)); void busdma_swi __P((void)); void cpu_halt __P((void)); -void cpu_power_down __P((void)); void cpu_reset __P((void)); void cpu_switch_load_fs __P((void)) __asm(__STRING(cpu_switch_load_fs)); void cpu_switch_load_gs __P((void)) __asm(__STRING(cpu_switch_load_gs)); diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index ff6997ce43d2..8a327a277508 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 - * $Id: kern_shutdown.c,v 1.39 1998/09/15 08:49:52 gibbs Exp $ + * $Id: kern_shutdown.c,v 1.40 1998/09/20 16:50:31 dt Exp $ */ #include "opt_ddb.h" @@ -111,6 +111,7 @@ typedef struct shutdown_list_element { LIST_ENTRY(shutdown_list_element) links; bootlist_fn function; void *arg; + int priority; } *sle_p; /* @@ -275,7 +276,6 @@ boot(howto) (*ep->function)(howto, ep->arg); if (howto & RB_HALT) { - cpu_power_down(); printf("\n"); printf("The operating system has halted.\n"); printf("Please press any key to reboot.\n\n"); @@ -431,7 +431,7 @@ panic(const char *fmt, ...) } /* - * Two routines to handle adding/deleting items on the + * Three routines to handle adding/deleting items on the * shutdown callout lists * * at_shutdown(): @@ -442,7 +442,19 @@ panic(const char *fmt, ...) int at_shutdown(bootlist_fn function, void *arg, int queue) { - sle_p ep; + return(at_shutdown_pri(function, arg, queue, SHUTDOWN_PRI_DEFAULT)); +} + +/* + * at_shutdown_pri(): + * Take the arguments given and put them onto the shutdown callout list + * with the given execution priority. + * returns 0 on success. + */ +int +at_shutdown_pri(bootlist_fn function, void *arg, int queue, int pri) +{ + sle_p ep, ip; if (queue < SHUTDOWN_PRE_SYNC || queue > SHUTDOWN_FINAL) { @@ -457,7 +469,23 @@ at_shutdown(bootlist_fn function, void *arg, int queue) return (ENOMEM); ep->function = function; ep->arg = arg; - LIST_INSERT_HEAD(&shutdown_lists[queue], ep, links); + ep->priority = pri; + + /* Sort into list of items on this queue */ + ip = LIST_FIRST(&shutdown_lists[queue]); + if (ip == NULL) { + LIST_INSERT_HEAD(&shutdown_lists[queue], ep, links); + } else { + for (; LIST_NEXT(ip, links) != NULL; ip = LIST_NEXT(ip, links)) { + if (ep->priority < ip->priority) { + LIST_INSERT_BEFORE(ip, ep, links); + ep = NULL; + break; + } + } + if (ep != NULL) + LIST_INSERT_AFTER(ip, ep, links); + } return (0); } diff --git a/sys/powerpc/include/md_var.h b/sys/powerpc/include/md_var.h index b3925f7474c4..c8db0523ed91 100644 --- a/sys/powerpc/include/md_var.h +++ b/sys/powerpc/include/md_var.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: md_var.h,v 1.3 1998/09/14 22:43:24 jdp Exp $ + * $Id: md_var.h,v 1.4 1998/09/26 12:22:53 dfr Exp $ */ #ifndef _MACHINE_MD_VAR_H_ @@ -44,7 +44,6 @@ struct proc; struct reg; struct cam_sim; -void cpu_power_down __P((void)); void cpu_halt __P((void)); void cpu_reset __P((void)); int is_physical_memory __P((vm_offset_t addr)); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 2b3236ad5f9a..072dc35f28b6 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)systm.h 8.7 (Berkeley) 3/29/95 - * $Id: systm.h,v 1.76 1998/09/15 10:07:26 gibbs Exp $ + * $Id: systm.h,v 1.77 1998/10/09 01:44:09 msmith Exp $ */ #ifndef _SYS_SYSTM_H_ @@ -267,10 +267,14 @@ int rm_at_fork __P((forklist_fn function)); #define SHUTDOWN_PRE_SYNC 0 #define SHUTDOWN_POST_SYNC 1 #define SHUTDOWN_FINAL 2 +#define SHUTDOWN_PRI_FIRST 0 +#define SHUTDOWN_PRI_DEFAULT 10000 +#define SHUTDOWN_PRI_LAST 20000 typedef void (*bootlist_fn) __P((int, void *)); int at_shutdown __P((bootlist_fn function, void *arg, int position)); +int at_shutdown_pri __P((bootlist_fn function, void *arg, int position, int pri)); int rm_at_shutdown __P((bootlist_fn function, void *arg)); /*