]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseCacheMaintenanceLib/x86Cache.c
2 Cache Maintenance Functions.
4 Copyright (c) 2006, Intel Corporation<BR>
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
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.
17 // Include common header file for this module.
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
24 // This size must be at or below the smallest cache size possible among all
25 // supported processors
27 #define CACHE_LINE_SIZE 0x20
30 Invalidates the entire instruction cache in cache coherency domain of the
33 Invalidates the entire instruction cache in cache coherency domain of the
39 InvalidateInstructionCache (
46 Invalidates a range of instruction cache lines in the cache coherency domain
49 Invalidates the instruction cache lines specified by Address and Length. If
50 Address is not aligned on a cache line boundary, then entire instruction
51 cache line containing Address is invalidated. If Address + Length is not
52 aligned on a cache line boundary, then the entire instruction cache line
53 containing Address + Length -1 is invalidated. This function may choose to
54 invalidate the entire instruction cache if that is more efficient than
55 invalidating the specified range. If Length is 0, the no instruction cache
56 lines are invalidated. Address is returned.
58 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
60 @param Address The base address of the instruction cache lines to
61 invalidate. If the CPU is in a physical addressing mode, then
62 Address is a physical address. If the CPU is in a virtual
63 addressing mode, then Address is a virtual address.
65 @param Length The number of bytes to invalidate from the instruction cache.
67 @return Address of cache invalidation.
72 InvalidateInstructionCacheRange (
77 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Address
+ 1);
82 Writes Back and Invalidates the entire data cache in cache coherency domain
85 Writes Back and Invalidates the entire data cache in cache coherency domain
86 of the calling CPU. This function guarantees that all dirty cache lines are
87 written back to system memory, and also invalidates all the data cache lines
88 in the cache coherency domain of the calling CPU.
93 WriteBackInvalidateDataCache (
101 Writes Back and Invalidates a range of data cache lines in the cache
102 coherency domain of the calling CPU.
104 Writes Back and Invalidate the data cache lines specified by Address and
105 Length. If Address is not aligned on a cache line boundary, then entire data
106 cache line containing Address is written back and invalidated. If Address +
107 Length is not aligned on a cache line boundary, then the entire data cache
108 line containing Address + Length -1 is written back and invalidated. This
109 function may choose to write back and invalidate the entire data cache if
110 that is more efficient than writing back and invalidating the specified
111 range. If Length is 0, the no data cache lines are written back and
112 invalidated. Address is returned.
114 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
116 @param Address The base address of the data cache lines to write back and
117 invalidate. If the CPU is in a physical addressing mode, then
118 Address is a physical address. If the CPU is in a virtual
119 addressing mode, then Address is a virtual address.
120 @param Length The number of bytes to write back and invalidate from the
123 @return Address of cache invalidation.
128 WriteBackInvalidateDataCacheRange (
135 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Address
+ 1);
141 Start
= (UINTN
)Address
;
143 // Calculate the cache line alignment
145 End
= (Start
+ Length
+ (CACHE_LINE_SIZE
- 1)) & ~(CACHE_LINE_SIZE
- 1);
146 Start
&= ~(CACHE_LINE_SIZE
- 1);
149 Start
= (UINTN
)AsmFlushCacheLine ((VOID
*)Start
) + CACHE_LINE_SIZE
;
150 } while (Start
!= End
);
155 Writes Back the entire data cache in cache coherency domain of the calling
158 Writes Back the entire data cache in cache coherency domain of the calling
159 CPU. This function guarantees that all dirty cache lines are written back to
160 system memory. This function may also invalidate all the data cache lines in
161 the cache coherency domain of the calling CPU.
170 WriteBackInvalidateDataCache ();
174 Writes Back a range of data cache lines in the cache coherency domain of the
177 Writes Back the data cache lines specified by Address and Length. If Address
178 is not aligned on a cache line boundary, then entire data cache line
179 containing Address is written back. If Address + Length is not aligned on a
180 cache line boundary, then the entire data cache line containing Address +
181 Length -1 is written back. This function may choose to write back the entire
182 data cache if that is more efficient than writing back the specified range.
183 If Length is 0, the no data cache lines are written back. This function may
184 also invalidate all the data cache lines in the specified range of the cache
185 coherency domain of the calling CPU. Address is returned.
187 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
189 @param Address The base address of the data cache lines to write back. If
190 the CPU is in a physical addressing mode, then Address is a
191 physical address. If the CPU is in a virtual addressing
192 mode, then Address is a virtual address.
193 @param Length The number of bytes to write back from the data cache.
195 @return Address of cache wrote in main memory.
200 WriteBackDataCacheRange (
205 return WriteBackInvalidateDataCacheRange (Address
, Length
);
209 Invalidates the entire data cache in cache coherency domain of the calling
212 Invalidates the entire data cache in cache coherency domain of the calling
213 CPU. This function must be used with care because dirty cache lines are not
214 written back to system memory. It is typically used for cache diagnostics. If
215 the CPU does not support invalidation of the entire data cache, then a write
216 back and invalidate operation should be performed on the entire data cache.
221 InvalidateDataCache (
229 Invalidates a range of data cache lines in the cache coherency domain of the
232 Invalidates the data cache lines specified by Address and Length. If Address
233 is not aligned on a cache line boundary, then entire data cache line
234 containing Address is invalidated. If Address + Length is not aligned on a
235 cache line boundary, then the entire data cache line containing Address +
236 Length -1 is invalidated. This function must never invalidate any cache lines
237 outside the specified range. If Length is 0, the no data cache lines are
238 invalidated. Address is returned. This function must be used with care
239 because dirty cache lines are not written back to system memory. It is
240 typically used for cache diagnostics. If the CPU does not support
241 invalidation of a data cache range, then a write back and invalidate
242 operation should be performed on the data cache range.
244 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
246 @param Address The base address of the data cache lines to invalidate. If
247 the CPU is in a physical addressing mode, then Address is a
248 physical address. If the CPU is in a virtual addressing mode,
249 then Address is a virtual address.
250 @param Length The number of bytes to invalidate from the data cache.
252 @return Address of cache invalidation.
257 InvalidateDataCacheRange (
262 return WriteBackInvalidateDataCacheRange (Address
, Length
);