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