Skip to content

Commit 14b6897

Browse files
committed
[keymgr_dpe, rtl, dv] Support multiple top configurations
This commit allows for a limited parametrization by the top without having a fully templated IP. The top can define the following: - Number of bootstages (either two or three) - Number of ROM digest values - Number of HW slots instanciated (up to 8 slots) The block level dv is extended to test two different configurations, called earlgrey and darjeeling. Signed-off-by: Raphael Roth <rroth@lowrisc.org>
1 parent d06e0d2 commit 14b6897

20 files changed

Lines changed: 444 additions & 122 deletions

hw/ip/keymgr_dpe/data/keymgr_dpe.hjson

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,33 @@
228228
default: "1",
229229
local: "true"
230230
},
231+
{ name: "NumMaxHwSlot",
232+
desc: '''
233+
Number of maximum supported HW slots. If this value is changed then the
234+
bit width in SLOT_SRC_SEL / SLOT_DST_SEL in the
235+
"CONTROL_SHADOWED" register needs to be updated too.
236+
''',
237+
type: "int",
238+
default: "8",
239+
local: "true"
240+
},
241+
{ name: "NumInstHwSlot",
242+
desc: "Number of instantiated HW slots",
243+
type: "int",
244+
default: "4",
245+
expose: "true"
246+
},
247+
{ name: "NumBootStages",
248+
desc: "Number of available boot stage",
249+
type: "int",
250+
default: "3",
251+
expose: "true"
252+
},
231253
{ name: "NumRomDigestInputs",
232254
desc: "Number of digest inputs from ROM_CTRL",
233255
type: "int",
234-
default: "2",
235-
local: "true"
256+
default: "1",
257+
expose: "true"
236258
},
237259
],
238260

hw/ip/keymgr_dpe/dv/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Here's how to run a smoke test:
102102
```console
103103
$ dvsim $REPO_TOP/hw/ip/keymgr_dpe/dv/keymgr_dpe_sim_cfg.hjson -i keymgr_dpe_smoke
104104
```
105+
With the configurations `keymgr_dpe_earlgrey_sim_cfg.hjson` / `keymgr_dpe_darjeeling_sim_cfg.hjson` it is possible to test the top dependent default configurations.
105106

106107
## Testplan
107108
[Testplan](../data/keymgr_dpe_testplan.hjson)

hw/ip/keymgr_dpe/dv/env/keymgr_dpe_ctrl_if.sv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ interface keymgr_dpe_ctrl_if (input clk_i, input rst_ni);
1010
// Function to access the key of one slot via backdoor.
1111
// Required to load the UDS after XORing with generated randomness.
1212
function automatic keymgr_dpe_env_pkg::key_shares_t get_key_of_slot(int unsigned slot);
13-
import keymgr_dpe_pkg::DpeNumSlots;
13+
import keymgr_dpe_env_pkg::DvNumInstHwSlot;
1414

15-
// Check that the slot index is in range. The key_slots_q array has length DpeNumSlots, which is
16-
// a global parameter.
17-
if (slot >= DpeNumSlots) begin
15+
// Check that the slot index is in range. The key_slots_q array has length DvNumInstHwSlot,
16+
// which is a global parameter.
17+
if (slot >= DvNumInstHwSlot) begin
1818
`uvm_error($sformatf("%m"),
19-
$sformatf("Slot index out of range: index is %0d but DpeNumSlots is %0d",
20-
slot, DpeNumSlots))
19+
$sformatf("Slot index out of range: index is %0d but DvNumInstHwSlot is %0d",
20+
slot, DvNumInstHwSlot))
2121
return '0;
2222
end
2323

hw/ip/keymgr_dpe/dv/env/keymgr_dpe_env_pkg.sv

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ package keymgr_dpe_env_pkg;
2020
`include "uvm_macros.svh"
2121
`include "dv_macros.svh"
2222

23+
// Define default values for all blocklevel dv parameter
24+
`ifndef DEF_DV_BOOT_STAGES
25+
`define DEF_DV_BOOT_STAGES 3
26+
`endif
27+
`ifndef DEF_DV_DPE_NUM_SLOT
28+
`define DEF_DV_DPE_NUM_SLOT 4
29+
`endif
30+
`ifndef DEF_DV_NUM_ROM_DIGEST
31+
`define DEF_DV_NUM_ROM_DIGEST 1
32+
`endif
33+
34+
// Avoid using defines throughout the DV code by introducing the following
35+
// parameters.
36+
parameter int DvBootStages = `DEF_DV_BOOT_STAGES;
37+
parameter int DvNumInstHwSlot = `DEF_DV_DPE_NUM_SLOT;
38+
parameter int DvNumRomDigestInputs = `DEF_DV_NUM_ROM_DIGEST;
39+
40+
// Advance width calculation
41+
// When deriving from the UDS the following data are consumed (Not ordered):
42+
// - Software binding
43+
// - Revision seed
44+
// - OTP device ID
45+
// - LC keymgr diversification value
46+
// - ROM digests
47+
// - Creator seed (only if boot stage equals two)
48+
parameter int DvDpeAdvDataWidth = keymgr_pkg::SwBindingWidth +
49+
keymgr_pkg::KeyWidth + keymgr_pkg::KeyWidth * (DvBootStages == 2) +
50+
lc_ctrl_pkg::LcKeymgrDivWidth + keymgr_dpe_pkg::DeviceIdWidth +
51+
keymgr_pkg::KeyWidth * DvNumRomDigestInputs;
52+
53+
localparam int DvNumInstHwSlotWidth = prim_util_pkg::vbits(DvNumInstHwSlot);
54+
typedef logic [DvNumInstHwSlotWidth-1:0] dv_keymgr_dpe_slot_idx_e;
55+
2356
// parameters and types
2457
parameter uint NUM_ALERTS = 2;
2558
parameter string LIST_OF_ALERTS[NUM_ALERTS] = {"recov_operation_err", "fatal_fault_err"};
@@ -64,8 +97,8 @@ package keymgr_dpe_env_pkg;
6497
} keymgr_dpe_fault_inject_type_e;
6598

6699
typedef struct{
67-
keymgr_dpe_pkg::keymgr_dpe_slot_idx_e src_slot;
68-
keymgr_dpe_pkg::keymgr_dpe_slot_idx_e dst_slot;
100+
dv_keymgr_dpe_slot_idx_e src_slot;
101+
dv_keymgr_dpe_slot_idx_e dst_slot;
69102
} keymgr_dpe_key_slot_t;
70103

71104
string msg_id = "keymgr_dpe_env_pkg";

hw/ip/keymgr_dpe/dv/env/keymgr_dpe_if.sv

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ interface keymgr_dpe_if(input clk, input rst_n);
77

88
import uvm_pkg::*;
99
import keymgr_dpe_env_pkg::*;
10-
import keymgr_dpe_reg_pkg::NumRomDigestInputs;
1110

1211
// Represents the keymgr_dpe sideload state for each sideload interface.
1312
//
@@ -16,13 +15,13 @@ interface keymgr_dpe_if(input clk, input rst_n);
1615
// Status can't be directly changed from SideLoadClear to SideLoadAvail.
1716
// When status is SideLoadClear due to SIDELOAD_CLEAR programmed, need to write CSR to 0 to reset
1817
// it so that status is changed to SideLoadNotAvail, then we may set it to SideLoadAvail again
19-
lc_ctrl_pkg::lc_tx_t keymgr_dpe_en;
20-
lc_ctrl_pkg::lc_keymgr_div_t keymgr_dpe_div;
21-
keymgr_dpe_pkg::keymgr_dpe_device_id_t otp_device_id;
22-
keymgr_dpe_pkg::keymgr_dpe_creator_root_key_t creator_root_key;
23-
keymgr_dpe_pkg::keymgr_dpe_creator_seed_t creator_seed;
24-
keymgr_dpe_pkg::keymgr_dpe_owner_seed_t owner_seed;
25-
rom_ctrl_pkg::keymgr_data_t[NumRomDigestInputs-1:0] rom_digests;
18+
lc_ctrl_pkg::lc_tx_t keymgr_dpe_en;
19+
lc_ctrl_pkg::lc_keymgr_div_t keymgr_dpe_div;
20+
keymgr_dpe_pkg::keymgr_dpe_device_id_t otp_device_id;
21+
keymgr_dpe_pkg::keymgr_dpe_creator_root_key_t creator_root_key;
22+
keymgr_dpe_pkg::keymgr_dpe_creator_seed_t creator_seed;
23+
keymgr_dpe_pkg::keymgr_dpe_owner_seed_t owner_seed;
24+
rom_ctrl_pkg::keymgr_data_t[DvNumRomDigestInputs-1:0] rom_digests;
2625

2726
keymgr_pkg::hw_key_req_t kmac_key;
2827
keymgr_pkg::hw_key_req_t aes_key;
@@ -103,7 +102,7 @@ interface keymgr_dpe_if(input clk, input rst_n);
103102

104103
// assigned from the keymgr_dpe.keymgr_dpe_ctrl.key_slots_q signal, which should hold the
105104
// current value of the keyslots in the dut.
106-
keymgr_dpe_pkg::keymgr_dpe_slot_t [keymgr_dpe_pkg::DpeNumSlots-1:0] internal_key_slots;
105+
keymgr_dpe_pkg::keymgr_dpe_slot_t [DvNumInstHwSlot-1:0] internal_key_slots;
107106

108107
task automatic init(bit rand_otp_key, bit invalid_otp_key);
109108
// Keymgr_dpe only latches OTP key once, so this scb does not support change OTP key on the
@@ -115,7 +114,7 @@ interface keymgr_dpe_if(input clk, input rst_n);
115114
keymgr_dpe_en = lc_ctrl_pkg::On;
116115
keymgr_dpe_div = 64'h5CFBD765CE33F34E;
117116
otp_device_id = 'hF0F0;
118-
for (int i = 0; i < NumRomDigestInputs; ++i) begin
117+
for (int i = 0; i < DvNumRomDigestInputs; ++i) begin
119118
rom_digests[i].data = 256'hA20A046CF42E6EAC560A3F82BFA76285B5C1D4AEA7C915E49A32D1C89BE0F507;
120119
rom_digests[i].valid = '1;
121120
end
@@ -193,14 +192,14 @@ interface keymgr_dpe_if(input clk, input rst_n);
193192
// as a set of flags / counters.
194193
bit bad_keymgr_dpe_div = 1'b0;
195194
bit bad_otp_device_id = 1'b0;
196-
bit [NumRomDigestInputs-1:0] bad_rom_data = '0, bad_rom_valid = '0;
195+
bit [DvNumRomDigestInputs-1:0] bad_rom_data = '0, bad_rom_valid = '0;
197196

198197
repeat (num_invalid_input) begin
199198
randcase
200199
1: bad_keymgr_dpe_div = 1'b1;
201200
1: bad_otp_device_id = 1'b1;
202-
1: bad_rom_data[$urandom % NumRomDigestInputs] = 1'b1;
203-
1: bad_rom_valid[$urandom % NumRomDigestInputs] = 1'b1;
201+
1: bad_rom_data[$urandom % DvNumRomDigestInputs] = 1'b1;
202+
1: bad_rom_valid[$urandom % DvNumRomDigestInputs] = 1'b1;
204203
endcase
205204
end
206205

@@ -221,7 +220,7 @@ interface keymgr_dpe_if(input clk, input rst_n);
221220

222221
// rom_digests
223222
begin
224-
for (int i = 0; i < NumRomDigestInputs; i++)
223+
for (int i = 0; i < DvNumRomDigestInputs; i++)
225224
fork
226225
automatic int local_i = i;
227226
#($urandom_range(1000, 0) * 1ns);
@@ -239,8 +238,8 @@ interface keymgr_dpe_if(input clk, input rst_n);
239238
function automatic void compare_internal_key_slot(
240239
keymgr_dpe_pkg::keymgr_dpe_slot_t dst_key_slot,
241240
keymgr_dpe_pkg::keymgr_dpe_slot_t src_key_slot,
242-
keymgr_dpe_pkg::keymgr_dpe_slot_idx_e dst_slot_index,
243-
keymgr_dpe_pkg::keymgr_dpe_slot_idx_e src_slot_index,
241+
dv_keymgr_dpe_slot_idx_e dst_slot_index,
242+
dv_keymgr_dpe_slot_idx_e src_slot_index,
244243
bit check_parent_retained
245244
);
246245
`DV_CHECK_EQ(dst_key_slot, internal_key_slots[dst_slot_index],

0 commit comments

Comments
 (0)