Skip to content

Commit

Permalink
Add config for PMP granularity (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
poemonsense authored Sep 7, 2023
1 parent 3e1b467 commit 108f1d2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions configs/riscv64-nutshell-ref_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CONFIG_CLINT_MMIO=0x38000000
# CONFIG_RVH is not set
CONFIG_RV_PMP_CSR=y
CONFIG_RV_PMP_NUM=4
CONFIG_PMP_GRANULARITY=2
# CONFIG_RV_PMP_CHECK is not set
# CONFIG_RV_SVINVAL is not set
CONFIG_MISA_UNCHANGEABLE=y
Expand Down
1 change: 1 addition & 0 deletions configs/riscv64-nutshell_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CONFIG_CLINT_MMIO=0x38000000
# CONFIG_RVH is not set
CONFIG_RV_PMP_CSR=y
CONFIG_RV_PMP_NUM=4
CONFIG_PMP_GRANULARITY=2
# CONFIG_RV_SVINVAL is not set
CONFIG_MISA_UNCHANGEABLE=y
CONFIG_XTVEC_VECTORED_MODE=y
Expand Down
1 change: 1 addition & 0 deletions configs/riscv64-xs-ref_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONFIG_RV_DEBUG=y
# CONFIG_RVSDTRIG is not set
CONFIG_RV_PMP_CSR=y
CONFIG_RV_PMP_NUM=16
CONFIG_PMP_GRANULARITY=12
CONFIG_RV_PMP_CHECK=y
CONFIG_RV_SVINVAL=y
CONFIG_MISA_UNCHANGEABLE=y
Expand Down
22 changes: 21 additions & 1 deletion configs/riscv64-xs_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ CONFIG_CLINT_MMIO=0x38000000
CONFIG_RVB=y
CONFIG_RVK=y
# CONFIG_RVV is not set
CONFIG_RV_DEBUG=y
# CONFIG_RVH is not set
# CONFIG_RVSDEXT is not set
# CONFIG_RVSDTRIG is not set
CONFIG_RV_PMP_CSR=y
CONFIG_RV_PMP_NUM=16
CONFIG_PMP_GRANULARITY=12
CONFIG_RV_SVINVAL=y
CONFIG_MISA_UNCHANGEABLE=y
CONFIG_XTVEC_VECTORED_MODE=y
# CONFIG_TVAL_EX_II is not set
CONFIG_FS_CLEAN_STATE=y
CONFIG_RV_ARCH_CSRS=y
CONFIG_USE_XS_ARCH_CSRS=y
# end of ISA-dependent Options for riscv64

CONFIG_ENGINE_INTERPRETER=y
Expand Down Expand Up @@ -64,6 +77,9 @@ CONFIG_DIFFTEST_REF_NAME="none"
#
CONFIG_MBASE=0x80000000
CONFIG_MSIZE=0x200000000
CONFIG_PADDRBITS=36
# CONFIG_STORE_LOG is not set
# CONFIG_BR_LOG is not set
CONFIG_BBL_OFFSET_WITH_CPT=0xa0000
# CONFIG_RESET_FROM_MMIO is not set
CONFIG_PC_RESET_OFFSET=0x0
Expand All @@ -76,9 +92,12 @@ CONFIG_DEVICE=y
CONFIG_HAS_PORT_IO=y
# CONFIG_HAS_SERIAL is not set
CONFIG_HAS_UARTLITE=y
# CONFIG_HAS_UART_SNPS is not set
# CONFIG_HAS_PLIC is not set
CONFIG_UARTLITE_PORT=0x3f8
CONFIG_UARTLITE_MMIO=0x40600000
# CONFIG_UARTLITE_INPUT_FIFO is not set
# CONFIG_UARTLITE_ASSERT_FOUR is not set
CONFIG_HAS_TIMER=y
CONFIG_RTC_PORT=0x48
CONFIG_RTC_MMIO=0xa1000048
Expand All @@ -89,7 +108,7 @@ CONFIG_HAS_VGA=y
CONFIG_FB_ADDR=0x50000000
CONFIG_VGA_CTL_PORT=0x100
CONFIG_VGA_CTL_MMIO=0x40001000
CONFIG_VGA_SHOW_SCREEN=n
# CONFIG_VGA_SHOW_SCREEN is not set
CONFIG_VGA_SIZE_400x300=y
# CONFIG_VGA_SIZE_800x600 is not set
# CONFIG_HAS_AUDIO is not set
Expand All @@ -116,6 +135,7 @@ CONFIG_AC_SOFT=y
#
CONFIG_TIMER_GETTIMEOFDAY=y
# CONFIG_TIMER_CLOCK_GETTIME is not set
CONFIG_REPORT_ILLEGAL_INSTR=y
CONFIG_RT_CHECK=y
CONFIG_PERF_OPT=y
CONFIG_TCACHE_SIZE=8192
Expand Down
9 changes: 7 additions & 2 deletions src/isa/riscv64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ config RV_PMP_NUM
default 16
range 0 16

config PMP_GRANULARITY
depends on RV_PMP_CSR
int "PMP granularity"
default 12

config RV_PMP_CHECK
# todo: pmp check still not work when enable PERF_OPT
depends on !PERF_OPT
Expand Down Expand Up @@ -107,8 +112,8 @@ config MIMPID_VALUE
default 0x0

config PMPTABLE_EXTENSION
# PMPTable covers PMPChecker function,
# close PMPChecker when using PMPTable.
# PMPTable covers PMPChecker function,
# close PMPChecker when using PMPTable.
depends on !PERF_OPT
depends on !RV_PMP_CHECK
depends on RV_PMP_CSR
Expand Down
9 changes: 4 additions & 5 deletions src/isa/riscv64/local-include/csr.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
f(scontext , 0x6a8) \
f(tselect , 0x7a0) f(tdata1 , 0x7a1) f(tdata2 , 0x7a2) f(tdata3 , 0x7a3) \
f(tinfo , 0x7a4) f(tcontrol , 0x7a5) f(mcontext , 0x7a8) \

#else
#define TRIGGER_CSRS(f)
#endif // CONFIG_RVSDTRIG
Expand Down Expand Up @@ -276,7 +276,6 @@ CSR_STRUCT_END(mip)
#define PMP_A 0x18
#define PMP_L 0x80
#define PMP_SHIFT 2
#define PMP_PLATFORMGARIN 12 // log2(4KB)

#ifdef CONFIG_PMPTABLE_EXTENSION
#define PMP_T 0x20
Expand Down Expand Up @@ -607,11 +606,11 @@ CSR_STRUCT_START(tdata3) // 0x7a3
CSR_STRUCT_END(tdata3)

CSR_STRUCT_START(tinfo) // 0x7a4
uint64_t info : 16; // [15:0]
uint64_t info : 16; // [15:0]
CSR_STRUCT_END(tinfo)

CSR_STRUCT_START(tcontrol) // 0x7a5
uint64_t pad0 : 3; // [2:0]
uint64_t pad0 : 3; // [2:0]
uint64_t mte : 1; // [3]
uint64_t pad1 : 3; // [6:4]
uint64_t mpte : 1; // [7]
Expand Down Expand Up @@ -813,7 +812,7 @@ CSR_STRUCT_START(vsatp)
uint64_t asid :16;
uint64_t mode : 4;
}_64;
};
};
CSR_STRUCT_END(vsatp)
#endif //CONFIG_RVH

Expand Down
4 changes: 2 additions & 2 deletions src/isa/riscv64/system/priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ word_t pmpaddr_from_csrid(int id) {
}

word_t inline pmp_tor_mask() {
return -((word_t)1 << (PMP_PLATFORMGARIN - PMP_SHIFT));
return -((word_t)1 << (CONFIG_PMP_GRANULARITY - PMP_SHIFT));
}

static inline void update_mstatus_sd() {
Expand Down Expand Up @@ -547,7 +547,7 @@ static inline void csr_write(word_t *dest, word_t src) {
word_t cfg = ((src >> (i*8)) & 0xff);
#endif
cfg &= ~PMP_W | ((cfg & PMP_R) ? PMP_W : 0); // Disallow R=0 W=1
if (PMP_PLATFORMGARIN != PMP_SHIFT && (cfg & PMP_A) == PMP_NA4)
if (CONFIG_PMP_GRANULARITY != PMP_SHIFT && (cfg & PMP_A) == PMP_NA4)
cfg |= PMP_NAPOT; // Disallow A=NA4 when granularity > 4
cfg_data |= (cfg << (i*8));
}
Expand Down

0 comments on commit 108f1d2

Please sign in to comment.