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