cache.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /****************************************************************************
  2. * include/nuttx/cache.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_NUTTX_CACHE_H
  21. #define __INCLUDE_NUTTX_CACHE_H
  22. #ifndef __ASSEMBLY__
  23. /****************************************************************************
  24. * Included Files
  25. ****************************************************************************/
  26. #include <nuttx/config.h>
  27. #include <stdint.h>
  28. #include <sys/types.h>
  29. /****************************************************************************
  30. * Pre-processor Definitions
  31. ****************************************************************************/
  32. #ifdef __cplusplus
  33. #define EXTERN extern "C"
  34. extern "C"
  35. {
  36. #else
  37. #define EXTERN extern
  38. #endif
  39. /****************************************************************************
  40. * Public Function Prototypes
  41. ****************************************************************************/
  42. /****************************************************************************
  43. * Name: up_enable_icache
  44. *
  45. * Description:
  46. * Enable the I-Cache
  47. *
  48. * Input Parameters:
  49. * None
  50. *
  51. * Returned Value:
  52. * None
  53. *
  54. * Caution:
  55. * The writable global variables aren't initialized yet.
  56. *
  57. ****************************************************************************/
  58. #ifdef CONFIG_ARCH_ICACHE
  59. void up_enable_icache(void);
  60. #else
  61. # define up_enable_icache()
  62. #endif
  63. /****************************************************************************
  64. * Name: up_disable_icache
  65. *
  66. * Description:
  67. * Disable the I-Cache
  68. *
  69. * Input Parameters:
  70. * None
  71. *
  72. * Returned Value:
  73. * None
  74. *
  75. ****************************************************************************/
  76. #ifdef CONFIG_ARCH_ICACHE
  77. void up_disable_icache(void);
  78. #else
  79. # define up_disable_icache()
  80. #endif
  81. /****************************************************************************
  82. * Name: up_invalidate_icache
  83. *
  84. * Description:
  85. * Invalidate the instruction cache within the specified region.
  86. *
  87. * Input Parameters:
  88. * start - virtual start address of region
  89. * end - virtual end address of region + 1
  90. *
  91. * Returned Value:
  92. * None
  93. *
  94. ****************************************************************************/
  95. #ifdef CONFIG_ARCH_ICACHE
  96. void up_invalidate_icache(uintptr_t start, uintptr_t end);
  97. #else
  98. # define up_invalidate_icache(start, end)
  99. #endif
  100. /****************************************************************************
  101. * Name: up_invalidate_icache_all
  102. *
  103. * Description:
  104. * Invalidate the entire contents of I cache.
  105. *
  106. * Input Parameters:
  107. * None
  108. *
  109. * Returned Value:
  110. * None
  111. *
  112. ****************************************************************************/
  113. #ifdef CONFIG_ARCH_ICACHE
  114. void up_invalidate_icache_all(void);
  115. #else
  116. # define up_invalidate_icache_all()
  117. #endif
  118. /****************************************************************************
  119. * Name: up_enable_dcache
  120. *
  121. * Description:
  122. * Enable the D-Cache
  123. *
  124. * Input Parameters:
  125. * None
  126. *
  127. * Returned Value:
  128. * None
  129. *
  130. * Caution:
  131. * The writable global variables aren't initialized yet.
  132. *
  133. ****************************************************************************/
  134. #ifdef CONFIG_ARCH_DCACHE
  135. void up_enable_dcache(void);
  136. #else
  137. # define up_enable_dcache()
  138. #endif
  139. /****************************************************************************
  140. * Name: up_disable_dcache
  141. *
  142. * Description:
  143. * Disable the D-Cache
  144. *
  145. * Input Parameters:
  146. * None
  147. *
  148. * Returned Value:
  149. * None
  150. *
  151. ****************************************************************************/
  152. #ifdef CONFIG_ARCH_DCACHE
  153. void up_disable_dcache(void);
  154. #else
  155. # define up_disable_dcache()
  156. #endif
  157. /****************************************************************************
  158. * Name: up_invalidate_dcache
  159. *
  160. * Description:
  161. * Invalidate the data cache within the specified region; we will be
  162. * performing a DMA operation in this region and we want to purge old data
  163. * in the cache.
  164. *
  165. * Input Parameters:
  166. * start - virtual start address of region
  167. * end - virtual end address of region + 1
  168. *
  169. * Returned Value:
  170. * None
  171. *
  172. ****************************************************************************/
  173. #ifdef CONFIG_ARCH_DCACHE
  174. void up_invalidate_dcache(uintptr_t start, uintptr_t end);
  175. #else
  176. # define up_invalidate_dcache(start, end)
  177. #endif
  178. /****************************************************************************
  179. * Name: up_invalidate_dcache_all
  180. *
  181. * Description:
  182. * Invalidate the entire contents of D cache.
  183. *
  184. * Input Parameters:
  185. * None
  186. *
  187. * Returned Value:
  188. * None
  189. *
  190. ****************************************************************************/
  191. #ifdef CONFIG_ARCH_DCACHE
  192. void up_invalidate_dcache_all(void);
  193. #else
  194. # define up_invalidate_dcache_all()
  195. #endif
  196. /****************************************************************************
  197. * Name: up_clean_dcache
  198. *
  199. * Description:
  200. * Clean the data cache within the specified region by flushing the
  201. * contents of the data cache to memory.
  202. *
  203. * Input Parameters:
  204. * start - virtual start address of region
  205. * end - virtual end address of region + 1
  206. *
  207. * Returned Value:
  208. * None
  209. *
  210. ****************************************************************************/
  211. #ifdef CONFIG_ARCH_DCACHE
  212. void up_clean_dcache(uintptr_t start, uintptr_t end);
  213. #else
  214. # define up_clean_dcache(start, end)
  215. #endif
  216. /****************************************************************************
  217. * Name: up_clean_dcache_all
  218. *
  219. * Description:
  220. * Clean the entire data cache within the specified region by flushing the
  221. * contents of the data cache to memory.
  222. *
  223. * Input Parameters:
  224. * None
  225. *
  226. * Returned Value:
  227. * None
  228. *
  229. ****************************************************************************/
  230. #ifdef CONFIG_ARCH_DCACHE
  231. void up_clean_dcache_all(void);
  232. #else
  233. # define up_clean_dcache_all()
  234. #endif
  235. /****************************************************************************
  236. * Name: up_flush_dcache
  237. *
  238. * Description:
  239. * Flush the data cache within the specified region by cleaning and
  240. * invalidating the D cache.
  241. *
  242. * Input Parameters:
  243. * start - virtual start address of region
  244. * end - virtual end address of region + 1
  245. *
  246. * Returned Value:
  247. * None
  248. *
  249. ****************************************************************************/
  250. #ifdef CONFIG_ARCH_DCACHE
  251. void up_flush_dcache(uintptr_t start, uintptr_t end);
  252. #else
  253. # define up_flush_dcache(start, end)
  254. #endif
  255. /****************************************************************************
  256. * Name: up_flush_dcache_all
  257. *
  258. * Description:
  259. * Flush the entire data cache by cleaning and invalidating the D cache.
  260. *
  261. * Input Parameters:
  262. * None
  263. *
  264. * Returned Value:
  265. * None
  266. *
  267. ****************************************************************************/
  268. #ifdef CONFIG_ARCH_DCACHE
  269. void up_flush_dcache_all(void);
  270. #else
  271. # define up_flush_dcache_all()
  272. #endif
  273. /****************************************************************************
  274. * Name: up_coherent_dcache
  275. *
  276. * Description:
  277. * Ensure that the I and D caches are coherent within specified region
  278. * by cleaning the D cache (i.e., flushing the D cache contents to memory
  279. * and invalidating the I cache. This is typically used when code has been
  280. * written to a memory region, and will be executed.
  281. *
  282. * Input Parameters:
  283. * addr - virtual start address of region
  284. * len - Size of the address region in bytes
  285. *
  286. * Returned Value:
  287. * None
  288. *
  289. ****************************************************************************/
  290. #ifdef CONFIG_ARCH_ICACHE
  291. void up_coherent_dcache(uintptr_t addr, size_t len);
  292. #else
  293. # define up_coherent_dcache(addr, len)
  294. #endif
  295. #undef EXTERN
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif /* __ASSEMBLY__ */
  300. #endif /* __INCLUDE_NUTTX_CACHE_H */