UVM_WARNING : map 'reg_map' does not seem to be initialized correctly, check that the top register model is locked()

Hi,
In my TB env, I have a total of 5 interfaces(1 I2C and 4 SPIs) which can access the reg bank concurrently. And the ‘default_map’ provided by the regmodel won’t be enough to achieve this parallelism. Hence, I have added 5 different reg_maps(1 for i2c and 1 for each SPI).

The regmodel is generated by a script and currently there is no way to add user maps to this. Hence, I have extended the top_reg_block (of type reg_block and contains all the register objects) and top_reg_model (also of type reg_block and contains the object of top_reg_block class called m_top_reg_block) and created a child class called ‘tb_reg_block’ and ‘tb_reg_model’ where I am adding my user maps.

top_reg_block <---------- tb_reg_block (child class)

top_reg_model <--------- tb_reg_model (child class)

I am getting ~2000 lines of warnings as shown below from uvm_reg_map when I call the “regs[i].get_offset(default_map)” and “regs[i].get_rights(default_maps)” function.

UVM_WARNING : map ‘reg_map’ does not seem to be initialized correctly, check that the top register model is locked().

After analysis, it looks like the map is set to intialized only when we call the lock_model(). But once the model is locked, we won’t be able to add mem/maps to it. I don’t find any other public API’s to set the default_map to initialized except Xinit_address_mapX( ), but, I don’t want to use this method as it seems to be local with its naming convention though it is not.

Functionally, this code is working fine as expected, but, please let me know

  1. If this approach is correct ?

  2. How to get rid of these warnings ?

Thanks in advance for your response.

PFB the example code ( EDA Playground )

`define CPU_MEM_NAME "cpu_mem"
`define SYS_MEM_NAME "sys_mem"
`define CPU_MEM_SIZE 256
`define SYS_MEM_SIZE 256
`define CPU_MEM_START_ADDR 0
`define SYS_MEM_START_ADDR 1024

`include "uvm_macros.svh"

//--------------------------------------------------------------------------------------------
//                                       RAL PACKAGE                                          
//--------------------------------------------------------------------------------------------
package ral_pkg;
  import uvm_pkg::*;

class reg1 extends uvm_reg;
  `uvm_object_utils(reg1)
  uvm_reg_field m_minor; 
  
  function new(string name = "reg1");
    super.new(name, 32, build_coverage(UVM_NO_COVERAGE));        
  endfunction: new

    virtual function void build();
        m_minor = uvm_reg_field::type_id::create("minor",,get_full_name());
        m_minor.configure(this, 8, 0, "RO", 0, 8'h1, 1, 0, 1);
    endfunction: build
endclass

class reg2 extends uvm_reg;
  `uvm_object_utils(reg2)
  uvm_reg_field m_minor;
  
  function new(string name = "reg2");
    super.new(name, 32, build_coverage(UVM_NO_COVERAGE));        
  endfunction: new

    virtual function void build();
        m_minor = uvm_reg_field::type_id::create("minor",,get_full_name());
        m_minor.configure(this, 8, 0, "RO", 0, 8'h1, 1, 0, 1);
    endfunction: build  
endclass

class reg3 extends uvm_reg;
  `uvm_object_utils(reg3)
  uvm_reg_field m_minor;
  
  function new(string name = "reg3");
    super.new(name, 32, build_coverage(UVM_NO_COVERAGE));        
  endfunction: new

    virtual function void build();
        m_minor = uvm_reg_field::type_id::create("minor",,get_full_name());
        m_minor.configure(this, 8, 0, "RO", 0, 8'h1, 1, 0, 1);
    endfunction: build  
endclass

class top_reg_block extends uvm_reg_block;
  `uvm_object_utils(top_reg_block)
  rand reg1 m_reg1;
  rand reg2 m_reg2;
  rand reg3 m_reg3;
  	
  function new(string name = "top_reg_block");
    super.new(name, build_coverage(UVM_NO_COVERAGE));        
  endfunction: new

  virtual function void build();
    this.default_map = create_map("", 0, 4, UVM_LITTLE_ENDIAN, 0);
    
    this.m_reg1 = reg1::type_id::create("reg1",,get_full_name());
    this.m_reg1.configure(this, null, "");
    this.m_reg1.build();
    this.default_map.add_reg(this.m_reg1, `UVM_REG_ADDR_WIDTH'h0, "RO", 0);
    
    this.m_reg2 = reg2::type_id::create("reg2",,get_full_name());
    this.m_reg2.configure(this, null, "");
    this.m_reg2.build();
    this.default_map.add_reg(this.m_reg2, `UVM_REG_ADDR_WIDTH'h4, "RO", 0);
    
    this.m_reg3 = reg3::type_id::create("reg3",,get_full_name());
    this.m_reg3.configure(this, null, "");
    this.m_reg3.build();
    this.default_map.add_reg(this.m_reg3, `UVM_REG_ADDR_WIDTH'h8, "RO", 0);
  endfunction
endclass

class top_reg_model extends uvm_reg_block;
  `uvm_object_utils(top_reg_model)
  rand top_reg_block m_top_reg_block;
    
  function new(string name = "top_reg_model");
    super.new(name, build_coverage(UVM_NO_COVERAGE));
  endfunction: new

  function void build();
    this.default_map = create_map("", 0, 4, UVM_LITTLE_ENDIAN, 0);
    this.m_top_reg_block = top_reg_block::type_id::create("top_reg_block",,"top_reg_block");
    this.m_top_reg_block.configure(this, "");
    this.m_top_reg_block.build();
    this.default_map.add_submap(this.m_top_reg_block.default_map, `UVM_REG_ADDR_WIDTH'h40000000);    
  endfunction : build
endclass

endpackage

//--------------------------------------------------------------------------------------------
//                                        TB PACKAGE                                          
//--------------------------------------------------------------------------------------------
package tb_pkg;
  import uvm_pkg::*;
  import ral_pkg::*;

  parameter NO_OF_I2CS = 1;
  parameter NO_OF_SPIS = 4;

//--------------------------------------
// tb_reg_block
//--------------------------------------
class tb_reg_block extends top_reg_block;
    `uvm_object_utils(tb_reg_block)

      uvm_reg_map m_i2c_maps [NO_OF_I2CS]; // NO_OF_I2CS = 1
      uvm_reg_map m_spi_maps [NO_OF_SPIS]; // NO_OF_SPIS = 4

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

   function void build();
      super.build();      
      this.add_user_map();
   endfunction : build

   function void add_user_map();
      // Create user maps - I2C
      for(int i = 0; i < NO_OF_I2CS; i++) begin
        m_i2c_maps[i] = create_map($sformatf("i2c_map_%0d", i), 'h0, 4, UVM_LITTLE_ENDIAN);
      end

      // Create user maps - SPI
      for(int i = 0; i < NO_OF_SPIS; i++) begin
        m_spi_maps[i] = create_map($sformatf("spi_map_%0d", i), 'h0, 4, UVM_LITTLE_ENDIAN);
      end

      // Copy registers to user maps
      mirror_regs_to_user_maps(1);
   endfunction

   function void mirror_regs_to_user_maps(bit include_regs = 1);
      // registers
      if(include_regs) begin
        uvm_reg regs[$];
        this.get_registers(regs);

        foreach(regs[i]) begin
          uvm_reg_addr_t offset = regs[i].get_offset(default_map); // !WARNING
          string         rights = regs[i].get_rights(default_map); // !WARNING

          foreach(m_i2c_maps[j]) begin
            m_i2c_maps[j].add_reg(regs[i], offset, rights);
          end // foreach[j]

          foreach(m_spi_maps[k]) begin
            m_spi_maps[k].add_reg(regs[i], offset, rights);
          end // foreach[k]

        end // foreach[i]

      end // if
   endfunction : mirror_regs_to_user_maps

  endclass

//--------------------------------------
// tb_reg_model
//--------------------------------------
class tb_reg_model extends top_reg_model;
  `uvm_object_utils(tb_reg_model)

  uvm_reg_map m_i2c_maps [NO_OF_I2CS]; // 1
  uvm_reg_map m_spi_maps [NO_OF_SPIS]; // 4

  uvm_mem cpu_mem;
  uvm_mem sys_mem;
    
  function new(string name = "tb_reg_model");
    super.new(name);
  endfunction: new

  function void build();
    super.build();
    this.add_user_mem();
    this.add_user_map();
  endfunction : build

  function void add_user_mem();
    // cpu_mem
    cpu_mem = new(`CPU_MEM_NAME, `CPU_MEM_SIZE, 32, "RW", UVM_NO_COVERAGE);
    cpu_mem.configure(this, `CPU_MEM_NAME);    
    this.default_map.add_mem(cpu_mem, (`CPU_MEM_START_ADDR + `CPU_MEM_SIZE));

    // sys_mem
    sys_mem = new(`SYS_MEM_NAME, `SYS_MEM_SIZE, 32, "RW", UVM_NO_COVERAGE);
    sys_mem.configure(this, `SYS_MEM_NAME);    
    this.default_map.add_mem(sys_mem, (`SYS_MEM_START_ADDR + `SYS_MEM_SIZE));
  endfunction
  
  function void add_user_map();
    // I2C
    for(int i = 0; i < NO_OF_I2CS; i++) begin
      m_i2c_maps[i] = create_map($sformatf("i2c_map_%0d", i), 'h0, 4, UVM_LITTLE_ENDIAN);
      m_i2c_maps[i].add_submap(this.m_top_reg_block.get_map_by_name($sformatf("i2c_map_%0d", i)), 'h0);

      m_i2c_maps[i].add_mem(cpu_mem, (`CPU_MEM_START_ADDR + (i * `CPU_MEM_SIZE) + 'h1000));
      m_i2c_maps[i].add_mem(sys_mem, (`SYS_MEM_START_ADDR + (i * `SYS_MEM_SIZE) + 'h1000));
    end

    // SPI
    for(int i = 0; i < NO_OF_SPIS; i++) begin
      m_spi_maps[i] = create_map($sformatf("spi_map_%0d", i), 'h0, 4, UVM_LITTLE_ENDIAN);
      m_spi_maps[i].add_submap(this.m_top_reg_block.get_map_by_name($sformatf("spi_map_%0d", i)), 'h0);
      
      m_spi_maps[i].add_mem(cpu_mem, (`CPU_MEM_START_ADDR + (i * `CPU_MEM_SIZE) + 'h2000));
      m_spi_maps[i].add_mem(sys_mem, (`SYS_MEM_START_ADDR + (i * `SYS_MEM_SIZE) + 'h2000));
    end
  endfunction
endclass

class env extends uvm_env;
    `uvm_component_utils(env)
    tb_reg_model m_regmodel;
    
    function new(string name = "env", uvm_component parent = null);
      super.new(name, parent);
    endfunction
    
    function void build_phase(uvm_phase phase);
      set_type_override_by_type(top_reg_block::get_type(), tb_reg_block::get_type());
      super.build_phase(phase);
      m_regmodel = tb_reg_model::type_id::create("m_regmodel", this);      
      `uvm_info(get_name(), "Building m_regmodel", UVM_LOW)
      m_regmodel.build();      
      `uvm_info(get_name(), "Locking m_regmodel", UVM_LOW)
      m_regmodel.lock_model();      
    endfunction
 endclass

endpackage

//--------------------------------------------------------------------------------------------
//                                        TB MODULE                                           
//--------------------------------------------------------------------------------------------
module tb();
  import uvm_pkg::*;
  import tb_pkg::*;
  
  env m_env;
  
  initial begin    
    m_env = env::type_id::create("m_env", null);
    run_test();
    #100 $finish;    
  end
endmodule

Regards,
Karan