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

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

bsps/arm: L2C 310 simplify and remove white space

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