NMSIS-Core  Version 1.5.0
NMSIS-Core support for Nuclei processor-based devices
Cache Functions

Functions that configure Instruction and Data Cache. More...

Modules

 Cluster-Cache Functions
 Functions that configure Cluster Cache by CCM.
 
 I-Cache Functions
 Functions that configure Instruction Cache.
 
 D-Cache Functions
 Functions that configure Data Cache.
 

Data Structures

struct  CacheInfo_Type
 Cache Information Type. More...
 

Macros

#define CCM_SUEN_SUEN_Msk   (0xFFFFFFFFFFFFFFFFUL)
 CSR CCM_SUEN: SUEN Mask. More...
 

Enumerations

enum  CCM_OP_FINFO_Type {
  CCM_OP_SUCCESS = 0x0 ,
  CCM_OP_EXCEED_ERR = 0x1 ,
  CCM_OP_PERM_CHECK_ERR = 0x2 ,
  CCM_OP_REFILL_BUS_ERR = 0x3 ,
  CCM_OP_ECC_ERR = 0x4
}
 Cache CCM Operation Fail Info. More...
 
enum  CCM_CMD_Type {
  CCM_DC_INVAL = 0x0 ,
  CCM_DC_WB = 0x1 ,
  CCM_DC_WBINVAL = 0x2 ,
  CCM_DC_LOCK = 0x3 ,
  CCM_DC_UNLOCK = 0x4 ,
  CCM_DC_WBINVAL_ALL = 0x6 ,
  CCM_DC_WB_ALL = 0x7 ,
  CCM_DC_INVAL_ALL = 0x17 ,
  CCM_IC_INVAL = 0x8 ,
  CCM_IC_LOCK = 0xb ,
  CCM_IC_UNLOCK = 0xc ,
  CCM_IC_INVAL_ALL = 0xd ,
  CCM_CC_LOCK = 0x13 ,
  CCM_CC_UNLOCK = 0x12
}
 Cache CCM Command Types. More...
 

Functions

__STATIC_FORCEINLINE void EnableSUCCM (void)
 Enable CCM operation in Supervisor/User Mode. More...
 
__STATIC_FORCEINLINE void DisableSUCCM (void)
 Disable CCM operation in Supervisor/User Mode. More...
 
__STATIC_FORCEINLINE void FlushPipeCCM (void)
 Flush pipeline after CCM operation. More...
 

Detailed Description

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 EnableSUCCM in M-Mode to enable it.

Macro Definition Documentation

◆ CCM_SUEN_SUEN_Msk

#define CCM_SUEN_SUEN_Msk   (0xFFFFFFFFFFFFFFFFUL)

CSR CCM_SUEN: SUEN Mask.

Definition at line 180 of file core_feature_cache.h.

Enumeration Type Documentation

◆ CCM_CMD_Type

Cache CCM Command Types.

Enumerator
CCM_DC_INVAL 

Unlock and invalidate D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR.

CCM_DC_WB 

Flush the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR.

CCM_DC_WBINVAL 

Unlock, flush and invalidate the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR.

CCM_DC_LOCK 

Lock the specific D-Cache line specified by CSR CCM_XBEGINADDR.

CCM_DC_UNLOCK 

Unlock the specific D-Cache line specified by CSR CCM_XBEGINADDR.

CCM_DC_WBINVAL_ALL 

Unlock and flush and invalidate all the valid and dirty D-Cache lines.

CCM_DC_WB_ALL 

Flush all the valid and dirty D-Cache lines.

CCM_DC_INVAL_ALL 

Unlock and invalidate all the D-Cache lines.

CCM_IC_INVAL 

Unlock and invalidate I-Cache line specified by CSR CCM_XBEGINADDR.

CCM_IC_LOCK 

Lock the specific I-Cache line specified by CSR CCM_XBEGINADDR.

CCM_IC_UNLOCK 

Unlock the specific I-Cache line specified by CSR CCM_XBEGINADDR.

CCM_IC_INVAL_ALL 

Unlock and invalidate all the I-Cache lines.

CCM_CC_LOCK 

Lock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR.

CCM_CC_UNLOCK 

Unlock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR.

Definition at line 150 of file core_feature_cache.h.

150  {
151  CCM_DC_INVAL = 0x0,
152  CCM_DC_WB = 0x1,
153  CCM_DC_WBINVAL = 0x2,
154  CCM_DC_LOCK = 0x3,
155  CCM_DC_UNLOCK = 0x4,
156  CCM_DC_WBINVAL_ALL = 0x6,
157  CCM_DC_WB_ALL = 0x7,
158  CCM_DC_INVAL_ALL = 0x17,
159  CCM_IC_INVAL = 0x8,
160  CCM_IC_LOCK = 0xb,
161  CCM_IC_UNLOCK = 0xc,
162  CCM_IC_INVAL_ALL = 0xd,
163  CCM_CC_LOCK = 0x13,
164  CCM_CC_UNLOCK = 0x12,
165 } CCM_CMD_Type;
CCM_CMD_Type
Cache CCM Command Types.
@ CCM_DC_WB
Flush the specific D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_DC_INVAL
Unlock and invalidate D-Cache line and Cluster Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_DC_WBINVAL
Unlock, flush and invalidate the specific D-Cache line and Cluster Cache line specified by CSR CCM_XB...
@ CCM_DC_LOCK
Lock the specific D-Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_IC_INVAL
Unlock and invalidate I-Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_IC_LOCK
Lock the specific I-Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_DC_WB_ALL
Flush all the valid and dirty D-Cache lines.
@ CCM_DC_INVAL_ALL
Unlock and invalidate all the D-Cache lines.
@ CCM_IC_INVAL_ALL
Unlock and invalidate all the I-Cache lines.
@ CCM_CC_LOCK
Lock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_DC_WBINVAL_ALL
Unlock and flush and invalidate all the valid and dirty D-Cache lines.
@ CCM_DC_UNLOCK
Unlock the specific D-Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_CC_UNLOCK
Unlock the specific Cluster Cache line specified by CSR CCM_XBEGINADDR.
@ CCM_IC_UNLOCK
Unlock the specific I-Cache line specified by CSR CCM_XBEGINADDR.

◆ CCM_OP_FINFO_Type

Cache CCM Operation Fail Info.

Enumerator
CCM_OP_SUCCESS 

Lock Succeed.

CCM_OP_EXCEED_ERR 

Exceed the the number of lockable ways(N-Way I/D-Cache, lockable is N-1)

CCM_OP_PERM_CHECK_ERR 

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 

Refill has Bus Error.

CCM_OP_ECC_ERR 

Deprecated, ECC Error, this error code is removed in later Nuclei CCM RTL design, please don't use it.

Definition at line 139 of file core_feature_cache.h.

139  {
140  CCM_OP_SUCCESS = 0x0,
141  CCM_OP_EXCEED_ERR = 0x1,
142  CCM_OP_PERM_CHECK_ERR = 0x2,
143  CCM_OP_REFILL_BUS_ERR = 0x3,
144  CCM_OP_ECC_ERR = 0x4
CCM_OP_FINFO_Type
Cache CCM Operation Fail Info.
@ CCM_OP_REFILL_BUS_ERR
Refill has Bus Error.
@ CCM_OP_ECC_ERR
Deprecated, ECC Error, this error code is removed in later Nuclei CCM RTL design, please don't use it...
@ CCM_OP_PERM_CHECK_ERR
PMP/sPMP/Page-Table X(I-Cache)/R(D-Cache) permission check failed, or belong to Device/Non-Cacheable ...
@ CCM_OP_SUCCESS
Lock Succeed.
@ CCM_OP_EXCEED_ERR
Exceed the the number of lockable ways(N-Way I/D-Cache, lockable is N-1)

Function Documentation

◆ DisableSUCCM()

__STATIC_FORCEINLINE void DisableSUCCM ( void  )

Disable CCM operation in Supervisor/User Mode.

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.
See also

Definition at line 216 of file core_feature_cache.h.

217 {
219 #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
220  SMPCC_CMD->CC_CTRL &= ~_VAL2FLD(SMPCC_CMD_CTRL_SUP_EN, SMPCC_CMD_CTRL_SUP_EN_DISABLE) &
221  ~_VAL2FLD(SMPCC_CMD_CTRL_USE_EN, SMPCC_CMD_CTRL_USE_EN_DISABLE);
222 #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
223 }
#define SMPCC_CMD
SMPCC CMD configuration struct.
#define SMPCC_CMD_CTRL_USE_EN_DISABLE
SMPCC_CMD CC_CTRL USE_EN Disable.
#define SMPCC_CMD_CTRL_SUP_EN_DISABLE
SMPCC_CMD CC_CTRL SUP_EN Disable.
#define __RV_CSR_CLEAR(csr, val)
CSR operation Macro for csrc instruction.
#define CSR_CCM_SUEN
#define CCM_SUEN_SUEN_Msk
CSR CCM_SUEN: SUEN Mask.
#define _VAL2FLD(field, value)
Mask and shift a bit field value for use in a register bit range.

References __RV_CSR_CLEAR, _VAL2FLD, CCM_SUEN_SUEN_Msk, CSR_CCM_SUEN, SMPCC_CMD, SMPCC_CMD_CTRL_SUP_EN_DISABLE, and SMPCC_CMD_CTRL_USE_EN_DISABLE.

◆ EnableSUCCM()

__STATIC_FORCEINLINE void EnableSUCCM ( void  )

Enable CCM operation in Supervisor/User Mode.

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.
See also

Definition at line 195 of file core_feature_cache.h.

196 {
198 #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1)
199  SMPCC_CMD->CC_CTRL |= _VAL2FLD(SMPCC_CMD_CTRL_SUP_EN, SMPCC_CMD_CTRL_SUP_EN_ENABLE) |
200  _VAL2FLD(SMPCC_CMD_CTRL_USE_EN, SMPCC_CMD_CTRL_USE_EN_ENABLE);
201 #endif /* #if defined(__SMPCC_PRESENT) && (__SMPCC_PRESENT == 1) */
202 }
#define SMPCC_CMD_CTRL_USE_EN_ENABLE
SMPCC_CMD CC_CTRL USE_EN Enable.
#define SMPCC_CMD_CTRL_SUP_EN_ENABLE
SMPCC_CMD CC_CTRL SUP_EN Enable.
#define __RV_CSR_SET(csr, val)
CSR operation Macro for csrs instruction.

References __RV_CSR_SET, _VAL2FLD, CCM_SUEN_SUEN_Msk, CSR_CCM_SUEN, SMPCC_CMD, SMPCC_CMD_CTRL_SUP_EN_ENABLE, and SMPCC_CMD_CTRL_USE_EN_ENABLE.

Referenced by _premain_init().

◆ FlushPipeCCM()

__STATIC_FORCEINLINE void FlushPipeCCM ( void  )

Flush pipeline after CCM operation.

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.

Definition at line 234 of file core_feature_cache.h.

235 {
237 }
#define __RV_CSR_WRITE(csr, val)
CSR operation Macro for csrw instruction.
#define CSR_CCM_FPIPE

References __RV_CSR_WRITE, and CSR_CCM_FPIPE.

Referenced by MFlushDCache(), MFlushDCacheCCache(), MFlushDCacheLine(), MFlushDCacheLines(), MFlushInvalDCache(), MFlushInvalDCacheCCache(), MFlushInvalDCacheLine(), MFlushInvalDCacheLines(), MInvalDCache(), MInvalDCacheCCache(), MInvalDCacheLine(), MInvalDCacheLines(), MInvalICache(), MInvalICacheCCache(), MInvalICacheCCacheLine(), MInvalICacheCCacheLines(), MInvalICacheLine(), MInvalICacheLines(), MLockCCacheLine(), MLockCCacheLines(), MLockDCacheLine(), MLockDCacheLines(), MLockICacheLine(), MLockICacheLines(), MUnlockCCacheLine(), MUnlockCCacheLines(), MUnlockDCacheLine(), MUnlockDCacheLines(), MUnlockICacheLine(), MUnlockICacheLines(), SFlushDCache(), SFlushDCacheCCache(), SFlushDCacheLine(), SFlushDCacheLines(), SFlushInvalDCache(), SFlushInvalDCacheCCache(), SFlushInvalDCacheLine(), SFlushInvalDCacheLines(), SInvalDCache(), SInvalDCacheCCache(), SInvalDCacheLine(), SInvalDCacheLines(), SInvalICache(), SInvalICacheCCache(), SInvalICacheCCacheLine(), SInvalICacheCCacheLines(), SInvalICacheLine(), SInvalICacheLines(), SLockCCacheLine(), SLockCCacheLines(), SLockDCacheLine(), SLockDCacheLines(), SLockICacheLine(), SLockICacheLines(), SUnlockCCacheLine(), SUnlockCCacheLines(), SUnlockDCacheLine(), SUnlockDCacheLines(), SUnlockICacheLine(), SUnlockICacheLines(), UFlushDCache(), UFlushDCacheCCache(), UFlushDCacheLine(), UFlushDCacheLines(), UFlushInvalDCache(), UFlushInvalDCacheCCache(), UFlushInvalDCacheLine(), UFlushInvalDCacheLines(), UInvalDCache(), UInvalDCacheCCache(), UInvalDCacheLine(), UInvalDCacheLines(), UInvalICache(), UInvalICacheCCache(), UInvalICacheCCacheLine(), UInvalICacheCCacheLines(), UInvalICacheLine(), UInvalICacheLines(), ULockCCacheLine(), ULockCCacheLines(), ULockDCacheLine(), ULockDCacheLines(), ULockICacheLine(), ULockICacheLines(), UUnlockCCacheLine(), UUnlockCCacheLines(), UUnlockDCacheLine(), UUnlockDCacheLines(), UUnlockICacheLine(), and UUnlockICacheLines().