]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011, ARM Limited. All rights reserved.\r | |
4 | *\r | |
5 | * SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | *\r | |
7 | **/\r | |
8 | \r | |
9 | #include <PiPei.h>\r | |
10 | \r | |
11 | //\r | |
12 | // The protocols, PPI and GUID definitions for this module\r | |
13 | //\r | |
14 | #include <Ppi/MasterBootMode.h>\r | |
15 | #include <Ppi/BootInRecoveryMode.h>\r | |
16 | #include <Guid/MemoryTypeInformation.h>\r | |
17 | //\r | |
18 | // The Library classes this module consumes\r | |
19 | //\r | |
20 | #include <Library/ArmPlatformLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
22 | #include <Library/HobLib.h>\r | |
23 | #include <Library/PeimEntryPoint.h>\r | |
24 | #include <Library/PeiServicesLib.h>\r | |
25 | #include <Library/PcdLib.h>\r | |
26 | \r | |
27 | EFI_STATUS\r | |
28 | EFIAPI\r | |
29 | MemoryPeim (\r | |
30 | IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r | |
31 | IN UINT64 UefiMemorySize\r | |
32 | );\r | |
33 | \r | |
34 | // May want to put this into a library so you only need the PCD settings if you are using the feature?\r | |
35 | VOID\r | |
36 | BuildMemoryTypeInformationHob (\r | |
37 | VOID\r | |
38 | )\r | |
39 | {\r | |
40 | EFI_MEMORY_TYPE_INFORMATION Info[10];\r | |
41 | \r | |
42 | Info[0].Type = EfiACPIReclaimMemory;\r | |
43 | Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);\r | |
44 | Info[1].Type = EfiACPIMemoryNVS;\r | |
45 | Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);\r | |
46 | Info[2].Type = EfiReservedMemoryType;\r | |
47 | Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);\r | |
48 | Info[3].Type = EfiRuntimeServicesData;\r | |
49 | Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);\r | |
50 | Info[4].Type = EfiRuntimeServicesCode;\r | |
51 | Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);\r | |
52 | Info[5].Type = EfiBootServicesCode;\r | |
53 | Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);\r | |
54 | Info[6].Type = EfiBootServicesData;\r | |
55 | Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);\r | |
56 | Info[7].Type = EfiLoaderCode;\r | |
57 | Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);\r | |
58 | Info[8].Type = EfiLoaderData;\r | |
59 | Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);\r | |
60 | \r | |
61 | // Terminator for the list\r | |
62 | Info[9].Type = EfiMaxMemoryType;\r | |
63 | Info[9].NumberOfPages = 0;\r | |
64 | \r | |
65 | BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));\r | |
66 | }\r | |
67 | \r | |
68 | /*++\r | |
69 | \r | |
70 | Routine Description:\r | |
71 | \r | |
72 | \r | |
73 | \r | |
74 | Arguments:\r | |
75 | \r | |
76 | FileHandle - Handle of the file being invoked.\r | |
77 | PeiServices - Describes the list of possible PEI Services.\r | |
78 | \r | |
79 | Returns:\r | |
80 | \r | |
81 | Status - EFI_SUCCESS if the boot mode could be set\r | |
82 | \r | |
83 | --*/\r | |
84 | EFI_STATUS\r | |
85 | EFIAPI\r | |
86 | InitializeMemory (\r | |
87 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
88 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
89 | )\r | |
90 | {\r | |
91 | EFI_STATUS Status;\r | |
92 | UINTN SystemMemoryBase;\r | |
93 | UINT64 SystemMemoryTop;\r | |
94 | UINTN FdBase;\r | |
95 | UINTN FdTop;\r | |
96 | UINTN UefiMemoryBase;\r | |
97 | \r | |
98 | DEBUG ((EFI_D_LOAD | EFI_D_INFO, "Memory Init PEIM Loaded\n"));\r | |
99 | \r | |
100 | // Ensure PcdSystemMemorySize has been set\r | |
101 | ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r | |
102 | ASSERT (PcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS);\r | |
103 | \r | |
104 | SystemMemoryBase = (UINTN)PcdGet64 (PcdSystemMemoryBase);\r | |
105 | SystemMemoryTop = SystemMemoryBase + PcdGet64 (PcdSystemMemorySize);\r | |
106 | if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {\r | |
107 | SystemMemoryTop = (UINT64)MAX_ALLOC_ADDRESS + 1;\r | |
108 | }\r | |
109 | FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress);\r | |
110 | FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize);\r | |
111 | \r | |
112 | //\r | |
113 | // Declare the UEFI memory to PEI\r | |
114 | //\r | |
115 | \r | |
116 | // In case the firmware has been shadowed in the System Memory\r | |
117 | if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) {\r | |
118 | // Check if there is enough space between the top of the system memory and the top of the\r | |
119 | // firmware to place the UEFI memory (for PEI & DXE phases)\r | |
120 | if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) {\r | |
121 | UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r | |
122 | } else {\r | |
123 | // Check there is enough space for the UEFI memory\r | |
124 | ASSERT (SystemMemoryBase + FixedPcdGet32 (PcdSystemMemoryUefiRegionSize) <= FdBase);\r | |
125 | \r | |
126 | UefiMemoryBase = FdBase - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r | |
127 | }\r | |
128 | } else {\r | |
129 | // Check the Firmware does not overlapped with the system memory\r | |
130 | ASSERT ((FdBase < SystemMemoryBase) || (FdBase >= SystemMemoryTop));\r | |
131 | ASSERT ((FdTop <= SystemMemoryBase) || (FdTop > SystemMemoryTop));\r | |
132 | \r | |
133 | UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);\r | |
134 | }\r | |
135 | \r | |
136 | Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
137 | ASSERT_EFI_ERROR (Status);\r | |
138 | \r | |
139 | // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r | |
140 | Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r | |
141 | ASSERT_EFI_ERROR (Status);\r | |
142 | \r | |
143 | return Status;\r | |
144 | }\r |