]>
Commit | Line | Data |
---|---|---|
a40e0b7a AB |
1 | /** @file\r |
2 | DxeServicesLib memory allocation routines\r | |
3 | \r | |
4 | Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>\r | |
5 | \r | |
9344f092 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a40e0b7a AB |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | #include <PiDxe.h>\r | |
11 | #include <Library/UefiBootServicesTableLib.h>\r | |
12 | #include <Library/DxeServicesLib.h>\r | |
13 | \r | |
14 | /**\r | |
15 | Allocates one or more 4KB pages of a given type from a memory region that is\r | |
16 | accessible to PEI.\r | |
17 | \r | |
18 | Allocates the number of 4KB pages of type 'MemoryType' and returns a\r | |
19 | pointer to the allocated buffer. The buffer returned is aligned on a 4KB\r | |
20 | boundary. If Pages is 0, then NULL is returned. If there is not enough\r | |
21 | memory remaining to satisfy the request, then NULL is returned.\r | |
22 | \r | |
23 | @param[in] MemoryType The memory type to allocate\r | |
24 | @param[in] Pages The number of 4 KB pages to allocate.\r | |
25 | \r | |
26 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
27 | \r | |
28 | **/\r | |
29 | VOID *\r | |
30 | EFIAPI\r | |
31 | AllocatePeiAccessiblePages (\r | |
32 | IN EFI_MEMORY_TYPE MemoryType,\r | |
33 | IN UINTN Pages\r | |
34 | )\r | |
35 | {\r | |
2f88bd3a MK |
36 | EFI_STATUS Status;\r |
37 | EFI_PHYSICAL_ADDRESS Memory;\r | |
a40e0b7a AB |
38 | \r |
39 | if (Pages == 0) {\r | |
40 | return NULL;\r | |
41 | }\r | |
42 | \r | |
43 | Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r | |
44 | if (EFI_ERROR (Status)) {\r | |
45 | return NULL;\r | |
46 | }\r | |
2f88bd3a | 47 | \r |
a40e0b7a AB |
48 | return (VOID *)(UINTN)Memory;\r |
49 | }\r |