pdc_chassis.c 7.9 KB

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