Commit | Line | Data |
---|---|---|
2ef2b01e A |
1 | /** @file |
2 | ||
3 | Copyright (c) 2008-2009, Apple Inc. All rights reserved. | |
4 | ||
5 | All rights reserved. This program and the accompanying materials | |
6 | are licensed and made available under the terms and conditions of the BSD License | |
7 | which accompanies this distribution. The full text of the license may be found at | |
8 | http://opensource.org/licenses/bsd-license.php | |
9 | ||
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
12 | ||
13 | **/ | |
14 | #include <Base.h> | |
15 | #include <Library/ArmLib.h> | |
16 | #include <Library/PcdLib.h> | |
17 | ||
18 | VOID | |
19 | CacheRangeOperation ( | |
20 | IN VOID *Start, | |
21 | IN UINTN Length, | |
22 | IN CACHE_OPERATION CacheOperation, | |
23 | IN LINE_OPERATION LineOperation | |
24 | ) | |
25 | { | |
26 | UINTN ArmCacheLineLength = ArmDataCacheLineLength(); | |
27 | UINTN ArmCacheLineAlignmentMask = ArmCacheLineLength - 1; | |
28 | UINTN ArmCacheOperationThreshold = PcdGet32(PcdArmCacheOperationThreshold); | |
29 | ||
30 | if ((CacheOperation != NULL) && (Length >= ArmCacheOperationThreshold)) | |
31 | { | |
32 | CacheOperation(); | |
33 | } | |
34 | else | |
35 | { | |
36 | // Align address (rounding down) | |
37 | UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask); | |
38 | UINTN EndAddress = (UINTN)Start + Length; | |
39 | ||
40 | // Perform the line operation on an address in each cache line | |
41 | while (AlignedAddress < EndAddress) | |
42 | { | |
43 | LineOperation(AlignedAddress); | |
44 | AlignedAddress += ArmCacheLineLength; | |
45 | } | |
46 | } | |
47 | } | |
48 | ||
49 | VOID | |
50 | EFIAPI | |
51 | InvalidateInstructionCache ( | |
52 | VOID | |
53 | ) | |
54 | { | |
55 | ArmCleanDataCache(); | |
56 | ArmInvalidateInstructionCache(); | |
57 | } | |
58 | ||
59 | VOID | |
60 | EFIAPI | |
61 | InvalidateDataCache ( | |
62 | VOID | |
63 | ) | |
64 | { | |
65 | ArmInvalidateDataCache(); | |
66 | } | |
67 | ||
68 | VOID * | |
69 | EFIAPI | |
70 | InvalidateInstructionCacheRange ( | |
71 | IN VOID *Address, | |
72 | IN UINTN Length | |
73 | ) | |
74 | { | |
75 | CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA); | |
76 | ArmInvalidateInstructionCache(); | |
77 | return Address; | |
78 | } | |
79 | ||
80 | VOID | |
81 | EFIAPI | |
82 | WriteBackInvalidateDataCache ( | |
83 | VOID | |
84 | ) | |
85 | { | |
86 | ArmCleanInvalidateDataCache(); | |
87 | } | |
88 | ||
89 | VOID * | |
90 | EFIAPI | |
91 | WriteBackInvalidateDataCacheRange ( | |
92 | IN VOID *Address, | |
93 | IN UINTN Length | |
94 | ) | |
95 | { | |
96 | CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCache, ArmCleanInvalidateDataCacheEntryByMVA); | |
97 | return Address; | |
98 | } | |
99 | ||
100 | VOID | |
101 | EFIAPI | |
102 | WriteBackDataCache ( | |
103 | VOID | |
104 | ) | |
105 | { | |
106 | ArmCleanDataCache(); | |
107 | } | |
108 | ||
109 | VOID * | |
110 | EFIAPI | |
111 | WriteBackDataCacheRange ( | |
112 | IN VOID *Address, | |
113 | IN UINTN Length | |
114 | ) | |
115 | { | |
116 | CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA); | |
117 | return Address; | |
118 | } | |
119 | ||
120 | VOID * | |
121 | EFIAPI | |
122 | InvalidateDataCacheRange ( | |
123 | IN VOID *Address, | |
124 | IN UINTN Length | |
125 | ) | |
126 | { | |
127 | CacheRangeOperation(Address, Length, NULL, ArmInvalidateDataCacheEntryByMVA); | |
128 | return Address; | |
129 | } |