-
Notifications
You must be signed in to change notification settings - Fork 688
/
cva6_hpdcache_subsystem.sv
460 lines (413 loc) · 17 KB
/
cva6_hpdcache_subsystem.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
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
// Copyright 2023 Commissariat a l'Energie Atomique et aux Energies
// Alternatives (CEA)
//
// Licensed under the Solderpad Hardware License, Version 2.1 (the “License”);
// you may not use this file except in compliance with the License.
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
// You may obtain a copy of the License at https://solderpad.org/licenses/
//
// Authors: Cesar Fuguet
// Date: February, 2023
// Description: CVA6 cache subsystem integrating standard CVA6's
// instruction cache and the Core-V High-Performance L1
// data cache (CV-HPDcache).
module cva6_hpdcache_subsystem
// Parameters
// {{{
#(
parameter config_pkg::cva6_cfg_t CVA6Cfg = config_pkg::cva6_cfg_empty,
parameter type icache_areq_t = logic,
parameter type icache_arsp_t = logic,
parameter type icache_dreq_t = logic,
parameter type icache_drsp_t = logic,
parameter type icache_req_t = logic,
parameter type icache_rtrn_t = logic,
parameter type dcache_req_i_t = logic,
parameter type dcache_req_o_t = logic,
parameter int NumPorts = 4,
parameter int NrHwPrefetchers = 4,
// AXI types
parameter type axi_ar_chan_t = logic,
parameter type axi_aw_chan_t = logic,
parameter type axi_w_chan_t = logic,
parameter type axi_b_chan_t = logic,
parameter type axi_r_chan_t = logic,
parameter type noc_req_t = logic,
parameter type noc_resp_t = logic,
parameter type cmo_req_t = logic,
parameter type cmo_rsp_t = logic
)
// }}}
// Ports
// {{{
(
// Subsystem Clock - SUBSYSTEM
input logic clk_i,
// Asynchronous reset active low - SUBSYSTEM
input logic rst_ni,
// AXI port to upstream memory/peripherals
// {{{
// noc request, can be AXI or OpenPiton - SUBSYSTEM
output noc_req_t noc_req_o,
// noc response, can be AXI or OpenPiton - SUBSYSTEM
input noc_resp_t noc_resp_i,
// }}}
// I$
// {{{
// Instruction cache enable - CSR_REGFILE
input logic icache_en_i,
// Flush the instruction cache - CONTROLLER
input logic icache_flush_i,
// instructino cache miss - PERF_COUNTERS
output logic icache_miss_o,
// Input address translation request - EX_STAGE
input icache_areq_t icache_areq_i,
// Output address translation request - EX_STAGE
output icache_arsp_t icache_areq_o,
// Input data translation request - FRONTEND
input icache_dreq_t icache_dreq_i,
// Output data translation request - FRONTEND
output icache_drsp_t icache_dreq_o,
// }}}
// D$
// {{{
// Cache management
// Data cache enable - CSR_REGFILE
input logic dcache_enable_i,
// Data cache flush - CONTROLLER
input logic dcache_flush_i,
// Flush acknowledge - CONTROLLER
output logic dcache_flush_ack_o,
// Load or store miss - PERF_COUNTERS
output logic dcache_miss_o,
// AMO request - EX_STAGE
input ariane_pkg::amo_req_t dcache_amo_req_i,
// AMO response - EX_STAGE
output ariane_pkg::amo_resp_t dcache_amo_resp_o,
// CMO interface request - TO_BE_COMPLETED
input cmo_req_t dcache_cmo_req_i,
// CMO interface response - TO_BE_COMPLETED
output cmo_rsp_t dcache_cmo_resp_o,
// Data cache input request ports - EX_STAGE
input dcache_req_i_t [NumPorts-1:0] dcache_req_ports_i,
// Data cache output request ports - EX_STAGE
output dcache_req_o_t [NumPorts-1:0] dcache_req_ports_o,
// Write buffer status to know if empty - EX_STAGE
output logic wbuffer_empty_o,
// Write buffer status to know if not non idempotent - EX_STAGE
output logic wbuffer_not_ni_o,
// Hardware memory prefetcher configuration
// TO_BE_COMPLETED - TO_BE_COMPLETED
input logic [NrHwPrefetchers-1:0] hwpf_base_set_i,
// TO_BE_COMPLETED - TO_BE_COMPLETED
input logic [NrHwPrefetchers-1:0][63:0] hwpf_base_i,
// TO_BE_COMPLETED - TO_BE_COMPLETED
output logic [NrHwPrefetchers-1:0][63:0] hwpf_base_o,
// TO_BE_COMPLETED - TO_BE_COMPLETED
input logic [NrHwPrefetchers-1:0] hwpf_param_set_i,
// TO_BE_COMPLETED - TO_BE_COMPLETED
input logic [NrHwPrefetchers-1:0][63:0] hwpf_param_i,
// TO_BE_COMPLETED - TO_BE_COMPLETED
output logic [NrHwPrefetchers-1:0][63:0] hwpf_param_o,
// TO_BE_COMPLETED - TO_BE_COMPLETED
input logic [NrHwPrefetchers-1:0] hwpf_throttle_set_i,
// TO_BE_COMPLETED - TO_BE_COMPLETED
input logic [NrHwPrefetchers-1:0][63:0] hwpf_throttle_i,
// TO_BE_COMPLETED - TO_BE_COMPLETED
output logic [NrHwPrefetchers-1:0][63:0] hwpf_throttle_o,
// TO_BE_COMPLETED - TO_BE_COMPLETED
output logic [ 63:0] hwpf_status_o
// }}}
);
// }}}
function int unsigned __minu(int unsigned x, int unsigned y);
return x < y ? x : y;
endfunction
function int unsigned __maxu(int unsigned x, int unsigned y);
return y < x ? x : y;
endfunction
// I$ instantiation
// {{{
logic icache_miss_valid, icache_miss_ready;
icache_req_t icache_miss;
logic icache_miss_resp_valid;
icache_rtrn_t icache_miss_resp;
localparam int ICACHE_RDTXID = 1 << (CVA6Cfg.MEM_TID_WIDTH - 1);
cva6_icache #(
.CVA6Cfg(CVA6Cfg),
.icache_areq_t(icache_areq_t),
.icache_arsp_t(icache_arsp_t),
.icache_dreq_t(icache_dreq_t),
.icache_drsp_t(icache_drsp_t),
.icache_req_t(icache_req_t),
.icache_rtrn_t(icache_rtrn_t),
.RdTxId(ICACHE_RDTXID)
) i_cva6_icache (
.clk_i (clk_i),
.rst_ni (rst_ni),
.flush_i (icache_flush_i),
.en_i (icache_en_i),
.miss_o (icache_miss_o),
.areq_i (icache_areq_i),
.areq_o (icache_areq_o),
.dreq_i (icache_dreq_i),
.dreq_o (icache_dreq_o),
.mem_rtrn_vld_i(icache_miss_resp_valid),
.mem_rtrn_i (icache_miss_resp),
.mem_data_req_o(icache_miss_valid),
.mem_data_ack_i(icache_miss_ready),
.mem_data_o (icache_miss)
);
// }}}
// D$ instantiation
// {{{
`include "hpdcache_typedef.svh"
// 0: Page-Table Walk (PTW)
// 1: Load unit
// 2: Accelerator load
// 3: Store/AMO
// .
// .
// .
// NumPorts: CMO
// NumPorts + 1: Hardware Memory Prefetcher (hwpf)
localparam int HPDCACHE_NREQUESTERS = NumPorts + 2;
localparam hpdcache_pkg::hpdcache_user_cfg_t HPDcacheUserCfg = '{
nRequesters: HPDCACHE_NREQUESTERS,
paWidth: CVA6Cfg.PLEN,
wordWidth: CVA6Cfg.XLEN,
sets: CVA6Cfg.DCACHE_NUM_WORDS,
ways: CVA6Cfg.DCACHE_SET_ASSOC,
clWords: CVA6Cfg.DCACHE_LINE_WIDTH / CVA6Cfg.XLEN,
reqWords: 1,
reqTransIdWidth: CVA6Cfg.DcacheIdWidth,
reqSrcIdWidth: 3, // Up to 8 requesters
victimSel: hpdcache_pkg::HPDCACHE_VICTIM_RANDOM,
dataWaysPerRamWord: __minu(CVA6Cfg.DCACHE_SET_ASSOC, 128 / CVA6Cfg.XLEN),
dataSetsPerRam: CVA6Cfg.DCACHE_NUM_WORDS,
dataRamByteEnable: 1'b1,
accessWords: __maxu(CVA6Cfg.DCACHE_LINE_WIDTH / (2 * CVA6Cfg.XLEN), 1),
mshrSets: CVA6Cfg.NrLoadBufEntries < 16 ? 1 : CVA6Cfg.NrLoadBufEntries / 2,
mshrWays: CVA6Cfg.NrLoadBufEntries < 16 ? CVA6Cfg.NrLoadBufEntries : 2,
mshrWaysPerRamWord: CVA6Cfg.NrLoadBufEntries < 16 ? CVA6Cfg.NrLoadBufEntries : 2,
mshrSetsPerRam: CVA6Cfg.NrLoadBufEntries < 16 ? 1 : CVA6Cfg.NrLoadBufEntries / 2,
mshrRamByteEnable: 1'b1,
mshrUseRegbank: (CVA6Cfg.NrLoadBufEntries < 16),
refillCoreRspFeedthrough: 1'b1,
refillFifoDepth: 2,
wbufDirEntries: CVA6Cfg.WtDcacheWbufDepth,
wbufDataEntries: CVA6Cfg.WtDcacheWbufDepth,
wbufWords: 1,
wbufTimecntWidth: 3,
rtabEntries: 4,
flushEntries: 0,
flushFifoDepth: 0,
memAddrWidth: CVA6Cfg.AxiAddrWidth,
memIdWidth: CVA6Cfg.MEM_TID_WIDTH,
memDataWidth: CVA6Cfg.AxiDataWidth,
wtEn: 1'b1,
wbEn: 1'b0
};
localparam hpdcache_pkg::hpdcache_cfg_t HPDcacheCfg = hpdcache_pkg::hpdcacheBuildConfig(
HPDcacheUserCfg
);
`HPDCACHE_TYPEDEF_MEM_ATTR_T(hpdcache_mem_addr_t, hpdcache_mem_id_t, hpdcache_mem_data_t,
hpdcache_mem_be_t, HPDcacheCfg);
`HPDCACHE_TYPEDEF_MEM_REQ_T(hpdcache_mem_req_t, hpdcache_mem_addr_t, hpdcache_mem_id_t);
`HPDCACHE_TYPEDEF_MEM_RESP_R_T(hpdcache_mem_resp_r_t, hpdcache_mem_id_t, hpdcache_mem_data_t);
`HPDCACHE_TYPEDEF_MEM_REQ_W_T(hpdcache_mem_req_w_t, hpdcache_mem_data_t, hpdcache_mem_be_t);
`HPDCACHE_TYPEDEF_MEM_RESP_W_T(hpdcache_mem_resp_w_t, hpdcache_mem_id_t);
`HPDCACHE_TYPEDEF_REQ_ATTR_T(hpdcache_req_offset_t, hpdcache_data_word_t, hpdcache_data_be_t,
hpdcache_req_data_t, hpdcache_req_be_t, hpdcache_req_sid_t,
hpdcache_req_tid_t, hpdcache_tag_t, HPDcacheCfg);
`HPDCACHE_TYPEDEF_REQ_T(hpdcache_req_t, hpdcache_req_offset_t, hpdcache_req_data_t,
hpdcache_req_be_t, hpdcache_req_sid_t, hpdcache_req_tid_t,
hpdcache_tag_t);
`HPDCACHE_TYPEDEF_RSP_T(hpdcache_rsp_t, hpdcache_req_data_t, hpdcache_req_sid_t,
hpdcache_req_tid_t);
typedef logic [HPDcacheCfg.u.wbufTimecntWidth-1:0] hpdcache_wbuf_timecnt_t;
logic dcache_read_ready;
logic dcache_read_valid;
hpdcache_mem_req_t dcache_read;
logic dcache_read_resp_ready;
logic dcache_read_resp_valid;
hpdcache_mem_resp_r_t dcache_read_resp;
logic dcache_write_ready;
logic dcache_write_valid;
hpdcache_mem_req_t dcache_write;
logic dcache_write_data_ready;
logic dcache_write_data_valid;
hpdcache_mem_req_w_t dcache_write_data;
logic dcache_write_resp_ready;
logic dcache_write_resp_valid;
hpdcache_mem_resp_w_t dcache_write_resp;
cva6_hpdcache_wrapper #(
.CVA6Cfg(CVA6Cfg),
.HPDcacheCfg(HPDcacheCfg),
.dcache_req_i_t(dcache_req_i_t),
.dcache_req_o_t(dcache_req_o_t),
.NumPorts(NumPorts),
.NrHwPrefetchers(NrHwPrefetchers),
.cmo_req_t(cmo_req_t),
.cmo_rsp_t(cmo_rsp_t),
.hpdcache_mem_addr_t(hpdcache_mem_addr_t),
.hpdcache_mem_id_t(hpdcache_mem_id_t),
.hpdcache_mem_data_t(hpdcache_mem_data_t),
.hpdcache_mem_be_t(hpdcache_mem_be_t),
.hpdcache_mem_req_t(hpdcache_mem_req_t),
.hpdcache_mem_req_w_t(hpdcache_mem_req_w_t),
.hpdcache_mem_resp_r_t(hpdcache_mem_resp_r_t),
.hpdcache_mem_resp_w_t(hpdcache_mem_resp_w_t),
.hpdcache_req_offset_t(hpdcache_req_offset_t),
.hpdcache_data_word_t(hpdcache_data_word_t),
.hpdcache_req_data_t(hpdcache_req_data_t),
.hpdcache_req_be_t(hpdcache_req_be_t),
.hpdcache_req_sid_t(hpdcache_req_sid_t),
.hpdcache_req_tid_t(hpdcache_req_tid_t),
.hpdcache_tag_t(hpdcache_tag_t),
.hpdcache_req_t(hpdcache_req_t),
.hpdcache_rsp_t(hpdcache_rsp_t),
.hpdcache_wbuf_timecnt_t(hpdcache_wbuf_timecnt_t),
.hpdcache_data_be_t(hpdcache_data_be_t)
) i_dcache (
.clk_i(clk_i),
.rst_ni(rst_ni),
.dcache_enable_i(dcache_enable_i),
.dcache_flush_i(dcache_flush_i),
.dcache_flush_ack_o(dcache_flush_ack_o),
.dcache_miss_o(dcache_miss_o),
.dcache_amo_req_i(dcache_amo_req_i),
.dcache_amo_resp_o(dcache_amo_resp_o),
.dcache_cmo_req_i(dcache_cmo_req_i),
.dcache_cmo_resp_o(dcache_cmo_resp_o),
.dcache_req_ports_i(dcache_req_ports_i),
.dcache_req_ports_o(dcache_req_ports_o),
.wbuffer_empty_o(wbuffer_empty_o),
.wbuffer_not_ni_o(wbuffer_not_ni_o),
.hwpf_base_set_i(hwpf_base_set_i),
.hwpf_base_i(hwpf_base_i),
.hwpf_base_o(hwpf_base_o),
.hwpf_param_set_i(hwpf_param_set_i),
.hwpf_param_i(hwpf_param_i),
.hwpf_param_o(hwpf_param_o),
.hwpf_throttle_set_i(hwpf_throttle_set_i),
.hwpf_throttle_i(hwpf_throttle_i),
.hwpf_throttle_o(hwpf_throttle_o),
.hwpf_status_o(hwpf_status_o),
.dcache_mem_req_read_ready_i(dcache_read_ready),
.dcache_mem_req_read_valid_o(dcache_read_valid),
.dcache_mem_req_read_o(dcache_read),
.dcache_mem_resp_read_ready_o(dcache_read_resp_ready),
.dcache_mem_resp_read_valid_i(dcache_read_resp_valid),
.dcache_mem_resp_read_i(dcache_read_resp),
.dcache_mem_req_write_ready_i(dcache_write_ready),
.dcache_mem_req_write_valid_o(dcache_write_valid),
.dcache_mem_req_write_o(dcache_write),
.dcache_mem_req_write_data_ready_i(dcache_write_data_ready),
.dcache_mem_req_write_data_valid_o(dcache_write_data_valid),
.dcache_mem_req_write_data_o(dcache_write_data),
.dcache_mem_resp_write_ready_o(dcache_write_resp_ready),
.dcache_mem_resp_write_valid_i(dcache_write_resp_valid),
.dcache_mem_resp_write_i(dcache_write_resp)
);
// AXI arbiter instantiation
// {{{
cva6_hpdcache_subsystem_axi_arbiter #(
.CVA6Cfg (CVA6Cfg),
.hpdcache_mem_id_t (hpdcache_mem_id_t),
.hpdcache_mem_req_t (hpdcache_mem_req_t),
.hpdcache_mem_req_w_t (hpdcache_mem_req_w_t),
.hpdcache_mem_resp_r_t(hpdcache_mem_resp_r_t),
.hpdcache_mem_resp_w_t(hpdcache_mem_resp_w_t),
.icache_req_t (icache_req_t),
.icache_rtrn_t (icache_rtrn_t),
.AxiAddrWidth (CVA6Cfg.AxiAddrWidth),
.AxiDataWidth (CVA6Cfg.AxiDataWidth),
.AxiIdWidth (CVA6Cfg.AxiIdWidth),
.AxiUserWidth (CVA6Cfg.AxiUserWidth),
.axi_ar_chan_t(axi_ar_chan_t),
.axi_aw_chan_t(axi_aw_chan_t),
.axi_w_chan_t (axi_w_chan_t),
.axi_b_chan_t (axi_b_chan_t),
.axi_r_chan_t (axi_r_chan_t),
.axi_req_t (noc_req_t),
.axi_rsp_t (noc_resp_t)
) i_axi_arbiter (
.clk_i,
.rst_ni,
.icache_miss_valid_i(icache_miss_valid),
.icache_miss_ready_o(icache_miss_ready),
.icache_miss_i (icache_miss),
.icache_miss_id_i (hpdcache_mem_id_t'(ICACHE_RDTXID)),
.icache_miss_resp_valid_o(icache_miss_resp_valid),
.icache_miss_resp_o (icache_miss_resp),
.dcache_read_ready_o(dcache_read_ready),
.dcache_read_valid_i(dcache_read_valid),
.dcache_read_i (dcache_read),
.dcache_read_resp_ready_i(dcache_read_resp_ready),
.dcache_read_resp_valid_o(dcache_read_resp_valid),
.dcache_read_resp_o (dcache_read_resp),
.dcache_write_ready_o(dcache_write_ready),
.dcache_write_valid_i(dcache_write_valid),
.dcache_write_i (dcache_write),
.dcache_write_data_ready_o(dcache_write_data_ready),
.dcache_write_data_valid_i(dcache_write_data_valid),
.dcache_write_data_i (dcache_write_data),
.dcache_write_resp_ready_i(dcache_write_resp_ready),
.dcache_write_resp_valid_o(dcache_write_resp_valid),
.dcache_write_resp_o (dcache_write_resp),
.axi_req_o (noc_req_o),
.axi_resp_i(noc_resp_i)
);
// }}}
// Assertions
// {{{
// pragma translate_off
initial begin : initial_assertions
assert (HPDcacheCfg.u.reqSrcIdWidth >= $clog2(HPDCACHE_NREQUESTERS))
else $fatal(1, "HPDCACHE_REQ_SRC_ID_WIDTH is not wide enough");
assert (CVA6Cfg.MEM_TID_WIDTH <= CVA6Cfg.AxiIdWidth)
else $fatal(1, "MEM_TID_WIDTH shall be less or equal to the AxiIdWidth");
assert (CVA6Cfg.MEM_TID_WIDTH >= ($clog2(HPDcacheCfg.u.mshrSets * HPDcacheCfg.u.mshrWays) + 1))
else $fatal(1, "MEM_TID_WIDTH shall allow to uniquely identify all D$ and I$ miss requests ");
assert (CVA6Cfg.MEM_TID_WIDTH >= ($clog2(HPDcacheCfg.u.wbufDirEntries) + 1))
else $fatal(1, "MEM_TID_WIDTH shall allow to uniquely identify all D$ write requests ");
end
a_invalid_instruction_fetch :
assert property (
@(posedge clk_i) disable iff (!rst_ni) icache_dreq_o.valid |-> (|icache_dreq_o.data) !== 1'hX)
else
$warning(
1,
"[l1 dcache] reading invalid instructions: vaddr=%08X, data=%08X",
icache_dreq_o.vaddr,
icache_dreq_o.data
);
a_invalid_write_data :
assert property (
@(posedge clk_i) disable iff (!rst_ni) dcache_req_ports_i[2].data_req |-> |dcache_req_ports_i[2].data_be |-> (|dcache_req_ports_i[2].data_wdata) !== 1'hX)
else
$warning(
1,
"[l1 dcache] writing invalid data: paddr=%016X, be=%02X, data=%016X",
{
dcache_req_ports_i[2].address_tag, dcache_req_ports_i[2].address_index
},
dcache_req_ports_i[2].data_be,
dcache_req_ports_i[2].data_wdata
);
for (genvar j = 0; j < 2; j++) begin : gen_assertion
a_invalid_read_data :
assert property (
@(posedge clk_i) disable iff (!rst_ni) dcache_req_ports_o[j].data_rvalid && ~dcache_req_ports_i[j].kill_req |-> (|dcache_req_ports_o[j].data_rdata) !== 1'hX)
else
$warning(
1,
"[l1 dcache] reading invalid data on port %01d: data=%016X",
j,
dcache_req_ports_o[j].data_rdata
);
end
// pragma translate_on
// }}}
endmodule : cva6_hpdcache_subsystem