]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/MemoryInitPei/MemoryInit.c
Add ArmPlatformPkg from ARM Ltd. patch.
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInit.c
CommitLineData
1d5d0ae9 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4* \r
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
12*\r
13**/\r
14\r
15//\r
16// The package level header files this module uses\r
17//\r
18#include <PiPei.h>\r
19//\r
20// The protocols, PPI and GUID defintions for this module\r
21//\r
22#include <Ppi/MasterBootMode.h>\r
23#include <Ppi/BootInRecoveryMode.h>\r
24#include <Guid/MemoryTypeInformation.h>\r
25//\r
26// The Library classes this module consumes\r
27//\r
28#include <Library/DebugLib.h>\r
29#include <Library/PeimEntryPoint.h>\r
30#include <Library/PcdLib.h>\r
31#include <Library/HobLib.h>\r
32#include <Library/PeiServicesLib.h>\r
33#include <Library/ArmLib.h>\r
34#include <Library/IoLib.h>\r
35#include <Library/ArmPlatformLib.h>\r
36\r
37//\r
38// Module globals\r
39//\r
40\r
41VOID\r
42InitMmu (\r
43 VOID\r
44 )\r
45{\r
46 ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
47 VOID *TranslationTableBase;\r
48 UINTN TranslationTableSize;\r
49\r
50 // Get Virtual Memory Map from the Platform Library\r
51 ArmPlatformGetVirtualMemoryMap(&MemoryTable);\r
52\r
53 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
54 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
55 ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
56}\r
57\r
58// May want to put this into a library so you only need the PCD setings if you are using the feature?\r
59VOID\r
60BuildMemoryTypeInformationHob (\r
61 VOID\r
62 )\r
63{\r
64 EFI_MEMORY_TYPE_INFORMATION Info[10];\r
65\r
66 Info[0].Type = EfiACPIReclaimMemory;\r
67 Info[0].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory);\r
68 Info[1].Type = EfiACPIMemoryNVS;\r
69 Info[1].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS);\r
70 Info[2].Type = EfiReservedMemoryType;\r
71 Info[2].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiReservedMemoryType);\r
72 Info[3].Type = EfiRuntimeServicesData;\r
73 Info[3].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData);\r
74 Info[4].Type = EfiRuntimeServicesCode;\r
75 Info[4].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode);\r
76 Info[5].Type = EfiBootServicesCode;\r
77 Info[5].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesCode);\r
78 Info[6].Type = EfiBootServicesData;\r
79 Info[6].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiBootServicesData);\r
80 Info[7].Type = EfiLoaderCode;\r
81 Info[7].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderCode);\r
82 Info[8].Type = EfiLoaderData;\r
83 Info[8].NumberOfPages = PcdGet32 (PcdMemoryTypeEfiLoaderData);\r
84 \r
85 // Terminator for the list\r
86 Info[9].Type = EfiMaxMemoryType;\r
87 Info[9].NumberOfPages = 0;\r
88\r
89\r
90 BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));\r
91}\r
92\r
93EFI_STATUS\r
94EFIAPI\r
95InitializeMemory (\r
96 IN EFI_PEI_FILE_HANDLE FileHandle,\r
97 IN CONST EFI_PEI_SERVICES **PeiServices\r
98 )\r
99/*++\r
100\r
101Routine Description:\r
102\r
103 \r
104\r
105Arguments:\r
106\r
107 FileHandle - Handle of the file being invoked.\r
108 PeiServices - Describes the list of possible PEI Services.\r
109 \r
110Returns:\r
111\r
112 Status - EFI_SUCCESS if the boot mode could be set\r
113\r
114--*/\r
115{\r
116 EFI_STATUS Status;\r
117 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR* EfiMemoryMap;\r
118 UINTN PeiMemoryBase;\r
119 UINTN PeiMemorySize;\r
120 UINTN Index;\r
121\r
122 DEBUG ((EFI_D_ERROR, "Memory Init PEIM Loaded\n"));\r
123\r
124 // If it is not a standalone version, then we need to initialize the System Memory\r
125 // In case of a standalone version, the DRAM is already initialized\r
126 if (FeaturePcdGet(PcdStandalone)) {\r
127 // Initialize the System Memory controller (DRAM)\r
128 ArmPlatformInitializeSystemMemory();\r
129 }\r
130\r
131 // Install the Memory to PEI\r
132 ArmPlatformGetPeiMemory (&PeiMemoryBase,&PeiMemorySize);\r
133 Status = PeiServicesInstallPeiMemory (PeiMemoryBase,PeiMemorySize);\r
134 ASSERT_EFI_ERROR (Status);\r
135\r
136 //\r
137 // Now, the permanent memory has been installed, we can call AllocatePages()\r
138 //\r
139\r
140 ArmPlatformGetEfiMemoryMap (&EfiMemoryMap);\r
141\r
142 // Install the EFI Memory Map\r
143 for (Index = 0; EfiMemoryMap[Index].ResourceAttribute != 0; Index++) {\r
144 BuildResourceDescriptorHob (\r
145 EFI_RESOURCE_SYSTEM_MEMORY,\r
146 EfiMemoryMap[Index].ResourceAttribute,\r
147 EfiMemoryMap[Index].PhysicalStart,\r
148 EfiMemoryMap[Index].NumberOfBytes\r
149 );\r
150 }\r
151\r
152 // Build Memory Allocation Hob\r
153 InitMmu ();\r
154\r
155 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
156 // Optional feature that helps prevent EFI memory map fragmentation. \r
157 BuildMemoryTypeInformationHob ();\r
158 }\r
159\r
160 return Status;\r
161}\r