]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 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 | Module Name: x86Cache.c\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | //\r | |
18 | // Include common header file for this module.\r | |
19 | //\r | |
20 | #include "CommonHeader.h"\r | |
21 | \r | |
22 | //\r | |
23 | // This size must be at or below the smallest cache size possible among all\r | |
24 | // supported processors\r | |
25 | //\r | |
26 | #define CACHE_LINE_SIZE 0x20\r | |
27 | \r | |
28 | /**\r | |
29 | Invalidates the entire instruction cache in cache coherency domain of the\r | |
30 | calling CPU.\r | |
31 | \r | |
32 | Invalidates the entire instruction cache in cache coherency domain of the\r | |
33 | calling CPU.\r | |
34 | \r | |
35 | **/\r | |
36 | VOID\r | |
37 | EFIAPI\r | |
38 | InvalidateInstructionCache (\r | |
39 | VOID\r | |
40 | )\r | |
41 | {\r | |
42 | }\r | |
43 | \r | |
44 | /**\r | |
45 | Invalidates a range of instruction cache lines in the cache coherency domain\r | |
46 | of the calling CPU.\r | |
47 | \r | |
48 | Invalidates the instruction cache lines specified by Address and Length. If\r | |
49 | Address is not aligned on a cache line boundary, then entire instruction\r | |
50 | cache line containing Address is invalidated. If Address + Length is not\r | |
51 | aligned on a cache line boundary, then the entire instruction cache line\r | |
52 | containing Address + Length -1 is invalidated. This function may choose to\r | |
53 | invalidate the entire instruction cache if that is more efficient than\r | |
54 | invalidating the specified range. If Length is 0, the no instruction cache\r | |
55 | lines are invalidated. Address is returned.\r | |
56 | \r | |
57 | If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r | |
58 | \r | |
59 | @param Address The base address of the instruction cache lines to\r | |
60 | invalidate. If the CPU is in a physical addressing mode, then\r | |
61 | Address is a physical address. If the CPU is in a virtual\r | |
62 | addressing mode, then Address is a virtual address.\r | |
63 | \r | |
64 | @param Length The number of bytes to invalidate from the instruction cache.\r | |
65 | \r | |
66 | @return Address\r | |
67 | \r | |
68 | **/\r | |
69 | VOID *\r | |
70 | EFIAPI\r | |
71 | InvalidateInstructionCacheRange (\r | |
72 | IN VOID *Address,\r | |
73 | IN UINTN Length\r | |
74 | )\r | |
75 | {\r | |
76 | ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1);\r | |
77 | return Address;\r | |
78 | }\r | |
79 | \r | |
80 | /**\r | |
81 | Writes Back and Invalidates the entire data cache in cache coherency domain\r | |
82 | of the calling CPU.\r | |
83 | \r | |
84 | Writes Back and Invalidates the entire data cache in cache coherency domain\r | |
85 | of the calling CPU. This function guarantees that all dirty cache lines are\r | |
86 | written back to system memory, and also invalidates all the data cache lines\r | |
87 | in the cache coherency domain of the calling CPU.\r | |
88 | \r | |
89 | **/\r | |
90 | VOID\r | |
91 | EFIAPI\r | |
92 | WriteBackInvalidateDataCache (\r | |
93 | VOID\r | |
94 | )\r | |
95 | {\r | |
96 | AsmWbinvd ();\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | Writes Back and Invalidates a range of data cache lines in the cache\r | |
101 | coherency domain of the calling CPU.\r | |
102 | \r | |
103 | Writes Back and Invalidate the data cache lines specified by Address and\r | |
104 | Length. If Address is not aligned on a cache line boundary, then entire data\r | |
105 | cache line containing Address is written back and invalidated. If Address +\r | |
106 | Length is not aligned on a cache line boundary, then the entire data cache\r | |
107 | line containing Address + Length -1 is written back and invalidated. This\r | |
108 | function may choose to write back and invalidate the entire data cache if\r | |
109 | that is more efficient than writing back and invalidating the specified\r | |
110 | range. If Length is 0, the no data cache lines are written back and\r | |
111 | invalidated. Address is returned.\r | |
112 | \r | |
113 | If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r | |
114 | \r | |
115 | @param Address The base address of the data cache lines to write back and\r | |
116 | invalidate. If the CPU is in a physical addressing mode, then\r | |
117 | Address is a physical address. If the CPU is in a virtual\r | |
118 | addressing mode, then Address is a virtual address.\r | |
119 | @param Length The number of bytes to write back and invalidate from the\r | |
120 | data cache.\r | |
121 | \r | |
122 | @return Address\r | |
123 | \r | |
124 | **/\r | |
125 | VOID *\r | |
126 | EFIAPI\r | |
127 | WriteBackInvalidateDataCacheRange (\r | |
128 | IN VOID *Address,\r | |
129 | IN UINTN Length\r | |
130 | )\r | |
131 | {\r | |
132 | UINTN Start, End;\r | |
133 | \r | |
134 | ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1);\r | |
135 | \r | |
136 | if (Length == 0) {\r | |
137 | return Address;\r | |
138 | }\r | |
139 | \r | |
140 | Start = (UINTN)Address;\r | |
141 | End = (Start + Length + (CACHE_LINE_SIZE - 1)) & ~(CACHE_LINE_SIZE - 1);\r | |
142 | Start &= ~(CACHE_LINE_SIZE - 1);\r | |
143 | \r | |
144 | do {\r | |
145 | Start = (UINTN)AsmFlushCacheLine ((VOID*)Start) + CACHE_LINE_SIZE;\r | |
146 | } while (Start != End);\r | |
147 | return Address;\r | |
148 | }\r | |
149 | \r | |
150 | /**\r | |
151 | Writes Back the entire data cache in cache coherency domain of the calling\r | |
152 | CPU.\r | |
153 | \r | |
154 | Writes Back the entire data cache in cache coherency domain of the calling\r | |
155 | CPU. This function guarantees that all dirty cache lines are written back to\r | |
156 | system memory. This function may also invalidate all the data cache lines in\r | |
157 | the cache coherency domain of the calling CPU.\r | |
158 | \r | |
159 | **/\r | |
160 | VOID\r | |
161 | EFIAPI\r | |
162 | WriteBackDataCache (\r | |
163 | VOID\r | |
164 | )\r | |
165 | {\r | |
166 | WriteBackInvalidateDataCache ();\r | |
167 | }\r | |
168 | \r | |
169 | /**\r | |
170 | Writes Back a range of data cache lines in the cache coherency domain of the\r | |
171 | calling CPU.\r | |
172 | \r | |
173 | Writes Back the data cache lines specified by Address and Length. If Address\r | |
174 | is not aligned on a cache line boundary, then entire data cache line\r | |
175 | containing Address is written back. If Address + Length is not aligned on a\r | |
176 | cache line boundary, then the entire data cache line containing Address +\r | |
177 | Length -1 is written back. This function may choose to write back the entire\r | |
178 | data cache if that is more efficient than writing back the specified range.\r | |
179 | If Length is 0, the no data cache lines are written back. This function may\r | |
180 | also invalidate all the data cache lines in the specified range of the cache\r | |
181 | coherency domain of the calling CPU. Address is returned.\r | |
182 | \r | |
183 | If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r | |
184 | \r | |
185 | @param Address The base address of the data cache lines to write back. If\r | |
186 | the CPU is in a physical addressing mode, then Address is a\r | |
187 | physical address. If the CPU is in a virtual addressing\r | |
188 | mode, then Address is a virtual address.\r | |
189 | @param Length The number of bytes to write back from the data cache.\r | |
190 | \r | |
191 | @return Address\r | |
192 | \r | |
193 | **/\r | |
194 | VOID *\r | |
195 | EFIAPI\r | |
196 | WriteBackDataCacheRange (\r | |
197 | IN VOID *Address,\r | |
198 | IN UINTN Length\r | |
199 | )\r | |
200 | {\r | |
201 | return WriteBackInvalidateDataCacheRange (Address, Length);\r | |
202 | }\r | |
203 | \r | |
204 | /**\r | |
205 | Invalidates the entire data cache in cache coherency domain of the calling\r | |
206 | CPU.\r | |
207 | \r | |
208 | Invalidates the entire data cache in cache coherency domain of the calling\r | |
209 | CPU. This function must be used with care because dirty cache lines are not\r | |
210 | written back to system memory. It is typically used for cache diagnostics. If\r | |
211 | the CPU does not support invalidation of the entire data cache, then a write\r | |
212 | back and invalidate operation should be performed on the entire data cache.\r | |
213 | \r | |
214 | **/\r | |
215 | VOID\r | |
216 | EFIAPI\r | |
217 | InvalidateDataCache (\r | |
218 | VOID\r | |
219 | )\r | |
220 | {\r | |
221 | AsmInvd ();\r | |
222 | }\r | |
223 | \r | |
224 | /**\r | |
225 | Invalidates a range of data cache lines in the cache coherency domain of the\r | |
226 | calling CPU.\r | |
227 | \r | |
228 | Invalidates the data cache lines specified by Address and Length. If Address\r | |
229 | is not aligned on a cache line boundary, then entire data cache line\r | |
230 | containing Address is invalidated. If Address + Length is not aligned on a\r | |
231 | cache line boundary, then the entire data cache line containing Address +\r | |
232 | Length -1 is invalidated. This function must never invalidate any cache lines\r | |
233 | outside the specified range. If Length is 0, the no data cache lines are\r | |
234 | invalidated. Address is returned. This function must be used with care\r | |
235 | because dirty cache lines are not written back to system memory. It is\r | |
236 | typically used for cache diagnostics. If the CPU does not support\r | |
237 | invalidation of a data cache range, then a write back and invalidate\r | |
238 | operation should be performed on the data cache range.\r | |
239 | \r | |
240 | If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r | |
241 | \r | |
242 | @param Address The base address of the data cache lines to invalidate. If\r | |
243 | the CPU is in a physical addressing mode, then Address is a\r | |
244 | physical address. If the CPU is in a virtual addressing mode,\r | |
245 | then Address is a virtual address.\r | |
246 | @param Length The number of bytes to invalidate from the data cache.\r | |
247 | \r | |
248 | @return Address\r | |
249 | \r | |
250 | **/\r | |
251 | VOID *\r | |
252 | EFIAPI\r | |
253 | InvalidateDataCacheRange (\r | |
254 | IN VOID *Address,\r | |
255 | IN UINTN Length\r | |
256 | )\r | |
257 | {\r | |
258 | return WriteBackInvalidateDataCacheRange (Address, Length);\r | |
259 | }\r |