cerr-sb1.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * Copyright (C) 2001,2002,2003 Broadcom 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 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/sched.h>
  19. #include <asm/mipsregs.h>
  20. #include <asm/sibyte/sb1250.h>
  21. #include <asm/sibyte/sb1250_regs.h>
  22. #if !defined(CONFIG_SIBYTE_BUS_WATCHER) || defined(CONFIG_SIBYTE_BW_TRACE)
  23. #include <asm/io.h>
  24. #include <asm/sibyte/sb1250_scd.h>
  25. #endif
  26. /*
  27. * We'd like to dump the L2_ECC_TAG register on errors, but errata make
  28. * that unsafe... So for now we don't. (BCM1250/BCM112x erratum SOC-48.)
  29. */
  30. #undef DUMP_L2_ECC_TAG_ON_ERROR
  31. /* SB1 definitions */
  32. /* XXX should come from config1 XXX */
  33. #define SB1_CACHE_INDEX_MASK 0x1fe0
  34. #define CP0_ERRCTL_RECOVERABLE (1 << 31)
  35. #define CP0_ERRCTL_DCACHE (1 << 30)
  36. #define CP0_ERRCTL_ICACHE (1 << 29)
  37. #define CP0_ERRCTL_MULTIBUS (1 << 23)
  38. #define CP0_ERRCTL_MC_TLB (1 << 15)
  39. #define CP0_ERRCTL_MC_TIMEOUT (1 << 14)
  40. #define CP0_CERRI_TAG_PARITY (1 << 29)
  41. #define CP0_CERRI_DATA_PARITY (1 << 28)
  42. #define CP0_CERRI_EXTERNAL (1 << 26)
  43. #define CP0_CERRI_IDX_VALID(c) (!((c) & CP0_CERRI_EXTERNAL))
  44. #define CP0_CERRI_DATA (CP0_CERRI_DATA_PARITY)
  45. #define CP0_CERRD_MULTIPLE (1 << 31)
  46. #define CP0_CERRD_TAG_STATE (1 << 30)
  47. #define CP0_CERRD_TAG_ADDRESS (1 << 29)
  48. #define CP0_CERRD_DATA_SBE (1 << 28)
  49. #define CP0_CERRD_DATA_DBE (1 << 27)
  50. #define CP0_CERRD_EXTERNAL (1 << 26)
  51. #define CP0_CERRD_LOAD (1 << 25)
  52. #define CP0_CERRD_STORE (1 << 24)
  53. #define CP0_CERRD_FILLWB (1 << 23)
  54. #define CP0_CERRD_COHERENCY (1 << 22)
  55. #define CP0_CERRD_DUPTAG (1 << 21)
  56. #define CP0_CERRD_DPA_VALID(c) (!((c) & CP0_CERRD_EXTERNAL))
  57. #define CP0_CERRD_IDX_VALID(c) \
  58. (((c) & (CP0_CERRD_LOAD | CP0_CERRD_STORE)) ? (!((c) & CP0_CERRD_EXTERNAL)) : 0)
  59. #define CP0_CERRD_CAUSES \
  60. (CP0_CERRD_LOAD | CP0_CERRD_STORE | CP0_CERRD_FILLWB | CP0_CERRD_COHERENCY | CP0_CERRD_DUPTAG)
  61. #define CP0_CERRD_TYPES \
  62. (CP0_CERRD_TAG_STATE | CP0_CERRD_TAG_ADDRESS | CP0_CERRD_DATA_SBE | CP0_CERRD_DATA_DBE | CP0_CERRD_EXTERNAL)
  63. #define CP0_CERRD_DATA (CP0_CERRD_DATA_SBE | CP0_CERRD_DATA_DBE)
  64. static uint32_t extract_ic(unsigned short addr, int data);
  65. static uint32_t extract_dc(unsigned short addr, int data);
  66. static inline void breakout_errctl(unsigned int val)
  67. {
  68. if (val & CP0_ERRCTL_RECOVERABLE)
  69. printk(" recoverable");
  70. if (val & CP0_ERRCTL_DCACHE)
  71. printk(" dcache");
  72. if (val & CP0_ERRCTL_ICACHE)
  73. printk(" icache");
  74. if (val & CP0_ERRCTL_MULTIBUS)
  75. printk(" multiple-buserr");
  76. printk("\n");
  77. }
  78. static inline void breakout_cerri(unsigned int val)
  79. {
  80. if (val & CP0_CERRI_TAG_PARITY)
  81. printk(" tag-parity");
  82. if (val & CP0_CERRI_DATA_PARITY)
  83. printk(" data-parity");
  84. if (val & CP0_CERRI_EXTERNAL)
  85. printk(" external");
  86. printk("\n");
  87. }
  88. static inline void breakout_cerrd(unsigned int val)
  89. {
  90. switch (val & CP0_CERRD_CAUSES) {
  91. case CP0_CERRD_LOAD:
  92. printk(" load,");
  93. break;
  94. case CP0_CERRD_STORE:
  95. printk(" store,");
  96. break;
  97. case CP0_CERRD_FILLWB:
  98. printk(" fill/wb,");
  99. break;
  100. case CP0_CERRD_COHERENCY:
  101. printk(" coherency,");
  102. break;
  103. case CP0_CERRD_DUPTAG:
  104. printk(" duptags,");
  105. break;
  106. default:
  107. printk(" NO CAUSE,");
  108. break;
  109. }
  110. if (!(val & CP0_CERRD_TYPES))
  111. printk(" NO TYPE");
  112. else {
  113. if (val & CP0_CERRD_MULTIPLE)
  114. printk(" multi-err");
  115. if (val & CP0_CERRD_TAG_STATE)
  116. printk(" tag-state");
  117. if (val & CP0_CERRD_TAG_ADDRESS)
  118. printk(" tag-address");
  119. if (val & CP0_CERRD_DATA_SBE)
  120. printk(" data-SBE");
  121. if (val & CP0_CERRD_DATA_DBE)
  122. printk(" data-DBE");
  123. if (val & CP0_CERRD_EXTERNAL)
  124. printk(" external");
  125. }
  126. printk("\n");
  127. }
  128. #ifndef CONFIG_SIBYTE_BUS_WATCHER
  129. static void check_bus_watcher(void)
  130. {
  131. uint32_t status, l2_err, memio_err;
  132. #ifdef DUMP_L2_ECC_TAG_ON_ERROR
  133. uint64_t l2_tag;
  134. #endif
  135. /* Destructive read, clears register and interrupt */
  136. status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
  137. /* Bit 31 is always on, but there's no #define for that */
  138. if (status & ~(1UL << 31)) {
  139. l2_err = csr_in32(IOADDR(A_BUS_L2_ERRORS));
  140. #ifdef DUMP_L2_ECC_TAG_ON_ERROR
  141. l2_tag = in64(IOADDR(A_L2_ECC_TAG));
  142. #endif
  143. memio_err = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
  144. printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
  145. printk("\nLast recorded signature:\n");
  146. printk("Request %02x from %d, answered by %d with Dcode %d\n",
  147. (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
  148. (int)(G_SCD_BERR_TID(status) >> 6),
  149. (int)G_SCD_BERR_RID(status),
  150. (int)G_SCD_BERR_DCODE(status));
  151. #ifdef DUMP_L2_ECC_TAG_ON_ERROR
  152. printk("Last L2 tag w/ bad ECC: %016llx\n", l2_tag);
  153. #endif
  154. } else {
  155. printk("Bus watcher indicates no error\n");
  156. }
  157. }
  158. #else
  159. extern void check_bus_watcher(void);
  160. #endif
  161. asmlinkage void sb1_cache_error(void)
  162. {
  163. uint32_t errctl, cerr_i, cerr_d, dpalo, dpahi, eepc, res;
  164. unsigned long long cerr_dpa;
  165. #ifdef CONFIG_SIBYTE_BW_TRACE
  166. /* Freeze the trace buffer now */
  167. #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
  168. csr_out32(M_BCM1480_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
  169. #else
  170. csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
  171. #endif
  172. printk("Trace buffer frozen\n");
  173. #endif
  174. printk("Cache error exception on CPU %x:\n",
  175. (read_c0_prid() >> 25) & 0x7);
  176. __asm__ __volatile__ (
  177. " .set push\n\t"
  178. " .set mips64\n\t"
  179. " .set noat\n\t"
  180. " mfc0 %0, $26\n\t"
  181. " mfc0 %1, $27\n\t"
  182. " mfc0 %2, $27, 1\n\t"
  183. " dmfc0 $1, $27, 3\n\t"
  184. " dsrl32 %3, $1, 0 \n\t"
  185. " sll %4, $1, 0 \n\t"
  186. " mfc0 %5, $30\n\t"
  187. " .set pop"
  188. : "=r" (errctl), "=r" (cerr_i), "=r" (cerr_d),
  189. "=r" (dpahi), "=r" (dpalo), "=r" (eepc));
  190. cerr_dpa = (((uint64_t)dpahi) << 32) | dpalo;
  191. printk(" c0_errorepc == %08x\n", eepc);
  192. printk(" c0_errctl == %08x", errctl);
  193. breakout_errctl(errctl);
  194. if (errctl & CP0_ERRCTL_ICACHE) {
  195. printk(" c0_cerr_i == %08x", cerr_i);
  196. breakout_cerri(cerr_i);
  197. if (CP0_CERRI_IDX_VALID(cerr_i)) {
  198. /* Check index of EPC, allowing for delay slot */
  199. if (((eepc & SB1_CACHE_INDEX_MASK) != (cerr_i & SB1_CACHE_INDEX_MASK)) &&
  200. ((eepc & SB1_CACHE_INDEX_MASK) != ((cerr_i & SB1_CACHE_INDEX_MASK) - 4)))
  201. printk(" cerr_i idx doesn't match eepc\n");
  202. else {
  203. res = extract_ic(cerr_i & SB1_CACHE_INDEX_MASK,
  204. (cerr_i & CP0_CERRI_DATA) != 0);
  205. if (!(res & cerr_i))
  206. printk("...didn't see indicated icache problem\n");
  207. }
  208. }
  209. }
  210. if (errctl & CP0_ERRCTL_DCACHE) {
  211. printk(" c0_cerr_d == %08x", cerr_d);
  212. breakout_cerrd(cerr_d);
  213. if (CP0_CERRD_DPA_VALID(cerr_d)) {
  214. printk(" c0_cerr_dpa == %010llx\n", cerr_dpa);
  215. if (!CP0_CERRD_IDX_VALID(cerr_d)) {
  216. res = extract_dc(cerr_dpa & SB1_CACHE_INDEX_MASK,
  217. (cerr_d & CP0_CERRD_DATA) != 0);
  218. if (!(res & cerr_d))
  219. printk("...didn't see indicated dcache problem\n");
  220. } else {
  221. if ((cerr_dpa & SB1_CACHE_INDEX_MASK) != (cerr_d & SB1_CACHE_INDEX_MASK))
  222. printk(" cerr_d idx doesn't match cerr_dpa\n");
  223. else {
  224. res = extract_dc(cerr_d & SB1_CACHE_INDEX_MASK,
  225. (cerr_d & CP0_CERRD_DATA) != 0);
  226. if (!(res & cerr_d))
  227. printk("...didn't see indicated problem\n");
  228. }
  229. }
  230. }
  231. }
  232. check_bus_watcher();
  233. /*
  234. * Calling panic() when a fatal cache error occurs scrambles the
  235. * state of the system (and the cache), making it difficult to
  236. * investigate after the fact. However, if you just stall the CPU,
  237. * the other CPU may keep on running, which is typically very
  238. * undesirable.
  239. */
  240. #ifdef CONFIG_SB1_CERR_STALL
  241. while (1)
  242. ;
  243. #else
  244. panic("unhandled cache error");
  245. #endif
  246. }
  247. /* Parity lookup table. */
  248. static const uint8_t parity[256] = {
  249. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  250. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  251. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  252. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  253. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  254. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  255. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  256. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  257. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  258. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  259. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  260. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  261. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
  262. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  263. 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
  264. 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0
  265. };
  266. /* Masks to select bits for Hamming parity, mask_72_64[i] for bit[i] */
  267. static const uint64_t mask_72_64[8] = {
  268. 0x0738C808099264FFULL,
  269. 0x38C808099264FF07ULL,
  270. 0xC808099264FF0738ULL,
  271. 0x08099264FF0738C8ULL,
  272. 0x099264FF0738C808ULL,
  273. 0x9264FF0738C80809ULL,
  274. 0x64FF0738C8080992ULL,
  275. 0xFF0738C808099264ULL
  276. };
  277. /* Calculate the parity on a range of bits */
  278. static char range_parity(uint64_t dword, int max, int min)
  279. {
  280. char parity = 0;
  281. int i;
  282. dword >>= min;
  283. for (i=max-min; i>=0; i--) {
  284. if (dword & 0x1)
  285. parity = !parity;
  286. dword >>= 1;
  287. }
  288. return parity;
  289. }
  290. /* Calculate the 4-bit even byte-parity for an instruction */
  291. static unsigned char inst_parity(uint32_t word)
  292. {
  293. int i, j;
  294. char parity = 0;
  295. for (j=0; j<4; j++) {
  296. char byte_parity = 0;
  297. for (i=0; i<8; i++) {
  298. if (word & 0x80000000)
  299. byte_parity = !byte_parity;
  300. word <<= 1;
  301. }
  302. parity <<= 1;
  303. parity |= byte_parity;
  304. }
  305. return parity;
  306. }
  307. static uint32_t extract_ic(unsigned short addr, int data)
  308. {
  309. unsigned short way;
  310. int valid;
  311. uint32_t taghi, taglolo, taglohi;
  312. unsigned long long taglo, va;
  313. uint64_t tlo_tmp;
  314. uint8_t lru;
  315. int res = 0;
  316. printk("Icache index 0x%04x ", addr);
  317. for (way = 0; way < 4; way++) {
  318. /* Index-load-tag-I */
  319. __asm__ __volatile__ (
  320. " .set push \n\t"
  321. " .set noreorder \n\t"
  322. " .set mips64 \n\t"
  323. " .set noat \n\t"
  324. " cache 4, 0(%3) \n\t"
  325. " mfc0 %0, $29 \n\t"
  326. " dmfc0 $1, $28 \n\t"
  327. " dsrl32 %1, $1, 0 \n\t"
  328. " sll %2, $1, 0 \n\t"
  329. " .set pop"
  330. : "=r" (taghi), "=r" (taglohi), "=r" (taglolo)
  331. : "r" ((way << 13) | addr));
  332. taglo = ((unsigned long long)taglohi << 32) | taglolo;
  333. if (way == 0) {
  334. lru = (taghi >> 14) & 0xff;
  335. printk("[Bank %d Set 0x%02x] LRU > %d %d %d %d > MRU\n",
  336. ((addr >> 5) & 0x3), /* bank */
  337. ((addr >> 7) & 0x3f), /* index */
  338. (lru & 0x3),
  339. ((lru >> 2) & 0x3),
  340. ((lru >> 4) & 0x3),
  341. ((lru >> 6) & 0x3));
  342. }
  343. va = (taglo & 0xC0000FFFFFFFE000ULL) | addr;
  344. if ((taglo & (1 << 31)) && (((taglo >> 62) & 0x3) == 3))
  345. va |= 0x3FFFF00000000000ULL;
  346. valid = ((taghi >> 29) & 1);
  347. if (valid) {
  348. tlo_tmp = taglo & 0xfff3ff;
  349. if (((taglo >> 10) & 1) ^ range_parity(tlo_tmp, 23, 0)) {
  350. printk(" ** bad parity in VTag0/G/ASID\n");
  351. res |= CP0_CERRI_TAG_PARITY;
  352. }
  353. if (((taglo >> 11) & 1) ^ range_parity(taglo, 63, 24)) {
  354. printk(" ** bad parity in R/VTag1\n");
  355. res |= CP0_CERRI_TAG_PARITY;
  356. }
  357. }
  358. if (valid ^ ((taghi >> 27) & 1)) {
  359. printk(" ** bad parity for valid bit\n");
  360. res |= CP0_CERRI_TAG_PARITY;
  361. }
  362. printk(" %d [VA %016llx] [Vld? %d] raw tags: %08X-%016llX\n",
  363. way, va, valid, taghi, taglo);
  364. if (data) {
  365. uint32_t datahi, insta, instb;
  366. uint8_t predecode;
  367. int offset;
  368. /* (hit all banks and ways) */
  369. for (offset = 0; offset < 4; offset++) {
  370. /* Index-load-data-I */
  371. __asm__ __volatile__ (
  372. " .set push\n\t"
  373. " .set noreorder\n\t"
  374. " .set mips64\n\t"
  375. " .set noat\n\t"
  376. " cache 6, 0(%3) \n\t"
  377. " mfc0 %0, $29, 1\n\t"
  378. " dmfc0 $1, $28, 1\n\t"
  379. " dsrl32 %1, $1, 0 \n\t"
  380. " sll %2, $1, 0 \n\t"
  381. " .set pop \n"
  382. : "=r" (datahi), "=r" (insta), "=r" (instb)
  383. : "r" ((way << 13) | addr | (offset << 3)));
  384. predecode = (datahi >> 8) & 0xff;
  385. if (((datahi >> 16) & 1) != (uint32_t)range_parity(predecode, 7, 0)) {
  386. printk(" ** bad parity in predecode\n");
  387. res |= CP0_CERRI_DATA_PARITY;
  388. }
  389. /* XXXKW should/could check predecode bits themselves */
  390. if (((datahi >> 4) & 0xf) ^ inst_parity(insta)) {
  391. printk(" ** bad parity in instruction a\n");
  392. res |= CP0_CERRI_DATA_PARITY;
  393. }
  394. if ((datahi & 0xf) ^ inst_parity(instb)) {
  395. printk(" ** bad parity in instruction b\n");
  396. res |= CP0_CERRI_DATA_PARITY;
  397. }
  398. printk(" %05X-%08X%08X", datahi, insta, instb);
  399. }
  400. printk("\n");
  401. }
  402. }
  403. return res;
  404. }
  405. /* Compute the ECC for a data doubleword */
  406. static uint8_t dc_ecc(uint64_t dword)
  407. {
  408. uint64_t t;
  409. uint32_t w;
  410. uint8_t p;
  411. int i;
  412. p = 0;
  413. for (i = 7; i >= 0; i--)
  414. {
  415. p <<= 1;
  416. t = dword & mask_72_64[i];
  417. w = (uint32_t)(t >> 32);
  418. p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
  419. ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
  420. w = (uint32_t)(t & 0xFFFFFFFF);
  421. p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
  422. ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
  423. }
  424. return p;
  425. }
  426. struct dc_state {
  427. unsigned char val;
  428. char *name;
  429. };
  430. static struct dc_state dc_states[] = {
  431. { 0x00, "INVALID" },
  432. { 0x0f, "COH-SHD" },
  433. { 0x13, "NCO-E-C" },
  434. { 0x19, "NCO-E-D" },
  435. { 0x16, "COH-E-C" },
  436. { 0x1c, "COH-E-D" },
  437. { 0xff, "*ERROR*" }
  438. };
  439. #define DC_TAG_VALID(state) \
  440. (((state) == 0x0) || ((state) == 0xf) || ((state) == 0x13) || \
  441. ((state) == 0x19) || ((state) == 0x16) || ((state) == 0x1c))
  442. static char *dc_state_str(unsigned char state)
  443. {
  444. struct dc_state *dsc = dc_states;
  445. while (dsc->val != 0xff) {
  446. if (dsc->val == state)
  447. break;
  448. dsc++;
  449. }
  450. return dsc->name;
  451. }
  452. static uint32_t extract_dc(unsigned short addr, int data)
  453. {
  454. int valid, way;
  455. unsigned char state;
  456. uint32_t taghi, taglolo, taglohi;
  457. unsigned long long taglo, pa;
  458. uint8_t ecc, lru;
  459. int res = 0;
  460. printk("Dcache index 0x%04x ", addr);
  461. for (way = 0; way < 4; way++) {
  462. __asm__ __volatile__ (
  463. " .set push\n\t"
  464. " .set noreorder\n\t"
  465. " .set mips64\n\t"
  466. " .set noat\n\t"
  467. " cache 5, 0(%3)\n\t" /* Index-load-tag-D */
  468. " mfc0 %0, $29, 2\n\t"
  469. " dmfc0 $1, $28, 2\n\t"
  470. " dsrl32 %1, $1, 0\n\t"
  471. " sll %2, $1, 0\n\t"
  472. " .set pop"
  473. : "=r" (taghi), "=r" (taglohi), "=r" (taglolo)
  474. : "r" ((way << 13) | addr));
  475. taglo = ((unsigned long long)taglohi << 32) | taglolo;
  476. pa = (taglo & 0xFFFFFFE000ULL) | addr;
  477. if (way == 0) {
  478. lru = (taghi >> 14) & 0xff;
  479. printk("[Bank %d Set 0x%02x] LRU > %d %d %d %d > MRU\n",
  480. ((addr >> 11) & 0x2) | ((addr >> 5) & 1), /* bank */
  481. ((addr >> 6) & 0x3f), /* index */
  482. (lru & 0x3),
  483. ((lru >> 2) & 0x3),
  484. ((lru >> 4) & 0x3),
  485. ((lru >> 6) & 0x3));
  486. }
  487. state = (taghi >> 25) & 0x1f;
  488. valid = DC_TAG_VALID(state);
  489. printk(" %d [PA %010llx] [state %s (%02x)] raw tags: %08X-%016llX\n",
  490. way, pa, dc_state_str(state), state, taghi, taglo);
  491. if (valid) {
  492. if (((taglo >> 11) & 1) ^ range_parity(taglo, 39, 26)) {
  493. printk(" ** bad parity in PTag1\n");
  494. res |= CP0_CERRD_TAG_ADDRESS;
  495. }
  496. if (((taglo >> 10) & 1) ^ range_parity(taglo, 25, 13)) {
  497. printk(" ** bad parity in PTag0\n");
  498. res |= CP0_CERRD_TAG_ADDRESS;
  499. }
  500. } else {
  501. res |= CP0_CERRD_TAG_STATE;
  502. }
  503. if (data) {
  504. uint32_t datalohi, datalolo, datahi;
  505. unsigned long long datalo;
  506. int offset;
  507. char bad_ecc = 0;
  508. for (offset = 0; offset < 4; offset++) {
  509. /* Index-load-data-D */
  510. __asm__ __volatile__ (
  511. " .set push\n\t"
  512. " .set noreorder\n\t"
  513. " .set mips64\n\t"
  514. " .set noat\n\t"
  515. " cache 7, 0(%3)\n\t" /* Index-load-data-D */
  516. " mfc0 %0, $29, 3\n\t"
  517. " dmfc0 $1, $28, 3\n\t"
  518. " dsrl32 %1, $1, 0 \n\t"
  519. " sll %2, $1, 0 \n\t"
  520. " .set pop"
  521. : "=r" (datahi), "=r" (datalohi), "=r" (datalolo)
  522. : "r" ((way << 13) | addr | (offset << 3)));
  523. datalo = ((unsigned long long)datalohi << 32) | datalolo;
  524. ecc = dc_ecc(datalo);
  525. if (ecc != datahi) {
  526. int bits;
  527. bad_ecc |= 1 << (3-offset);
  528. ecc ^= datahi;
  529. bits = hweight8(ecc);
  530. res |= (bits == 1) ? CP0_CERRD_DATA_SBE : CP0_CERRD_DATA_DBE;
  531. }
  532. printk(" %02X-%016llX", datahi, datalo);
  533. }
  534. printk("\n");
  535. if (bad_ecc)
  536. printk(" dwords w/ bad ECC: %d %d %d %d\n",
  537. !!(bad_ecc & 8), !!(bad_ecc & 4),
  538. !!(bad_ecc & 2), !!(bad_ecc & 1));
  539. }
  540. }
  541. return res;
  542. }