fsp2.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * FSP-2 board specific routines
  4. *
  5. * Based on earlier code:
  6. * Matt Porter <[email protected]>
  7. * Copyright 2002-2005 MontaVista Software Inc.
  8. *
  9. * Eugene Surovegin <[email protected]> or <[email protected]>
  10. * Copyright (c) 2003-2005 Zultys Technologies
  11. *
  12. * Rewritten and ported to the merged powerpc tree:
  13. * Copyright 2007 David Gibson <[email protected]>, IBM Corporation.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/of_fdt.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/rtc.h>
  19. #include <asm/machdep.h>
  20. #include <asm/udbg.h>
  21. #include <asm/time.h>
  22. #include <asm/uic.h>
  23. #include <asm/ppc4xx.h>
  24. #include <asm/dcr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/of_irq.h>
  27. #include "fsp2.h"
  28. #define FSP2_BUS_ERR "ibm,bus-error-irq"
  29. #define FSP2_CMU_ERR "ibm,cmu-error-irq"
  30. #define FSP2_CONF_ERR "ibm,conf-error-irq"
  31. #define FSP2_OPBD_ERR "ibm,opbd-error-irq"
  32. #define FSP2_MCUE "ibm,mc-ue-irq"
  33. #define FSP2_RST_WRN "ibm,reset-warning-irq"
  34. static __initdata struct of_device_id fsp2_of_bus[] = {
  35. { .compatible = "ibm,plb4", },
  36. { .compatible = "ibm,plb6", },
  37. { .compatible = "ibm,opb", },
  38. {},
  39. };
  40. static void l2regs(void)
  41. {
  42. pr_err("L2 Controller:\n");
  43. pr_err("MCK: 0x%08x\n", mfl2(L2MCK));
  44. pr_err("INT: 0x%08x\n", mfl2(L2INT));
  45. pr_err("PLBSTAT0: 0x%08x\n", mfl2(L2PLBSTAT0));
  46. pr_err("PLBSTAT1: 0x%08x\n", mfl2(L2PLBSTAT1));
  47. pr_err("ARRSTAT0: 0x%08x\n", mfl2(L2ARRSTAT0));
  48. pr_err("ARRSTAT1: 0x%08x\n", mfl2(L2ARRSTAT1));
  49. pr_err("ARRSTAT2: 0x%08x\n", mfl2(L2ARRSTAT2));
  50. pr_err("CPUSTAT: 0x%08x\n", mfl2(L2CPUSTAT));
  51. pr_err("RACSTAT0: 0x%08x\n", mfl2(L2RACSTAT0));
  52. pr_err("WACSTAT0: 0x%08x\n", mfl2(L2WACSTAT0));
  53. pr_err("WACSTAT1: 0x%08x\n", mfl2(L2WACSTAT1));
  54. pr_err("WACSTAT2: 0x%08x\n", mfl2(L2WACSTAT2));
  55. pr_err("WDFSTAT: 0x%08x\n", mfl2(L2WDFSTAT));
  56. pr_err("LOG0: 0x%08x\n", mfl2(L2LOG0));
  57. pr_err("LOG1: 0x%08x\n", mfl2(L2LOG1));
  58. pr_err("LOG2: 0x%08x\n", mfl2(L2LOG2));
  59. pr_err("LOG3: 0x%08x\n", mfl2(L2LOG3));
  60. pr_err("LOG4: 0x%08x\n", mfl2(L2LOG4));
  61. pr_err("LOG5: 0x%08x\n", mfl2(L2LOG5));
  62. }
  63. static void show_plbopb_regs(u32 base, int num)
  64. {
  65. pr_err("\nPLBOPB Bridge %d:\n", num);
  66. pr_err("GESR0: 0x%08x\n", mfdcr(base + PLB4OPB_GESR0));
  67. pr_err("GESR1: 0x%08x\n", mfdcr(base + PLB4OPB_GESR1));
  68. pr_err("GESR2: 0x%08x\n", mfdcr(base + PLB4OPB_GESR2));
  69. pr_err("GEARU: 0x%08x\n", mfdcr(base + PLB4OPB_GEARU));
  70. pr_err("GEAR: 0x%08x\n", mfdcr(base + PLB4OPB_GEAR));
  71. }
  72. static irqreturn_t bus_err_handler(int irq, void *data)
  73. {
  74. pr_err("Bus Error\n");
  75. l2regs();
  76. pr_err("\nPLB6 Controller:\n");
  77. pr_err("BC_SHD: 0x%08x\n", mfdcr(DCRN_PLB6_SHD));
  78. pr_err("BC_ERR: 0x%08x\n", mfdcr(DCRN_PLB6_ERR));
  79. pr_err("\nPLB6-to-PLB4 Bridge:\n");
  80. pr_err("ESR: 0x%08x\n", mfdcr(DCRN_PLB6PLB4_ESR));
  81. pr_err("EARH: 0x%08x\n", mfdcr(DCRN_PLB6PLB4_EARH));
  82. pr_err("EARL: 0x%08x\n", mfdcr(DCRN_PLB6PLB4_EARL));
  83. pr_err("\nPLB4-to-PLB6 Bridge:\n");
  84. pr_err("ESR: 0x%08x\n", mfdcr(DCRN_PLB4PLB6_ESR));
  85. pr_err("EARH: 0x%08x\n", mfdcr(DCRN_PLB4PLB6_EARH));
  86. pr_err("EARL: 0x%08x\n", mfdcr(DCRN_PLB4PLB6_EARL));
  87. pr_err("\nPLB6-to-MCIF Bridge:\n");
  88. pr_err("BESR0: 0x%08x\n", mfdcr(DCRN_PLB6MCIF_BESR0));
  89. pr_err("BESR1: 0x%08x\n", mfdcr(DCRN_PLB6MCIF_BESR1));
  90. pr_err("BEARH: 0x%08x\n", mfdcr(DCRN_PLB6MCIF_BEARH));
  91. pr_err("BEARL: 0x%08x\n", mfdcr(DCRN_PLB6MCIF_BEARL));
  92. pr_err("\nPLB4 Arbiter:\n");
  93. pr_err("P0ESRH 0x%08x\n", mfdcr(DCRN_PLB4_P0ESRH));
  94. pr_err("P0ESRL 0x%08x\n", mfdcr(DCRN_PLB4_P0ESRL));
  95. pr_err("P0EARH 0x%08x\n", mfdcr(DCRN_PLB4_P0EARH));
  96. pr_err("P0EARH 0x%08x\n", mfdcr(DCRN_PLB4_P0EARH));
  97. pr_err("P1ESRH 0x%08x\n", mfdcr(DCRN_PLB4_P1ESRH));
  98. pr_err("P1ESRL 0x%08x\n", mfdcr(DCRN_PLB4_P1ESRL));
  99. pr_err("P1EARH 0x%08x\n", mfdcr(DCRN_PLB4_P1EARH));
  100. pr_err("P1EARH 0x%08x\n", mfdcr(DCRN_PLB4_P1EARH));
  101. show_plbopb_regs(DCRN_PLB4OPB0_BASE, 0);
  102. show_plbopb_regs(DCRN_PLB4OPB1_BASE, 1);
  103. show_plbopb_regs(DCRN_PLB4OPB2_BASE, 2);
  104. show_plbopb_regs(DCRN_PLB4OPB3_BASE, 3);
  105. pr_err("\nPLB4-to-AHB Bridge:\n");
  106. pr_err("ESR: 0x%08x\n", mfdcr(DCRN_PLB4AHB_ESR));
  107. pr_err("SEUAR: 0x%08x\n", mfdcr(DCRN_PLB4AHB_SEUAR));
  108. pr_err("SELAR: 0x%08x\n", mfdcr(DCRN_PLB4AHB_SELAR));
  109. pr_err("\nAHB-to-PLB4 Bridge:\n");
  110. pr_err("\nESR: 0x%08x\n", mfdcr(DCRN_AHBPLB4_ESR));
  111. pr_err("\nEAR: 0x%08x\n", mfdcr(DCRN_AHBPLB4_EAR));
  112. panic("Bus Error\n");
  113. }
  114. static irqreturn_t cmu_err_handler(int irq, void *data) {
  115. pr_err("CMU Error\n");
  116. pr_err("FIR0: 0x%08x\n", mfcmu(CMUN_FIR0));
  117. panic("CMU Error\n");
  118. }
  119. static irqreturn_t conf_err_handler(int irq, void *data) {
  120. pr_err("Configuration Logic Error\n");
  121. pr_err("CONF_FIR: 0x%08x\n", mfdcr(DCRN_CONF_FIR_RWC));
  122. pr_err("RPERR0: 0x%08x\n", mfdcr(DCRN_CONF_RPERR0));
  123. pr_err("RPERR1: 0x%08x\n", mfdcr(DCRN_CONF_RPERR1));
  124. panic("Configuration Logic Error\n");
  125. }
  126. static irqreturn_t opbd_err_handler(int irq, void *data) {
  127. panic("OPBD Error\n");
  128. }
  129. static irqreturn_t mcue_handler(int irq, void *data) {
  130. pr_err("DDR: Uncorrectable Error\n");
  131. pr_err("MCSTAT: 0x%08x\n",
  132. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_MCSTAT));
  133. pr_err("MCOPT1: 0x%08x\n",
  134. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_MCOPT1));
  135. pr_err("MCOPT2: 0x%08x\n",
  136. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_MCOPT2));
  137. pr_err("PHYSTAT: 0x%08x\n",
  138. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_PHYSTAT));
  139. pr_err("CFGR0: 0x%08x\n",
  140. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_CFGR0));
  141. pr_err("CFGR1: 0x%08x\n",
  142. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_CFGR1));
  143. pr_err("CFGR2: 0x%08x\n",
  144. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_CFGR2));
  145. pr_err("CFGR3: 0x%08x\n",
  146. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_CFGR3));
  147. pr_err("SCRUB_CNTL: 0x%08x\n",
  148. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_SCRUB_CNTL));
  149. pr_err("ECCERR_PORT0: 0x%08x\n",
  150. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_ECCERR_PORT0));
  151. pr_err("ECCERR_ADDR_PORT0: 0x%08x\n",
  152. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_ECCERR_ADDR_PORT0));
  153. pr_err("ECCERR_CNT_PORT0: 0x%08x\n",
  154. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_ECCERR_COUNT_PORT0));
  155. pr_err("ECC_CHECK_PORT0: 0x%08x\n",
  156. mfdcr(DCRN_DDR34_BASE + DCRN_DDR34_ECC_CHECK_PORT0));
  157. pr_err("MCER0: 0x%08x\n",
  158. mfdcr(DCRN_CW_BASE + DCRN_CW_MCER0));
  159. pr_err("MCER1: 0x%08x\n",
  160. mfdcr(DCRN_CW_BASE + DCRN_CW_MCER1));
  161. pr_err("BESR: 0x%08x\n",
  162. mfdcr(DCRN_PLB6MCIF_BESR0));
  163. pr_err("BEARL: 0x%08x\n",
  164. mfdcr(DCRN_PLB6MCIF_BEARL));
  165. pr_err("BEARH: 0x%08x\n",
  166. mfdcr(DCRN_PLB6MCIF_BEARH));
  167. panic("DDR: Uncorrectable Error\n");
  168. }
  169. static irqreturn_t rst_wrn_handler(int irq, void *data) {
  170. u32 crcs = mfcmu(CMUN_CRCS);
  171. switch (crcs & CRCS_STAT_MASK) {
  172. case CRCS_STAT_CHIP_RST_B:
  173. panic("Received chassis-initiated reset request");
  174. default:
  175. panic("Unknown external reset: CRCS=0x%x", crcs);
  176. }
  177. }
  178. static void __init node_irq_request(const char *compat, irq_handler_t errirq_handler)
  179. {
  180. struct device_node *np;
  181. unsigned int irq;
  182. int32_t rc;
  183. for_each_compatible_node(np, NULL, compat) {
  184. irq = irq_of_parse_and_map(np, 0);
  185. if (irq == NO_IRQ) {
  186. pr_err("device tree node %pOFn is missing a interrupt",
  187. np);
  188. of_node_put(np);
  189. return;
  190. }
  191. rc = request_irq(irq, errirq_handler, 0, np->name, np);
  192. if (rc) {
  193. pr_err("fsp_of_probe: request_irq failed: np=%pOF rc=%d",
  194. np, rc);
  195. of_node_put(np);
  196. return;
  197. }
  198. }
  199. }
  200. static void __init critical_irq_setup(void)
  201. {
  202. node_irq_request(FSP2_CMU_ERR, cmu_err_handler);
  203. node_irq_request(FSP2_BUS_ERR, bus_err_handler);
  204. node_irq_request(FSP2_CONF_ERR, conf_err_handler);
  205. node_irq_request(FSP2_OPBD_ERR, opbd_err_handler);
  206. node_irq_request(FSP2_MCUE, mcue_handler);
  207. node_irq_request(FSP2_RST_WRN, rst_wrn_handler);
  208. }
  209. static int __init fsp2_device_probe(void)
  210. {
  211. of_platform_bus_probe(NULL, fsp2_of_bus, NULL);
  212. return 0;
  213. }
  214. machine_device_initcall(fsp2, fsp2_device_probe);
  215. static int __init fsp2_probe(void)
  216. {
  217. u32 val;
  218. unsigned long root = of_get_flat_dt_root();
  219. if (!of_flat_dt_is_compatible(root, "ibm,fsp2"))
  220. return 0;
  221. /* Clear BC_ERR and mask snoopable request plb errors. */
  222. val = mfdcr(DCRN_PLB6_CR0);
  223. val |= 0x20000000;
  224. mtdcr(DCRN_PLB6_BASE, val);
  225. mtdcr(DCRN_PLB6_HD, 0xffff0000);
  226. mtdcr(DCRN_PLB6_SHD, 0xffff0000);
  227. /* TVSENSE reset is blocked (clock gated) by the POR default of the TVS
  228. * sleep config bit. As a consequence, TVSENSE will provide erratic
  229. * sensor values, which may result in spurious (parity) errors
  230. * recorded in the CMU FIR and leading to erroneous interrupt requests
  231. * once the CMU interrupt is unmasked.
  232. */
  233. /* 1. set TVS1[UNDOZE] */
  234. val = mfcmu(CMUN_TVS1);
  235. val |= 0x4;
  236. mtcmu(CMUN_TVS1, val);
  237. /* 2. clear FIR[TVS] and FIR[TVSPAR] */
  238. val = mfcmu(CMUN_FIR0);
  239. val |= 0x30000000;
  240. mtcmu(CMUN_FIR0, val);
  241. /* L2 machine checks */
  242. mtl2(L2PLBMCKEN0, 0xffffffff);
  243. mtl2(L2PLBMCKEN1, 0x0000ffff);
  244. mtl2(L2ARRMCKEN0, 0xffffffff);
  245. mtl2(L2ARRMCKEN1, 0xffffffff);
  246. mtl2(L2ARRMCKEN2, 0xfffff000);
  247. mtl2(L2CPUMCKEN, 0xffffffff);
  248. mtl2(L2RACMCKEN0, 0xffffffff);
  249. mtl2(L2WACMCKEN0, 0xffffffff);
  250. mtl2(L2WACMCKEN1, 0xffffffff);
  251. mtl2(L2WACMCKEN2, 0xffffffff);
  252. mtl2(L2WDFMCKEN, 0xffffffff);
  253. /* L2 interrupts */
  254. mtl2(L2PLBINTEN1, 0xffff0000);
  255. /*
  256. * At a global level, enable all L2 machine checks and interrupts
  257. * reported by the L2 subsystems, except for the external machine check
  258. * input (UIC0.1).
  259. */
  260. mtl2(L2MCKEN, 0x000007ff);
  261. mtl2(L2INTEN, 0x000004ff);
  262. /* Enable FSP-2 configuration logic parity errors */
  263. mtdcr(DCRN_CONF_EIR_RS, 0x80000000);
  264. return 1;
  265. }
  266. static void __init fsp2_irq_init(void)
  267. {
  268. uic_init_tree();
  269. critical_irq_setup();
  270. }
  271. define_machine(fsp2) {
  272. .name = "FSP-2",
  273. .probe = fsp2_probe,
  274. .progress = udbg_progress,
  275. .init_IRQ = fsp2_irq_init,
  276. .get_irq = uic_get_irq,
  277. .restart = ppc4xx_reset_system,
  278. .calibrate_decr = generic_calibrate_decr,
  279. };