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.
16 // The package level header files this module uses
20 // The protocols, PPI and GUID defintions for this module
23 // The Library classes this module consumes
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/PeiServicesTablePointerLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/DebugLib.h>
30 #include "MemoryAllocationLibInternals.h"
33 Allocates one or more 4KB pages of a certain memory type.
35 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
36 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
37 If there is not enough memory remaining to satisfy the request, then NULL is returned.
39 @param MemoryType The type of memory to allocate.
40 @param Pages The number of 4 KB pages to allocate.
42 @return A pointer to the allocated buffer or NULL if allocation fails.
46 InternalAllocatePages (
47 IN EFI_MEMORY_TYPE MemoryType
,
52 EFI_PHYSICAL_ADDRESS Memory
;
53 EFI_PEI_SERVICES
**PeiServices
;
59 PeiServices
= GetPeiServicesTablePointer ();
60 Status
= (*PeiServices
)->AllocatePages (PeiServices
, MemoryType
, Pages
, &Memory
);
61 if (EFI_ERROR (Status
)) {
64 return (VOID
*) (UINTN
) Memory
;
68 Allocates one or more 4KB pages of type EfiBootServicesData.
70 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
71 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
72 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
75 @param Pages The number of 4 KB pages to allocate.
77 @return A pointer to the allocated buffer or NULL if allocation fails.
86 return InternalAllocatePages (EfiBootServicesData
, Pages
);
90 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
92 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
93 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
94 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
97 @param Pages The number of 4 KB pages to allocate.
99 @return A pointer to the allocated buffer or NULL if allocation fails.
104 AllocateRuntimePages (
108 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
112 Allocates one or more 4KB pages of type EfiReservedMemoryType.
114 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
115 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
116 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
119 @param Pages The number of 4 KB pages to allocate.
121 @return A pointer to the allocated buffer or NULL if allocation fails.
126 AllocateReservedPages (
130 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
134 Frees one or more 4KB pages that were previously allocated with one of the page allocation
135 functions in the Memory Allocation Library.
137 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
138 must have been allocated on a previous call to the page allocation services of the Memory
140 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
142 If Pages is zero, then ASSERT().
144 @param Buffer Pointer to the buffer of pages to free.
145 @param Pages The number of 4 KB pages to free.
156 // PEI phase does not support to free pages, so leave it as NOP.
161 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
163 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
164 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
165 If there is not enough memory at the specified alignment remaining to satisfy the request, then
167 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
169 @param MemoryType The type of memory to allocate.
170 @param Pages The number of 4 KB pages to allocate.
171 @param Alignment The requested alignment of the allocation. Must be a power of two.
172 If Alignment is zero, then byte alignment is used.
174 @return A pointer to the allocated buffer or NULL if allocation fails.
178 InternalAllocateAlignedPages (
179 IN EFI_MEMORY_TYPE MemoryType
,
188 // Alignment must be a power of two or zero.
190 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
196 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
198 ASSERT (Pages
<= (MAX_ADDRESS
- EFI_SIZE_TO_PAGES (Alignment
)));
200 // We would rather waste some memory to save PEI code size.
202 Memory
= InternalAllocatePages (MemoryType
, Pages
+ EFI_SIZE_TO_PAGES (Alignment
));
203 if (Alignment
== 0) {
204 AlignmentMask
= Alignment
;
206 AlignmentMask
= Alignment
- 1;
208 return (VOID
*) (UINTN
) (((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
);
212 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
214 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
215 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
216 returned. If there is not enough memory at the specified alignment remaining to satisfy the
217 request, then NULL is returned.
218 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
220 @param Pages The number of 4 KB pages to allocate.
221 @param Alignment The requested alignment of the allocation. Must be a power of two.
222 If Alignment is zero, then byte alignment is used.
224 @return A pointer to the allocated buffer or NULL if allocation fails.
229 AllocateAlignedPages (
234 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
238 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
240 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
241 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
242 returned. If there is not enough memory at the specified alignment remaining to satisfy the
243 request, then NULL is returned.
244 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
246 @param Pages The number of 4 KB pages to allocate.
247 @param Alignment The requested alignment of the allocation. Must be a power of two.
248 If Alignment is zero, then byte alignment is used.
250 @return A pointer to the allocated buffer or NULL if allocation fails.
255 AllocateAlignedRuntimePages (
260 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
264 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
266 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
267 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
268 returned. If there is not enough memory at the specified alignment remaining to satisfy the
269 request, then NULL is returned.
270 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
272 @param Pages The number of 4 KB pages to allocate.
273 @param Alignment The requested alignment of the allocation. Must be a power of two.
274 If Alignment is zero, then byte alignment is used.
276 @return A pointer to the allocated buffer or NULL if allocation fails.
281 AllocateAlignedReservedPages (
286 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
290 Frees one or more 4KB pages that were previously allocated with one of the aligned page
291 allocation functions in the Memory Allocation Library.
293 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
294 must have been allocated on a previous call to the aligned page allocation services of the Memory
296 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
297 Library, then ASSERT().
298 If Pages is zero, then ASSERT().
300 @param Buffer Pointer to the buffer of pages to free.
301 @param Pages The number of 4 KB pages to free.
312 // PEI phase does not support to free pages, so leave it as NOP.
317 Allocates a buffer of a certain pool type.
319 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
320 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
321 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
323 @param MemoryType The type of memory to allocate.
324 @param AllocationSize The number of bytes to allocate.
326 @return A pointer to the allocated buffer or NULL if allocation fails.
330 InternalAllocatePool (
331 IN EFI_MEMORY_TYPE MemoryType
,
332 IN UINTN AllocationSize
336 // If we need lots of small runtime/reserved memory type from PEI in the future,
337 // we can consider providing a more complex algorithm that allocates runtime pages and
338 // provide pool allocations from those pages.
340 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
344 Allocates a buffer of type EfiBootServicesData.
346 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
347 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
348 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
350 @param AllocationSize The number of bytes to allocate.
352 @return A pointer to the allocated buffer or NULL if allocation fails.
358 IN UINTN AllocationSize
362 EFI_PEI_SERVICES
**PeiServices
;
365 PeiServices
= GetPeiServicesTablePointer ();
367 Status
= (*PeiServices
)->AllocatePool (PeiServices
, AllocationSize
, &Buffer
);
368 if (EFI_ERROR (Status
)) {
375 Allocates a buffer of type EfiRuntimeServicesData.
377 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
378 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
379 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
381 @param AllocationSize The number of bytes to allocate.
383 @return A pointer to the allocated buffer or NULL if allocation fails.
388 AllocateRuntimePool (
389 IN UINTN AllocationSize
392 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
396 Allocates a buffer of type EfieservedMemoryType.
398 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
399 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
400 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
402 @param AllocationSize The number of bytes to allocate.
404 @return A pointer to the allocated buffer or NULL if allocation fails.
409 AllocateReservedPool (
410 IN UINTN AllocationSize
413 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
417 Allocates and zeros a buffer of a certian pool type.
419 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer
420 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
421 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
422 then NULL is returned.
424 @param PoolType The type of memory to allocate.
425 @param AllocationSize The number of bytes to allocate and zero.
427 @return A pointer to the allocated buffer or NULL if allocation fails.
431 InternalAllocateZeroPool (
432 IN EFI_MEMORY_TYPE PoolType
,
433 IN UINTN AllocationSize
438 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
439 if (Memory
!= NULL
) {
440 Memory
= ZeroMem (Memory
, AllocationSize
);
446 Allocates and zeros a buffer of type EfiBootServicesData.
448 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
449 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
450 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
451 request, then NULL is returned.
453 @param AllocationSize The number of bytes to allocate and zero.
455 @return A pointer to the allocated buffer or NULL if allocation fails.
461 IN UINTN AllocationSize
466 Memory
= AllocatePool (AllocationSize
);
467 if (Memory
!= NULL
) {
468 Memory
= ZeroMem (Memory
, AllocationSize
);
474 Allocates and zeros a buffer of type EfiRuntimeServicesData.
476 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
477 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
478 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
479 request, then NULL is returned.
481 @param AllocationSize The number of bytes to allocate and zero.
483 @return A pointer to the allocated buffer or NULL if allocation fails.
488 AllocateRuntimeZeroPool (
489 IN UINTN AllocationSize
492 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
496 Allocates and zeros a buffer of type EfiReservedMemoryType.
498 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
499 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
500 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
501 request, then NULL is returned.
503 @param AllocationSize The number of bytes to allocate and zero.
505 @return A pointer to the allocated buffer or NULL if allocation fails.
510 AllocateReservedZeroPool (
511 IN UINTN AllocationSize
514 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
518 Copies a buffer to an allocated buffer of a certian pool type.
520 Allocates the number bytes specified by AllocationSize of a certian pool type, copies
521 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
522 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
523 is not enough memory remaining to satisfy the request, then NULL is returned.
524 If Buffer is NULL, then ASSERT().
525 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
527 @param PoolType The type of pool to allocate.
528 @param AllocationSize The number of bytes to allocate and zero.
529 @param Buffer The buffer to copy to the allocated buffer.
531 @return A pointer to the allocated buffer or NULL if allocation fails.
535 InternalAllocateCopyPool (
536 IN EFI_MEMORY_TYPE PoolType
,
537 IN UINTN AllocationSize
,
538 IN CONST VOID
*Buffer
543 ASSERT (Buffer
!= NULL
);
544 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
546 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
547 if (Memory
!= NULL
) {
548 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
554 Copies a buffer to an allocated buffer of type EfiBootServicesData.
556 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
557 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
558 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
559 is not enough memory remaining to satisfy the request, then NULL is returned.
560 If Buffer is NULL, then ASSERT().
561 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
563 @param AllocationSize The number of bytes to allocate and zero.
564 @param Buffer The buffer to copy to the allocated buffer.
566 @return A pointer to the allocated buffer or NULL if allocation fails.
572 IN UINTN AllocationSize
,
573 IN CONST VOID
*Buffer
578 ASSERT (Buffer
!= NULL
);
579 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
581 Memory
= AllocatePool (AllocationSize
);
582 if (Memory
!= NULL
) {
583 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
589 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
591 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
592 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
593 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
594 is not enough memory remaining to satisfy the request, then NULL is returned.
595 If Buffer is NULL, then ASSERT().
596 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
598 @param AllocationSize The number of bytes to allocate and zero.
599 @param Buffer The buffer to copy to the allocated buffer.
601 @return A pointer to the allocated buffer or NULL if allocation fails.
606 AllocateRuntimeCopyPool (
607 IN UINTN AllocationSize
,
608 IN CONST VOID
*Buffer
611 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
615 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
617 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
618 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
619 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
620 is not enough memory remaining to satisfy the request, then NULL is returned.
621 If Buffer is NULL, then ASSERT().
622 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
624 @param AllocationSize The number of bytes to allocate and zero.
625 @param Buffer The buffer to copy to the allocated buffer.
627 @return A pointer to the allocated buffer or NULL if allocation fails.
632 AllocateReservedCopyPool (
633 IN UINTN AllocationSize
,
634 IN CONST VOID
*Buffer
637 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
641 Frees a buffer that was previously allocated with one of the pool allocation functions in the
642 Memory Allocation Library.
644 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
645 pool allocation services of the Memory Allocation Library.
646 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
649 @param Buffer Pointer to the buffer to free.
659 // PEI phase does not support to free pool, so leave it as NOP.
664 Allocates a buffer of a certain pool type at a specified alignment.
666 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
667 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
668 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
669 to satisfy the request, then NULL is returned.
670 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
672 @param PoolType The type of pool to allocate.
673 @param AllocationSize The number of bytes to allocate.
674 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.
675 If Alignment is zero, then byte alignment is used.
677 @return A pointer to the allocated buffer or NULL if allocation fails.
681 InternalAllocateAlignedPool (
682 IN EFI_MEMORY_TYPE PoolType
,
683 IN UINTN AllocationSize
,
688 UINTN AlignedAddress
;
692 // Alignment must be a power of two or zero.
694 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
696 if (Alignment
== 0) {
697 AlignmentMask
= Alignment
;
699 AlignmentMask
= Alignment
- 1;
702 // Make sure that AllocationSize plus AlignmentMask does not overflow.
704 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
706 RawAddress
= InternalAllocatePool (PoolType
, AllocationSize
+ AlignmentMask
);
708 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
710 return (VOID
*) AlignedAddress
;
714 Allocates a buffer of type EfiBootServicesData at a specified alignment.
716 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
717 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
718 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
719 alignment remaining to satisfy the request, then NULL is returned.
720 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
722 @param AllocationSize The number of bytes to allocate.
723 @param Alignment The requested alignment of the allocation. Must be a power of two.
724 If Alignment is zero, then byte alignment is used.
726 @return A pointer to the allocated buffer or NULL if allocation fails.
731 AllocateAlignedPool (
732 IN UINTN AllocationSize
,
737 UINTN AlignedAddress
;
741 // Alignment must be a power of two or zero.
743 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
745 if (Alignment
== 0) {
746 AlignmentMask
= Alignment
;
748 AlignmentMask
= Alignment
- 1;
752 // Make sure that AllocationSize plus AlignmentMask does not overflow.
754 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
756 RawAddress
= AllocatePool (AllocationSize
+ AlignmentMask
);
758 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
760 return (VOID
*) AlignedAddress
;
764 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
766 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
767 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
768 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
769 alignment remaining to satisfy the request, then NULL is returned.
770 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
772 @param AllocationSize The number of bytes to allocate.
773 @param Alignment The requested alignment of the allocation. Must be a power of two.
774 If Alignment is zero, then byte alignment is used.
776 @return A pointer to the allocated buffer or NULL if allocation fails.
781 AllocateAlignedRuntimePool (
782 IN UINTN AllocationSize
,
786 return InternalAllocateAlignedPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
790 Allocates a buffer of type EfieservedMemoryType at a specified alignment.
792 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
793 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
794 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
795 alignment remaining to satisfy the request, then NULL is returned.
796 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
798 @param AllocationSize The number of bytes to allocate.
799 @param Alignment The requested alignment of the allocation. Must be a power of two.
800 If Alignment is zero, then byte alignment is used.
802 @return A pointer to the allocated buffer or NULL if allocation fails.
807 AllocateAlignedReservedPool (
808 IN UINTN AllocationSize
,
812 return InternalAllocateAlignedPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
816 Allocates and zeros a buffer of a certain pool type at a specified alignment.
818 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
819 specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated
820 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not
821 enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.
822 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
824 @param PoolType The type of pool to allocate.
825 @param AllocationSize The number of bytes to allocate.
826 @param Alignment The requested alignment of the allocation. Must be a power of two.
827 If Alignment is zero, then byte alignment is used.
829 @return A pointer to the allocated buffer or NULL if allocation fails.
833 InternalAllocateAlignedZeroPool (
834 IN EFI_MEMORY_TYPE PoolType
,
835 IN UINTN AllocationSize
,
841 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
842 if (Memory
!= NULL
) {
843 Memory
= ZeroMem (Memory
, AllocationSize
);
849 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
851 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
852 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
853 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
854 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
856 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
858 @param AllocationSize The number of bytes to allocate.
859 @param Alignment The requested alignment of the allocation. Must be a power of two.
860 If Alignment is zero, then byte alignment is used.
862 @return A pointer to the allocated buffer or NULL if allocation fails.
867 AllocateAlignedZeroPool (
868 IN UINTN AllocationSize
,
874 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
875 if (Memory
!= NULL
) {
876 Memory
= ZeroMem (Memory
, AllocationSize
);
882 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
884 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
885 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
886 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
887 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
889 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
891 @param AllocationSize The number of bytes to allocate.
892 @param Alignment The requested alignment of the allocation. Must be a power of two.
893 If Alignment is zero, then byte alignment is used.
895 @return A pointer to the allocated buffer or NULL if allocation fails.
900 AllocateAlignedRuntimeZeroPool (
901 IN UINTN AllocationSize
,
905 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
909 Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
911 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
912 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
913 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
914 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
916 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
918 @param AllocationSize The number of bytes to allocate.
919 @param Alignment The requested alignment of the allocation. Must be a power of two.
920 If Alignment is zero, then byte alignment is used.
922 @return A pointer to the allocated buffer or NULL if allocation fails.
927 AllocateAlignedReservedZeroPool (
928 IN UINTN AllocationSize
,
932 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
936 Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.
938 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
939 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
940 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
941 to satisfy the request, then NULL is returned.
942 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
944 @param PoolType The type of pool to allocate.
945 @param AllocationSize The number of bytes to allocate.
946 @param Buffer The buffer to copy to the allocated buffer.
947 @param Alignment The requested alignment of the allocation. Must be a power of two.
948 If Alignment is zero, then byte alignment is used.
950 @return A pointer to the allocated buffer or NULL if allocation fails.
954 InternalAllocateAlignedCopyPool (
955 IN EFI_MEMORY_TYPE PoolType
,
956 IN UINTN AllocationSize
,
957 IN CONST VOID
*Buffer
,
963 ASSERT (Buffer
!= NULL
);
964 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
966 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
967 if (Memory
!= NULL
) {
968 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
974 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
976 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
977 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
978 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
979 alignment remaining to satisfy the request, then NULL is returned.
980 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
982 @param AllocationSize The number of bytes to allocate.
983 @param Buffer The buffer to copy to the allocated buffer.
984 @param Alignment The requested alignment of the allocation. Must be a power of two.
985 If Alignment is zero, then byte alignment is used.
987 @return A pointer to the allocated buffer or NULL if allocation fails.
992 AllocateAlignedCopyPool (
993 IN UINTN AllocationSize
,
994 IN CONST VOID
*Buffer
,
1000 ASSERT (Buffer
!= NULL
);
1001 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
1003 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
1004 if (Memory
!= NULL
) {
1005 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
1011 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
1013 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
1014 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1015 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1016 alignment remaining to satisfy the request, then NULL is returned.
1017 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1019 @param AllocationSize The number of bytes to allocate.
1020 @param Buffer The buffer to copy to the allocated buffer.
1021 @param Alignment The requested alignment of the allocation. Must be a power of two.
1022 If Alignment is zero, then byte alignment is used.
1024 @return A pointer to the allocated buffer or NULL if allocation fails.
1029 AllocateAlignedRuntimeCopyPool (
1030 IN UINTN AllocationSize
,
1031 IN CONST VOID
*Buffer
,
1035 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
, Alignment
);
1039 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
1041 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
1042 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1043 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1044 alignment remaining to satisfy the request, then NULL is returned.
1045 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1047 @param AllocationSize The number of bytes to allocate.
1048 @param Buffer The buffer to copy to the allocated buffer.
1049 @param Alignment The requested alignment of the allocation. Must be a power of two.
1050 If Alignment is zero, then byte alignment is used.
1052 @return A pointer to the allocated buffer or NULL if allocation fails.
1057 AllocateAlignedReservedCopyPool (
1058 IN UINTN AllocationSize
,
1059 IN CONST VOID
*Buffer
,
1063 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
, Alignment
);
1067 Frees a buffer that was previously allocated with one of the aligned pool allocation functions
1068 in the Memory Allocation Library.
1070 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
1071 aligned pool allocation services of the Memory Allocation Library.
1072 If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
1073 Library, then ASSERT().
1075 @param Buffer Pointer to the buffer to free.
1085 // PEI phase does not support to free pool, so leave it as NOP.