]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
ArmPkg/UncachedMemoryAllocationLib: use CWG value to align pool allocations
[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 45typedef 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
55STATIC LIST_ENTRY mPageList = INITIALIZE_LIST_HEAD_VARIABLE (mPageList);\r
56// Track the size of the non-allocated buffer in the linked-list\r
57STATIC 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
73STATIC\r
74EFI_STATUS\r
75AllocatePagesFromList (\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
198STATIC\r
199EFI_STATUS\r
200FreePagesFromList (\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
238EFI_STATUS\r
239EFIAPI\r
240UncachedMemoryAllocationLibDestructor (\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
283EFI_PHYSICAL_ADDRESS\r
284ConvertToPhysicalAddress (\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
292VOID *\r
293UncachedInternalAllocatePages (\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
302VOID *\r
303EFIAPI\r
304UncachedAllocatePages (\r
305 IN UINTN Pages\r
306 )\r
307{\r
308 return UncachedInternalAllocatePages (EfiBootServicesData, Pages);\r
309}\r
310\r
311VOID *\r
312EFIAPI\r
313UncachedAllocateRuntimePages (\r
314 IN UINTN Pages\r
315 )\r
316{\r
317 return UncachedInternalAllocatePages (EfiRuntimeServicesData, Pages);\r
318}\r
319\r
320VOID *\r
321EFIAPI\r
322UncachedAllocateReservedPages (\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
331VOID\r
332EFIAPI\r
333UncachedFreePages (\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
343VOID *\r
344UncachedInternalAllocateAlignedPages (\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
368VOID\r
369EFIAPI\r
370UncachedFreeAlignedPages (\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
379VOID *\r
380UncachedInternalAllocateAlignedPool (\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
405VOID *\r
406EFIAPI\r
407UncachedAllocateAlignedPool (\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
415VOID *\r
416EFIAPI\r
417UncachedAllocateAlignedRuntimePool (\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
425VOID *\r
426EFIAPI\r
427UncachedAllocateAlignedReservedPool (\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
435VOID *\r
436UncachedInternalAllocateAlignedZeroPool (\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
450VOID *\r
451EFIAPI\r
452UncachedAllocateAlignedZeroPool (\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
460VOID *\r
461EFIAPI\r
462UncachedAllocateAlignedRuntimeZeroPool (\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
470VOID *\r
471EFIAPI\r
472UncachedAllocateAlignedReservedZeroPool (\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
480VOID *\r
481UncachedInternalAllocateAlignedCopyPool (\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
500VOID *\r
501EFIAPI\r
502UncachedAllocateAlignedCopyPool (\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
511VOID *\r
512EFIAPI\r
513UncachedAllocateAlignedRuntimeCopyPool (\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
522VOID *\r
523EFIAPI\r
524UncachedAllocateAlignedReservedCopyPool (\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
533VOID\r
534EFIAPI\r
535UncachedFreeAlignedPool (\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
542VOID *\r
543UncachedInternalAllocatePool (\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
552VOID *\r
553EFIAPI\r
554UncachedAllocatePool (\r
555 IN UINTN AllocationSize\r
556 )\r
557{\r
558 return UncachedInternalAllocatePool (EfiBootServicesData, AllocationSize);\r
559}\r
560\r
561VOID *\r
562EFIAPI\r
563UncachedAllocateRuntimePool (\r
564 IN UINTN AllocationSize\r
565 )\r
566{\r
567 return UncachedInternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
568}\r
569\r
570VOID *\r
571EFIAPI\r
572UncachedAllocateReservedPool (\r
573 IN UINTN AllocationSize\r
574 )\r
575{\r
576 return UncachedInternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
577}\r
578\r
579VOID *\r
580UncachedInternalAllocateZeroPool (\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
594VOID *\r
595EFIAPI\r
596UncachedAllocateZeroPool (\r
597 IN UINTN AllocationSize\r
598 )\r
599{\r
600 return UncachedInternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r
601}\r
602\r
603VOID *\r
604EFIAPI\r
605UncachedAllocateRuntimeZeroPool (\r
606 IN UINTN AllocationSize\r
607 )\r
608{\r
609 return UncachedInternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
610}\r
611\r
612VOID *\r
613EFIAPI\r
614UncachedAllocateReservedZeroPool (\r
615 IN UINTN AllocationSize\r
616 )\r
617{\r
618 return UncachedInternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
619}\r
620\r
621VOID *\r
622UncachedInternalAllocateCopyPool (\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
640VOID *\r
641EFIAPI\r
642UncachedAllocateCopyPool (\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
650VOID *\r
651EFIAPI\r
652UncachedAllocateRuntimeCopyPool (\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
660VOID *\r
661EFIAPI\r
662UncachedAllocateReservedCopyPool (\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
670VOID\r
671EFIAPI\r
672UncachedFreePool (\r
673 IN VOID *Buffer\r
674 )\r
675{\r
883b666e 676 UncachedFreeAlignedPool (Buffer);\r
2ef2b01e
A
677}\r
678\r
679VOID\r
680EFIAPI\r
681UncachedSafeFreePool (\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