2007-05-25 01:37:12 -06:00
|
|
|
/* sstate.c: System soft state support.
|
|
|
|
*
|
2008-09-02 01:49:38 -06:00
|
|
|
* Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
|
2007-05-25 01:37:12 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/notifier.h>
|
2008-09-02 01:49:38 -06:00
|
|
|
#include <linux/reboot.h>
|
2007-05-25 01:37:12 -06:00
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <asm/hypervisor.h>
|
2008-09-02 01:49:38 -06:00
|
|
|
#include <asm/spitfire.h>
|
2007-05-25 01:37:12 -06:00
|
|
|
#include <asm/oplib.h>
|
|
|
|
#include <asm/head.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
2011-08-02 00:27:17 -06:00
|
|
|
#include "kernel.h"
|
2007-05-25 01:37:12 -06:00
|
|
|
|
2011-08-02 00:27:17 -06:00
|
|
|
static int hv_supports_soft_state;
|
2007-05-25 01:37:12 -06:00
|
|
|
|
|
|
|
static void do_set_sstate(unsigned long state, const char *msg)
|
|
|
|
{
|
|
|
|
unsigned long err;
|
|
|
|
|
|
|
|
if (!hv_supports_soft_state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
|
|
|
|
"state[%lx] msg[%s], err=%lu\n",
|
|
|
|
state, msg, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char booting_msg[32] __attribute__((aligned(32))) =
|
|
|
|
"Linux booting";
|
|
|
|
static const char running_msg[32] __attribute__((aligned(32))) =
|
|
|
|
"Linux running";
|
|
|
|
static const char halting_msg[32] __attribute__((aligned(32))) =
|
|
|
|
"Linux halting";
|
|
|
|
static const char poweroff_msg[32] __attribute__((aligned(32))) =
|
|
|
|
"Linux powering off";
|
|
|
|
static const char rebooting_msg[32] __attribute__((aligned(32))) =
|
|
|
|
"Linux rebooting";
|
2017-01-10 10:57:56 -07:00
|
|
|
static const char panicking_msg[32] __attribute__((aligned(32))) =
|
|
|
|
"Linux panicking";
|
2007-05-25 01:37:12 -06:00
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
static int sstate_reboot_call(struct notifier_block *np, unsigned long type, void *_unused)
|
2007-05-25 01:37:12 -06:00
|
|
|
{
|
2008-09-02 01:49:38 -06:00
|
|
|
const char *msg;
|
2007-05-25 01:37:12 -06:00
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
switch (type) {
|
|
|
|
case SYS_DOWN:
|
|
|
|
default:
|
|
|
|
msg = rebooting_msg;
|
|
|
|
break;
|
2007-05-25 01:37:12 -06:00
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
case SYS_HALT:
|
|
|
|
msg = halting_msg;
|
|
|
|
break;
|
2007-05-25 01:37:12 -06:00
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
case SYS_POWER_OFF:
|
|
|
|
msg = poweroff_msg;
|
|
|
|
break;
|
|
|
|
}
|
2007-05-25 01:37:12 -06:00
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
do_set_sstate(HV_SOFT_STATE_TRANSITION, msg);
|
|
|
|
|
|
|
|
return NOTIFY_OK;
|
2007-05-25 01:37:12 -06:00
|
|
|
}
|
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
static struct notifier_block sstate_reboot_notifier = {
|
|
|
|
.notifier_call = sstate_reboot_call,
|
|
|
|
};
|
|
|
|
|
2007-05-25 01:37:12 -06:00
|
|
|
static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
|
|
|
|
{
|
2017-01-10 10:57:56 -07:00
|
|
|
do_set_sstate(HV_SOFT_STATE_TRANSITION, panicking_msg);
|
2007-05-25 01:37:12 -06:00
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block sstate_panic_block = {
|
|
|
|
.notifier_call = sstate_panic_event,
|
|
|
|
.priority = INT_MAX,
|
|
|
|
};
|
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
static int __init sstate_init(void)
|
2007-05-25 01:37:12 -06:00
|
|
|
{
|
|
|
|
unsigned long major, minor;
|
|
|
|
|
2008-09-02 01:49:38 -06:00
|
|
|
if (tlb_type != hypervisor)
|
|
|
|
return 0;
|
|
|
|
|
2007-05-25 01:37:12 -06:00
|
|
|
major = 1;
|
|
|
|
minor = 0;
|
|
|
|
if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
|
2008-09-02 01:49:38 -06:00
|
|
|
return 0;
|
2007-05-25 01:37:12 -06:00
|
|
|
|
|
|
|
hv_supports_soft_state = 1;
|
|
|
|
|
|
|
|
prom_sun4v_guest_soft_state();
|
2008-09-02 01:49:38 -06:00
|
|
|
|
|
|
|
do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
|
|
|
|
|
2007-05-25 01:37:12 -06:00
|
|
|
atomic_notifier_chain_register(&panic_notifier_list,
|
|
|
|
&sstate_panic_block);
|
2008-09-02 01:49:38 -06:00
|
|
|
register_reboot_notifier(&sstate_reboot_notifier);
|
|
|
|
|
|
|
|
return 0;
|
2007-05-25 01:37:12 -06:00
|
|
|
}
|
2008-09-02 01:49:38 -06:00
|
|
|
|
|
|
|
core_initcall(sstate_init);
|
|
|
|
|
|
|
|
static int __init sstate_running(void)
|
|
|
|
{
|
|
|
|
do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
late_initcall(sstate_running);
|