core_feature_cache.h 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720
  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. * 4. __SMPCC_PRESENT: Define whether SMP & Cluster Cache Unit is present or not.
  36. * * 0: Not present
  37. * * 1: Present
  38. * 5. __SMPCC_BASEADDR: Base address of the SMP & Cluster Cache unit.
  39. */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #include "core_feature_base.h"
  44. #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
  45. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  46. /**
  47. * \defgroup NMSIS_Core_CCache Cluster-Cache Functions
  48. * \ingroup NMSIS_Core_Cache
  49. * \brief Functions that configure Cluster Cache by CCM
  50. * @{
  51. */
  52. /**
  53. * \brief Cluster Cache Control and Command Registers
  54. * \remarks This structure only holds a part of SMPCC registers, which are related to
  55. * Cluster Cache CCM operations. Other more registers of SMPCC are listed in core_feature_smpcc.h
  56. */
  57. typedef struct {
  58. __IM uint8_t RESERVED0[16]; /*!< 0x00~0x0F (R) Not shown here for these registers are not related with cache operation */
  59. __IOM uint32_t CC_CTRL; /*!< Offset: 0x10 (R/W) Cluster Cache Control Register */
  60. __IOM uint32_t CC_mCMD; /*!< Offset: 0x14 (R/W) Cluster Cache M-mode Command Register */
  61. __IM uint8_t RESERVED1[168]; /*!< 0x18~0xBF (R) not shown here for these registers are not related with cache operation */
  62. __IOM uint32_t CC_sCMD; /*!< Offset: 0xC0 (R/W) Cluster Cache S-mode Command Register */
  63. __IOM uint32_t CC_uCMD; /*!< Offset: 0xC4 (R/W) Cluster Cache U-mode Command Register */
  64. __IM uint8_t RESERVED2[20]; /*!< 0xC8~0xDB (R) not shown here for these registers are not related with cache operation */
  65. __IOM uint32_t CC_INVALID_ALL; /*!< Offset: 0xDC (R/W) Cluster Cache Invalid All Register */
  66. } SMPCC_CMD_Type;
  67. #define SMPCC_CMD_CTRL_SUP_EN_Pos 9U /*!< SMPCC_CMD CC_CTRL SUP_EN Position */
  68. #define SMPCC_CMD_CTRL_SUP_EN_Msk (0x1UL << SMPCC_CMD_CTRL_SUP_EN_Pos) /*!< SMPCC_CMD CC_CTRL SUP_EN Mask */
  69. #define SMPCC_CMD_CTRL_SUP_EN_ENABLE 1U /*!< SMPCC_CMD CC_CTRL SUP_EN Enable */
  70. #define SMPCC_CMD_CTRL_SUP_EN_DISABLE 0U /*!< SMPCC_CMD CC_CTRL SUP_EN Disable */
  71. #define SMPCC_CMD_CTRL_USE_EN_Pos 10U /*!< SMPCC_CMD CC_CTRL USE_EN Position */
  72. #define SMPCC_CMD_CTRL_USE_EN_Msk (0x1UL << SMPCC_CMD_CTRL_USE_EN_Pos) /*!< SMPCC_CMD CC_CTRL USE_EN Mask */
  73. #define SMPCC_CMD_CTRL_USE_EN_ENABLE 1U /*!< SMPCC_CMD CC_CTRL USE_EN Enable */
  74. #define SMPCC_CMD_CTRL_USE_EN_DISABLE 0U /*!< SMPCC_CMD CC_CTRL USE_EN Disable */
  75. #define SMPCC_CMD_xCMD_CMD_Pos 0U /*!< SMPCC_CMD register xCMD field CMD Position */
  76. #define SMPCC_CMD_xCMD_CMD_Msk (0x1FUL << SMPCC_CMD_xCMD_CMD_Pos) /*!< SMPCC_CMD register xCMD field CMD Mask */
  77. #define SMPCC_CMD_xCMD_CMD_WB_ALL 0x7U /*!< SMPCC_CMD xCMD CMD WB_ALL */
  78. #define SMPCC_CMD_xCMD_CMD_WBINVAL_ALL 0x6U /*!< SMPCC_CMD xCMD CMD WBINVAL_ALL */
  79. #define SMPCC_CMD_xCMD_RESULT_Pos 26U /*!< SMPCC_CMD xCMD RESULT Position */
  80. #define SMPCC_CMD_xCMD_RESULT_Msk (0x1FUL << SMPCC_CMD_xCMD_RESULT_Pos) /*!< SMPCC_CMD xCMD RESULT Mask */
  81. #define SMPCC_CMD_xCMD_RESULT_SUCCESS 0x0U /*!< SMPCC_CMD xCMD RESULT Success */
  82. #define SMPCC_CMD_xCMD_RESULT_ENTRY_EXCEED_LIMIT 0x1U /*!< SMPCC_CMD xCMD RESULT Exceed the upper entry num of lockable way */
  83. #define SMPCC_CMD_xCMD_RESULT_REFILL_BUS_ERROR 0x3U /*!< SMPCC_CMD xCMD RESULT Refill Bus Error */
  84. #define SMPCC_CMD_xCMD_RESULT_ECC_ERROR 0x4U /*!< SMPCC_CMD xCMD RESULT ECC Error */
  85. #define SMPCC_CMD_xCMD_RESULT_CPBACK_BUS_ERROR 0x5U /*!< SMPCC_CMD xCMD RESULT Copy Back Bus Error */
  86. #define SMPCC_CMD_xCMD_COMPLETE_Pos 31U /*!< SMPCC_CMD xCMD COMPLETE Position */
  87. #define SMPCC_CMD_xCMD_COMPLETE_Msk (0x1UL << SMPCC_CMD_xCMD_COMPLETE_Pos) /*!< SMPCC_CMD xCMD COMPLETE Mask */
  88. #define SMPCC_CMD_INVALID_ALL_Pos 0U /*!< SMPCC_CMD INVALID_ALL Position */
  89. #define SMPCC_CMD_INVALID_ALL_Msk (0x1UL << SMPCC_CMD_INVALID_ALL_Pos) /*!< SMPCC_CMD INVALID_ALL Mask */
  90. #ifndef __SMPCC_BASEADDR
  91. /* Base address of SMPCC(__SMPCC_BASEADDR) should be defined in <Device.h> */
  92. #error "__SMPCC_BASEADDR is not defined, please check!"
  93. #endif
  94. /* SMPCC CMD registers Memory mapping of Device */
  95. #define SMPCC_CMD_BASE __SMPCC_BASEADDR /*!< SMPCC CMD Base Address */
  96. #define SMPCC_CMD ((SMPCC_CMD_Type *)SMPCC_CMD_BASE) /*!< SMPCC CMD configuration struct */
  97. /** @} */ /* End of Doxygen Group NMSIS_Core_CCache */
  98. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  99. /* ########################## Cache functions #################################### */
  100. /**
  101. * \defgroup NMSIS_Core_Cache Cache Functions
  102. * \brief Functions that configure Instruction and Data Cache.
  103. * @{
  104. *
  105. * Nuclei provide Cache Control and Maintainence(CCM) for software to control and maintain
  106. * the internal L1 I/D Cache and Cluster Cache of the RISC-V Core, software can manage the
  107. * cache flexibly to meet the actual application scenarios.
  108. *
  109. * The CCM operations have 3 types: by single address, by all and flush pipeline.
  110. * The CCM operations are done via CSR registers, M/S/U mode has its own CSR registers to
  111. * do CCM operations. By default, CCM operations are not allowed in S/U mode, you can execute
  112. * \ref EnableSUCCM in M-Mode to enable it.
  113. *
  114. * * API names started with M<operations>, such as \ref MInvalICacheLine must be called in M-Mode only.
  115. * * API names started with S<operations>, such as \ref SInvalICacheLine should be called in S-Mode.
  116. * * API names started with U<operations>, such as \ref UInvalICacheLine should be called in U-Mode.
  117. *
  118. */
  119. /**
  120. * \brief Cache CCM Operation Fail Info
  121. */
  122. typedef enum CCM_OP_FINFO {
  123. CCM_OP_SUCCESS = 0x0, /*!< Lock Succeed */
  124. CCM_OP_EXCEED_ERR = 0x1, /*!< Exceed the the number of lockable ways(N-Way I/D-Cache, lockable is N-1) */
  125. 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 */
  126. CCM_OP_REFILL_BUS_ERR = 0x3, /*!< Refill has Bus Error */
  127. CCM_OP_ECC_ERR = 0x4 /*!< Deprecated, ECC Error, this error code is removed in later Nuclei CCM RTL design, please don't use it */
  128. } CCM_OP_FINFO_Type;
  129. /**
  130. * \brief Cache CCM Command Types
  131. */
  132. typedef enum CCM_CMD {
  133. CCM_DC_INVAL = 0x0, /*!< Unlock and invalidate D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR */
  134. CCM_DC_WB = 0x1, /*!< Flush the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR */
  135. CCM_DC_WBINVAL = 0x2, /*!< Unlock, flush and invalidate the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR */
  136. CCM_DC_LOCK = 0x3, /*!< Lock the specific D-Cache line specified by CSR CCM_XBEGINADDR */
  137. CCM_DC_UNLOCK = 0x4, /*!< Unlock the specific D-Cache line specified by CSR CCM_XBEGINADDR */
  138. CCM_DC_WBINVAL_ALL = 0x6, /*!< Unlock and flush and invalidate all the valid and dirty D-Cache lines */
  139. CCM_DC_WB_ALL = 0x7, /*!< Flush all the valid and dirty D-Cache lines */
  140. CCM_DC_INVAL_ALL = 0x17, /*!< Unlock and invalidate all the D-Cache lines */
  141. CCM_IC_INVAL = 0x8, /*!< Unlock and invalidate I-Cache line specified by CSR CCM_XBEGINADDR */
  142. CCM_IC_LOCK = 0xb, /*!< Lock the specific I-Cache line specified by CSR CCM_XBEGINADDR */
  143. CCM_IC_UNLOCK = 0xc, /*!< Unlock the specific I-Cache line specified by CSR CCM_XBEGINADDR */
  144. CCM_IC_INVAL_ALL = 0xd, /*!< Unlock and invalidate all the I-Cache lines */
  145. CCM_CC_LOCK = 0x13, /*!< Lock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR */
  146. CCM_CC_UNLOCK = 0x12, /*!< Unlock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR */
  147. } CCM_CMD_Type;
  148. /**
  149. * \brief Cache Information Type
  150. */
  151. typedef struct CacheInfo {
  152. uint32_t linesize; /*!< Cache Line size in bytes */
  153. uint32_t ways; /*!< Cache ways */
  154. uint32_t setperway; /*!< Cache set per way */
  155. uint32_t size; /*!< Cache total size in bytes */
  156. } CacheInfo_Type;
  157. #if __riscv_xlen == 32
  158. #define CCM_SUEN_SUEN_Msk (0xFFFFFFFFUL) /*!< CSR CCM_SUEN: SUEN Mask */
  159. #else
  160. #define CCM_SUEN_SUEN_Msk (0xFFFFFFFFFFFFFFFFUL) /*!< CSR CCM_SUEN: SUEN Mask */
  161. #endif
  162. /**
  163. * \brief Enable CCM operation in Supervisor/User Mode
  164. * \details
  165. * This function enable CCM operation in Supervisor/User Mode.
  166. * If enabled, CCM operations in supervisor/user mode will
  167. * be allowed. Besides CCM registers, CC_sCMD and CC_uCMD registers
  168. * which belong to SMPCC module are also allowed.
  169. * \remarks
  170. * - This function can be called in M-Mode only.
  171. * \sa
  172. * - \ref DisableSUCCM
  173. */
  174. __STATIC_FORCEINLINE void EnableSUCCM(void)
  175. {
  176. __RV_CSR_SET(CSR_CCM_SUEN, CCM_SUEN_SUEN_Msk);
  177. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  178. SMPCC_CMD->CC_CTRL |= _VAL2FLD(SMPCC_CMD_CTRL_SUP_EN, SMPCC_CMD_CTRL_SUP_EN_ENABLE) |
  179. _VAL2FLD(SMPCC_CMD_CTRL_USE_EN, SMPCC_CMD_CTRL_USE_EN_ENABLE);
  180. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  181. }
  182. /**
  183. * \brief Disable CCM operation in Supervisor/User Mode
  184. * \details
  185. * This function disable CCM operation in Supervisor/User Mode.
  186. * If not enabled, CCM operations in supervisor/user mode will
  187. * trigger a *illegal intruction* exception, access to CC_sCMD
  188. * and CC_uCMD register is also forbidden.
  189. * \remarks
  190. * - This function can be called in M-Mode only.
  191. * \sa
  192. * - \ref EnableSUCCM
  193. */
  194. __STATIC_FORCEINLINE void DisableSUCCM(void)
  195. {
  196. __RV_CSR_CLEAR(CSR_CCM_SUEN, CCM_SUEN_SUEN_Msk);
  197. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  198. SMPCC_CMD->CC_CTRL &= ~_VAL2FLD(SMPCC_CMD_CTRL_SUP_EN, SMPCC_CMD_CTRL_SUP_EN_DISABLE) &
  199. ~_VAL2FLD(SMPCC_CMD_CTRL_USE_EN, SMPCC_CMD_CTRL_USE_EN_DISABLE);
  200. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  201. }
  202. /**
  203. * \brief Flush pipeline after CCM operation
  204. * \details
  205. * This function is used to flush pipeline after CCM operations
  206. * on Cache, it will ensure latest instructions or data can be
  207. * seen by pipeline.
  208. * \remarks
  209. * - This function can be called in M/S/U-Mode only.
  210. */
  211. __STATIC_FORCEINLINE void FlushPipeCCM(void)
  212. {
  213. __RV_CSR_WRITE(CSR_CCM_FPIPE, 0x1);
  214. }
  215. /** @} */ /* End of Doxygen Group NMSIS_Core_Cache */
  216. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  217. /**
  218. * \ingroup NMSIS_Core_CCache
  219. * @{
  220. */
  221. /**
  222. * \brief Lock one Cluster Cache line specified by address in M-Mode
  223. * \details
  224. * This function lock one Cluster Cache line specified by the address.
  225. * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  226. * \remarks
  227. * This function must be executed in M-Mode only.
  228. * \param [in] addr start address to be locked
  229. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  230. */
  231. __STATIC_INLINE unsigned long MLockCCacheLine(unsigned long addr)
  232. {
  233. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  234. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_LOCK);
  235. FlushPipeCCM();
  236. __RWMB();
  237. return __RV_CSR_READ(CSR_CCM_MDATA);
  238. }
  239. /**
  240. * \brief Lock several Cluster Cache lines specified by address in M-Mode
  241. * \details
  242. * This function lock several Cluster Cache lines specified by the address
  243. * and line count.
  244. * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  245. * \remarks
  246. * This function must be executed in M-Mode only.
  247. * \param [in] addr start address to be locked
  248. * \param [in] cnt count of cache lines to be locked
  249. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  250. */
  251. __STATIC_INLINE unsigned long MLockCCacheLines(unsigned long addr, unsigned long cnt)
  252. {
  253. if (cnt > 0) {
  254. unsigned long i;
  255. unsigned long fail_info = CCM_OP_SUCCESS;
  256. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  257. for (i = 0; i < cnt; i++) {
  258. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_LOCK);
  259. FlushPipeCCM();
  260. __RWMB();
  261. fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
  262. if (CCM_OP_SUCCESS != fail_info) {
  263. return fail_info;
  264. }
  265. }
  266. }
  267. return CCM_OP_SUCCESS;
  268. }
  269. /**
  270. * \brief Lock one Cluster Cache line specified by address in S-Mode
  271. * \details
  272. * This function lock one Cluster Cache line specified by the address.
  273. * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  274. * \remarks
  275. * This function must be executed in M/S-Mode only.
  276. * \param [in] addr start address to be locked
  277. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  278. */
  279. __STATIC_INLINE unsigned long SLockCCacheLine(unsigned long addr)
  280. {
  281. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  282. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_LOCK);
  283. FlushPipeCCM();
  284. __RWMB();
  285. return __RV_CSR_READ(CSR_CCM_SDATA);
  286. }
  287. /**
  288. * \brief Lock several Cluster Cache lines specified by address in S-Mode
  289. * \details
  290. * This function lock several Cluster Cache lines specified by the address
  291. * and line count.
  292. * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  293. * \remarks
  294. * This function must be executed in M/S-Mode only.
  295. * \param [in] addr start address to be locked
  296. * \param [in] cnt count of cache lines to be locked
  297. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  298. */
  299. __STATIC_INLINE unsigned long SLockCCacheLines(unsigned long addr, unsigned long cnt)
  300. {
  301. if (cnt > 0) {
  302. unsigned long i;
  303. unsigned long fail_info = CCM_OP_SUCCESS;
  304. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  305. for (i = 0; i < cnt; i++) {
  306. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_LOCK);
  307. FlushPipeCCM();
  308. __RWMB();
  309. fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
  310. if (CCM_OP_SUCCESS != fail_info) {
  311. return fail_info;
  312. }
  313. }
  314. }
  315. return CCM_OP_SUCCESS;
  316. }
  317. /**
  318. * \brief Lock one Cluster Cache line specified by address in U-Mode
  319. * \details
  320. * This function lock one Cluster Cache line specified by the address.
  321. * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  322. * \remarks
  323. * This function must be executed in M/S/U-Mode only.
  324. * \param [in] addr start address to be locked
  325. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  326. */
  327. __STATIC_INLINE unsigned long ULockCCacheLine(unsigned long addr)
  328. {
  329. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  330. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_LOCK);
  331. FlushPipeCCM();
  332. __RWMB();
  333. return __RV_CSR_READ(CSR_CCM_UDATA);
  334. }
  335. /**
  336. * \brief Lock several Cluster Cache lines specified by address in U-Mode
  337. * \details
  338. * This function lock several Cluster Cache lines specified by the address
  339. * and line count.
  340. * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  341. * \remarks
  342. * This function must be executed in M/S/U-Mode only.
  343. * \param [in] addr start address to be locked
  344. * \param [in] cnt count of cache lines to be locked
  345. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  346. */
  347. __STATIC_INLINE unsigned long ULockCCacheLines(unsigned long addr, unsigned long cnt)
  348. {
  349. if (cnt > 0) {
  350. unsigned long i;
  351. unsigned long fail_info = CCM_OP_SUCCESS;
  352. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  353. for (i = 0; i < cnt; i++) {
  354. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_LOCK);
  355. FlushPipeCCM();
  356. __RWMB();
  357. fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
  358. if (CCM_OP_SUCCESS != fail_info) {
  359. return fail_info;
  360. }
  361. }
  362. }
  363. return CCM_OP_SUCCESS;
  364. }
  365. /**
  366. * \brief Unlock one Cluster Cache line specified by address in M-Mode
  367. * \details
  368. * This function unlock one Cluster Cache line specified by the address.
  369. * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  370. * \remarks
  371. * This function must be executed in M-Mode only.
  372. * \param [in] addr start address to be unlocked
  373. */
  374. __STATIC_INLINE void MUnlockCCacheLine(unsigned long addr)
  375. {
  376. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  377. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_UNLOCK);
  378. FlushPipeCCM();
  379. __RWMB();
  380. }
  381. /**
  382. * \brief Unlock several Cluster Cache lines specified by address in M-Mode
  383. * \details
  384. * This function unlock several Cluster Cache lines specified
  385. * by the address and line count.
  386. * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  387. * \remarks
  388. * This function must be executed in M-Mode only.
  389. * \param [in] addr start address to be unlocked
  390. * \param [in] cnt count of cache lines to be unlocked
  391. */
  392. __STATIC_INLINE void MUnlockCCacheLines(unsigned long addr, unsigned long cnt)
  393. {
  394. if (cnt > 0) {
  395. unsigned long i;
  396. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  397. for (i = 0; i < cnt; i++) {
  398. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_UNLOCK);
  399. }
  400. FlushPipeCCM();
  401. __RWMB();
  402. }
  403. }
  404. /**
  405. * \brief Unlock one Cluster Cache line specified by address in S-Mode
  406. * \details
  407. * This function unlock one Cluster Cache line specified by the address.
  408. * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  409. * \remarks
  410. * This function must be executed in M/S-Mode only.
  411. * \param [in] addr start address to be unlocked
  412. */
  413. __STATIC_INLINE void SUnlockCCacheLine(unsigned long addr)
  414. {
  415. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  416. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_UNLOCK);
  417. FlushPipeCCM();
  418. __RWMB();
  419. }
  420. /**
  421. * \brief Unlock several Cluster Cache lines specified by address in S-Mode
  422. * \details
  423. * This function unlock several Cluster Cache lines specified
  424. * by the address and line count.
  425. * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  426. * \remarks
  427. * This function must be executed in M/S-Mode only.
  428. * \param [in] addr start address to be unlocked
  429. * \param [in] cnt count of cache lines to be unlocked
  430. */
  431. __STATIC_INLINE void SUnlockCCacheLines(unsigned long addr, unsigned long cnt)
  432. {
  433. if (cnt > 0) {
  434. unsigned long i;
  435. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  436. for (i = 0; i < cnt; i++) {
  437. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_UNLOCK);
  438. }
  439. FlushPipeCCM();
  440. __RWMB();
  441. }
  442. }
  443. /**
  444. * \brief Unlock one Cluster Cache line specified by address in U-Mode
  445. * \details
  446. * This function unlock one Cluster Cache line specified by the address.
  447. * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  448. * \remarks
  449. * This function must be executed in M/S/U-Mode only.
  450. * \param [in] addr start address to be unlocked
  451. */
  452. __STATIC_INLINE void UUnlockCCacheLine(unsigned long addr)
  453. {
  454. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  455. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_UNLOCK);
  456. FlushPipeCCM();
  457. __RWMB();
  458. }
  459. /**
  460. * \brief Unlock several Cluster Cache lines specified by address in U-Mode
  461. * \details
  462. * This function unlock several Cluster Cache lines specified
  463. * by the address and line count.
  464. * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  465. * \remarks
  466. * This function must be executed in M/S/U-Mode only.
  467. * \param [in] addr start address to be unlocked
  468. * \param [in] cnt count of cache lines to be unlocked
  469. */
  470. __STATIC_INLINE void UUnlockCCacheLines(unsigned long addr, unsigned long cnt)
  471. {
  472. if (cnt > 0) {
  473. unsigned long i;
  474. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  475. for (i = 0; i < cnt; i++) {
  476. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_UNLOCK);
  477. }
  478. FlushPipeCCM();
  479. __RWMB();
  480. }
  481. }
  482. /** @} */ /* End of Doxygen Group NMSIS_Core_CCache */
  483. #endif /* defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  484. #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
  485. #if defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1)
  486. /**
  487. * \defgroup NMSIS_Core_ICache I-Cache Functions
  488. * \ingroup NMSIS_Core_Cache
  489. * \brief Functions that configure Instruction Cache.
  490. * @{
  491. */
  492. /**
  493. * \brief Check ICache Unit Present or Not
  494. * \details
  495. * This function check icache unit present or not via mcfg_info csr
  496. * \remarks
  497. * - This function might not work for some old nuclei processors
  498. * - Please make sure the version of your nuclei processor contain ICACHE bit in mcfg_info
  499. * \return 1 if present otherwise 0
  500. */
  501. __STATIC_INLINE int32_t ICachePresent(void)
  502. {
  503. if (__RV_CSR_READ(CSR_MCFG_INFO) & MCFG_INFO_ICACHE) {
  504. return 1;
  505. }
  506. return 0;
  507. }
  508. /**
  509. * \brief Enable ICache
  510. * \details
  511. * This function enable I-Cache
  512. * \remarks
  513. * - This function can be called in M-Mode only.
  514. * - This \ref CSR_MCACHE_CTL register control I Cache enable.
  515. * \sa
  516. * - \ref DisableICache
  517. */
  518. __STATIC_FORCEINLINE void EnableICache(void)
  519. {
  520. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_EN);
  521. }
  522. /**
  523. * \brief Disable ICache
  524. * \details
  525. * This function Disable I-Cache
  526. * \remarks
  527. * - This function can be called in M-Mode only.
  528. * - This \ref CSR_MCACHE_CTL register control I Cache enable.
  529. * \sa
  530. * - \ref EnableICache
  531. */
  532. __STATIC_FORCEINLINE void DisableICache(void)
  533. {
  534. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_EN);
  535. }
  536. /**
  537. * \brief Enable ICache ECC
  538. * \details
  539. * This function enable I-Cache ECC
  540. * \remarks
  541. * - This function can be called in M-Mode only.
  542. * - This \ref CSR_MCACHE_CTL register control I Cache ECC enable.
  543. * \sa
  544. * - \ref DisableICacheECC
  545. */
  546. __STATIC_FORCEINLINE void EnableICacheECC(void)
  547. {
  548. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN);
  549. }
  550. /**
  551. * \brief Disable ICache ECC
  552. * \details
  553. * This function disable I-Cache ECC
  554. * \remarks
  555. * - This function can be called in M-Mode only.
  556. * - This \ref CSR_MCACHE_CTL register control I Cache ECC enable.
  557. * \sa
  558. * - \ref EnableICacheECC
  559. */
  560. __STATIC_FORCEINLINE void DisableICacheECC(void)
  561. {
  562. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN);
  563. }
  564. #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
  565. /**
  566. * \brief Get I-Cache Information
  567. * \details
  568. * This function get I-Cache Information
  569. * \remarks
  570. * - This function can be called in M-Mode only.
  571. * - You can use this function in combination with cache lines operations
  572. * \sa
  573. * - \ref GetDCacheInfo
  574. */
  575. __STATIC_INLINE int32_t GetICacheInfo(CacheInfo_Type *info)
  576. {
  577. if (info == NULL) {
  578. return -1;
  579. }
  580. CSR_MICFGINFO_Type csr_ccfg;
  581. csr_ccfg.d = __RV_CSR_READ(CSR_MICFG_INFO);
  582. info->setperway = (1UL << csr_ccfg.b.set) << 3;
  583. info->ways = (1 + csr_ccfg.b.way);
  584. if (csr_ccfg.b.lsize == 0) {
  585. info->linesize = 0;
  586. } else {
  587. info->linesize = (1UL << (csr_ccfg.b.lsize - 1)) << 3;
  588. }
  589. info->size = info->setperway * info->ways * info->linesize;
  590. return 0;
  591. }
  592. /**
  593. * \brief Invalidate one I-Cache line specified by address in M-Mode
  594. * \details
  595. * This function unlock and invalidate one I-Cache line specified
  596. * by the address.
  597. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  598. * \remarks
  599. * This function must be executed in M-Mode only.
  600. * \param [in] addr start address to be invalidated
  601. */
  602. __STATIC_INLINE void MInvalICacheLine(unsigned long addr)
  603. {
  604. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  605. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
  606. FlushPipeCCM();
  607. __RWMB();
  608. }
  609. /**
  610. * \brief Invalidate several I-Cache lines specified by address in M-Mode
  611. * \details
  612. * This function unlock and invalidate several I-Cache lines specified
  613. * by the address and line count.
  614. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  615. * \remarks
  616. * This function must be executed in M-Mode only.
  617. * \param [in] addr start address to be invalidated
  618. * \param [in] cnt count of cache lines to be invalidated
  619. */
  620. __STATIC_INLINE void MInvalICacheLines(unsigned long addr, unsigned long cnt)
  621. {
  622. if (cnt > 0) {
  623. unsigned long i;
  624. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  625. for (i = 0; i < cnt; i++) {
  626. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
  627. }
  628. FlushPipeCCM();
  629. __RWMB();
  630. }
  631. }
  632. /**
  633. * \brief Invalidate one I-Cache line specified by address in S-Mode
  634. * \details
  635. * This function unlock and invalidate one I-Cache line specified
  636. * by the address.
  637. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  638. * \remarks
  639. * This function must be executed in M/S-Mode only.
  640. * \param [in] addr start address to be invalidated
  641. */
  642. __STATIC_INLINE void SInvalICacheLine(unsigned long addr)
  643. {
  644. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  645. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
  646. FlushPipeCCM();
  647. __RWMB();
  648. }
  649. /**
  650. * \brief Invalidate several I-Cache lines specified by address in S-Mode
  651. * \details
  652. * This function unlock and invalidate several I-Cache lines specified
  653. * by the address and line count.
  654. * Command \ref CCM_IC_INVAL 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. * \param [in] cnt count of cache lines to be invalidated
  659. */
  660. __STATIC_INLINE void SInvalICacheLines(unsigned long addr, unsigned long cnt)
  661. {
  662. if (cnt > 0) {
  663. unsigned long i;
  664. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  665. for (i = 0; i < cnt; i++) {
  666. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
  667. }
  668. FlushPipeCCM();
  669. __RWMB();
  670. }
  671. }
  672. /**
  673. * \brief Invalidate one I-Cache line specified by address in U-Mode
  674. * \details
  675. * This function unlock and invalidate one I-Cache line specified
  676. * by the address.
  677. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  678. * \remarks
  679. * This function must be executed in M/S/U-Mode only.
  680. * \param [in] addr start address to be invalidated
  681. */
  682. __STATIC_INLINE void UInvalICacheLine(unsigned long addr)
  683. {
  684. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  685. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
  686. FlushPipeCCM();
  687. __RWMB();
  688. }
  689. /**
  690. * \brief Invalidate several I-Cache lines specified by address in U-Mode
  691. * \details
  692. * This function unlock and invalidate several I-Cache lines specified
  693. * by the address and line count.
  694. * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  695. * \remarks
  696. * This function must be executed in M/S/U-Mode only.
  697. * \param [in] addr start address to be invalidated
  698. * \param [in] cnt count of cache lines to be invalidated
  699. */
  700. __STATIC_INLINE void UInvalICacheLines(unsigned long addr, unsigned long cnt)
  701. {
  702. if (cnt > 0) {
  703. unsigned long i;
  704. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  705. for (i = 0; i < cnt; i++) {
  706. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
  707. }
  708. FlushPipeCCM();
  709. __RWMB();
  710. }
  711. }
  712. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  713. /**
  714. * \brief Invalidate one I-Cache and Cluster Cache line specified by address in M-Mode
  715. * \details
  716. * This function unlock and invalidate one I-Cache line and corresponding Cluster Cache line
  717. * specified by the address.
  718. * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_MCOMMAND.
  719. * \remarks
  720. * This function must be executed in M-Mode only.
  721. * \param [in] addr start address to be invalidated
  722. */
  723. __STATIC_INLINE void MInvalICacheCCacheLine(unsigned long addr)
  724. {
  725. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  726. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
  727. /* Trigger Cluster Cache invalidation by DC_INVAL */
  728. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
  729. FlushPipeCCM();
  730. __RWMB();
  731. }
  732. /**
  733. * \brief Invalidate several I-Cache and Cluster Cache lines specified by address in M-Mode
  734. * \details
  735. * This function unlock and invalidate several I-Cache lines and corresponding Cluster Cache lines
  736. * specified by the address and line count.
  737. * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_MCOMMAND.
  738. * \remarks
  739. * This function must be executed in M-Mode only.
  740. * \param [in] addr start address to be invalidated
  741. * \param [in] cnt count of cache lines to be invalidated
  742. */
  743. __STATIC_INLINE void MInvalICacheCCacheLines(unsigned long addr, unsigned long cnt)
  744. {
  745. if (cnt > 0) {
  746. unsigned long i;
  747. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  748. for (i = 0; i < cnt; i++) {
  749. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
  750. /* Trigger Cluster Cache invalidation by DC_INVAL */
  751. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
  752. }
  753. FlushPipeCCM();
  754. __RWMB();
  755. }
  756. }
  757. /**
  758. * \brief Invalidate one I-Cache and Cluster Cache line specified by address in S-Mode
  759. * \details
  760. * This function unlock and invalidate one I-Cache line and corresponding Cluster Cache line
  761. * specified by the address.
  762. * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_SCOMMAND.
  763. * \remarks
  764. * This function must be executed in M/S-Mode only.
  765. * \param [in] addr start address to be invalidated
  766. */
  767. __STATIC_INLINE void SInvalICacheCCacheLine(unsigned long addr)
  768. {
  769. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  770. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
  771. /* Trigger Cluster Cache invalidation by DC_INVAL */
  772. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
  773. FlushPipeCCM();
  774. __RWMB();
  775. }
  776. /**
  777. * \brief Invalidate several I-Cache and Cluster Cache lines specified by address in S-Mode
  778. * \details
  779. * This function unlock and invalidate several I-Cache lines and corresponding Cluster Cache lines
  780. * specified by the address and line count.
  781. * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_SCOMMAND.
  782. * \remarks
  783. * This function must be executed in M/S-Mode only.
  784. * \param [in] addr start address to be invalidated
  785. * \param [in] cnt count of cache lines to be invalidated
  786. */
  787. __STATIC_INLINE void SInvalICacheCCacheLines(unsigned long addr, unsigned long cnt)
  788. {
  789. if (cnt > 0) {
  790. unsigned long i;
  791. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  792. for (i = 0; i < cnt; i++) {
  793. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
  794. /* Trigger Cluster Cache invalidation by DC_INVAL */
  795. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
  796. }
  797. FlushPipeCCM();
  798. __RWMB();
  799. }
  800. }
  801. /**
  802. * \brief Invalidate one I-Cache and Cluster Cache line specified by address in U-Mode
  803. * \details
  804. * This function unlock and invalidate one I-Cache line and corresponding Cluster Cache line
  805. * specified by the address.
  806. * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_UCOMMAND.
  807. * \remarks
  808. * This function must be executed in M/S/U-Mode only.
  809. * \param [in] addr start address to be invalidated
  810. */
  811. __STATIC_INLINE void UInvalICacheCCacheLine(unsigned long addr)
  812. {
  813. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  814. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
  815. /* Trigger Cluster Cache invalidation by DC_INVAL */
  816. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
  817. FlushPipeCCM();
  818. __RWMB();
  819. }
  820. /**
  821. * \brief Invalidate several I-Cache and Cluster Cache lines specified by address in U-Mode
  822. * \details
  823. * This function unlock and invalidate several I-Cache lines and corresponding Cluster Cache lines
  824. * specified by the address and line count.
  825. * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_UCOMMAND.
  826. * \remarks
  827. * This function must be executed in M/S/U-Mode only.
  828. * \param [in] addr start address to be invalidated
  829. * \param [in] cnt count of cache lines to be invalidated
  830. */
  831. __STATIC_INLINE void UInvalICacheCCacheLines(unsigned long addr, unsigned long cnt)
  832. {
  833. if (cnt > 0) {
  834. unsigned long i;
  835. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  836. for (i = 0; i < cnt; i++) {
  837. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
  838. /* Trigger Cluster Cache invalidation by DC_INVAL */
  839. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
  840. }
  841. FlushPipeCCM();
  842. __RWMB();
  843. }
  844. }
  845. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  846. /**
  847. * \brief Lock one I-Cache line specified by address in M-Mode
  848. * \details
  849. * This function lock one I-Cache line specified by the address.
  850. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  851. * \remarks
  852. * This function must be executed in M-Mode only.
  853. * \param [in] addr start address to be locked
  854. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  855. */
  856. __STATIC_INLINE unsigned long MLockICacheLine(unsigned long addr)
  857. {
  858. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  859. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_LOCK);
  860. FlushPipeCCM();
  861. __RWMB();
  862. return __RV_CSR_READ(CSR_CCM_MDATA);
  863. }
  864. /**
  865. * \brief Lock several I-Cache lines specified by address in M-Mode
  866. * \details
  867. * This function lock several I-Cache lines specified by the address
  868. * and line count.
  869. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  870. * \remarks
  871. * This function must be executed in M-Mode only.
  872. * \param [in] addr start address to be locked
  873. * \param [in] cnt count of cache lines to be locked
  874. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  875. */
  876. __STATIC_INLINE unsigned long MLockICacheLines(unsigned long addr, unsigned long cnt)
  877. {
  878. if (cnt > 0) {
  879. unsigned long i;
  880. unsigned long fail_info = CCM_OP_SUCCESS;
  881. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  882. for (i = 0; i < cnt; i++) {
  883. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_LOCK);
  884. FlushPipeCCM();
  885. __RWMB();
  886. fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
  887. if (CCM_OP_SUCCESS != fail_info) {
  888. return fail_info;
  889. }
  890. }
  891. }
  892. return CCM_OP_SUCCESS;
  893. }
  894. /**
  895. * \brief Lock one I-Cache line specified by address in S-Mode
  896. * \details
  897. * This function lock one I-Cache line specified by the address.
  898. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  899. * \remarks
  900. * This function must be executed in M/S-Mode only.
  901. * \param [in] addr start address to be locked
  902. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  903. */
  904. __STATIC_INLINE unsigned long SLockICacheLine(unsigned long addr)
  905. {
  906. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  907. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_LOCK);
  908. FlushPipeCCM();
  909. __RWMB();
  910. return __RV_CSR_READ(CSR_CCM_SDATA);
  911. }
  912. /**
  913. * \brief Lock several I-Cache lines specified by address in S-Mode
  914. * \details
  915. * This function lock several I-Cache lines specified by the address
  916. * and line count.
  917. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  918. * \remarks
  919. * This function must be executed in M/S-Mode only.
  920. * \param [in] addr start address to be locked
  921. * \param [in] cnt count of cache lines to be locked
  922. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  923. */
  924. __STATIC_INLINE unsigned long SLockICacheLines(unsigned long addr, unsigned long cnt)
  925. {
  926. if (cnt > 0) {
  927. unsigned long i;
  928. unsigned long fail_info = CCM_OP_SUCCESS;
  929. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  930. for (i = 0; i < cnt; i++) {
  931. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_LOCK);
  932. FlushPipeCCM();
  933. __RWMB();
  934. fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
  935. if (CCM_OP_SUCCESS != fail_info) {
  936. return fail_info;
  937. }
  938. }
  939. }
  940. return CCM_OP_SUCCESS;
  941. }
  942. /**
  943. * \brief Lock one I-Cache line specified by address in U-Mode
  944. * \details
  945. * This function lock one I-Cache line specified by the address.
  946. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  947. * \remarks
  948. * This function must be executed in M/S/U-Mode only.
  949. * \param [in] addr start address to be locked
  950. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  951. */
  952. __STATIC_INLINE unsigned long ULockICacheLine(unsigned long addr)
  953. {
  954. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  955. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_LOCK);
  956. FlushPipeCCM();
  957. __RWMB();
  958. return __RV_CSR_READ(CSR_CCM_UDATA);
  959. }
  960. /**
  961. * \brief Lock several I-Cache lines specified by address in U-Mode
  962. * \details
  963. * This function lock several I-Cache lines specified by the address
  964. * and line count.
  965. * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  966. * \remarks
  967. * This function must be executed in M/S/U-Mode only.
  968. * \param [in] addr start address to be locked
  969. * \param [in] cnt count of cache lines to be locked
  970. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  971. */
  972. __STATIC_INLINE unsigned long ULockICacheLines(unsigned long addr, unsigned long cnt)
  973. {
  974. if (cnt > 0) {
  975. unsigned long i;
  976. unsigned long fail_info = CCM_OP_SUCCESS;
  977. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  978. for (i = 0; i < cnt; i++) {
  979. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_LOCK);
  980. FlushPipeCCM();
  981. __RWMB();
  982. fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
  983. if (CCM_OP_SUCCESS != fail_info) {
  984. return fail_info;
  985. }
  986. }
  987. }
  988. return CCM_OP_SUCCESS;
  989. }
  990. /**
  991. * \brief Unlock one I-Cache line specified by address in M-Mode
  992. * \details
  993. * This function unlock one I-Cache line specified by the address.
  994. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  995. * \remarks
  996. * This function must be executed in M-Mode only.
  997. * \param [in] addr start address to be unlocked
  998. */
  999. __STATIC_INLINE void MUnlockICacheLine(unsigned long addr)
  1000. {
  1001. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1002. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_UNLOCK);
  1003. FlushPipeCCM();
  1004. __RWMB();
  1005. }
  1006. /**
  1007. * \brief Unlock several I-Cache lines specified by address in M-Mode
  1008. * \details
  1009. * This function unlock several I-Cache lines specified
  1010. * by the address and line count.
  1011. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1012. * \remarks
  1013. * This function must be executed in M-Mode only.
  1014. * \param [in] addr start address to be unlocked
  1015. * \param [in] cnt count of cache lines to be unlocked
  1016. */
  1017. __STATIC_INLINE void MUnlockICacheLines(unsigned long addr, unsigned long cnt)
  1018. {
  1019. if (cnt > 0) {
  1020. unsigned long i;
  1021. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1022. for (i = 0; i < cnt; i++) {
  1023. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_UNLOCK);
  1024. }
  1025. FlushPipeCCM();
  1026. __RWMB();
  1027. }
  1028. }
  1029. /**
  1030. * \brief Unlock one I-Cache line specified by address in S-Mode
  1031. * \details
  1032. * This function unlock one I-Cache line specified by the address.
  1033. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1034. * \remarks
  1035. * This function must be executed in M/S-Mode only.
  1036. * \param [in] addr start address to be unlocked
  1037. */
  1038. __STATIC_INLINE void SUnlockICacheLine(unsigned long addr)
  1039. {
  1040. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1041. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_UNLOCK);
  1042. FlushPipeCCM();
  1043. __RWMB();
  1044. }
  1045. /**
  1046. * \brief Unlock several I-Cache lines specified by address in S-Mode
  1047. * \details
  1048. * This function unlock several I-Cache lines specified
  1049. * by the address and line count.
  1050. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1051. * \remarks
  1052. * This function must be executed in M/S-Mode only.
  1053. * \param [in] addr start address to be unlocked
  1054. * \param [in] cnt count of cache lines to be unlocked
  1055. */
  1056. __STATIC_INLINE void SUnlockICacheLines(unsigned long addr, unsigned long cnt)
  1057. {
  1058. if (cnt > 0) {
  1059. unsigned long i;
  1060. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1061. for (i = 0; i < cnt; i++) {
  1062. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_UNLOCK);
  1063. }
  1064. FlushPipeCCM();
  1065. __RWMB();
  1066. }
  1067. }
  1068. /**
  1069. * \brief Unlock one I-Cache line specified by address in U-Mode
  1070. * \details
  1071. * This function unlock one I-Cache line specified by the address.
  1072. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1073. * \remarks
  1074. * This function must be executed in M/S/U-Mode only.
  1075. * \param [in] addr start address to be unlocked
  1076. */
  1077. __STATIC_INLINE void UUnlockICacheLine(unsigned long addr)
  1078. {
  1079. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1080. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_UNLOCK);
  1081. FlushPipeCCM();
  1082. __RWMB();
  1083. }
  1084. /**
  1085. * \brief Unlock several I-Cache lines specified by address in U-Mode
  1086. * \details
  1087. * This function unlock several I-Cache lines specified
  1088. * by the address and line count.
  1089. * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1090. * \remarks
  1091. * This function must be executed in M/S/U-Mode only.
  1092. * \param [in] addr start address to be unlocked
  1093. * \param [in] cnt count of cache lines to be unlocked
  1094. */
  1095. __STATIC_INLINE void UUnlockICacheLines(unsigned long addr, unsigned long cnt)
  1096. {
  1097. if (cnt > 0) {
  1098. unsigned long i;
  1099. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1100. for (i = 0; i < cnt; i++) {
  1101. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_UNLOCK);
  1102. }
  1103. FlushPipeCCM();
  1104. __RWMB();
  1105. }
  1106. }
  1107. /**
  1108. * \brief Invalidate all I-Cache lines in M-Mode
  1109. * \details
  1110. * This function invalidate all I-Cache lines.
  1111. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  1112. * \remarks
  1113. * This function must be executed in M-Mode only.
  1114. * \param [in] addr start address to be invalidated
  1115. */
  1116. __STATIC_INLINE void MInvalICache(void)
  1117. {
  1118. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL_ALL);
  1119. FlushPipeCCM();
  1120. __RWMB();
  1121. }
  1122. /**
  1123. * \brief Invalidate all I-Cache lines in S-Mode
  1124. * \details
  1125. * This function invalidate all I-Cache lines.
  1126. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  1127. * \remarks
  1128. * This function must be executed in M/S-Mode only.
  1129. * \param [in] addr start address to be invalidated
  1130. */
  1131. __STATIC_INLINE void SInvalICache(void)
  1132. {
  1133. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL_ALL);
  1134. FlushPipeCCM();
  1135. __RWMB();
  1136. }
  1137. /**
  1138. * \brief Invalidate all I-Cache lines in U-Mode
  1139. * \details
  1140. * This function invalidate all I-Cache lines.
  1141. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  1142. * \remarks
  1143. * This function must be executed in M/S/U-Mode only.
  1144. * \param [in] addr start address to be invalidated
  1145. */
  1146. __STATIC_INLINE void UInvalICache(void)
  1147. {
  1148. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL_ALL);
  1149. FlushPipeCCM();
  1150. __RWMB();
  1151. }
  1152. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  1153. /**
  1154. * \brief Invalidate all Cluster Cache in M-Mode
  1155. * \details
  1156. * This function invalidate all Cluster Cache.
  1157. * \remarks
  1158. * This function must be executed in M-Mode only.
  1159. */
  1160. __STATIC_INLINE void MInvalCCache(void)
  1161. {
  1162. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  1163. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  1164. __RWMB();
  1165. }
  1166. /**
  1167. * \brief Invalidate all Cluster Cache in S-Mode
  1168. * \details
  1169. * This function invalidate all Cluster Cache.
  1170. * \remarks
  1171. * This function must be executed in M/S-Mode only.
  1172. */
  1173. __STATIC_INLINE void SInvalCCache(void)
  1174. {
  1175. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  1176. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  1177. __RWMB();
  1178. }
  1179. /**
  1180. * \brief Invalidate all Cluster Cache in U-Mode
  1181. * \details
  1182. * This function invalidate all Cluster Cache.
  1183. * \remarks
  1184. * This function must be executed in M/S/U-Mode only.
  1185. */
  1186. __STATIC_INLINE void UInvalCCache(void)
  1187. {
  1188. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  1189. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  1190. __RWMB();
  1191. }
  1192. /**
  1193. * \brief Invalidate all I-Cache and Cluster Cache in M-Mode
  1194. * \details
  1195. * This function unlock and invalidate all I-Cache and Cluster Cache.
  1196. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  1197. * \remarks
  1198. * This function must be executed in M-Mode only.
  1199. */
  1200. __STATIC_INLINE void MInvalICacheCCache(void)
  1201. {
  1202. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL_ALL);
  1203. FlushPipeCCM();
  1204. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  1205. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  1206. __RWMB();
  1207. }
  1208. /**
  1209. * \brief Invalidate all I-Cache and Cluster Cache in S-Mode
  1210. * \details
  1211. * This function unlock and invalidate all I-Cache and Cluster Cache.
  1212. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  1213. * \remarks
  1214. * This function must be executed in M/S-Mode only.
  1215. */
  1216. __STATIC_INLINE void SInvalICacheCCache(void)
  1217. {
  1218. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL_ALL);
  1219. FlushPipeCCM();
  1220. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  1221. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  1222. __RWMB();
  1223. }
  1224. /**
  1225. * \brief Invalidate all I-Cache and Cluster Cache in U-Mode
  1226. * \details
  1227. * This function unlock and invalidate all I-Cache and Cluster Cache.
  1228. * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  1229. * \remarks
  1230. * This function must be executed in M/S/U-Mode only.
  1231. */
  1232. __STATIC_INLINE void UInvalICacheCCache(void)
  1233. {
  1234. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL_ALL);
  1235. FlushPipeCCM();
  1236. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  1237. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  1238. __RWMB();
  1239. }
  1240. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  1241. #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
  1242. /** @} */ /* End of Doxygen Group NMSIS_Core_ICache */
  1243. #endif /* defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1) */
  1244. #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1)
  1245. /**
  1246. * \defgroup NMSIS_Core_DCache D-Cache Functions
  1247. * \ingroup NMSIS_Core_Cache
  1248. * \brief Functions that configure Data Cache.
  1249. * @{
  1250. */
  1251. /**
  1252. * \brief Check DCache Unit Present or Not
  1253. * \details
  1254. * This function check dcache unit present or not via mcfg_info csr
  1255. * \remarks
  1256. * - This function might not work for some old nuclei processors
  1257. * - Please make sure the version of your nuclei processor contain DCACHE bit in mcfg_info
  1258. * \return 1 if present otherwise 0
  1259. */
  1260. __STATIC_INLINE int32_t DCachePresent(void)
  1261. {
  1262. if (__RV_CSR_READ(CSR_MCFG_INFO) & MCFG_INFO_DCACHE) {
  1263. return 1;
  1264. }
  1265. return 0;
  1266. }
  1267. /**
  1268. * \brief Enable DCache
  1269. * \details
  1270. * This function enable D-Cache
  1271. * \remarks
  1272. * - This function can be called in M-Mode only.
  1273. * - This \ref CSR_MCACHE_CTL register control D Cache enable.
  1274. * \sa
  1275. * - \ref DisableDCache
  1276. */
  1277. __STATIC_FORCEINLINE void EnableDCache(void)
  1278. {
  1279. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_EN);
  1280. }
  1281. /**
  1282. * \brief Disable DCache
  1283. * \details
  1284. * This function Disable D-Cache
  1285. * \remarks
  1286. * - This function can be called in M-Mode only.
  1287. * - This \ref CSR_MCACHE_CTL register control D Cache enable.
  1288. * \sa
  1289. * - \ref EnableDCache
  1290. */
  1291. __STATIC_FORCEINLINE void DisableDCache(void)
  1292. {
  1293. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_EN);
  1294. }
  1295. /**
  1296. * \brief Enable DCache ECC
  1297. * \details
  1298. * This function enable D-Cache ECC
  1299. * \remarks
  1300. * - This function can be called in M-Mode only.
  1301. * - This \ref CSR_MCACHE_CTL register control D Cache ECC enable.
  1302. * \sa
  1303. * - \ref DisableDCacheECC
  1304. */
  1305. __STATIC_FORCEINLINE void EnableDCacheECC(void)
  1306. {
  1307. __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN);
  1308. }
  1309. /**
  1310. * \brief Disable DCache ECC
  1311. * \details
  1312. * This function disable D-Cache ECC
  1313. * \remarks
  1314. * - This function can be called in M-Mode only.
  1315. * - This \ref CSR_MCACHE_CTL register control D Cache ECC enable.
  1316. * \sa
  1317. * - \ref EnableDCacheECC
  1318. */
  1319. __STATIC_FORCEINLINE void DisableDCacheECC(void)
  1320. {
  1321. __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN);
  1322. }
  1323. #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
  1324. /**
  1325. * \brief Get D-Cache Information
  1326. * \details
  1327. * This function get D-Cache Information
  1328. * \remarks
  1329. * - This function can be called in M-Mode only.
  1330. * - You can use this function in combination with cache lines operations
  1331. * \sa
  1332. * - \ref GetICacheInfo
  1333. */
  1334. __STATIC_INLINE int32_t GetDCacheInfo(CacheInfo_Type *info)
  1335. {
  1336. if (info == NULL) {
  1337. return -1;
  1338. }
  1339. CSR_MDCFGINFO_Type csr_ccfg;
  1340. csr_ccfg.d = __RV_CSR_READ(CSR_MDCFG_INFO);
  1341. info->setperway = (1UL << csr_ccfg.b.set) << 3;
  1342. info->ways = (1 + csr_ccfg.b.way);
  1343. if (csr_ccfg.b.lsize == 0) {
  1344. info->linesize = 0;
  1345. } else {
  1346. info->linesize = (1UL << (csr_ccfg.b.lsize - 1)) << 3;
  1347. }
  1348. info->size = info->setperway * info->ways * info->linesize;
  1349. return 0;
  1350. }
  1351. /**
  1352. * \brief Invalidate one D-Cache line specified by address in M-Mode
  1353. * \details
  1354. * This function unlock and invalidate one D-Cache line specified
  1355. * by the address.
  1356. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1357. * \remarks
  1358. * This function must be executed in M-Mode only.
  1359. * \param [in] addr start address to be invalidated
  1360. */
  1361. __STATIC_INLINE void MInvalDCacheLine(unsigned long addr)
  1362. {
  1363. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1364. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
  1365. FlushPipeCCM();
  1366. __RWMB();
  1367. }
  1368. /**
  1369. * \brief Invalidate several D-Cache lines specified by address in M-Mode
  1370. * \details
  1371. * This function unlock and invalidate several D-Cache lines specified
  1372. * by the address and line count.
  1373. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1374. * \remarks
  1375. * This function must be executed in M-Mode only.
  1376. * \param [in] addr start address to be invalidated
  1377. * \param [in] cnt count of cache lines to be invalidated
  1378. */
  1379. __STATIC_INLINE void MInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1380. {
  1381. if (cnt > 0) {
  1382. unsigned long i;
  1383. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1384. for (i = 0; i < cnt; i++) {
  1385. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
  1386. }
  1387. FlushPipeCCM();
  1388. __RWMB();
  1389. }
  1390. }
  1391. /**
  1392. * \brief Invalidate one D-Cache line specified by address in S-Mode
  1393. * \details
  1394. * This function unlock and invalidate one D-Cache line specified
  1395. * by the address.
  1396. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1397. * \remarks
  1398. * This function must be executed in M/S-Mode only.
  1399. * \param [in] addr start address to be invalidated
  1400. */
  1401. __STATIC_INLINE void SInvalDCacheLine(unsigned long addr)
  1402. {
  1403. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1404. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
  1405. FlushPipeCCM();
  1406. __RWMB();
  1407. }
  1408. /**
  1409. * \brief Invalidate several D-Cache lines specified by address in S-Mode
  1410. * \details
  1411. * This function unlock and invalidate several D-Cache lines specified
  1412. * by the address and line count.
  1413. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  1414. * \remarks
  1415. * This function must be executed in M/S-Mode only.
  1416. * \param [in] addr start address to be invalidated
  1417. * \param [in] cnt count of cache lines to be invalidated
  1418. */
  1419. __STATIC_INLINE void SInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1420. {
  1421. if (cnt > 0) {
  1422. unsigned long i;
  1423. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1424. for (i = 0; i < cnt; i++) {
  1425. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
  1426. }
  1427. FlushPipeCCM();
  1428. __RWMB();
  1429. }
  1430. }
  1431. /**
  1432. * \brief Invalidate one D-Cache line specified by address in U-Mode
  1433. * \details
  1434. * This function unlock and invalidate one D-Cache line specified
  1435. * by the address.
  1436. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  1437. * \remarks
  1438. * This function must be executed in M/S/U-Mode only.
  1439. * \param [in] addr start address to be invalidated
  1440. */
  1441. __STATIC_INLINE void UInvalDCacheLine(unsigned long addr)
  1442. {
  1443. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1444. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
  1445. FlushPipeCCM();
  1446. __RWMB();
  1447. }
  1448. /**
  1449. * \brief Invalidate several D-Cache lines specified by address in U-Mode
  1450. * \details
  1451. * This function unlock and invalidate several D-Cache lines specified
  1452. * by the address and line count.
  1453. * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  1454. * \remarks
  1455. * This function must be executed in M/S/U-Mode only.
  1456. * \param [in] addr start address to be invalidated
  1457. * \param [in] cnt count of cache lines to be invalidated
  1458. */
  1459. __STATIC_INLINE void UInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1460. {
  1461. if (cnt > 0) {
  1462. unsigned long i;
  1463. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1464. for (i = 0; i < cnt; i++) {
  1465. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
  1466. }
  1467. FlushPipeCCM();
  1468. __RWMB();
  1469. }
  1470. }
  1471. /**
  1472. * \brief Flush one D-Cache line specified by address in M-Mode
  1473. * \details
  1474. * This function flush one D-Cache line specified by the address.
  1475. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_MCOMMAND.
  1476. * \remarks
  1477. * This function must be executed in M-Mode only.
  1478. * \param [in] addr start address to be flushed
  1479. */
  1480. __STATIC_INLINE void MFlushDCacheLine(unsigned long addr)
  1481. {
  1482. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1483. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB);
  1484. FlushPipeCCM();
  1485. __RWMB();
  1486. }
  1487. /**
  1488. * \brief Flush several D-Cache lines specified by address in M-Mode
  1489. * \details
  1490. * This function flush several D-Cache lines specified
  1491. * by the address and line count.
  1492. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_MCOMMAND.
  1493. * \remarks
  1494. * This function must be executed in M-Mode only.
  1495. * \param [in] addr start address to be flushed
  1496. * \param [in] cnt count of cache lines to be flushed
  1497. */
  1498. __STATIC_INLINE void MFlushDCacheLines(unsigned long addr, unsigned long cnt)
  1499. {
  1500. if (cnt > 0) {
  1501. unsigned long i;
  1502. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1503. for (i = 0; i < cnt; i++) {
  1504. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB);
  1505. }
  1506. FlushPipeCCM();
  1507. __RWMB();
  1508. }
  1509. }
  1510. /**
  1511. * \brief Flush one D-Cache line specified by address in S-Mode
  1512. * \details
  1513. * This function flush one D-Cache line specified by the address.
  1514. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_SCOMMAND.
  1515. * \remarks
  1516. * This function must be executed in M/S-Mode only.
  1517. * \param [in] addr start address to be flushed
  1518. */
  1519. __STATIC_INLINE void SFlushDCacheLine(unsigned long addr)
  1520. {
  1521. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1522. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB);
  1523. FlushPipeCCM();
  1524. __RWMB();
  1525. }
  1526. /**
  1527. * \brief Flush several D-Cache lines specified by address in S-Mode
  1528. * \details
  1529. * This function flush several D-Cache lines specified
  1530. * by the address and line count.
  1531. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_SCOMMAND.
  1532. * \remarks
  1533. * This function must be executed in M/S-Mode only.
  1534. * \param [in] addr start address to be flushed
  1535. * \param [in] cnt count of cache lines to be flushed
  1536. */
  1537. __STATIC_INLINE void SFlushDCacheLines(unsigned long addr, unsigned long cnt)
  1538. {
  1539. if (cnt > 0) {
  1540. unsigned long i;
  1541. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1542. for (i = 0; i < cnt; i++) {
  1543. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB);
  1544. }
  1545. FlushPipeCCM();
  1546. __RWMB();
  1547. }
  1548. }
  1549. /**
  1550. * \brief Flush one D-Cache line specified by address in U-Mode
  1551. * \details
  1552. * This function flush one D-Cache line specified by the address.
  1553. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_UCOMMAND.
  1554. * \remarks
  1555. * This function must be executed in M/S/U-Mode only.
  1556. * \param [in] addr start address to be flushed
  1557. */
  1558. __STATIC_INLINE void UFlushDCacheLine(unsigned long addr)
  1559. {
  1560. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1561. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB);
  1562. FlushPipeCCM();
  1563. __RWMB();
  1564. }
  1565. /**
  1566. * \brief Flush several D-Cache lines specified by address in U-Mode
  1567. * \details
  1568. * This function flush several D-Cache lines specified
  1569. * by the address and line count.
  1570. * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_UCOMMAND.
  1571. * \remarks
  1572. * This function must be executed in M/S/U-Mode only.
  1573. * \param [in] addr start address to be flushed
  1574. * \param [in] cnt count of cache lines to be flushed
  1575. */
  1576. __STATIC_INLINE void UFlushDCacheLines(unsigned long addr, unsigned long cnt)
  1577. {
  1578. if (cnt > 0) {
  1579. unsigned long i;
  1580. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1581. for (i = 0; i < cnt; i++) {
  1582. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB);
  1583. }
  1584. FlushPipeCCM();
  1585. __RWMB();
  1586. }
  1587. }
  1588. /**
  1589. * \brief Flush and invalidate one D-Cache line specified by address in M-Mode
  1590. * \details
  1591. * This function flush and invalidate one D-Cache line specified by the address.
  1592. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1593. * \remarks
  1594. * This function must be executed in M-Mode only.
  1595. * \param [in] addr start address to be flushed and invalidated
  1596. */
  1597. __STATIC_INLINE void MFlushInvalDCacheLine(unsigned long addr)
  1598. {
  1599. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1600. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL);
  1601. FlushPipeCCM();
  1602. __RWMB();
  1603. }
  1604. /**
  1605. * \brief Flush and invalidate several D-Cache lines specified by address in M-Mode
  1606. * \details
  1607. * This function flush and invalidate several D-Cache lines specified
  1608. * by the address and line count.
  1609. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_MCOMMAND.
  1610. * \remarks
  1611. * This function must be executed in M-Mode only.
  1612. * \param [in] addr start address to be flushed and invalidated
  1613. * \param [in] cnt count of cache lines to be flushed and invalidated
  1614. */
  1615. __STATIC_INLINE void MFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1616. {
  1617. if (cnt > 0) {
  1618. unsigned long i;
  1619. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1620. for (i = 0; i < cnt; i++) {
  1621. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL);
  1622. }
  1623. FlushPipeCCM();
  1624. __RWMB();
  1625. }
  1626. }
  1627. /**
  1628. * \brief Flush and invalidate one D-Cache line specified by address in S-Mode
  1629. * \details
  1630. * This function flush and invalidate one D-Cache line specified by the address.
  1631. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  1632. * \remarks
  1633. * This function must be executed in M/S-Mode only.
  1634. * \param [in] addr start address to be flushed and invalidated
  1635. */
  1636. __STATIC_INLINE void SFlushInvalDCacheLine(unsigned long addr)
  1637. {
  1638. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1639. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL);
  1640. FlushPipeCCM();
  1641. __RWMB();
  1642. }
  1643. /**
  1644. * \brief Flush and invalidate several D-Cache lines specified by address in S-Mode
  1645. * \details
  1646. * This function flush and invalidate several D-Cache lines specified
  1647. * by the address and line count.
  1648. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_SCOMMAND.
  1649. * \remarks
  1650. * This function must be executed in M/S-Mode only.
  1651. * \param [in] addr start address to be flushed and invalidated
  1652. * \param [in] cnt count of cache lines to be flushed and invalidated
  1653. */
  1654. __STATIC_INLINE void SFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1655. {
  1656. if (cnt > 0) {
  1657. unsigned long i;
  1658. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1659. for (i = 0; i < cnt; i++) {
  1660. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL);
  1661. }
  1662. FlushPipeCCM();
  1663. __RWMB();
  1664. }
  1665. }
  1666. /**
  1667. * \brief Flush and invalidate one D-Cache line specified by address in U-Mode
  1668. * \details
  1669. * This function flush and invalidate one D-Cache line specified by the address.
  1670. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  1671. * \remarks
  1672. * This function must be executed in M/S/U-Mode only.
  1673. * \param [in] addr start address to be flushed and invalidated
  1674. */
  1675. __STATIC_INLINE void UFlushInvalDCacheLine(unsigned long addr)
  1676. {
  1677. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1678. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL);
  1679. FlushPipeCCM();
  1680. __RWMB();
  1681. }
  1682. /**
  1683. * \brief Flush and invalidate several D-Cache lines specified by address in U-Mode
  1684. * \details
  1685. * This function flush and invalidate several D-Cache lines specified
  1686. * by the address and line count.
  1687. * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_UCOMMAND.
  1688. * \remarks
  1689. * This function must be executed in M/S/U-Mode only.
  1690. * \param [in] addr start address to be flushed and invalidated
  1691. * \param [in] cnt count of cache lines to be flushed and invalidated
  1692. */
  1693. __STATIC_INLINE void UFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
  1694. {
  1695. if (cnt > 0) {
  1696. unsigned long i;
  1697. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1698. for (i = 0; i < cnt; i++) {
  1699. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL);
  1700. }
  1701. FlushPipeCCM();
  1702. __RWMB();
  1703. }
  1704. }
  1705. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  1706. /**
  1707. * \brief Invalidate one D-Cache and Cluster Cache line specified by address in M-Mode
  1708. * \details
  1709. * This macro is an alias for MInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1710. * \remarks
  1711. * This macro must be executed in M-Mode only.
  1712. * \param [in] addr start address to be invalidated
  1713. */
  1714. #define MInvalDCacheCCacheLine(addr) MInvalDCacheLine(addr)
  1715. /**
  1716. * \brief Invalidate several D-Cache and Cluster Cache lines specified by address in M-Mode
  1717. * \details
  1718. * This macro is an alias for MInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1719. * \remarks
  1720. * This macro must be executed in M-Mode only.
  1721. * \param [in] addr start address to be invalidated
  1722. * \param [in] cnt count of cache lines to be invalidated
  1723. */
  1724. #define MInvalDCacheCCacheLines(addr, cnt) MInvalDCacheLines(addr, cnt)
  1725. /**
  1726. * \brief Invalidate one D-Cache and Cluster Cache line specified by address in S-Mode
  1727. * \details
  1728. * This macro is an alias for SInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1729. * \remarks
  1730. * This macro must be executed in M/S-Mode only.
  1731. * \param [in] addr start address to be invalidated
  1732. */
  1733. #define SInvalDCacheCCacheLine(addr) SInvalDCacheLine(addr)
  1734. /**
  1735. * \brief Invalidate several D-Cache and Cluster Cache lines specified by address in S-Mode
  1736. * \details
  1737. * This macro is an alias for SInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1738. * \remarks
  1739. * This macro must be executed in M/S-Mode only.
  1740. * \param [in] addr start address to be invalidated
  1741. * \param [in] cnt count of cache lines to be invalidated
  1742. */
  1743. #define SInvalDCacheCCacheLines(addr, cnt) SInvalDCacheLines(addr, cnt)
  1744. /**
  1745. * \brief Invalidate one D-Cache and Cluster Cache line specified by address in U-Mode
  1746. * \details
  1747. * This macro is an alias for UInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1748. * \remarks
  1749. * This macro must be executed in M/S/U-Mode only.
  1750. * \param [in] addr start address to be invalidated
  1751. */
  1752. #define UInvalDCacheCCacheLine(addr) UInvalDCacheLine(addr)
  1753. /**
  1754. * \brief Invalidate several D-Cache and Cluster Cache lines specified by address in U-Mode
  1755. * \details
  1756. * This macro is an alias for UInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1757. * \remarks
  1758. * This macro must be executed in M/S/U-Mode only.
  1759. * \param [in] addr start address to be invalidated
  1760. * \param [in] cnt count of cache lines to be invalidated
  1761. */
  1762. #define UInvalDCacheCCacheLines(addr, cnt) UInvalDCacheLines(addr, cnt)
  1763. /**
  1764. * \brief Flush one D-Cache and Cluster Cache line specified by address in M-Mode
  1765. * \details
  1766. * This macro is an alias for MFlushDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1767. * \remarks
  1768. * This macro must be executed in M-Mode only.
  1769. * \param [in] addr start address to be flushed
  1770. */
  1771. #define MFlushDCacheCCacheLine(addr) MFlushDCacheLine(addr)
  1772. /**
  1773. * \brief Flush several D-Cache and Cluster Cache lines specified by address in M-Mode
  1774. * \details
  1775. * This macro is an alias for MFlushDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1776. * \remarks
  1777. * This macro must be executed in M-Mode only.
  1778. * \param [in] addr start address to be flushed
  1779. * \param [in] cnt count of cache lines to be flushed
  1780. */
  1781. #define MFlushDCacheCCacheLines(addr, cnt) MFlushDCacheLines(addr, cnt)
  1782. /**
  1783. * \brief Flush one D-Cache and Cluster Cache line specified by address in S-Mode
  1784. * \details
  1785. * This macro is an alias for SFlushDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1786. * \remarks
  1787. * This macro must be executed in M/S-Mode only.
  1788. * \param [in] addr start address to be flushed
  1789. */
  1790. #define SFlushDCacheCCacheLine(addr) SFlushDCacheLine(addr)
  1791. /**
  1792. * \brief Flush several D-Cache and Cluster Cache lines specified by address in S-Mode
  1793. * \details
  1794. * This macro is an alias for SFlushDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1795. * \remarks
  1796. * This macro must be executed in M/S-Mode only.
  1797. * \param [in] addr start address to be flushed
  1798. * \param [in] cnt count of cache lines to be flushed
  1799. */
  1800. #define SFlushDCacheCCacheLines(addr, cnt) SFlushDCacheLines(addr, cnt)
  1801. /**
  1802. * \brief Flush one D-Cache and Cluster Cache line specified by address in U-Mode
  1803. * \details
  1804. * This macro is an alias for UFlushDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1805. * \remarks
  1806. * This macro must be executed in M/S/U-Mode only.
  1807. * \param [in] addr start address to be flushed
  1808. */
  1809. #define UFlushDCacheCCacheLine(addr) UFlushDCacheLine(addr)
  1810. /**
  1811. * \brief Flush several D-Cache and Cluster Cache lines specified by address in U-Mode
  1812. * \details
  1813. * This macro is an alias for UFlushDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1814. * \remarks
  1815. * This macro must be executed in M/S/U-Mode only.
  1816. * \param [in] addr start address to be flushed
  1817. * \param [in] cnt count of cache lines to be flushed
  1818. */
  1819. #define UFlushDCacheCCacheLines(addr, cnt) UFlushDCacheLines(addr, cnt)
  1820. /**
  1821. * \brief Flush and invalidate one D-Cache and Cluster Cache line specified by address in M-Mode
  1822. * \details
  1823. * This macro is an alias for MFlushInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1824. * \remarks
  1825. * This macro must be executed in M-Mode only.
  1826. * \param [in] addr start address to be flushed and invalidated
  1827. */
  1828. #define MFlushInvalDCacheCCacheLine(addr) MFlushInvalDCacheLine(addr)
  1829. /**
  1830. * \brief Flush and invalidate several D-Cache and Cluster Cache lines specified by address in M-Mode
  1831. * \details
  1832. * This macro is an alias for MFlushInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1833. * \remarks
  1834. * This macro must be executed in M-Mode only.
  1835. * \param [in] addr start address to be flushed and invalidated
  1836. * \param [in] cnt count of cache lines to be flushed and invalidated
  1837. */
  1838. #define MFlushInvalDCacheCCacheLines(addr, cnt) MFlushInvalDCacheLines(addr, cnt)
  1839. /**
  1840. * \brief Flush and invalidate one D-Cache and Cluster Cache line specified by address in S-Mode
  1841. * \details
  1842. * This macro is an alias for SFlushInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1843. * \remarks
  1844. * This macro must be executed in M/S-Mode only.
  1845. * \param [in] addr start address to be flushed and invalidated
  1846. */
  1847. #define SFlushInvalDCacheCCacheLine(addr) SFlushInvalDCacheLine(addr)
  1848. /**
  1849. * \brief Flush and invalidate several D-Cache and Cluster Cache lines specified by address in S-Mode
  1850. * \details
  1851. * This macro is an alias for SFlushInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1852. * \remarks
  1853. * This macro must be executed in M/S-Mode only.
  1854. * \param [in] addr start address to be flushed and invalidated
  1855. * \param [in] cnt count of cache lines to be flushed and invalidated
  1856. */
  1857. #define SFlushInvalDCacheCCacheLines(addr, cnt) SFlushInvalDCacheLines(addr, cnt)
  1858. /**
  1859. * \brief Flush and invalidate one D-Cache and Cluster Cache line specified by address in U-Mode
  1860. * \details
  1861. * This macro is an alias for UFlushInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
  1862. * \remarks
  1863. * This macro must be executed in M/S/U-Mode only.
  1864. * \param [in] addr start address to be flushed and invalidated
  1865. */
  1866. #define UFlushInvalDCacheCCacheLine(addr) UFlushInvalDCacheLine(addr)
  1867. /**
  1868. * \brief Flush and invalidate several D-Cache and Cluster Cache lines specified by address in U-Mode
  1869. * \details
  1870. * This macro is an alias for UFlushInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
  1871. * \remarks
  1872. * This macro must be executed in M/S/U-Mode only.
  1873. * \param [in] addr start address to be flushed and invalidated
  1874. * \param [in] cnt count of cache lines to be flushed and invalidated
  1875. */
  1876. #define UFlushInvalDCacheCCacheLines(addr, cnt) UFlushInvalDCacheLines(addr, cnt)
  1877. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  1878. /**
  1879. * \brief Lock one D-Cache line specified by address in M-Mode
  1880. * \details
  1881. * This function lock one D-Cache line specified by the address.
  1882. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1883. * \remarks
  1884. * This function must be executed in M-Mode only.
  1885. * \param [in] addr start address to be locked
  1886. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1887. */
  1888. __STATIC_INLINE unsigned long MLockDCacheLine(unsigned long addr)
  1889. {
  1890. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1891. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_LOCK);
  1892. FlushPipeCCM();
  1893. __RWMB();
  1894. return __RV_CSR_READ(CSR_CCM_MDATA);
  1895. }
  1896. /**
  1897. * \brief Lock several D-Cache lines specified by address in M-Mode
  1898. * \details
  1899. * This function lock several D-Cache lines specified by the address
  1900. * and line count.
  1901. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  1902. * \remarks
  1903. * This function must be executed in M-Mode only.
  1904. * \param [in] addr start address to be locked
  1905. * \param [in] cnt count of cache lines to be locked
  1906. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1907. */
  1908. __STATIC_INLINE unsigned long MLockDCacheLines(unsigned long addr, unsigned long cnt)
  1909. {
  1910. if (cnt > 0) {
  1911. unsigned long i;
  1912. unsigned long fail_info = CCM_OP_SUCCESS;
  1913. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  1914. for (i = 0; i < cnt; i++) {
  1915. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_LOCK);
  1916. FlushPipeCCM();
  1917. __RWMB();
  1918. fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
  1919. if (CCM_OP_SUCCESS != fail_info) {
  1920. return fail_info;
  1921. }
  1922. }
  1923. }
  1924. return CCM_OP_SUCCESS;
  1925. }
  1926. /**
  1927. * \brief Lock one D-Cache line specified by address in S-Mode
  1928. * \details
  1929. * This function lock one D-Cache line specified by the address.
  1930. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1931. * \remarks
  1932. * This function must be executed in M/S-Mode only.
  1933. * \param [in] addr start address to be locked
  1934. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1935. */
  1936. __STATIC_INLINE unsigned long SLockDCacheLine(unsigned long addr)
  1937. {
  1938. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1939. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_LOCK);
  1940. FlushPipeCCM();
  1941. __RWMB();
  1942. return __RV_CSR_READ(CSR_CCM_SDATA);
  1943. }
  1944. /**
  1945. * \brief Lock several D-Cache lines specified by address in S-Mode
  1946. * \details
  1947. * This function lock several D-Cache lines specified by the address
  1948. * and line count.
  1949. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  1950. * \remarks
  1951. * This function must be executed in M/S-Mode only.
  1952. * \param [in] addr start address to be locked
  1953. * \param [in] cnt count of cache lines to be locked
  1954. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1955. */
  1956. __STATIC_INLINE unsigned long SLockDCacheLines(unsigned long addr, unsigned long cnt)
  1957. {
  1958. if (cnt > 0) {
  1959. unsigned long i;
  1960. unsigned long fail_info = CCM_OP_SUCCESS;
  1961. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  1962. for (i = 0; i < cnt; i++) {
  1963. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_LOCK);
  1964. FlushPipeCCM();
  1965. __RWMB();
  1966. fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
  1967. if (CCM_OP_SUCCESS != fail_info) {
  1968. return fail_info;
  1969. }
  1970. }
  1971. }
  1972. return CCM_OP_SUCCESS;
  1973. }
  1974. /**
  1975. * \brief Lock one D-Cache line specified by address in U-Mode
  1976. * \details
  1977. * This function lock one D-Cache line specified by the address.
  1978. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1979. * \remarks
  1980. * This function must be executed in M/S/U-Mode only.
  1981. * \param [in] addr start address to be locked
  1982. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  1983. */
  1984. __STATIC_INLINE unsigned long ULockDCacheLine(unsigned long addr)
  1985. {
  1986. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  1987. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_LOCK);
  1988. FlushPipeCCM();
  1989. __RWMB();
  1990. return __RV_CSR_READ(CSR_CCM_UDATA);
  1991. }
  1992. /**
  1993. * \brief Lock several D-Cache lines specified by address in U-Mode
  1994. * \details
  1995. * This function lock several D-Cache lines specified by the address
  1996. * and line count.
  1997. * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  1998. * \remarks
  1999. * This function must be executed in M/S/U-Mode only.
  2000. * \param [in] addr start address to be locked
  2001. * \param [in] cnt count of cache lines to be locked
  2002. * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
  2003. */
  2004. __STATIC_INLINE unsigned long ULockDCacheLines(unsigned long addr, unsigned long cnt)
  2005. {
  2006. if (cnt > 0) {
  2007. unsigned long i;
  2008. unsigned long fail_info = CCM_OP_SUCCESS;
  2009. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  2010. for (i = 0; i < cnt; i++) {
  2011. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_LOCK);
  2012. FlushPipeCCM();
  2013. __RWMB();
  2014. fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
  2015. if (CCM_OP_SUCCESS != fail_info) {
  2016. return fail_info;
  2017. }
  2018. }
  2019. }
  2020. return CCM_OP_SUCCESS;
  2021. }
  2022. /**
  2023. * \brief Unlock one D-Cache line specified by address in M-Mode
  2024. * \details
  2025. * This function unlock one D-Cache line specified by the address.
  2026. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  2027. * \remarks
  2028. * This function must be executed in M-Mode only.
  2029. * \param [in] addr start address to be unlocked
  2030. */
  2031. __STATIC_INLINE void MUnlockDCacheLine(unsigned long addr)
  2032. {
  2033. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  2034. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_UNLOCK);
  2035. FlushPipeCCM();
  2036. __RWMB();
  2037. }
  2038. /**
  2039. * \brief Unlock several D-Cache lines specified by address in M-Mode
  2040. * \details
  2041. * This function unlock several D-Cache lines specified
  2042. * by the address and line count.
  2043. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
  2044. * \remarks
  2045. * This function must be executed in M-Mode only.
  2046. * \param [in] addr start address to be unlocked
  2047. * \param [in] cnt count of cache lines to be unlocked
  2048. */
  2049. __STATIC_INLINE void MUnlockDCacheLines(unsigned long addr, unsigned long cnt)
  2050. {
  2051. if (cnt > 0) {
  2052. unsigned long i;
  2053. __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
  2054. for (i = 0; i < cnt; i++) {
  2055. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_UNLOCK);
  2056. }
  2057. FlushPipeCCM();
  2058. __RWMB();
  2059. }
  2060. }
  2061. /**
  2062. * \brief Unlock one D-Cache line specified by address in S-Mode
  2063. * \details
  2064. * This function unlock one D-Cache line specified by the address.
  2065. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  2066. * \remarks
  2067. * This function must be executed in M/S-Mode only.
  2068. * \param [in] addr start address to be unlocked
  2069. */
  2070. __STATIC_INLINE void SUnlockDCacheLine(unsigned long addr)
  2071. {
  2072. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  2073. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_UNLOCK);
  2074. FlushPipeCCM();
  2075. __RWMB();
  2076. }
  2077. /**
  2078. * \brief Unlock several D-Cache lines specified by address in S-Mode
  2079. * \details
  2080. * This function unlock several D-Cache lines specified
  2081. * by the address and line count.
  2082. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
  2083. * \remarks
  2084. * This function must be executed in M/S-Mode only.
  2085. * \param [in] addr start address to be unlocked
  2086. * \param [in] cnt count of cache lines to be unlocked
  2087. */
  2088. __STATIC_INLINE void SUnlockDCacheLines(unsigned long addr, unsigned long cnt)
  2089. {
  2090. if (cnt > 0) {
  2091. unsigned long i;
  2092. __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
  2093. for (i = 0; i < cnt; i++) {
  2094. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_UNLOCK);
  2095. }
  2096. FlushPipeCCM();
  2097. __RWMB();
  2098. }
  2099. }
  2100. /**
  2101. * \brief Unlock one D-Cache line specified by address in U-Mode
  2102. * \details
  2103. * This function unlock one D-Cache line specified by the address.
  2104. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  2105. * \remarks
  2106. * This function must be executed in M/S/U-Mode only.
  2107. * \param [in] addr start address to be unlocked
  2108. */
  2109. __STATIC_INLINE void UUnlockDCacheLine(unsigned long addr)
  2110. {
  2111. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  2112. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_UNLOCK);
  2113. FlushPipeCCM();
  2114. __RWMB();
  2115. }
  2116. /**
  2117. * \brief Unlock several D-Cache lines specified by address in U-Mode
  2118. * \details
  2119. * This function unlock several D-Cache lines specified
  2120. * by the address and line count.
  2121. * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
  2122. * \remarks
  2123. * This function must be executed in M/S/U-Mode only.
  2124. * \param [in] addr start address to be unlocked
  2125. * \param [in] cnt count of cache lines to be unlocked
  2126. */
  2127. __STATIC_INLINE void UUnlockDCacheLines(unsigned long addr, unsigned long cnt)
  2128. {
  2129. if (cnt > 0) {
  2130. unsigned long i;
  2131. __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
  2132. for (i = 0; i < cnt; i++) {
  2133. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_UNLOCK);
  2134. }
  2135. FlushPipeCCM();
  2136. __RWMB();
  2137. }
  2138. }
  2139. /**
  2140. * \brief Invalidate all D-Cache lines in M-Mode
  2141. * \details
  2142. * This function invalidate all D-Cache lines.
  2143. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  2144. * \remarks
  2145. * This function must be executed in M-Mode only.
  2146. * \param [in] addr start address to be invalidated
  2147. */
  2148. __STATIC_INLINE void MInvalDCache(void)
  2149. {
  2150. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL_ALL);
  2151. FlushPipeCCM();
  2152. __RWMB();
  2153. }
  2154. /**
  2155. * \brief Invalidate all D-Cache lines in S-Mode
  2156. * \details
  2157. * This function invalidate all D-Cache lines.
  2158. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  2159. * \remarks
  2160. * This function must be executed in M/S-Mode only.
  2161. * \param [in] addr start address to be invalidated
  2162. */
  2163. __STATIC_INLINE void SInvalDCache(void)
  2164. {
  2165. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL_ALL);
  2166. FlushPipeCCM();
  2167. __RWMB();
  2168. }
  2169. /**
  2170. * \brief Invalidate all D-Cache lines in U-Mode
  2171. * \details
  2172. * This function invalidate all D-Cache lines.
  2173. * In U-Mode, this operation will be automatically
  2174. * translated to flush and invalidate operations by hardware.
  2175. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  2176. * \remarks
  2177. * This function must be executed in M/S/U-Mode only.
  2178. * \param [in] addr start address to be invalidated
  2179. */
  2180. __STATIC_INLINE void UInvalDCache(void)
  2181. {
  2182. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL_ALL);
  2183. FlushPipeCCM();
  2184. __RWMB();
  2185. }
  2186. /**
  2187. * \brief Flush all D-Cache lines in M-Mode
  2188. * \details
  2189. * This function flush all D-Cache lines.
  2190. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  2191. * \remarks
  2192. * This function must be executed in M-Mode only.
  2193. * \param [in] addr start address to be flushed
  2194. */
  2195. __STATIC_INLINE void MFlushDCache(void)
  2196. {
  2197. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB_ALL);
  2198. FlushPipeCCM();
  2199. __RWMB();
  2200. }
  2201. /**
  2202. * \brief Flush all D-Cache lines in S-Mode
  2203. * \details
  2204. * This function flush all D-Cache lines.
  2205. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  2206. * \remarks
  2207. * This function must be executed in M/S-Mode only.
  2208. * \param [in] addr start address to be flushed
  2209. */
  2210. __STATIC_INLINE void SFlushDCache(void)
  2211. {
  2212. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB_ALL);
  2213. FlushPipeCCM();
  2214. __RWMB();
  2215. }
  2216. /**
  2217. * \brief Flush all D-Cache lines in U-Mode
  2218. * \details
  2219. * This function flush all D-Cache lines.
  2220. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  2221. * \remarks
  2222. * This function must be executed in M/S/U-Mode only.
  2223. * \param [in] addr start address to be flushed
  2224. */
  2225. __STATIC_INLINE void UFlushDCache(void)
  2226. {
  2227. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB_ALL);
  2228. FlushPipeCCM();
  2229. __RWMB();
  2230. }
  2231. /**
  2232. * \brief Flush and invalidate all D-Cache lines in M-Mode
  2233. * \details
  2234. * This function flush and invalidate all D-Cache lines.
  2235. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  2236. * \remarks
  2237. * This function must be executed in M-Mode only.
  2238. * \param [in] addr start address to be flushed and locked
  2239. */
  2240. __STATIC_INLINE void MFlushInvalDCache(void)
  2241. {
  2242. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL_ALL);
  2243. FlushPipeCCM();
  2244. __RWMB();
  2245. }
  2246. /**
  2247. * \brief Flush and invalidate all D-Cache lines in S-Mode
  2248. * \details
  2249. * This function flush and invalidate all D-Cache lines.
  2250. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  2251. * \remarks
  2252. * This function must be executed in M/S-Mode only.
  2253. * \param [in] addr start address to be flushed and locked
  2254. */
  2255. __STATIC_INLINE void SFlushInvalDCache(void)
  2256. {
  2257. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL_ALL);
  2258. FlushPipeCCM();
  2259. __RWMB();
  2260. }
  2261. /**
  2262. * \brief Flush and invalidate all D-Cache lines in U-Mode
  2263. * \details
  2264. * This function flush and invalidate all D-Cache lines.
  2265. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  2266. * \remarks
  2267. * This function must be executed in M/S/U-Mode only.
  2268. * \param [in] addr start address to be flushed and locked
  2269. */
  2270. __STATIC_INLINE void UFlushInvalDCache(void)
  2271. {
  2272. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL_ALL);
  2273. FlushPipeCCM();
  2274. __RWMB();
  2275. }
  2276. #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
  2277. /**
  2278. * \brief Flush all Cluster Cache in M-Mode
  2279. * \details
  2280. * This function flush all Cluster Cache.
  2281. * Command \ref SMPCC_CMD_WB_ALL is written to SMPCC CMD register.
  2282. * \remarks
  2283. * This function must be executed in M-Mode only.
  2284. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2285. */
  2286. __STATIC_INLINE int32_t MFlushCCache(void)
  2287. {
  2288. SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2289. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
  2290. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
  2291. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
  2292. __RWMB();
  2293. return res;
  2294. }
  2295. /**
  2296. * \brief Flush all Cluster Cache in S-Mode
  2297. * \details
  2298. * This function flush all Cluster Cache.
  2299. * Command \ref SMPCC_CMD_WB_ALL is written to SMPCC CMD register.
  2300. * \remarks
  2301. * This function must be executed in M/S-Mode only.
  2302. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2303. */
  2304. __STATIC_INLINE int32_t SFlushCCache(void)
  2305. {
  2306. SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2307. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
  2308. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
  2309. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
  2310. __RWMB();
  2311. return res;
  2312. }
  2313. /**
  2314. * \brief Flush all Cluster Cache in U-Mode
  2315. * \details
  2316. * This function flush all Cluster Cache.
  2317. * Command \ref SMPCC_CMD_WB_ALL is written to SMPCC CMD register.
  2318. * \remarks
  2319. * This function must be executed in M/S/U-Mode only.
  2320. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2321. */
  2322. __STATIC_INLINE int32_t UFlushCCache(void)
  2323. {
  2324. SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2325. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
  2326. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
  2327. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
  2328. __RWMB();
  2329. return res;
  2330. }
  2331. /**
  2332. * \brief Flush and invalidate all Cluster Cache in M-Mode
  2333. * \details
  2334. * This function flush and invalidate all Cluster Cache.
  2335. * Command \ref SMPCC_CMD_WBINVAL_ALL is written to SMPCC CMD register.
  2336. * \remarks
  2337. * This function must be executed in M-Mode only.
  2338. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2339. */
  2340. __STATIC_INLINE int32_t MFlushInvalCCache(void)
  2341. {
  2342. SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2343. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
  2344. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
  2345. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
  2346. __RWMB();
  2347. return res;
  2348. }
  2349. /**
  2350. * \brief Flush and invalidate all Cluster Cache in S-Mode
  2351. * \details
  2352. * This function flush and invalidate all Cluster Cache.
  2353. * Command \ref SMPCC_CMD_WBINVAL_ALL is written to SMPCC CMD register.
  2354. * \remarks
  2355. * This function must be executed in M/S-Mode only.
  2356. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2357. */
  2358. __STATIC_INLINE int32_t SFlushInvalCCache(void)
  2359. {
  2360. SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2361. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
  2362. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
  2363. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
  2364. __RWMB();
  2365. return res;
  2366. }
  2367. /**
  2368. * \brief Flush and invalidate all Cluster Cache in U-Mode
  2369. * \details
  2370. * This function flush and invalidate all Cluster Cache.
  2371. * Command \ref SMPCC_CMD_WBINVAL_ALL is written to SMPCC CMD register.
  2372. * \remarks
  2373. * This function must be executed in M/S/U-Mode only.
  2374. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2375. */
  2376. __STATIC_INLINE int32_t UFlushInvalCCache(void)
  2377. {
  2378. SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2379. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
  2380. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
  2381. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
  2382. __RWMB();
  2383. return res;
  2384. }
  2385. /**
  2386. * \brief Invalidate all D-Cache and Cluster Cache in M-Mode
  2387. * \details
  2388. * This function unlock and invalidate all D-Cache and Cluster Cache.
  2389. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  2390. * \remarks
  2391. * This function must be executed in M-Mode only.
  2392. */
  2393. __STATIC_INLINE void MInvalDCacheCCache(void)
  2394. {
  2395. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL_ALL);
  2396. FlushPipeCCM();
  2397. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  2398. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  2399. __RWMB();
  2400. }
  2401. /**
  2402. * \brief Invalidate all D-Cache and Cluster Cache in S-Mode
  2403. * \details
  2404. * This function unlock and invalidate all D-Cache and Cluster Cache.
  2405. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  2406. * \remarks
  2407. * This function must be executed in M/S-Mode only.
  2408. */
  2409. __STATIC_INLINE void SInvalDCacheCCache(void)
  2410. {
  2411. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL_ALL);
  2412. FlushPipeCCM();
  2413. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  2414. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  2415. __RWMB();
  2416. }
  2417. /**
  2418. * \brief Invalidate all D-Cache and Cluster Cache in U-Mode
  2419. * \details
  2420. * This function unlock and invalidate all D-Cache and Cluster Cache.
  2421. * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  2422. * \remarks
  2423. * This function must be executed in M/S/U-Mode only.
  2424. */
  2425. __STATIC_INLINE void UInvalDCacheCCache(void)
  2426. {
  2427. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL_ALL);
  2428. FlushPipeCCM();
  2429. SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
  2430. while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
  2431. __RWMB();
  2432. }
  2433. /**
  2434. * \brief Flush all D-Cache and Cluster Cache in M-Mode
  2435. * \details
  2436. * This function flush all D-Cache and Cluster Cache.
  2437. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  2438. * \remarks
  2439. * This function must be executed in M-Mode only.
  2440. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2441. */
  2442. __STATIC_INLINE int32_t MFlushDCacheCCache(void)
  2443. {
  2444. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB_ALL);
  2445. FlushPipeCCM();
  2446. SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2447. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
  2448. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
  2449. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
  2450. __RWMB();
  2451. return res;
  2452. }
  2453. /**
  2454. * \brief Flush all D-Cache and Cluster Cache in S-Mode
  2455. * \details
  2456. * This function flush all D-Cache and Cluster Cache.
  2457. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  2458. * \remarks
  2459. * This function must be executed in M/S-Mode only.
  2460. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2461. */
  2462. __STATIC_INLINE int32_t SFlushDCacheCCache(void)
  2463. {
  2464. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB_ALL);
  2465. FlushPipeCCM();
  2466. SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2467. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
  2468. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
  2469. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
  2470. __RWMB();
  2471. return res;
  2472. }
  2473. /**
  2474. * \brief Flush all D-Cache and Cluster Cache in U-Mode
  2475. * \details
  2476. * This function flush all D-Cache and Cluster Cache.
  2477. * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  2478. * \remarks
  2479. * This function must be executed in M/S/U-Mode only.
  2480. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2481. */
  2482. __STATIC_INLINE int32_t UFlushDCacheCCache(void)
  2483. {
  2484. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB_ALL);
  2485. FlushPipeCCM();
  2486. SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2487. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
  2488. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
  2489. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
  2490. __RWMB();
  2491. return res;
  2492. }
  2493. /**
  2494. * \brief Flush and invalidate all D-Cache and Cluster Cache in M-Mode
  2495. * \details
  2496. * This function flush and invalidate all D-Cache and Cluster Cache.
  2497. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
  2498. * \remarks
  2499. * This function must be executed in M-Mode only.
  2500. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2501. */
  2502. __STATIC_INLINE int32_t MFlushInvalDCacheCCache(void)
  2503. {
  2504. __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL_ALL);
  2505. FlushPipeCCM();
  2506. SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2507. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
  2508. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
  2509. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
  2510. __RWMB();
  2511. return res;
  2512. }
  2513. /**
  2514. * \brief Flush and invalidate all D-Cache and Cluster Cache in S-Mode
  2515. * \details
  2516. * This function flush and invalidate all D-Cache and Cluster Cache.
  2517. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
  2518. * \remarks
  2519. * This function must be executed in M/S-Mode only.
  2520. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2521. */
  2522. __STATIC_INLINE int32_t SFlushInvalDCacheCCache(void)
  2523. {
  2524. __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL_ALL);
  2525. FlushPipeCCM();
  2526. SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2527. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
  2528. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
  2529. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
  2530. __RWMB();
  2531. return res;
  2532. }
  2533. /**
  2534. * \brief Flush and invalidate all D-Cache and Cluster Cache in U-Mode
  2535. * \details
  2536. * This function flush and invalidate all D-Cache and Cluster Cache.
  2537. * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
  2538. * \remarks
  2539. * This function must be executed in M/S/U-Mode only.
  2540. * \return Operation result, see enum \ref SMPCC_CMD_RESULT
  2541. */
  2542. __STATIC_INLINE int32_t UFlushInvalDCacheCCache(void)
  2543. {
  2544. __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL_ALL);
  2545. FlushPipeCCM();
  2546. SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
  2547. _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
  2548. while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
  2549. int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
  2550. __RWMB();
  2551. return res;
  2552. }
  2553. #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
  2554. #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
  2555. /** @} */ /* End of Doxygen Group NMSIS_Core_DCache */
  2556. #endif /* defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1) */
  2557. #ifdef __cplusplus
  2558. }
  2559. #endif
  2560. #endif /* __CORE_FEATURE_CACHE_H__ */