cache.c 1.8 KB

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