xref: /openbmc/linux/arch/parisc/kernel/pdc_chassis.c (revision c4c3c32d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *    interfaces to Chassis Codes via PDC (firmware)
4  *
5  *    Copyright (C) 2002 Laurent Canet <canetl@esiee.fr>
6  *    Copyright (C) 2002-2006 Thibaut VARENE <varenet@parisc-linux.org>
7  *
8  *    TODO: poll chassis warns, trigger (configurable) machine shutdown when
9  *    		needed.
10  *    	    Find out how to get Chassis warnings out of PAT boxes?
11  */
12 
13 #undef PDC_CHASSIS_DEBUG
14 #ifdef PDC_CHASSIS_DEBUG
15 #define DPRINTK(fmt, args...)	printk(fmt, ## args)
16 #else
17 #define DPRINTK(fmt, args...)
18 #endif
19 
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/panic_notifier.h>
24 #include <linux/reboot.h>
25 #include <linux/notifier.h>
26 #include <linux/cache.h>
27 #include <linux/proc_fs.h>
28 #include <linux/seq_file.h>
29 
30 #include <asm/pdc_chassis.h>
31 #include <asm/processor.h>
32 #include <asm/pdc.h>
33 #include <asm/pdcpat.h>
34 
35 #define PDC_CHASSIS_VER	"0.05"
36 
37 #ifdef CONFIG_PDC_CHASSIS
38 static unsigned int pdc_chassis_enabled __read_mostly = 1;
39 
40 
41 /**
42  * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
43  * @str: configuration param: 0 to disable chassis log
44  * @return 1
45  */
46 
47 static int __init pdc_chassis_setup(char *str)
48 {
49 	/*panic_timeout = simple_strtoul(str, NULL, 0);*/
50 	get_option(&str, &pdc_chassis_enabled);
51 	return 1;
52 }
53 __setup("pdcchassis=", pdc_chassis_setup);
54 
55 
56 /**
57  * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
58  *
59  * Currently, only E class and A180 are known to work with this.
60  * Inspired by Christoph Plattner
61  */
62 #if 0
63 static void __init pdc_chassis_checkold(void)
64 {
65 	switch(CPU_HVERSION) {
66 		case 0x480:		/* E25 */
67 		case 0x481:		/* E35 */
68 		case 0x482:		/* E45 */
69 		case 0x483:		/* E55 */
70 		case 0x516:		/* A180 */
71 			break;
72 
73 		default:
74 			break;
75 	}
76 	DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
77 }
78 #endif
79 
80 /**
81  * pdc_chassis_panic_event() - Called by the panic handler.
82  * @this: unused
83  * @event: unused
84  * @ptr: unused
85  *
86  * As soon as a panic occurs, we should inform the PDC.
87  */
88 
89 static int pdc_chassis_panic_event(struct notifier_block *this,
90 		        unsigned long event, void *ptr)
91 {
92 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
93 	return NOTIFY_DONE;
94 }
95 
96 
97 static struct notifier_block pdc_chassis_panic_block = {
98 	.notifier_call = pdc_chassis_panic_event,
99 	.priority = INT_MAX,
100 };
101 
102 
103 /**
104  * pdc_chassis_reboot_event() - Called by the reboot handler.
105  * @this: unused
106  * @event: unused
107  * @ptr: unused
108  *
109  * As soon as a reboot occurs, we should inform the PDC.
110  */
111 
112 static int pdc_chassis_reboot_event(struct notifier_block *this,
113 		        unsigned long event, void *ptr)
114 {
115 	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
116 	return NOTIFY_DONE;
117 }
118 
119 
120 static struct notifier_block pdc_chassis_reboot_block = {
121 	.notifier_call = pdc_chassis_reboot_event,
122 	.priority = INT_MAX,
123 };
124 #endif /* CONFIG_PDC_CHASSIS */
125 
126 
127 /**
128  * parisc_pdc_chassis_init() - Called at boot time.
129  */
130 
131 void __init parisc_pdc_chassis_init(void)
132 {
133 #ifdef CONFIG_PDC_CHASSIS
134 	if (likely(pdc_chassis_enabled)) {
135 		DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
136 
137 		/* Let see if we have something to handle... */
138 		printk(KERN_INFO "Enabling %s chassis codes support v%s\n",
139 				is_pdc_pat() ? "PDC_PAT" : "regular",
140 				PDC_CHASSIS_VER);
141 
142 		/* initialize panic notifier chain */
143 		atomic_notifier_chain_register(&panic_notifier_list,
144 				&pdc_chassis_panic_block);
145 
146 		/* initialize reboot notifier chain */
147 		register_reboot_notifier(&pdc_chassis_reboot_block);
148 	}
149 #endif /* CONFIG_PDC_CHASSIS */
150 }
151 
152 
153 /**
154  * pdc_chassis_send_status() - Sends a predefined message to the chassis,
155  * and changes the front panel LEDs according to the new system state
156  * @message: Type of message, one of PDC_CHASSIS_DIRECT_* values.
157  *
158  * Only machines with 64 bits PDC PAT and those reported in
159  * pdc_chassis_checkold() are supported atm.
160  *
161  * returns 0 if no error, -1 if no supported PDC is present or invalid message,
162  * else returns the appropriate PDC error code.
163  *
164  * For a list of predefined messages, see asm-parisc/pdc_chassis.h
165  */
166 
167 int pdc_chassis_send_status(int message)
168 {
169 	/* Maybe we should do that in an other way ? */
170 	int retval = 0;
171 #ifdef CONFIG_PDC_CHASSIS
172 	if (likely(pdc_chassis_enabled)) {
173 
174 		DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
175 
176 #ifdef CONFIG_64BIT
177 		if (is_pdc_pat()) {
178 			switch(message) {
179 				case PDC_CHASSIS_DIRECT_BSTART:
180 					retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
181 					break;
182 
183 				case PDC_CHASSIS_DIRECT_BCOMPLETE:
184 					retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
185 					break;
186 
187 				case PDC_CHASSIS_DIRECT_SHUTDOWN:
188 					retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
189 					break;
190 
191 				case PDC_CHASSIS_DIRECT_PANIC:
192 					retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
193 					break;
194 
195 				case PDC_CHASSIS_DIRECT_LPMC:
196 					retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
197 					break;
198 
199 				case PDC_CHASSIS_DIRECT_HPMC:
200 					retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
201 					break;
202 
203 				default:
204 					retval = -1;
205 			}
206 		} else retval = -1;
207 #else
208 		if (1) {
209 			switch (message) {
210 				case PDC_CHASSIS_DIRECT_BSTART:
211 					retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT));
212 					break;
213 
214 				case PDC_CHASSIS_DIRECT_BCOMPLETE:
215 					retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));
216 					break;
217 
218 				case PDC_CHASSIS_DIRECT_SHUTDOWN:
219 					retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));
220 					break;
221 
222 				case PDC_CHASSIS_DIRECT_HPMC:
223 				case PDC_CHASSIS_DIRECT_PANIC:
224 					retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));
225 					break;
226 
227 				case PDC_CHASSIS_DIRECT_LPMC:
228 					retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));
229 					break;
230 
231 				default:
232 					retval = -1;
233 			}
234 		} else retval = -1;
235 #endif /* CONFIG_64BIT */
236 	}	/* if (pdc_chassis_enabled) */
237 #endif /* CONFIG_PDC_CHASSIS */
238 	return retval;
239 }
240 
241 #ifdef CONFIG_PDC_CHASSIS_WARN
242 #ifdef CONFIG_PROC_FS
243 static int pdc_chassis_warn_show(struct seq_file *m, void *v)
244 {
245 	unsigned long warn;
246 	u32 warnreg;
247 
248 	if (pdc_chassis_warn(&warn) != PDC_OK)
249 		return -EIO;
250 
251 	warnreg = (warn & 0xFFFFFFFF);
252 
253 	if ((warnreg >> 24) & 0xFF)
254 		seq_printf(m, "Chassis component failure! (eg fan or PSU): 0x%.2x\n",
255 			   (warnreg >> 24) & 0xFF);
256 
257 	seq_printf(m, "Battery: %s\n", (warnreg & 0x04) ? "Low!" : "OK");
258 	seq_printf(m, "Temp low: %s\n", (warnreg & 0x02) ? "Exceeded!" : "OK");
259 	seq_printf(m, "Temp mid: %s\n", (warnreg & 0x01) ? "Exceeded!" : "OK");
260 	return 0;
261 }
262 
263 static int __init pdc_chassis_create_procfs(void)
264 {
265 	unsigned long test;
266 	int ret;
267 
268 	ret = pdc_chassis_warn(&test);
269 	if ((ret == PDC_BAD_PROC) || (ret == PDC_BAD_OPTION)) {
270 		/* seems that some boxes (eg L1000) do not implement this */
271 		printk(KERN_INFO "Chassis warnings not supported.\n");
272 		return 0;
273 	}
274 
275 	printk(KERN_INFO "Enabling PDC chassis warnings support v%s\n",
276 			PDC_CHASSIS_VER);
277 	proc_create_single("chassis", 0400, NULL, pdc_chassis_warn_show);
278 	return 0;
279 }
280 
281 __initcall(pdc_chassis_create_procfs);
282 
283 #endif /* CONFIG_PROC_FS */
284 #endif /* CONFIG_PDC_CHASSIS_WARN */
285