# Uvm\_config\_db / uvm\_resource\_db for registering virtual interfaces

**URL:** <https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179>\
**Category:** UVM\
**Tags:** virtual-interface, UVM, uvm\_config\_db\
**Created:** [June 6, 2017, 1:53pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179 "2017-06-06T13:53:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 6, 2017, 1:53pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/1 "2017-06-06T13:53:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 6, 2017, 2:49pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/2 "2017-06-06T14:49:56Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179):_

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:

```verilog
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

```

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 6, 2017, 3:04pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/3 "2017-06-06T15:04:53Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/2):_

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.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 6, 2017, 3:13pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/4 "2017-06-06T15:13:15Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/3):_  
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.

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 6, 2017, 3:21pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/5 "2017-06-06T15:21:35Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/4):_

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.

```verilog

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

```

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 6, 2017, 3:33pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/6 "2017-06-06T15:33:14Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/5):_

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

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 6, 2017, 4:18pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/7 "2017-06-06T16:18:49Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/6):_

So the testbench would look like this

```verilog

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 ?

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 6, 2017, 4:38pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/8 "2017-06-06T16:38:14Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/7):_

First I have to correct ny Syntax:

```verilog
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

```

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 6, 2017, 5:05pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/9 "2017-06-06T17:05:16Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/8):_

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

```verilog

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

```

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 6, 2017, 6:15pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/10 "2017-06-06T18:15:36Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/9):_

```verilog
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

```

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 6, 2017, 7:47pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/11 "2017-06-06T19:47:28Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/10):_

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.

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 6, 2017, 8:49pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/12 "2017-06-06T20:49:00Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/11):_

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”.

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 7, 2017, 12:13pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/13 "2017-06-07T12:13:22Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/12):_

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

```verilog

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

```

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 7, 2017, 12:27pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/14 "2017-06-07T12:27:05Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/13):_

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.

---

<div class="post-metadata">

**Author:** ![Vperrin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/eada6e/32.png) [@Vperrin](https://verificationacademy.com/forums/u/Vperrin)\
**Post date:** [June 7, 2017, 12:46pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/15 "2017-06-07T12:46:24Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/14):_

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

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [June 7, 2017, 1:02pm UTC](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/16 "2017-06-07T13:02:30Z")

</div>

_In reply to [Vperrin](https://verificationacademy.com/forums/t/uvm-config-db-uvm-resource-db-for-registering-virtual-interfaces/33179/15):_

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.
