cache.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * (C) Copyright 2011
  3. * Ilya Yanok, EmCraft Systems
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <linux/types.h>
  8. #include <common.h>
  9. #ifndef CONFIG_SYS_DCACHE_OFF
  10. void invalidate_dcache_all(void)
  11. {
  12. asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
  13. }
  14. void flush_dcache_all(void)
  15. {
  16. asm volatile(
  17. "0:"
  18. "mrc p15, 0, r15, c7, c14, 3\n"
  19. "bne 0b\n"
  20. "mcr p15, 0, %0, c7, c10, 4\n"
  21. : : "r"(0) : "memory"
  22. );
  23. }
  24. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  25. {
  26. if (!check_cache_range(start, stop))
  27. return;
  28. while (start < stop) {
  29. asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
  30. start += CONFIG_SYS_CACHELINE_SIZE;
  31. }
  32. }
  33. void flush_dcache_range(unsigned long start, unsigned long stop)
  34. {
  35. if (!check_cache_range(start, stop))
  36. return;
  37. while (start < stop) {
  38. asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
  39. start += CONFIG_SYS_CACHELINE_SIZE;
  40. }
  41. asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
  42. }
  43. #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
  44. void invalidate_dcache_all(void)
  45. {
  46. }
  47. void flush_dcache_all(void)
  48. {
  49. }
  50. #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
  51. /*
  52. * Stub implementations for l2 cache operations
  53. */
  54. __weak void l2_cache_disable(void) {}
  55. #if defined CONFIG_SYS_THUMB_BUILD
  56. __weak void invalidate_l2_cache(void) {}
  57. #endif