]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | SMM Core Main Entry Point\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials are licensed and made available \r | |
6 | under the terms and conditions of the BSD License which accompanies this \r | |
7 | distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "PiSmmCore.h"\r | |
16 | \r | |
17 | //\r | |
18 | // Physical pointer to private structure shared between SMM IPL and the SMM Core\r | |
19 | //\r | |
20 | SMM_CORE_PRIVATE_DATA *gSmmCorePrivate;\r | |
21 | \r | |
22 | //\r | |
23 | // SMM Core global variable for SMM System Table. Only accessed as a physical structure in SMRAM.\r | |
24 | //\r | |
25 | EFI_SMM_SYSTEM_TABLE2 gSmmCoreSmst = {\r | |
26 | {\r | |
27 | SMM_SMST_SIGNATURE,\r | |
28 | EFI_SMM_SYSTEM_TABLE2_REVISION,\r | |
29 | sizeof (gSmmCoreSmst.Hdr)\r | |
30 | },\r | |
31 | NULL, // SmmFirmwareVendor\r | |
32 | 0, // SmmFirmwareRevision\r | |
33 | SmmInstallConfigurationTable,\r | |
34 | {\r | |
35 | {\r | |
36 | (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmMemRead\r | |
37 | (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmMemWrite\r | |
38 | },\r | |
39 | {\r | |
40 | (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5, // SmmIoRead\r | |
41 | (EFI_SMM_CPU_IO2) SmmEfiNotAvailableYetArg5 // SmmIoWrite\r | |
42 | }\r | |
43 | },\r | |
44 | SmmAllocatePool,\r | |
45 | SmmFreePool,\r | |
46 | SmmAllocatePages,\r | |
47 | SmmFreePages,\r | |
48 | NULL, // SmmStartupThisAp\r | |
49 | 0, // CurrentlyExecutingCpu\r | |
50 | 0, // NumberOfCpus\r | |
51 | NULL, // CpuSaveStateSize\r | |
52 | NULL, // CpuSaveState\r | |
53 | 0, // NumberOfTableEntries\r | |
54 | NULL, // SmmConfigurationTable\r | |
55 | SmmInstallProtocolInterface,\r | |
56 | SmmUninstallProtocolInterface,\r | |
57 | SmmHandleProtocol,\r | |
58 | SmmRegisterProtocolNotify,\r | |
59 | SmmLocateHandle,\r | |
60 | SmmLocateProtocol,\r | |
61 | SmiManage,\r | |
62 | SmiHandlerRegister,\r | |
63 | SmiHandlerUnRegister\r | |
64 | };\r | |
65 | \r | |
66 | //\r | |
67 | // Flag to determine if the platform has performed a legacy boot.\r | |
68 | // If this flag is TRUE, then the runtime code and runtime data associated with the \r | |
69 | // SMM IPL are converted to free memory, so the SMM COre must guarantee that is\r | |
70 | // does not touch of the code/data associated with the SMM IPL if this flag is TRUE.\r | |
71 | //\r | |
72 | BOOLEAN mInLegacyBoot = FALSE;\r | |
73 | \r | |
74 | //\r | |
75 | // Table of SMI Handlers that are registered by the SMM Core when it is initialized\r | |
76 | //\r | |
77 | SMM_CORE_SMI_HANDLERS mSmmCoreSmiHandlers[] = {\r | |
78 | { SmmDriverDispatchHandler, &gEfiEventDxeDispatchGuid, NULL, TRUE },\r | |
79 | { SmmReadyToLockHandler, &gEfiDxeSmmReadyToLockProtocolGuid, NULL, FALSE }, \r | |
80 | { SmmLegacyBootHandler, &gEfiEventLegacyBootGuid, NULL, FALSE },\r | |
81 | { NULL, NULL, NULL, FALSE }\r | |
82 | };\r | |
83 | \r | |
84 | /**\r | |
85 | Place holder function until all the SMM System Table Service are available.\r | |
86 | \r | |
87 | Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.\r | |
88 | \r | |
89 | @param Arg1 Undefined\r | |
90 | @param Arg2 Undefined\r | |
91 | @param Arg3 Undefined\r | |
92 | @param Arg4 Undefined\r | |
93 | @param Arg5 Undefined\r | |
94 | \r | |
95 | @return EFI_NOT_AVAILABLE_YET\r | |
96 | \r | |
97 | **/\r | |
98 | EFI_STATUS\r | |
99 | EFIAPI\r | |
100 | SmmEfiNotAvailableYetArg5 (\r | |
101 | UINTN Arg1,\r | |
102 | UINTN Arg2,\r | |
103 | UINTN Arg3,\r | |
104 | UINTN Arg4,\r | |
105 | UINTN Arg5\r | |
106 | )\r | |
107 | {\r | |
108 | //\r | |
109 | // This function should never be executed. If it does, then the architectural protocols\r | |
110 | // have not been designed correctly.\r | |
111 | //\r | |
112 | return EFI_NOT_AVAILABLE_YET;\r | |
113 | }\r | |
114 | \r | |
115 | /**\r | |
116 | Software SMI handler that is called when a Legacy Boot event is signalled. The SMM\r | |
117 | Core uses this signal to know that a Legacy Boot has been performed and that \r | |
118 | gSmmCorePrivate that is shared between the UEFI and SMM execution environments can\r | |
119 | not be accessed from SMM anymore since that structure is considered free memory by\r | |
120 | a legacy OS.\r | |
121 | \r | |
122 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
123 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
124 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
125 | be conveyed from a non-SMM environment into an SMM environment.\r | |
126 | @param CommBufferSize The size of the CommBuffer.\r | |
127 | \r | |
128 | @return Status Code\r | |
129 | \r | |
130 | **/\r | |
131 | EFI_STATUS\r | |
132 | EFIAPI\r | |
133 | SmmLegacyBootHandler (\r | |
134 | IN EFI_HANDLE DispatchHandle,\r | |
135 | IN CONST VOID *Context, OPTIONAL\r | |
136 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
137 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
138 | )\r | |
139 | {\r | |
140 | mInLegacyBoot = TRUE;\r | |
141 | return EFI_SUCCESS;\r | |
142 | }\r | |
143 | \r | |
144 | /**\r | |
145 | Software SMI handler that is called when the DxeSmmReadyToLock protocol is added\r | |
146 | or if gEfiEventReadyToBootGuid is signalled. This function unregisters the \r | |
147 | Software SMIs that are nor required after SMRAM is locked and installs the \r | |
148 | SMM Ready To Lock Protocol so SMM Drivers are informed that SMRAM is about \r | |
149 | to be locked. It also verifies the the SMM CPU I/O 2 Protocol has been installed\r | |
150 | and NULLs gBS and gST because they can not longer be used after SMRAM is locked.\r | |
151 | \r | |
152 | @param DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
153 | @param Context Points to an optional handler context which was specified when the handler was registered.\r | |
154 | @param CommBuffer A pointer to a collection of data in memory that will\r | |
155 | be conveyed from a non-SMM environment into an SMM environment.\r | |
156 | @param CommBufferSize The size of the CommBuffer.\r | |
157 | \r | |
158 | @return Status Code\r | |
159 | \r | |
160 | **/\r | |
161 | EFI_STATUS\r | |
162 | EFIAPI\r | |
163 | SmmReadyToLockHandler (\r | |
164 | IN EFI_HANDLE DispatchHandle,\r | |
165 | IN CONST VOID *Context, OPTIONAL\r | |
166 | IN OUT VOID *CommBuffer, OPTIONAL\r | |
167 | IN OUT UINTN *CommBufferSize OPTIONAL\r | |
168 | )\r | |
169 | {\r | |
170 | EFI_STATUS Status;\r | |
171 | UINTN Index;\r | |
172 | EFI_HANDLE SmmHandle;\r | |
173 | VOID *Interface;\r | |
174 | \r | |
175 | //\r | |
176 | // Unregister SMI Handlers that are no required after the SMM driver dispatch is stopped\r | |
177 | //\r | |
178 | for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {\r | |
179 | if (mSmmCoreSmiHandlers[Index].UnRegister) {\r | |
180 | SmiHandlerUnRegister (mSmmCoreSmiHandlers[Index].DispatchHandle);\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
184 | //\r | |
185 | // Install SMM Ready to lock protocol\r | |
186 | //\r | |
187 | SmmHandle = NULL;\r | |
188 | Status = SmmInstallProtocolInterface (\r | |
189 | &SmmHandle,\r | |
190 | &gEfiSmmReadyToLockProtocolGuid,\r | |
191 | EFI_NATIVE_INTERFACE,\r | |
192 | NULL\r | |
193 | );\r | |
194 | \r | |
195 | //\r | |
196 | // Make sure SMM CPU I/O 2 Procol has been installed into the handle database\r | |
197 | //\r | |
198 | Status = SmmLocateProtocol (&gEfiSmmCpuIo2ProtocolGuid, NULL, &Interface);\r | |
199 | \r | |
200 | //\r | |
201 | // Print a message on a debug build if the SMM CPU I/O 2 Protocol is not installed\r | |
202 | //\r | |
203 | DEBUG_CODE_BEGIN ();\r | |
204 | if (EFI_ERROR (Status)) {\r | |
205 | DEBUG ((DEBUG_ERROR, "\nSMM: SmmCpuIo Arch Protocol not present!!\n"));\r | |
206 | }\r | |
207 | DEBUG_CODE_END ();\r | |
208 | \r | |
209 | //\r | |
210 | // Assert if the CPU I/O 2 Protocol is not installed\r | |
211 | //\r | |
212 | ASSERT_EFI_ERROR (Status);\r | |
213 | \r | |
214 | //\r | |
215 | // Display any drivers that were not dispatched because dependency expression\r | |
216 | // evaluated to false if this is a debug build\r | |
217 | //\r | |
218 | DEBUG_CODE_BEGIN ();\r | |
219 | SmmDisplayDiscoveredNotDispatched ();\r | |
220 | DEBUG_CODE_END ();\r | |
221 | \r | |
222 | //\r | |
223 | // Not allowed to use gST or gBS after lock\r | |
224 | //\r | |
225 | gST = NULL;\r | |
226 | gBS = NULL;\r | |
227 | \r | |
228 | return Status;\r | |
229 | }\r | |
230 | \r | |
231 | /**\r | |
232 | The main entry point to SMM Foundation.\r | |
233 | \r | |
234 | Note: This function is only used by SMRAM invocation. It is never used by DXE invocation.\r | |
235 | \r | |
236 | @param SmmEntryContext Processor information and functionality\r | |
237 | needed by SMM Foundation.\r | |
238 | \r | |
239 | **/\r | |
240 | VOID\r | |
241 | EFIAPI\r | |
242 | SmmEntryPoint (\r | |
243 | IN CONST EFI_SMM_ENTRY_CONTEXT *SmmEntryContext\r | |
244 | )\r | |
245 | {\r | |
246 | EFI_STATUS Status;\r | |
247 | EFI_SMM_COMMUNICATE_HEADER *CommunicateHeader;\r | |
248 | \r | |
249 | //\r | |
250 | // Update SMST using the context\r | |
251 | //\r | |
252 | CopyMem (&gSmmCoreSmst.SmmStartupThisAp, SmmEntryContext, sizeof (EFI_SMM_ENTRY_CONTEXT));\r | |
253 | \r | |
254 | //\r | |
255 | // If a legacy boot has occured, then make sure gSmmCorePrivate is not accessed\r | |
256 | //\r | |
257 | if (mInLegacyBoot) {\r | |
258 | //\r | |
259 | // Asynchronous SMI\r | |
260 | //\r | |
261 | SmiManage (NULL, NULL, NULL, NULL);\r | |
262 | return;\r | |
263 | }\r | |
264 | \r | |
265 | //\r | |
266 | // Mark the InSmm flag as TRUE, it will be used by SmmBase2 protocol\r | |
267 | //\r | |
268 | gSmmCorePrivate->InSmm = TRUE;\r | |
269 | \r | |
270 | //\r | |
271 | // Check to see if this is a Synchronous SMI sent through the SMM Communication \r | |
272 | // Protocol or an Asynchronous SMI\r | |
273 | //\r | |
274 | if (gSmmCorePrivate->CommunicationBuffer != NULL) {\r | |
275 | //\r | |
276 | // Synchronous SMI for SMM Core or request from Communicate protocol\r | |
277 | //\r | |
278 | CommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *)gSmmCorePrivate->CommunicationBuffer;\r | |
279 | *gSmmCorePrivate->BufferSize -= OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r | |
280 | Status = SmiManage (\r | |
281 | &CommunicateHeader->HeaderGuid, \r | |
282 | NULL, \r | |
283 | CommunicateHeader->Data, \r | |
284 | gSmmCorePrivate->BufferSize\r | |
285 | );\r | |
286 | \r | |
287 | //\r | |
288 | // Update CommunicationBuffer, BufferSize and ReturnStatus\r | |
289 | // Communicate service finished, reset the pointer to CommBuffer to NULL\r | |
290 | //\r | |
291 | *gSmmCorePrivate->BufferSize += OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data);\r | |
292 | gSmmCorePrivate->CommunicationBuffer = NULL;\r | |
293 | gSmmCorePrivate->ReturnStatus = (Status == EFI_WARN_INTERRUPT_SOURCE_QUIESCED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r | |
294 | } else {\r | |
295 | //\r | |
296 | // Asynchronous SMI\r | |
297 | //\r | |
298 | SmiManage (NULL, NULL, NULL, NULL);\r | |
299 | }\r | |
300 | \r | |
301 | //\r | |
302 | // Clear the InSmm flag as we are going to leave SMM\r | |
303 | //\r | |
304 | gSmmCorePrivate->InSmm = FALSE;\r | |
305 | }\r | |
306 | \r | |
307 | /**\r | |
308 | The Entry Point for SMM Core\r | |
309 | \r | |
310 | Install DXE Protocols and reload SMM Core into SMRAM and register SMM Core \r | |
311 | EntryPoint on the SMI vector.\r | |
312 | \r | |
313 | Note: This function is called for both DXE invocation and SMRAM invocation.\r | |
314 | \r | |
315 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
316 | @param SystemTable A pointer to the EFI System Table.\r | |
317 | \r | |
318 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
319 | @retval Other Some error occurred when executing this entry point.\r | |
320 | \r | |
321 | **/\r | |
322 | EFI_STATUS\r | |
323 | EFIAPI\r | |
324 | SmmMain (\r | |
325 | IN EFI_HANDLE ImageHandle,\r | |
326 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
327 | )\r | |
328 | {\r | |
329 | EFI_STATUS Status;\r | |
330 | UINTN Index;\r | |
331 | \r | |
332 | //\r | |
333 | // Get SMM Core Private context passed in from SMM IPL in ImageHandle.\r | |
334 | //\r | |
335 | gSmmCorePrivate = (SMM_CORE_PRIVATE_DATA *)ImageHandle;\r | |
336 | \r | |
337 | //\r | |
338 | // Fill in SMRAM physical address for the SMM Services Table and the SMM Entry Point.\r | |
339 | //\r | |
340 | gSmmCorePrivate->Smst = &gSmmCoreSmst;\r | |
341 | gSmmCorePrivate->SmmEntryPoint = SmmEntryPoint;\r | |
342 | \r | |
343 | //\r | |
344 | // Initialize memory service using free SMRAM\r | |
345 | //\r | |
346 | SmmInitializeMemoryServices (gSmmCorePrivate->SmramRangeCount, gSmmCorePrivate->SmramRanges);\r | |
347 | \r | |
348 | //\r | |
349 | // Register all SMI Handlers required by the SMM Core\r | |
350 | //\r | |
351 | for (Index = 0; mSmmCoreSmiHandlers[Index].HandlerType != NULL; Index++) {\r | |
352 | Status = SmiHandlerRegister (\r | |
353 | mSmmCoreSmiHandlers[Index].Handler,\r | |
354 | mSmmCoreSmiHandlers[Index].HandlerType,\r | |
355 | &mSmmCoreSmiHandlers[Index].DispatchHandle\r | |
356 | );\r | |
357 | ASSERT_EFI_ERROR (Status);\r | |
358 | }\r | |
359 | \r | |
360 | return EFI_SUCCESS;\r | |
361 | }\r |