]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/PrePi/PrePi.c
ArmVirtPkg/PrePi: move DRAM discovery code into PrePi
[mirror_edk2.git] / ArmVirtPkg / PrePi / PrePi.c
CommitLineData
f9a9d2dc
AB
1/** @file\r
2*\r
3* Copyright (c) 2011-2014, 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#include <PiPei.h>\r
16\r
17#include <Library/PrePiLib.h>\r
18#include <Library/PrintLib.h>\r
19#include <Library/PeCoffGetEntryPointLib.h>\r
20#include <Library/PrePiHobListPointerLib.h>\r
21#include <Library/TimerLib.h>\r
22#include <Library/PerformanceLib.h>\r
c9e5618f 23#include <Library/CacheMaintenanceLib.h>\r
f9a9d2dc
AB
24\r
25#include <Ppi/GuidedSectionExtraction.h>\r
26#include <Ppi/ArmMpCoreInfo.h>\r
27#include <Guid/LzmaDecompress.h>\r
f9a9d2dc
AB
28\r
29#include "PrePi.h"\r
30#include "LzmaDecompress.h"\r
31\r
af47c618 32VOID\r
f9a9d2dc 33EFIAPI\r
af47c618 34ProcessLibraryConstructorList (\r
f9a9d2dc
AB
35 VOID\r
36 );\r
37\r
f9a9d2dc
AB
38VOID\r
39PrePiMain (\r
40 IN UINTN UefiMemoryBase,\r
41 IN UINTN StacksBase,\r
f9a9d2dc
AB
42 IN UINT64 StartTimeStamp\r
43 )\r
44{\r
45 EFI_HOB_HANDOFF_INFO_TABLE* HobList;\r
46 EFI_STATUS Status;\r
47 CHAR8 Buffer[100];\r
48 UINTN CharCount;\r
49 UINTN StacksSize;\r
50\r
51 // Initialize the architecture specific bits\r
52 ArchInitialize ();\r
53\r
f9a9d2dc
AB
54 // Declare the PI/UEFI memory region\r
55 HobList = HobConstructor (\r
56 (VOID*)UefiMemoryBase,\r
57 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),\r
58 (VOID*)UefiMemoryBase,\r
59 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks\r
60 );\r
61 PrePeiSetHobList (HobList);\r
62\r
c9e5618f
AB
63 //\r
64 // Ensure that the loaded image is invalidated in the caches, so that any\r
65 // modifications we made with the caches and MMU off (such as the applied\r
66 // relocations) don't become invisible once we turn them on.\r
67 //\r
68 InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));\r
69\r
f9a9d2dc
AB
70 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)\r
71 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));\r
72 ASSERT_EFI_ERROR (Status);\r
73\r
c9e5618f
AB
74 // Initialize the Serial Port\r
75 SerialPortInitialize ();\r
76 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",\r
77 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);\r
78 SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
79\r
f9a9d2dc
AB
80 // Create the Stacks HOB (reserve the memory for all stacks)\r
81 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);\r
82 BuildStackHob (StacksBase, StacksSize);\r
83\r
f9a9d2dc
AB
84 //TODO: Call CpuPei as a library\r
85 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r
86\r
87 // Set the Boot Mode\r
88 SetBootMode (ArmPlatformGetBootMode ());\r
89\r
90 // Initialize Platform HOBs (CpuHob and FvHob)\r
91 Status = PlatformPeim ();\r
92 ASSERT_EFI_ERROR (Status);\r
93\r
94 // Now, the HOB List has been initialized, we can register performance information\r
95 PERF_START (NULL, "PEI", NULL, StartTimeStamp);\r
96\r
97 // SEC phase needs to run library constructors by hand.\r
af47c618 98 ProcessLibraryConstructorList ();\r
f9a9d2dc
AB
99\r
100 // Build HOBs to pass up our version of stuff the DXE Core needs to save space\r
101 BuildPeCoffLoaderHob ();\r
102 BuildExtractSectionHob (\r
103 &gLzmaCustomDecompressGuid,\r
104 LzmaGuidedSectionGetInfo,\r
105 LzmaGuidedSectionExtraction\r
106 );\r
107\r
108 // Assume the FV that contains the SEC (our code) also contains a compressed FV.\r
109 Status = DecompressFirstFv ();\r
110 ASSERT_EFI_ERROR (Status);\r
111\r
112 // Load the DXE Core and transfer control to it\r
113 Status = LoadDxeCoreFromFv (NULL, 0);\r
114 ASSERT_EFI_ERROR (Status);\r
115}\r
116\r
117VOID\r
118CEntryPoint (\r
119 IN UINTN MpId,\r
120 IN UINTN UefiMemoryBase,\r
5eeba3b7 121 IN UINTN StacksBase\r
f9a9d2dc
AB
122 )\r
123{\r
124 UINT64 StartTimeStamp;\r
125\r
126 // Initialize the platform specific controllers\r
127 ArmPlatformInitialize (MpId);\r
128\r
129 if (PerformanceMeasurementEnabled ()) {\r
130 // Initialize the Timer Library to setup the Timer HW controller\r
131 TimerConstructor ();\r
132 // We cannot call yet the PerformanceLib because the HOB List has not been initialized\r
133 StartTimeStamp = GetPerformanceCounter ();\r
134 } else {\r
135 StartTimeStamp = 0;\r
136 }\r
137\r
138 // Data Cache enabled on Primary core when MMU is enabled.\r
139 ArmDisableDataCache ();\r
f9a9d2dc
AB
140 // Invalidate instruction cache\r
141 ArmInvalidateInstructionCache ();\r
142 // Enable Instruction Caches on all cores.\r
143 ArmEnableInstructionCache ();\r
144\r
5eeba3b7 145 PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);\r
f9a9d2dc
AB
146\r
147 // DXE Core should always load and never return\r
148 ASSERT (FALSE);\r
149}\r