cache.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2011
  4. * Ilya Yanok, EmCraft Systems
  5. */
  6. #include <cpu_func.h>
  7. #include <linux/types.h>
  8. #include <common.h>
  9. #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  10. void invalidate_dcache_all(void)
  11. {
  12. asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
  13. }
  14. void flush_dcache_all(void)
  15. {
  16. asm volatile(
  17. "0:"
  18. "mrc p15, 0, r15, c7, c14, 3\n"
  19. "bne 0b\n"
  20. "mcr p15, 0, %0, c7, c10, 4\n"
  21. : : "r"(0) : "memory"
  22. );
  23. }
  24. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  25. {
  26. if (!check_cache_range(start, stop))
  27. return;
  28. while (start < stop) {
  29. asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
  30. start += CONFIG_SYS_CACHELINE_SIZE;
  31. }
  32. }
  33. void flush_dcache_range(unsigned long start, unsigned long stop)
  34. {
  35. if (!check_cache_range(start, stop))
  36. return;
  37. while (start < stop) {
  38. asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
  39. start += CONFIG_SYS_CACHELINE_SIZE;
  40. }
  41. asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
  42. }
  43. #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
  44. void invalidate_dcache_all(void)
  45. {
  46. }
  47. void flush_dcache_all(void)
  48. {
  49. }
  50. #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
  51. /*
  52. * Stub implementations for l2 cache operations
  53. */
  54. __weak void l2_cache_disable(void) {}
  55. #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
  56. __weak void invalidate_l2_cache(void) {}
  57. #endif
  58. #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
  59. /* Invalidate entire I-cache and branch predictor array */
  60. void invalidate_icache_all(void)
  61. {
  62. unsigned long i = 0;
  63. asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
  64. }
  65. #else
  66. void invalidate_icache_all(void) {}
  67. #endif
  68. void enable_caches(void)
  69. {
  70. #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
  71. icache_enable();
  72. #endif
  73. #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
  74. dcache_enable();
  75. #endif
  76. }