Skip to content

Commit c68a903

Browse files
greentimepalmer-dabbelt
authored andcommitted
riscv: set pmp configuration if kernel is running in M-mode
When the kernel is running in S-mode, the expectation is that the bootloader or SBI layer will configure the PMP to allow the kernel to access physical memory. But, when the kernel is running in M-mode and is started with the ELF "loader", there's probably no bootloader or SBI layer involved to configure the PMP. Thus, we need to configure the PMP ourselves to enable the kernel to access all regions. Signed-off-by: Greentime Hu <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 11a48a5 commit c68a903

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

arch/riscv/include/asm/csr.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@
7272
#define EXC_LOAD_PAGE_FAULT 13
7373
#define EXC_STORE_PAGE_FAULT 15
7474

75+
/* PMP configuration */
76+
#define PMP_R 0x01
77+
#define PMP_W 0x02
78+
#define PMP_X 0x04
79+
#define PMP_A 0x18
80+
#define PMP_A_TOR 0x08
81+
#define PMP_A_NA4 0x10
82+
#define PMP_A_NAPOT 0x18
83+
#define PMP_L 0x80
84+
7585
/* symbolic CSR names: */
7686
#define CSR_CYCLE 0xc00
7787
#define CSR_TIME 0xc01
@@ -100,6 +110,8 @@
100110
#define CSR_MCAUSE 0x342
101111
#define CSR_MTVAL 0x343
102112
#define CSR_MIP 0x344
113+
#define CSR_PMPCFG0 0x3a0
114+
#define CSR_PMPADDR0 0x3b0
103115
#define CSR_MHARTID 0xf14
104116

105117
#ifdef CONFIG_RISCV_M_MODE

arch/riscv/kernel/head.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ _start_kernel:
5858
/* Reset all registers except ra, a0, a1 */
5959
call reset_regs
6060

61+
/* Setup a PMP to permit access to all of memory. */
62+
li a0, -1
63+
csrw CSR_PMPADDR0, a0
64+
li a0, (PMP_A_NAPOT | PMP_R | PMP_W | PMP_X)
65+
csrw CSR_PMPCFG0, a0
66+
6167
/*
6268
* The hartid in a0 is expected later on, and we have no firmware
6369
* to hand it to us.

0 commit comments

Comments
 (0)