Skip to content

Commit

Permalink
[hw] Re-introduce mmu stub
Browse files Browse the repository at this point in the history
  • Loading branch information
mp-17 committed Dec 3, 2024
1 parent 5e9e19d commit ce0b0e3
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 10 deletions.
108 changes: 98 additions & 10 deletions hw/cheshire_soc.sv
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ module cheshire_soc import cheshire_pkg::*; #(
// TODO: Implement X interface support

// Accelerator ports
acc_pkg::cva6_to_acc_t acc_req;
acc_pkg::acc_to_cva6_t acc_resp;
acc_pkg::cva6_to_acc_t acc_req_cva6, acc_req_ara;
acc_pkg::acc_to_cva6_t acc_resp_cva6, acc_resp_ara;

// CVA6-Ara memory consistency
logic acc_cons_en;
Expand All @@ -567,13 +567,13 @@ module cheshire_soc import cheshire_pkg::*; #(
logic inval_ready;

// Pack invalidation interface into acc interface
acc_pkg::acc_to_cva6_t acc_resp_pack;
acc_pkg::acc_to_cva6_t acc_resp_pack_cva6;
always_comb begin : pack_inval
acc_resp_pack = acc_resp;
acc_resp_pack.acc_resp.inval_valid = inval_valid;
acc_resp_pack.acc_resp.inval_addr = inval_addr;
inval_ready = acc_req.acc_req.inval_ready;
acc_cons_en = acc_req.acc_req.acc_cons_en;
acc_resp_pack_cva6 = acc_resp_cva6;
acc_resp_pack_cva6.acc_resp.inval_valid = inval_valid;
acc_resp_pack_cva6.acc_resp.inval_addr = inval_addr;
inval_ready = acc_req_cva6.acc_req.inval_ready;
acc_cons_en = acc_req_cva6.acc_req.acc_cons_en;
end

`CHESHIRE_TYPEDEF_AXI_CT(axi_cva6, addr_t, cva6_id_t, axi_data_t, axi_strb_t, axi_user_t)
Expand Down Expand Up @@ -786,6 +786,21 @@ module cheshire_soc import cheshire_pkg::*; #(
axi_mst_req_t axi_ara_narrow_req;
axi_mst_rsp_t axi_ara_narrow_resp;

// SoC-level regfile helpers for STUB, MMU_REQ_GEN, and Ara
(* dont_touch = "yes" *) (* mark_debug = "true" *) logic soc_csr_virt_mem_en;
(* dont_touch = "yes" *) (* mark_debug = "true" *) logic soc_csr_ex_en;
logic [31:0] soc_csr_no_ex_lat;
logic [31:0] soc_csr_req_rsp_lat;
(* dont_touch = "yes" *) (* mark_debug = "true" *) logic soc_csr_mmu_req_en;
(* dont_touch = "yes" *) (* mark_debug = "true" *) logic [5:0] soc_csr_mmu_req_lat;

assign soc_csr_virt_mem_en = reg_reg2hw.ara_virt_mem_en[0];
assign soc_csr_ex_en = reg_reg2hw.stub_ex_en[0];
assign soc_csr_no_ex_lat = reg_reg2hw.stub_no_ex_lat;
assign soc_csr_req_rsp_lat = reg_reg2hw.stub_req_rsp_lat;
assign soc_csr_mmu_req_en = reg_reg2hw.mmu_req_gen_en[0];
assign soc_csr_mmu_req_lat = reg_reg2hw.mmu_req_gen_lat[5:0];

ara #(
.NrLanes ( Cfg.AraNrLanes ),
.VLEN ( Cfg.AraVLEN ),
Expand All @@ -804,12 +819,85 @@ module cheshire_soc import cheshire_pkg::*; #(
.scan_enable_i ( 1'b0 ),
.scan_data_i ( 1'b0 ),
.scan_data_o ( /* Unused */ ),
.acc_req_i ( acc_req ),
.acc_resp_o ( acc_resp ),
.acc_req_i ( acc_req_ara ),
.acc_resp_o ( acc_resp_ara ),
.axi_req_o ( axi_ara_wide_req ),
.axi_resp_i ( axi_ara_wide_resp )
);

// MMU ports
ariane_pkg::exception_t mmu_misaligned_ex_acc_cva6, dbg_mmu_stub_misaligned_ex, dbg_mmu_req_gen_misaligned_ex;

Check warning on line 829 in hw/cheshire_soc.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/cheshire_soc.sv#L829

Line length exceeds max: 100; is: 114 [Style: line-length] [line-length]
Raw output
message:"Line length exceeds max: 100; is: 114 [Style: line-length] [line-length]" location:{path:"hw/cheshire_soc.sv" range:{start:{line:829 column:101}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
logic mmu_req_acc_cva6, dbg_mmu_stub_req, dbg_mmu_req_gen_req;
logic [riscv::VLEN-1:0] mmu_vaddr_acc_cva6, dbg_mmu_stub_vaddr, dbg_mmu_req_gen_vaddr;
logic mmu_is_store_acc_cva6, dbg_mmu_stub_is_store, dbg_mmu_req_gen_is_store;
logic mmu_dtlb_hit_cva6_acc, dbg_mmu_stub_dtlb_hit, dbg_mmu_req_gen_dtlb_hit;
logic [riscv::PPNW-1:0] mmu_dtlb_ppn_cva6_acc, dbg_mmu_stub_dtlb_ppn, dbg_mmu_req_gen_dtlb_ppn;
logic mmu_valid_cva6_acc, dbg_mmu_stub_valid, dbg_mmu_req_gen_valid;
logic [riscv::PLEN-1:0] mmu_paddr_cva6_acc, dbg_mmu_stub_paddr, dbg_mmu_req_gen_paddr;
ariane_pkg::exception_t mmu_exception_cva6_acc, dbg_mmu_stub_exception, dbg_mmu_req_gen_exception;

Check warning on line 837 in hw/cheshire_soc.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/cheshire_soc.sv#L837

Line length exceeds max: 100; is: 102 [Style: line-length] [line-length]
Raw output
message:"Line length exceeds max: 100; is: 102 [Style: line-length] [line-length]" location:{path:"hw/cheshire_soc.sv" range:{start:{line:837 column:101}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}

// DEBUG: MMU stub
`define MMU_DEBUG
`ifdef MMU_DEBUG
$info("MMU STUB enabled.");
$info("MMU REQ GEN ENABLED.");

assign acc_req_ara.acc_req = acc_req_cva6.acc_req;
assign acc_resp_cva6.acc_resp = acc_resp_ara.acc_resp;

assign acc_req_ara.acc_mmu_en = soc_csr_virt_mem_en;
assign acc_req_ara.acc_mmu_resp.acc_mmu_dtlb_hit = dbg_mmu_stub_dtlb_hit;
assign acc_req_ara.acc_mmu_resp.acc_mmu_dtlb_ppn = dbg_mmu_stub_dtlb_ppn;
assign acc_req_ara.acc_mmu_resp.acc_mmu_valid = dbg_mmu_stub_valid;
assign acc_req_ara.acc_mmu_resp.acc_mmu_paddr = dbg_mmu_stub_paddr;
assign acc_req_ara.acc_mmu_resp.acc_mmu_exception = dbg_mmu_stub_exception;

assign dbg_mmu_stub_misaligned_ex = acc_resp_ara.acc_mmu_req.acc_mmu_misaligned_ex;
assign dbg_mmu_stub_req = acc_resp_ara.acc_mmu_req.acc_mmu_req;
assign dbg_mmu_stub_vaddr = acc_resp_ara.acc_mmu_req.acc_mmu_vaddr;
assign dbg_mmu_stub_is_store = acc_resp_ara.acc_mmu_req.acc_mmu_is_store;

assign acc_resp_cva6.acc_mmu_req.acc_mmu_misaligned_ex = dbg_mmu_req_gen_misaligned_ex;
assign acc_resp_cva6.acc_mmu_req.acc_mmu_req = dbg_mmu_stub_req;
assign acc_resp_cva6.acc_mmu_req.acc_mmu_vaddr = dbg_mmu_stub_vaddr;
assign acc_resp_cva6.acc_mmu_req.acc_mmu_is_store = dbg_mmu_stub_is_store;

assign dbg_mmu_stub_valid = acc_req_cva.acc_mmu_resp.acc_mmu_valid;

mmu_stub i_mmu_stub (
.ex_en_i ( soc_csr_ex_en ),
.no_ex_lat_i ( soc_csr_no_ex_lat ),
.req_rsp_lat_i ( soc_csr_req_rsp_lat ),
.clk_i ( clk_i ),
.rst_ni ( rst_ni ),
.en_ld_st_translation_i ( soc_csr_virt_mem_en ),
.misaligned_ex_i ( dbg_mmu_stub_misaligned_ex ),
.req_i ( dbg_mmu_stub_req ),
.vaddr_i ( dbg_mmu_stub_vaddr ),
.is_store_i ( dbg_mmu_stub_is_store ),
.dtlb_hit_o ( dbg_mmu_stub_dtlb_hit ),
.dtlb_ppn_o ( dbg_mmu_stub_dtlb_ppn ),
.valid_o ( dbg_mmu_stub_valid ),
.paddr_o ( dbg_mmu_stub_paddr ),
.exception_o ( dbg_mmu_stub_exception )
);

mmu_req_gen i_mmu_req_gen (
.clk_i (clk_i ),
.rst_ni (rst_ni ),
.mmu_req_en_i (soc_csr_mmu_req_en ),
.mmu_req_lat_i (soc_csr_mmu_req_lat ),
.acc_mmu_misaligned_ex_o(dbg_mmu_req_gen_misaligned_ex),
.acc_mmu_req_o (dbg_mmu_req_gen_req ),
.acc_mmu_vaddr_o (dbg_mmu_req_gen_vaddr ),
.acc_mmu_is_store_o (dbg_mmu_req_gen_is_store ),
.acc_mmu_valid_i (dbg_mmu_req_gen_valid )
);
`else
assign acc_req_ara = acc_req_cva6;
assign acc_resp_cva6 = acc_req_ara;
`endif

// Issue invalidations to CVA6 L1D$
axi_inval_filter #(
.MaxTxns ( 4 ),
Expand Down
77 changes: 77 additions & 0 deletions hw/mmu_req_gen.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2022 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
//
// Author: Matteo Perotti <[email protected]>
//
// Description: Simple memory translation request generator for CVA6's shared MMU
// Generate a request after mmu_req_lat_i cycles from last answer
// Enable with mmu_req_en_i

module mmu_req_gen (
input logic clk_i,
input logic rst_ni,
input logic mmu_req_en_i, // Enable the mmu req generator
input logic [5:0] mmu_req_lat_i, // Latency for a new req after last answer (max: 62)

Check warning on line 15 in hw/mmu_req_gen.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_req_gen.sv#L15

Line length exceeds max: 100; is: 108 [Style: line-length] [line-length]
Raw output
message:"Line length exceeds max: 100; is: 108 [Style: line-length] [line-length]" location:{path:"hw/mmu_req_gen.sv" range:{start:{line:15 column:101}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
// MMU interface with accelerator
output ariane_pkg::exception_t acc_mmu_misaligned_ex_o,
output logic acc_mmu_req_o, // request address translation
output logic [riscv::VLEN-1:0] acc_mmu_vaddr_o, // virtual address in
output logic acc_mmu_is_store_o, // the translation is requested by a store

Check warning on line 20 in hw/mmu_req_gen.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_req_gen.sv#L20

Line length exceeds max: 100; is: 105 [Style: line-length] [line-length]
Raw output
message:"Line length exceeds max: 100; is: 105 [Style: line-length] [line-length]" location:{path:"hw/mmu_req_gen.sv" range:{start:{line:20 column:101}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic acc_mmu_valid_i // translation is valid
);

// Registers
`include "common_cells/registers.svh"

logic wait_ans_d, wait_ans_q;
logic acc_mmu_req_d, acc_mmu_req_q;
logic mmu_req_en_q;
logic [5:0] mmu_req_lat_d, mmu_req_lat_q;
logic [5:0] ans2req_cnt_d, ans2req_cnt_q;
logic [5:0] cnt_threshold;

`FF(wait_ans_q, wait_ans_d, '0, clk_i, rst_ni)
`FF(mmu_req_en_q, mmu_req_en_i, '0, clk_i, rst_ni)
`FF(mmu_req_lat_q, mmu_req_lat_d, '0, clk_i, rst_ni)
`FF(ans2req_cnt_q, ans2req_cnt_d, '0, clk_i, rst_ni)
`FF(acc_mmu_req_q, acc_mmu_req_d, '0, clk_i, rst_ni)

assign cnt_threshold = mmu_req_lat_q;
assign acc_mmu_req_o = acc_mmu_req_d | acc_mmu_req_q;

always_comb begin
acc_mmu_misaligned_ex_o = '0;
acc_mmu_vaddr_o = '0;
acc_mmu_is_store_o = '0;

wait_ans_d = wait_ans_q;
mmu_req_lat_d = mmu_req_lat_q;
ans2req_cnt_d = ans2req_cnt_q;
acc_mmu_req_d = acc_mmu_req_q;

// Act only if enabled
if (mmu_req_en_q) begin
// If we are not waiting for an answer or if it arrived, count up
if (!wait_ans_q) begin
ans2req_cnt_d += 1;

// If we have reached the threshold already, make the request and wait for ans
if (ans2req_cnt_q == cnt_threshold) begin
acc_mmu_req_d = 1'b1;
wait_ans_d = 1'b1;
end
end

// Ans arrived
if (acc_mmu_valid_i) begin
// Reset the req and the counter
ans2req_cnt_d = '0;
acc_mmu_req_d = 1'b0;
// We are not waiting anymore for ans
wait_ans_d = 1'b0;
end
end
end

endmodule
114 changes: 114 additions & 0 deletions hw/mmu_stub.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright 2022 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
//
// Author: Vincenzo Maisto <[email protected]>
//
// Description: Simple stub emulating MMU behaviour

module mmu_stub (
// Configuration from SoC regfile
input logic ex_en_i, // Exception enable/disable. If disable, the internal status for the exception is reset

Check warning on line 11 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L11

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:11 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}

Check warning on line 11 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L11

Line length exceeds max: 100; is: 119 [Style: line-length] [line-length]
Raw output
message:"Line length exceeds max: 100; is: 119 [Style: line-length] [line-length]" location:{path:"hw/mmu_stub.sv" range:{start:{line:11 column:101}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic [31:0] no_ex_lat_i, // Number of requests to accept before throwing an exception

Check warning on line 12 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L12

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:12 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}

Check warning on line 12 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L12

Line length exceeds max: 100; is: 101 [Style: line-length] [line-length]
Raw output
message:"Line length exceeds max: 100; is: 101 [Style: line-length] [line-length]" location:{path:"hw/mmu_stub.sv" range:{start:{line:12 column:101}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic [31:0] req_rsp_lat_i, // Latency between request and response

Check warning on line 13 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L13

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:13 column:23}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
// Interface
input logic clk_i,

Check warning on line 15 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L15

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:15 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic rst_ni,

Check warning on line 16 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L16

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:16 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic en_ld_st_translation_i, // Enable behaviour

Check warning on line 17 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L17

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:17 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input ariane_pkg::exception_t misaligned_ex_i, // Ignored

Check warning on line 18 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L18

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:18 column:10}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic req_i,

Check warning on line 19 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L19

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:19 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
input logic [riscv::VLEN-1:0] vaddr_i,
input logic is_store_i, // Mux exception_o.tval

Check warning on line 21 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L21

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:21 column:16}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
// Cycle 0
output logic dtlb_hit_o,

Check warning on line 23 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L23

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:23 column:17}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
output logic [riscv::PPNW-1:0] dtlb_ppn_o, // Constant '1
// Cycle 1
output logic valid_o,

Check warning on line 26 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L26

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:26 column:17}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
output logic [riscv::PLEN-1:0] paddr_o, // Same as vaddr_i
output ariane_pkg::exception_t exception_o // Valid on trigger_exception_i

Check warning on line 28 in hw/mmu_stub.sv

View workflow job for this annotation

GitHub Actions / verible-verilog-lint

[verible-verilog-lint] hw/mmu_stub.sv#L28

Use spaces, not tabs. [Style: tabs] [no-tabs]
Raw output
message:"Use spaces, not tabs. [Style: tabs] [no-tabs]" location:{path:"hw/mmu_stub.sv" range:{start:{line:28 column:11}}} severity:WARNING source:{name:"verible-verilog-lint" url:"https://github.com/chipsalliance/verible"}
);

// Registers
`include "common_cells/registers.svh"
logic [riscv::PLEN-1:0] mock_paddr_d, mock_paddr_q;
logic [riscv::VLEN-1:0] vaddr_d, vaddr_q;
logic is_store_q, is_store_d;
logic lat_cnt_en, lat_cnt_clr;
logic [31:0] lat_cnt_q, lat_cnt_d;
logic [31:0] req_rsp_lat_q, req_rsp_lat_d;
logic [31:0] no_ex_lat_cnt_q, no_ex_lat_cnt_d;
`FF(mock_paddr_q , mock_paddr_d , '0, clk_i, rst_ni)
`FF(vaddr_q , vaddr_d , '0, clk_i, rst_ni)
`FF(is_store_q , is_store_d , '0, clk_i, rst_ni)
`FF(lat_cnt_q , lat_cnt_d , '0, clk_i, rst_ni)
`FF(req_rsp_lat_q , req_rsp_lat_d , '0, clk_i, rst_ni)
`FF(no_ex_lat_cnt_q, no_ex_lat_cnt_d, '0, clk_i, rst_ni)

// Combinatorial logic
always_comb begin : mmu_stub
// Outputs (defaults)
dtlb_hit_o = '0;
dtlb_ppn_o = '0; // Never used
valid_o = '0;
paddr_o = '0;
exception_o = '0;

// Latency counter
lat_cnt_en = 1'b0;
lat_cnt_clr = 1'b0;

// Registers feedback
mock_paddr_d = mock_paddr_q;
vaddr_d = vaddr_q;
is_store_d = is_store_q;
lat_cnt_d = lat_cnt_q;
no_ex_lat_cnt_d = no_ex_lat_cnt_q;
req_rsp_lat_d = req_rsp_lat_i;

// If translation is enabled
if ( en_ld_st_translation_i ) begin : enable_translation
// Cycle 0
if ( req_i ) begin : req_valid
// Sample inputs, for next cycle
mock_paddr_d = vaddr_i; // Mock, just pass back the same vaddr
vaddr_d = vaddr_i;
is_store_d = is_store_i;

// DTBL hit, assume 100%
// NOTE: Ara does not use these
dtlb_hit_o = 1'b1;
dtlb_ppn_o = '1;

// Count up
lat_cnt_d = lat_cnt_q + 1;
end : req_valid

// Answer
if (lat_cnt_q == req_rsp_lat_q) begin : valid
// Output to Ara
// Assume Ara consumes this request
valid_o = 1'b1;
paddr_o = mock_paddr_q;

// Reset the latency counter
lat_cnt_d = '0;

// Another answer without exception!
no_ex_lat_cnt_d = no_ex_lat_cnt_q + 1;
end : valid

// Mock exception logic
if (ex_en_i && no_ex_lat_cnt_q == no_ex_lat_i && valid_o) begin : exception
exception_o.valid = 1'b1;
exception_o.cause = ( is_store_q ) ? riscv::STORE_PAGE_FAULT : riscv::LOAD_PAGE_FAULT;
exception_o.tval = {'0, vaddr_q};
// Reset the ex_lat counter
no_ex_lat_cnt_d = '0;
end : exception
// Reset the ex_lat counter if the exception engine is turned off
if (!ex_en_i) begin
no_ex_lat_cnt_d = '0;
end
end : enable_translation
end : mmu_stub
endmodule : mmu_stub

0 comments on commit ce0b0e3

Please sign in to comment.