2 * Copyright (C) 2001 Broadcom Corporation
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.
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.
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.
19 #include <linux/sched.h>
20 #include <asm/mipsregs.h>
21 #include <asm/sibyte/sb1250.h>
23 #ifndef CONFIG_SIBYTE_BUS_WATCHER
25 #include <asm/sibyte/sb1250_regs.h>
26 #include <asm/sibyte/sb1250_scd.h>
27 #include <asm/sibyte/64bit.h>
32 /* XXX should come from config1 XXX */
33 #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)
42 #define CP0_CERRI_TAG_PARITY (1 << 29)
43 #define CP0_CERRI_DATA_PARITY (1 << 28)
44 #define CP0_CERRI_EXTERNAL (1 << 26)
46 #define CP0_CERRI_IDX_VALID(c) (!((c) & CP0_CERRI_EXTERNAL))
47 #define CP0_CERRI_DATA (CP0_CERRI_DATA_PARITY)
49 #define CP0_CERRD_MULTIPLE (1 << 31)
50 #define CP0_CERRD_TAG_STATE (1 << 30)
51 #define CP0_CERRD_TAG_ADDRESS (1 << 29)
52 #define CP0_CERRD_DATA_SBE (1 << 28)
53 #define CP0_CERRD_DATA_DBE (1 << 27)
54 #define CP0_CERRD_EXTERNAL (1 << 26)
55 #define CP0_CERRD_LOAD (1 << 25)
56 #define CP0_CERRD_STORE (1 << 24)
57 #define CP0_CERRD_FILLWB (1 << 23)
58 #define CP0_CERRD_COHERENCY (1 << 22)
59 #define CP0_CERRD_DUPTAG (1 << 21)
61 #define CP0_CERRD_DPA_VALID(c) (!((c) & CP0_CERRD_EXTERNAL))
62 #define CP0_CERRD_IDX_VALID(c) \
63 (((c) & (CP0_CERRD_LOAD | CP0_CERRD_STORE)) ? (!((c) & CP0_CERRD_EXTERNAL)) : 0)
64 #define CP0_CERRD_CAUSES \
65 (CP0_CERRD_LOAD | CP0_CERRD_STORE | CP0_CERRD_FILLWB | CP0_CERRD_COHERENCY | CP0_CERRD_DUPTAG)
66 #define CP0_CERRD_TYPES \
67 (CP0_CERRD_TAG_STATE | CP0_CERRD_TAG_ADDRESS | CP0_CERRD_DATA_SBE | CP0_CERRD_DATA_DBE | CP0_CERRD_EXTERNAL)
68 #define CP0_CERRD_DATA (CP0_CERRD_DATA_SBE | CP0_CERRD_DATA_DBE)
70 static uint32_t extract_ic(unsigned short addr, int data);
71 static uint32_t extract_dc(unsigned short addr, int data);
73 static inline void breakout_errctl(unsigned int val)
75 if (val & CP0_ERRCTL_RECOVERABLE)
76 prom_printf(" recoverable");
77 if (val & CP0_ERRCTL_DCACHE)
78 prom_printf(" dcache");
79 if (val & CP0_ERRCTL_ICACHE)
80 prom_printf(" icache");
81 if (val & CP0_ERRCTL_MULTIBUS)
82 prom_printf(" multiple-buserr");
86 static inline void breakout_cerri(unsigned int val)
88 if (val & CP0_CERRI_TAG_PARITY)
89 prom_printf(" tag-parity");
90 if (val & CP0_CERRI_DATA_PARITY)
91 prom_printf(" data-parity");
92 if (val & CP0_CERRI_EXTERNAL)
93 prom_printf(" external");
97 static inline void breakout_cerrd(unsigned int val)
99 switch (val & CP0_CERRD_CAUSES) {
101 prom_printf(" load,");
103 case CP0_CERRD_STORE:
104 prom_printf(" store,");
106 case CP0_CERRD_FILLWB:
107 prom_printf(" fill/wb,");
109 case CP0_CERRD_COHERENCY:
110 prom_printf(" coherency,");
112 case CP0_CERRD_DUPTAG:
113 prom_printf(" duptags,");
116 prom_printf(" NO CAUSE,");
119 if (!(val & CP0_CERRD_TYPES))
120 prom_printf(" NO TYPE");
122 if (val & CP0_CERRD_MULTIPLE)
123 prom_printf(" multi-err");
124 if (val & CP0_CERRD_TAG_STATE)
125 prom_printf(" tag-state");
126 if (val & CP0_CERRD_TAG_ADDRESS)
127 prom_printf(" tag-address");
128 if (val & CP0_CERRD_DATA_SBE)
129 prom_printf(" data-SBE");
130 if (val & CP0_CERRD_DATA_DBE)
131 prom_printf(" data-DBE");
132 if (val & CP0_CERRD_EXTERNAL)
133 prom_printf(" external");
138 #ifndef CONFIG_SIBYTE_BUS_WATCHER
140 static void check_bus_watcher(void)
142 uint32_t status, l2_err, memio_err;
144 /* Destructive read, clears register and interrupt */
145 status = csr_in32(IO_SPACE_BASE | A_SCD_BUS_ERR_STATUS);
146 /* Bit 31 is always on, but there's no #define for that */
147 if (status & ~(1UL << 31)) {
148 l2_err = csr_in32(IO_SPACE_BASE | A_BUS_L2_ERRORS);
149 memio_err = csr_in32(IO_SPACE_BASE | A_BUS_MEM_IO_ERRORS);
150 prom_printf("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
151 prom_printf("\nLast recorded signature:\n");
152 prom_printf("Request %02x from %d, answered by %d with Dcode %d\n",
153 (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
154 (int)(G_SCD_BERR_TID(status) >> 6),
155 (int)G_SCD_BERR_RID(status),
156 (int)G_SCD_BERR_DCODE(status));
158 prom_printf("Bus watcher indicates no error\n");
162 extern void check_bus_watcher(void);
165 asmlinkage void sb1_cache_error(void)
168 uint32_t errctl, cerr_i, cerr_d, dpalo, dpahi, eepc, res;
170 prom_printf("Cache error exception on CPU %x:\n",
171 (read_c0_prid() >> 25) & 0x7);
173 __asm__ __volatile__ (
179 " mfc0 %2, $27, 1\n\t"
180 " dmfc0 $1, $27, 3\n\t"
181 " dsrl32 %3, $1, 0 \n\t"
182 " sll %4, $1, 0 \n\t"
185 : "=r" (errctl), "=r" (cerr_i), "=r" (cerr_d),
186 "=r" (dpahi), "=r" (dpalo), "=r" (eepc));
188 cerr_dpa = (((uint64_t)dpahi) << 32) | dpalo;
189 prom_printf(" cp0_errorepc == %08x\n", eepc);
190 prom_printf(" cp0_errctl == %08x", errctl);
191 breakout_errctl(errctl);
192 if (errctl & CP0_ERRCTL_ICACHE) {
193 prom_printf(" cp0_cerr_i == %08x", cerr_i);
194 breakout_cerri(cerr_i);
195 if (CP0_CERRI_IDX_VALID(cerr_i)) {
196 /* Check index of EPC, allowing for delay slot */
197 if (((eepc & SB1_CACHE_INDEX_MASK) != (cerr_i & SB1_CACHE_INDEX_MASK)) &&
198 ((eepc & SB1_CACHE_INDEX_MASK) != ((cerr_i & SB1_CACHE_INDEX_MASK) - 4)))
199 prom_printf(" cerr_i idx doesn't match eepc\n");
201 res = extract_ic(cerr_i & SB1_CACHE_INDEX_MASK,
202 (cerr_i & CP0_CERRI_DATA) != 0);
204 prom_printf("...didn't see indicated icache problem\n");
208 if (errctl & CP0_ERRCTL_DCACHE) {
209 prom_printf(" cp0_cerr_d == %08x", cerr_d);
210 breakout_cerrd(cerr_d);
211 if (CP0_CERRD_DPA_VALID(cerr_d)) {
212 prom_printf(" cp0_cerr_dpa == %010llx\n", cerr_dpa);
213 if (!CP0_CERRD_IDX_VALID(cerr_d)) {
214 res = extract_dc(cerr_dpa & SB1_CACHE_INDEX_MASK,
215 (cerr_d & CP0_CERRD_DATA) != 0);
217 prom_printf("...didn't see indicated dcache problem\n");
219 if ((cerr_dpa & SB1_CACHE_INDEX_MASK) != (cerr_d & SB1_CACHE_INDEX_MASK))
220 prom_printf(" cerr_d idx doesn't match cerr_dpa\n");
222 res = extract_dc(cerr_d & SB1_CACHE_INDEX_MASK,
223 (cerr_d & CP0_CERRD_DATA) != 0);
225 prom_printf("...didn't see indicated problem\n");
235 * This tends to make things get really ugly; let's just stall instead.
236 * panic("Can't handle the cache error!");
241 /* Parity lookup table. */
242 static const uint8_t parity[256] = {
243 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,
244 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,
245 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,
246 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,
247 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,
248 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,
249 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,
250 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 /* Masks to select bits for Hamming parity, mask_72_64[i] for bit[i] */
254 static const uint64_t mask_72_64[8] = {
265 /* Calculate the parity on a range of bits */
266 static char range_parity(uint64_t dword, int max, int min)
271 for (i=max-min; i>=0; i--) {
279 /* Calculate the 4-bit even byte-parity for an instruction */
280 static unsigned char inst_parity(uint32_t word)
284 for (j=0; j<4; j++) {
285 char byte_parity = 0;
286 for (i=0; i<8; i++) {
287 if (word & 0x80000000)
288 byte_parity = !byte_parity;
292 parity |= byte_parity;
297 static uint32_t extract_ic(unsigned short addr, int data)
301 uint64_t taglo, va, tlo_tmp;
302 uint32_t taghi, taglolo, taglohi;
306 prom_printf("Icache index 0x%04x ", addr);
307 for (way = 0; way < 4; way++) {
308 /* Index-load-tag-I */
309 __asm__ __volatile__ (
311 " .set noreorder \n\t"
314 " cache 4, 0(%3) \n\t"
316 " dmfc0 $1, $28 \n\t"
317 " dsrl32 %1, $1, 0 \n\t"
318 " sll %2, $1, 0 \n\t"
320 : "=r" (taghi), "=r" (taglohi), "=r" (taglolo)
321 : "r" ((way << 13) | addr));
323 taglo = ((unsigned long long)taglohi << 32) | taglolo;
325 lru = (taghi >> 14) & 0xff;
326 prom_printf("[Bank %d Set 0x%02x] LRU > %d %d %d %d > MRU\n",
327 ((addr >> 5) & 0x3), /* bank */
328 ((addr >> 7) & 0x3f), /* index */
334 va = (taglo & 0xC0000FFFFFFFE000) | addr;
335 if ((taglo & (1 << 31)) && (((taglo >> 62) & 0x3) == 3))
336 va |= 0x3FFFF00000000000;
337 valid = ((taghi >> 29) & 1);
339 tlo_tmp = taglo & 0xfff3ff;
340 if (((taglo >> 10) & 1) ^ range_parity(tlo_tmp, 23, 0)) {
341 prom_printf(" ** bad parity in VTag0/G/ASID\n");
342 res |= CP0_CERRI_TAG_PARITY;
344 if (((taglo >> 11) & 1) ^ range_parity(taglo, 63, 24)) {
345 prom_printf(" ** bad parity in R/VTag1\n");
346 res |= CP0_CERRI_TAG_PARITY;
349 if (valid ^ ((taghi >> 27) & 1)) {
350 prom_printf(" ** bad parity for valid bit\n");
351 res |= CP0_CERRI_TAG_PARITY;
353 prom_printf(" %d [VA %016llx] [Vld? %d] raw tags: %08X-%016llX\n",
354 way, va, valid, taghi, taglo);
357 uint32_t datahi, insta, instb;
361 /* (hit all banks and ways) */
362 for (offset = 0; offset < 4; offset++) {
363 /* Index-load-data-I */
364 __asm__ __volatile__ (
366 " .set noreorder\n\t"
369 " cache 6, 0(%3) \n\t"
370 " mfc0 %0, $29, 1\n\t"
371 " dmfc0 $1, $28, 1\n\t"
372 " dsrl32 %1, $1, 0 \n\t"
373 " sll %2, $1, 0 \n\t"
375 : "=r" (datahi), "=r" (insta), "=r" (instb)
376 : "r" ((way << 13) | addr | (offset << 3)));
377 predecode = (datahi >> 8) & 0xff;
378 if (((datahi >> 16) & 1) != (uint32_t)range_parity(predecode, 7, 0)) {
379 prom_printf(" ** bad parity in predecode\n");
380 res |= CP0_CERRI_DATA_PARITY;
382 /* XXXKW should/could check predecode bits themselves */
383 if (((datahi >> 4) & 0xf) ^ inst_parity(insta)) {
384 prom_printf(" ** bad parity in instruction a\n");
385 res |= CP0_CERRI_DATA_PARITY;
387 if ((datahi & 0xf) ^ inst_parity(instb)) {
388 prom_printf(" ** bad parity in instruction b\n");
389 res |= CP0_CERRI_DATA_PARITY;
391 prom_printf(" %05X-%08X%08X", datahi, insta, instb);
399 /* Compute the ECC for a data doubleword */
400 static uint8_t dc_ecc(uint64_t dword)
408 for (i = 7; i >= 0; i--)
411 t = dword & mask_72_64[i];
412 w = (uint32_t)(t >> 32);
413 p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
414 ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
415 w = (uint32_t)(t & 0xFFFFFFFF);
416 p ^= (parity[w>>24] ^ parity[(w>>16) & 0xFF]
417 ^ parity[(w>>8) & 0xFF] ^ parity[w & 0xFF]);
427 static struct dc_state dc_states[] = {
437 #define DC_TAG_VALID(state) \
438 (((state) == 0xf) || ((state) == 0x13) || ((state) == 0x19) || ((state == 0x16)) || ((state) == 0x1c))
440 static char *dc_state_str(unsigned char state)
442 struct dc_state *dsc = dc_states;
443 while (dsc->val != 0xff) {
444 if (dsc->val == state)
451 static uint32_t extract_dc(unsigned short addr, int data)
456 uint32_t taghi, taglolo, taglohi;
460 prom_printf("Dcache index 0x%04x ", addr);
461 for (way = 0; way < 4; way++) {
462 __asm__ __volatile__ (
464 " .set noreorder\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"
473 : "=r" (taghi), "=r" (taglohi), "=r" (taglolo)
474 : "r" ((way << 13) | addr));
476 taglo = ((unsigned long long)taglohi << 32) | taglolo;
477 pa = (taglo & 0xFFFFFFE000) | addr;
479 lru = (taghi >> 14) & 0xff;
480 prom_printf("[Bank %d Set 0x%02x] LRU > %d %d %d %d > MRU\n",
481 ((addr >> 11) & 0x2) | ((addr >> 5) & 1), /* bank */
482 ((addr >> 6) & 0x3f), /* index */
488 state = (taghi >> 25) & 0x1f;
489 valid = DC_TAG_VALID(state);
490 prom_printf(" %d [PA %010llx] [state %s (%02x)] raw tags: %08X-%016llX\n",
491 way, pa, dc_state_str(state), state, taghi, taglo);
493 if (((taglo >> 11) & 1) ^ range_parity(taglo, 39, 26)) {
494 prom_printf(" ** bad parity in PTag1\n");
495 res |= CP0_CERRD_TAG_ADDRESS;
497 if (((taglo >> 10) & 1) ^ range_parity(taglo, 25, 13)) {
498 prom_printf(" ** bad parity in PTag0\n");
499 res |= CP0_CERRD_TAG_ADDRESS;
502 res |= CP0_CERRD_TAG_STATE;
507 uint32_t datalohi, datalolo, datahi;
510 for (offset = 0; offset < 4; offset++) {
511 /* Index-load-data-D */
512 __asm__ __volatile__ (
514 " .set noreorder\n\t"
517 " cache 7, 0(%3)\n\t" /* Index-load-data-D */
518 " mfc0 %0, $29, 3\n\t"
519 " dmfc0 $1, $28, 3\n\t"
520 " dsrl32 %1, $1, 0 \n\t"
521 " sll %2, $1, 0 \n\t"
523 : "=r" (datahi), "=r" (datalohi), "=r" (datalolo)
524 : "r" ((way << 13) | addr | (offset << 3)));
525 datalo = ((unsigned long long)datalohi << 32) | datalolo;
526 ecc = dc_ecc(datalo);
529 prom_printf(" ** bad ECC (%02x %02x) ->",
536 res |= (bits == 1) ? CP0_CERRD_DATA_SBE : CP0_CERRD_DATA_DBE;
538 prom_printf(" %02X-%016llX", datahi, datalo);