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