cache.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * (C) Copyright 2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /* for now: just dummy functions to satisfy the linker */
  8. #include <common.h>
  9. #include <malloc.h>
  10. /*
  11. * Flush range from all levels of d-cache/unified-cache.
  12. * Affects the range [start, start + size - 1].
  13. */
  14. __weak void flush_cache(unsigned long start, unsigned long size)
  15. {
  16. flush_dcache_range(start, start + size);
  17. }
  18. /*
  19. * Default implementation:
  20. * do a range flush for the entire range
  21. */
  22. __weak void flush_dcache_all(void)
  23. {
  24. flush_cache(0, ~0);
  25. }
  26. /*
  27. * Default implementation of enable_caches()
  28. * Real implementation should be in platform code
  29. */
  30. __weak void enable_caches(void)
  31. {
  32. puts("WARNING: Caches not enabled\n");
  33. }
  34. __weak void invalidate_dcache_range(unsigned long start, unsigned long stop)
  35. {
  36. /* An empty stub, real implementation should be in platform code */
  37. }
  38. __weak void flush_dcache_range(unsigned long start, unsigned long stop)
  39. {
  40. /* An empty stub, real implementation should be in platform code */
  41. }
  42. 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. warn_non_spl("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
  51. start, stop);
  52. }
  53. return ok;
  54. }
  55. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  56. /*
  57. * Reserve one MMU section worth of address space below the malloc() area that
  58. * will be mapped uncached.
  59. */
  60. static unsigned long noncached_start;
  61. static unsigned long noncached_end;
  62. static unsigned long noncached_next;
  63. void noncached_init(void)
  64. {
  65. phys_addr_t start, end;
  66. size_t size;
  67. end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
  68. size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
  69. start = end - size;
  70. debug("mapping memory %pa-%pa non-cached\n", &start, &end);
  71. noncached_start = start;
  72. noncached_end = end;
  73. noncached_next = start;
  74. #ifndef CONFIG_SYS_DCACHE_OFF
  75. mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
  76. #endif
  77. }
  78. phys_addr_t noncached_alloc(size_t size, size_t align)
  79. {
  80. phys_addr_t next = ALIGN(noncached_next, align);
  81. if (next >= noncached_end || (noncached_end - next) < size)
  82. return 0;
  83. debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
  84. noncached_next = next + size;
  85. return next;
  86. }
  87. #endif /* CONFIG_SYS_NONCACHED_MEMORY */
  88. #if defined(CONFIG_SYS_THUMB_BUILD)
  89. void invalidate_l2_cache(void)
  90. {
  91. unsigned int val = 0;
  92. asm volatile("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache"
  93. : : "r" (val) : "cc");
  94. isb();
  95. }
  96. #endif