Implement powerd(8) interface via sysmon(9) for power switch, controllable by sysctl(8).

This commit is contained in:
jkunz 2005-01-28 17:38:50 +00:00
parent 3c88ecfad5
commit 74a2c9190e
3 changed files with 71 additions and 33 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.16 2004/10/23 17:07:39 thorpej Exp $ */
/* $NetBSD: autoconf.c,v 1.17 2005/01/28 17:38:50 jkunz Exp $ */
/* $OpenBSD: autoconf.c,v 1.15 2001/06/25 00:43:10 mickey Exp $ */
@ -86,10 +86,11 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.16 2004/10/23 17:07:39 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.17 2005/01/28 17:38:50 jkunz Exp $");
#include "opt_kgdb.h"
#include "opt_useleds.h"
#include "opt_power_switch.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -117,10 +118,10 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.16 2004/10/23 17:07:39 thorpej Exp $"
#include <dev/cons.h>
#include <hp700/hp700/machdep.h>
#include <hp700/hp700/power.h>
#include <hp700/dev/cpudevs.h>
#include <hp700/gsc/gscbusvar.h>
void (*cold_hook)(void); /* see below */
register_t kpsw = PSW_Q | PSW_P | PSW_C | PSW_D;
/*
@ -166,8 +167,10 @@ cpu_configure(void)
spl0();
cold = 0;
if (cold_hook)
(*cold_hook)();
#ifdef POWER_SWITCH
/* Give OS control over the power switch. */
pwr_sw_ctrl(PWR_SW_CTRL_ENABLE);
#endif /* POWER_SWITCH */
#ifdef USELEDS
memset(_hp700_led_on_cycles, 0, sizeof(_hp700_led_on_cycles));

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.20 2004/07/24 18:59:05 chs Exp $ */
/* $NetBSD: machdep.c,v 1.21 2005/01/28 17:38:51 jkunz Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -70,13 +70,14 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.20 2004/07/24 18:59:05 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.21 2005/01/28 17:38:51 jkunz Exp $");
#include "opt_cputype.h"
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "opt_compat_hpux.h"
#include "opt_useleds.h"
#include "opt_power_switch.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -137,6 +138,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.20 2004/07/24 18:59:05 chs Exp $");
#include <hp700/hp700/intr.h>
#include <hp700/hp700/machdep.h>
#include <hp700/hp700/pim.h>
#include <hp700/hp700/power.h>
#include <hp700/dev/cpudevs.h>
#include "ksyms.h"
@ -1337,39 +1339,58 @@ cpu_reboot(howto, user_boot_string)
int howto;
char *user_boot_string;
{
#ifdef POWER_SWITCH
int i;
#endif /* POWER_SWITCH */
/* If the system is cold, just give up and halt. */
if (cold)
goto haltsys;
howto |= RB_HALT;
else {
boothowto = howto | (boothowto & RB_HALT);
boothowto = howto | (boothowto & RB_HALT);
if (!(howto & RB_NOSYNC) && waittime < 0) {
waittime = 0;
vfs_shutdown();
if (!(howto & RB_NOSYNC) && waittime < 0) {
waittime = 0;
vfs_shutdown();
#if 0
if ((howto & RB_TIMEBAD) == 0)
resettodr();
else
if ((howto & RB_TIMEBAD) == 0)
resettodr();
else
#endif
printf("WARNING: not updating battery clock\n");
printf("WARNING: not updating battery clock\n");
}
/* XXX probably save howto into stable storage */
/* Disable interrupts. */
splhigh();
/* Make a crash dump. */
if (howto & RB_DUMP)
dumpsys();
/* Run any shutdown hooks. */
doshutdownhooks();
#ifdef POWER_SWITCH
if (pwr_sw_state == 0 &&
(howto & RB_POWERDOWN) == RB_POWERDOWN) {
printf("Soft power down in 10 seconds...");
for (i = 10; i > 0; i--) {
printf(" %d", i);
DELAY(1000000);
}
printf("\n");
howto &= ~RB_HALT;
}
pwr_sw_ctrl(PWR_SW_CTRL_DISABLE);
DELAY(1000000);
#endif /* POWER_SWITCH */
}
/* XXX probably save howto into stable storage */
/* Disable interrupts. */
splhigh();
/* Make a crash dump. */
if (howto & RB_DUMP)
dumpsys();
/* Run any shutdown hooks. */
doshutdownhooks();
if (howto & RB_HALT) {
haltsys:
printf("System halted!\n");
DELAY(1000000);
__asm __volatile("stwas %0, 0(%1)"
:: "r" (CMD_STOP), "r" (LBCAST_ADDR + iomod_command));
} else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: mainbus.c,v 1.22 2004/12/14 02:32:02 chs Exp $ */
/* $NetBSD: mainbus.c,v 1.23 2005/01/28 17:38:51 jkunz Exp $ */
/*-
* Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
@ -70,9 +70,10 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.22 2004/12/14 02:32:02 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.23 2005/01/28 17:38:51 jkunz Exp $");
#include "locators.h"
#include "opt_power_switch.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -90,6 +91,7 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.22 2004/12/14 02:32:02 chs Exp $");
#include <hp700/hp700/machdep.h>
#include <hp700/hp700/intr.h>
#include <hp700/hp700/power.h>
#include <hp700/dev/cpudevs.h>
static struct pdc_hpa pdc_hpa PDC_ALIGNMENT;
@ -184,8 +186,10 @@ mbus_add_mapping(bus_addr_t bpa, bus_size_t size, int flags,
bus_space_handle_t *bshp)
{
u_int frames;
/*
vsize_t btlb_size;
int error;
*/
/*
* We must be called with a page-aligned address in
@ -209,7 +213,6 @@ mbus_add_mapping(bus_addr_t bpa, bus_size_t size, int flags,
/*
* If this mapping is more than eight pages long,
* try to add a BTLB entry.
*/
if (frames > 8 &&
frames >= hppa_btlb_size_min) {
btlb_size = frames;
@ -230,6 +233,7 @@ mbus_add_mapping(bus_addr_t bpa, bus_size_t size, int flags,
else if (error != ENOMEM)
return error;
}
*/
/*
* Enter another single-page mapping.
@ -1589,6 +1593,16 @@ mbattach(struct device *parent, struct device *self, void *aux)
nca.ca_dp.dp_bc[3] = nca.ca_dp.dp_bc[4] = nca.ca_dp.dp_bc[5] = -1;
nca.ca_dp.dp_mod = -1;
pdc_scanbus(self, &nca, mb_module_callback);
#ifdef POWER_SWITCH
/*
* Initialize soft power switch code. This may need to bus_space_map(9)
* the power switch status register. So call it from here to give it
* a bus space tag. This may need to use the lasi_pwr_sw_reg so call
* it after all IO hardware is found.
*/
pwr_sw_init(&hppa_bustag);
#endif /* POWER_SWITCH */
}
/*