]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeServicesLib/Allocate.c
MdePkg: Replace BSD License with BSD+Patent License
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <PiDxe.h>
11 #include <Library/UefiBootServicesTableLib.h>
12 #include <Library/DxeServicesLib.h>
13
14 /**
15 Allocates one or more 4KB pages of a given type from a memory region that is
16 accessible to PEI.
17
18 Allocates the number of 4KB pages of type 'MemoryType' and returns a
19 pointer to the allocated buffer. The buffer returned is aligned on a 4KB
20 boundary. If Pages is 0, then NULL is returned. If there is not enough
21 memory remaining to satisfy the request, then NULL is returned.
22
23 @param[in] MemoryType The memory type to allocate
24 @param[in] Pages The number of 4 KB pages to allocate.
25
26 @return A pointer to the allocated buffer or NULL if allocation fails.
27
28 **/
29 VOID *
30 EFIAPI
31 AllocatePeiAccessiblePages (
32 IN EFI_MEMORY_TYPE MemoryType,
33 IN UINTN Pages
34 )
35 {
36 EFI_STATUS Status;
37 EFI_PHYSICAL_ADDRESS Memory;
38
39 if (Pages == 0) {
40 return NULL;
41 }
42
43 Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);
44 if (EFI_ERROR (Status)) {
45 return NULL;
46 }
47 return (VOID *)(UINTN)Memory;
48 }