1 // SPDX-License-Identifier: GPL-2.0
2 /* sstate.c: System soft state support.
4 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
7 #include <linux/kernel.h>
8 #include <linux/notifier.h>
9 #include <linux/panic_notifier.h>
10 #include <linux/reboot.h>
11 #include <linux/init.h>
13 #include <asm/hypervisor.h>
14 #include <asm/spitfire.h>
15 #include <asm/oplib.h>
21 static int hv_supports_soft_state
;
23 static void do_set_sstate(unsigned long state
, const char *msg
)
27 if (!hv_supports_soft_state
)
30 err
= sun4v_mach_set_soft_state(state
, kimage_addr_to_ra(msg
));
32 printk(KERN_WARNING
"SSTATE: Failed to set soft-state to "
33 "state[%lx] msg[%s], err=%lu\n",
38 static const char booting_msg
[32] __attribute__((aligned(32))) =
40 static const char running_msg
[32] __attribute__((aligned(32))) =
42 static const char halting_msg
[32] __attribute__((aligned(32))) =
44 static const char poweroff_msg
[32] __attribute__((aligned(32))) =
46 static const char rebooting_msg
[32] __attribute__((aligned(32))) =
48 static const char panicking_msg
[32] __attribute__((aligned(32))) =
51 static int sstate_reboot_call(struct notifier_block
*np
, unsigned long type
, void *_unused
)
70 do_set_sstate(HV_SOFT_STATE_TRANSITION
, msg
);
75 static struct notifier_block sstate_reboot_notifier
= {
76 .notifier_call
= sstate_reboot_call
,
79 static int sstate_panic_event(struct notifier_block
*n
, unsigned long event
, void *ptr
)
81 do_set_sstate(HV_SOFT_STATE_TRANSITION
, panicking_msg
);
86 static struct notifier_block sstate_panic_block
= {
87 .notifier_call
= sstate_panic_event
,
91 static int __init
sstate_init(void)
93 unsigned long major
, minor
;
95 if (tlb_type
!= hypervisor
)
100 if (sun4v_hvapi_register(HV_GRP_SOFT_STATE
, major
, &minor
))
103 hv_supports_soft_state
= 1;
105 prom_sun4v_guest_soft_state();
107 do_set_sstate(HV_SOFT_STATE_TRANSITION
, booting_msg
);
109 atomic_notifier_chain_register(&panic_notifier_list
,
110 &sstate_panic_block
);
111 register_reboot_notifier(&sstate_reboot_notifier
);
116 core_initcall(sstate_init
);
118 static int __init
sstate_running(void)
120 do_set_sstate(HV_SOFT_STATE_NORMAL
, running_msg
);
124 late_initcall(sstate_running
);