Skip to contentSkip to conversation

target/riscv: csr: Implement mconfigptr CSR

PATCH In review Rahul Pathak 2 participants 4 messages Oct 3, 2021 – Oct 13, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: csr: Implement mconfigptr CSR

mconfigptr is an mandatory CSR as per the priv spec. This csr holds the physical address of the configuration data structure if this data structure is implemented Its an readonly csr set to zero making configuration data structure not supported.

---
 target/riscv/cpu_bits.h | 1 +
 target/riscv/csr.c      | 1 +
 2 files changed, 2 insertions(+)
target/riscv/cpu_bits.h +1 -0
index 999187a9ee..5dc4729ed5 100644
@@ -140,6 +140,7 @@
 #define CSR_MARCHID         0xf12
 #define CSR_MIMPID          0xf13
 #define CSR_MHARTID         0xf14
+#define CSR_MCONFIGPTR      0xf15 
 
 /* Machine Trap Setup */
 #define CSR_MSTATUS         0x300
target/riscv/csr.c +1 -0
index 23fbbd3216..2182943f54 100644
@@ -1549,6 +1549,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
     [CSR_MARCHID]   = { "marchid",   any,   read_zero    },
     [CSR_MIMPID]    = { "mimpid",    any,   read_zero    },
     [CSR_MHARTID]   = { "mhartid",   any,   read_mhartid },
+    [CSR_MCONFIGPTR] = {"mconfigptr", any,  read_zero    },
 
     /* Machine Trap Setup */
     [CSR_MSTATUS]     = { "mstatus",    any,   read_mstatus,     write_mstatus     },
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Rahul Pathak

mconfigptr is an mandatory CSR as per the priv spec.

%s/an/a

as per the priv spec v1.12

Quoted 28 lines

This csr holds the physical address of the configuration data structure if this data structure is implemented Its an readonly csr set to zero making configuration data structure not supported.

---
 target/riscv/cpu_bits.h | 1 +
 target/riscv/csr.c      | 1 +
 2 files changed, 2 insertions(+)
target/riscv/cpu_bits.h +1 -0
index 999187a9ee..5dc4729ed5 100644
@@ -140,6 +140,7 @@
 #define CSR_MARCHID         0xf12
 #define CSR_MIMPID          0xf13
 #define CSR_MHARTID         0xf14
+#define CSR_MCONFIGPTR      0xf15
 
 /* Machine Trap Setup */
 #define CSR_MSTATUS         0x300
target/riscv/csr.c +0 -0
index 23fbbd3216..2182943f54 100644

target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { · line 1552

Quoted 4 lines
target/riscv/csr.c +1 -0
@@ -1549,6 +1549,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
     [CSR_MARCHID]   = { "marchid",   any,   read_zero    },
     [CSR_MIMPID]    = { "mimpid",    any,   read_zero    },
     [CSR_MHARTID]   = { "mhartid",   any,   read_mhartid },
+    [CSR_MCONFIGPTR] = {"mconfigptr", any,  read_zero    },

Not any, as we need to check the priv version >= 1.12

target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {

Quoted 4 lines
target/riscv/csr.c +0 -1
     /* Machine Trap Setup */
     [CSR_MSTATUS]     = { "mstatus",    any,   read_mstatus,     write_mstatus     },
--

Regards,
Bin

#2 lore raw

Hi Bin

Quoted 7 lines · Bin Meng
Quoted 2 lines · Rahul Pathak

mconfigptr is an mandatory CSR as per the priv spec.

%s/an/a

Done

Quoted 24 lines

as per the priv spec v1.12

Quoted 21 lines

This csr holds the physical address of the configuration data structure if this data structure is implemented Its an readonly csr set to zero making configuration data structure not supported.

---
 target/riscv/cpu_bits.h | 1 +
 target/riscv/csr.c      | 1 +
 2 files changed, 2 insertions(+)
target/riscv/cpu_bits.h +1 -0
index 999187a9ee..5dc4729ed5 100644
@@ -140,6 +140,7 @@
 #define CSR_MARCHID         0xf12
 #define CSR_MIMPID          0xf13
 #define CSR_MHARTID         0xf14
+#define CSR_MCONFIGPTR      0xf15
 
Quoted 13 lines

target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { · line 1552

Quoted 11 lines
target/riscv/cpu_bits.h +0 -0
 /* Machine Trap Setup */
 #define CSR_MSTATUS         0x300
target/riscv/csr.c +1 -0
index 23fbbd3216..2182943f54 100644
@@ -1549,6 +1549,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
     [CSR_MARCHID]   = { "marchid",   any,   read_zero    },
     [CSR_MIMPID]    = { "mimpid",    any,   read_zero    },
     [CSR_MHARTID]   = { "mhartid",   any,   read_mhartid },
+    [CSR_MCONFIGPTR] = {"mconfigptr", any,  read_zero    },

Not any, as we need to check the priv version >= 1.12

To check the priv version, I am thinking of creating a generic predicate function
which checks the env->priv_ver.?
Generic predicate function for the priv version can be reused in other such scenarios also.

Quoted 8 lines

target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {

Quoted 5 lines
target/riscv/csr.c +0 -1
     /* Machine Trap Setup */
     [CSR_MSTATUS]     = { "mstatus",    any,   read_mstatus,     write_mstatus     },
--

Regards,
Bin

#3 lore raw

HI Rahul,

Quoted 54 lines · Rahul Pathak

Hi Bin

Quoted 7 lines · Bin Meng
Quoted 2 lines · Rahul Pathak

mconfigptr is an mandatory CSR as per the priv spec.

%s/an/a

Done

Quoted 24 lines

as per the priv spec v1.12

Quoted 21 lines

This csr holds the physical address of the configuration data structure if this data structure is implemented Its an readonly csr set to zero making configuration data structure not supported.

---
 target/riscv/cpu_bits.h | 1 +
 target/riscv/csr.c      | 1 +
 2 files changed, 2 insertions(+)
target/riscv/cpu_bits.h +1 -0
index 999187a9ee..5dc4729ed5 100644
@@ -140,6 +140,7 @@
 #define CSR_MARCHID         0xf12
 #define CSR_MIMPID          0xf13
 #define CSR_MHARTID         0xf14
+#define CSR_MCONFIGPTR      0xf15
 
Quoted 13 lines

target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { · line 1552

Quoted 11 lines
target/riscv/cpu_bits.h +0 -0
 /* Machine Trap Setup */
 #define CSR_MSTATUS         0x300
target/riscv/csr.c +1 -0
index 23fbbd3216..2182943f54 100644
@@ -1549,6 +1549,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = {
     [CSR_MARCHID]   = { "marchid",   any,   read_zero    },
     [CSR_MIMPID]    = { "mimpid",    any,   read_zero    },
     [CSR_MHARTID]   = { "mhartid",   any,   read_mhartid },
+    [CSR_MCONFIGPTR] = {"mconfigptr", any,  read_zero    },

Not any, as we need to check the priv version >= 1.12

Quoted 5 lines

To check the priv version, I am thinking of creating a generic predicate function
which checks the env->priv_ver.?
Generic predicate function for the priv version can be reused in other such scenarios also.

Sounds good to me. Thanks!

Regards,
Bin