| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720 |
- /*
- * Copyright (c) 2019 Nuclei Limited. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #ifndef __CORE_FEATURE_CACHE_H__
- #define __CORE_FEATURE_CACHE_H__
- /*!
- * @file core_feature_cache.h
- * @brief Cache feature API header file for Nuclei N/NX Core
- */
- /*
- * Cache Feature Configuration Macro:
- * 1. __ICACHE_PRESENT: Define whether I-Cache Unit is present or not.
- * * 0: Not present
- * * 1: Present
- * 2. __DCACHE_PRESENT: Define whether D-Cache Unit is present or not.
- * * 0: Not present
- * * 1: Present
- * 3. __CCM_PRESENT: Define whether Nuclei Cache Control and Maintainence(CCM) Unit is present or not.
- * * 0: Not present
- * * 1: Present
- * 4. __SMPCC_PRESENT: Define whether SMP & Cluster Cache Unit is present or not.
- * * 0: Not present
- * * 1: Present
- * 5. __SMPCC_BASEADDR: Base address of the SMP & Cluster Cache unit.
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "core_feature_base.h"
- #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- /**
- * \defgroup NMSIS_Core_CCache Cluster-Cache Functions
- * \ingroup NMSIS_Core_Cache
- * \brief Functions that configure Cluster Cache by CCM
- * @{
- */
- /**
- * \brief Cluster Cache Control and Command Registers
- * \remarks This structure only holds a part of SMPCC registers, which are related to
- * Cluster Cache CCM operations. Other more registers of SMPCC are listed in core_feature_smpcc.h
- */
- typedef struct {
- __IM uint8_t RESERVED0[16]; /*!< 0x00~0x0F (R) Not shown here for these registers are not related with cache operation */
- __IOM uint32_t CC_CTRL; /*!< Offset: 0x10 (R/W) Cluster Cache Control Register */
- __IOM uint32_t CC_mCMD; /*!< Offset: 0x14 (R/W) Cluster Cache M-mode Command Register */
- __IM uint8_t RESERVED1[168]; /*!< 0x18~0xBF (R) not shown here for these registers are not related with cache operation */
- __IOM uint32_t CC_sCMD; /*!< Offset: 0xC0 (R/W) Cluster Cache S-mode Command Register */
- __IOM uint32_t CC_uCMD; /*!< Offset: 0xC4 (R/W) Cluster Cache U-mode Command Register */
- __IM uint8_t RESERVED2[20]; /*!< 0xC8~0xDB (R) not shown here for these registers are not related with cache operation */
- __IOM uint32_t CC_INVALID_ALL; /*!< Offset: 0xDC (R/W) Cluster Cache Invalid All Register */
- } SMPCC_CMD_Type;
- #define SMPCC_CMD_CTRL_SUP_EN_Pos 9U /*!< SMPCC_CMD CC_CTRL SUP_EN Position */
- #define SMPCC_CMD_CTRL_SUP_EN_Msk (0x1UL << SMPCC_CMD_CTRL_SUP_EN_Pos) /*!< SMPCC_CMD CC_CTRL SUP_EN Mask */
- #define SMPCC_CMD_CTRL_SUP_EN_ENABLE 1U /*!< SMPCC_CMD CC_CTRL SUP_EN Enable */
- #define SMPCC_CMD_CTRL_SUP_EN_DISABLE 0U /*!< SMPCC_CMD CC_CTRL SUP_EN Disable */
- #define SMPCC_CMD_CTRL_USE_EN_Pos 10U /*!< SMPCC_CMD CC_CTRL USE_EN Position */
- #define SMPCC_CMD_CTRL_USE_EN_Msk (0x1UL << SMPCC_CMD_CTRL_USE_EN_Pos) /*!< SMPCC_CMD CC_CTRL USE_EN Mask */
- #define SMPCC_CMD_CTRL_USE_EN_ENABLE 1U /*!< SMPCC_CMD CC_CTRL USE_EN Enable */
- #define SMPCC_CMD_CTRL_USE_EN_DISABLE 0U /*!< SMPCC_CMD CC_CTRL USE_EN Disable */
- #define SMPCC_CMD_xCMD_CMD_Pos 0U /*!< SMPCC_CMD register xCMD field CMD Position */
- #define SMPCC_CMD_xCMD_CMD_Msk (0x1FUL << SMPCC_CMD_xCMD_CMD_Pos) /*!< SMPCC_CMD register xCMD field CMD Mask */
- #define SMPCC_CMD_xCMD_CMD_WB_ALL 0x7U /*!< SMPCC_CMD xCMD CMD WB_ALL */
- #define SMPCC_CMD_xCMD_CMD_WBINVAL_ALL 0x6U /*!< SMPCC_CMD xCMD CMD WBINVAL_ALL */
- #define SMPCC_CMD_xCMD_RESULT_Pos 26U /*!< SMPCC_CMD xCMD RESULT Position */
- #define SMPCC_CMD_xCMD_RESULT_Msk (0x1FUL << SMPCC_CMD_xCMD_RESULT_Pos) /*!< SMPCC_CMD xCMD RESULT Mask */
- #define SMPCC_CMD_xCMD_RESULT_SUCCESS 0x0U /*!< SMPCC_CMD xCMD RESULT Success */
- #define SMPCC_CMD_xCMD_RESULT_ENTRY_EXCEED_LIMIT 0x1U /*!< SMPCC_CMD xCMD RESULT Exceed the upper entry num of lockable way */
- #define SMPCC_CMD_xCMD_RESULT_REFILL_BUS_ERROR 0x3U /*!< SMPCC_CMD xCMD RESULT Refill Bus Error */
- #define SMPCC_CMD_xCMD_RESULT_ECC_ERROR 0x4U /*!< SMPCC_CMD xCMD RESULT ECC Error */
- #define SMPCC_CMD_xCMD_RESULT_CPBACK_BUS_ERROR 0x5U /*!< SMPCC_CMD xCMD RESULT Copy Back Bus Error */
- #define SMPCC_CMD_xCMD_COMPLETE_Pos 31U /*!< SMPCC_CMD xCMD COMPLETE Position */
- #define SMPCC_CMD_xCMD_COMPLETE_Msk (0x1UL << SMPCC_CMD_xCMD_COMPLETE_Pos) /*!< SMPCC_CMD xCMD COMPLETE Mask */
- #define SMPCC_CMD_INVALID_ALL_Pos 0U /*!< SMPCC_CMD INVALID_ALL Position */
- #define SMPCC_CMD_INVALID_ALL_Msk (0x1UL << SMPCC_CMD_INVALID_ALL_Pos) /*!< SMPCC_CMD INVALID_ALL Mask */
- #ifndef __SMPCC_BASEADDR
- /* Base address of SMPCC(__SMPCC_BASEADDR) should be defined in <Device.h> */
- #error "__SMPCC_BASEADDR is not defined, please check!"
- #endif
- /* SMPCC CMD registers Memory mapping of Device */
- #define SMPCC_CMD_BASE __SMPCC_BASEADDR /*!< SMPCC CMD Base Address */
- #define SMPCC_CMD ((SMPCC_CMD_Type *)SMPCC_CMD_BASE) /*!< SMPCC CMD configuration struct */
- /** @} */ /* End of Doxygen Group NMSIS_Core_CCache */
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- /* ########################## Cache functions #################################### */
- /**
- * \defgroup NMSIS_Core_Cache Cache Functions
- * \brief Functions that configure Instruction and Data Cache.
- * @{
- *
- * Nuclei provide Cache Control and Maintainence(CCM) for software to control and maintain
- * the internal L1 I/D Cache and Cluster Cache of the RISC-V Core, software can manage the
- * cache flexibly to meet the actual application scenarios.
- *
- * The CCM operations have 3 types: by single address, by all and flush pipeline.
- * The CCM operations are done via CSR registers, M/S/U mode has its own CSR registers to
- * do CCM operations. By default, CCM operations are not allowed in S/U mode, you can execute
- * \ref EnableSUCCM in M-Mode to enable it.
- *
- * * API names started with M<operations>, such as \ref MInvalICacheLine must be called in M-Mode only.
- * * API names started with S<operations>, such as \ref SInvalICacheLine should be called in S-Mode.
- * * API names started with U<operations>, such as \ref UInvalICacheLine should be called in U-Mode.
- *
- */
- /**
- * \brief Cache CCM Operation Fail Info
- */
- typedef enum CCM_OP_FINFO {
- CCM_OP_SUCCESS = 0x0, /*!< Lock Succeed */
- CCM_OP_EXCEED_ERR = 0x1, /*!< Exceed the the number of lockable ways(N-Way I/D-Cache, lockable is N-1) */
- 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 */
- CCM_OP_REFILL_BUS_ERR = 0x3, /*!< Refill has Bus Error */
- CCM_OP_ECC_ERR = 0x4 /*!< Deprecated, ECC Error, this error code is removed in later Nuclei CCM RTL design, please don't use it */
- } CCM_OP_FINFO_Type;
- /**
- * \brief Cache CCM Command Types
- */
- typedef enum CCM_CMD {
- CCM_DC_INVAL = 0x0, /*!< Unlock and invalidate D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR */
- CCM_DC_WB = 0x1, /*!< Flush the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR */
- CCM_DC_WBINVAL = 0x2, /*!< Unlock, flush and invalidate the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR */
- CCM_DC_LOCK = 0x3, /*!< Lock the specific D-Cache line specified by CSR CCM_XBEGINADDR */
- CCM_DC_UNLOCK = 0x4, /*!< Unlock the specific D-Cache line specified by CSR CCM_XBEGINADDR */
- CCM_DC_WBINVAL_ALL = 0x6, /*!< Unlock and flush and invalidate all the valid and dirty D-Cache lines */
- CCM_DC_WB_ALL = 0x7, /*!< Flush all the valid and dirty D-Cache lines */
- CCM_DC_INVAL_ALL = 0x17, /*!< Unlock and invalidate all the D-Cache lines */
- CCM_IC_INVAL = 0x8, /*!< Unlock and invalidate I-Cache line specified by CSR CCM_XBEGINADDR */
- CCM_IC_LOCK = 0xb, /*!< Lock the specific I-Cache line specified by CSR CCM_XBEGINADDR */
- CCM_IC_UNLOCK = 0xc, /*!< Unlock the specific I-Cache line specified by CSR CCM_XBEGINADDR */
- CCM_IC_INVAL_ALL = 0xd, /*!< Unlock and invalidate all the I-Cache lines */
- CCM_CC_LOCK = 0x13, /*!< Lock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR */
- CCM_CC_UNLOCK = 0x12, /*!< Unlock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR */
- } CCM_CMD_Type;
- /**
- * \brief Cache Information Type
- */
- typedef struct CacheInfo {
- uint32_t linesize; /*!< Cache Line size in bytes */
- uint32_t ways; /*!< Cache ways */
- uint32_t setperway; /*!< Cache set per way */
- uint32_t size; /*!< Cache total size in bytes */
- } CacheInfo_Type;
- #if __riscv_xlen == 32
- #define CCM_SUEN_SUEN_Msk (0xFFFFFFFFUL) /*!< CSR CCM_SUEN: SUEN Mask */
- #else
- #define CCM_SUEN_SUEN_Msk (0xFFFFFFFFFFFFFFFFUL) /*!< CSR CCM_SUEN: SUEN Mask */
- #endif
- /**
- * \brief Enable CCM operation in Supervisor/User Mode
- * \details
- * This function enable CCM operation in Supervisor/User Mode.
- * If enabled, CCM operations in supervisor/user mode will
- * be allowed. Besides CCM registers, CC_sCMD and CC_uCMD registers
- * which belong to SMPCC module are also allowed.
- * \remarks
- * - This function can be called in M-Mode only.
- * \sa
- * - \ref DisableSUCCM
- */
- __STATIC_FORCEINLINE void EnableSUCCM(void)
- {
- __RV_CSR_SET(CSR_CCM_SUEN, CCM_SUEN_SUEN_Msk);
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- SMPCC_CMD->CC_CTRL |= _VAL2FLD(SMPCC_CMD_CTRL_SUP_EN, SMPCC_CMD_CTRL_SUP_EN_ENABLE) |
- _VAL2FLD(SMPCC_CMD_CTRL_USE_EN, SMPCC_CMD_CTRL_USE_EN_ENABLE);
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- }
- /**
- * \brief Disable CCM operation in Supervisor/User Mode
- * \details
- * This function disable CCM operation in Supervisor/User Mode.
- * If not enabled, CCM operations in supervisor/user mode will
- * trigger a *illegal intruction* exception, access to CC_sCMD
- * and CC_uCMD register is also forbidden.
- * \remarks
- * - This function can be called in M-Mode only.
- * \sa
- * - \ref EnableSUCCM
- */
- __STATIC_FORCEINLINE void DisableSUCCM(void)
- {
- __RV_CSR_CLEAR(CSR_CCM_SUEN, CCM_SUEN_SUEN_Msk);
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- SMPCC_CMD->CC_CTRL &= ~_VAL2FLD(SMPCC_CMD_CTRL_SUP_EN, SMPCC_CMD_CTRL_SUP_EN_DISABLE) &
- ~_VAL2FLD(SMPCC_CMD_CTRL_USE_EN, SMPCC_CMD_CTRL_USE_EN_DISABLE);
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- }
- /**
- * \brief Flush pipeline after CCM operation
- * \details
- * This function is used to flush pipeline after CCM operations
- * on Cache, it will ensure latest instructions or data can be
- * seen by pipeline.
- * \remarks
- * - This function can be called in M/S/U-Mode only.
- */
- __STATIC_FORCEINLINE void FlushPipeCCM(void)
- {
- __RV_CSR_WRITE(CSR_CCM_FPIPE, 0x1);
- }
- /** @} */ /* End of Doxygen Group NMSIS_Core_Cache */
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- /**
- * \ingroup NMSIS_Core_CCache
- * @{
- */
- /**
- * \brief Lock one Cluster Cache line specified by address in M-Mode
- * \details
- * This function lock one Cluster Cache line specified by the address.
- * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long MLockCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_MDATA);
- }
- /**
- * \brief Lock several Cluster Cache lines specified by address in M-Mode
- * \details
- * This function lock several Cluster Cache lines specified by the address
- * and line count.
- * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long MLockCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Lock one Cluster Cache line specified by address in S-Mode
- * \details
- * This function lock one Cluster Cache line specified by the address.
- * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long SLockCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_SDATA);
- }
- /**
- * \brief Lock several Cluster Cache lines specified by address in S-Mode
- * \details
- * This function lock several Cluster Cache lines specified by the address
- * and line count.
- * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long SLockCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Lock one Cluster Cache line specified by address in U-Mode
- * \details
- * This function lock one Cluster Cache line specified by the address.
- * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long ULockCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_UDATA);
- }
- /**
- * \brief Lock several Cluster Cache lines specified by address in U-Mode
- * \details
- * This function lock several Cluster Cache lines specified by the address
- * and line count.
- * Command \ref CCM_CC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long ULockCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Unlock one Cluster Cache line specified by address in M-Mode
- * \details
- * This function unlock one Cluster Cache line specified by the address.
- * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void MUnlockCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several Cluster Cache lines specified by address in M-Mode
- * \details
- * This function unlock several Cluster Cache lines specified
- * by the address and line count.
- * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void MUnlockCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_CC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Unlock one Cluster Cache line specified by address in S-Mode
- * \details
- * This function unlock one Cluster Cache line specified by the address.
- * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void SUnlockCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several Cluster Cache lines specified by address in S-Mode
- * \details
- * This function unlock several Cluster Cache lines specified
- * by the address and line count.
- * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void SUnlockCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_CC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Unlock one Cluster Cache line specified by address in U-Mode
- * \details
- * This function unlock one Cluster Cache line specified by the address.
- * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void UUnlockCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several Cluster Cache lines specified by address in U-Mode
- * \details
- * This function unlock several Cluster Cache lines specified
- * by the address and line count.
- * Command \ref CCM_CC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void UUnlockCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_CC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /** @} */ /* End of Doxygen Group NMSIS_Core_CCache */
- #endif /* defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
- #if defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1)
- /**
- * \defgroup NMSIS_Core_ICache I-Cache Functions
- * \ingroup NMSIS_Core_Cache
- * \brief Functions that configure Instruction Cache.
- * @{
- */
- /**
- * \brief Check ICache Unit Present or Not
- * \details
- * This function check icache unit present or not via mcfg_info csr
- * \remarks
- * - This function might not work for some old nuclei processors
- * - Please make sure the version of your nuclei processor contain ICACHE bit in mcfg_info
- * \return 1 if present otherwise 0
- */
- __STATIC_INLINE int32_t ICachePresent(void)
- {
- if (__RV_CSR_READ(CSR_MCFG_INFO) & MCFG_INFO_ICACHE) {
- return 1;
- }
- return 0;
- }
- /**
- * \brief Enable ICache
- * \details
- * This function enable I-Cache
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control I Cache enable.
- * \sa
- * - \ref DisableICache
- */
- __STATIC_FORCEINLINE void EnableICache(void)
- {
- __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_EN);
- }
- /**
- * \brief Disable ICache
- * \details
- * This function Disable I-Cache
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control I Cache enable.
- * \sa
- * - \ref EnableICache
- */
- __STATIC_FORCEINLINE void DisableICache(void)
- {
- __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_EN);
- }
- /**
- * \brief Enable ICache ECC
- * \details
- * This function enable I-Cache ECC
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control I Cache ECC enable.
- * \sa
- * - \ref DisableICacheECC
- */
- __STATIC_FORCEINLINE void EnableICacheECC(void)
- {
- __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN);
- }
- /**
- * \brief Disable ICache ECC
- * \details
- * This function disable I-Cache ECC
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control I Cache ECC enable.
- * \sa
- * - \ref EnableICacheECC
- */
- __STATIC_FORCEINLINE void DisableICacheECC(void)
- {
- __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN);
- }
- #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
- /**
- * \brief Get I-Cache Information
- * \details
- * This function get I-Cache Information
- * \remarks
- * - This function can be called in M-Mode only.
- * - You can use this function in combination with cache lines operations
- * \sa
- * - \ref GetDCacheInfo
- */
- __STATIC_INLINE int32_t GetICacheInfo(CacheInfo_Type *info)
- {
- if (info == NULL) {
- return -1;
- }
- CSR_MICFGINFO_Type csr_ccfg;
- csr_ccfg.d = __RV_CSR_READ(CSR_MICFG_INFO);
- info->setperway = (1UL << csr_ccfg.b.set) << 3;
- info->ways = (1 + csr_ccfg.b.way);
- if (csr_ccfg.b.lsize == 0) {
- info->linesize = 0;
- } else {
- info->linesize = (1UL << (csr_ccfg.b.lsize - 1)) << 3;
- }
- info->size = info->setperway * info->ways * info->linesize;
- return 0;
- }
- /**
- * \brief Invalidate one I-Cache line specified by address in M-Mode
- * \details
- * This function unlock and invalidate one I-Cache line specified
- * by the address.
- * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void MInvalICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several I-Cache lines specified by address in M-Mode
- * \details
- * This function unlock and invalidate several I-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void MInvalICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate one I-Cache line specified by address in S-Mode
- * \details
- * This function unlock and invalidate one I-Cache line specified
- * by the address.
- * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void SInvalICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several I-Cache lines specified by address in S-Mode
- * \details
- * This function unlock and invalidate several I-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void SInvalICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate one I-Cache line specified by address in U-Mode
- * \details
- * This function unlock and invalidate one I-Cache line specified
- * by the address.
- * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void UInvalICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several I-Cache lines specified by address in U-Mode
- * \details
- * This function unlock and invalidate several I-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_IC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void UInvalICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- /**
- * \brief Invalidate one I-Cache and Cluster Cache line specified by address in M-Mode
- * \details
- * This function unlock and invalidate one I-Cache line and corresponding Cluster Cache line
- * specified by the address.
- * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void MInvalICacheCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
- /* Trigger Cluster Cache invalidation by DC_INVAL */
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several I-Cache and Cluster Cache lines specified by address in M-Mode
- * \details
- * This function unlock and invalidate several I-Cache lines and corresponding Cluster Cache lines
- * specified by the address and line count.
- * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void MInvalICacheCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL);
- /* Trigger Cluster Cache invalidation by DC_INVAL */
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate one I-Cache and Cluster Cache line specified by address in S-Mode
- * \details
- * This function unlock and invalidate one I-Cache line and corresponding Cluster Cache line
- * specified by the address.
- * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void SInvalICacheCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
- /* Trigger Cluster Cache invalidation by DC_INVAL */
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several I-Cache and Cluster Cache lines specified by address in S-Mode
- * \details
- * This function unlock and invalidate several I-Cache lines and corresponding Cluster Cache lines
- * specified by the address and line count.
- * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void SInvalICacheCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL);
- /* Trigger Cluster Cache invalidation by DC_INVAL */
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate one I-Cache and Cluster Cache line specified by address in U-Mode
- * \details
- * This function unlock and invalidate one I-Cache line and corresponding Cluster Cache line
- * specified by the address.
- * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void UInvalICacheCCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
- /* Trigger Cluster Cache invalidation by DC_INVAL */
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several I-Cache and Cluster Cache lines specified by address in U-Mode
- * \details
- * This function unlock and invalidate several I-Cache lines and corresponding Cluster Cache lines
- * specified by the address and line count.
- * Commands \ref CCM_IC_INVAL and \ref CCM_DC_INVAL are written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void UInvalICacheCCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL);
- /* Trigger Cluster Cache invalidation by DC_INVAL */
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- /**
- * \brief Lock one I-Cache line specified by address in M-Mode
- * \details
- * This function lock one I-Cache line specified by the address.
- * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long MLockICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_MDATA);
- }
- /**
- * \brief Lock several I-Cache lines specified by address in M-Mode
- * \details
- * This function lock several I-Cache lines specified by the address
- * and line count.
- * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long MLockICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Lock one I-Cache line specified by address in S-Mode
- * \details
- * This function lock one I-Cache line specified by the address.
- * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long SLockICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_SDATA);
- }
- /**
- * \brief Lock several I-Cache lines specified by address in S-Mode
- * \details
- * This function lock several I-Cache lines specified by the address
- * and line count.
- * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long SLockICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Lock one I-Cache line specified by address in U-Mode
- * \details
- * This function lock one I-Cache line specified by the address.
- * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long ULockICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_UDATA);
- }
- /**
- * \brief Lock several I-Cache lines specified by address in U-Mode
- * \details
- * This function lock several I-Cache lines specified by the address
- * and line count.
- * Command \ref CCM_IC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long ULockICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Unlock one I-Cache line specified by address in M-Mode
- * \details
- * This function unlock one I-Cache line specified by the address.
- * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void MUnlockICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several I-Cache lines specified by address in M-Mode
- * \details
- * This function unlock several I-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void MUnlockICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Unlock one I-Cache line specified by address in S-Mode
- * \details
- * This function unlock one I-Cache line specified by the address.
- * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void SUnlockICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several I-Cache lines specified by address in S-Mode
- * \details
- * This function unlock several I-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void SUnlockICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Unlock one I-Cache line specified by address in U-Mode
- * \details
- * This function unlock one I-Cache line specified by the address.
- * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void UUnlockICacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several I-Cache lines specified by address in U-Mode
- * \details
- * This function unlock several I-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_IC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void UUnlockICacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate all I-Cache lines in M-Mode
- * \details
- * This function invalidate all I-Cache lines.
- * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void MInvalICache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate all I-Cache lines in S-Mode
- * \details
- * This function invalidate all I-Cache lines.
- * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void SInvalICache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate all I-Cache lines in U-Mode
- * \details
- * This function invalidate all I-Cache lines.
- * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void UInvalICache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- /**
- * \brief Invalidate all Cluster Cache in M-Mode
- * \details
- * This function invalidate all Cluster Cache.
- * \remarks
- * This function must be executed in M-Mode only.
- */
- __STATIC_INLINE void MInvalCCache(void)
- {
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all Cluster Cache in S-Mode
- * \details
- * This function invalidate all Cluster Cache.
- * \remarks
- * This function must be executed in M/S-Mode only.
- */
- __STATIC_INLINE void SInvalCCache(void)
- {
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all Cluster Cache in U-Mode
- * \details
- * This function invalidate all Cluster Cache.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- */
- __STATIC_INLINE void UInvalCCache(void)
- {
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all I-Cache and Cluster Cache in M-Mode
- * \details
- * This function unlock and invalidate all I-Cache and Cluster Cache.
- * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- */
- __STATIC_INLINE void MInvalICacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_IC_INVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all I-Cache and Cluster Cache in S-Mode
- * \details
- * This function unlock and invalidate all I-Cache and Cluster Cache.
- * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- */
- __STATIC_INLINE void SInvalICacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_IC_INVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all I-Cache and Cluster Cache in U-Mode
- * \details
- * This function unlock and invalidate all I-Cache and Cluster Cache.
- * Command \ref CCM_IC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- */
- __STATIC_INLINE void UInvalICacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_IC_INVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
- /** @} */ /* End of Doxygen Group NMSIS_Core_ICache */
- #endif /* defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1) */
- #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1)
- /**
- * \defgroup NMSIS_Core_DCache D-Cache Functions
- * \ingroup NMSIS_Core_Cache
- * \brief Functions that configure Data Cache.
- * @{
- */
- /**
- * \brief Check DCache Unit Present or Not
- * \details
- * This function check dcache unit present or not via mcfg_info csr
- * \remarks
- * - This function might not work for some old nuclei processors
- * - Please make sure the version of your nuclei processor contain DCACHE bit in mcfg_info
- * \return 1 if present otherwise 0
- */
- __STATIC_INLINE int32_t DCachePresent(void)
- {
- if (__RV_CSR_READ(CSR_MCFG_INFO) & MCFG_INFO_DCACHE) {
- return 1;
- }
- return 0;
- }
- /**
- * \brief Enable DCache
- * \details
- * This function enable D-Cache
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control D Cache enable.
- * \sa
- * - \ref DisableDCache
- */
- __STATIC_FORCEINLINE void EnableDCache(void)
- {
- __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_EN);
- }
- /**
- * \brief Disable DCache
- * \details
- * This function Disable D-Cache
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control D Cache enable.
- * \sa
- * - \ref EnableDCache
- */
- __STATIC_FORCEINLINE void DisableDCache(void)
- {
- __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_EN);
- }
- /**
- * \brief Enable DCache ECC
- * \details
- * This function enable D-Cache ECC
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control D Cache ECC enable.
- * \sa
- * - \ref DisableDCacheECC
- */
- __STATIC_FORCEINLINE void EnableDCacheECC(void)
- {
- __RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN);
- }
- /**
- * \brief Disable DCache ECC
- * \details
- * This function disable D-Cache ECC
- * \remarks
- * - This function can be called in M-Mode only.
- * - This \ref CSR_MCACHE_CTL register control D Cache ECC enable.
- * \sa
- * - \ref EnableDCacheECC
- */
- __STATIC_FORCEINLINE void DisableDCacheECC(void)
- {
- __RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN);
- }
- #if defined(__CCM_PRESENT) && (__CCM_PRESENT == 1)
- /**
- * \brief Get D-Cache Information
- * \details
- * This function get D-Cache Information
- * \remarks
- * - This function can be called in M-Mode only.
- * - You can use this function in combination with cache lines operations
- * \sa
- * - \ref GetICacheInfo
- */
- __STATIC_INLINE int32_t GetDCacheInfo(CacheInfo_Type *info)
- {
- if (info == NULL) {
- return -1;
- }
- CSR_MDCFGINFO_Type csr_ccfg;
- csr_ccfg.d = __RV_CSR_READ(CSR_MDCFG_INFO);
- info->setperway = (1UL << csr_ccfg.b.set) << 3;
- info->ways = (1 + csr_ccfg.b.way);
- if (csr_ccfg.b.lsize == 0) {
- info->linesize = 0;
- } else {
- info->linesize = (1UL << (csr_ccfg.b.lsize - 1)) << 3;
- }
- info->size = info->setperway * info->ways * info->linesize;
- return 0;
- }
- /**
- * \brief Invalidate one D-Cache line specified by address in M-Mode
- * \details
- * This function unlock and invalidate one D-Cache line specified
- * by the address.
- * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void MInvalDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several D-Cache lines specified by address in M-Mode
- * \details
- * This function unlock and invalidate several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void MInvalDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate one D-Cache line specified by address in S-Mode
- * \details
- * This function unlock and invalidate one D-Cache line specified
- * by the address.
- * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void SInvalDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several D-Cache lines specified by address in S-Mode
- * \details
- * This function unlock and invalidate several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void SInvalDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate one D-Cache line specified by address in U-Mode
- * \details
- * This function unlock and invalidate one D-Cache line specified
- * by the address.
- * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void UInvalDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate several D-Cache lines specified by address in U-Mode
- * \details
- * This function unlock and invalidate several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_INVAL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- __STATIC_INLINE void UInvalDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Flush one D-Cache line specified by address in M-Mode
- * \details
- * This function flush one D-Cache line specified by the address.
- * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be flushed
- */
- __STATIC_INLINE void MFlushDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush several D-Cache lines specified by address in M-Mode
- * \details
- * This function flush several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be flushed
- * \param [in] cnt count of cache lines to be flushed
- */
- __STATIC_INLINE void MFlushDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Flush one D-Cache line specified by address in S-Mode
- * \details
- * This function flush one D-Cache line specified by the address.
- * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed
- */
- __STATIC_INLINE void SFlushDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush several D-Cache lines specified by address in S-Mode
- * \details
- * This function flush several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed
- * \param [in] cnt count of cache lines to be flushed
- */
- __STATIC_INLINE void SFlushDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Flush one D-Cache line specified by address in U-Mode
- * \details
- * This function flush one D-Cache line specified by the address.
- * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed
- */
- __STATIC_INLINE void UFlushDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush several D-Cache lines specified by address in U-Mode
- * \details
- * This function flush several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_WB is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed
- * \param [in] cnt count of cache lines to be flushed
- */
- __STATIC_INLINE void UFlushDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Flush and invalidate one D-Cache line specified by address in M-Mode
- * \details
- * This function flush and invalidate one D-Cache line specified by the address.
- * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- */
- __STATIC_INLINE void MFlushInvalDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush and invalidate several D-Cache lines specified by address in M-Mode
- * \details
- * This function flush and invalidate several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- * \param [in] cnt count of cache lines to be flushed and invalidated
- */
- __STATIC_INLINE void MFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Flush and invalidate one D-Cache line specified by address in S-Mode
- * \details
- * This function flush and invalidate one D-Cache line specified by the address.
- * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- */
- __STATIC_INLINE void SFlushInvalDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush and invalidate several D-Cache lines specified by address in S-Mode
- * \details
- * This function flush and invalidate several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- * \param [in] cnt count of cache lines to be flushed and invalidated
- */
- __STATIC_INLINE void SFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Flush and invalidate one D-Cache line specified by address in U-Mode
- * \details
- * This function flush and invalidate one D-Cache line specified by the address.
- * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- */
- __STATIC_INLINE void UFlushInvalDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush and invalidate several D-Cache lines specified by address in U-Mode
- * \details
- * This function flush and invalidate several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_WBINVAL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- * \param [in] cnt count of cache lines to be flushed and invalidated
- */
- __STATIC_INLINE void UFlushInvalDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- /**
- * \brief Invalidate one D-Cache and Cluster Cache line specified by address in M-Mode
- * \details
- * This macro is an alias for MInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- */
- #define MInvalDCacheCCacheLine(addr) MInvalDCacheLine(addr)
- /**
- * \brief Invalidate several D-Cache and Cluster Cache lines specified by address in M-Mode
- * \details
- * This macro is an alias for MInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- #define MInvalDCacheCCacheLines(addr, cnt) MInvalDCacheLines(addr, cnt)
- /**
- * \brief Invalidate one D-Cache and Cluster Cache line specified by address in S-Mode
- * \details
- * This macro is an alias for SInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- */
- #define SInvalDCacheCCacheLine(addr) SInvalDCacheLine(addr)
- /**
- * \brief Invalidate several D-Cache and Cluster Cache lines specified by address in S-Mode
- * \details
- * This macro is an alias for SInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- #define SInvalDCacheCCacheLines(addr, cnt) SInvalDCacheLines(addr, cnt)
- /**
- * \brief Invalidate one D-Cache and Cluster Cache line specified by address in U-Mode
- * \details
- * This macro is an alias for UInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- */
- #define UInvalDCacheCCacheLine(addr) UInvalDCacheLine(addr)
- /**
- * \brief Invalidate several D-Cache and Cluster Cache lines specified by address in U-Mode
- * \details
- * This macro is an alias for UInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- * \param [in] cnt count of cache lines to be invalidated
- */
- #define UInvalDCacheCCacheLines(addr, cnt) UInvalDCacheLines(addr, cnt)
- /**
- * \brief Flush one D-Cache and Cluster Cache line specified by address in M-Mode
- * \details
- * This macro is an alias for MFlushDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M-Mode only.
- * \param [in] addr start address to be flushed
- */
- #define MFlushDCacheCCacheLine(addr) MFlushDCacheLine(addr)
- /**
- * \brief Flush several D-Cache and Cluster Cache lines specified by address in M-Mode
- * \details
- * This macro is an alias for MFlushDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M-Mode only.
- * \param [in] addr start address to be flushed
- * \param [in] cnt count of cache lines to be flushed
- */
- #define MFlushDCacheCCacheLines(addr, cnt) MFlushDCacheLines(addr, cnt)
- /**
- * \brief Flush one D-Cache and Cluster Cache line specified by address in S-Mode
- * \details
- * This macro is an alias for SFlushDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed
- */
- #define SFlushDCacheCCacheLine(addr) SFlushDCacheLine(addr)
- /**
- * \brief Flush several D-Cache and Cluster Cache lines specified by address in S-Mode
- * \details
- * This macro is an alias for SFlushDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed
- * \param [in] cnt count of cache lines to be flushed
- */
- #define SFlushDCacheCCacheLines(addr, cnt) SFlushDCacheLines(addr, cnt)
- /**
- * \brief Flush one D-Cache and Cluster Cache line specified by address in U-Mode
- * \details
- * This macro is an alias for UFlushDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed
- */
- #define UFlushDCacheCCacheLine(addr) UFlushDCacheLine(addr)
- /**
- * \brief Flush several D-Cache and Cluster Cache lines specified by address in U-Mode
- * \details
- * This macro is an alias for UFlushDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed
- * \param [in] cnt count of cache lines to be flushed
- */
- #define UFlushDCacheCCacheLines(addr, cnt) UFlushDCacheLines(addr, cnt)
- /**
- * \brief Flush and invalidate one D-Cache and Cluster Cache line specified by address in M-Mode
- * \details
- * This macro is an alias for MFlushInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- */
- #define MFlushInvalDCacheCCacheLine(addr) MFlushInvalDCacheLine(addr)
- /**
- * \brief Flush and invalidate several D-Cache and Cluster Cache lines specified by address in M-Mode
- * \details
- * This macro is an alias for MFlushInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- * \param [in] cnt count of cache lines to be flushed and invalidated
- */
- #define MFlushInvalDCacheCCacheLines(addr, cnt) MFlushInvalDCacheLines(addr, cnt)
- /**
- * \brief Flush and invalidate one D-Cache and Cluster Cache line specified by address in S-Mode
- * \details
- * This macro is an alias for SFlushInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- */
- #define SFlushInvalDCacheCCacheLine(addr) SFlushInvalDCacheLine(addr)
- /**
- * \brief Flush and invalidate several D-Cache and Cluster Cache lines specified by address in S-Mode
- * \details
- * This macro is an alias for SFlushInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- * \param [in] cnt count of cache lines to be flushed and invalidated
- */
- #define SFlushInvalDCacheCCacheLines(addr, cnt) SFlushInvalDCacheLines(addr, cnt)
- /**
- * \brief Flush and invalidate one D-Cache and Cluster Cache line specified by address in U-Mode
- * \details
- * This macro is an alias for UFlushInvalDCacheLine. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- */
- #define UFlushInvalDCacheCCacheLine(addr) UFlushInvalDCacheLine(addr)
- /**
- * \brief Flush and invalidate several D-Cache and Cluster Cache lines specified by address in U-Mode
- * \details
- * This macro is an alias for UFlushInvalDCacheLines. D-Cache CCM operations are also effective for Cluster Cache.
- * \remarks
- * This macro must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed and invalidated
- * \param [in] cnt count of cache lines to be flushed and invalidated
- */
- #define UFlushInvalDCacheCCacheLines(addr, cnt) UFlushInvalDCacheLines(addr, cnt)
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- /**
- * \brief Lock one D-Cache line specified by address in M-Mode
- * \details
- * This function lock one D-Cache line specified by the address.
- * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long MLockDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_MDATA);
- }
- /**
- * \brief Lock several D-Cache lines specified by address in M-Mode
- * \details
- * This function lock several D-Cache lines specified by the address
- * and line count.
- * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long MLockDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_MDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Lock one D-Cache line specified by address in S-Mode
- * \details
- * This function lock one D-Cache line specified by the address.
- * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long SLockDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_SDATA);
- }
- /**
- * \brief Lock several D-Cache lines specified by address in S-Mode
- * \details
- * This function lock several D-Cache lines specified by the address
- * and line count.
- * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long SLockDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_SDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Lock one D-Cache line specified by address in U-Mode
- * \details
- * This function lock one D-Cache line specified by the address.
- * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long ULockDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_LOCK);
- FlushPipeCCM();
- __RWMB();
- return __RV_CSR_READ(CSR_CCM_UDATA);
- }
- /**
- * \brief Lock several D-Cache lines specified by address in U-Mode
- * \details
- * This function lock several D-Cache lines specified by the address
- * and line count.
- * Command \ref CCM_DC_LOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be locked
- * \param [in] cnt count of cache lines to be locked
- * \return result of CCM lock operation, see enum \ref CCM_OP_FINFO
- */
- __STATIC_INLINE unsigned long ULockDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- unsigned long fail_info = CCM_OP_SUCCESS;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_LOCK);
- FlushPipeCCM();
- __RWMB();
- fail_info = __RV_CSR_READ(CSR_CCM_UDATA);
- if (CCM_OP_SUCCESS != fail_info) {
- return fail_info;
- }
- }
- }
- return CCM_OP_SUCCESS;
- }
- /**
- * \brief Unlock one D-Cache line specified by address in M-Mode
- * \details
- * This function unlock one D-Cache line specified by the address.
- * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void MUnlockDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several D-Cache lines specified by address in M-Mode
- * \details
- * This function unlock several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void MUnlockDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_MBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Unlock one D-Cache line specified by address in S-Mode
- * \details
- * This function unlock one D-Cache line specified by the address.
- * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void SUnlockDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several D-Cache lines specified by address in S-Mode
- * \details
- * This function unlock several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void SUnlockDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_SBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Unlock one D-Cache line specified by address in U-Mode
- * \details
- * This function unlock one D-Cache line specified by the address.
- * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be unlocked
- */
- __STATIC_INLINE void UUnlockDCacheLine(unsigned long addr)
- {
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_UNLOCK);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Unlock several D-Cache lines specified by address in U-Mode
- * \details
- * This function unlock several D-Cache lines specified
- * by the address and line count.
- * Command \ref CCM_DC_UNLOCK is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be unlocked
- * \param [in] cnt count of cache lines to be unlocked
- */
- __STATIC_INLINE void UUnlockDCacheLines(unsigned long addr, unsigned long cnt)
- {
- if (cnt > 0) {
- unsigned long i;
- __RV_CSR_WRITE(CSR_CCM_UBEGINADDR, addr);
- for (i = 0; i < cnt; i++) {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_UNLOCK);
- }
- FlushPipeCCM();
- __RWMB();
- }
- }
- /**
- * \brief Invalidate all D-Cache lines in M-Mode
- * \details
- * This function invalidate all D-Cache lines.
- * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void MInvalDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate all D-Cache lines in S-Mode
- * \details
- * This function invalidate all D-Cache lines.
- * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void SInvalDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Invalidate all D-Cache lines in U-Mode
- * \details
- * This function invalidate all D-Cache lines.
- * In U-Mode, this operation will be automatically
- * translated to flush and invalidate operations by hardware.
- * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be invalidated
- */
- __STATIC_INLINE void UInvalDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush all D-Cache lines in M-Mode
- * \details
- * This function flush all D-Cache lines.
- * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be flushed
- */
- __STATIC_INLINE void MFlushDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush all D-Cache lines in S-Mode
- * \details
- * This function flush all D-Cache lines.
- * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed
- */
- __STATIC_INLINE void SFlushDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush all D-Cache lines in U-Mode
- * \details
- * This function flush all D-Cache lines.
- * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed
- */
- __STATIC_INLINE void UFlushDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush and invalidate all D-Cache lines in M-Mode
- * \details
- * This function flush and invalidate all D-Cache lines.
- * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \param [in] addr start address to be flushed and locked
- */
- __STATIC_INLINE void MFlushInvalDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush and invalidate all D-Cache lines in S-Mode
- * \details
- * This function flush and invalidate all D-Cache lines.
- * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \param [in] addr start address to be flushed and locked
- */
- __STATIC_INLINE void SFlushInvalDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- /**
- * \brief Flush and invalidate all D-Cache lines in U-Mode
- * \details
- * This function flush and invalidate all D-Cache lines.
- * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \param [in] addr start address to be flushed and locked
- */
- __STATIC_INLINE void UFlushInvalDCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL_ALL);
- FlushPipeCCM();
- __RWMB();
- }
- #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
- /**
- * \brief Flush all Cluster Cache in M-Mode
- * \details
- * This function flush all Cluster Cache.
- * Command \ref SMPCC_CMD_WB_ALL is written to SMPCC CMD register.
- * \remarks
- * This function must be executed in M-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t MFlushCCache(void)
- {
- SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush all Cluster Cache in S-Mode
- * \details
- * This function flush all Cluster Cache.
- * Command \ref SMPCC_CMD_WB_ALL is written to SMPCC CMD register.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t SFlushCCache(void)
- {
- SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush all Cluster Cache in U-Mode
- * \details
- * This function flush all Cluster Cache.
- * Command \ref SMPCC_CMD_WB_ALL is written to SMPCC CMD register.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t UFlushCCache(void)
- {
- SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush and invalidate all Cluster Cache in M-Mode
- * \details
- * This function flush and invalidate all Cluster Cache.
- * Command \ref SMPCC_CMD_WBINVAL_ALL is written to SMPCC CMD register.
- * \remarks
- * This function must be executed in M-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t MFlushInvalCCache(void)
- {
- SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush and invalidate all Cluster Cache in S-Mode
- * \details
- * This function flush and invalidate all Cluster Cache.
- * Command \ref SMPCC_CMD_WBINVAL_ALL is written to SMPCC CMD register.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t SFlushInvalCCache(void)
- {
- SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush and invalidate all Cluster Cache in U-Mode
- * \details
- * This function flush and invalidate all Cluster Cache.
- * Command \ref SMPCC_CMD_WBINVAL_ALL is written to SMPCC CMD register.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t UFlushInvalCCache(void)
- {
- SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Invalidate all D-Cache and Cluster Cache in M-Mode
- * \details
- * This function unlock and invalidate all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- */
- __STATIC_INLINE void MInvalDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_INVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all D-Cache and Cluster Cache in S-Mode
- * \details
- * This function unlock and invalidate all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- */
- __STATIC_INLINE void SInvalDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_INVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Invalidate all D-Cache and Cluster Cache in U-Mode
- * \details
- * This function unlock and invalidate all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_INVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- */
- __STATIC_INLINE void UInvalDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_INVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_INVALID_ALL = _VAL2FLD(SMPCC_CMD_INVALID_ALL, 1);
- while(_FLD2VAL(SMPCC_CMD_INVALID_ALL, SMPCC_CMD->CC_INVALID_ALL));
- __RWMB();
- }
- /**
- * \brief Flush all D-Cache and Cluster Cache in M-Mode
- * \details
- * This function flush all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t MFlushDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WB_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush all D-Cache and Cluster Cache in S-Mode
- * \details
- * This function flush all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t SFlushDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WB_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush all D-Cache and Cluster Cache in U-Mode
- * \details
- * This function flush all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_WB_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t UFlushDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WB_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WB_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush and invalidate all D-Cache and Cluster Cache in M-Mode
- * \details
- * This function flush and invalidate all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_MCOMMAND.
- * \remarks
- * This function must be executed in M-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t MFlushInvalDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_MCOMMAND, CCM_DC_WBINVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_mCMD = (SMPCC_CMD->CC_mCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_mCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_mCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush and invalidate all D-Cache and Cluster Cache in S-Mode
- * \details
- * This function flush and invalidate all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_SCOMMAND.
- * \remarks
- * This function must be executed in M/S-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t SFlushInvalDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_SCOMMAND, CCM_DC_WBINVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_sCMD = (SMPCC_CMD->CC_sCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_sCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_sCMD);
- __RWMB();
- return res;
- }
- /**
- * \brief Flush and invalidate all D-Cache and Cluster Cache in U-Mode
- * \details
- * This function flush and invalidate all D-Cache and Cluster Cache.
- * Command \ref CCM_DC_WBINVAL_ALL is written to CSR \ref CSR_CCM_UCOMMAND.
- * \remarks
- * This function must be executed in M/S/U-Mode only.
- * \return Operation result, see enum \ref SMPCC_CMD_RESULT
- */
- __STATIC_INLINE int32_t UFlushInvalDCacheCCache(void)
- {
- __RV_CSR_WRITE(CSR_CCM_UCOMMAND, CCM_DC_WBINVAL_ALL);
- FlushPipeCCM();
- SMPCC_CMD->CC_uCMD = (SMPCC_CMD->CC_uCMD & ~SMPCC_CMD_xCMD_CMD_Msk) |
- _VAL2FLD(SMPCC_CMD_xCMD_CMD, SMPCC_CMD_xCMD_CMD_WBINVAL_ALL);
- while(_FLD2VAL(SMPCC_CMD_xCMD_COMPLETE, SMPCC_CMD->CC_uCMD) == 0);
- int32_t res = _FLD2VAL(SMPCC_CMD_xCMD_RESULT, SMPCC_CMD->CC_uCMD);
- __RWMB();
- return res;
- }
- #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
- #endif /* defined(__CCM_PRESENT) && (__CCM_PRESENT == 1) */
- /** @} */ /* End of Doxygen Group NMSIS_Core_DCache */
- #endif /* defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1) */
- #ifdef __cplusplus
- }
- #endif
- #endif /* __CORE_FEATURE_CACHE_H__ */
|