Module 4: Stimulus and Drivers | Lesson 36

Virtual Interfaces

Learn how UVM components access DUT signals through virtual interfaces, how interfaces connect the testbench to the design, and how to configure them safely through the UVM configuration database.

Learning objectives

  • Explain the difference between a SystemVerilog interface and a virtual interface.
  • Understand why UVM drivers and monitors commonly use virtual interfaces.
  • Declare and use a virtual interface inside a UVM component.
  • Pass an interface handle into the UVM hierarchy using uvm_config_db.
  • Retrieve and validate the virtual interface during build_phase().
  • Trace the complete path from DUT interface to UVM driver.
  • Debug common virtual-interface configuration and connection failures.

Step 1: Understand the problem virtual interfaces solve

A UVM driver needs to control DUT signals. A monitor needs to observe them. But UVM components are classes, while DUT interfaces are connected through modules and SystemVerilog interfaces.

A virtual interface provides the class-based testbench with a handle to an actual SystemVerilog interface instance.

Core idea: The interface exists in the static HDL hierarchy. The virtual interface gives a UVM class a reference to that interface.

Without this connection, a driver can receive transactions perfectly but has no way to turn those transactions into DUT pin activity.

Step 2: Understand the SystemVerilog interface

First, define an interface containing the signals associated with the DUT protocol.

interface bus_if(input logic clk);

logic        valid;
logic        ready;
logic        write;
logic [7:0]  addr;
logic [7:0]  data;


endinterface

The interface groups related signals together instead of passing every signal independently through the testbench.

For example, instead of giving a driver five separate handles for valid, ready, write, addr, and data, the driver can use one interface:

vif.valid


vif.ready
vif.write
vif.addr
vif.data

This creates a clean boundary between the DUT and the verification environment.

Step 3: Connect the interface to the DUT

The actual interface instance is normally created in the top-level testbench module.

module tb_top;

logic clk;

bus_if bus_vif(clk);

dut u_dut (
    .clk   (clk),
    .valid (bus_vif.valid),
    .ready (bus_vif.ready),
    .write (bus_vif.write),
    .addr  (bus_vif.addr),
    .data  (bus_vif.data)
);


endmodule

At this point, bus_vif is a real interface instance connected to the DUT.

The UVM driver still cannot automatically see it. We need another step.

Step 4: Declare a virtual interface in the driver

The driver declares a virtual interface variable using the interface type.

class bus_driver extends uvm_driver #(bus_transaction);

`uvm_component_utils(bus_driver)

virtual bus_if vif;

function new(string name = "bus_driver",
             uvm_component parent = null);
    super.new(name, parent);
endfunction


endclass

The keyword virtual is important. The variable vif does not create another interface. Instead, it holds a reference to an existing interface instance.

Remember: bus_if bus_vif declares an actual interface instance. virtual bus_if vif declares a handle that can refer to an interface instance.

Step 5: See the complete connection

The complete relationship now looks like this:

                 STATIC HDL WORLD
             
             +----------------+
             |    bus_if      |
             |----------------|
             | valid          |
             | ready          |
             | write          |
             | addr           |
             | data           |
             +-------+--------+
                     |
                     | connected to DUT
                     v
             +----------------+
             |      DUT       |
             +----------------+

                     ^
                     |
              virtual handle
                     |
             +-------+--------+
             |   bus_driver   |
             |----------------|
             | virtual bus_if |
             | vif            |
             +----------------+
                     ^
                     |
             UVM configuration
                     |
             +-------+--------+
             |    uvm_test    |
             |   / uvm_env    |
             +----------------+

The virtual interface is therefore the bridge between the class-based UVM environment and the signal-level HDL environment.

Step 6: Pass the interface through uvm_config_db

A common UVM pattern is to place the interface handle into the configuration database from the top-level testbench.

uvm_config_db#(virtual bus_if)::set(
null,
"uvm_test_top.env.agent.driver",
"vif",
bus_vif


);

This call says:

  • Type: virtual bus_if
  • Scope: uvm_test_top.env.agent.driver
  • Field name: vif
  • Value: the real interface instance bus_vif

This is the same configuration mechanism introduced in Lesson 20, now applied to a real verification component.

Step 7: Retrieve the virtual interface in build_phase()

The driver retrieves the interface during its build phase.

function void build_phase(uvm_phase phase);

super.build_phase(phase);

if (!uvm_config_db#(virtual bus_if)::get(
        this,
        "",
        "vif",
        vif
    )) begin

    `uvm_fatal("NOVIF",
               "Virtual interface was not configured")

end


endfunction

If the lookup succeeds, vif now refers to the actual bus_vif instance.

The driver can then safely use:

vif.valid


vif.ready
vif.addr
vif.data

A fatal error is appropriate here because a driver that cannot access its required interface cannot perform its basic job.

Step 8: Why configure the interface before build_phase()?

Recall the UVM phase ordering from earlier lessons. Components are created during build, and components commonly retrieve configuration during their own build phase.

Therefore, the interface configuration must be available before the driver attempts to retrieve it.

Configure interface
    |
    v


Create UVM hierarchy
|
v
Driver build_phase()
|
v
Driver gets vif
|
v
Connect components
|
v
Run simulation
|
v
Driver accesses DUT signals
Rule: Configure required resources early enough that the component can retrieve them during its build phase.

Step 9: Use the virtual interface in the driver

Once vif has been configured, the driver can implement its protocol behavior.

task run_phase(uvm_phase phase);

forever begin

    seq_item_port.get_next_item(req);

    @(posedge vif.clk);

    vif.valid <= 1'b1;
    vif.write <= req.write;
    vif.addr  <= req.addr;
    vif.data  <= req.data;

    do begin
        @(posedge vif.clk);
    end
    while (!vif.ready);

    vif.valid <= 1'b0;

    seq_item_port.item_done();

end


endtask

Notice the clean division of responsibility:

  • The sequence creates req.
  • The sequencer transfers req to the driver.
  • The driver uses vif to implement the protocol.
  • The DUT responds through the same interface.

Step 10: Understand why virtual interfaces improve reuse

A driver should not depend on one particular DUT instance or hard-coded hierarchical signal path.

A fragile approach would look like:

dut.bus_valid = req.valid;


dut.bus_data  = req.data;

This tightly couples the driver to a particular module hierarchy.

A better approach is:

vif.valid <= req.valid;


vif.data  <= req.data;

Now the driver only depends on the interface contract. The actual DUT instance can change without changing the driver's protocol code.

Reusable architecture: Depend on the interface definition, not on the internal hierarchy of a particular DUT.

Step 11: Virtual interfaces are useful for monitors too

Drivers are not the only UVM components that need access to DUT signals. Monitors commonly use virtual interfaces as well.

class bus_monitor extends uvm_monitor;

`uvm_component_utils(bus_monitor)

virtual bus_if vif;

function new(string name = "bus_monitor",
             uvm_component parent = null);
    super.new(name, parent);
endfunction

task run_phase(uvm_phase phase);

    forever begin

        @(posedge vif.clk);

        if (vif.valid && vif.ready) begin

            `uvm_info(
                "MONITOR",
                $sformatf(
                    "Observed addr=0x%0h data=0x%0h",
                    vif.addr,
                    vif.data
                ),
                UVM_MEDIUM
            )

        end

    end

endtask


endclass

The driver uses the interface to drive activity. The monitor uses it to observe activity.

Step 12: Driver versus monitor access

Component Interface purpose
Driver Drive DUT inputs according to the protocol.
Monitor Observe DUT activity and reconstruct transactions.
Scoreboard Usually does not need direct pin access; it consumes transactions from the monitor.
Sequence Usually does not need direct pin access; it creates transactions.

This reinforces an important UVM architecture rule: higher-level components should work with transactions rather than reaching directly into DUT signals.

Step 13: Common virtual-interface mistakes

Mistake 1: Never setting the interface

The driver calls get(), but nothing was placed into the configuration database.

Result: get() fails and vif remains invalid.

Mistake 2: Wrong configuration path

The interface was set for one component path but the driver searches another path.

uvm_test_top.env.agent.driver

must match the actual UVM hierarchy or an intentionally broader configuration scope.

Mistake 3: Wrong field name

The setter uses:

"vif"

while the driver searches for:

"bus_vif"

Those are different configuration keys.

Mistake 4: Wrong interface type

The type used in set() and get() must match.

uvm_config_db#(virtual bus_if)

is not the same configuration type as an unrelated interface.

Mistake 5: Using vif before checking it

If configuration failed, accessing vif.valid or vif.clk can produce confusing simulation failures.

Validate required configuration during build rather than discovering the problem later in run_phase().

Step 14: Debug a missing virtual interface

If the driver reports that its virtual interface is missing, debug the problem in this order:

  1. Does the real interface instance exist?
  2. Is the interface connected to the DUT?
  3. Was the interface placed into uvm_config_db?
  4. Is the configuration type exactly correct?
  5. Is the field name the same in set() and get()?
  6. Does the configuration scope match the UVM hierarchy?
  7. Does the driver retrieve the interface during build_phase()?
  8. Does the driver use the retrieved handle rather than another uninitialized variable?

A useful mental model is:

Real interface
  |
  v


config_db set()
|
v
UVM hierarchy
|
v
config_db get()
|
v
driver.vif
|
v
DUT signal activity

Step 15: A complete minimal example

The following pieces show the essential pattern together.

Interface

interface bus_if(input logic clk);

logic        valid;
logic        ready;
logic        write;
logic [7:0]  addr;
logic [7:0]  data;


endinterface

Top-level configuration

module tb_top;

logic clk;

bus_if bus_vif(clk);

initial begin

    uvm_config_db#(virtual bus_if)::set(
        null,
        "uvm_test_top.env.agent.driver",
        "vif",
        bus_vif
    );

    run_test();

end


endmodule

Driver retrieval

function void build_phase(uvm_phase phase);

super.build_phase(phase);

if (!uvm_config_db#(virtual bus_if)::get(
        this,
        "",
        "vif",
        vif
    )) begin

    `uvm_fatal("NOVIF",
               "bus_if was not configured for the driver")

end


endfunction

This is one of the most common virtual-interface patterns you will see in real UVM environments.

Step 16: Keep the architecture clean

Virtual interfaces should provide access to the interface, not become a shortcut for bypassing UVM architecture.

Prefer:

Sequence
|
| transaction
v


Sequencer
|
v
Driver
|
| virtual interface
v
DUT

Avoid architectures where:

Sequence
|
+----> DUT signals directly
|
+----> internal DUT hierarchy
|
+----> unrelated testbench components

The virtual interface belongs primarily at the boundary between the transaction-level component and the signal-level interface.

Try it yourself

Build a complete virtual-interface connection for a simple bus.

  1. Create a bus_if containing clk, valid, ready, addr, and data.
  2. Instantiate the interface in tb_top.
  3. Connect the interface signals to the DUT.
  4. Declare virtual bus_if vif inside the driver.
  5. Place the interface into uvm_config_db.
  6. Retrieve it during the driver's build_phase().
  7. Use vif to drive one transaction.
  8. Add a fatal message if the interface cannot be retrieved.

Challenge: Add the same virtual interface to a monitor. Have the driver perform one transfer while the monitor prints the address and data it observes. This gives you your first complete connection from transaction → driver → interface → DUT → monitor.

Key takeaways

  • A SystemVerilog interface groups related DUT signals into a reusable protocol boundary.
  • A virtual interface is a class-side handle to an actual interface instance.
  • UVM drivers commonly use virtual interfaces to convert transactions into pin-level activity.
  • UVM monitors commonly use virtual interfaces to observe pin-level activity.
  • uvm_config_db is a common mechanism for passing virtual interfaces into the UVM hierarchy.
  • The interface should be configured before components attempt to retrieve it during build_phase().
  • Use configuration checks such as uvm_fatal when a required virtual interface is missing.
  • Keep sequences transaction-oriented and keep protocol-specific signal behavior inside drivers and monitors.
  • When debugging, trace the path: real interface → config_db set → config_db get → vif → DUT activity.