cpu.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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, <garyj@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 <asm/system.h>
  35. static void cache_flush(void);
  36. int cleanup_before_linux (void)
  37. {
  38. /*
  39. * this function is called just before we call linux
  40. * it prepares the processor for linux
  41. *
  42. * we turn off caches etc ...
  43. */
  44. disable_interrupts ();
  45. #ifdef CONFIG_LCD
  46. {
  47. extern void lcd_disable(void);
  48. extern void lcd_panel_disable(void);
  49. lcd_disable(); /* proper disable of lcd & panel */
  50. lcd_panel_disable();
  51. }
  52. #endif
  53. /* turn off I/D-cache */
  54. icache_disable();
  55. dcache_disable();
  56. /* flush I/D-cache */
  57. cache_flush();
  58. return 0;
  59. }
  60. static void cache_flush(void)
  61. {
  62. unsigned long i = 0;
  63. /* clean entire data cache */
  64. asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
  65. /* invalidate both caches and flush btb */
  66. asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
  67. /* mem barrier to sync things */
  68. asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
  69. }
  70. #ifndef CONFIG_SYS_DCACHE_OFF
  71. #ifndef CONFIG_SYS_CACHELINE_SIZE
  72. #define CONFIG_SYS_CACHELINE_SIZE 32
  73. #endif
  74. void invalidate_dcache_all(void)
  75. {
  76. asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
  77. }
  78. void flush_dcache_all(void)
  79. {
  80. asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
  81. asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
  82. }
  83. static int check_cache_range(unsigned long start, unsigned long stop)
  84. {
  85. int ok = 1;
  86. if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
  87. ok = 0;
  88. if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
  89. ok = 0;
  90. if (!ok)
  91. debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
  92. start, stop);
  93. return ok;
  94. }
  95. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  96. {
  97. if (!check_cache_range(start, stop))
  98. return;
  99. while (start < stop) {
  100. asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
  101. start += CONFIG_SYS_CACHELINE_SIZE;
  102. }
  103. }
  104. void flush_dcache_range(unsigned long start, unsigned long stop)
  105. {
  106. if (!check_cache_range(start, stop))
  107. return;
  108. while (start < stop) {
  109. asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
  110. start += CONFIG_SYS_CACHELINE_SIZE;
  111. }
  112. asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
  113. }
  114. void flush_cache(unsigned long start, unsigned long size)
  115. {
  116. flush_dcache_range(start, start + size);
  117. }
  118. void enable_caches(void)
  119. {
  120. #ifndef CONFIG_SYS_ICACHE_OFF
  121. icache_enable();
  122. #endif
  123. #ifndef CONFIG_SYS_DCACHE_OFF
  124. dcache_enable();
  125. #endif
  126. }
  127. #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
  128. void invalidate_dcache_all(void)
  129. {
  130. }
  131. void flush_dcache_all(void)
  132. {
  133. }
  134. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  135. {
  136. }
  137. void flush_dcache_range(unsigned long start, unsigned long stop)
  138. {
  139. }
  140. void flush_cache(unsigned long start, unsigned long size)
  141. {
  142. }
  143. #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */