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