cache.c 1.2 KB

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