pdc_chassis.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * interfaces to log Chassis Codes via PDC (firmware)
  3. *
  4. * Copyright (C) 2002 Laurent Canet <canetl@esiee.fr>
  5. * Copyright (C) 2002-2004 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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #undef PDC_CHASSIS_DEBUG
  22. #ifdef PDC_CHASSIS_DEBUG
  23. #define DPRINTK(fmt, args...) printk(fmt, ## args)
  24. #else
  25. #define DPRINTK(fmt, args...)
  26. #endif
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/reboot.h>
  30. #include <linux/notifier.h>
  31. #include <asm/pdc_chassis.h>
  32. #include <asm/processor.h>
  33. #include <asm/pdc.h>
  34. #include <asm/pdcpat.h>
  35. #ifdef CONFIG_PDC_CHASSIS
  36. static int pdc_chassis_old = 0;
  37. static unsigned int pdc_chassis_enabled = 1;
  38. /**
  39. * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
  40. * @str configuration param: 0 to disable chassis log
  41. * @return 1
  42. */
  43. static int __init pdc_chassis_setup(char *str)
  44. {
  45. /*panic_timeout = simple_strtoul(str, NULL, 0);*/
  46. get_option(&str, &pdc_chassis_enabled);
  47. return 1;
  48. }
  49. __setup("pdcchassis=", pdc_chassis_setup);
  50. /**
  51. * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
  52. * @pdc_chassis_old: 1 if old pdc chassis style
  53. *
  54. * Currently, only E class and A180 are known to work with this.
  55. * Inspired by Christoph Plattner
  56. */
  57. static void __init pdc_chassis_checkold(void)
  58. {
  59. switch(CPU_HVERSION) {
  60. case 0x480: /* E25 */
  61. case 0x481: /* E35 */
  62. case 0x482: /* E45 */
  63. case 0x483: /* E55 */
  64. case 0x516: /* A180 */
  65. pdc_chassis_old = 1;
  66. break;
  67. default:
  68. break;
  69. }
  70. DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
  71. }
  72. /**
  73. * pdc_chassis_panic_event() - Called by the panic handler.
  74. *
  75. * As soon as a panic occurs, we should inform the PDC.
  76. */
  77. static int pdc_chassis_panic_event(struct notifier_block *this,
  78. unsigned long event, void *ptr)
  79. {
  80. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  81. return NOTIFY_DONE;
  82. }
  83. static struct notifier_block pdc_chassis_panic_block = {
  84. .notifier_call = pdc_chassis_panic_event,
  85. .priority = INT_MAX,
  86. };
  87. /**
  88. * parisc_reboot_event() - Called by the reboot handler.
  89. *
  90. * As soon as a reboot occurs, we should inform the PDC.
  91. */
  92. static int pdc_chassis_reboot_event(struct notifier_block *this,
  93. unsigned long event, void *ptr)
  94. {
  95. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
  96. return NOTIFY_DONE;
  97. }
  98. static struct notifier_block pdc_chassis_reboot_block = {
  99. .notifier_call = pdc_chassis_reboot_event,
  100. .priority = INT_MAX,
  101. };
  102. #endif /* CONFIG_PDC_CHASSIS */
  103. /**
  104. * parisc_pdc_chassis_init() - Called at boot time.
  105. */
  106. void __init parisc_pdc_chassis_init(void)
  107. {
  108. #ifdef CONFIG_PDC_CHASSIS
  109. int handle = 0;
  110. if (pdc_chassis_enabled) {
  111. DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
  112. /* Let see if we have something to handle... */
  113. /* Check for PDC_PAT or old LED Panel */
  114. pdc_chassis_checkold();
  115. if (is_pdc_pat()) {
  116. printk(KERN_INFO "Enabling PDC_PAT chassis codes support.\n");
  117. handle = 1;
  118. }
  119. else if (pdc_chassis_old) {
  120. printk(KERN_INFO "Enabling old style chassis LED panel support.\n");
  121. handle = 1;
  122. }
  123. if (handle) {
  124. /* initialize panic notifier chain */
  125. notifier_chain_register(&panic_notifier_list, &pdc_chassis_panic_block);
  126. /* initialize reboot notifier chain */
  127. register_reboot_notifier(&pdc_chassis_reboot_block);
  128. }
  129. }
  130. #endif /* CONFIG_PDC_CHASSIS */
  131. }
  132. /**
  133. * pdc_chassis_send_status() - Sends a predefined message to the chassis,
  134. * and changes the front panel LEDs according to the new system state
  135. * @retval: PDC call return value.
  136. *
  137. * Only machines with 64 bits PDC PAT and those reported in
  138. * pdc_chassis_checkold() are supported atm.
  139. *
  140. * returns 0 if no error, -1 if no supported PDC is present or invalid message,
  141. * else returns the appropriate PDC error code.
  142. *
  143. * For a list of predefined messages, see asm-parisc/pdc_chassis.h
  144. */
  145. int pdc_chassis_send_status(int message)
  146. {
  147. /* Maybe we should do that in an other way ? */
  148. int retval = 0;
  149. #ifdef CONFIG_PDC_CHASSIS
  150. if (pdc_chassis_enabled) {
  151. DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
  152. #ifdef CONFIG_64BIT
  153. if (is_pdc_pat()) {
  154. switch(message) {
  155. case PDC_CHASSIS_DIRECT_BSTART:
  156. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
  157. break;
  158. case PDC_CHASSIS_DIRECT_BCOMPLETE:
  159. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
  160. break;
  161. case PDC_CHASSIS_DIRECT_SHUTDOWN:
  162. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
  163. break;
  164. case PDC_CHASSIS_DIRECT_PANIC:
  165. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
  166. break;
  167. case PDC_CHASSIS_DIRECT_LPMC:
  168. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
  169. break;
  170. case PDC_CHASSIS_DIRECT_HPMC:
  171. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
  172. break;
  173. default:
  174. retval = -1;
  175. }
  176. } else retval = -1;
  177. #else
  178. if (pdc_chassis_old) {
  179. switch (message) {
  180. case PDC_CHASSIS_DIRECT_BSTART:
  181. case PDC_CHASSIS_DIRECT_BCOMPLETE:
  182. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_RUN));
  183. break;
  184. case PDC_CHASSIS_DIRECT_SHUTDOWN:
  185. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_SHUT));
  186. break;
  187. case PDC_CHASSIS_DIRECT_HPMC:
  188. case PDC_CHASSIS_DIRECT_PANIC:
  189. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_FLT));
  190. break;
  191. case PDC_CHASSIS_DIRECT_LPMC:
  192. retval = pdc_chassis_disp(PDC_CHASSIS_DISP_DATA(OSTAT_WARN));
  193. break;
  194. default:
  195. retval = -1;
  196. }
  197. } else retval = -1;
  198. #endif /* CONFIG_64BIT */
  199. } /* if (pdc_chassis_enabled) */
  200. #endif /* CONFIG_PDC_CHASSIS */
  201. return retval;
  202. }