ras.c 7.8 KB

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