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.
13 Module Name: MemoryAllocationLib.c
19 Allocates one or more 4KB pages of a certain memory type.
21 Allocates the number of 4KB pages of a certain memory type and returns a pointer to the allocated
22 buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL is returned.
23 If there is not enough memory remaining to satisfy the request, then NULL is returned.
25 @param MemoryType The type of memory to allocate.
26 @param Pages The number of 4 KB pages to allocate.
28 @return A pointer to the allocated buffer or NULL if allocation fails.
32 InternalAllocatePages (
33 IN EFI_MEMORY_TYPE MemoryType
,
38 EFI_PHYSICAL_ADDRESS Memory
;
39 EFI_PEI_SERVICES
**PeiServices
;
45 PeiServices
= GetPeiServicesTablePointer ();
46 Status
= (*PeiServices
)->AllocatePages (PeiServices
, MemoryType
, Pages
, &Memory
);
47 if (EFI_ERROR (Status
)) {
50 return (VOID
*) (UINTN
) Memory
;
54 Allocates one or more 4KB pages of type EfiBootServicesData.
56 Allocates the number of 4KB pages of type EfiBootServicesData and returns a pointer to the
57 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
58 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
61 @param Pages The number of 4 KB pages to allocate.
63 @return A pointer to the allocated buffer or NULL if allocation fails.
72 return InternalAllocatePages (EfiBootServicesData
, Pages
);
76 Allocates one or more 4KB pages of type EfiRuntimeServicesData.
78 Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the
79 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
80 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
83 @param Pages The number of 4 KB pages to allocate.
85 @return A pointer to the allocated buffer or NULL if allocation fails.
90 AllocateRuntimePages (
94 return InternalAllocatePages (EfiRuntimeServicesData
, Pages
);
98 Allocates one or more 4KB pages of type EfiReservedMemoryType.
100 Allocates the number of 4KB pages of type EfiReservedMemoryType and returns a pointer to the
101 allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL
102 is returned. If there is not enough memory remaining to satisfy the request, then NULL is
105 @param Pages The number of 4 KB pages to allocate.
107 @return A pointer to the allocated buffer or NULL if allocation fails.
112 AllocateReservedPages (
116 return InternalAllocatePages (EfiReservedMemoryType
, Pages
);
120 Frees one or more 4KB pages that were previously allocated with one of the page allocation
121 functions in the Memory Allocation Library.
123 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
124 must have been allocated on a previous call to the page allocation services of the Memory
126 If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
128 If Pages is zero, then ASSERT().
130 @param Buffer Pointer to the buffer of pages to free.
131 @param Pages The number of 4 KB pages to free.
142 // PEI phase does not support to free pages, so leave it as NOP.
147 Allocates one or more 4KB pages of a certain memory type at a specified alignment.
149 Allocates the number of 4KB pages specified by Pages of a certain memory type with an alignment
150 specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is returned.
151 If there is not enough memory at the specified alignment remaining to satisfy the request, then
153 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
155 @param MemoryType The type of memory to allocate.
156 @param Pages The number of 4 KB pages to allocate.
157 @param Alignment The requested alignment of the allocation. Must be a power of two.
158 If Alignment is zero, then byte alignment is used.
160 @return A pointer to the allocated buffer or NULL if allocation fails.
164 InternalAllocateAlignedPages (
165 IN EFI_MEMORY_TYPE MemoryType
,
174 // Alignment must be a power of two or zero.
176 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
182 // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
184 ASSERT (Pages
<= (MAX_ADDRESS
- EFI_SIZE_TO_PAGES (Alignment
)));
186 // We would rather waste some memory to save PEI code size.
188 Memory
= InternalAllocatePages (MemoryType
, Pages
+ EFI_SIZE_TO_PAGES (Alignment
));
189 if (Alignment
== 0) {
190 AlignmentMask
= Alignment
;
192 AlignmentMask
= Alignment
- 1;
194 return (VOID
*) (UINTN
) (((UINTN
) Memory
+ AlignmentMask
) & ~AlignmentMask
);
198 Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
200 Allocates the number of 4KB pages specified by Pages of type EfiBootServicesData with an
201 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
202 returned. If there is not enough memory at the specified alignment remaining to satisfy the
203 request, then NULL is returned.
204 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
206 @param Pages The number of 4 KB pages to allocate.
207 @param Alignment The requested alignment of the allocation. Must be a power of two.
208 If Alignment is zero, then byte alignment is used.
210 @return A pointer to the allocated buffer or NULL if allocation fails.
215 AllocateAlignedPages (
220 return InternalAllocateAlignedPages (EfiBootServicesData
, Pages
, Alignment
);
224 Allocates one or more 4KB pages of type EfiRuntimeServicesData at a specified alignment.
226 Allocates the number of 4KB pages specified by Pages of type EfiRuntimeServicesData with an
227 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
228 returned. If there is not enough memory at the specified alignment remaining to satisfy the
229 request, then NULL is returned.
230 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
232 @param Pages The number of 4 KB pages to allocate.
233 @param Alignment The requested alignment of the allocation. Must be a power of two.
234 If Alignment is zero, then byte alignment is used.
236 @return A pointer to the allocated buffer or NULL if allocation fails.
241 AllocateAlignedRuntimePages (
246 return InternalAllocateAlignedPages (EfiRuntimeServicesData
, Pages
, Alignment
);
250 Allocates one or more 4KB pages of type EfiReservedMemoryType at a specified alignment.
252 Allocates the number of 4KB pages specified by Pages of type EfiReservedMemoryType with an
253 alignment specified by Alignment. The allocated buffer is returned. If Pages is 0, then NULL is
254 returned. If there is not enough memory at the specified alignment remaining to satisfy the
255 request, then NULL is returned.
256 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
258 @param Pages The number of 4 KB pages to allocate.
259 @param Alignment The requested alignment of the allocation. Must be a power of two.
260 If Alignment is zero, then byte alignment is used.
262 @return A pointer to the allocated buffer or NULL if allocation fails.
267 AllocateAlignedReservedPages (
272 return InternalAllocateAlignedPages (EfiReservedMemoryType
, Pages
, Alignment
);
276 Frees one or more 4KB pages that were previously allocated with one of the aligned page
277 allocation functions in the Memory Allocation Library.
279 Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
280 must have been allocated on a previous call to the aligned page allocation services of the Memory
282 If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
283 Library, then ASSERT().
284 If Pages is zero, then ASSERT().
286 @param Buffer Pointer to the buffer of pages to free.
287 @param Pages The number of 4 KB pages to free.
298 // PEI phase does not support to free pages, so leave it as NOP.
303 Allocates a buffer of a certain pool type.
305 Allocates the number bytes specified by AllocationSize of a certain pool type and returns a
306 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
307 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
309 @param MemoryType The type of memory to allocate.
310 @param AllocationSize The number of bytes to allocate.
312 @return A pointer to the allocated buffer or NULL if allocation fails.
316 InternalAllocatePool (
317 IN EFI_MEMORY_TYPE MemoryType
,
318 IN UINTN AllocationSize
322 // If we need lots of small runtime/reserved memory type from PEI in the future,
323 // we can consider providing a more complex algorithm that allocates runtime pages and
324 // provide pool allocations from those pages.
326 return InternalAllocatePages (MemoryType
, EFI_SIZE_TO_PAGES (AllocationSize
));
330 Allocates a buffer of type EfiBootServicesData.
332 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData and returns a
333 pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
334 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
336 @param AllocationSize The number of bytes to allocate.
338 @return A pointer to the allocated buffer or NULL if allocation fails.
344 IN UINTN AllocationSize
348 EFI_PEI_SERVICES
**PeiServices
;
351 PeiServices
= GetPeiServicesTablePointer ();
353 Status
= (*PeiServices
)->AllocatePool (PeiServices
, AllocationSize
, &Buffer
);
354 if (EFI_ERROR (Status
)) {
361 Allocates a buffer of type EfiRuntimeServicesData.
363 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData and returns
364 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
365 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
367 @param AllocationSize The number of bytes to allocate.
369 @return A pointer to the allocated buffer or NULL if allocation fails.
374 AllocateRuntimePool (
375 IN UINTN AllocationSize
378 return InternalAllocatePool (EfiRuntimeServicesData
, AllocationSize
);
382 Allocates a buffer of type EfieservedMemoryType.
384 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType and returns
385 a pointer to the allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is
386 returned. If there is not enough memory remaining to satisfy the request, then NULL is returned.
388 @param AllocationSize The number of bytes to allocate.
390 @return A pointer to the allocated buffer or NULL if allocation fails.
395 AllocateReservedPool (
396 IN UINTN AllocationSize
399 return InternalAllocatePool (EfiReservedMemoryType
, AllocationSize
);
403 Allocates and zeros a buffer of a certian pool type.
405 Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer
406 with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a valid
407 buffer of 0 size is returned. If there is not enough memory remaining to satisfy the request,
408 then NULL is returned.
410 @param PoolType The type of memory to allocate.
411 @param AllocationSize The number of bytes to allocate and zero.
413 @return A pointer to the allocated buffer or NULL if allocation fails.
417 InternalAllocateZeroPool (
418 IN EFI_MEMORY_TYPE PoolType
,
419 IN UINTN AllocationSize
424 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
425 if (Memory
!= NULL
) {
426 Memory
= ZeroMem (Memory
, AllocationSize
);
432 Allocates and zeros a buffer of type EfiBootServicesData.
434 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the
435 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
436 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
437 request, then NULL is returned.
439 @param AllocationSize The number of bytes to allocate and zero.
441 @return A pointer to the allocated buffer or NULL if allocation fails.
447 IN UINTN AllocationSize
452 Memory
= AllocatePool (AllocationSize
);
453 if (Memory
!= NULL
) {
454 Memory
= ZeroMem (Memory
, AllocationSize
);
460 Allocates and zeros a buffer of type EfiRuntimeServicesData.
462 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, clears the
463 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
464 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
465 request, then NULL is returned.
467 @param AllocationSize The number of bytes to allocate and zero.
469 @return A pointer to the allocated buffer or NULL if allocation fails.
474 AllocateRuntimeZeroPool (
475 IN UINTN AllocationSize
478 return InternalAllocateZeroPool (EfiRuntimeServicesData
, AllocationSize
);
482 Allocates and zeros a buffer of type EfiReservedMemoryType.
484 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, clears the
485 buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a
486 valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the
487 request, then NULL is returned.
489 @param AllocationSize The number of bytes to allocate and zero.
491 @return A pointer to the allocated buffer or NULL if allocation fails.
496 AllocateReservedZeroPool (
497 IN UINTN AllocationSize
500 return InternalAllocateZeroPool (EfiReservedMemoryType
, AllocationSize
);
504 Copies a buffer to an allocated buffer of a certian pool type.
506 Allocates the number bytes specified by AllocationSize of a certian pool type, copies
507 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
508 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
509 is not enough memory remaining to satisfy the request, then NULL is returned.
510 If Buffer is NULL, then ASSERT().
511 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
513 @param PoolType The type of pool to allocate.
514 @param AllocationSize The number of bytes to allocate and zero.
515 @param Buffer The buffer to copy to the allocated buffer.
517 @return A pointer to the allocated buffer or NULL if allocation fails.
521 InternalAllocateCopyPool (
522 IN EFI_MEMORY_TYPE PoolType
,
523 IN UINTN AllocationSize
,
524 IN CONST VOID
*Buffer
529 ASSERT (Buffer
!= NULL
);
530 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
532 Memory
= InternalAllocatePool (PoolType
, AllocationSize
);
533 if (Memory
!= NULL
) {
534 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
540 Copies a buffer to an allocated buffer of type EfiBootServicesData.
542 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, copies
543 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
544 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
545 is not enough memory remaining to satisfy the request, then NULL is returned.
546 If Buffer is NULL, then ASSERT().
547 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
549 @param AllocationSize The number of bytes to allocate and zero.
550 @param Buffer The buffer to copy to the allocated buffer.
552 @return A pointer to the allocated buffer or NULL if allocation fails.
558 IN UINTN AllocationSize
,
559 IN CONST VOID
*Buffer
564 ASSERT (Buffer
!= NULL
);
565 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
567 Memory
= AllocatePool (AllocationSize
);
568 if (Memory
!= NULL
) {
569 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
575 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData.
577 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData, copies
578 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
579 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
580 is not enough memory remaining to satisfy the request, then NULL is returned.
581 If Buffer is NULL, then ASSERT().
582 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
584 @param AllocationSize The number of bytes to allocate and zero.
585 @param Buffer The buffer to copy to the allocated buffer.
587 @return A pointer to the allocated buffer or NULL if allocation fails.
592 AllocateRuntimeCopyPool (
593 IN UINTN AllocationSize
,
594 IN CONST VOID
*Buffer
597 return InternalAllocateCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
);
601 Copies a buffer to an allocated buffer of type EfiReservedMemoryType.
603 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType, copies
604 AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the
605 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
606 is not enough memory remaining to satisfy the request, then NULL is returned.
607 If Buffer is NULL, then ASSERT().
608 If AllocationSize is greater than (MAX_ADDRESS ? Buffer + 1), then ASSERT().
610 @param AllocationSize The number of bytes to allocate and zero.
611 @param Buffer The buffer to copy to the allocated buffer.
613 @return A pointer to the allocated buffer or NULL if allocation fails.
618 AllocateReservedCopyPool (
619 IN UINTN AllocationSize
,
620 IN CONST VOID
*Buffer
623 return InternalAllocateCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
);
627 Frees a buffer that was previously allocated with one of the pool allocation functions in the
628 Memory Allocation Library.
630 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
631 pool allocation services of the Memory Allocation Library.
632 If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
635 @param Buffer Pointer to the buffer to free.
645 // PEI phase does not support to free pool, so leave it as NOP.
650 Allocates a buffer of a certain pool type at a specified alignment.
652 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
653 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
654 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
655 to satisfy the request, then NULL is returned.
656 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
658 @param PoolType The type of pool to allocate.
659 @param AllocationSize The number of bytes to allocate.
660 @param Alignment The requested alignment of the allocation. Must be a power of two. If Alignment is zero, then byte alignment is used.
661 If Alignment is zero, then byte alignment is used.
663 @return A pointer to the allocated buffer or NULL if allocation fails.
667 InternalAllocateAlignedPool (
668 IN EFI_MEMORY_TYPE PoolType
,
669 IN UINTN AllocationSize
,
674 UINTN AlignedAddress
;
678 // Alignment must be a power of two or zero.
680 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
682 if (Alignment
== 0) {
683 AlignmentMask
= Alignment
;
685 AlignmentMask
= Alignment
- 1;
688 // Make sure that AllocationSize plus AlignmentMask does not overflow.
690 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
692 RawAddress
= InternalAllocatePool (PoolType
, AllocationSize
+ AlignmentMask
);
694 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
696 return (VOID
*) AlignedAddress
;
700 Allocates a buffer of type EfiBootServicesData at a specified alignment.
702 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
703 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
704 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
705 alignment remaining to satisfy the request, then NULL is returned.
706 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
708 @param AllocationSize The number of bytes to allocate.
709 @param Alignment The requested alignment of the allocation. Must be a power of two.
710 If Alignment is zero, then byte alignment is used.
712 @return A pointer to the allocated buffer or NULL if allocation fails.
717 AllocateAlignedPool (
718 IN UINTN AllocationSize
,
723 UINTN AlignedAddress
;
727 // Alignment must be a power of two or zero.
729 ASSERT ((Alignment
& (Alignment
- 1)) == 0);
731 if (Alignment
== 0) {
732 AlignmentMask
= Alignment
;
734 AlignmentMask
= Alignment
- 1;
738 // Make sure that AllocationSize plus AlignmentMask does not overflow.
740 ASSERT (AllocationSize
<= (MAX_ADDRESS
- AlignmentMask
));
742 RawAddress
= AllocatePool (AllocationSize
+ AlignmentMask
);
744 AlignedAddress
= ((UINTN
) RawAddress
+ AlignmentMask
) & ~AlignmentMask
;
746 return (VOID
*) AlignedAddress
;
750 Allocates a buffer of type EfiRuntimeServicesData at a specified alignment.
752 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
753 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
754 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
755 alignment remaining to satisfy the request, then NULL is returned.
756 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
758 @param AllocationSize The number of bytes to allocate.
759 @param Alignment The requested alignment of the allocation. Must be a power of two.
760 If Alignment is zero, then byte alignment is used.
762 @return A pointer to the allocated buffer or NULL if allocation fails.
767 AllocateAlignedRuntimePool (
768 IN UINTN AllocationSize
,
772 return InternalAllocateAlignedPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
776 Allocates a buffer of type EfieservedMemoryType at a specified alignment.
778 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
779 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
780 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
781 alignment remaining to satisfy the request, then NULL is returned.
782 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
784 @param AllocationSize The number of bytes to allocate.
785 @param Alignment The requested alignment of the allocation. Must be a power of two.
786 If Alignment is zero, then byte alignment is used.
788 @return A pointer to the allocated buffer or NULL if allocation fails.
793 AllocateAlignedReservedPool (
794 IN UINTN AllocationSize
,
798 return InternalAllocateAlignedPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
802 Allocates and zeros a buffer of a certain pool type at a specified alignment.
804 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
805 specified by Alignment, clears the buffer with zeros, and returns a pointer to the allocated
806 buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there is not
807 enough memory at the specified alignment remaining to satisfy the request, then NULL is returned.
808 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
810 @param PoolType The type of pool to allocate.
811 @param AllocationSize The number of bytes to allocate.
812 @param Alignment The requested alignment of the allocation. Must be a power of two.
813 If Alignment is zero, then byte alignment is used.
815 @return A pointer to the allocated buffer or NULL if allocation fails.
819 InternalAllocateAlignedZeroPool (
820 IN EFI_MEMORY_TYPE PoolType
,
821 IN UINTN AllocationSize
,
827 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
828 if (Memory
!= NULL
) {
829 Memory
= ZeroMem (Memory
, AllocationSize
);
835 Allocates and zeros a buffer of type EfiBootServicesData at a specified alignment.
837 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData with an
838 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
839 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
840 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
842 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
844 @param AllocationSize The number of bytes to allocate.
845 @param Alignment The requested alignment of the allocation. Must be a power of two.
846 If Alignment is zero, then byte alignment is used.
848 @return A pointer to the allocated buffer or NULL if allocation fails.
853 AllocateAlignedZeroPool (
854 IN UINTN AllocationSize
,
860 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
861 if (Memory
!= NULL
) {
862 Memory
= ZeroMem (Memory
, AllocationSize
);
868 Allocates and zeros a buffer of type EfiRuntimeServicesData at a specified alignment.
870 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData with an
871 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
872 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
873 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
875 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
877 @param AllocationSize The number of bytes to allocate.
878 @param Alignment The requested alignment of the allocation. Must be a power of two.
879 If Alignment is zero, then byte alignment is used.
881 @return A pointer to the allocated buffer or NULL if allocation fails.
886 AllocateAlignedRuntimeZeroPool (
887 IN UINTN AllocationSize
,
891 return InternalAllocateAlignedZeroPool (EfiRuntimeServicesData
, AllocationSize
, Alignment
);
895 Allocates and zeros a buffer of type EfieservedMemoryType at a specified alignment.
897 Allocates the number bytes specified by AllocationSize of type EfieservedMemoryType with an
898 alignment specified by Alignment, clears the buffer with zeros, and returns a pointer to the
899 allocated buffer. If AllocationSize is 0, then a valid buffer of 0 size is returned. If there
900 is not enough memory at the specified alignment remaining to satisfy the request, then NULL is
902 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
904 @param AllocationSize The number of bytes to allocate.
905 @param Alignment The requested alignment of the allocation. Must be a power of two.
906 If Alignment is zero, then byte alignment is used.
908 @return A pointer to the allocated buffer or NULL if allocation fails.
913 AllocateAlignedReservedZeroPool (
914 IN UINTN AllocationSize
,
918 return InternalAllocateAlignedZeroPool (EfiReservedMemoryType
, AllocationSize
, Alignment
);
922 Copies a buffer to an allocated buffer of a certain pool type at a specified alignment.
924 Allocates the number bytes specified by AllocationSize of a certain pool type with an alignment
925 specified by Alignment. The allocated buffer is returned. If AllocationSize is 0, then a valid
926 buffer of 0 size is returned. If there is not enough memory at the specified alignment remaining
927 to satisfy the request, then NULL is returned.
928 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
930 @param PoolType The type of pool to allocate.
931 @param AllocationSize The number of bytes to allocate.
932 @param Buffer The buffer to copy to the allocated buffer.
933 @param Alignment The requested alignment of the allocation. Must be a power of two.
934 If Alignment is zero, then byte alignment is used.
936 @return A pointer to the allocated buffer or NULL if allocation fails.
940 InternalAllocateAlignedCopyPool (
941 IN EFI_MEMORY_TYPE PoolType
,
942 IN UINTN AllocationSize
,
943 IN CONST VOID
*Buffer
,
949 ASSERT (Buffer
!= NULL
);
950 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
952 Memory
= InternalAllocateAlignedPool (PoolType
, AllocationSize
, Alignment
);
953 if (Memory
!= NULL
) {
954 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
960 Copies a buffer to an allocated buffer of type EfiBootServicesData at a specified alignment.
962 Allocates the number bytes specified by AllocationSize of type EfiBootServicesData type with an
963 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
964 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
965 alignment remaining to satisfy the request, then NULL is returned.
966 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
968 @param AllocationSize The number of bytes to allocate.
969 @param Buffer The buffer to copy to the allocated buffer.
970 @param Alignment The requested alignment of the allocation. Must be a power of two.
971 If Alignment is zero, then byte alignment is used.
973 @return A pointer to the allocated buffer or NULL if allocation fails.
978 AllocateAlignedCopyPool (
979 IN UINTN AllocationSize
,
980 IN CONST VOID
*Buffer
,
986 ASSERT (Buffer
!= NULL
);
987 ASSERT (AllocationSize
<= (MAX_ADDRESS
- (UINTN
) Buffer
+ 1));
989 Memory
= AllocateAlignedPool (AllocationSize
, Alignment
);
990 if (Memory
!= NULL
) {
991 Memory
= CopyMem (Memory
, Buffer
, AllocationSize
);
997 Copies a buffer to an allocated buffer of type EfiRuntimeServicesData at a specified alignment.
999 Allocates the number bytes specified by AllocationSize of type EfiRuntimeServicesData type with an
1000 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1001 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1002 alignment remaining to satisfy the request, then NULL is returned.
1003 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1005 @param AllocationSize The number of bytes to allocate.
1006 @param Buffer The buffer to copy to the allocated buffer.
1007 @param Alignment The requested alignment of the allocation. Must be a power of two.
1008 If Alignment is zero, then byte alignment is used.
1010 @return A pointer to the allocated buffer or NULL if allocation fails.
1015 AllocateAlignedRuntimeCopyPool (
1016 IN UINTN AllocationSize
,
1017 IN CONST VOID
*Buffer
,
1021 return InternalAllocateAlignedCopyPool (EfiRuntimeServicesData
, AllocationSize
, Buffer
, Alignment
);
1025 Copies a buffer to an allocated buffer of type EfiReservedMemoryType at a specified alignment.
1027 Allocates the number bytes specified by AllocationSize of type EfiReservedMemoryType type with an
1028 alignment specified by Alignment. The allocated buffer is returned. If AllocationSize is 0,
1029 then a valid buffer of 0 size is returned. If there is not enough memory at the specified
1030 alignment remaining to satisfy the request, then NULL is returned.
1031 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
1033 @param AllocationSize The number of bytes to allocate.
1034 @param Buffer The buffer to copy to the allocated buffer.
1035 @param Alignment The requested alignment of the allocation. Must be a power of two.
1036 If Alignment is zero, then byte alignment is used.
1038 @return A pointer to the allocated buffer or NULL if allocation fails.
1043 AllocateAlignedReservedCopyPool (
1044 IN UINTN AllocationSize
,
1045 IN CONST VOID
*Buffer
,
1049 return InternalAllocateAlignedCopyPool (EfiReservedMemoryType
, AllocationSize
, Buffer
, Alignment
);
1053 Frees a buffer that was previously allocated with one of the aligned pool allocation functions
1054 in the Memory Allocation Library.
1056 Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
1057 aligned pool allocation services of the Memory Allocation Library.
1058 If Buffer was not allocated with an aligned pool allocation function in the Memory Allocation
1059 Library, then ASSERT().
1061 @param Buffer Pointer to the buffer to free.
1071 // PEI phase does not support to free pool, so leave it as NOP.