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

Subversion Repositories zap

[/] [zap/] [trunk/] [src/] [rtl/] [cpu/] [zap_cache.v] - Blame information for rev 43

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

Line No. Rev Author Line
1 26 Revanth
// -----------------------------------------------------------------------------
2
// --                                                                         --
3
// --                   (C) 2016-2018 Revanth Kamaraj.                        --
4 43 Revanth
// --                                                                         --
5 26 Revanth
// -- --------------------------------------------------------------------------
6
// --                                                                         --
7
// -- This program is free software; you can redistribute it and/or           --
8
// -- modify it under the terms of the GNU General Public License             --
9
// -- as published by the Free Software Foundation; either version 2          --
10
// -- of the License, or (at your option) any later version.                  --
11
// --                                                                         --
12
// -- This program is distributed in the hope that it will be useful,         --
13
// -- but WITHOUT ANY WARRANTY; without even the implied warranty of          --
14
// -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           --
15
// -- GNU General Public License for more details.                            --
16
// --                                                                         --
17
// -- You should have received a copy of the GNU General Public License       --
18
// -- along with this program; if not, write to the Free Software             --
19
// -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA           --
20
// -- 02110-1301, USA.                                                        --
21
// --                                                                         --
22
// -----------------------------------------------------------------------------
23 43 Revanth
// --                                                                         --
24 26 Revanth
// -- This is the top level cache module that contains the MMU and cache.     --
25 43 Revanth
// -- This will be instantiated twice in the processor TOP, once for          --
26 26 Revanth
// -- instruction and the other for data.                                     --
27
// --                                                                         --
28
// -----------------------------------------------------------------------------
29
 
30
`default_nettype none
31
 
32
module zap_cache #(
33
 
34
parameter [31:0] CACHE_SIZE             = 1024,
35
parameter [31:0] SPAGE_TLB_ENTRIES      = 8,
36
parameter [31:0] LPAGE_TLB_ENTRIES      = 8,
37
parameter [31:0] SECTION_TLB_ENTRIES    = 8
38
 
39
) /* Port List */ (
40
 
41
// Clock and reset.
42
input   wire            i_clk,
43
input   wire            i_reset,
44
 
45
// Address from processor.
46
input   wire    [31:0]  i_address,
47
input   wire    [31:0]  i_address_nxt,
48
 
49
// Other control signals from/to processor.
50
input   wire            i_rd,
51
input   wire            i_wr,
52
input   wire [3:0]      i_ben,
53
input   wire [31:0]     i_dat,
54
output wire  [31:0]     o_dat,
55
output  wire            o_ack,
56
output  wire            o_err,
57
output  wire [7:0]      o_fsr,
58
output wire [31:0]      o_far,
59
 
60
// MMU controls from/to processor.
61
input   wire            i_mmu_en,
62
input   wire            i_cache_en,
63
input   wire            i_cache_inv_req,
64
input   wire            i_cache_clean_req,
65
output wire             o_cache_inv_done,
66
output  wire            o_cache_clean_done,
67
input   wire [31:0]     i_cpsr,
68
input   wire [1:0]      i_sr,
69
input   wire [31:0]     i_baddr,
70
input   wire [31:0]     i_dac_reg,
71
input  wire             i_tlb_inv,
72
 
73
// Wishbone. Signals from all 4 modules are ORed.
74
output reg              o_wb_stb, o_wb_stb_nxt,
75
output reg              o_wb_cyc, o_wb_cyc_nxt,
76
output reg              o_wb_wen, o_wb_wen_nxt,
77
output reg  [3:0]       o_wb_sel, o_wb_sel_nxt,
78
output reg  [31:0]      o_wb_dat, o_wb_dat_nxt,
79
output reg  [31:0]      o_wb_adr, o_wb_adr_nxt,
80
output reg  [2:0]       o_wb_cti, o_wb_cti_nxt,
81
input  wire [31:0]      i_wb_dat,
82
input  wire             i_wb_ack
83
 
84
);
85
 
86
`include "zap_defines.vh"
87
`include "zap_localparams.vh"
88
`include "zap_functions.vh"
89
 
90 43 Revanth
localparam                      S0=0;
91
localparam                      S1=1;
92
localparam                      S2=2;
93 26 Revanth
 
94 43 Revanth
wire [2:0]                      wb_stb;
95
wire [2:0]                      wb_cyc;
96
wire [2:0]                      wb_wen;
97
wire [3:0]                      wb_sel [2:0];
98
wire [31:0]                     wb_dat [2:0];
99
wire [31:0]                     wb_adr [2:0];
100
wire [2:0]                      wb_cti [2:0];
101
wire [31:0]                     wb_dat0_cachefsm, wb_dat1_tagram, wb_dat2_tlb;
102
wire [31:0]                     tlb_phy_addr;
103
wire [7:0]                      tlb_fsr;
104
wire [31:0]                     tlb_far;
105
wire                            tlb_fault;
106
wire                            tlb_cacheable;
107
wire                            tlb_busy;
108
wire [127:0]                    tr_cache_line;
109
wire [127:0]                    cf_cache_line;
110
wire [15:0]                     cf_cache_line_ben;
111
wire                            cf_cache_tag_wr_en;
112
wire [`CACHE_TAG_WDT-1:0]       tr_cache_tag, cf_cache_tag;
113
wire                            tr_cache_tag_valid;
114
wire                            tr_cache_tag_dirty, cf_cache_tag_dirty;
115
wire                            cf_cache_clean_req, cf_cache_inv_req;
116
wire                            tr_cache_inv_done, tr_cache_clean_done;
117
reg [2:0]                       wb_ack;
118
reg [1:0]                       state_ff, state_nxt;
119 26 Revanth
 
120 43 Revanth
// Data from each Wishbone master.
121 26 Revanth
assign wb_dat0_cachefsm = wb_dat[0];
122 43 Revanth
assign wb_dat1_tagram   = wb_dat[1];
123
assign wb_dat2_tlb      = wb_dat[2];
124 26 Revanth
 
125 43 Revanth
// Bit 2 of Wishbone CTI is always on all CPU supported modes.
126
assign wb_cti[2] = 0;
127 26 Revanth
 
128 43 Revanth
// Basic cache FSM - serves as Master 0.
129
zap_cache_fsm #(.CACHE_SIZE(CACHE_SIZE)) u_zap_cache_fsm (
130
        .i_clk                  (i_clk),
131
        .i_reset                (i_reset),
132
        .i_address              (i_address),
133
        .i_rd                   (i_rd),
134
        .i_wr                   (i_wr),
135
        .i_din                  (i_dat),
136
        .i_ben                  (i_ben),
137
        .o_dat                  (o_dat),
138
        .o_ack                  (o_ack),
139
        .o_err                  (o_err),
140
        .o_fsr                  (o_fsr),
141
        .o_far                  (o_far),
142
        .i_cache_en             (i_cache_en),
143
        .i_cache_inv            (i_cache_inv_req),
144
        .i_cache_clean          (i_cache_clean_req),
145
        .o_cache_inv_done       (o_cache_inv_done),
146
        .o_cache_clean_done     (o_cache_clean_done),
147
        .i_cache_line           (tr_cache_line),
148
        .i_cache_tag_dirty      (tr_cache_tag_dirty),
149
        .i_cache_tag            (tr_cache_tag),
150
        .i_cache_tag_valid      (tr_cache_tag_valid),
151
        .o_cache_tag            (cf_cache_tag),
152
        .o_cache_tag_dirty      (cf_cache_tag_dirty),
153
        .o_cache_tag_wr_en      (cf_cache_tag_wr_en),
154
        .o_cache_line           (cf_cache_line),
155
        .o_cache_line_ben       (cf_cache_line_ben),
156
        .o_cache_clean_req      (cf_cache_clean_req),
157
        .i_cache_clean_done     (tr_cache_clean_done),
158
        .o_cache_inv_req        (cf_cache_inv_req),
159
        .i_cache_inv_done       (tr_cache_inv_done),
160
        .i_phy_addr             (tlb_phy_addr),
161
        .i_fsr                  (tlb_fsr),
162
        .i_far                  (tlb_far),
163
        .i_fault                (tlb_fault),
164
        .i_cacheable            (tlb_cacheable),
165
        .i_busy                 (tlb_busy),
166
        .o_wb_cyc_ff            (),
167
        .o_wb_cyc_nxt           (wb_cyc[0]),
168
        .o_wb_stb_ff            (),
169
        .o_wb_stb_nxt           (wb_stb[0]),
170
        .o_wb_adr_ff            (),
171
        .o_wb_adr_nxt           (wb_adr[0]),
172
        .o_wb_dat_ff            (),
173
        .o_wb_dat_nxt           (wb_dat[0]),
174
        .o_wb_sel_ff            (),
175
        .o_wb_sel_nxt           (wb_sel[0]),
176
        .o_wb_wen_ff            (),
177
        .o_wb_wen_nxt           (wb_wen[0]),
178
        .o_wb_cti_ff            (),
179
        .o_wb_cti_nxt           (wb_cti[0]),
180
        .i_wb_dat               (i_wb_dat),
181
        .i_wb_ack               (wb_ack[0])
182 26 Revanth
);
183
 
184 43 Revanth
// Cache Tag RAM - As a master - this performs cache clean - Master 1.
185
zap_cache_tag_ram #(.CACHE_SIZE(CACHE_SIZE)) u_zap_cache_tag_ram     (
186
        .i_clk                  (i_clk),
187
        .i_reset                (i_reset),
188
        .i_address_nxt          (i_address_nxt),
189
        .i_address              (i_address),
190
        .i_cache_en             (i_cache_en),
191
        .i_cache_line           (cf_cache_line),
192
        .o_cache_line           (tr_cache_line),
193
        .i_cache_line_ben       (cf_cache_line_ben),
194
        .i_cache_tag_wr_en      (cf_cache_tag_wr_en),
195
        .i_cache_tag            (cf_cache_tag),
196
        .i_cache_tag_dirty      (cf_cache_tag_dirty),
197
        .o_cache_tag            (tr_cache_tag),
198
        .o_cache_tag_valid      (tr_cache_tag_valid),
199
        .o_cache_tag_dirty      (tr_cache_tag_dirty),
200
        .i_cache_inv_req        (cf_cache_inv_req),
201
        .o_cache_inv_done       (tr_cache_inv_done),
202
        .i_cache_clean_req      (cf_cache_clean_req),
203
        .o_cache_clean_done     (tr_cache_clean_done),
204
        .o_wb_cyc_ff            (),
205
        .o_wb_cyc_nxt           (wb_cyc[1]),
206
        .o_wb_stb_ff            (),
207
        .o_wb_stb_nxt           (wb_stb[1]),
208
        .o_wb_adr_ff            (),
209
        .o_wb_adr_nxt           (wb_adr[1]),
210
        .o_wb_dat_ff            (),
211
        .o_wb_dat_nxt           (wb_dat[1]),
212
        .o_wb_sel_ff            (),
213
        .o_wb_sel_nxt           (wb_sel[1]),
214
        .o_wb_wen_ff            (),
215
        .o_wb_wen_nxt           (wb_wen[1]),
216
        .o_wb_cti_ff            (),
217
        .o_wb_cti_nxt           (wb_cti[1]),
218
        .i_wb_dat               (i_wb_dat),
219
        .i_wb_ack               (wb_ack[1])
220 26 Revanth
);
221
 
222 43 Revanth
// ZAP TLB control module. Includes TLB RAM inside.
223 26 Revanth
zap_tlb #(
224 43 Revanth
        .LPAGE_TLB_ENTRIES      (LPAGE_TLB_ENTRIES),
225
        .SPAGE_TLB_ENTRIES      (SPAGE_TLB_ENTRIES),
226
        .SECTION_TLB_ENTRIES    (SECTION_TLB_ENTRIES))
227 26 Revanth
u_zap_tlb (
228 43 Revanth
        .i_clk          (i_clk),
229
        .i_reset        (i_reset),
230
        .i_address      (i_address),
231
        .i_address_nxt  (i_address_nxt),
232
        .i_rd           (i_rd),
233
        .i_wr           (i_wr),
234
        .i_cpsr         (i_cpsr),
235
        .i_sr           (i_sr),
236
        .i_dac_reg      (i_dac_reg),
237
        .i_baddr        (i_baddr),
238
        .i_mmu_en       (i_mmu_en),
239
        .i_inv          (i_tlb_inv),
240
        .o_phy_addr     (tlb_phy_addr),
241
        .o_fsr          (tlb_fsr),
242
        .o_far          (tlb_far),
243
        .o_fault        (tlb_fault),
244
        .o_cacheable    (tlb_cacheable),
245
        .o_busy         (tlb_busy),
246
        .o_wb_stb_nxt   (wb_stb[2]),
247
        .o_wb_cyc_nxt   (wb_cyc[2]),
248
        .o_wb_adr_nxt   (wb_adr[2]),
249
        .o_wb_wen_nxt   (wb_wen[2]),
250
        .o_wb_sel_nxt   (wb_sel[2]),
251
        .o_wb_dat_nxt   (wb_dat[2]),
252
        .i_wb_dat       (i_wb_dat),
253
        .i_wb_ack       (wb_ack[2])
254 26 Revanth
);
255
 
256 43 Revanth
// Sequential Block
257
always @ ( posedge i_clk )
258 26 Revanth
begin
259
        if ( i_reset )
260
        begin
261
                state_ff <= S0;
262
                o_wb_stb <= 1'd0;
263
                o_wb_cyc <= 1'd0;
264
                o_wb_adr <= 32'd0;
265
                o_wb_cti <= CTI_CLASSIC;
266
                o_wb_sel <= 4'd0;
267
                o_wb_dat <= 32'd0;
268
                o_wb_wen <= 1'd0;
269
        end
270
        else
271
        begin
272
                state_ff <= state_nxt;
273
                o_wb_stb <= o_wb_stb_nxt;
274
                o_wb_cyc <= o_wb_cyc_nxt;
275
                o_wb_adr <= o_wb_adr_nxt;
276
                o_wb_cti <= o_wb_cti_nxt;
277
                o_wb_sel <= o_wb_sel_nxt;
278
                o_wb_dat <= o_wb_dat_nxt;
279
                o_wb_wen <= o_wb_wen_nxt;
280
        end
281
end
282
 
283 43 Revanth
// Next state logic.
284 26 Revanth
always @*
285
begin
286
        state_nxt = state_ff;
287
 
288
        // Change state only if strobe is inactive or strobe has just completed.
289
        if ( !o_wb_stb || (o_wb_stb && i_wb_ack) )
290
        begin
291
                casez({wb_cyc[2],wb_cyc[1],wb_cyc[0]})
292
                3'b1?? : state_nxt = S2; // TLB.
293
                3'b01? : state_nxt = S1; // Tag.
294
                3'b001 : state_nxt = S0; // Cache.
295
                default: state_nxt = state_ff;
296
                endcase
297
        end
298
end
299
 
300 43 Revanth
// Route ACKs to respective masters.
301 26 Revanth
always @*
302
begin
303
        wb_ack = 0;
304
 
305
        case(state_ff)
306
        S0: wb_ack[0] = i_wb_ack;
307
        S1: wb_ack[1] = i_wb_ack;
308
        S2: wb_ack[2] = i_wb_ack;
309
        endcase
310
end
311
 
312
// Combo signals for external MUXing.
313
always @*
314
begin
315
        o_wb_stb_nxt = wb_stb[state_nxt];
316
        o_wb_cyc_nxt = wb_cyc[state_nxt];
317
        o_wb_adr_nxt = wb_adr[state_nxt];
318
        o_wb_dat_nxt = wb_dat[state_nxt];
319
        o_wb_cti_nxt = wb_cti[state_nxt];
320
        o_wb_sel_nxt = wb_sel[state_nxt];
321
        o_wb_wen_nxt = wb_wen[state_nxt];
322
end
323
 
324 43 Revanth
// assertions_start
325
        reg     xerr = 0;
326
 
327
        always @ (posedge i_clk)
328
        begin
329
                // Check if data delivered to processor is 'x'.
330
                if ( o_dat[0] === 1'dx && o_ack && i_rd )
331
                begin
332
                        $display($time, "Error : %m Data went to x when giving data to core.");
333
                        xerr = xerr + 1;
334
                        $stop;
335
                end
336 26 Revanth
        end
337 43 Revanth
// assertions_end
338 26 Revanth
 
339 43 Revanth
endmodule // zap_cache
340
 
341 26 Revanth
`default_nettype wire

powered by: WebSVN 2.1.0

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