Skip to content

Commit 8b42024

Browse files
committed
Use vendored-in primitives from OpenTitan
Instead of using copies of primitives from OpenTitan, vendor the files in directly from OpenTitan, and use them. Benefits: - Less potential for diverging code between OpenTitan and Ibex, causing problems when importing Ibex into OT. - Use of the abstract primitives instead of the generic ones. The abstract primitives are replaced during synthesis time with target-dependent implementations. For simulation, nothing changes. For synthesis for a given target technology (e.g. a specific ASIC or FPGA technology), the primitives system can be instructed to choose optimized versions (if available). This is most relevant for the icache, which hard-coded the generic SRAM primitive before. This primitive is always implemented as registers. By using the abstract primitive (prim_ram_1p) instead, the RAMs can be replaced with memory-compiler-generated ones if necessary. There are no real draw-backs, but a couple points to be aware of: - Our ram_1p and ram_2p implementations are kept as wrapper around the primitives, since their interface deviates slightly from the one in prim_ram*. This also includes a rather unfortunate naming confusion around rvalid, which means "read data valid" in the OpenTitan advanced RAM primitives (prim_ram_1p_adv for example), but means "ack" in PULP-derived IP and in our bus implementation. - The core_ibex UVM DV doesn't use FuseSoC to generate its file list, but uses a hard-coded list in `ibex_files.f` instead. Since the dynamic primitives system requires the use of FuseSoC we need to provide a stop-gap until this file is removed. Issue lowRISC#893 tracks progress on that. - Dynamic primitives depend no a not-yet-merged feature of FuseSoC (olofk/fusesoc#391). We depend on the same functionality in OpenTitan and have instructed users to use a patched branch of FuseSoC for a long time through `python-requirements.txt`, so no action is needed for users which are either successfully interacting with the OpenTitan source code, or have followed our instructions. All other users will see a reasonably descriptive error message during a FuseSoC run. - This commit is massive, but there are no good ways to split it into bisectable, yet small, chunks. I'm sorry. Reviewers can safely ignore all code in `vendor/lowrisc_ip`, it's an import from OpenTitan. - The check_tool_requirements tooling isn't easily vendor-able from OpenTitan at the moment. I've filed lowRISC/opentitan#2309 to get that sorted. - The LFSR primitive doesn't have a own core file, forcing us to include the catch-all `lowrisc:prim:all` core. I've filed lowRISC/opentitan#2310 to get that sorted.
1 parent 3f4e706 commit 8b42024

File tree

190 files changed

+11808
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+11808
-252
lines changed

check_tool_requirements.core

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CAPI=2:
22
# Copyright lowRISC contributors.
33
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
44
# SPDX-License-Identifier: Apache-2.0
5-
name: "lowrisc:ibex:check_tool_requirements:0.1"
5+
name: "lowrisc:tool:check_tool_requirements:0.1"
66
description: "Check tool requirements"
77

88
filesets:

dv/riscv_compliance/ibex_riscv_compliance.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ int main(int argc, char **argv) {
1313
simctrl.SetTop(&top, &top.IO_CLK, &top.IO_RST_N,
1414
VerilatorSimCtrlFlags::ResetPolarityNegative);
1515

16-
memutil.RegisterMemoryArea("ram", "TOP.ibex_riscv_compliance.u_ram.u_ram");
16+
memutil.RegisterMemoryArea(
17+
"ram",
18+
"TOP.ibex_riscv_compliance.u_ram.u_ram.gen_generic.u_impl_generic");
1719
simctrl.RegisterExtension(&memutil);
1820

1921
return simctrl.Exec(argc, argv);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright lowRISC contributors.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Abstract primitives wrapper.
6+
//
7+
// This file is a stop-gap until the DV file list is generated by FuseSoC.
8+
// Its contents are taken from the file which would be generated by FuseSoC.
9+
// https://github.com/lowRISC/ibex/issues/893
10+
11+
`ifndef PRIM_DEFAULT_IMPL
12+
`define PRIM_DEFAULT_IMPL prim_pkg::ImplGeneric
13+
`endif
14+
15+
module prim_clock_gating (
16+
input clk_i,
17+
input en_i,
18+
input test_en_i,
19+
output logic clk_o
20+
);
21+
parameter prim_pkg::impl_e Impl = `PRIM_DEFAULT_IMPL;
22+
23+
if (Impl == prim_pkg::ImplGeneric) begin : gen_generic
24+
prim_generic_clock_gating u_impl_generic (
25+
.*
26+
);
27+
end else if (Impl == prim_pkg::ImplXilinx) begin : gen_xilinx
28+
prim_xilinx_clock_gating u_impl_xilinx (
29+
.*
30+
);
31+
end else begin : gen_failure
32+
// TODO: Find code that works across tools and causes a compile failure
33+
end
34+
35+
endmodule
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright lowRISC contributors.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Constants for use in primitives
6+
//
7+
// This file is a stop-gap until the DV file list is generated by FuseSoC.
8+
// Its contents are taken from the file which would be generated by FuseSoC.
9+
// https://github.com/lowRISC/ibex/issues/893
10+
11+
package prim_pkg;
12+
13+
// Implementation target specialization
14+
typedef enum integer {
15+
ImplGeneric,
16+
ImplXilinx
17+
} impl_e;
18+
endpackage : prim_pkg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright lowRISC contributors.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Abstract primitives wrapper.
6+
//
7+
// This file is a stop-gap until the DV file list is generated by FuseSoC.
8+
// Its contents are taken from the file which would be generated by FuseSoC.
9+
// https://github.com/lowRISC/ibex/issues/893
10+
11+
`ifndef PRIM_DEFAULT_IMPL
12+
`define PRIM_DEFAULT_IMPL prim_pkg::ImplGeneric
13+
`endif
14+
15+
module prim_ram_1p #(
16+
parameter int Width = 32, // bit
17+
parameter int Depth = 128,
18+
parameter int DataBitsPerMask = 1, // Number of data bits per bit of write mask
19+
localparam int Aw = $clog2(Depth) // derived parameter
20+
) (
21+
input logic clk_i,
22+
23+
input logic req_i,
24+
input logic write_i,
25+
input logic [Aw-1:0] addr_i,
26+
input logic [Width-1:0] wdata_i,
27+
input logic [Width-1:0] wmask_i,
28+
output logic [Width-1:0] rdata_o // Read data. Data is returned one cycle after req_i is high.
29+
);
30+
parameter prim_pkg::impl_e Impl = `PRIM_DEFAULT_IMPL;
31+
32+
if (Impl == prim_pkg::ImplGeneric) begin : gen_generic
33+
prim_generic_ram_1p u_impl_generic (
34+
.*
35+
);
36+
end else begin : gen_failure
37+
// TODO: Find code that works across tools and causes a compile failure
38+
end
39+
40+
endmodule

dv/uvm/core_ibex/ibex_dv.f

+17-9
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,27 @@
77
+define+BOOT_ADDR=2147483648 // 32'h8000_0000
88
+define+TRACE_EXECUTION
99
+define+RVFI
10-
+incdir+${PRJ_DIR}/ibex/shared/rtl
1110

12-
${PRJ_DIR}/ibex/shared/rtl/prim_clock_gating.sv
11+
// Shared lowRISC code
12+
+incdir+${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl
13+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl/prim_assert.sv
14+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl/prim_lfsr.sv
15+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl/prim_secded_28_22_enc.sv
16+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl/prim_secded_28_22_dec.sv
17+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl/prim_secded_72_64_enc.sv
18+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim/rtl/prim_secded_72_64_dec.sv
19+
20+
// Until this list is generated by FuseSoC, we have to use manually generated
21+
// wrappers around the prim_* modules to instantiate the prim_generic_* ones,
22+
// see https://github.com/lowRISC/ibex/issues/893.
23+
${PRJ_DIR}/ibex/dv/uvm/core_ibex/common/prim/prim_pkg.sv
24+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim_generic/rtl/prim_generic_ram_1p.sv
25+
${PRJ_DIR}/ibex/dv/uvm/core_ibex/common/prim/prim_ram_1p.sv
26+
${PRJ_DIR}/ibex/vendor/lowrisc_ip/prim_generic/rtl/prim_generic_clock_gating.sv
27+
${PRJ_DIR}/ibex/dv/uvm/core_ibex/common/prim/prim_clock_gating.sv
1328

1429
// ibex CORE RTL files
1530
+incdir+${PRJ_DIR}/ibex/rtl
16-
${PRJ_DIR}/ibex/shared/rtl/prim_assert.sv
17-
${PRJ_DIR}/ibex/shared/rtl/prim_generic_ram_1p.sv
18-
${PRJ_DIR}/ibex/shared/rtl/prim_lfsr.sv
19-
${PRJ_DIR}/ibex/shared/rtl/prim_secded_28_22_enc.sv
20-
${PRJ_DIR}/ibex/shared/rtl/prim_secded_28_22_dec.sv
21-
${PRJ_DIR}/ibex/shared/rtl/prim_secded_72_64_enc.sv
22-
${PRJ_DIR}/ibex/shared/rtl/prim_secded_72_64_dec.sv
2331
${PRJ_DIR}/ibex/rtl/ibex_pkg.sv
2432
${PRJ_DIR}/ibex/rtl/ibex_tracer_pkg.sv
2533
${PRJ_DIR}/ibex/rtl/ibex_tracer.sv

examples/simple_system/ibex_simple_system.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ int main(int argc, char **argv) {
1717
simctrl.SetTop(&top, &top.IO_CLK, &top.IO_RST_N,
1818
VerilatorSimCtrlFlags::ResetPolarityNegative);
1919

20-
memutil.RegisterMemoryArea("ram", "TOP.ibex_simple_system.u_ram");
20+
memutil.RegisterMemoryArea(
21+
"ram", "TOP.ibex_simple_system.u_ram.u_ram.gen_generic.u_impl_generic");
2122
simctrl.RegisterExtension(&memutil);
2223

2324
std::cout << "Simulation of Ibex" << std::endl

ibex_core.core

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ filesets:
99
files_rtl:
1010
depend:
1111
- lowrisc:prim:assert
12-
- lowrisc:prim:lfsr
12+
# TODO: Only lfsr is needed. Replace with a more specific dependency
13+
# once available.
14+
- lowrisc:prim:all
1315
- lowrisc:ibex:ibex_pkg
1416
- lowrisc:ibex:ibex_icache
1517
files:
@@ -48,7 +50,7 @@ filesets:
4850

4951
files_check_tool_requirements:
5052
depend:
51-
- lowrisc:ibex:check_tool_requirements
53+
- lowrisc:tool:check_tool_requirements
5254

5355
parameters:
5456
RVFI:

lint/verilator_waiver.vlt

+4
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,7 @@ lint_off -rule UNUSED -file "*/rtl/ibex_decoder.sv" -match "*instr_alu*"
152152
// ibex_core.cs_registers_i.mie_q
153153
// Issue lowrisc/ibex#212
154154
lint_off -rule UNOPTFLAT -file "*/rtl/ibex_cs_registers.sv" -match "*ibex_core.cs_registers_i.mie_q*"
155+
156+
// Temporary waivers until OpenTitan primitives are lint-clean
157+
// https://github.com/lowRISC/opentitan/issues/2313
158+
lint_off -file "*/lowrisc_prim_*/rtl/*.sv"

python-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ git+https://github.com/lowRISC/edalize.git@ot
99
git+https://github.com/lowRISC/fusesoc.git@ot
1010

1111
pyyaml
12+
mako

rtl/ibex_icache.sv

+2-6
Original file line numberDiff line numberDiff line change
@@ -300,33 +300,29 @@ module ibex_icache #(
300300

301301
for (genvar way = 0; way < NumWays; way++) begin : gen_rams
302302
// Tag RAM instantiation
303-
prim_generic_ram_1p #(
303+
prim_ram_1p #(
304304
.Width (TAG_SIZE_ECC),
305305
.Depth (NUM_LINES)
306306
) tag_bank (
307307
.clk_i (clk_i),
308-
.rst_ni (rst_ni),
309308
.req_i (tag_req_ic0 & tag_banks_ic0[way]),
310309
.write_i (tag_write_ic0),
311310
.wmask_i ({TAG_SIZE_ECC{1'b1}}),
312311
.addr_i (tag_index_ic0),
313312
.wdata_i (tag_wdata_ic0),
314-
.rvalid_o (),
315313
.rdata_o (tag_rdata_ic1[way])
316314
);
317315
// Data RAM instantiation
318-
prim_generic_ram_1p #(
316+
prim_ram_1p #(
319317
.Width (LINE_SIZE_ECC),
320318
.Depth (NUM_LINES)
321319
) data_bank (
322320
.clk_i (clk_i),
323-
.rst_ni (rst_ni),
324321
.req_i (data_req_ic0 & data_banks_ic0[way]),
325322
.write_i (data_write_ic0),
326323
.wmask_i ({LINE_SIZE_ECC{1'b1}}),
327324
.addr_i (data_index_ic0),
328325
.wdata_i (data_wdata_ic0),
329-
.rvalid_o (),
330326
.rdata_o (data_rdata_ic1[way])
331327
);
332328
end

shared/fpga_xilinx.core

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ name: "lowrisc:ibex:fpga_xilinx_shared"
66
description: "Collection of useful RTL for Xilinx based examples"
77
filesets:
88
files_sv:
9+
depend:
10+
- lowrisc:prim:clock_gating
911
files:
10-
- rtl/fpga/xilinx/prim_clock_gating.sv
1112
- rtl/fpga/xilinx/clkgen_xil7series.sv
1213
- rtl/ram_1p.sv
1314
file_type: systemVerilogSource

shared/rtl/prim_clock_gating.sv

-24
This file was deleted.

shared/rtl/prim_generic_ram_1p.sv

-109
This file was deleted.

0 commit comments

Comments
 (0)