source: rtems/c/src/lib/libbsp/arm/shared/arm-l2c-310/cache_.h @ 55741886

4.115
Last change on this file since 55741886 was 55741886, checked in by Sebastian Huber <sebastian.huber@…>, on 11/19/14 at 13:19:13

bsps/arm: L2C 310 exclusive config is fatal

  • Property mode set to 100644
File size: 38.4 KB
Line 
1/**
2 * @file cache_.h
3 *
4 * @ingroup L2C-310_cache
5 *
6 * @brief Cache definitions and functions.
7 *
8 * This file implements handling for the ARM L2C-310 cache controller
9 */
10
11/*
12 * Authorship
13 * ----------
14 * This software was created by
15 *     R. Claus <claus@slac.stanford.edu>, 2013,
16 *       Stanford Linear Accelerator Center, Stanford University.
17 *
18 * Acknowledgement of sponsorship
19 * ------------------------------
20 * This software was produced by
21 *     the Stanford Linear Accelerator Center, Stanford University,
22 *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
23 *
24 * Government disclaimer of liability
25 * ----------------------------------
26 * Neither the United States nor the United States Department of Energy,
27 * nor any of their employees, makes any warranty, express or implied, or
28 * assumes any legal liability or responsibility for the accuracy,
29 * completeness, or usefulness of any data, apparatus, product, or process
30 * disclosed, or represents that its use would not infringe privately owned
31 * rights.
32 *
33 * Stanford disclaimer of liability
34 * --------------------------------
35 * Stanford University makes no representations or warranties, express or
36 * implied, nor assumes any liability for the use of this software.
37 *
38 * Stanford disclaimer of copyright
39 * --------------------------------
40 * Stanford University, owner of the copyright, hereby disclaims its
41 * copyright and all other rights in this software.  Hence, anyone may
42 * freely use it for any purpose without restriction.
43 *
44 * Maintenance of notices
45 * ----------------------
46 * In the interest of clarity regarding the origin and status of this
47 * SLAC software, this and all the preceding Stanford University notices
48 * are to remain affixed to any copy or derivative of this software made
49 * or distributed by the recipient and are to be affixed to any copy of
50 * software made or distributed by the recipient that contains a copy or
51 * derivative of this software.
52 *
53 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
54 */
55
56#ifndef LIBBSP_ARM_SHARED_L2C_310_CACHE_H
57#define LIBBSP_ARM_SHARED_L2C_310_CACHE_H
58
59#include <assert.h>
60#include <bsp.h>
61#include <bsp/fatal.h>
62#include <libcpu/arm-cp15.h>
63#include <rtems/rtems/intr.h>
64#include <bsp/arm-release-id.h>
65#include <bsp/arm-errata.h>
66#include "../include/arm-cache-l1.h"
67
68#ifdef __cplusplus
69extern "C" {
70#endif /* __cplusplus */
71
72/* These two defines also ensure that the rtems_cache_* functions have bodies */
73#define CPU_DATA_CACHE_ALIGNMENT ARM_CACHE_L1_CPU_DATA_ALIGNMENT
74#define CPU_INSTRUCTION_CACHE_ALIGNMENT ARM_CACHE_L1_CPU_INSTRUCTION_ALIGNMENT
75#define CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS \
76  ARM_CACHE_L1_CPU_SUPPORT_PROVIDES_RANGE_FUNCTIONS
77#define CPU_CACHE_SUPPORT_PROVIDES_CACHE_SIZE_FUNCTIONS
78
79#define L2C_310_DATA_LINE_MASK ( CPU_DATA_CACHE_ALIGNMENT - 1 )
80#define L2C_310_INSTRUCTION_LINE_MASK \
81  ( CPU_INSTRUCTION_CACHE_ALIGNMENT \
82    - 1 )
83#define L2C_310_NUM_WAYS 8
84#define L2C_310_WAY_MASK ( ( 1 << L2C_310_NUM_WAYS ) - 1 )
85
86#define L2C_310_MIN( a, b ) \
87  ((a < b) ? (a) : (b))
88
89#define L2C_310_MAX_LOCKING_BYTES (4 * 1024)
90
91
92/* RTL release number as can be read from cache_id register */
93typedef enum {
94  L2C_310_RTL_RELEASE_R0_P0 = 0x0,
95  L2C_310_RTL_RELEASE_R1_P0 = 0x2,
96  L2C_310_RTL_RELEASE_R2_P0 = 0x4,
97  L2C_310_RTL_RELEASE_R3_P0 = 0x5,
98  L2C_310_RTL_RELEASE_R3_P1 = 0x6,
99  L2C_310_RTL_RELEASE_R3_P2 = 0x8,
100  L2C_310_RTL_RELEASE_R3_P3 = 0x9
101} l2c_310_rtl_release;
102
103/**
104 * @defgroup L2C-310_cache Cache Support
105 * @ingroup arm_shared
106 * @brief Cache Functions and Defitions
107 * @{
108 */
109
110
111/**
112 * @brief L2CC Register Offsets
113 */
114typedef struct {
115  /** @brief Cache ID */
116  uint32_t cache_id;
117#define L2C_310_ID_RTL_MASK 0x3f
118#define L2C_310_ID_PART_MASK ( 0xf << 6 )
119#define L2C_310_ID_PART_L210 ( 1 << 6 )
120#define L2C_310_ID_PART_L310 ( 3 << 6 )
121#define L2C_310_ID_IMPL_MASK ( 0xff << 24 )
122  /** @brief Cache type */
123  uint32_t cache_type;
124/** @brief 1 if data banking implemented, 0 if not */
125#define L2C_310_TYPE_DATA_BANKING_MASK 0x80000000
126/** @brief 11xy, where: x=1 if pl310_LOCKDOWN_BY_MASTER is defined, otherwise 0 */
127#define L2C_310_TYPE_CTYPE_MASK 0x1E000000
128/** @brief y=1 if pl310_LOCKDOWN_BY_LINE is defined, otherwise 0. */
129#define L2C_310_TYPE_CTYPE_SHIFT 25
130/** @brief 1 for Harvard architecture, 0 for unified architecture */
131#define L2C_310_TYPE_HARVARD_MASK 0x01000000
132/** @brief Data cache way size = 2 Exp(value + 2) KB */
133#define L2C_310_TYPE_SIZE_D_WAYS_MASK 0x00700000
134#define L2C_310_TYPE_SIZE_D_WAYS_SHIFT 20
135/** @brief Assoziativity aka number of data ways = (value * 8) + 8 */
136#define L2C_310_TYPE_NUM_D_WAYS_MASK 0x00040000
137#define L2C_310_TYPE_NUM_D_WAYS_SHIFT 18
138/** @brief Data cache line length 00 - 32 */
139#define L2C_310_TYPE_LENGTH_D_LINE_MASK 0x00003000
140#define L2C_310_TYPE_LENGTH_D_LINE_SHIFT 12
141#define L2C_310_TYPE_LENGTH_D_LINE_VAL_32 0x0
142/** @brief Instruction cache way size = 2 Exp(value + 2) KB */
143#define L2C_310_TYPE_SIZE_I_WAYS_MASK 0x00000700
144#define L2C_310_TYPE_SIZE_I_WAYS_SHIFT 8
145/** @brief Assoziativity aka number of instruction ways = (value * 8) + 8 */
146#define L2C_310_TYPE_NUM_I_WAYS_MASK 0x00000040
147#define L2C_310_TYPE_NUM_I_WAYS_SHIFT 6
148/** @brief Instruction cache line length 00 - 32 */
149#define L2C_310_TYPE_LENGTH_I_LINE_MASK 0x00000003
150#define L2C_310_TYPE_LENGTH_I_LINE_SHIFT 0
151#define L2C_310_TYPE_LENGTH_I_LINE_VAL_32 0x0
152
153  uint8_t reserved_8[0x100 - 8];
154  uint32_t ctrl; /* Control */
155/** @brief Enables the L2CC */
156#define L2C_310_CTRL_ENABLE 0x00000001
157
158#define L2C_310_CTRL_EXCL_CONFIG (1 << 12)
159
160  /** @brief Auxiliary control */
161  uint32_t aux_ctrl;
162
163/** @brief Early BRESP Enable */
164#define L2C_310_AUX_EBRESPE_MASK 0x40000000
165
166/** @brief Instruction Prefetch Enable */
167#define L2C_310_AUX_IPFE_MASK 0x20000000
168
169/** @brief Data Prefetch Enable */
170#define L2C_310_AUX_DPFE_MASK 0x10000000
171
172/** @brief Non-secure interrupt access control */
173#define L2C_310_AUX_NSIC_MASK 0x08000000
174
175/** @brief Non-secure lockdown enable */
176#define L2C_310_AUX_NSLE_MASK 0x04000000
177
178/** @brief Cache replacement policy */
179#define L2C_310_AUX_CRP_MASK 0x02000000
180
181/** @brief Force write allocate */
182#define L2C_310_AUX_FWE_MASK 0x01800000
183
184/** @brief Shared attribute override enable */
185#define L2C_310_AUX_SAOE_MASK 0x00400000
186
187/** @brief Parity enable */
188#define L2C_310_AUX_PE_MASK 0x00200000
189
190/** @brief Event monitor bus enable */
191#define L2C_310_AUX_EMBE_MASK 0x00100000
192
193/** @brief Way-size */
194#define L2C_310_AUX_WAY_SIZE_MASK 0x000E0000
195#define L2C_310_AUX_WAY_SIZE_SHIFT 17
196
197/** @brief Way-size */
198#define L2C_310_AUX_ASSOC_MASK 0x00010000
199
200/** @brief Shared attribute invalidate enable */
201#define L2C_310_AUX_SAIE_MASK 0x00002000
202
203/** @brief Exclusive cache configuration */
204#define L2C_310_AUX_EXCL_CACHE_MASK 0x00001000
205
206/** @brief Store buffer device limitation Enable */
207#define L2C_310_AUX_SBDLE_MASK 0x00000800
208
209/** @brief High Priority for SO and Dev Reads Enable */
210#define L2C_310_AUX_HPSODRE_MASK 0x00000400
211
212/** @brief Full line of zero enable */
213#define L2C_310_AUX_FLZE_MASK 0x00000001
214
215/** @brief Enable all prefetching, */
216#define L2C_310_AUX_REG_DEFAULT_MASK \
217  ( L2C_310_AUX_WAY_SIZE_MASK & ( 0x3 << L2C_310_AUX_WAY_SIZE_SHIFT ) ) \
218  | L2C_310_AUX_PE_MASK      /* Prefetch enable */ \
219  | L2C_310_AUX_SAOE_MASK    /* Shared attribute override enable */ \
220  | L2C_310_AUX_CRP_MASK     /* Cache replacement policy */ \
221  | L2C_310_AUX_DPFE_MASK    /* Data prefetch enable */ \
222  | L2C_310_AUX_IPFE_MASK    /* Instruction prefetch enable */ \
223  | L2C_310_AUX_EBRESPE_MASK /* Early BRESP enable */
224
225#define L2C_310_AUX_REG_ZERO_MASK 0xFFF1FFFF
226
227/** @brief 1 cycle of latency, there is no additional latency fot tag RAM */
228#define L2C_310_RAM_1_CYCLE_LAT_VAL 0x00000000
229/** @brief 2 cycles of latency for tag RAM */
230#define L2C_310_RAM_2_CYCLE_LAT_VAL 0x00000001
231/** @brief 3 cycles of latency for tag RAM */
232#define L2C_310_RAM_3_CYCLE_LAT_VAL 0x00000002
233/** @brief 4 cycles of latency for tag RAM */
234#define L2C_310_RAM_4_CYCLE_LAT_VAL 0x00000003
235/** @brief 5 cycles of latency for tag RAM */
236#define L2C_310_RAM_5_CYCLE_LAT_VAL 0x00000004
237/** @brief 6 cycles of latency for tag RAM */
238#define L2C_310_RAM_6_CYCLE_LAT_VAL 0x00000005
239/** @brief 7 cycles of latency for tag RAM */
240#define L2C_310_RAM_7_CYCLE_LAT_VAL 0x00000006
241/** @brief 8 cycles of latency for tag RAM */
242#define L2C_310_RAM_8_CYCLE_LAT_VAL 0x00000007
243/** @brief Shift left setup latency values by this value */
244#define L2C_310_RAM_SETUP_SHIFT 0x00000000
245/** @brief Shift left read latency values by this value */
246#define L2C_310_RAM_READ_SHIFT 0x00000004
247/** @brief Shift left write latency values by this value */
248#define L2C_310_RAM_WRITE_SHIFT 0x00000008
249/** @brief Mask for RAM setup latency */
250#define L2C_310_RAM_SETUP_LAT_MASK 0x00000007
251/** @brief Mask for RAM read latency */
252#define L2C_310_RAM_READ_LAT_MASK 0x00000070
253/** @brief Mask for RAM read latency */
254#define L2C_310_RAM_WRITE_LAT_MASK 0x00000700
255  /** @brief Latency for tag RAM */
256  uint32_t tag_ram_ctrl;
257/* @brief Latency for tag RAM */
258#define L2C_310_TAG_RAM_DEFAULT_LAT \
259  ( ( L2C_310_RAM_2_CYCLE_LAT_VAL << L2C_310_RAM_SETUP_SHIFT ) \
260    | ( L2C_310_RAM_2_CYCLE_LAT_VAL << L2C_310_RAM_READ_SHIFT ) \
261    | ( L2C_310_RAM_2_CYCLE_LAT_VAL << L2C_310_RAM_WRITE_SHIFT ) )
262  /** @brief Latency for data RAM */
263  uint32_t data_ram_ctrl;
264/** @brief Latency for data RAM */
265#define L2C_310_DATA_RAM_DEFAULT_MASK \
266  ( ( L2C_310_RAM_2_CYCLE_LAT_VAL << L2C_310_RAM_SETUP_SHIFT ) \
267    | ( L2C_310_RAM_3_CYCLE_LAT_VAL << L2C_310_RAM_READ_SHIFT ) \
268    | ( L2C_310_RAM_2_CYCLE_LAT_VAL << L2C_310_RAM_WRITE_SHIFT ) )
269
270  uint8_t reserved_110[0x200 - 0x110];
271
272  /** @brief Event counter control */
273  uint32_t ev_ctrl;
274
275  /** @brief Event counter 1 configuration */
276  uint32_t ev_cnt1_cfg;
277
278  /** @brief Event counter 0 configuration */
279  uint32_t ev_cnt0_cfg;
280
281  /** @brief Event counter 1 value */
282  uint32_t ev_cnt1;
283
284  /** @brief Event counter 0 value */
285  uint32_t ev_cnt0;
286
287  /** @brief Interrupt enable mask */
288  uint32_t int_mask;
289
290  /** @brief Masked   interrupt status (read-only)*/
291  uint32_t int_mask_status;
292
293  /** @brief Unmasked interrupt status */
294  uint32_t int_raw_status;
295
296  /** @brief Interrupt clear */
297  uint32_t int_clr;
298
299/**
300 * @name Interrupt bit masks
301 *
302 * @{
303 */
304
305/** @brief DECERR from L3 */
306#define L2C_310_INT_DECERR_MASK 0x00000100
307
308/** @brief SLVERR from L3 */
309#define L2C_310_INT_SLVERR_MASK 0x00000080
310
311/** @brief Error on L2 data RAM (Read) */
312#define L2C_310_INT_ERRRD_MASK 0x00000040
313
314/** @brief Error on L2 tag RAM (Read) */
315#define L2C_310_INT_ERRRT_MASK 0x00000020
316
317/** @brief Error on L2 data RAM (Write) */
318#define L2C_310_INT_ERRWD_MASK 0x00000010
319
320/** @brief Error on L2 tag RAM (Write) */
321#define L2C_310_INT_ERRWT_MASK 0x00000008
322
323/** @brief Parity Error on L2 data RAM (Read) */
324#define L2C_310_INT_PARRD_MASK 0x00000004
325
326/** @brief Parity Error on L2 tag RAM (Read) */
327#define L2C_310_INT_PARRT_MASK 0x00000002
328
329/** @brief Event Counter1/0 Overflow Increment */
330#define L2C_310_INT_ECNTR_MASK 0x00000001
331
332/** @} */
333
334  uint8_t reserved_224[0x730 - 0x224];
335
336  /** @brief Drain the STB */
337  uint32_t cache_sync;
338  uint8_t reserved_734[0x740 - 0x734];
339  /** @brief ARM Errata 753970 for pl310-r3p0 */
340  uint32_t dummy_cache_sync_reg;
341  uint8_t reserved_744[0x770 - 0x744];
342
343  /** @brief Invalidate line by PA */
344  uint32_t inv_pa;
345  uint8_t reserved_774[0x77c - 0x774];
346
347  /** @brief Invalidate by Way */
348  uint32_t inv_way;
349  uint8_t reserved_780[0x7b0 - 0x780];
350
351  /** @brief Clean Line by PA */
352  uint32_t clean_pa;
353  uint8_t reserved_7b4[0x7b8 - 0x7b4];
354
355  /** @brief Clean Line by Set/Way */
356  uint32_t clean_index;
357
358  /** @brief Clean by Way */
359  uint32_t clean_way;
360  uint8_t reserved_7c0[0x7f0 - 0x7c0];
361
362  /** @brief Clean and Invalidate Line by PA */
363  uint32_t clean_inv_pa;
364  uint8_t reserved_7f4[0x7f8 - 0x7f4];
365
366  /** @brief Clean and Invalidate Line by Set/Way */
367  uint32_t clean_inv_indx;
368
369  /** @brief Clean and Invalidate by Way */
370  uint32_t clean_inv_way;
371
372  /** @brief Data        lock down 0 */
373  uint32_t d_lockdown_0;
374
375  /** @brief Instruction lock down 0 */
376  uint32_t i_lockdown_0;
377
378  /** @brief Data        lock down 1 */
379  uint32_t d_lockdown_1;
380
381  /** @brief Instruction lock down 1 */
382  uint32_t i_lockdown_1;
383
384  /** @brief Data        lock down 2 */
385  uint32_t d_lockdown_2;
386
387  /** @brief Instruction lock down 2 */
388  uint32_t i_lockdown_2;
389
390  /** @brief Data        lock down 3 */
391  uint32_t d_lockdown_3;
392
393  /** @brief Instruction lock down 3 */
394  uint32_t i_lockdown_3;
395
396  /** @brief Data        lock down 4 */
397  uint32_t d_lockdown_4;
398
399  /** @brief Instruction lock down 4 */
400  uint32_t i_lockdown_4;
401
402  /** @brief Data        lock down 5 */
403  uint32_t d_lockdown_5;
404
405  /** @brief Instruction lock down 5 */
406  uint32_t i_lockdown_5;
407
408  /** @brief Data        lock down 6 */
409  uint32_t d_lockdown_6;
410
411  /** @brief Instruction lock down 6 */
412  uint32_t i_lockdown_6;
413
414  /** @brief Data        lock down 7 */
415  uint32_t d_lockdown_7;
416
417  /** @brief Instruction lock down 7 */
418  uint32_t i_lockdown_7;
419
420  uint8_t reserved_940[0x950 - 0x940];
421
422  /** @brief Lockdown by Line Enable */
423  uint32_t lock_line_en;
424
425  /** @brief Cache lockdown by way */
426  uint32_t unlock_way;
427
428  uint8_t reserved_958[0xc00 - 0x958];
429
430  /** @brief Address range redirect, part 1 */
431  uint32_t addr_filtering_start;
432
433  /** @brief Address range redirect, part 2 */
434  uint32_t addr_filtering_end;
435
436/** @brief Address filtering valid bits*/
437#define L2C_310_ADDR_FILTER_VALID_MASK 0xFFF00000
438
439/** @brief Address filtering enable bit*/
440#define L2C_310_ADDR_FILTER_ENABLE_MASK 0x00000001
441
442  uint8_t reserved_c08[0xf40 - 0xc08];
443
444  /** @brief Debug control */
445  uint32_t debug_ctrl;
446
447/** @brief Debug SPIDEN bit */
448#define L2C_310_DEBUG_SPIDEN_MASK 0x00000004
449
450/** @brief Debug DWB bit, forces write through */
451#define L2C_310_DEBUG_DWB_MASK 0x00000002
452
453/** @brief Debug DCL bit, disables cache line fill */
454#define L2C_310_DEBUG_DCL_MASK 0x00000002
455
456  uint8_t reserved_f44[0xf60 - 0xf44];
457
458  /** @brief Purpose prefetch enables */
459  uint32_t prefetch_ctrl;
460/** @brief Prefetch offset */
461#define L2C_310_PREFETCH_OFFSET_MASK 0x0000001F
462  uint8_t reserved_f64[0xf80 - 0xf64];
463
464  /** @brief Purpose power controls */
465  uint32_t power_ctrl;
466} L2CC;
467
468rtems_interrupt_lock l2c_310_lock = RTEMS_INTERRUPT_LOCK_INITIALIZER(
469  "cache"
470);
471
472/* Errata table for the LC2 310 Level 2 cache from ARM.
473* Information taken from ARMs
474* "CoreLink controllers and peripherals
475* - System controllers
476* - L2C-310 Level 2 Cache Controller
477* - Revision r3p3
478* - Software Developer Errata Notice
479* - ARM CoreLink Level 2 Cache Controller (L2C-310 or PL310),
480*   r3 releases Software Developers Errata Notice"
481* Please see this document for more information on these erratas */
482static bool l2c_310_errata_is_applicable_753970(
483  l2c_310_rtl_release rtl_release
484)
485{
486  bool is_applicable = false;
487
488  switch ( rtl_release ) {
489    case L2C_310_RTL_RELEASE_R3_P3:
490    case L2C_310_RTL_RELEASE_R3_P2:
491    case L2C_310_RTL_RELEASE_R3_P1:
492    case L2C_310_RTL_RELEASE_R2_P0:
493    case L2C_310_RTL_RELEASE_R1_P0:
494    case L2C_310_RTL_RELEASE_R0_P0:
495      is_applicable = false;
496      break;
497    case L2C_310_RTL_RELEASE_R3_P0:
498      is_applicable = true;
499      break;
500    default:
501      assert( 0 );
502      break;
503  }
504
505  return is_applicable;
506}
507
508static bool l2c_310_errata_is_applicable_727913(
509  l2c_310_rtl_release rtl_release
510)
511{
512  bool is_applicable = false;
513
514  switch ( rtl_release ) {
515    case L2C_310_RTL_RELEASE_R3_P3:
516    case L2C_310_RTL_RELEASE_R3_P2:
517    case L2C_310_RTL_RELEASE_R3_P1:
518    case L2C_310_RTL_RELEASE_R2_P0:
519    case L2C_310_RTL_RELEASE_R1_P0:
520    case L2C_310_RTL_RELEASE_R0_P0:
521      is_applicable = false;
522      break;
523    case L2C_310_RTL_RELEASE_R3_P0:
524      is_applicable = true;
525      break;
526    default:
527      assert( 0 );
528      break;
529  }
530
531  return is_applicable;
532}
533
534static bool l2c_310_errata_is_applicable_727914(
535  l2c_310_rtl_release rtl_release
536)
537{
538  bool is_applicable = false;
539
540  switch ( rtl_release ) {
541    case L2C_310_RTL_RELEASE_R3_P3:
542    case L2C_310_RTL_RELEASE_R3_P2:
543    case L2C_310_RTL_RELEASE_R3_P1:
544    case L2C_310_RTL_RELEASE_R2_P0:
545    case L2C_310_RTL_RELEASE_R1_P0:
546    case L2C_310_RTL_RELEASE_R0_P0:
547      is_applicable = false;
548      break;
549    case L2C_310_RTL_RELEASE_R3_P0:
550      is_applicable = true;
551      break;
552    default:
553      assert( 0 );
554      break;
555  }
556
557  return is_applicable;
558}
559
560static bool l2c_310_errata_is_applicable_727915(
561  l2c_310_rtl_release rtl_release
562)
563{
564  bool is_applicable = false;
565
566  switch ( rtl_release ) {
567    case L2C_310_RTL_RELEASE_R3_P3:
568    case L2C_310_RTL_RELEASE_R3_P2:
569    case L2C_310_RTL_RELEASE_R3_P1:
570    case L2C_310_RTL_RELEASE_R1_P0:
571    case L2C_310_RTL_RELEASE_R0_P0:
572      is_applicable = false;
573      break;
574    case L2C_310_RTL_RELEASE_R3_P0:
575    case L2C_310_RTL_RELEASE_R2_P0:
576      is_applicable = true;
577      break;
578    default:
579      assert( 0 );
580      break;
581  }
582
583  return is_applicable;
584}
585
586static bool l2c_310_errata_is_applicable_729806(
587  l2c_310_rtl_release rtl_release
588)
589{
590  bool is_applicable = false;
591
592  switch ( rtl_release ) {
593    case L2C_310_RTL_RELEASE_R3_P3:
594    case L2C_310_RTL_RELEASE_R3_P2:
595    case L2C_310_RTL_RELEASE_R2_P0:
596    case L2C_310_RTL_RELEASE_R1_P0:
597    case L2C_310_RTL_RELEASE_R0_P0:
598      is_applicable = false;
599      break;
600    case L2C_310_RTL_RELEASE_R3_P1:
601    case L2C_310_RTL_RELEASE_R3_P0:
602      is_applicable = true;
603      break;
604    default:
605      assert( 0 );
606      break;
607  }
608
609  return is_applicable;
610}
611
612static bool l2c_310_errata_is_applicable_729815(
613  l2c_310_rtl_release rtl_release
614)
615{
616  bool is_applicable = false;
617
618  switch ( rtl_release ) {
619    case L2C_310_RTL_RELEASE_R3_P3:
620    case L2C_310_RTL_RELEASE_R1_P0:
621    case L2C_310_RTL_RELEASE_R0_P0:
622      is_applicable = false;
623      break;
624    case L2C_310_RTL_RELEASE_R3_P2:
625    case L2C_310_RTL_RELEASE_R3_P1:
626    case L2C_310_RTL_RELEASE_R3_P0:
627    case L2C_310_RTL_RELEASE_R2_P0:
628      is_applicable = true;
629      break;
630    default:
631      assert( 0 );
632      break;
633  }
634
635  return is_applicable;
636}
637
638static bool l2c_310_errata_is_applicable_742884(
639  l2c_310_rtl_release rtl_release
640)
641{
642  bool is_applicable = false;
643
644  switch ( rtl_release ) {
645    case L2C_310_RTL_RELEASE_R3_P3:
646    case L2C_310_RTL_RELEASE_R3_P2:
647    case L2C_310_RTL_RELEASE_R3_P0:
648    case L2C_310_RTL_RELEASE_R2_P0:
649    case L2C_310_RTL_RELEASE_R1_P0:
650    case L2C_310_RTL_RELEASE_R0_P0:
651      is_applicable = false;
652      break;
653    case L2C_310_RTL_RELEASE_R3_P1:
654      is_applicable = true;
655      break;
656    default:
657      assert( 0 );
658      break;
659  }
660
661  return is_applicable;
662}
663
664static bool l2c_310_errata_is_applicable_752271(
665  l2c_310_rtl_release rtl_release
666)
667{
668  bool is_applicable = false;
669
670  switch ( rtl_release ) {
671    case L2C_310_RTL_RELEASE_R3_P3:
672    case L2C_310_RTL_RELEASE_R3_P2:
673    case L2C_310_RTL_RELEASE_R2_P0:
674    case L2C_310_RTL_RELEASE_R1_P0:
675    case L2C_310_RTL_RELEASE_R0_P0:
676      is_applicable = false;
677      break;
678    case L2C_310_RTL_RELEASE_R3_P1:
679    case L2C_310_RTL_RELEASE_R3_P0:
680      is_applicable = true;
681      break;
682    default:
683      assert( 0 );
684      break;
685  }
686
687  return is_applicable;
688}
689
690static bool l2c_310_errata_is_applicable_765569(
691  l2c_310_rtl_release rtl_release
692)
693{
694  bool is_applicable = false;
695
696  switch ( rtl_release ) {
697    case L2C_310_RTL_RELEASE_R3_P3:
698    case L2C_310_RTL_RELEASE_R3_P2:
699    case L2C_310_RTL_RELEASE_R3_P1:
700    case L2C_310_RTL_RELEASE_R3_P0:
701    case L2C_310_RTL_RELEASE_R2_P0:
702    case L2C_310_RTL_RELEASE_R1_P0:
703    case L2C_310_RTL_RELEASE_R0_P0:
704      is_applicable = true;
705      break;
706    default:
707      assert( 0 );
708      break;
709  }
710
711  return is_applicable;
712}
713
714static bool l2c_310_errata_is_applicable_769419(
715  l2c_310_rtl_release rtl_release
716)
717{
718  bool is_applicable = false;
719
720  switch ( rtl_release ) {
721    case L2C_310_RTL_RELEASE_R3_P3:
722    case L2C_310_RTL_RELEASE_R3_P2:
723      is_applicable = false;
724      break;
725    case L2C_310_RTL_RELEASE_R3_P1:
726    case L2C_310_RTL_RELEASE_R3_P0:
727    case L2C_310_RTL_RELEASE_R2_P0:
728    case L2C_310_RTL_RELEASE_R1_P0:
729    case L2C_310_RTL_RELEASE_R0_P0:
730      is_applicable = true;
731      break;
732    default:
733      assert( 0 );
734      break;
735  }
736
737  return is_applicable;
738}
739
740static bool l2c_310_errata_is_applicable_588369(
741  l2c_310_rtl_release rtl_release
742)
743{
744  bool is_applicable = false;
745
746  switch ( rtl_release ) {
747    case L2C_310_RTL_RELEASE_R3_P3:
748    case L2C_310_RTL_RELEASE_R3_P2:
749    case L2C_310_RTL_RELEASE_R3_P1:
750    case L2C_310_RTL_RELEASE_R3_P0:
751    case L2C_310_RTL_RELEASE_R2_P0:
752      is_applicable = false;
753      break;
754    case L2C_310_RTL_RELEASE_R1_P0:
755    case L2C_310_RTL_RELEASE_R0_P0:
756      is_applicable = true;
757      break;
758    default:
759      assert( 0 );
760      break;
761  }
762
763  return is_applicable;
764}
765
766#ifdef CACHE_ERRATA_CHECKS_FOR_IMPLEMENTED_ERRATAS
767static bool l2c_310_errata_is_applicable_754670(
768  l2c_310_rtl_release rtl_release
769)
770{
771  bool is_applicable = false;
772
773  switch ( rtl_release ) {
774    case L2C_310_RTL_RELEASE_R3_P3:
775    case L2C_310_RTL_RELEASE_R3_P2:
776    case L2C_310_RTL_RELEASE_R3_P1:
777    case L2C_310_RTL_RELEASE_R3_P0:
778    case L2C_310_RTL_RELEASE_R2_P0:
779    case L2C_310_RTL_RELEASE_R1_P0:
780    case L2C_310_RTL_RELEASE_R0_P0:
781      is_applicable = true;
782    break;
783    default:
784      assert( 0 );
785      break;
786  }
787
788  return is_applicable;
789}
790#endif /* CACHE_ERRATA_CHECKS_FOR_IMPLEMENTED_ERRATAS */
791
792/* The common workaround for this erratum would be to add a
793 * data synchronization barrier to the beginning of the abort handler.
794 * But for RTEMS a call of the abort handler means a fatal condition anyway.
795 * So there is no need to handle this erratum */
796#define CACHE_ARM_ERRATA_775420_HANDLER()                   \
797  if( arm_errata_is_applicable_processor_errata_775420 ) {  \
798  }                                                         \
799
800static void l2c_310_check_errata( l2c_310_rtl_release rtl_release )
801{
802  /* This erratum gets handled within the sources */
803  /* Unhandled erratum present: 588369 Errata 588369 says that clean + inv may
804   * keep the cache line if it was clean. See ARMs documentation on the erratum
805   * for a workaround */
806  /* assert( ! l2c_310_errata_is_applicable_588369( rtl_release ) ); */
807
808  /* Unhandled erratum present: 727913 Prefetch dropping feature can cause
809   * incorrect behavior when PL310 handles reads that cross cache line
810   * boundary */
811  assert( ! l2c_310_errata_is_applicable_727913( rtl_release ) );
812
813  /* Unhandled erratum present: 727914 Double linefill feature can cause
814   * deadlock */
815  assert( ! l2c_310_errata_is_applicable_727914( rtl_release ) );
816
817  /* Unhandled erratum present: 727915 Background Clean and Invalidate by Way
818   * operation can cause data corruption */
819  assert( ! l2c_310_errata_is_applicable_727915( rtl_release ) );
820
821  /* Unhandled erratum present: 729806 Speculative reads from the Cortex-A9
822   * MPCore processor can cause deadlock */
823  assert( ! l2c_310_errata_is_applicable_729806( rtl_release ) );
824
825  if( l2c_310_errata_is_applicable_729815( rtl_release ) )
826  {
827    volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
828
829    assert( 0 == ( l2cc->aux_ctrl & L2C_310_AUX_HPSODRE_MASK ) );
830
831    /* Erratum: 729815 The “High Priority for SO and Dev reads” feature can
832     * cause Quality of Service issues to cacheable read transactions*/
833
834    /* Conditions
835       This problem occurs when the following conditions are met:
836       1. Bit[10] “High Priority for SO and Dev reads enable” of the PL310
837          Auxiliary Control Register is set to 1.
838       2. PL310 receives a cacheable read that misses in the L2 cache.
839       3. PL310 receives a continuous flow of Strongly Ordered or Device
840          reads that take all address slots in the master interface.
841       Workaround
842       A workaround is only necessary in systems that are able to issue a
843       continuous flow of Strongly Ordered or Device reads. In such a case,
844       the workaround is to disable the “High Priority for SO and Dev reads”
845       feature. This is the default behavior.*/
846  }
847
848  /* Unhandled erratum present: 742884 Double linefill feature might introduce
849   * circular dependency and deadlock */
850  assert( ! l2c_310_errata_is_applicable_742884( rtl_release ) );
851
852  /* Unhandled erratum present: 752271 Double linefill feature can cause data
853   * corruption */
854  assert( ! l2c_310_errata_is_applicable_752271( rtl_release ) );
855
856  /* This erratum can not be worked around: 754670 A continuous write flow can
857   * stall a read targeting the same memory area
858   * But this erratum does not lead to any data corruption */
859  /* assert( ! l2c_310_errata_is_applicable_754670() ); */
860
861  if( l2c_310_errata_is_applicable_765569( rtl_release ) )
862  {
863    volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
864
865    assert( !( ( l2cc->aux_ctrl & L2C_310_AUX_IPFE_MASK
866                 || l2cc->aux_ctrl & L2C_310_AUX_DPFE_MASK )
867               && ( ( l2cc->prefetch_ctrl & L2C_310_PREFETCH_OFFSET_MASK )
868                    == 23 ) ) );
869
870    /* Unhandled erratum present: 765569 Prefetcher can cross 4KB boundary if
871     * offset is programmed with value 23 */
872
873    /* Conditions
874       This problem occurs when the following conditions are met:
875       1. One of the Prefetch Enable bits (bits [29:28] of the Auxiliary or
876          Prefetch Control Register) is set HIGH.
877       2. The prefetch offset bits are programmed with value 23 (5'b10111).
878       Workaround
879       A workaround for this erratum is to program the prefetch offset with any
880       value except 23.*/
881  }
882
883  /* Unhandled erratum present: 769419 No automatic Store Buffer drain,
884   * visibility of written data requires an explicit Cache */
885  assert( ! l2c_310_errata_is_applicable_769419( rtl_release ) );
886}
887
888static inline void
889l2c_310_sync( void )
890{
891  volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
892  l2c_310_rtl_release rtl_release =
893    l2cc->cache_id & L2C_310_ID_RTL_MASK;
894
895  if( l2c_310_errata_is_applicable_753970( rtl_release ) ) {
896    l2cc->dummy_cache_sync_reg = 0;
897  } else {
898    l2cc->cache_sync           = 0;
899  }
900}
901
902static inline void
903l2c_310_flush_1_line(
904  const void *d_addr,
905  const bool  is_errata_588369applicable
906)
907{
908  volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
909
910  if( is_errata_588369applicable ) {
911    /*
912    * Errata 588369 says that clean + inv may keep the
913    * cache line if it was clean, the recommended
914    * workaround is to clean then invalidate the cache
915    * line, with write-back and cache linefill disabled.
916    */
917    l2cc->clean_pa     = (uint32_t) d_addr;
918    l2c_310_sync();
919    l2cc->inv_pa       = (uint32_t) d_addr;
920  } else {
921    l2cc->clean_inv_pa = (uint32_t) d_addr;
922  }
923}
924
925static inline void
926l2c_310_flush_range( const void* d_addr, const size_t n_bytes )
927{
928  rtems_interrupt_lock_context lock_context;
929  /* Back starting address up to start of a line and invalidate until ADDR_LAST */
930  uint32_t       adx               = (uint32_t)d_addr
931    & ~L2C_310_DATA_LINE_MASK;
932  const uint32_t ADDR_LAST         =
933    (uint32_t)( (size_t)d_addr + n_bytes - 1 );
934  uint32_t       block_end         =
935    L2C_310_MIN( ADDR_LAST, adx + L2C_310_MAX_LOCKING_BYTES );
936  volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
937  l2c_310_rtl_release rtl_release =
938    l2cc->cache_id & L2C_310_ID_RTL_MASK;
939  bool is_errata_588369_applicable =
940    l2c_310_errata_is_applicable_588369( rtl_release );
941
942  rtems_interrupt_lock_acquire( &l2c_310_lock, &lock_context );
943
944  for (;
945       adx      <= ADDR_LAST;
946       adx       = block_end + 1,
947       block_end = L2C_310_MIN( ADDR_LAST, adx + L2C_310_MAX_LOCKING_BYTES )) {
948    for (; adx <= block_end; adx += CPU_DATA_CACHE_ALIGNMENT ) {
949      l2c_310_flush_1_line( (void*)adx, is_errata_588369_applicable );
950    }
951    if( block_end < ADDR_LAST ) {
952      rtems_interrupt_lock_release( &l2c_310_lock, &lock_context );
953      rtems_interrupt_lock_acquire( &l2c_310_lock, &lock_context );
954    }
955  }
956  l2c_310_sync();
957  rtems_interrupt_lock_release( &l2c_310_lock, &lock_context );
958}
959
960static inline void
961l2c_310_flush_entire( void )
962{
963  volatile L2CC               *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
964  rtems_interrupt_lock_context lock_context;
965
966  /* Only flush if level 2 cache is active */
967  if( ( l2cc->ctrl & L2C_310_CTRL_ENABLE ) != 0 ) {
968
969    /* ensure ordering with previous memory accesses */
970    _ARM_Data_memory_barrier();
971
972    rtems_interrupt_lock_acquire( &l2c_310_lock, &lock_context );
973    l2cc->clean_inv_way = L2C_310_WAY_MASK;
974
975    while ( l2cc->clean_inv_way & L2C_310_WAY_MASK ) {};
976
977    /* Wait for the flush to complete */
978    l2c_310_sync();
979
980    rtems_interrupt_lock_release( &l2c_310_lock, &lock_context );
981  }
982}
983
984static inline void
985l2c_310_invalidate_1_line( const void *d_addr )
986{
987  volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
988
989
990  l2cc->inv_pa = (uint32_t) d_addr;
991  l2c_310_sync();
992}
993
994static inline void
995l2c_310_invalidate_range( uint32_t adx, const uint32_t ADDR_LAST )
996{
997  volatile L2CC               *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
998  rtems_interrupt_lock_context lock_context;
999
1000  rtems_interrupt_lock_acquire( &l2c_310_lock, &lock_context );
1001  for (;
1002       adx <= ADDR_LAST;
1003       adx += CPU_INSTRUCTION_CACHE_ALIGNMENT ) {
1004    /* Invalidate L2 cache line */
1005    l2cc->inv_pa = adx;
1006  }
1007  l2c_310_sync();
1008  rtems_interrupt_lock_release( &l2c_310_lock, &lock_context );
1009}
1010
1011static inline void
1012l2c_310_invalidate_entire( void )
1013{
1014  volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
1015
1016  /* Invalidate the caches */
1017
1018  /* ensure ordering with previous memory accesses */
1019  _ARM_Data_memory_barrier();
1020
1021  l2cc->inv_way = L2C_310_WAY_MASK;
1022
1023  while ( l2cc->inv_way & L2C_310_WAY_MASK ) ;
1024
1025  /* Wait for the invalidate to complete */
1026  l2c_310_sync();
1027}
1028
1029static inline void
1030l2c_310_clean_and_invalidate_entire( void )
1031{
1032  volatile L2CC               *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
1033  rtems_interrupt_lock_context lock_context;
1034
1035  if( ( l2cc->ctrl & L2C_310_CTRL_ENABLE ) != 0 ) {
1036    /* Invalidate the caches */
1037
1038    /* ensure ordering with previous memory accesses */
1039    _ARM_Data_memory_barrier();
1040
1041    rtems_interrupt_lock_acquire( &l2c_310_lock, &lock_context );
1042    l2cc->clean_inv_way = L2C_310_WAY_MASK;
1043
1044    while ( l2cc->clean_inv_way & L2C_310_WAY_MASK ) ;
1045
1046    /* Wait for the invalidate to complete */
1047    l2c_310_sync();
1048
1049    rtems_interrupt_lock_release( &l2c_310_lock, &lock_context );
1050  }
1051}
1052
1053static inline void
1054l2c_310_freeze( void )
1055{
1056  /* To be implemented as needed, if supported
1057   by hardware at all */
1058}
1059
1060static inline void
1061l2c_310_unfreeze( void )
1062{
1063  /* To be implemented as needed, if supported
1064   by hardware at all */
1065}
1066
1067static inline size_t
1068l2c_310_get_cache_size( void )
1069{
1070  size_t         size       = 0;
1071  volatile L2CC *l2cc       = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
1072  uint32_t       cache_type = l2cc->cache_type;
1073  uint32_t       way_size;
1074  uint32_t       num_ways;
1075
1076  way_size = (cache_type & L2C_310_TYPE_SIZE_D_WAYS_MASK)
1077    >> L2C_310_TYPE_SIZE_D_WAYS_SHIFT;
1078  num_ways = (cache_type & L2C_310_TYPE_NUM_D_WAYS_MASK)
1079    >> L2C_310_TYPE_NUM_D_WAYS_SHIFT;
1080
1081  assert( way_size <= 0x07 );
1082  assert( num_ways <= 0x01 );
1083  if(  way_size <= 0x07 && num_ways <= 0x01 ) {
1084    if( way_size == 0x00 ) {
1085      way_size = 16 * 1024;
1086    } else if( way_size == 0x07 ) {
1087      way_size = 512 * 1024;
1088    } else {
1089      way_size = (1 << (way_size - 1)) * 16 * 1024;
1090    }
1091    switch( num_ways ) {
1092      case 0:
1093        num_ways = 8;
1094        break;
1095      case 1:
1096        num_ways = 16;
1097        break;
1098      default:
1099        num_ways = 0;
1100        break;
1101    }
1102    size = way_size * num_ways;
1103  }
1104  return size;
1105}
1106
1107static void l2c_310_unlock( volatile L2CC *l2cc )
1108{
1109  l2cc->d_lockdown_0 = 0;
1110  l2cc->i_lockdown_0 = 0;
1111  l2cc->d_lockdown_1 = 0;
1112  l2cc->i_lockdown_1 = 0;
1113  l2cc->d_lockdown_2 = 0;
1114  l2cc->i_lockdown_2 = 0;
1115  l2cc->d_lockdown_3 = 0;
1116  l2cc->i_lockdown_3 = 0;
1117  l2cc->d_lockdown_4 = 0;
1118  l2cc->i_lockdown_4 = 0;
1119  l2cc->d_lockdown_5 = 0;
1120  l2cc->i_lockdown_5 = 0;
1121  l2cc->d_lockdown_6 = 0;
1122  l2cc->i_lockdown_6 = 0;
1123  l2cc->d_lockdown_7 = 0;
1124  l2cc->i_lockdown_7 = 0;
1125}
1126
1127static void l2c_310_wait_for_background_ops( volatile L2CC *l2cc )
1128{
1129  while ( l2cc->inv_way & L2C_310_WAY_MASK ) ;
1130
1131  while ( l2cc->clean_way & L2C_310_WAY_MASK ) ;
1132
1133  while ( l2cc->clean_inv_way & L2C_310_WAY_MASK ) ;
1134}
1135
1136/* We support only the L2C-310 revisions r3p2 and r3p3 cache controller */
1137
1138#if (BSP_ARM_L2C_310_ID & L2C_310_ID_PART_MASK) \
1139  != L2C_310_ID_PART_L310
1140#error "invalid L2-310 cache controller part number"
1141#endif
1142
1143#if ((BSP_ARM_L2C_310_ID & L2C_310_ID_RTL_MASK) != 0x8) \
1144  && ((BSP_ARM_L2C_310_ID & L2C_310_ID_RTL_MASK) != 0x9)
1145#error "invalid L2-310 cache controller RTL revision"
1146#endif
1147
1148static inline void
1149l2c_310_enable( void )
1150{
1151  volatile L2CC *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
1152  uint32_t cache_id = l2cc->cache_id;
1153  l2c_310_rtl_release rtl_release =
1154    cache_id & L2C_310_ID_RTL_MASK;
1155  uint32_t id_mask =
1156    L2C_310_ID_IMPL_MASK | L2C_310_ID_PART_MASK;
1157  uint32_t ctrl;
1158
1159  /*
1160   * Do we actually have an L2C-310 cache controller?  Has BSP_ARM_L2C_310_BASE
1161   * been configured correctly?
1162   */
1163  if (
1164    (BSP_ARM_L2C_310_ID & id_mask) != (cache_id & id_mask)
1165      || rtl_release < (BSP_ARM_L2C_310_ID & L2C_310_ID_RTL_MASK)
1166  ) {
1167    bsp_fatal( ARM_FATAL_L2C_310_UNEXPECTED_ID );
1168  }
1169
1170  l2c_310_check_errata( rtl_release );
1171
1172  ctrl = l2cc->ctrl;
1173
1174  if ( ( ctrl & L2C_310_CTRL_EXCL_CONFIG ) != 0 ) {
1175    bsp_fatal( ARM_FATAL_L2C_310_EXCLUSIVE_CONFIG );
1176  }
1177
1178  /* Only enable if L2CC is currently disabled */
1179  if( ( ctrl & L2C_310_CTRL_ENABLE ) == 0 ) {
1180    uint32_t aux_ctrl;
1181    int ways;
1182
1183    /* Make sure that I&D is not locked down when starting */
1184    l2c_310_unlock( l2cc );
1185
1186    l2c_310_wait_for_background_ops( l2cc );
1187
1188    aux_ctrl = l2cc->aux_ctrl;
1189
1190    if ( (aux_ctrl & ( 1 << 16 )) != 0 ) {
1191      ways = 16;
1192    } else {
1193      ways = 8;
1194    }
1195
1196    if ( ways != L2C_310_NUM_WAYS ) {
1197      bsp_fatal( ARM_FATAL_L2C_310_UNEXPECTED_NUM_WAYS );
1198    }
1199
1200    /* Set up the way size */
1201    aux_ctrl &= L2C_310_AUX_REG_ZERO_MASK; /* Set way_size to 0 */
1202    aux_ctrl |= L2C_310_AUX_REG_DEFAULT_MASK;
1203
1204    l2cc->aux_ctrl = aux_ctrl;
1205
1206    /* Set up the latencies */
1207    l2cc->tag_ram_ctrl  = L2C_310_TAG_RAM_DEFAULT_LAT;
1208    l2cc->data_ram_ctrl = L2C_310_DATA_RAM_DEFAULT_MASK;
1209
1210    l2c_310_invalidate_entire();
1211
1212    /* Clear the pending interrupts */
1213    l2cc->int_clr = l2cc->int_raw_status;
1214
1215    /* Enable the L2CC */
1216    l2cc->ctrl = ctrl | L2C_310_CTRL_ENABLE;
1217  }
1218}
1219
1220static inline void
1221l2c_310_disable( void )
1222{
1223  volatile L2CC               *l2cc = (volatile L2CC *) BSP_ARM_L2C_310_BASE;
1224  rtems_interrupt_lock_context lock_context;
1225
1226  if ( l2cc->ctrl & L2C_310_CTRL_ENABLE ) {
1227    /* Clean and Invalidate L2 Cache */
1228    l2c_310_flush_entire();
1229    rtems_interrupt_lock_acquire( &l2c_310_lock, &lock_context );
1230
1231    l2c_310_wait_for_background_ops( l2cc );
1232
1233    /* Disable the L2 cache */
1234    l2cc->ctrl &= ~L2C_310_CTRL_ENABLE;
1235    rtems_interrupt_lock_release( &l2c_310_lock, &lock_context );
1236  }
1237}
1238
1239static inline void
1240_CPU_cache_enable_data( void )
1241{
1242  l2c_310_enable();
1243}
1244
1245static inline void
1246_CPU_cache_disable_data( void )
1247{
1248  arm_cache_l1_disable_data();
1249  l2c_310_disable();
1250}
1251
1252static inline void
1253_CPU_cache_enable_instruction( void )
1254{
1255  l2c_310_enable();
1256}
1257
1258static inline void
1259_CPU_cache_disable_instruction( void )
1260{
1261  arm_cache_l1_disable_instruction();
1262  l2c_310_disable();
1263}
1264
1265static inline void
1266_CPU_cache_flush_data_range(
1267  const void *d_addr,
1268  size_t      n_bytes
1269)
1270{
1271  if ( n_bytes != 0 ) {
1272    arm_cache_l1_flush_data_range(
1273      d_addr,
1274      n_bytes
1275    );
1276    l2c_310_flush_range(
1277      d_addr,
1278      n_bytes
1279    );
1280  }
1281}
1282
1283static inline void
1284_CPU_cache_flush_entire_data( void )
1285{
1286  arm_cache_l1_flush_entire_data();
1287  l2c_310_flush_entire();
1288}
1289
1290static inline void
1291_CPU_cache_invalidate_data_range(
1292  const void *addr_first,
1293  size_t     n_bytes
1294)
1295{
1296  if ( n_bytes > 0 ) {
1297    /* Back starting address up to start of a line and invalidate until ADDR_LAST */
1298    uint32_t       adx       = (uint32_t) addr_first
1299      & ~L2C_310_DATA_LINE_MASK;
1300    const uint32_t ADDR_LAST =
1301      (uint32_t)( (size_t)addr_first + n_bytes - 1 );
1302    uint32_t       block_end =
1303      L2C_310_MIN( ADDR_LAST, adx + L2C_310_MAX_LOCKING_BYTES );
1304
1305    /* We have to apply a lock. Thus we will operate only L2C_310_MAX_LOCKING_BYTES
1306     * at a time */
1307    for (;
1308         adx      <= ADDR_LAST;
1309         adx       = block_end + 1,
1310         block_end = L2C_310_MIN( ADDR_LAST, adx + L2C_310_MAX_LOCKING_BYTES )) {
1311      l2c_310_invalidate_range(
1312        adx,
1313        block_end
1314      );
1315    }
1316    arm_cache_l1_invalidate_data_range(
1317      addr_first,
1318      n_bytes
1319    );
1320
1321    adx       = (uint32_t)addr_first & ~L2C_310_DATA_LINE_MASK;
1322    block_end = L2C_310_MIN( ADDR_LAST, adx + L2C_310_MAX_LOCKING_BYTES );
1323    for (;
1324         adx      <= ADDR_LAST;
1325         adx       = block_end + 1,
1326         block_end = L2C_310_MIN( ADDR_LAST, adx + L2C_310_MAX_LOCKING_BYTES )) {
1327      l2c_310_invalidate_range(
1328        adx,
1329        block_end
1330      );
1331    }
1332    arm_cache_l1_invalidate_data_range(
1333      addr_first,
1334      n_bytes
1335    );
1336  }
1337}
1338
1339static inline void
1340_CPU_cache_invalidate_entire_data( void )
1341{
1342  /* This is broadcast within the cluster */
1343  arm_cache_l1_flush_entire_data();
1344
1345  /* forces the address out past level 2 */
1346  l2c_310_clean_and_invalidate_entire();
1347
1348  /*This is broadcast within the cluster */
1349  arm_cache_l1_clean_and_invalidate_entire_data();
1350}
1351
1352static inline void
1353_CPU_cache_freeze_data( void )
1354{
1355  arm_cache_l1_freeze_data();
1356  l2c_310_freeze();
1357}
1358
1359static inline void
1360_CPU_cache_unfreeze_data( void )
1361{
1362  arm_cache_l1_unfreeze_data();
1363  l2c_310_unfreeze();
1364}
1365
1366static inline void
1367_CPU_cache_invalidate_instruction_range( const void *i_addr, size_t n_bytes)
1368{
1369  arm_cache_l1_invalidate_instruction_range( i_addr, n_bytes );
1370}
1371
1372static inline void
1373_CPU_cache_invalidate_entire_instruction( void )
1374{
1375  arm_cache_l1_invalidate_entire_instruction();
1376}
1377
1378static inline void
1379_CPU_cache_freeze_instruction( void )
1380{
1381  arm_cache_l1_freeze_instruction();
1382  l2c_310_freeze();
1383}
1384
1385static inline void
1386_CPU_cache_unfreeze_instruction( void )
1387{
1388  arm_cache_l1_unfreeze_instruction();
1389  l2c_310_unfreeze();
1390}
1391
1392static inline size_t
1393_CPU_cache_get_data_cache_size( const uint32_t level )
1394{
1395  size_t size = 0;
1396
1397  switch( level )
1398  {
1399    case 1:
1400      size = arm_cache_l1_get_data_cache_size();
1401    break;
1402    case 0:
1403    case 2:
1404      size = l2c_310_get_cache_size();
1405    break;
1406    default:
1407      size = 0;
1408    break;
1409  }
1410  return size;
1411}
1412
1413static inline size_t
1414_CPU_cache_get_instruction_cache_size( const uint32_t level )
1415{
1416  size_t size = 0;
1417
1418  switch( level )
1419  {
1420    case 1:
1421      size = arm_cache_l1_get_instruction_cache_size();
1422      break;
1423    case 0:
1424    case 2:
1425      size = l2c_310_get_cache_size();
1426      break;
1427    default:
1428      size = 0;
1429      break;
1430  }
1431  return size;
1432}
1433
1434
1435/** @} */
1436
1437#ifdef __cplusplus
1438}
1439#endif /* __cplusplus */
1440
1441#endif /* LIBBSP_ARM_SHARED_L2C_310_CACHE_H */
Note: See TracBrowser for help on using the repository browser.