blob: e35620c9aebd180ccfa4a53d020adb610d853b99 [file] [log] [blame]
Aubrey Li65458982007-03-20 18:16:24 +08001/*
2 * U-boot - traps.c Routines related to interrupts and exceptions
3 *
Aubrey Li155fd762007-04-05 18:31:18 +08004 * Copyright (c) 2005-2007 Analog Devices Inc.
Aubrey Li65458982007-03-20 18:16:24 +08005 *
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
Aubrey Li155fd762007-04-05 18:31:18 +080032 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
33 * MA 02110-1301 USA
Aubrey Li65458982007-03-20 18:16:24 +080034 */
35
36#include <common.h>
37#include <linux/types.h>
38#include <asm/errno.h>
Aubrey Li65458982007-03-20 18:16:24 +080039#include <asm/system.h>
40#include <asm/traps.h>
Aubrey Li65458982007-03-20 18:16:24 +080041#include "cpu.h"
Aubrey Li65458982007-03-20 18:16:24 +080042#include <asm/cplb.h>
43#include <asm/io.h>
Mike Frysingerd4d77302008-02-04 19:26:55 -050044#include <asm/mach-common/bits/core.h>
45#include <asm/mach-common/bits/mpu.h>
Aubrey Li65458982007-03-20 18:16:24 +080046
47void init_IRQ(void)
48{
49 blackfin_init_IRQ();
50 return;
51}
52
53void process_int(unsigned long vec, struct pt_regs *fp)
54{
55 printf("interrupt\n");
56 return;
57}
58
59extern unsigned int icplb_table[page_descriptor_table_size][2];
60extern unsigned int dcplb_table[page_descriptor_table_size][2];
61
62unsigned long last_cplb_fault_retx;
63
64static unsigned int cplb_sizes[4] =
65 { 1024, 4 * 1024, 1024 * 1024, 4 * 1024 * 1024 };
66
67void trap_c(struct pt_regs *regs)
68{
69 unsigned int addr;
Mike Frysingerd4d77302008-02-04 19:26:55 -050070 unsigned long trapnr = (regs->seqstat) & EXCAUSE;
Aubrey Li65458982007-03-20 18:16:24 +080071 unsigned int i, j, size, *I0, *I1;
72 unsigned short data = 0;
73
74 switch (trapnr) {
75 /* 0x26 - Data CPLB Miss */
76 case VEC_CPLB_M:
77
Mike Frysingerd4d77302008-02-04 19:26:55 -050078#if ANOMALY_05000261
Aubrey Li65458982007-03-20 18:16:24 +080079 /*
80 * Work around an anomaly: if we see a new DCPLB fault, return
81 * without doing anything. Then, if we get the same fault again,
82 * handle it.
83 */
84 addr = last_cplb_fault_retx;
85 last_cplb_fault_retx = regs->retx;
86 printf("this time, curr = 0x%08x last = 0x%08x\n", addr,
87 last_cplb_fault_retx);
88 if (addr != last_cplb_fault_retx)
89 goto trap_c_return;
90#endif
91 data = 1;
92
93 case VEC_CPLB_I_M:
94
95 if (data)
96 addr = *pDCPLB_FAULT_ADDR;
97 else
98 addr = *pICPLB_FAULT_ADDR;
99
100 for (i = 0; i < page_descriptor_table_size; i++) {
101 if (data) {
102 size = cplb_sizes[dcplb_table[i][1] >> 16];
103 j = dcplb_table[i][0];
104 } else {
105 size = cplb_sizes[icplb_table[i][1] >> 16];
106 j = icplb_table[i][0];
107 }
108 if ((j <= addr) && ((j + size) > addr)) {
109 debug("found %i 0x%08x\n", i, j);
110 break;
111 }
112 }
113 if (i == page_descriptor_table_size) {
114 printf("something is really wrong\n");
115 do_reset(NULL, 0, 0, NULL);
116 }
117
118 /* Turn the cache off */
119 if (data) {
Mike Frysingerd4d77302008-02-04 19:26:55 -0500120 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800121 asm(" .align 8; ");
122 *(unsigned int *)DMEM_CONTROL &=
123 ~(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500124 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800125 } else {
Mike Frysingerd4d77302008-02-04 19:26:55 -0500126 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800127 asm(" .align 8; ");
128 *(unsigned int *)IMEM_CONTROL &= ~(IMC | ENICPLB);
Mike Frysingerd4d77302008-02-04 19:26:55 -0500129 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800130 }
131
132 if (data) {
133 I0 = (unsigned int *)DCPLB_ADDR0;
134 I1 = (unsigned int *)DCPLB_DATA0;
135 } else {
136 I0 = (unsigned int *)ICPLB_ADDR0;
137 I1 = (unsigned int *)ICPLB_DATA0;
138 }
139
140 j = 0;
141 while (*I1 & CPLB_LOCK) {
142 debug("skipping %i %08p - %08x\n", j, I1, *I1);
143 *I0++;
144 *I1++;
145 j++;
146 }
147
148 debug("remove %i 0x%08x 0x%08x\n", j, *I0, *I1);
149
150 for (; j < 15; j++) {
151 debug("replace %i 0x%08x 0x%08x\n", j, I0, I0 + 1);
152 *I0++ = *(I0 + 1);
153 *I1++ = *(I1 + 1);
154 }
155
156 if (data) {
157 *I0 = dcplb_table[i][0];
158 *I1 = dcplb_table[i][1];
159 I0 = (unsigned int *)DCPLB_ADDR0;
160 I1 = (unsigned int *)DCPLB_DATA0;
161 } else {
162 *I0 = icplb_table[i][0];
163 *I1 = icplb_table[i][1];
164 I0 = (unsigned int *)ICPLB_ADDR0;
165 I1 = (unsigned int *)ICPLB_DATA0;
166 }
167
168 for (j = 0; j < 16; j++) {
169 debug("%i 0x%08x 0x%08x\n", j, *I0++, *I1++);
170 }
171
172 /* Turn the cache back on */
173 if (data) {
174 j = *(unsigned int *)DMEM_CONTROL;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500175 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800176 asm(" .align 8; ");
177 *(unsigned int *)DMEM_CONTROL =
178 ACACHE_BCACHE | ENDCPLB | PORT_PREF0 | j;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500179 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800180 } else {
Mike Frysingerd4d77302008-02-04 19:26:55 -0500181 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800182 asm(" .align 8; ");
183 *(unsigned int *)IMEM_CONTROL = IMC | ENICPLB;
Mike Frysingerd4d77302008-02-04 19:26:55 -0500184 SSYNC();
Aubrey Li65458982007-03-20 18:16:24 +0800185 }
186
187 break;
188 default:
189 /* All traps come here */
190 printf("code=[0x%x], ", (unsigned int)(regs->seqstat & 0x3f));
191 printf("stack frame=0x%x, ", (unsigned int)regs);
192 printf("bad PC=0x%04x\n", (unsigned int)regs->pc);
193 dump(regs);
194 printf("\n\n");
195
196 printf("Unhandled IRQ or exceptions!\n");
197 printf("Please reset the board \n");
198 do_reset(NULL, 0, 0, NULL);
199 }
200
201trap_c_return:
202 return;
203
204}
205
206void dump(struct pt_regs *fp)
207{
208 debug("RETE: %08lx RETN: %08lx RETX: %08lx RETS: %08lx\n", fp->rete,
209 fp->retn, fp->retx, fp->rets);
210 debug("IPEND: %04lx SYSCFG: %04lx\n", fp->ipend, fp->syscfg);
211 debug("SEQSTAT: %08lx SP: %08lx\n", (long)fp->seqstat, (long)fp);
212 debug("R0: %08lx R1: %08lx R2: %08lx R3: %08lx\n", fp->r0,
213 fp->r1, fp->r2, fp->r3);
214 debug("R4: %08lx R5: %08lx R6: %08lx R7: %08lx\n", fp->r4,
215 fp->r5, fp->r6, fp->r7);
216 debug("P0: %08lx P1: %08lx P2: %08lx P3: %08lx\n", fp->p0,
217 fp->p1, fp->p2, fp->p3);
218 debug("P4: %08lx P5: %08lx FP: %08lx\n", fp->p4, fp->p5, fp->fp);
219 debug("A0.w: %08lx A0.x: %08lx A1.w: %08lx A1.x: %08lx\n",
220 fp->a0w, fp->a0x, fp->a1w, fp->a1x);
221
222 debug("LB0: %08lx LT0: %08lx LC0: %08lx\n", fp->lb0, fp->lt0,
223 fp->lc0);
224 debug("LB1: %08lx LT1: %08lx LC1: %08lx\n", fp->lb1, fp->lt1,
225 fp->lc1);
226 debug("B0: %08lx L0: %08lx M0: %08lx I0: %08lx\n", fp->b0, fp->l0,
227 fp->m0, fp->i0);
228 debug("B1: %08lx L1: %08lx M1: %08lx I1: %08lx\n", fp->b1, fp->l1,
229 fp->m1, fp->i1);
230 debug("B2: %08lx L2: %08lx M2: %08lx I2: %08lx\n", fp->b2, fp->l2,
231 fp->m2, fp->i2);
232 debug("B3: %08lx L3: %08lx M3: %08lx I3: %08lx\n", fp->b3, fp->l3,
233 fp->m3, fp->i3);
234
235 debug("DCPLB_FAULT_ADDR=%p\n", *pDCPLB_FAULT_ADDR);
236 debug("ICPLB_FAULT_ADDR=%p\n", *pICPLB_FAULT_ADDR);
237
238}