]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/PrePi/PrePi.c
OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events
[mirror_edk2.git] / ArmVirtPkg / PrePi / PrePi.c
1 /** @file
2 *
3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
6 *
7 **/
8
9 #include <PiPei.h>
10 #include <Pi/PiBootMode.h>
11
12 #include <Library/PeCoffLib.h>
13 #include <Library/PrePiLib.h>
14 #include <Library/PrintLib.h>
15 #include <Library/PrePiHobListPointerLib.h>
16 #include <Library/TimerLib.h>
17 #include <Library/PerformanceLib.h>
18 #include <Library/CacheMaintenanceLib.h>
19
20 #include <Ppi/GuidedSectionExtraction.h>
21 #include <Ppi/ArmMpCoreInfo.h>
22
23 #include "PrePi.h"
24
25 VOID
26 EFIAPI
27 ProcessLibraryConstructorList (
28 VOID
29 );
30
31 VOID
32 PrePiMain (
33 IN UINTN UefiMemoryBase,
34 IN UINTN StacksBase,
35 IN UINT64 StartTimeStamp
36 )
37 {
38 EFI_HOB_HANDOFF_INFO_TABLE* HobList;
39 EFI_STATUS Status;
40 CHAR8 Buffer[100];
41 UINTN CharCount;
42 UINTN StacksSize;
43
44 // Initialize the architecture specific bits
45 ArchInitialize ();
46
47 // Declare the PI/UEFI memory region
48 HobList = HobConstructor (
49 (VOID*)UefiMemoryBase,
50 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
51 (VOID*)UefiMemoryBase,
52 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks
53 );
54 PrePeiSetHobList (HobList);
55
56 //
57 // Ensure that the loaded image is invalidated in the caches, so that any
58 // modifications we made with the caches and MMU off (such as the applied
59 // relocations) don't become invisible once we turn them on.
60 //
61 InvalidateDataCacheRange((VOID *)(UINTN)PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize));
62
63 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
64 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
65 ASSERT_EFI_ERROR (Status);
66
67 // Initialize the Serial Port
68 SerialPortInitialize ();
69 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",
70 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
71 SerialPortWrite ((UINT8 *) Buffer, CharCount);
72
73 // Create the Stacks HOB (reserve the memory for all stacks)
74 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
75 BuildStackHob (StacksBase, StacksSize);
76
77 //TODO: Call CpuPei as a library
78 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
79
80 // Set the Boot Mode
81 SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
82
83 // Initialize Platform HOBs (CpuHob and FvHob)
84 Status = PlatformPeim ();
85 ASSERT_EFI_ERROR (Status);
86
87 // Now, the HOB List has been initialized, we can register performance information
88 PERF_START (NULL, "PEI", NULL, StartTimeStamp);
89
90 // SEC phase needs to run library constructors by hand.
91 ProcessLibraryConstructorList ();
92
93 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
94 Status = DecompressFirstFv ();
95 ASSERT_EFI_ERROR (Status);
96
97 // Load the DXE Core and transfer control to it
98 Status = LoadDxeCoreFromFv (NULL, 0);
99 ASSERT_EFI_ERROR (Status);
100 }
101
102 VOID
103 CEntryPoint (
104 IN UINTN MpId,
105 IN UINTN UefiMemoryBase,
106 IN UINTN StacksBase
107 )
108 {
109 UINT64 StartTimeStamp;
110
111 if (PerformanceMeasurementEnabled ()) {
112 // Initialize the Timer Library to setup the Timer HW controller
113 TimerConstructor ();
114 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
115 StartTimeStamp = GetPerformanceCounter ();
116 } else {
117 StartTimeStamp = 0;
118 }
119
120 // Data Cache enabled on Primary core when MMU is enabled.
121 ArmDisableDataCache ();
122 // Invalidate instruction cache
123 ArmInvalidateInstructionCache ();
124 // Enable Instruction Caches on all cores.
125 ArmEnableInstructionCache ();
126
127 PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);
128
129 // DXE Core should always load and never return
130 ASSERT (FALSE);
131 }
132
133 VOID
134 RelocatePeCoffImage (
135 IN EFI_PEI_FV_HANDLE FwVolHeader,
136 IN PE_COFF_LOADER_READ_FILE ImageRead
137 )
138 {
139 EFI_PEI_FILE_HANDLE FileHandle;
140 VOID *SectionData;
141 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
142 EFI_STATUS Status;
143
144 FileHandle = NULL;
145 Status = FfsFindNextFile (EFI_FV_FILETYPE_SECURITY_CORE, FwVolHeader,
146 &FileHandle);
147 ASSERT_EFI_ERROR (Status);
148
149 Status = FfsFindSectionData (EFI_SECTION_PE32, FileHandle, &SectionData);
150 if (EFI_ERROR (Status)) {
151 Status = FfsFindSectionData (EFI_SECTION_TE, FileHandle, &SectionData);
152 }
153 ASSERT_EFI_ERROR (Status);
154
155 ZeroMem (&ImageContext, sizeof ImageContext);
156
157 ImageContext.Handle = (EFI_HANDLE)SectionData;
158 ImageContext.ImageRead = ImageRead;
159 PeCoffLoaderGetImageInfo (&ImageContext);
160
161 if (ImageContext.ImageAddress != (UINTN)SectionData) {
162 ImageContext.ImageAddress = (UINTN)SectionData;
163 PeCoffLoaderRelocateImage (&ImageContext);
164 }
165 }