Cannot get item (virtual interface) from config_db

I am trying to setup a simple uvm test bench and i am struggling with setting/getting items from the config_db

Below i have posted code for my top level (testbench_top.sv) where i am setting my interface and my driver (driver.sv) where i am attempting to get my virtual interface.

i am calling set() wit the following arguments:

 uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top", "input_i", input_i);

I am reading the UVM cookbook about how to use this function and it says for the cntxt and inst_name:

• cntxt and inst_name together form a scope that is used to locate the resource within the database; it is formed by
appending the instance name to the full hierarchical name of the context, i.e.
{cntxt.get_full_name(),“.”,inst_name}.

So for the arguments to the function it seems that i have
cntxt = “uvm_test_top”
inst_name = “input_i”

So from my understanding of uvm i should be able to use the cntxt and inst_name to get the virtual interface in my driver with the following function call:

uvm_config_db#(virtual uvm_csv_depack_in)::get(this, "uvm_test_top", "input_i", virtual_interface))

However, the get() always fails.

I have utilized the uvm_config_db #(int)::dump(); function for debugging and i can see that my interface seems to be in the config database…

=== resource pool ===

input_i [/^uvm_test_top$/] : (virtual uvm_csv_depack_in) /top_tb/input_i

-

output_o [/^uvm_test_top$/] : (virtual uvm_csv_depack_in) /top_tb/output_o

-

recording_detail : (reg signed[4095:0]) 0

-

recording_detail : (int) 0

-

=== end of resource pool ===

it even seems that the expected context “uvm_test_top” and the instance name "input_i " are in there…

but the get() still fails?

any ideas?

testbench_top.sv

import uvm_pkg::*;
import uvm_csv_test_pkg::*;

module top_tb;

  timeunit      1ns;
  timeprecision 1ps;

initial begin
  input_i.clk = 0;
  forever #10ns input_i.clk = ~input_i.clk;
end

 uvm_csv_depack_in input_i ();
 uvm_csv_depack_in output_o ();

  depacketizer depack (
    // input
    .data_i(input_i.data),
  .data_valid_i(input_i.data_valid),
  .x_res_i(13'h0000),
  .y_res_i(12'h000),
  .clk_i(input_i.clk),
  .rst_i(1'b0),
  // output 
  .data_o(output_o.data),
  .data_valid_o(output_o.data_valid)
);

  initial
  begin
    uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top", "input_i", input_i); 
    uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top", "output_o", output_o);
    run_test(); // run the test
  end
endmodule

driver.sv

`ifndef uvm_csv_driver_SV
`define uvm_csv_driver_SV

import uvm_pkg::*;
`include "uvm_macros.svh"

class uvm_csv_driver extends uvm_driver #(uvm_csv_packet_item);

  `uvm_component_utils(uvm_csv_driver)
  virtual uvm_csv_depack_in virtual_interface;
  extern function new(string name, uvm_component parent);
  extern task run_phase(uvm_phase phase);
  extern function void build_phase(uvm_phase phase);
  extern task do_drive();

endclass : uvm_csv_driver 


  function void uvm_csv_driver::build_phase(uvm_phase phase);
  super.build_phase(phase);
    
  uvm_config_db #(int)::dump(); // This prints out a resource pool?  
  uvm_report_info(get_full_name(),"get_full_name()");

  if( !uvm_config_db#(virtual uvm_csv_depack_in)::get(this, "uvm_test_top", "input_i", virtual_interface))
    `uvm_fatal(get_type_name(),"cannot get virutal interface")
  endfunction: build_phase



In reply to mreister:

You will able to get successfully when set path match with get path.
But,in your case get path will be like {this.get_full_name(),“uvm_test_top”} not matching in driver class.

Please, try below code.



uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top.*", "input_i", input_i); 
uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top.*", "output_o", output_o);
..........
..........
uvm_config_db#(virtual uvm_csv_depack_in)::get(this, "", "input_i", virtual_interface))

Also please check below link for more understanding.
https://verificationacademy.com/forums/uvm/configdb-parameters-set/get-method

Thanks,
Harsh

In reply to harsh pandya:

Thanks that worked.

Just to double check my understanding the reason why it didnt work before was when i had just “uvm_test_top” it was scoped to only components that were in “uvm_test_top”? But when i added: “uvm_test_top.*” the wild card scoped it to anything under “uvm_test_top”?

In reply to mreister:

Yes, you are correct.

You could as well use this to further simplify
uvm_config_db #(virtual uvm_csv_depack_in)::set(null,“*”, “input_i”, input_i);

In reply to mreister:

Let me clarify more.

Thare is issue in hierarchical scope of your get method.


//You have use set like below
// Entry stored inside config database with "uvm_test_top"
uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top", "input_i", input_i); 

However you are trying to get using below call.


// hierarchical scope create by considering first two argument.
//So,You are trying to get like below.
//{this,"uvm_test_top"} == {this.get_full_name(),"uvm_test_top"} 
//which is not matching with set path.
uvm_config_db #(virtual uvm_csv_depack_in)::get(this,"uvm_test_top", "input_i", input_i); 

In my example I have just simply code with uvm_test_top.* for easy understand.
However, below code also work.


//Set path uvm_top_test
uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top", "input_i", input_i); 
//Get path uvm_top_test
uvm_config_db #(virtual uvm_csv_depack_in)::get(null,"uvm_test_top", "input_i", input_i); 

Thanks,
Harsh

In reply to harsh pandya:

Using ‘null’ as the first argument in the set/get command means the seconde argument will be considered as an abolute path. ‘this’ is indicating a relative path.

In reply to chr_sue:

Thanks Christopher for correcting me,
Btw,I have one query with null.
Supposed we calling config_db set from top base test and get method using null inside driver.
How exactly the hierarchical path stored in configuration databases for below example.
I mean from uvm_root to ? which point.


//Top base test
// uvm_root to uvm_test_top ?
uvm_config_db #(virtual uvm_csv_depack_in)::set(null,"uvm_test_top", "input_i", input_i); 

//Driver
//uvm_root to uvm_test_top ?
uvm_config_db #(virtual uvm_csv_depack_in)::get(null,"uvm_test_top", "input_i", input_i); 

Thanks,
Harsh

In reply to harsh pandya:

@Harsh
What you are proposing in your last post is correct it works.

To make it easy my recommedndations are:
(1) In the toplevel module use ‘null’ as the first argument and as the 2nd “uvm_test_top”. This as the 1st argument is impossible because there is no parent.
(2) In a class-based component use as 1sr argument ‘this’ and as the 2nd ‘“”’.

Following these rules it is easy to handle the virtual interface. You can see here in the forum lots of questions regarding this topic. Following these rule you can avoid at least 50% of the questions.

In reply to chr_sue:

Yes, I agree with your point.