]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
ArmPkg/UncachedMemoryAllocationLib: map uncached allocations non-executable
[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
e7b24ec9
AB
157 Status = gDS->SetMemorySpaceAttributes (Memory, EFI_PAGES_TO_SIZE (Pages),\r
158 EFI_MEMORY_WC | EFI_MEMORY_XP);\r
1a70a690
OM
159 if (EFI_ERROR (Status)) {\r
160 gBS->FreePages (Memory, Pages);\r
161 return Status;\r
162 }\r
163\r
e266db59
HG
164 InvalidateDataCacheRange ((VOID *)(UINTN)Memory, EFI_PAGES_TO_SIZE (Pages));\r
165\r
1a70a690 166 NewNode = AllocatePool (sizeof (FREE_PAGE_NODE));\r
883b666e 167 if (NewNode == NULL) {\r
168 ASSERT (FALSE);\r
1a70a690
OM
169 gBS->FreePages (Memory, Pages);\r
170 return EFI_OUT_OF_RESOURCES;\r
883b666e 171 }\r
3402aac7 172\r
1a70a690
OM
173 NewNode->Base = Memory;\r
174 NewNode->Allocation = (VOID*)(((UINTN)Memory + AlignmentMask) & ~AlignmentMask);\r
883b666e 175 NewNode->Pages = Pages;\r
1a70a690
OM
176 NewNode->Allocated = TRUE;\r
177 NewNode->MemoryType = MemoryType;\r
bb52ec2d 178 NewNode->Attributes = Descriptor.Attributes;\r
3402aac7 179\r
883b666e 180 InsertTailList (&mPageList, &NewNode->Link);\r
1a70a690
OM
181\r
182 *Allocation = NewNode->Allocation;\r
183 return EFI_SUCCESS;\r
2ef2b01e
A
184}\r
185\r
1a70a690
OM
186/**\r
187 * Free the memory allocation\r
188 *\r
189 * This function will actually try to find the allocation in the linked list.\r
190 * And it will then mark the entry as freed.\r
191 *\r
192 * @param Allocation Base address of the buffer to free\r
193 *\r
194 * @return EFI_SUCCESS The allocation has been freed\r
195 * @return EFI_NOT_FOUND The allocation was not found in the pool.\r
196 * @return EFI_INVALID_PARAMETER If Allocation is NULL\r
197 *\r
198 */\r
199STATIC\r
200EFI_STATUS\r
201FreePagesFromList (\r
202 IN VOID *Allocation\r
203 )\r
204{\r
205 LIST_ENTRY *Link;\r
206 FREE_PAGE_NODE *Node;\r
207\r
208 if (Allocation == NULL) {\r
209 return EFI_INVALID_PARAMETER;\r
210 }\r
883b666e 211\r
1a70a690
OM
212 for (Link = mPageList.ForwardLink; Link != &mPageList; Link = Link->ForwardLink) {\r
213 Node = BASE_CR (Link, FREE_PAGE_NODE, Link);\r
214 if ((UINTN)Node->Allocation == (UINTN)Allocation) {\r
215 Node->Allocated = FALSE;\r
216\r
217 // Update the size of the freed buffer\r
218 mFreedBufferSize += Node->Pages * EFI_PAGE_SIZE;\r
219\r
220 // If the size of the non-allocated reaches the threshold we raise a warning.\r
221 // It might be an expected behaviour in some cases.\r
222 // We might device to free some of these buffers later on.\r
223 if (mFreedBufferSize > PcdGet64 (PcdArmFreeUncachedMemorySizeThreshold)) {\r
224 DEBUG ((EFI_D_WARN, "Warning: The list of non-allocated buffer has reach the threshold.\n"));\r
225 }\r
226 return EFI_SUCCESS;\r
227 }\r
228 }\r
229\r
230 return EFI_NOT_FOUND;\r
231}\r
232\r
233/**\r
234 * This function is automatically invoked when the driver exits\r
235 * It frees all the non-allocated memory buffer.\r
236 * This function is not responsible to free allocated buffer (eg: case of memory leak,\r
237 * runtime allocation).\r
238 */\r
239EFI_STATUS\r
240EFIAPI\r
241UncachedMemoryAllocationLibDestructor (\r
242 IN EFI_HANDLE ImageHandle,\r
243 IN EFI_SYSTEM_TABLE *SystemTable\r
2ef2b01e
A
244 )\r
245{\r
883b666e 246 LIST_ENTRY *Link;\r
247 FREE_PAGE_NODE *OldNode;\r
248\r
1a70a690
OM
249 // Test if the list is empty\r
250 Link = mPageList.ForwardLink;\r
251 if (Link == &mPageList) {\r
252 return EFI_SUCCESS;\r
253 }\r
3402aac7 254\r
1a70a690
OM
255 // Free all the pages and nodes\r
256 do {\r
883b666e 257 OldNode = BASE_CR (Link, FREE_PAGE_NODE, Link);\r
1a70a690
OM
258 // Point to the next entry\r
259 Link = Link->ForwardLink;\r
3402aac7 260\r
1a70a690
OM
261 // We only free the non-allocated buffer\r
262 if (OldNode->Allocated == FALSE) {\r
263 gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base, OldNode->Pages);\r
bb52ec2d
AB
264\r
265 gDS->SetMemorySpaceAttributes ((EFI_PHYSICAL_ADDRESS)(UINTN)OldNode->Base,\r
266 EFI_PAGES_TO_SIZE (OldNode->Pages), OldNode->Attributes);\r
267\r
883b666e 268 RemoveEntryList (&OldNode->Link);\r
269 FreePool (OldNode);\r
883b666e 270 }\r
1a70a690 271 } while (Link != &mPageList);\r
883b666e 272\r
1a70a690 273 return EFI_SUCCESS;\r
2ef2b01e
A
274}\r
275\r
883b666e 276/**\r
277 Converts a cached or uncached address to a physical address suitable for use in SoC registers.\r
278\r
279 @param VirtualAddress The pointer to convert.\r
280\r
281 @return The physical address of the supplied virtual pointer.\r
282\r
283**/\r
284EFI_PHYSICAL_ADDRESS\r
285ConvertToPhysicalAddress (\r
286 IN VOID *VirtualAddress\r
287 )\r
288{\r
289 return (EFI_PHYSICAL_ADDRESS)(UINTN)VirtualAddress;\r
290}\r
291\r
292\r
2ef2b01e
A
293VOID *\r
294UncachedInternalAllocatePages (\r
3402aac7 295 IN EFI_MEMORY_TYPE MemoryType,\r
2ef2b01e
A
296 IN UINTN Pages\r
297 )\r
298{\r
883b666e 299 return UncachedInternalAllocateAlignedPages (MemoryType, Pages, EFI_PAGE_SIZE);\r
2ef2b01e
A
300}\r
301\r
883b666e 302\r
2ef2b01e
A
303VOID *\r
304EFIAPI\r
305UncachedAllocatePages (\r
306 IN UINTN Pages\r
307 )\r
308{\r
309 return UncachedInternalAllocatePages (EfiBootServicesData, Pages);\r
310}\r
311\r
312VOID *\r
313EFIAPI\r
314UncachedAllocateRuntimePages (\r
315 IN UINTN Pages\r
316 )\r
317{\r
318 return UncachedInternalAllocatePages (EfiRuntimeServicesData, Pages);\r
319}\r
320\r
321VOID *\r
322EFIAPI\r
323UncachedAllocateReservedPages (\r
324 IN UINTN Pages\r
325 )\r
326{\r
327 return UncachedInternalAllocatePages (EfiReservedMemoryType, Pages);\r
328}\r
329\r
883b666e 330\r
331\r
2ef2b01e
A
332VOID\r
333EFIAPI\r
334UncachedFreePages (\r
335 IN VOID *Buffer,\r
336 IN UINTN Pages\r
337 )\r
338{\r
883b666e 339 UncachedFreeAlignedPages (Buffer, Pages);\r
340 return;\r
2ef2b01e
A
341}\r
342\r
883b666e 343\r
2ef2b01e
A
344VOID *\r
345UncachedInternalAllocateAlignedPages (\r
3402aac7 346 IN EFI_MEMORY_TYPE MemoryType,\r
2ef2b01e
A
347 IN UINTN Pages,\r
348 IN UINTN Alignment\r
349 )\r
350{\r
1a70a690
OM
351 EFI_STATUS Status;\r
352 VOID *Allocation;\r
3402aac7 353\r
2ef2b01e
A
354 if (Pages == 0) {\r
355 return NULL;\r
356 }\r
3402aac7 357\r
1a70a690
OM
358 Allocation = NULL;\r
359 Status = AllocatePagesFromList (MemoryType, Pages, Alignment, &Allocation);\r
360 if (EFI_ERROR (Status)) {\r
361 ASSERT_EFI_ERROR (Status);\r
362 return NULL;\r
363 } else {\r
364 return Allocation;\r
2ef2b01e 365 }\r
2ef2b01e
A
366}\r
367\r
2ef2b01e
A
368\r
369VOID\r
370EFIAPI\r
371UncachedFreeAlignedPages (\r
372 IN VOID *Buffer,\r
373 IN UINTN Pages\r
374 )\r
375{\r
1a70a690 376 FreePagesFromList (Buffer);\r
2ef2b01e
A
377}\r
378\r
883b666e 379\r
2ef2b01e
A
380VOID *\r
381UncachedInternalAllocateAlignedPool (\r
382 IN EFI_MEMORY_TYPE PoolType,\r
383 IN UINTN AllocationSize,\r
384 IN UINTN Alignment\r
385 )\r
386{\r
883b666e 387 VOID *AlignedAddress;\r
3402aac7 388\r
2ef2b01e
A
389 //\r
390 // Alignment must be a power of two or zero.\r
391 //\r
392 ASSERT ((Alignment & (Alignment - 1)) == 0);\r
393\r
883b666e 394 if (Alignment < EFI_PAGE_SIZE) {\r
395 Alignment = EFI_PAGE_SIZE;\r
2ef2b01e 396 }\r
3402aac7 397\r
883b666e 398 AlignedAddress = UncachedInternalAllocateAlignedPages (PoolType, EFI_SIZE_TO_PAGES (AllocationSize), Alignment);\r
399 if (AlignedAddress == NULL) {\r
2ef2b01e
A
400 return NULL;\r
401 }\r
402\r
2ef2b01e
A
403 return (VOID *) AlignedAddress;\r
404}\r
405\r
406VOID *\r
407EFIAPI\r
408UncachedAllocateAlignedPool (\r
409 IN UINTN AllocationSize,\r
410 IN UINTN Alignment\r
411 )\r
412{\r
413 return UncachedInternalAllocateAlignedPool (EfiBootServicesData, AllocationSize, Alignment);\r
414}\r
415\r
416VOID *\r
417EFIAPI\r
418UncachedAllocateAlignedRuntimePool (\r
419 IN UINTN AllocationSize,\r
420 IN UINTN Alignment\r
421 )\r
422{\r
423 return UncachedInternalAllocateAlignedPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
424}\r
425\r
426VOID *\r
427EFIAPI\r
428UncachedAllocateAlignedReservedPool (\r
429 IN UINTN AllocationSize,\r
430 IN UINTN Alignment\r
431 )\r
432{\r
433 return UncachedInternalAllocateAlignedPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
434}\r
435\r
436VOID *\r
437UncachedInternalAllocateAlignedZeroPool (\r
438 IN EFI_MEMORY_TYPE PoolType,\r
439 IN UINTN AllocationSize,\r
440 IN UINTN Alignment\r
441 )\r
442{\r
443 VOID *Memory;\r
444 Memory = UncachedInternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
445 if (Memory != NULL) {\r
446 Memory = ZeroMem (Memory, AllocationSize);\r
447 }\r
448 return Memory;\r
449}\r
450\r
451VOID *\r
452EFIAPI\r
453UncachedAllocateAlignedZeroPool (\r
454 IN UINTN AllocationSize,\r
455 IN UINTN Alignment\r
456 )\r
457{\r
458 return UncachedInternalAllocateAlignedZeroPool (EfiBootServicesData, AllocationSize, Alignment);\r
459}\r
460\r
461VOID *\r
462EFIAPI\r
463UncachedAllocateAlignedRuntimeZeroPool (\r
464 IN UINTN AllocationSize,\r
465 IN UINTN Alignment\r
466 )\r
467{\r
468 return UncachedInternalAllocateAlignedZeroPool (EfiRuntimeServicesData, AllocationSize, Alignment);\r
469}\r
470\r
471VOID *\r
472EFIAPI\r
473UncachedAllocateAlignedReservedZeroPool (\r
474 IN UINTN AllocationSize,\r
475 IN UINTN Alignment\r
476 )\r
477{\r
478 return UncachedInternalAllocateAlignedZeroPool (EfiReservedMemoryType, AllocationSize, Alignment);\r
479}\r
480\r
481VOID *\r
482UncachedInternalAllocateAlignedCopyPool (\r
483 IN EFI_MEMORY_TYPE PoolType,\r
484 IN UINTN AllocationSize,\r
485 IN CONST VOID *Buffer,\r
486 IN UINTN Alignment\r
487 )\r
488{\r
489 VOID *Memory;\r
3402aac7 490\r
2ef2b01e
A
491 ASSERT (Buffer != NULL);\r
492 ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
493\r
494 Memory = UncachedInternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);\r
495 if (Memory != NULL) {\r
496 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
497 }\r
498 return Memory;\r
499}\r
500\r
501VOID *\r
502EFIAPI\r
503UncachedAllocateAlignedCopyPool (\r
504 IN UINTN AllocationSize,\r
505 IN CONST VOID *Buffer,\r
506 IN UINTN Alignment\r
507 )\r
508{\r
509 return UncachedInternalAllocateAlignedCopyPool (EfiBootServicesData, AllocationSize, Buffer, Alignment);\r
510}\r
511\r
512VOID *\r
513EFIAPI\r
514UncachedAllocateAlignedRuntimeCopyPool (\r
515 IN UINTN AllocationSize,\r
516 IN CONST VOID *Buffer,\r
517 IN UINTN Alignment\r
518 )\r
519{\r
520 return UncachedInternalAllocateAlignedCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer, Alignment);\r
521}\r
522\r
523VOID *\r
524EFIAPI\r
525UncachedAllocateAlignedReservedCopyPool (\r
526 IN UINTN AllocationSize,\r
527 IN CONST VOID *Buffer,\r
528 IN UINTN Alignment\r
529 )\r
530{\r
531 return UncachedInternalAllocateAlignedCopyPool (EfiReservedMemoryType, AllocationSize, Buffer, Alignment);\r
532}\r
533\r
534VOID\r
535EFIAPI\r
536UncachedFreeAlignedPool (\r
883b666e 537 IN VOID *Allocation\r
2ef2b01e
A
538 )\r
539{\r
1a70a690 540 UncachedFreePages (Allocation, 0);\r
2ef2b01e
A
541}\r
542\r
543VOID *\r
544UncachedInternalAllocatePool (\r
3402aac7 545 IN EFI_MEMORY_TYPE MemoryType,\r
2ef2b01e
A
546 IN UINTN AllocationSize\r
547 )\r
548{\r
25549bda 549 UINTN CacheLineLength = ArmCacheWritebackGranule ();\r
883b666e 550 return UncachedInternalAllocateAlignedPool (MemoryType, AllocationSize, CacheLineLength);\r
2ef2b01e
A
551}\r
552\r
553VOID *\r
554EFIAPI\r
555UncachedAllocatePool (\r
556 IN UINTN AllocationSize\r
557 )\r
558{\r
559 return UncachedInternalAllocatePool (EfiBootServicesData, AllocationSize);\r
560}\r
561\r
562VOID *\r
563EFIAPI\r
564UncachedAllocateRuntimePool (\r
565 IN UINTN AllocationSize\r
566 )\r
567{\r
568 return UncachedInternalAllocatePool (EfiRuntimeServicesData, AllocationSize);\r
569}\r
570\r
571VOID *\r
572EFIAPI\r
573UncachedAllocateReservedPool (\r
574 IN UINTN AllocationSize\r
575 )\r
576{\r
577 return UncachedInternalAllocatePool (EfiReservedMemoryType, AllocationSize);\r
578}\r
579\r
580VOID *\r
581UncachedInternalAllocateZeroPool (\r
3402aac7 582 IN EFI_MEMORY_TYPE PoolType,\r
2ef2b01e 583 IN UINTN AllocationSize\r
3402aac7 584 )\r
2ef2b01e
A
585{\r
586 VOID *Memory;\r
587\r
588 Memory = UncachedInternalAllocatePool (PoolType, AllocationSize);\r
589 if (Memory != NULL) {\r
590 Memory = ZeroMem (Memory, AllocationSize);\r
591 }\r
592 return Memory;\r
593}\r
594\r
595VOID *\r
596EFIAPI\r
597UncachedAllocateZeroPool (\r
598 IN UINTN AllocationSize\r
599 )\r
600{\r
601 return UncachedInternalAllocateZeroPool (EfiBootServicesData, AllocationSize);\r
602}\r
603\r
604VOID *\r
605EFIAPI\r
606UncachedAllocateRuntimeZeroPool (\r
607 IN UINTN AllocationSize\r
608 )\r
609{\r
610 return UncachedInternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);\r
611}\r
612\r
613VOID *\r
614EFIAPI\r
615UncachedAllocateReservedZeroPool (\r
616 IN UINTN AllocationSize\r
617 )\r
618{\r
619 return UncachedInternalAllocateZeroPool (EfiReservedMemoryType, AllocationSize);\r
620}\r
621\r
622VOID *\r
623UncachedInternalAllocateCopyPool (\r
3402aac7 624 IN EFI_MEMORY_TYPE PoolType,\r
2ef2b01e
A
625 IN UINTN AllocationSize,\r
626 IN CONST VOID *Buffer\r
3402aac7 627 )\r
2ef2b01e
A
628{\r
629 VOID *Memory;\r
630\r
631 ASSERT (Buffer != NULL);\r
632 ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));\r
633\r
634 Memory = UncachedInternalAllocatePool (PoolType, AllocationSize);\r
635 if (Memory != NULL) {\r
636 Memory = CopyMem (Memory, Buffer, AllocationSize);\r
637 }\r
638 return Memory;\r
3402aac7 639}\r
2ef2b01e
A
640\r
641VOID *\r
642EFIAPI\r
643UncachedAllocateCopyPool (\r
644 IN UINTN AllocationSize,\r
645 IN CONST VOID *Buffer\r
646 )\r
647{\r
648 return UncachedInternalAllocateCopyPool (EfiBootServicesData, AllocationSize, Buffer);\r
649}\r
650\r
651VOID *\r
652EFIAPI\r
653UncachedAllocateRuntimeCopyPool (\r
654 IN UINTN AllocationSize,\r
655 IN CONST VOID *Buffer\r
656 )\r
657{\r
658 return UncachedInternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);\r
659}\r
660\r
661VOID *\r
662EFIAPI\r
663UncachedAllocateReservedCopyPool (\r
664 IN UINTN AllocationSize,\r
665 IN CONST VOID *Buffer\r
666 )\r
667{\r
668 return UncachedInternalAllocateCopyPool (EfiReservedMemoryType, AllocationSize, Buffer);\r
669}\r
670\r
671VOID\r
672EFIAPI\r
673UncachedFreePool (\r
674 IN VOID *Buffer\r
675 )\r
676{\r
883b666e 677 UncachedFreeAlignedPool (Buffer);\r
2ef2b01e
A
678}\r
679\r
680VOID\r
681EFIAPI\r
682UncachedSafeFreePool (\r
683 IN VOID *Buffer\r
684 )\r
685{\r
686 if (Buffer != NULL) {\r
687 UncachedFreePool (Buffer);\r
688 Buffer = NULL;\r
689 }\r
690}\r
691\r