ras.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 <linux/kexec.h>
  15. #include <linux/crash_dump.h>
  16. #include <asm/kexec.h>
  17. #include <asm/reg.h>
  18. #include <asm/io.h>
  19. #include <asm/prom.h>
  20. #include <asm/machdep.h>
  21. #include <asm/rtas.h>
  22. #include <asm/cell-regs.h>
  23. #include "ras.h"
  24. static void dump_fir(int cpu)
  25. {
  26. struct cbe_pmd_regs __iomem *pregs = cbe_get_cpu_pmd_regs(cpu);
  27. struct cbe_iic_regs __iomem *iregs = cbe_get_cpu_iic_regs(cpu);
  28. if (pregs == NULL)
  29. return;
  30. /* Todo: do some nicer parsing of bits and based on them go down
  31. * to other sub-units FIRs and not only IIC
  32. */
  33. printk(KERN_ERR "Global Checkstop FIR : 0x%016llx\n",
  34. in_be64(&pregs->checkstop_fir));
  35. printk(KERN_ERR "Global Recoverable FIR : 0x%016llx\n",
  36. in_be64(&pregs->checkstop_fir));
  37. printk(KERN_ERR "Global MachineCheck FIR : 0x%016llx\n",
  38. in_be64(&pregs->spec_att_mchk_fir));
  39. if (iregs == NULL)
  40. return;
  41. printk(KERN_ERR "IOC FIR : 0x%016llx\n",
  42. in_be64(&iregs->ioc_fir));
  43. }
  44. void cbe_system_error_exception(struct pt_regs *regs)
  45. {
  46. int cpu = smp_processor_id();
  47. printk(KERN_ERR "System Error Interrupt on CPU %d !\n", cpu);
  48. dump_fir(cpu);
  49. dump_stack();
  50. }
  51. void cbe_maintenance_exception(struct pt_regs *regs)
  52. {
  53. int cpu = smp_processor_id();
  54. /*
  55. * Nothing implemented for the maintenance interrupt at this point
  56. */
  57. printk(KERN_ERR "Unhandled Maintenance interrupt on CPU %d !\n", cpu);
  58. dump_stack();
  59. }
  60. void cbe_thermal_exception(struct pt_regs *regs)
  61. {
  62. int cpu = smp_processor_id();
  63. /*
  64. * Nothing implemented for the thermal interrupt at this point
  65. */
  66. printk(KERN_ERR "Unhandled Thermal interrupt on CPU %d !\n", cpu);
  67. dump_stack();
  68. }
  69. static int cbe_machine_check_handler(struct pt_regs *regs)
  70. {
  71. int cpu = smp_processor_id();
  72. printk(KERN_ERR "Machine Check Interrupt on CPU %d !\n", cpu);
  73. dump_fir(cpu);
  74. /* No recovery from this code now, lets continue */
  75. return 0;
  76. }
  77. struct ptcal_area {
  78. struct list_head list;
  79. int nid;
  80. int order;
  81. struct page *pages;
  82. };
  83. static LIST_HEAD(ptcal_list);
  84. static int ptcal_start_tok, ptcal_stop_tok;
  85. static int __init cbe_ptcal_enable_on_node(int nid, int order)
  86. {
  87. struct ptcal_area *area;
  88. int ret = -ENOMEM;
  89. unsigned long addr;
  90. if (is_kdump_kernel())
  91. rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
  92. area = kmalloc(sizeof(*area), GFP_KERNEL);
  93. if (!area)
  94. goto out_err;
  95. area->nid = nid;
  96. area->order = order;
  97. area->pages = alloc_pages_node(area->nid, GFP_KERNEL, area->order);
  98. if (!area->pages)
  99. goto out_free_area;
  100. addr = __pa(page_address(area->pages));
  101. ret = -EIO;
  102. if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid,
  103. (unsigned int)(addr >> 32),
  104. (unsigned int)(addr & 0xffffffff))) {
  105. printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n",
  106. __func__, nid);
  107. goto out_free_pages;
  108. }
  109. list_add(&area->list, &ptcal_list);
  110. return 0;
  111. out_free_pages:
  112. __free_pages(area->pages, area->order);
  113. out_free_area:
  114. kfree(area);
  115. out_err:
  116. return ret;
  117. }
  118. static int __init cbe_ptcal_enable(void)
  119. {
  120. const u32 *size;
  121. struct device_node *np;
  122. int order, found_mic = 0;
  123. np = of_find_node_by_path("/rtas");
  124. if (!np)
  125. return -ENODEV;
  126. size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
  127. if (!size)
  128. return -ENODEV;
  129. pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);
  130. order = get_order(*size);
  131. of_node_put(np);
  132. /* support for malta device trees, with be@/mic@ nodes */
  133. for_each_node_by_type(np, "mic-tm") {
  134. cbe_ptcal_enable_on_node(of_node_to_nid(np), order);
  135. found_mic = 1;
  136. }
  137. if (found_mic)
  138. return 0;
  139. /* support for older device tree - use cpu nodes */
  140. for_each_node_by_type(np, "cpu") {
  141. const u32 *nid = of_get_property(np, "node-id", NULL);
  142. if (!nid) {
  143. printk(KERN_ERR "%s: node %s is missing node-id?\n",
  144. __func__, np->full_name);
  145. continue;
  146. }
  147. cbe_ptcal_enable_on_node(*nid, order);
  148. found_mic = 1;
  149. }
  150. return found_mic ? 0 : -ENODEV;
  151. }
  152. static int cbe_ptcal_disable(void)
  153. {
  154. struct ptcal_area *area, *tmp;
  155. int ret = 0;
  156. pr_debug("%s: disabling PTCAL\n", __func__);
  157. list_for_each_entry_safe(area, tmp, &ptcal_list, list) {
  158. /* disable ptcal on this node */
  159. if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) {
  160. printk(KERN_ERR "%s: error disabling PTCAL "
  161. "on node %d!\n", __func__,
  162. area->nid);
  163. ret = -EIO;
  164. continue;
  165. }
  166. /* ensure we can access the PTCAL area */
  167. memset(page_address(area->pages), 0,
  168. 1 << (area->order + PAGE_SHIFT));
  169. /* clean up */
  170. list_del(&area->list);
  171. __free_pages(area->pages, area->order);
  172. kfree(area);
  173. }
  174. return ret;
  175. }
  176. static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
  177. unsigned long code, void *data)
  178. {
  179. return cbe_ptcal_disable();
  180. }
  181. static void cbe_ptcal_crash_shutdown(void)
  182. {
  183. cbe_ptcal_disable();
  184. }
  185. static struct notifier_block cbe_ptcal_reboot_notifier = {
  186. .notifier_call = cbe_ptcal_notify_reboot
  187. };
  188. #ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
  189. static int sysreset_hack;
  190. static int __init cbe_sysreset_init(void)
  191. {
  192. struct cbe_pmd_regs __iomem *regs;
  193. sysreset_hack = machine_is_compatible("IBM,CBPLUS-1.0");
  194. if (!sysreset_hack)
  195. return 0;
  196. regs = cbe_get_cpu_pmd_regs(0);
  197. if (!regs)
  198. return 0;
  199. /* Enable JTAG system-reset hack */
  200. out_be32(&regs->fir_mode_reg,
  201. in_be32(&regs->fir_mode_reg) |
  202. CBE_PMD_FIR_MODE_M8);
  203. return 0;
  204. }
  205. device_initcall(cbe_sysreset_init);
  206. int cbe_sysreset_hack(void)
  207. {
  208. struct cbe_pmd_regs __iomem *regs;
  209. /*
  210. * The BMC can inject user triggered system reset exceptions,
  211. * but cannot set the system reset reason in srr1,
  212. * so check an extra register here.
  213. */
  214. if (sysreset_hack && (smp_processor_id() == 0)) {
  215. regs = cbe_get_cpu_pmd_regs(0);
  216. if (!regs)
  217. return 0;
  218. if (in_be64(&regs->ras_esc_0) & 0x0000ffff) {
  219. out_be64(&regs->ras_esc_0, 0);
  220. return 0;
  221. }
  222. }
  223. return 1;
  224. }
  225. #endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
  226. int __init cbe_ptcal_init(void)
  227. {
  228. int ret;
  229. ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal");
  230. ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal");
  231. if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE
  232. || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)
  233. return -ENODEV;
  234. ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);
  235. if (ret)
  236. goto out1;
  237. ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown);
  238. if (ret)
  239. goto out2;
  240. return cbe_ptcal_enable();
  241. out2:
  242. unregister_reboot_notifier(&cbe_ptcal_reboot_notifier);
  243. out1:
  244. printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
  245. return ret;
  246. }
  247. arch_initcall(cbe_ptcal_init);
  248. void __init cbe_ras_init(void)
  249. {
  250. unsigned long hid0;
  251. /*
  252. * Enable System Error & thermal interrupts and wakeup conditions
  253. */
  254. hid0 = mfspr(SPRN_HID0);
  255. hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP |
  256. HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP;
  257. mtspr(SPRN_HID0, hid0);
  258. mb();
  259. /*
  260. * Install machine check handler. Leave setting of precise mode to
  261. * what the firmware did for now
  262. */
  263. ppc_md.machine_check_exception = cbe_machine_check_handler;
  264. mb();
  265. /*
  266. * For now, we assume that IOC_FIR is already set to forward some
  267. * error conditions to the System Error handler. If that is not true
  268. * then it will have to be fixed up here.
  269. */
  270. }