ras.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Copyright 2006-2008, IBM Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #undef DEBUG
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/smp.h>
  13. #include <linux/reboot.h>
  14. #include <asm/reg.h>
  15. #include <asm/io.h>
  16. #include <asm/prom.h>
  17. #include <asm/machdep.h>
  18. #include <asm/rtas.h>
  19. #include <asm/cell-regs.h>
  20. #include "ras.h"
  21. static void dump_fir(int cpu)
  22. {
  23. struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu);
  24. struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu);
  25. if (pregs == NULL)
  26. return;
  27. /* Todo: do some nicer parsing of bits and based on them go down
  28. * to other sub-units FIRs and not only IIC
  29. */
  30. printk(KERN_ERR "Global Checkstop FIR : 0x%016lx\n",
  31. in_be64(&pregs->checkstop_fir));
  32. printk(KERN_ERR "Global Recoverable FIR : 0x%016lx\n",
  33. in_be64(&pregs->checkstop_fir));
  34. printk(KERN_ERR "Global MachineCheck FIR : 0x%016lx\n",
  35. in_be64(&pregs->spec_att_mchk_fir));
  36. if (iregs == NULL)
  37. return;
  38. printk(KERN_ERR "IOC FIR : 0x%016lx\n",
  39. in_be64(&iregs->ioc_fir));
  40. }
  41. void cbe_system_error_exception(struct pt_regs *regs)
  42. {
  43. int cpu = smp_processor_id();
  44. printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu);
  45. dump_fir(cpu);
  46. dump_stack();
  47. }
  48. void cbe_maintenance_exception(struct pt_regs *regs)
  49. {
  50. int cpu = smp_processor_id();
  51. /*
  52. * Nothing implemented for the maintenance interrupt at this point
  53. */
  54. printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu);
  55. dump_stack();
  56. }
  57. void cbe_thermal_exception(struct pt_regs *regs)
  58. {
  59. int cpu = smp_processor_id();
  60. /*
  61. * Nothing implemented for the thermal interrupt at this point
  62. */
  63. printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu);
  64. dump_stack();
  65. }
  66. static int cbe_machine_check_handler(struct pt_regs *regs)
  67. {
  68. int cpu = smp_processor_id();
  69. printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu);
  70. dump_fir(cpu);
  71. /* No recovery from this code now, lets continue */
  72. return 0;
  73. }
  74. struct ptcal_area {
  75. struct list_head list;
  76. int nid;
  77. int order;
  78. struct page *pages;
  79. };
  80. static LIST_HEAD(ptcal_list);
  81. static int ptcal_start_tok, ptcal_stop_tok;
  82. static int __init cbe_ptcal_enable_on_node(int nid, int order)
  83. {
  84. struct ptcal_area *area;
  85. int ret = -ENOMEM;
  86. unsigned long addr;
  87. #ifdef CONFIG_CRASH_DUMP
  88. rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
  89. #endif
  90. area = kmalloc(sizeof(*area), GFP_KERNEL);
  91. if (!area)
  92. goto out_err;
  93. area->nid = nid;
  94. area->order = order;
  95. area->pages = alloc_pages_node(area->nid, GFP_KERNEL, area->order);
  96. if (!area->pages)
  97. goto out_free_area;
  98. addr = __pa(page_address(area->pages));
  99. ret = -EIO;
  100. if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid,
  101. (unsigned int)(addr >> 32),
  102. (unsigned int)(addr & 0xffffffff))) {
  103. printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n",
  104. __func__, nid);
  105. goto out_free_pages;
  106. }
  107. list_add(&area->list, &ptcal_list);
  108. return 0;
  109. out_free_pages:
  110. __free_pages(area->pages, area->order);
  111. out_free_area:
  112. kfree(area);
  113. out_err:
  114. return ret;
  115. }
  116. static int __init cbe_ptcal_enable(void)
  117. {
  118. const u32 *size;
  119. struct device_node *np;
  120. int order, found_mic = 0;
  121. np = of_find_node_by_path("/rtas");
  122. if (!np)
  123. return -ENODEV;
  124. size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
  125. if (!size)
  126. return -ENODEV;
  127. pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);
  128. order = get_order(*size);
  129. of_node_put(np);
  130. /* support for malta device trees, with be@/mic@ nodes */
  131. for_each_node_by_type(np, "mic-tm") {
  132. cbe_ptcal_enable_on_node(of_node_to_nid(np), order);
  133. found_mic = 1;
  134. }
  135. if (found_mic)
  136. return 0;
  137. /* support for older device tree - use cpu nodes */
  138. for_each_node_by_type(np, "cpu") {
  139. const u32 *nid = of_get_property(np, "node-id", NULL);
  140. if (!nid) {
  141. printk(KERN_ERR "%s: node %s is missing node-id?\n",
  142. __func__, np->full_name);
  143. continue;
  144. }
  145. cbe_ptcal_enable_on_node(*nid, order);
  146. found_mic = 1;
  147. }
  148. return found_mic ? 0 : -ENODEV;
  149. }
  150. static int cbe_ptcal_disable(void)
  151. {
  152. struct ptcal_area *area, *tmp;
  153. int ret = 0;
  154. pr_debug("%s: disabling PTCAL\n", __func__);
  155. list_for_each_entry_safe(area, tmp, &ptcal_list, list) {
  156. /* disable ptcal on this node */
  157. if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) {
  158. printk(KERN_ERR "%s: error disabling PTCAL "
  159. "on node %d!\n", __func__,
  160. area->nid);
  161. ret = -EIO;
  162. continue;
  163. }
  164. /* ensure we can access the PTCAL area */
  165. memset(page_address(area->pages), 0,
  166. 1 << (area->order + PAGE_SHIFT));
  167. /* clean up */
  168. list_del(&area->list);
  169. __free_pages(area->pages, area->order);
  170. kfree(area);
  171. }
  172. return ret;
  173. }
  174. static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
  175. unsigned long code, void *data)
  176. {
  177. return cbe_ptcal_disable();
  178. }
  179. static struct notifier_block cbe_ptcal_reboot_notifier = {
  180. .notifier_call = cbe_ptcal_notify_reboot
  181. };
  182. int __init cbe_ptcal_init(void)
  183. {
  184. int ret;
  185. ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal");
  186. ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal");
  187. if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE
  188. || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)
  189. return -ENODEV;
  190. ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);
  191. if (ret) {
  192. printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
  193. return ret;
  194. }
  195. return cbe_ptcal_enable();
  196. }
  197. arch_initcall(cbe_ptcal_init);
  198. void __init cbe_ras_init(void)
  199. {
  200. unsigned long hid0;
  201. /*
  202. * Enable System Error & thermal interrupts and wakeup conditions
  203. */
  204. hid0 = mfspr(SPRN_HID0);
  205. hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP |
  206. HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP;
  207. mtspr(SPRN_HID0, hid0);
  208. mb();
  209. /*
  210. * Install machine check handler. Leave setting of precise mode to
  211. * what the firmware did for now
  212. */
  213. ppc_md.machine_check_exception = cbe_machine_check_handler;
  214. mb();
  215. /*
  216. * For now, we assume that IOC_FIR is already set to forward some
  217. * error conditions to the System Error handler. If that is not true
  218. * then it will have to be fixed up here.
  219. */
  220. }