Skip to content

Commit

Permalink
SoC/evalsoc: Add ECC_EN to control whether ECC is enabled or not for …
Browse files Browse the repository at this point in the history
…evalsoc

when ECC_EN=1, ECC check will be enabled during __premain_init function,
when ECC_EN=0, ECC check will be disabled, when not specified, nothing
will be changed.

Signed-off-by: Huaqi Fang <[email protected]>
  • Loading branch information
fanghuaqi committed Jul 15, 2024
1 parent eda116e commit 2fd590f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
45 changes: 41 additions & 4 deletions SoC/evalsoc/Common/Source/system_evalsoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,24 +749,42 @@ void _premain_init(void)
// TODO This code controlled by macros RUNMODE_* are only used internally by Nuclei
// You can remove it if you don't want it
// No need to use in your code
#if defined(RUNMODE_ILM_EN)
#if defined(RUNMODE_ILM_EN) || defined(RUNMODE_ECC_EN)
// Only disable ilm when it is present
if (mcfginfo & MCFG_INFO_ILM) {
#if defined(RUNMODE_ECC_EN)
#if RUNMODE_ECC_EN == 0
__RV_CSR_CLEAR(CSR_MILM_CTL, MILM_CTL_ILM_ECC_EN | MILM_CTL_ILM_ECC_EXCP_EN | MILM_CTL_ILM_ECC_CHK_EN);
#else
__RV_CSR_SET(CSR_MILM_CTL, MILM_CTL_ILM_ECC_EN | MILM_CTL_ILM_ECC_EXCP_EN | MILM_CTL_ILM_ECC_CHK_EN);
#endif
#endif
#if defined(RUNMODE_ILM_EN)
#if RUNMODE_ILM_EN == 0
__RV_CSR_CLEAR(CSR_MILM_CTL, MILM_CTL_ILM_EN);
#else
__RV_CSR_SET(CSR_MILM_CTL, MILM_CTL_ILM_EN);
#endif
#endif
}
#endif

#if defined(RUNMODE_DLM_EN)
#if defined(RUNMODE_DLM_EN) || defined(RUNMODE_ECC_EN)
// Only disable dlm when it is present
if (mcfginfo & MCFG_INFO_DLM) {
#if defined(RUNMODE_ECC_EN)
#if RUNMODE_ECC_EN == 0
__RV_CSR_CLEAR(CSR_MDLM_CTL, MDLM_CTL_DLM_ECC_EN | MDLM_CTL_DLM_ECC_EXCP_EN | MDLM_CTL_DLM_ECC_CHK_EN);
#else
__RV_CSR_SET(CSR_MDLM_CTL, MDLM_CTL_DLM_ECC_EN | MDLM_CTL_DLM_ECC_EXCP_EN | MDLM_CTL_DLM_ECC_CHK_EN);
#endif
#endif
#if defined(RUNMODE_DLM_EN)
#if RUNMODE_DLM_EN == 0
__RV_CSR_CLEAR(CSR_MDLM_CTL, MDLM_CTL_DLM_EN);
#else
__RV_CSR_SET(CSR_MDLM_CTL, MDLM_CTL_DLM_EN);
#endif
#endif
}
#endif
Expand All @@ -784,14 +802,33 @@ void _premain_init(void)
// __CCM_PRESENT is still default to 0 in evalsoc.h, since it is used in core_feature_eclic.h to register interrupt, if set to 1, it might cause exception
// but in the cpu, icache or dcache might not exist due to cpu configuration, so here
// we need to check whether icache/dcache really exist, if yes, then turn on it
#if defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1)
#if defined(__ICACHE_PRESENT) || defined(RUNMODE_ECC_EN)
if (ICachePresent()) { // Check whether icache real present or not
#if defined(RUNMODE_ECC_EN)
#if RUNMODE_ECC_EN == 0
__RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN | MCACHE_CTL_IC_ECC_EXCP_EN | MCACHE_CTL_IC_ECC_CHK_EN);
#else
__RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_IC_ECC_EN | MCACHE_CTL_IC_ECC_EXCP_EN | MCACHE_CTL_IC_ECC_CHK_EN);
#endif
#endif

#if defined(__ICACHE_PRESENT) && (__ICACHE_PRESENT == 1)
EnableICache();
#endif
}
#endif
#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1)
#if defined(__DCACHE_PRESENT) || defined(RUNMODE_ECC_EN)
if (DCachePresent()) { // Check whether dcache real present or not
#if defined(RUNMODE_ECC_EN)
#if RUNMODE_ECC_EN == 0
__RV_CSR_CLEAR(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN | MCACHE_CTL_DC_ECC_EXCP_EN | MCACHE_CTL_DC_ECC_CHK_EN);
#else
__RV_CSR_SET(CSR_MCACHE_CTL, MCACHE_CTL_DC_ECC_EN | MCACHE_CTL_DC_ECC_EXCP_EN | MCACHE_CTL_DC_ECC_CHK_EN);
#endif
#endif
#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1)
EnableDCache();
#endif
}
#endif

Expand Down
5 changes: 5 additions & 0 deletions SoC/evalsoc/runmode.mk
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ ifneq ($(BPU_EN),)
COMMON_FLAGS += -DRUNMODE_BPU_EN=$(BPU_EN)
endif

ECC_EN ?=
ifneq ($(ECC_EN),)
COMMON_FLAGS += -DRUNMODE_ECC_EN=$(ECC_EN)
endif

# NOTE: extra XLCFG_xxx make variables to control
# cpu feature present or not which is only internally used by Nuclei(XinLai)
# This will affect the cpufeature.h and evalsoc.h
Expand Down

0 comments on commit 2fd590f

Please sign in to comment.