ras.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2006-2008, IBM Corporation.
  4. */
  5. #undef DEBUG
  6. #include <linux/types.h>
  7. #include <linux/kernel.h>
  8. #include <linux/slab.h>
  9. #include <linux/smp.h>
  10. #include <linux/reboot.h>
  11. #include <linux/kexec.h>
  12. #include <linux/crash_dump.h>
  13. #include <linux/of.h>
  14. #include <asm/kexec.h>
  15. #include <asm/reg.h>
  16. #include <asm/io.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%016llx\n",
  31. in_be64(&pregs->checkstop_fir));
  32. printk(KERN_ERR "Global Recoverable FIR : 0x%016llx\n",
  33. in_be64(&pregs->checkstop_fir));
  34. printk(KERN_ERR "Global MachineCheck FIR : 0x%016llx\n",
  35. in_be64(&pregs->spec_att_mchk_fir));
  36. if (iregs == NULL)
  37. return;
  38. printk(KERN_ERR "IOC FIR : 0x%016llx\n",
  39. in_be64(&iregs->ioc_fir));
  40. }
  41. DEFINE_INTERRUPT_HANDLER(cbe_system_error_exception)
  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. DEFINE_INTERRUPT_HANDLER(cbe_maintenance_exception)
  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. DEFINE_INTERRUPT_HANDLER(cbe_thermal_exception)
  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. if (is_kdump_kernel())
  88. rtas_call(ptcal_stop_tok, 1, 1, NULL, nid);
  89. area = kmalloc(sizeof(*area), GFP_KERNEL);
  90. if (!area)
  91. goto out_err;
  92. area->nid = nid;
  93. area->order = order;
  94. area->pages = __alloc_pages_node(area->nid,
  95. GFP_KERNEL|__GFP_THISNODE,
  96. area->order);
  97. if (!area->pages) {
  98. printk(KERN_WARNING "%s: no page on node %d\n",
  99. __func__, area->nid);
  100. goto out_free_area;
  101. }
  102. /*
  103. * We move the ptcal area to the middle of the allocated
  104. * page, in order to avoid prefetches in memcpy and similar
  105. * functions stepping on it.
  106. */
  107. addr = __pa(page_address(area->pages)) + (PAGE_SIZE >> 1);
  108. printk(KERN_DEBUG "%s: enabling PTCAL on node %d address=0x%016lx\n",
  109. __func__, area->nid, addr);
  110. ret = -EIO;
  111. if (rtas_call(ptcal_start_tok, 3, 1, NULL, area->nid,
  112. (unsigned int)(addr >> 32),
  113. (unsigned int)(addr & 0xffffffff))) {
  114. printk(KERN_ERR "%s: error enabling PTCAL on node %d!\n",
  115. __func__, nid);
  116. goto out_free_pages;
  117. }
  118. list_add(&area->list, &ptcal_list);
  119. return 0;
  120. out_free_pages:
  121. __free_pages(area->pages, area->order);
  122. out_free_area:
  123. kfree(area);
  124. out_err:
  125. return ret;
  126. }
  127. static int __init cbe_ptcal_enable(void)
  128. {
  129. const u32 *size;
  130. struct device_node *np;
  131. int order, found_mic = 0;
  132. np = of_find_node_by_path("/rtas");
  133. if (!np)
  134. return -ENODEV;
  135. size = of_get_property(np, "ibm,cbe-ptcal-size", NULL);
  136. if (!size) {
  137. of_node_put(np);
  138. return -ENODEV;
  139. }
  140. pr_debug("%s: enabling PTCAL, size = 0x%x\n", __func__, *size);
  141. order = get_order(*size);
  142. of_node_put(np);
  143. /* support for malta device trees, with be@/mic@ nodes */
  144. for_each_node_by_type(np, "mic-tm") {
  145. cbe_ptcal_enable_on_node(of_node_to_nid(np), order);
  146. found_mic = 1;
  147. }
  148. if (found_mic)
  149. return 0;
  150. /* support for older device tree - use cpu nodes */
  151. for_each_node_by_type(np, "cpu") {
  152. const u32 *nid = of_get_property(np, "node-id", NULL);
  153. if (!nid) {
  154. printk(KERN_ERR "%s: node %pOF is missing node-id?\n",
  155. __func__, np);
  156. continue;
  157. }
  158. cbe_ptcal_enable_on_node(*nid, order);
  159. found_mic = 1;
  160. }
  161. return found_mic ? 0 : -ENODEV;
  162. }
  163. static int cbe_ptcal_disable(void)
  164. {
  165. struct ptcal_area *area, *tmp;
  166. int ret = 0;
  167. pr_debug("%s: disabling PTCAL\n", __func__);
  168. list_for_each_entry_safe(area, tmp, &ptcal_list, list) {
  169. /* disable ptcal on this node */
  170. if (rtas_call(ptcal_stop_tok, 1, 1, NULL, area->nid)) {
  171. printk(KERN_ERR "%s: error disabling PTCAL "
  172. "on node %d!\n", __func__,
  173. area->nid);
  174. ret = -EIO;
  175. continue;
  176. }
  177. /* ensure we can access the PTCAL area */
  178. memset(page_address(area->pages), 0,
  179. 1 << (area->order + PAGE_SHIFT));
  180. /* clean up */
  181. list_del(&area->list);
  182. __free_pages(area->pages, area->order);
  183. kfree(area);
  184. }
  185. return ret;
  186. }
  187. static int cbe_ptcal_notify_reboot(struct notifier_block *nb,
  188. unsigned long code, void *data)
  189. {
  190. return cbe_ptcal_disable();
  191. }
  192. static void cbe_ptcal_crash_shutdown(void)
  193. {
  194. cbe_ptcal_disable();
  195. }
  196. static struct notifier_block cbe_ptcal_reboot_notifier = {
  197. .notifier_call = cbe_ptcal_notify_reboot
  198. };
  199. #ifdef CONFIG_PPC_IBM_CELL_RESETBUTTON
  200. static int sysreset_hack;
  201. static int __init cbe_sysreset_init(void)
  202. {
  203. struct cbe_pmd_regs __iomem *regs;
  204. sysreset_hack = of_machine_is_compatible("IBM,CBPLUS-1.0");
  205. if (!sysreset_hack)
  206. return 0;
  207. regs = cbe_get_cpu_pmd_regs(0);
  208. if (!regs)
  209. return 0;
  210. /* Enable JTAG system-reset hack */
  211. out_be32(&regs->fir_mode_reg,
  212. in_be32(&regs->fir_mode_reg) |
  213. CBE_PMD_FIR_MODE_M8);
  214. return 0;
  215. }
  216. device_initcall(cbe_sysreset_init);
  217. int cbe_sysreset_hack(void)
  218. {
  219. struct cbe_pmd_regs __iomem *regs;
  220. /*
  221. * The BMC can inject user triggered system reset exceptions,
  222. * but cannot set the system reset reason in srr1,
  223. * so check an extra register here.
  224. */
  225. if (sysreset_hack && (smp_processor_id() == 0)) {
  226. regs = cbe_get_cpu_pmd_regs(0);
  227. if (!regs)
  228. return 0;
  229. if (in_be64(&regs->ras_esc_0) & 0x0000ffff) {
  230. out_be64(&regs->ras_esc_0, 0);
  231. return 0;
  232. }
  233. }
  234. return 1;
  235. }
  236. #endif /* CONFIG_PPC_IBM_CELL_RESETBUTTON */
  237. static int __init cbe_ptcal_init(void)
  238. {
  239. int ret;
  240. ptcal_start_tok = rtas_token("ibm,cbe-start-ptcal");
  241. ptcal_stop_tok = rtas_token("ibm,cbe-stop-ptcal");
  242. if (ptcal_start_tok == RTAS_UNKNOWN_SERVICE
  243. || ptcal_stop_tok == RTAS_UNKNOWN_SERVICE)
  244. return -ENODEV;
  245. ret = register_reboot_notifier(&cbe_ptcal_reboot_notifier);
  246. if (ret)
  247. goto out1;
  248. ret = crash_shutdown_register(&cbe_ptcal_crash_shutdown);
  249. if (ret)
  250. goto out2;
  251. return cbe_ptcal_enable();
  252. out2:
  253. unregister_reboot_notifier(&cbe_ptcal_reboot_notifier);
  254. out1:
  255. printk(KERN_ERR "Can't disable PTCAL, so not enabling\n");
  256. return ret;
  257. }
  258. arch_initcall(cbe_ptcal_init);
  259. void __init cbe_ras_init(void)
  260. {
  261. unsigned long hid0;
  262. /*
  263. * Enable System Error & thermal interrupts and wakeup conditions
  264. */
  265. hid0 = mfspr(SPRN_HID0);
  266. hid0 |= HID0_CBE_THERM_INT_EN | HID0_CBE_THERM_WAKEUP |
  267. HID0_CBE_SYSERR_INT_EN | HID0_CBE_SYSERR_WAKEUP;
  268. mtspr(SPRN_HID0, hid0);
  269. mb();
  270. /*
  271. * Install machine check handler. Leave setting of precise mode to
  272. * what the firmware did for now
  273. */
  274. ppc_md.machine_check_exception = cbe_machine_check_handler;
  275. mb();
  276. /*
  277. * For now, we assume that IOC_FIR is already set to forward some
  278. * error conditions to the System Error handler. If that is not true
  279. * then it will have to be fixed up here.
  280. */
  281. }