2 * interfaces to Chassis Codes via PDC (firmware)
4 * Copyright (C) 2002 Laurent Canet <canetl@esiee.fr>
5 * Copyright (C) 2002-2006 Thibaut VARENE <varenet@parisc-linux.org>
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.
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.
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
20 * TODO: poll chassis warns, trigger (configurable) machine shutdown when
22 * Find out how to get Chassis warnings out of PAT boxes?
25 #undef PDC_CHASSIS_DEBUG
26 #ifdef PDC_CHASSIS_DEBUG
27 #define DPRINTK(fmt, args...) printk(fmt, ## args)
29 #define DPRINTK(fmt, args...)
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>
39 #include <asm/pdc_chassis.h>
40 #include <asm/processor.h>
42 #include <asm/pdcpat.h>
44 #define PDC_CHASSIS_VER "0.05"
46 #ifdef CONFIG_PDC_CHASSIS
47 static unsigned int pdc_chassis_enabled __read_mostly = 1;
51 * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
52 * @str configuration param: 0 to disable chassis log
56 static int __init pdc_chassis_setup(char *str)
58 /*panic_timeout = simple_strtoul(str, NULL, 0);*/
59 get_option(&str, &pdc_chassis_enabled);
62 __setup("pdcchassis=", pdc_chassis_setup);
66 * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
67 * @pdc_chassis_old: 1 if old pdc chassis style
69 * Currently, only E class and A180 are known to work with this.
70 * Inspired by Christoph Plattner
73 static void __init pdc_chassis_checkold(void)
75 switch(CPU_HVERSION) {
80 case 0x516: /* A180 */
86 DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
91 * pdc_chassis_panic_event() - Called by the panic handler.
93 * As soon as a panic occurs, we should inform the PDC.
96 static int pdc_chassis_panic_event(struct notifier_block *this,
97 unsigned long event, void *ptr)
99 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
104 static struct notifier_block pdc_chassis_panic_block = {
105 .notifier_call = pdc_chassis_panic_event,
111 * parisc_reboot_event() - Called by the reboot handler.
113 * As soon as a reboot occurs, we should inform the PDC.
116 static int pdc_chassis_reboot_event(struct notifier_block *this,
117 unsigned long event, void *ptr)
119 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
124 static struct notifier_block pdc_chassis_reboot_block = {
125 .notifier_call = pdc_chassis_reboot_event,
128 #endif /* CONFIG_PDC_CHASSIS */
132 * parisc_pdc_chassis_init() - Called at boot time.
135 void __init parisc_pdc_chassis_init(void)
137 #ifdef CONFIG_PDC_CHASSIS
138 if (likely(pdc_chassis_enabled)) {
139 DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
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",
146 /* initialize panic notifier chain */
147 atomic_notifier_chain_register(&panic_notifier_list,
148 &pdc_chassis_panic_block);
150 /* initialize reboot notifier chain */
151 register_reboot_notifier(&pdc_chassis_reboot_block);
153 #endif /* CONFIG_PDC_CHASSIS */
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.
162 * Only machines with 64 bits PDC PAT and those reported in
163 * pdc_chassis_checkold() are supported atm.
165 * returns 0 if no error, -1 if no supported PDC is present or invalid message,
166 * else returns the appropriate PDC error code.
168 * For a list of predefined messages, see asm-parisc/pdc_chassis.h
171 int pdc_chassis_send_status(int message)
173 /* Maybe we should do that in an other way ? */
175 #ifdef CONFIG_PDC_CHASSIS
176 if (likely(pdc_chassis_enabled)) {
178 DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
183 case PDC_CHASSIS_DIRECT_BSTART:
184 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
187 case PDC_CHASSIS_DIRECT_BCOMPLETE:
188 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
191 case PDC_CHASSIS_DIRECT_SHUTDOWN:
192 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
195 case PDC_CHASSIS_DIRECT_PANIC:
196 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
199 case PDC_CHASSIS_DIRECT_LPMC:
200 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
203 case PDC_CHASSIS_DIRECT_HPMC:
204 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
214 case PDC_CHASSIS_DIRECT_BSTART:
215 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT));
218 case PDC_CHASSIS_DIRECT_BCOMPLETE:
219 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));
222 case PDC_CHASSIS_DIRECT_SHUTDOWN:
223 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));
226 case PDC_CHASSIS_DIRECT_HPMC:
227 case PDC_CHASSIS_DIRECT_PANIC:
228 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));
231 case PDC_CHASSIS_DIRECT_LPMC:
232 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));
239 #endif /* CONFIG_64BIT */
240 } /* if (pdc_chassis_enabled) */
241 #endif /* CONFIG_PDC_CHASSIS */
245 #ifdef CONFIG_PDC_CHASSIS_WARN
246 #ifdef CONFIG_PROC_FS
247 static int pdc_chassis_warn_pread(char *page, char **start, off_t off,
248 int count, int *eof, void *data)
255 ret = pdc_chassis_warn(&warn);
259 warnreg = (warn & 0xFFFFFFFF);
261 if ((warnreg >> 24) & 0xFF)
262 out += sprintf(out, "Chassis component failure! (eg fan or PSU): 0x%.2x\n", ((warnreg >> 24) & 0xFF));
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");
268 len = out - page - off;
271 if (len <= 0) return 0;
279 static int __init pdc_chassis_create_procfs(void)
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");
291 printk(KERN_INFO "Enabling PDC chassis warnings support v%s\n",
293 create_proc_read_entry("chassis", 0400, NULL, pdc_chassis_warn_pread,
298 __initcall(pdc_chassis_create_procfs);
300 #endif /* CONFIG_PROC_FS */
301 #endif /* CONFIG_PDC_CHASSIS_WARN */