Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - traps.c Routines related to interrupts and exceptions |
| 3 | * |
| 4 | * Copyright (c) 2005 blackfin.uclinux.org |
| 5 | * |
| 6 | * This file is based on |
| 7 | * No original Copyright holder listed, |
| 8 | * Probabily original (C) Roman Zippel (assigned DJD, 1999) |
| 9 | * |
| 10 | * Copyright 2003 Metrowerks - for Blackfin |
| 11 | * Copyright 2000-2001 Lineo, Inc. D. Jeff Dionne <jeff@lineo.ca> |
| 12 | * Copyright 1999-2000 D. Jeff Dionne, <jeff@uclinux.org> |
| 13 | * |
| 14 | * (C) Copyright 2000-2004 |
| 15 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 16 | * |
| 17 | * See file CREDITS for list of people who contributed to this |
| 18 | * project. |
| 19 | * |
| 20 | * This program is free software; you can redistribute it and/or |
| 21 | * modify it under the terms of the GNU General Public License as |
| 22 | * published by the Free Software Foundation; either version 2 of |
| 23 | * the License, or (at your option) any later version. |
| 24 | * |
| 25 | * This program is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | * GNU General Public License for more details. |
| 29 | * |
| 30 | * You should have received a copy of the GNU General Public License |
| 31 | * along with this program; if not, write to the Free Software |
| 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 33 | * MA 02111-1307 USA |
| 34 | */ |
| 35 | |
| 36 | #include <common.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <asm/errno.h> |
| 39 | #include <asm/irq.h> |
| 40 | #include <asm/system.h> |
| 41 | #include <asm/traps.h> |
| 42 | #include <asm/page.h> |
| 43 | #include <asm/machdep.h> |
| 44 | #include "cpu.h" |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 45 | #include <asm/arch/anomaly.h> |
| 46 | #include <asm/cplb.h> |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 47 | #include <asm/io.h> |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 48 | |
| 49 | void init_IRQ(void) |
| 50 | { |
| 51 | blackfin_init_IRQ(); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | void process_int(unsigned long vec, struct pt_regs *fp) |
| 56 | { |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 57 | printf("interrupt\n"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 61 | extern unsigned int icplb_table[page_descriptor_table_size][2]; |
| 62 | extern unsigned int dcplb_table[page_descriptor_table_size][2]; |
| 63 | |
| 64 | unsigned long last_cplb_fault_retx; |
| 65 | |
| 66 | static unsigned int cplb_sizes[4] = |
| 67 | { 1024, 4 * 1024, 1024 * 1024, 4 * 1024 * 1024 }; |
| 68 | |
| 69 | void trap_c(struct pt_regs *regs) |
| 70 | { |
| 71 | unsigned int addr; |
| 72 | unsigned long trapnr = (regs->seqstat) & SEQSTAT_EXCAUSE; |
| 73 | unsigned int i, j, size, *I0, *I1; |
| 74 | unsigned short data = 0; |
| 75 | |
| 76 | switch (trapnr) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 77 | /* 0x26 - Data CPLB Miss */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 78 | case VEC_CPLB_M: |
| 79 | |
| 80 | #ifdef ANOMALY_05000261 |
| 81 | /* |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 82 | * Work around an anomaly: if we see a new DCPLB fault, |
| 83 | * return without doing anything. Then, |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 84 | * if we get the same fault again, handle it. |
| 85 | */ |
| 86 | addr = last_cplb_fault_retx; |
| 87 | last_cplb_fault_retx = regs->retx; |
| 88 | printf("this time, curr = 0x%08x last = 0x%08x\n", |
| 89 | addr, last_cplb_fault_retx); |
| 90 | if (addr != last_cplb_fault_retx) |
| 91 | goto trap_c_return; |
| 92 | #endif |
| 93 | data = 1; |
| 94 | |
| 95 | case VEC_CPLB_I_M: |
| 96 | |
| 97 | if (data) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 98 | addr = *(unsigned int *)pDCPLB_FAULT_ADDR; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 99 | } else { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 100 | addr = *(unsigned int *)pICPLB_FAULT_ADDR; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 101 | } |
| 102 | for (i = 0; i < page_descriptor_table_size; i++) { |
| 103 | if (data) { |
| 104 | size = cplb_sizes[dcplb_table[i][1] >> 16]; |
| 105 | j = dcplb_table[i][0]; |
| 106 | } else { |
| 107 | size = cplb_sizes[icplb_table[i][1] >> 16]; |
| 108 | j = icplb_table[i][0]; |
| 109 | } |
| 110 | if ((j <= addr) && ((j + size) > addr)) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 111 | debug("found %i 0x%08x\n", i, j); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 112 | break; |
| 113 | } |
| 114 | } |
| 115 | if (i == page_descriptor_table_size) { |
| 116 | printf("something is really wrong\n"); |
| 117 | do_reset(NULL, 0, 0, NULL); |
| 118 | } |
| 119 | |
| 120 | /* Turn the cache off */ |
| 121 | if (data) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 122 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 123 | asm(" .align 8; "); |
| 124 | *(unsigned int *)DMEM_CONTROL &= |
| 125 | ~(ACACHE_BCACHE | ENDCPLB | PORT_PREF0); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 126 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 127 | } else { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 128 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 129 | asm(" .align 8; "); |
| 130 | *(unsigned int *)IMEM_CONTROL &= ~(IMC | ENICPLB); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 131 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | if (data) { |
| 135 | I0 = (unsigned int *)DCPLB_ADDR0; |
| 136 | I1 = (unsigned int *)DCPLB_DATA0; |
| 137 | } else { |
| 138 | I0 = (unsigned int *)ICPLB_ADDR0; |
| 139 | I1 = (unsigned int *)ICPLB_DATA0; |
| 140 | } |
| 141 | |
| 142 | j = 0; |
| 143 | while (*I1 & CPLB_LOCK) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 144 | debug("skipping %i %08p - %08x\n", j, I1, *I1); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 145 | *I0++; |
| 146 | *I1++; |
| 147 | j++; |
| 148 | } |
| 149 | |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 150 | debug("remove %i 0x%08x 0x%08x\n", j, *I0, *I1); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 151 | |
| 152 | for (; j < 15; j++) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 153 | debug("replace %i 0x%08x 0x%08x\n", j, I0, I0 + 1); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 154 | *I0++ = *(I0 + 1); |
| 155 | *I1++ = *(I1 + 1); |
| 156 | } |
| 157 | |
| 158 | if (data) { |
| 159 | *I0 = dcplb_table[i][0]; |
| 160 | *I1 = dcplb_table[i][1]; |
| 161 | I0 = (unsigned int *)DCPLB_ADDR0; |
| 162 | I1 = (unsigned int *)DCPLB_DATA0; |
| 163 | } else { |
| 164 | *I0 = icplb_table[i][0]; |
| 165 | *I1 = icplb_table[i][1]; |
| 166 | I0 = (unsigned int *)ICPLB_ADDR0; |
| 167 | I1 = (unsigned int *)ICPLB_DATA0; |
| 168 | } |
| 169 | |
| 170 | for (j = 0; j < 16; j++) { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 171 | debug("%i 0x%08x 0x%08x\n", j, *I0++, *I1++); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* Turn the cache back on */ |
| 175 | if (data) { |
| 176 | j = *(unsigned int *)DMEM_CONTROL; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 177 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 178 | asm(" .align 8; "); |
| 179 | *(unsigned int *)DMEM_CONTROL = |
| 180 | ACACHE_BCACHE | ENDCPLB | PORT_PREF0 | j; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 181 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 182 | } else { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 183 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 184 | asm(" .align 8; "); |
| 185 | *(unsigned int *)IMEM_CONTROL = IMC | ENICPLB; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 186 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | break; |
| 190 | default: |
| 191 | /* All traps come here */ |
| 192 | printf("code=[0x%x], ", (unsigned int)(regs->seqstat & 0x3f)); |
| 193 | printf("stack frame=0x%x, ", (unsigned int)regs); |
| 194 | printf("bad PC=0x%04x\n", (unsigned int)regs->pc); |
| 195 | dump(regs); |
| 196 | printf("\n\n"); |
| 197 | |
| 198 | printf("Unhandled IRQ or exceptions!\n"); |
| 199 | printf("Please reset the board \n"); |
| 200 | do_reset(NULL, 0, 0, NULL); |
| 201 | } |
| 202 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 203 | return; |
| 204 | |
| 205 | } |
| 206 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 207 | void dump(struct pt_regs *fp) |
| 208 | { |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 209 | debug("RETE: %08lx RETN: %08lx RETX: %08lx RETS: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 210 | fp->rete, fp->retn, fp->retx, fp->rets); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 211 | debug("IPEND: %04lx SYSCFG: %04lx\n", fp->ipend, fp->syscfg); |
| 212 | debug("SEQSTAT: %08lx SP: %08lx\n", (long)fp->seqstat, (long)fp); |
| 213 | debug("R0: %08lx R1: %08lx R2: %08lx R3: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 214 | fp->r0, fp->r1, fp->r2, fp->r3); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 215 | debug("R4: %08lx R5: %08lx R6: %08lx R7: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 216 | fp->r4, fp->r5, fp->r6, fp->r7); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 217 | debug("P0: %08lx P1: %08lx P2: %08lx P3: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 218 | fp->p0, fp->p1, fp->p2, fp->p3); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 219 | debug("P4: %08lx P5: %08lx FP: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 220 | fp->p4, fp->p5, fp->fp); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 221 | debug("A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 222 | fp->a0w, fp->a0x, fp->a1w, fp->a1x); |
| 223 | |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 224 | debug("LB0: %08lx LT0: %08lx LC0: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 225 | fp->lb0, fp->lt0, fp->lc0); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 226 | debug("LB1: %08lx LT1: %08lx LC1: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 227 | fp->lb1, fp->lt1, fp->lc1); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 228 | debug("B0: %08lx L0: %08lx M0: %08lx I0: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 229 | fp->b0, fp->l0, fp->m0, fp->i0); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 230 | debug("B1: %08lx L1: %08lx M1: %08lx I1: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 231 | fp->b1, fp->l1, fp->m1, fp->i1); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 232 | debug("B2: %08lx L2: %08lx M2: %08lx I2: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 233 | fp->b2, fp->l2, fp->m2, fp->i2); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 234 | debug("B3: %08lx L3: %08lx M3: %08lx I3: %08lx\n", |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 235 | fp->b3, fp->l3, fp->m3, fp->i3); |
| 236 | |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 237 | debug("DCPLB_FAULT_ADDR=%p\n", *pDCPLB_FAULT_ADDR); |
| 238 | debug("ICPLB_FAULT_ADDR=%p\n", *pICPLB_FAULT_ADDR); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 239 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 240 | } |