]>
Commit | Line | Data |
---|---|---|
2ef2b01e | 1 | /** @file\r |
a7463b30 | 2 | UncachedMemoryAllocation lib that uses DXE Service to change cachability for\r |
883b666e | 3 | a buffer.\r |
2ef2b01e | 4 | \r |
d6ebcab7 | 5 | Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>\r |
1a70a690 | 6 | Copyright (c) 2014, AMR Ltd. All rights reserved.<BR>\r |
3402aac7 | 7 | \r |
d6ebcab7 | 8 | This program and the accompanying materials\r |
2ef2b01e A |
9 | are licensed and made available under the terms and conditions of the BSD License\r |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
44c01161 | 18 | #include <Base.h>\r |
883b666e | 19 | #include <Library/BaseLib.h>\r |
2ef2b01e | 20 | #include <Library/BaseMemoryLib.h>\r |
883b666e | 21 | #include <Library/MemoryAllocationLib.h>\r |
2ef2b01e A |
22 | #include <Library/DebugLib.h>\r |
23 | #include <Library/UefiBootServicesTableLib.h>\r | |
24 | #include <Library/UncachedMemoryAllocationLib.h>\r | |
25 | #include <Library/PcdLib.h>\r | |
26 | #include <Library/ArmLib.h>\r | |
883b666e | 27 | #include <Library/DxeServicesTableLib.h>\r |
e266db59 | 28 | #include <Library/CacheMaintenanceLib.h>\r |
883b666e | 29 | \r |
883b666e | 30 | VOID *\r |
31 | UncachedInternalAllocatePages (\r | |
3402aac7 | 32 | IN EFI_MEMORY_TYPE MemoryType,\r |
883b666e | 33 | IN UINTN Pages\r |
34 | );\r | |
35 | \r | |
36 | VOID *\r | |
37 | UncachedInternalAllocateAlignedPages (\r | |
3402aac7 | 38 | IN EFI_MEMORY_TYPE MemoryType,\r |
883b666e | 39 | IN UINTN Pages,\r |
40 | IN UINTN Alignment\r | |
41 | );\r | |
3402aac7 RC |
42 | \r |
43 | \r | |
2ef2b01e | 44 | \r |
883b666e | 45 | typedef struct {\r |
1a70a690 OM |
46 | EFI_PHYSICAL_ADDRESS Base;\r |
47 | VOID *Allocation;\r | |
48 | UINTN Pages;\r | |
49 | EFI_MEMORY_TYPE MemoryType;\r | |
50 | BOOLEAN Allocated;\r | |
51 | LIST_ENTRY Link;\r | |
bb52ec2d | 52 | UINT64 Attributes;\r |
883b666e | 53 | } FREE_PAGE_NODE;\r |
54 | \r | |
1a70a690 OM |
55 | STATIC LIST_ENTRY mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);\r |
56 | // Track the size of the non-allocated buffer in the linked-list\r | |
57 | STATIC UINTN mFreedBufferSize = 0;\r | |
883b666e | 58 | \r |
1a70a690 OM |
59 | /**\r |
60 | * This function firstly checks if the requested allocation can fit into one\r | |
61 | * of the previously allocated buffer.\r | |
62 | * If the requested allocation does not fit in the existing pool then\r | |
63 | * the function makes a new allocation.\r | |
64 | *\r | |
65 | * @param MemoryType Type of memory requested for the new allocation\r | |
66 | * @param Pages Number of requested page\r | |
67 | * @param Alignment Required alignment\r | |
68 | * @param Allocation Address of the newly allocated buffer\r | |
69 | *\r | |
70 | * @return EFI_SUCCESS If the function manage to allocate a buffer\r | |
71 | * @return !EFI_SUCCESS If the function did not manage to allocate a buffer\r | |
72 | */\r | |
73 | STATIC\r | |
74 | EFI_STATUS\r | |
75 | AllocatePagesFromList (\r | |
76 | IN EFI_MEMORY_TYPE MemoryType,\r | |
77 | IN UINTN Pages,\r | |
78 | IN UINTN Alignment,\r | |
79 | OUT VOID **Allocation\r | |
2ef2b01e A |
80 | )\r |
81 | {\r | |
1a70a690 OM |
82 | EFI_STATUS Status;\r |
83 | LIST_ENTRY *Link;\r | |
84 | FREE_PAGE_NODE *Node;\r | |
883b666e | 85 | FREE_PAGE_NODE *NewNode;\r |
1a70a690 OM |
86 | UINTN AlignmentMask;\r |
87 | EFI_PHYSICAL_ADDRESS Memory;\r | |
88 | EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;\r | |
89 | \r | |
90 | // Alignment must be a power of two or zero.\r | |
91 | ASSERT ((Alignment & (Alignment - 1)) == 0);\r | |
92 | \r | |
93 | //\r | |
94 | // Look in our list for the smallest page that could satisfy the new allocation\r | |
95 | //\r | |
95ac787f | 96 | Node = NULL;\r |
1a70a690 OM |
97 | NewNode = NULL;\r |
98 | for (Link = mPageList.ForwardLink; Link != &mPageList; Link = Link->ForwardLink) {\r | |
99 | Node = BASE_CR (Link, FREE_PAGE_NODE, Link);\r | |
100 | if ((Node->Allocated == FALSE) && (Node->MemoryType == MemoryType)) {\r | |
101 | // We have a node that fits our requirements\r | |
102 | if (((UINTN)Node->Base & (Alignment - 1)) == 0) {\r | |
103 | // We found a page that matches the page size\r | |
104 | if (Node->Pages == Pages) {\r | |
105 | Node->Allocated = TRUE;\r | |
106 | Node->Allocation = (VOID*)(UINTN)Node->Base;\r | |
107 | *Allocation = Node->Allocation;\r | |
108 | \r | |
109 | // Update the size of the freed buffer\r | |
110 | mFreedBufferSize -= Pages * EFI_PAGE_SIZE;\r | |
111 | return EFI_SUCCESS;\r | |
112 | } else if (Node->Pages > Pages) {\r | |
113 | if (NewNode == NULL) {\r | |
114 | // It is the first node that could contain our new allocation\r | |
115 | NewNode = Node;\r | |
116 | } else if (NewNode->Pages > Node->Pages) {\r | |
117 | // This node offers a smaller number of page.\r | |
118 | NewNode = Node;\r | |
119 | }\r | |
120 | }\r | |
121 | }\r | |
122 | }\r | |
123 | }\r | |
124 | // Check if we have found a node that could contain our new allocation\r | |
125 | if (NewNode != NULL) {\r | |
da705630 HG |
126 | NewNode->Allocated = TRUE;\r |
127 | NewNode->Allocation = (VOID*)(UINTN)NewNode->Base;\r | |
128 | *Allocation = NewNode->Allocation;\r | |
129 | mFreedBufferSize -= NewNode->Pages * EFI_PAGE_SIZE;\r | |
1a70a690 OM |
130 | return EFI_SUCCESS;\r |
131 | }\r | |
3402aac7 | 132 | \r |
1a70a690 OM |
133 | //\r |
134 | // Otherwise, we need to allocate a new buffer\r | |
135 | //\r | |
136 | \r | |
137 | // We do not want to over-allocate in case the alignment requirement does not\r | |
138 | // require extra pages\r | |
139 | if (Alignment > EFI_PAGE_SIZE) {\r | |
140 | AlignmentMask = Alignment - 1;\r | |
141 | Pages += EFI_SIZE_TO_PAGES (Alignment);\r | |
142 | } else {\r | |
143 | AlignmentMask = 0;\r | |
144 | }\r | |
145 | \r | |
146 | Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r | |
147 | if (EFI_ERROR (Status)) {\r | |
148 | return Status;\r | |
149 | }\r | |
150 | \r | |
151 | Status = gDS->GetMemorySpaceDescriptor (Memory, &Descriptor);\r | |
bb52ec2d | 152 | if (EFI_ERROR (Status)) {\r |
1a70a690 OM |
153 | gBS->FreePages (Memory, Pages);\r |
154 | return Status;\r | |
155 | }\r | |
156 | \r | |
157 | Status = gDS->SetMemorySpaceAttributes (Memory, EFI_PAGES_TO_SIZE (Pages), EFI_MEMORY_WC);\r | |
158 | if (EFI_ERROR (Status)) {\r | |
159 | gBS->FreePages (Memory, Pages);\r | |
160 | return Status;\r | |
161 | }\r | |
162 | \r | |
e266db59 HG |
163 | InvalidateDataCacheRange ((VOID *)(UINTN)Memory, EFI_PAGES_TO_SIZE (Pages));\r |
164 | \r | |
1a70a690 | 165 | NewNode = AllocatePool (sizeof (FREE_PAGE_NODE));\r |
883b666e | 166 | if (NewNode == NULL) {\r |
167 | ASSERT (FALSE);\r | |
1a70a690 OM |
168 | gBS->FreePages (Memory, Pages);\r |
169 | return EFI_OUT_OF_RESOURCES;\r | |
883b666e | 170 | }\r |
3402aac7 | 171 | \r |
1a70a690 OM |
172 | NewNode->Base = Memory;\r |
173 | NewNode->Allocation = (VOID*)(((UINTN)Memory + AlignmentMask) & ~AlignmentMask);\r | |
883b666e | 174 | NewNode->Pages = Pages;\r |
1a70a690 OM |
175 | NewNode->Allocated = TRUE;\r |
176 | NewNode->MemoryType = MemoryType;\r | |
bb52ec2d | 177 | NewNode->Attributes = Descriptor.Attributes;\r |
3402aac7 | 178 | \r |
883b666e | 179 | InsertTailList (&mPageList, &NewNode->Link);\r |
1a70a690 OM |
180 | \r |
181 | *Allocation = NewNode->Allocation;\r | |
182 | return EFI_SUCCESS;\r | |
2ef2b01e A |
183 | }\r |
184 | \r | |
1a70a690 OM |
185 | /**\r |
186 | * Free the memory allocation\r | |
187 | *\r | |
188 | * This function will actually try to find the allocation in the linked list.\r | |
189 | * And it will then mark the entry as freed.\r | |
190 | *\r | |
191 | * @param Allocation Base address of the buffer to free\r | |
192 | *\r | |
193 | * @return EFI_SUCCESS The allocation has been freed\r | |
194 | * @return EFI_NOT_FOUND The allocation was not found in the pool.\r | |
195 | * @return EFI_INVALID_PARAMETER If Allocation is NULL\r | |
196 | *\r | |
197 | */\r | |
198 | STATIC\r | |
199 | EFI_STATUS\r | |
200 | FreePagesFromList (\r | |
201 | IN VOID *Allocation\r | |
202 | )\r | |
203 | {\r | |
204 | LIST_ENTRY *Link;\r | |
205 | FREE_PAGE_NODE *Node;\r | |
206 | \r | |
207 | if (Allocation == NULL) {\r | |
208 | return EFI_INVALID_PARAMETER;\r | |
209 | }\r | |
883b666e | 210 | \r |
1a70a690 OM |
211 | for (Link = mPageList.ForwardLink; Link != &mPageList; Link = Link->ForwardLink) {\r |
212 | Node = BASE_CR (Link, FREE_PAGE_NODE, Link);\r | |
213 | if ((UINTN)Node->Allocation == (UINTN)Allocation) {\r | |
214 | Node->Allocated = FALSE;\r | |
215 | \r | |
216 | // Update the size of the freed buffer\r | |
217 | mFreedBufferSize += Node->Pages * EFI_PAGE_SIZE;\r | |
218 | \r | |
219 | // If the size of the non-allocated reaches the threshold we raise a warning.\r | |
220 | // It might be an expected behaviour in some cases.\r | |
221 | // We might device to free some of these buffers later on.\r | |
222 | if (mFreedBufferSize > PcdGet64 (PcdArmFreeUncachedMemorySizeThreshold)) {\r | |
223 | DEBUG ((EFI_D_WARN, "Warning: The list of non-allocated buffer has reach the threshold.\n"));\r | |
224 | }\r | |
225 | return EFI_SUCCESS;\r | |
226 | }\r | |
227 | }\r | |
228 | \r | |
229 | return EFI_NOT_FOUND;\r | |
230 | }\r | |
231 | \r | |
232 | /**\r | |
233 | * This function is automatically invoked when the driver exits\r | |
234 | * It frees all the non-allocated memory buffer.\r | |
235 | * This function is not responsible to free allocated buffer (eg: case of memory leak,\r | |
236 | * runtime allocation).\r | |
237 | */\r | |
238 | EFI_STATUS\r | |
239 | EFIAPI\r | |
240 | UncachedMemoryAllocationLibDestructor (\r | |
241 | IN EFI_HANDLE ImageHandle,\r | |
242 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
2ef2b01e A |
243 | )\r |
244 | {\r | |
883b666e | 245 | LIST_ENTRY *Link;\r |
246 | FREE_PAGE_NODE *OldNode;\r | |
247 | \r | |
1a70a690 OM |
248 | // Test if the list is empty\r |
249 | Link = mPageList.ForwardLink;\r | |
250 | if (Link == &mPageList) {\r | |
251 | return EFI_SUCCESS;\r | |
252 | }\r | |
3402aac7 | 253 | \r |
1a70a690 OM |
254 | // Free all the pages and nodes\r |
255 | do {\r | |
883b666e | 256 | OldNode = BASE_CR (Link, FREE_PAGE_NODE, Link);\r |
1a70a690 OM |
257 | // Point to the next entry\r |
258 | Link = Link->ForwardLink;\r | |
3402aac7 | 259 | \r |
1a70a690 OM |
260 | // We only free the non-allocated buffer\r |
261 | if (OldNode->Allocated == FALSE) {\r | |
262 | gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);\r | |
bb52ec2d AB |
263 | \r |
264 | gDS->SetMemorySpaceAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base,\r | |
265 | EFI_PAGES_TO_SIZE (OldNode->Pages), OldNode->Attributes);\r | |
266 | \r | |
883b666e | 267 | RemoveEntryList (&OldNode->Link);\r |
268 | FreePool (OldNode);\r | |
883b666e | 269 | }\r |
1a70a690 | 270 | } while (Link != &mPageList);\r |
883b666e | 271 | \r |
1a70a690 | 272 | return EFI_SUCCESS;\r |
2ef2b01e A |
273 | }\r |
274 | \r | |
883b666e | 275 | /**\r |
276 | Converts a cached or uncached address to a physical address suitable for use in SoC registers.\r | |
277 | \r | |
278 | @param VirtualAddress The pointer to convert.\r | |
279 | \r | |
280 | @return The physical address of the supplied virtual pointer.\r | |
281 | \r | |
282 | **/\r | |
283 | EFI_PHYSICAL_ADDRESS\r | |
284 | ConvertToPhysicalAddress (\r | |
285 | IN VOID *VirtualAddress\r | |
286 | )\r | |
287 | {\r | |
288 | return (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAddress;\r | |
289 | }\r | |
290 | \r | |
291 | \r | |
2ef2b01e A |
292 | VOID *\r |
293 | UncachedInternalAllocatePages (\r | |
3402aac7 | 294 | IN EFI_MEMORY_TYPE MemoryType,\r |
2ef2b01e A |
295 | IN UINTN Pages\r |
296 | )\r | |
297 | {\r | |
883b666e | 298 | return UncachedInternalAllocateAlignedPages (MemoryType, Pages, EFI_PAGE_SIZE);\r |
2ef2b01e A |
299 | }\r |
300 | \r | |
883b666e | 301 | \r |
2ef2b01e A |
302 | VOID *\r |
303 | EFIAPI\r | |
304 | UncachedAllocatePages (\r | |
305 | IN UINTN Pages\r | |
306 | )\r | |
307 | {\r | |
308 | return UncachedInternalAllocatePages (EfiBootServicesData, Pages);\r | |
309 | }\r | |
310 | \r | |
311 | VOID *\r | |
312 | EFIAPI\r | |
313 | UncachedAllocateRuntimePages (\r | |
314 | IN UINTN Pages\r | |
315 | )\r | |
316 | {\r | |
317 | return UncachedInternalAllocatePages (EfiRuntimeServicesData, Pages);\r | |
318 | }\r | |
319 | \r | |
320 | VOID *\r | |
321 | EFIAPI\r | |
322 | UncachedAllocateReservedPages (\r | |
323 | IN UINTN Pages\r | |
324 | )\r | |
325 | {\r | |
326 | return UncachedInternalAllocatePages (EfiReservedMemoryType, Pages);\r | |
327 | }\r | |
328 | \r | |
883b666e | 329 | \r |
330 | \r | |
2ef2b01e A |
331 | VOID\r |
332 | EFIAPI\r | |
333 | UncachedFreePages (\r | |
334 | IN VOID *Buffer,\r | |
335 | IN UINTN Pages\r | |
336 | )\r | |
337 | {\r | |
883b666e | 338 | UncachedFreeAlignedPages (Buffer, Pages);\r |
339 | return;\r | |
2ef2b01e A |
340 | }\r |
341 | \r | |
883b666e | 342 | \r |
2ef2b01e A |
343 | VOID *\r |
344 | UncachedInternalAllocateAlignedPages (\r | |
3402aac7 | 345 | IN EFI_MEMORY_TYPE MemoryType,\r |
2ef2b01e A |
346 | IN UINTN Pages,\r |
347 | IN UINTN Alignment\r | |
348 | )\r | |
349 | {\r | |
1a70a690 OM |
350 | EFI_STATUS Status;\r |
351 | VOID *Allocation;\r | |
3402aac7 | 352 | \r |
2ef2b01e A |
353 | if (Pages == 0) {\r |
354 | return NULL;\r | |
355 | }\r | |
3402aac7 | 356 | \r |
1a70a690 OM |
357 | Allocation = NULL;\r |
358 | Status = AllocatePagesFromList (MemoryType, Pages, Alignment, &Allocation);\r | |
359 | if (EFI_ERROR (Status)) {\r | |
360 | ASSERT_EFI_ERROR (Status);\r | |
361 | return NULL;\r | |
362 | } else {\r | |
363 | return Allocation;\r | |
2ef2b01e | 364 | }\r |
2ef2b01e A |
365 | }\r |
366 | \r | |
2ef2b01e A |
367 | \r |
368 | VOID\r | |
369 | EFIAPI\r | |
370 | UncachedFreeAlignedPages (\r | |
371 | IN VOID *Buffer,\r | |
372 | IN UINTN Pages\r | |
373 | )\r | |
374 | {\r | |
1a70a690 | 375 | FreePagesFromList (Buffer);\r |
2ef2b01e A |
376 | }\r |
377 | \r | |
883b666e | 378 | \r |
2ef2b01e A |
379 | VOID *\r |
380 | UncachedInternalAllocateAlignedPool (\r | |
381 | IN EFI_MEMORY_TYPE PoolType,\r | |
382 | IN UINTN AllocationSize,\r | |
383 | IN UINTN Alignment\r | |
384 | )\r | |
385 | {\r | |
883b666e | 386 | VOID *AlignedAddress;\r |
3402aac7 | 387 | \r |
2ef2b01e A |
388 | //\r |
389 | // Alignment must be a power of two or zero.\r | |
390 | //\r | |
391 | ASSERT ((Alignment & (Alignment - 1)) == 0);\r | |
392 | \r | |
883b666e | 393 | if (Alignment < EFI_PAGE_SIZE) {\r |
394 | Alignment = EFI_PAGE_SIZE;\r | |
2ef2b01e | 395 | }\r |
3402aac7 | 396 | \r |
883b666e | 397 | AlignedAddress = UncachedInternalAllocateAlignedPages (PoolType, EFI_SIZE_TO_PAGES (AllocationSize), Alignment);\r |
398 | if (AlignedAddress == NULL) {\r | |
2ef2b01e A |
399 | return NULL;\r |
400 | }\r | |
401 | \r | |
2ef2b01e A |
402 | return (VOID *) AlignedAddress;\r |
403 | }\r | |
404 | \r | |
405 | VOID *\r | |
406 | EFIAPI\r | |
407 | UncachedAllocateAlignedPool (\r | |
408 | IN UINTN AllocationSize,\r | |
409 | IN UINTN Alignment\r | |
410 | )\r | |
411 | {\r | |
412 | return UncachedInternalAllocateAlignedPool (EfiBootServicesData, AllocationSize, Alignment);\r | |
413 | }\r | |
414 | \r | |
415 | VOID *\r | |
416 | EFIAPI\r | |
417 | UncachedAllocateAlignedRuntimePool (\r | |
418 | IN UINTN AllocationSize,\r | |
419 | IN UINTN Alignment\r | |
420 | )\r | |
421 | {\r | |
422 | return UncachedInternalAllocateAlignedPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r | |
423 | }\r | |
424 | \r | |
425 | VOID *\r | |
426 | EFIAPI\r | |
427 | UncachedAllocateAlignedReservedPool (\r | |
428 | IN UINTN AllocationSize,\r | |
429 | IN UINTN Alignment\r | |
430 | )\r | |
431 | {\r | |
432 | return UncachedInternalAllocateAlignedPool (EfiReservedMemoryType, AllocationSize, Alignment);\r | |
433 | }\r | |
434 | \r | |
435 | VOID *\r | |
436 | UncachedInternalAllocateAlignedZeroPool (\r | |
437 | IN EFI_MEMORY_TYPE PoolType,\r | |
438 | IN UINTN AllocationSize,\r | |
439 | IN UINTN Alignment\r | |
440 | )\r | |
441 | {\r | |
442 | VOID *Memory;\r | |
443 | Memory = UncachedInternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r | |
444 | if (Memory != NULL) {\r | |
445 | Memory = ZeroMem (Memory, AllocationSize);\r | |
446 | }\r | |
447 | return Memory;\r | |
448 | }\r | |
449 | \r | |
450 | VOID *\r | |
451 | EFIAPI\r | |
452 | UncachedAllocateAlignedZeroPool (\r | |
453 | IN UINTN AllocationSize,\r | |
454 | IN UINTN Alignment\r | |
455 | )\r | |
456 | {\r | |
457 | return UncachedInternalAllocateAlignedZeroPool (EfiBootServicesData, AllocationSize, Alignment);\r | |
458 | }\r | |
459 | \r | |
460 | VOID *\r | |
461 | EFIAPI\r | |
462 | UncachedAllocateAlignedRuntimeZeroPool (\r | |
463 | IN UINTN AllocationSize,\r | |
464 | IN UINTN Alignment\r | |
465 | )\r | |
466 | {\r | |
467 | return UncachedInternalAllocateAlignedZeroPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r | |
468 | }\r | |
469 | \r | |
470 | VOID *\r | |
471 | EFIAPI\r | |
472 | UncachedAllocateAlignedReservedZeroPool (\r | |
473 | IN UINTN AllocationSize,\r | |
474 | IN UINTN Alignment\r | |
475 | )\r | |
476 | {\r | |
477 | return UncachedInternalAllocateAlignedZeroPool (EfiReservedMemoryType, AllocationSize, Alignment);\r | |
478 | }\r | |
479 | \r | |
480 | VOID *\r | |
481 | UncachedInternalAllocateAlignedCopyPool (\r | |
482 | IN EFI_MEMORY_TYPE PoolType,\r | |
483 | IN UINTN AllocationSize,\r | |
484 | IN CONST VOID *Buffer,\r | |
485 | IN UINTN Alignment\r | |
486 | )\r | |
487 | {\r | |
488 | VOID *Memory;\r | |
3402aac7 | 489 | \r |
2ef2b01e A |
490 | ASSERT (Buffer != NULL);\r |
491 | ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r | |
492 | \r | |
493 | Memory = UncachedInternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r | |
494 | if (Memory != NULL) {\r | |
495 | Memory = CopyMem (Memory, Buffer, AllocationSize);\r | |
496 | }\r | |
497 | return Memory;\r | |
498 | }\r | |
499 | \r | |
500 | VOID *\r | |
501 | EFIAPI\r | |
502 | UncachedAllocateAlignedCopyPool (\r | |
503 | IN UINTN AllocationSize,\r | |
504 | IN CONST VOID *Buffer,\r | |
505 | IN UINTN Alignment\r | |
506 | )\r | |
507 | {\r | |
508 | return UncachedInternalAllocateAlignedCopyPool (EfiBootServicesData, AllocationSize, Buffer, Alignment);\r | |
509 | }\r | |
510 | \r | |
511 | VOID *\r | |
512 | EFIAPI\r | |
513 | UncachedAllocateAlignedRuntimeCopyPool (\r | |
514 | IN UINTN AllocationSize,\r | |
515 | IN CONST VOID *Buffer,\r | |
516 | IN UINTN Alignment\r | |
517 | )\r | |
518 | {\r | |
519 | return UncachedInternalAllocateAlignedCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer, Alignment);\r | |
520 | }\r | |
521 | \r | |
522 | VOID *\r | |
523 | EFIAPI\r | |
524 | UncachedAllocateAlignedReservedCopyPool (\r | |
525 | IN UINTN AllocationSize,\r | |
526 | IN CONST VOID *Buffer,\r | |
527 | IN UINTN Alignment\r | |
528 | )\r | |
529 | {\r | |
530 | return UncachedInternalAllocateAlignedCopyPool (EfiReservedMemoryType, AllocationSize, Buffer, Alignment);\r | |
531 | }\r | |
532 | \r | |
533 | VOID\r | |
534 | EFIAPI\r | |
535 | UncachedFreeAlignedPool (\r | |
883b666e | 536 | IN VOID *Allocation\r |
2ef2b01e A |
537 | )\r |
538 | {\r | |
1a70a690 | 539 | UncachedFreePages (Allocation, 0);\r |
2ef2b01e A |
540 | }\r |
541 | \r | |
542 | VOID *\r | |
543 | UncachedInternalAllocatePool (\r | |
3402aac7 | 544 | IN EFI_MEMORY_TYPE MemoryType,\r |
2ef2b01e A |
545 | IN UINTN AllocationSize\r |
546 | )\r | |
547 | {\r | |
25549bda | 548 | UINTN CacheLineLength = ArmCacheWritebackGranule ();\r |
883b666e | 549 | return UncachedInternalAllocateAlignedPool (MemoryType, AllocationSize, CacheLineLength);\r |
2ef2b01e A |
550 | }\r |
551 | \r | |
552 | VOID *\r | |
553 | EFIAPI\r | |
554 | UncachedAllocatePool (\r | |
555 | IN UINTN AllocationSize\r | |
556 | )\r | |
557 | {\r | |
558 | return UncachedInternalAllocatePool (EfiBootServicesData, AllocationSize);\r | |
559 | }\r | |
560 | \r | |
561 | VOID *\r | |
562 | EFIAPI\r | |
563 | UncachedAllocateRuntimePool (\r | |
564 | IN UINTN AllocationSize\r | |
565 | )\r | |
566 | {\r | |
567 | return UncachedInternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r | |
568 | }\r | |
569 | \r | |
570 | VOID *\r | |
571 | EFIAPI\r | |
572 | UncachedAllocateReservedPool (\r | |
573 | IN UINTN AllocationSize\r | |
574 | )\r | |
575 | {\r | |
576 | return UncachedInternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r | |
577 | }\r | |
578 | \r | |
579 | VOID *\r | |
580 | UncachedInternalAllocateZeroPool (\r | |
3402aac7 | 581 | IN EFI_MEMORY_TYPE PoolType,\r |
2ef2b01e | 582 | IN UINTN AllocationSize\r |
3402aac7 | 583 | )\r |
2ef2b01e A |
584 | {\r |
585 | VOID *Memory;\r | |
586 | \r | |
587 | Memory = UncachedInternalAllocatePool (PoolType, AllocationSize);\r | |
588 | if (Memory != NULL) {\r | |
589 | Memory = ZeroMem (Memory, AllocationSize);\r | |
590 | }\r | |
591 | return Memory;\r | |
592 | }\r | |
593 | \r | |
594 | VOID *\r | |
595 | EFIAPI\r | |
596 | UncachedAllocateZeroPool (\r | |
597 | IN UINTN AllocationSize\r | |
598 | )\r | |
599 | {\r | |
600 | return UncachedInternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r | |
601 | }\r | |
602 | \r | |
603 | VOID *\r | |
604 | EFIAPI\r | |
605 | UncachedAllocateRuntimeZeroPool (\r | |
606 | IN UINTN AllocationSize\r | |
607 | )\r | |
608 | {\r | |
609 | return UncachedInternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r | |
610 | }\r | |
611 | \r | |
612 | VOID *\r | |
613 | EFIAPI\r | |
614 | UncachedAllocateReservedZeroPool (\r | |
615 | IN UINTN AllocationSize\r | |
616 | )\r | |
617 | {\r | |
618 | return UncachedInternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r | |
619 | }\r | |
620 | \r | |
621 | VOID *\r | |
622 | UncachedInternalAllocateCopyPool (\r | |
3402aac7 | 623 | IN EFI_MEMORY_TYPE PoolType,\r |
2ef2b01e A |
624 | IN UINTN AllocationSize,\r |
625 | IN CONST VOID *Buffer\r | |
3402aac7 | 626 | )\r |
2ef2b01e A |
627 | {\r |
628 | VOID *Memory;\r | |
629 | \r | |
630 | ASSERT (Buffer != NULL);\r | |
631 | ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r | |
632 | \r | |
633 | Memory = UncachedInternalAllocatePool (PoolType, AllocationSize);\r | |
634 | if (Memory != NULL) {\r | |
635 | Memory = CopyMem (Memory, Buffer, AllocationSize);\r | |
636 | }\r | |
637 | return Memory;\r | |
3402aac7 | 638 | }\r |
2ef2b01e A |
639 | \r |
640 | VOID *\r | |
641 | EFIAPI\r | |
642 | UncachedAllocateCopyPool (\r | |
643 | IN UINTN AllocationSize,\r | |
644 | IN CONST VOID *Buffer\r | |
645 | )\r | |
646 | {\r | |
647 | return UncachedInternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);\r | |
648 | }\r | |
649 | \r | |
650 | VOID *\r | |
651 | EFIAPI\r | |
652 | UncachedAllocateRuntimeCopyPool (\r | |
653 | IN UINTN AllocationSize,\r | |
654 | IN CONST VOID *Buffer\r | |
655 | )\r | |
656 | {\r | |
657 | return UncachedInternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r | |
658 | }\r | |
659 | \r | |
660 | VOID *\r | |
661 | EFIAPI\r | |
662 | UncachedAllocateReservedCopyPool (\r | |
663 | IN UINTN AllocationSize,\r | |
664 | IN CONST VOID *Buffer\r | |
665 | )\r | |
666 | {\r | |
667 | return UncachedInternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r | |
668 | }\r | |
669 | \r | |
670 | VOID\r | |
671 | EFIAPI\r | |
672 | UncachedFreePool (\r | |
673 | IN VOID *Buffer\r | |
674 | )\r | |
675 | {\r | |
883b666e | 676 | UncachedFreeAlignedPool (Buffer);\r |
2ef2b01e A |
677 | }\r |
678 | \r | |
679 | VOID\r | |
680 | EFIAPI\r | |
681 | UncachedSafeFreePool (\r | |
682 | IN VOID *Buffer\r | |
683 | )\r | |
684 | {\r | |
685 | if (Buffer != NULL) {\r | |
686 | UncachedFreePool (Buffer);\r | |
687 | Buffer = NULL;\r | |
688 | }\r | |
689 | }\r | |
690 | \r |