cache.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _ROM_CACHE_H_
  7. #define _ROM_CACHE_H_
  8. #include "esp_attr.h"
  9. #if __has_include("dport_access.h")
  10. #include "dport_access.h"
  11. #else
  12. #pragma message("For ESP32 with ECO version < 2, you need to use a DPORT workaround that stalls the other CPU")
  13. #define DPORT_STALL_OTHER_CPU_START()
  14. #define DPORT_STALL_OTHER_CPU_END()
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** \defgroup uart_apis, uart configuration and communication related apis
  20. * @brief uart apis
  21. */
  22. /** @addtogroup uart_apis
  23. * @{
  24. */
  25. /**
  26. * @brief Initialise cache mmu, mark all entries as invalid.
  27. * Please do not call this function in your SDK application.
  28. *
  29. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  30. *
  31. * @return None
  32. */
  33. void mmu_init(int cpu_no);
  34. /**
  35. * @brief Set Flash-Cache mmu mapping.
  36. * Please do not call this function in your SDK application.
  37. *
  38. * @param int cpu_no : CPU number, 0 for PRO cpu, 1 for APP cpu.
  39. *
  40. * @param int pod : process identifier. Range 0~7.
  41. *
  42. * @param unsigned int vaddr : virtual address in CPU address space.
  43. * Can be IRam0, IRam1, IRom0 and DRom0 memory address.
  44. * Should be aligned by psize.
  45. *
  46. * @param unsigned int paddr : physical address in Flash.
  47. * Should be aligned by psize.
  48. *
  49. * @param int psize : page size of flash, in kilobytes. Should be 64 here.
  50. *
  51. * @param int num : pages to be set.
  52. *
  53. * @return unsigned int: error status
  54. * 0 : mmu set success
  55. * 1 : vaddr or paddr is not aligned
  56. * 2 : pid error
  57. * 3 : psize error
  58. * 4 : mmu table to be written is out of range
  59. * 5 : vaddr is out of range
  60. */
  61. static inline __attribute__((always_inline)) unsigned int IRAM_ATTR cache_flash_mmu_set(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num)
  62. {
  63. extern unsigned int cache_flash_mmu_set_rom(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num);
  64. unsigned int ret;
  65. DPORT_STALL_OTHER_CPU_START();
  66. ret = cache_flash_mmu_set_rom(cpu_no, pid, vaddr, paddr, psize, num);
  67. DPORT_STALL_OTHER_CPU_END();
  68. return ret;
  69. }
  70. /**
  71. * @brief Set Ext-SRAM-Cache mmu mapping.
  72. * Please do not call this function in your SDK application.
  73. *
  74. * Note that this code lives in IRAM and has a bugfix in respect to the ROM version
  75. * of this function (which erroneously refused a vaddr > 2MiB
  76. *
  77. * @param int cpu_no : CPU number, 0 for PRO cpu, 1 for APP cpu.
  78. *
  79. * @param int pod : process identifier. Range 0~7.
  80. *
  81. * @param unsigned int vaddr : virtual address in CPU address space.
  82. * Can be IRam0, IRam1, IRom0 and DRom0 memory address.
  83. * Should be aligned by psize.
  84. *
  85. * @param unsigned int paddr : physical address in Ext-SRAM.
  86. * Should be aligned by psize.
  87. *
  88. * @param int psize : page size of flash, in kilobytes. Should be 32 here.
  89. *
  90. * @param int num : pages to be set.
  91. *
  92. * @return unsigned int: error status
  93. * 0 : mmu set success
  94. * 1 : vaddr or paddr is not aligned
  95. * 2 : pid error
  96. * 3 : psize error
  97. * 4 : mmu table to be written is out of range
  98. * 5 : vaddr is out of range
  99. */
  100. unsigned int IRAM_ATTR cache_sram_mmu_set(int cpu_no, int pid, unsigned int vaddr, unsigned int paddr, int psize, int num);
  101. /**
  102. * @brief Initialise cache access for the cpu.
  103. * Please do not call this function in your SDK application.
  104. *
  105. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  106. *
  107. * @return None
  108. */
  109. static inline __attribute__((always_inline)) void IRAM_ATTR Cache_Read_Init(int cpu_no)
  110. {
  111. extern void Cache_Read_Init_rom(int cpu_no);
  112. DPORT_STALL_OTHER_CPU_START();
  113. Cache_Read_Init_rom(cpu_no);
  114. DPORT_STALL_OTHER_CPU_END();
  115. }
  116. /**
  117. * @brief Flush the cache value for the cpu.
  118. * Please do not call this function in your SDK application.
  119. *
  120. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  121. *
  122. * @return None
  123. */
  124. static inline __attribute__((always_inline)) void IRAM_ATTR Cache_Flush(int cpu_no)
  125. {
  126. extern void Cache_Flush_rom(int cpu_no);
  127. DPORT_STALL_OTHER_CPU_START();
  128. Cache_Flush_rom(cpu_no);
  129. DPORT_STALL_OTHER_CPU_END();
  130. }
  131. /**
  132. * @brief Disable Cache access for the cpu.
  133. * Please do not call this function in your SDK application.
  134. *
  135. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  136. *
  137. * @return None
  138. */
  139. static inline __attribute__((always_inline)) void IRAM_ATTR Cache_Read_Disable(int cpu_no)
  140. {
  141. extern void Cache_Read_Disable_rom(int cpu_no);
  142. DPORT_STALL_OTHER_CPU_START();
  143. Cache_Read_Disable_rom(cpu_no);
  144. DPORT_STALL_OTHER_CPU_END();
  145. }
  146. /**
  147. * @brief Enable Cache access for the cpu.
  148. * Please do not call this function in your SDK application.
  149. *
  150. * @param int cpu_no : 0 for PRO cpu, 1 for APP cpu.
  151. *
  152. * @return None
  153. */
  154. static inline __attribute__((always_inline)) void IRAM_ATTR Cache_Read_Enable(int cpu_no)
  155. {
  156. extern void Cache_Read_Enable_rom(int cpu_no);
  157. DPORT_STALL_OTHER_CPU_START();
  158. Cache_Read_Enable_rom(cpu_no);
  159. DPORT_STALL_OTHER_CPU_END();
  160. }
  161. /**
  162. * @}
  163. */
  164. #ifdef __cplusplus
  165. }
  166. #endif
  167. #endif /* _ROM_CACHE_H_ */