mem_cache.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_FRAMEWORK_INCLUDE_MEMORY_MEM_CACHE_H_
  7. #define ZEPHYR_FRAMEWORK_INCLUDE_MEMORY_MEM_CACHE_H_
  8. #include <stdint.h>
  9. #include <stdbool.h>
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief Invalidate memory dcache
  15. *
  16. * @note This function is asynchronous. Call mem_dcache_sync() to synchronize.
  17. *
  18. * @param addr memory base address
  19. * @param length memory length
  20. *
  21. * @retval true if ops is asynchronized else false
  22. */
  23. bool mem_dcache_invalidate(const void *addr, uint32_t length);
  24. /**
  25. * @brief Invalidate all memory dcache
  26. *
  27. * @note This function is asynchronous. Call mem_dcache_sync() to synchronize.
  28. *
  29. * @retval true if ops is asynchronized else false
  30. */
  31. bool mem_dcache_invalidate_all(void);
  32. /**
  33. * @brief Clean memory dcache
  34. *
  35. * If the addr is uncache or write through memory, it will flush the write buffer.
  36. *
  37. * @note This function is asynchronous. Call mem_dcache_sync() to synchronize.
  38. *
  39. * @param addr memory base address
  40. * @param length memory length
  41. *
  42. * @retval true if ops is asynchronized else false
  43. */
  44. bool mem_dcache_clean(const void *addr, uint32_t length);
  45. /**
  46. * @brief Clean all memory dcache and the write buffer
  47. *
  48. * @note This function is asynchronous. Call mem_dcache_sync() to synchronize.
  49. *
  50. * @retval true if ops is asynchronized else false
  51. */
  52. bool mem_dcache_clean_all(void);
  53. /**
  54. * @brief Flush (clean, then invalidate) memory dcache and the write buffer
  55. *
  56. * @note This function is asynchronous. Call mem_dcache_sync() to synchronize.
  57. *
  58. * @param addr memory base address
  59. * @param length memory length
  60. *
  61. * @retval true if ops is asynchronized else false
  62. */
  63. bool mem_dcache_flush(const void *addr, uint32_t length);
  64. /**
  65. * @brief Flush (clean, then invalidate) all memory dcache
  66. *
  67. * @note This function is asynchronous. Call mem_dcache_sync() to synchronize.
  68. *
  69. * @retval true if ops is asynchronized else false
  70. */
  71. bool mem_dcache_flush_all(void);
  72. /**
  73. * @brief Clean the memory write buffer
  74. *
  75. * @retval true if ops is asynchronized else false
  76. */
  77. bool mem_writebuf_clean(const void *addr, uint32_t length);
  78. /**
  79. * @brief Clean all memory write buffer
  80. *
  81. * @param addr memory base address
  82. * @param length memory length
  83. *
  84. * @retval true if ops is asynchronized else false
  85. */
  86. bool mem_writebuf_clean_all(void);
  87. /**
  88. * @brief Synchronize the dcache ops, that is, wait until all the dcache ops finished
  89. *
  90. * @retval N/A
  91. */
  92. void mem_dcache_sync(void);
  93. /**
  94. * @brief translate the cache address to uncache address
  95. *
  96. * @param addr memory cache address
  97. *
  98. * @retval the uncache address
  99. */
  100. void * mem_addr_to_uncache(const void * addr);
  101. /**
  102. * @brief translate the memory address to write-back and cache write-allocate address
  103. *
  104. * @retval the write allocate cache address
  105. */
  106. void * mem_addr_to_cache(const void * addr);
  107. /**
  108. * @brief translate the memory address to write-through and cache read-allocate address
  109. *
  110. * @retval the write through cache address
  111. */
  112. void * mem_addr_to_cache_wt(const void * addr);
  113. /**
  114. * @brief Query whether the memory is cacheable
  115. *
  116. * @param addr memory base address
  117. *
  118. * @retval query result
  119. */
  120. bool mem_is_cacheable(const void *addr);
  121. /**
  122. * @brief Query whether the memory is bufferable
  123. *
  124. * @param addr memory base address
  125. *
  126. * @retval query result
  127. */
  128. bool mem_is_bufferable(const void *addr);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* ZEPHYR_FRAMEWORK_INCLUDE_MEMORY_MEM_CACHE_H_ */