cpu.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * (C) Copyright 2004 Texas Insturments
  3. *
  4. * (C) Copyright 2002
  5. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  6. * Marius Groeger <mgroeger@sysgo.de>
  7. *
  8. * (C) Copyright 2002
  9. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. /*
  30. * CPU specific code
  31. */
  32. #include <common.h>
  33. #include <command.h>
  34. #include <s3c6400.h>
  35. static void cache_flush (void);
  36. /* read co-processor 15, register #1 (control register) */
  37. static unsigned long read_p15_c1 (void)
  38. {
  39. unsigned long value;
  40. __asm__ __volatile__(
  41. "mrc p15, 0, %0, c1, c0, 0 @ read control reg\n"
  42. : "=r" (value)
  43. :
  44. : "memory");
  45. return value;
  46. }
  47. /* write to co-processor 15, register #1 (control register) */
  48. static void write_p15_c1 (unsigned long value)
  49. {
  50. __asm__ __volatile__(
  51. "mcr p15, 0, %0, c1, c0, 0 @ write it back\n"
  52. :
  53. : "r" (value)
  54. : "memory");
  55. read_p15_c1();
  56. }
  57. static void cp_delay (void)
  58. {
  59. volatile int i;
  60. /* Many OMAP regs need at least 2 nops */
  61. for (i = 0; i < 100; i++)
  62. __asm__ __volatile__("nop\n");
  63. }
  64. /* See also ARM Ref. Man. */
  65. #define C1_MMU (1 << 0) /* mmu off/on */
  66. #define C1_ALIGN (1 << 1) /* alignment faults off/on */
  67. #define C1_DC (1 << 2) /* dcache off/on */
  68. #define C1_WB (1 << 3) /* merging write buffer on/off */
  69. #define C1_BIG_ENDIAN (1 << 7) /* big endian off/on */
  70. #define C1_SYS_PROT (1 << 8) /* system protection */
  71. #define C1_ROM_PROT (1 << 9) /* ROM protection */
  72. #define C1_IC (1 << 12) /* icache off/on */
  73. #define C1_HIGH_VECTORS (1 << 13) /* location of vectors: low/high */
  74. #define RESERVED_1 (0xf << 3) /* must be 111b for R/W */
  75. int cpu_init (void)
  76. {
  77. return 0;
  78. }
  79. int cleanup_before_linux (void)
  80. {
  81. /*
  82. * this function is called just before we call linux
  83. * it prepares the processor for linux
  84. *
  85. * we turn off caches etc ...
  86. */
  87. disable_interrupts ();
  88. /* turn off I/D-cache */
  89. icache_disable();
  90. dcache_disable();
  91. cache_flush();
  92. return 0;
  93. }
  94. /* * reset the cpu by setting up the watchdog timer and let him time out */
  95. void reset_cpu (ulong ignored)
  96. {
  97. printf("reset... \n\n\n");
  98. SW_RST_REG = 0x6400;
  99. /* loop forever and wait for reset to happen */
  100. while (1) {
  101. if (serial_tstc()) {
  102. serial_getc();
  103. break;
  104. }
  105. }
  106. /*NOTREACHED*/
  107. }
  108. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  109. {
  110. disable_interrupts ();
  111. reset_cpu (0);
  112. /*NOTREACHED*/
  113. return 0;
  114. }
  115. void icache_enable (void)
  116. {
  117. ulong reg;
  118. reg = read_p15_c1 (); /* get control reg. */
  119. cp_delay ();
  120. write_p15_c1 (reg | C1_IC);
  121. }
  122. void icache_disable (void)
  123. {
  124. ulong reg;
  125. reg = read_p15_c1 ();
  126. cp_delay ();
  127. write_p15_c1 (reg & ~C1_IC);
  128. }
  129. int icache_status (void)
  130. {
  131. return (read_p15_c1 () & C1_IC) != 0;
  132. }
  133. /* It makes no sense to use the dcache if the MMU is not enabled */
  134. void dcache_enable (void)
  135. {
  136. ulong reg;
  137. reg = read_p15_c1 ();
  138. cp_delay ();
  139. write_p15_c1 (reg | C1_DC);
  140. }
  141. void dcache_disable (void)
  142. {
  143. ulong reg;
  144. reg = read_p15_c1 ();
  145. cp_delay ();
  146. write_p15_c1 (reg & ~C1_DC);
  147. }
  148. int dcache_status (void)
  149. {
  150. return (read_p15_c1 () & C1_DC) != 0;
  151. }
  152. /* flush I/D-cache */
  153. static void cache_flush (void)
  154. {
  155. /* invalidate both caches and flush btb */
  156. asm ("mcr p15, 0, %0, c7, c7, 0": :"r" (0));
  157. /* mem barrier to sync things */
  158. asm ("mcr p15, 0, %0, c7, c10, 4": :"r" (0));
  159. }