cpu.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. disable_interrupts();
  46. #ifdef CONFIG_MMU
  47. /* turn off I/D-cache */
  48. icache_disable();
  49. dcache_disable();
  50. /* flush I/D-cache */
  51. invalidate_icac();
  52. invalidate_dcac();
  53. #endif
  54. return 0;
  55. }
  56. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  57. {
  58. disable_interrupts();
  59. /*
  60. * reset to the base addr of andesboot.
  61. * currently no ROM loader at addr 0.
  62. * do not use reset_cpu(0);
  63. */
  64. #ifdef CONFIG_FTWDT010_WATCHDOG
  65. /*
  66. * workaround: if we use CONFIG_HW_WATCHDOG with ftwdt010, will lead
  67. * automatic hardware reset when booting Linux.
  68. * Please do not use CONFIG_HW_WATCHDOG and WATCHDOG_RESET() here.
  69. */
  70. ftwdt010_wdt_reset();
  71. #endif /* CONFIG_FTWDT010_WATCHDOG */
  72. hang();
  73. /*NOTREACHED*/
  74. }
  75. static inline unsigned long CACHE_LINE_SIZE(enum cache_t cache)
  76. {
  77. if (cache == ICACHE)
  78. return 8 << (((GET_ICM_CFG() & ICM_CFG_MSK_ISZ) \
  79. >> ICM_CFG_OFF_ISZ) - 1);
  80. else
  81. return 8 << (((GET_DCM_CFG() & DCM_CFG_MSK_DSZ) \
  82. >> DCM_CFG_OFF_DSZ) - 1);
  83. }
  84. void dcache_flush_range(unsigned long start, unsigned long end)
  85. {
  86. unsigned long line_size;
  87. line_size = CACHE_LINE_SIZE(DCACHE);
  88. while (end > start) {
  89. __asm__ volatile ("\n\tcctl %0, L1D_VA_WB" : : "r"(start));
  90. __asm__ volatile ("\n\tcctl %0, L1D_VA_INVAL" : : "r"(start));
  91. start += line_size;
  92. }
  93. }
  94. void icache_inval_range(unsigned long start, unsigned long end)
  95. {
  96. unsigned long line_size;
  97. line_size = CACHE_LINE_SIZE(ICACHE);
  98. while (end > start) {
  99. __asm__ volatile ("\n\tcctl %0, L1I_VA_INVAL" : : "r"(start));
  100. start += line_size;
  101. }
  102. }
  103. void flush_cache(unsigned long addr, unsigned long size)
  104. {
  105. dcache_flush_range(addr, addr + size);
  106. icache_inval_range(addr, addr + size);
  107. }
  108. void icache_enable(void)
  109. {
  110. __asm__ __volatile__ (
  111. "mfsr $p0, $mr8\n\t"
  112. "ori $p0, $p0, 0x01\n\t"
  113. "mtsr $p0, $mr8\n\t"
  114. "isb\n\t"
  115. );
  116. }
  117. void icache_disable(void)
  118. {
  119. __asm__ __volatile__ (
  120. "mfsr $p0, $mr8\n\t"
  121. "li $p1, ~0x01\n\t"
  122. "and $p0, $p0, $p1\n\t"
  123. "mtsr $p0, $mr8\n\t"
  124. "isb\n\t"
  125. );
  126. }
  127. int icache_status(void)
  128. {
  129. int ret;
  130. __asm__ __volatile__ (
  131. "mfsr $p0, $mr8\n\t"
  132. "andi %0, $p0, 0x01\n\t"
  133. : "=r" (ret)
  134. :
  135. : "memory"
  136. );
  137. return ret;
  138. }
  139. void dcache_enable(void)
  140. {
  141. __asm__ __volatile__ (
  142. "mfsr $p0, $mr8\n\t"
  143. "ori $p0, $p0, 0x02\n\t"
  144. "mtsr $p0, $mr8\n\t"
  145. "isb\n\t"
  146. );
  147. }
  148. void dcache_disable(void)
  149. {
  150. __asm__ __volatile__ (
  151. "mfsr $p0, $mr8\n\t"
  152. "li $p1, ~0x02\n\t"
  153. "and $p0, $p0, $p1\n\t"
  154. "mtsr $p0, $mr8\n\t"
  155. "isb\n\t"
  156. );
  157. }
  158. int dcache_status(void)
  159. {
  160. int ret;
  161. __asm__ __volatile__ (
  162. "mfsr $p0, $mr8\n\t"
  163. "andi %0, $p0, 0x02\n\t"
  164. : "=r" (ret)
  165. :
  166. : "memory"
  167. );
  168. return ret;
  169. }