cpu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * U-boot - cpu.c CPU specific functions
  3. *
  4. * Copyright (c) 2005 blackfin.uclinux.org
  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., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 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. #define CACHE_ON 1
  33. #define CACHE_OFF 0
  34. extern unsigned int icplb_table[page_descriptor_table_size][2];
  35. extern unsigned int dcplb_table[page_descriptor_table_size][2];
  36. #ifdef DEBUG
  37. #define pr_debug(fmt,arg...) printf(fmt,##arg)
  38. #else
  39. static inline int
  40. __attribute__ ((format(printf, 1, 2))) pr_debug(const char *fmt, ...)
  41. {
  42. return 0;
  43. }
  44. #endif
  45. int do_reset(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  46. {
  47. __asm__ __volatile__("cli r3;" "P0 = %0;" "JUMP (P0);"::"r"(L1_ISRAM)
  48. );
  49. return 0;
  50. }
  51. /* These functions are just used to satisfy the linker */
  52. int cpu_init(void)
  53. {
  54. return 0;
  55. }
  56. int cleanup_before_linux(void)
  57. {
  58. return 0;
  59. }
  60. void icache_enable(void)
  61. {
  62. unsigned int *I0, *I1;
  63. int i, j = 0;
  64. #ifdef __ADSPBF537__
  65. if ((*pCHIPID >> 28) < 2)
  66. return;
  67. #endif
  68. /* Before enable icache, disable it first */
  69. icache_disable();
  70. I0 = (unsigned int *)ICPLB_ADDR0;
  71. I1 = (unsigned int *)ICPLB_DATA0;
  72. /* make sure the locked ones go in first */
  73. for (i = 0; i < page_descriptor_table_size; i++) {
  74. if (CPLB_LOCK & icplb_table[i][1]) {
  75. pr_debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  76. icplb_table[i][0], icplb_table[i][1]);
  77. *I0++ = icplb_table[i][0];
  78. *I1++ = icplb_table[i][1];
  79. j++;
  80. }
  81. }
  82. for (i = 0; i < page_descriptor_table_size; i++) {
  83. if (!(CPLB_LOCK & icplb_table[i][1])) {
  84. pr_debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  85. icplb_table[i][0], icplb_table[i][1]);
  86. *I0++ = icplb_table[i][0];
  87. *I1++ = icplb_table[i][1];
  88. j++;
  89. if (j == 16) {
  90. break;
  91. }
  92. }
  93. }
  94. /* Fill the rest with invalid entry */
  95. if (j <= 15) {
  96. for (; j <= 16; j++) {
  97. pr_debug("filling %i with 0", j);
  98. *I1++ = 0x0;
  99. }
  100. }
  101. cli();
  102. __builtin_bfin_ssync();
  103. asm(" .align 8; ");
  104. *(unsigned int *)IMEM_CONTROL = IMC | ENICPLB;
  105. __builtin_bfin_ssync();
  106. sti();
  107. }
  108. void icache_disable(void)
  109. {
  110. #ifdef __ADSPBF537__
  111. if ((*pCHIPID >> 28) < 2)
  112. return;
  113. #endif
  114. cli();
  115. __builtin_bfin_ssync();
  116. asm(" .align 8; ");
  117. *(unsigned int *)IMEM_CONTROL &= ~(IMC | ENICPLB);
  118. __builtin_bfin_ssync();
  119. sti();
  120. }
  121. int icache_status(void)
  122. {
  123. unsigned int value;
  124. value = *(unsigned int *)IMEM_CONTROL;
  125. if (value & (IMC | ENICPLB))
  126. return CACHE_ON;
  127. else
  128. return CACHE_OFF;
  129. }
  130. void dcache_enable(void)
  131. {
  132. unsigned int *I0, *I1;
  133. unsigned int temp;
  134. int i, j = 0;
  135. /* Before enable dcache, disable it first */
  136. dcache_disable();
  137. I0 = (unsigned int *)DCPLB_ADDR0;
  138. I1 = (unsigned int *)DCPLB_DATA0;
  139. /* make sure the locked ones go in first */
  140. for (i = 0; i < page_descriptor_table_size; i++) {
  141. if (CPLB_LOCK & dcplb_table[i][1]) {
  142. pr_debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  143. dcplb_table[i][0], dcplb_table[i][1]);
  144. *I0++ = dcplb_table[i][0];
  145. *I1++ = dcplb_table[i][1];
  146. j++;
  147. } else {
  148. pr_debug("skip %02i %02i 0x%08x 0x%08x\n", i, j,
  149. dcplb_table[i][0], dcplb_table[i][1]);
  150. }
  151. }
  152. for (i = 0; i < page_descriptor_table_size; i++) {
  153. if (!(CPLB_LOCK & dcplb_table[i][1])) {
  154. pr_debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  155. dcplb_table[i][0], dcplb_table[i][1]);
  156. *I0++ = dcplb_table[i][0];
  157. *I1++ = dcplb_table[i][1];
  158. j++;
  159. if (j == 16) {
  160. break;
  161. }
  162. }
  163. }
  164. /* Fill the rest with invalid entry */
  165. if (j <= 15) {
  166. for (; j <= 16; j++) {
  167. pr_debug("filling %i with 0", j);
  168. *I1++ = 0x0;
  169. }
  170. }
  171. cli();
  172. temp = *(unsigned int *)DMEM_CONTROL;
  173. __builtin_bfin_ssync();
  174. asm(" .align 8; ");
  175. *(unsigned int *)DMEM_CONTROL =
  176. ACACHE_BCACHE | ENDCPLB | PORT_PREF0 | temp;
  177. __builtin_bfin_ssync();
  178. sti();
  179. }
  180. void dcache_disable(void)
  181. {
  182. unsigned int *I0, *I1;
  183. int i;
  184. cli();
  185. __builtin_bfin_ssync();
  186. asm(" .align 8; ");
  187. *(unsigned int *)DMEM_CONTROL &=
  188. ~(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
  189. __builtin_bfin_ssync();
  190. sti();
  191. /* after disable dcache,
  192. * clear it so we don't confuse the next application
  193. */
  194. I0 = (unsigned int *)DCPLB_ADDR0;
  195. I1 = (unsigned int *)DCPLB_DATA0;
  196. for (i = 0; i < 16; i++) {
  197. *I0++ = 0x0;
  198. *I1++ = 0x0;
  199. }
  200. }
  201. int dcache_status(void)
  202. {
  203. unsigned int value;
  204. value = *(unsigned int *)DMEM_CONTROL;
  205. if (value & (ENDCPLB))
  206. return CACHE_ON;
  207. else
  208. return CACHE_OFF;
  209. }