cache.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. __weak void flush_cache(unsigned long start, unsigned long size)
  11. {
  12. #if defined(CONFIG_CPU_ARM1136)
  13. #if !defined(CONFIG_SYS_ICACHE_OFF)
  14. asm("mcr p15, 0, r1, c7, c5, 0"); /* invalidate I cache */
  15. #endif
  16. #if !defined(CONFIG_SYS_DCACHE_OFF)
  17. asm("mcr p15, 0, r1, c7, c14, 0"); /* Clean+invalidate D cache */
  18. #endif
  19. #endif /* CONFIG_CPU_ARM1136 */
  20. #ifdef CONFIG_CPU_ARM926EJS
  21. #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
  22. /* test and clean, page 2-23 of arm926ejs manual */
  23. asm("0: mrc p15, 0, r15, c7, c10, 3\n\t" "bne 0b\n" : : : "memory");
  24. /* disable write buffer as well (page 2-22) */
  25. asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
  26. #endif
  27. #endif /* CONFIG_CPU_ARM926EJS */
  28. return;
  29. }
  30. /*
  31. * Default implementation:
  32. * do a range flush for the entire range
  33. */
  34. __weak void flush_dcache_all(void)
  35. {
  36. flush_cache(0, ~0);
  37. }
  38. /*
  39. * Default implementation of enable_caches()
  40. * Real implementation should be in platform code
  41. */
  42. __weak void enable_caches(void)
  43. {
  44. puts("WARNING: Caches not enabled\n");
  45. }
  46. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  47. /*
  48. * Reserve one MMU section worth of address space below the malloc() area that
  49. * will be mapped uncached.
  50. */
  51. static unsigned long noncached_start;
  52. static unsigned long noncached_end;
  53. static unsigned long noncached_next;
  54. void noncached_init(void)
  55. {
  56. phys_addr_t start, end;
  57. size_t size;
  58. end = ALIGN(mem_malloc_start, MMU_SECTION_SIZE) - MMU_SECTION_SIZE;
  59. size = ALIGN(CONFIG_SYS_NONCACHED_MEMORY, MMU_SECTION_SIZE);
  60. start = end - size;
  61. debug("mapping memory %pa-%pa non-cached\n", &start, &end);
  62. noncached_start = start;
  63. noncached_end = end;
  64. noncached_next = start;
  65. #ifndef CONFIG_SYS_DCACHE_OFF
  66. mmu_set_region_dcache_behaviour(noncached_start, size, DCACHE_OFF);
  67. #endif
  68. }
  69. phys_addr_t noncached_alloc(size_t size, size_t align)
  70. {
  71. phys_addr_t next = ALIGN(noncached_next, align);
  72. if (next >= noncached_end || (noncached_end - next) < size)
  73. return 0;
  74. debug("allocated %zu bytes of uncached memory @%pa\n", size, &next);
  75. noncached_next = next + size;
  76. return next;
  77. }
  78. #endif /* CONFIG_SYS_NONCACHED_MEMORY */