mips-cm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2013 Imagination Technologies
  4. * Author: Paul Burton <paul.burton@mips.com>
  5. */
  6. #include <linux/errno.h>
  7. #include <linux/of.h>
  8. #include <linux/percpu.h>
  9. #include <linux/spinlock.h>
  10. #include <asm/mips-cps.h>
  11. #include <asm/mipsregs.h>
  12. void __iomem *mips_gcr_base;
  13. void __iomem *mips_cm_l2sync_base;
  14. int mips_cm_is64;
  15. bool mips_cm_is_l2_hci_broken;
  16. static char *cm2_tr[8] = {
  17. "mem", "gcr", "gic", "mmio",
  18. "0x04", "cpc", "0x06", "0x07"
  19. };
  20. /* CM3 Tag ECC transaction 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_l2_type[4] = {
  110. [0x0] = "None",
  111. [0x1] = "Tag RAM single/double ECC error",
  112. [0x2] = "Data RAM single/double ECC error",
  113. [0x3] = "WS RAM uncorrectable dirty parity"
  114. };
  115. static char *cm2_l2_instr[32] = {
  116. [0x00] = "L2_NOP",
  117. [0x01] = "L2_ERR_CORR",
  118. [0x02] = "L2_TAG_INV",
  119. [0x03] = "L2_WS_CLEAN",
  120. [0x04] = "L2_RD_MDYFY_WR",
  121. [0x05] = "L2_WS_MRU",
  122. [0x06] = "L2_EVICT_LN2",
  123. [0x07] = "0x07",
  124. [0x08] = "L2_EVICT",
  125. [0x09] = "L2_REFL",
  126. [0x0a] = "L2_RD",
  127. [0x0b] = "L2_WR",
  128. [0x0c] = "L2_EVICT_MRU",
  129. [0x0d] = "L2_SYNC",
  130. [0x0e] = "L2_REFL_ERR",
  131. [0x0f] = "0x0f",
  132. [0x10] = "L2_INDX_WB_INV",
  133. [0x11] = "L2_INDX_LD_TAG",
  134. [0x12] = "L2_INDX_ST_TAG",
  135. [0x13] = "L2_INDX_ST_DATA",
  136. [0x14] = "L2_INDX_ST_ECC",
  137. [0x15] = "0x15",
  138. [0x16] = "0x16",
  139. [0x17] = "0x17",
  140. [0x18] = "L2_FTCH_AND_LCK",
  141. [0x19] = "L2_HIT_INV",
  142. [0x1a] = "L2_HIT_WB_INV",
  143. [0x1b] = "L2_HIT_WB",
  144. [0x1c] = "0x1c",
  145. [0x1d] = "0x1d",
  146. [0x1e] = "0x1e",
  147. [0x1f] = "0x1f"
  148. };
  149. static char *cm2_causes[32] = {
  150. "None", "GC_WR_ERR", "GC_RD_ERR", "COH_WR_ERR",
  151. "COH_RD_ERR", "MMIO_WR_ERR", "MMIO_RD_ERR", "0x07",
  152. "0x08", "0x09", "0x0a", "0x0b",
  153. "0x0c", "0x0d", "0x0e", "0x0f",
  154. "0x10", "INTVN_WR_ERR", "INTVN_RD_ERR", "0x13",
  155. "0x14", "0x15", "0x16", "0x17",
  156. "L2_RD_UNCORR", "L2_WR_UNCORR", "L2_CORR", "0x1b",
  157. "0x1c", "0x1d", "0x1e", "0x1f"
  158. };
  159. static char *cm3_causes[32] = {
  160. "0x0", "MP_CORRECTABLE_ECC_ERR", "MP_REQUEST_DECODE_ERR",
  161. "MP_UNCORRECTABLE_ECC_ERR", "MP_PARITY_ERR", "MP_COHERENCE_ERR",
  162. "CMBIU_REQUEST_DECODE_ERR", "CMBIU_PARITY_ERR", "CMBIU_AXI_RESP_ERR",
  163. "0x9", "RBI_BUS_ERR", "0xb", "0xc", "0xd", "0xe", "0xf", "0x10",
  164. "0x11", "0x12", "0x13", "0x14", "0x15", "0x16", "0x17", "0x18",
  165. "0x19", "0x1a", "0x1b", "0x1c", "0x1d", "0x1e", "0x1f"
  166. };
  167. static DEFINE_PER_CPU_ALIGNED(spinlock_t, cm_core_lock);
  168. static DEFINE_PER_CPU_ALIGNED(unsigned long, cm_core_lock_flags);
  169. phys_addr_t __weak mips_cm_phys_base(void)
  170. {
  171. unsigned long cmgcr;
  172. /* Check the CMGCRBase register is implemented */
  173. if (!(read_c0_config() & MIPS_CONF_M))
  174. return 0;
  175. if (!(read_c0_config2() & MIPS_CONF_M))
  176. return 0;
  177. if (!(read_c0_config3() & MIPS_CONF3_CMGCR))
  178. return 0;
  179. /* Read the address from CMGCRBase */
  180. cmgcr = read_c0_cmgcrbase();
  181. return (cmgcr & MIPS_CMGCRF_BASE) << (36 - 32);
  182. }
  183. phys_addr_t __weak mips_cm_l2sync_phys_base(void)
  184. {
  185. u32 base_reg;
  186. /*
  187. * If the L2-only sync region is already enabled then leave it at it's
  188. * current location.
  189. */
  190. base_reg = read_gcr_l2_only_sync_base();
  191. if (base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN)
  192. return base_reg & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE;
  193. /* Default to following the CM */
  194. return mips_cm_phys_base() + MIPS_CM_GCR_SIZE;
  195. }
  196. static void mips_cm_probe_l2sync(void)
  197. {
  198. unsigned major_rev;
  199. phys_addr_t addr;
  200. /* L2-only sync was introduced with CM major revision 6 */
  201. major_rev = FIELD_GET(CM_GCR_REV_MAJOR, read_gcr_rev());
  202. if (major_rev < 6)
  203. return;
  204. /* Find a location for the L2 sync region */
  205. addr = mips_cm_l2sync_phys_base();
  206. BUG_ON((addr & CM_GCR_L2_ONLY_SYNC_BASE_SYNCBASE) != addr);
  207. if (!addr)
  208. return;
  209. /* Set the region base address & enable it */
  210. write_gcr_l2_only_sync_base(addr | CM_GCR_L2_ONLY_SYNC_BASE_SYNCEN);
  211. /* Map the region */
  212. mips_cm_l2sync_base = ioremap(addr, MIPS_CM_L2SYNC_SIZE);
  213. }
  214. void mips_cm_update_property(void)
  215. {
  216. struct device_node *cm_node;
  217. cm_node = of_find_compatible_node(of_root, NULL, "mobileye,eyeq6-cm");
  218. if (!cm_node)
  219. return;
  220. pr_info("HCI (Hardware Cache Init for the L2 cache) in GCR_L2_RAM_CONFIG from the CM3 is broken");
  221. mips_cm_is_l2_hci_broken = true;
  222. of_node_put(cm_node);
  223. }
  224. int mips_cm_probe(void)
  225. {
  226. phys_addr_t addr;
  227. u32 base_reg;
  228. unsigned cpu;
  229. /*
  230. * No need to probe again if we have already been
  231. * here before.
  232. */
  233. if (mips_gcr_base)
  234. return 0;
  235. addr = mips_cm_phys_base();
  236. BUG_ON((addr & CM_GCR_BASE_GCRBASE) != addr);
  237. if (!addr)
  238. return -ENODEV;
  239. mips_gcr_base = ioremap(addr, MIPS_CM_GCR_SIZE);
  240. if (!mips_gcr_base)
  241. return -ENXIO;
  242. /* sanity check that we're looking at a CM */
  243. base_reg = read_gcr_base();
  244. if ((base_reg & CM_GCR_BASE_GCRBASE) != addr) {
  245. pr_err("GCRs appear to have been moved (expected them at 0x%08lx)!\n",
  246. (unsigned long)addr);
  247. iounmap(mips_gcr_base);
  248. mips_gcr_base = NULL;
  249. return -ENODEV;
  250. }
  251. /* set default target to memory */
  252. change_gcr_base(CM_GCR_BASE_CMDEFTGT, CM_GCR_BASE_CMDEFTGT_MEM);
  253. /* disable CM regions */
  254. write_gcr_reg0_base(CM_GCR_REGn_BASE_BASEADDR);
  255. write_gcr_reg0_mask(CM_GCR_REGn_MASK_ADDRMASK);
  256. write_gcr_reg1_base(CM_GCR_REGn_BASE_BASEADDR);
  257. write_gcr_reg1_mask(CM_GCR_REGn_MASK_ADDRMASK);
  258. write_gcr_reg2_base(CM_GCR_REGn_BASE_BASEADDR);
  259. write_gcr_reg2_mask(CM_GCR_REGn_MASK_ADDRMASK);
  260. write_gcr_reg3_base(CM_GCR_REGn_BASE_BASEADDR);
  261. write_gcr_reg3_mask(CM_GCR_REGn_MASK_ADDRMASK);
  262. /* probe for an L2-only sync region */
  263. mips_cm_probe_l2sync();
  264. /* determine register width for this CM */
  265. mips_cm_is64 = IS_ENABLED(CONFIG_64BIT) && (mips_cm_revision() >= CM_REV_CM3);
  266. for_each_possible_cpu(cpu)
  267. spin_lock_init(&per_cpu(cm_core_lock, cpu));
  268. return 0;
  269. }
  270. void mips_cm_lock_other(unsigned int cluster, unsigned int core,
  271. unsigned int vp, unsigned int block)
  272. {
  273. unsigned int curr_core, cm_rev;
  274. u32 val;
  275. cm_rev = mips_cm_revision();
  276. preempt_disable();
  277. if (cm_rev >= CM_REV_CM3) {
  278. val = FIELD_PREP(CM3_GCR_Cx_OTHER_CORE, core) |
  279. FIELD_PREP(CM3_GCR_Cx_OTHER_VP, vp);
  280. if (cm_rev >= CM_REV_CM3_5) {
  281. val |= CM_GCR_Cx_OTHER_CLUSTER_EN;
  282. val |= FIELD_PREP(CM_GCR_Cx_OTHER_CLUSTER, cluster);
  283. val |= FIELD_PREP(CM_GCR_Cx_OTHER_BLOCK, block);
  284. } else {
  285. WARN_ON(cluster != 0);
  286. WARN_ON(block != CM_GCR_Cx_OTHER_BLOCK_LOCAL);
  287. }
  288. /*
  289. * We need to disable interrupts in SMP systems in order to
  290. * ensure that we don't interrupt the caller with code which
  291. * may modify the redirect register. We do so here in a
  292. * slightly obscure way by using a spin lock, since this has
  293. * the neat property of also catching any nested uses of
  294. * mips_cm_lock_other() leading to a deadlock or a nice warning
  295. * with lockdep enabled.
  296. */
  297. spin_lock_irqsave(this_cpu_ptr(&cm_core_lock),
  298. *this_cpu_ptr(&cm_core_lock_flags));
  299. } else {
  300. WARN_ON(cluster != 0);
  301. WARN_ON(block != CM_GCR_Cx_OTHER_BLOCK_LOCAL);
  302. /*
  303. * We only have a GCR_CL_OTHER per core in systems with
  304. * CM 2.5 & older, so have to ensure other VP(E)s don't
  305. * race with us.
  306. */
  307. curr_core = cpu_core(&current_cpu_data);
  308. spin_lock_irqsave(&per_cpu(cm_core_lock, curr_core),
  309. per_cpu(cm_core_lock_flags, curr_core));
  310. val = FIELD_PREP(CM_GCR_Cx_OTHER_CORENUM, core);
  311. }
  312. write_gcr_cl_other(val);
  313. /*
  314. * Ensure the core-other region reflects the appropriate core &
  315. * VP before any accesses to it occur.
  316. */
  317. mb();
  318. }
  319. void mips_cm_unlock_other(void)
  320. {
  321. unsigned int curr_core;
  322. if (mips_cm_revision() < CM_REV_CM3) {
  323. curr_core = cpu_core(&current_cpu_data);
  324. spin_unlock_irqrestore(&per_cpu(cm_core_lock, curr_core),
  325. per_cpu(cm_core_lock_flags, curr_core));
  326. } else {
  327. spin_unlock_irqrestore(this_cpu_ptr(&cm_core_lock),
  328. *this_cpu_ptr(&cm_core_lock_flags));
  329. }
  330. preempt_enable();
  331. }
  332. void mips_cm_error_report(void)
  333. {
  334. u64 cm_error, cm_addr, cm_other;
  335. unsigned long revision;
  336. int ocause, cause;
  337. char buf[256];
  338. if (!mips_cm_present())
  339. return;
  340. revision = mips_cm_revision();
  341. cm_error = read_gcr_error_cause();
  342. cm_addr = read_gcr_error_addr();
  343. cm_other = read_gcr_error_mult();
  344. if (revision < CM_REV_CM3) { /* CM2 */
  345. cause = FIELD_GET(CM_GCR_ERROR_CAUSE_ERRTYPE, cm_error);
  346. ocause = FIELD_GET(CM_GCR_ERROR_MULT_ERR2ND, cm_other);
  347. if (!cause)
  348. return;
  349. if (cause < 16) {
  350. unsigned long cca_bits = (cm_error >> 15) & 7;
  351. unsigned long tr_bits = (cm_error >> 12) & 7;
  352. unsigned long cmd_bits = (cm_error >> 7) & 0x1f;
  353. unsigned long stag_bits = (cm_error >> 3) & 15;
  354. unsigned long sport_bits = (cm_error >> 0) & 7;
  355. snprintf(buf, sizeof(buf),
  356. "CCA=%lu TR=%s MCmd=%s STag=%lu "
  357. "SPort=%lu\n", cca_bits, cm2_tr[tr_bits],
  358. cm2_cmd[cmd_bits], stag_bits, sport_bits);
  359. } else if (cause < 24) {
  360. /* glob state & sresp together */
  361. unsigned long c3_bits = (cm_error >> 18) & 7;
  362. unsigned long c2_bits = (cm_error >> 15) & 7;
  363. unsigned long c1_bits = (cm_error >> 12) & 7;
  364. unsigned long c0_bits = (cm_error >> 9) & 7;
  365. unsigned long sc_bit = (cm_error >> 8) & 1;
  366. unsigned long cmd_bits = (cm_error >> 3) & 0x1f;
  367. unsigned long sport_bits = (cm_error >> 0) & 7;
  368. snprintf(buf, sizeof(buf),
  369. "C3=%s C2=%s C1=%s C0=%s SC=%s "
  370. "MCmd=%s SPort=%lu\n",
  371. cm2_core[c3_bits], cm2_core[c2_bits],
  372. cm2_core[c1_bits], cm2_core[c0_bits],
  373. sc_bit ? "True" : "False",
  374. cm2_cmd[cmd_bits], sport_bits);
  375. } else {
  376. unsigned long muc_bit = (cm_error >> 23) & 1;
  377. unsigned long ins_bits = (cm_error >> 18) & 0x1f;
  378. unsigned long arr_bits = (cm_error >> 16) & 3;
  379. unsigned long dw_bits = (cm_error >> 12) & 15;
  380. unsigned long way_bits = (cm_error >> 9) & 7;
  381. unsigned long mway_bit = (cm_error >> 8) & 1;
  382. unsigned long syn_bits = (cm_error >> 0) & 0xFF;
  383. snprintf(buf, sizeof(buf),
  384. "Type=%s%s Instr=%s DW=%lu Way=%lu "
  385. "MWay=%s Syndrome=0x%02lx",
  386. muc_bit ? "Multi-UC " : "",
  387. cm2_l2_type[arr_bits],
  388. cm2_l2_instr[ins_bits], dw_bits, way_bits,
  389. mway_bit ? "True" : "False", syn_bits);
  390. }
  391. pr_err("CM_ERROR=%08llx %s <%s>\n", cm_error,
  392. cm2_causes[cause], buf);
  393. pr_err("CM_ADDR =%08llx\n", cm_addr);
  394. pr_err("CM_OTHER=%08llx %s\n", cm_other, cm2_causes[ocause]);
  395. } else { /* CM3 */
  396. ulong core_id_bits, vp_id_bits, cmd_bits, cmd_group_bits;
  397. ulong cm3_cca_bits, mcp_bits, cm3_tr_bits, sched_bit;
  398. cause = FIELD_GET(CM3_GCR_ERROR_CAUSE_ERRTYPE, cm_error);
  399. ocause = FIELD_GET(CM_GCR_ERROR_MULT_ERR2ND, cm_other);
  400. if (!cause)
  401. return;
  402. /* Used by cause == {1,2,3} */
  403. core_id_bits = (cm_error >> 22) & 0xf;
  404. vp_id_bits = (cm_error >> 18) & 0xf;
  405. cmd_bits = (cm_error >> 14) & 0xf;
  406. cmd_group_bits = (cm_error >> 11) & 0xf;
  407. cm3_cca_bits = (cm_error >> 8) & 7;
  408. mcp_bits = (cm_error >> 5) & 0xf;
  409. cm3_tr_bits = (cm_error >> 1) & 0xf;
  410. sched_bit = cm_error & 0x1;
  411. if (cause == 1 || cause == 3) { /* Tag ECC */
  412. unsigned long tag_ecc = (cm_error >> 57) & 0x1;
  413. unsigned long tag_way_bits = (cm_error >> 29) & 0xffff;
  414. unsigned long dword_bits = (cm_error >> 49) & 0xff;
  415. unsigned long data_way_bits = (cm_error >> 45) & 0xf;
  416. unsigned long data_sets_bits = (cm_error >> 29) & 0xfff;
  417. unsigned long bank_bit = (cm_error >> 28) & 0x1;
  418. snprintf(buf, sizeof(buf),
  419. "%s ECC Error: Way=%lu (DWORD=%lu, Sets=%lu)"
  420. "Bank=%lu CoreID=%lu VPID=%lu Command=%s"
  421. "Command Group=%s CCA=%lu MCP=%d"
  422. "Transaction type=%s Scheduler=%lu\n",
  423. tag_ecc ? "TAG" : "DATA",
  424. tag_ecc ? (unsigned long)ffs(tag_way_bits) - 1 :
  425. data_way_bits, bank_bit, dword_bits,
  426. data_sets_bits,
  427. core_id_bits, vp_id_bits,
  428. cm3_cmd[cmd_bits],
  429. cm3_cmd_group[cmd_group_bits],
  430. cm3_cca_bits, 1 << mcp_bits,
  431. cm3_tr[cm3_tr_bits], sched_bit);
  432. } else if (cause == 2) {
  433. unsigned long data_error_type = (cm_error >> 41) & 0xfff;
  434. unsigned long data_decode_cmd = (cm_error >> 37) & 0xf;
  435. unsigned long data_decode_group = (cm_error >> 34) & 0x7;
  436. unsigned long data_decode_destination_id = (cm_error >> 28) & 0x3f;
  437. snprintf(buf, sizeof(buf),
  438. "Decode Request Error: Type=%lu, Command=%lu"
  439. "Command Group=%lu Destination ID=%lu"
  440. "CoreID=%lu VPID=%lu Command=%s"
  441. "Command Group=%s CCA=%lu MCP=%d"
  442. "Transaction type=%s Scheduler=%lu\n",
  443. data_error_type, data_decode_cmd,
  444. data_decode_group, data_decode_destination_id,
  445. core_id_bits, vp_id_bits,
  446. cm3_cmd[cmd_bits],
  447. cm3_cmd_group[cmd_group_bits],
  448. cm3_cca_bits, 1 << mcp_bits,
  449. cm3_tr[cm3_tr_bits], sched_bit);
  450. } else {
  451. buf[0] = 0;
  452. }
  453. pr_err("CM_ERROR=%llx %s <%s>\n", cm_error,
  454. cm3_causes[cause], buf);
  455. pr_err("CM_ADDR =%llx\n", cm_addr);
  456. pr_err("CM_OTHER=%llx %s\n", cm_other, cm3_causes[ocause]);
  457. }
  458. /* reprime cause register */
  459. write_gcr_error_cause(cm_error);
  460. }
  461. unsigned int mips_cps_first_online_in_cluster(void)
  462. {
  463. unsigned int local_cl;
  464. int i;
  465. local_cl = cpu_cluster(&current_cpu_data);
  466. /*
  467. * We rely upon knowledge that CPUs are numbered sequentially by
  468. * cluster - ie. CPUs 0..X will be in cluster 0, CPUs X+1..Y in cluster
  469. * 1, CPUs Y+1..Z in cluster 2 etc. This means that CPUs in the same
  470. * cluster will immediately precede or follow one another.
  471. *
  472. * First we scan backwards, until we find an online CPU in the cluster
  473. * or we move on to another cluster.
  474. */
  475. for (i = smp_processor_id() - 1; i >= 0; i--) {
  476. if (cpu_cluster(&cpu_data[i]) != local_cl)
  477. break;
  478. if (!cpu_online(i))
  479. continue;
  480. return false;
  481. }
  482. /* Then do the same for higher numbered CPUs */
  483. for (i = smp_processor_id() + 1; i < nr_cpu_ids; i++) {
  484. if (cpu_cluster(&cpu_data[i]) != local_cl)
  485. break;
  486. if (!cpu_online(i))
  487. continue;
  488. return false;
  489. }
  490. /* We found no online CPUs in the local cluster */
  491. return true;
  492. }