Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 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 | // Flash Controller Module |
| 6 | // |
| 7 | // |
| 8 | |
| 9 | `include "prim_assert.sv" |
| 10 | |
Rupert Swarbrick | 21d6e5b | 2021-03-18 09:07:35 +0000 | [diff] [blame] | 11 | module flash_ctrl |
| 12 | import flash_ctrl_pkg::*; |
| 13 | import flash_ctrl_reg_pkg::*; |
| 14 | #( |
| 15 | parameter logic [NumAlerts-1:0] AlertAsyncOn = {NumAlerts{1'b1}}, |
| 16 | parameter flash_key_t RndCnstAddrKey = RndCnstAddrKeyDefault, |
| 17 | parameter flash_key_t RndCnstDataKey = RndCnstDataKeyDefault, |
| 18 | parameter lfsr_seed_t RndCnstLfsrSeed = RndCnstLfsrSeedDefault, |
| 19 | parameter lfsr_perm_t RndCnstLfsrPerm = RndCnstLfsrPermDefault |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 20 | ) ( |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 21 | input clk_i, |
| 22 | input rst_ni, |
| 23 | |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 24 | input clk_otp_i, |
| 25 | input rst_otp_ni, |
| 26 | |
Timothy Chen | 8ea1b41 | 2020-11-18 18:32:08 -0800 | [diff] [blame] | 27 | // life cycle interface |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 28 | input lc_ctrl_pkg::lc_tx_t lc_creator_seed_sw_rw_en_i, |
| 29 | input lc_ctrl_pkg::lc_tx_t lc_owner_seed_sw_rw_en_i, |
| 30 | input lc_ctrl_pkg::lc_tx_t lc_iso_part_sw_rd_en_i, |
| 31 | input lc_ctrl_pkg::lc_tx_t lc_iso_part_sw_wr_en_i, |
| 32 | input lc_ctrl_pkg::lc_tx_t lc_seed_hw_rd_en_i, |
Timothy Chen | 8ea1b41 | 2020-11-18 18:32:08 -0800 | [diff] [blame] | 33 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 34 | // Bus Interface |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 35 | input tlul_pkg::tl_h2d_t core_tl_i, |
| 36 | output tlul_pkg::tl_d2h_t core_tl_o, |
| 37 | input tlul_pkg::tl_h2d_t prim_tl_i, |
| 38 | output tlul_pkg::tl_d2h_t prim_tl_o, |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 39 | |
| 40 | // Flash Interface |
| 41 | input flash_rsp_t flash_i, |
| 42 | output flash_req_t flash_o, |
| 43 | |
| 44 | // otp/lc/pwrmgr/keymgr Interface |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 45 | output otp_ctrl_pkg::flash_otp_key_req_t otp_o, |
| 46 | input otp_ctrl_pkg::flash_otp_key_rsp_t otp_i, |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 47 | input lc_ctrl_pkg::lc_tx_t rma_req_i, |
| 48 | input lc_ctrl_pkg::lc_flash_rma_seed_t rma_seed_i, |
| 49 | output lc_ctrl_pkg::lc_tx_t rma_ack_o, |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 50 | input pwrmgr_pkg::pwr_flash_req_t pwrmgr_i, |
| 51 | output pwrmgr_pkg::pwr_flash_rsp_t pwrmgr_o, |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 52 | output keymgr_flash_t keymgr_o, |
| 53 | |
Timothy Chen | d8fded8 | 2021-02-22 11:32:55 -0800 | [diff] [blame] | 54 | // IOs |
| 55 | input cio_tck_i, |
| 56 | input cio_tms_i, |
| 57 | input cio_tdi_i, |
| 58 | output logic cio_tdo_en_o, |
| 59 | output logic cio_tdo_o, |
| 60 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 61 | // Interrupts |
| 62 | output logic intr_prog_empty_o, // Program fifo is empty |
| 63 | output logic intr_prog_lvl_o, // Program fifo is empty |
| 64 | output logic intr_rd_full_o, // Read fifo is full |
| 65 | output logic intr_rd_lvl_o, // Read fifo is full |
| 66 | output logic intr_op_done_o, // Requested flash operation (wr/erase) done |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 67 | |
| 68 | // Alerts |
| 69 | input prim_alert_pkg::alert_rx_t [flash_ctrl_reg_pkg::NumAlerts-1:0] alert_rx_i, |
| 70 | output prim_alert_pkg::alert_tx_t [flash_ctrl_reg_pkg::NumAlerts-1:0] alert_tx_o |
| 71 | |
| 72 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 73 | ); |
| 74 | |
| 75 | import flash_ctrl_reg_pkg::*; |
| 76 | |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 77 | flash_ctrl_core_reg2hw_t reg2hw; |
| 78 | flash_ctrl_core_hw2reg_t hw2reg; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 79 | |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 80 | tlul_pkg::tl_h2d_t tl_win_h2d [2]; |
| 81 | tlul_pkg::tl_d2h_t tl_win_d2h [2]; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 82 | |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 83 | assign prim_tl_o = flash_i.tl_flash_p2c; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 84 | // Register module |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 85 | flash_ctrl_core_reg_top u_reg_core ( |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 86 | .clk_i, |
| 87 | .rst_ni, |
| 88 | |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 89 | .tl_i(core_tl_i), |
| 90 | .tl_o(core_tl_o), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 91 | |
Timothy Chen | 6e49518 | 2020-12-28 16:16:35 -0800 | [diff] [blame] | 92 | .tl_win_o (tl_win_h2d), |
| 93 | .tl_win_i (tl_win_d2h), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 94 | |
| 95 | .reg2hw, |
| 96 | .hw2reg, |
| 97 | |
Timothy Chen | 8ec347f | 2021-03-02 11:52:17 -0800 | [diff] [blame] | 98 | .intg_err_o (), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 99 | .devmode_i (1'b1) |
| 100 | ); |
| 101 | |
| 102 | // FIFO Connections |
| 103 | logic prog_fifo_wvalid; |
| 104 | logic prog_fifo_wready; |
| 105 | logic prog_fifo_rvalid; |
| 106 | logic prog_fifo_ren; |
| 107 | logic [BusWidth-1:0] prog_fifo_wdata; |
| 108 | logic [BusWidth-1:0] prog_fifo_rdata; |
| 109 | logic [FifoDepthW-1:0] prog_fifo_depth; |
| 110 | logic rd_fifo_wready; |
| 111 | logic rd_fifo_rvalid; |
| 112 | logic rd_fifo_rready; |
| 113 | logic rd_fifo_wen; |
| 114 | logic rd_fifo_ren; |
| 115 | logic [BusWidth-1:0] rd_fifo_wdata; |
| 116 | logic [BusWidth-1:0] rd_fifo_rdata; |
| 117 | logic [FifoDepthW-1:0] rd_fifo_depth; |
Timothy Chen | 71d98f8 | 2020-12-17 17:17:25 -0800 | [diff] [blame] | 118 | logic rd_fifo_full; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 119 | |
| 120 | // Program Control Connections |
| 121 | logic prog_flash_req; |
| 122 | logic prog_flash_ovfl; |
| 123 | logic [BusAddrW-1:0] prog_flash_addr; |
| 124 | logic prog_op_valid; |
| 125 | |
| 126 | // Read Control Connections |
| 127 | logic rd_flash_req; |
| 128 | logic rd_flash_ovfl; |
| 129 | logic [BusAddrW-1:0] rd_flash_addr; |
| 130 | |
| 131 | // Erase Control Connections |
| 132 | logic erase_flash_req; |
| 133 | logic [BusAddrW-1:0] erase_flash_addr; |
| 134 | flash_erase_e erase_flash_type; |
| 135 | |
| 136 | // Done / Error signaling from ctrl modules |
| 137 | logic prog_done, rd_done, erase_done; |
| 138 | logic prog_err, rd_err, erase_err; |
| 139 | |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 140 | // Flash Memory Properties Connections |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 141 | logic [BusAddrW-1:0] flash_addr; |
| 142 | logic flash_req; |
| 143 | logic flash_rd_done, flash_prog_done, flash_erase_done; |
| 144 | logic flash_mp_error; |
| 145 | logic [BusWidth-1:0] flash_prog_data; |
| 146 | logic flash_prog_last; |
| 147 | flash_prog_e flash_prog_type; |
| 148 | logic [BusWidth-1:0] flash_rd_data; |
| 149 | logic flash_rd_err; |
| 150 | logic flash_phy_busy; |
| 151 | logic rd_op; |
| 152 | logic prog_op; |
| 153 | logic erase_op; |
| 154 | logic [AllPagesW-1:0] err_addr; |
| 155 | flash_lcmgr_phase_e phase; |
| 156 | |
| 157 | // Flash control arbitration connections to hardware interface |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 158 | flash_key_t addr_key; |
| 159 | flash_key_t data_key; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 160 | flash_ctrl_reg2hw_control_reg_t hw_ctrl; |
| 161 | logic hw_req; |
| 162 | logic [top_pkg::TL_AW-1:0] hw_addr; |
| 163 | logic hw_done; |
| 164 | logic hw_err; |
| 165 | logic hw_rvalid; |
| 166 | logic hw_rready; |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 167 | logic hw_wvalid; |
| 168 | logic [BusWidth-1:0] hw_wdata; |
| 169 | logic hw_wready; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 170 | flash_sel_e if_sel; |
| 171 | logic sw_sel; |
| 172 | flash_lcmgr_phase_e hw_phase; |
| 173 | logic creator_seed_priv; |
| 174 | logic owner_seed_priv; |
| 175 | |
| 176 | // Flash control arbitration connections to software interface |
| 177 | logic sw_ctrl_done; |
| 178 | logic sw_ctrl_err; |
| 179 | |
| 180 | // Flash control muxed connections |
| 181 | flash_ctrl_reg2hw_control_reg_t muxed_ctrl; |
| 182 | logic [top_pkg::TL_AW-1:0] muxed_addr; |
| 183 | logic op_start; |
| 184 | logic [11:0] op_num_words; |
| 185 | logic [BusAddrW-1:0] op_addr; |
| 186 | flash_op_e op_type; |
| 187 | flash_part_e op_part; |
| 188 | logic [InfoTypesWidth-1:0] op_info_sel; |
| 189 | flash_erase_e op_erase_type; |
| 190 | flash_prog_e op_prog_type; |
| 191 | |
| 192 | logic ctrl_init_busy; |
| 193 | logic fifo_clr; |
| 194 | |
| 195 | // software tlul to flash control aribration |
| 196 | logic sw_rvalid; |
| 197 | logic adapter_rvalid; |
| 198 | logic sw_wvalid; |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 199 | logic [BusWidth-1:0] sw_wdata; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 200 | logic sw_wen; |
| 201 | logic sw_wready; |
| 202 | |
| 203 | // lfsr for local entropy usage |
| 204 | logic [31:0] rand_val; |
| 205 | logic lfsr_en; |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 206 | logic lfsr_seed_en; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 207 | |
Timothy Chen | 8ea1b41 | 2020-11-18 18:32:08 -0800 | [diff] [blame] | 208 | // life cycle connections |
Cindy Chen | 39b1434 | 2021-01-29 16:25:24 -0800 | [diff] [blame] | 209 | lc_ctrl_pkg::lc_tx_t [0:0] lc_creator_seed_sw_rw_en; |
| 210 | lc_ctrl_pkg::lc_tx_t [0:0] lc_owner_seed_sw_rw_en; |
| 211 | lc_ctrl_pkg::lc_tx_t [0:0] lc_iso_part_sw_rd_en; |
| 212 | lc_ctrl_pkg::lc_tx_t [0:0] lc_iso_part_sw_wr_en; |
| 213 | lc_ctrl_pkg::lc_tx_t [0:0] lc_seed_hw_rd_en; |
Timothy Chen | 8ea1b41 | 2020-11-18 18:32:08 -0800 | [diff] [blame] | 214 | |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 215 | // synchronize enables into local domain |
Timothy Chen | 8d92315 | 2020-12-02 18:01:28 -0800 | [diff] [blame] | 216 | prim_lc_sync #( |
| 217 | .NumCopies(1) |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 218 | ) u_lc_creator_seed_sw_rw_en_sync ( |
Timothy Chen | 8d92315 | 2020-12-02 18:01:28 -0800 | [diff] [blame] | 219 | .clk_i, |
| 220 | .rst_ni, |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 221 | .lc_en_i(lc_creator_seed_sw_rw_en_i), |
| 222 | .lc_en_o(lc_creator_seed_sw_rw_en) |
Timothy Chen | 8d92315 | 2020-12-02 18:01:28 -0800 | [diff] [blame] | 223 | ); |
| 224 | |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 225 | prim_lc_sync #( |
| 226 | .NumCopies(1) |
| 227 | ) u_lc_owner_seed_sw_rw_en_sync ( |
| 228 | .clk_i, |
| 229 | .rst_ni, |
| 230 | .lc_en_i(lc_owner_seed_sw_rw_en_i), |
| 231 | .lc_en_o(lc_owner_seed_sw_rw_en) |
| 232 | ); |
| 233 | |
| 234 | prim_lc_sync #( |
| 235 | .NumCopies(1) |
| 236 | ) u_lc_iso_part_sw_rd_en_sync ( |
| 237 | .clk_i, |
| 238 | .rst_ni, |
| 239 | .lc_en_i(lc_iso_part_sw_rd_en_i), |
| 240 | .lc_en_o(lc_iso_part_sw_rd_en) |
| 241 | ); |
| 242 | |
| 243 | prim_lc_sync #( |
| 244 | .NumCopies(1) |
| 245 | ) u_lc_iso_part_sw_wr_en_sync ( |
| 246 | .clk_i, |
| 247 | .rst_ni, |
| 248 | .lc_en_i(lc_iso_part_sw_wr_en_i), |
| 249 | .lc_en_o(lc_iso_part_sw_wr_en) |
| 250 | ); |
| 251 | |
| 252 | prim_lc_sync #( |
| 253 | .NumCopies(1) |
| 254 | ) u_lc_seed_hw_rd_en_sync ( |
| 255 | .clk_i, |
| 256 | .rst_ni, |
| 257 | .lc_en_i(lc_seed_hw_rd_en_i), |
| 258 | .lc_en_o(lc_seed_hw_rd_en) |
| 259 | ); |
Timothy Chen | 8d92315 | 2020-12-02 18:01:28 -0800 | [diff] [blame] | 260 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 261 | prim_lfsr #( |
Timothy Chen | aeffadc | 2020-12-11 15:03:07 -0800 | [diff] [blame] | 262 | .EntropyDw(EdnWidth), |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 263 | .LfsrDw(LfsrWidth), |
Timothy Chen | aeffadc | 2020-12-11 15:03:07 -0800 | [diff] [blame] | 264 | .StateOutDw(LfsrWidth), |
| 265 | .DefaultSeed(RndCnstLfsrSeed), |
| 266 | .StatePermEn(1), |
| 267 | .StatePerm(RndCnstLfsrPerm) |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 268 | ) u_lfsr ( |
| 269 | .clk_i, |
| 270 | .rst_ni, |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 271 | .seed_en_i(lfsr_seed_en), |
| 272 | .seed_i(rma_seed_i), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 273 | .lfsr_en_i(lfsr_en), |
Timothy Chen | aeffadc | 2020-12-11 15:03:07 -0800 | [diff] [blame] | 274 | .entropy_i('0), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 275 | .state_o(rand_val) |
| 276 | ); |
| 277 | |
| 278 | // flash control arbitration between softawre / harware interfaces |
| 279 | flash_ctrl_arb u_ctrl_arb ( |
| 280 | .clk_i, |
| 281 | .rst_ni, |
| 282 | |
| 283 | // software interface to rd_ctrl / erase_ctrl |
| 284 | .sw_ctrl_i(reg2hw.control), |
| 285 | .sw_addr_i(reg2hw.addr.q), |
| 286 | .sw_ack_o(sw_ctrl_done), |
| 287 | .sw_err_o(sw_ctrl_err), |
| 288 | |
| 289 | // software interface to rd_fifo |
| 290 | .sw_rvalid_o(sw_rvalid), |
| 291 | .sw_rready_i(adapter_rvalid), |
| 292 | |
| 293 | // software interface to prog_fifo |
| 294 | .sw_wvalid_i(sw_wvalid & sw_wen), |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 295 | .sw_wdata_i(sw_wdata), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 296 | .sw_wready_o(sw_wready), |
| 297 | |
| 298 | // hardware interface to rd_ctrl / erase_ctrl |
| 299 | .hw_req_i(hw_req), |
| 300 | .hw_ctrl_i(hw_ctrl), |
| 301 | |
| 302 | // hardware interface indicating operation phase |
| 303 | .hw_phase_i(hw_phase), |
| 304 | |
| 305 | // hardware works on word address, however software expects byte address |
| 306 | .hw_addr_i(hw_addr), |
| 307 | .hw_ack_o(hw_done), |
| 308 | .hw_err_o(hw_err), |
| 309 | |
| 310 | // hardware interface to rd_fifo |
| 311 | .hw_rvalid_o(hw_rvalid), |
| 312 | .hw_rready_i(hw_rready), |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 313 | .hw_wvalid_i(hw_wvalid), |
| 314 | .hw_wdata_i(hw_wdata), |
| 315 | .hw_wready_o(hw_wready), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 316 | |
| 317 | // hardware interface does not talk to prog_fifo |
| 318 | |
| 319 | // muxed interface to rd_ctrl / erase_ctrl |
| 320 | .muxed_ctrl_o(muxed_ctrl), |
| 321 | .muxed_addr_o(muxed_addr), |
| 322 | .prog_ack_i(prog_done), |
| 323 | .prog_err_i(prog_err), |
| 324 | .rd_ack_i(rd_done), |
| 325 | .rd_err_i(rd_err), |
| 326 | .erase_ack_i(erase_done), |
| 327 | .erase_err_i(erase_err), |
| 328 | |
| 329 | // muxed interface to rd_fifo |
| 330 | .rd_fifo_rvalid_i(rd_fifo_rvalid), |
| 331 | .rd_fifo_rready_o(rd_fifo_rready), |
| 332 | |
| 333 | // muxed interface to prog_fifo |
| 334 | .prog_fifo_wvalid_o(prog_fifo_wvalid), |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 335 | .prog_fifo_wdata_o(prog_fifo_wdata), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 336 | .prog_fifo_wready_i(prog_fifo_wready), |
| 337 | |
| 338 | // flash phy initilization ongoing |
| 339 | .flash_phy_busy_i(flash_phy_busy), |
| 340 | |
| 341 | // clear fifos |
| 342 | .fifo_clr_o(fifo_clr), |
| 343 | |
| 344 | // phase indication |
| 345 | .phase_o(phase), |
| 346 | |
| 347 | // indication that sw has been selected |
Timothy Chen | aeffadc | 2020-12-11 15:03:07 -0800 | [diff] [blame] | 348 | .sel_o(if_sel) |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 349 | ); |
| 350 | |
| 351 | assign op_start = muxed_ctrl.start.q; |
| 352 | assign op_num_words = muxed_ctrl.num.q; |
| 353 | assign op_erase_type = flash_erase_e'(muxed_ctrl.erase_sel.q); |
| 354 | assign op_prog_type = flash_prog_e'(muxed_ctrl.prog_sel.q); |
| 355 | assign op_addr = muxed_addr[BusByteWidth +: BusAddrW]; |
| 356 | assign op_type = flash_op_e'(muxed_ctrl.op.q); |
| 357 | assign op_part = flash_part_e'(muxed_ctrl.partition_sel.q); |
| 358 | assign op_info_sel = muxed_ctrl.info_sel.q; |
| 359 | assign rd_op = op_type == FlashOpRead; |
| 360 | assign prog_op = op_type == FlashOpProgram; |
| 361 | assign erase_op = op_type == FlashOpErase; |
| 362 | assign sw_sel = if_sel == SwSel; |
| 363 | |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 364 | // software privilege to creator seed |
Cindy Chen | 39b1434 | 2021-01-29 16:25:24 -0800 | [diff] [blame] | 365 | assign creator_seed_priv = lc_creator_seed_sw_rw_en[0] == lc_ctrl_pkg::On; |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 366 | |
| 367 | // software privilege to owner seed |
Cindy Chen | 39b1434 | 2021-01-29 16:25:24 -0800 | [diff] [blame] | 368 | assign owner_seed_priv = lc_owner_seed_sw_rw_en[0] == lc_ctrl_pkg::On; |
Timothy Chen | 99f3e3a | 2020-12-09 18:30:19 -0800 | [diff] [blame] | 369 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 370 | // hardware interface |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 371 | flash_ctrl_lcmgr #( |
| 372 | .RndCnstAddrKey(RndCnstAddrKey), |
| 373 | .RndCnstDataKey(RndCnstDataKey) |
| 374 | ) u_flash_hw_if ( |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 375 | .clk_i, |
| 376 | .rst_ni, |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 377 | .clk_otp_i, |
| 378 | .rst_otp_ni, |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 379 | |
| 380 | .init_i(pwrmgr_i.flash_init), |
| 381 | .init_done_o(pwrmgr_o.flash_done), |
Cindy Chen | 39b1434 | 2021-01-29 16:25:24 -0800 | [diff] [blame] | 382 | .provision_en_i(lc_seed_hw_rd_en[0] == lc_ctrl_pkg::On), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 383 | |
| 384 | // interface to ctrl arb control ports |
| 385 | .ctrl_o(hw_ctrl), |
| 386 | .req_o(hw_req), |
| 387 | .addr_o(hw_addr), |
| 388 | .done_i(hw_done), |
| 389 | .err_i(hw_err), |
| 390 | |
| 391 | // interface to ctrl_arb data ports |
| 392 | .rready_o(hw_rready), |
| 393 | .rvalid_i(hw_rvalid), |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 394 | .wready_i(hw_wready), |
| 395 | .wvalid_o(hw_wvalid), |
| 396 | .wdata_o(hw_wdata), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 397 | |
| 398 | // direct form rd_fifo |
| 399 | .rdata_i(rd_fifo_rdata), |
| 400 | |
| 401 | // external rma request |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 402 | .rma_req_i, |
| 403 | .rma_ack_o, |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 404 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 405 | // outgoing seeds |
| 406 | .seeds_o(keymgr_o.seeds), |
| 407 | .seed_err_o(), // TBD hook-up to Err code register |
| 408 | |
| 409 | // phase indication |
| 410 | .phase_o(hw_phase), |
| 411 | |
Timothy Chen | 6b241b3 | 2020-11-13 15:15:45 -0800 | [diff] [blame] | 412 | // phy read buffer enable |
| 413 | .rd_buf_en_o(flash_o.rd_buf_en), |
| 414 | |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 415 | // connection to otp |
| 416 | .otp_key_req_o(otp_o), |
| 417 | .otp_key_rsp_i(otp_i), |
| 418 | .addr_key_o(addr_key), |
| 419 | .data_key_o(data_key), |
| 420 | |
Timothy Chen | aeffadc | 2020-12-11 15:03:07 -0800 | [diff] [blame] | 421 | // entropy interface |
Timothy Chen | d39402a | 2020-12-15 20:34:09 -0800 | [diff] [blame] | 422 | .edn_req_o(lfsr_seed_en), |
| 423 | .edn_ack_i(1'b1), |
Timothy Chen | aeffadc | 2020-12-11 15:03:07 -0800 | [diff] [blame] | 424 | .lfsr_en_o(lfsr_en), |
| 425 | .rand_i(rand_val), |
| 426 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 427 | // init ongoing |
| 428 | .init_busy_o(ctrl_init_busy) |
| 429 | ); |
| 430 | |
| 431 | // Program FIFO |
| 432 | // Since the program and read FIFOs are never used at the same time, it should really be one |
| 433 | // FIFO with muxed inputs and outputs. This should be addressed once the flash integration |
| 434 | // strategy has been identified |
| 435 | assign prog_op_valid = op_start & prog_op; |
| 436 | |
| 437 | tlul_adapter_sram #( |
| 438 | .SramAw(1), //address unused |
| 439 | .SramDw(BusWidth), |
| 440 | .ByteAccess(0), //flash may not support byte access |
| 441 | .ErrOnRead(1) //reads not supported |
| 442 | ) u_to_prog_fifo ( |
| 443 | .clk_i, |
| 444 | .rst_ni, |
Timothy Chen | 1a9a60f | 2021-02-10 18:04:39 -0800 | [diff] [blame] | 445 | .tl_i (tl_win_h2d[0]), |
| 446 | .tl_o (tl_win_d2h[0]), |
| 447 | .en_ifetch_i (tlul_pkg::InstrDis), |
| 448 | .req_o (sw_wvalid), |
| 449 | .gnt_i (sw_wready), |
| 450 | .we_o (sw_wen), |
| 451 | .addr_o (), |
| 452 | .wmask_o (), |
Timothy Chen | 12cce14 | 2021-03-02 18:11:01 -0800 | [diff] [blame] | 453 | .intg_error_o(), |
Timothy Chen | 1a9a60f | 2021-02-10 18:04:39 -0800 | [diff] [blame] | 454 | .wdata_o (sw_wdata), |
| 455 | .rdata_i (BusWidth'(0)), |
| 456 | .rvalid_i (1'b0), |
| 457 | .rerror_i (2'b0) |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 458 | ); |
| 459 | |
| 460 | prim_fifo_sync #( |
| 461 | .Width(BusWidth), |
| 462 | .Depth(FifoDepth) |
| 463 | ) u_prog_fifo ( |
| 464 | .clk_i, |
| 465 | .rst_ni, |
| 466 | .clr_i (reg2hw.fifo_rst.q | fifo_clr), |
| 467 | .wvalid_i(prog_fifo_wvalid & prog_op_valid), |
| 468 | .wready_o(prog_fifo_wready), |
| 469 | .wdata_i (prog_fifo_wdata), |
| 470 | .depth_o (prog_fifo_depth), |
Philipp Wagner | 7858f3d | 2021-02-01 16:38:13 +0000 | [diff] [blame] | 471 | .full_o (), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 472 | .rvalid_o(prog_fifo_rvalid), |
| 473 | .rready_i(prog_fifo_ren), |
| 474 | .rdata_o (prog_fifo_rdata) |
| 475 | ); |
| 476 | |
| 477 | // Program handler is consumer of prog_fifo |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 478 | logic [1:0] prog_type_en; |
| 479 | assign prog_type_en[FlashProgNormal] = flash_i.prog_type_avail[FlashProgNormal] & |
| 480 | reg2hw.prog_type_en.normal.q; |
| 481 | assign prog_type_en[FlashProgRepair] = flash_i.prog_type_avail[FlashProgRepair] & |
| 482 | reg2hw.prog_type_en.repair.q; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 483 | flash_ctrl_prog u_flash_ctrl_prog ( |
| 484 | .clk_i, |
| 485 | .rst_ni, |
| 486 | |
| 487 | // Control interface |
| 488 | .op_start_i (prog_op_valid), |
| 489 | .op_num_words_i (op_num_words), |
| 490 | .op_done_o (prog_done), |
| 491 | .op_err_o (prog_err), |
| 492 | .op_addr_i (op_addr), |
| 493 | .op_type_i (op_prog_type), |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 494 | .type_avail_i (prog_type_en), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 495 | |
| 496 | // FIFO Interface |
| 497 | .data_i (prog_fifo_rdata), |
| 498 | .data_rdy_i (prog_fifo_rvalid), |
| 499 | .data_rd_o (prog_fifo_ren), |
| 500 | |
| 501 | // Flash Macro Interface |
| 502 | .flash_req_o (prog_flash_req), |
| 503 | .flash_addr_o (prog_flash_addr), |
| 504 | .flash_ovfl_o (prog_flash_ovfl), |
| 505 | .flash_data_o (flash_prog_data), |
| 506 | .flash_last_o (flash_prog_last), |
| 507 | .flash_type_o (flash_prog_type), |
| 508 | .flash_done_i (flash_prog_done), |
| 509 | .flash_error_i (flash_mp_error) |
| 510 | ); |
| 511 | |
| 512 | always_ff @(posedge clk_i or negedge rst_ni) begin |
| 513 | if (!rst_ni) begin |
| 514 | adapter_rvalid <= 1'b0; |
| 515 | end else begin |
| 516 | adapter_rvalid <= rd_fifo_ren && sw_rvalid; |
| 517 | end |
| 518 | end |
| 519 | |
| 520 | // tlul adapter represents software's access interface to flash |
| 521 | tlul_adapter_sram #( |
| 522 | .SramAw(1), //address unused |
| 523 | .SramDw(BusWidth), |
| 524 | .ByteAccess(0), //flash may not support byte access |
| 525 | .ErrOnWrite(1) //writes not supported |
| 526 | ) u_to_rd_fifo ( |
| 527 | .clk_i, |
| 528 | .rst_ni, |
Timothy Chen | 1a9a60f | 2021-02-10 18:04:39 -0800 | [diff] [blame] | 529 | .tl_i (tl_win_h2d[1]), |
| 530 | .tl_o (tl_win_d2h[1]), |
| 531 | .en_ifetch_i (tlul_pkg::InstrDis), |
| 532 | .req_o (rd_fifo_ren), |
| 533 | .gnt_i (rd_fifo_rvalid), |
| 534 | .we_o (), |
| 535 | .addr_o (), |
| 536 | .wmask_o (), |
| 537 | .wdata_o (), |
Timothy Chen | 12cce14 | 2021-03-02 18:11:01 -0800 | [diff] [blame] | 538 | .intg_error_o(), |
Timothy Chen | 1a9a60f | 2021-02-10 18:04:39 -0800 | [diff] [blame] | 539 | .rdata_i (rd_fifo_rdata), |
| 540 | .rvalid_i (adapter_rvalid), |
| 541 | .rerror_i (2'b0) |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 542 | ); |
| 543 | |
| 544 | prim_fifo_sync #( |
| 545 | .Width(BusWidth), |
| 546 | .Depth(FifoDepth) |
| 547 | ) u_rd_fifo ( |
| 548 | .clk_i, |
| 549 | .rst_ni, |
| 550 | .clr_i (reg2hw.fifo_rst.q | fifo_clr), |
| 551 | .wvalid_i(rd_fifo_wen), |
| 552 | .wready_o(rd_fifo_wready), |
| 553 | .wdata_i (rd_fifo_wdata), |
Timothy Chen | 71d98f8 | 2020-12-17 17:17:25 -0800 | [diff] [blame] | 554 | .full_o (rd_fifo_full), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 555 | .depth_o (rd_fifo_depth), |
| 556 | .rvalid_o(rd_fifo_rvalid), |
| 557 | .rready_i(rd_fifo_rready), |
| 558 | .rdata_o (rd_fifo_rdata) |
| 559 | ); |
| 560 | |
| 561 | // Read handler is consumer of rd_fifo |
| 562 | flash_ctrl_rd u_flash_ctrl_rd ( |
| 563 | .clk_i, |
| 564 | .rst_ni, |
| 565 | |
| 566 | // To arbiter Interface |
| 567 | .op_start_i (op_start & rd_op), |
| 568 | .op_num_words_i (op_num_words), |
| 569 | .op_done_o (rd_done), |
| 570 | .op_err_o (rd_err), |
| 571 | .op_addr_i (op_addr), |
| 572 | |
| 573 | // FIFO Interface |
| 574 | .data_rdy_i (rd_fifo_wready), |
| 575 | .data_o (rd_fifo_wdata), |
| 576 | .data_wr_o (rd_fifo_wen), |
| 577 | |
| 578 | // Flash Macro Interface |
| 579 | .flash_req_o (rd_flash_req), |
| 580 | .flash_addr_o (rd_flash_addr), |
| 581 | .flash_ovfl_o (rd_flash_ovfl), |
| 582 | .flash_data_i (flash_rd_data), |
| 583 | .flash_done_i (flash_rd_done), |
| 584 | .flash_error_i (flash_mp_error | flash_rd_err) |
| 585 | ); |
| 586 | |
| 587 | // Erase handler does not consume fifo |
| 588 | flash_ctrl_erase u_flash_ctrl_erase ( |
| 589 | // Software Interface |
| 590 | .op_start_i (op_start & erase_op), |
| 591 | .op_type_i (op_erase_type), |
| 592 | .op_done_o (erase_done), |
| 593 | .op_err_o (erase_err), |
| 594 | .op_addr_i (op_addr), |
| 595 | |
| 596 | // Flash Macro Interface |
| 597 | .flash_req_o (erase_flash_req), |
| 598 | .flash_addr_o (erase_flash_addr), |
| 599 | .flash_op_o (erase_flash_type), |
| 600 | .flash_done_i (flash_erase_done), |
| 601 | .flash_error_i (flash_mp_error) |
| 602 | ); |
| 603 | |
| 604 | // Final muxing to flash macro module |
| 605 | always_comb begin |
| 606 | unique case (op_type) |
| 607 | FlashOpRead: begin |
| 608 | flash_req = rd_flash_req; |
| 609 | flash_addr = rd_flash_addr; |
| 610 | end |
| 611 | FlashOpProgram: begin |
| 612 | flash_req = prog_flash_req; |
| 613 | flash_addr = prog_flash_addr; |
| 614 | end |
| 615 | FlashOpErase: begin |
| 616 | flash_req = erase_flash_req; |
| 617 | flash_addr = erase_flash_addr; |
| 618 | end |
| 619 | default: begin |
| 620 | flash_req = 1'b0; |
| 621 | flash_addr = '0; |
| 622 | end |
| 623 | endcase // unique case (op_type) |
| 624 | end |
| 625 | |
| 626 | ////////////////////////////////////// |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 627 | // Data partition properties configuration |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 628 | ////////////////////////////////////// |
| 629 | // extra region is the default region |
| 630 | mp_region_cfg_t [MpRegions:0] region_cfgs; |
| 631 | assign region_cfgs[MpRegions-1:0] = reg2hw.mp_region_cfg[MpRegions-1:0]; |
| 632 | |
| 633 | //default region |
| 634 | assign region_cfgs[MpRegions].base.q = '0; |
| 635 | assign region_cfgs[MpRegions].size.q = NumBanks * PagesPerBank; |
| 636 | assign region_cfgs[MpRegions].en.q = 1'b1; |
| 637 | assign region_cfgs[MpRegions].rd_en.q = reg2hw.default_region.rd_en.q; |
| 638 | assign region_cfgs[MpRegions].prog_en.q = reg2hw.default_region.prog_en.q; |
| 639 | assign region_cfgs[MpRegions].erase_en.q = reg2hw.default_region.erase_en.q; |
| 640 | assign region_cfgs[MpRegions].scramble_en.q = reg2hw.default_region.scramble_en.q; |
Timothy Chen | a2db933 | 2020-11-13 18:47:54 -0800 | [diff] [blame] | 641 | assign region_cfgs[MpRegions].ecc_en.q = reg2hw.default_region.ecc_en.q; |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 642 | assign region_cfgs[MpRegions].he_en.q = reg2hw.default_region.he_en.q; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 643 | |
| 644 | ////////////////////////////////////// |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 645 | // Info partition properties configuration |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 646 | ////////////////////////////////////// |
| 647 | info_page_cfg_t [NumBanks-1:0][InfoTypes-1:0][InfosPerBank-1:0] reg2hw_info_page_cfgs; |
| 648 | info_page_cfg_t [NumBanks-1:0][InfoTypes-1:0][InfosPerBank-1:0] info_page_cfgs; |
Timothy Chen | e97e0b8 | 2020-12-11 17:18:43 -0800 | [diff] [blame] | 649 | localparam int InfoBits = $bits(info_page_cfg_t) * InfosPerBank; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 650 | |
| 651 | // transform from reg output to structure |
Timothy Chen | e97e0b8 | 2020-12-11 17:18:43 -0800 | [diff] [blame] | 652 | // Not all types have the maximum number of banks, so those are packed to 0 |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 653 | % for bank in range(cfg['banks']): |
| 654 | % for idx in range(cfg['info_types']): |
Timothy Chen | e97e0b8 | 2020-12-11 17:18:43 -0800 | [diff] [blame] | 655 | assign reg2hw_info_page_cfgs[${bank}][${idx}] = InfoBits'(reg2hw.bank${bank}_info${idx}_page_cfg); |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 656 | % endfor |
| 657 | % endfor |
| 658 | |
| 659 | // qualify reg2hw settings with creator / owner privileges |
| 660 | for(genvar i = 0; i < NumBanks; i++) begin : gen_info_priv_bank |
| 661 | for (genvar j = 0; j < InfoTypes; j++) begin : gen_info_priv_type |
| 662 | flash_ctrl_info_cfg # ( |
| 663 | .Bank(i), |
| 664 | .InfoSel(j) |
| 665 | ) u_info_cfg ( |
| 666 | .cfgs_i(reg2hw_info_page_cfgs[i][j]), |
| 667 | .creator_seed_priv_i(creator_seed_priv), |
| 668 | .owner_seed_priv_i(owner_seed_priv), |
Cindy Chen | 39b1434 | 2021-01-29 16:25:24 -0800 | [diff] [blame] | 669 | .iso_flash_wr_en_i(lc_iso_part_sw_wr_en[0] == lc_ctrl_pkg::On), |
| 670 | .iso_flash_rd_en_i(lc_iso_part_sw_rd_en[0] == lc_ctrl_pkg::On), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 671 | .cfgs_o(info_page_cfgs[i][j]) |
| 672 | ); |
| 673 | end |
| 674 | end |
| 675 | |
| 676 | ////////////////////////////////////// |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 677 | // flash memory properties |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 678 | ////////////////////////////////////// |
| 679 | // direct assignment since prog/rd/erase_ctrl do not make use of op_part |
| 680 | flash_part_e flash_part_sel; |
| 681 | logic [InfoTypesWidth-1:0] flash_info_sel; |
| 682 | assign flash_part_sel = op_part; |
| 683 | assign flash_info_sel = op_info_sel; |
| 684 | |
Timothy Chen | 7d051eb | 2020-12-11 14:06:43 -0800 | [diff] [blame] | 685 | // tie off hardware clear path |
| 686 | assign hw2reg.erase_suspend.d = 1'b0; |
| 687 | |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 688 | // Flash memory Properties |
| 689 | // Memory property is page based and thus should use phy addressing |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 690 | // This should move to flash_phy long term |
| 691 | flash_mp u_flash_mp ( |
| 692 | .clk_i, |
| 693 | .rst_ni, |
| 694 | |
| 695 | // arbiter interface selection |
| 696 | .if_sel_i(if_sel), |
| 697 | |
| 698 | // sw configuration for data partition |
| 699 | .region_cfgs_i(region_cfgs), |
| 700 | .bank_cfgs_i(reg2hw.mp_bank_cfg), |
| 701 | |
| 702 | // sw configuration for info partition |
| 703 | .info_page_cfgs_i(info_page_cfgs), |
| 704 | |
| 705 | // read / prog / erase controls |
| 706 | .req_i(flash_req), |
| 707 | .phase_i(phase), |
| 708 | .req_addr_i(flash_addr[BusAddrW-1 -: AllPagesW]), |
| 709 | .req_part_i(flash_part_sel), |
| 710 | .info_sel_i(flash_info_sel), |
| 711 | .addr_ovfl_i(rd_flash_ovfl | prog_flash_ovfl), |
| 712 | .rd_i(rd_op), |
| 713 | .prog_i(prog_op), |
| 714 | .pg_erase_i(erase_op & (erase_flash_type == FlashErasePage)), |
| 715 | .bk_erase_i(erase_op & (erase_flash_type == FlashEraseBank)), |
Timothy Chen | 7d051eb | 2020-12-11 14:06:43 -0800 | [diff] [blame] | 716 | .erase_suspend_i(reg2hw.erase_suspend), |
| 717 | .erase_suspend_done_o(hw2reg.erase_suspend.de), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 718 | .rd_done_o(flash_rd_done), |
| 719 | .prog_done_o(flash_prog_done), |
| 720 | .erase_done_o(flash_erase_done), |
| 721 | .error_o(flash_mp_error), |
| 722 | .err_addr_o(err_addr), |
| 723 | |
| 724 | // flash phy interface |
| 725 | .req_o(flash_o.req), |
| 726 | .scramble_en_o(flash_o.scramble_en), |
Timothy Chen | a2db933 | 2020-11-13 18:47:54 -0800 | [diff] [blame] | 727 | .ecc_en_o(flash_o.ecc_en), |
Timothy Chen | d532356 | 2020-12-02 16:10:44 -0800 | [diff] [blame] | 728 | .he_en_o(flash_o.he_en), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 729 | .rd_o(flash_o.rd), |
| 730 | .prog_o(flash_o.prog), |
| 731 | .pg_erase_o(flash_o.pg_erase), |
| 732 | .bk_erase_o(flash_o.bk_erase), |
Timothy Chen | 7d051eb | 2020-12-11 14:06:43 -0800 | [diff] [blame] | 733 | .erase_suspend_o(flash_o.erase_suspend), |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 734 | .rd_done_i(flash_i.rd_done), |
| 735 | .prog_done_i(flash_i.prog_done), |
| 736 | .erase_done_i(flash_i.erase_done) |
| 737 | ); |
| 738 | |
| 739 | |
| 740 | // software interface feedback |
| 741 | // most values (other than flash_phy_busy) should only update when software operations |
| 742 | // are actually selected |
| 743 | assign hw2reg.op_status.done.d = 1'b1; |
| 744 | assign hw2reg.op_status.done.de = sw_ctrl_done; |
| 745 | assign hw2reg.op_status.err.d = 1'b1; |
| 746 | assign hw2reg.op_status.err.de = sw_ctrl_err; |
Timothy Chen | 71d98f8 | 2020-12-17 17:17:25 -0800 | [diff] [blame] | 747 | assign hw2reg.status.rd_full.d = rd_fifo_full; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 748 | assign hw2reg.status.rd_full.de = sw_sel; |
| 749 | assign hw2reg.status.rd_empty.d = ~rd_fifo_rvalid; |
| 750 | assign hw2reg.status.rd_empty.de = sw_sel; |
| 751 | assign hw2reg.status.prog_full.d = ~prog_fifo_wready; |
| 752 | assign hw2reg.status.prog_full.de = sw_sel; |
| 753 | assign hw2reg.status.prog_empty.d = ~prog_fifo_rvalid; |
| 754 | assign hw2reg.status.prog_empty.de = sw_sel; |
| 755 | assign hw2reg.status.init_wip.d = flash_phy_busy | ctrl_init_busy; |
| 756 | assign hw2reg.status.init_wip.de = 1'b1; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 757 | assign hw2reg.control.start.d = 1'b0; |
| 758 | assign hw2reg.control.start.de = sw_ctrl_done; |
| 759 | // if software operation selected, based on transaction start |
| 760 | // if software operation not selected, software is free to change contents |
| 761 | assign hw2reg.ctrl_regwen.d = sw_sel ? !op_start : 1'b1; |
| 762 | |
| 763 | // phy status |
| 764 | assign hw2reg.phy_status.init_wip.d = flash_phy_busy; |
| 765 | assign hw2reg.phy_status.init_wip.de = 1'b1; |
| 766 | assign hw2reg.phy_status.prog_normal_avail.d = flash_i.prog_type_avail[FlashProgNormal]; |
| 767 | assign hw2reg.phy_status.prog_normal_avail.de = 1'b1; |
| 768 | assign hw2reg.phy_status.prog_repair_avail.d = flash_i.prog_type_avail[FlashProgRepair]; |
| 769 | assign hw2reg.phy_status.prog_repair_avail.de = 1'b1; |
| 770 | |
| 771 | // Flash Interface |
| 772 | assign flash_o.addr = flash_addr; |
| 773 | assign flash_o.part = flash_part_sel; |
Timothy Chen | a0a550a | 2020-12-03 13:11:03 -0800 | [diff] [blame] | 774 | assign flash_o.info_sel = flash_info_sel; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 775 | assign flash_o.prog_type = flash_prog_type; |
| 776 | assign flash_o.prog_data = flash_prog_data; |
| 777 | assign flash_o.prog_last = flash_prog_last; |
| 778 | assign flash_o.region_cfgs = region_cfgs; |
Timothy Chen | f52a461 | 2020-12-04 20:37:49 -0800 | [diff] [blame] | 779 | assign flash_o.addr_key = addr_key; |
| 780 | assign flash_o.data_key = data_key; |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 781 | assign flash_o.tl_flash_c2p = prim_tl_i; |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 782 | assign flash_o.alert_trig = reg2hw.phy_alert_cfg.alert_trig.q; |
| 783 | assign flash_o.alert_ack = reg2hw.phy_alert_cfg.alert_ack.q; |
Timothy Chen | d8fded8 | 2021-02-22 11:32:55 -0800 | [diff] [blame] | 784 | assign flash_o.jtag_req.tck = cio_tck_i; |
| 785 | assign flash_o.jtag_req.tms = cio_tms_i; |
| 786 | assign flash_o.jtag_req.tdi = cio_tdi_i; |
| 787 | assign flash_o.jtag_req.trst_n = '0; |
| 788 | assign cio_tdo_o = flash_i.jtag_rsp.tdo; |
| 789 | assign cio_tdo_en_o = flash_i.jtag_rsp.tdo_oe; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 790 | assign flash_rd_err = flash_i.rd_err; |
| 791 | assign flash_rd_data = flash_i.rd_data; |
| 792 | assign flash_phy_busy = flash_i.init_busy; |
| 793 | |
Timothy Chen | d8fded8 | 2021-02-22 11:32:55 -0800 | [diff] [blame] | 794 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 795 | // Interface to pwrmgr |
| 796 | // flash is not idle as long as there is a stateful operation ongoing |
| 797 | logic flash_idle_d; |
| 798 | assign flash_idle_d = ~(flash_o.req & |
| 799 | (flash_o.prog | flash_o.pg_erase | flash_o.bk_erase)); |
| 800 | |
| 801 | prim_flop #( |
| 802 | .Width(1), |
| 803 | .ResetValue(1'b1) |
| 804 | ) u_reg_idle ( |
| 805 | .clk_i, |
| 806 | .rst_ni, |
| 807 | .d_i(flash_idle_d), |
| 808 | .q_o(pwrmgr_o.flash_idle) |
| 809 | ); |
| 810 | |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 811 | ////////////////////////////////////// |
| 812 | // Alert senders |
| 813 | ////////////////////////////////////// |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 814 | |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 815 | logic [NumAlerts-1:0] alert_srcs; |
| 816 | logic [NumAlerts-1:0] alert_tests; |
| 817 | |
Timothy Chen | 5302fff | 2021-01-22 14:36:54 -0800 | [diff] [blame] | 818 | logic recov_err; |
| 819 | assign recov_err = flash_i.flash_alert_p | ~flash_i.flash_alert_n; |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 820 | |
| 821 | logic recov_mp_err; |
| 822 | assign recov_mp_err = flash_mp_error; |
| 823 | |
| 824 | logic recov_ecc_err; |
| 825 | assign recov_ecc_err = |flash_i.ecc_single_err | |flash_i.ecc_multi_err; |
| 826 | |
| 827 | assign alert_srcs = { recov_ecc_err, |
| 828 | recov_mp_err, |
Timothy Chen | 5302fff | 2021-01-22 14:36:54 -0800 | [diff] [blame] | 829 | recov_err |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 830 | }; |
| 831 | |
| 832 | assign alert_tests = { reg2hw.alert_test.recov_ecc_err.q & reg2hw.alert_test.recov_ecc_err.qe, |
| 833 | reg2hw.alert_test.recov_mp_err.q & reg2hw.alert_test.recov_mp_err.qe, |
Timothy Chen | 5302fff | 2021-01-22 14:36:54 -0800 | [diff] [blame] | 834 | reg2hw.alert_test.recov_err.q & reg2hw.alert_test.recov_err.qe |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 835 | }; |
| 836 | |
| 837 | for (genvar i = 0; i < NumAlerts; i++) begin : gen_alert_senders |
| 838 | prim_alert_sender #( |
Rupert Swarbrick | 21d6e5b | 2021-03-18 09:07:35 +0000 | [diff] [blame] | 839 | .AsyncOn(AlertAsyncOn[i]) |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 840 | ) u_alert_sender ( |
| 841 | .clk_i, |
| 842 | .rst_ni, |
Timothy Chen | 06f7831 | 2021-01-20 18:43:27 -0800 | [diff] [blame] | 843 | .alert_req_i(alert_srcs[i]), |
| 844 | .alert_test_i(alert_tests[i]), |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 845 | .alert_ack_o(), |
Timothy Chen | 06f7831 | 2021-01-20 18:43:27 -0800 | [diff] [blame] | 846 | .alert_state_o(), |
Timothy Chen | 1674110 | 2021-01-15 17:32:13 -0800 | [diff] [blame] | 847 | .alert_rx_i(alert_rx_i[i]), |
| 848 | .alert_tx_o(alert_tx_o[i]) |
| 849 | ); |
| 850 | end |
| 851 | |
| 852 | |
| 853 | ////////////////////////////////////// |
| 854 | // Errors and Interrupts |
| 855 | ////////////////////////////////////// |
| 856 | |
| 857 | assign hw2reg.err_code.mp_err.d = 1'b1; |
| 858 | assign hw2reg.err_code.ecc_single_err.d = 1'b1; |
| 859 | assign hw2reg.err_code.ecc_multi_err.d = 1'b1; |
| 860 | assign hw2reg.err_code.flash_err.d = 1'b1; |
| 861 | assign hw2reg.err_code.flash_alert.d = 1'b1; |
| 862 | assign hw2reg.err_code.mp_err.de = flash_mp_error; |
| 863 | assign hw2reg.err_code.ecc_single_err.de = |flash_i.ecc_single_err; |
| 864 | assign hw2reg.err_code.ecc_multi_err.de = |flash_i.ecc_multi_err; |
| 865 | assign hw2reg.err_code.flash_err.de = flash_i.flash_err; |
| 866 | assign hw2reg.err_code.flash_alert.de = flash_i.flash_alert_p | ~flash_i.flash_alert_n; |
| 867 | assign hw2reg.err_addr.d = err_addr; |
| 868 | assign hw2reg.err_addr.de = flash_mp_error; |
| 869 | |
| 870 | for (genvar bank = 0; bank < NumBanks; bank++) begin : gen_err_cons |
| 871 | assign hw2reg.ecc_err_addr[bank].d = {flash_i.ecc_addr[bank], {BusByteWidth{1'b0}}}; |
| 872 | assign hw2reg.ecc_err_addr[bank].de = flash_i.ecc_single_err[bank] | |
| 873 | flash_i.ecc_multi_err[bank]; |
| 874 | end |
| 875 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 876 | // Generate edge triggered signals for sources that are level |
| 877 | logic [3:0] intr_src; |
| 878 | logic [3:0] intr_src_q; |
| 879 | logic [3:0] intr_assert; |
| 880 | |
| 881 | assign intr_src = { ~prog_fifo_rvalid, |
| 882 | reg2hw.fifo_lvl.prog.q == prog_fifo_depth, |
Timothy Chen | 71d98f8 | 2020-12-17 17:17:25 -0800 | [diff] [blame] | 883 | rd_fifo_full, |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 884 | reg2hw.fifo_lvl.rd.q == rd_fifo_depth |
| 885 | }; |
| 886 | |
| 887 | always_ff @(posedge clk_i or negedge rst_ni) begin |
| 888 | if (!rst_ni) begin |
| 889 | intr_src_q <= 4'h8; //prog_fifo is empty by default |
| 890 | end else if (sw_sel) begin |
| 891 | intr_src_q <= intr_src; |
| 892 | end |
| 893 | end |
| 894 | |
| 895 | assign intr_assert = ~intr_src_q & intr_src; |
| 896 | |
| 897 | |
| 898 | assign intr_prog_empty_o = reg2hw.intr_enable.prog_empty.q & reg2hw.intr_state.prog_empty.q; |
| 899 | assign intr_prog_lvl_o = reg2hw.intr_enable.prog_lvl.q & reg2hw.intr_state.prog_lvl.q; |
| 900 | assign intr_rd_full_o = reg2hw.intr_enable.rd_full.q & reg2hw.intr_state.rd_full.q; |
| 901 | assign intr_rd_lvl_o = reg2hw.intr_enable.rd_lvl.q & reg2hw.intr_state.rd_lvl.q; |
| 902 | assign intr_op_done_o = reg2hw.intr_enable.op_done.q & reg2hw.intr_state.op_done.q; |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 903 | |
| 904 | assign hw2reg.intr_state.prog_empty.d = 1'b1; |
| 905 | assign hw2reg.intr_state.prog_empty.de = intr_assert[3] | |
| 906 | (reg2hw.intr_test.prog_empty.qe & |
| 907 | reg2hw.intr_test.prog_empty.q); |
| 908 | |
| 909 | assign hw2reg.intr_state.prog_lvl.d = 1'b1; |
| 910 | assign hw2reg.intr_state.prog_lvl.de = intr_assert[2] | |
| 911 | (reg2hw.intr_test.prog_lvl.qe & |
| 912 | reg2hw.intr_test.prog_lvl.q); |
| 913 | |
| 914 | assign hw2reg.intr_state.rd_full.d = 1'b1; |
| 915 | assign hw2reg.intr_state.rd_full.de = intr_assert[1] | |
| 916 | (reg2hw.intr_test.rd_full.qe & |
| 917 | reg2hw.intr_test.rd_full.q); |
| 918 | |
| 919 | assign hw2reg.intr_state.rd_lvl.d = 1'b1; |
| 920 | assign hw2reg.intr_state.rd_lvl.de = intr_assert[0] | |
| 921 | (reg2hw.intr_test.rd_lvl.qe & |
| 922 | reg2hw.intr_test.rd_lvl.q); |
| 923 | |
| 924 | |
| 925 | assign hw2reg.intr_state.op_done.d = 1'b1; |
| 926 | assign hw2reg.intr_state.op_done.de = sw_ctrl_done | |
| 927 | (reg2hw.intr_test.op_done.qe & |
| 928 | reg2hw.intr_test.op_done.q); |
| 929 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 930 | |
| 931 | // Unused bits |
| 932 | logic [BusByteWidth-1:0] unused_byte_sel; |
| 933 | logic [top_pkg::TL_AW-1-BusAddrW:0] unused_higher_addr_bits; |
| 934 | logic [top_pkg::TL_AW-1:0] unused_scratch; |
| 935 | |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 936 | // Unused signals |
| 937 | assign unused_byte_sel = muxed_addr[BusByteWidth-1:0]; |
| 938 | assign unused_higher_addr_bits = muxed_addr[top_pkg::TL_AW-1:BusAddrW]; |
| 939 | assign unused_scratch = reg2hw.scratch; |
| 940 | |
| 941 | |
| 942 | // Assertions |
Timothy Chen | 8adb20d | 2021-03-25 16:49:04 -0700 | [diff] [blame^] | 943 | `ASSERT_KNOWN(TlDValidKnownO_A, core_tl_o.d_valid ) |
| 944 | `ASSERT_KNOWN(TlAReadyKnownO_A, core_tl_o.a_ready ) |
| 945 | `ASSERT_KNOWN(PrimTlDValidKnownO_A, prim_tl_o.d_valid ) |
| 946 | `ASSERT_KNOWN(PrimTlAReadyKnownO_A, prim_tl_o.a_ready ) |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 947 | `ASSERT_KNOWN(FlashKnownO_A, {flash_o.req, flash_o.rd, flash_o.prog, flash_o.pg_erase, |
| 948 | flash_o.bk_erase}) |
| 949 | `ASSERT_KNOWN_IF(FlashAddrKnown_A, flash_o.addr, flash_o.req) |
| 950 | `ASSERT_KNOWN_IF(FlashProgKnown_A, flash_o.prog_data, flash_o.prog & flash_o.req) |
| 951 | `ASSERT_KNOWN(IntrProgEmptyKnownO_A, intr_prog_empty_o) |
| 952 | `ASSERT_KNOWN(IntrProgLvlKnownO_A, intr_prog_lvl_o ) |
| 953 | `ASSERT_KNOWN(IntrProgRdFullKnownO_A, intr_rd_full_o ) |
| 954 | `ASSERT_KNOWN(IntrRdLvlKnownO_A, intr_rd_lvl_o ) |
| 955 | `ASSERT_KNOWN(IntrOpDoneKnownO_A, intr_op_done_o ) |
Timothy Chen | ff4a770 | 2020-10-27 15:08:53 -0700 | [diff] [blame] | 956 | |
| 957 | endmodule |