]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BaseCacheMaintenanceLib/X86Cache.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / BaseCacheMaintenanceLib / X86Cache.c
CommitLineData
3eb9473e 1/*++\r
2\r
2c7e5c2f
HT
3Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12\r
13Module Name:\r
14\r
15 x86Cache.c\r
16 \r
17Abstract: \r
18\r
19 Cache Maintenance Functions.\r
20\r
21--*/\r
22\r
23#include "EdkIIGlueBase.h"\r
24\r
25//\r
26// This size must be at or below the smallest cache size possible among all\r
27// supported processors\r
28//\r
29#define CACHE_LINE_SIZE 0x20\r
30\r
31/**\r
32 Invalidates the entire instruction cache in cache coherency domain of the\r
33 calling CPU.\r
34\r
35 Invalidates the entire instruction cache in cache coherency domain of the\r
36 calling CPU.\r
37\r
38**/\r
39VOID\r
40EFIAPI\r
41GlueInvalidateInstructionCache (\r
42 VOID\r
43 )\r
44{\r
45}\r
46\r
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 return Address;\r
81}\r
82\r
83/**\r
84 Writes Back and Invalidates the entire data cache in cache coherency domain\r
85 of the calling CPU.\r
86\r
87 Writes Back and Invalidates the entire data cache in cache coherency domain\r
88 of the calling CPU. This function guarantees that all dirty cache lines are\r
89 written back to system memory, and also invalidates all the data cache lines\r
90 in the cache coherency domain of the calling CPU.\r
91\r
92**/\r
93VOID\r
94EFIAPI\r
95WriteBackInvalidateDataCache (\r
96 VOID\r
97 )\r
98{\r
99 AsmWbinvd ();\r
100}\r
101\r
102/**\r
103 Writes Back and Invalidates a range of data cache lines in the cache\r
104 coherency domain of the calling CPU.\r
105\r
106 Writes Back and Invalidate the data cache lines specified by Address and\r
107 Length. If Address is not aligned on a cache line boundary, then entire data\r
108 cache line containing Address is written back and invalidated. If Address +\r
109 Length is not aligned on a cache line boundary, then the entire data cache\r
110 line containing Address + Length -1 is written back and invalidated. This\r
111 function may choose to write back and invalidate the entire data cache if\r
112 that is more efficient than writing back and invalidating the specified\r
113 range. If Length is 0, the no data cache lines are written back and\r
114 invalidated. Address is returned.\r
115\r
116 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
117\r
118 @param Address The base address of the data cache lines to write back and\r
119 invalidate. If the CPU is in a physical addressing mode, then\r
120 Address is a physical address. If the CPU is in a virtual\r
121 addressing mode, then Address is a virtual address.\r
122 @param Length The number of bytes to write back and invalidate from the\r
123 data cache.\r
124\r
125 @return Address\r
126\r
127**/\r
128VOID *\r
129EFIAPI\r
130WriteBackInvalidateDataCacheRange (\r
131 IN VOID *Address,\r
132 IN UINTN Length\r
133 )\r
134{\r
135 UINTN Start, End;\r
136\r
137 ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1);\r
138\r
139 if (Length == 0) {\r
140 return Address;\r
141 }\r
142\r
143 Start = (UINTN)Address;\r
144 End = (Start + Length + (CACHE_LINE_SIZE - 1)) & ~(CACHE_LINE_SIZE - 1);\r
145 Start &= ~(CACHE_LINE_SIZE - 1);\r
146\r
147 do {\r
148 Start = (UINTN)AsmFlushCacheLine ((VOID*)Start) + CACHE_LINE_SIZE;\r
149 } while (Start != End);\r
150 return Address;\r
151}\r
152\r
153/**\r
154 Writes Back the entire data cache in cache coherency domain of the calling\r
155 CPU.\r
156\r
157 Writes Back the entire data cache in cache coherency domain of the calling\r
158 CPU. This function guarantees that all dirty cache lines are written back to\r
159 system memory. This function may also invalidate all the data cache lines in\r
160 the cache coherency domain of the calling CPU.\r
161\r
162**/\r
163VOID\r
164EFIAPI\r
165WriteBackDataCache (\r
166 VOID\r
167 )\r
168{\r
169 WriteBackInvalidateDataCache ();\r
170}\r
171\r
172/**\r
173 Writes Back a range of data cache lines in the cache coherency domain of the\r
174 calling CPU.\r
175\r
176 Writes Back the data cache lines specified by Address and Length. If Address\r
177 is not aligned on a cache line boundary, then entire data cache line\r
178 containing Address is written back. If Address + Length is not aligned on a\r
179 cache line boundary, then the entire data cache line containing Address +\r
180 Length -1 is written back. This function may choose to write back the entire\r
181 data cache if that is more efficient than writing back the specified range.\r
182 If Length is 0, the no data cache lines are written back. This function may\r
183 also invalidate all the data cache lines in the specified range of the cache\r
184 coherency domain of the calling CPU. Address is returned.\r
185\r
186 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
187\r
188 @param Address The base address of the data cache lines to write back. If\r
189 the CPU is in a physical addressing mode, then Address is a\r
190 physical address. If the CPU is in a virtual addressing\r
191 mode, then Address is a virtual address.\r
192 @param Length The number of bytes to write back from the data cache.\r
193\r
194 @return Address\r
195\r
196**/\r
197VOID *\r
198EFIAPI\r
199WriteBackDataCacheRange (\r
200 IN VOID *Address,\r
201 IN UINTN Length\r
202 )\r
203{\r
204 return WriteBackInvalidateDataCacheRange (Address, Length);\r
205}\r
206\r
207/**\r
208 Invalidates the entire data cache in cache coherency domain of the calling\r
209 CPU.\r
210\r
211 Invalidates the entire data cache in cache coherency domain of the calling\r
212 CPU. This function must be used with care because dirty cache lines are not\r
213 written back to system memory. It is typically used for cache diagnostics. If\r
214 the CPU does not support invalidation of the entire data cache, then a write\r
215 back and invalidate operation should be performed on the entire data cache.\r
216\r
217**/\r
218VOID\r
219EFIAPI\r
220InvalidateDataCache (\r
221 VOID\r
222 )\r
223{\r
224 AsmInvd ();\r
225}\r
226\r
227/**\r
228 Invalidates a range of data cache lines in the cache coherency domain of the\r
229 calling CPU.\r
230\r
231 Invalidates the data cache lines specified by Address and Length. If Address\r
232 is not aligned on a cache line boundary, then entire data cache line\r
233 containing Address is invalidated. If Address + Length is not aligned on a\r
234 cache line boundary, then the entire data cache line containing Address +\r
235 Length -1 is invalidated. This function must never invalidate any cache lines\r
236 outside the specified range. If Length is 0, the no data cache lines are\r
237 invalidated. Address is returned. This function must be used with care\r
238 because dirty cache lines are not written back to system memory. It is\r
239 typically used for cache diagnostics. If the CPU does not support\r
240 invalidation of a data cache range, then a write back and invalidate\r
241 operation should be performed on the data cache range.\r
242\r
243 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
244\r
245 @param Address The base address of the data cache lines to invalidate. If\r
246 the CPU is in a physical addressing mode, then Address is a\r
247 physical address. If the CPU is in a virtual addressing mode,\r
248 then Address is a virtual address.\r
249 @param Length The number of bytes to invalidate from the data cache.\r
250\r
251 @return Address\r
252\r
253**/\r
254VOID *\r
255EFIAPI\r
256InvalidateDataCacheRange (\r
257 IN VOID *Address,\r
258 IN UINTN Length\r
259 )\r
260{\r
261 return WriteBackInvalidateDataCacheRange (Address, Length);\r
262}\r