OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [seq/] [uvm_sequencer_base.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//----------------------------------------------------------------------
2
//   Copyright 2007-2011 Mentor Graphics Corporation
3
//   Copyright 2007-2011 Cadence Design Systems, Inc.
4
//   Copyright 2010-2011 Synopsys, Inc.
5
//   Copyright 2013-2014 NVIDIA Corporation
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License for the specific language governing
20
//   permissions and limitations under the License.
21
//----------------------------------------------------------------------
22
 
23
typedef uvm_config_db#(uvm_sequence_base) uvm_config_seq;
24
typedef class uvm_sequence_request;
25
 
26
// Utility class for tracking default_sequences
27
class uvm_sequence_process_wrapper;
28
    process pid;
29
    uvm_sequence_base seq;
30
endclass : uvm_sequence_process_wrapper
31
 
32
//------------------------------------------------------------------------------
33
//
34
// CLASS: uvm_sequencer_base
35
//
36
// Controls the flow of sequences, which generate the stimulus (sequence item
37
// transactions) that is passed on to drivers for execution.
38
//
39
//------------------------------------------------------------------------------
40
 
41
class uvm_sequencer_base extends uvm_component;
42
 
43
  typedef enum {SEQ_TYPE_REQ,
44
                SEQ_TYPE_LOCK,
45
                SEQ_TYPE_GRAB} seq_req_t; // FIXME SEQ_TYPE_GRAB is unused
46
 
47
// queue of sequences waiting for arbitration
48
  protected uvm_sequence_request arb_sequence_q[$];
49
 
50
  protected bit                 arb_completed[int];
51
 
52
  protected uvm_sequence_base   lock_list[$];
53
  protected uvm_sequence_base   reg_sequences[int];
54
  protected int                 m_sequencer_id;
55
  protected int                 m_lock_arb_size;  // used for waiting processes
56
  protected int                 m_arb_size;       // used for waiting processes
57
  protected int                 m_wait_for_item_sequence_id,
58
                                m_wait_for_item_transaction_id;
59
  protected int                 m_wait_relevant_count = 0 ;
60
  protected int                 m_max_zero_time_wait_relevant_count = 10;
61
  protected time                m_last_wait_relevant_time = 0 ;
62
 
63
  local uvm_sequencer_arb_mode  m_arbitration = UVM_SEQ_ARB_FIFO;
64
  local static int              g_request_id;
65
  local static int              g_sequence_id = 1;
66
  local static int              g_sequencer_id = 1;
67
 
68
 
69
  // Function: new
70
  //
71
  // Creates and initializes an instance of this class using the normal
72
  // constructor arguments for uvm_component: name is the name of the
73
  // instance, and parent is the handle to the hierarchical parent.
74
 
75
  extern function new (string name, uvm_component parent);
76
 
77
 
78
  // Function: is_child
79
  //
80
  // Returns 1 if the child sequence is a child of the parent sequence,
81
  // 0 otherwise.
82
  //
83
  extern function bit is_child (uvm_sequence_base parent, uvm_sequence_base child);
84
 
85
 
86
  // Function: user_priority_arbitration
87
  //
88
  // When the sequencer arbitration mode is set to UVM_SEQ_ARB_USER (via the
89
  //  method), the sequencer will call this function each
90
  // time that it needs to arbitrate among sequences.
91
  //
92
  // Derived sequencers may override this method to perform a custom arbitration
93
  // policy. The override must return one of the entries from the
94
  // avail_sequences queue, which are indexes into an internal queue,
95
  // arb_sequence_q.
96
  //
97
  // The default implementation behaves like UVM_SEQ_ARB_FIFO, which returns the
98
  // entry at avail_sequences[0].
99
  //
100
  extern virtual function integer user_priority_arbitration(integer avail_sequences[$]);
101
 
102
 
103
  // Task: execute_item
104
  //
105
  // Executes the given transaction ~item~ directly on this sequencer. A temporary
106
  // parent sequence is automatically created for the ~item~.  There is no capability to
107
  // retrieve responses. If the driver returns responses, they will accumulate in the
108
  // sequencer, eventually causing response overflow unless
109
  //  is called.
110
 
111
  extern virtual task execute_item(uvm_sequence_item item);
112
 
113
  // Hidden array, keeps track of running default sequences
114
  protected uvm_sequence_process_wrapper m_default_sequences[uvm_phase];
115
 
116
  // Function: start_phase_sequence
117
  //
118
  // Start the default sequence for this phase, if any.
119
  // The default sequence is configured via resources using
120
  // either a sequence instance or sequence type (object wrapper).
121
  // If both are used,
122
  // the sequence instance takes precedence. When attempting to override
123
  // a previous default sequence setting, you must override both
124
  // the instance and type (wrapper) resources, else your override may not
125
  // take effect.
126
  //
127
  // When setting the resource using ~set~, the 1st argument specifies the
128
  // context pointer, usually ~this~ for components or ~null~ when executed from
129
  // outside the component hierarchy (i.e. in module).
130
  // The 2nd argument is the instance string, which is a path name to the
131
  // target sequencer, relative to the context pointer.  The path must include
132
  // the name of the phase with a "_phase" suffix. The 3rd argument is the
133
  // resource name, which is "default_sequence". The 4th argument is either
134
  // an object wrapper for the sequence type, or an instance of a sequence.
135
  //
136
  // Configuration by instances
137
  // allows pre-initialization, setting rand_mode, use of inline
138
  // constraints, etc.
139
  //
140
  //| myseq_t myseq = new("myseq");
141
  //| myseq.randomize() with { ... };
142
  //| uvm_config_db #(uvm_sequence_base)::set(null, "top.agent.myseqr.main_phase",
143
  //|                                         "default_sequence",
144
  //|                                         myseq);
145
  //
146
  // Configuration by type is shorter and can be substituted via
147
  // the factory.
148
  //
149
  //| uvm_config_db #(uvm_object_wrapper)::set(null, "top.agent.myseqr.main_phase",
150
  //|                                          "default_sequence",
151
  //|                                          myseq_type::type_id::get());
152
  //
153
  // The uvm_resource_db can similarly be used.
154
  //
155
  //| myseq_t myseq = new("myseq");
156
  //| myseq.randomize() with { ... };
157
  //| uvm_resource_db #(uvm_sequence_base)::set({get_full_name(), ".myseqr.main_phase",
158
  //|                                           "default_sequence",
159
  //|                                           myseq, this);
160
  //
161
  //| uvm_resource_db #(uvm_object_wrapper)::set({get_full_name(), ".myseqr.main_phase",
162
  //|                                            "default_sequence",
163
  //|                                            myseq_t::type_id::get(),
164
  //|                                            this );
165
  //
166
  //
167
 
168
 
169
 
170
  extern virtual function void start_phase_sequence(uvm_phase phase);
171
 
172
  // Function: stop_phase_sequence
173
  //
174
  // Stop the default sequence for this phase, if any exists, and it
175
  // is still executing.
176
 
177
  extern virtual function void stop_phase_sequence(uvm_phase phase);
178
 
179
 
180
 
181
  // Task: wait_for_grant
182
  //
183
  // This task issues a request for the specified sequence.  If item_priority
184
  // is not specified, then the current sequence priority will be used by the
185
  // arbiter.  If a lock_request is made, then the  sequencer will issue a lock
186
  // immediately before granting the sequence.  (Note that the lock may be
187
  // granted without the sequence being granted if is_relevant is not asserted).
188
  //
189
  // When this method returns, the sequencer has granted the sequence, and the
190
  // sequence must call send_request without inserting any simulation delay
191
  // other than delta cycles.  The driver is currently waiting for the next
192
  // item to be sent via the send_request call.
193
 
194
  extern virtual task wait_for_grant(uvm_sequence_base sequence_ptr,
195
                                     int item_priority = -1,
196
                                     bit lock_request = 0);
197
 
198
 
199
  // Task: wait_for_item_done
200
  //
201
  // A sequence may optionally call wait_for_item_done.  This task will block
202
  // until the driver calls item_done() or put() on a transaction issued by the
203
  // specified sequence.  If no transaction_id parameter is specified, then the
204
  // call will return the next time that the driver calls item_done() or put().
205
  // If a specific transaction_id is specified, then the call will only return
206
  // when the driver indicates that it has completed that specific item.
207
  //
208
  // Note that if a specific transaction_id has been specified, and the driver
209
  // has already issued an item_done or put for that transaction, then the call
210
  // will hang waiting for that specific transaction_id.
211
  //
212
  extern virtual task wait_for_item_done(uvm_sequence_base sequence_ptr,
213
                                         int transaction_id);
214
 
215
 
216
  // Function: is_blocked
217
  //
218
  // Returns 1 if the sequence referred to by sequence_ptr is currently locked
219
  // out of the sequencer.  It will return 0 if the sequence is currently
220
  // allowed to issue operations.
221
  //
222
  // Note that even when a sequence is not blocked, it is possible for another
223
  // sequence to issue a lock before this sequence is able to issue a request
224
  // or lock.
225
  //
226
  extern function bit is_blocked(uvm_sequence_base sequence_ptr);
227
 
228
 
229
  // Function: has_lock
230
  //
231
  // Returns 1 if the sequence referred to in the parameter currently has a lock
232
  // on this sequencer, 0 otherwise.
233
  //
234
  // Note that even if this sequence has a lock, a child sequence may also have
235
  // a lock, in which case the sequence is still blocked from issuing
236
  // operations on the sequencer
237
  //
238
  extern function bit has_lock(uvm_sequence_base sequence_ptr);
239
 
240
 
241
  // Task: lock
242
  //
243
  // Requests a lock for the sequence specified by sequence_ptr.
244
  //
245
  // A lock request will be arbitrated the same as any other request. A lock is
246
  // granted after all earlier requests are completed and no other locks or
247
  // grabs are blocking this sequence.
248
  //
249
  // The lock call will return when the lock has been granted.
250
  //
251
  extern virtual task lock(uvm_sequence_base sequence_ptr);
252
 
253
 
254
  // Task: grab
255
  //
256
  // Requests a lock for the sequence specified by sequence_ptr.
257
  //
258
  // A grab request is put in front of the arbitration queue. It will be
259
  // arbitrated before any other requests. A grab is granted when no other
260
  // grabs or locks are blocking this sequence.
261
  //
262
  // The grab call will return when the grab has been granted.
263
  //
264
  extern virtual task grab(uvm_sequence_base sequence_ptr);
265
 
266
 
267
  // Function: unlock
268
  //
269
  // Removes any locks and grabs obtained by the specified sequence_ptr.
270
  //
271
  extern virtual function void unlock(uvm_sequence_base sequence_ptr);
272
 
273
 
274
  // Function: ungrab
275
  //
276
  // Removes any locks and grabs obtained by the specified sequence_ptr.
277
  //
278
  extern virtual function void  ungrab(uvm_sequence_base sequence_ptr);
279
 
280
 
281
  // Function: stop_sequences
282
  //
283
  // Tells the sequencer to kill all sequences and child sequences currently
284
  // operating on the sequencer, and remove all requests, locks and responses
285
  // that are currently queued.  This essentially resets the sequencer to an
286
  // idle state.
287
  //
288
  extern virtual function void stop_sequences();
289
 
290
 
291
  // Function: is_grabbed
292
  //
293
  // Returns 1 if any sequence currently has a lock or grab on this sequencer,
294
  // 0 otherwise.
295
  //
296
  extern virtual function bit is_grabbed();
297
 
298
 
299
  // Function: current_grabber
300
  //
301
  // Returns a reference to the sequence that currently has a lock or grab on
302
  // the sequence.  If multiple hierarchical sequences have a lock, it returns
303
  // the child that is currently allowed to perform operations on the sequencer.
304
  //
305
  extern virtual function uvm_sequence_base current_grabber();
306
 
307
 
308
  // Function: has_do_available
309
  //
310
  // Returns 1 if any sequence running on this sequencer is ready to supply a
311
  // transaction, 0 otherwise. A sequence is ready if it is not blocked (via
312
  // ~grab~ or ~lock~ and ~is_relevant~ returns 1.
313
  //
314
  extern virtual function bit has_do_available();
315
 
316
 
317
  // Function: set_arbitration
318
  //
319
  // Specifies the arbitration mode for the sequencer. It is one of
320
  //
321
  // UVM_SEQ_ARB_FIFO          - Requests are granted in FIFO order (default)
322
  // UVM_SEQ_ARB_WEIGHTED      - Requests are granted randomly by weight
323
  // UVM_SEQ_ARB_RANDOM        - Requests are granted randomly
324
  // UVM_SEQ_ARB_STRICT_FIFO   - Requests at highest priority granted in FIFO order
325
  // UVM_SEQ_ARB_STRICT_RANDOM - Requests at highest priority granted in randomly
326
  // UVM_SEQ_ARB_USER          - Arbitration is delegated to the user-defined
327
  //                             function, user_priority_arbitration. That function
328
  //                             will specify the next sequence to grant.
329
  //
330
  // The default user function specifies FIFO order.
331
  //
332
  extern function void set_arbitration(UVM_SEQ_ARB_TYPE val);
333
 
334
 
335
  // Function: get_arbitration
336
  //
337
  // Return the current arbitration mode set for this sequencer. See
338
  //  for a list of possible modes.
339
  //
340
  extern function UVM_SEQ_ARB_TYPE get_arbitration();
341
 
342
 
343
  // Task: wait_for_sequences
344
  //
345
  // Waits for a sequence to have a new item available. Uses
346
  //  to give a sequence as much time as
347
  // possible to deliver an item before advancing time.
348
 
349
  extern virtual task wait_for_sequences();
350
 
351
 
352
  // Function: send_request
353
  //
354
  // Derived classes implement this function to send a request item to the
355
  // sequencer, which will forward it to the driver.  If the rerandomize bit
356
  // is set, the item will be randomized before being sent to the driver.
357
  //
358
  // This function may only be called after a  call.
359
 
360
  extern virtual function void send_request(uvm_sequence_base sequence_ptr,
361
                                            uvm_sequence_item t,
362
                                            bit rerandomize = 0);
363
 
364
  // Function: set_max_zero_time_wait_relevant_count
365
  //
366
  // Can be called at any time to change the maximum number of times
367
  // wait_for_relevant() can be called by the sequencer in zero time before
368
  // an error is declared.  The default maximum is 10.
369
  extern virtual function void set_max_zero_time_wait_relevant_count(int new_val) ;
370
 
371
 
372
  //----------------------------------------------------------------------------
373
  // INTERNAL METHODS - DO NOT CALL DIRECTLY, ONLY OVERLOAD IF VIRTUAL
374
  //----------------------------------------------------------------------------
375
 
376
  extern protected function void grant_queued_locks();
377
 
378
 
379
  extern protected task          m_select_sequence();
380
  extern protected function int  m_choose_next_request();
381
  extern           task          m_wait_for_arbitration_completed(int request_id);
382
  extern           function void m_set_arbitration_completed(int request_id);
383
 
384
 
385
  extern local task m_lock_req(uvm_sequence_base sequence_ptr, bit lock);
386
 
387
 
388
  // Task- m_unlock_req
389
  //
390
  // Called by a sequence to request an unlock.  This
391
  // will remove a lock for this sequence if it exists
392
 
393
  extern function void m_unlock_req(uvm_sequence_base sequence_ptr);
394
 
395
 
396
  extern local function void remove_sequence_from_queues(uvm_sequence_base sequence_ptr);
397
  extern function void m_sequence_exiting(uvm_sequence_base sequence_ptr);
398
  extern function void kill_sequence(uvm_sequence_base sequence_ptr);
399
 
400
  extern virtual function void analysis_write(uvm_sequence_item t);
401
 
402
 
403
  extern virtual   function void   build();
404
  extern virtual   function void   build_phase(uvm_phase phase);
405
  extern           function void   do_print (uvm_printer printer);
406
 
407
 
408
  extern virtual   function int    m_register_sequence(uvm_sequence_base sequence_ptr);
409
  extern protected
410
           virtual function void   m_unregister_sequence(int sequence_id);
411
  extern protected function
412
                 uvm_sequence_base m_find_sequence(int sequence_id);
413
 
414
  extern protected function void   m_update_lists();
415
  extern           function string convert2string();
416
  extern protected
417
           virtual function int    m_find_number_driver_connections();
418
  extern protected task            m_wait_arb_not_equal();
419
  extern protected task            m_wait_for_available_sequence();
420
  extern protected function int    m_get_seq_item_priority(uvm_sequence_request seq_q_entry);
421
 
422
  int m_is_relevant_completed;
423
 
424
 
425
`ifdef UVM_DISABLE_AUTO_ITEM_RECORDING
426
  local bit m_auto_item_recording = 0;
427
`else
428
  local bit m_auto_item_recording = 1;
429
`endif
430
 
431
 
432
  // Access to following internal methods provided via seq_item_export
433
 
434
  virtual function void disable_auto_item_recording();
435
    m_auto_item_recording = 0;
436
  endfunction
437
 
438
  virtual function bit is_auto_item_recording_enabled();
439
    return m_auto_item_recording;
440
  endfunction
441
 
442
  //----------------------------------------------------------------------------
443
  // DEPRECATED - DO NOT USE IN NEW DESIGNS - NOT PART OF UVM STANDARD
444
  //----------------------------------------------------------------------------
445
 
446
`ifndef UVM_NO_DEPRECATED
447
  // Variable- count
448
  //
449
  // Sets the number of items to execute.
450
  //
451
  // Supercedes the max_random_count variable for uvm_random_sequence class
452
  // for backward compatibility.
453
 
454
  int count = -1;
455
 
456
  int m_random_count;
457
  int m_exhaustive_count;
458
  int m_simple_count;
459
 
460
  int unsigned max_random_count = 10;
461
  int unsigned max_random_depth = 4;
462
 
463
  protected string default_sequence = "uvm_random_sequence";
464
  protected bit m_default_seq_set;
465
 
466
 
467
  string sequences[$];
468
  protected int sequence_ids[string];
469
  protected rand int seq_kind;
470
 
471
  extern function void              add_sequence(string type_name);
472
  extern function void              remove_sequence(string type_name);
473
  extern function void              set_sequences_queue(ref string sequencer_sequence_lib[$]);
474
  extern virtual task               start_default_sequence();
475
  extern function int               get_seq_kind(string type_name);
476
  extern function uvm_sequence_base get_sequence(int req_kind);
477
  extern function int               num_sequences();
478
  extern virtual function void      m_add_builtin_seqs(bit add_simple = 1);
479
  extern virtual task               run_phase(uvm_phase phase);
480
`endif
481
 
482
endclass
483
 
484
 
485
 
486
 
487
//------------------------------------------------------------------------------
488
// IMPLEMENTATION
489
//------------------------------------------------------------------------------
490
 
491
 
492
// new
493
// ---
494
 
495
function uvm_sequencer_base::new (string name, uvm_component parent);
496
  super.new(name, parent);
497
  m_sequencer_id = g_sequencer_id++;
498
  m_lock_arb_size = -1;
499
endfunction
500
 
501
 
502
// build_phase
503
// -----------
504
 
505
function void uvm_sequencer_base::build_phase(uvm_phase phase);
506
  // For mantis 3402, the config stuff must be done in the deprecated
507
  // build() phase in order for a manual build call to work. Both
508
  // the manual build call and the config settings in build() are
509
  // deprecated.
510
  super.build_phase(phase);
511
endfunction
512
 
513
 
514
function void uvm_sequencer_base::build();
515
  int dummy;
516
  super.build();
517
  `ifndef UVM_NO_DEPRECATED
518
  // deprecated parameters for sequencer. Use uvm_sequence_library class
519
  // for sequence library functionality.
520
  if (uvm_config_string::get(this, "", "default_sequence", default_sequence)) begin
521
    `uvm_warning("UVM_DEPRECATED",{"default_sequence config parameter is deprecated and not ",
522
                 "part of the UVM standard. See documentation for uvm_sequencer_base::start_phase_sequence()."})
523
    this.m_default_seq_set = 1;
524
  end
525
  if (uvm_config_int::get(this, "", "count", count)) begin
526
    `uvm_warning("UVM_DEPRECATED",{"count config parameter is deprecated and not ",
527
                 "part of the UVM standard"})
528
  end
529
  if (uvm_config_int::get(this, "", "max_random_count", max_random_count)) begin
530
    `uvm_warning("UVM_DEPRECATED",{"count config parameter is deprecated and not ",
531
                 "part of the UVM standard"})
532
  end
533
  if (uvm_config_int::get(this, "", "max_random_depth", max_random_depth)) begin
534
    `uvm_warning("UVM_DEPRECATED",{"max_random_depth config parameter is deprecated and not ",
535
                 "part of the UVM standard. Use 'uvm_sequence_library' class for ",
536
                 "sequence library functionality"})
537
  end
538
  if (uvm_config_int::get(this, "", "pound_zero_count", dummy))
539
    `uvm_warning("UVM_DEPRECATED",
540
      {"pound_zero_count was set but ignored. ",
541
       "Sequencer/driver synchronization now uses 'uvm_wait_for_nba_region'"})
542
  `endif // UVM_NO_DEPRECATED
543
endfunction
544
 
545
 
546
// do_print
547
// --------
548
 
549
function void uvm_sequencer_base::do_print (uvm_printer printer);
550
  super.do_print(printer);
551
  printer.print_array_header("arbitration_queue", arb_sequence_q.size());
552
  foreach (arb_sequence_q[i])
553
    printer.print_string($sformatf("[%0d]", i),
554
       $sformatf("%s@seqid%0d",arb_sequence_q[i].request.name(),arb_sequence_q[i].sequence_id), "[");
555
  printer.print_array_footer(arb_sequence_q.size());
556
 
557
  printer.print_array_header("lock_queue", lock_list.size());
558
  foreach(lock_list[i])
559
    printer.print_string($sformatf("[%0d]", i),
560
       $sformatf("%s@seqid%0d",lock_list[i].get_full_name(),lock_list[i].get_sequence_id()), "[");
561
  printer.print_array_footer(lock_list.size());
562
endfunction
563
 
564
 
565
// m_update_lists
566
// --------------
567
 
568
function void uvm_sequencer_base::m_update_lists();
569
  m_lock_arb_size++;
570
endfunction
571
 
572
 
573
// convert2string
574
// ----------------
575
 
576
function string uvm_sequencer_base::convert2string();
577
  string s;
578
 
579
  $sformat(s, "  -- arb i/id/type: ");
580
  foreach (arb_sequence_q[i]) begin
581
    $sformat(s, "%s %0d/%0d/%s ", s, i, arb_sequence_q[i].sequence_id, arb_sequence_q[i].request.name());
582
  end
583
  $sformat(s, "%s\n -- lock_list i/id: ", s);
584
  foreach (lock_list[i]) begin
585
    $sformat(s, "%s %0d/%0d",s, i, lock_list[i].get_sequence_id());
586
  end
587
  return(s);
588
endfunction
589
 
590
 
591
 
592
// m_find_number_driver_connections
593
// --------------------------------
594
 
595
function int  uvm_sequencer_base::m_find_number_driver_connections();
596
  return 0;
597
endfunction
598
 
599
 
600
// m_register_sequence
601
// -------------------
602
 
603
function int uvm_sequencer_base::m_register_sequence(uvm_sequence_base sequence_ptr);
604
 
605
  if (sequence_ptr.m_get_sqr_sequence_id(m_sequencer_id, 1) > 0)
606
    return sequence_ptr.get_sequence_id();
607
 
608
  sequence_ptr.m_set_sqr_sequence_id(m_sequencer_id, g_sequence_id++);
609
  reg_sequences[sequence_ptr.get_sequence_id()] = sequence_ptr;
610
  return sequence_ptr.get_sequence_id();
611
endfunction
612
 
613
 
614
// m_find_sequence
615
// ---------------
616
 
617
function uvm_sequence_base uvm_sequencer_base::m_find_sequence(int sequence_id);
618
  uvm_sequence_base seq_ptr;
619
  int           i;
620
 
621
  // When sequence_id is -1, return the first available sequence.  This is used
622
  // when deleting all sequences
623
  if (sequence_id == -1) begin
624
    if (reg_sequences.first(i)) begin
625
      return(reg_sequences[i]);
626
    end
627
    return(null);
628
  end
629
 
630
  if (!reg_sequences.exists(sequence_id))
631
    return null;
632
  return reg_sequences[sequence_id];
633
endfunction
634
 
635
 
636
// m_unregister_sequence
637
// ---------------------
638
 
639
function void uvm_sequencer_base::m_unregister_sequence(int sequence_id);
640
  if (!reg_sequences.exists(sequence_id))
641
    return;
642
  reg_sequences.delete(sequence_id);
643
endfunction
644
 
645
 
646
// user_priority_arbitration
647
// -------------------------
648
 
649
function integer uvm_sequencer_base::user_priority_arbitration(integer avail_sequences[$]);
650
  return avail_sequences[0];
651
endfunction
652
 
653
 
654
// grant_queued_locks
655
// ------------------
656
// Any lock or grab requests that are at the front of the queue will be
657
// granted at the earliest possible time.  This function grants any queues
658
// at the front that are not locked out
659
 
660
function void uvm_sequencer_base::grant_queued_locks();
661
  // first remove sequences with dead lock control process
662
  begin
663
          uvm_sequence_request q[$];
664
          q = arb_sequence_q.find(item) with (item.request==SEQ_TYPE_LOCK && item.process_id.status inside {process::KILLED,process::FINISHED});
665
          foreach(q[idx]) begin
666
                `uvm_error("SEQLCKZMB", $sformatf("The task responsible for requesting a lock on sequencer '%s' for sequence '%s' has been killed, to avoid a deadlock the sequence will be removed from the arbitration queues", this.get_full_name(), q[idx].sequence_ptr.get_full_name()))
667
 
668
                remove_sequence_from_queues(q[idx].sequence_ptr);
669
          end
670
  end
671
 
672
  // now move all is_blocked() into lock_list
673
  begin
674
        uvm_sequence_request leading_lock_reqs[$],blocked_seqs[$],not_blocked_seqs[$];
675
        int q1[$];
676
        int b=arb_sequence_q.size(); // index for first non-LOCK request
677
        q1 = arb_sequence_q.find_first_index(item) with (item.request!=SEQ_TYPE_LOCK);
678
        if(q1.size())
679
                b=q1[0];
680
        if(b!=0) begin // at least one lock
681
                leading_lock_reqs = arb_sequence_q[0:b-1]; // set of locks; arb_sequence[b] is the first req!=SEQ_TYPE_LOCK
682
                // split into blocked/not-blocked requests
683
                foreach(leading_lock_reqs[i]) begin
684
                        uvm_sequence_request item = leading_lock_reqs[i];
685
                        if(is_blocked(item.sequence_ptr)!=0)
686
                                blocked_seqs.push_back(item);
687
                        else
688
                                not_blocked_seqs.push_back(item);
689
                end
690
 
691
                if(b>arb_sequence_q.size()-1)
692
                        arb_sequence_q=blocked_seqs;
693
                  else
694
                        arb_sequence_q={blocked_seqs,arb_sequence_q[b:arb_sequence_q.size()-1]};
695
 
696
                foreach(not_blocked_seqs[idx]) begin
697
                        lock_list.push_back(not_blocked_seqs[idx].sequence_ptr);
698
                        m_set_arbitration_completed(not_blocked_seqs[idx].request_id);
699
                end
700
 
701
                // trigger listeners if lock list has changed
702
                if(not_blocked_seqs.size())
703
                        m_update_lists();
704
        end
705
  end
706
endfunction
707
 
708
 
709
// m_select_sequence
710
// -----------------
711
 
712
task uvm_sequencer_base::m_select_sequence();
713
   int selected_sequence;
714
 
715
    // Select a sequence
716
    do begin
717
      wait_for_sequences();
718
      selected_sequence = m_choose_next_request();
719
      if (selected_sequence == -1) begin
720
        m_wait_for_available_sequence();
721
      end
722
    end while (selected_sequence == -1);
723
    // issue grant
724
    if (selected_sequence >= 0) begin
725
      m_set_arbitration_completed(arb_sequence_q[selected_sequence].request_id);
726
      arb_sequence_q.delete(selected_sequence);
727
      m_update_lists();
728
    end
729
endtask
730
 
731
 
732
// m_choose_next_request
733
// ---------------------
734
// When a driver requests an operation, this function must find the next
735
// available, unlocked, relevant sequence.
736
//
737
// This function returns -1 if no sequences are available or the entry into
738
// arb_sequence_q for the chosen sequence
739
 
740
function int uvm_sequencer_base::m_choose_next_request();
741
  int i, temp;
742
  int avail_sequence_count;
743
  int sum_priority_val;
744
  integer avail_sequences[$];
745
  integer highest_sequences[$];
746
  int highest_pri;
747
  string  s;
748
 
749
  avail_sequence_count = 0;
750
 
751
  grant_queued_locks();
752
 
753
  i = 0;
754
  while (i < arb_sequence_q.size()) begin
755
     if ((arb_sequence_q[i].process_id.status == process::KILLED) ||
756
         (arb_sequence_q[i].process_id.status == process::FINISHED)) begin
757
        `uvm_error("SEQREQZMB", $sformatf("The task responsible for requesting a wait_for_grant on sequencer '%s' for sequence '%s' has been killed, to avoid a deadlock the sequence will be removed from the arbitration queues", this.get_full_name(), arb_sequence_q[i].sequence_ptr.get_full_name()))
758
         remove_sequence_from_queues(arb_sequence_q[i].sequence_ptr);
759
         continue;
760
     end
761
 
762
    if (i < arb_sequence_q.size())
763
      if (arb_sequence_q[i].request == SEQ_TYPE_REQ)
764
        if (is_blocked(arb_sequence_q[i].sequence_ptr) == 0)
765
          if (arb_sequence_q[i].sequence_ptr.is_relevant() == 1) begin
766
            if (m_arbitration == UVM_SEQ_ARB_FIFO) begin
767
              return i;
768
            end
769
            else avail_sequences.push_back(i);
770
          end
771
 
772
    i++;
773
  end
774
 
775
  // Return immediately if there are 0 or 1 available sequences
776
  if (m_arbitration == UVM_SEQ_ARB_FIFO) begin
777
    return -1;
778
  end
779
  if (avail_sequences.size() < 1)  begin
780
    return -1;
781
  end
782
 
783
  if (avail_sequences.size() == 1) begin
784
    return avail_sequences[0];
785
  end
786
 
787
  // If any locks are in place, then the available queue must
788
  // be checked to see if a lock prevents any sequence from proceeding
789
  if (lock_list.size() > 0) begin
790
    for (i = 0; i < avail_sequences.size(); i++) begin
791
      if (is_blocked(arb_sequence_q[avail_sequences[i]].sequence_ptr) != 0) begin
792
        avail_sequences.delete(i);
793
        i--;
794
      end
795
    end
796
    if (avail_sequences.size() < 1)
797
      return -1;
798
    if (avail_sequences.size() == 1)
799
      return avail_sequences[0];
800
  end
801
 
802
  //  Weighted Priority Distribution
803
  // Pick an available sequence based on weighted priorities of available sequences
804
  if (m_arbitration == UVM_SEQ_ARB_WEIGHTED) begin
805
    sum_priority_val = 0;
806
    for (i = 0; i < avail_sequences.size(); i++) begin
807
      sum_priority_val += m_get_seq_item_priority(arb_sequence_q[avail_sequences[i]]);
808
    end
809
 
810
    temp = $urandom_range(sum_priority_val-1, 0);
811
 
812
    sum_priority_val = 0;
813
    for (i = 0; i < avail_sequences.size(); i++) begin
814
      if ((m_get_seq_item_priority(arb_sequence_q[avail_sequences[i]]) +
815
           sum_priority_val) > temp) begin
816
        return avail_sequences[i];
817
      end
818
      sum_priority_val += m_get_seq_item_priority(arb_sequence_q[avail_sequences[i]]);
819
    end
820
    uvm_report_fatal("Sequencer", "UVM Internal error in weighted arbitration code", UVM_NONE);
821
  end
822
 
823
  //  Random Distribution
824
  if (m_arbitration == UVM_SEQ_ARB_RANDOM) begin
825
    i = $urandom_range(avail_sequences.size()-1, 0);
826
    return avail_sequences[i];
827
  end
828
 
829
  //  Strict Fifo
830
  if ((m_arbitration == UVM_SEQ_ARB_STRICT_FIFO) || m_arbitration == UVM_SEQ_ARB_STRICT_RANDOM) begin
831
    highest_pri = 0;
832
    // Build a list of sequences at the highest priority
833
    for (i = 0; i < avail_sequences.size(); i++) begin
834
      if (m_get_seq_item_priority(arb_sequence_q[avail_sequences[i]]) > highest_pri) begin
835
        // New highest priority, so start new list
836
        highest_sequences.delete();
837
        highest_sequences.push_back(avail_sequences[i]);
838
        highest_pri = m_get_seq_item_priority(arb_sequence_q[avail_sequences[i]]);
839
      end
840
      else if (m_get_seq_item_priority(arb_sequence_q[avail_sequences[i]]) == highest_pri) begin
841
        highest_sequences.push_back(avail_sequences[i]);
842
      end
843
    end
844
 
845
    // Now choose one based on arbitration type
846
    if (m_arbitration == UVM_SEQ_ARB_STRICT_FIFO) begin
847
      return(highest_sequences[0]);
848
    end
849
 
850
    i = $urandom_range(highest_sequences.size()-1, 0);
851
    return highest_sequences[i];
852
  end
853
 
854
  if (m_arbitration == UVM_SEQ_ARB_USER) begin
855
    i = user_priority_arbitration( avail_sequences);
856
 
857
    // Check that the returned sequence is in the list of available sequences.  Failure to
858
    // use an available sequence will cause highly unpredictable results.
859
    highest_sequences = avail_sequences.find with (item == i);
860
    if (highest_sequences.size() == 0) begin
861
      uvm_report_fatal("Sequencer",
862
          $sformatf("Error in User arbitration, sequence %0d not available\n%s",
863
                    i, convert2string()), UVM_NONE);
864
    end
865
    return(i);
866
  end
867
 
868
  uvm_report_fatal("Sequencer", "Internal error: Failed to choose sequence", UVM_NONE);
869
 
870
endfunction
871
 
872
 
873
// m_wait_arb_not_equal
874
// --------------------
875
 
876
task uvm_sequencer_base::m_wait_arb_not_equal();
877
  wait (m_arb_size != m_lock_arb_size);
878
endtask
879
 
880
 
881
// m_wait_for_available_sequence
882
// -----------------------------
883
 
884
task uvm_sequencer_base::m_wait_for_available_sequence();
885
  int i;
886
  int is_relevant_entries[$];
887
 
888
  // This routine will wait for a change in the request list, or for
889
  // wait_for_relevant to return on any non-relevant, non-blocked sequence
890
  m_arb_size = m_lock_arb_size;
891
 
892
  for (i = 0; i < arb_sequence_q.size(); i++) begin
893
    if (arb_sequence_q[i].request == SEQ_TYPE_REQ) begin
894
      if (is_blocked(arb_sequence_q[i].sequence_ptr) == 0) begin
895
        if (arb_sequence_q[i].sequence_ptr.is_relevant() == 0) begin
896
          is_relevant_entries.push_back(i);
897
        end
898
      end
899
    end
900
  end
901
 
902
  // Typical path - don't need fork if all queued entries are relevant
903
  if (is_relevant_entries.size() == 0) begin
904
    m_wait_arb_not_equal();
905
    return;
906
  end
907
 
908
  fork  // isolate inner fork block for disabling
909
    begin
910
      fork
911
        begin
912
          fork
913
              begin
914
                // One path in fork is for any wait_for_relevant to return
915
                m_is_relevant_completed = 0;
916
 
917
                for(i = 0; i < is_relevant_entries.size(); i++) begin
918
                fork
919
                    automatic int k = i;
920
 
921
                  begin
922
                    arb_sequence_q[is_relevant_entries[k]].sequence_ptr.wait_for_relevant();
923
                    if ($realtime != m_last_wait_relevant_time) begin
924
                       m_last_wait_relevant_time = $realtime ;
925
                       m_wait_relevant_count = 0 ;
926
                    end
927
                    else begin
928
                       m_wait_relevant_count++ ;
929
                       if (m_wait_relevant_count > m_max_zero_time_wait_relevant_count) begin
930
                          `uvm_fatal("SEQRELEVANTLOOP",$sformatf("Zero time loop detected, passed wait_for_relevant %0d times without time advancing",m_wait_relevant_count))
931
                       end
932
                    end
933
                    m_is_relevant_completed = 1;
934
                  end
935
                join_none
936
 
937
                end
938
                wait (m_is_relevant_completed > 0);
939
              end
940
 
941
            // The other path in the fork is for any queue entry to change
942
            begin
943
              m_wait_arb_not_equal();
944
            end
945
          join_any
946
        end
947
      join_any
948
      disable fork;
949
    end
950
  join
951
endtask
952
 
953
 
954
// m_get_seq_item_priority
955
// -----------------------
956
 
957
function int uvm_sequencer_base::m_get_seq_item_priority(uvm_sequence_request seq_q_entry);
958
  // If the priority was set on the item, then that is used
959
  if (seq_q_entry.item_priority != -1) begin
960
    if (seq_q_entry.item_priority <= 0) begin
961
      uvm_report_fatal("SEQITEMPRI",
962
                    $sformatf("Sequence item from %s has illegal priority: %0d",
963
                            seq_q_entry.sequence_ptr.get_full_name(),
964
                            seq_q_entry.item_priority), UVM_NONE);
965
    end
966
    return seq_q_entry.item_priority;
967
  end
968
  // Otherwise, use the priority of the calling sequence
969
  if (seq_q_entry.sequence_ptr.get_priority() < 0) begin
970
    uvm_report_fatal("SEQDEFPRI",
971
                    $sformatf("Sequence %s has illegal priority: %0d",
972
                            seq_q_entry.sequence_ptr.get_full_name(),
973
                            seq_q_entry.sequence_ptr.get_priority()), UVM_NONE);
974
  end
975
  return seq_q_entry.sequence_ptr.get_priority();
976
endfunction
977
 
978
 
979
// m_wait_for_arbitration_completed
980
// --------------------------------
981
 
982
task uvm_sequencer_base::m_wait_for_arbitration_completed(int request_id);
983
  int lock_arb_size;
984
 
985
  // Search the list of arb_wait_q, see if this item is done
986
  forever
987
    begin
988
      lock_arb_size  = m_lock_arb_size;
989
 
990
      if (arb_completed.exists(request_id)) begin
991
        arb_completed.delete(request_id);
992
        return;
993
      end
994
      wait (lock_arb_size != m_lock_arb_size);
995
    end
996
endtask
997
 
998
 
999
// m_set_arbitration_completed
1000
// ---------------------------
1001
 
1002
function void uvm_sequencer_base::m_set_arbitration_completed(int request_id);
1003
  arb_completed[request_id] = 1;
1004
endfunction
1005
 
1006
 
1007
// is_child
1008
// --------
1009
 
1010
function bit uvm_sequencer_base::is_child (uvm_sequence_base parent,
1011
                                           uvm_sequence_base child);
1012
  uvm_sequence_base child_parent;
1013
 
1014
  if (child == null) begin
1015
    uvm_report_fatal("uvm_sequencer", "is_child passed null child", UVM_NONE);
1016
  end
1017
 
1018
  if (parent == null) begin
1019
    uvm_report_fatal("uvm_sequencer", "is_child passed null parent", UVM_NONE);
1020
  end
1021
 
1022
  child_parent = child.get_parent_sequence();
1023
  while (child_parent != null) begin
1024
    if (child_parent.get_inst_id() == parent.get_inst_id()) begin
1025
      return 1;
1026
    end
1027
    child_parent = child_parent.get_parent_sequence();
1028
  end
1029
  return 0;
1030
endfunction
1031
 
1032
 
1033
// execute_item
1034
// ------------
1035
 
1036
task uvm_sequencer_base::execute_item(uvm_sequence_item item);
1037
  uvm_sequence_base seq;
1038
 
1039
  seq = new();
1040
  item.set_sequencer(this);
1041
  item.set_parent_sequence(seq);
1042
  seq.set_sequencer(this);
1043
  seq.start_item(item);
1044
  seq.finish_item(item);
1045
endtask
1046
 
1047
 
1048
// wait_for_grant
1049
// --------------
1050
 
1051
task uvm_sequencer_base::wait_for_grant(uvm_sequence_base sequence_ptr,
1052
                                        int item_priority = -1,
1053
                                        bit lock_request = 0);
1054
  uvm_sequence_request req_s;
1055
  int my_seq_id;
1056
 
1057
  if (sequence_ptr == null)
1058
    uvm_report_fatal("uvm_sequencer",
1059
       "wait_for_grant passed null sequence_ptr", UVM_NONE);
1060
 
1061
  my_seq_id = m_register_sequence(sequence_ptr);
1062
 
1063
  // If lock_request is asserted, then issue a lock.  Don't wait for the response, since
1064
  // there is a request immediately following the lock request
1065
  if (lock_request == 1) begin
1066
    req_s = new();
1067
    req_s.grant = 0;
1068
    req_s.sequence_id = my_seq_id;
1069
    req_s.request = SEQ_TYPE_LOCK;
1070
    req_s.sequence_ptr = sequence_ptr;
1071
    req_s.request_id = g_request_id++;
1072
    req_s.process_id = process::self();
1073
    arb_sequence_q.push_back(req_s);
1074
  end
1075
 
1076
  // Push the request onto the queue
1077
  req_s = new();
1078
  req_s.grant = 0;
1079
  req_s.request = SEQ_TYPE_REQ;
1080
  req_s.sequence_id = my_seq_id;
1081
  req_s.item_priority = item_priority;
1082
  req_s.sequence_ptr = sequence_ptr;
1083
  req_s.request_id = g_request_id++;
1084
  req_s.process_id = process::self();
1085
  arb_sequence_q.push_back(req_s);
1086
  m_update_lists();
1087
 
1088
  // Wait until this entry is granted
1089
  // Continue to point to the element, since location in queue will change
1090
  m_wait_for_arbitration_completed(req_s.request_id);
1091
 
1092
  // The wait_for_grant_semaphore is used only to check that send_request
1093
  // is only called after wait_for_grant.  This is not a complete check, since
1094
  // requests might be done in parallel, but it will catch basic errors
1095
  req_s.sequence_ptr.m_wait_for_grant_semaphore++;
1096
 
1097
endtask
1098
 
1099
 
1100
// wait_for_item_done
1101
// ------------------
1102
 
1103
task uvm_sequencer_base::wait_for_item_done(uvm_sequence_base sequence_ptr,
1104
                                            int transaction_id);
1105
  int sequence_id;
1106
 
1107
  sequence_id = sequence_ptr.m_get_sqr_sequence_id(m_sequencer_id, 1);
1108
  m_wait_for_item_sequence_id = -1;
1109
  m_wait_for_item_transaction_id = -1;
1110
 
1111
  if (transaction_id == -1)
1112
    wait (m_wait_for_item_sequence_id == sequence_id);
1113
  else
1114
    wait ((m_wait_for_item_sequence_id == sequence_id &&
1115
           m_wait_for_item_transaction_id == transaction_id));
1116
endtask
1117
 
1118
 
1119
// is_blocked
1120
// ----------
1121
 
1122
function bit uvm_sequencer_base::is_blocked(uvm_sequence_base sequence_ptr);
1123
 
1124
  if (sequence_ptr == null)
1125
    uvm_report_fatal("uvm_sequence_controller",
1126
                     "is_blocked passed null sequence_ptr", UVM_NONE);
1127
 
1128
    foreach (lock_list[i]) begin
1129
      if ((lock_list[i].get_inst_id() !=
1130
           sequence_ptr.get_inst_id()) &&
1131
          (is_child(lock_list[i], sequence_ptr) == 0)) begin
1132
        return 1;
1133
      end
1134
    end
1135
    return 0;
1136
endfunction
1137
 
1138
 
1139
// has_lock
1140
// --------
1141
 
1142
function bit uvm_sequencer_base::has_lock(uvm_sequence_base sequence_ptr);
1143
  int my_seq_id;
1144
 
1145
  if (sequence_ptr == null)
1146
    uvm_report_fatal("uvm_sequence_controller",
1147
                     "has_lock passed null sequence_ptr", UVM_NONE);
1148
  my_seq_id = m_register_sequence(sequence_ptr);
1149
    foreach (lock_list[i]) begin
1150
      if (lock_list[i].get_inst_id() == sequence_ptr.get_inst_id()) begin
1151
        return 1;
1152
      end
1153
    end
1154
  return 0;
1155
endfunction
1156
 
1157
 
1158
// m_lock_req
1159
// ----------
1160
// Internal method. Called by a sequence to request a lock.
1161
// Puts the lock request onto the arbitration queue.
1162
 
1163
task uvm_sequencer_base::m_lock_req(uvm_sequence_base sequence_ptr, bit lock);
1164
  int my_seq_id;
1165
  uvm_sequence_request new_req;
1166
 
1167
  if (sequence_ptr == null)
1168
    uvm_report_fatal("uvm_sequence_controller",
1169
                     "lock_req passed null sequence_ptr", UVM_NONE);
1170
 
1171
  my_seq_id = m_register_sequence(sequence_ptr);
1172
  new_req = new();
1173
  new_req.grant = 0;
1174
  new_req.sequence_id = sequence_ptr.get_sequence_id();
1175
  new_req.request = SEQ_TYPE_LOCK;
1176
  new_req.sequence_ptr = sequence_ptr;
1177
  new_req.request_id = g_request_id++;
1178
  new_req.process_id = process::self();
1179
 
1180
  if (lock == 1) begin
1181
    // Locks are arbitrated just like all other requests
1182
    arb_sequence_q.push_back(new_req);
1183
  end else begin
1184
    // Grabs are not arbitrated - they go to the front
1185
    // TODO:
1186
    // Missing: grabs get arbitrated behind other grabs
1187
    arb_sequence_q.push_front(new_req);
1188
    m_update_lists();
1189
  end
1190
 
1191
  // If this lock can be granted immediately, then do so.
1192
  grant_queued_locks();
1193
 
1194
  m_wait_for_arbitration_completed(new_req.request_id);
1195
endtask
1196
 
1197
 
1198
// m_unlock_req
1199
// ------------
1200
// Called by a sequence to request an unlock.  This
1201
// will remove a lock for this sequence if it exists
1202
 
1203
function void uvm_sequencer_base::m_unlock_req(uvm_sequence_base sequence_ptr);
1204
  if (sequence_ptr == null) begin
1205
    uvm_report_fatal("uvm_sequencer",
1206
                     "m_unlock_req passed null sequence_ptr", UVM_NONE);
1207
  end
1208
 
1209
  begin
1210
          int q[$];
1211
          int seqid=sequence_ptr.get_inst_id();
1212
          q=lock_list.find_first_index(item) with (item.get_inst_id() == seqid);
1213
          if(q.size()==1) begin
1214
              lock_list.delete(q[0]);
1215
                  grant_queued_locks(); // grant lock requests
1216
                  m_update_lists();
1217
          end
1218
          else
1219
                  uvm_report_warning("SQRUNL",
1220
           {"Sequence '", sequence_ptr.get_full_name(),
1221
            "' called ungrab / unlock, but didn't have lock"}, UVM_NONE);
1222
 
1223
  end
1224
endfunction
1225
 
1226
 
1227
// lock
1228
// ----
1229
 
1230
task uvm_sequencer_base::lock(uvm_sequence_base sequence_ptr);
1231
  m_lock_req(sequence_ptr, 1);
1232
endtask
1233
 
1234
 
1235
// grab
1236
// ----
1237
 
1238
task uvm_sequencer_base::grab(uvm_sequence_base sequence_ptr);
1239
  m_lock_req(sequence_ptr, 0);
1240
endtask
1241
 
1242
 
1243
// unlock
1244
// ------
1245
 
1246
function void uvm_sequencer_base::unlock(uvm_sequence_base sequence_ptr);
1247
  m_unlock_req(sequence_ptr);
1248
endfunction
1249
 
1250
 
1251
// ungrab
1252
// ------
1253
 
1254
function void  uvm_sequencer_base::ungrab(uvm_sequence_base sequence_ptr);
1255
  m_unlock_req(sequence_ptr);
1256
endfunction
1257
 
1258
 
1259
// remove_sequence_from_queues
1260
// ---------------------------
1261
 
1262
function void uvm_sequencer_base::remove_sequence_from_queues(
1263
                                       uvm_sequence_base sequence_ptr);
1264
  int i;
1265
  int seq_id;
1266
 
1267
  seq_id = sequence_ptr.m_get_sqr_sequence_id(m_sequencer_id, 0);
1268
 
1269
  // Remove all queued items for this sequence and any child sequences
1270
  i = 0;
1271
  do
1272
    begin
1273
      if (arb_sequence_q.size() > i) begin
1274
        if ((arb_sequence_q[i].sequence_id == seq_id) ||
1275
            (is_child(sequence_ptr, arb_sequence_q[i].sequence_ptr))) begin
1276
          if (sequence_ptr.get_sequence_state() == UVM_FINISHED)
1277
            `uvm_error("SEQFINERR", $sformatf("Parent sequence '%s' should not finish before all items from itself and items from descendent sequences are processed.  The item request from the sequence '%s' is being removed.", sequence_ptr.get_full_name(), arb_sequence_q[i].sequence_ptr.get_full_name()))
1278
          arb_sequence_q.delete(i);
1279
          m_update_lists();
1280
        end
1281
        else begin
1282
          i++;
1283
        end
1284
      end
1285
    end
1286
  while (i < arb_sequence_q.size());
1287
 
1288
  // remove locks for this sequence, and any child sequences
1289
  i = 0;
1290
  do
1291
    begin
1292
      if (lock_list.size() > i) begin
1293
        if ((lock_list[i].get_inst_id() == sequence_ptr.get_inst_id()) ||
1294
            (is_child(sequence_ptr, lock_list[i]))) begin
1295
          if (sequence_ptr.get_sequence_state() == UVM_FINISHED)
1296
            `uvm_error("SEQFINERR", $sformatf("Parent sequence '%s' should not finish before locks from itself and descedent sequences are removed.  The lock held by the child sequence '%s' is being removed.",sequence_ptr.get_full_name(), lock_list[i].get_full_name()))
1297
          lock_list.delete(i);
1298
          m_update_lists();
1299
        end
1300
        else begin
1301
          i++;
1302
        end
1303
      end
1304
    end
1305
  while (i < lock_list.size());
1306
 
1307
  // Unregister the sequence_id, so that any returning data is dropped
1308
  m_unregister_sequence(sequence_ptr.m_get_sqr_sequence_id(m_sequencer_id, 1));
1309
endfunction
1310
 
1311
 
1312
// stop_sequences
1313
// --------------
1314
 
1315
function void uvm_sequencer_base::stop_sequences();
1316
  uvm_sequence_base seq_ptr;
1317
 
1318
  seq_ptr = m_find_sequence(-1);
1319
  while (seq_ptr != null)
1320
    begin
1321
      kill_sequence(seq_ptr);
1322
      seq_ptr = m_find_sequence(-1);
1323
    end
1324
endfunction
1325
 
1326
 
1327
// m_sequence_exiting
1328
// ------------------
1329
 
1330
function void uvm_sequencer_base::m_sequence_exiting(uvm_sequence_base sequence_ptr);
1331
  remove_sequence_from_queues(sequence_ptr);
1332
endfunction
1333
 
1334
 
1335
// kill_sequence
1336
// -------------
1337
 
1338
function void uvm_sequencer_base::kill_sequence(uvm_sequence_base sequence_ptr);
1339
  remove_sequence_from_queues(sequence_ptr);
1340
  sequence_ptr.m_kill();
1341
endfunction
1342
 
1343
 
1344
// is_grabbed
1345
// ----------
1346
 
1347
function bit uvm_sequencer_base::is_grabbed();
1348
  return (lock_list.size() != 0);
1349
endfunction
1350
 
1351
 
1352
// current_grabber
1353
// ---------------
1354
 
1355
function uvm_sequence_base uvm_sequencer_base::current_grabber();
1356
  if (lock_list.size() == 0) begin
1357
    return null;
1358
  end
1359
  return lock_list[lock_list.size()-1];
1360
endfunction
1361
 
1362
 
1363
// has_do_available
1364
// ----------------
1365
 
1366
function bit uvm_sequencer_base::has_do_available();
1367
 
1368
  foreach (arb_sequence_q[i]) begin
1369
    if ((arb_sequence_q[i].sequence_ptr.is_relevant() == 1) &&
1370
        (is_blocked(arb_sequence_q[i].sequence_ptr) == 0)) begin
1371
      return 1;
1372
    end
1373
  end
1374
  return 0;
1375
endfunction
1376
 
1377
 
1378
// set_arbitration
1379
// ---------------
1380
 
1381
function void uvm_sequencer_base::set_arbitration(UVM_SEQ_ARB_TYPE val);
1382
  m_arbitration = val;
1383
endfunction
1384
 
1385
 
1386
// get_arbitration
1387
// ---------------
1388
 
1389
function UVM_SEQ_ARB_TYPE uvm_sequencer_base::get_arbitration();
1390
  return m_arbitration;
1391
endfunction
1392
 
1393
 
1394
// analysis_write
1395
// --------------
1396
 
1397
function void uvm_sequencer_base::analysis_write(uvm_sequence_item t);
1398
  return;
1399
endfunction
1400
 
1401
 
1402
// wait_for_sequences
1403
// ------------------
1404
 
1405
task uvm_sequencer_base::wait_for_sequences();
1406
  uvm_wait_for_nba_region();
1407
endtask
1408
 
1409
 
1410
 
1411
// send_request
1412
// ------------
1413
 
1414
function void uvm_sequencer_base::send_request(uvm_sequence_base sequence_ptr,
1415
                                               uvm_sequence_item t,
1416
                                               bit rerandomize = 0);
1417
  return;
1418
endfunction
1419
 
1420
 
1421
// set_max_zero_time_wait_relevant_count
1422
// ------------
1423
 
1424
function void uvm_sequencer_base::set_max_zero_time_wait_relevant_count(int new_val) ;
1425
   m_max_zero_time_wait_relevant_count = new_val ;
1426
endfunction
1427
 
1428
 
1429
// start_phase_sequence
1430
// --------------------
1431
 
1432
function void uvm_sequencer_base::start_phase_sequence(uvm_phase phase);
1433
  uvm_resource_pool            rp = uvm_resource_pool::get();
1434
  uvm_resource_types::rsrc_q_t rq;
1435
  uvm_sequence_base            seq;
1436
  uvm_coreservice_t cs = uvm_coreservice_t::get();
1437
  uvm_factory                  f = cs.get_factory();
1438
 
1439
  // Has a default sequence been specified?
1440
  rq = rp.lookup_name({get_full_name(), ".", phase.get_name(), "_phase"},
1441
                      "default_sequence", null, 0);
1442
  uvm_resource_pool::sort_by_precedence(rq);
1443
 
1444
  // Look for the first one if the appropriate type
1445
  for (int i = 0; seq == null && i < rq.size(); i++) begin
1446
    uvm_resource_base rsrc = rq.get(i);
1447
 
1448
    uvm_resource#(uvm_sequence_base)  sbr;
1449
    uvm_resource#(uvm_object_wrapper) owr;
1450
 
1451
    // uvm_config_db#(uvm_sequence_base)?
1452
    // Priority is given to uvm_sequence_base because it is a specific sequence instance
1453
    // and thus more specific than one that is dynamically created via the
1454
    // factory and the object wrapper.
1455
    if ($cast(sbr, rsrc) && sbr != null) begin
1456
      seq = sbr.read(this);
1457
      if (seq == null) begin
1458
        `uvm_info("UVM/SQR/PH/DEF/SB/NULL", {"Default phase sequence for phase '",
1459
                                             phase.get_name(),"' explicitly disabled"}, UVM_FULL)
1460
        return;
1461
      end
1462
    end
1463
 
1464
    // uvm_config_db#(uvm_object_wrapper)?
1465
    else if ($cast(owr, rsrc) && owr != null) begin
1466
      uvm_object_wrapper wrapper;
1467
 
1468
      wrapper = owr.read(this);
1469
      if (wrapper == null) begin
1470
        `uvm_info("UVM/SQR/PH/DEF/OW/NULL", {"Default phase sequence for phase '",
1471
                                             phase.get_name(),"' explicitly disabled"}, UVM_FULL)
1472
        return;
1473
      end
1474
 
1475
      if (!$cast(seq, f.create_object_by_type(wrapper, get_full_name(),
1476
                                              wrapper.get_type_name()))
1477
          || seq == null) begin
1478
        `uvm_warning("PHASESEQ", {"Default sequence for phase '",
1479
                                  phase.get_name(),"' %s is not a sequence type"})
1480
        return;
1481
      end
1482
    end
1483
  end
1484
 
1485
  if (seq == null) begin
1486
    `uvm_info("PHASESEQ", {"No default phase sequence for phase '",
1487
                           phase.get_name(),"'"}, UVM_FULL)
1488
    return;
1489
  end
1490
 
1491
  `uvm_info("PHASESEQ", {"Starting default sequence '",
1492
                         seq.get_type_name(),"' for phase '", phase.get_name(),"'"}, UVM_FULL)
1493
 
1494
  seq.print_sequence_info = 1;
1495
  seq.set_sequencer(this);
1496
  seq.reseed();
1497
  seq.set_starting_phase(phase);
1498
 
1499
  if (!seq.do_not_randomize && !seq.randomize()) begin
1500
    `uvm_warning("STRDEFSEQ", {"Randomization failed for default sequence '",
1501
                               seq.get_type_name(),"' for phase '", phase.get_name(),"'"})
1502
    return;
1503
  end
1504
 
1505
  fork begin
1506
    uvm_sequence_process_wrapper w = new();
1507
    // reseed this process for random stability
1508
    w.pid = process::self();
1509
    w.seq = seq;
1510
    w.pid.srandom(uvm_create_random_seed(seq.get_type_name(), this.get_full_name()));
1511
    m_default_sequences[phase] = w;
1512
    // this will either complete naturally, or be killed later
1513
    seq.start(this);
1514
    m_default_sequences.delete(phase);
1515
  end
1516
  join_none
1517
 
1518
endfunction
1519
 
1520
// stop_phase_sequence
1521
// --------------------
1522
 
1523
function void uvm_sequencer_base::stop_phase_sequence(uvm_phase phase);
1524
    if (m_default_sequences.exists(phase)) begin
1525
        `uvm_info("PHASESEQ",
1526
                  {"Killing default sequence '", m_default_sequences[phase].seq.get_type_name(),
1527
                   "' for phase '", phase.get_name(), "'"}, UVM_FULL)
1528
        m_default_sequences[phase].seq.kill();
1529
    end
1530
    else begin
1531
        `uvm_info("PHASESEQ",
1532
                  {"No default sequence to kill for phase '", phase.get_name(), "'"},
1533
                  UVM_FULL)
1534
    end
1535
endfunction : stop_phase_sequence
1536
 
1537
 
1538
//----------------------------------------------------------------------------
1539
//
1540
//                              *** DEPRECATED ***
1541
//
1542
//                        - DO NOT USE IN NEW DESIGNS -
1543
//
1544
//                        - NOT PART OF UVM STANDARD -
1545
//----------------------------------------------------------------------------
1546
 
1547
`ifndef UVM_NO_DEPRECATED
1548
 
1549
// add_sequence
1550
// ------------
1551
//
1552
// Adds a sequence of type specified in the type_name paramter to the
1553
// sequencer's sequence library.
1554
 
1555
function void uvm_sequencer_base::add_sequence(string type_name);
1556
 
1557
  `uvm_warning("UVM_DEPRECATED",{"Registering sequence '",type_name,
1558
     "' with sequencer '",get_full_name(),"' is deprecated. "})
1559
 
1560
  //assign typename key to an int based on size
1561
  //used with get_seq_kind to return an int key to match a type name
1562
  if (!sequence_ids.exists(type_name)) begin
1563
    sequence_ids[type_name] = sequences.size();
1564
    //used w/ get_sequence to return a uvm_sequence factory object that
1565
    //matches an int id
1566
    sequences.push_back(type_name);
1567
  end
1568
endfunction
1569
 
1570
 
1571
// remove_sequence
1572
// ---------------
1573
 
1574
function void uvm_sequencer_base::remove_sequence(string type_name);
1575
  sequence_ids.delete(type_name);
1576
  for (int i = 0; i < this.sequences.size(); i++) begin
1577
    if (this.sequences[i] == type_name)
1578
      this.sequences.delete(i);
1579
  end
1580
endfunction
1581
 
1582
 
1583
// set_sequences_queue
1584
// -------------------
1585
 
1586
function void uvm_sequencer_base::set_sequences_queue(
1587
                                    ref string sequencer_sequence_lib[$]);
1588
 
1589
  for(int j=0; j < sequencer_sequence_lib.size(); j++) begin
1590
    sequence_ids[sequencer_sequence_lib[j]] = sequences.size();
1591
    this.sequences.push_back(sequencer_sequence_lib[j]);
1592
  end
1593
endfunction
1594
 
1595
 
1596
// start_default_sequence
1597
// ----------------------
1598
// Called when the run phase begins, this method starts the default sequence,
1599
// as specified by the default_sequence member variable.
1600
//
1601
 
1602
task uvm_sequencer_base::start_default_sequence();
1603
  uvm_sequence_base m_seq ;
1604
  uvm_coreservice_t cs = uvm_coreservice_t::get();
1605
  uvm_factory factory=cs.get_factory();
1606
 
1607
  // Default sequence was cleared, or the count is zero
1608
  if (default_sequence == "" || count == 0 ||
1609
        (sequences.size() == 0 && default_sequence == "uvm_random_sequence"))
1610
    return;
1611
 
1612
  // Have run-time phases and no user setting of default sequence
1613
  if(this.m_default_seq_set == 0 && m_domain != null) begin
1614
    default_sequence = "";
1615
    `uvm_info("NODEFSEQ", {"The \"default_sequence\" has not been set. ",
1616
       "Since this sequencer has a runtime phase schedule, the ",
1617
       "uvm_random_sequence is not being started for the run phase."}, UVM_HIGH)
1618
    return;
1619
  end
1620
 
1621
  // Have a user setting for both old and new default sequence mechanisms
1622
  if (this.m_default_seq_set == 1 &&
1623
     (uvm_config_db #(uvm_sequence_base)::exists(this, "run_phase", "default_sequence", 0) ||
1624
      uvm_config_db #(uvm_object_wrapper)::exists(this, "run_phase", "default_sequence", 0)))
1625
  begin
1626
    `uvm_warning("MULDEFSEQ", {"A default phase sequence has been set via the ",
1627
       "\".default_sequence\" configuration option.",
1628
       "The deprecated \"default_sequence\" configuration option is ignored."})
1629
    return;
1630
  end
1631
 
1632
  // no user sequences to choose from
1633
  if(sequences.size() == 2 &&
1634
     sequences[0] == "uvm_random_sequence" &&
1635
     sequences[1] == "uvm_exhaustive_sequence") begin
1636
    uvm_report_warning("NOUSERSEQ", {"No user sequence available. ",
1637
                       "Not starting the (deprecated) default sequence."}, UVM_HIGH);
1638
    return;
1639
  end
1640
 
1641
        `uvm_warning("UVM_DEPRECATED",{"Starting (deprecated) default sequence '",default_sequence,
1642
     "' on sequencer '",get_full_name(),
1643
     "'. See documentation for uvm_sequencer_base::start_phase_sequence() for information on ",
1644
     "starting default sequences in UVM."})
1645
 
1646
    //create the sequence object
1647
    if (!$cast(m_seq, factory.create_object_by_name(default_sequence,
1648
                                            get_full_name(), default_sequence)))
1649
      begin
1650
        uvm_report_fatal("FCTSEQ",{"Default sequence set to invalid value : ",
1651
                                   default_sequence}, UVM_NONE);
1652
      end
1653
 
1654
    if (m_seq == null) begin
1655
      uvm_report_fatal("STRDEFSEQ", "Null m_sequencer reference", UVM_NONE);
1656
    end
1657
    m_seq.set_starting_phase(run_ph);
1658
    m_seq.print_sequence_info = 1;
1659
    m_seq.set_parent_sequence(null);
1660
    m_seq.set_sequencer(this);
1661
    m_seq.reseed();
1662
    if (!m_seq.randomize()) begin
1663
      uvm_report_warning("STRDEFSEQ", "Failed to randomize sequence");
1664
    end
1665
    m_seq.start(this);
1666
endtask
1667
 
1668
 
1669
// get_seq_kind
1670
// ------------
1671
// Returns an int seq_kind correlating to the sequence of type type_name
1672
// in the sequencers sequence library. If the named sequence is not
1673
// registered a SEQNF warning is issued and -1 is returned.
1674
 
1675
function int uvm_sequencer_base::get_seq_kind(string type_name);
1676
 
1677
  `uvm_warning("UVM_DEPRECATED", $sformatf("%m is deprecated"))
1678
 
1679
  if (sequence_ids.exists(type_name))
1680
    return sequence_ids[type_name];
1681
 
1682
  `uvm_warning("SEQNF",
1683
    {"Sequence type_name '",type_name,"' not registered with this sequencer."})
1684
 
1685
  return -1;
1686
endfunction
1687
 
1688
 
1689
// get_sequence
1690
// ------------
1691
// Returns a reference to a sequence specified by the seq_kind int.
1692
// The seq_kind int may be obtained using the get_seq_kind() method.
1693
 
1694
function uvm_sequence_base uvm_sequencer_base::get_sequence(int req_kind);
1695
  uvm_coreservice_t cs = uvm_coreservice_t::get();
1696
  uvm_factory factory = cs.get_factory();
1697
  uvm_sequence_base m_seq ;
1698
  string m_seq_type;
1699
 
1700
  `uvm_warning("UVM_DEPRECATED", $sformatf("%m is deprecated"))
1701
 
1702
  if (req_kind < 0 || req_kind >= sequences.size()) begin
1703
    uvm_report_error("SEQRNG",
1704
      $sformatf("Kind arg '%0d' out of range. Need 0-%0d",
1705
      req_kind, sequences.size()-1));
1706
  end
1707
 
1708
  m_seq_type = sequences[req_kind];
1709
  if (!$cast(m_seq, factory.create_object_by_name(m_seq_type,
1710
                                          get_full_name(),
1711
                                          m_seq_type)))
1712
  begin
1713
      uvm_report_fatal("FCTSEQ",
1714
        $sformatf("Factory cannot produce a sequence of type %0s.",
1715
        m_seq_type), UVM_NONE);
1716
  end
1717
 
1718
  m_seq.print_sequence_info = 1;
1719
  m_seq.set_sequencer (this);
1720
  return m_seq;
1721
 
1722
endfunction
1723
 
1724
 
1725
// num_sequences
1726
// -------------
1727
 
1728
function int uvm_sequencer_base::num_sequences();
1729
  return sequences.size();
1730
endfunction
1731
 
1732
 
1733
// m_add_builtin_seqs
1734
// ------------------
1735
 
1736
function void uvm_sequencer_base::m_add_builtin_seqs(bit add_simple=1);
1737
  if(!sequence_ids.exists("uvm_random_sequence"))
1738
    add_sequence("uvm_random_sequence");
1739
  if(!sequence_ids.exists("uvm_exhaustive_sequence"))
1740
    add_sequence("uvm_exhaustive_sequence");
1741
  if(add_simple == 1) begin
1742
    if(!sequence_ids.exists("uvm_simple_sequence"))
1743
      add_sequence("uvm_simple_sequence");
1744
  end
1745
endfunction
1746
 
1747
 
1748
// run_phase
1749
// ---------
1750
 
1751
task uvm_sequencer_base::run_phase(uvm_phase phase);
1752
  super.run_phase(phase);
1753
  start_default_sequence();
1754
endtask
1755
 
1756
 
1757
`endif // UVM_NO_DEPRECATED
1758
 
1759
//------------------------------------------------------------------------------
1760
//
1761
// Class- uvm_sequence_request
1762
//
1763
//------------------------------------------------------------------------------
1764
 
1765
class uvm_sequence_request;
1766
  bit        grant;
1767
  int        sequence_id;
1768
  int        request_id;
1769
  int        item_priority;
1770
  process    process_id;
1771
  uvm_sequencer_base::seq_req_t  request;
1772
  uvm_sequence_base sequence_ptr;
1773
endclass
1774
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.