ras.c 7.3 KB

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