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/PeiServicesLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/DebugLib.h>
25 #include "MemoryAllocationLibInternals.h"
28 Allocates one or more 4KB pages of a certain memory type.
30 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
31 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
32 If there is not enough memory remaining to satisfy the request, then NULL is returned.
34 @param MemoryType The type of memory to allocate.
35 @param Pages The number of 4 KB pages to allocate.
37 @return A pointer to the allocated buffer or NULL if allocation fails.
41 InternalAllocatePages (
42 IN EFI_MEMORY_TYPE MemoryType
,
47 EFI_PHYSICAL_ADDRESS Memory
;
53 Status
= PeiServicesAllocatePages (MemoryType
, Pages
, &Memory
);
54 if (EFI_ERROR (Status
)) {
57 return (VOID
*) (UINTN
) Memory
;
61 Allocates one or more 4KB pages of type EfiBootServicesData.
63 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
64 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
65 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
68 @param Pages The number of 4 KB pages to allocate.
70 @return A pointer to the allocated buffer or NULL if allocation fails.
79 return InternalAllocatePages (EfiBootServicesData
, Pages
);
83 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
85 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
86 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
87 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
90 @param Pages The number of 4 KB pages to allocate.
92 @return A pointer to the allocated buffer or NULL if allocation fails.
97 AllocateRuntimePages (
101 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
105 Allocates one or more 4KB pages of type EfiReservedMemoryType.
107 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
108 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
109 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
112 @param Pages The number of 4 KB pages to allocate.
114 @return A pointer to the allocated buffer or NULL if allocation fails.
119 AllocateReservedPages (
123 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
127 Frees one or more 4KB pages that were previously allocated with one of the page allocation
128 functions in the Memory Allocation Library.
130 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
131 must have been allocated on a previous call to the page allocation services of the Memory
133 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
135 If Pages is zero, then ASSERT().
137 @param Buffer Pointer to the buffer of pages to free.
138 @param Pages The number of 4 KB pages to free.
149 // PEI phase does not support to free pages, so leave it as NOP.
154 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
156 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
157 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
158 If there is not enough memory at the specified alignment remaining to satisfy the request, then
160 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
162 @param MemoryType The type of memory to allocate.
163 @param Pages The number of 4 KB pages to allocate.
164 @param Alignment The requested alignment of the allocation. Must be a power of two.
165 If Alignment is zero, then byte alignment is used.
167 @return A pointer to the allocated buffer or NULL if allocation fails.
171 InternalAllocateAlignedPages (
172 IN EFI_MEMORY_TYPE MemoryType
,
181 // Alignment must be a power of two or zero.
183 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
189 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
191 ASSERT (Pages
<= (MAX_ADDRESS
- EFI_SIZE_TO_PAGES (Alignment
)));
193 // We would rather waste some memory to save PEI code size.
195 Memory
= InternalAllocatePages (MemoryType
, Pages
+ EFI_SIZE_TO_PAGES (Alignment
));
196 if (Alignment
== 0) {
197 AlignmentMask
= Alignment
;
199 AlignmentMask
= Alignment
- 1;
201 return (VOID
*) (UINTN
) (((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
);
205 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
207 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
208 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
209 returned. If there is not enough memory at the specified alignment remaining to satisfy the
210 request, then NULL is returned.
211 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
213 @param Pages The number of 4 KB pages to allocate.
214 @param Alignment The requested alignment of the allocation. Must be a power of two.
215 If Alignment is zero, then byte alignment is used.
217 @return A pointer to the allocated buffer or NULL if allocation fails.
222 AllocateAlignedPages (
227 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
231 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
233 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
234 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
235 returned. If there is not enough memory at the specified alignment remaining to satisfy the
236 request, then NULL is returned.
237 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
239 @param Pages The number of 4 KB pages to allocate.
240 @param Alignment The requested alignment of the allocation. Must be a power of two.
241 If Alignment is zero, then byte alignment is used.
243 @return A pointer to the allocated buffer or NULL if allocation fails.
248 AllocateAlignedRuntimePages (
253 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
257 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
259 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
260 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
261 returned. If there is not enough memory at the specified alignment remaining to satisfy the
262 request, then NULL is returned.
263 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
265 @param Pages The number of 4 KB pages to allocate.
266 @param Alignment The requested alignment of the allocation. Must be a power of two.
267 If Alignment is zero, then byte alignment is used.
269 @return A pointer to the allocated buffer or NULL if allocation fails.
274 AllocateAlignedReservedPages (
279 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
283 Frees one or more 4KB pages that were previously allocated with one of the aligned page
284 allocation functions in the Memory Allocation Library.
286 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
287 must have been allocated on a previous call to the aligned page allocation services of the Memory
289 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
290 Library, then ASSERT().
291 If Pages is zero, then ASSERT().
293 @param Buffer Pointer to the buffer of pages to free.
294 @param Pages The number of 4 KB pages to free.
305 // PEI phase does not support to free pages, so leave it as NOP.
310 Allocates a buffer of a certain pool type.
312 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
313 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
314 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
316 @param MemoryType The type of memory to allocate.
317 @param AllocationSize The number of bytes to allocate.
319 @return A pointer to the allocated buffer or NULL if allocation fails.
323 InternalAllocatePool (
324 IN EFI_MEMORY_TYPE MemoryType
,
325 IN UINTN AllocationSize
329 // If we need lots of small runtime/reserved memory type from PEI in the future,
330 // we can consider providing a more complex algorithm that allocates runtime pages and
331 // provide pool allocations from those pages.
333 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
337 Allocates a buffer of type EfiBootServicesData.
339 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
340 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
341 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
343 @param AllocationSize The number of bytes to allocate.
345 @return A pointer to the allocated buffer or NULL if allocation fails.
351 IN UINTN AllocationSize
357 Status
= PeiServicesAllocatePool (AllocationSize
, &Buffer
);
358 if (EFI_ERROR (Status
)) {
365 Allocates a buffer of type EfiRuntimeServicesData.
367 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
368 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
369 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
371 @param AllocationSize The number of bytes to allocate.
373 @return A pointer to the allocated buffer or NULL if allocation fails.
378 AllocateRuntimePool (
379 IN UINTN AllocationSize
382 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
386 Allocates a buffer of type EfieservedMemoryType.
388 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
389 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
390 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
392 @param AllocationSize The number of bytes to allocate.
394 @return A pointer to the allocated buffer or NULL if allocation fails.
399 AllocateReservedPool (
400 IN UINTN AllocationSize
403 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
407 Allocates and zeros a buffer of a certian pool type.
409 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer
410 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
411 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
412 then NULL is returned.
414 @param PoolType The type of memory to allocate.
415 @param AllocationSize The number of bytes to allocate and zero.
417 @return A pointer to the allocated buffer or NULL if allocation fails.
421 InternalAllocateZeroPool (
422 IN EFI_MEMORY_TYPE PoolType
,
423 IN UINTN AllocationSize
428 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
429 if (Memory
!= NULL
) {
430 Memory
= ZeroMem (Memory
, AllocationSize
);
436 Allocates and zeros a buffer of type EfiBootServicesData.
438 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
439 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
440 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
441 request, then NULL is returned.
443 @param AllocationSize The number of bytes to allocate and zero.
445 @return A pointer to the allocated buffer or NULL if allocation fails.
451 IN UINTN AllocationSize
456 Memory
= AllocatePool (AllocationSize
);
457 if (Memory
!= NULL
) {
458 Memory
= ZeroMem (Memory
, AllocationSize
);
464 Allocates and zeros a buffer of type EfiRuntimeServicesData.
466 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
467 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
468 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
469 request, then NULL is returned.
471 @param AllocationSize The number of bytes to allocate and zero.
473 @return A pointer to the allocated buffer or NULL if allocation fails.
478 AllocateRuntimeZeroPool (
479 IN UINTN AllocationSize
482 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
486 Allocates and zeros a buffer of type EfiReservedMemoryType.
488 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
489 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
490 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
491 request, then NULL is returned.
493 @param AllocationSize The number of bytes to allocate and zero.
495 @return A pointer to the allocated buffer or NULL if allocation fails.
500 AllocateReservedZeroPool (
501 IN UINTN AllocationSize
504 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
508 Copies a buffer to an allocated buffer of a certian pool type.
510 Allocates the number bytes specified by AllocationSize of a certian pool type, copies
511 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
512 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
513 is not enough memory remaining to satisfy the request, then NULL is returned.
514 If Buffer is NULL, then ASSERT().
515 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
517 @param PoolType The type of pool to allocate.
518 @param AllocationSize The number of bytes to allocate and zero.
519 @param Buffer The buffer to copy to the allocated buffer.
521 @return A pointer to the allocated buffer or NULL if allocation fails.
525 InternalAllocateCopyPool (
526 IN EFI_MEMORY_TYPE PoolType
,
527 IN UINTN AllocationSize
,
528 IN CONST VOID
*Buffer
533 ASSERT (Buffer
!= NULL
);
534 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
536 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
537 if (Memory
!= NULL
) {
538 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
544 Copies a buffer to an allocated buffer of type EfiBootServicesData.
546 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
547 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
548 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
549 is not enough memory remaining to satisfy the request, then NULL is returned.
550 If Buffer is NULL, then ASSERT().
551 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
553 @param AllocationSize The number of bytes to allocate and zero.
554 @param Buffer The buffer to copy to the allocated buffer.
556 @return A pointer to the allocated buffer or NULL if allocation fails.
562 IN UINTN AllocationSize
,
563 IN CONST VOID
*Buffer
568 ASSERT (Buffer
!= NULL
);
569 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
571 Memory
= AllocatePool (AllocationSize
);
572 if (Memory
!= NULL
) {
573 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
579 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
581 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
582 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
583 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
584 is not enough memory remaining to satisfy the request, then NULL is returned.
585 If Buffer is NULL, then ASSERT().
586 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
588 @param AllocationSize The number of bytes to allocate and zero.
589 @param Buffer The buffer to copy to the allocated buffer.
591 @return A pointer to the allocated buffer or NULL if allocation fails.
596 AllocateRuntimeCopyPool (
597 IN UINTN AllocationSize
,
598 IN CONST VOID
*Buffer
601 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
605 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
607 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
608 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
609 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
610 is not enough memory remaining to satisfy the request, then NULL is returned.
611 If Buffer is NULL, then ASSERT().
612 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
614 @param AllocationSize The number of bytes to allocate and zero.
615 @param Buffer The buffer to copy to the allocated buffer.
617 @return A pointer to the allocated buffer or NULL if allocation fails.
622 AllocateReservedCopyPool (
623 IN UINTN AllocationSize
,
624 IN CONST VOID
*Buffer
627 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
631 Frees a buffer that was previously allocated with one of the pool allocation functions in the
632 Memory Allocation Library.
634 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
635 pool allocation services of the Memory Allocation Library.
636 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
639 @param Buffer Pointer to the buffer to free.
649 // PEI phase does not support to free pool, so leave it as NOP.
654 Allocates a buffer of a certain pool type at a specified alignment.
656 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
657 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
658 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
659 to satisfy the request, then NULL is returned.
660 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
662 @param PoolType The type of pool to allocate.
663 @param AllocationSize The number of bytes to allocate.
664 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.
665 If Alignment is zero, then byte alignment is used.
667 @return A pointer to the allocated buffer or NULL if allocation fails.
671 InternalAllocateAlignedPool (
672 IN EFI_MEMORY_TYPE PoolType
,
673 IN UINTN AllocationSize
,
678 UINTN AlignedAddress
;
682 // Alignment must be a power of two or zero.
684 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
686 if (Alignment
== 0) {
687 AlignmentMask
= Alignment
;
689 AlignmentMask
= Alignment
- 1;
692 // Make sure that AllocationSize plus AlignmentMask does not overflow.
694 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
696 RawAddress
= InternalAllocatePool (PoolType
, AllocationSize
+ AlignmentMask
);
698 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
700 return (VOID
*) AlignedAddress
;
704 Allocates a buffer of type EfiBootServicesData at a specified alignment.
706 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
707 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
708 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
709 alignment remaining to satisfy the request, then NULL is returned.
710 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
712 @param AllocationSize The number of bytes to allocate.
713 @param Alignment The requested alignment of the allocation. Must be a power of two.
714 If Alignment is zero, then byte alignment is used.
716 @return A pointer to the allocated buffer or NULL if allocation fails.
721 AllocateAlignedPool (
722 IN UINTN AllocationSize
,
727 UINTN AlignedAddress
;
731 // Alignment must be a power of two or zero.
733 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
735 if (Alignment
== 0) {
736 AlignmentMask
= Alignment
;
738 AlignmentMask
= Alignment
- 1;
742 // Make sure that AllocationSize plus AlignmentMask does not overflow.
744 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
746 RawAddress
= AllocatePool (AllocationSize
+ AlignmentMask
);
748 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
750 return (VOID
*) AlignedAddress
;
754 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
756 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
757 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
758 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
759 alignment remaining to satisfy the request, then NULL is returned.
760 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
762 @param AllocationSize The number of bytes to allocate.
763 @param Alignment The requested alignment of the allocation. Must be a power of two.
764 If Alignment is zero, then byte alignment is used.
766 @return A pointer to the allocated buffer or NULL if allocation fails.
771 AllocateAlignedRuntimePool (
772 IN UINTN AllocationSize
,
776 return InternalAllocateAlignedPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
780 Allocates a buffer of type EfieservedMemoryType at a specified alignment.
782 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
783 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
784 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
785 alignment remaining to satisfy the request, then NULL is returned.
786 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
788 @param AllocationSize The number of bytes to allocate.
789 @param Alignment The requested alignment of the allocation. Must be a power of two.
790 If Alignment is zero, then byte alignment is used.
792 @return A pointer to the allocated buffer or NULL if allocation fails.
797 AllocateAlignedReservedPool (
798 IN UINTN AllocationSize
,
802 return InternalAllocateAlignedPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
806 Allocates and zeros a buffer of a certain pool type at a specified alignment.
808 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
809 specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated
810 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not
811 enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.
812 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
814 @param PoolType The type of pool to allocate.
815 @param AllocationSize The number of bytes to allocate.
816 @param Alignment The requested alignment of the allocation. Must be a power of two.
817 If Alignment is zero, then byte alignment is used.
819 @return A pointer to the allocated buffer or NULL if allocation fails.
823 InternalAllocateAlignedZeroPool (
824 IN EFI_MEMORY_TYPE PoolType
,
825 IN UINTN AllocationSize
,
831 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
832 if (Memory
!= NULL
) {
833 Memory
= ZeroMem (Memory
, AllocationSize
);
839 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
841 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
842 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
843 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
844 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
846 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
848 @param AllocationSize The number of bytes to allocate.
849 @param Alignment The requested alignment of the allocation. Must be a power of two.
850 If Alignment is zero, then byte alignment is used.
852 @return A pointer to the allocated buffer or NULL if allocation fails.
857 AllocateAlignedZeroPool (
858 IN UINTN AllocationSize
,
864 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
865 if (Memory
!= NULL
) {
866 Memory
= ZeroMem (Memory
, AllocationSize
);
872 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
874 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
875 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
876 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
877 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
879 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
881 @param AllocationSize The number of bytes to allocate.
882 @param Alignment The requested alignment of the allocation. Must be a power of two.
883 If Alignment is zero, then byte alignment is used.
885 @return A pointer to the allocated buffer or NULL if allocation fails.
890 AllocateAlignedRuntimeZeroPool (
891 IN UINTN AllocationSize
,
895 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
899 Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
901 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
902 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
903 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
904 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
906 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
908 @param AllocationSize The number of bytes to allocate.
909 @param Alignment The requested alignment of the allocation. Must be a power of two.
910 If Alignment is zero, then byte alignment is used.
912 @return A pointer to the allocated buffer or NULL if allocation fails.
917 AllocateAlignedReservedZeroPool (
918 IN UINTN AllocationSize
,
922 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
926 Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.
928 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
929 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
930 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
931 to satisfy the request, then NULL is returned.
932 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
934 @param PoolType The type of pool to allocate.
935 @param AllocationSize The number of bytes to allocate.
936 @param Buffer The buffer to copy to the allocated buffer.
937 @param Alignment The requested alignment of the allocation. Must be a power of two.
938 If Alignment is zero, then byte alignment is used.
940 @return A pointer to the allocated buffer or NULL if allocation fails.
944 InternalAllocateAlignedCopyPool (
945 IN EFI_MEMORY_TYPE PoolType
,
946 IN UINTN AllocationSize
,
947 IN CONST VOID
*Buffer
,
953 ASSERT (Buffer
!= NULL
);
954 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
956 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
957 if (Memory
!= NULL
) {
958 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
964 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
966 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
967 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
968 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
969 alignment remaining to satisfy the request, then NULL is returned.
970 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
972 @param AllocationSize The number of bytes to allocate.
973 @param Buffer The buffer to copy to the allocated buffer.
974 @param Alignment The requested alignment of the allocation. Must be a power of two.
975 If Alignment is zero, then byte alignment is used.
977 @return A pointer to the allocated buffer or NULL if allocation fails.
982 AllocateAlignedCopyPool (
983 IN UINTN AllocationSize
,
984 IN CONST VOID
*Buffer
,
990 ASSERT (Buffer
!= NULL
);
991 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
993 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
994 if (Memory
!= NULL
) {
995 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
1001 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
1003 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
1004 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1005 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1006 alignment remaining to satisfy the request, then NULL is returned.
1007 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1009 @param AllocationSize The number of bytes to allocate.
1010 @param Buffer The buffer to copy to the allocated buffer.
1011 @param Alignment The requested alignment of the allocation. Must be a power of two.
1012 If Alignment is zero, then byte alignment is used.
1014 @return A pointer to the allocated buffer or NULL if allocation fails.
1019 AllocateAlignedRuntimeCopyPool (
1020 IN UINTN AllocationSize
,
1021 IN CONST VOID
*Buffer
,
1025 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
, Alignment
);
1029 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
1031 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
1032 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1033 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1034 alignment remaining to satisfy the request, then NULL is returned.
1035 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1037 @param AllocationSize The number of bytes to allocate.
1038 @param Buffer The buffer to copy to the allocated buffer.
1039 @param Alignment The requested alignment of the allocation. Must be a power of two.
1040 If Alignment is zero, then byte alignment is used.
1042 @return A pointer to the allocated buffer or NULL if allocation fails.
1047 AllocateAlignedReservedCopyPool (
1048 IN UINTN AllocationSize
,
1049 IN CONST VOID
*Buffer
,
1053 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
, Alignment
);
1057 Frees a buffer that was previously allocated with one of the aligned pool allocation functions
1058 in the Memory Allocation Library.
1060 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
1061 aligned pool allocation services of the Memory Allocation Library.
1062 If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
1063 Library, then ASSERT().
1065 @param Buffer Pointer to the buffer to free.
1075 // PEI phase does not support to free pool, so leave it as NOP.