cpu.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #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. 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. cli();
  92. sync();
  93. asm(" .align 8; ");
  94. *(unsigned int *)IMEM_CONTROL = IMC | ENICPLB;
  95. sync();
  96. sti();
  97. }
  98. void icache_disable(void)
  99. {
  100. if ((*pCHIPID >> 28) < 2)
  101. return;
  102. cli();
  103. sync();
  104. asm(" .align 8; ");
  105. *(unsigned int *)IMEM_CONTROL &= ~(IMC | ENICPLB);
  106. sync();
  107. sti();
  108. }
  109. int icache_status(void)
  110. {
  111. unsigned int value;
  112. value = *(unsigned int *)IMEM_CONTROL;
  113. if (value & (IMC | ENICPLB))
  114. return CACHE_ON;
  115. else
  116. return CACHE_OFF;
  117. }
  118. void dcache_enable(void)
  119. {
  120. unsigned int *I0, *I1;
  121. unsigned int temp;
  122. int i, j = 0;
  123. /* Before enable dcache, disable it first */
  124. dcache_disable();
  125. I0 = (unsigned int *)DCPLB_ADDR0;
  126. I1 = (unsigned int *)DCPLB_DATA0;
  127. /* make sure the locked ones go in first */
  128. for (i = 0; i < page_descriptor_table_size; i++) {
  129. if (CPLB_LOCK & dcplb_table[i][1]) {
  130. debug("adding %02i %02i 0x%08x 0x%08x\n", i, j,
  131. dcplb_table[i][0], dcplb_table[i][1]);
  132. *I0++ = dcplb_table[i][0];
  133. *I1++ = dcplb_table[i][1];
  134. j++;
  135. } else {
  136. debug("skip %02i %02i 0x%08x 0x%08x\n", i, j,
  137. dcplb_table[i][0], dcplb_table[i][1]);
  138. }
  139. }
  140. for (i = 0; i < page_descriptor_table_size; i++) {
  141. if (!(CPLB_LOCK & dcplb_table[i][1])) {
  142. 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. if (j == 16) {
  148. break;
  149. }
  150. }
  151. }
  152. /* Fill the rest with invalid entry */
  153. if (j <= 15) {
  154. for (; j < 16; j++) {
  155. debug("filling %i with 0", j);
  156. *I1++ = 0x0;
  157. }
  158. }
  159. cli();
  160. temp = *(unsigned int *)DMEM_CONTROL;
  161. sync();
  162. asm(" .align 8; ");
  163. *(unsigned int *)DMEM_CONTROL =
  164. ACACHE_BCACHE | ENDCPLB | PORT_PREF0 | temp;
  165. sync();
  166. sti();
  167. }
  168. void dcache_disable(void)
  169. {
  170. unsigned int *I0, *I1;
  171. int i;
  172. cli();
  173. sync();
  174. asm(" .align 8; ");
  175. *(unsigned int *)DMEM_CONTROL &=
  176. ~(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
  177. sync();
  178. sti();
  179. /* after disable dcache,
  180. * clear it so we don't confuse the next application
  181. */
  182. I0 = (unsigned int *)DCPLB_ADDR0;
  183. I1 = (unsigned int *)DCPLB_DATA0;
  184. for (i = 0; i < 16; i++) {
  185. *I0++ = 0x0;
  186. *I1++ = 0x0;
  187. }
  188. }
  189. int dcache_status(void)
  190. {
  191. unsigned int value;
  192. value = *(unsigned int *)DMEM_CONTROL;
  193. if (value & (ENDCPLB))
  194. return CACHE_ON;
  195. else
  196. return CACHE_OFF;
  197. }