cerr-sb1.c 16 KB

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