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