a0b7c09f |
1 | /*++\r |
2 | \r |
3 | Copyright (c) 2006, Intel Corporation\r |
4 | All rights reserved. This program and the accompanying materials\r |
5 | are licensed and made available under the terms and conditions of the BSD License\r |
6 | which accompanies this distribution. The full text of the license may be found at\r |
7 | http://opensource.org/licenses/bsd-license.php\r |
8 | \r |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
11 | \r |
12 | Module Name:\r |
13 | \r |
14 | PeiMain.c\r |
15 | \r |
16 | Abstract:\r |
17 | \r |
18 | Pei Core Main Entry Point\r |
19 | \r |
20 | Revision 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 |
31 | static 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 |
41 | static 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 |
75 | EFI_STATUS\r |
76 | EFIAPI\r |
77 | PeiCore (\r |
78 | IN EFI_PEI_STARTUP_DESCRIPTOR *PeiStartupDescriptor,\r |
79 | IN PEI_CORE_INSTANCE *OldCoreData\r |
80 | )\r |
81 | /*++\r |
82 | \r |
83 | Routine 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 |
89 | Arguments:\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 |
95 | Returns:\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 |
110 | #ifdef EFI_PEI_PERFORMANCE\r |
111 | if (OldCoreData == NULL) {\r |
112 | mTick = GetPerformanceCounter ();\r |
113 | }\r |
114 | #endif\r |
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 |
181 | PERF_START (NULL,"DisMem", NULL, 0);\r |
84a99d48 |
182 | Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r |
a0b7c09f |
183 | PERF_END (NULL,"DisMem", NULL, 0);\r |
184 | \r |
185 | } else {\r |
186 | \r |
187 | //\r |
188 | // Report Status Code EFI_SW_PC_INIT\r |
189 | //\r |
190 | REPORT_STATUS_CODE (\r |
191 | EFI_PROGRESS_CODE,\r |
192 | EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r |
193 | );\r |
194 | \r |
195 | //\r |
196 | // If first pass, start performance measurement.\r |
197 | //\r |
198 | PERF_START (NULL,"PreMem", NULL, mTick);\r |
199 | \r |
200 | //\r |
201 | // If SEC provided any PPI services to PEI, install them.\r |
202 | //\r |
203 | if (PeiStartupDescriptor->DispatchTable != NULL) {\r |
84a99d48 |
204 | Status = PeiServicesInstallPpi (PeiStartupDescriptor->DispatchTable);\r |
a0b7c09f |
205 | ASSERT_EFI_ERROR (Status);\r |
206 | }\r |
207 | }\r |
208 | \r |
209 | DispatchData = &PrivateData.DispatchData;\r |
210 | \r |
211 | //\r |
212 | // Call PEIM dispatcher\r |
213 | //\r |
214 | PeiDispatcher (PeiStartupDescriptor, &PrivateData, DispatchData);\r |
215 | \r |
216 | //\r |
217 | // Check if InstallPeiMemory service was called.\r |
218 | //\r |
219 | ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r |
220 | \r |
221 | PERF_END (NULL, "PostMem", NULL, 0);\r |
222 | \r |
84a99d48 |
223 | Status = PeiServicesLocatePpi (\r |
a0b7c09f |
224 | &gEfiDxeIplPpiGuid,\r |
225 | 0,\r |
226 | NULL,\r |
227 | (VOID **)&TempPtr.DxeIpl\r |
228 | );\r |
229 | ASSERT_EFI_ERROR (Status);\r |
230 | \r |
231 | DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r |
232 | Status = TempPtr.DxeIpl->Entry (\r |
233 | TempPtr.DxeIpl,\r |
234 | &PrivateData.PS,\r |
235 | PrivateData.HobList\r |
236 | );\r |
237 | \r |
238 | ASSERT_EFI_ERROR (Status);\r |
239 | \r |
240 | return EFI_NOT_FOUND;\r |
241 | }\r |
242 | \r |