cpu.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_ISRAM)
  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. /* Before enable icache, disable it first */
  57. icache_disable();
  58. I0 = (unsigned int *)ICPLB_ADDR0;
  59. I1 = (unsigned int *)ICPLB_DATA0;
  60. /* make sure the locked ones go in first */
  61. for (i = 0; i < page_descriptor_table_size; i++) {
  62. if (CPLB_LOCK & icplb_table[i][1]) {
  63. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  64. icplb_table[i][0], icplb_table[i][1]);
  65. *I0++ = icplb_table[i][0];
  66. *I1++ = icplb_table[i][1];
  67. j++;
  68. }
  69. }
  70. for (i = 0; i < page_descriptor_table_size; i++) {
  71. if (!(CPLB_LOCK & icplb_table[i][1])) {
  72. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  73. icplb_table[i][0], icplb_table[i][1]);
  74. *I0++ = icplb_table[i][0];
  75. *I1++ = icplb_table[i][1];
  76. j++;
  77. if (j == 16) {
  78. break;
  79. }
  80. }
  81. }
  82. /* Fill the rest with invalid entry */
  83. if (j <= 15) {
  84. for (; j < 16; j++) {
  85. debug("filling %i with 0", j);
  86. *I1++ = 0x0;
  87. }
  88. }
  89. cli();
  90. sync();
  91. asm(" .align 8; ");
  92. *(unsigned int *)IMEM_CONTROL = IMC | ENICPLB;
  93. sync();
  94. sti();
  95. }
  96. void icache_disable(void)
  97. {
  98. cli();
  99. sync();
  100. asm(" .align 8; ");
  101. *(unsigned int *)IMEM_CONTROL &= ~(IMC | ENICPLB);
  102. sync();
  103. sti();
  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. cli();
  156. temp = *(unsigned int *)DMEM_CONTROL;
  157. sync();
  158. asm(" .align 8; ");
  159. *(unsigned int *)DMEM_CONTROL =
  160. ACACHE_BCACHE | ENDCPLB | PORT_PREF0 | temp;
  161. sync();
  162. sti();
  163. }
  164. void dcache_disable(void)
  165. {
  166. unsigned int *I0, *I1;
  167. int i;
  168. cli();
  169. sync();
  170. asm(" .align 8; ");
  171. *(unsigned int *)DMEM_CONTROL &=
  172. ~(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
  173. sync();
  174. sti();
  175. /* after disable dcache,
  176. * clear it so we don't confuse the next application
  177. */
  178. I0 = (unsigned int *)DCPLB_ADDR0;
  179. I1 = (unsigned int *)DCPLB_DATA0;
  180. for (i = 0; i < 16; i++) {
  181. *I0++ = 0x0;
  182. *I1++ = 0x0;
  183. }
  184. }
  185. int dcache_status(void)
  186. {
  187. unsigned int value;
  188. value = *(unsigned int *)DMEM_CONTROL;
  189. if (value & (ENDCPLB))
  190. return CACHE_ON;
  191. else
  192. return CACHE_OFF;
  193. }