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 73/** 74 * pdc_chassis_panic_event() - Called by the panic handler. 75 * 76 * As soon as a panic occurs, we should inform the PDC. 77 */ 78 79static int pdc_chassis_panic_event(struct notifier_block *this, 80 unsigned long event, void *ptr) 81{ 82 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC); 83 return NOTIFY_DONE; 84} 85 86 87static struct notifier_block pdc_chassis_panic_block = { 88 .notifier_call = pdc_chassis_panic_event, 89 .priority = INT_MAX, 90}; 91 92 93/** 94 * parisc_reboot_event() - Called by the reboot handler. 95 * 96 * As soon as a reboot occurs, we should inform the PDC. 97 */ 98 99static int pdc_chassis_reboot_event(struct notifier_block *this, 100 unsigned long event, void *ptr) 101{ 102 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN); 103 return NOTIFY_DONE; 104} 105 106 107static struct notifier_block pdc_chassis_reboot_block = { 108 .notifier_call = pdc_chassis_reboot_event, 109 .priority = INT_MAX, 110}; 111#endif /* CONFIG_PDC_CHASSIS */ 112 113 114/** 115 * parisc_pdc_chassis_init() - Called at boot time. 116 */ 117 118void __init parisc_pdc_chassis_init(void) 119{ 120#ifdef CONFIG_PDC_CHASSIS 121 if (likely(pdc_chassis_enabled)) { 122 DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__); 123 124 /* Let see if we have something to handle... */ 125 printk(KERN_INFO "Enabling %s chassis codes support v%s\n", 126 is_pdc_pat() ? "PDC_PAT" : "regular", 127 PDC_CHASSIS_VER); 128 129 /* initialize panic notifier chain */ 130 atomic_notifier_chain_register(&panic_notifier_list, 131 &pdc_chassis_panic_block); 132 133 /* initialize reboot notifier chain */ 134 register_reboot_notifier(&pdc_chassis_reboot_block); 135 } 136#endif /* CONFIG_PDC_CHASSIS */ 137} 138 139 140/** 141 * pdc_chassis_send_status() - Sends a predefined message to the chassis, 142 * and changes the front panel LEDs according to the new system state 143 * @retval: PDC call return value. 144 * 145 * Only machines with 64 bits PDC PAT and those reported in 146 * pdc_chassis_checkold() are supported atm. 147 * 148 * returns 0 if no error, -1 if no supported PDC is present or invalid message, 149 * else returns the appropriate PDC error code. 150 * 151 * For a list of predefined messages, see asm-parisc/pdc_chassis.h 152 */ 153 154int pdc_chassis_send_status(int message) 155{ 156 /* Maybe we should do that in an other way ? */ 157 int retval = 0; 158#ifdef CONFIG_PDC_CHASSIS 159 if (likely(pdc_chassis_enabled)) { 160 161 DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message); 162 163#ifdef CONFIG_64BIT 164 if (is_pdc_pat()) { 165 switch(message) { 166 case PDC_CHASSIS_DIRECT_BSTART: 167 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL); 168 break; 169 170 case PDC_CHASSIS_DIRECT_BCOMPLETE: 171 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL); 172 break; 173 174 case PDC_CHASSIS_DIRECT_SHUTDOWN: 175 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS); 176 break; 177 178 case PDC_CHASSIS_DIRECT_PANIC: 179 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC); 180 break; 181 182 case PDC_CHASSIS_DIRECT_LPMC: 183 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT); 184 break; 185 186 case PDC_CHASSIS_DIRECT_HPMC: 187 retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT); 188 break; 189 190 default: 191 retval = -1; 192 } 193 } else retval = -1; 194#else 195 if (1) { 196 switch (message) { 197 case PDC_CHASSIS_DIRECT_BSTART: 198 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT)); 199 break; 200 201 case PDC_CHASSIS_DIRECT_BCOMPLETE: 202 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN)); 203 break; 204 205 case PDC_CHASSIS_DIRECT_SHUTDOWN: 206 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT)); 207 break; 208 209 case PDC_CHASSIS_DIRECT_HPMC: 210 case PDC_CHASSIS_DIRECT_PANIC: 211 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT)); 212 break; 213 214 case PDC_CHASSIS_DIRECT_LPMC: 215 retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN)); 216 break; 217 218 default: 219 retval = -1; 220 } 221 } else retval = -1; 222#endif /* CONFIG_64BIT */ 223 } /* if (pdc_chassis_enabled) */ 224#endif /* CONFIG_PDC_CHASSIS */ 225 return retval; 226} 227 228#ifdef CONFIG_PDC_CHASSIS_WARN 229#ifdef CONFIG_PROC_FS 230static int pdc_chassis_warn_pread(char *page, char **start, off_t off, 231 int count, int *eof, void *data) 232{ 233 char *out = page; 234 int len, ret; 235 unsigned long warn; 236 u32 warnreg; 237 238 ret = pdc_chassis_warn(&warn); 239 if (ret != PDC_OK) 240 return -EIO; 241 242 warnreg = (warn & 0xFFFFFFFF); 243 244 if ((warnreg >> 24) & 0xFF) 245 out += sprintf(out, "Chassis component failure! (eg fan or PSU): 0x%.2x\n", ((warnreg >> 24) & 0xFF)); 246 247 out += sprintf(out, "Battery: %s\n", (warnreg & 0x04) ? "Low!" : "OK"); 248 out += sprintf(out, "Temp low: %s\n", (warnreg & 0x02) ? "Exceeded!" : "OK"); 249 out += sprintf(out, "Temp mid: %s\n", (warnreg & 0x01) ? "Exceeded!" : "OK"); 250 251 len = out - page - off; 252 if (len < count) { 253 *eof = 1; 254 if (len <= 0) return 0; 255 } else { 256 len = count; 257 } 258 *start = page + off; 259 return len; 260} 261 262static int __init pdc_chassis_create_procfs(void) 263{ 264 unsigned long test; 265 int ret; 266 267 ret = pdc_chassis_warn(&test); 268 if ((ret == PDC_BAD_PROC) || (ret == PDC_BAD_OPTION)) { 269 /* seems that some boxes (eg L1000) do not implement this */ 270 printk(KERN_INFO "Chassis warnings not supported.\n"); 271 return 0; 272 } 273 274 printk(KERN_INFO "Enabling PDC chassis warnings support v%s\n", 275 PDC_CHASSIS_VER); 276 create_proc_read_entry("chassis", 0400, NULL, pdc_chassis_warn_pread, 277 NULL); 278 return 0; 279} 280 281__initcall(pdc_chassis_create_procfs); 282 283#endif /* CONFIG_PROC_FS */ 284#endif /* CONFIG_PDC_CHASSIS_WARN */ 285