]> git.proxmox.com Git - mirror_edk2.git/blob - BeagleBoardPkg/PrePi/PrePi.c
46f63f40c46e4b236f8998fdc22d5bc283ad95a0
[mirror_edk2.git] / BeagleBoardPkg / PrePi / PrePi.c
1 /** @file
2 *
3 * Copyright (c) 2011-2017, ARM Limited. All rights reserved.
4 * Copyright (c) 2017, Linaro, Ltd. All rights reserved.
5 *
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
10 *
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 *
14 **/
15
16 #include <PiPei.h>
17
18 #include <Library/DebugAgentLib.h>
19 #include <Library/PrePiLib.h>
20 #include <Library/PrintLib.h>
21 #include <Library/PeCoffGetEntryPointLib.h>
22 #include <Library/PrePiHobListPointerLib.h>
23 #include <Library/TimerLib.h>
24 #include <Library/PerformanceLib.h>
25
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Ppi/ArmMpCoreInfo.h>
28 #include <Ppi/SecPerformance.h>
29 #include <Guid/LzmaDecompress.h>
30
31 #include "PrePi.h"
32 #include "LzmaDecompress.h"
33
34 #define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \
35 ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))
36
37 UINT64 mSystemMemoryEnd = FixedPcdGet64(PcdSystemMemoryBase) +
38 FixedPcdGet64(PcdSystemMemorySize) - 1;
39
40 EFI_STATUS
41 GetPlatformPpi (
42 IN EFI_GUID *PpiGuid,
43 OUT VOID **Ppi
44 )
45 {
46 UINTN PpiListSize;
47 UINTN PpiListCount;
48 EFI_PEI_PPI_DESCRIPTOR *PpiList;
49 UINTN Index;
50
51 PpiListSize = 0;
52 ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
53 PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR);
54 for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
55 if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {
56 *Ppi = PpiList->Ppi;
57 return EFI_SUCCESS;
58 }
59 }
60
61 return EFI_NOT_FOUND;
62 }
63
64 VOID
65 PrePiMain (
66 IN UINTN UefiMemoryBase,
67 IN UINTN StacksBase,
68 IN UINT64 StartTimeStamp
69 )
70 {
71 EFI_HOB_HANDOFF_INFO_TABLE* HobList;
72 EFI_STATUS Status;
73 CHAR8 Buffer[100];
74 UINTN CharCount;
75 UINTN StacksSize;
76 FIRMWARE_SEC_PERFORMANCE Performance;
77
78 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
79 ASSERT (IS_XIP() ||
80 ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&
81 ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd)));
82
83 // Initialize the architecture specific bits
84 ArchInitialize ();
85
86 // Initialize the Serial Port
87 SerialPortInitialize ();
88 CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r",
89 (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
90 SerialPortWrite ((UINT8 *) Buffer, CharCount);
91
92 // Initialize the Debug Agent for Source Level Debugging
93 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
94 SaveAndSetDebugTimerInterrupt (TRUE);
95
96 // Declare the PI/UEFI memory region
97 HobList = HobConstructor (
98 (VOID*)UefiMemoryBase,
99 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
100 (VOID*)UefiMemoryBase,
101 (VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks
102 );
103 PrePeiSetHobList (HobList);
104
105 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
106 Status = MemoryPeim (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
107 ASSERT_EFI_ERROR (Status);
108
109 StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
110 BuildStackHob (StacksBase, StacksSize);
111
112 //TODO: Call CpuPei as a library
113 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
114
115 // Store timer value logged at the beginning of firmware image execution
116 Performance.ResetEnd = GetTimeInNanoSecond (StartTimeStamp);
117
118 // Build SEC Performance Data Hob
119 BuildGuidDataHob (&gEfiFirmwarePerformanceGuid, &Performance, sizeof (Performance));
120
121 // Set the Boot Mode
122 SetBootMode (ArmPlatformGetBootMode ());
123
124 // Initialize Platform HOBs (CpuHob and FvHob)
125 Status = PlatformPeim ();
126 ASSERT_EFI_ERROR (Status);
127
128 // Now, the HOB List has been initialized, we can register performance information
129 PERF_START (NULL, "PEI", NULL, StartTimeStamp);
130
131 // SEC phase needs to run library constructors by hand.
132 ProcessLibraryConstructorList ();
133
134 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
135 BuildPeCoffLoaderHob ();
136 BuildExtractSectionHob (
137 &gLzmaCustomDecompressGuid,
138 LzmaGuidedSectionGetInfo,
139 LzmaGuidedSectionExtraction
140 );
141
142 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
143 Status = DecompressFirstFv ();
144 ASSERT_EFI_ERROR (Status);
145
146 // Load the DXE Core and transfer control to it
147 Status = LoadDxeCoreFromFv (NULL, 0);
148 ASSERT_EFI_ERROR (Status);
149 }
150
151 VOID
152 CEntryPoint (
153 IN UINTN MpId,
154 IN UINTN UefiMemoryBase,
155 IN UINTN StacksBase
156 )
157 {
158 UINT64 StartTimeStamp;
159
160 // Initialize the platform specific controllers
161 ArmPlatformInitialize (MpId);
162
163 if (PerformanceMeasurementEnabled ()) {
164 // Initialize the Timer Library to setup the Timer HW controller
165 TimerConstructor ();
166 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
167 StartTimeStamp = GetPerformanceCounter ();
168 } else {
169 StartTimeStamp = 0;
170 }
171
172 // Data Cache enabled on Primary core when MMU is enabled.
173 ArmDisableDataCache ();
174 // Invalidate Data cache
175 ArmInvalidateDataCache ();
176 // Invalidate instruction cache
177 ArmInvalidateInstructionCache ();
178 // Enable Instruction Caches on all cores.
179 ArmEnableInstructionCache ();
180
181 PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);
182
183 // DXE Core should always load and never return
184 ASSERT (FALSE);
185 }