]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeServicesLib/Allocate.c
MdePkg/DxeServicesLib: introduce AllocatePeiAccessiblePages routine
[mirror_edk2.git] / MdePkg / Library / DxeServicesLib / Allocate.c
1 /** @file
2 DxeServicesLib memory allocation routines
3
4 Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>
5
6 This program and the accompanying materials are licensed and made available
7 under the terms and conditions of the BSD License which accompanies this
8 distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <PiDxe.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/DxeServicesLib.h>
19
20 /**
21 Allocates one or more 4KB pages of a given type from a memory region that is
22 accessible to PEI.
23
24 Allocates the number of 4KB pages of type 'MemoryType' and returns a
25 pointer to the allocated buffer. The buffer returned is aligned on a 4KB
26 boundary. If Pages is 0, then NULL is returned. If there is not enough
27 memory remaining to satisfy the request, then NULL is returned.
28
29 @param[in] MemoryType The memory type to allocate
30 @param[in] Pages The number of 4 KB pages to allocate.
31
32 @return A pointer to the allocated buffer or NULL if allocation fails.
33
34 **/
35 VOID *
36 EFIAPI
37 AllocatePeiAccessiblePages (
38 IN EFI_MEMORY_TYPE MemoryType,
39 IN UINTN Pages
40 )
41 {
42 EFI_STATUS Status;
43 EFI_PHYSICAL_ADDRESS Memory;
44
45 if (Pages == 0) {
46 return NULL;
47 }
48
49 Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);
50 if (EFI_ERROR (Status)) {
51 return NULL;
52 }
53 return (VOID *)(UINTN)Memory;
54 }