]>
Commit | Line | Data |
---|---|---|
45051539 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 | 2 | /* |
8ffaeaf4 | 3 | * interfaces to Chassis Codes via PDC (firmware) |
1da177e4 LT |
4 | * |
5 | * Copyright (C) 2002 Laurent Canet <canetl@esiee.fr> | |
8ffaeaf4 | 6 | * Copyright (C) 2002-2006 Thibaut VARENE <varenet@parisc-linux.org> |
1da177e4 | 7 | * |
8ffaeaf4 TV |
8 | * TODO: poll chassis warns, trigger (configurable) machine shutdown when |
9 | * needed. | |
9b0703fe | 10 | * Find out how to get Chassis warnings out of PAT boxes? |
1da177e4 LT |
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> | |
28ff1188 | 21 | #include <linux/module.h> |
1da177e4 | 22 | #include <linux/kernel.h> |
f39650de | 23 | #include <linux/panic_notifier.h> |
1da177e4 LT |
24 | #include <linux/reboot.h> |
25 | #include <linux/notifier.h> | |
8039de10 | 26 | #include <linux/cache.h> |
8ffaeaf4 | 27 | #include <linux/proc_fs.h> |
28ff1188 | 28 | #include <linux/seq_file.h> |
1da177e4 LT |
29 | |
30 | #include <asm/pdc_chassis.h> | |
31 | #include <asm/processor.h> | |
32 | #include <asm/pdc.h> | |
33 | #include <asm/pdcpat.h> | |
34 | ||
9b0703fe | 35 | #define PDC_CHASSIS_VER "0.05" |
1da177e4 LT |
36 | |
37 | #ifdef CONFIG_PDC_CHASSIS | |
8039de10 | 38 | static unsigned int pdc_chassis_enabled __read_mostly = 1; |
1da177e4 LT |
39 | |
40 | ||
41 | /** | |
42 | * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time. | |
9872fb13 | 43 | * @str: configuration param: 0 to disable chassis log |
1da177e4 LT |
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 | |
1da177e4 LT |
58 | * |
59 | * Currently, only E class and A180 are known to work with this. | |
60 | * Inspired by Christoph Plattner | |
61 | */ | |
8ffaeaf4 | 62 | #if 0 |
1da177e4 LT |
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 */ | |
1da177e4 LT |
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 | } | |
8ffaeaf4 | 78 | #endif |
1da177e4 LT |
79 | |
80 | /** | |
81 | * pdc_chassis_panic_event() - Called by the panic handler. | |
9872fb13 HD |
82 | * @this: unused |
83 | * @event: unused | |
84 | * @ptr: unused | |
1da177e4 LT |
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); | |
9872fb13 | 93 | return NOTIFY_DONE; |
1da177e4 LT |
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 | /** | |
9872fb13 HD |
104 | * pdc_chassis_reboot_event() - Called by the reboot handler. |
105 | * @this: unused | |
106 | * @event: unused | |
107 | * @ptr: unused | |
1da177e4 LT |
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); | |
9872fb13 | 116 | return NOTIFY_DONE; |
1da177e4 LT |
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 | |
8039de10 | 134 | if (likely(pdc_chassis_enabled)) { |
1da177e4 LT |
135 | DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__); |
136 | ||
137 | /* Let see if we have something to handle... */ | |
9b0703fe TV |
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); | |
1da177e4 LT |
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 | |
9872fb13 | 156 | * @message: Type of message, one of PDC_CHASSIS_DIRECT_* values. |
1da177e4 LT |
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 | |
8039de10 | 172 | if (likely(pdc_chassis_enabled)) { |
1da177e4 LT |
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 | |
8ffaeaf4 | 208 | if (1) { |
1da177e4 LT |
209 | switch (message) { |
210 | case PDC_CHASSIS_DIRECT_BSTART: | |
8ffaeaf4 TV |
211 | retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT)); |
212 | break; | |
213 | ||
1da177e4 LT |
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 | } | |
8ffaeaf4 TV |
240 | |
241 | #ifdef CONFIG_PDC_CHASSIS_WARN | |
242 | #ifdef CONFIG_PROC_FS | |
28ff1188 | 243 | static int pdc_chassis_warn_show(struct seq_file *m, void *v) |
8ffaeaf4 | 244 | { |
8ffaeaf4 TV |
245 | unsigned long warn; |
246 | u32 warnreg; | |
247 | ||
28ff1188 | 248 | if (pdc_chassis_warn(&warn) != PDC_OK) |
8ffaeaf4 TV |
249 | return -EIO; |
250 | ||
251 | warnreg = (warn & 0xFFFFFFFF); | |
252 | ||
253 | if ((warnreg >> 24) & 0xFF) | |
28ff1188 DH |
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 | ||
8ffaeaf4 TV |
263 | static int __init pdc_chassis_create_procfs(void) |
264 | { | |
9b0703fe TV |
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); | |
3f3942ac | 277 | proc_create_single("chassis", 0400, NULL, pdc_chassis_warn_show); |
8ffaeaf4 TV |
278 | return 0; |
279 | } | |
280 | ||
281 | __initcall(pdc_chassis_create_procfs); | |
282 | ||
283 | #endif /* CONFIG_PROC_FS */ | |
284 | #endif /* CONFIG_PDC_CHASSIS_WARN */ |