3 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
4 Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Chipset/ArmV7.h>
17 #include <Library/ArmLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/IoLib.h>
21 #include "ArmLibPrivate.h"
29 return ARM_CACHE_TYPE_WRITE_BACK
;
32 ARM_CACHE_ARCHITECTURE
34 ArmCacheArchitecture (
38 UINT32 CLIDR
= ReadCLIDR ();
40 return (ARM_CACHE_ARCHITECTURE
)CLIDR
; // BugBug Fix Me
49 UINT32 CLIDR
= ReadCLIDR ();
51 if ((CLIDR
& 0x2) == 0x2) {
52 // Instruction cache exists
55 if ((CLIDR
& 0x7) == 0x4) {
72 UINT32 CCSIDR
= ReadCCSIDR (0);
74 LineSize
= (1 << ((CCSIDR
& 0x7) + 2));
75 Associativity
= ((CCSIDR
>> 3) & 0x3ff) + 1;
76 NumSets
= ((CCSIDR
>> 13) & 0x7fff) + 1;
78 // LineSize is in words (4 byte chunks)
79 return NumSets
* Associativity
* LineSize
* 4;
84 ArmDataCacheAssociativity (
88 UINT32 CCSIDR
= ReadCCSIDR (0);
90 return ((CCSIDR
>> 3) & 0x3ff) + 1;
98 UINT32 CCSIDR
= ReadCCSIDR (0);
100 return ((CCSIDR
>> 13) & 0x7fff) + 1;
105 ArmDataCacheLineLength (
109 UINT32 CCSIDR
= ReadCCSIDR (0) & 7;
111 // * 4 converts to bytes
112 return (1 << (CCSIDR
+ 2)) * 4;
117 ArmInstructionCachePresent (
121 UINT32 CLIDR
= ReadCLIDR ();
123 if ((CLIDR
& 1) == 1) {
124 // Instruction cache exists
127 if ((CLIDR
& 0x7) == 0x4) {
137 ArmInstructionCacheSize (
142 UINT32 Associativity
;
144 UINT32 CCSIDR
= ReadCCSIDR (1);
146 LineSize
= (1 << ((CCSIDR
& 0x7) + 2));
147 Associativity
= ((CCSIDR
>> 3) & 0x3ff) + 1;
148 NumSets
= ((CCSIDR
>> 13) & 0x7fff) + 1;
150 // LineSize is in words (4 byte chunks)
151 return NumSets
* Associativity
* LineSize
* 4;
156 ArmInstructionCacheAssociativity (
160 UINT32 CCSIDR
= ReadCCSIDR (1);
162 return ((CCSIDR
>> 3) & 0x3ff) + 1;
168 ArmInstructionCacheSets (
172 UINT32 CCSIDR
= ReadCCSIDR (1);
174 return ((CCSIDR
>> 13) & 0x7fff) + 1;
179 ArmInstructionCacheLineLength (
183 UINT32 CCSIDR
= ReadCCSIDR (1) & 7;
185 // * 4 converts to bytes
186 return (1 << (CCSIDR
+ 2)) * 4;
193 ArmV7DataCacheOperation (
194 IN ARM_V7_CACHE_OPERATION DataCacheOperation
197 UINTN SavedInterruptState
;
199 SavedInterruptState
= ArmGetInterruptState ();
200 ArmDisableInterrupts ();
202 ArmV7AllDataCachesOperation (DataCacheOperation
);
204 ArmDrainWriteBuffer ();
206 if (SavedInterruptState
) {
207 ArmEnableInterrupts ();
213 ArmV7PoUDataCacheOperation (
214 IN ARM_V7_CACHE_OPERATION DataCacheOperation
217 UINTN SavedInterruptState
;
219 SavedInterruptState
= ArmGetInterruptState ();
220 ArmDisableInterrupts ();
222 ArmV7PerformPoUDataCacheOperation (DataCacheOperation
);
224 ArmDrainWriteBuffer ();
226 if (SavedInterruptState
) {
227 ArmEnableInterrupts ();
233 ArmInvalidateDataCache (
237 ArmDrainWriteBuffer ();
238 ArmV7DataCacheOperation (ArmInvalidateDataCacheEntryBySetWay
);
243 ArmCleanInvalidateDataCache (
247 ArmDrainWriteBuffer ();
248 ArmV7DataCacheOperation (ArmCleanInvalidateDataCacheEntryBySetWay
);
257 ArmDrainWriteBuffer ();
258 ArmV7DataCacheOperation (ArmCleanDataCacheEntryBySetWay
);
263 ArmCleanDataCacheToPoU (
267 ArmDrainWriteBuffer ();
268 ArmV7PoUDataCacheOperation (ArmCleanDataCacheEntryBySetWay
);