Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion hw/vendor/lowrisc_ip.vendor.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

upstream: {
url: "https://github.com/lowRISC/opentitan"
rev: "master"
// Pinned to the lock revision so the description alone is reproducible.
rev: "012fb0fe3042a2ab97f9fa045520286486a4b98f"
}

mapping: [
Expand All @@ -25,6 +26,37 @@
{from: "hw/check_tool_requirements.py", to: "check_tool_requirements.py"},
{from: "hw/tool_requirements.py", to: "tool_requirements.py", patch_dir: "scripts"},

// DV libraries for the UVM bench (hw/ip/uart16550/dv), with their dependencies
{from: "hw/dv/sv/alert_agent", to: "dv/sv/alert_agent"},
{from: "hw/dv/sv/bus_params_pkg", to: "dv/sv/bus_params_pkg"},
{from: "hw/dv/sv/common_ifs", to: "dv/sv/common_ifs"},
{from: "hw/dv/sv/csr_utils", to: "dv/sv/csr_utils"},
{from: "hw/dv/sv/dv_base_agent", to: "dv/sv/dv_base_agent"},
{from: "hw/dv/sv/dv_base_reg", to: "dv/sv/dv_base_reg"},
{from: "hw/dv/sv/dv_lib", to: "dv/sv/dv_lib"},
{from: "hw/dv/sv/dv_utils", to: "dv/sv/dv_utils"},
{from: "hw/dv/sv/mem_model", to: "dv/sv/mem_model"},
{from: "hw/dv/sv/str_utils", to: "dv/sv/str_utils"},
{from: "hw/dv/sv/tl_agent", to: "dv/sv/tl_agent"},
{from: "hw/dv/sv/uart_agent", to: "dv/sv/uart_agent"},

// Only the DVSim/Xcelium files the smoke flow uses: the job makefile, configs imported
// by the project sim cfg, the run script with the Tcl it sources (waves for debug), and
// the coverage files referenced by xcelium.hjson and the project sim cfg.
{from: "hw/dv/tools/dvsim/sim.mk", to: "dv/tools/dvsim/sim.mk"},
{from: "hw/dv/tools/dvsim/common_modes.hjson", to: "dv/tools/dvsim/common_modes.hjson"},
{from: "hw/dv/tools/dvsim/fusesoc.hjson", to: "dv/tools/dvsim/fusesoc.hjson"},
{from: "hw/dv/tools/dvsim/xcelium.hjson", to: "dv/tools/dvsim/xcelium.hjson"},
{from: "hw/dv/tools/sim.tcl", to: "dv/tools/sim.tcl"},
{from: "hw/dv/tools/common.tcl", to: "dv/tools/common.tcl"},
{from: "hw/dv/tools/waves.tcl", to: "dv/tools/waves.tcl"},
{from: "hw/dv/tools/xcelium/cover.ccf", to: "dv/tools/xcelium/cover.ccf"},
{from: "hw/dv/tools/xcelium/common.ccf", to: "dv/tools/xcelium/common.ccf"},
{from: "hw/dv/tools/xcelium/unr.cfg", to: "dv/tools/xcelium/unr.cfg"},
{from: "hw/dv/tools/xcelium/common_cov_excl.tcl", to: "dv/tools/xcelium/common_cov_excl.tcl"},
{from: "hw/dv/tools/xcelium/cov_merge.tcl", to: "dv/tools/xcelium/cov_merge.tcl"},
{from: "hw/dv/tools/xcelium/cov_report.tcl", to: "dv/tools/xcelium/cov_report.tcl"},

// Commit linting scripts
{from: "util/lint_commits.py", to: "util/lint_commits.py"},
{from: "ci/scripts/lint-commits.sh", to: "ci/scripts/lint-commits.sh", patch_dir: "ci"},
Expand All @@ -38,5 +70,7 @@
"hw/ip/prim/util",
"hw/ip/tlul/generic_dv",
"hw/ip/uart/dv",
// Self-test bench of the TL agent
"hw/dv/sv/tl_agent/dv",
]
}
14 changes: 14 additions & 0 deletions hw/vendor/lowrisc_ip/dv/sv/alert_agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Alert agent

The alert agent extends from the `dv_lib` agent classes.

## Description

This agent implements the alert interface protocol.
For design documentation, please refer to [alert_handler spec](../../../top_earlgrey/ip_autogen/alert_handler/README.md).
The agent can be configured to behave as an alert sender (host mode) or receiver (device mode).

## Device Agent

For IPs that send out alerts, it is recommended to attach alert device agents to the block level testbench.
Please refer to [cip_lib documentation](../cip_lib/README.md) regarding instructions to configure alert device agent in DV testbenches.
37 changes: 37 additions & 0 deletions hw/vendor/lowrisc_ip/dv/sv/alert_agent/alert_agent.core
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CAPI=2:
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
name: "lowrisc:dv:alert_agent"
description: "A UVM agent that interacts with the alert interface"

filesets:
files_dv:
depend:
- lowrisc:prim:all:0.1
- lowrisc:dv:dv_lib
files:
- alert_if.sv
- alert_agent_pkg.sv
- alert_agent_cfg.sv: {is_include_file: true}
- alert_agent.sv: {is_include_file: true}
- alert_agent_cov.sv: {is_include_file: true}
- alert_base_driver.sv: {is_include_file: true}
- alert_sender_driver.sv: {is_include_file: true}
- alert_receiver_driver.sv: {is_include_file: true}
- alert_monitor.sv: {is_include_file: true}
- alert_seq_item.sv: {is_include_file: true}
- alert_sequencer.sv: {is_include_file: true}
- seq_lib/alert_receiver_base_seq.sv: {is_include_file: true}
- seq_lib/alert_receiver_alert_rsp_seq.sv: {is_include_file: true}
- seq_lib/alert_receiver_ping_seq.sv: {is_include_file: true}
- seq_lib/alert_receiver_seq.sv: {is_include_file: true}
- seq_lib/alert_sender_base_seq.sv: {is_include_file: true}
- seq_lib/alert_sender_ping_rsp_seq.sv: {is_include_file: true}
- seq_lib/alert_sender_seq.sv: {is_include_file: true}
file_type: systemVerilogSource

targets:
default:
filesets:
- files_dv
114 changes: 114 additions & 0 deletions hw/vendor/lowrisc_ip/dv/sv/alert_agent/alert_agent.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

// An agent that represents an alert interface.

class alert_agent extends dv_reactive_agent #(
.CFG_T (alert_agent_cfg),
.DRIVER_T (alert_base_driver),
.HOST_DRIVER_T (alert_sender_driver),
.DEVICE_DRIVER_T (alert_receiver_driver),
.SEQUENCER_T (alert_sequencer),
.MONITOR_T (alert_monitor),
.COV_T (alert_agent_cov)
);

`uvm_component_utils(alert_agent)

// An output port that reports alert items that have been seen.
uvm_analysis_port #(alert_seq_item) m_alert_port;

extern function new (string name, uvm_component parent);
extern function void build_phase(uvm_phase phase);
// Create automatic response (from monitor) to ping and alert requests.
extern function void connect_phase(uvm_phase phase);
extern virtual task run_phase(uvm_phase phase);

endclass : alert_agent

function alert_agent::new (string name, uvm_component parent);
super.new(name, parent);
endfunction : new

function void alert_agent::build_phase(uvm_phase phase);
alert_agent_cfg cfg;
if (!uvm_config_db#(CFG_T)::get(this, "", "cfg", cfg)) begin
`uvm_fatal(`gfn, $sformatf("failed to get %s from uvm_config_db", cfg.get_type_name()))
end

// The reactive agent upon which we build will have a request fifo iff the agent is active.
cfg.has_req_fifo = cfg.is_active;

super.build_phase(phase);

m_alert_port = new("m_alert_port", this);

void'($value$plusargs("bypass_alert_ready_to_end_check=%0b",
cfg.bypass_alert_ready_to_end_check));

// get alert_if handle
if (!uvm_config_db#(virtual alert_if)::get(this, "", "vif", cfg.vif)) begin
`uvm_fatal(`gfn, "failed to get alert_if handle from uvm_config_db")
end

// set variables to alert interface
cfg.vif.is_async = cfg.is_async;
cfg.vif.is_active = cfg.is_active;
cfg.vif.if_mode = cfg.if_mode;

// set async alert clock frequency
if (cfg.is_async) begin
cfg.vif.clk_rst_async_if.set_active(.drive_rst_n_val(0));
if (cfg.clk_freq_mhz > 0) begin
int min_freq_mhz = (cfg.clk_freq_mhz / 10) ? (cfg.clk_freq_mhz / 10) : 1;
cfg.vif.clk_rst_async_if.set_freq_mhz($urandom_range(min_freq_mhz, cfg.clk_freq_mhz * 10));
end else begin
cfg.vif.clk_rst_async_if.set_freq_mhz($urandom_range(10, 240));
end
end

// Configure the sequencer to take priorities into account. This allows alert responses to be
// scheduled over ping requests, which come from a sequence that is started with low priority.
if (sequencer != null) sequencer.set_arbitration(UVM_SEQ_ARB_STRICT_FIFO);
endfunction : build_phase

function void alert_agent::connect_phase(uvm_phase phase);
super.connect_phase(phase);
if (cfg.has_req_fifo) begin
monitor.req_analysis_port.connect(sequencer.req_analysis_fifo.analysis_export);
end

monitor.m_alert_port.connect(m_alert_port);
endfunction : connect_phase

task alert_agent::run_phase(uvm_phase phase);
super.run_phase(phase);
if (cfg.is_active && cfg.start_default_rsp_seq) begin
// For host mode, run alert ping auto-response sequence.
if (cfg.if_mode == dv_utils_pkg::Host) begin
alert_sender_ping_rsp_seq m_seq =
alert_sender_ping_rsp_seq::type_id::create("m_seq", this);
uvm_config_db#(uvm_object_wrapper)::set(null, {sequencer.get_full_name(), ".run_phase"},
"default_sequence", m_seq.get_type());
sequencer.start_phase_sequence(phase);
end else begin
alert_receiver_alert_rsp_seq response_seq;
alert_receiver_ping_seq ping_seq;

// For device mode, run an alert auto-response sequence, which will only have a sequence
// item when an alert is generated by the device.
response_seq = alert_receiver_alert_rsp_seq::type_id::create("response_seq", this);
uvm_config_db#(uvm_object_wrapper)::set(null, {sequencer.get_full_name(), ".run_phase"},
"default_sequence", response_seq.get_type());
sequencer.start_phase_sequence(phase);

// Also run an alert ping sequence, which will send back-to-back sequence items that wait a
// while and then request a ping (stopping immediately if a genuine alert has been raised).
// The priority is low so that the response sequence will take precedence.
ping_seq = alert_receiver_ping_seq::type_id::create("ping_seq", this);
`DV_CHECK_FATAL(ping_seq.randomize())
ping_seq.start(sequencer, .this_priority(1));
end
end
endtask
81 changes: 81 additions & 0 deletions hw/vendor/lowrisc_ip/dv/sv/alert_agent/alert_agent_cfg.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

class alert_agent_cfg extends dv_reactive_agent_cfg;
virtual alert_if vif;

bit is_async = 0;
bit en_ping_cov = 1;
bit en_lpg_cov = 1;
bit alert_init_done = 0;
bit en_alert_lpg = 0;

// Enabled via plusarg.
// Please only use this plusarg in top-level test.
// For IP level test, please set `exp_fatal_alert` in post_start() instead.
bit bypass_alert_ready_to_end_check = 0;

// When this flag is set to 1, and agent in alert host mode, the sequence will automatically
// response to alert ping requests.
bit start_default_rsp_seq = 1;

// Control if ping response will timeout or not.
bit ping_timeout = 0;

// Monitor will set this value to 1 when the agent is under ping handshake.
bit under_ping_handshake = 0;

// Monitor will set this value to 1 when the agent is under ping handshake phase 2.
bit under_ping_handshake_ph_2 = 0;

// dut clk frequency, used to generate alert async_clk frequency
int clk_freq_mhz;

// sender mode
int unsigned alert_delay_min = 0;
int unsigned alert_delay_max = 10;

// receiver mode
int unsigned ack_delay_min = 0;
int unsigned ack_delay_max = 10;

int unsigned ack_stable_min = 0;
int unsigned ack_stable_max = 10;

// The minimum and maximum value that alert_receiver_ping_seq will use for ping_delay
//
// To enable a "stress test", which sends lots of back-to-back ping items, these can be made
// small.
int unsigned ping_delay_min = 10000;
int unsigned ping_delay_max = 20000;

// When this bit is set, alert agent responds to alert without delay
// This is set by plusarg "+fast_rcvr_{alert_name}"
bit fast_rcvr = 0;

int unsigned ping_timeout_cycle = 32;

// Incremented by the monitor on each ping
int unsigned ping_count = 0;
// Needed for alert checks starting after a ping
// This flag is updated in the alert_monitor task `monitor_ping` when a ping is detected.
bit active_ping = 0;

`uvm_object_utils_begin(alert_agent_cfg)
`uvm_field_int(alert_delay_min, UVM_DEFAULT)
`uvm_field_int(alert_delay_max, UVM_DEFAULT)
`uvm_field_int(ack_delay_min, UVM_DEFAULT)
`uvm_field_int(ack_delay_max, UVM_DEFAULT)
`uvm_field_int(ack_stable_min, UVM_DEFAULT)
`uvm_field_int(ack_stable_max, UVM_DEFAULT)
`uvm_field_int(ping_delay_max, UVM_DEFAULT)
`uvm_object_utils_end

extern function new (string name="");

endclass : alert_agent_cfg

function alert_agent_cfg::new (string name="");
super.new(name);
endfunction : new
57 changes: 57 additions & 0 deletions hw/vendor/lowrisc_ip/dv/sv/alert_agent/alert_agent_cov.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

// A general covergroup to track completion / alerts in an alert interface. The status input to the
// sample() function should be an alert_handshake_e enum value, but the function takes an int
// unsigned (the encoding of the enum) to avoid needing to parameterise the type.
covergroup handshake_complete_cg (int unsigned complete_status)
with function sample(int unsigned handshake_status);
option.per_instance = 1;

cp_handshake_complete: coverpoint handshake_status {
bins complete = {complete_status};
}
endgroup : handshake_complete_cg

covergroup alert_trans_cg with function sample(alert_trans_type_e trans);
option.per_instance = 1;

cp_handshake_complete: coverpoint trans {
bins alert_trans = {AlertSigTrans};
bins ping_trans = {AlertPingTrans};
}
endgroup : alert_trans_cg

covergroup alert_lpg_cg with function sample(bit alert_lpg_en);
option.per_instance = 1;
cp_alert_lpg: coverpoint alert_lpg_en;
endgroup

// If a module contains alert ports, these covergroups can check if all alerts/pings have been
// completed.
class alert_agent_cov extends dv_base_agent_cov #(alert_agent_cfg);

handshake_complete_cg m_handshake_complete_cg;
alert_trans_cg m_alert_trans_cg;
alert_lpg_cg m_alert_lpg_cg;

`uvm_component_utils(alert_agent_cov)

extern function new (string name, uvm_component parent);
extern function void build_phase(uvm_phase phase);

endclass : alert_agent_cov

function alert_agent_cov::new (string name, uvm_component parent);
super.new(name, parent);
endfunction : new

function void alert_agent_cov::build_phase(uvm_phase phase);
super.build_phase(phase);

if (cfg.en_ping_cov) m_alert_trans_cg = new();
if (cfg.en_lpg_cov) m_alert_lpg_cg = new();

m_handshake_complete_cg = new(AlertAckComplete);
endfunction : build_phase
Loading