cache.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2016 Vasily Khoruzhick <anarsoul@gmail.com>
  4. */
  5. #include <cpu_func.h>
  6. #include <asm/cache.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. /* Flush/Invalidate I cache */
  13. asm volatile("mcr p15, 0, %0, c7, c5, 0\n" : : "r"(0));
  14. /* Flush/Invalidate D cache */
  15. asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
  16. }
  17. void flush_dcache_all(void)
  18. {
  19. return invalidate_dcache_all();
  20. }
  21. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  22. {
  23. start &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
  24. stop &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
  25. while (start <= stop) {
  26. asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
  27. start += CONFIG_SYS_CACHELINE_SIZE;
  28. }
  29. }
  30. void flush_dcache_range(unsigned long start, unsigned long stop)
  31. {
  32. return invalidate_dcache_range(start, stop);
  33. }
  34. #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
  35. void invalidate_dcache_all(void)
  36. {
  37. }
  38. void flush_dcache_all(void)
  39. {
  40. }
  41. #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
  42. /*
  43. * Stub implementations for l2 cache operations
  44. */
  45. __weak void l2_cache_disable(void) {}
  46. #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
  47. __weak void invalidate_l2_cache(void) {}
  48. #endif