MMU: Refetch PTE on access fault
[microwatt.git] / dcache.vhdl
1 --
2 -- Set associative dcache write-through
3 --
4 -- TODO (in no specific order):
5 --
6 -- * See list in icache.vhdl
7 -- * Complete load misses on the cycle when WB data comes instead of
8 -- at the end of line (this requires dealing with requests coming in
9 -- while not idle...)
10 --
11 library ieee;
12 use ieee.std_logic_1164.all;
13 use ieee.numeric_std.all;
14
15 library work;
16 use work.utils.all;
17 use work.common.all;
18 use work.helpers.all;
19 use work.wishbone_types.all;
20
21 entity dcache is
22 generic (
23 -- Line size in bytes
24 LINE_SIZE : positive := 64;
25 -- Number of lines in a set
26 NUM_LINES : positive := 32;
27 -- Number of ways
28 NUM_WAYS : positive := 4;
29 -- L1 DTLB entries per set
30 TLB_SET_SIZE : positive := 64;
31 -- L1 DTLB number of sets
32 TLB_NUM_WAYS : positive := 2;
33 -- L1 DTLB log_2(page_size)
34 TLB_LG_PGSZ : positive := 12
35 );
36 port (
37 clk : in std_ulogic;
38 rst : in std_ulogic;
39
40 d_in : in Loadstore1ToDcacheType;
41 d_out : out DcacheToLoadstore1Type;
42
43 m_in : in MmuToDcacheType;
44 m_out : out DcacheToMmuType;
45
46 stall_out : out std_ulogic;
47
48 wishbone_out : out wishbone_master_out;
49 wishbone_in : in wishbone_slave_out
50 );
51 end entity dcache;
52
53 architecture rtl of dcache is
54 -- BRAM organisation: We never access more than wishbone_data_bits at
55 -- a time so to save resources we make the array only that wide, and
56 -- use consecutive indices for to make a cache "line"
57 --
58 -- ROW_SIZE is the width in bytes of the BRAM (based on WB, so 64-bits)
59 constant ROW_SIZE : natural := wishbone_data_bits / 8;
60 -- ROW_PER_LINE is the number of row (wishbone transactions) in a line
61 constant ROW_PER_LINE : natural := LINE_SIZE / ROW_SIZE;
62 -- BRAM_ROWS is the number of rows in BRAM needed to represent the full
63 -- dcache
64 constant BRAM_ROWS : natural := NUM_LINES * ROW_PER_LINE;
65
66 -- Bit fields counts in the address
67
68 -- REAL_ADDR_BITS is the number of real address bits that we store
69 constant REAL_ADDR_BITS : positive := 56;
70 -- ROW_BITS is the number of bits to select a row
71 constant ROW_BITS : natural := log2(BRAM_ROWS);
72 -- ROW_LINEBITS is the number of bits to select a row within a line
73 constant ROW_LINEBITS : natural := log2(ROW_PER_LINE);
74 -- LINE_OFF_BITS is the number of bits for the offset in a cache line
75 constant LINE_OFF_BITS : natural := log2(LINE_SIZE);
76 -- ROW_OFF_BITS is the number of bits for the offset in a row
77 constant ROW_OFF_BITS : natural := log2(ROW_SIZE);
78 -- INDEX_BITS is the number if bits to select a cache line
79 constant INDEX_BITS : natural := log2(NUM_LINES);
80 -- SET_SIZE_BITS is the log base 2 of the set size
81 constant SET_SIZE_BITS : natural := LINE_OFF_BITS + INDEX_BITS;
82 -- TAG_BITS is the number of bits of the tag part of the address
83 constant TAG_BITS : natural := REAL_ADDR_BITS - SET_SIZE_BITS;
84 -- WAY_BITS is the number of bits to select a way
85 constant WAY_BITS : natural := log2(NUM_WAYS);
86
87 -- Example of layout for 32 lines of 64 bytes:
88 --
89 -- .. tag |index| line |
90 -- .. | row | |
91 -- .. | |---| | ROW_LINEBITS (3)
92 -- .. | |--- - --| LINE_OFF_BITS (6)
93 -- .. | |- --| ROW_OFF_BITS (3)
94 -- .. |----- ---| | ROW_BITS (8)
95 -- .. |-----| | INDEX_BITS (5)
96 -- .. --------| | TAG_BITS (45)
97
98 subtype row_t is integer range 0 to BRAM_ROWS-1;
99 subtype index_t is integer range 0 to NUM_LINES-1;
100 subtype way_t is integer range 0 to NUM_WAYS-1;
101
102 -- The cache data BRAM organized as described above for each way
103 subtype cache_row_t is std_ulogic_vector(wishbone_data_bits-1 downto 0);
104
105 -- The cache tags LUTRAM has a row per set. Vivado is a pain and will
106 -- not handle a clean (commented) definition of the cache tags as a 3d
107 -- memory. For now, work around it by putting all the tags
108 subtype cache_tag_t is std_logic_vector(TAG_BITS-1 downto 0);
109 -- type cache_tags_set_t is array(way_t) of cache_tag_t;
110 -- type cache_tags_array_t is array(index_t) of cache_tags_set_t;
111 constant TAG_RAM_WIDTH : natural := TAG_BITS * NUM_WAYS;
112 subtype cache_tags_set_t is std_logic_vector(TAG_RAM_WIDTH-1 downto 0);
113 type cache_tags_array_t is array(index_t) of cache_tags_set_t;
114
115 -- The cache valid bits
116 subtype cache_way_valids_t is std_ulogic_vector(NUM_WAYS-1 downto 0);
117 type cache_valids_t is array(index_t) of cache_way_valids_t;
118
119 -- Storage. Hopefully "cache_rows" is a BRAM, the rest is LUTs
120 signal cache_tags : cache_tags_array_t;
121 signal cache_valids : cache_valids_t;
122
123 attribute ram_style : string;
124 attribute ram_style of cache_tags : signal is "distributed";
125
126 -- L1 TLB.
127 constant TLB_SET_BITS : natural := log2(TLB_SET_SIZE);
128 constant TLB_WAY_BITS : natural := log2(TLB_NUM_WAYS);
129 constant TLB_EA_TAG_BITS : natural := 64 - (TLB_LG_PGSZ + TLB_SET_BITS);
130 constant TLB_TAG_WAY_BITS : natural := TLB_NUM_WAYS * TLB_EA_TAG_BITS;
131 constant TLB_PTE_BITS : natural := 64;
132 constant TLB_PTE_WAY_BITS : natural := TLB_NUM_WAYS * TLB_PTE_BITS;
133
134 subtype tlb_way_t is integer range 0 to TLB_NUM_WAYS - 1;
135 subtype tlb_index_t is integer range 0 to TLB_SET_SIZE - 1;
136 subtype tlb_way_valids_t is std_ulogic_vector(TLB_NUM_WAYS-1 downto 0);
137 type tlb_valids_t is array(tlb_index_t) of tlb_way_valids_t;
138 subtype tlb_tag_t is std_ulogic_vector(TLB_EA_TAG_BITS - 1 downto 0);
139 subtype tlb_way_tags_t is std_ulogic_vector(TLB_TAG_WAY_BITS-1 downto 0);
140 type tlb_tags_t is array(tlb_index_t) of tlb_way_tags_t;
141 subtype tlb_pte_t is std_ulogic_vector(TLB_PTE_BITS - 1 downto 0);
142 subtype tlb_way_ptes_t is std_ulogic_vector(TLB_PTE_WAY_BITS-1 downto 0);
143 type tlb_ptes_t is array(tlb_index_t) of tlb_way_ptes_t;
144 type hit_way_set_t is array(tlb_way_t) of way_t;
145
146 signal dtlb_valids : tlb_valids_t;
147 signal dtlb_tags : tlb_tags_t;
148 signal dtlb_ptes : tlb_ptes_t;
149 attribute ram_style of dtlb_tags : signal is "distributed";
150 attribute ram_style of dtlb_ptes : signal is "distributed";
151
152 -- Record for storing permission, attribute, etc. bits from a PTE
153 type perm_attr_t is record
154 reference : std_ulogic;
155 changed : std_ulogic;
156 nocache : std_ulogic;
157 priv : std_ulogic;
158 rd_perm : std_ulogic;
159 wr_perm : std_ulogic;
160 end record;
161
162 function extract_perm_attr(pte : std_ulogic_vector(TLB_PTE_BITS - 1 downto 0)) return perm_attr_t is
163 variable pa : perm_attr_t;
164 begin
165 pa.reference := pte(8);
166 pa.changed := pte(7);
167 pa.nocache := pte(5);
168 pa.priv := pte(3);
169 pa.rd_perm := pte(2);
170 pa.wr_perm := pte(1);
171 return pa;
172 end;
173
174 constant real_mode_perm_attr : perm_attr_t := (nocache => '0', others => '1');
175
176 -- Type of operation on a "valid" input
177 type op_t is (OP_NONE,
178 OP_LOAD_HIT, -- Cache hit on load
179 OP_LOAD_MISS, -- Load missing cache
180 OP_LOAD_NC, -- Non-cachable load
181 OP_BAD, -- BAD: Cache hit on NC load/store
182 OP_TLB_ERR, -- TLB miss or protection/RC failure
183 OP_STORE_HIT, -- Store hitting cache
184 OP_STORE_MISS); -- Store missing cache
185
186 -- Cache state machine
187 type state_t is (IDLE, -- Normal load hit processing
188 RELOAD_WAIT_ACK, -- Cache reload wait ack
189 FINISH_LD_MISS, -- Extra cycle after load miss
190 STORE_WAIT_ACK, -- Store wait ack
191 NC_LOAD_WAIT_ACK);-- Non-cachable load wait ack
192
193
194 --
195 -- Dcache operations:
196 --
197 -- In order to make timing, we use the BRAMs with an output buffer,
198 -- which means that the BRAM output is delayed by an extra cycle.
199 --
200 -- Thus, the dcache has a 2-stage internal pipeline for cache hits
201 -- with no stalls.
202 --
203 -- All other operations are handled via stalling in the first stage.
204 --
205 -- The second stage can thus complete a hit at the same time as the
206 -- first stage emits a stall for a complex op.
207 --
208
209 -- Stage 0 register, basically contains just the latched request
210 type reg_stage_0_t is record
211 req : Loadstore1ToDcacheType;
212 tlbie : std_ulogic;
213 tlbld : std_ulogic;
214 mmu_req : std_ulogic; -- indicates source of request
215 end record;
216
217 signal r0 : reg_stage_0_t;
218 signal r0_valid : std_ulogic;
219
220 -- First stage register, contains state for stage 1 of load hits
221 -- and for the state machine used by all other operations
222 --
223 type reg_stage_1_t is record
224 -- Latch the complete request from ls1
225 req : Loadstore1ToDcacheType;
226 mmu_req : std_ulogic;
227
228 -- Cache hit state
229 hit_way : way_t;
230 hit_load_valid : std_ulogic;
231
232 -- Data buffer for "slow" read ops (load miss and NC loads).
233 slow_data : std_ulogic_vector(63 downto 0);
234 slow_valid : std_ulogic;
235
236 -- Signal to complete a failed stcx.
237 stcx_fail : std_ulogic;
238
239 -- Cache miss state (reload state machine)
240 state : state_t;
241 wb : wishbone_master_out;
242 store_way : way_t;
243 store_row : row_t;
244 store_index : index_t;
245
246 -- Signals to complete with error
247 error_done : std_ulogic;
248 cache_paradox : std_ulogic;
249
250 -- completion signal for tlbie
251 tlbie_done : std_ulogic;
252 end record;
253
254 signal r1 : reg_stage_1_t;
255
256 -- Reservation information
257 --
258 type reservation_t is record
259 valid : std_ulogic;
260 addr : std_ulogic_vector(63 downto LINE_OFF_BITS);
261 end record;
262
263 signal reservation : reservation_t;
264
265 -- Async signals on incoming request
266 signal req_index : index_t;
267 signal req_row : row_t;
268 signal req_hit_way : way_t;
269 signal req_tag : cache_tag_t;
270 signal req_op : op_t;
271 signal req_data : std_ulogic_vector(63 downto 0);
272 signal req_laddr : std_ulogic_vector(63 downto 0);
273
274 signal early_req_row : row_t;
275
276 signal cancel_store : std_ulogic;
277 signal set_rsrv : std_ulogic;
278 signal clear_rsrv : std_ulogic;
279
280 -- Cache RAM interface
281 type cache_ram_out_t is array(way_t) of cache_row_t;
282 signal cache_out : cache_ram_out_t;
283
284 -- PLRU output interface
285 type plru_out_t is array(index_t) of std_ulogic_vector(WAY_BITS-1 downto 0);
286 signal plru_victim : plru_out_t;
287 signal replace_way : way_t;
288
289 -- Wishbone read/write/cache write formatting signals
290 signal bus_sel : std_ulogic_vector(7 downto 0);
291
292 -- TLB signals
293 signal tlb_tag_way : tlb_way_tags_t;
294 signal tlb_pte_way : tlb_way_ptes_t;
295 signal tlb_valid_way : tlb_way_valids_t;
296 signal tlb_req_index : tlb_index_t;
297 signal tlb_hit : std_ulogic;
298 signal tlb_hit_way : tlb_way_t;
299 signal pte : tlb_pte_t;
300 signal ra : std_ulogic_vector(REAL_ADDR_BITS - 1 downto 0);
301 signal valid_ra : std_ulogic;
302 signal perm_attr : perm_attr_t;
303 signal rc_ok : std_ulogic;
304 signal perm_ok : std_ulogic;
305
306 -- TLB PLRU output interface
307 type tlb_plru_out_t is array(tlb_index_t) of std_ulogic_vector(TLB_WAY_BITS-1 downto 0);
308 signal tlb_plru_victim : tlb_plru_out_t;
309
310 --
311 -- Helper functions to decode incoming requests
312 --
313
314 -- Return the cache line index (tag index) for an address
315 function get_index(addr: std_ulogic_vector(63 downto 0)) return index_t is
316 begin
317 return to_integer(unsigned(addr(SET_SIZE_BITS - 1 downto LINE_OFF_BITS)));
318 end;
319
320 -- Return the cache row index (data memory) for an address
321 function get_row(addr: std_ulogic_vector(63 downto 0)) return row_t is
322 begin
323 return to_integer(unsigned(addr(SET_SIZE_BITS - 1 downto ROW_OFF_BITS)));
324 end;
325
326 -- Returns whether this is the last row of a line
327 function is_last_row_addr(addr: wishbone_addr_type) return boolean is
328 constant ones : std_ulogic_vector(ROW_LINEBITS-1 downto 0) := (others => '1');
329 begin
330 return addr(LINE_OFF_BITS-1 downto ROW_OFF_BITS) = ones;
331 end;
332
333 -- Returns whether this is the last row of a line
334 function is_last_row(row: row_t) return boolean is
335 variable row_v : std_ulogic_vector(ROW_BITS-1 downto 0);
336 constant ones : std_ulogic_vector(ROW_LINEBITS-1 downto 0) := (others => '1');
337 begin
338 row_v := std_ulogic_vector(to_unsigned(row, ROW_BITS));
339 return row_v(ROW_LINEBITS-1 downto 0) = ones;
340 end;
341
342 -- Return the address of the next row in the current cache line
343 function next_row_addr(addr: wishbone_addr_type) return std_ulogic_vector is
344 variable row_idx : std_ulogic_vector(ROW_LINEBITS-1 downto 0);
345 variable result : wishbone_addr_type;
346 begin
347 -- Is there no simpler way in VHDL to generate that 3 bits adder ?
348 row_idx := addr(LINE_OFF_BITS-1 downto ROW_OFF_BITS);
349 row_idx := std_ulogic_vector(unsigned(row_idx) + 1);
350 result := addr;
351 result(LINE_OFF_BITS-1 downto ROW_OFF_BITS) := row_idx;
352 return result;
353 end;
354
355 -- Return the next row in the current cache line. We use a dedicated
356 -- function in order to limit the size of the generated adder to be
357 -- only the bits within a cache line (3 bits with default settings)
358 --
359 function next_row(row: row_t) return row_t is
360 variable row_v : std_ulogic_vector(ROW_BITS-1 downto 0);
361 variable row_idx : std_ulogic_vector(ROW_LINEBITS-1 downto 0);
362 variable result : std_ulogic_vector(ROW_BITS-1 downto 0);
363 begin
364 row_v := std_ulogic_vector(to_unsigned(row, ROW_BITS));
365 row_idx := row_v(ROW_LINEBITS-1 downto 0);
366 row_v(ROW_LINEBITS-1 downto 0) := std_ulogic_vector(unsigned(row_idx) + 1);
367 return to_integer(unsigned(row_v));
368 end;
369
370 -- Get the tag value from the address
371 function get_tag(addr: std_ulogic_vector(REAL_ADDR_BITS - 1 downto 0)) return cache_tag_t is
372 begin
373 return addr(REAL_ADDR_BITS - 1 downto SET_SIZE_BITS);
374 end;
375
376 -- Read a tag from a tag memory row
377 function read_tag(way: way_t; tagset: cache_tags_set_t) return cache_tag_t is
378 begin
379 return tagset((way+1) * TAG_BITS - 1 downto way * TAG_BITS);
380 end;
381
382 -- Write a tag to tag memory row
383 procedure write_tag(way: in way_t; tagset: inout cache_tags_set_t;
384 tag: cache_tag_t) is
385 begin
386 tagset((way+1) * TAG_BITS - 1 downto way * TAG_BITS) := tag;
387 end;
388
389 -- Read a TLB tag from a TLB tag memory row
390 function read_tlb_tag(way: tlb_way_t; tags: tlb_way_tags_t) return tlb_tag_t is
391 variable j : integer;
392 begin
393 j := way * TLB_EA_TAG_BITS;
394 return tags(j + TLB_EA_TAG_BITS - 1 downto j);
395 end;
396
397 -- Write a TLB tag to a TLB tag memory row
398 procedure write_tlb_tag(way: tlb_way_t; tags: inout tlb_way_tags_t;
399 tag: tlb_tag_t) is
400 variable j : integer;
401 begin
402 j := way * TLB_EA_TAG_BITS;
403 tags(j + TLB_EA_TAG_BITS - 1 downto j) := tag;
404 end;
405
406 -- Read a PTE from a TLB PTE memory row
407 function read_tlb_pte(way: tlb_way_t; ptes: tlb_way_ptes_t) return tlb_pte_t is
408 variable j : integer;
409 begin
410 j := way * TLB_PTE_BITS;
411 return ptes(j + TLB_PTE_BITS - 1 downto j);
412 end;
413
414 procedure write_tlb_pte(way: tlb_way_t; ptes: inout tlb_way_ptes_t; newpte: tlb_pte_t) is
415 variable j : integer;
416 begin
417 j := way * TLB_PTE_BITS;
418 ptes(j + TLB_PTE_BITS - 1 downto j) := newpte;
419 end;
420
421 begin
422
423 assert LINE_SIZE mod ROW_SIZE = 0 report "LINE_SIZE not multiple of ROW_SIZE" severity FAILURE;
424 assert ispow2(LINE_SIZE) report "LINE_SIZE not power of 2" severity FAILURE;
425 assert ispow2(NUM_LINES) report "NUM_LINES not power of 2" severity FAILURE;
426 assert ispow2(ROW_PER_LINE) report "ROW_PER_LINE not power of 2" severity FAILURE;
427 assert (ROW_BITS = INDEX_BITS + ROW_LINEBITS)
428 report "geometry bits don't add up" severity FAILURE;
429 assert (LINE_OFF_BITS = ROW_OFF_BITS + ROW_LINEBITS)
430 report "geometry bits don't add up" severity FAILURE;
431 assert (REAL_ADDR_BITS = TAG_BITS + INDEX_BITS + LINE_OFF_BITS)
432 report "geometry bits don't add up" severity FAILURE;
433 assert (REAL_ADDR_BITS = TAG_BITS + ROW_BITS + ROW_OFF_BITS)
434 report "geometry bits don't add up" severity FAILURE;
435 assert (64 = wishbone_data_bits)
436 report "Can't yet handle a wishbone width that isn't 64-bits" severity FAILURE;
437
438 -- Latch the request in r0.req as long as we're not stalling
439 stage_0 : process(clk)
440 begin
441 if rising_edge(clk) then
442 if rst = '1' then
443 r0.req.valid <= '0';
444 elsif stall_out = '0' then
445 assert (d_in.valid and m_in.valid) = '0' report
446 "request collision loadstore vs MMU";
447 if m_in.valid = '1' then
448 r0.req.valid <= '1';
449 r0.req.load <= not (m_in.tlbie or m_in.tlbld);
450 r0.req.dcbz <= '0';
451 r0.req.nc <= '0';
452 r0.req.reserve <= '0';
453 r0.req.virt_mode <= '0';
454 r0.req.priv_mode <= '1';
455 r0.req.addr <= m_in.addr;
456 r0.req.data <= m_in.pte;
457 r0.req.byte_sel <= (others => '1');
458 r0.tlbie <= m_in.tlbie;
459 r0.tlbld <= m_in.tlbld;
460 r0.mmu_req <= '1';
461 else
462 r0.req <= d_in;
463 r0.tlbie <= '0';
464 r0.tlbld <= '0';
465 r0.mmu_req <= '0';
466 end if;
467 end if;
468 end if;
469 end process;
470
471 -- we don't yet handle collisions between loadstore1 requests and MMU requests
472 m_out.stall <= '0';
473
474 -- Hold off the request in r0 when stalling,
475 -- and cancel it if we get an error in a previous request.
476 r0_valid <= r0.req.valid and not stall_out and not r1.error_done;
477
478 -- TLB
479 -- Operates in the second cycle on the request latched in r0.req.
480 -- TLB updates write the entry at the end of the second cycle.
481 tlb_read : process(clk)
482 variable index : tlb_index_t;
483 variable addrbits : std_ulogic_vector(TLB_SET_BITS - 1 downto 0);
484 begin
485 if rising_edge(clk) then
486 if stall_out = '1' then
487 -- keep reading the same thing while stalled
488 index := tlb_req_index;
489 else
490 if m_in.valid = '1' then
491 addrbits := m_in.addr(TLB_LG_PGSZ + TLB_SET_BITS - 1 downto TLB_LG_PGSZ);
492 else
493 addrbits := d_in.addr(TLB_LG_PGSZ + TLB_SET_BITS - 1 downto TLB_LG_PGSZ);
494 end if;
495 index := to_integer(unsigned(addrbits));
496 end if;
497 tlb_valid_way <= dtlb_valids(index);
498 tlb_tag_way <= dtlb_tags(index);
499 tlb_pte_way <= dtlb_ptes(index);
500 end if;
501 end process;
502
503 -- Generate TLB PLRUs
504 maybe_tlb_plrus: if TLB_NUM_WAYS > 1 generate
505 begin
506 tlb_plrus: for i in 0 to TLB_SET_SIZE - 1 generate
507 -- TLB PLRU interface
508 signal tlb_plru_acc : std_ulogic_vector(TLB_WAY_BITS-1 downto 0);
509 signal tlb_plru_acc_en : std_ulogic;
510 signal tlb_plru_out : std_ulogic_vector(TLB_WAY_BITS-1 downto 0);
511 begin
512 tlb_plru : entity work.plru
513 generic map (
514 BITS => TLB_WAY_BITS
515 )
516 port map (
517 clk => clk,
518 rst => rst,
519 acc => tlb_plru_acc,
520 acc_en => tlb_plru_acc_en,
521 lru => tlb_plru_out
522 );
523
524 process(tlb_req_index, tlb_hit, tlb_hit_way, tlb_plru_out)
525 begin
526 -- PLRU interface
527 if tlb_hit = '1' and tlb_req_index = i then
528 tlb_plru_acc_en <= '1';
529 else
530 tlb_plru_acc_en <= '0';
531 end if;
532 tlb_plru_acc <= std_ulogic_vector(to_unsigned(tlb_hit_way, TLB_WAY_BITS));
533 tlb_plru_victim(i) <= tlb_plru_out;
534 end process;
535 end generate;
536 end generate;
537
538 tlb_search : process(all)
539 variable hitway : tlb_way_t;
540 variable hit : std_ulogic;
541 variable eatag : tlb_tag_t;
542 begin
543 tlb_req_index <= to_integer(unsigned(r0.req.addr(TLB_LG_PGSZ + TLB_SET_BITS - 1
544 downto TLB_LG_PGSZ)));
545 hitway := 0;
546 hit := '0';
547 eatag := r0.req.addr(63 downto TLB_LG_PGSZ + TLB_SET_BITS);
548 for i in tlb_way_t loop
549 if tlb_valid_way(i) = '1' and
550 read_tlb_tag(i, tlb_tag_way) = eatag then
551 hitway := i;
552 hit := '1';
553 end if;
554 end loop;
555 tlb_hit <= hit and r0_valid;
556 tlb_hit_way <= hitway;
557 if tlb_hit = '1' then
558 pte <= read_tlb_pte(hitway, tlb_pte_way);
559 else
560 pte <= (others => '0');
561 end if;
562 valid_ra <= tlb_hit or not r0.req.virt_mode;
563 if r0.req.virt_mode = '1' then
564 ra <= pte(REAL_ADDR_BITS - 1 downto TLB_LG_PGSZ) &
565 r0.req.addr(TLB_LG_PGSZ - 1 downto 0);
566 perm_attr <= extract_perm_attr(pte);
567 else
568 ra <= r0.req.addr(REAL_ADDR_BITS - 1 downto 0);
569 perm_attr <= real_mode_perm_attr;
570 end if;
571 end process;
572
573 tlb_update : process(clk)
574 variable tlbie : std_ulogic;
575 variable tlbia : std_ulogic;
576 variable tlbwe : std_ulogic;
577 variable repl_way : tlb_way_t;
578 variable eatag : tlb_tag_t;
579 variable tagset : tlb_way_tags_t;
580 variable pteset : tlb_way_ptes_t;
581 begin
582 if rising_edge(clk) then
583 tlbie := '0';
584 tlbia := '0';
585 tlbwe := r0_valid and r0.tlbld;
586 if r0_valid = '1' and r0.tlbie = '1' then
587 if r0.req.addr(11 downto 10) /= "00" then
588 tlbia := '1';
589 elsif r0.req.addr(9) = '1' then
590 tlbwe := '1';
591 else
592 tlbie := '1';
593 end if;
594 end if;
595 if rst = '1' or tlbia = '1' then
596 -- clear all valid bits at once
597 for i in tlb_index_t loop
598 dtlb_valids(i) <= (others => '0');
599 end loop;
600 elsif tlbie = '1' then
601 if tlb_hit = '1' then
602 dtlb_valids(tlb_req_index)(tlb_hit_way) <= '0';
603 end if;
604 elsif tlbwe = '1' then
605 if tlb_hit = '1' then
606 repl_way := tlb_hit_way;
607 else
608 repl_way := to_integer(unsigned(tlb_plru_victim(tlb_req_index)));
609 end if;
610 eatag := r0.req.addr(63 downto TLB_LG_PGSZ + TLB_SET_BITS);
611 tagset := tlb_tag_way;
612 write_tlb_tag(repl_way, tagset, eatag);
613 dtlb_tags(tlb_req_index) <= tagset;
614 pteset := tlb_pte_way;
615 write_tlb_pte(repl_way, pteset, r0.req.data);
616 dtlb_ptes(tlb_req_index) <= pteset;
617 dtlb_valids(tlb_req_index)(repl_way) <= '1';
618 end if;
619 end if;
620 end process;
621
622 -- Generate PLRUs
623 maybe_plrus: if NUM_WAYS > 1 generate
624 begin
625 plrus: for i in 0 to NUM_LINES-1 generate
626 -- PLRU interface
627 signal plru_acc : std_ulogic_vector(WAY_BITS-1 downto 0);
628 signal plru_acc_en : std_ulogic;
629 signal plru_out : std_ulogic_vector(WAY_BITS-1 downto 0);
630
631 begin
632 plru : entity work.plru
633 generic map (
634 BITS => WAY_BITS
635 )
636 port map (
637 clk => clk,
638 rst => rst,
639 acc => plru_acc,
640 acc_en => plru_acc_en,
641 lru => plru_out
642 );
643
644 process(req_index, req_op, req_hit_way, plru_out)
645 begin
646 -- PLRU interface
647 if (req_op = OP_LOAD_HIT or
648 req_op = OP_STORE_HIT) and req_index = i then
649 plru_acc_en <= '1';
650 else
651 plru_acc_en <= '0';
652 end if;
653 plru_acc <= std_ulogic_vector(to_unsigned(req_hit_way, WAY_BITS));
654 plru_victim(i) <= plru_out;
655 end process;
656 end generate;
657 end generate;
658
659 -- Cache request parsing and hit detection
660 dcache_request : process(all)
661 variable is_hit : std_ulogic;
662 variable hit_way : way_t;
663 variable op : op_t;
664 variable opsel : std_ulogic_vector(2 downto 0);
665 variable go : std_ulogic;
666 variable nc : std_ulogic;
667 variable s_hit : std_ulogic;
668 variable s_tag : cache_tag_t;
669 variable s_pte : tlb_pte_t;
670 variable s_ra : std_ulogic_vector(REAL_ADDR_BITS - 1 downto 0);
671 variable hit_set : std_ulogic_vector(TLB_NUM_WAYS - 1 downto 0);
672 variable hit_way_set : hit_way_set_t;
673 begin
674 -- Extract line, row and tag from request
675 req_index <= get_index(r0.req.addr);
676 req_row <= get_row(r0.req.addr);
677 req_tag <= get_tag(ra);
678
679 -- Only do anything if not being stalled by stage 1
680 go := r0_valid and not (r0.tlbie or r0.tlbld);
681
682 -- Calculate address of beginning of cache line, will be
683 -- used for cache miss processing if needed
684 --
685 req_laddr <= (63 downto REAL_ADDR_BITS => '0') &
686 ra(REAL_ADDR_BITS - 1 downto LINE_OFF_BITS) &
687 (LINE_OFF_BITS-1 downto 0 => '0');
688
689 -- Test if pending request is a hit on any way
690 -- In order to make timing in virtual mode, when we are using the TLB,
691 -- we compare each way with each of the real addresses from each way of
692 -- the TLB, and then decide later which match to use.
693 hit_way := 0;
694 is_hit := '0';
695 if r0.req.virt_mode = '1' then
696 for j in tlb_way_t loop
697 hit_way_set(j) := 0;
698 s_hit := '0';
699 s_pte := read_tlb_pte(j, tlb_pte_way);
700 s_ra := s_pte(REAL_ADDR_BITS - 1 downto TLB_LG_PGSZ) &
701 r0.req.addr(TLB_LG_PGSZ - 1 downto 0);
702 s_tag := get_tag(s_ra);
703 for i in way_t loop
704 if go = '1' and cache_valids(req_index)(i) = '1' and
705 read_tag(i, cache_tags(req_index)) = s_tag and
706 tlb_valid_way(j) = '1' then
707 hit_way_set(j) := i;
708 s_hit := '1';
709 end if;
710 end loop;
711 hit_set(j) := s_hit;
712 end loop;
713 if tlb_hit = '1' then
714 is_hit := hit_set(tlb_hit_way);
715 hit_way := hit_way_set(tlb_hit_way);
716 end if;
717 else
718 s_tag := get_tag(r0.req.addr(REAL_ADDR_BITS - 1 downto 0));
719 for i in way_t loop
720 if go = '1' and cache_valids(req_index)(i) = '1' and
721 read_tag(i, cache_tags(req_index)) = s_tag then
722 hit_way := i;
723 is_hit := '1';
724 end if;
725 end loop;
726 end if;
727
728 -- The way that matched on a hit
729 req_hit_way <= hit_way;
730
731 -- The way to replace on a miss
732 replace_way <= to_integer(unsigned(plru_victim(req_index)));
733
734 -- work out whether we have permission for this access
735 -- NB we don't yet implement AMR, thus no KUAP
736 rc_ok <= perm_attr.reference and (r0.req.load or perm_attr.changed);
737 perm_ok <= (r0.req.priv_mode or not perm_attr.priv) and
738 (perm_attr.wr_perm or (r0.req.load and perm_attr.rd_perm));
739
740 -- Combine the request and cache hit status to decide what
741 -- operation needs to be done
742 --
743 nc := r0.req.nc or perm_attr.nocache;
744 op := OP_NONE;
745 if go = '1' then
746 if valid_ra = '1' and rc_ok = '1' and perm_ok = '1' then
747 opsel := r0.req.load & nc & is_hit;
748 case opsel is
749 when "101" => op := OP_LOAD_HIT;
750 when "100" => op := OP_LOAD_MISS;
751 when "110" => op := OP_LOAD_NC;
752 when "001" => op := OP_STORE_HIT;
753 when "000" => op := OP_STORE_MISS;
754 when "010" => op := OP_STORE_MISS;
755 when "011" => op := OP_BAD;
756 when "111" => op := OP_BAD;
757 when others => op := OP_NONE;
758 end case;
759 else
760 op := OP_TLB_ERR;
761 end if;
762 end if;
763 req_op <= op;
764
765 -- Version of the row number that is valid one cycle earlier
766 -- in the cases where we need to read the cache data BRAM.
767 -- If we're stalling then we need to keep reading the last
768 -- row requested.
769 if stall_out = '0' then
770 if m_in.valid = '1' then
771 early_req_row <= get_row(m_in.addr);
772 else
773 early_req_row <= get_row(d_in.addr);
774 end if;
775 else
776 early_req_row <= req_row;
777 end if;
778 end process;
779
780 -- Wire up wishbone request latch out of stage 1
781 wishbone_out <= r1.wb;
782
783 -- Generate stalls from stage 1 state machine
784 stall_out <= '1' when r1.state /= IDLE else '0';
785
786 -- Handle load-with-reservation and store-conditional instructions
787 reservation_comb: process(all)
788 begin
789 cancel_store <= '0';
790 set_rsrv <= '0';
791 clear_rsrv <= '0';
792 if r0_valid = '1' and r0.req.reserve = '1' then
793 -- XXX generate alignment interrupt if address is not aligned
794 -- XXX or if r0.req.nc = '1'
795 if r0.req.load = '1' then
796 -- load with reservation
797 set_rsrv <= '1';
798 else
799 -- store conditional
800 clear_rsrv <= '1';
801 if reservation.valid = '0' or
802 r0.req.addr(63 downto LINE_OFF_BITS) /= reservation.addr then
803 cancel_store <= '1';
804 end if;
805 end if;
806 end if;
807 end process;
808
809 reservation_reg: process(clk)
810 begin
811 if rising_edge(clk) then
812 if rst = '1' or clear_rsrv = '1' then
813 reservation.valid <= '0';
814 elsif set_rsrv = '1' then
815 reservation.valid <= '1';
816 reservation.addr <= r0.req.addr(63 downto LINE_OFF_BITS);
817 end if;
818 end if;
819 end process;
820
821 -- Return data for loads & completion control logic
822 --
823 writeback_control: process(all)
824 begin
825
826 -- The mux on d_out.data defaults to the normal load hit case.
827 d_out.valid <= '0';
828 d_out.data <= cache_out(r1.hit_way);
829 d_out.store_done <= '0';
830 d_out.error <= '0';
831 d_out.cache_paradox <= '0';
832
833 -- Outputs to MMU
834 m_out.done <= r1.tlbie_done;
835 m_out.err <= '0';
836 m_out.data <= cache_out(r1.hit_way);
837
838 -- We have a valid load or store hit or we just completed a slow
839 -- op such as a load miss, a NC load or a store
840 --
841 -- Note: the load hit is delayed by one cycle. However it can still
842 -- not collide with r.slow_valid (well unless I miscalculated) because
843 -- slow_valid can only be set on a subsequent request and not on its
844 -- first cycle (the state machine must have advanced), which makes
845 -- slow_valid at least 2 cycles from the previous hit_load_valid.
846 --
847
848 -- Sanity: Only one of these must be set in any given cycle
849 assert (r1.slow_valid and r1.stcx_fail) /= '1' report
850 "unexpected slow_valid collision with stcx_fail"
851 severity FAILURE;
852 assert ((r1.slow_valid or r1.stcx_fail) and r1.hit_load_valid) /= '1' report
853 "unexpected hit_load_delayed collision with slow_valid"
854 severity FAILURE;
855
856 if r1.mmu_req = '0' then
857 -- Request came from loadstore1...
858 -- Load hit case is the standard path
859 if r1.hit_load_valid = '1' then
860 report "completing load hit";
861 d_out.valid <= '1';
862 end if;
863
864 -- error cases complete without stalling
865 if r1.error_done = '1' then
866 report "completing ld/st with error";
867 d_out.error <= '1';
868 d_out.cache_paradox <= r1.cache_paradox;
869 d_out.valid <= '1';
870 end if;
871
872 -- Slow ops (load miss, NC, stores)
873 if r1.slow_valid = '1' then
874 -- If it's a load, enable register writeback and switch
875 -- mux accordingly
876 --
877 if r1.req.load then
878 -- Read data comes from the slow data latch
879 d_out.data <= r1.slow_data;
880 end if;
881 d_out.store_done <= '1';
882
883 report "completing store or load miss";
884 d_out.valid <= '1';
885 end if;
886
887 if r1.stcx_fail = '1' then
888 d_out.store_done <= '0';
889 d_out.valid <= '1';
890 end if;
891
892 else
893 -- Request came from MMU
894 if r1.hit_load_valid = '1' then
895 report "completing load hit to MMU, data=" & to_hstring(m_out.data);
896 m_out.done <= '1';
897 end if;
898
899 -- error cases complete without stalling
900 if r1.error_done = '1' then
901 report "completing MMU ld with error";
902 m_out.err <= '1';
903 m_out.done <= '1';
904 end if;
905
906 -- Slow ops (i.e. load miss)
907 if r1.slow_valid = '1' then
908 -- Read data comes from the slow data latch
909 m_out.data <= r1.slow_data;
910 report "completing MMU load miss, data=" & to_hstring(m_out.data);
911 m_out.done <= '1';
912 end if;
913 end if;
914
915 end process;
916
917 --
918 -- Generate a cache RAM for each way. This handles the normal
919 -- reads, writes from reloads and the special store-hit update
920 -- path as well.
921 --
922 -- Note: the BRAMs have an extra read buffer, meaning the output
923 -- is pipelined an extra cycle. This differs from the
924 -- icache. The writeback logic needs to take that into
925 -- account by using 1-cycle delayed signals for load hits.
926 --
927 rams: for i in 0 to NUM_WAYS-1 generate
928 signal do_read : std_ulogic;
929 signal rd_addr : std_ulogic_vector(ROW_BITS-1 downto 0);
930 signal do_write : std_ulogic;
931 signal wr_addr : std_ulogic_vector(ROW_BITS-1 downto 0);
932 signal wr_data : std_ulogic_vector(wishbone_data_bits-1 downto 0);
933 signal wr_sel : std_ulogic_vector(ROW_SIZE-1 downto 0);
934 signal dout : cache_row_t;
935 begin
936 way: entity work.cache_ram
937 generic map (
938 ROW_BITS => ROW_BITS,
939 WIDTH => wishbone_data_bits,
940 ADD_BUF => true
941 )
942 port map (
943 clk => clk,
944 rd_en => do_read,
945 rd_addr => rd_addr,
946 rd_data => dout,
947 wr_en => do_write,
948 wr_sel => wr_sel,
949 wr_addr => wr_addr,
950 wr_data => wr_data
951 );
952 process(all)
953 variable tmp_adr : std_ulogic_vector(63 downto 0);
954 variable reloading : boolean;
955 begin
956 -- Cache hit reads
957 do_read <= '1';
958 rd_addr <= std_ulogic_vector(to_unsigned(early_req_row, ROW_BITS));
959 cache_out(i) <= dout;
960
961 -- Write mux:
962 --
963 -- Defaults to wishbone read responses (cache refill),
964 --
965 -- For timing, the mux on wr_data/sel/addr is not dependent on anything
966 -- other than the current state. Only the do_write signal is.
967 --
968 if r1.state = IDLE then
969 -- In IDLE state, the only write path is the store-hit update case
970 wr_addr <= std_ulogic_vector(to_unsigned(req_row, ROW_BITS));
971 wr_data <= r0.req.data;
972 wr_sel <= r0.req.byte_sel;
973 else
974 -- Otherwise, we might be doing a reload or a DCBZ
975 if r1.req.dcbz = '1' then
976 wr_data <= (others => '0');
977 else
978 wr_data <= wishbone_in.dat;
979 end if;
980 wr_sel <= (others => '1');
981 wr_addr <= std_ulogic_vector(to_unsigned(r1.store_row, ROW_BITS));
982 end if;
983
984 -- The two actual write cases here
985 do_write <= '0';
986 reloading := r1.state = RELOAD_WAIT_ACK;
987 if reloading and wishbone_in.ack = '1' and r1.store_way = i then
988 do_write <= '1';
989 end if;
990 if req_op = OP_STORE_HIT and req_hit_way = i and cancel_store = '0' and
991 r1.req.dcbz = '0' then
992 assert not reloading report "Store hit while in state:" &
993 state_t'image(r1.state)
994 severity FAILURE;
995 do_write <= '1';
996 end if;
997 end process;
998 end generate;
999
1000 --
1001 -- Cache hit synchronous machine for the easy case. This handles load hits.
1002 -- It also handles error cases (TLB miss, cache paradox)
1003 --
1004 dcache_fast_hit : process(clk)
1005 begin
1006 if rising_edge(clk) then
1007 -- If we have a request incoming, we have to latch it as r0.req.valid
1008 -- is only set for a single cycle. It's up to the control logic to
1009 -- ensure we don't override an uncompleted request (for now we are
1010 -- single issue on load/stores so we are fine, later, we can generate
1011 -- a stall output if necessary).
1012
1013 if req_op /= OP_NONE and stall_out = '0' then
1014 r1.req <= r0.req;
1015 r1.mmu_req <= r0.mmu_req;
1016 report "op:" & op_t'image(req_op) &
1017 " addr:" & to_hstring(r0.req.addr) &
1018 " nc:" & std_ulogic'image(r0.req.nc) &
1019 " idx:" & integer'image(req_index) &
1020 " tag:" & to_hstring(req_tag) &
1021 " way: " & integer'image(req_hit_way);
1022 end if;
1023
1024 -- Fast path for load/store hits. Set signals for the writeback controls.
1025 if req_op = OP_LOAD_HIT then
1026 r1.hit_way <= req_hit_way;
1027 r1.hit_load_valid <= '1';
1028 else
1029 r1.hit_load_valid <= '0';
1030 end if;
1031
1032 if req_op = OP_TLB_ERR then
1033 report "Signalling ld/st error valid_ra=" & std_ulogic'image(valid_ra) &
1034 " rc_ok=" & std_ulogic'image(rc_ok) & " perm_ok=" & std_ulogic'image(perm_ok);
1035 r1.error_done <= '1';
1036 r1.cache_paradox <= '0';
1037 elsif req_op = OP_BAD then
1038 report "Signalling cache paradox";
1039 r1.error_done <= '1';
1040 r1.cache_paradox <= '1';
1041 else
1042 r1.error_done <= '0';
1043 r1.cache_paradox <= '0';
1044 end if;
1045
1046 -- complete tlbies and TLB loads in the third cycle
1047 r1.tlbie_done <= r0_valid and (r0.tlbie or r0.tlbld);
1048 end if;
1049 end process;
1050
1051 --
1052 -- Every other case is handled by this state machine:
1053 --
1054 -- * Cache load miss/reload (in conjunction with "rams")
1055 -- * Load hits for non-cachable forms
1056 -- * Stores (the collision case is handled in "rams")
1057 --
1058 -- All wishbone requests generation is done here. This machine
1059 -- operates at stage 1.
1060 --
1061 dcache_slow : process(clk)
1062 variable tagset : cache_tags_set_t;
1063 variable stbs_done : boolean;
1064 begin
1065 if rising_edge(clk) then
1066 -- On reset, clear all valid bits to force misses
1067 if rst = '1' then
1068 for i in index_t loop
1069 cache_valids(i) <= (others => '0');
1070 end loop;
1071 r1.state <= IDLE;
1072 r1.slow_valid <= '0';
1073 r1.wb.cyc <= '0';
1074 r1.wb.stb <= '0';
1075
1076 -- Not useful normally but helps avoiding tons of sim warnings
1077 r1.wb.adr <= (others => '0');
1078 else
1079 -- One cycle pulses reset
1080 r1.slow_valid <= '0';
1081 r1.stcx_fail <= '0';
1082
1083 -- Main state machine
1084 case r1.state is
1085 when IDLE =>
1086 case req_op is
1087 when OP_LOAD_HIT =>
1088 -- stay in IDLE state
1089
1090 when OP_LOAD_MISS =>
1091 -- Normal load cache miss, start the reload machine
1092 --
1093 report "cache miss addr:" & to_hstring(r0.req.addr) &
1094 " idx:" & integer'image(req_index) &
1095 " way:" & integer'image(replace_way) &
1096 " tag:" & to_hstring(req_tag);
1097
1098 -- Force misses on that way while reloading that line
1099 cache_valids(req_index)(replace_way) <= '0';
1100
1101 -- Store new tag in selected way
1102 for i in 0 to NUM_WAYS-1 loop
1103 if i = replace_way then
1104 tagset := cache_tags(req_index);
1105 write_tag(i, tagset, req_tag);
1106 cache_tags(req_index) <= tagset;
1107 end if;
1108 end loop;
1109
1110 -- Keep track of our index and way for subsequent stores.
1111 r1.store_index <= req_index;
1112 r1.store_way <= replace_way;
1113 r1.store_row <= get_row(req_laddr);
1114
1115 -- Prep for first wishbone read. We calculate the address of
1116 -- the start of the cache line and start the WB cycle
1117 --
1118 r1.wb.adr <= req_laddr(r1.wb.adr'left downto 0);
1119 r1.wb.sel <= (others => '1');
1120 r1.wb.we <= '0';
1121 r1.wb.cyc <= '1';
1122 r1.wb.stb <= '1';
1123
1124 -- Track that we had one request sent
1125 r1.state <= RELOAD_WAIT_ACK;
1126
1127 when OP_LOAD_NC =>
1128 r1.wb.sel <= r0.req.byte_sel;
1129 r1.wb.adr <= ra(r1.wb.adr'left downto 3) & "000";
1130 r1.wb.cyc <= '1';
1131 r1.wb.stb <= '1';
1132 r1.wb.we <= '0';
1133 r1.state <= NC_LOAD_WAIT_ACK;
1134
1135 when OP_STORE_HIT | OP_STORE_MISS =>
1136 if r0.req.dcbz = '0' then
1137 r1.wb.sel <= r0.req.byte_sel;
1138 r1.wb.adr <= ra(r1.wb.adr'left downto 3) & "000";
1139 r1.wb.dat <= r0.req.data;
1140 if cancel_store = '0' then
1141 r1.wb.cyc <= '1';
1142 r1.wb.stb <= '1';
1143 r1.wb.we <= '1';
1144 r1.state <= STORE_WAIT_ACK;
1145 else
1146 r1.stcx_fail <= '1';
1147 r1.state <= IDLE;
1148 end if;
1149 else
1150 -- dcbz is handled much like a load miss except
1151 -- that we are writing to memory instead of reading
1152 r1.store_index <= req_index;
1153 r1.store_row <= get_row(req_laddr);
1154
1155 if req_op = OP_STORE_HIT then
1156 r1.store_way <= req_hit_way;
1157 else
1158 r1.store_way <= replace_way;
1159
1160 -- Force misses on the victim way while zeroing
1161 cache_valids(req_index)(replace_way) <= '0';
1162
1163 -- Store new tag in selected way
1164 for i in 0 to NUM_WAYS-1 loop
1165 if i = replace_way then
1166 tagset := cache_tags(req_index);
1167 write_tag(i, tagset, req_tag);
1168 cache_tags(req_index) <= tagset;
1169 end if;
1170 end loop;
1171 end if;
1172
1173 -- Set up for wishbone writes
1174 r1.wb.adr <= req_laddr(r1.wb.adr'left downto 0);
1175 r1.wb.sel <= (others => '1');
1176 r1.wb.we <= '1';
1177 r1.wb.dat <= (others => '0');
1178 r1.wb.cyc <= '1';
1179 r1.wb.stb <= '1';
1180
1181 -- Handle the rest like a load miss
1182 r1.state <= RELOAD_WAIT_ACK;
1183 end if;
1184
1185 -- OP_NONE and OP_BAD do nothing
1186 -- OP_BAD was handled above already
1187 when OP_NONE =>
1188 when OP_BAD =>
1189 when OP_TLB_ERR =>
1190 end case;
1191
1192 when RELOAD_WAIT_ACK =>
1193 -- Requests are all sent if stb is 0
1194 stbs_done := r1.wb.stb = '0';
1195
1196 -- If we are still sending requests, was one accepted ?
1197 if wishbone_in.stall = '0' and not stbs_done then
1198 -- That was the last word ? We are done sending. Clear
1199 -- stb and set stbs_done so we can handle an eventual last
1200 -- ack on the same cycle.
1201 --
1202 if is_last_row_addr(r1.wb.adr) then
1203 r1.wb.stb <= '0';
1204 stbs_done := true;
1205 end if;
1206
1207 -- Calculate the next row address
1208 r1.wb.adr <= next_row_addr(r1.wb.adr);
1209 end if;
1210
1211 -- Incoming acks processing
1212 if wishbone_in.ack = '1' then
1213 -- Is this the data we were looking for ? Latch it so
1214 -- we can respond later. We don't currently complete the
1215 -- pending miss request immediately, we wait for the
1216 -- whole line to be loaded. The reason is that if we
1217 -- did, we would potentially get new requests in while
1218 -- not idle, which we don't currently know how to deal
1219 -- with.
1220 --
1221 if r1.store_row = get_row(r1.req.addr) and r1.req.dcbz = '0' then
1222 r1.slow_data <= wishbone_in.dat;
1223 end if;
1224
1225 -- Check for completion
1226 if stbs_done and is_last_row(r1.store_row) then
1227 -- Complete wishbone cycle
1228 r1.wb.cyc <= '0';
1229
1230 -- Cache line is now valid
1231 cache_valids(r1.store_index)(r1.store_way) <= '1';
1232
1233 -- Don't complete and go idle until next cycle, in
1234 -- case the next request is for the last dword of
1235 -- the cache line we just loaded.
1236 r1.state <= FINISH_LD_MISS;
1237 end if;
1238
1239 -- Increment store row counter
1240 r1.store_row <= next_row(r1.store_row);
1241 end if;
1242
1243 when FINISH_LD_MISS =>
1244 -- Write back the load data that we got
1245 r1.slow_valid <= '1';
1246 r1.state <= IDLE;
1247 report "completing miss !";
1248
1249 when STORE_WAIT_ACK | NC_LOAD_WAIT_ACK =>
1250 -- Clear stb when slave accepted request
1251 if wishbone_in.stall = '0' then
1252 r1.wb.stb <= '0';
1253 end if;
1254
1255 -- Got ack ? complete.
1256 if wishbone_in.ack = '1' then
1257 if r1.state = NC_LOAD_WAIT_ACK then
1258 r1.slow_data <= wishbone_in.dat;
1259 end if;
1260 r1.state <= IDLE;
1261 r1.slow_valid <= '1';
1262 r1.wb.cyc <= '0';
1263 r1.wb.stb <= '0';
1264 end if;
1265 end case;
1266 end if;
1267 end if;
1268 end process;
1269 end;