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
;
46 EFI_PEI_SERVICES
**PeiServices
;
52 PeiServices
= GetPeiServicesTablePointer ();
53 Status
= ((*PeiServices
)->AllocatePages
) (PeiServices
, 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
355 EFI_PEI_SERVICES
**PeiServices
;
358 PeiServices
= GetPeiServicesTablePointer ();
360 Status
= ((*PeiServices
)->AllocatePool
) (PeiServices
, AllocationSize
, &Buffer
);
361 if (EFI_ERROR (Status
)) {
368 Allocates a buffer of type EfiRuntimeServicesData.
370 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
371 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
372 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
374 @param AllocationSize The number of bytes to allocate.
376 @return A pointer to the allocated buffer or NULL if allocation fails.
381 AllocateRuntimePool (
382 IN UINTN AllocationSize
385 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
389 Allocates a buffer of type EfieservedMemoryType.
391 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
392 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
393 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
395 @param AllocationSize The number of bytes to allocate.
397 @return A pointer to the allocated buffer or NULL if allocation fails.
402 AllocateReservedPool (
403 IN UINTN AllocationSize
406 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
410 Allocates and zeros a buffer of a certian pool type.
412 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer
413 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
414 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
415 then NULL is returned.
417 @param PoolType The type of memory to allocate.
418 @param AllocationSize The number of bytes to allocate and zero.
420 @return A pointer to the allocated buffer or NULL if allocation fails.
424 InternalAllocateZeroPool (
425 IN EFI_MEMORY_TYPE PoolType
,
426 IN UINTN AllocationSize
431 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
432 if (Memory
!= NULL
) {
433 Memory
= ZeroMem (Memory
, AllocationSize
);
439 Allocates and zeros a buffer of type EfiBootServicesData.
441 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
442 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
443 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
444 request, then NULL is returned.
446 @param AllocationSize The number of bytes to allocate and zero.
448 @return A pointer to the allocated buffer or NULL if allocation fails.
453 GlueAllocateZeroPool (
454 IN UINTN AllocationSize
459 Memory
= AllocatePool (AllocationSize
);
460 if (Memory
!= NULL
) {
461 Memory
= ZeroMem (Memory
, AllocationSize
);
467 Allocates and zeros a buffer of type EfiRuntimeServicesData.
469 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
470 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
471 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
472 request, then NULL is returned.
474 @param AllocationSize The number of bytes to allocate and zero.
476 @return A pointer to the allocated buffer or NULL if allocation fails.
481 AllocateRuntimeZeroPool (
482 IN UINTN AllocationSize
485 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
489 Allocates and zeros a buffer of type EfiReservedMemoryType.
491 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
492 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
493 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
494 request, then NULL is returned.
496 @param AllocationSize The number of bytes to allocate and zero.
498 @return A pointer to the allocated buffer or NULL if allocation fails.
503 AllocateReservedZeroPool (
504 IN UINTN AllocationSize
507 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
511 Copies a buffer to an allocated buffer of a certian pool type.
513 Allocates the number bytes specified by AllocationSize of a certian pool type, copies
514 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
515 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
516 is not enough memory remaining to satisfy the request, then NULL is returned.
517 If Buffer is NULL, then ASSERT().
518 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
520 @param PoolType The type of pool to allocate.
521 @param AllocationSize The number of bytes to allocate and zero.
522 @param Buffer The buffer to copy to the allocated buffer.
524 @return A pointer to the allocated buffer or NULL if allocation fails.
528 InternalAllocateCopyPool (
529 IN EFI_MEMORY_TYPE PoolType
,
530 IN UINTN AllocationSize
,
531 IN CONST VOID
*Buffer
536 ASSERT (Buffer
!= NULL
);
537 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
539 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
540 if (Memory
!= NULL
) {
541 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
547 Copies a buffer to an allocated buffer of type EfiBootServicesData.
549 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
550 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
551 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
552 is not enough memory remaining to satisfy the request, then NULL is returned.
553 If Buffer is NULL, then ASSERT().
554 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
556 @param AllocationSize The number of bytes to allocate and zero.
557 @param Buffer The buffer to copy to the allocated buffer.
559 @return A pointer to the allocated buffer or NULL if allocation fails.
564 GlueAllocateCopyPool (
565 IN UINTN AllocationSize
,
566 IN CONST VOID
*Buffer
571 ASSERT (Buffer
!= NULL
);
572 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
574 Memory
= AllocatePool (AllocationSize
);
575 if (Memory
!= NULL
) {
576 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
582 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
584 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
585 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
586 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
587 is not enough memory remaining to satisfy the request, then NULL is returned.
588 If Buffer is NULL, then ASSERT().
589 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
591 @param AllocationSize The number of bytes to allocate and zero.
592 @param Buffer The buffer to copy to the allocated buffer.
594 @return A pointer to the allocated buffer or NULL if allocation fails.
599 AllocateRuntimeCopyPool (
600 IN UINTN AllocationSize
,
601 IN CONST VOID
*Buffer
604 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
608 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
610 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
611 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
612 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
613 is not enough memory remaining to satisfy the request, then NULL is returned.
614 If Buffer is NULL, then ASSERT().
615 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
617 @param AllocationSize The number of bytes to allocate and zero.
618 @param Buffer The buffer to copy to the allocated buffer.
620 @return A pointer to the allocated buffer or NULL if allocation fails.
625 AllocateReservedCopyPool (
626 IN UINTN AllocationSize
,
627 IN CONST VOID
*Buffer
630 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
634 Frees a buffer that was previously allocated with one of the pool allocation functions in the
635 Memory Allocation Library.
637 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
638 pool allocation services of the Memory Allocation Library.
639 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
642 @param Buffer Pointer to the buffer to free.
652 // PEI phase does not support to free pool, so leave it as NOP.
657 Allocates a buffer of a certain pool type at a specified alignment.
659 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
660 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
661 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
662 to satisfy the request, then NULL is returned.
663 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
665 @param PoolType The type of pool to allocate.
666 @param AllocationSize The number of bytes to allocate.
667 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.
668 If Alignment is zero, then byte alignment is used.
670 @return A pointer to the allocated buffer or NULL if allocation fails.
674 InternalAllocateAlignedPool (
675 IN EFI_MEMORY_TYPE PoolType
,
676 IN UINTN AllocationSize
,
681 UINTN AlignedAddress
;
685 // Alignment must be a power of two or zero.
687 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
689 if (Alignment
== 0) {
690 AlignmentMask
= Alignment
;
692 AlignmentMask
= Alignment
- 1;
695 // Make sure that AllocationSize plus AlignmentMask does not overflow.
697 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
699 RawAddress
= InternalAllocatePool (PoolType
, AllocationSize
+ AlignmentMask
);
701 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
703 return (VOID
*) AlignedAddress
;
707 Allocates a buffer of type EfiBootServicesData at a specified alignment.
709 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
710 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
711 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
712 alignment remaining to satisfy the request, then NULL is returned.
713 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
715 @param AllocationSize The number of bytes to allocate.
716 @param Alignment The requested alignment of the allocation. Must be a power of two.
717 If Alignment is zero, then byte alignment is used.
719 @return A pointer to the allocated buffer or NULL if allocation fails.
724 AllocateAlignedPool (
725 IN UINTN AllocationSize
,
730 UINTN AlignedAddress
;
734 // Alignment must be a power of two or zero.
736 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
738 if (Alignment
== 0) {
739 AlignmentMask
= Alignment
;
741 AlignmentMask
= Alignment
- 1;
745 // Make sure that AllocationSize plus AlignmentMask does not overflow.
747 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
749 RawAddress
= AllocatePool (AllocationSize
+ AlignmentMask
);
751 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
753 return (VOID
*) AlignedAddress
;
757 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
759 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
760 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
761 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
762 alignment remaining to satisfy the request, then NULL is returned.
763 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
765 @param AllocationSize The number of bytes to allocate.
766 @param Alignment The requested alignment of the allocation. Must be a power of two.
767 If Alignment is zero, then byte alignment is used.
769 @return A pointer to the allocated buffer or NULL if allocation fails.
774 AllocateAlignedRuntimePool (
775 IN UINTN AllocationSize
,
779 return InternalAllocateAlignedPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
783 Allocates a buffer of type EfieservedMemoryType at a specified alignment.
785 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
786 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
787 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
788 alignment remaining to satisfy the request, then NULL is returned.
789 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
791 @param AllocationSize The number of bytes to allocate.
792 @param Alignment The requested alignment of the allocation. Must be a power of two.
793 If Alignment is zero, then byte alignment is used.
795 @return A pointer to the allocated buffer or NULL if allocation fails.
800 AllocateAlignedReservedPool (
801 IN UINTN AllocationSize
,
805 return InternalAllocateAlignedPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
809 Allocates and zeros a buffer of a certain pool type at a specified alignment.
811 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
812 specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated
813 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not
814 enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.
815 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
817 @param PoolType The type of pool to allocate.
818 @param AllocationSize The number of bytes to allocate.
819 @param Alignment The requested alignment of the allocation. Must be a power of two.
820 If Alignment is zero, then byte alignment is used.
822 @return A pointer to the allocated buffer or NULL if allocation fails.
826 InternalAllocateAlignedZeroPool (
827 IN EFI_MEMORY_TYPE PoolType
,
828 IN UINTN AllocationSize
,
834 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
835 if (Memory
!= NULL
) {
836 Memory
= ZeroMem (Memory
, AllocationSize
);
842 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
844 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
845 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
846 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
847 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
849 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
851 @param AllocationSize The number of bytes to allocate.
852 @param Alignment The requested alignment of the allocation. Must be a power of two.
853 If Alignment is zero, then byte alignment is used.
855 @return A pointer to the allocated buffer or NULL if allocation fails.
860 AllocateAlignedZeroPool (
861 IN UINTN AllocationSize
,
867 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
868 if (Memory
!= NULL
) {
869 Memory
= ZeroMem (Memory
, AllocationSize
);
875 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
877 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
878 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
879 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
880 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
882 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
884 @param AllocationSize The number of bytes to allocate.
885 @param Alignment The requested alignment of the allocation. Must be a power of two.
886 If Alignment is zero, then byte alignment is used.
888 @return A pointer to the allocated buffer or NULL if allocation fails.
893 AllocateAlignedRuntimeZeroPool (
894 IN UINTN AllocationSize
,
898 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
902 Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
904 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
905 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
906 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
907 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
909 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
911 @param AllocationSize The number of bytes to allocate.
912 @param Alignment The requested alignment of the allocation. Must be a power of two.
913 If Alignment is zero, then byte alignment is used.
915 @return A pointer to the allocated buffer or NULL if allocation fails.
920 AllocateAlignedReservedZeroPool (
921 IN UINTN AllocationSize
,
925 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
929 Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.
931 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
932 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
933 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
934 to satisfy the request, then NULL is returned.
935 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
937 @param PoolType The type of pool to allocate.
938 @param AllocationSize The number of bytes to allocate.
939 @param Buffer The buffer to copy to the allocated buffer.
940 @param Alignment The requested alignment of the allocation. Must be a power of two.
941 If Alignment is zero, then byte alignment is used.
943 @return A pointer to the allocated buffer or NULL if allocation fails.
947 InternalAllocateAlignedCopyPool (
948 IN EFI_MEMORY_TYPE PoolType
,
949 IN UINTN AllocationSize
,
950 IN CONST VOID
*Buffer
,
956 ASSERT (Buffer
!= NULL
);
957 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
959 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
960 if (Memory
!= NULL
) {
961 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
967 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
969 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
970 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
971 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
972 alignment remaining to satisfy the request, then NULL is returned.
973 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
975 @param AllocationSize The number of bytes to allocate.
976 @param Buffer The buffer to copy to the allocated buffer.
977 @param Alignment The requested alignment of the allocation. Must be a power of two.
978 If Alignment is zero, then byte alignment is used.
980 @return A pointer to the allocated buffer or NULL if allocation fails.
985 AllocateAlignedCopyPool (
986 IN UINTN AllocationSize
,
987 IN CONST VOID
*Buffer
,
993 ASSERT (Buffer
!= NULL
);
994 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
996 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
997 if (Memory
!= NULL
) {
998 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
1004 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
1006 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
1007 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1008 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1009 alignment remaining to satisfy the request, then NULL is returned.
1010 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1012 @param AllocationSize The number of bytes to allocate.
1013 @param Buffer The buffer to copy to the allocated buffer.
1014 @param Alignment The requested alignment of the allocation. Must be a power of two.
1015 If Alignment is zero, then byte alignment is used.
1017 @return A pointer to the allocated buffer or NULL if allocation fails.
1022 AllocateAlignedRuntimeCopyPool (
1023 IN UINTN AllocationSize
,
1024 IN CONST VOID
*Buffer
,
1028 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
, Alignment
);
1032 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
1034 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
1035 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1036 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1037 alignment remaining to satisfy the request, then NULL is returned.
1038 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1040 @param AllocationSize The number of bytes to allocate.
1041 @param Buffer The buffer to copy to the allocated buffer.
1042 @param Alignment The requested alignment of the allocation. Must be a power of two.
1043 If Alignment is zero, then byte alignment is used.
1045 @return A pointer to the allocated buffer or NULL if allocation fails.
1050 AllocateAlignedReservedCopyPool (
1051 IN UINTN AllocationSize
,
1052 IN CONST VOID
*Buffer
,
1056 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
, Alignment
);
1060 Frees a buffer that was previously allocated with one of the aligned pool allocation functions
1061 in the Memory Allocation Library.
1063 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
1064 aligned pool allocation services of the Memory Allocation Library.
1065 If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
1066 Library, then ASSERT().
1068 @param Buffer Pointer to the buffer to free.
1078 // PEI phase does not support to free pool, so leave it as NOP.