traps.c 6.3 KB

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