]>
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/UefiBootServicesTableLib.h>\r | |
18 | #include <Library/DxeServicesLib.h>\r | |
19 | \r | |
20 | /**\r | |
21 | Allocates one or more 4KB pages of a given type from a memory region that is\r | |
22 | accessible to PEI.\r | |
23 | \r | |
24 | Allocates the number of 4KB pages of type 'MemoryType' and returns a\r | |
25 | pointer to the allocated buffer. The buffer returned is aligned on a 4KB\r | |
26 | boundary. If Pages is 0, then NULL is returned. If there is not enough\r | |
27 | memory remaining to satisfy the request, then NULL is returned.\r | |
28 | \r | |
29 | @param[in] MemoryType The memory type to allocate\r | |
30 | @param[in] Pages The number of 4 KB pages to allocate.\r | |
31 | \r | |
32 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
33 | \r | |
34 | **/\r | |
35 | VOID *\r | |
36 | EFIAPI\r | |
37 | AllocatePeiAccessiblePages (\r | |
38 | IN EFI_MEMORY_TYPE MemoryType,\r | |
39 | IN UINTN Pages\r | |
40 | )\r | |
41 | {\r | |
42 | EFI_STATUS Status;\r | |
43 | EFI_PHYSICAL_ADDRESS Memory;\r | |
44 | \r | |
45 | if (Pages == 0) {\r | |
46 | return NULL;\r | |
47 | }\r | |
48 | \r | |
49 | Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, Pages, &Memory);\r | |
50 | if (EFI_ERROR (Status)) {\r | |
51 | return NULL;\r | |
52 | }\r | |
53 | return (VOID *)(UINTN)Memory;\r | |
54 | }\r |