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