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.
13 Module Name: x86Cache.c
18 // This size must be at or below the smallest cache size possible among all
19 // supported processors
21 #define CACHE_LINE_SIZE 0x20
24 Invalidates the entire instruction cache in cache coherency domain of the
27 Invalidates the entire instruction cache in cache coherency domain of the
33 InvalidateInstructionCache (
40 Invalidates a range of instruction cache lines in the cache coherency domain
43 Invalidates the instruction cache lines specified by Address and Length. If
44 Address is not aligned on a cache line boundary, then entire instruction
45 cache line containing Address is invalidated. If Address + Length is not
46 aligned on a cache line boundary, then the entire instruction cache line
47 containing Address + Length -1 is invalidated. This function may choose to
48 invalidate the entire instruction cache if that is more efficient than
49 invalidating the specified range. If Length is 0, the no instruction cache
50 lines are invalidated. Address is returned.
52 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
54 @param Address The base address of the instruction cache lines to
55 invalidate. If the CPU is in a physical addressing mode, then
56 Address is a physical address. If the CPU is in a virtual
57 addressing mode, then Address is a virtual address.
59 @param Length The number of bytes to invalidate from the instruction cache.
66 InvalidateInstructionCacheRange (
71 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Address
+ 1);
76 Writes Back and Invalidates the entire data cache in cache coherency domain
79 Writes Back and Invalidates the entire data cache in cache coherency domain
80 of the calling CPU. This function guarantees that all dirty cache lines are
81 written back to system memory, and also invalidates all the data cache lines
82 in the cache coherency domain of the calling CPU.
87 WriteBackInvalidateDataCache (
95 Writes Back and Invalidates a range of data cache lines in the cache
96 coherency domain of the calling CPU.
98 Writes Back and Invalidate the data cache lines specified by Address and
99 Length. If Address is not aligned on a cache line boundary, then entire data
100 cache line containing Address is written back and invalidated. If Address +
101 Length is not aligned on a cache line boundary, then the entire data cache
102 line containing Address + Length -1 is written back and invalidated. This
103 function may choose to write back and invalidate the entire data cache if
104 that is more efficient than writing back and invalidating the specified
105 range. If Length is 0, the no data cache lines are written back and
106 invalidated. Address is returned.
108 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
110 @param Address The base address of the data cache lines to write back and
111 invalidate. If the CPU is in a physical addressing mode, then
112 Address is a physical address. If the CPU is in a virtual
113 addressing mode, then Address is a virtual address.
114 @param Length The number of bytes to write back and invalidate from the
122 WriteBackInvalidateDataCacheRange (
129 ASSERT (Length
<= MAX_ADDRESS
- (UINTN
)Address
+ 1);
135 Start
= (UINTN
)Address
;
136 End
= (Start
+ Length
+ (CACHE_LINE_SIZE
- 1)) & ~(CACHE_LINE_SIZE
- 1);
137 Start
&= ~(CACHE_LINE_SIZE
- 1);
140 Start
= (UINTN
)AsmFlushCacheLine ((VOID
*)Start
) + CACHE_LINE_SIZE
;
141 } while (Start
!= End
);
146 Writes Back the entire data cache in cache coherency domain of the calling
149 Writes Back the entire data cache in cache coherency domain of the calling
150 CPU. This function guarantees that all dirty cache lines are written back to
151 system memory. This function may also invalidate all the data cache lines in
152 the cache coherency domain of the calling CPU.
161 WriteBackInvalidateDataCache ();
165 Writes Back a range of data cache lines in the cache coherency domain of the
168 Writes Back the data cache lines specified by Address and Length. If Address
169 is not aligned on a cache line boundary, then entire data cache line
170 containing Address is written back. If Address + Length is not aligned on a
171 cache line boundary, then the entire data cache line containing Address +
172 Length -1 is written back. This function may choose to write back the entire
173 data cache if that is more efficient than writing back the specified range.
174 If Length is 0, the no data cache lines are written back. This function may
175 also invalidate all the data cache lines in the specified range of the cache
176 coherency domain of the calling CPU. Address is returned.
178 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
180 @param Address The base address of the data cache lines to write back. If
181 the CPU is in a physical addressing mode, then Address is a
182 physical address. If the CPU is in a virtual addressing
183 mode, then Address is a virtual address.
184 @param Length The number of bytes to write back from the data cache.
191 WriteBackDataCacheRange (
196 return WriteBackInvalidateDataCacheRange (Address
, Length
);
200 Invalidates the entire data cache in cache coherency domain of the calling
203 Invalidates the entire data cache in cache coherency domain of the calling
204 CPU. This function must be used with care because dirty cache lines are not
205 written back to system memory. It is typically used for cache diagnostics. If
206 the CPU does not support invalidation of the entire data cache, then a write
207 back and invalidate operation should be performed on the entire data cache.
212 InvalidateDataCache (
220 Invalidates a range of data cache lines in the cache coherency domain of the
223 Invalidates the data cache lines specified by Address and Length. If Address
224 is not aligned on a cache line boundary, then entire data cache line
225 containing Address is invalidated. If Address + Length is not aligned on a
226 cache line boundary, then the entire data cache line containing Address +
227 Length -1 is invalidated. This function must never invalidate any cache lines
228 outside the specified range. If Length is 0, the no data cache lines are
229 invalidated. Address is returned. This function must be used with care
230 because dirty cache lines are not written back to system memory. It is
231 typically used for cache diagnostics. If the CPU does not support
232 invalidation of a data cache range, then a write back and invalidate
233 operation should be performed on the data cache range.
235 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().
237 @param Address The base address of the data cache lines to invalidate. If
238 the CPU is in a physical addressing mode, then Address is a
239 physical address. If the CPU is in a virtual addressing mode,
240 then Address is a virtual address.
241 @param Length The number of bytes to invalidate from the data cache.
248 InvalidateDataCacheRange (
253 return WriteBackInvalidateDataCacheRange (Address
, Length
);