cpu.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
  8. *
  9. * Copyright (C) 2011 Andes Technology Corporation
  10. * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
  11. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  12. *
  13. * See file CREDITS for list of people who contributed to this
  14. * project.
  15. *
  16. * This program is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 2 of
  19. * the License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  29. * MA 02111-1307 USA
  30. */
  31. /* CPU specific code */
  32. #include <common.h>
  33. #include <command.h>
  34. #include <watchdog.h>
  35. #include <asm/cache.h>
  36. #include <faraday/ftwdt010_wdt.h>
  37. /*
  38. * cleanup_before_linux() is called just before we call linux
  39. * it prepares the processor for linux
  40. *
  41. * we disable interrupt and caches.
  42. */
  43. int cleanup_before_linux(void)
  44. {
  45. #ifdef CONFIG_MMU
  46. unsigned long i;
  47. #endif
  48. disable_interrupts();
  49. #ifdef CONFIG_MMU
  50. /* turn off I/D-cache */
  51. icache_disable();
  52. dcache_disable();
  53. /* flush I/D-cache */
  54. invalidate_icac();
  55. invalidate_dcac();
  56. #endif
  57. return 0;
  58. }
  59. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  60. {
  61. disable_interrupts();
  62. /*
  63. * reset to the base addr of andesboot.
  64. * currently no ROM loader at addr 0.
  65. * do not use reset_cpu(0);
  66. */
  67. #ifdef CONFIG_FTWDT010_WATCHDOG
  68. /*
  69. * workaround: if we use CONFIG_HW_WATCHDOG with ftwdt010, will lead
  70. * automatic hardware reset when booting Linux.
  71. * Please do not use CONFIG_HW_WATCHDOG and WATCHDOG_RESET() here.
  72. */
  73. ftwdt010_wdt_reset();
  74. while (1)
  75. ;
  76. #endif /* CONFIG_FTWDT010_WATCHDOG */
  77. /*NOTREACHED*/
  78. }
  79. static inline unsigned long CACHE_LINE_SIZE(enum cache_t cache)
  80. {
  81. if (cache == ICACHE)
  82. return 8 << (((GET_ICM_CFG() & ICM_CFG_MSK_ISZ) \
  83. >> ICM_CFG_OFF_ISZ) - 1);
  84. else
  85. return 8 << (((GET_DCM_CFG() & DCM_CFG_MSK_DSZ) \
  86. >> DCM_CFG_OFF_DSZ) - 1);
  87. }
  88. void dcache_flush_range(unsigned long start, unsigned long end)
  89. {
  90. unsigned long line_size;
  91. line_size = CACHE_LINE_SIZE(DCACHE);
  92. while (end > start) {
  93. __asm__ volatile ("\n\tcctl %0, L1D_VA_WB" : : "r"(start));
  94. __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL" : : "r"(start));
  95. start += line_size;
  96. }
  97. }
  98. void icache_inval_range(unsigned long start, unsigned long end)
  99. {
  100. unsigned long line_size;
  101. line_size = CACHE_LINE_SIZE(ICACHE);
  102. while (end > start) {
  103. __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL" : : "r"(start));
  104. start += line_size;
  105. }
  106. }
  107. void flush_cache(unsigned long addr, unsigned long size)
  108. {
  109. dcache_flush_range(addr , addr + size);
  110. icache_inval_range(addr , addr + size);
  111. }
  112. void icache_enable(void)
  113. {
  114. __asm__ __volatile__ (
  115. "mfsr $p0, $mr8\n\t"
  116. "ori $p0, $p0, 0x01\n\t"
  117. "mtsr $p0, $mr8\n\t"
  118. "isb\n\t"
  119. );
  120. }
  121. void icache_disable(void)
  122. {
  123. __asm__ __volatile__ (
  124. "mfsr $p0, $mr8\n\t"
  125. "li $p1, ~0x01\n\t"
  126. "and $p0, $p0, $p1\n\t"
  127. "mtsr $p0, $mr8\n\t"
  128. "isb\n\t"
  129. );
  130. }
  131. int icache_status(void)
  132. {
  133. int ret;
  134. __asm__ __volatile__ (
  135. "mfsr $p0, $mr8\n\t"
  136. "andi %0, $p0, 0x01\n\t"
  137. : "=r" (ret)
  138. :
  139. : "memory"
  140. );
  141. return ret;
  142. }
  143. void dcache_enable(void)
  144. {
  145. __asm__ __volatile__ (
  146. "mfsr $p0, $mr8\n\t"
  147. "ori $p0, $p0, 0x02\n\t"
  148. "mtsr $p0, $mr8\n\t"
  149. "isb\n\t"
  150. );
  151. }
  152. void dcache_disable(void)
  153. {
  154. __asm__ __volatile__ (
  155. "mfsr $p0, $mr8\n\t"
  156. "li $p1, ~0x02\n\t"
  157. "and $p0, $p0, $p1\n\t"
  158. "mtsr $p0, $mr8\n\t"
  159. "isb\n\t"
  160. );
  161. }
  162. int dcache_status(void)
  163. {
  164. int ret;
  165. __asm__ __volatile__ (
  166. "mfsr $p0, $mr8\n\t"
  167. "andi %0, $p0, 0x02\n\t"
  168. : "=r" (ret)
  169. :
  170. : "memory"
  171. );
  172. return ret;
  173. }