| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637 |
- /*
- * 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
- */
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "core_feature_base.h"
- #if defined(__CCM_PRESENT) && (__CCM_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 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 specified by CSR CCM_XBEGINADDR */
- CCM_DC_WB = 0x1, /*!< Flush the specific D-Cache line specified by CSR CCM_XBEGINADDR */
- CCM_DC_WBINVAL = 0x2, /*!< Unlock, flush and invalidate the specific D-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_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.
- * \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);
- }
- /**
- * \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.
- * \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);
- }
- /**
- * \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 */
- #endif
- #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();
- }
- }
- /**
- * \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();
- }
- #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();
- }
- }
- /**
- * \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();
- }
- #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__ */
|