Skip to content

Commit

Permalink
[dma,dv] Top-level test for DMA
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Schilling <[email protected]>
  • Loading branch information
Razer6 committed Jan 16, 2024
1 parent d4cadf5 commit 52c6ef7
Show file tree
Hide file tree
Showing 16 changed files with 630 additions and 12 deletions.
39 changes: 39 additions & 0 deletions hw/dv/sv/spi_agent/seq_lib/spi_device_dma_seq.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

// --------------------
// Device sequence
// --------------------
class spi_device_dma_seq extends spi_base_seq;

`uvm_object_utils(spi_device_dma_seq)

spi_item data;

typedef bit[7:0] data_t[];

function new(string name="");
super.new(name);
data = spi_item::type_id::create("data");
data = new();
`DV_CHECK_RANDOMIZE_WITH_FATAL(data,
item_type == SpiTransNormal;
// Size must be in sync with test dma_inline_hashing.c
data.size() == 512;
)
endfunction : new

function data_t get_data();
return data.data;
endfunction : get_data

virtual task body();
forever begin
start_item(data);
finish_item(data);
get_response(data);
end
endtask : body

endclass : spi_device_dma_seq
1 change: 1 addition & 0 deletions hw/dv/sv/spi_agent/seq_lib/spi_seq_list.sv
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
`include "spi_host_dummy_seq.sv"
`include "spi_device_seq.sv"
`include "spi_device_cmd_rsp_seq.sv"
`include "spi_device_dma_seq.sv"
1 change: 1 addition & 0 deletions hw/dv/sv/spi_agent/spi_agent.core
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ filesets:
- seq_lib/spi_device_flash_seq.sv: {is_include_file: true}
- seq_lib/spi_device_seq.sv: {is_include_file: true}
- seq_lib/spi_device_cmd_rsp_seq.sv: {is_include_file: true}
- seq_lib/spi_device_dma_seq.sv: {is_include_file: true}
file_type: systemVerilogSource

targets:
Expand Down
7 changes: 7 additions & 0 deletions hw/top_darjeeling/dv/chip_sim_cfg.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,13 @@
]
run_timeout_mins: 300
}
{
name: chip_sw_dma_inline_hashing
uvm_test_seq: chip_sw_dma_spi_hw_handshake_vseq
sw_images: ["//sw/device/tests:dma_inline_hashing:6"]
en_run_modes: ["sw_test_mode_test_rom"]
run_opts: ["+sw_test_timeout_ns=22_000_000"]
}
]

// List of regressions.
Expand Down
2 changes: 2 additions & 0 deletions hw/top_darjeeling/dv/env/chip_env.core
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ filesets:
- lowrisc:ip:kmac_pkg
- lowrisc:ip:aes
- lowrisc:dv:cip_lib
- lowrisc:dv:cryptoc_dpi:0.1
- lowrisc:dv:digestpp_dpi
- lowrisc:dv:aes_model_dpi
- lowrisc:ip:jtag_pkg
Expand Down Expand Up @@ -125,6 +126,7 @@ filesets:
- seq_lib/chip_sw_rom_e2e_jtag_inject_vseq.sv: {is_include_file: true}
- seq_lib/chip_sw_power_virus_vseq.sv: {is_include_file: true}
- seq_lib/chip_sw_ast_clk_rst_inputs_vseq.sv: {is_include_file: true}
- seq_lib/chip_sw_dma_spi_hw_handshake_vseq.sv: {is_include_file: true}
- autogen/chip_env_pkg__params.sv: {is_include_file: true}
- alerts_if.sv
- ast_ext_clk_if.sv
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

class chip_sw_dma_spi_hw_handshake_vseq extends chip_sw_base_vseq;
`uvm_object_utils(chip_sw_dma_spi_hw_handshake_vseq)

`uvm_object_new

task pre_start();
// Setting the byte order to 0 ensures that the 4 byte transaction sent to
// the agent from the DUT is played back in exactly the same order, thus
// making things easy to compare.
cfg.m_spi_device_agent_cfgs[0].byte_order = '0;
super.pre_start();
endtask

virtual task cpu_init();
super.cpu_init();
endtask

virtual task body();
spi_device_dma_seq m_device_dma_seq;
bit [31:0] exp_digest[16];
bit[7:0] sha_mode_arr[1];

spi_device_dma_seq::data_t msg;

super.body();
`uvm_info(`gfn, "Testing with spi host 0", UVM_LOW)

// enable spi agent
cfg.chip_vif.enable_spi_device(.inst_num(0), .enable(1));

// Wait for the sw to finish configuring the spi_host DUT
`DV_WAIT(cfg.sw_logger_vif.printed_log == "spi host configuration complete",
"Timedout waiting for spi host c configuration.")

// create and start the spi_device sequence
m_device_dma_seq = spi_device_dma_seq::type_id::create("m_device_dma_seq");
msg = m_device_dma_seq.get_data();

// Randomize the SHA mode and compute the expected hash of the source data
unique case($urandom_range(0, 2))
0: begin
cryptoc_dpi_pkg::sv_dpi_get_sha256_digest(msg, exp_digest[0:7]);
sha_mode_arr = {dma_pkg::OpcSha256};
end
1: begin
cryptoc_dpi_pkg::sv_dpi_get_sha384_digest(msg, exp_digest[0:11]);
sha_mode_arr = {dma_pkg::OpcSha384};
end
2: begin
cryptoc_dpi_pkg::sv_dpi_get_sha512_digest(msg, exp_digest[0:15]);
sha_mode_arr = {dma_pkg::OpcSha512};
end
default: begin
`dv_fatal("Invalid SHA mode.")
end
endcase

// By default, the hardware outputs little-endian data for each digest (32 bits). But DPI
// functions expect output to be big-endian.
for (int i = 0; i < 16; ++i) begin
exp_digest[i] = {<<8{exp_digest[i]}};
end

// Backdoor the software with the SHA mode and the expected digest
sw_symbol_backdoor_overwrite("kShaMode", sha_mode_arr);
sw_symbol_backdoor_overwrite("kShaDigestExpData", {<<8{{<<32{exp_digest}}}});

fork m_device_dma_seq.start(p_sequencer.spi_device_sequencer_hs[0]); join_none
endtask
endclass : chip_sw_dma_spi_hw_handshake_vseq
1 change: 1 addition & 0 deletions hw/top_darjeeling/dv/env/seq_lib/chip_vseq_list.sv
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@
`include "chip_sw_rom_e2e_jtag_inject_vseq.sv"
`include "chip_sw_ast_clk_rst_inputs_vseq.sv"
`include "chip_sw_power_virus_vseq.sv"
`include "chip_sw_dma_spi_hw_handshake_vseq.sv"
20 changes: 20 additions & 0 deletions sw/device/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,26 @@ opentitan_functest(
],
)

opentitan_functest(
name = "dma_inline_hashing",
srcs = ["dma_inline_hashing.c"],
targets = [
"dv",
],
deps = [
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/lib/sw/device/base:macros",
"//sw/lib/sw/device/base:mmio",
"//sw/lib/sw/device/runtime:log",
"//sw/top_darjeeling/sw/device/runtime:print",
"//sw/top_darjeeling/sw/dif:dma",
"//sw/top_darjeeling/sw/dif:spi_host",
"//sw/top_darjeeling/sw/test/utils:dma_testutils",
"//sw/top_darjeeling/sw/test/utils:isr_testutils",
"//sw/top_darjeeling/sw/test/utils:pinmux_testutils",
],
)

opentitan_functest(
name = "entropy_src_csrng_test",
srcs = ["entropy_src_csrng_test.c"],
Expand Down
Loading

0 comments on commit 52c6ef7

Please sign in to comment.