TO Be coming

Nov 21, 2026

UVM Course :Day 18: Integrating RAL — uvm_reg_adapter, uvm_reg_predictor, and Wiring the Model to the Bus

Day 18: Integrating RAL — uvm_reg_adapter, uvm_reg_predictor, and Wiring the Model to the Bus
Advertisement
Top banner — drop your 728×90 or responsive ad unit here.

Day 18: Integrating RAL — uvm_reg_adapter, uvm_reg_predictor, and Wiring the Model to the Bus

A 30-day SystemVerilog/UVM verification series. The model is built and mapped. Now it has to reach the DUT.

By Day 17 you have a register model with correct fields, correct access policies, and correct addresses. It is also completely inert. It has never touched a bus. If you write a test that calls ctrl.write() today, RAL will produce a register operation, hand it to a sequencer, and the sequencer will produce nothing because there is nothing connected. This is what "integrating RAL" fixes.

Two components do the wiring. The adapter translates a register operation into a bus transaction — the same kind of transaction your driver knows how to drive. The predictor watches the bus and updates the model's mirror when it sees a register access the model did not initiate. Together they make RAL an active participant in the test, not a static document.


1. The Adapter

An adapter extends uvm_reg_adapter and implements two functions: reg2bus(), which converts a register operation into a bus sequence item, and bus2reg(), which converts an observed bus item back into a register operation (used by the predictor).

class fifo_reg_adapter extends uvm_reg_adapter;
    `uvm_object_utils(fifo_reg_adapter)

    function new(string name = "fifo_reg_adapter");
        super.new(name);
        supports_byte_enable = 0;
        provides_responses    = 1;
    endfunction

    // Convert RAL operation into a bus sequence item
    virtual function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
        bus_item item = bus_item::type_id::create("item");
        item.addr  = rw.addr;
        item.data  = rw.data;
        item.we    = (rw.kind == UVM_WRITE);
        return item;
    endfunction

    // Convert observed bus item back into a RAL operation
    virtual function void bus2reg(uvm_sequence_item bus_item,
                                 ref uvm_reg_bus_op rw);
        bus_item item;
        if (!$cast(item, bus_item)) begin
            `uvm_fatal("NOT_BUS", "adapter got wrong item type")
            return;
        end
        rw.kind = item.we ? UVM_WRITE : UVM_READ;
        rw.addr = item.addr;
        rw.data = item.data;
        rw.status = UVM_IS_OK;
    endfunction
endclass

Three things to note:

  • provides_responses = 1 tells RAL that the driver will return a response item on reads, so the model can get the data back. For a bus that always responds, set it to 1.
  • supports_byte_enable = 0 says the bus does not have byte-enable signals. If your bus does, set it to 1 and populate byte_en in reg2bus.
  • rw.status = UVM_IS_OK in bus2reg is what tells RAL the access succeeded. If your bus can fail (error response), set status accordingly.
The rw.kind field is not a bit. It is uvm_access_e — UVM_READ or UVM_WRITE. Newcomers sometimes write rw.kind = item.we which compiles but is a type mismatch at runtime on some simulators.

2. Wiring the Adapter to the Sequencer

The model's bus access path is: reg.write() → map → sequencer → adapter → driver. The connection happens in the env's connect_phase, after both the register model and the bus agent exist:

class fifo_env extends uvm_env;
    // ...

    fifo_reg_block     reg_model;
    fifo_reg_adapter   reg_adapter;

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        reg_model   = fifo_reg_block::type_id::create("reg_model", this);
        reg_adapter = fifo_reg_adapter::type_id::create("reg_adapter");
        // ...
    endfunction

    virtual function void connect_phase(uvm_phase phase);
        super.connect_phase(phase);

        // Wire the model's default map through the adapter to the bus sequencer
        reg_model.default_map.set_sequencer(bus_agent.sqr, reg_adapter);
        reg_model.default_map.set_auto_predict(1);

        // ... monitor connections ...
    endfunction
endclass

The two key calls:

  • set_sequencer tells RAL which sequencer to send bus items to, and which adapter to convert them with.
  • set_auto_predict tells RAL to update the mirror based on the operations the model itself performs. This is fine for the base case. Day 18's second half explains why you'll usually want to turn this off later.

3. Writing a Register Sequence

Once wired, register access from a sequence looks like a register access from software:

class fifo_reg_seq extends uvm_sequence;
    `uvm_object_utils(fifo_reg_seq)
    `uvm_declare_p_sequencer(fifo_vseqr)

    function new(string name = "fifo_reg_seq");
        super.new(name);
    endfunction

    virtual task body();
        uvm_status_e   status;
        uvm_reg_data_t value;

        // Write ENABLE=1, MODE=2 in one operation
        p_sequencer.reg_model.ctrl.write(status, 'h05);
        if (status != UVM_IS_OK)
            `uvm_error("RSEQ", "ctrl write failed")

        // Read STATUS and check the ENABLE bit
        p_sequencer.reg_model.status.read(status, value);
        if (status != UVM_IS_OK)
            `uvm_error("RSEQ", "status read failed")
        `uvm_info("RSEQ", $sformatf("status = 0x%0h", value), UVM_LOW)
    endtask
endclass
What RAL just did for you: it calculated the absolute address for ctrl, built a bus item with that address and the right write data, sent it to the sequencer, waited for the driver to handshake, collected the response, updated the mirror, and returned UVM_IS_OK. All of that came from a two-line call.

4. The Predictor

Auto-prediction updates the mirror based on what the model did. It has one blind spot: anything the model did not do. If a driver writes to a register through a direct bus sequence (not through RAL), or a volatile field changes due to DUT behavior, auto-prediction misses it. The mirror goes stale, and every subsequent comparison fails.

The predictor observes the bus and updates the mirror from actual traffic:

class fifo_env extends uvm_env;
    // ...

    uvm_reg_predictor #(bus_item) reg_predictor;

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        reg_predictor = uvm_reg_predictor#(bus_item)::type_id::create(
                            "reg_predictor", this);
        // ...
    endfunction

    virtual function void connect_phase(uvm_phase phase);
        super.connect_phase(phase);

        reg_model.default_map.set_sequencer(bus_agent.sqr, reg_adapter);
        reg_model.default_map.set_auto_predict(0);       // explicit prediction

        // Predictor sees every bus transaction the monitor observed
        reg_predictor.map     = reg_model.default_map;
        reg_predictor.adapter = reg_adapter;
        bus_agent.mon.ap.connect(reg_predictor.bus_in);
    endfunction
endclass

The predictor is a subscriber to the bus monitor's analysis port. Every observed bus item is converted by bus2reg into a register operation and applied to the mirror. Now the model knows about every register access, not just the ones the model itself performed.


5. Auto vs Explicit Prediction

ModeUpdates mirror fromUse when
set_auto_predict(1)Only operations the model initiatedSmall testbenches, only model-initiated register access, no volatile fields, no out-of-band writes
set_auto_predict(0) + predictorEvery bus transaction the monitor observedAnything real. Volatile fields, direct bus writes, multi-agent DUTs
Do not enable both. If auto-predict is on and a predictor is connected, the mirror gets updated twice per access. Writes look fine (same value written twice) but reads get double-counted in fields with read side effects (RC, WC). Set set_auto_predict(0) when you attach a predictor.

6. What Day 19 Will Add

Tomorrow: RAL Operations. You have write() and read(). Tomorrow adds mirror(), update(), poke(), and peek(), and shows when each one is the right tool. mirror() compares the DUT's actual register value against the model. update() pushes the model's mirror value back to the DUT. poke()/peek() use backdoor access to bypass the bus. Each one is a different verification question.


7. Quiz

Ten questions on adapters, predictors, and wiring.

Question 1 of 10
Loading…
    0 / 10
    Advertisement
    Bottom banner — drop your 728×90 or responsive ad unit here.

    Coming Up Next: Day 19 — RAL Operations

    • mirror() — read the DUT and compare against the model's mirror.
    • update() — push the mirror value back to the DUT.
    • poke() / peek() — backdoor access that bypasses the bus.
    • When each is right — the verification question each operation answers.
    ← Back to the 30-Day UVM Course
    See all 30 days, week by week.

    Series: 30 days of SystemVerilog/UVM verification. Day 18 wires RAL to the bus.

    No comments:

    Post a Comment

    SiteMap