Path: blob/master/arch/parisc/kernel/pdc_chassis.c
10819 views
/*1* interfaces to Chassis Codes via PDC (firmware)2*3* Copyright (C) 2002 Laurent Canet <[email protected]>4* Copyright (C) 2002-2006 Thibaut VARENE <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License, version 2, as8* published by the Free Software Foundation.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License16* along with this program; if not, write to the Free Software17* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA18*19* TODO: poll chassis warns, trigger (configurable) machine shutdown when20* needed.21* Find out how to get Chassis warnings out of PAT boxes?22*/2324#undef PDC_CHASSIS_DEBUG25#ifdef PDC_CHASSIS_DEBUG26#define DPRINTK(fmt, args...) printk(fmt, ## args)27#else28#define DPRINTK(fmt, args...)29#endif3031#include <linux/init.h>32#include <linux/kernel.h>33#include <linux/reboot.h>34#include <linux/notifier.h>35#include <linux/cache.h>36#include <linux/proc_fs.h>3738#include <asm/pdc_chassis.h>39#include <asm/processor.h>40#include <asm/pdc.h>41#include <asm/pdcpat.h>4243#define PDC_CHASSIS_VER "0.05"4445#ifdef CONFIG_PDC_CHASSIS46static unsigned int pdc_chassis_enabled __read_mostly = 1;474849/**50* pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.51* @str configuration param: 0 to disable chassis log52* @return 153*/5455static int __init pdc_chassis_setup(char *str)56{57/*panic_timeout = simple_strtoul(str, NULL, 0);*/58get_option(&str, &pdc_chassis_enabled);59return 1;60}61__setup("pdcchassis=", pdc_chassis_setup);626364/**65* pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility66* @pdc_chassis_old: 1 if old pdc chassis style67*68* Currently, only E class and A180 are known to work with this.69* Inspired by Christoph Plattner70*/71#if 072static void __init pdc_chassis_checkold(void)73{74switch(CPU_HVERSION) {75case 0x480: /* E25 */76case 0x481: /* E35 */77case 0x482: /* E45 */78case 0x483: /* E55 */79case 0x516: /* A180 */80break;8182default:83break;84}85DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);86}87#endif8889/**90* pdc_chassis_panic_event() - Called by the panic handler.91*92* As soon as a panic occurs, we should inform the PDC.93*/9495static int pdc_chassis_panic_event(struct notifier_block *this,96unsigned long event, void *ptr)97{98pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);99return NOTIFY_DONE;100}101102103static struct notifier_block pdc_chassis_panic_block = {104.notifier_call = pdc_chassis_panic_event,105.priority = INT_MAX,106};107108109/**110* parisc_reboot_event() - Called by the reboot handler.111*112* As soon as a reboot occurs, we should inform the PDC.113*/114115static int pdc_chassis_reboot_event(struct notifier_block *this,116unsigned long event, void *ptr)117{118pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);119return NOTIFY_DONE;120}121122123static struct notifier_block pdc_chassis_reboot_block = {124.notifier_call = pdc_chassis_reboot_event,125.priority = INT_MAX,126};127#endif /* CONFIG_PDC_CHASSIS */128129130/**131* parisc_pdc_chassis_init() - Called at boot time.132*/133134void __init parisc_pdc_chassis_init(void)135{136#ifdef CONFIG_PDC_CHASSIS137if (likely(pdc_chassis_enabled)) {138DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);139140/* Let see if we have something to handle... */141printk(KERN_INFO "Enabling %s chassis codes support v%s\n",142is_pdc_pat() ? "PDC_PAT" : "regular",143PDC_CHASSIS_VER);144145/* initialize panic notifier chain */146atomic_notifier_chain_register(&panic_notifier_list,147&pdc_chassis_panic_block);148149/* initialize reboot notifier chain */150register_reboot_notifier(&pdc_chassis_reboot_block);151}152#endif /* CONFIG_PDC_CHASSIS */153}154155156/**157* pdc_chassis_send_status() - Sends a predefined message to the chassis,158* and changes the front panel LEDs according to the new system state159* @retval: PDC call return value.160*161* Only machines with 64 bits PDC PAT and those reported in162* pdc_chassis_checkold() are supported atm.163*164* returns 0 if no error, -1 if no supported PDC is present or invalid message,165* else returns the appropriate PDC error code.166*167* For a list of predefined messages, see asm-parisc/pdc_chassis.h168*/169170int pdc_chassis_send_status(int message)171{172/* Maybe we should do that in an other way ? */173int retval = 0;174#ifdef CONFIG_PDC_CHASSIS175if (likely(pdc_chassis_enabled)) {176177DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);178179#ifdef CONFIG_64BIT180if (is_pdc_pat()) {181switch(message) {182case PDC_CHASSIS_DIRECT_BSTART:183retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);184break;185186case PDC_CHASSIS_DIRECT_BCOMPLETE:187retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);188break;189190case PDC_CHASSIS_DIRECT_SHUTDOWN:191retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);192break;193194case PDC_CHASSIS_DIRECT_PANIC:195retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);196break;197198case PDC_CHASSIS_DIRECT_LPMC:199retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);200break;201202case PDC_CHASSIS_DIRECT_HPMC:203retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);204break;205206default:207retval = -1;208}209} else retval = -1;210#else211if (1) {212switch (message) {213case PDC_CHASSIS_DIRECT_BSTART:214retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT));215break;216217case PDC_CHASSIS_DIRECT_BCOMPLETE:218retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));219break;220221case PDC_CHASSIS_DIRECT_SHUTDOWN:222retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));223break;224225case PDC_CHASSIS_DIRECT_HPMC:226case PDC_CHASSIS_DIRECT_PANIC:227retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));228break;229230case PDC_CHASSIS_DIRECT_LPMC:231retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));232break;233234default:235retval = -1;236}237} else retval = -1;238#endif /* CONFIG_64BIT */239} /* if (pdc_chassis_enabled) */240#endif /* CONFIG_PDC_CHASSIS */241return retval;242}243244#ifdef CONFIG_PDC_CHASSIS_WARN245#ifdef CONFIG_PROC_FS246static int pdc_chassis_warn_pread(char *page, char **start, off_t off,247int count, int *eof, void *data)248{249char *out = page;250int len, ret;251unsigned long warn;252u32 warnreg;253254ret = pdc_chassis_warn(&warn);255if (ret != PDC_OK)256return -EIO;257258warnreg = (warn & 0xFFFFFFFF);259260if ((warnreg >> 24) & 0xFF)261out += sprintf(out, "Chassis component failure! (eg fan or PSU): 0x%.2x\n", ((warnreg >> 24) & 0xFF));262263out += sprintf(out, "Battery: %s\n", (warnreg & 0x04) ? "Low!" : "OK");264out += sprintf(out, "Temp low: %s\n", (warnreg & 0x02) ? "Exceeded!" : "OK");265out += sprintf(out, "Temp mid: %s\n", (warnreg & 0x01) ? "Exceeded!" : "OK");266267len = out - page - off;268if (len < count) {269*eof = 1;270if (len <= 0) return 0;271} else {272len = count;273}274*start = page + off;275return len;276}277278static int __init pdc_chassis_create_procfs(void)279{280unsigned long test;281int ret;282283ret = pdc_chassis_warn(&test);284if ((ret == PDC_BAD_PROC) || (ret == PDC_BAD_OPTION)) {285/* seems that some boxes (eg L1000) do not implement this */286printk(KERN_INFO "Chassis warnings not supported.\n");287return 0;288}289290printk(KERN_INFO "Enabling PDC chassis warnings support v%s\n",291PDC_CHASSIS_VER);292create_proc_read_entry("chassis", 0400, NULL, pdc_chassis_warn_pread,293NULL);294return 0;295}296297__initcall(pdc_chassis_create_procfs);298299#endif /* CONFIG_PROC_FS */300#endif /* CONFIG_PDC_CHASSIS_WARN */301302303