1 /* sstate.c: System soft state support.
3 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
6 #include <linux/kernel.h>
7 #include <linux/notifier.h>
8 #include <linux/reboot.h>
9 #include <linux/init.h>
11 #include <asm/hypervisor.h>
12 #include <asm/spitfire.h>
13 #include <asm/oplib.h>
17 static int hv_supports_soft_state;
19 static unsigned long kimage_addr_to_ra(const char *p)
21 unsigned long val = (unsigned long) p;
23 return kern_base + (val - KERNBASE);
26 static void do_set_sstate(unsigned long state, const char *msg)
30 if (!hv_supports_soft_state)
33 err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
35 printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
36 "state[%lx] msg[%s], err=%lu\n",
41 static const char booting_msg[32] __attribute__((aligned(32))) =
43 static const char running_msg[32] __attribute__((aligned(32))) =
45 static const char halting_msg[32] __attribute__((aligned(32))) =
47 static const char poweroff_msg[32] __attribute__((aligned(32))) =
49 static const char rebooting_msg[32] __attribute__((aligned(32))) =
51 static const char panicing_msg[32] __attribute__((aligned(32))) =
54 static int sstate_reboot_call(struct notifier_block *np, unsigned long type, void *_unused)
73 do_set_sstate(HV_SOFT_STATE_TRANSITION, msg);
78 static struct notifier_block sstate_reboot_notifier = {
79 .notifier_call = sstate_reboot_call,
82 static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
84 do_set_sstate(HV_SOFT_STATE_TRANSITION, panicing_msg);
89 static struct notifier_block sstate_panic_block = {
90 .notifier_call = sstate_panic_event,
94 static int __init sstate_init(void)
96 unsigned long major, minor;
98 if (tlb_type != hypervisor)
103 if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
106 hv_supports_soft_state = 1;
108 prom_sun4v_guest_soft_state();
110 do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
112 atomic_notifier_chain_register(&panic_notifier_list,
113 &sstate_panic_block);
114 register_reboot_notifier(&sstate_reboot_notifier);
119 core_initcall(sstate_init);
121 static int __init sstate_running(void)
123 do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
127 late_initcall(sstate_running);