Protected Course Page
Enter the password to view Day 18 of the UVM 30-Day plan.
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 = 1tells 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 = 0says 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_OKinbus2regis what tells RAL the access succeeded. If your bus can fail (error response), set status accordingly.
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_sequencertells RAL which sequencer to send bus items to, and which adapter to convert them with.set_auto_predicttells 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
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
| Mode | Updates mirror from | Use when |
|---|---|---|
set_auto_predict(1) | Only operations the model initiated | Small testbenches, only model-initiated register access, no volatile fields, no out-of-band writes |
set_auto_predict(0) + predictor | Every bus transaction the monitor observed | Anything real. Volatile fields, direct bus writes, multi-agent DUTs |
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.
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.
Series: 30 days of SystemVerilog/UVM verification. Day 18 wires RAL to the bus.
No comments:
Post a Comment