2 Support routines for memory allocation routines for use with drivers.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/PeiServicesTablePointerLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/DebugLib.h>
24 #include "MemoryAllocationLibInternals.h"
27 Allocates one or more 4KB pages of a certain memory type.
29 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
30 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
31 If there is not enough memory remaining to satisfy the request, then NULL is returned.
33 @param MemoryType The type of memory to allocate.
34 @param Pages The number of 4 KB pages to allocate.
36 @return A pointer to the allocated buffer or NULL if allocation fails.
40 InternalAllocatePages (
41 IN EFI_MEMORY_TYPE MemoryType
,
46 EFI_PHYSICAL_ADDRESS Memory
;
47 EFI_PEI_SERVICES
**PeiServices
;
53 PeiServices
= GetPeiServicesTablePointer ();
54 Status
= (*PeiServices
)->AllocatePages (PeiServices
, MemoryType
, Pages
, &Memory
);
55 if (EFI_ERROR (Status
)) {
58 return (VOID
*) (UINTN
) Memory
;
62 Allocates one or more 4KB pages of type EfiBootServicesData.
64 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
65 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
66 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
69 @param Pages The number of 4 KB pages to allocate.
71 @return A pointer to the allocated buffer or NULL if allocation fails.
80 return InternalAllocatePages (EfiBootServicesData
, Pages
);
84 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
86 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
87 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
88 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
91 @param Pages The number of 4 KB pages to allocate.
93 @return A pointer to the allocated buffer or NULL if allocation fails.
98 AllocateRuntimePages (
102 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
106 Allocates one or more 4KB pages of type EfiReservedMemoryType.
108 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
109 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
110 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
113 @param Pages The number of 4 KB pages to allocate.
115 @return A pointer to the allocated buffer or NULL if allocation fails.
120 AllocateReservedPages (
124 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
128 Frees one or more 4KB pages that were previously allocated with one of the page allocation
129 functions in the Memory Allocation Library.
131 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
132 must have been allocated on a previous call to the page allocation services of the Memory
134 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
136 If Pages is zero, then ASSERT().
138 @param Buffer Pointer to the buffer of pages to free.
139 @param Pages The number of 4 KB pages to free.
150 // PEI phase does not support to free pages, so leave it as NOP.
155 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
157 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
158 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
159 If there is not enough memory at the specified alignment remaining to satisfy the request, then
161 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
163 @param MemoryType The type of memory to allocate.
164 @param Pages The number of 4 KB pages to allocate.
165 @param Alignment The requested alignment of the allocation. Must be a power of two.
166 If Alignment is zero, then byte alignment is used.
168 @return A pointer to the allocated buffer or NULL if allocation fails.
172 InternalAllocateAlignedPages (
173 IN EFI_MEMORY_TYPE MemoryType
,
182 // Alignment must be a power of two or zero.
184 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
190 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
192 ASSERT (Pages
<= (MAX_ADDRESS
- EFI_SIZE_TO_PAGES (Alignment
)));
194 // We would rather waste some memory to save PEI code size.
196 Memory
= InternalAllocatePages (MemoryType
, Pages
+ EFI_SIZE_TO_PAGES (Alignment
));
197 if (Alignment
== 0) {
198 AlignmentMask
= Alignment
;
200 AlignmentMask
= Alignment
- 1;
202 return (VOID
*) (UINTN
) (((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
);
206 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
208 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
209 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
210 returned. If there is not enough memory at the specified alignment remaining to satisfy the
211 request, then NULL is returned.
212 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
214 @param Pages The number of 4 KB pages to allocate.
215 @param Alignment The requested alignment of the allocation. Must be a power of two.
216 If Alignment is zero, then byte alignment is used.
218 @return A pointer to the allocated buffer or NULL if allocation fails.
223 AllocateAlignedPages (
228 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
232 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
234 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
235 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
236 returned. If there is not enough memory at the specified alignment remaining to satisfy the
237 request, then NULL is returned.
238 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
240 @param Pages The number of 4 KB pages to allocate.
241 @param Alignment The requested alignment of the allocation. Must be a power of two.
242 If Alignment is zero, then byte alignment is used.
244 @return A pointer to the allocated buffer or NULL if allocation fails.
249 AllocateAlignedRuntimePages (
254 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
258 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
260 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
261 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
262 returned. If there is not enough memory at the specified alignment remaining to satisfy the
263 request, then NULL is returned.
264 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
266 @param Pages The number of 4 KB pages to allocate.
267 @param Alignment The requested alignment of the allocation. Must be a power of two.
268 If Alignment is zero, then byte alignment is used.
270 @return A pointer to the allocated buffer or NULL if allocation fails.
275 AllocateAlignedReservedPages (
280 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
284 Frees one or more 4KB pages that were previously allocated with one of the aligned page
285 allocation functions in the Memory Allocation Library.
287 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
288 must have been allocated on a previous call to the aligned page allocation services of the Memory
290 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
291 Library, then ASSERT().
292 If Pages is zero, then ASSERT().
294 @param Buffer Pointer to the buffer of pages to free.
295 @param Pages The number of 4 KB pages to free.
306 // PEI phase does not support to free pages, so leave it as NOP.
311 Allocates a buffer of a certain pool type.
313 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
314 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
315 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
317 @param MemoryType The type of memory to allocate.
318 @param AllocationSize The number of bytes to allocate.
320 @return A pointer to the allocated buffer or NULL if allocation fails.
324 InternalAllocatePool (
325 IN EFI_MEMORY_TYPE MemoryType
,
326 IN UINTN AllocationSize
330 // If we need lots of small runtime/reserved memory type from PEI in the future,
331 // we can consider providing a more complex algorithm that allocates runtime pages and
332 // provide pool allocations from those pages.
334 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
338 Allocates a buffer of type EfiBootServicesData.
340 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
341 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
342 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
344 @param AllocationSize The number of bytes to allocate.
346 @return A pointer to the allocated buffer or NULL if allocation fails.
352 IN UINTN AllocationSize
356 EFI_PEI_SERVICES
**PeiServices
;
359 PeiServices
= GetPeiServicesTablePointer ();
361 Status
= (*PeiServices
)->AllocatePool (PeiServices
, AllocationSize
, &Buffer
);
362 if (EFI_ERROR (Status
)) {
369 Allocates a buffer of type EfiRuntimeServicesData.
371 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
372 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
373 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
375 @param AllocationSize The number of bytes to allocate.
377 @return A pointer to the allocated buffer or NULL if allocation fails.
382 AllocateRuntimePool (
383 IN UINTN AllocationSize
386 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
390 Allocates a buffer of type EfieservedMemoryType.
392 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
393 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
394 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
396 @param AllocationSize The number of bytes to allocate.
398 @return A pointer to the allocated buffer or NULL if allocation fails.
403 AllocateReservedPool (
404 IN UINTN AllocationSize
407 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
411 Allocates and zeros a buffer of a certian pool type.
413 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer
414 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
415 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
416 then NULL is returned.
418 @param PoolType The type of memory to allocate.
419 @param AllocationSize The number of bytes to allocate and zero.
421 @return A pointer to the allocated buffer or NULL if allocation fails.
425 InternalAllocateZeroPool (
426 IN EFI_MEMORY_TYPE PoolType
,
427 IN UINTN AllocationSize
432 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
433 if (Memory
!= NULL
) {
434 Memory
= ZeroMem (Memory
, AllocationSize
);
440 Allocates and zeros a buffer of type EfiBootServicesData.
442 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
443 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
444 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
445 request, then NULL is returned.
447 @param AllocationSize The number of bytes to allocate and zero.
449 @return A pointer to the allocated buffer or NULL if allocation fails.
455 IN UINTN AllocationSize
460 Memory
= AllocatePool (AllocationSize
);
461 if (Memory
!= NULL
) {
462 Memory
= ZeroMem (Memory
, AllocationSize
);
468 Allocates and zeros a buffer of type EfiRuntimeServicesData.
470 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
471 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
472 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
473 request, then NULL is returned.
475 @param AllocationSize The number of bytes to allocate and zero.
477 @return A pointer to the allocated buffer or NULL if allocation fails.
482 AllocateRuntimeZeroPool (
483 IN UINTN AllocationSize
486 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
490 Allocates and zeros a buffer of type EfiReservedMemoryType.
492 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
493 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
494 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
495 request, then NULL is returned.
497 @param AllocationSize The number of bytes to allocate and zero.
499 @return A pointer to the allocated buffer or NULL if allocation fails.
504 AllocateReservedZeroPool (
505 IN UINTN AllocationSize
508 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
512 Copies a buffer to an allocated buffer of a certian pool type.
514 Allocates the number bytes specified by AllocationSize of a certian pool type, copies
515 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
516 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
517 is not enough memory remaining to satisfy the request, then NULL is returned.
518 If Buffer is NULL, then ASSERT().
519 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
521 @param PoolType The type of pool to allocate.
522 @param AllocationSize The number of bytes to allocate and zero.
523 @param Buffer The buffer to copy to the allocated buffer.
525 @return A pointer to the allocated buffer or NULL if allocation fails.
529 InternalAllocateCopyPool (
530 IN EFI_MEMORY_TYPE PoolType
,
531 IN UINTN AllocationSize
,
532 IN CONST VOID
*Buffer
537 ASSERT (Buffer
!= NULL
);
538 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
540 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
541 if (Memory
!= NULL
) {
542 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
548 Copies a buffer to an allocated buffer of type EfiBootServicesData.
550 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
551 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
552 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
553 is not enough memory remaining to satisfy the request, then NULL is returned.
554 If Buffer is NULL, then ASSERT().
555 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
557 @param AllocationSize The number of bytes to allocate and zero.
558 @param Buffer The buffer to copy to the allocated buffer.
560 @return A pointer to the allocated buffer or NULL if allocation fails.
566 IN UINTN AllocationSize
,
567 IN CONST VOID
*Buffer
572 ASSERT (Buffer
!= NULL
);
573 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
575 Memory
= AllocatePool (AllocationSize
);
576 if (Memory
!= NULL
) {
577 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
583 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
585 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
586 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
587 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
588 is not enough memory remaining to satisfy the request, then NULL is returned.
589 If Buffer is NULL, then ASSERT().
590 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
592 @param AllocationSize The number of bytes to allocate and zero.
593 @param Buffer The buffer to copy to the allocated buffer.
595 @return A pointer to the allocated buffer or NULL if allocation fails.
600 AllocateRuntimeCopyPool (
601 IN UINTN AllocationSize
,
602 IN CONST VOID
*Buffer
605 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
609 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
611 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
612 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
613 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
614 is not enough memory remaining to satisfy the request, then NULL is returned.
615 If Buffer is NULL, then ASSERT().
616 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
618 @param AllocationSize The number of bytes to allocate and zero.
619 @param Buffer The buffer to copy to the allocated buffer.
621 @return A pointer to the allocated buffer or NULL if allocation fails.
626 AllocateReservedCopyPool (
627 IN UINTN AllocationSize
,
628 IN CONST VOID
*Buffer
631 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
635 Frees a buffer that was previously allocated with one of the pool allocation functions in the
636 Memory Allocation Library.
638 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
639 pool allocation services of the Memory Allocation Library.
640 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
643 @param Buffer Pointer to the buffer to free.
653 // PEI phase does not support to free pool, so leave it as NOP.
658 Allocates a buffer of a certain pool type at a specified alignment.
660 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
661 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
662 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
663 to satisfy the request, then NULL is returned.
664 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
666 @param PoolType The type of pool to allocate.
667 @param AllocationSize The number of bytes to allocate.
668 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.
669 If Alignment is zero, then byte alignment is used.
671 @return A pointer to the allocated buffer or NULL if allocation fails.
675 InternalAllocateAlignedPool (
676 IN EFI_MEMORY_TYPE PoolType
,
677 IN UINTN AllocationSize
,
682 UINTN AlignedAddress
;
686 // Alignment must be a power of two or zero.
688 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
690 if (Alignment
== 0) {
691 AlignmentMask
= Alignment
;
693 AlignmentMask
= Alignment
- 1;
696 // Make sure that AllocationSize plus AlignmentMask does not overflow.
698 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
700 RawAddress
= InternalAllocatePool (PoolType
, AllocationSize
+ AlignmentMask
);
702 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
704 return (VOID
*) AlignedAddress
;
708 Allocates a buffer of type EfiBootServicesData at a specified alignment.
710 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
711 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
712 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
713 alignment remaining to satisfy the request, then NULL is returned.
714 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
716 @param AllocationSize The number of bytes to allocate.
717 @param Alignment The requested alignment of the allocation. Must be a power of two.
718 If Alignment is zero, then byte alignment is used.
720 @return A pointer to the allocated buffer or NULL if allocation fails.
725 AllocateAlignedPool (
726 IN UINTN AllocationSize
,
731 UINTN AlignedAddress
;
735 // Alignment must be a power of two or zero.
737 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
739 if (Alignment
== 0) {
740 AlignmentMask
= Alignment
;
742 AlignmentMask
= Alignment
- 1;
746 // Make sure that AllocationSize plus AlignmentMask does not overflow.
748 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
750 RawAddress
= AllocatePool (AllocationSize
+ AlignmentMask
);
752 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
754 return (VOID
*) AlignedAddress
;
758 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
760 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
761 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
762 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
763 alignment remaining to satisfy the request, then NULL is returned.
764 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
766 @param AllocationSize The number of bytes to allocate.
767 @param Alignment The requested alignment of the allocation. Must be a power of two.
768 If Alignment is zero, then byte alignment is used.
770 @return A pointer to the allocated buffer or NULL if allocation fails.
775 AllocateAlignedRuntimePool (
776 IN UINTN AllocationSize
,
780 return InternalAllocateAlignedPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
784 Allocates a buffer of type EfieservedMemoryType at a specified alignment.
786 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
787 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
788 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
789 alignment remaining to satisfy the request, then NULL is returned.
790 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
792 @param AllocationSize The number of bytes to allocate.
793 @param Alignment The requested alignment of the allocation. Must be a power of two.
794 If Alignment is zero, then byte alignment is used.
796 @return A pointer to the allocated buffer or NULL if allocation fails.
801 AllocateAlignedReservedPool (
802 IN UINTN AllocationSize
,
806 return InternalAllocateAlignedPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
810 Allocates and zeros a buffer of a certain pool type at a specified alignment.
812 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
813 specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated
814 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not
815 enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.
816 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
818 @param PoolType The type of pool to allocate.
819 @param AllocationSize The number of bytes to allocate.
820 @param Alignment The requested alignment of the allocation. Must be a power of two.
821 If Alignment is zero, then byte alignment is used.
823 @return A pointer to the allocated buffer or NULL if allocation fails.
827 InternalAllocateAlignedZeroPool (
828 IN EFI_MEMORY_TYPE PoolType
,
829 IN UINTN AllocationSize
,
835 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
836 if (Memory
!= NULL
) {
837 Memory
= ZeroMem (Memory
, AllocationSize
);
843 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
845 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
846 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
847 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
848 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
850 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
852 @param AllocationSize The number of bytes to allocate.
853 @param Alignment The requested alignment of the allocation. Must be a power of two.
854 If Alignment is zero, then byte alignment is used.
856 @return A pointer to the allocated buffer or NULL if allocation fails.
861 AllocateAlignedZeroPool (
862 IN UINTN AllocationSize
,
868 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
869 if (Memory
!= NULL
) {
870 Memory
= ZeroMem (Memory
, AllocationSize
);
876 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
878 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
879 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
880 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
881 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
883 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
885 @param AllocationSize The number of bytes to allocate.
886 @param Alignment The requested alignment of the allocation. Must be a power of two.
887 If Alignment is zero, then byte alignment is used.
889 @return A pointer to the allocated buffer or NULL if allocation fails.
894 AllocateAlignedRuntimeZeroPool (
895 IN UINTN AllocationSize
,
899 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
903 Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
905 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
906 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
907 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
908 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
910 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
912 @param AllocationSize The number of bytes to allocate.
913 @param Alignment The requested alignment of the allocation. Must be a power of two.
914 If Alignment is zero, then byte alignment is used.
916 @return A pointer to the allocated buffer or NULL if allocation fails.
921 AllocateAlignedReservedZeroPool (
922 IN UINTN AllocationSize
,
926 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
930 Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.
932 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
933 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
934 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
935 to satisfy the request, then NULL is returned.
936 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
938 @param PoolType The type of pool to allocate.
939 @param AllocationSize The number of bytes to allocate.
940 @param Buffer The buffer to copy to the allocated buffer.
941 @param Alignment The requested alignment of the allocation. Must be a power of two.
942 If Alignment is zero, then byte alignment is used.
944 @return A pointer to the allocated buffer or NULL if allocation fails.
948 InternalAllocateAlignedCopyPool (
949 IN EFI_MEMORY_TYPE PoolType
,
950 IN UINTN AllocationSize
,
951 IN CONST VOID
*Buffer
,
957 ASSERT (Buffer
!= NULL
);
958 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
960 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
961 if (Memory
!= NULL
) {
962 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
968 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
970 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
971 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
972 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
973 alignment remaining to satisfy the request, then NULL is returned.
974 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
976 @param AllocationSize The number of bytes to allocate.
977 @param Buffer The buffer to copy to the allocated buffer.
978 @param Alignment The requested alignment of the allocation. Must be a power of two.
979 If Alignment is zero, then byte alignment is used.
981 @return A pointer to the allocated buffer or NULL if allocation fails.
986 AllocateAlignedCopyPool (
987 IN UINTN AllocationSize
,
988 IN CONST VOID
*Buffer
,
994 ASSERT (Buffer
!= NULL
);
995 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
997 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
998 if (Memory
!= NULL
) {
999 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
1005 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
1007 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
1008 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1009 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1010 alignment remaining to satisfy the request, then NULL is returned.
1011 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1013 @param AllocationSize The number of bytes to allocate.
1014 @param Buffer The buffer to copy to the allocated buffer.
1015 @param Alignment The requested alignment of the allocation. Must be a power of two.
1016 If Alignment is zero, then byte alignment is used.
1018 @return A pointer to the allocated buffer or NULL if allocation fails.
1023 AllocateAlignedRuntimeCopyPool (
1024 IN UINTN AllocationSize
,
1025 IN CONST VOID
*Buffer
,
1029 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
, Alignment
);
1033 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
1035 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
1036 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1037 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1038 alignment remaining to satisfy the request, then NULL is returned.
1039 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1041 @param AllocationSize The number of bytes to allocate.
1042 @param Buffer The buffer to copy to the allocated buffer.
1043 @param Alignment The requested alignment of the allocation. Must be a power of two.
1044 If Alignment is zero, then byte alignment is used.
1046 @return A pointer to the allocated buffer or NULL if allocation fails.
1051 AllocateAlignedReservedCopyPool (
1052 IN UINTN AllocationSize
,
1053 IN CONST VOID
*Buffer
,
1057 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
, Alignment
);
1061 Frees a buffer that was previously allocated with one of the aligned pool allocation functions
1062 in the Memory Allocation Library.
1064 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
1065 aligned pool allocation services of the Memory Allocation Library.
1066 If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
1067 Library, then ASSERT().
1069 @param Buffer Pointer to the buffer to free.
1079 // PEI phase does not support to free pool, so leave it as NOP.