Merge tag 'soc-ep93xx-dt-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-block.git] / arch / sparc / kernel / sstate.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
22d6a1cb
DM
2/* sstate.c: System soft state support.
3 *
446139a8 4 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
22d6a1cb
DM
5 */
6
7#include <linux/kernel.h>
8#include <linux/notifier.h>
f39650de 9#include <linux/panic_notifier.h>
446139a8 10#include <linux/reboot.h>
22d6a1cb
DM
11#include <linux/init.h>
12
13#include <asm/hypervisor.h>
446139a8 14#include <asm/spitfire.h>
22d6a1cb
DM
15#include <asm/oplib.h>
16#include <asm/head.h>
17#include <asm/io.h>
18
ea5e7447 19#include "kernel.h"
22d6a1cb 20
ea5e7447 21static int hv_supports_soft_state;
22d6a1cb
DM
22
23static void do_set_sstate(unsigned long state, const char *msg)
24{
25 unsigned long err;
26
27 if (!hv_supports_soft_state)
28 return;
29
30 err = sun4v_mach_set_soft_state(state, kimage_addr_to_ra(msg));
31 if (err) {
32 printk(KERN_WARNING "SSTATE: Failed to set soft-state to "
33 "state[%lx] msg[%s], err=%lu\n",
34 state, msg, err);
35 }
36}
37
38static const char booting_msg[32] __attribute__((aligned(32))) =
39 "Linux booting";
40static const char running_msg[32] __attribute__((aligned(32))) =
41 "Linux running";
42static const char halting_msg[32] __attribute__((aligned(32))) =
43 "Linux halting";
44static const char poweroff_msg[32] __attribute__((aligned(32))) =
45 "Linux powering off";
46static const char rebooting_msg[32] __attribute__((aligned(32))) =
47 "Linux rebooting";
5d0e7705
TH
48static const char panicking_msg[32] __attribute__((aligned(32))) =
49 "Linux panicking";
22d6a1cb 50
446139a8 51static int sstate_reboot_call(struct notifier_block *np, unsigned long type, void *_unused)
22d6a1cb 52{
446139a8 53 const char *msg;
22d6a1cb 54
446139a8
DM
55 switch (type) {
56 case SYS_DOWN:
57 default:
58 msg = rebooting_msg;
59 break;
22d6a1cb 60
446139a8
DM
61 case SYS_HALT:
62 msg = halting_msg;
63 break;
22d6a1cb 64
446139a8
DM
65 case SYS_POWER_OFF:
66 msg = poweroff_msg;
67 break;
68 }
22d6a1cb 69
446139a8
DM
70 do_set_sstate(HV_SOFT_STATE_TRANSITION, msg);
71
72 return NOTIFY_OK;
22d6a1cb
DM
73}
74
446139a8
DM
75static struct notifier_block sstate_reboot_notifier = {
76 .notifier_call = sstate_reboot_call,
77};
78
22d6a1cb
DM
79static int sstate_panic_event(struct notifier_block *n, unsigned long event, void *ptr)
80{
5d0e7705 81 do_set_sstate(HV_SOFT_STATE_TRANSITION, panicking_msg);
22d6a1cb
DM
82
83 return NOTIFY_DONE;
84}
85
86static struct notifier_block sstate_panic_block = {
87 .notifier_call = sstate_panic_event,
88 .priority = INT_MAX,
89};
90
446139a8 91static int __init sstate_init(void)
22d6a1cb
DM
92{
93 unsigned long major, minor;
94
446139a8
DM
95 if (tlb_type != hypervisor)
96 return 0;
97
22d6a1cb
DM
98 major = 1;
99 minor = 0;
100 if (sun4v_hvapi_register(HV_GRP_SOFT_STATE, major, &minor))
446139a8 101 return 0;
22d6a1cb
DM
102
103 hv_supports_soft_state = 1;
104
105 prom_sun4v_guest_soft_state();
446139a8
DM
106
107 do_set_sstate(HV_SOFT_STATE_TRANSITION, booting_msg);
108
22d6a1cb
DM
109 atomic_notifier_chain_register(&panic_notifier_list,
110 &sstate_panic_block);
446139a8
DM
111 register_reboot_notifier(&sstate_reboot_notifier);
112
113 return 0;
22d6a1cb 114}
446139a8
DM
115
116core_initcall(sstate_init);
117
118static int __init sstate_running(void)
119{
120 do_set_sstate(HV_SOFT_STATE_NORMAL, running_msg);
121 return 0;
122}
123
124late_initcall(sstate_running);