pdc_chassis.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 <linux/cache.h>
  32. #include <asm/pdc_chassis.h>
  33. #include <asm/processor.h>
  34. #include <asm/pdc.h>
  35. #include <asm/pdcpat.h>
  36. #ifdef CONFIG_PDC_CHASSIS
  37. static int pdc_chassis_old __read_mostly = 0;
  38. static unsigned int pdc_chassis_enabled __read_mostly = 1;
  39. /**
  40. * pdc_chassis_setup() - Enable/disable pdc_chassis code at boot time.
  41. * @str configuration param: 0 to disable chassis log
  42. * @return 1
  43. */
  44. static int __init pdc_chassis_setup(char *str)
  45. {
  46. /*panic_timeout = simple_strtoul(str, NULL, 0);*/
  47. get_option(&str, &pdc_chassis_enabled);
  48. return 1;
  49. }
  50. __setup("pdcchassis=", pdc_chassis_setup);
  51. /**
  52. * pdc_chassis_checkold() - Checks for old PDC_CHASSIS compatibility
  53. * @pdc_chassis_old: 1 if old pdc chassis style
  54. *
  55. * Currently, only E class and A180 are known to work with this.
  56. * Inspired by Christoph Plattner
  57. */
  58. static void __init pdc_chassis_checkold(void)
  59. {
  60. switch(CPU_HVERSION) {
  61. case 0x480: /* E25 */
  62. case 0x481: /* E35 */
  63. case 0x482: /* E45 */
  64. case 0x483: /* E55 */
  65. case 0x516: /* A180 */
  66. pdc_chassis_old = 1;
  67. break;
  68. default:
  69. break;
  70. }
  71. DPRINTK(KERN_DEBUG "%s: pdc_chassis_checkold(); pdc_chassis_old = %d\n", __FILE__, pdc_chassis_old);
  72. }
  73. /**
  74. * pdc_chassis_panic_event() - Called by the panic handler.
  75. *
  76. * As soon as a panic occurs, we should inform the PDC.
  77. */
  78. static int pdc_chassis_panic_event(struct notifier_block *this,
  79. unsigned long event, void *ptr)
  80. {
  81. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  82. return NOTIFY_DONE;
  83. }
  84. static struct notifier_block pdc_chassis_panic_block = {
  85. .notifier_call = pdc_chassis_panic_event,
  86. .priority = INT_MAX,
  87. };
  88. /**
  89. * parisc_reboot_event() - Called by the reboot handler.
  90. *
  91. * As soon as a reboot occurs, we should inform the PDC.
  92. */
  93. static int pdc_chassis_reboot_event(struct notifier_block *this,
  94. unsigned long event, void *ptr)
  95. {
  96. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
  97. return NOTIFY_DONE;
  98. }
  99. static struct notifier_block pdc_chassis_reboot_block = {
  100. .notifier_call = pdc_chassis_reboot_event,
  101. .priority = INT_MAX,
  102. };
  103. #endif /* CONFIG_PDC_CHASSIS */
  104. /**
  105. * parisc_pdc_chassis_init() - Called at boot time.
  106. */
  107. void __init parisc_pdc_chassis_init(void)
  108. {
  109. #ifdef CONFIG_PDC_CHASSIS
  110. int handle = 0;
  111. if (likely(pdc_chassis_enabled)) {
  112. DPRINTK(KERN_DEBUG "%s: parisc_pdc_chassis_init()\n", __FILE__);
  113. /* Let see if we have something to handle... */
  114. /* Check for PDC_PAT or old LED Panel */
  115. pdc_chassis_checkold();
  116. if (is_pdc_pat()) {
  117. printk(KERN_INFO "Enabling PDC_PAT chassis codes support.\n");
  118. handle = 1;
  119. }
  120. else if (unlikely(pdc_chassis_old)) {
  121. printk(KERN_INFO "Enabling old style chassis LED panel support.\n");
  122. handle = 1;
  123. }
  124. if (handle) {
  125. /* initialize panic notifier chain */
  126. notifier_chain_register(&panic_notifier_list, &pdc_chassis_panic_block);
  127. /* initialize reboot notifier chain */
  128. register_reboot_notifier(&pdc_chassis_reboot_block);
  129. }
  130. }
  131. #endif /* CONFIG_PDC_CHASSIS */
  132. }
  133. /**
  134. * pdc_chassis_send_status() - Sends a predefined message to the chassis,
  135. * and changes the front panel LEDs according to the new system state
  136. * @retval: PDC call return value.
  137. *
  138. * Only machines with 64 bits PDC PAT and those reported in
  139. * pdc_chassis_checkold() are supported atm.
  140. *
  141. * returns 0 if no error, -1 if no supported PDC is present or invalid message,
  142. * else returns the appropriate PDC error code.
  143. *
  144. * For a list of predefined messages, see asm-parisc/pdc_chassis.h
  145. */
  146. int pdc_chassis_send_status(int message)
  147. {
  148. /* Maybe we should do that in an other way ? */
  149. int retval = 0;
  150. #ifdef CONFIG_PDC_CHASSIS
  151. if (likely(pdc_chassis_enabled)) {
  152. DPRINTK(KERN_DEBUG "%s: pdc_chassis_send_status(%d)\n", __FILE__, message);
  153. #ifdef CONFIG_64BIT
  154. if (is_pdc_pat()) {
  155. switch(message) {
  156. case PDC_CHASSIS_DIRECT_BSTART:
  157. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BSTART, PDC_CHASSIS_LSTATE_RUN_NORMAL);
  158. break;
  159. case PDC_CHASSIS_DIRECT_BCOMPLETE:
  160. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_BCOMPLETE, PDC_CHASSIS_LSTATE_RUN_NORMAL);
  161. break;
  162. case PDC_CHASSIS_DIRECT_SHUTDOWN:
  163. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_SHUTDOWN, PDC_CHASSIS_LSTATE_NONOS);
  164. break;
  165. case PDC_CHASSIS_DIRECT_PANIC:
  166. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_PANIC, PDC_CHASSIS_LSTATE_RUN_CRASHREC);
  167. break;
  168. case PDC_CHASSIS_DIRECT_LPMC:
  169. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_LPMC, PDC_CHASSIS_LSTATE_RUN_SYSINT);
  170. break;
  171. case PDC_CHASSIS_DIRECT_HPMC:
  172. retval = pdc_pat_chassis_send_log(PDC_CHASSIS_PMSG_HPMC, PDC_CHASSIS_LSTATE_RUN_NCRIT);
  173. break;
  174. default:
  175. retval = -1;
  176. }
  177. } else retval = -1;
  178. #else
  179. if (unlikely(pdc_chassis_old)) {
  180. switch (message) {
  181. case PDC_CHASSIS_DIRECT_BSTART:
  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. }