]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Core/Pei/PeiMain/PeiMain.c
Add pair of performance macro function to measure the whole PEI phase's performance.
[mirror_edk2.git] / EdkModulePkg / Core / Pei / PeiMain / PeiMain.c
CommitLineData
a0b7c09f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 PeiMain.c\r
15\r
16Abstract:\r
17\r
18 Pei Core Main Entry Point\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
24#include <PeiMain.h>\r
25\r
26//\r
27//CAR is filled with this initial value during SEC phase\r
28//\r
29#define INIT_CAR_VALUE 0x5AA55AA5\r
30\r
31static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
32 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
33 &gEfiPeiMemoryDiscoveredPpiGuid,\r
34 NULL\r
35};\r
36\r
37//\r
38// Pei Core Module Variables\r
39//\r
40//\r
41static EFI_PEI_SERVICES mPS = {\r
42 {\r
43 PEI_SERVICES_SIGNATURE,\r
44 PEI_SERVICES_REVISION,\r
45 sizeof (EFI_PEI_SERVICES),\r
46 0,\r
47 0\r
48 },\r
49 PeiInstallPpi,\r
50 PeiReInstallPpi,\r
51 PeiLocatePpi,\r
52 PeiNotifyPpi,\r
53\r
54 PeiGetBootMode,\r
55 PeiSetBootMode,\r
56\r
57 PeiGetHobList,\r
58 PeiCreateHob,\r
59\r
60 PeiFvFindNextVolume,\r
61 PeiFfsFindNextFile,\r
62 PeiFfsFindSectionData,\r
63\r
64 PeiInstallPeiMemory,\r
65 PeiAllocatePages,\r
66 PeiAllocatePool,\r
67 (EFI_PEI_COPY_MEM)CopyMem,\r
68 (EFI_PEI_SET_MEM)SetMem,\r
69\r
70 PeiReportStatusCode,\r
71\r
72 PeiResetSystem\r
73};\r
74\r
75EFI_STATUS\r
76EFIAPI\r
77PeiCore (\r
78 IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r
79 IN PEI_CORE_INSTANCE *OldCoreData\r
80 )\r
81/*++\r
82\r
83Routine Description:\r
84\r
85 The entry routine to Pei Core, invoked by PeiMain during transition\r
86 from SEC to PEI. After switching stack in the PEI core, it will restart\r
87 with the old core data.\r
88\r
89Arguments:\r
90\r
91 PeiStartupDescriptor - Information and services provided by SEC phase.\r
92 OldCoreData - Pointer to old core data that is used to initialize the\r
93 core's data areas.\r
94\r
95Returns:\r
96\r
97 This function never returns\r
98 EFI_NOT_FOUND - Never reach\r
99\r
100--*/\r
101{\r
102 PEI_CORE_INSTANCE PrivateData;\r
103 EFI_STATUS Status;\r
104 PEI_CORE_TEMP_POINTERS TempPtr;\r
105 PEI_CORE_DISPATCH_DATA *DispatchData;\r
106 UINT64 mTick;\r
107\r
108 mTick = 0;\r
109\r
217f1d11 110 if (PerformanceMeasurementEnabled()) {\r
111 if (OldCoreData == NULL) {\r
112 mTick = GetPerformanceCounter ();\r
113 }\r
a0b7c09f 114 }\r
a0b7c09f 115\r
116 //\r
117 // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
118 // the 63-bit of address is set to 1.\r
119 //\r
120 SWITCH_TO_CACHE_MODE (OldCoreData);\r
121\r
122 if (OldCoreData != NULL) {\r
123 CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
124 } else {\r
125 ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
126 }\r
127\r
128 PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
129 PrivateData.PS = &mPS;\r
130\r
131 //\r
132 // Initialize libraries that the PeiCore is linked against\r
133 // BUGBUG: The FfsHeader is passed in as NULL. Do we look it up or remove it from the lib init?\r
134 //\r
135 ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
136\r
137 InitializeMemoryServices (&PrivateData.PS, PeiStartupDescriptor, OldCoreData);\r
138\r
139 InitializePpiServices (&PrivateData.PS, OldCoreData);\r
140\r
141 InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
142\r
143 InitializeDispatcherData (&PrivateData.PS, OldCoreData, PeiStartupDescriptor);\r
144\r
145 if (OldCoreData != NULL) {\r
146\r
147 PERF_END (NULL,"PreMem", NULL, 0);\r
148 PERF_START (NULL,"PostMem", NULL, 0);\r
149\r
150 //\r
151 // The following code dumps out interesting cache as RAM usage information\r
152 // so we can keep tabs on how the cache as RAM is being utilized. The\r
2ce31132 153 // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled\r
a0b7c09f 154 // on a debug build.\r
155 //\r
2ce31132 156 DEBUG_CODE_BEGIN ();\r
a0b7c09f 157 UINTN *StackPointer;\r
158 UINTN StackValue;\r
159\r
160 StackValue = INIT_CAR_VALUE;\r
161 for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
162 ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
163 && StackValue == INIT_CAR_VALUE;\r
164 StackPointer++) {\r
165 StackValue = *StackPointer;\r
166 }\r
167\r
168 DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
169 DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r
170 ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
171 ));\r
172 DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r
173 ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
174 (UINTN) OldCoreData->HobList.Raw)\r
175 ));\r
2ce31132 176 DEBUG_CODE_END ();\r
a0b7c09f 177\r
178 //\r
179 // Alert any listeners that there is permanent memory available\r
180 //\r
217f1d11 181 PERF_START (NULL,"PEI", NULL, mTick);\r
a0b7c09f 182 PERF_START (NULL,"DisMem", NULL, 0);\r
84a99d48 183 Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
a0b7c09f 184 PERF_END (NULL,"DisMem", NULL, 0);\r
185\r
186 } else {\r
187\r
188 //\r
189 // Report Status Code EFI_SW_PC_INIT\r
190 //\r
191 REPORT_STATUS_CODE (\r
192 EFI_PROGRESS_CODE,\r
193 EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r
194 );\r
195\r
196 //\r
197 // If first pass, start performance measurement.\r
198 //\r
199 PERF_START (NULL,"PreMem", NULL, mTick);\r
200\r
201 //\r
202 // If SEC provided any PPI services to PEI, install them.\r
203 //\r
204 if (PeiStartupDescriptor->DispatchTable != NULL) {\r
84a99d48 205 Status = PeiServicesInstallPpi (PeiStartupDescriptor->DispatchTable);\r
a0b7c09f 206 ASSERT_EFI_ERROR (Status);\r
207 }\r
208 }\r
209\r
210 DispatchData = &PrivateData.DispatchData;\r
211\r
212 //\r
213 // Call PEIM dispatcher\r
214 //\r
215 PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);\r
216\r
217 //\r
218 // Check if InstallPeiMemory service was called.\r
219 //\r
220 ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
221\r
222 PERF_END (NULL, "PostMem", NULL, 0);\r
223\r
84a99d48 224 Status = PeiServicesLocatePpi (\r
a0b7c09f 225 &gEfiDxeIplPpiGuid,\r
226 0,\r
227 NULL,\r
228 (VOID **)&TempPtr.DxeIpl\r
229 );\r
230 ASSERT_EFI_ERROR (Status);\r
231\r
232 DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
233 Status = TempPtr.DxeIpl->Entry (\r
234 TempPtr.DxeIpl,\r
235 &PrivateData.PS,\r
236 PrivateData.HobList\r
237 );\r
238\r
239 ASSERT_EFI_ERROR (Status);\r
240\r
241 return EFI_NOT_FOUND;\r
242}\r
243\r