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

Subversion Repositories mpmc8

[/] [mpmc8/] [trunk/] [rtl/] [mpmc10/] [mpcm10_cache.sv] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2015-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
import faxi_pkg::*;
38
import mpmc10_pkg::*;
39
 
40
module mpmc10_cache(input rst, wclk, inv,
41
        input faxi_write_request256_t wchi,
42
        output faxi_write_response_t wcho,
43
        input faxi_write_request256_t ld,
44
        input ch0clk,
45
        input ch1clk,
46
        input ch2clk,
47
        input ch3clk,
48
        input ch4clk,
49
        input ch5clk,
50
        input ch6clk,
51
        input ch7clk,
52
        input faxi_read_request_t ch0i,
53
        input faxi_read_request_t ch1i,
54
        input faxi_read_request_t ch2i,
55
        input faxi_read_request_t ch3i,
56
        input faxi_read_request_t ch4i,
57
        input faxi_read_request_t ch5i,
58
        input faxi_read_request_t ch6i,
59
        input faxi_read_request_t ch7i,
60
        output faxi_read_response256_t ch0o,
61
        output faxi_read_response256_t ch1o,
62
        output faxi_read_response256_t ch2o,
63
        output faxi_read_response256_t ch3o,
64
        output faxi_read_response256_t ch4o,
65
        output faxi_read_response256_t ch5o,
66
        output faxi_read_response256_t ch6o,
67
        output faxi_read_response256_t ch7o
68
);
69
 
70
integer n,n2,n3;
71
 
72
(* ram_style="distributed" *)
73
reg [127:0] vbit [0:CACHE_ASSOC-1];
74
 
75
reg [31:0] radrr0;
76
reg [31:0] radrr1;
77
reg [31:0] radrr2;
78
reg [31:0] radrr3;
79
reg [31:0] radrr4;
80
reg [31:0] radrr5;
81
reg [31:0] radrr6;
82
reg [31:0] radrr7;
83
reg [31:0] radrr8;
84
 
85
mpmc10_cache_line_t doutb [0:8][0:3];
86
mpmc10_cache_line_t wrdata, wdata;
87
reg [31:0] wadr;
88
reg [35:0] wstrb;
89
reg [1:0] wway;
90
reg wvalid;
91
 
92
reg [CACHE_ASSOC-1:0] vbito0a;
93
reg [CACHE_ASSOC-1:0] vbito1a;
94
reg [CACHE_ASSOC-1:0] vbito2a;
95
reg [CACHE_ASSOC-1:0] vbito3a;
96
reg [CACHE_ASSOC-1:0] vbito4a;
97
reg [CACHE_ASSOC-1:0] vbito5a;
98
reg [CACHE_ASSOC-1:0] vbito6a;
99
reg [CACHE_ASSOC-1:0] vbito7a;
100
reg [CACHE_ASSOC-1:0] vbito8a;
101
 
102
reg [CACHE_ASSOC-1:0] hit0a;
103
reg [CACHE_ASSOC-1:0] hit1a;
104
reg [CACHE_ASSOC-1:0] hit2a;
105
reg [CACHE_ASSOC-1:0] hit3a;
106
reg [CACHE_ASSOC-1:0] hit4a;
107
reg [CACHE_ASSOC-1:0] hit5a;
108
reg [CACHE_ASSOC-1:0] hit6a;
109
reg [CACHE_ASSOC-1:0] hit7a;
110
reg [CACHE_ASSOC-1:0] hit8a;
111
 
112
// Always ready to accept a read request.
113
assign ch0o.ARREADY = 1'b1;
114
assign ch1o.ARREADY = 1'b1;
115
assign ch2o.ARREADY = 1'b1;
116
assign ch3o.ARREADY = 1'b1;
117
assign ch4o.ARREADY = 1'b1;
118
assign ch5o.ARREADY = 1'b1;
119
assign ch6o.ARREADY = 1'b1;
120
assign ch7o.ARREADY = 1'b1;
121
 
122
always_ff @(posedge ch0clk) radrr0 <= ch0i.ad.AADDR;
123
always_ff @(posedge ch1clk) radrr1 <= ch1i.ad.AADDR;
124
always_ff @(posedge ch2clk) radrr2 <= ch2i.ad.AADDR;
125
always_ff @(posedge ch3clk) radrr3 <= ch3i.ad.AADDR;
126
always_ff @(posedge ch4clk) radrr4 <= ch4i.ad.AADDR;
127
always_ff @(posedge ch5clk) radrr5 <= ch5i.ad.AADDR;
128
always_ff @(posedge ch6clk) radrr6 <= ch6i.ad.AADDR;
129
always_ff @(posedge ch7clk) radrr7 <= ch7i.ad.AADDR;
130
 
131
always_ff @(posedge ch0clk) ch0o.RID <= ch0i.ad.AID;
132
always_ff @(posedge ch1clk) ch1o.RID <= ch1i.ad.AID;
133
always_ff @(posedge ch2clk) ch2o.RID <= ch2i.ad.AID;
134
always_ff @(posedge ch3clk) ch3o.RID <= ch3i.ad.AID;
135
always_ff @(posedge ch4clk) ch4o.RID <= ch4i.ad.AID;
136
always_ff @(posedge ch5clk) ch5o.RID <= ch5i.ad.AID;
137
always_ff @(posedge ch6clk) ch6o.RID <= ch6i.ad.AID;
138
always_ff @(posedge ch7clk) ch7o.RID <= ch7i.ad.AID;
139
 
140
reg [8:0] rclkp;
141
always_comb
142
begin
143
        rclkp[0] = ch0clk;
144
        rclkp[1] = ch1clk;
145
        rclkp[2] = ch2clk;
146
        rclkp[3] = ch3clk;
147
        rclkp[4] = ch4clk;
148
        rclkp[5] = ch5clk;
149
        rclkp[6] = ch6clk;
150
        rclkp[7] = ch7clk;
151
        rclkp[8] = wclk;
152
end
153
 
154
reg [6:0] radr [0:8];
155
always_comb
156
begin
157
        radr[0] = ch0i.ad.AADDR[11:5];
158
        radr[1] = ch1i.ad.AADDR[11:5];
159
        radr[2] = ch2i.ad.AADDR[11:5];
160
        radr[3] = ch3i.ad.AADDR[11:5];
161
        radr[4] = ch4i.ad.AADDR[11:5];
162
        radr[5] = ch5i.ad.AADDR[11:5];
163
        radr[6] = ch6i.ad.AADDR[11:5];
164
        radr[7] = ch7i.ad.AADDR[11:5];
165
        radr[8] = wchi.ad.AADDR[11:5];
166
end
167
 
168
   // xpm_memory_sdpram: Simple Dual Port RAM
169
   // Xilinx Parameterized Macro, version 2020.2
170
 
171
genvar gway,gport;
172
 
173
generate begin : gCacheRAM
174
        for (gport = 0; gport < 9; gport = gport + 1)
175
                for (gway = 0; gway < CACHE_ASSOC; gway = gway + 1)
176
   xpm_memory_sdpram #(
177
      .ADDR_WIDTH_A(7),               // DECIMAL
178
      .ADDR_WIDTH_B(7),               // DECIMAL
179
      .AUTO_SLEEP_TIME(0),            // DECIMAL
180
      .BYTE_WRITE_WIDTH_A(8),        // DECIMAL
181
      .CASCADE_HEIGHT(0),             // DECIMAL
182
      .CLOCKING_MODE("independent_clock"), // String
183
      .ECC_MODE("no_ecc"),            // String
184
      .MEMORY_INIT_FILE("none"),      // String
185
      .MEMORY_INIT_PARAM("0"),        // String
186
      .MEMORY_OPTIMIZATION("true"),   // String
187
      .MEMORY_PRIMITIVE("block"),      // String
188
      .MEMORY_SIZE($bits(mpmc10_cache_line_t)*128),             // DECIMAL
189
      .MESSAGE_CONTROL(0),            // DECIMAL
190
      .READ_DATA_WIDTH_B($bits(mpmc10_cache_line_t)),         // DECIMAL
191
      .READ_LATENCY_B(1),             // DECIMAL
192
      .READ_RESET_VALUE_B("0"),       // String
193
      .RST_MODE_A("SYNC"),            // String
194
      .RST_MODE_B("SYNC"),            // String
195
      .SIM_ASSERT_CHK(0),             // DECIMAL; 0=disable simulation messages, 1=enable simulation messages
196
      .USE_EMBEDDED_CONSTRAINT(0),    // DECIMAL
197
      .USE_MEM_INIT(1),               // DECIMAL
198
      .WAKEUP_TIME("disable_sleep"),  // String
199
      .WRITE_DATA_WIDTH_A($bits(mpmc10_cache_line_t)),        // DECIMAL
200
      .WRITE_MODE_B("no_change")      // String
201
   )
202
   xpm_memory_sdpram_inst (
203
      .dbiterrb(),             // 1-bit output: Status signal to indicate double bit error occurrence
204
                                       // on the data output of port B.
205
 
206
      .doutb(doutb[gport][gway]),                   // READ_DATA_WIDTH_B-bit output: Data output for port B read operations.
207
      .sbiterrb(),             // 1-bit output: Status signal to indicate single bit error occurrence
208
                                       // on the data output of port B.
209
 
210
      .addra(wadr[11:5]),                                       // ADDR_WIDTH_A-bit input: Address for port A write operations.
211
      .addrb(radr[gport]),             // ADDR_WIDTH_B-bit input: Address for port B read operations.
212
      .clka(wclk),                 // 1-bit input: Clock signal for port A. Also clocks port B when
213
                                       // parameter CLOCKING_MODE is "common_clock".
214
 
215
      .clkb(rclkp[gport]),                     // 1-bit input: Clock signal for port B when parameter CLOCKING_MODE is
216
                                       // "independent_clock". Unused when parameter CLOCKING_MODE is
217
                                       // "common_clock".
218
 
219
      .dina(wdata),                // WRITE_DATA_WIDTH_A-bit input: Data input for port A write operations.
220
      .ena(wvalid & |wstrb & wway==gway),          // 1-bit input: Memory enable signal for port A. Must be high on clock
221
                                       // cycles when write operations are initiated. Pipelined internally.
222
 
223
      .enb(1'b1),                      // 1-bit input: Memory enable signal for port B. Must be high on clock
224
                                       // cycles when read operations are initiated. Pipelined internally.
225
 
226
      .injectdbiterra(1'b0), // 1-bit input: Controls double bit error injection on input data when
227
                                       // ECC enabled (Error injection capability is not available in
228
                                       // "decode_only" mode).
229
 
230
      .injectsbiterra(1'b0), // 1-bit input: Controls single bit error injection on input data when
231
                                       // ECC enabled (Error injection capability is not available in
232
                                       // "decode_only" mode).
233
 
234
      .regceb(1'b1),                 // 1-bit input: Clock Enable for the last register stage on the output
235
                                       // data path.
236
 
237
      .rstb(rst),                     // 1-bit input: Reset signal for the final port B output register stage.
238
                                       // Synchronously resets output port doutb to the value specified by
239
                                       // parameter READ_RESET_VALUE_B.
240
 
241
      .sleep(1'b0),                   // 1-bit input: sleep signal to enable the dynamic power saving feature.
242
      .wea(wstrb)                     // WRITE_DATA_WIDTH_A/BYTE_WRITE_WIDTH_A-bit input: Write enable vector
243
                                       // for port A input data port dina. 1 bit wide when word-wide writes are
244
                                       // used. In byte-wide write configurations, each bit controls the
245
                                       // writing one byte of dina to address addra. For example, to
246
                                       // synchronously write only bits [15-8] of dina when WRITE_DATA_WIDTH_A
247
                                       // is 32, wea would be 4'b0010.
248
 
249
   );
250
end
251
endgenerate
252
 
253
genvar g;
254
generate begin : gReaddat
255
        for (g = 0; g < CACHE_ASSOC; g = g + 1) begin
256
                always_ff @(posedge ch0clk) vbito0a[g] <= vbit[g][radrr0[11:5]];
257
                always_ff @(posedge ch1clk) vbito1a[g] <= vbit[g][radrr1[11:5]];
258
                always_ff @(posedge ch2clk) vbito2a[g] <= vbit[g][radrr2[11:5]];
259
                always_ff @(posedge ch3clk) vbito3a[g] <= vbit[g][radrr3[11:5]];
260
                always_ff @(posedge ch4clk) vbito4a[g] <= vbit[g][radrr4[11:5]];
261
                always_ff @(posedge ch5clk) vbito5a[g] <= vbit[g][radrr5[11:5]];
262
                always_ff @(posedge ch6clk) vbito6a[g] <= vbit[g][radrr6[11:5]];
263
                always_ff @(posedge ch7clk) vbito7a[g] <= vbit[g][radrr7[11:5]];
264
                always_ff @(posedge wclk) vbito8a[g] <= vbit[g][radrr8[11:5]];
265
 
266
                always_comb     hit0a[g] = (doutb[0][g].tag==radrr0[31:13]) && (vbito0a[g]==1'b1);
267
                always_comb     hit1a[g] = (doutb[1][g].tag==radrr1[31:13]) && (vbito1a[g]==1'b1);
268
                always_comb     hit2a[g] = (doutb[2][g].tag==radrr2[31:13]) && (vbito2a[g]==1'b1);
269
                always_comb     hit3a[g] = (doutb[3][g].tag==radrr3[31:13]) && (vbito3a[g]==1'b1);
270
                always_comb     hit4a[g] = (doutb[4][g].tag==radrr4[31:13]) && (vbito4a[g]==1'b1);
271
                always_comb     hit5a[g] = (doutb[5][g].tag==radrr5[31:13]) && (vbito5a[g]==1'b1);
272
                always_comb     hit6a[g] = (doutb[6][g].tag==radrr6[31:13]) && (vbito6a[g]==1'b1);
273
                always_comb     hit7a[g] = (doutb[7][g].tag==radrr7[31:13]) && (vbito7a[g]==1'b1);
274
                always_comb     hit8a[g] = (doutb[8][g].tag==radrr8[31:13]) && (vbito8a[g]==1'b1);
275
 
276
                always_ff @(posedge ch0clk) ch0o.RLAST <= ch0i.ad.ACOUNT==ch0i.ad.ALEN;
277
                always_ff @(posedge ch1clk) ch1o.RLAST <= ch1i.ad.ACOUNT==ch1i.ad.ALEN;
278
                always_ff @(posedge ch2clk) ch2o.RLAST <= ch2i.ad.ACOUNT==ch2i.ad.ALEN;
279
                always_ff @(posedge ch3clk) ch3o.RLAST <= ch3i.ad.ACOUNT==ch3i.ad.ALEN;
280
                always_ff @(posedge ch4clk) ch4o.RLAST <= ch4i.ad.ACOUNT==ch4i.ad.ALEN;
281
                always_ff @(posedge ch5clk) ch5o.RLAST <= ch5i.ad.ACOUNT==ch5i.ad.ALEN;
282
                always_ff @(posedge ch6clk) ch6o.RLAST <= ch6i.ad.ACOUNT==ch6i.ad.ALEN;
283
                always_ff @(posedge ch7clk) ch7o.RLAST <= ch7i.ad.ACOUNT==ch7i.ad.ALEN;
284
 
285
                always_comb ch0o.RVALID = |hit0a;
286
                always_comb ch1o.RVALID = |hit1a;
287
                always_comb ch2o.RVALID = |hit2a;
288
                always_comb ch3o.RVALID = |hit3a;
289
                always_comb ch4o.RVALID = |hit4a;
290
                always_comb ch5o.RVALID = |hit5a;
291
                always_comb ch6o.RVALID = |hit6a;
292
                always_comb ch7o.RVALID = |hit7a;
293
        end
294
end
295
endgenerate
296
 
297
always_comb
298
begin
299
        ch0o.RDATA <= 'd0;
300
        ch1o.RDATA <= 'd0;
301
        ch2o.RDATA <= 'd0;
302
        ch3o.RDATA <= 'd0;
303
        ch4o.RDATA <= 'd0;
304
        ch5o.RDATA <= 'd0;
305
        ch6o.RDATA <= 'd0;
306
        ch7o.RDATA <= 'd0;
307
        wrdata <= 'd0;
308
        for (n2 = 0; n2 < CACHE_ASSOC; n2 = n2 + 1) begin
309
                if (hit0a[n2]) ch0o.RDATA <= doutb[0][n2];
310
                if (hit1a[n2]) ch1o.RDATA <= doutb[1][n2];
311
                if (hit2a[n2]) ch2o.RDATA <= doutb[2][n2];
312
                if (hit3a[n2]) ch3o.RDATA <= doutb[3][n2];
313
                if (hit4a[n2]) ch4o.RDATA <= doutb[4][n2];
314
                if (hit5a[n2]) ch5o.RDATA <= doutb[5][n2];
315
                if (hit6a[n2]) ch6o.RDATA <= doutb[6][n2];
316
                if (hit7a[n2]) ch7o.RDATA <= doutb[7][n2];
317
                if (hit8a[n2]) wrdata <= doutb[8][n2];
318
        end
319
end
320
 
321
always_comb
322
begin
323
        ch0o.ARWAY <= 2'd0;
324
        ch1o.ARWAY <= 2'd0;
325
        ch2o.ARWAY <= 2'd0;
326
        ch3o.ARWAY <= 2'd0;
327
        ch4o.ARWAY <= 2'd0;
328
        ch5o.ARWAY <= 2'd0;
329
        ch6o.ARWAY <= 2'd0;
330
        ch7o.ARWAY <= 2'd0;
331
        wway <= 2'd0;
332
        for (n3 = 0; n3 < CACHE_ASSOC; n3 = n3 + 1) begin
333
                if (hit0a[n3]) ch0o.ARWAY <= n3;
334
                if (hit1a[n3]) ch1o.ARWAY <= n3;
335
                if (hit2a[n3]) ch2o.ARWAY <= n3;
336
                if (hit3a[n3]) ch3o.ARWAY <= n3;
337
                if (hit4a[n3]) ch4o.ARWAY <= n3;
338
                if (hit5a[n3]) ch5o.ARWAY <= n3;
339
                if (hit6a[n3]) ch6o.ARWAY <= n3;
340
                if (hit7a[n3]) ch7o.ARWAY <= n3;
341
                if (hit8a[n3]) wway <= n3;
342
        end
343
end
344
 
345
always_ff @(posedge wclk)
346
if (rst) begin
347
        for (n = 0; n < 4; n = n + 1)
348
                vbit[n] <= 'b0;
349
end
350
else begin
351
        if (|wchi.WSTRB)
352
                vbit[wchi.ad.AWAY][wchi.ad.AADDR[11:5]] <= 1'b1;
353
        else if (inv)
354
                vbit[wchi.ad.AWAY][wchi.ad.AADDR[11:5]] <= 1'b0;
355
end
356
 
357
// Pass back decode error to indicate a miss.
358
always_comb ch0o.RRESP = |hit0a ? FAXI_OKAY : FAXI_DECERR;
359
always_comb ch1o.RRESP = |hit1a ? FAXI_OKAY : FAXI_DECERR;
360
always_comb ch2o.RRESP = |hit2a ? FAXI_OKAY : FAXI_DECERR;
361
always_comb ch3o.RRESP = |hit3a ? FAXI_OKAY : FAXI_DECERR;
362
always_comb ch4o.RRESP = |hit4a ? FAXI_OKAY : FAXI_DECERR;
363
always_comb ch5o.RRESP = |hit5a ? FAXI_OKAY : FAXI_DECERR;
364
always_comb ch6o.RRESP = |hit6a ? FAXI_OKAY : FAXI_DECERR;
365
always_comb ch7o.RRESP = |hit7a ? FAXI_OKAY : FAXI_DECERR;
366
 
367
// Update the cache only if there was a write hit or if loading the cache line
368
// due to a read miss. For a read miss the entire line is updated, otherwise
369
// just the part of the line relevant to the write is updated.
370
always_ff @(posedge wclk)
371
begin
372
        wadr <= ld.ad.AWVALID ? ld.ad.AWADDR : wchi.ad.AWADDR;
373
        wstrb <= ld.WVALID ? ld.WSTRB : wchi.WSTRB & {36{|hit8a}};
374
        wvalid <= ld.WVALID ? 1'b1 : wchi.WVALID & |hit8a;
375
end
376
 
377
// Merge write data into cache line.
378
generate begin : gWrData
379
        for (g = 0; g < 32; g = g + 1)
380
                always_comb
381
                        if (ld.WVALID)
382
                                wdata[g*8+7:g*8] <= ld.WDATA[g*8+7:g*8];
383
                        else
384
                                wdata[g*8+7:g*8] <= wstrb[g] ? wchi.WDATA[g*8+7:g*8] : wrdata[g*8+7:g*8];
385
        always_comb
386
                wdata[263:256] <= wstrb[32] ? (ld.WVALID ? {ld.WTAG,ld.WMOD} : {wchi.WTAG,wchi.WMOD}) : wrdata[263:256];
387
        always_comb
388
                wdata[287:264] <= wstrb[33] ? (ld.WVALID ? {ld.WTAG,ld.WMOD} : {wchi.WTAG,wchi.WMOD}) : wrdata[287:264];
389
end
390
endgenerate
391
 
392
// Writes take two clock cycles, 1 to read the RAM and find out if it is a
393
// write hit and a second clock to write the data.
394
reg awready;
395
always_ff @(posedge wclk)
396
if (rst)
397
        awready <= 1'b1;
398
else begin
399
        awready <= 1'b1;
400
        wcho.BRESP <= FAXI_SLVERR;
401
        wcho.BVALID <= 1'b0;
402
        if (wchi.AWVALID)
403
                awready <= 1'b0;
404
        if (wchi.AWVALID & ~ld.AWVALID) begin
405
                wcho.BRESP <= FAXI_OKAY;
406
                wcho.BID <= wchi.AWID;
407
                wcho.BVALID <= 1'b1;
408
        end
409
end
410
always_comb wcho.AWREADY = awready;
411
 
412
endmodule

powered by: WebSVN 2.1.0

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