cache.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * (C) Copyright 2011
  3. * Ilya Yanok, EmCraft Systems
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc.
  21. */
  22. #include <linux/types.h>
  23. #include <common.h>
  24. #ifndef CONFIG_SYS_DCACHE_OFF
  25. #ifndef CONFIG_SYS_CACHELINE_SIZE
  26. #define CONFIG_SYS_CACHELINE_SIZE 32
  27. #endif
  28. void invalidate_dcache_all(void)
  29. {
  30. asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
  31. }
  32. void flush_dcache_all(void)
  33. {
  34. asm volatile(
  35. "0:"
  36. "mrc p15, 0, r15, c7, c14, 3\n"
  37. "bne 0b\n"
  38. "mcr p15, 0, %0, c7, c10, 4\n"
  39. : : "r"(0) : "memory"
  40. );
  41. }
  42. static int check_cache_range(unsigned long start, unsigned long stop)
  43. {
  44. int ok = 1;
  45. if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
  46. ok = 0;
  47. if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
  48. ok = 0;
  49. if (!ok)
  50. debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
  51. start, stop);
  52. return ok;
  53. }
  54. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  55. {
  56. if (!check_cache_range(start, stop))
  57. return;
  58. while (start < stop) {
  59. asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
  60. start += CONFIG_SYS_CACHELINE_SIZE;
  61. }
  62. }
  63. void flush_dcache_range(unsigned long start, unsigned long stop)
  64. {
  65. if (!check_cache_range(start, stop))
  66. return;
  67. while (start < stop) {
  68. asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
  69. start += CONFIG_SYS_CACHELINE_SIZE;
  70. }
  71. asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
  72. }
  73. void flush_cache(unsigned long start, unsigned long size)
  74. {
  75. flush_dcache_range(start, start + size);
  76. }
  77. #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
  78. void invalidate_dcache_all(void)
  79. {
  80. }
  81. void flush_dcache_all(void)
  82. {
  83. }
  84. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  85. {
  86. }
  87. void flush_dcache_range(unsigned long start, unsigned long stop)
  88. {
  89. }
  90. void flush_cache(unsigned long start, unsigned long size)
  91. {
  92. }
  93. #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
  94. /*
  95. * Stub implementations for l2 cache operations
  96. */
  97. void __l2_cache_disable(void) {}
  98. void l2_cache_disable(void)
  99. __attribute__((weak, alias("__l2_cache_disable")));