mips-cm.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/errno.h>
  11. #include <asm/mips-cm.h>
  12. #include <asm/mipsregs.h>
  13. void __iomem *mips_cm_base;
  14. void __iomem *mips_cm_l2sync_base;
  15. int mips_cm_is64;
  16. static char *cm2_tr[8] = {
  17. "mem", "gcr", "gic", "mmio",
  18. "0x04", "cpc", "0x06", "0x07"
  19. };
  20. /* CM3 Tag ECC transation type */
  21. static char *cm3_tr[16] = {
  22. [0x0] = "ReqNoData",
  23. [0x1] = "0x1",
  24. [0x2] = "ReqWData",
  25. [0x3] = "0x3",
  26. [0x4] = "IReqNoResp",
  27. [0x5] = "IReqWResp",
  28. [0x6] = "IReqNoRespDat",
  29. [0x7] = "IReqWRespDat",
  30. [0x8] = "RespNoData",
  31. [0x9] = "RespDataFol",
  32. [0xa] = "RespWData",
  33. [0xb] = "RespDataOnly",
  34. [0xc] = "IRespNoData",
  35. [0xd] = "IRespDataFol",
  36. [0xe] = "IRespWData",
  37. [0xf] = "IRespDataOnly"
  38. };
  39. static char *cm2_cmd[32] = {
  40. [0x00] = "0x00",
  41. [0x01] = "Legacy Write",
  42. [0x02] = "Legacy Read",
  43. [0x03] = "0x03",
  44. [0x04] = "0x04",
  45. [0x05] = "0x05",
  46. [0x06] = "0x06",
  47. [0x07] = "0x07",
  48. [0x08] = "Coherent Read Own",
  49. [0x09] = "Coherent Read Share",
  50. [0x0a] = "Coherent Read Discard",
  51. [0x0b] = "Coherent Ready Share Always",
  52. [0x0c] = "Coherent Upgrade",
  53. [0x0d] = "Coherent Writeback",
  54. [0x0e] = "0x0e",
  55. [0x0f] = "0x0f",
  56. [0x10] = "Coherent Copyback",
  57. [0x11] = "Coherent Copyback Invalidate",
  58. [0x12] = "Coherent Invalidate",
  59. [0x13] = "Coherent Write Invalidate",
  60. [0x14] = "Coherent Completion Sync",
  61. [0x15] = "0x15",
  62. [0x16] = "0x16",
  63. [0x17] = "0x17",
  64. [0x18] = "0x18",
  65. [0x19] = "0x19",
  66. [0x1a] = "0x1a",
  67. [0x1b] = "0x1b",
  68. [0x1c] = "0x1c",
  69. [0x1d] = "0x1d",
  70. [0x1e] = "0x1e",
  71. [0x1f] = "0x1f"
  72. };
  73. /* CM3 Tag ECC command type */
  74. static char *cm3_cmd[16] = {
  75. [0x0] = "Legacy Read",
  76. [0x1] = "Legacy Write",
  77. [0x2] = "Coherent Read Own",
  78. [0x3] = "Coherent Read Share",
  79. [0x4] = "Coherent Read Discard",
  80. [0x5] = "Coherent Evicted",
  81. [0x6] = "Coherent Upgrade",
  82. [0x7] = "Coherent Upgrade for Store Conditional",
  83. [0x8] = "Coherent Writeback",
  84. [0x9] = "Coherent Write Invalidate",
  85. [0xa] = "0xa",
  86. [0xb] = "0xb",
  87. [0xc] = "0xc",
  88. [0xd] = "0xd",
  89. [0xe] = "0xe",
  90. [0xf] = "0xf"
  91. };
  92. /* CM3 Tag ECC command group */
  93. static char *cm3_cmd_group[8] = {
  94. [0x0] = "Normal",
  95. [0x1] = "Registers",
  96. [0x2] = "TLB",
  97. [0x3] = "0x3",
  98. [0x4] = "L1I",
  99. [0x5] = "L1D",
  100. [0x6] = "L3",
  101. [0x7] = "L2"
  102. };
  103. static char *cm2_core[8] = {
  104. "Invalid/OK", "Invalid/Data",
  105. "Shared/OK", "Shared/Data",
  106. "Modified/OK", "Modified/Data",
  107. "Exclusive/OK", "Exclusive/Data"
  108. };
  109. static char *cm2_causes[32] = {
  110. "None", "GC_WR_ERR", "GC_RD_ERR", "COH_WR_ERR",
  111. "COH_RD_ERR", "MMIO_WR_ERR", "MMIO_RD_ERR", "0x07",
  112. "0x08", "0x09", "0x0a", "0x0b",
  113. "0x0c", "0x0d", "0x0e", "0x0f",
  114. "0x10", "0x11", "0x12", "0x13",
  115. "0x14", "0x15", "0x16", "INTVN_WR_ERR",
  116. "INTVN_RD_ERR", "0x19", "0x1a", "0x1b",
  117. "0x1c", "0x1d", "0x1e", "0x1f"
  118. };
  119. static char *cm3_causes[32] = {
  120. "0x0", "MP_CORRECTABLE_ECC_ERR", "MP_REQUEST_DECODE_ERR",
  121. "MP_UNCORRECTABLE_ECC_ERR", "MP_PARITY_ERR", "MP_COHERENCE_ERR",
  122. "CMBIU_REQUEST_DECODE_ERR", "CMBIU_PARITY_ERR", "CMBIU_AXI_RESP_ERR",
  123. "0x9", "RBI_BUS_ERR", "0xb", "0xc", "0xd", "0xe", "0xf", "0x10",
  124. "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18",
  125. "0x19", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f"
  126. };
  127. phys_addr_t __mips_cm_phys_base(void)
  128. {
  129. u32 config3 = read_c0_config3();
  130. unsigned long cmgcr;
  131. /* Check the CMGCRBase register is implemented */
  132. if (!(config3 & MIPS_CONF3_CMGCR))
  133. return 0;
  134. /* Read the address from CMGCRBase */
  135. cmgcr = read_c0_cmgcrbase();
  136. return (cmgcr & MIPS_CMGCRF_BASE) << (36 - 32);
  137. }
  138. phys_addr_t mips_cm_phys_base(void)
  139. __attribute__((weak, alias("__mips_cm_phys_base")));
  140. phys_addr_t __mips_cm_l2sync_phys_base(void)
  141. {
  142. u32 base_reg;
  143. /*
  144. * If the L2-only sync region is already enabled then leave it at it's
  145. * current location.
  146. */
  147. base_reg = read_gcr_l2_only_sync_base();
  148. if (base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN_MSK)
  149. return base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE_MSK;
  150. /* Default to following the CM */
  151. return mips_cm_phys_base() + MIPS_CM_GCR_SIZE;
  152. }
  153. phys_addr_t mips_cm_l2sync_phys_base(void)
  154. __attribute__((weak, alias("__mips_cm_l2sync_phys_base")));
  155. static void mips_cm_probe_l2sync(void)
  156. {
  157. unsigned major_rev;
  158. phys_addr_t addr;
  159. /* L2-only sync was introduced with CM major revision 6 */
  160. major_rev = (read_gcr_rev() & CM_GCR_REV_MAJOR_MSK) >>
  161. CM_GCR_REV_MAJOR_SHF;
  162. if (major_rev < 6)
  163. return;
  164. /* Find a location for the L2 sync region */
  165. addr = mips_cm_l2sync_phys_base();
  166. BUG_ON((addr & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE_MSK) != addr);
  167. if (!addr)
  168. return;
  169. /* Set the region base address & enable it */
  170. write_gcr_l2_only_sync_base(addr | CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN_MSK);
  171. /* Map the region */
  172. mips_cm_l2sync_base = ioremap_nocache(addr, MIPS_CM_L2SYNC_SIZE);
  173. }
  174. int mips_cm_probe(void)
  175. {
  176. phys_addr_t addr;
  177. u32 base_reg;
  178. /*
  179. * No need to probe again if we have already been
  180. * here before.
  181. */
  182. if (mips_cm_base)
  183. return 0;
  184. addr = mips_cm_phys_base();
  185. BUG_ON((addr & CM_GCR_BASE_GCRBASE_MSK) != addr);
  186. if (!addr)
  187. return -ENODEV;
  188. mips_cm_base = ioremap_nocache(addr, MIPS_CM_GCR_SIZE);
  189. if (!mips_cm_base)
  190. return -ENXIO;
  191. /* sanity check that we're looking at a CM */
  192. base_reg = read_gcr_base();
  193. if ((base_reg & CM_GCR_BASE_GCRBASE_MSK) != addr) {
  194. pr_err("GCRs appear to have been moved (expected them at 0x%08lx)!\n",
  195. (unsigned long)addr);
  196. mips_cm_base = NULL;
  197. return -ENODEV;
  198. }
  199. /* set default target to memory */
  200. base_reg &= ~CM_GCR_BASE_CMDEFTGT_MSK;
  201. base_reg |= CM_GCR_BASE_CMDEFTGT_MEM;
  202. write_gcr_base(base_reg);
  203. /* disable CM regions */
  204. write_gcr_reg0_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  205. write_gcr_reg0_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  206. write_gcr_reg1_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  207. write_gcr_reg1_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  208. write_gcr_reg2_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  209. write_gcr_reg2_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  210. write_gcr_reg3_base(CM_GCR_REGn_BASE_BASEADDR_MSK);
  211. write_gcr_reg3_mask(CM_GCR_REGn_MASK_ADDRMASK_MSK);
  212. /* probe for an L2-only sync region */
  213. mips_cm_probe_l2sync();
  214. /* determine register width for this CM */
  215. mips_cm_is64 = config_enabled(CONFIG_64BIT) && (mips_cm_revision() >= CM_REV_CM3);
  216. return 0;
  217. }
  218. void mips_cm_error_report(void)
  219. {
  220. unsigned long revision = mips_cm_revision();
  221. /*
  222. * CM3 has a 64-bit Error cause register with 0:57 containing the error
  223. * info and 63:58 the error type. For old CMs, everything is contained
  224. * in a single 32-bit register (0:26 and 31:27 respectively). Even
  225. * though the cm_error is u64, we will simply ignore the upper word
  226. * for CM2.
  227. */
  228. u64 cm_error = read_gcr_error_cause();
  229. int cm_error_cause_sft = CM_GCR_ERROR_CAUSE_ERRTYPE_SHF +
  230. ((revision >= CM_REV_CM3) ? 31 : 0);
  231. unsigned long cm_addr = read_gcr_error_addr();
  232. unsigned long cm_other = read_gcr_error_mult();
  233. int ocause, cause;
  234. char buf[256];
  235. if (!mips_cm_present())
  236. return;
  237. cause = cm_error >> cm_error_cause_sft;
  238. if (!cause)
  239. /* All good */
  240. return;
  241. ocause = cm_other >> CM_GCR_ERROR_MULT_ERR2ND_SHF;
  242. if (revision < CM_REV_CM3) { /* CM2 */
  243. if (cause < 16) {
  244. unsigned long cca_bits = (cm_error >> 15) & 7;
  245. unsigned long tr_bits = (cm_error >> 12) & 7;
  246. unsigned long cmd_bits = (cm_error >> 7) & 0x1f;
  247. unsigned long stag_bits = (cm_error >> 3) & 15;
  248. unsigned long sport_bits = (cm_error >> 0) & 7;
  249. snprintf(buf, sizeof(buf),
  250. "CCA=%lu TR=%s MCmd=%s STag=%lu "
  251. "SPort=%lu\n", cca_bits, cm2_tr[tr_bits],
  252. cm2_cmd[cmd_bits], stag_bits, sport_bits);
  253. } else {
  254. /* glob state & sresp together */
  255. unsigned long c3_bits = (cm_error >> 18) & 7;
  256. unsigned long c2_bits = (cm_error >> 15) & 7;
  257. unsigned long c1_bits = (cm_error >> 12) & 7;
  258. unsigned long c0_bits = (cm_error >> 9) & 7;
  259. unsigned long sc_bit = (cm_error >> 8) & 1;
  260. unsigned long cmd_bits = (cm_error >> 3) & 0x1f;
  261. unsigned long sport_bits = (cm_error >> 0) & 7;
  262. snprintf(buf, sizeof(buf),
  263. "C3=%s C2=%s C1=%s C0=%s SC=%s "
  264. "MCmd=%s SPort=%lu\n",
  265. cm2_core[c3_bits], cm2_core[c2_bits],
  266. cm2_core[c1_bits], cm2_core[c0_bits],
  267. sc_bit ? "True" : "False",
  268. cm2_cmd[cmd_bits], sport_bits);
  269. }
  270. pr_err("CM_ERROR=%08llx %s <%s>\n", cm_error,
  271. cm2_causes[cause], buf);
  272. pr_err("CM_ADDR =%08lx\n", cm_addr);
  273. pr_err("CM_OTHER=%08lx %s\n", cm_other, cm2_causes[ocause]);
  274. } else { /* CM3 */
  275. /* Used by cause == {1,2,3} */
  276. unsigned long core_id_bits = (cm_error >> 22) & 0xf;
  277. unsigned long vp_id_bits = (cm_error >> 18) & 0xf;
  278. unsigned long cmd_bits = (cm_error >> 14) & 0xf;
  279. unsigned long cmd_group_bits = (cm_error >> 11) & 0xf;
  280. unsigned long cm3_cca_bits = (cm_error >> 8) & 7;
  281. unsigned long mcp_bits = (cm_error >> 5) & 0xf;
  282. unsigned long cm3_tr_bits = (cm_error >> 1) & 0xf;
  283. unsigned long sched_bit = cm_error & 0x1;
  284. if (cause == 1 || cause == 3) { /* Tag ECC */
  285. unsigned long tag_ecc = (cm_error >> 57) & 0x1;
  286. unsigned long tag_way_bits = (cm_error >> 29) & 0xffff;
  287. unsigned long dword_bits = (cm_error >> 49) & 0xff;
  288. unsigned long data_way_bits = (cm_error >> 45) & 0xf;
  289. unsigned long data_sets_bits = (cm_error >> 29) & 0xfff;
  290. unsigned long bank_bit = (cm_error >> 28) & 0x1;
  291. snprintf(buf, sizeof(buf),
  292. "%s ECC Error: Way=%lu (DWORD=%lu, Sets=%lu)"
  293. "Bank=%lu CoreID=%lu VPID=%lu Command=%s"
  294. "Command Group=%s CCA=%lu MCP=%d"
  295. "Transaction type=%s Scheduler=%lu\n",
  296. tag_ecc ? "TAG" : "DATA",
  297. tag_ecc ? (unsigned long)ffs(tag_way_bits) - 1 :
  298. data_way_bits, bank_bit, dword_bits,
  299. data_sets_bits,
  300. core_id_bits, vp_id_bits,
  301. cm3_cmd[cmd_bits],
  302. cm3_cmd_group[cmd_group_bits],
  303. cm3_cca_bits, 1 << mcp_bits,
  304. cm3_tr[cm3_tr_bits], sched_bit);
  305. } else if (cause == 2) {
  306. unsigned long data_error_type = (cm_error >> 41) & 0xfff;
  307. unsigned long data_decode_cmd = (cm_error >> 37) & 0xf;
  308. unsigned long data_decode_group = (cm_error >> 34) & 0x7;
  309. unsigned long data_decode_destination_id = (cm_error >> 28) & 0x3f;
  310. snprintf(buf, sizeof(buf),
  311. "Decode Request Error: Type=%lu, Command=%lu"
  312. "Command Group=%lu Destination ID=%lu"
  313. "CoreID=%lu VPID=%lu Command=%s"
  314. "Command Group=%s CCA=%lu MCP=%d"
  315. "Transaction type=%s Scheduler=%lu\n",
  316. data_error_type, data_decode_cmd,
  317. data_decode_group, data_decode_destination_id,
  318. core_id_bits, vp_id_bits,
  319. cm3_cmd[cmd_bits],
  320. cm3_cmd_group[cmd_group_bits],
  321. cm3_cca_bits, 1 << mcp_bits,
  322. cm3_tr[cm3_tr_bits], sched_bit);
  323. }
  324. pr_err("CM_ERROR=%llx %s <%s>\n", cm_error,
  325. cm3_causes[cause], buf);
  326. pr_err("CM_ADDR =%lx\n", cm_addr);
  327. pr_err("CM_OTHER=%lx %s\n", cm_other, cm3_causes[ocause]);
  328. }
  329. /* reprime cause register */
  330. write_gcr_error_cause(0);
  331. }