core_feature_cache.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. /*
  2. * Copyright (c) 2019 Nuclei Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef __CORE_FEATURE_CACHE_H__
  19. #define __CORE_FEATURE_CACHE_H__
  20. /*!
  21. * @file core_feature_cache.h
  22. * @brief Cache feature API header file for Nuclei N/NX Core
  23. */
  24. /*
  25. * Cache Feature Configuration Macro:
  26. * 1. __ICACHE_PRESENT: Define whether I-Cache Unit is present or not.
  27. * * 0: Not present
  28. * * 1: Present
  29. * 2. __DCACHE_PRESENT: Define whether D-Cache Unit is present or not.
  30. * * 0: Not present
  31. * * 1: Present
  32. * 3. __CCM_PRESENT: Define whether Nuclei Cache Control and Maintainence(CCM) Unit is present or not.
  33. * * 0: Not present
  34. * * 1: Present
  35. */
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "core_feature_base.h"
  40. #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
  41. /* ########################## Cache functions #################################### */
  42. /**
  43. * \defgroup NMSIS_Core_Cache Cache Functions
  44. * \brief Functions that configure Instruction and Data Cache.
  45. * @{
  46. *
  47. * Nuclei provide Cache Control and Maintainence(CCM) for software to control and maintain
  48. * the internal L1 I/D Cache of the RISC-V Core, software can manage the cache flexibly to
  49. * meet the actual application scenarios.
  50. *
  51. * The CCM operations have 3 types: by single address, by all and flush pipeline.
  52. * The CCM operations are done via CSR registers, M/S/U mode has its own CSR registers to
  53. * do CCM operations. By default, CCM operations are not allowed in S/U mode, you can execute
  54. * \ref EnableSUCCM in M-Mode to enable it.
  55. *
  56. * * API names started with M<operations>, such as \ref MInvalICacheLine must be called in M-Mode only.
  57. * * API names started with S<operations>, such as \ref SInvalICacheLine should be called in S-Mode.
  58. * * API names started with U<operations>, such as \ref UInvalICacheLine should be called in U-Mode.
  59. *
  60. */
  61. /**
  62. * \brief Cache CCM Operation Fail Info
  63. */
  64. typedef enum CCM_OP_FINFO {
  65. CCM_OP_SUCCESS = 0x0, /*!< Lock Succeed */
  66. CCM_OP_EXCEED_ERR = 0x1, /*!< Exceed the the number of lockable ways(N-Way I/D-Cache, lockable is N-1) */
  67. CCM_OP_PERM_CHECK_ERR = 0x2, /*!< PMP/sPMP/Page-Table X(I-Cache)/R(D-Cache) permission check failed, or belong to Device/Non-Cacheable address range */
  68. CCM_OP_REFILL_BUS_ERR = 0x3, /*!< Refill has Bus Error */
  69. CCM_OP_ECC_ERR = 0x4 /*!< Deprecated, ECC Error, this error code is removed in later Nuclei CCM RTL design, please don't use it */
  70. } CCM_OP_FINFO_Type;
  71. /**
  72. * \brief Cache CCM Command Types
  73. */
  74. typedef enum CCM_CMD {
  75. CCM_DC_INVAL = 0x0, /*!< Unlock and invalidate D-Cache line specified by CSR CCM_XBEGINADDR */
  76. CCM_DC_WB = 0x1, /*!< Flush the specific D-Cache line specified by CSR CCM_XBEGINADDR */
  77. CCM_DC_WBINVAL = 0x2, /*!< Unlock, flush and invalidate the specific D-Cache line specified by CSR CCM_XBEGINADDR */
  78. CCM_DC_LOCK = 0x3, /*!< Lock the specific D-Cache line specified by CSR CCM_XBEGINADDR */
  79. CCM_DC_UNLOCK = 0x4, /*!< Unlock the specific D-Cache line specified by CSR CCM_XBEGINADDR */
  80. CCM_DC_WBINVAL_ALL = 0x6, /*!< Unlock and flush and invalidate all the valid and dirty D-Cache lines */
  81. CCM_DC_WB_ALL = 0x7, /*!< Flush all the valid and dirty D-Cache lines */
  82. CCM_DC_INVAL_ALL = 0x17, /*!< Unlock and invalidate all the D-Cache lines */
  83. CCM_IC_INVAL = 0x8, /*!< Unlock and invalidate I-Cache line specified by CSR CCM_XBEGINADDR */
  84. CCM_IC_LOCK = 0xb, /*!< Lock the specific I-Cache line specified by CSR CCM_XBEGINADDR */
  85. CCM_IC_UNLOCK = 0xc, /*!< Unlock the specific I-Cache line specified by CSR CCM_XBEGINADDR */
  86. CCM_IC_INVAL_ALL = 0xd /*!< Unlock and invalidate all the I-Cache lines */
  87. } CCM_CMD_Type;
  88. /**
  89. * \brief Cache Information Type
  90. */
  91. typedef struct CacheInfo {
  92. uint32_t linesize; /*!< Cache Line size in bytes */
  93. uint32_t ways; /*!< Cache ways */
  94. uint32_t setperway; /*!< Cache set per way */
  95. uint32_t size; /*!< Cache total size in bytes */
  96. } CacheInfo_Type;
  97. #if __riscv_xlen == 32
  98. #define CCM_SUEN_SUEN_Msk (0xFFFFFFFFUL) /*!< CSR CCM_SUEN: SUEN Mask */
  99. #else
  100. #define CCM_SUEN_SUEN_Msk (0xFFFFFFFFFFFFFFFFUL) /*!< CSR CCM_SUEN: SUEN Mask */
  101. #endif
  102. /**
  103. * \brief Enable CCM operation in Supervisor/User Mode
  104. * \details
  105. * This function enable CCM operation in Supervisor/User Mode.
  106. * If enabled, CCM operations in supervisor/user mode will
  107. * be allowed.
  108. * \remarks
  109. * - This function can be called in M-Mode only.
  110. * \sa
  111. * - \ref DisableSUCCM
  112. */
  113. __STATIC_FORCEINLINE void EnableSUCCM(void)
  114. {
  115. __RV_CSR_SET(CSR_CCM_SUEN, CCM_SUEN_SUEN_Msk);
  116. }
  117. /**
  118. * \brief Disable CCM operation in Supervisor/User Mode
  119. * \details
  120. * This function disable CCM operation in Supervisor/User Mode.
  121. * If not enabled, CCM operations in supervisor/user mode will
  122. * trigger a *illegal intruction* exception.
  123. * \remarks
  124. * - This function can be called in M-Mode only.
  125. * \sa
  126. * - \ref EnableSUCCM
  127. */
  128. __STATIC_FORCEINLINE void DisableSUCCM(void)
  129. {
  130. __RV_CSR_CLEAR(CSR_CCM_SUEN, CCM_SUEN_SUEN_Msk);
  131. }
  132. /**
  133. * \brief Flush pipeline after CCM operation
  134. * \details
  135. * This function is used to flush pipeline after CCM operations
  136. * on Cache, it will ensure latest instructions or data can be
  137. * seen by pipeline.
  138. * \remarks
  139. * - This function can be called in M/S/U-Mode only.
  140. */
  141. __STATIC_FORCEINLINE void FlushPipeCCM(void)
  142. {
  143. __RV_CSR_WRITE(CSR_CCM_FPIPE, 0x1);
  144. }
  145. /** @} */ /* End of Doxygen Group NMSIS_Core_Cache */
  146. #endif
  147. #if defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1)
  148. /**
  149. * \defgroup NMSIS_Core_ICache I-Cache Functions
  150. * \ingroup NMSIS_Core_Cache
  151. * \brief Functions that configure Instruction Cache.
  152. * @{
  153. */
  154. /**
  155. * \brief Check ICache Unit Present or Not
  156. * \details
  157. * This function check icache unit present or not via mcfg_info csr
  158. * \remarks
  159. * - This function might not work for some old nuclei processors
  160. * - Please make sure the version of your nuclei processor contain ICACHE bit in mcfg_info
  161. * \return 1 if present otherwise 0
  162. */
  163. __STATIC_INLINE int32_t ICachePresent(void)
  164. {
  165. if (__RV_CSR_READ(CSR_MCFG_INFO) & MCFG_INFO_ICACHE) {
  166. return 1;
  167. }
  168. return 0;
  169. }
  170. /**
  171. * \brief Enable ICache
  172. * \details
  173. * This function enable I-Cache
  174. * \remarks
  175. * - This function can be called in M-Mode only.
  176. * - This \ref CSR_MCACHE_CTL register control I Cache enable.
  177. * \sa
  178. * - \ref DisableICache
  179. */
  180. __STATIC_FORCEINLINE void EnableICache(void)
  181. {
  182. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_EN);
  183. }
  184. /**
  185. * \brief Disable ICache
  186. * \details
  187. * This function Disable I-Cache
  188. * \remarks
  189. * - This function can be called in M-Mode only.
  190. * - This \ref CSR_MCACHE_CTL register control I Cache enable.
  191. * \sa
  192. * - \ref EnableICache
  193. */
  194. __STATIC_FORCEINLINE void DisableICache(void)
  195. {
  196. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_EN);
  197. }
  198. /**
  199. * \brief Enable ICache ECC
  200. * \details
  201. * This function enable I-Cache ECC
  202. * \remarks
  203. * - This function can be called in M-Mode only.
  204. * - This \ref CSR_MCACHE_CTL register control I Cache ECC enable.
  205. * \sa
  206. * - \ref DisableICacheECC
  207. */
  208. __STATIC_FORCEINLINE void EnableICacheECC(void)
  209. {
  210. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN);
  211. }
  212. /**
  213. * \brief Disable ICache ECC
  214. * \details
  215. * This function disable I-Cache ECC
  216. * \remarks
  217. * - This function can be called in M-Mode only.
  218. * - This \ref CSR_MCACHE_CTL register control I Cache ECC enable.
  219. * \sa
  220. * - \ref EnableICacheECC
  221. */
  222. __STATIC_FORCEINLINE void DisableICacheECC(void)
  223. {
  224. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN);
  225. }
  226. #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
  227. /**
  228. * \brief Get I-Cache Information
  229. * \details
  230. * This function get I-Cache Information
  231. * \remarks
  232. * - This function can be called in M-Mode only.
  233. * - You can use this function in combination with cache lines operations
  234. * \sa
  235. * - \ref GetDCacheInfo
  236. */
  237. __STATIC_INLINE int32_t GetICacheInfo(CacheInfo_Type *info)
  238. {
  239. if (info == NULL) {
  240. return -1;
  241. }
  242. CSR_MICFGINFO_Type csr_ccfg;
  243. csr_ccfg.d = __RV_CSR_READ(CSR_MICFG_INFO);
  244. info->setperway = (1UL << csr_ccfg.b.set) << 3;
  245. info->ways = (1 + csr_ccfg.b.way);
  246. if (csr_ccfg.b.lsize == 0) {
  247. info->linesize = 0;
  248. } else {
  249. info->linesize = (1UL << (csr_ccfg.b.lsize - 1)) << 3;
  250. }
  251. info->size = info->setperway * info->ways * info->linesize;
  252. return 0;
  253. }
  254. /**
  255. * \brief Invalidate one I-Cache line specified by address in M-Mode
  256. * \details
  257. * This function unlock and invalidate one I-Cache line specified
  258. * by the address.
  259. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  260. * \remarks
  261. * This function must be executed in M-Mode only.
  262. * \param [in] addr start address to be invalidated
  263. */
  264. __STATIC_INLINE void MInvalICacheLine(unsigned long addr)
  265. {
  266. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  267. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
  268. FlushPipeCCM();
  269. __RWMB();
  270. }
  271. /**
  272. * \brief Invalidate several I-Cache lines specified by address in M-Mode
  273. * \details
  274. * This function unlock and invalidate several I-Cache lines specified
  275. * by the address and line count.
  276. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  277. * \remarks
  278. * This function must be executed in M-Mode only.
  279. * \param [in] addr start address to be invalidated
  280. * \param [in] cnt count of cache lines to be invalidated
  281. */
  282. __STATIC_INLINE void MInvalICacheLines(unsigned long addr, unsigned long cnt)
  283. {
  284. if (cnt > 0) {
  285. unsigned long i;
  286. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  287. for (i = 0; i < cnt; i++) {
  288. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
  289. }
  290. FlushPipeCCM();
  291. __RWMB();
  292. }
  293. }
  294. /**
  295. * \brief Invalidate one I-Cache line specified by address in S-Mode
  296. * \details
  297. * This function unlock and invalidate one I-Cache line specified
  298. * by the address.
  299. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  300. * \remarks
  301. * This function must be executed in M/S-Mode only.
  302. * \param [in] addr start address to be invalidated
  303. */
  304. __STATIC_INLINE void SInvalICacheLine(unsigned long addr)
  305. {
  306. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  307. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
  308. FlushPipeCCM();
  309. __RWMB();
  310. }
  311. /**
  312. * \brief Invalidate several I-Cache lines specified by address in S-Mode
  313. * \details
  314. * This function unlock and invalidate several I-Cache lines specified
  315. * by the address and line count.
  316. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  317. * \remarks
  318. * This function must be executed in M/S-Mode only.
  319. * \param [in] addr start address to be invalidated
  320. * \param [in] cnt count of cache lines to be invalidated
  321. */
  322. __STATIC_INLINE void SInvalICacheLines(unsigned long addr, unsigned long cnt)
  323. {
  324. if (cnt > 0) {
  325. unsigned long i;
  326. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  327. for (i = 0; i < cnt; i++) {
  328. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
  329. }
  330. FlushPipeCCM();
  331. __RWMB();
  332. }
  333. }
  334. /**
  335. * \brief Invalidate one I-Cache line specified by address in U-Mode
  336. * \details
  337. * This function unlock and invalidate one I-Cache line specified
  338. * by the address.
  339. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  340. * \remarks
  341. * This function must be executed in M/S/U-Mode only.
  342. * \param [in] addr start address to be invalidated
  343. */
  344. __STATIC_INLINE void UInvalICacheLine(unsigned long addr)
  345. {
  346. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  347. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
  348. FlushPipeCCM();
  349. __RWMB();
  350. }
  351. /**
  352. * \brief Invalidate several I-Cache lines specified by address in U-Mode
  353. * \details
  354. * This function unlock and invalidate several I-Cache lines specified
  355. * by the address and line count.
  356. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  357. * \remarks
  358. * This function must be executed in M/S/U-Mode only.
  359. * \param [in] addr start address to be invalidated
  360. * \param [in] cnt count of cache lines to be invalidated
  361. */
  362. __STATIC_INLINE void UInvalICacheLines(unsigned long addr, unsigned long cnt)
  363. {
  364. if (cnt > 0) {
  365. unsigned long i;
  366. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  367. for (i = 0; i < cnt; i++) {
  368. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
  369. }
  370. FlushPipeCCM();
  371. __RWMB();
  372. }
  373. }
  374. /**
  375. * \brief Lock one I-Cache line specified by address in M-Mode
  376. * \details
  377. * This function lock one I-Cache line specified by the address.
  378. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  379. * \remarks
  380. * This function must be executed in M-Mode only.
  381. * \param [in] addr start address to be locked
  382. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  383. */
  384. __STATIC_INLINE unsigned long MLockICacheLine(unsigned long addr)
  385. {
  386. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  387. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_LOCK);
  388. FlushPipeCCM();
  389. __RWMB();
  390. return __RV_CSR_READ(CSR_CCM_MDATA);
  391. }
  392. /**
  393. * \brief Lock several I-Cache lines specified by address in M-Mode
  394. * \details
  395. * This function lock several I-Cache lines specified by the address
  396. * and line count.
  397. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  398. * \remarks
  399. * This function must be executed in M-Mode only.
  400. * \param [in] addr start address to be locked
  401. * \param [in] cnt count of cache lines to be locked
  402. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  403. */
  404. __STATIC_INLINE unsigned long MLockICacheLines(unsigned long addr, unsigned long cnt)
  405. {
  406. if (cnt > 0) {
  407. unsigned long i;
  408. unsigned long fail_info = CCM_OP_SUCCESS;
  409. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  410. for (i = 0; i < cnt; i++) {
  411. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_LOCK);
  412. FlushPipeCCM();
  413. __RWMB();
  414. fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
  415. if (CCM_OP_SUCCESS != fail_info) {
  416. return fail_info;
  417. }
  418. }
  419. }
  420. return CCM_OP_SUCCESS;
  421. }
  422. /**
  423. * \brief Lock one I-Cache line specified by address in S-Mode
  424. * \details
  425. * This function lock one I-Cache line specified by the address.
  426. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  427. * \remarks
  428. * This function must be executed in M/S-Mode only.
  429. * \param [in] addr start address to be locked
  430. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  431. */
  432. __STATIC_INLINE unsigned long SLockICacheLine(unsigned long addr)
  433. {
  434. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  435. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_LOCK);
  436. FlushPipeCCM();
  437. __RWMB();
  438. return __RV_CSR_READ(CSR_CCM_SDATA);
  439. }
  440. /**
  441. * \brief Lock several I-Cache lines specified by address in S-Mode
  442. * \details
  443. * This function lock several I-Cache lines specified by the address
  444. * and line count.
  445. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  446. * \remarks
  447. * This function must be executed in M/S-Mode only.
  448. * \param [in] addr start address to be locked
  449. * \param [in] cnt count of cache lines to be locked
  450. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  451. */
  452. __STATIC_INLINE unsigned long SLockICacheLines(unsigned long addr, unsigned long cnt)
  453. {
  454. if (cnt > 0) {
  455. unsigned long i;
  456. unsigned long fail_info = CCM_OP_SUCCESS;
  457. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  458. for (i = 0; i < cnt; i++) {
  459. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_LOCK);
  460. FlushPipeCCM();
  461. __RWMB();
  462. fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
  463. if (CCM_OP_SUCCESS != fail_info) {
  464. return fail_info;
  465. }
  466. }
  467. }
  468. return CCM_OP_SUCCESS;
  469. }
  470. /**
  471. * \brief Lock one I-Cache line specified by address in U-Mode
  472. * \details
  473. * This function lock one I-Cache line specified by the address.
  474. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  475. * \remarks
  476. * This function must be executed in M/S/U-Mode only.
  477. * \param [in] addr start address to be locked
  478. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  479. */
  480. __STATIC_INLINE unsigned long ULockICacheLine(unsigned long addr)
  481. {
  482. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  483. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_LOCK);
  484. FlushPipeCCM();
  485. __RWMB();
  486. return __RV_CSR_READ(CSR_CCM_UDATA);
  487. }
  488. /**
  489. * \brief Lock several I-Cache lines specified by address in U-Mode
  490. * \details
  491. * This function lock several I-Cache lines specified by the address
  492. * and line count.
  493. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  494. * \remarks
  495. * This function must be executed in M/S/U-Mode only.
  496. * \param [in] addr start address to be locked
  497. * \param [in] cnt count of cache lines to be locked
  498. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  499. */
  500. __STATIC_INLINE unsigned long ULockICacheLines(unsigned long addr, unsigned long cnt)
  501. {
  502. if (cnt > 0) {
  503. unsigned long i;
  504. unsigned long fail_info = CCM_OP_SUCCESS;
  505. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  506. for (i = 0; i < cnt; i++) {
  507. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_LOCK);
  508. FlushPipeCCM();
  509. __RWMB();
  510. fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
  511. if (CCM_OP_SUCCESS != fail_info) {
  512. return fail_info;
  513. }
  514. }
  515. }
  516. return CCM_OP_SUCCESS;
  517. }
  518. /**
  519. * \brief Unlock one I-Cache line specified by address in M-Mode
  520. * \details
  521. * This function unlock one I-Cache line specified by the address.
  522. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  523. * \remarks
  524. * This function must be executed in M-Mode only.
  525. * \param [in] addr start address to be unlocked
  526. */
  527. __STATIC_INLINE void MUnlockICacheLine(unsigned long addr)
  528. {
  529. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  530. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_UNLOCK);
  531. FlushPipeCCM();
  532. __RWMB();
  533. }
  534. /**
  535. * \brief Unlock several I-Cache lines specified by address in M-Mode
  536. * \details
  537. * This function unlock several I-Cache lines specified
  538. * by the address and line count.
  539. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  540. * \remarks
  541. * This function must be executed in M-Mode only.
  542. * \param [in] addr start address to be unlocked
  543. * \param [in] cnt count of cache lines to be unlocked
  544. */
  545. __STATIC_INLINE void MUnlockICacheLines(unsigned long addr, unsigned long cnt)
  546. {
  547. if (cnt > 0) {
  548. unsigned long i;
  549. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  550. for (i = 0; i < cnt; i++) {
  551. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_UNLOCK);
  552. }
  553. FlushPipeCCM();
  554. __RWMB();
  555. }
  556. }
  557. /**
  558. * \brief Unlock one I-Cache line specified by address in S-Mode
  559. * \details
  560. * This function unlock one I-Cache line specified by the address.
  561. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  562. * \remarks
  563. * This function must be executed in M/S-Mode only.
  564. * \param [in] addr start address to be unlocked
  565. */
  566. __STATIC_INLINE void SUnlockICacheLine(unsigned long addr)
  567. {
  568. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  569. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_UNLOCK);
  570. FlushPipeCCM();
  571. __RWMB();
  572. }
  573. /**
  574. * \brief Unlock several I-Cache lines specified by address in S-Mode
  575. * \details
  576. * This function unlock several I-Cache lines specified
  577. * by the address and line count.
  578. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  579. * \remarks
  580. * This function must be executed in M/S-Mode only.
  581. * \param [in] addr start address to be unlocked
  582. * \param [in] cnt count of cache lines to be unlocked
  583. */
  584. __STATIC_INLINE void SUnlockICacheLines(unsigned long addr, unsigned long cnt)
  585. {
  586. if (cnt > 0) {
  587. unsigned long i;
  588. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  589. for (i = 0; i < cnt; i++) {
  590. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_UNLOCK);
  591. }
  592. FlushPipeCCM();
  593. __RWMB();
  594. }
  595. }
  596. /**
  597. * \brief Unlock one I-Cache line specified by address in U-Mode
  598. * \details
  599. * This function unlock one I-Cache line specified by the address.
  600. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  601. * \remarks
  602. * This function must be executed in M/S/U-Mode only.
  603. * \param [in] addr start address to be unlocked
  604. */
  605. __STATIC_INLINE void UUnlockICacheLine(unsigned long addr)
  606. {
  607. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  608. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_UNLOCK);
  609. FlushPipeCCM();
  610. __RWMB();
  611. }
  612. /**
  613. * \brief Unlock several I-Cache lines specified by address in U-Mode
  614. * \details
  615. * This function unlock several I-Cache lines specified
  616. * by the address and line count.
  617. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  618. * \remarks
  619. * This function must be executed in M/S/U-Mode only.
  620. * \param [in] addr start address to be unlocked
  621. * \param [in] cnt count of cache lines to be unlocked
  622. */
  623. __STATIC_INLINE void UUnlockICacheLines(unsigned long addr, unsigned long cnt)
  624. {
  625. if (cnt > 0) {
  626. unsigned long i;
  627. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  628. for (i = 0; i < cnt; i++) {
  629. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_UNLOCK);
  630. }
  631. FlushPipeCCM();
  632. __RWMB();
  633. }
  634. }
  635. /**
  636. * \brief Invalidate all I-Cache lines in M-Mode
  637. * \details
  638. * This function invalidate all I-Cache lines.
  639. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  640. * \remarks
  641. * This function must be executed in M-Mode only.
  642. * \param [in] addr start address to be invalidated
  643. */
  644. __STATIC_INLINE void MInvalICache(void)
  645. {
  646. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL_ALL);
  647. FlushPipeCCM();
  648. __RWMB();
  649. }
  650. /**
  651. * \brief Invalidate all I-Cache lines in S-Mode
  652. * \details
  653. * This function invalidate all I-Cache lines.
  654. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  655. * \remarks
  656. * This function must be executed in M/S-Mode only.
  657. * \param [in] addr start address to be invalidated
  658. */
  659. __STATIC_INLINE void SInvalICache(void)
  660. {
  661. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL_ALL);
  662. FlushPipeCCM();
  663. __RWMB();
  664. }
  665. /**
  666. * \brief Invalidate all I-Cache lines in U-Mode
  667. * \details
  668. * This function invalidate all I-Cache lines.
  669. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  670. * \remarks
  671. * This function must be executed in M/S/U-Mode only.
  672. * \param [in] addr start address to be invalidated
  673. */
  674. __STATIC_INLINE void UInvalICache(void)
  675. {
  676. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL_ALL);
  677. FlushPipeCCM();
  678. __RWMB();
  679. }
  680. #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
  681. /** @} */ /* End of Doxygen Group NMSIS_Core_ICache */
  682. #endif /* defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1) */
  683. #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1)
  684. /**
  685. * \defgroup NMSIS_Core_DCache D-Cache Functions
  686. * \ingroup NMSIS_Core_Cache
  687. * \brief Functions that configure Data Cache.
  688. * @{
  689. */
  690. /**
  691. * \brief Check DCache Unit Present or Not
  692. * \details
  693. * This function check dcache unit present or not via mcfg_info csr
  694. * \remarks
  695. * - This function might not work for some old nuclei processors
  696. * - Please make sure the version of your nuclei processor contain DCACHE bit in mcfg_info
  697. * \return 1 if present otherwise 0
  698. */
  699. __STATIC_INLINE int32_t DCachePresent(void)
  700. {
  701. if (__RV_CSR_READ(CSR_MCFG_INFO) & MCFG_INFO_DCACHE) {
  702. return 1;
  703. }
  704. return 0;
  705. }
  706. /**
  707. * \brief Enable DCache
  708. * \details
  709. * This function enable D-Cache
  710. * \remarks
  711. * - This function can be called in M-Mode only.
  712. * - This \ref CSR_MCACHE_CTL register control D Cache enable.
  713. * \sa
  714. * - \ref DisableDCache
  715. */
  716. __STATIC_FORCEINLINE void EnableDCache(void)
  717. {
  718. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_EN);
  719. }
  720. /**
  721. * \brief Disable DCache
  722. * \details
  723. * This function Disable D-Cache
  724. * \remarks
  725. * - This function can be called in M-Mode only.
  726. * - This \ref CSR_MCACHE_CTL register control D Cache enable.
  727. * \sa
  728. * - \ref EnableDCache
  729. */
  730. __STATIC_FORCEINLINE void DisableDCache(void)
  731. {
  732. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_EN);
  733. }
  734. /**
  735. * \brief Enable DCache ECC
  736. * \details
  737. * This function enable D-Cache ECC
  738. * \remarks
  739. * - This function can be called in M-Mode only.
  740. * - This \ref CSR_MCACHE_CTL register control D Cache ECC enable.
  741. * \sa
  742. * - \ref DisableDCacheECC
  743. */
  744. __STATIC_FORCEINLINE void EnableDCacheECC(void)
  745. {
  746. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN);
  747. }
  748. /**
  749. * \brief Disable DCache ECC
  750. * \details
  751. * This function disable D-Cache ECC
  752. * \remarks
  753. * - This function can be called in M-Mode only.
  754. * - This \ref CSR_MCACHE_CTL register control D Cache ECC enable.
  755. * \sa
  756. * - \ref EnableDCacheECC
  757. */
  758. __STATIC_FORCEINLINE void DisableDCacheECC(void)
  759. {
  760. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN);
  761. }
  762. #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
  763. /**
  764. * \brief Get D-Cache Information
  765. * \details
  766. * This function get D-Cache Information
  767. * \remarks
  768. * - This function can be called in M-Mode only.
  769. * - You can use this function in combination with cache lines operations
  770. * \sa
  771. * - \ref GetICacheInfo
  772. */
  773. __STATIC_INLINE int32_t GetDCacheInfo(CacheInfo_Type *info)
  774. {
  775. if (info == NULL) {
  776. return -1;
  777. }
  778. CSR_MDCFGINFO_Type csr_ccfg;
  779. csr_ccfg.d = __RV_CSR_READ(CSR_MDCFG_INFO);
  780. info->setperway = (1UL << csr_ccfg.b.set) << 3;
  781. info->ways = (1 + csr_ccfg.b.way);
  782. if (csr_ccfg.b.lsize == 0) {
  783. info->linesize = 0;
  784. } else {
  785. info->linesize = (1UL << (csr_ccfg.b.lsize - 1)) << 3;
  786. }
  787. info->size = info->setperway * info->ways * info->linesize;
  788. return 0;
  789. }
  790. /**
  791. * \brief Invalidate one D-Cache line specified by address in M-Mode
  792. * \details
  793. * This function unlock and invalidate one D-Cache line specified
  794. * by the address.
  795. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  796. * \remarks
  797. * This function must be executed in M-Mode only.
  798. * \param [in] addr start address to be invalidated
  799. */
  800. __STATIC_INLINE void MInvalDCacheLine(unsigned long addr)
  801. {
  802. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  803. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
  804. FlushPipeCCM();
  805. __RWMB();
  806. }
  807. /**
  808. * \brief Invalidate several D-Cache lines specified by address in M-Mode
  809. * \details
  810. * This function unlock and invalidate several D-Cache lines specified
  811. * by the address and line count.
  812. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  813. * \remarks
  814. * This function must be executed in M-Mode only.
  815. * \param [in] addr start address to be invalidated
  816. * \param [in] cnt count of cache lines to be invalidated
  817. */
  818. __STATIC_INLINE void MInvalDCacheLines(unsigned long addr, unsigned long cnt)
  819. {
  820. if (cnt > 0) {
  821. unsigned long i;
  822. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  823. for (i = 0; i < cnt; i++) {
  824. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
  825. }
  826. FlushPipeCCM();
  827. __RWMB();
  828. }
  829. }
  830. /**
  831. * \brief Invalidate one D-Cache line specified by address in S-Mode
  832. * \details
  833. * This function unlock and invalidate one D-Cache line specified
  834. * by the address.
  835. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  836. * \remarks
  837. * This function must be executed in M/S-Mode only.
  838. * \param [in] addr start address to be invalidated
  839. */
  840. __STATIC_INLINE void SInvalDCacheLine(unsigned long addr)
  841. {
  842. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  843. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
  844. FlushPipeCCM();
  845. __RWMB();
  846. }
  847. /**
  848. * \brief Invalidate several D-Cache lines specified by address in S-Mode
  849. * \details
  850. * This function unlock and invalidate several D-Cache lines specified
  851. * by the address and line count.
  852. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  853. * \remarks
  854. * This function must be executed in M/S-Mode only.
  855. * \param [in] addr start address to be invalidated
  856. * \param [in] cnt count of cache lines to be invalidated
  857. */
  858. __STATIC_INLINE void SInvalDCacheLines(unsigned long addr, unsigned long cnt)
  859. {
  860. if (cnt > 0) {
  861. unsigned long i;
  862. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  863. for (i = 0; i < cnt; i++) {
  864. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
  865. }
  866. FlushPipeCCM();
  867. __RWMB();
  868. }
  869. }
  870. /**
  871. * \brief Invalidate one D-Cache line specified by address in U-Mode
  872. * \details
  873. * This function unlock and invalidate one D-Cache line specified
  874. * by the address.
  875. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  876. * \remarks
  877. * This function must be executed in M/S/U-Mode only.
  878. * \param [in] addr start address to be invalidated
  879. */
  880. __STATIC_INLINE void UInvalDCacheLine(unsigned long addr)
  881. {
  882. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  883. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
  884. FlushPipeCCM();
  885. __RWMB();
  886. }
  887. /**
  888. * \brief Invalidate several D-Cache lines specified by address in U-Mode
  889. * \details
  890. * This function unlock and invalidate several D-Cache lines specified
  891. * by the address and line count.
  892. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  893. * \remarks
  894. * This function must be executed in M/S/U-Mode only.
  895. * \param [in] addr start address to be invalidated
  896. * \param [in] cnt count of cache lines to be invalidated
  897. */
  898. __STATIC_INLINE void UInvalDCacheLines(unsigned long addr, unsigned long cnt)
  899. {
  900. if (cnt > 0) {
  901. unsigned long i;
  902. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  903. for (i = 0; i < cnt; i++) {
  904. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
  905. }
  906. FlushPipeCCM();
  907. __RWMB();
  908. }
  909. }
  910. /**
  911. * \brief Flush one D-Cache line specified by address in M-Mode
  912. * \details
  913. * This function flush one D-Cache line specified by the address.
  914. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_MCOMMAND.
  915. * \remarks
  916. * This function must be executed in M-Mode only.
  917. * \param [in] addr start address to be flushed
  918. */
  919. __STATIC_INLINE void MFlushDCacheLine(unsigned long addr)
  920. {
  921. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  922. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB);
  923. FlushPipeCCM();
  924. __RWMB();
  925. }
  926. /**
  927. * \brief Flush several D-Cache lines specified by address in M-Mode
  928. * \details
  929. * This function flush several D-Cache lines specified
  930. * by the address and line count.
  931. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_MCOMMAND.
  932. * \remarks
  933. * This function must be executed in M-Mode only.
  934. * \param [in] addr start address to be flushed
  935. * \param [in] cnt count of cache lines to be flushed
  936. */
  937. __STATIC_INLINE void MFlushDCacheLines(unsigned long addr, unsigned long cnt)
  938. {
  939. if (cnt > 0) {
  940. unsigned long i;
  941. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  942. for (i = 0; i < cnt; i++) {
  943. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB);
  944. }
  945. FlushPipeCCM();
  946. __RWMB();
  947. }
  948. }
  949. /**
  950. * \brief Flush one D-Cache line specified by address in S-Mode
  951. * \details
  952. * This function flush one D-Cache line specified by the address.
  953. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_SCOMMAND.
  954. * \remarks
  955. * This function must be executed in M/S-Mode only.
  956. * \param [in] addr start address to be flushed
  957. */
  958. __STATIC_INLINE void SFlushDCacheLine(unsigned long addr)
  959. {
  960. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  961. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB);
  962. FlushPipeCCM();
  963. __RWMB();
  964. }
  965. /**
  966. * \brief Flush several D-Cache lines specified by address in S-Mode
  967. * \details
  968. * This function flush several D-Cache lines specified
  969. * by the address and line count.
  970. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_SCOMMAND.
  971. * \remarks
  972. * This function must be executed in M/S-Mode only.
  973. * \param [in] addr start address to be flushed
  974. * \param [in] cnt count of cache lines to be flushed
  975. */
  976. __STATIC_INLINE void SFlushDCacheLines(unsigned long addr, unsigned long cnt)
  977. {
  978. if (cnt > 0) {
  979. unsigned long i;
  980. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  981. for (i = 0; i < cnt; i++) {
  982. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB);
  983. }
  984. FlushPipeCCM();
  985. __RWMB();
  986. }
  987. }
  988. /**
  989. * \brief Flush one D-Cache line specified by address in U-Mode
  990. * \details
  991. * This function flush one D-Cache line specified by the address.
  992. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_UCOMMAND.
  993. * \remarks
  994. * This function must be executed in M/S/U-Mode only.
  995. * \param [in] addr start address to be flushed
  996. */
  997. __STATIC_INLINE void UFlushDCacheLine(unsigned long addr)
  998. {
  999. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1000. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB);
  1001. FlushPipeCCM();
  1002. __RWMB();
  1003. }
  1004. /**
  1005. * \brief Flush several D-Cache lines specified by address in U-Mode
  1006. * \details
  1007. * This function flush several D-Cache lines specified
  1008. * by the address and line count.
  1009. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_UCOMMAND.
  1010. * \remarks
  1011. * This function must be executed in M/S/U-Mode only.
  1012. * \param [in] addr start address to be flushed
  1013. * \param [in] cnt count of cache lines to be flushed
  1014. */
  1015. __STATIC_INLINE void UFlushDCacheLines(unsigned long addr, unsigned long cnt)
  1016. {
  1017. if (cnt > 0) {
  1018. unsigned long i;
  1019. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1020. for (i = 0; i < cnt; i++) {
  1021. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB);
  1022. }
  1023. FlushPipeCCM();
  1024. __RWMB();
  1025. }
  1026. }
  1027. /**
  1028. * \brief Flush and invalidate one D-Cache line specified by address in M-Mode
  1029. * \details
  1030. * This function flush and invalidate one D-Cache line specified by the address.
  1031. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1032. * \remarks
  1033. * This function must be executed in M-Mode only.
  1034. * \param [in] addr start address to be flushed and invalidated
  1035. */
  1036. __STATIC_INLINE void MFlushInvalDCacheLine(unsigned long addr)
  1037. {
  1038. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1039. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL);
  1040. FlushPipeCCM();
  1041. __RWMB();
  1042. }
  1043. /**
  1044. * \brief Flush and invalidate several D-Cache lines specified by address in M-Mode
  1045. * \details
  1046. * This function flush and invalidate several D-Cache lines specified
  1047. * by the address and line count.
  1048. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1049. * \remarks
  1050. * This function must be executed in M-Mode only.
  1051. * \param [in] addr start address to be flushed and invalidated
  1052. * \param [in] cnt count of cache lines to be flushed and invalidated
  1053. */
  1054. __STATIC_INLINE void MFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1055. {
  1056. if (cnt > 0) {
  1057. unsigned long i;
  1058. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1059. for (i = 0; i < cnt; i++) {
  1060. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL);
  1061. }
  1062. FlushPipeCCM();
  1063. __RWMB();
  1064. }
  1065. }
  1066. /**
  1067. * \brief Flush and invalidate one D-Cache line specified by address in S-Mode
  1068. * \details
  1069. * This function flush and invalidate one D-Cache line specified by the address.
  1070. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  1071. * \remarks
  1072. * This function must be executed in M/S-Mode only.
  1073. * \param [in] addr start address to be flushed and invalidated
  1074. */
  1075. __STATIC_INLINE void SFlushInvalDCacheLine(unsigned long addr)
  1076. {
  1077. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1078. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL);
  1079. FlushPipeCCM();
  1080. __RWMB();
  1081. }
  1082. /**
  1083. * \brief Flush and invalidate several D-Cache lines specified by address in S-Mode
  1084. * \details
  1085. * This function flush and invalidate several D-Cache lines specified
  1086. * by the address and line count.
  1087. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  1088. * \remarks
  1089. * This function must be executed in M/S-Mode only.
  1090. * \param [in] addr start address to be flushed and invalidated
  1091. * \param [in] cnt count of cache lines to be flushed and invalidated
  1092. */
  1093. __STATIC_INLINE void SFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1094. {
  1095. if (cnt > 0) {
  1096. unsigned long i;
  1097. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1098. for (i = 0; i < cnt; i++) {
  1099. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL);
  1100. }
  1101. FlushPipeCCM();
  1102. __RWMB();
  1103. }
  1104. }
  1105. /**
  1106. * \brief Flush and invalidate one D-Cache line specified by address in U-Mode
  1107. * \details
  1108. * This function flush and invalidate one D-Cache line specified by the address.
  1109. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  1110. * \remarks
  1111. * This function must be executed in M/S/U-Mode only.
  1112. * \param [in] addr start address to be flushed and invalidated
  1113. */
  1114. __STATIC_INLINE void UFlushInvalDCacheLine(unsigned long addr)
  1115. {
  1116. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1117. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL);
  1118. FlushPipeCCM();
  1119. __RWMB();
  1120. }
  1121. /**
  1122. * \brief Flush and invalidate several D-Cache lines specified by address in U-Mode
  1123. * \details
  1124. * This function flush and invalidate several D-Cache lines specified
  1125. * by the address and line count.
  1126. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  1127. * \remarks
  1128. * This function must be executed in M/S/U-Mode only.
  1129. * \param [in] addr start address to be flushed and invalidated
  1130. * \param [in] cnt count of cache lines to be flushed and invalidated
  1131. */
  1132. __STATIC_INLINE void UFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1133. {
  1134. if (cnt > 0) {
  1135. unsigned long i;
  1136. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1137. for (i = 0; i < cnt; i++) {
  1138. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL);
  1139. }
  1140. FlushPipeCCM();
  1141. __RWMB();
  1142. }
  1143. }
  1144. /**
  1145. * \brief Lock one D-Cache line specified by address in M-Mode
  1146. * \details
  1147. * This function lock one D-Cache line specified by the address.
  1148. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1149. * \remarks
  1150. * This function must be executed in M-Mode only.
  1151. * \param [in] addr start address to be locked
  1152. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1153. */
  1154. __STATIC_INLINE unsigned long MLockDCacheLine(unsigned long addr)
  1155. {
  1156. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1157. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_LOCK);
  1158. FlushPipeCCM();
  1159. __RWMB();
  1160. return __RV_CSR_READ(CSR_CCM_MDATA);
  1161. }
  1162. /**
  1163. * \brief Lock several D-Cache lines specified by address in M-Mode
  1164. * \details
  1165. * This function lock several D-Cache lines specified by the address
  1166. * and line count.
  1167. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1168. * \remarks
  1169. * This function must be executed in M-Mode only.
  1170. * \param [in] addr start address to be locked
  1171. * \param [in] cnt count of cache lines to be locked
  1172. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1173. */
  1174. __STATIC_INLINE unsigned long MLockDCacheLines(unsigned long addr, unsigned long cnt)
  1175. {
  1176. if (cnt > 0) {
  1177. unsigned long i;
  1178. unsigned long fail_info = CCM_OP_SUCCESS;
  1179. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1180. for (i = 0; i < cnt; i++) {
  1181. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_LOCK);
  1182. FlushPipeCCM();
  1183. __RWMB();
  1184. fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
  1185. if (CCM_OP_SUCCESS != fail_info) {
  1186. return fail_info;
  1187. }
  1188. }
  1189. }
  1190. return CCM_OP_SUCCESS;
  1191. }
  1192. /**
  1193. * \brief Lock one D-Cache line specified by address in S-Mode
  1194. * \details
  1195. * This function lock one D-Cache line specified by the address.
  1196. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1197. * \remarks
  1198. * This function must be executed in M/S-Mode only.
  1199. * \param [in] addr start address to be locked
  1200. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1201. */
  1202. __STATIC_INLINE unsigned long SLockDCacheLine(unsigned long addr)
  1203. {
  1204. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1205. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_LOCK);
  1206. FlushPipeCCM();
  1207. __RWMB();
  1208. return __RV_CSR_READ(CSR_CCM_SDATA);
  1209. }
  1210. /**
  1211. * \brief Lock several D-Cache lines specified by address in S-Mode
  1212. * \details
  1213. * This function lock several D-Cache lines specified by the address
  1214. * and line count.
  1215. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1216. * \remarks
  1217. * This function must be executed in M/S-Mode only.
  1218. * \param [in] addr start address to be locked
  1219. * \param [in] cnt count of cache lines to be locked
  1220. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1221. */
  1222. __STATIC_INLINE unsigned long SLockDCacheLines(unsigned long addr, unsigned long cnt)
  1223. {
  1224. if (cnt > 0) {
  1225. unsigned long i;
  1226. unsigned long fail_info = CCM_OP_SUCCESS;
  1227. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1228. for (i = 0; i < cnt; i++) {
  1229. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_LOCK);
  1230. FlushPipeCCM();
  1231. __RWMB();
  1232. fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
  1233. if (CCM_OP_SUCCESS != fail_info) {
  1234. return fail_info;
  1235. }
  1236. }
  1237. }
  1238. return CCM_OP_SUCCESS;
  1239. }
  1240. /**
  1241. * \brief Lock one D-Cache line specified by address in U-Mode
  1242. * \details
  1243. * This function lock one D-Cache line specified by the address.
  1244. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1245. * \remarks
  1246. * This function must be executed in M/S/U-Mode only.
  1247. * \param [in] addr start address to be locked
  1248. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1249. */
  1250. __STATIC_INLINE unsigned long ULockDCacheLine(unsigned long addr)
  1251. {
  1252. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1253. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_LOCK);
  1254. FlushPipeCCM();
  1255. __RWMB();
  1256. return __RV_CSR_READ(CSR_CCM_UDATA);
  1257. }
  1258. /**
  1259. * \brief Lock several D-Cache lines specified by address in U-Mode
  1260. * \details
  1261. * This function lock several D-Cache lines specified by the address
  1262. * and line count.
  1263. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1264. * \remarks
  1265. * This function must be executed in M/S/U-Mode only.
  1266. * \param [in] addr start address to be locked
  1267. * \param [in] cnt count of cache lines to be locked
  1268. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1269. */
  1270. __STATIC_INLINE unsigned long ULockDCacheLines(unsigned long addr, unsigned long cnt)
  1271. {
  1272. if (cnt > 0) {
  1273. unsigned long i;
  1274. unsigned long fail_info = CCM_OP_SUCCESS;
  1275. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1276. for (i = 0; i < cnt; i++) {
  1277. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_LOCK);
  1278. FlushPipeCCM();
  1279. __RWMB();
  1280. fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
  1281. if (CCM_OP_SUCCESS != fail_info) {
  1282. return fail_info;
  1283. }
  1284. }
  1285. }
  1286. return CCM_OP_SUCCESS;
  1287. }
  1288. /**
  1289. * \brief Unlock one D-Cache line specified by address in M-Mode
  1290. * \details
  1291. * This function unlock one D-Cache line specified by the address.
  1292. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1293. * \remarks
  1294. * This function must be executed in M-Mode only.
  1295. * \param [in] addr start address to be unlocked
  1296. */
  1297. __STATIC_INLINE void MUnlockDCacheLine(unsigned long addr)
  1298. {
  1299. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1300. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_UNLOCK);
  1301. FlushPipeCCM();
  1302. __RWMB();
  1303. }
  1304. /**
  1305. * \brief Unlock several D-Cache lines specified by address in M-Mode
  1306. * \details
  1307. * This function unlock several D-Cache lines specified
  1308. * by the address and line count.
  1309. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1310. * \remarks
  1311. * This function must be executed in M-Mode only.
  1312. * \param [in] addr start address to be unlocked
  1313. * \param [in] cnt count of cache lines to be unlocked
  1314. */
  1315. __STATIC_INLINE void MUnlockDCacheLines(unsigned long addr, unsigned long cnt)
  1316. {
  1317. if (cnt > 0) {
  1318. unsigned long i;
  1319. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1320. for (i = 0; i < cnt; i++) {
  1321. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_UNLOCK);
  1322. }
  1323. FlushPipeCCM();
  1324. __RWMB();
  1325. }
  1326. }
  1327. /**
  1328. * \brief Unlock one D-Cache line specified by address in S-Mode
  1329. * \details
  1330. * This function unlock one D-Cache line specified by the address.
  1331. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1332. * \remarks
  1333. * This function must be executed in M/S-Mode only.
  1334. * \param [in] addr start address to be unlocked
  1335. */
  1336. __STATIC_INLINE void SUnlockDCacheLine(unsigned long addr)
  1337. {
  1338. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1339. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_UNLOCK);
  1340. FlushPipeCCM();
  1341. __RWMB();
  1342. }
  1343. /**
  1344. * \brief Unlock several D-Cache lines specified by address in S-Mode
  1345. * \details
  1346. * This function unlock several D-Cache lines specified
  1347. * by the address and line count.
  1348. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1349. * \remarks
  1350. * This function must be executed in M/S-Mode only.
  1351. * \param [in] addr start address to be unlocked
  1352. * \param [in] cnt count of cache lines to be unlocked
  1353. */
  1354. __STATIC_INLINE void SUnlockDCacheLines(unsigned long addr, unsigned long cnt)
  1355. {
  1356. if (cnt > 0) {
  1357. unsigned long i;
  1358. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1359. for (i = 0; i < cnt; i++) {
  1360. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_UNLOCK);
  1361. }
  1362. FlushPipeCCM();
  1363. __RWMB();
  1364. }
  1365. }
  1366. /**
  1367. * \brief Unlock one D-Cache line specified by address in U-Mode
  1368. * \details
  1369. * This function unlock one D-Cache line specified by the address.
  1370. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1371. * \remarks
  1372. * This function must be executed in M/S/U-Mode only.
  1373. * \param [in] addr start address to be unlocked
  1374. */
  1375. __STATIC_INLINE void UUnlockDCacheLine(unsigned long addr)
  1376. {
  1377. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1378. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_UNLOCK);
  1379. FlushPipeCCM();
  1380. __RWMB();
  1381. }
  1382. /**
  1383. * \brief Unlock several D-Cache lines specified by address in U-Mode
  1384. * \details
  1385. * This function unlock several D-Cache lines specified
  1386. * by the address and line count.
  1387. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1388. * \remarks
  1389. * This function must be executed in M/S/U-Mode only.
  1390. * \param [in] addr start address to be unlocked
  1391. * \param [in] cnt count of cache lines to be unlocked
  1392. */
  1393. __STATIC_INLINE void UUnlockDCacheLines(unsigned long addr, unsigned long cnt)
  1394. {
  1395. if (cnt > 0) {
  1396. unsigned long i;
  1397. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1398. for (i = 0; i < cnt; i++) {
  1399. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_UNLOCK);
  1400. }
  1401. FlushPipeCCM();
  1402. __RWMB();
  1403. }
  1404. }
  1405. /**
  1406. * \brief Invalidate all D-Cache lines in M-Mode
  1407. * \details
  1408. * This function invalidate all D-Cache lines.
  1409. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  1410. * \remarks
  1411. * This function must be executed in M-Mode only.
  1412. * \param [in] addr start address to be invalidated
  1413. */
  1414. __STATIC_INLINE void MInvalDCache(void)
  1415. {
  1416. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL_ALL);
  1417. FlushPipeCCM();
  1418. __RWMB();
  1419. }
  1420. /**
  1421. * \brief Invalidate all D-Cache lines in S-Mode
  1422. * \details
  1423. * This function invalidate all D-Cache lines.
  1424. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  1425. * \remarks
  1426. * This function must be executed in M/S-Mode only.
  1427. * \param [in] addr start address to be invalidated
  1428. */
  1429. __STATIC_INLINE void SInvalDCache(void)
  1430. {
  1431. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL_ALL);
  1432. FlushPipeCCM();
  1433. __RWMB();
  1434. }
  1435. /**
  1436. * \brief Invalidate all D-Cache lines in U-Mode
  1437. * \details
  1438. * This function invalidate all D-Cache lines.
  1439. * In U-Mode, this operation will be automatically
  1440. * translated to flush and invalidate operations by hardware.
  1441. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  1442. * \remarks
  1443. * This function must be executed in M/S/U-Mode only.
  1444. * \param [in] addr start address to be invalidated
  1445. */
  1446. __STATIC_INLINE void UInvalDCache(void)
  1447. {
  1448. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL_ALL);
  1449. FlushPipeCCM();
  1450. __RWMB();
  1451. }
  1452. /**
  1453. * \brief Flush all D-Cache lines in M-Mode
  1454. * \details
  1455. * This function flush all D-Cache lines.
  1456. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  1457. * \remarks
  1458. * This function must be executed in M-Mode only.
  1459. * \param [in] addr start address to be flushed
  1460. */
  1461. __STATIC_INLINE void MFlushDCache(void)
  1462. {
  1463. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB_ALL);
  1464. FlushPipeCCM();
  1465. __RWMB();
  1466. }
  1467. /**
  1468. * \brief Flush all D-Cache lines in S-Mode
  1469. * \details
  1470. * This function flush all D-Cache lines.
  1471. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  1472. * \remarks
  1473. * This function must be executed in M/S-Mode only.
  1474. * \param [in] addr start address to be flushed
  1475. */
  1476. __STATIC_INLINE void SFlushDCache(void)
  1477. {
  1478. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB_ALL);
  1479. FlushPipeCCM();
  1480. __RWMB();
  1481. }
  1482. /**
  1483. * \brief Flush all D-Cache lines in U-Mode
  1484. * \details
  1485. * This function flush all D-Cache lines.
  1486. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  1487. * \remarks
  1488. * This function must be executed in M/S/U-Mode only.
  1489. * \param [in] addr start address to be flushed
  1490. */
  1491. __STATIC_INLINE void UFlushDCache(void)
  1492. {
  1493. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB_ALL);
  1494. FlushPipeCCM();
  1495. __RWMB();
  1496. }
  1497. /**
  1498. * \brief Flush and invalidate all D-Cache lines in M-Mode
  1499. * \details
  1500. * This function flush and invalidate all D-Cache lines.
  1501. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  1502. * \remarks
  1503. * This function must be executed in M-Mode only.
  1504. * \param [in] addr start address to be flushed and locked
  1505. */
  1506. __STATIC_INLINE void MFlushInvalDCache(void)
  1507. {
  1508. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL_ALL);
  1509. FlushPipeCCM();
  1510. __RWMB();
  1511. }
  1512. /**
  1513. * \brief Flush and invalidate all D-Cache lines in S-Mode
  1514. * \details
  1515. * This function flush and invalidate all D-Cache lines.
  1516. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  1517. * \remarks
  1518. * This function must be executed in M/S-Mode only.
  1519. * \param [in] addr start address to be flushed and locked
  1520. */
  1521. __STATIC_INLINE void SFlushInvalDCache(void)
  1522. {
  1523. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL_ALL);
  1524. FlushPipeCCM();
  1525. __RWMB();
  1526. }
  1527. /**
  1528. * \brief Flush and invalidate all D-Cache lines in U-Mode
  1529. * \details
  1530. * This function flush and invalidate all D-Cache lines.
  1531. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  1532. * \remarks
  1533. * This function must be executed in M/S/U-Mode only.
  1534. * \param [in] addr start address to be flushed and locked
  1535. */
  1536. __STATIC_INLINE void UFlushInvalDCache(void)
  1537. {
  1538. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL_ALL);
  1539. FlushPipeCCM();
  1540. __RWMB();
  1541. }
  1542. #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
  1543. /** @} */ /* End of Doxygen Group NMSIS_Core_DCache */
  1544. #endif /* defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1) */
  1545. #ifdef __cplusplus
  1546. }
  1547. #endif
  1548. #endif /* __CORE_FEATURE_CACHE_H__ */