]>
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 | |
6 | This program and the accompanying materials are licensed and made available\r | |
7 | under the terms and conditions of the BSD License which accompanies this\r | |
8 | distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php.\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include <PiDxe.h>\r | |
17 | #include <Library/HobLib.h>\r | |
18 | #include <Library/UefiBootServicesTableLib.h>\r | |
19 | #include <Library/DxeServicesLib.h>\r | |
20 | \r | |
21 | /**\r | |
22 | Allocates one or more 4KB pages of a given type from a memory region that is\r | |
23 | accessible to PEI.\r | |
24 | \r | |
25 | Allocates the number of 4KB pages of type 'MemoryType' and returns a\r | |
26 | pointer to the allocated buffer. The buffer returned is aligned on a 4KB\r | |
27 | boundary. If Pages is 0, then NULL is returned. If there is not enough\r | |
28 | memory remaining to satisfy the request, then NULL is returned.\r | |
29 | \r | |
30 | @param[in] MemoryType The memory type to allocate\r | |
31 | @param[in] Pages The number of 4 KB pages to allocate.\r | |
32 | \r | |
33 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
34 | \r | |
35 | **/\r | |
36 | VOID *\r | |
37 | EFIAPI\r | |
38 | AllocatePeiAccessiblePages (\r | |
39 | IN EFI_MEMORY_TYPE MemoryType,\r | |
40 | IN UINTN Pages\r | |
41 | )\r | |
42 | {\r | |
43 | EFI_STATUS Status;\r | |
44 | EFI_ALLOCATE_TYPE AllocType;\r | |
45 | EFI_PHYSICAL_ADDRESS Memory;\r | |
46 | EFI_HOB_HANDOFF_INFO_TABLE *PhitHob;\r | |
47 | \r | |
48 | if (Pages == 0) {\r | |
49 | return NULL;\r | |
50 | }\r | |
51 | \r | |
52 | AllocType = AllocateAnyPages;\r | |
53 | //\r | |
54 | // A X64 build of DXE may be combined with a 32-bit build of PEI, and so we\r | |
55 | // need to check the memory limit set by PEI, and allocate below 4 GB if the\r | |
56 | // limit is set to 4 GB or lower.\r | |
57 | //\r | |
58 | PhitHob = (EFI_HOB_HANDOFF_INFO_TABLE *)GetHobList ();\r | |
59 | if (PhitHob->EfiFreeMemoryTop <= MAX_UINT32) {\r | |
60 | AllocType = AllocateMaxAddress;\r | |
61 | Memory = MAX_UINT32;\r | |
62 | }\r | |
63 | \r | |
64 | Status = gBS->AllocatePages (AllocType, MemoryType, Pages, &Memory);\r | |
65 | if (EFI_ERROR (Status)) {\r | |
66 | return NULL;\r | |
67 | }\r | |
68 | return (VOID *)(UINTN)Memory;\r | |
69 | }\r |