|
| 1 | +// Copyright lowRISC contributors (OpenTitan project). |
| 2 | +// Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +`include "prim_assert.sv" |
| 6 | + |
| 7 | +/** |
| 8 | + * Tile-Link UL adapter for SRAM-like devices with RACL support |
| 9 | + * |
| 10 | + * - Intentionally omitted BaseAddr in case of multiple memory maps are used in a SoC, |
| 11 | + * it means that aliasing can happen if target device size in TL-UL crossbar is bigger |
| 12 | + * than SRAM size |
| 13 | + * - At most one of EnableDataIntgGen / EnableDataIntgPt can be enabled. However it |
| 14 | + * possible for both to be disabled. |
| 15 | + * A module can neither generate an integrity response nor pass through any pre-existing |
| 16 | + * integrity. This might be the case for non-security critical memories where there is |
| 17 | + * no stored integrity AND another entity upstream is already generating returning integrity. |
| 18 | + * There is however no case where EnableDataIntgGen and EnableDataIntgPt are both true. |
| 19 | + */ |
| 20 | +module tlul_adapter_sram_racl |
| 21 | + import tlul_pkg::*; |
| 22 | + import prim_mubi_pkg::mubi4_t; |
| 23 | +#( |
| 24 | + parameter int SramAw = 12, |
| 25 | + parameter int SramDw = 32, // Must be multiple of the TL width |
| 26 | + parameter int Outstanding = 1, // Only one request is accepted |
| 27 | + parameter int SramBusBankAW = 12, // SRAM bus address width of the SRAM bank. Only used |
| 28 | + // when DataXorAddr=1. |
| 29 | + parameter bit ByteAccess = 1, // 1: Enables sub-word write transactions. Note that this |
| 30 | + // results in read-modify-write operations for integrity |
| 31 | + // re-generation if EnableDataIntgPt is set to 1. |
| 32 | + parameter bit ErrOnWrite = 0, // 1: Writes not allowed, automatically error |
| 33 | + parameter bit ErrOnRead = 0, // 1: Reads not allowed, automatically error |
| 34 | + parameter bit CmdIntgCheck = 0, // 1: Enable command integrity check |
| 35 | + parameter bit EnableRspIntgGen = 0, // 1: Generate response integrity |
| 36 | + parameter bit EnableDataIntgGen = 0, // 1: Generate response data integrity |
| 37 | + parameter bit EnableDataIntgPt = 0, // 1: Passthrough command/response data integrity |
| 38 | + parameter bit SecFifoPtr = 0, // 1: Duplicated fifo pointers |
| 39 | + parameter bit EnableReadback = 0, // 1: Readback and check written/read data. |
| 40 | + parameter bit DataXorAddr = 0, // 1: XOR data and address for address protection |
| 41 | + parameter bit EnableRacl = 0, // 1: Enable RACL checks on access |
| 42 | + parameter bit RaclErrorRsp = 1, // 1: Return TLUL error on RACL errors |
| 43 | + parameter int RaclPolicySelVec = 0, // RACL policy for this SRAM adapter |
| 44 | + localparam int WidthMult = SramDw / top_pkg::TL_DW, |
| 45 | + localparam int IntgWidth = tlul_pkg::DataIntgWidth * WidthMult, |
| 46 | + localparam int DataOutW = EnableDataIntgPt ? SramDw + IntgWidth : SramDw |
| 47 | +) ( |
| 48 | + input clk_i, |
| 49 | + input rst_ni, |
| 50 | + |
| 51 | + // TL-UL interface |
| 52 | + input tl_h2d_t tl_i, |
| 53 | + output tl_d2h_t tl_o, |
| 54 | + |
| 55 | + // control interface |
| 56 | + input mubi4_t en_ifetch_i, |
| 57 | + |
| 58 | + // SRAM interface |
| 59 | + output logic req_o, |
| 60 | + output mubi4_t req_type_o, |
| 61 | + input gnt_i, |
| 62 | + output logic we_o, |
| 63 | + output logic [SramAw-1:0] addr_o, |
| 64 | + output logic [DataOutW-1:0] wdata_o, |
| 65 | + output logic [DataOutW-1:0] wmask_o, |
| 66 | + output logic intg_error_o, |
| 67 | + output logic [RsvdWidth-1:0] user_rsvd_o, |
| 68 | + input [DataOutW-1:0] rdata_i, |
| 69 | + input rvalid_i, |
| 70 | + input [1:0] rerror_i, // 2 bit error [1]: Uncorrectable, [0]: Correctable |
| 71 | + output logic compound_txn_in_progress_o, |
| 72 | + input mubi4_t readback_en_i, |
| 73 | + output logic readback_error_o, |
| 74 | + input logic wr_collision_i, |
| 75 | + input logic write_pending_i, |
| 76 | + // RACL interface |
| 77 | + input top_racl_pkg::racl_policy_vec_t racl_policies_i, |
| 78 | + output logic racl_error_o, |
| 79 | + output top_racl_pkg::racl_error_log_t racl_error_log_o |
| 80 | +); |
| 81 | + tl_h2d_t tl_h2d_filtered; |
| 82 | + tl_d2h_t tl_d2h_filtered; |
| 83 | + |
| 84 | + if (EnableRacl) begin : gen_racl_role_logic |
| 85 | + // Retrieve RACL role from user bits and one-hot encode that for the comparison bitmap |
| 86 | + top_racl_pkg::racl_role_t racl_role; |
| 87 | + assign racl_role = top_racl_pkg::tlul_extract_racl_role_bits(tl_i.a_user.rsvd); |
| 88 | + |
| 89 | + top_racl_pkg::racl_role_vec_t racl_role_vec; |
| 90 | + prim_onehot_enc #( |
| 91 | + .OneHotWidth( $bits(top_racl_pkg::racl_role_vec_t) ) |
| 92 | + ) u_racl_role_encode ( |
| 93 | + .in_i ( racl_role ), |
| 94 | + .en_i ( 1'b1 ), |
| 95 | + .out_o( racl_role_vec ) |
| 96 | + ); |
| 97 | + |
| 98 | + logic rd_req, racl_read_allowed, racl_write_allowed; |
| 99 | + assign rd_req = tl_i.a_opcode == tlul_pkg::Get; |
| 100 | + assign racl_read_allowed = (|(racl_policies_i[RaclPolicySelVec].read_perm & racl_role_vec)); |
| 101 | + assign racl_write_allowed = (|(racl_policies_i[RaclPolicySelVec].write_perm & racl_role_vec)); |
| 102 | + assign racl_error_o = (rd_req & ~racl_read_allowed) | (~rd_req & ~racl_write_allowed); |
| 103 | + |
| 104 | + tlul_request_loopback #( |
| 105 | + .ErrorRsp(RaclErrorRsp) |
| 106 | + ) u_loopback ( |
| 107 | + .clk_i, |
| 108 | + .rst_ni, |
| 109 | + .squash_req_i ( racl_error_o ), |
| 110 | + .tl_h2d_i ( tl_i ), |
| 111 | + .tl_d2h_o ( tl_o ), |
| 112 | + .tl_h2d_o ( tl_h2d_filtered ), |
| 113 | + .tl_d2h_i ( tl_d2h_filtered ) |
| 114 | + ); |
| 115 | + |
| 116 | + // Collect RACL error information |
| 117 | + assign racl_error_log_o.read_access = tl_i.a_opcode == tlul_pkg::Get; |
| 118 | + assign racl_error_log_o.racl_role = racl_role; |
| 119 | + assign racl_error_log_o.ctn_uid = top_racl_pkg::tlul_extract_ctn_uid_bits(tl_i.a_user.rsvd); |
| 120 | + end else begin : gen_no_racl_role_logic |
| 121 | + // Pass through and default assignments |
| 122 | + assign tl_h2d_filtered = tl_i; |
| 123 | + assign tl_o = tl_d2h_filtered; |
| 124 | + assign racl_error_o = 1'b0; |
| 125 | + assign racl_error_log_o = '0; |
| 126 | + end |
| 127 | + |
| 128 | + tlul_adapter_sram #( |
| 129 | + .SramAw ( SramAw ), |
| 130 | + .SramDw ( SramDw ), |
| 131 | + .Outstanding ( Outstanding ), |
| 132 | + .SramBusBankAW ( SramBusBankAW ), |
| 133 | + .ByteAccess ( ByteAccess ), |
| 134 | + .ErrOnWrite ( ErrOnWrite ), |
| 135 | + .ErrOnRead ( ErrOnRead ), |
| 136 | + .CmdIntgCheck ( CmdIntgCheck ), |
| 137 | + .EnableRspIntgGen ( EnableRspIntgGen ), |
| 138 | + .EnableDataIntgPt ( EnableDataIntgPt ), |
| 139 | + .SecFifoPtr ( SecFifoPtr ), |
| 140 | + .EnableReadback ( EnableReadback ), |
| 141 | + .DataXorAddr ( DataXorAddr ) |
| 142 | + ) tlul_adapter_sram ( |
| 143 | + .clk_i, |
| 144 | + .rst_ni, |
| 145 | + .tl_i(tl_h2d_filtered), |
| 146 | + .tl_i(tl_d2h_filtered), |
| 147 | + .en_ifetch_i, |
| 148 | + .req_o, |
| 149 | + .req_type_o, |
| 150 | + .gnt_i, |
| 151 | + .we_o, |
| 152 | + .addr_o, |
| 153 | + .wdata_o, |
| 154 | + .intg_error_o, |
| 155 | + .user_rsvd_o, |
| 156 | + .rdata_i, |
| 157 | + .rvalid_i, |
| 158 | + .rerror_i, |
| 159 | + .compound_txn_in_progress_o, |
| 160 | + .readback_en_i, |
| 161 | + .readback_error_o, |
| 162 | + .wr_collision_i, |
| 163 | + .write_pending_i |
| 164 | + ); |
| 165 | + |
| 166 | + // Not all RACL policies are used, even if RACL is enabled |
| 167 | + logic unused_policy_sel; |
| 168 | + assign unused_policy_sel = ^racl_policies_i; |
| 169 | + |
| 170 | + // Ensure that RACL signals are not undefined |
| 171 | + `ASSERT_KNOWN(RaclAdapterSramErrorKnown_A, racl_error_o) |
| 172 | + `ASSERT_KNOWN(RaclAdapterSramErrorLogKnown_A, racl_error_log_o) |
| 173 | + |
| 174 | +endmodule |
0 commit comments