cache.c 1.7 KB

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