cache.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  43. /*
  44. * Reserve one MMU section worth of address space below the malloc() area that
  45. * will be mapped uncached.
  46. */
  47. static unsigned long noncached_start;
  48. static unsigned long noncached_end;
  49. static unsigned long noncached_next;
  50. void noncached_init(void)
  51. {
  52. phys_addr_t start, end;
  53. size_t size;
  54. end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
  55. size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
  56. start = end - size;
  57. debug("mapping memory %pa-%pa non-cached\n", &start, &end);
  58. noncached_start = start;
  59. noncached_end = end;
  60. noncached_next = start;
  61. #ifndef CONFIG_SYS_DCACHE_OFF
  62. mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
  63. #endif
  64. }
  65. phys_addr_t noncached_alloc(size_t size, size_t align)
  66. {
  67. phys_addr_t next = ALIGN(noncached_next, align);
  68. if (next >= noncached_end || (noncached_end - next) < size)
  69. return 0;
  70. debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
  71. noncached_next = next + size;
  72. return next;
  73. }
  74. #endif /* CONFIG_SYS_NONCACHED_MEMORY */
  75. #if defined(CONFIG_SYS_THUMB_BUILD)
  76. void invalidate_l2_cache(void)
  77. {
  78. unsigned int val = 0;
  79. asm volatile("mcr p15, 1, %0, c15, c11, 0 @ invl l2 cache"
  80. : : "r" (val) : "cc");
  81. isb();
  82. }
  83. #endif