pdc_chassis.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. #undef PDC_CHASSIS_DEBUG
  25. #ifdef PDC_CHASSIS_DEBUG
  26. #define DPRINTK(fmt, args...) printk(fmt, ## args)
  27. #else
  28. #define DPRINTK(fmt, args...)
  29. #endif
  30. #include <linux/init.h>
  31. #include <linux/module.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>
  37. #include <linux/seq_file.h>
  38. #include <asm/pdc_chassis.h>
  39. #include <asm/processor.h>
  40. #include <asm/pdc.h>
  41. #include <asm/pdcpat.h>
  42. #define PDC_CHASSIS_VER "0.05"
  43. #ifdef CONFIG_PDC_CHASSIS
  44. static unsigned int pdc_chassis_enabled __read_mostly = 1;
  45. /**
  46. * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
  47. * @str configuration param: 0 to disable chassis log
  48. * @return 1
  49. */
  50. static int __init pdc_chassis_setup(char *str)
  51. {
  52. /*panic_timeout = simple_strtoul(str, NULL, 0);*/
  53. get_option(&str, &pdc_chassis_enabled);
  54. return 1;
  55. }
  56. __setup("pdcchassis=", pdc_chassis_setup);
  57. /**
  58. * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
  59. * @pdc_chassis_old: 1 if old pdc chassis style
  60. *
  61. * Currently, only E class and A180 are known to work with this.
  62. * Inspired by Christoph Plattner
  63. */
  64. #if 0
  65. static void __init pdc_chassis_checkold(void)
  66. {
  67. switch(CPU_HVERSION) {
  68. case 0x480: /* E25 */
  69. case 0x481: /* E35 */
  70. case 0x482: /* E45 */
  71. case 0x483: /* E55 */
  72. case 0x516: /* A180 */
  73. break;
  74. default:
  75. break;
  76. }
  77. DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
  78. }
  79. #endif
  80. /**
  81. * pdc_chassis_panic_event() - Called by the panic handler.
  82. *
  83. * As soon as a panic occurs, we should inform the PDC.
  84. */
  85. static int pdc_chassis_panic_event(struct notifier_block *this,
  86. unsigned long event, void *ptr)
  87. {
  88. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  89. return NOTIFY_DONE;
  90. }
  91. static struct notifier_block pdc_chassis_panic_block = {
  92. .notifier_call = pdc_chassis_panic_event,
  93. .priority = INT_MAX,
  94. };
  95. /**
  96. * parisc_reboot_event() - Called by the reboot handler.
  97. *
  98. * As soon as a reboot occurs, we should inform the PDC.
  99. */
  100. static int pdc_chassis_reboot_event(struct notifier_block *this,
  101. unsigned long event, void *ptr)
  102. {
  103. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
  104. return NOTIFY_DONE;
  105. }
  106. static struct notifier_block pdc_chassis_reboot_block = {
  107. .notifier_call = pdc_chassis_reboot_event,
  108. .priority = INT_MAX,
  109. };
  110. #endif /* CONFIG_PDC_CHASSIS */
  111. /**
  112. * parisc_pdc_chassis_init() - Called at boot time.
  113. */
  114. void __init parisc_pdc_chassis_init(void)
  115. {
  116. #ifdef CONFIG_PDC_CHASSIS
  117. if (likely(pdc_chassis_enabled)) {
  118. DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
  119. /* Let see if we have something to handle... */
  120. printk(KERN_INFO "Enabling %s chassis codes support v%s\n",
  121. is_pdc_pat() ? "PDC_PAT" : "regular",
  122. PDC_CHASSIS_VER);
  123. /* initialize panic notifier chain */
  124. atomic_notifier_chain_register(&panic_notifier_list,
  125. &pdc_chassis_panic_block);
  126. /* initialize reboot notifier chain */
  127. register_reboot_notifier(&pdc_chassis_reboot_block);
  128. }
  129. #endif /* CONFIG_PDC_CHASSIS */
  130. }
  131. /**
  132. * pdc_chassis_send_status() - Sends a predefined message to the chassis,
  133. * and changes the front panel LEDs according to the new system state
  134. * @retval: PDC call return value.
  135. *
  136. * Only machines with 64 bits PDC PAT and those reported in
  137. * pdc_chassis_checkold() are supported atm.
  138. *
  139. * returns 0 if no error, -1 if no supported PDC is present or invalid message,
  140. * else returns the appropriate PDC error code.
  141. *
  142. * For a list of predefined messages, see asm-parisc/pdc_chassis.h
  143. */
  144. int pdc_chassis_send_status(int message)
  145. {
  146. /* Maybe we should do that in an other way ? */
  147. int retval = 0;
  148. #ifdef CONFIG_PDC_CHASSIS
  149. if (likely(pdc_chassis_enabled)) {
  150. DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
  151. #ifdef CONFIG_64BIT
  152. if (is_pdc_pat()) {
  153. switch(message) {
  154. case PDC_CHASSIS_DIRECT_BSTART:
  155. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
  156. break;
  157. case PDC_CHASSIS_DIRECT_BCOMPLETE:
  158. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
  159. break;
  160. case PDC_CHASSIS_DIRECT_SHUTDOWN:
  161. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
  162. break;
  163. case PDC_CHASSIS_DIRECT_PANIC:
  164. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
  165. break;
  166. case PDC_CHASSIS_DIRECT_LPMC:
  167. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
  168. break;
  169. case PDC_CHASSIS_DIRECT_HPMC:
  170. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
  171. break;
  172. default:
  173. retval = -1;
  174. }
  175. } else retval = -1;
  176. #else
  177. if (1) {
  178. switch (message) {
  179. case PDC_CHASSIS_DIRECT_BSTART:
  180. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_INIT));
  181. break;
  182. case PDC_CHASSIS_DIRECT_BCOMPLETE:
  183. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));
  184. break;
  185. case PDC_CHASSIS_DIRECT_SHUTDOWN:
  186. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));
  187. break;
  188. case PDC_CHASSIS_DIRECT_HPMC:
  189. case PDC_CHASSIS_DIRECT_PANIC:
  190. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));
  191. break;
  192. case PDC_CHASSIS_DIRECT_LPMC:
  193. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));
  194. break;
  195. default:
  196. retval = -1;
  197. }
  198. } else retval = -1;
  199. #endif /* CONFIG_64BIT */
  200. } /* if (pdc_chassis_enabled) */
  201. #endif /* CONFIG_PDC_CHASSIS */
  202. return retval;
  203. }
  204. #ifdef CONFIG_PDC_CHASSIS_WARN
  205. #ifdef CONFIG_PROC_FS
  206. static int pdc_chassis_warn_show(struct seq_file *m, void *v)
  207. {
  208. unsigned long warn;
  209. u32 warnreg;
  210. if (pdc_chassis_warn(&warn) != PDC_OK)
  211. return -EIO;
  212. warnreg = (warn & 0xFFFFFFFF);
  213. if ((warnreg >> 24) & 0xFF)
  214. seq_printf(m, "Chassis component failure! (eg fan or PSU): 0x%.2x\n",
  215. (warnreg >> 24) & 0xFF);
  216. seq_printf(m, "Battery: %s\n", (warnreg & 0x04) ? "Low!" : "OK");
  217. seq_printf(m, "Temp low: %s\n", (warnreg & 0x02) ? "Exceeded!" : "OK");
  218. seq_printf(m, "Temp mid: %s\n", (warnreg & 0x01) ? "Exceeded!" : "OK");
  219. return 0;
  220. }
  221. static int pdc_chassis_warn_open(struct inode *inode, struct file *file)
  222. {
  223. return single_open(file, pdc_chassis_warn_show, NULL);
  224. }
  225. static const struct file_operations pdc_chassis_warn_fops = {
  226. .open = pdc_chassis_warn_open,
  227. .read = seq_read,
  228. .llseek = seq_lseek,
  229. .release = single_release,
  230. };
  231. static int __init pdc_chassis_create_procfs(void)
  232. {
  233. unsigned long test;
  234. int ret;
  235. ret = pdc_chassis_warn(&test);
  236. if ((ret == PDC_BAD_PROC) || (ret == PDC_BAD_OPTION)) {
  237. /* seems that some boxes (eg L1000) do not implement this */
  238. printk(KERN_INFO "Chassis warnings not supported.\n");
  239. return 0;
  240. }
  241. printk(KERN_INFO "Enabling PDC chassis warnings support v%s\n",
  242. PDC_CHASSIS_VER);
  243. proc_create("chassis", 0400, NULL, &pdc_chassis_warn_fops);
  244. return 0;
  245. }
  246. __initcall(pdc_chassis_create_procfs);
  247. #endif /* CONFIG_PROC_FS */
  248. #endif /* CONFIG_PDC_CHASSIS_WARN */