cache.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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