3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Support routines for memory allocation routines for use with drivers.
23 #include "EdkIIGluePeim.h"
26 Allocates one or more 4KB pages of a certain memory type.
28 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
29 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
30 If there is not enough memory remaining to satisfy the request, then NULL is returned.
32 @param MemoryType The type of memory to allocate.
33 @param Pages The number of 4 KB pages to allocate.
35 @return A pointer to the allocated buffer or NULL if allocation fails.
39 InternalAllocatePages (
40 IN EFI_MEMORY_TYPE MemoryType
,
45 EFI_PHYSICAL_ADDRESS Memory
;
51 Status
= PeiServicesAllocatePages (MemoryType
, Pages
, &Memory
);
52 if (EFI_ERROR (Status
)) {
55 return (VOID
*) (UINTN
) Memory
;
59 Allocates one or more 4KB pages of type EfiBootServicesData.
61 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
62 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
63 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
66 @param Pages The number of 4 KB pages to allocate.
68 @return A pointer to the allocated buffer or NULL if allocation fails.
77 return InternalAllocatePages (EfiBootServicesData
, Pages
);
81 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
83 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
84 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
85 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
88 @param Pages The number of 4 KB pages to allocate.
90 @return A pointer to the allocated buffer or NULL if allocation fails.
95 AllocateRuntimePages (
99 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
103 Allocates one or more 4KB pages of type EfiReservedMemoryType.
105 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
106 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
107 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
110 @param Pages The number of 4 KB pages to allocate.
112 @return A pointer to the allocated buffer or NULL if allocation fails.
117 AllocateReservedPages (
121 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
125 Frees one or more 4KB pages that were previously allocated with one of the page allocation
126 functions in the Memory Allocation Library.
128 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
129 must have been allocated on a previous call to the page allocation services of the Memory
131 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
133 If Pages is zero, then ASSERT().
135 @param Buffer Pointer to the buffer of pages to free.
136 @param Pages The number of 4 KB pages to free.
147 // PEI phase does not support to free pages, so leave it as NOP.
152 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
154 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
155 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
156 If there is not enough memory at the specified alignment remaining to satisfy the request, then
158 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
160 @param MemoryType The type of memory to allocate.
161 @param Pages The number of 4 KB pages to allocate.
162 @param Alignment The requested alignment of the allocation. Must be a power of two.
163 If Alignment is zero, then byte alignment is used.
165 @return A pointer to the allocated buffer or NULL if allocation fails.
169 InternalAllocateAlignedPages (
170 IN EFI_MEMORY_TYPE MemoryType
,
179 // Alignment must be a power of two or zero.
181 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
187 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
189 ASSERT (Pages
<= (MAX_ADDRESS
- EFI_SIZE_TO_PAGES (Alignment
)));
191 // We would rather waste some memory to save PEI code size.
193 Memory
= InternalAllocatePages (MemoryType
, Pages
+ EFI_SIZE_TO_PAGES (Alignment
));
194 if (Alignment
== 0) {
195 AlignmentMask
= Alignment
;
197 AlignmentMask
= Alignment
- 1;
199 return (VOID
*) (UINTN
) (((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
);
203 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
205 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
206 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
207 returned. If there is not enough memory at the specified alignment remaining to satisfy the
208 request, then NULL is returned.
209 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
211 @param Pages The number of 4 KB pages to allocate.
212 @param Alignment The requested alignment of the allocation. Must be a power of two.
213 If Alignment is zero, then byte alignment is used.
215 @return A pointer to the allocated buffer or NULL if allocation fails.
220 AllocateAlignedPages (
225 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
229 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
231 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
232 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
233 returned. If there is not enough memory at the specified alignment remaining to satisfy the
234 request, then NULL is returned.
235 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
237 @param Pages The number of 4 KB pages to allocate.
238 @param Alignment The requested alignment of the allocation. Must be a power of two.
239 If Alignment is zero, then byte alignment is used.
241 @return A pointer to the allocated buffer or NULL if allocation fails.
246 AllocateAlignedRuntimePages (
251 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
255 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
257 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
258 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
259 returned. If there is not enough memory at the specified alignment remaining to satisfy the
260 request, then NULL is returned.
261 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
263 @param Pages The number of 4 KB pages to allocate.
264 @param Alignment The requested alignment of the allocation. Must be a power of two.
265 If Alignment is zero, then byte alignment is used.
267 @return A pointer to the allocated buffer or NULL if allocation fails.
272 AllocateAlignedReservedPages (
277 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
281 Frees one or more 4KB pages that were previously allocated with one of the aligned page
282 allocation functions in the Memory Allocation Library.
284 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
285 must have been allocated on a previous call to the aligned page allocation services of the Memory
287 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
288 Library, then ASSERT().
289 If Pages is zero, then ASSERT().
291 @param Buffer Pointer to the buffer of pages to free.
292 @param Pages The number of 4 KB pages to free.
303 // PEI phase does not support to free pages, so leave it as NOP.
308 Allocates a buffer of a certain pool type.
310 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
311 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
312 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
314 @param MemoryType The type of memory to allocate.
315 @param AllocationSize The number of bytes to allocate.
317 @return A pointer to the allocated buffer or NULL if allocation fails.
321 InternalAllocatePool (
322 IN EFI_MEMORY_TYPE MemoryType
,
323 IN UINTN AllocationSize
327 // If we need lots of small runtime/reserved memory type from PEI in the future,
328 // we can consider providing a more complex algorithm that allocates runtime pages and
329 // provide pool allocations from those pages.
331 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
335 Allocates a buffer of type EfiBootServicesData.
337 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
338 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
339 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
341 @param AllocationSize The number of bytes to allocate.
343 @return A pointer to the allocated buffer or NULL if allocation fails.
349 IN UINTN AllocationSize
355 Status
= PeiServicesAllocatePool (AllocationSize
, &Buffer
);
356 if (EFI_ERROR (Status
)) {
363 Allocates a buffer of type EfiRuntimeServicesData.
365 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
366 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
367 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
369 @param AllocationSize The number of bytes to allocate.
371 @return A pointer to the allocated buffer or NULL if allocation fails.
376 AllocateRuntimePool (
377 IN UINTN AllocationSize
380 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
384 Allocates a buffer of type EfieservedMemoryType.
386 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
387 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
388 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
390 @param AllocationSize The number of bytes to allocate.
392 @return A pointer to the allocated buffer or NULL if allocation fails.
397 AllocateReservedPool (
398 IN UINTN AllocationSize
401 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
405 Allocates and zeros a buffer of a certian pool type.
407 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer
408 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
409 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
410 then NULL is returned.
412 @param PoolType The type of memory to allocate.
413 @param AllocationSize The number of bytes to allocate and zero.
415 @return A pointer to the allocated buffer or NULL if allocation fails.
419 InternalAllocateZeroPool (
420 IN EFI_MEMORY_TYPE PoolType
,
421 IN UINTN AllocationSize
426 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
427 if (Memory
!= NULL
) {
428 Memory
= ZeroMem (Memory
, AllocationSize
);
434 Allocates and zeros a buffer of type EfiBootServicesData.
436 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
437 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
438 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
439 request, then NULL is returned.
441 @param AllocationSize The number of bytes to allocate and zero.
443 @return A pointer to the allocated buffer or NULL if allocation fails.
448 GlueAllocateZeroPool (
449 IN UINTN AllocationSize
454 Memory
= AllocatePool (AllocationSize
);
455 if (Memory
!= NULL
) {
456 Memory
= ZeroMem (Memory
, AllocationSize
);
462 Allocates and zeros a buffer of type EfiRuntimeServicesData.
464 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
465 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
466 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
467 request, then NULL is returned.
469 @param AllocationSize The number of bytes to allocate and zero.
471 @return A pointer to the allocated buffer or NULL if allocation fails.
476 AllocateRuntimeZeroPool (
477 IN UINTN AllocationSize
480 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
484 Allocates and zeros a buffer of type EfiReservedMemoryType.
486 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
487 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
488 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
489 request, then NULL is returned.
491 @param AllocationSize The number of bytes to allocate and zero.
493 @return A pointer to the allocated buffer or NULL if allocation fails.
498 AllocateReservedZeroPool (
499 IN UINTN AllocationSize
502 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
506 Copies a buffer to an allocated buffer of a certian pool type.
508 Allocates the number bytes specified by AllocationSize of a certian pool type, copies
509 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
510 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
511 is not enough memory remaining to satisfy the request, then NULL is returned.
512 If Buffer is NULL, then ASSERT().
513 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
515 @param PoolType The type of pool to allocate.
516 @param AllocationSize The number of bytes to allocate and zero.
517 @param Buffer The buffer to copy to the allocated buffer.
519 @return A pointer to the allocated buffer or NULL if allocation fails.
523 InternalAllocateCopyPool (
524 IN EFI_MEMORY_TYPE PoolType
,
525 IN UINTN AllocationSize
,
526 IN CONST VOID
*Buffer
531 ASSERT (Buffer
!= NULL
);
532 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
534 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
535 if (Memory
!= NULL
) {
536 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
542 Copies a buffer to an allocated buffer of type EfiBootServicesData.
544 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
545 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
546 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
547 is not enough memory remaining to satisfy the request, then NULL is returned.
548 If Buffer is NULL, then ASSERT().
549 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
551 @param AllocationSize The number of bytes to allocate and zero.
552 @param Buffer The buffer to copy to the allocated buffer.
554 @return A pointer to the allocated buffer or NULL if allocation fails.
559 GlueAllocateCopyPool (
560 IN UINTN AllocationSize
,
561 IN CONST VOID
*Buffer
566 ASSERT (Buffer
!= NULL
);
567 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
569 Memory
= AllocatePool (AllocationSize
);
570 if (Memory
!= NULL
) {
571 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
577 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
579 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
580 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
581 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
582 is not enough memory remaining to satisfy the request, then NULL is returned.
583 If Buffer is NULL, then ASSERT().
584 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
586 @param AllocationSize The number of bytes to allocate and zero.
587 @param Buffer The buffer to copy to the allocated buffer.
589 @return A pointer to the allocated buffer or NULL if allocation fails.
594 AllocateRuntimeCopyPool (
595 IN UINTN AllocationSize
,
596 IN CONST VOID
*Buffer
599 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
603 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
605 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
606 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
607 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
608 is not enough memory remaining to satisfy the request, then NULL is returned.
609 If Buffer is NULL, then ASSERT().
610 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
612 @param AllocationSize The number of bytes to allocate and zero.
613 @param Buffer The buffer to copy to the allocated buffer.
615 @return A pointer to the allocated buffer or NULL if allocation fails.
620 AllocateReservedCopyPool (
621 IN UINTN AllocationSize
,
622 IN CONST VOID
*Buffer
625 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
629 Frees a buffer that was previously allocated with one of the pool allocation functions in the
630 Memory Allocation Library.
632 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
633 pool allocation services of the Memory Allocation Library.
634 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
637 @param Buffer Pointer to the buffer to free.
647 // PEI phase does not support to free pool, so leave it as NOP.
652 Allocates a buffer of a certain pool type at a specified alignment.
654 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
655 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
656 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
657 to satisfy the request, then NULL is returned.
658 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
660 @param PoolType The type of pool to allocate.
661 @param AllocationSize The number of bytes to allocate.
662 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.
663 If Alignment is zero, then byte alignment is used.
665 @return A pointer to the allocated buffer or NULL if allocation fails.
669 InternalAllocateAlignedPool (
670 IN EFI_MEMORY_TYPE PoolType
,
671 IN UINTN AllocationSize
,
676 UINTN AlignedAddress
;
680 // Alignment must be a power of two or zero.
682 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
684 if (Alignment
== 0) {
685 AlignmentMask
= Alignment
;
687 AlignmentMask
= Alignment
- 1;
690 // Make sure that AllocationSize plus AlignmentMask does not overflow.
692 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
694 RawAddress
= InternalAllocatePool (PoolType
, AllocationSize
+ AlignmentMask
);
696 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
698 return (VOID
*) AlignedAddress
;
702 Allocates a buffer of type EfiBootServicesData at a specified alignment.
704 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
705 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
706 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
707 alignment remaining to satisfy the request, then NULL is returned.
708 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
710 @param AllocationSize The number of bytes to allocate.
711 @param Alignment The requested alignment of the allocation. Must be a power of two.
712 If Alignment is zero, then byte alignment is used.
714 @return A pointer to the allocated buffer or NULL if allocation fails.
719 AllocateAlignedPool (
720 IN UINTN AllocationSize
,
725 UINTN AlignedAddress
;
729 // Alignment must be a power of two or zero.
731 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
733 if (Alignment
== 0) {
734 AlignmentMask
= Alignment
;
736 AlignmentMask
= Alignment
- 1;
740 // Make sure that AllocationSize plus AlignmentMask does not overflow.
742 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
744 RawAddress
= AllocatePool (AllocationSize
+ AlignmentMask
);
746 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
748 return (VOID
*) AlignedAddress
;
752 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
754 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
755 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
756 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
757 alignment remaining to satisfy the request, then NULL is returned.
758 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
760 @param AllocationSize The number of bytes to allocate.
761 @param Alignment The requested alignment of the allocation. Must be a power of two.
762 If Alignment is zero, then byte alignment is used.
764 @return A pointer to the allocated buffer or NULL if allocation fails.
769 AllocateAlignedRuntimePool (
770 IN UINTN AllocationSize
,
774 return InternalAllocateAlignedPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
778 Allocates a buffer of type EfieservedMemoryType at a specified alignment.
780 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
781 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
782 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
783 alignment remaining to satisfy the request, then NULL is returned.
784 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
786 @param AllocationSize The number of bytes to allocate.
787 @param Alignment The requested alignment of the allocation. Must be a power of two.
788 If Alignment is zero, then byte alignment is used.
790 @return A pointer to the allocated buffer or NULL if allocation fails.
795 AllocateAlignedReservedPool (
796 IN UINTN AllocationSize
,
800 return InternalAllocateAlignedPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
804 Allocates and zeros a buffer of a certain pool type at a specified alignment.
806 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
807 specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated
808 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not
809 enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.
810 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
812 @param PoolType The type of pool to allocate.
813 @param AllocationSize The number of bytes to allocate.
814 @param Alignment The requested alignment of the allocation. Must be a power of two.
815 If Alignment is zero, then byte alignment is used.
817 @return A pointer to the allocated buffer or NULL if allocation fails.
821 InternalAllocateAlignedZeroPool (
822 IN EFI_MEMORY_TYPE PoolType
,
823 IN UINTN AllocationSize
,
829 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
830 if (Memory
!= NULL
) {
831 Memory
= ZeroMem (Memory
, AllocationSize
);
837 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
839 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
840 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
841 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
842 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
844 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
846 @param AllocationSize The number of bytes to allocate.
847 @param Alignment The requested alignment of the allocation. Must be a power of two.
848 If Alignment is zero, then byte alignment is used.
850 @return A pointer to the allocated buffer or NULL if allocation fails.
855 AllocateAlignedZeroPool (
856 IN UINTN AllocationSize
,
862 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
863 if (Memory
!= NULL
) {
864 Memory
= ZeroMem (Memory
, AllocationSize
);
870 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
872 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
873 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
874 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
875 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
877 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
879 @param AllocationSize The number of bytes to allocate.
880 @param Alignment The requested alignment of the allocation. Must be a power of two.
881 If Alignment is zero, then byte alignment is used.
883 @return A pointer to the allocated buffer or NULL if allocation fails.
888 AllocateAlignedRuntimeZeroPool (
889 IN UINTN AllocationSize
,
893 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
897 Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
899 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
900 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
901 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
902 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
904 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
906 @param AllocationSize The number of bytes to allocate.
907 @param Alignment The requested alignment of the allocation. Must be a power of two.
908 If Alignment is zero, then byte alignment is used.
910 @return A pointer to the allocated buffer or NULL if allocation fails.
915 AllocateAlignedReservedZeroPool (
916 IN UINTN AllocationSize
,
920 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
924 Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.
926 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
927 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
928 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
929 to satisfy the request, then NULL is returned.
930 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
932 @param PoolType The type of pool to allocate.
933 @param AllocationSize The number of bytes to allocate.
934 @param Buffer The buffer to copy to the allocated buffer.
935 @param Alignment The requested alignment of the allocation. Must be a power of two.
936 If Alignment is zero, then byte alignment is used.
938 @return A pointer to the allocated buffer or NULL if allocation fails.
942 InternalAllocateAlignedCopyPool (
943 IN EFI_MEMORY_TYPE PoolType
,
944 IN UINTN AllocationSize
,
945 IN CONST VOID
*Buffer
,
951 ASSERT (Buffer
!= NULL
);
952 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
954 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
955 if (Memory
!= NULL
) {
956 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
962 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
964 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
965 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
966 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
967 alignment remaining to satisfy the request, then NULL is returned.
968 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
970 @param AllocationSize The number of bytes to allocate.
971 @param Buffer The buffer to copy to the allocated buffer.
972 @param Alignment The requested alignment of the allocation. Must be a power of two.
973 If Alignment is zero, then byte alignment is used.
975 @return A pointer to the allocated buffer or NULL if allocation fails.
980 AllocateAlignedCopyPool (
981 IN UINTN AllocationSize
,
982 IN CONST VOID
*Buffer
,
988 ASSERT (Buffer
!= NULL
);
989 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
991 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
992 if (Memory
!= NULL
) {
993 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
999 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
1001 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
1002 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1003 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1004 alignment remaining to satisfy the request, then NULL is returned.
1005 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1007 @param AllocationSize The number of bytes to allocate.
1008 @param Buffer The buffer to copy to the allocated buffer.
1009 @param Alignment The requested alignment of the allocation. Must be a power of two.
1010 If Alignment is zero, then byte alignment is used.
1012 @return A pointer to the allocated buffer or NULL if allocation fails.
1017 AllocateAlignedRuntimeCopyPool (
1018 IN UINTN AllocationSize
,
1019 IN CONST VOID
*Buffer
,
1023 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
, Alignment
);
1027 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
1029 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
1030 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1031 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1032 alignment remaining to satisfy the request, then NULL is returned.
1033 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1035 @param AllocationSize The number of bytes to allocate.
1036 @param Buffer The buffer to copy to the allocated buffer.
1037 @param Alignment The requested alignment of the allocation. Must be a power of two.
1038 If Alignment is zero, then byte alignment is used.
1040 @return A pointer to the allocated buffer or NULL if allocation fails.
1045 AllocateAlignedReservedCopyPool (
1046 IN UINTN AllocationSize
,
1047 IN CONST VOID
*Buffer
,
1051 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
, Alignment
);
1055 Frees a buffer that was previously allocated with one of the aligned pool allocation functions
1056 in the Memory Allocation Library.
1058 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
1059 aligned pool allocation services of the Memory Allocation Library.
1060 If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
1061 Library, then ASSERT().
1063 @param Buffer Pointer to the buffer to free.
1073 // PEI phase does not support to free pool, so leave it as NOP.