pdc_chassis.c 7.7 KB

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