]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseCacheMaintenanceLib/RiscVCache.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseCacheMaintenanceLib / RiscVCache.c
CommitLineData
38e72aa8
AC
1/** @file\r
2 RISC-V specific functionality for cache.\r
3\r
4 Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>\r
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7**/\r
8\r
9#include <Base.h>\r
10#include <Library/BaseLib.h>\r
11#include <Library/DebugLib.h>\r
12\r
13/**\r
14 RISC-V invalidate instruction cache.\r
15\r
16**/\r
17VOID\r
18EFIAPI\r
19RiscVInvalidateInstCacheAsm (\r
20 VOID\r
21 );\r
22\r
23/**\r
24 RISC-V invalidate data cache.\r
25\r
26**/\r
27VOID\r
28EFIAPI\r
29RiscVInvalidateDataCacheAsm (\r
30 VOID\r
31 );\r
32\r
33/**\r
34 Invalidates the entire instruction cache in cache coherency domain of the\r
35 calling CPU.\r
36\r
37**/\r
38VOID\r
39EFIAPI\r
40InvalidateInstructionCache (\r
41 VOID\r
42 )\r
43{\r
44 RiscVInvalidateInstCacheAsm ();\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, then 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
2f88bd3a
MK
75 IN VOID *Address,\r
76 IN UINTN Length\r
38e72aa8
AC
77 )\r
78{\r
2f88bd3a 79 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__));\r
38e72aa8
AC
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
2f88bd3a 99 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__));\r
38e72aa8
AC
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 invalidates 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, then 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 of cache invalidation.\r
126\r
127**/\r
128VOID *\r
129EFIAPI\r
130WriteBackInvalidateDataCacheRange (\r
2f88bd3a
MK
131 IN VOID *Address,\r
132 IN UINTN Length\r
38e72aa8
AC
133 )\r
134{\r
2f88bd3a 135 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__));\r
38e72aa8
AC
136 return Address;\r
137}\r
138\r
139/**\r
140 Writes back the entire data cache in cache coherency domain of the calling\r
141 CPU.\r
142\r
143 Writes back the entire data cache in cache coherency domain of the calling\r
144 CPU. This function guarantees that all dirty cache lines are written back to\r
145 system memory. This function may also invalidate all the data cache lines in\r
146 the cache coherency domain of the calling CPU.\r
147\r
148**/\r
149VOID\r
150EFIAPI\r
151WriteBackDataCache (\r
152 VOID\r
153 )\r
154{\r
2f88bd3a 155 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__));\r
38e72aa8
AC
156}\r
157\r
158/**\r
159 Writes back a range of data cache lines in the cache coherency domain of the\r
160 calling CPU.\r
161\r
162 Writes back the data cache lines specified by Address and Length. If Address\r
163 is not aligned on a cache line boundary, then entire data cache line\r
164 containing Address is written back. If Address + Length is not aligned on a\r
165 cache line boundary, then the entire data cache line containing Address +\r
166 Length -1 is written back. This function may choose to write back the entire\r
167 data cache if that is more efficient than writing back the specified range.\r
168 If Length is 0, then no data cache lines are written back. This function may\r
169 also invalidate all the data cache lines in the specified range of the cache\r
170 coherency domain of the calling CPU. Address is returned.\r
171\r
172 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
173\r
174 @param Address The base address of the data cache lines to write back. If\r
175 the CPU is in a physical addressing mode, then Address is a\r
176 physical address. If the CPU is in a virtual addressing\r
177 mode, then Address is a virtual address.\r
178 @param Length The number of bytes to write back from the data cache.\r
179\r
180 @return Address of cache written in main memory.\r
181\r
182**/\r
183VOID *\r
184EFIAPI\r
185WriteBackDataCacheRange (\r
2f88bd3a
MK
186 IN VOID *Address,\r
187 IN UINTN Length\r
38e72aa8
AC
188 )\r
189{\r
2f88bd3a 190 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__));\r
38e72aa8
AC
191 return Address;\r
192}\r
193\r
194/**\r
195 Invalidates the entire data cache in cache coherency domain of the calling\r
196 CPU.\r
197\r
198 Invalidates the entire data cache in cache coherency domain of the calling\r
199 CPU. This function must be used with care because dirty cache lines are not\r
200 written back to system memory. It is typically used for cache diagnostics. If\r
201 the CPU does not support invalidation of the entire data cache, then a write\r
202 back and invalidate operation should be performed on the entire data cache.\r
203\r
204**/\r
205VOID\r
206EFIAPI\r
207InvalidateDataCache (\r
208 VOID\r
209 )\r
210{\r
211 RiscVInvalidateDataCacheAsm ();\r
212}\r
213\r
214/**\r
215 Invalidates a range of data cache lines in the cache coherency domain of the\r
216 calling CPU.\r
217\r
218 Invalidates the data cache lines specified by Address and Length. If Address\r
219 is not aligned on a cache line boundary, then entire data cache line\r
220 containing Address is invalidated. If Address + Length is not aligned on a\r
221 cache line boundary, then the entire data cache line containing Address +\r
222 Length -1 is invalidated. This function must never invalidate any cache lines\r
223 outside the specified range. If Length is 0, then no data cache lines are\r
224 invalidated. Address is returned. This function must be used with care\r
225 because dirty cache lines are not written back to system memory. It is\r
226 typically used for cache diagnostics. If the CPU does not support\r
227 invalidation of a data cache range, then a write back and invalidate\r
228 operation should be performed on the data cache range.\r
229\r
230 If Length is greater than (MAX_ADDRESS - Address + 1), then ASSERT().\r
231\r
232 @param Address The base address of the data cache lines to invalidate. If\r
233 the CPU is in a physical addressing mode, then Address is a\r
234 physical address. If the CPU is in a virtual addressing mode,\r
235 then Address is a virtual address.\r
236 @param Length The number of bytes to invalidate from the data cache.\r
237\r
238 @return Address.\r
239\r
240**/\r
241VOID *\r
242EFIAPI\r
243InvalidateDataCacheRange (\r
2f88bd3a
MK
244 IN VOID *Address,\r
245 IN UINTN Length\r
38e72aa8
AC
246 )\r
247{\r
2f88bd3a 248 DEBUG ((DEBUG_ERROR, "%a:RISC-V unsupported function.\n", __FUNCTION__));\r
38e72aa8
AC
249 return Address;\r
250}\r