-
Notifications
You must be signed in to change notification settings - Fork 15
/
uvm_reg_map.svh
2224 lines (1754 loc) · 71.2 KB
/
uvm_reg_map.svh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -------------------------------------------------------------
// Copyright 2004-2011 Synopsys, Inc.
// Copyright 2010-2011 Mentor Graphics Corporation
// Copyright 2010-2011 Cadence Design Systems, Inc.
// All Rights Reserved Worldwide
//
// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of
// the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in
// writing, software distributed under the License is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See
// the License for the specific language governing
// permissions and limitations under the License.
// -------------------------------------------------------------
//
class uvm_reg_map_info;
uvm_reg_addr_t offset;
string rights;
bit unmapped;
uvm_reg_addr_t addr[];
uvm_reg_frontdoor frontdoor;
uvm_reg_map_addr_range mem_range;
// if set marks the uvm_reg_map_info as initialized, prevents using an uninitialized map (for instance if the model
// has not been locked accidently and the maps have not been computed before)
bit is_initialized;
endclass
// Class: uvm_reg_transaction_order_policy
virtual class uvm_reg_transaction_order_policy extends uvm_object;
function new(string name = "policy");
super.new(name);
endfunction
// Function: order
// the order() function may reorder the sequence of bus transactions
// produced by a single uvm_reg transaction (read/write).
// This can be used in scenarios when the register width differs from
// the bus width and one register access results in a series of bus transactions.
// the first item (0) of the queue will be the first bus transaction (the last($)
// will be the final transaction
pure virtual function void order(ref uvm_reg_bus_op q[$]);
endclass
//------------------------------------------------------------------------------
//
// Class: uvm_reg_map
//
// :Address map abstraction class
//
// This class represents an address map.
// An address map is a collection of registers and memories
// accessible via a specific physical interface.
// Address maps can be composed into higher-level address maps.
//
// Address maps are created using the <uvm_reg_block::create_map()>
// method.
//------------------------------------------------------------------------------
class uvm_reg_map extends uvm_object;
`uvm_object_utils(uvm_reg_map)
// info that is valid only if top-level map
local uvm_reg_addr_t m_base_addr;
local int unsigned m_n_bytes;
local uvm_endianness_e m_endian;
local bit m_byte_addressing;
local uvm_object_wrapper m_sequence_wrapper;
local uvm_reg_adapter m_adapter;
local uvm_sequencer_base m_sequencer;
local bit m_auto_predict;
local bit m_check_on_read;
local uvm_reg_block m_parent;
local int unsigned m_system_n_bytes;
local uvm_reg_map m_parent_map;
local uvm_reg_addr_t m_parent_maps[uvm_reg_map]; // value=offset of this map at parent level
local uvm_reg_addr_t m_submaps[uvm_reg_map]; // value=offset of submap at this level
local string m_submap_rights[uvm_reg_map]; // value=rights of submap at this level
local uvm_reg_map_info m_regs_info[uvm_reg];
local uvm_reg_map_info m_mems_info[uvm_mem];
local uvm_reg m_regs_by_offset[uvm_reg_addr_t];
// Use only in addition to above if a RO and a WO
// register share the same address.
local uvm_reg m_regs_by_offset_wo[uvm_reg_addr_t];
local uvm_mem m_mems_by_offset[uvm_reg_map_addr_range];
local uvm_reg_transaction_order_policy policy;
extern /*local*/ function void Xinit_address_mapX();
static local uvm_reg_map m_backdoor;
// Function: backdoor
// Return the backdoor pseudo-map singleton
//
// This pseudo-map is used to specify or configure the backdoor
// instead of a real address map.
//
static function uvm_reg_map backdoor();
if (m_backdoor == null)
m_backdoor = new("Backdoor");
return m_backdoor;
endfunction
//----------------------
// Group: Initialization
//----------------------
// Function: new
//
// Create a new instance
//
extern function new(string name="uvm_reg_map");
// Function: configure
//
// Instance-specific configuration
//
// Configures this map with the following properties.
//
// parent - the block in which this map is created and applied
//
// base_addr - the base address for this map. All registers, memories,
// and sub-blocks will be at offsets to this address
//
// n_bytes - the byte-width of the bus on which this map is used
//
// endian - the endian format. See <uvm_endianness_e> for possible
// values
//
// byte_addressing - specifies whether the address increment is on a
// per-byte basis. For example, consecutive memory locations
// with ~n_bytes~=4 (32-bit bus) are 4 apart: 0, 4, 8, and
// so on. Default is TRUE.
//
extern function void configure(uvm_reg_block parent,
uvm_reg_addr_t base_addr,
int unsigned n_bytes,
uvm_endianness_e endian,
bit byte_addressing = 1);
// Function: add_reg
//
// Add a register
//
// Add the specified register instance ~rg~ to this address map.
//
// The register is located at the specified address ~offset~ from
// this maps configured base address.
//
// The ~rights~ specify the register's accessibility via this map.
// Valid values are "RW", "RO", and "WO". Whether a register field
// can be read or written depends on both the field's configured access
// policy (see <uvm_reg_field::configure> and the register's rights in
// the map being used to access the field.
//
// The number of consecutive physical addresses occupied by the register
// depends on the width of the register and the number of bytes in the
// physical interface corresponding to this address map.
//
// If ~unmapped~ is TRUE, the register does not occupy any
// physical addresses and the base address is ignored.
// Unmapped registers require a user-defined ~frontdoor~ to be specified.
//
// A register may be added to multiple address maps
// if it is accessible from multiple physical interfaces.
// A register may only be added to an address map whose parent block
// is the same as the register's parent block.
//
extern virtual function void add_reg (uvm_reg rg,
uvm_reg_addr_t offset,
string rights = "RW",
bit unmapped=0,
uvm_reg_frontdoor frontdoor=null);
// Function: add_mem
//
// Add a memory
//
// Add the specified memory instance to this address map.
// The memory is located at the specified base address and has the
// specified access rights ("RW", "RO" or "WO").
// The number of consecutive physical addresses occupied by the memory
// depends on the width and size of the memory and the number of bytes in the
// physical interface corresponding to this address map.
//
// If ~unmapped~ is TRUE, the memory does not occupy any
// physical addresses and the base address is ignored.
// Unmapped memories require a user-defined ~frontdoor~ to be specified.
//
// A memory may be added to multiple address maps
// if it is accessible from multiple physical interfaces.
// A memory may only be added to an address map whose parent block
// is the same as the memory's parent block.
//
extern virtual function void add_mem (uvm_mem mem,
uvm_reg_addr_t offset,
string rights = "RW",
bit unmapped=0,
uvm_reg_frontdoor frontdoor=null);
// Function: add_submap
//
// Add an address map
//
// Add the specified address map instance to this address map.
// The address map is located at the specified base address.
// The number of consecutive physical addresses occupied by the submap
// depends on the number of bytes in the physical interface
// that corresponds to the submap,
// the number of addresses used in the submap and
// the number of bytes in the
// physical interface corresponding to this address map.
//
// An address map may be added to multiple address maps
// if it is accessible from multiple physical interfaces.
// An address map may only be added to an address map
// in the grand-parent block of the address submap.
//
extern virtual function void add_submap (uvm_reg_map child_map,
uvm_reg_addr_t offset);
// Function: set_sequencer
//
// Set the sequencer and adapter associated with this map. This method
// ~must~ be called before starting any sequences based on uvm_reg_sequence.
extern virtual function void set_sequencer (uvm_sequencer_base sequencer,
uvm_reg_adapter adapter=null);
// Function: set_submap_offset
//
// Set the offset of the given ~submap~ to ~offset~.
extern virtual function void set_submap_offset (uvm_reg_map submap,
uvm_reg_addr_t offset);
// Function: get_submap_offset
//
// Return the offset of the given ~submap~.
extern virtual function uvm_reg_addr_t get_submap_offset (uvm_reg_map submap);
// Function: set_base_addr
//
// Set the base address of this map.
extern virtual function void set_base_addr (uvm_reg_addr_t offset);
// Function: reset
//
// Reset the mirror for all registers in this address map.
//
// Sets the mirror value of all registers in this address map
// and all of its submaps
// to the reset value corresponding to the specified reset event.
// See <uvm_reg_field::reset()> for more details.
// Does not actually set the value of the registers in the design,
// only the values mirrored in their corresponding mirror.
//
// Note that, unlike the other reset() method, the default
// reset event for this method is "SOFT".
//
extern virtual function void reset(string kind = "SOFT");
/*local*/ extern virtual function void add_parent_map(uvm_reg_map parent_map,
uvm_reg_addr_t offset);
/*local*/ extern virtual function void Xverify_map_configX();
/*local*/ extern virtual function void m_set_reg_offset(uvm_reg rg,
uvm_reg_addr_t offset,
bit unmapped);
/*local*/ extern virtual function void m_set_mem_offset(uvm_mem mem,
uvm_reg_addr_t offset,
bit unmapped);
//---------------------
// Group: Introspection
//---------------------
// Function: get_name
//
// Get the simple name
//
// Return the simple object name of this address map.
//
// Function: get_full_name
//
// Get the hierarchical name
//
// Return the hierarchal name of this address map.
// The base of the hierarchical name is the root block.
//
extern virtual function string get_full_name();
// Function: get_root_map
//
// Get the externally-visible address map
//
// Get the top-most address map where this address map is instantiated.
// It corresponds to the externally-visible address map that can
// be accessed by the verification environment.
//
extern virtual function uvm_reg_map get_root_map();
// Function: get_parent
//
// Get the parent block
//
// Return the block that is the parent of this address map.
//
extern virtual function uvm_reg_block get_parent();
// Function: get_parent_map
// Get the higher-level address map
//
// Return the address map in which this address map is mapped.
// returns ~null~ if this is a top-level address map.
//
extern virtual function uvm_reg_map get_parent_map();
// Function: get_base_addr
//
// Get the base offset address for this map. If this map is the
// root map, the base address is that set with the ~base_addr~ argument
// to <uvm_reg_block::create_map()>. If this map is a submap of a higher-level map,
// the base address is offset given this submap by the parent map.
// See <set_submap_offset>.
//
extern virtual function uvm_reg_addr_t get_base_addr (uvm_hier_e hier=UVM_HIER);
// Function: get_n_bytes
//
// Get the width in bytes of the bus associated with this map. If ~hier~
// is ~UVM_HIER~, then gets the effective bus width relative to the system
// level. The effective bus width is the narrowest bus width from this
// map to the top-level root map. Each bus access will be limited to this
// bus width.
//
extern virtual function int unsigned get_n_bytes (uvm_hier_e hier=UVM_HIER);
// Function: get_addr_unit_bytes
//
// Get the number of bytes in the smallest addressable unit in the map.
// Returns 1 if the address map was configured using byte-level addressing.
// Returns <get_n_bytes()> otherwise.
//
extern virtual function int unsigned get_addr_unit_bytes();
// Function: get_base_addr
//
// Gets the endianness of the bus associated with this map. If ~hier~ is
// set to ~UVM_HIER~, gets the system-level endianness.
//
extern virtual function uvm_endianness_e get_endian (uvm_hier_e hier=UVM_HIER);
// Function: get_sequencer
//
// Gets the sequencer for the bus associated with this map. If ~hier~ is
// set to ~UVM_HIER~, gets the sequencer for the bus at the system-level.
// See <set_sequencer>.
//
extern virtual function uvm_sequencer_base get_sequencer (uvm_hier_e hier=UVM_HIER);
// Function: get_adapter
//
// Gets the bus adapter for the bus associated with this map. If ~hier~ is
// set to ~UVM_HIER~, gets the adapter for the bus used at the system-level.
// See <set_sequencer>.
//
extern virtual function uvm_reg_adapter get_adapter (uvm_hier_e hier=UVM_HIER);
// Function: get_submaps
//
// Get the address sub-maps
//
// Get the address maps instantiated in this address map.
// If ~hier~ is ~UVM_HIER~, recursively includes the address maps,
// in the sub-maps.
//
extern virtual function void get_submaps (ref uvm_reg_map maps[$],
input uvm_hier_e hier=UVM_HIER);
// Function: get_registers
//
// Get the registers
//
// Get the registers instantiated in this address map.
// If ~hier~ is ~UVM_HIER~, recursively includes the registers
// in the sub-maps.
//
extern virtual function void get_registers (ref uvm_reg regs[$],
input uvm_hier_e hier=UVM_HIER);
// Function: get_fields
//
// Get the fields
//
// Get the fields in the registers instantiated in this address map.
// If ~hier~ is ~UVM_HIER~, recursively includes the fields of the registers
// in the sub-maps.
//
extern virtual function void get_fields (ref uvm_reg_field fields[$],
input uvm_hier_e hier=UVM_HIER);
// Function: get_memories
//
// Get the memories
//
// Get the memories instantiated in this address map.
// If ~hier~ is ~UVM_HIER~, recursively includes the memories
// in the sub-maps.
//
extern virtual function void get_memories (ref uvm_mem mems[$],
input uvm_hier_e hier=UVM_HIER);
// Function: get_virtual_registers
//
// Get the virtual registers
//
// Get the virtual registers instantiated in this address map.
// If ~hier~ is ~UVM_HIER~, recursively includes the virtual registers
// in the sub-maps.
//
extern virtual function void get_virtual_registers (ref uvm_vreg regs[$],
input uvm_hier_e hier=UVM_HIER);
// Function: get_virtual_fields
//
// Get the virtual fields
//
// Get the virtual fields from the virtual registers instantiated
// in this address map.
// If ~hier~ is ~UVM_HIER~, recursively includes the virtual fields
// in the virtual registers in the sub-maps.
//
extern virtual function void get_virtual_fields (ref uvm_vreg_field fields[$],
input uvm_hier_e hier=UVM_HIER);
extern virtual function uvm_reg_map_info get_reg_map_info(uvm_reg rg, bit error=1);
extern virtual function uvm_reg_map_info get_mem_map_info(uvm_mem mem, bit error=1);
extern virtual function int unsigned get_size();
// Function: get_physical_addresses
//
// Translate a local address into external addresses
//
// Identify the sequence of addresses that must be accessed physically
// to access the specified number of bytes at the specified address
// within this address map.
// Returns the number of bytes of valid data in each access.
//
// Returns in ~addr~ a list of address in little endian order,
// with the granularity of the top-level address map.
//
// A register is specified using a base address with ~mem_offset~ as 0.
// A location within a memory is specified using the base address
// of the memory and the index of the location within that memory.
//
extern virtual function int get_physical_addresses(uvm_reg_addr_t base_addr,
uvm_reg_addr_t mem_offset,
int unsigned n_bytes,
ref uvm_reg_addr_t addr[]);
// Function: get_reg_by_offset
//
// Get register mapped at offset
//
// Identify the register located at the specified offset within
// this address map for the specified type of access.
// Returns ~null~ if no such register is found.
//
// The model must be locked using <uvm_reg_block::lock_model()>
// to enable this functionality.
//
extern virtual function uvm_reg get_reg_by_offset(uvm_reg_addr_t offset,
bit read = 1);
//
// Function: get_mem_by_offset
// Get memory mapped at offset
//
// Identify the memory located at the specified offset within
// this address map. The offset may refer to any memory location
// in that memory.
// Returns ~null~ if no such memory is found.
//
// The model must be locked using <uvm_reg_block::lock_model()>
// to enable this functionality.
//
extern virtual function uvm_mem get_mem_by_offset(uvm_reg_addr_t offset);
//------------------
// Group: Bus Access
//------------------
// Function: set_auto_predict
//
// Sets the auto-predict mode for his map.
//
// When ~on~ is ~TRUE~,
// the register model will automatically update its mirror
// (what it thinks should be in the DUT) immediately after
// any bus read or write operation via this map. Before a <uvm_reg::write>
// or <uvm_reg::read> operation returns, the register's <uvm_reg::predict>
// method is called to update the mirrored value in the register.
//
// When ~on~ is ~FALSE~, bus reads and writes via this map do not
// automatically update the mirror. For real-time updates to the mirror
// in this mode, you connect a <uvm_reg_predictor> instance to the bus
// monitor. The predictor takes observed bus transactions from the
// bus monitor, looks up the associated <uvm_reg> register given
// the address, then calls that register's <uvm_reg::predict> method.
// While more complex, this mode will capture all register read/write
// activity, including that not directly descendant from calls to
// <uvm_reg::write> and <uvm_reg::read>.
//
// By default, auto-prediction is turned off.
//
function void set_auto_predict(bit on=1); m_auto_predict = on; endfunction
// Function: get_auto_predict
//
// Gets the auto-predict mode setting for this map.
//
function bit get_auto_predict(); return m_auto_predict; endfunction
// Function: set_check_on_read
//
// Sets the check-on-read mode for his map
// and all of its submaps.
//
// When ~on~ is ~TRUE~,
// the register model will automatically check any value read back from
// a register or field against the current value in its mirror
// and report any discrepancy.
// This effectively combines the functionality of the
// <uvm_reg::read()> and ~uvm_reg::mirror(UVM_CHECK)~ method.
// This mode is useful when the register model is used passively.
//
// When ~on~ is ~FALSE~, no check is made against the mirrored value.
//
// At the end of the read operation, the mirror value is updated based
// on the value that was read regardless of this mode setting.
//
// By default, auto-prediction is turned off.
//
function void set_check_on_read(bit on=1);
m_check_on_read = on;
foreach (m_submaps[submap]) begin
submap.set_check_on_read(on);
end
endfunction
// Function: get_check_on_read
//
// Gets the check-on-read mode setting for this map.
//
function bit get_check_on_read(); return m_check_on_read; endfunction
// Task: do_bus_write
//
// Perform a bus write operation.
//
extern virtual task do_bus_write (uvm_reg_item rw,
uvm_sequencer_base sequencer,
uvm_reg_adapter adapter);
// Task: do_bus_read
//
// Perform a bus read operation.
//
extern virtual task do_bus_read (uvm_reg_item rw,
uvm_sequencer_base sequencer,
uvm_reg_adapter adapter);
// Task: do_write
//
// Perform a write operation.
//
extern virtual task do_write(uvm_reg_item rw);
// Task: do_read
//
// Perform a read operation.
//
extern virtual task do_read(uvm_reg_item rw);
extern function void Xget_bus_infoX (uvm_reg_item rw,
output uvm_reg_map_info map_info,
output int size,
output int lsb,
output int addr_skip);
extern virtual function string convert2string();
extern virtual function uvm_object clone();
extern virtual function void do_print (uvm_printer printer);
extern virtual function void do_copy (uvm_object rhs);
//extern virtual function bit do_compare (uvm_object rhs, uvm_comparer comparer);
//extern virtual function void do_pack (uvm_packer packer);
//extern virtual function void do_unpack (uvm_packer packer);
// Function: set_transaction_order_policy
// set the transaction order policy
function void set_transaction_order_policy(uvm_reg_transaction_order_policy pol);
policy = pol;
endfunction
// Function: get_transaction_order_policy
// set the transaction order policy
function uvm_reg_transaction_order_policy get_transaction_order_policy();
return policy;
endfunction
endclass: uvm_reg_map
//---------------
// Initialization
//---------------
// new
function uvm_reg_map::new(string name = "uvm_reg_map");
super.new((name == "") ? "default_map" : name);
m_auto_predict = 0;
m_check_on_read = 0;
endfunction
// configure
function void uvm_reg_map::configure(uvm_reg_block parent,
uvm_reg_addr_t base_addr,
int unsigned n_bytes,
uvm_endianness_e endian,
bit byte_addressing=1);
m_parent = parent;
m_n_bytes = n_bytes;
m_endian = endian;
m_base_addr = base_addr;
m_byte_addressing = byte_addressing;
endfunction: configure
// add_reg
function void uvm_reg_map::add_reg(uvm_reg rg,
uvm_reg_addr_t offset,
string rights = "RW",
bit unmapped=0,
uvm_reg_frontdoor frontdoor=null);
if (m_regs_info.exists(rg)) begin
`uvm_error("RegModel", {"Register '",rg.get_name(),
"' has already been added to map '",get_name(),"'"})
return;
end
if (rg.get_parent() != get_parent()) begin
`uvm_error("RegModel",
{"Register '",rg.get_full_name(),"' may not be added to address map '",
get_full_name(),"' : they are not in the same block"})
return;
end
rg.add_map(this);
begin
uvm_reg_map_info info = new;
info.offset = offset;
info.rights = rights;
info.unmapped = unmapped;
info.frontdoor = frontdoor;
m_regs_info[rg] = info;
end
endfunction
// m_set_reg_offset
function void uvm_reg_map::m_set_reg_offset(uvm_reg rg,
uvm_reg_addr_t offset,
bit unmapped);
if (!m_regs_info.exists(rg)) begin
`uvm_error("RegModel",
{"Cannot modify offset of register '",rg.get_full_name(),
"' in address map '",get_full_name(),
"' : register not mapped in that address map"})
return;
end
begin
uvm_reg_map_info info = m_regs_info[rg];
uvm_reg_block blk = get_parent();
uvm_reg_map top_map = get_root_map();
uvm_reg_addr_t addrs[];
// if block is not locked, Xinit_address_mapX will resolve map when block is locked
if (blk.is_locked()) begin
// remove any existing cached addresses
if (!info.unmapped) begin
foreach (info.addr[i]) begin
if (!top_map.m_regs_by_offset_wo.exists(info.addr[i])) begin
top_map.m_regs_by_offset.delete(info.addr[i]);
end
else begin
if (top_map.m_regs_by_offset[info.addr[i]] == rg) begin
top_map.m_regs_by_offset[info.addr[i]] =
top_map.m_regs_by_offset_wo[info.addr[i]];
uvm_reg_read_only_cbs::remove(rg);
uvm_reg_write_only_cbs::remove(top_map.m_regs_by_offset[info.addr[i]]);
end
else begin
uvm_reg_write_only_cbs::remove(rg);
uvm_reg_read_only_cbs::remove(top_map.m_regs_by_offset[info.addr[i]]);
end
top_map.m_regs_by_offset_wo.delete(info.addr[i]);
end
end
end
// if we are remapping...
if (!unmapped) begin
string rg_acc = rg.Xget_fields_accessX(this);
// get new addresses
void'(get_physical_addresses(offset,0,rg.get_n_bytes(),addrs));
// make sure they do not conflict with others
foreach (addrs[i]) begin
uvm_reg_addr_t addr = addrs[i];
if (top_map.m_regs_by_offset.exists(addr)) begin
uvm_reg rg2 = top_map.m_regs_by_offset[addr];
string rg2_acc = rg2.Xget_fields_accessX(this);
// If the register at the same address is RO or WO
// and this register is WO or RO, this is OK
if (rg_acc == "RO" && rg2_acc == "WO") begin
top_map.m_regs_by_offset[addr] = rg;
uvm_reg_read_only_cbs::add(rg);
top_map.m_regs_by_offset_wo[addr] = rg2;
uvm_reg_write_only_cbs::add(rg2);
end
else if (rg_acc == "WO" && rg2_acc == "RO") begin
top_map.m_regs_by_offset_wo[addr] = rg;
uvm_reg_write_only_cbs::add(rg);
uvm_reg_read_only_cbs::add(rg2);
end
else begin
string a;
a = $sformatf("%0h",addr);
`uvm_warning("RegModel", {"In map '",get_full_name(),"' register '",
rg.get_full_name(), "' maps to same address as register '",
top_map.m_regs_by_offset[addr].get_full_name(),"': 'h",a})
end
end
else
top_map.m_regs_by_offset[addr] = rg;
foreach (top_map.m_mems_by_offset[range]) begin
if (addrs[i] >= range.min && addrs[i] <= range.max) begin
string a;
a = $sformatf("%0h",addrs[i]);
`uvm_warning("RegModel", {"In map '",get_full_name(),"' register '",
rg.get_full_name(), "' overlaps with address range of memory '",
top_map.m_mems_by_offset[range].get_full_name(),"': 'h",a})
end
end
end
info.addr = addrs; // cache it
end
end
if (unmapped) begin
info.offset = -1;
info.unmapped = 1;
end
else begin
info.offset = offset;
info.unmapped = 0;
end
end
endfunction
// add_mem
function void uvm_reg_map::add_mem(uvm_mem mem,
uvm_reg_addr_t offset,
string rights = "RW",
bit unmapped=0,
uvm_reg_frontdoor frontdoor=null);
if (m_mems_info.exists(mem)) begin
`uvm_error("RegModel", {"Memory '",mem.get_name(),
"' has already been added to map '",get_name(),"'"})
return;
end
if (mem.get_parent() != get_parent()) begin
`uvm_error("RegModel",
{"Memory '",mem.get_full_name(),"' may not be added to address map '",
get_full_name(),"' : they are not in the same block"})
return;
end
mem.add_map(this);
begin
uvm_reg_map_info info = new;
info.offset = offset;
info.rights = rights;
info.unmapped = unmapped;
info.frontdoor = frontdoor;
m_mems_info[mem] = info;
end
endfunction: add_mem
// m_set_mem_offset
function void uvm_reg_map::m_set_mem_offset(uvm_mem mem,
uvm_reg_addr_t offset,
bit unmapped);
if (!m_mems_info.exists(mem)) begin
`uvm_error("RegModel",
{"Cannot modify offset of memory '",mem.get_full_name(),
"' in address map '",get_full_name(),
"' : memory not mapped in that address map"})
return;
end
begin
uvm_reg_map_info info = m_mems_info[mem];
uvm_reg_block blk = get_parent();
uvm_reg_map top_map = get_root_map();
uvm_reg_addr_t addrs[];
// if block is not locked, Xinit_address_mapX will resolve map when block is locked
if (blk.is_locked()) begin
// remove any existing cached addresses
if (!info.unmapped) begin
foreach (top_map.m_mems_by_offset[range]) begin
if (top_map.m_mems_by_offset[range] == mem)
top_map.m_mems_by_offset.delete(range);
end
end
// if we are remapping...
if (!unmapped) begin
uvm_reg_addr_t addrs[],addrs_max[];
uvm_reg_addr_t min, max, min2, max2;
int unsigned stride;
void'(get_physical_addresses(offset,0,mem.get_n_bytes(),addrs));
min = (addrs[0] < addrs[addrs.size()-1]) ? addrs[0] : addrs[addrs.size()-1];
min2 = addrs[0];
void'(get_physical_addresses(offset,(mem.get_size()-1),
mem.get_n_bytes(),addrs_max));
max = (addrs_max[0] > addrs_max[addrs_max.size()-1]) ?
addrs_max[0] : addrs_max[addrs_max.size()-1];
max2 = addrs_max[0];
// address interval between consecutive mem locations
stride = (max2 - max)/(mem.get_size()-1);
// make sure new offset does not conflict with others
foreach (top_map.m_regs_by_offset[reg_addr]) begin
if (reg_addr >= min && reg_addr <= max) begin
string a,b;
a = $sformatf("[%0h:%0h]",min,max);
b = $sformatf("%0h",reg_addr);
`uvm_warning("RegModel", {"In map '",get_full_name(),"' memory '",
mem.get_full_name(), "' with range ",a,
" overlaps with address of existing register '",
top_map.m_regs_by_offset[reg_addr].get_full_name(),"': 'h",b})
end
end
foreach (top_map.m_mems_by_offset[range]) begin
if (min <= range.max && max >= range.max ||
min <= range.min && max >= range.min ||
min >= range.min && max <= range.max) begin
string a,b;
a = $sformatf("[%0h:%0h]",min,max);
b = $sformatf("[%0h:%0h]",range.min,range.max);
`uvm_warning("RegModel", {"In map '",get_full_name(),"' memory '",
mem.get_full_name(), "' with range ",a,
" overlaps existing memory with range '",
top_map.m_mems_by_offset[range].get_full_name(),"': ",b})
end
end
begin
uvm_reg_map_addr_range range = '{ min, max, stride };
top_map.m_mems_by_offset[range] = mem;
info.addr = addrs;
info.mem_range = range;
end
end
end
if (unmapped) begin
info.offset = -1;
info.unmapped = 1;
end
else begin
info.offset = offset;
info.unmapped = 0;
end
end
endfunction
// add_submap
function void uvm_reg_map::add_submap (uvm_reg_map child_map,
uvm_reg_addr_t offset);
uvm_reg_map parent_map;
if (child_map == null) begin
`uvm_error("RegModel", {"Attempting to add NULL map to map '",get_full_name(),"'"})
return;
end
parent_map = child_map.get_parent_map();
// Cannot have more than one parent (currently)
if (parent_map != null) begin
`uvm_error("RegModel", {"Map '", child_map.get_full_name(),