T02 Tutorial PDF
T02 Tutorial PDF
intherealworld
                 Tutorial
                      MarkLi.erick
                       JasonSpro.
                    JonathanBromley
                     VanessaCooper
                                                     Application-specific code
      VericaHonEnvironment
                                                     Uses UVM building blocks
                                                     Open source (Apache)
 UniversalVericaHonMethodology                   Class library
               (UVM)                                Consistent methodology
                                                     Facilitates interoperability
       SystemVerilogIEEE1800                     Supported by all simulators
                                                   Multi-language simulators
 MentorTM
Questa        IUSTM 
              Cadence                  VCSTM
                                      Synopsys    VHDL, Verilog,
                                                     SystemVerilog, SystemC
                        UVM Methodology
                        base-classes
                        use-cases
                        configuration-db
                        factory operation
                        phases
                        etc...
       Verilab & Accellera      4
                       SystemVerilog
 Languagesyntax&semanHcsareprerequisite
    detailedunderstandingisnotuniquetoUVM...
    ...but,vericaHonsupersetmuchbiggerthandesign!
                        Design                 Verification
              RTL                      signals         OOP
             blocks                  interfaces        class
            modules                clocking-block     random
            vectors                  scheduling     constraints
          assignments                 functions      coverage
             arrays                     tasks         queues
              etc.                       etc.           etc.
 uvm_resource_db
   datasharingmechanismwherehierarchyisnotimportant
   eachentryiscalledaresource
   whenaccessingthedatabase,youmustspecifythe
     resourcetypeasaparameter
                    uvm_resource_db#(bit)::set(CHECKS_DISABLE,
 static function void set(input string scope, disable_scoreboard,
                          input string name,    1, this);
                                       T val,
              input uvm_object accessor=null)
uvm_resource_db#(bit)::set({REG::,
                            m_env.m_reg.get_full_name( ),
                            .cfg_reg},
                            NO_REG_TESTS, 1, this);
 uvm_cong_db
   usedwhenhierarchyisimportant
   canspecify,withgreatdetail,thelevelofaccesstoa
     resource
   almostalwaysusedinsteadoftheresourcedatabase
dut_intf vif
retry_count rty_cnt
my_env_cfg env_cfg
uvm_config_db#(TYPE)::get(this,,label,value);
retry_count rty_cnt
if(!uvm_config_db#(TYPE)::get(this,,label,value))
   `uvm_fatal(NOVIF, Virtual interface GET failed.)
 h?p://www.accellera.org
 VanessaCooper,GeMngStartedwithUVM:A
   BeginnersGuide,1sted,VerilabPublishing,2013
 SystemVerilogisanObjectOrientedProgramminglanguage
 OVM/UVMmakeextensiveuseofstandardOOPpa*erns
      FactorycreaAonofobjectswithoutspecifyingexacttype
      ObjectPoolsharingsetofiniAalizedobjects
      Singletonensureonlyoneinstancewithglobalaccess
      Proxyprovidessurrogateorplaceholderforanotherobject
      Publisher/SubscriberobjectdistribuAonto0ormoretargets
      Strategy/Policyimplementbehaviouralparametersets
      etc...
 ThemainO/UVMlesare:
    o/uvm_object_denes.svh
    o/uvm_registry.svh
                               a great benefit of OVM/UVM is that
    o/uvm_factory.svh        all source-code is open-source
 Overview:
      userobjectandcomponenttypesareregisteredviatypedef
      factorygeneratesandstoresproxies:*_registry#(T,Tname)
      proxyonlyknowshowtoconstructtheobjectitrepresents
      factorydetermineswhattypetocreatebasedonconguraAon,then
        asksthattypesproxytoconstructinstancefortheuser
 Constructcomponentsandobjectsusingcreatenotnew
    componentsshouldbecreatedduringbuildphaseofparent
   component_type::type_id::create(name,this);
   object_type::type_id::create(name,this);
 Usetypebasedoverridemechanisms
   set_type_override_by_type(...);                     do not use
                                                     name-based API
   set_inst_override_by_type(...);
original_type::type_id::set_type_override(override_type);
    original_type::type_id::set_inst_override(override_type,...);
     usingcomponentfactorymethods
set_type_override_by_type(original_type,override_type);
set_inst_override_by_type(...,original_type,override_type);
Factoryconstructsoverridedescriptorandaddstoaqueue:
if (!this.get_config_object("field",value)) `uvm_fatal(...)
 UVMthesearemappedtocong_db,e.g.(simplicaAon)
   function void set_config_object("inst","field",value);
     uvm_config_db#(uvm_object)::set(this,"inst","field",value);
   endfunction
 InUVMitisrecommendedtousecong_dbexplicitly
   uvm_config_db#(my_type)::set(cntxt,"inst","field",value);
 Implementsstringbasedlookuptablesinadatabase
    set methods do not configure targeted component fields directly
 buildphaseforcomponentbaseclassautomaAcally
   conguresalleldsregisteredusingeldmacros
    function void uvm_component::build_phase(...);
      apply_config_settings(..); // search for fields & configure
   endfunction
 buildphaseforderivedcompsmustcallsuper.build
    class my_comp extends uvm_component;
                          missing field-macro results in no auto-config
      `uvm_component_utils_begin(my_comp)
        `uvm_field_int(my_field,UVM_DEFAULT)
      ...
                          missing super.build results in no auto-config
      function void build_phase(...);
        super.build_phase(..);
        // class-specific build operations like create
so set_config* can come before or after the create for corresponding component!
  do not confuse create (which tells the factory to new original or override type)
      with build phase (which is top-down dynamic building of environment)
                 Verilab & Accellera       23
 InteracAonofFactory,Cong&Build
                                                     test
class my_test extends uvm_test;
                                                    env
  function new(..);
                                                     test
  function void build_phase(..);
                                                    comp
    env = my_env::type_id::create(env,this);
    obj = my_obj::type_id::create(obj,this);       obj
    set_type_overide_by_type(my_comp,test_comp);
    set_config_object(env,obj,obj,0);
  endfunction                                        obj
endclass
                                                    factory
class my_env extends uvm_env;                        test
  `uvm_field_object(obj,UVM_DEFAULT)                comp
  function void build_phase(..);
    super.build_phase(..);
    if (obj==null) `uvm_fatal(..)                    db
    comp = my_comp::type_id::create(comp,this);
  endfunction                                        obj
endclass
      JonathanBromley,VerilabLtd
       MarkLi=erick,VerilabGmbH
                    
   =ac#veagent
                                                       agent
   implemen&ngaprotocol                                      C
                                                 sqr
 S&mulusdrivenintoDUT           sequence
                                                             monitored
                                                              items
   byadriver                         items
                                             driver          monitor
 S&mulusdatasenttodriver
   fromasequencer
 Runsequencesonsequencer
   tomakeinteres&ngac&vity             DUTobj
obj
                                                                               monitored
                                                          sequence              items
S6mulusitemneedsaddi&onal items
driver monitor
   constraintsandcontrolknobs
class vbus_seq_item extends vbus_item;
  rand bit only_IO_space;                 Bus protocol controls only!
  constraint c_restrict_IO {                 Class is part of uVC
    only_IO_space -> (addr >= 'hFC00);  NO distribution constraints
  } ...                                 NO DUT-specific strategy
                                                                              sqr
    block_size inside {1,2,4,8,16};
                                                                                        monitored
    addr % block_size == 0;              NO distribution constraints sequence              items
                                                                       items
  }                                    NO DUT-specific strategy            driver       monitor
  rand vbus_seq_item item;
  task body();
    for (int beat=0; beat<block_size; beat++) begin
      `uvm_do_with( item,
          {addr==base_addr+beat; dir==WR;} )
    end
  endtask    Behaviour is meaningful even without any external constraint
  ...
                                                             virtualsequencer
 class smoke_test extends dut_test;
   `uvm_component_utils(smoke_test)
                                                         S  vbus
                                                                S           I2C
   smoke_test_seq test_seq;                                
                                                             UVC
                                                                
                                                                            UVC
                                                                              
   base_dut_env env;                                     D  M   D             M
   ...
   task run_phase(uvm_phase phase);
     ...
     test_seq = smoke_test_seq::type_id::create("smoke_test");
     ...
     test_seq.start(env.top_sequencer); start(null) is possible
     ...
configure/randomize the test seq
                                   2
            Verilab & Accellera       2
REGISTERMODELOVERVIEW
          R2
            ...                                                                   R1
                                                                          MEM
  MAP    RN
                            C       BUS UVC
                                                                                  R2
R3
                                                              INTERFACE
                                                                                   ...
                                                VIF
         ADAPTER             S          D                            NORMALLY AUTO-
                                                                           GENERATED
                                                                                  RX
                                                                                   ...
                                                VIF
 PREDICTOR                               M                            DUE TO REGULAR
                          AGENT                                                   RN
                                                                     STRUCTURE AND LARGE SIZE
 SetofDUTspeciclesthatextenduvm_reg*base
 Instan9atedinenvalongsidebusinterfaceUVCs
    adapterconvertsgenericread/writetobustransac9ons
    predictorupdatesmodelbasedonobservedtransac9ons
                                                      5
                   Verilab & Accellera                   5
                RegisterModelConcepts
 REG MODEL                                   ENV                       DUT
          R1                       SEQ
  MEM                    VS                      C                            CPU   F/W
          R2                             BACKDOOR ACCESS
            ...                                                                 R1
                                                                       MEM
  MAP    RN
                            C       BUS UVC
                                                                                R2
R3
                                                           INTERFACE
                                          FRONT-DOOR ACCESS                      ...
                                             VIF
         ADAPTER             S          D
                                                                              VOLATILE
                                                                                RX    UPDATE
                                                                                 ...
                                             VIF
 PREDICTOR                               M ACTIVE MONITORING
                          AGENT                                                 RN
 NormalfrontdooraccessviabustransacKon&I/F
    sneakybackdooraccessviahdl_pathnobustransac9on
 VolaKleeldsmodiedbynonbusRTLfunc9onality
    modelupdatedusingacKvemonitoringviahdl_path
                                                   6
                   Verilab & Accellera                6
          Ac9ve&PassiveOpera9on
 REG MODEL                                     ENV                       DUT
          R1                      SEQ
  MEM                   VS                         C                               CPU   F/W
     1 R2...      2                                                          3   R1
                                                                         MEM
  MAP    RN
                           C       BUS UVC
                                                                                     R2
R3
                                                             INTERFACE
                                                                                      ...
                                               VIF
         ADAPTER            S          D
                                                                                     RX
                                                                                      ...
                                               VIF
 PREDICTOR                              M
                         AGENT                                                       RN
 Modelmusttolerateac9ve&passiveopera9ons:
   1.   acKvemodelread/writegeneratesitemsviaadapter
   2.   passivebehaviorwhenasequencedoesnotusemodel
   3.   passivebehaviorwhenembeddedCPUupdatesregister
                                                     7
                  Verilab & Accellera                   7
               RegisterAccessAPI
                              stimulus                     result
  configure()
                                                 reset()     REG MODEL
                              m_reset
  randomize()                                          m_mirrored
                                 value
     set()                                                          predict()
write(),update(),poke() read(),mirror(),peek()
 Usecasecanberegisteroreldcentric
    constrainedrandoms9mulustypicallyregistercentric
      e.g.reg.randomize();reg.update();
    directedorhigherlevelscenariostypicallyeldcentric
      e.g.object.randomize();eld.write(object.var.value);
                                         8
              Verilab & Accellera           8
           RegisterFieldModeling
 Fieldaccesspolicy               modify on write       modify on read
    selfcontained                           REG
      opera9onson
      thisregistereld             W                 FIELD        R
                                      field value           field operation
 FieldinteracKon
                                      W               SOURCE          R
    betweendierent
      registerelds
                          W            AFFECTED R
 Registeraccessrightsinassociatedmemorymap
 Modelfunc9onalbehaviorofDUTforvolaKleelds
                                       9
               Verilab & Accellera        9
                   FieldAccessPolicies
 Comprehensivepredenedeldaccesspolicies
                   NO        WRITE           WRITE         WRITE    WRITE     WRITE
                  WRITE      VALUE           CLEAR          SET    TOGGLE     ONCE
     NO
                           WO          WOC           WOS                   WO1
    READ
                                          WC            WS
    READ                                                              W1T
             RO             RW          W1C           W1S                     W1
    VALUE                                                             W0T
                                          W0C           W0S
                                                         WSRC
    READ                                                                   Just defining  access
             RC             WRC                      W1SRC                  
    CLEAR
                                                         W0SRC             policy is not enough!
                                          WCRS
    READ                                                                   Must also
             RS             WRS         W1CRS                               implement
     SET
                                          W0CRS                             special behavior!
 Userdenedeldaccesspoliciescanbeadded
local static bit m = uvm_reg_field::define_access(UDAP);
if(!uvm_reg_field::define_access(UDAP)) `uvm_error(...)
                                                  10
                   Verilab & Accellera             10
                 Hooks&Callbacks
 Fieldbaseclasshasemptyvirtualmethodhooks
    implementinderivedeldtospecializebehavior
   class my_reg_field extends uvm_reg_field;               pre_write
     virtual task post_write(item rw);                     post_write
       // specific implementation                          pre_read
     endtask                                               post_read
 Callbackbaseclasshasemptyvirtualmethods
    implementinderivedcallback®isteritwitheld
   class my_field_cb extends uvm_reg_cbs;                  pre_write
     function new(string name, ...);                       post_write
     virtual task post_write(item   rw); callback
                         most important                    pre_read
       // specific implementation                          post_read
                          for passive operation is
     endtask                                               post_predict
                                            post_predict
                                                           encode
   my_field_cb my_cb = new("my_cb", ...);                  decode
   uvm_reg_field_cb::add(regX.fieldY, my_cb);
                                     11
              Verilab & Accellera     11
       Hook&CallbackExecu9on
 Fieldmethodhooksarealwaysexecuted
 Callbackmethodsareonlyexecutedifregistered
   task uvm_reg_field::do_write(item rw);
     ...
                                                 ACTUAL WRITE
     rw.local_map.do_write(rw);
     ...                                        HOOK METHOD
     post_write(rw);
     for (uvm_reg_cbs cb=cbs.first();
           cb!=null;
                                       CALLBACK METHOD
           cb=cbs.next())
                                    FOR ALL REGISTERED CBS
       cb.post_write(rw);
     ...
   endtask      callbacks registered with field using add
                  multiple callbacks can be registered with field
                  callback methods executed in cbs queue order
                                     12
              Verilab & Accellera     12
MODELINGEXAMPLES
              W                       WRES           R
 Exampleuserdenedeldaccesspolicy
    predenedaccesspoliciesforWritetoClear/Set(WC,WS)
    userdenedpolicyrequiredforWritetoReset(WRES)
    uvm_reg_field::define_access(WRES)
 Demonstratethreepossiblesolu9ons:
    post_writehookimplementa9oninderivedeld
    post_writeimplementa9onincallback
    post_predictimplementa9onincallback
                                    14
             Verilab & Accellera     14
    WRESUsingpost_writeHook
 class wres_field_t extends uvm_reg_field;
  ...                                           DERIVED FIELD
  virtual task post_write(uvm_reg_item rw);
   if (!predict(rw.get_reset())) `uvm_error(..)
                                      IMPLEMENT post_write TO
  endtask
NOT PASSIVE                         SET MIRROR TO RESET VALUE
                 W                    PROTECTED          R
              W           LOCK      R
 ExampleregistereldinteracKon
    protectedeldbehaviorbasedonstateoflockeld,or
    lockeldoperaKonmodiesbehaviorofprotectedeld
 Demonstratetwopossiblesolu9ons:
    post_predictimplementa9onincallback
    dynamiceldaccesspolicycontrolledbycallback
    (notbadpre_writeimplementa9onfromUVMUserGuide)
                                      18
             Verilab & Accellera       18
  LockUsingpost_predictCallback
class prot_field_cb extends uvm_reg_cbs;
                                               HANDLE TO
 local uvm_reg_field lock_field;               LOCK FIELD
 function new (string name, uvm_reg_field lock);
  super.new (name);
  this.lock_field = lock;
 endfunction
 virtual function void post_predict(..previous,value);
  if (kind == UVM_PREDICT_WRITE)
   if (lock_field.get())             REVERT TO PREVIOUS
    value = previous;                VALUE IF LOCK ACTIVE
 endfunction
                                     CONNECT LOCK FIELD
class my_reg_block extends uvm_reg_block;
 prot_field_cb prot_cb = new(prot_cb, lock_field);
 uvm_reg_field_cb::add(prot_field, prot_cb);
                                     REGISTER CALLBACK
                                    WITH PROTECTED FIELD
                                  19
           Verilab & Accellera     19
   LockUsingDynamicAccessPolicy
class lock_field_cb extends uvm_reg_cbs;
                                                HANDLE TO
 local uvm_reg_field prot_field;              PROTECTED FIELD
 function new (string name, uvm_reg_field prot);
  super.new (name);
  this.prot_field = prot;
 endfunction
                                          SET ACCESS POLICY FOR
 virtual function void post_predict(...);
                                     PROTECTED FIELD BASED ON
  if (kind == UVM_PREDICT_WRITE)          LOCK OPERATION
   if (value)
    void'(prot_field.set_access("RO"));
   else                                prot_field.get_access()
    void'(prot_field.set_access("RW"));
                                    RETURNS CURRENT POLICY
 endfunction
     REGISTER CALLBACK
       WITH LOCK FIELD                   CONNECT PROTECTED FIELD
class my_reg_block extends uvm_reg_block;
 lock_field_cb lock_cb = new(lock_cb, prot_field);
 uvm_reg_field_cb::add(lock_field, lock_cb);
                                  20
           Verilab & Accellera     20
         BueredWriteExample
           write to buffer                     read from current
W BUFFER
           copy on write
             to trigger
                                    CURRENT      R
                                    TRIGGER
                       W                          R
 ExampleregistereldinteracKon
    triggereldoperaKoneectsbueredeldbehavior
 Demonstratetwopossiblesolu9ons:
    overlappedregisterimplementa9onwithcallback
    derivedbuereldcontrolledbymul9plecallbacks
                                    21
             Verilab & Accellera     21
    BueredWriteUsing2Registers
                                                            HANDLES TO BOTH
 class trig_field_cb extends uvm_reg_cbs;
                                       CURRENT & BUFFER FIELDS
  local uvm_reg_field current, buffer;
  function new (string name, uvm_reg_field current,
                             uvm_reg_field buffer);
   ...                             COPY FROM BUFFER TO CURRENT
  virtual function void post_predict(...);
                                        ON WRITE TO TRIGGER
   if (kind == UVM_PREDICT_WRITE) begin
    uvm_reg_data_t val = buffer.get_mirrored_value();
    if (!current.predict(val)) `uvm_error(...)
                               RO & WO REGISTER AT SAME ADDRESS
                                             all writes go to WO buffer
  class my_reg_block extends uvm_reg_block;
                                       all reads come from RO current
   ...
   default_map.add_reg(cur_reg, 'h10, "RO");
   default_map.add_reg(buf_reg, 'h10, "WO");
   ...
 cannot share address again     REGISTER CALLBACK WITH TRIGGER FIELD
   trig_field_cb      trig_cb
 complicated to generate    = new(
       trig_cb,
 confusing          cur_reg.cur_field, buf_reg.buf_field);
             map for user
   uvm_reg_field_cb::add(trig_field, trig_cb);
                                     22
              Verilab & Accellera     22
  BueredWriteUsingDerivedField
class buf_reg_field extends uvm_reg_field;
 uvm_reg_data_t buffer;              ADD BUFFER TO DERIVED FIELD
 virtual function void reset(string kind);
  super.reset(kind);           RESET BUFFER TO FIELD RESET VALUE
  buffer = get_reset(kind);
                                           post_predict callback
class buf_field_cb extends uvm_reg_cbs;
                                            required for passive
 local buf_reg_field buf_field;
 virtual function void post_predict(...); // if write
  buf_field.buffer = value;SET BUFFER TO VALUE ON WRITE TO FIELD,
  value = previous;         SET MIRROR TO PREVIOUS (UNCHANGED)
class trig_field_cb extends uvm_reg_cbs;
 local buf_reg_field buf_field;        COPY BUFFER TO MIRROR
 virtual function void post_predict(...);ON// if write
                                            WRITE TO TRIGGER
  buf_field.predict(buf_field.buffer);
                                          REGISTER CALLBACKS WITH
buf_field_cb buf_cb = new(buf_cb,buf_field);
                                    BUFFERED & TRIGGER FIELDS
uvm_reg_field_cb::add(buf_field, buf_cb);
trig_field_cb trig_cb = new(trig_cb,buf_field);
uvm_reg_field_cb::add(trig_field, trig_cb);
                                   23
            Verilab & Accellera     23
    RegisterSideEectsExample
 Randomizeormodifyregisters&recongureDUT
    whataboutUVCconguraKon?
        updatefromregistersequences                not passive
                                                                        VIF
             R2
                                  cfg.set_var(val);
                                                           S    D
               ...
      MAP                                                        M
                                                                        VIF
             RN
                                                          AGENT
                                          ENV
                                           24
               Verilab & Accellera          24
   CongUpdateUsingCallback
class reg_cfg_cb extends uvm_reg_cbs;
 my_config cfg;                     HANDLE TO CONFIG OBJECT
 function new (string name, my_config cfg);
  super.new (name);
  this.cfg = cfg;
 endfunction                           SET CONFIG ON WRITE
 virtual function void post_predict(...);TO REGISTER FIELD
                                      (TRANSLATE IF REQUIRED)
  if (kind == UVM_PREDICT_WRITE)
   cfg.set_var(my_enum_t'(value));
 endfunction
                                            ENVIRONMENT HAS
class my_env extends uvm_env;             UVC & REG_MODEL
 ...
 uvc = my_uvc::type_id::create(...);       CONNECT CONFIG
 reg_model = my_reg_block::type_id::create(...);
 ...                                     REGISTER CALLBACK
 reg_cfg_cb cfg_cb = new(cfg_cb, uvc.cfg);
 uvm_reg_field_cb::add(reg_model.reg.field, cfg_cb);
                           25
REGISTERMODELPERFORMANCE
                                    32
             Verilab & Accellera     32
                        Ques9ons