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