[SPARC64]: Export powerd facilities for external entities.
Besides the existing usage for power-button interrupts, we'll want to make use of this code for domain-services where the LDOM manager can send reboot requests to the guest node. Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
2c4f4ecb7a
commit
13077d8028
2 changed files with 38 additions and 23 deletions
|
@ -1,7 +1,6 @@
|
|||
/* $Id: power.c,v 1.10 2001/12/11 01:57:16 davem Exp $
|
||||
* power.c: Power management driver.
|
||||
/* power.c: Power management driver.
|
||||
*
|
||||
* Copyright (C) 1999 David S. Miller (davem@redhat.com)
|
||||
* Copyright (C) 1999, 2007 David S. Miller (davem@davemloft.net)
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
|
@ -19,6 +18,7 @@
|
|||
#include <asm/prom.h>
|
||||
#include <asm/of_device.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/power.h>
|
||||
#include <asm/sstate.h>
|
||||
|
||||
#include <linux/unistd.h>
|
||||
|
@ -29,24 +29,26 @@
|
|||
*/
|
||||
int scons_pwroff = 1;
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
#include <linux/pci.h>
|
||||
static void __iomem *power_reg;
|
||||
|
||||
static DECLARE_WAIT_QUEUE_HEAD(powerd_wait);
|
||||
static int button_pressed;
|
||||
|
||||
static irqreturn_t power_handler(int irq, void *dev_id)
|
||||
void wake_up_powerd(void)
|
||||
{
|
||||
if (button_pressed == 0) {
|
||||
button_pressed = 1;
|
||||
wake_up(&powerd_wait);
|
||||
}
|
||||
}
|
||||
|
||||
static irqreturn_t power_handler(int irq, void *dev_id)
|
||||
{
|
||||
wake_up_powerd();
|
||||
|
||||
/* FIXME: Check registers for status... */
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
#endif /* CONFIG_PCI */
|
||||
|
||||
extern void machine_halt(void);
|
||||
extern void machine_alt_power_off(void);
|
||||
|
@ -56,19 +58,18 @@ void machine_power_off(void)
|
|||
{
|
||||
sstate_poweroff();
|
||||
if (!serial_console || scons_pwroff) {
|
||||
#ifdef CONFIG_PCI
|
||||
if (power_reg) {
|
||||
/* Both register bits seem to have the
|
||||
* same effect, so until I figure out
|
||||
* what the difference is...
|
||||
*/
|
||||
writel(AUXIO_PCIO_CPWR_OFF | AUXIO_PCIO_SPWR_OFF, power_reg);
|
||||
} else
|
||||
#endif /* CONFIG_PCI */
|
||||
} else {
|
||||
if (poweroff_method != NULL) {
|
||||
poweroff_method();
|
||||
/* not reached */
|
||||
}
|
||||
}
|
||||
}
|
||||
machine_halt();
|
||||
}
|
||||
|
@ -76,7 +77,6 @@ void machine_power_off(void)
|
|||
void (*pm_power_off)(void) = machine_power_off;
|
||||
EXPORT_SYMBOL(pm_power_off);
|
||||
|
||||
#ifdef CONFIG_PCI
|
||||
static int powerd(void *__unused)
|
||||
{
|
||||
static char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
|
||||
|
@ -86,7 +86,7 @@ static int powerd(void *__unused)
|
|||
daemonize("powerd");
|
||||
|
||||
add_wait_queue(&powerd_wait, &wait);
|
||||
again:
|
||||
|
||||
for (;;) {
|
||||
set_task_state(current, TASK_INTERRUPTIBLE);
|
||||
if (button_pressed)
|
||||
|
@ -100,16 +100,28 @@ static int powerd(void *__unused)
|
|||
/* Ok, down we go... */
|
||||
button_pressed = 0;
|
||||
if (kernel_execve("/sbin/shutdown", argv, envp) < 0) {
|
||||
printk("powerd: shutdown execution failed\n");
|
||||
add_wait_queue(&powerd_wait, &wait);
|
||||
goto again;
|
||||
printk(KERN_ERR "powerd: shutdown execution failed\n");
|
||||
machine_power_off();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int start_powerd(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = kernel_thread(powerd, NULL, CLONE_FS);
|
||||
if (err < 0)
|
||||
printk(KERN_ERR "power: Failed to start power daemon.\n");
|
||||
else
|
||||
printk(KERN_INFO "power: powerd running.\n");
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int __init has_button_interrupt(unsigned int irq, struct device_node *dp)
|
||||
{
|
||||
if (irq == PCI_IRQ_NONE)
|
||||
if (irq == 0xffffffff)
|
||||
return 0;
|
||||
if (!of_find_property(dp, "button", NULL))
|
||||
return 0;
|
||||
|
@ -130,17 +142,14 @@ static int __devinit power_probe(struct of_device *op, const struct of_device_id
|
|||
poweroff_method = machine_halt; /* able to use the standard halt */
|
||||
|
||||
if (has_button_interrupt(irq, op->node)) {
|
||||
if (kernel_thread(powerd, NULL, CLONE_FS) < 0) {
|
||||
printk("Failed to start power daemon.\n");
|
||||
if (start_powerd() < 0)
|
||||
return 0;
|
||||
}
|
||||
printk("powerd running.\n");
|
||||
|
||||
if (request_irq(irq,
|
||||
power_handler, 0, "power", NULL) < 0)
|
||||
printk("power: Error, cannot register IRQ handler.\n");
|
||||
printk(KERN_ERR "power: Cannot setup IRQ handler.\n");
|
||||
} else {
|
||||
printk("not using powerd.\n");
|
||||
printk(KERN_INFO "power: Not using powerd.\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -164,4 +173,3 @@ void __init power_init(void)
|
|||
of_register_driver(&power_driver, &of_bus_type);
|
||||
return;
|
||||
}
|
||||
#endif /* CONFIG_PCI */
|
||||
|
|
7
include/asm-sparc64/power.h
Normal file
7
include/asm-sparc64/power.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef _SPARC64_POWER_H
|
||||
#define _SPARC64_POWER_H
|
||||
|
||||
extern void wake_up_powerd(void);
|
||||
extern int start_powerd(void);
|
||||
|
||||
#endif /* !(_SPARC64_POWER_H) */
|
Loading…
Reference in a new issue