cache.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef CONFIG_SYS_CACHELINE_SIZE
  11. #define CONFIG_SYS_CACHELINE_SIZE 32
  12. #endif
  13. void invalidate_dcache_all(void)
  14. {
  15. asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
  16. }
  17. void flush_dcache_all(void)
  18. {
  19. asm volatile(
  20. "0:"
  21. "mrc p15, 0, r15, c7, c14, 3\n"
  22. "bne 0b\n"
  23. "mcr p15, 0, %0, c7, c10, 4\n"
  24. : : "r"(0) : "memory"
  25. );
  26. }
  27. static int check_cache_range(unsigned long start, unsigned long stop)
  28. {
  29. int ok = 1;
  30. if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
  31. ok = 0;
  32. if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
  33. ok = 0;
  34. if (!ok)
  35. debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
  36. start, stop);
  37. return ok;
  38. }
  39. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  40. {
  41. if (!check_cache_range(start, stop))
  42. return;
  43. while (start < stop) {
  44. asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
  45. start += CONFIG_SYS_CACHELINE_SIZE;
  46. }
  47. }
  48. void flush_dcache_range(unsigned long start, unsigned long stop)
  49. {
  50. if (!check_cache_range(start, stop))
  51. return;
  52. while (start < stop) {
  53. asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
  54. start += CONFIG_SYS_CACHELINE_SIZE;
  55. }
  56. asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
  57. }
  58. void flush_cache(unsigned long start, unsigned long size)
  59. {
  60. flush_dcache_range(start, start + size);
  61. }
  62. #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
  63. void invalidate_dcache_all(void)
  64. {
  65. }
  66. void flush_dcache_all(void)
  67. {
  68. }
  69. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  70. {
  71. }
  72. void flush_dcache_range(unsigned long start, unsigned long stop)
  73. {
  74. }
  75. void flush_cache(unsigned long start, unsigned long size)
  76. {
  77. }
  78. #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
  79. /*
  80. * Stub implementations for l2 cache operations
  81. */
  82. __weak void l2_cache_disable(void) {}