cpu.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * U-boot - cpu.c CPU specific functions
  3. *
  4. * Copyright (c) 2005-2007 Analog Devices Inc.
  5. *
  6. * (C) Copyright 2000-2004
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  25. * MA 02110-1301 USA
  26. */
  27. #include <common.h>
  28. #include <asm/blackfin.h>
  29. #include <command.h>
  30. #include <asm/entry.h>
  31. #include <asm/cplb.h>
  32. #include <asm/io.h>
  33. #define CACHE_ON 1
  34. #define CACHE_OFF 0
  35. extern unsigned int icplb_table[page_descriptor_table_size][2];
  36. extern unsigned int dcplb_table[page_descriptor_table_size][2];
  37. int do_reset(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  38. {
  39. __asm__ __volatile__("cli r3;" "P0 = %0;" "JUMP (P0);"::"r"(L1_INST_SRAM)
  40. );
  41. return 0;
  42. }
  43. /* These functions are just used to satisfy the linker */
  44. int cpu_init(void)
  45. {
  46. return 0;
  47. }
  48. int cleanup_before_linux(void)
  49. {
  50. return 0;
  51. }
  52. void icache_enable(void)
  53. {
  54. unsigned int *I0, *I1;
  55. int i, j = 0;
  56. if ((*pCHIPID >> 28) < 2)
  57. return;
  58. /* Before enable icache, disable it first */
  59. icache_disable();
  60. I0 = (unsigned int *)ICPLB_ADDR0;
  61. I1 = (unsigned int *)ICPLB_DATA0;
  62. /* make sure the locked ones go in first */
  63. for (i = 0; i < page_descriptor_table_size; i++) {
  64. if (CPLB_LOCK & icplb_table[i][1]) {
  65. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  66. icplb_table[i][0], icplb_table[i][1]);
  67. *I0++ = icplb_table[i][0];
  68. *I1++ = icplb_table[i][1];
  69. j++;
  70. }
  71. }
  72. for (i = 0; i < page_descriptor_table_size; i++) {
  73. if (!(CPLB_LOCK & icplb_table[i][1])) {
  74. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  75. icplb_table[i][0], icplb_table[i][1]);
  76. *I0++ = icplb_table[i][0];
  77. *I1++ = icplb_table[i][1];
  78. j++;
  79. if (j == 16) {
  80. break;
  81. }
  82. }
  83. }
  84. /* Fill the rest with invalid entry */
  85. if (j <= 15) {
  86. for (; j < 16; j++) {
  87. debug("filling %i with 0", j);
  88. *I1++ = 0x0;
  89. }
  90. }
  91. SSYNC();
  92. asm(" .align 8; ");
  93. *(unsigned int *)IMEM_CONTROL = IMC | ENICPLB;
  94. SSYNC();
  95. }
  96. void icache_disable(void)
  97. {
  98. if ((*pCHIPID >> 28) < 2)
  99. return;
  100. SSYNC();
  101. asm(" .align 8; ");
  102. *(unsigned int *)IMEM_CONTROL &= ~(IMC | ENICPLB);
  103. SSYNC();
  104. }
  105. int icache_status(void)
  106. {
  107. unsigned int value;
  108. value = *(unsigned int *)IMEM_CONTROL;
  109. if (value & (IMC | ENICPLB))
  110. return CACHE_ON;
  111. else
  112. return CACHE_OFF;
  113. }
  114. void dcache_enable(void)
  115. {
  116. unsigned int *I0, *I1;
  117. unsigned int temp;
  118. int i, j = 0;
  119. /* Before enable dcache, disable it first */
  120. dcache_disable();
  121. I0 = (unsigned int *)DCPLB_ADDR0;
  122. I1 = (unsigned int *)DCPLB_DATA0;
  123. /* make sure the locked ones go in first */
  124. for (i = 0; i < page_descriptor_table_size; i++) {
  125. if (CPLB_LOCK & dcplb_table[i][1]) {
  126. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  127. dcplb_table[i][0], dcplb_table[i][1]);
  128. *I0++ = dcplb_table[i][0];
  129. *I1++ = dcplb_table[i][1];
  130. j++;
  131. } else {
  132. debug("skip %02i %02i 0x%08x 0x%08x\n", i, j,
  133. dcplb_table[i][0], dcplb_table[i][1]);
  134. }
  135. }
  136. for (i = 0; i < page_descriptor_table_size; i++) {
  137. if (!(CPLB_LOCK & dcplb_table[i][1])) {
  138. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  139. dcplb_table[i][0], dcplb_table[i][1]);
  140. *I0++ = dcplb_table[i][0];
  141. *I1++ = dcplb_table[i][1];
  142. j++;
  143. if (j == 16) {
  144. break;
  145. }
  146. }
  147. }
  148. /* Fill the rest with invalid entry */
  149. if (j <= 15) {
  150. for (; j < 16; j++) {
  151. debug("filling %i with 0", j);
  152. *I1++ = 0x0;
  153. }
  154. }
  155. temp = *(unsigned int *)DMEM_CONTROL;
  156. SSYNC();
  157. asm(" .align 8; ");
  158. *(unsigned int *)DMEM_CONTROL =
  159. ACACHE_BCACHE | ENDCPLB | PORT_PREF0 | temp;
  160. SSYNC();
  161. }
  162. void dcache_disable(void)
  163. {
  164. unsigned int *I0, *I1;
  165. int i;
  166. SSYNC();
  167. asm(" .align 8; ");
  168. *(unsigned int *)DMEM_CONTROL &=
  169. ~(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
  170. SSYNC();
  171. /* after disable dcache,
  172. * clear it so we don't confuse the next application
  173. */
  174. I0 = (unsigned int *)DCPLB_ADDR0;
  175. I1 = (unsigned int *)DCPLB_DATA0;
  176. for (i = 0; i < 16; i++) {
  177. *I0++ = 0x0;
  178. *I1++ = 0x0;
  179. }
  180. }
  181. int dcache_status(void)
  182. {
  183. unsigned int value;
  184. value = *(unsigned int *)DMEM_CONTROL;
  185. if (value & (ENDCPLB))
  186. return CACHE_ON;
  187. else
  188. return CACHE_OFF;
  189. }