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 <walter@fortean.com>
This commit is contained in:
msmith 1998-10-30 05:41:15 +00:00
parent 0fcabcf90e
commit e79dcdb69f
12 changed files with 64 additions and 64 deletions

View File

@ -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
*/

View File

@ -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));

View File

@ -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 <net/netisr.h>
#endif
#if NAPM > 0
#include <machine/apm_bios.h>
#endif
#include <machine/cpu.h>
#include <machine/reg.h>
#include <machine/clock.h>
@ -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
*/

View File

@ -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));

View File

@ -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 <sys/systm.h>
#include <sys/time.h>
#include <sys/reboot.h>
#include <i386/isa/isa_device.h>
#include <machine/apm_bios.h>
#include <machine/segments.h>
@ -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

View File

@ -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 <sys/systm.h>
#include <sys/time.h>
#include <sys/reboot.h>
#include <i386/isa/isa_device.h>
#include <machine/apm_bios.h>
#include <machine/segments.h>
@ -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

View File

@ -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 <net/netisr.h>
#endif
#if NAPM > 0
#include <machine/apm_bios.h>
#endif
#include <machine/cpu.h>
#include <machine/reg.h>
#include <machine/clock.h>
@ -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
*/

View File

@ -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 */

View File

@ -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));

View File

@ -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);
}

View File

@ -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));

View File

@ -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));
/*