]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseCacheMaintenanceLib/IpfCache.c
BaseCacheMaintenanceLib has now been completed on all architectures.
[mirror_edk2.git] / MdePkg / Library / BaseCacheMaintenanceLib / IpfCache.c
CommitLineData
878ddf1f 1/** @file\r
2 Cache Maintenance Functions.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15typedef struct {\r
16 UINT64 Status;\r
17 UINT64 r9;\r
18 UINT64 r10;\r
19 UINT64 r11;\r
20} PAL_PROC_RETURN;\r
21\r
22PAL_PROC_RETURN\r
23CallPalProcStatic (\r
24 IN UINT64 Arg1,\r
25 IN UINT64 Arg2,\r
26 IN UINT64 Arg3,\r
27 IN UINT64 Arg4\r
28 );\r
29\r
9f84a609 30/**\r
31 Invalidates the entire instruction cache in cache coherency domain of the\r
32 calling CPU.\r
33\r
34 Invalidates the entire instruction cache in cache coherency domain of the\r
35 calling CPU.\r
36\r
37**/\r
878ddf1f 38VOID\r
39EFIAPI\r
40InvalidateInstructionCache (\r
41 VOID\r
42 )\r
43{\r
44 CallPalProcStatic (1, 1, 1, 0);\r
45}\r
46\r
9f84a609 47/**\r
48 Invalidates a range of instruction cache lines in the cache coherency domain\r
49 of the calling CPU.\r
50\r
51 Invalidates the instruction cache lines specified by Address and Length. If\r
52 Address is not aligned on a cache line boundary, then entire instruction\r
53 cache line containing Address is invalidated. If Address + Length is not\r
54 aligned on a cache line boundary, then the entire instruction cache line\r
55 containing Address + Length -1 is invalidated. This function may choose to\r
56 invalidate the entire instruction cache if that is more efficient than\r
57 invalidating the specified range. If Length is 0, the no instruction cache\r
58 lines are invalidated. Address is returned.\r
59\r
60 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
61\r
62 @param Address The base address of the instruction cache lines to\r
63 invalidate. If the CPU is in a physical addressing mode, then\r
64 Address is a physical address. If the CPU is in a virtual\r
65 addressing mode, then Address is a virtual address.\r
66\r
67 @param Length The number of bytes to invalidate from the instruction cache.\r
68\r
69 @return Address\r
70\r
71**/\r
72VOID*\r
73EFIAPI\r
74InvalidateInstructionCacheRange (\r
75 IN VOID *Address,\r
76 IN UINTN Length\r
77 )\r
78{\r
79 ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1);\r
80\r
81 if (Length > 0) {\r
82 InvalidateInstructionCache ();\r
83 }\r
84 return Address;\r
85}\r
86\r
87/**\r
88 Writes Back and Invalidates the entire data cache in cache coherency domain\r
89 of the calling CPU.\r
90\r
91 Writes Back and Invalidates the entire data cache in cache coherency domain\r
92 of the calling CPU. This function guarantees that all dirty cache lines are\r
93 written back to system memory, and also invalidates all the data cache lines\r
94 in the cache coherency domain of the calling CPU.\r
95\r
96**/\r
878ddf1f 97VOID\r
98EFIAPI\r
99WriteBackInvalidateDataCache (\r
100 VOID\r
101 )\r
102{\r
103 CallPalProcStatic (1, 2, 1, 0);\r
104}\r
105\r
9f84a609 106/**\r
107 Writes Back and Invalidates a range of data cache lines in the cache\r
108 coherency domain of the calling CPU.\r
109\r
110 Writes Back and Invalidate the data cache lines specified by Address and\r
111 Length. If Address is not aligned on a cache line boundary, then entire data\r
112 cache line containing Address is written back and invalidated. If Address +\r
113 Length is not aligned on a cache line boundary, then the entire data cache\r
114 line containing Address + Length -1 is written back and invalidated. This\r
115 function may choose to write back and invalidate the entire data cache if\r
116 that is more efficient than writing back and invalidating the specified\r
117 range. If Length is 0, the no data cache lines are written back and\r
118 invalidated. Address is returned.\r
119\r
120 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
121\r
122 @param Address The base address of the data cache lines to write back and\r
123 invalidate. If the CPU is in a physical addressing mode, then\r
124 Address is a physical address. If the CPU is in a virtual\r
125 addressing mode, then Address is a virtual address.\r
126 @param Length The number of bytes to write back and invalidate from the\r
127 data cache.\r
128\r
129 @return Address\r
130\r
131**/\r
878ddf1f 132VOID *\r
133EFIAPI\r
134WriteBackInvalidateDataCacheRange (\r
135 IN VOID *Address,\r
136 IN UINTN Length\r
137 )\r
138{\r
9f84a609 139 ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1);\r
140\r
141 if (Length > 0) {\r
142 WriteBackInvalidateDataCache ();\r
143 }\r
878ddf1f 144 return Address;\r
145}\r
146\r
9f84a609 147/**\r
148 Writes Back the entire data cache in cache coherency domain of the calling\r
149 CPU.\r
150\r
151 Writes Back the entire data cache in cache coherency domain of the calling\r
152 CPU. This function guarantees that all dirty cache lines are written back to\r
153 system memory. This function may also invalidate all the data cache lines in\r
154 the cache coherency domain of the calling CPU.\r
155\r
156**/\r
878ddf1f 157VOID\r
158EFIAPI\r
159WriteBackDataCache (\r
160 VOID\r
161 )\r
162{\r
163 CallPalProcStatic (1, 2, 0, 0);\r
164}\r
165\r
9f84a609 166/**\r
167 Writes Back a range of data cache lines in the cache coherency domain of the\r
168 calling CPU.\r
169\r
170 Writes Back the data cache lines specified by Address and Length. If Address\r
171 is not aligned on a cache line boundary, then entire data cache line\r
172 containing Address is written back. If Address + Length is not aligned on a\r
173 cache line boundary, then the entire data cache line containing Address +\r
174 Length -1 is written back. This function may choose to write back the entire\r
175 data cache if that is more efficient than writing back the specified range.\r
176 If Length is 0, the no data cache lines are written back. This function may\r
177 also invalidate all the data cache lines in the specified range of the cache\r
178 coherency domain of the calling CPU. Address is returned.\r
179\r
180 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
181\r
182 @param Address The base address of the data cache lines to write back. If\r
183 the CPU is in a physical addressing mode, then Address is a\r
184 physical address. If the CPU is in a virtual addressing\r
185 mode, then Address is a virtual address.\r
186 @param Length The number of bytes to write back from the data cache.\r
187\r
188 @return Address\r
189\r
190**/\r
878ddf1f 191VOID *\r
192EFIAPI\r
193WriteBackDataCacheRange (\r
194 IN VOID *Address,\r
195 IN UINTN Length\r
196 )\r
197{\r
9f84a609 198 ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1);\r
199\r
200 if (Length > 0) {\r
201 WriteBackDataCache ();\r
202 }\r
878ddf1f 203 return Address;\r
204}\r
205\r
9f84a609 206/**\r
207 Invalidates the entire data cache in cache coherency domain of the calling\r
208 CPU.\r
209\r
210 Invalidates the entire data cache in cache coherency domain of the calling\r
211 CPU. This function must be used with care because dirty cache lines are not\r
212 written back to system memory. It is typically used for cache diagnostics. If\r
213 the CPU does not support invalidation of the entire data cache, then a write\r
214 back and invalidate operation should be performed on the entire data cache.\r
215\r
216**/\r
878ddf1f 217VOID\r
218EFIAPI\r
219InvalidateDataCache (\r
220 VOID\r
221 )\r
222{\r
9f84a609 223 WriteBackInvalidateDataCache ();\r
878ddf1f 224}\r
225\r
9f84a609 226/**\r
227 Invalidates a range of data cache lines in the cache coherency domain of the\r
228 calling CPU.\r
229\r
230 Invalidates the data cache lines specified by Address and Length. If Address\r
231 is not aligned on a cache line boundary, then entire data cache line\r
232 containing Address is invalidated. If Address + Length is not aligned on a\r
233 cache line boundary, then the entire data cache line containing Address +\r
234 Length -1 is invalidated. This function must never invalidate any cache lines\r
235 outside the specified range. If Length is 0, the no data cache lines are\r
236 invalidated. Address is returned. This function must be used with care\r
237 because dirty cache lines are not written back to system memory. It is\r
238 typically used for cache diagnostics. If the CPU does not support\r
239 invalidation of a data cache range, then a write back and invalidate\r
240 operation should be performed on the data cache range.\r
241\r
242 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
243\r
244 @param Address The base address of the data cache lines to invalidate. If\r
245 the CPU is in a physical addressing mode, then Address is a\r
246 physical address. If the CPU is in a virtual addressing mode,\r
247 then Address is a virtual address.\r
248 @param Length The number of bytes to invalidate from the data cache.\r
249\r
250 @return Address\r
251\r
252**/\r
878ddf1f 253VOID *\r
254EFIAPI\r
255InvalidateDataCacheRange (\r
256 IN VOID *Address,\r
257 IN UINTN Length\r
258 )\r
259{\r
9f84a609 260 return WriteBackInvalidateDataCacheRange (Address, Length);\r
878ddf1f 261}\r