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