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/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>
30 #include <asm/pdc_chassis.h>
31 #include <asm/processor.h>
33 #include <asm/pdcpat.h>
36 #define PDC_CHASSIS_VER "0.05"
38 #ifdef CONFIG_PDC_CHASSIS
39 static unsigned int pdc_chassis_enabled __read_mostly
= 1;
43 * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
44 * @str: configuration param: 0 to disable chassis log
48 static int __init
pdc_chassis_setup(char *str
)
50 /*panic_timeout = simple_strtoul(str, NULL, 0);*/
51 get_option(&str
, &pdc_chassis_enabled
);
54 __setup("pdcchassis=", pdc_chassis_setup
);
58 * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
60 * Currently, only E class and A180 are known to work with this.
61 * Inspired by Christoph Plattner
64 static void __init
pdc_chassis_checkold(void)
66 switch(CPU_HVERSION
) {
71 case 0x516: /* A180 */
77 DPRINTK(KERN_DEBUG
"%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__
, pdc_chassis_old
);
82 * pdc_chassis_panic_event() - Called by the panic handler.
87 * As soon as a panic occurs, we should inform the PDC.
90 static int pdc_chassis_panic_event(struct notifier_block
*this,
91 unsigned long event
, void *ptr
)
93 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC
);
98 static struct notifier_block pdc_chassis_panic_block
= {
99 .notifier_call
= pdc_chassis_panic_event
,
105 * pdc_chassis_reboot_event() - Called by the reboot handler.
110 * As soon as a reboot occurs, we should inform the PDC.
113 static int pdc_chassis_reboot_event(struct notifier_block
*this,
114 unsigned long event
, void *ptr
)
116 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN
);
121 static struct notifier_block pdc_chassis_reboot_block
= {
122 .notifier_call
= pdc_chassis_reboot_event
,
125 #endif /* CONFIG_PDC_CHASSIS */
129 * parisc_pdc_chassis_init() - Called at boot time.
132 void __init
parisc_pdc_chassis_init(void)
134 #ifdef CONFIG_PDC_CHASSIS
135 if (likely(pdc_chassis_enabled
)) {
136 DPRINTK(KERN_DEBUG
"%s: parisc_pdc_chassis_init()\n", __FILE__
);
138 /* Let see if we have something to handle... */
139 printk(KERN_INFO
"Enabling %s chassis codes support v%s\n",
140 is_pdc_pat() ? "PDC_PAT" : "regular",
143 /* initialize panic notifier chain */
144 atomic_notifier_chain_register(&panic_notifier_list
,
145 &pdc_chassis_panic_block
);
147 /* initialize reboot notifier chain */
148 register_reboot_notifier(&pdc_chassis_reboot_block
);
150 #endif /* CONFIG_PDC_CHASSIS */
155 * pdc_chassis_send_status() - Sends a predefined message to the chassis,
156 * and changes the front panel LEDs according to the new system state
157 * @message: Type of message, one of PDC_CHASSIS_DIRECT_* values.
159 * Only machines with 64 bits PDC PAT and those reported in
160 * pdc_chassis_checkold() are supported atm.
162 * returns 0 if no error, -1 if no supported PDC is present or invalid message,
163 * else returns the appropriate PDC error code.
165 * For a list of predefined messages, see asm-parisc/pdc_chassis.h
168 int pdc_chassis_send_status(int message
)
170 /* Maybe we should do that in an other way ? */
172 #ifdef CONFIG_PDC_CHASSIS
173 if (likely(pdc_chassis_enabled
)) {
175 DPRINTK(KERN_DEBUG
"%s: pdc_chassis_send_status(%d)\n", __FILE__
, message
);
180 case PDC_CHASSIS_DIRECT_BSTART
:
181 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART
, PDC_CHASSIS_LSTATE_RUN_NORMAL
);
184 case PDC_CHASSIS_DIRECT_BCOMPLETE
:
185 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE
, PDC_CHASSIS_LSTATE_RUN_NORMAL
);
188 case PDC_CHASSIS_DIRECT_SHUTDOWN
:
189 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN
, PDC_CHASSIS_LSTATE_NONOS
);
192 case PDC_CHASSIS_DIRECT_PANIC
:
193 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC
, PDC_CHASSIS_LSTATE_RUN_CRASHREC
);
196 case PDC_CHASSIS_DIRECT_LPMC
:
197 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC
, PDC_CHASSIS_LSTATE_RUN_SYSINT
);
200 case PDC_CHASSIS_DIRECT_HPMC
:
201 retval
= pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC
, PDC_CHASSIS_LSTATE_RUN_NCRIT
);
211 case PDC_CHASSIS_DIRECT_BSTART
:
212 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT
));
215 case PDC_CHASSIS_DIRECT_BCOMPLETE
:
216 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN
));
219 case PDC_CHASSIS_DIRECT_SHUTDOWN
:
220 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT
));
223 case PDC_CHASSIS_DIRECT_HPMC
:
224 case PDC_CHASSIS_DIRECT_PANIC
:
225 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT
));
228 case PDC_CHASSIS_DIRECT_LPMC
:
229 retval
= pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN
));
236 #endif /* CONFIG_64BIT */
237 } /* if (pdc_chassis_enabled) */
239 /* if system has LCD display, update current string */
240 if (retval
!= -1 && IS_ENABLED(CONFIG_CHASSIS_LCD_LED
))
243 #endif /* CONFIG_PDC_CHASSIS */
247 #ifdef CONFIG_PDC_CHASSIS_WARN
248 #ifdef CONFIG_PROC_FS
249 static int pdc_chassis_warn_show(struct seq_file
*m
, void *v
)
254 if (pdc_chassis_warn(&warn
) != PDC_OK
)
257 warnreg
= (warn
& 0xFFFFFFFF);
259 if ((warnreg
>> 24) & 0xFF)
260 seq_printf(m
, "Chassis component failure! (eg fan or PSU): 0x%.2x\n",
261 (warnreg
>> 24) & 0xFF);
263 seq_printf(m
, "Battery: %s\n", (warnreg
& 0x04) ? "Low!" : "OK");
264 seq_printf(m
, "Temp low: %s\n", (warnreg
& 0x02) ? "Exceeded!" : "OK");
265 seq_printf(m
, "Temp mid: %s\n", (warnreg
& 0x01) ? "Exceeded!" : "OK");
269 static int __init
pdc_chassis_create_procfs(void)
274 ret
= pdc_chassis_warn(&test
);
275 if ((ret
== PDC_BAD_PROC
) || (ret
== PDC_BAD_OPTION
)) {
276 /* seems that some boxes (eg L1000) do not implement this */
277 printk(KERN_INFO
"Chassis warnings not supported.\n");
281 printk(KERN_INFO
"Enabling PDC chassis warnings support v%s\n",
283 proc_create_single("chassis", 0400, NULL
, pdc_chassis_warn_show
);
287 __initcall(pdc_chassis_create_procfs
);
289 #endif /* CONFIG_PROC_FS */
290 #endif /* CONFIG_PDC_CHASSIS_WARN */