1 // SPDX-License-Identifier: GPL-2.0-only
3 * interfaces to Chassis Codes via PDC (firmware)
5 * Copyright (C) 2002 Laurent Canet <canetl@esiee.fr>
6 * Copyright (C) 2002-2006 Thibaut VARENE <varenet@parisc-linux.org>
8 * TODO: poll chassis warns, trigger (configurable) machine shutdown when
10 * Find out how to get Chassis warnings out of PAT boxes?
13 #undef PDC_CHASSIS_DEBUG
14 #ifdef PDC_CHASSIS_DEBUG
15 #define DPRINTK(fmt, args...) printk(fmt, ## args)
17 #define DPRINTK(fmt, args...)
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>
29 #include <asm/pdc_chassis.h>
30 #include <asm/processor.h>
32 #include <asm/pdcpat.h>
34 #define PDC_CHASSIS_VER "0.05"
36 #ifdef CONFIG_PDC_CHASSIS
37 static unsigned int pdc_chassis_enabled __read_mostly
= 1;
41 * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
42 * @str configuration param: 0 to disable chassis log
46 static int __init
pdc_chassis_setup(char *str
)
48 /*panic_timeout = simple_strtoul(str, NULL, 0);*/
49 get_option(&str
, &pdc_chassis_enabled
);
52 __setup("pdcchassis=", pdc_chassis_setup
);
56 * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
57 * @pdc_chassis_old: 1 if old pdc chassis style
59 * Currently, only E class and A180 are known to work with this.
60 * Inspired by Christoph Plattner
63 static void __init
pdc_chassis_checkold(void)
65 switch(CPU_HVERSION
) {
70 case 0x516: /* A180 */
76 DPRINTK(KERN_DEBUG
"%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__
, pdc_chassis_old
);
81 * pdc_chassis_panic_event() - Called by the panic handler.
83 * As soon as a panic occurs, we should inform the PDC.
86 static int pdc_chassis_panic_event(struct notifier_block
*this,
87 unsigned long event
, void *ptr
)
89 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC
);
94 static struct notifier_block pdc_chassis_panic_block
= {
95 .notifier_call
= pdc_chassis_panic_event
,
101 * parisc_reboot_event() - Called by the reboot handler.
103 * As soon as a reboot occurs, we should inform the PDC.
106 static int pdc_chassis_reboot_event(struct notifier_block
*this,
107 unsigned long event
, void *ptr
)
109 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN
);
114 static struct notifier_block pdc_chassis_reboot_block
= {
115 .notifier_call
= pdc_chassis_reboot_event
,
118 #endif /* CONFIG_PDC_CHASSIS */
122 * parisc_pdc_chassis_init() - Called at boot time.
125 void __init
parisc_pdc_chassis_init(void)
127 #ifdef CONFIG_PDC_CHASSIS
128 if (likely(pdc_chassis_enabled
)) {
129 DPRINTK(KERN_DEBUG
"%s: parisc_pdc_chassis_init()\n", __FILE__
);
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",
136 /* initialize panic notifier chain */
137 atomic_notifier_chain_register(&panic_notifier_list
,
138 &pdc_chassis_panic_block
);
140 /* initialize reboot notifier chain */
141 register_reboot_notifier(&pdc_chassis_reboot_block
);
143 #endif /* CONFIG_PDC_CHASSIS */
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.
152 * Only machines with 64 bits PDC PAT and those reported in
153 * pdc_chassis_checkold() are supported atm.
155 * returns 0 if no error, -1 if no supported PDC is present or invalid message,
156 * else returns the appropriate PDC error code.
158 * For a list of predefined messages, see asm-parisc/pdc_chassis.h
161 int pdc_chassis_send_status(int message
)
163 /* Maybe we should do that in an other way ? */
165 #ifdef CONFIG_PDC_CHASSIS
166 if (likely(pdc_chassis_enabled
)) {
168 DPRINTK(KERN_DEBUG
"%s: pdc_chassis_send_status(%d)\n", __FILE__
, message
);
173 case PDC_CHASSIS_DIRECT_BSTART
:
174 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART
, PDC_CHASSIS_LSTATE_RUN_NORMAL
);
177 case PDC_CHASSIS_DIRECT_BCOMPLETE
:
178 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE
, PDC_CHASSIS_LSTATE_RUN_NORMAL
);
181 case PDC_CHASSIS_DIRECT_SHUTDOWN
:
182 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN
, PDC_CHASSIS_LSTATE_NONOS
);
185 case PDC_CHASSIS_DIRECT_PANIC
:
186 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC
, PDC_CHASSIS_LSTATE_RUN_CRASHREC
);
189 case PDC_CHASSIS_DIRECT_LPMC
:
190 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC
, PDC_CHASSIS_LSTATE_RUN_SYSINT
);
193 case PDC_CHASSIS_DIRECT_HPMC
:
194 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC
, PDC_CHASSIS_LSTATE_RUN_NCRIT
);
204 case PDC_CHASSIS_DIRECT_BSTART
:
205 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT
));
208 case PDC_CHASSIS_DIRECT_BCOMPLETE
:
209 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN
));
212 case PDC_CHASSIS_DIRECT_SHUTDOWN
:
213 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT
));
216 case PDC_CHASSIS_DIRECT_HPMC
:
217 case PDC_CHASSIS_DIRECT_PANIC
:
218 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT
));
221 case PDC_CHASSIS_DIRECT_LPMC
:
222 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN
));
229 #endif /* CONFIG_64BIT */
230 } /* if (pdc_chassis_enabled) */
231 #endif /* CONFIG_PDC_CHASSIS */
235 #ifdef CONFIG_PDC_CHASSIS_WARN
236 #ifdef CONFIG_PROC_FS
237 static int pdc_chassis_warn_show(struct seq_file
*m
, void *v
)
242 if (pdc_chassis_warn(&warn
) != PDC_OK
)
245 warnreg
= (warn
& 0xFFFFFFFF);
247 if ((warnreg
>> 24) & 0xFF)
248 seq_printf(m
, "Chassis component failure! (eg fan or PSU): 0x%.2x\n",
249 (warnreg
>> 24) & 0xFF);
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");
257 static int __init
pdc_chassis_create_procfs(void)
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");
269 printk(KERN_INFO
"Enabling PDC chassis warnings support v%s\n",
271 proc_create_single("chassis", 0400, NULL
, pdc_chassis_warn_show
);
275 __initcall(pdc_chassis_create_procfs
);
277 #endif /* CONFIG_PROC_FS */
278 #endif /* CONFIG_PDC_CHASSIS_WARN */