Uvm_config_db / uvm_resource_db for registering virtual interfaces

Hi UVM experts,

I read from the Advanced UVM book (Second Edition) that resource_db must be used when information is not associated with any part of the uvm component hierarchy, otherwise we must use config_db.
Therefore according to the author, it is recommended to use resource_db for handling virtual interface registration.
However i came with cases where component hierarchy matters for registering virtual interfaces such as follows :

Tx_env contains one apb agent
Rx_env contains one apb agent
Top_env contains one tx_env and one rx_env.
In testbench I have two differents apb interfaces, one for rx and one for tx.

In this case, how can i use resource_db for registering the two apb interfaces as I use the same apb class for tx and rx ?

Best regards,

Victor Perrin
Verification Engineer

In reply to Vperrin:

Hi Victor,

first, never use resource_db. Instead use config_db. config_db is a layer put around the resource_db adding more flexibility.
second, passing virtual interfaces to the config_db has nothing to do with classes.
third, you can pass the handles of the virtual Interfaces to the config_db like this in the toplevel module of your UVM testbench:

apb_if   apb_ifrx();
apb_if   apb_iftx();

initial
begin
 uvm_config_db #(virtual apb_if)::set(null, "uvm_test_top", "apb_if_tx", apb_iftx);
 uvm_config_db #(virtual apb_if)::set(null, "uvm_test_top", "apb_if_rx", apb_ifrx)
....
end

In reply to chr_sue:

Thanks for the feedback.
My concern was more about how to register virtual interfaces with resource_db when you have multiple instances of the same agent, but i can see that config_db is more appropriate.
That s why it was confusing me that the book recommended to use resource_db for registering virtual interfaces.

In reply to Vperrin:
Using resource_db does not look so different.
But you have seen how to deal with 2 instances of the same interface type.
You do not pass the Interface type to the config_db but there instances.

In reply to chr_sue:

The problem i see for resource_db is the following :
Here is the code for driver. It s getting virtual interface with name and scope but it does not have information about hierarchy. If we have apb_tx and apb_rx agent how can you get correctly the corresponding interfaces to each agent instances.


class apb_driver extends uvm_driver #(apb_trans);
     virtual interface apb_interface vif;

    `uvm_component_utils(apb_driver)
 
    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if(!uvm_resource_db#(virtual interface apb_interface)::get("apb_pkg", "vif", vif))
         `uvm_fatal(get_type_name(), "Unable to get virtual interface");
   
    endfunction: build_phase



In reply to Vperrin:

It depends how you are Setting the context. You could use a wildcard(*). Then it should work.

In reply to chr_sue:

So the testbench would look like this


module top
interface apb_interface apb_tx_if();
interface apb_interface apb_rx_if();

initial begin
  uvm_resource_db#(...)
end

endmodule

How would you set the resource_db with the apb interfaces ?

In reply to Vperrin:

First I have to correct ny Syntax:

module top
  apb_interface apb_tx_if(); // the keyword interface was wrong in this place
  apb_interface apb_rx_if();
 
initial begin
  uvm_resource_db #(virtual apb_interface) ("*", "apb_tx", apb_tx_if );
  uvm_resource_db #(virtual apb_interface) ("*", "apb_rx", apb_rx_if );

end
 
endmodule

In reply to chr_sue:

You’re right about the syntax.

What you described won’t work in the case described because of the following code in the agent implemented for getting virtual interface


virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if(!uvm_resource_db#(virtual interface apb_interface)::get("apb_pkg", "vif", vif))
         `uvm_fatal(get_type_name(), "Unable to get virtual interface");
 
endfunction: build_phase

In reply to Vperrin:

virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if(!uvm_resource_db#(virtual interface apb_interface)::get("", "apb_tx", vif))
         `uvm_fatal(get_type_name(), "Unable to get virtual interface");
 
endfunction: build_phase



In reply to chr_sue:

If you do that, that means you have different code for apb_tx and apb_rx. I want the two agents to use the same class.

In reply to Vperrin:

What do you mean with the ‘same class’. An interface is not a class. It is a SV Interface. And a virtual interface uses the SV Interface as a type.
I understood you have 2 Interfaces of the same type. One is stored in the config_db/resource_db under the Name “apb_tx” and the other one under the name “apb_rx”.

In reply to chr_sue:

I meant same class for the agents as described in the following example :



apb_agent_c apb_tx;
apb_agent_c apb_rx;

virtual task build_phase(uvm_phase phase);
        apb_tx = apb_agent_c::type_id::create("apb_tx", this);
        apb_rx = apb_agent_c::type_id::create("apb_rx", this);
endtask: build_phase


In reply to Vperrin:

This is the build_phase function of your env. Right?
There is also no Problem. The resource_db/config_db is storing the Interfaces under seperate names.
I’d make the names of the agents and the config_db names different.

In reply to chr_sue:

Yes this is the build_phase of the env. I don’t see any problem for the config_db but I still have the issue with resource_db.

Ok you can put different names in the resource_db in your top module (“apb_tx”, “apb_rx”) but in the agent build_phase when you call resource_db you don’t know which string to provide for the name

In reply to Vperrin:

In the env you have to retrieve the data usingg the same name:
if the set in the toplevel module uses as name “apb_tx” you have to perform the get for the same Name.