Skip to content

Commit

Permalink
[prim,earlgrey,fpga] Add specialized ram_1p prim
Browse files Browse the repository at this point in the history
Add a specialized ram_1p prim for the prim_xilinx library. This prim
adds some prim_xilinx-specific parameters to enable selecting particular
layouts for embedded memories. The intention is to have the top-level
override the parameters with hierarchical assignment.

This feature is intended for use with memories that are too wide to fit
in updatemem's capabilities (where splicing is required). The flash info
pages are one such type, since updatemem can only handle up to 64-bit
wide items, and the info page array is 76 bits wide. Synthesis chooses
the most efficient layout of the memories, but the layout is awkward for
handling splices.

Force earlgrey's flash info data and metadata into separate arrays for
the FPGA.

Signed-off-by: Alexander Williams <[email protected]>
  • Loading branch information
a-will committed Dec 7, 2024
1 parent d869445 commit b7e19f4
Show file tree
Hide file tree
Showing 14 changed files with 367 additions and 64 deletions.
19 changes: 19 additions & 0 deletions hw/ip/prim_xilinx/prim_xilinx_default_pkg.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CAPI=2:
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

name: "lowrisc:prim_xilinx:prim_xilinx_default_pkg"
description: "Single port RAM"
virtual:
- lowrisc:prim_xilinx:prim_xilinx_pkg
filesets:
files_rtl:
files:
- rtl/prim_xilinx_pkg.sv
file_type: systemVerilogSource

targets:
default: &default_target
filesets:
- files_rtl
41 changes: 41 additions & 0 deletions hw/ip/prim_xilinx/prim_xilinx_ram_1p.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CAPI=2:
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

name: "lowrisc:prim_xilinx:ram_1p"
description: "Single port RAM"
filesets:
files_rtl:
depend:
- lowrisc:prim:assert
- lowrisc:prim:ram_1p_pkg
- lowrisc:prim_xilinx:prim_xilinx_pkg
- lowrisc:prim_generic:ram_1p
- lowrisc:prim:util_memload
files:
- rtl/prim_xilinx_ram_1p.sv
file_type: systemVerilogSource

files_verilator_waiver:
depend:
# common waivers
- lowrisc:lint:common

files_ascentlint_waiver:
depend:
# common waivers
- lowrisc:lint:common

files_veriblelint_waiver:
depend:
# common waivers
- lowrisc:lint:common

targets:
default:
filesets:
- tool_verilator ? (files_verilator_waiver)
- tool_ascentlint ? (files_ascentlint_waiver)
- tool_veriblelint ? (files_veriblelint_waiver)
- files_rtl
11 changes: 11 additions & 0 deletions hw/ip/prim_xilinx/rtl/prim_xilinx_pkg.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

package prim_xilinx_pkg;

function automatic int get_ram_max_width(int width, int depth);
return 0;
endfunction

endpackage : prim_xilinx_pkg
77 changes: 77 additions & 0 deletions hw/ip/prim_xilinx/rtl/prim_xilinx_ram_1p.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Synchronous single-port SRAM model

`include "prim_assert.sv"

module prim_xilinx_ram_1p import prim_ram_1p_pkg::*; #(
parameter int Width = 32, // bit
parameter int Depth = 128,
parameter int DataBitsPerMask = 1, // Number of data bits per bit of write mask
parameter MemInitFile = "", // VMEM file to initialize the memory with

localparam int Aw = $clog2(Depth) // derived parameter
) (
input logic clk_i,

input logic req_i,
input logic write_i,
input logic [Aw-1:0] addr_i,
input logic [Width-1:0] wdata_i,
input logic [Width-1:0] wmask_i,
output logic [Width-1:0] rdata_o, // Read data. Data is returned one cycle after req_i is high.
input ram_1p_cfg_t cfg_i
);

localparam int PrimMaxWidth = prim_xilinx_pkg::get_ram_max_width(Width, Depth);

if (PrimMaxWidth <= 0) begin : gen_generic
prim_generic_ram_1p #(
.Width(Width),
.Depth(Depth),
.DataBitsPerMask(DataBitsPerMask),
.MemInitFile(MemInitFile)
) u_ram_1p (
.*
);
end else begin : gen_xpm
logic wr_en;
assign wr_en = write_i & wmask_i[0];

logic unused_cfg_i;
assign unused_cfg_i = cfg_i;

for (genvar k = 0; k < Width; k = k + PrimMaxWidth) begin : gen_split
localparam int PrimWidth = ((Width - k) > PrimMaxWidth) ? PrimMaxWidth : Width - k;
localparam string PrimMemoryInitFile = (MemInitFile != "") ? MemInitFile : "none";

xpm_memory_spram #(
.ADDR_WIDTH_A(Aw),
.BYTE_WRITE_WIDTH_A(PrimWidth), // Masks are not supported
.MEMORY_INIT_FILE(PrimMemoryInitFile),
.MEMORY_SIZE(Depth * PrimWidth),
.READ_DATA_WIDTH_A(PrimWidth),
.READ_LATENCY_A(1),
.USE_MEM_INIT_MMI(1),
.WRITE_DATA_WIDTH_A(PrimWidth)
) u_ram_1p (
.clka(clk_i),
.addra(addr_i),
.dbiterra(),
.dina(wdata_i[k +: PrimWidth]),
.douta(rdata_o[k +: PrimWidth]),
.ena(req_i),
.injectdbiterra(1'b0),
.injectsbiterra(1'b0),
.regcea(1'b1),
.rsta(1'b0),
.sbiterra(),
.sleep(1'b0),
.wea(wr_en)
);
end
end

endmodule
19 changes: 19 additions & 0 deletions hw/ip/prim_xilinx_ultrascale/prim_xilinx_ultrascale_ram_1p.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CAPI=2:
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

name: "lowrisc:prim_xilinx_ultrascale:ram_1p"
description: "Single port RAM"
filesets:
files_rtl:
depend:
- lowrisc:prim_xilinx:ram_1p
files:
- rtl/prim_xilinx_ultrascale_ram_1p.sv
file_type: systemVerilogSource

targets:
default:
filesets:
- files_rtl
35 changes: 35 additions & 0 deletions hw/ip/prim_xilinx_ultrascale/rtl/prim_xilinx_ultrascale_ram_1p.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Synchronous single-port SRAM model

`include "prim_assert.sv"

module prim_xilinx_ultrascale_ram_1p import prim_ram_1p_pkg::*; #(
parameter int Width = 32, // bit
parameter int Depth = 128,
parameter int DataBitsPerMask = 1, // Number of data bits per bit of write mask
parameter MemInitFile = "", // VMEM file to initialize the memory with

localparam int Aw = $clog2(Depth) // derived parameter
) (
input logic clk_i,

input logic req_i,
input logic write_i,
input logic [Aw-1:0] addr_i,
input logic [Width-1:0] wdata_i,
input logic [Width-1:0] wmask_i,
output logic [Width-1:0] rdata_o, // Read data. Data is returned one cycle after req_i is high.
input ram_1p_cfg_t cfg_i
);

prim_xilinx_ram_1p #(
.Width(Width),
.Depth(Depth),
.DataBitsPerMask(DataBitsPerMask),
.MemInitFile(MemInitFile)
) u_inst (.*);

endmodule
2 changes: 1 addition & 1 deletion hw/top_earlgrey/chip_earlgrey_cw310.core
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description: "Earl Grey toplevel for the ChipWhisperer CW310 board"
filesets:
files_rtl_cw310:
depend:
- lowrisc:prim_xilinx:earlgrey_xilinx_prim_pkg
- lowrisc:systems:top_earlgrey:0.1
- lowrisc:systems:top_earlgrey_pkg
- lowrisc:systems:ast
Expand All @@ -23,7 +24,6 @@ filesets:
- data/clocks.xdc
- data/pins_cw310.xdc
- data/placement.xdc
- data/synth.xdc
file_type: xdc

files_tcl:
Expand Down
2 changes: 1 addition & 1 deletion hw/top_earlgrey/chip_earlgrey_cw310_hyperdebug.core
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description: "Earl Grey toplevel for the ChipWhisperer CW310 board's hyperdebug
filesets:
files_rtl_cw310:
depend:
- lowrisc:prim_xilinx:earlgrey_xilinx_prim_pkg
- lowrisc:systems:top_earlgrey:0.1
- lowrisc:systems:top_earlgrey_pkg
- lowrisc:systems:ast
Expand All @@ -25,7 +26,6 @@ filesets:
# same as lowrisc:systems:chip_earlgrey_cw310.
- data/pins_cw310_hyperdebug.xdc
- data/placement.xdc
- data/synth.xdc
file_type: xdc

files_tcl:
Expand Down
2 changes: 1 addition & 1 deletion hw/top_earlgrey/chip_earlgrey_cw340.core
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description: "Earl Grey toplevel for the ChipWhisperer CW340 board"
filesets:
files_rtl_cw340:
depend:
- lowrisc:prim_xilinx:earlgrey_xilinx_prim_pkg
- lowrisc:systems:top_earlgrey:0.1
- lowrisc:systems:top_earlgrey_pkg
- lowrisc:systems:ast
Expand All @@ -22,7 +23,6 @@ filesets:
files:
- data/clocks_cw341.xdc
- data/pins_cw341.xdc
- data/synth.xdc
file_type: xdc

files_tcl:
Expand Down
14 changes: 0 additions & 14 deletions hw/top_earlgrey/data/synth.xdc

This file was deleted.

19 changes: 19 additions & 0 deletions hw/top_earlgrey/earlgrey_xilinx_prim_pkg.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CAPI=2:
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

name: "lowrisc:prim_xilinx:earlgrey_xilinx_prim_pkg"
description: "Single port RAM"
virtual:
- lowrisc:prim_xilinx:prim_xilinx_pkg
filesets:
files_rtl:
files:
- rtl/prim_xilinx_pkg.sv
file_type: systemVerilogSource

targets:
default: &default_target
filesets:
- files_rtl
14 changes: 14 additions & 0 deletions hw/top_earlgrey/rtl/prim_xilinx_pkg.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

package prim_xilinx_pkg;

function automatic int get_ram_max_width(int width, int depth);
if (width == 76 && depth < 4096) begin
return 64;
end
return 0;
endfunction

endpackage : prim_xilinx_pkg
Loading

0 comments on commit b7e19f4

Please sign in to comment.