1 /* sstate.c: System soft state support.
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net>
6 #include <linux/kernel.h>
7 #include <linux/notifier.h>
8 #include <linux/init.h>
10 #include <asm/hypervisor.h>
11 #include <asm/sstate.h>
12 #include <asm/oplib.h>
16 static int hv_supports_soft_state;
18 static unsigned long kimage_addr_to_ra(const char *p)
20 unsigned long val = (unsigned long) p;
22 return kern_base + (val - KERNBASE);
25 static void do_set_sstate(unsigned long state, const char *msg)
29 if (!hv_supports_soft_state)
32 err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
34 printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
35 "state[%lx] msg[%s], err=%lu\n",
40 static const char booting_msg[32] __attribute__((aligned(32))) =
42 static const char running_msg[32] __attribute__((aligned(32))) =
44 static const char halting_msg[32] __attribute__((aligned(32))) =
46 static const char poweroff_msg[32] __attribute__((aligned(32))) =
48 static const char rebooting_msg[32] __attribute__((aligned(32))) =
50 static const char panicing_msg[32] __attribute__((aligned(32))) =
53 void sstate_booting(void)
55 do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
58 void sstate_running(void)
60 do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
63 void sstate_halt(void)
65 do_set_sstate(HV_SOFT_STATE_TRANSITION, halting_msg);
68 void sstate_poweroff(void)
70 do_set_sstate(HV_SOFT_STATE_TRANSITION, poweroff_msg);
73 void sstate_reboot(void)
75 do_set_sstate(HV_SOFT_STATE_TRANSITION, rebooting_msg);
78 static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
80 do_set_sstate(HV_SOFT_STATE_TRANSITION, panicing_msg);
85 static struct notifier_block sstate_panic_block = {
86 .notifier_call = sstate_panic_event,
90 void __init sun4v_sstate_init(void)
92 unsigned long major, minor;
96 if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
99 hv_supports_soft_state = 1;
101 prom_sun4v_guest_soft_state();
102 atomic_notifier_chain_register(&panic_notifier_list,
103 &sstate_panic_block);