forked from openhwgroup/cva6
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuvme_cva6_cfg.sv
355 lines (284 loc) · 13 KB
/
uvme_cva6_cfg.sv
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
// Copyright 2020 OpenHW Group
// Copyright 2020 Datum Technology Corporation
// Copyright 2020 Silicon Labs, Inc.
// Copyright 2021 Thales DIS Design Services SAS
//
// Licensed under the Solderpad Hardware Licence, 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
//
// https://solderpad.org/licenses/
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.0
`ifndef __UVME_CVA6_CFG_SV__
`define __UVME_CVA6_CFG_SV__
/**
* Object encapsulating all parameters for creating, connecting and running
* CVA6 environment (uvme_cva6_env_c) components.
*/
class uvme_cva6_cfg_c extends uvma_core_cntrl_cfg_c;
// Integrals
rand bit enabled;
rand bit scoreboard_enabled;
rand bit tandem_enabled;
rand bit cov_model_enabled;
rand bit trn_log_enabled;
rand bit force_disable_csr_checks; // force disable all csr checks in RVFI. Note that all csrs info in instruction from RVFI will be removed
rand int unsigned sys_clk_period;
bit performance_mode; // Will force disable coverage, csr checks, scoreboard and loggers
// Agent cfg handles
rand uvma_clknrst_cfg_c clknrst_cfg;
rand uvma_axi_cfg_c axi_cfg;
rand uvma_rvfi_cfg_c#(ILEN,XLEN) rvfi_cfg;
rand uvma_isacov_cfg_c isacov_cfg;
rand uvma_interrupt_cfg_c interrupt_cfg;
// Zicond extension
rand bit ext_zicond_supported;
// HPDcache support
rand bit HPDCache_supported;
// pmp entries
rand int nr_pmp_entries;
// Zihpm extension
rand bit ext_zihpm_supported;
// MMU support
rand bit MmuPresent;
`uvm_object_utils_begin(uvme_cva6_cfg_c)
`uvm_field_int ( enabled , UVM_DEFAULT )
`uvm_field_enum(uvm_active_passive_enum, is_active , UVM_DEFAULT )
`uvm_field_int ( scoreboard_enabled , UVM_DEFAULT )
`uvm_field_int ( tandem_enabled , UVM_DEFAULT )
`uvm_field_int ( cov_model_enabled , UVM_DEFAULT )
`uvm_field_int ( trn_log_enabled , UVM_DEFAULT )
`uvm_field_int ( force_disable_csr_checks , UVM_DEFAULT )
`uvm_field_int ( ext_zicond_supported , UVM_DEFAULT )
`uvm_field_int ( HPDCache_supported , UVM_DEFAULT )
`uvm_field_int ( nr_pmp_entries , UVM_DEFAULT )
`uvm_field_int ( ext_zihpm_supported , UVM_DEFAULT )
`uvm_field_int ( MmuPresent , UVM_DEFAULT )
`uvm_field_int ( sys_clk_period , UVM_DEFAULT + UVM_DEC)
`uvm_field_int ( performance_mode , UVM_DEFAULT )
`uvm_field_object(clknrst_cfg, UVM_DEFAULT)
`uvm_field_object(axi_cfg, UVM_DEFAULT)
`uvm_field_object(rvfi_cfg, UVM_DEFAULT)
`uvm_field_object(isacov_cfg, UVM_DEFAULT)
`uvm_field_object(interrupt_cfg, UVM_DEFAULT)
`uvm_object_utils_end
constraint defaults_cons {
soft enabled == 1;
soft is_active == UVM_ACTIVE;
soft scoreboard_enabled == 1;
soft cov_model_enabled == 1;
soft trn_log_enabled == 1;
soft force_disable_csr_checks == 0;
soft sys_clk_period == uvme_cva6_sys_default_clk_period; // see uvme_cva6_constants.sv
}
constraint cva6_riscv_cons {
xlen == RTLCVA6Cfg.XLEN;
ext_zihpm_supported == 0;
ext_zicond_supported == RTLCVA6Cfg.RVZiCond;
nr_pmp_entries == 64;
unaligned_access_supported == 0;
unaligned_access_amo_supported == 0;
bitmanip_version == BITMANIP_VERSION_1P00;
priv_spec_version == PRIV_VERSION_MASTER;
endianness == ENDIAN_LITTLE;
boot_addr_valid == 1;
mtvec_addr_valid == 1;
dm_halt_addr_valid == 1;
dm_exception_addr_valid == 1;
nmi_addr_valid == 1;
HPDCache_supported == (RTLCVA6Cfg.DCacheType == 2);
MmuPresent == RTLCVA6Cfg.MmuPresent;
}
constraint ext_const {
if (!ext_c_supported) {
ext_zcb_supported == 0;
}
}
constraint pmp_const {
if (!pmp_supported) {
nr_pmp_entries == 0;
}
else {
nr_pmp_entries inside {0, 16, 64};
}
}
constraint default_cva6_boot_cons {
(!mhartid_plusarg_valid) -> (mhartid == 'h0000_0000);
(!mimpid_plusarg_valid) -> (mimpid == 'h0000_0000);
(!boot_addr_plusarg_valid) -> (boot_addr == 'h8000_0000);
(!mtvec_addr_plusarg_valid) -> (mtvec_addr == 'h0000_0000);
(!nmi_addr_plusarg_valid) -> (nmi_addr == 'h0000_0000);
(!dm_halt_addr_plusarg_valid) -> (dm_halt_addr == 'h0000_0000);
(!dm_exception_addr_plusarg_valid) -> (dm_exception_addr == 'h0000_0000);
}
constraint default_interrupt_cons {
if (interrupt_cfg.interrupt_plusarg_valid) {
interrupt_cfg.enable_interrupt == 'h1;
}
else
interrupt_cfg.enable_interrupt == 'h0;
}
constraint agent_cfg_cons {
if (enabled) {
clknrst_cfg.enabled == 1;
isacov_cfg.enabled == 1;
rvfi_cfg.enabled == 1;
interrupt_cfg.enabled == 1;
}
isacov_cfg.seq_instr_group_x2_enabled == 1;
isacov_cfg.seq_instr_group_x3_enabled == 0;
isacov_cfg.seq_instr_group_x4_enabled == 0;
isacov_cfg.seq_instr_x2_enabled == 1;
isacov_cfg.reg_crosses_enabled == 0;
isacov_cfg.reg_hazards_enabled == 1;
rvfi_cfg.nret == RTLCVA6Cfg.NrCommitPorts;
unified_traps == 0;
axi_cfg.rand_channel_delay_enabled == 0;
if (is_active == UVM_ACTIVE) {
clknrst_cfg.is_active == UVM_ACTIVE;
isacov_cfg.is_active == UVM_PASSIVE;
rvfi_cfg.is_active == UVM_PASSIVE;
interrupt_cfg.is_active == UVM_ACTIVE;
}
if (trn_log_enabled) {
clknrst_cfg.trn_log_enabled == 0;
axi_cfg.trn_log_enabled == 1;
rvfi_cfg.trn_log_enabled == 1;
isacov_cfg.trn_log_enabled == 1;
} else {
clknrst_cfg.trn_log_enabled == 0;
axi_cfg.trn_log_enabled == 0;
rvfi_cfg.trn_log_enabled == 0;
isacov_cfg.trn_log_enabled == 0;
}
if (cov_model_enabled) {
isacov_cfg.cov_model_enabled == 1;
axi_cfg.cov_model_enabled == 1;
interrupt_cfg.cov_model_enabled == 1;
} else {
isacov_cfg.cov_model_enabled == 0;
axi_cfg.cov_model_enabled == 0;
interrupt_cfg.cov_model_enabled == 0;
}
}
/**
* Creates sub-configuration objects.
*/
extern function new(string name="uvme_cva6_cfg");
/**
* Sample the parameters of the DUT via the virtual interface in a context
*/
extern virtual function void sample_parameters(uvma_core_cntrl_cntxt_c cntxt);
/**
* Set unsupported_csr_mask based on extensions/modes supported
*/
extern virtual function void set_unsupported_csr_mask();
extern virtual function void read_disable_csr_check_plusargs();
endclass : uvme_cva6_cfg_c
function uvme_cva6_cfg_c::new(string name="uvme_cva6_cfg");
super.new(name);
clknrst_cfg = uvma_clknrst_cfg_c::type_id::create("clknrst_cfg");
axi_cfg = uvma_axi_cfg_c::type_id::create("axi_cfg");
rvfi_cfg = uvma_rvfi_cfg_c#(ILEN,XLEN)::type_id::create("rvfi_cfg");
isacov_cfg = uvma_isacov_cfg_c::type_id::create("isacov_cfg");
interrupt_cfg = uvma_interrupt_cfg_c::type_id::create("interrupt_cfg");
isacov_cfg.core_cfg = this;
rvfi_cfg.core_cfg = this;
$value$plusargs("core_name=%s", this.core_name);
if ($test$plusargs("tb_performance_mode")) begin
performance_mode = 1;
`uvm_info(get_type_name(), "Testbench set in performance mode, coverage & csr checks & scoreboard & loggers will be deactivated", UVM_NONE);
end
endfunction : new
function void uvme_cva6_cfg_c::sample_parameters(uvma_core_cntrl_cntxt_c cntxt);
uvma_cva6_core_cntrl_cntxt_c cva6_cntxt;
if (!$cast(cva6_cntxt, cntxt)) begin
`uvm_fatal("SAMPLECNTXT", "Could not cast cntxt to uvma_cva6_core_cntrl_cntxt_c");
end
num_mhpmcounters = cva6_cntxt.core_cntrl_vif.num_mhpmcounters;
// TODO : Check PMA
//~ pma_regions = new[cva6_cntxt.core_cntrl_vif.pma_cfg.size()];
//~ foreach (pma_regions[i]) begin
//~ pma_regions[i] = uvma_core_cntrl_pma_region_c::type_id::create($sformatf("pma_region%0d", i));
//~ pma_regions[i].word_addr_low = cva6_cntxt.core_cntrl_vif.pma_cfg[i].word_addr_low;
//~ pma_regions[i].word_addr_high = cva6_cntxt.core_cntrl_vif.pma_cfg[i].word_addr_high;
//~ pma_regions[i].main = cva6_cntxt.core_cntrl_vif.pma_cfg[i].main;
//~ pma_regions[i].bufferable = core_cntrl_vif.pma_cfg[i].bufferable;
//~ pma_regions[i].cacheable = core_cntrl_vif.pma_cfg[i].cacheable;
//~ pma_regions[i].atomic = core_cntrl_vif.pma_cfg[i].atomic;
//~ end
//~ // Copy to the pma_configuration
//~ pma_cfg.regions = new[pma_regions.size()];
//~ foreach (pma_cfg.regions[i])
//~ pma_cfg.regions[i] = pma_regions[i];
endfunction : sample_parameters
function void uvme_cva6_cfg_c::set_unsupported_csr_mask();
super.set_unsupported_csr_mask();
// Add supported CSRs for Embedded configuration
for (int i = 0; i < MAX_NUM_HPMCOUNTERS; i++) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::MHPMEVENT3+i] = 0;
if (xlen == 32) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::MHPMCOUNTER3+i] = 0;
unsupported_csr_mask[uvma_core_cntrl_pkg::MHPMCOUNTER3H+i] = 0;
end
else if (xlen == 64) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::MHPMCOUNTER3+i] = 1;
unsupported_csr_mask[uvma_core_cntrl_pkg::MHPMCOUNTER3H+i] = 1;
end
end
// Zihpm extension CSRs
if (ext_zihpm_supported) begin
for (int i = 0; i < MAX_NUM_HPMCOUNTERS; i++) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::HPMCOUNTER3+i] = 0;
if (xlen == 32) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::HPMCOUNTER3H+i] = 0;
end
else if (xlen ==64) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::HPMCOUNTER3H+i] = 1;
end
end
end
else begin
for (int i = 0; i < MAX_NUM_HPMCOUNTERS; i++) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::HPMCOUNTER3+i] = 1;
unsupported_csr_mask[uvma_core_cntrl_pkg::HPMCOUNTER3H+i] = 1;
end
end
// Upper Machine mode CSRs
if (xlen == 32) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::MSTATUSH] = 0;
unsupported_csr_mask[uvma_core_cntrl_pkg::MCYCLEH] = 0;
unsupported_csr_mask[uvma_core_cntrl_pkg::MINSTRETH] = 0;
end
else if (xlen == 64) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::MSTATUSH] = 1;
unsupported_csr_mask[uvma_core_cntrl_pkg::MCYCLEH] = 1;
unsupported_csr_mask[uvma_core_cntrl_pkg::MINSTRETH] = 1;
end
// Remove unsupported pmp CSRs
if (nr_pmp_entries == 0) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::PMPCFG0+:16] = 16'hffff;
unsupported_csr_mask[uvma_core_cntrl_pkg::PMPADDR0+:64] = 64'hffffffffffffffff;
end
else if (nr_pmp_entries == 16) begin
unsupported_csr_mask[uvma_core_cntrl_pkg::PMPCFG4+:12] = 12'hfff;
unsupported_csr_mask[uvma_core_cntrl_pkg::PMPADDR16+:48] = 48'hffffffffffff;
end
else if (nr_pmp_entries == 64) begin //if pmp entries is 64 we support all the pmp CSRs
unsupported_csr_mask[uvma_core_cntrl_pkg::PMPCFG0+:16] = 16'h0;
unsupported_csr_mask[uvma_core_cntrl_pkg::PMPADDR0+:64] = 64'h0;
end
endfunction : set_unsupported_csr_mask
function void uvme_cva6_cfg_c::read_disable_csr_check_plusargs();
super.read_disable_csr_check_plusargs();
if (force_disable_csr_checks)
disable_all_csr_checks = 1;
endfunction : read_disable_csr_check_plusargs
`endif // __UVME_CVA6_CFG_SV__