Skip to content

Commit

Permalink
config_pkg/csr_regfile: Add PMP entry rst vals & RO option
Browse files Browse the repository at this point in the history
This commit adds three new fields to the cva6_cfg_t configuration
struct, which allow to specify reset values for the PMP configuration
and address CSRs as well as optionally making invidiual PMP entries
read-only.  The purpose is to allow hard-wiring of certain regions'
privileges, which is explicitely allowed by the RISC-V Privileged
Architecture specification Machine-Level ISA, v1.12 (see Sect. 3.7).
  • Loading branch information
michael-platzer committed Jan 16, 2024
1 parent 49cdc90 commit 3b15abe
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 4 deletions.
19 changes: 15 additions & 4 deletions core/csr_regfile.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1554,8 +1554,15 @@ module csr_regfile
// wait for interrupt
wfi_q <= 1'b0;
// pmp
pmpcfg_q <= '0;
pmpaddr_q <= '0;
for (int i = 0; i < 16; i++) begin
if (i < CVA6Cfg.NrPMPEntries) begin
pmpcfg_q[i] <= CVA6Cfg.PMPCfgRstVal[i];
pmpaddr_q[i] <= CVA6Cfg.PMPAddrRstVal[i];
end else begin
pmpcfg_q[i] <= '0;
pmpaddr_q[i] <= '0;
end
end
end else begin
priv_lvl_q <= priv_lvl_d;
// floating-point registers
Expand Down Expand Up @@ -1607,12 +1614,16 @@ module csr_regfile
for (int i = 0; i < 16; i++) begin
if (i < CVA6Cfg.NrPMPEntries) begin
// We only support >=8-byte granularity, NA4 is disabled
if(pmpcfg_d[i].addr_mode != riscv::NA4 && !(pmpcfg_d[i].access_type.r == '0 && pmpcfg_d[i].access_type.w == '1)) begin
if(!CVA6Cfg.PMPEntryReadOnly[i] && pmpcfg_d[i].addr_mode != riscv::NA4 && !(pmpcfg_d[i].access_type.r == '0 && pmpcfg_d[i].access_type.w == '1)) begin
pmpcfg_q[i] <= pmpcfg_d[i];
end else begin
pmpcfg_q[i] <= pmpcfg_q[i];
end
pmpaddr_q[i] <= pmpaddr_d[i];
if (!CVA6Cfg.PMPEntryReadOnly[i]) begin
pmpaddr_q[i] <= pmpaddr_d[i];
end else begin
pmpaddr_q[i] <= pmpaddr_q[i];
end
end else begin
pmpcfg_q[i] <= '0;
pmpaddr_q[i] <= '0;
Expand Down
4 changes: 4 additions & 0 deletions core/include/config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ package config_pkg;
logic [63:0] DmBaseAddress;
/// Number of PMP entries.
int unsigned NrPMPEntries;
/// Physical Memory Protection (PMP) CSR reset values and read-only bits
riscv::pmpcfg_t [15:0] PMPCfgRstVal;
logic [15:0][riscv::PLEN-3:0] PMPAddrRstVal;
bit [15:0] PMPEntryReadOnly;
/// Set to the bus type in use.
noc_type_e NOCType;
/// Physical Memory Attributes (PMAs)
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv32a60x_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv32a6_embedded_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv32a6_ima_sv32_fpga_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv32a6_imac_sv0_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv32a6_imac_sv32_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv32a6_imafc_sv32_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv64a6_imadfcv_sv39_polara_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_L15_BIG_ENDIAN,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv64a6_imafdc_sv39_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv64a6_imafdc_sv39_hpdcache_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv64a6_imafdc_sv39_openpiton_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_L15_BIG_ENDIAN,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv64a6_imafdc_sv39_wb_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down
3 changes: 3 additions & 0 deletions core/include/cv64a6_imafdcv_sv39_config_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ package cva6_config_pkg;
BHTEntries: unsigned'(CVA6ConfigBHTEntries),
DmBaseAddress: 64'h0,
NrPMPEntries: unsigned'(CVA6ConfigNrPMPEntries),
PMPCfgRstVal: {16{riscv::pmpcfg_t'('0)}},
PMPAddrRstVal: {16{(riscv::PLEN-2)'('0)}},
PMPEntryReadOnly: 16'd0,
NOCType: config_pkg::NOC_TYPE_AXI4_ATOP,
// idempotent region
NrNonIdempotentRules:
Expand Down

0 comments on commit 3b15abe

Please sign in to comment.