Skip to content

Commit

Permalink
UVM: Add support for (randomly) running an early mailbox command
Browse files Browse the repository at this point in the history
  • Loading branch information
calebofearth committed Feb 6, 2024
1 parent bbc9a32 commit 6049a09
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/integration/test_suites/caliptra_top/caliptra_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void main() {
// Clear SHA accelerator lock (FIPS requirement)
soc_ifc_w1clr_sha_lock_field(SHA512_ACC_CSR_LOCK_LOCK_MASK);

VPRINTF(LOW, "Waiting for FMC FW to be loaded\n");
// Wait for FW available (FMC)
VPRINTF(LOW, "Waiting for first mailbox command\n");
// Wait for mailbox command available (FMC, or an early stash-measurement-like command)
do {
intr_sts = lsu_read_32(CLP_SOC_IFC_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R);
intr_sts &= SOC_IFC_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_AVAIL_STS_MASK;
Expand All @@ -98,10 +98,37 @@ void main() {

op = soc_ifc_read_mbox_cmd();
if (op.cmd != MBOX_CMD_FMC_UPDATE) {
VPRINTF(FATAL, "Received invalid mailbox command from SOC! Expected 0x%x, got 0x%x\n", MBOX_CMD_FMC_UPDATE, op.cmd);
SEND_STDOUT_CTRL(0x1);
while(1);
// Handling for early mailbox command
uint32_t read_data;
if ((op.cmd & MBOX_CMD_FIELD_RESP_MASK) || (op.cmd & MBOX_CMD_FIELD_FW_MASK)) {
VPRINTF(FATAL, "Got inv mailbox command from SOC! RESP_REQ: %d FIELD_FW: %d\n", op.cmd & MBOX_CMD_FIELD_RESP_MASK, op.cmd & MBOX_CMD_FIELD_FW_MASK);
SEND_STDOUT_CTRL(0x1);
while(1);
}
VPRINTF(MEDIUM, "Got cmd (0x%x) with DLEN 0x%x\n", op.cmd, op.dlen);

// Read provided data
for (uint32_t loop_iter = 0; loop_iter<op.dlen; loop_iter+=4) {
read_data = soc_ifc_mbox_read_dataout_single();
}

// Set final status
soc_ifc_set_mbox_status_field(CMD_COMPLETE);

// Now we wait for FW
VPRINTF(LOW, "Waiting for firmware mailbox command\n");

// Wait for mailbox command available (FMC)
do {
intr_sts = lsu_read_32(CLP_SOC_IFC_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R);
intr_sts &= SOC_IFC_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_AVAIL_STS_MASK;
} while (!intr_sts);
//clear the interrupt
lsu_write_32(CLP_SOC_IFC_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R, SOC_IFC_REG_INTR_BLOCK_RF_NOTIF_INTERNAL_INTR_R_NOTIF_CMD_AVAIL_STS_MASK);

op = soc_ifc_read_mbox_cmd();
}

//TODO: Enhancement - Check the integrity of the firmware

// Load FMC from mailbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class caliptra_top_rand_sequence extends caliptra_top_bench_sequence_base;

rand soc_ifc_env_bringup_sequence_t soc_ifc_env_bringup_seq;
rand soc_ifc_env_pauser_init_sequence_t soc_ifc_env_pauser_init_seq;
rand soc_ifc_env_mbox_rand_small_sequence_t soc_ifc_env_early_mbox_seq;
rand soc_ifc_env_mbox_real_fw_sequence_t soc_ifc_env_mbox_fmc_seq;
rand soc_ifc_env_mbox_real_fw_sequence_t soc_ifc_env_mbox_rt_seq;
rand soc_ifc_env_sequence_base_t soc_ifc_env_seq_ii[];
Expand Down Expand Up @@ -84,6 +85,7 @@ class caliptra_top_rand_sequence extends caliptra_top_bench_sequence_base;
} rand_seq_idx;

rand int iteration_count;
rand bit do_early_mbox_seq;
int sts_rsp_count = 0;

// Choose rand weights for each sequence to determine run frequency
Expand Down Expand Up @@ -172,6 +174,18 @@ class caliptra_top_rand_sequence extends caliptra_top_bench_sequence_base;
else
`uvm_info("CALIPTRA_TOP_RAND_TEST", $sformatf("Did not receive Command Line Iteration Count Argument with +CALIPTRA_TOP_RAND_ITER, defaulting to %0d", iteration_count), UVM_LOW);
end
// Users can manually override whether or not the early mailbox sequence is run prior to firmware load
if ($test$plusargs("CALIPTRA_TOP_EARLY_MB_SEQ")) begin
`uvm_info("CALIPTRA_TOP_RAND_TEST", $sformatf("Received command line argument specifying to run the early mailbox sequence before firmware initialization"), UVM_LOW);
do_early_mbox_seq = 1;
do_early_mbox_seq.rand_mode(0);
end
else begin
if (!this.randomize(do_early_mbox_seq))
`uvm_fatal("CALIPTRA_TOP_RAND_TEST", "Failed to randomize do_early_mbox_seq after receiving no command line override")
else
`uvm_info("CALIPTRA_TOP_RAND_TEST", $sformatf("Did not receive Command Line Argument for early mailbox sequence with +CALIPTRA_TOP_EARLY_MB_SEQ, defaulting to %0d", do_early_mbox_seq), UVM_LOW);
end
soc_ifc_env_seq_ii = new[iteration_count];
endfunction

Expand Down Expand Up @@ -214,6 +228,7 @@ class caliptra_top_rand_sequence extends caliptra_top_bench_sequence_base;
caliptra_top_env_seq = caliptra_top_env_sequence_base_t::type_id::create("caliptra_top_env_seq");
soc_ifc_env_bringup_seq = soc_ifc_env_bringup_sequence_t::type_id::create("soc_ifc_env_bringup_seq");
soc_ifc_env_pauser_init_seq = soc_ifc_env_pauser_init_sequence_t::type_id::create("soc_ifc_env_pauser_init_seq");
soc_ifc_env_early_mbox_seq = soc_ifc_env_mbox_rand_small_sequence_t::type_id::create("soc_ifc_env_early_mbox_seq");
soc_ifc_env_mbox_fmc_seq = soc_ifc_env_mbox_real_fw_sequence_t::type_id::create("soc_ifc_env_mbox_fmc_seq");
soc_ifc_env_mbox_rt_seq = soc_ifc_env_mbox_real_fw_sequence_t::type_id::create("soc_ifc_env_mbox_rt_seq");

Expand All @@ -224,6 +239,7 @@ class caliptra_top_rand_sequence extends caliptra_top_bench_sequence_base;
// Handle to the responder sequence for getting response transactions
soc_ifc_env_bringup_seq.soc_ifc_status_agent_rsp_seq = soc_ifc_subenv_soc_ifc_status_agent_responder_seq;
soc_ifc_env_pauser_init_seq.soc_ifc_status_agent_rsp_seq = soc_ifc_subenv_soc_ifc_status_agent_responder_seq;
soc_ifc_env_early_mbox_seq.soc_ifc_status_agent_rsp_seq = soc_ifc_subenv_soc_ifc_status_agent_responder_seq;
soc_ifc_env_mbox_fmc_seq.soc_ifc_status_agent_rsp_seq = soc_ifc_subenv_soc_ifc_status_agent_responder_seq;
soc_ifc_env_mbox_rt_seq.soc_ifc_status_agent_rsp_seq = soc_ifc_subenv_soc_ifc_status_agent_responder_seq;

Expand Down Expand Up @@ -268,6 +284,13 @@ class caliptra_top_rand_sequence extends caliptra_top_bench_sequence_base;

`uvm_info("CALIPTRA_TOP_BRINGUP", "SoC completed poweron and observed reset deassertion to system", UVM_LOW)

if (do_early_mbox_seq) begin
if (!soc_ifc_env_early_mbox_seq.randomize() with { mbox_op_rand.dlen <= 32'h0000_0020; !mbox_op_rand.cmd.cmd_s.resp_reqd; })
`uvm_fatal("CALIPTRA_TOP_RAND_TEST", "caliptra_top_rand_sequence::body() - soc_ifc_env_early_mbox_seq randomization failed")
`uvm_info("CALIPTRA_TOP_RAND_TEST", "Running early mailbox sequence", UVM_MEDIUM)
soc_ifc_env_early_mbox_seq.start(top_configuration.soc_ifc_subenv_config.vsqr);
end

run_firmware_init(soc_ifc_env_mbox_fmc_seq,soc_ifc_env_mbox_rt_seq);

// In this loop, randomly select a sequence to run (from the list of available
Expand Down

0 comments on commit 6049a09

Please sign in to comment.