]>
Commit | Line | Data |
---|---|---|
0c18794e | 1 | /** @file\r |
2 | The sample implementation for SMM variable protocol. And this driver \r | |
3 | implements an SMI handler to communicate with the DXE runtime driver \r | |
4 | to provide variable services.\r | |
5 | \r | |
dc204d5a JY |
6 | Caution: This module requires additional review when modified.\r |
7 | This driver will have external input - variable data and communicate buffer in SMM mode.\r | |
8 | This external input must be validated carefully to avoid security issue like\r | |
9 | buffer overflow, integer overflow.\r | |
10 | \r | |
11 | SmmVariableHandler() will receive untrusted input and do basic validation.\r | |
12 | \r | |
13 | Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(), \r | |
14 | VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(), \r | |
15 | SmmVariableGetStatistics() should also do validation based on its own knowledge.\r | |
16 | \r | |
17 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r | |
0c18794e | 18 | This program and the accompanying materials \r |
19 | are licensed and made available under the terms and conditions of the BSD License \r | |
20 | which accompanies this distribution. The full text of the license may be found at \r | |
21 | http://opensource.org/licenses/bsd-license.php\r | |
22 | \r | |
23 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
24 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
25 | \r | |
26 | **/\r | |
27 | \r | |
28 | #include <Protocol/SmmVariable.h>\r | |
29 | #include <Protocol/SmmFirmwareVolumeBlock.h>\r | |
30 | #include <Protocol/SmmFaultTolerantWrite.h>\r | |
31 | #include <Library/SmmServicesTableLib.h>\r | |
32 | \r | |
33 | #include <Guid/AuthenticatedVariableFormat.h>\r | |
34 | #include <Guid/SmmVariableCommon.h>\r | |
35 | #include "Variable.h"\r | |
36 | \r | |
37 | extern VARIABLE_INFO_ENTRY *gVariableInfo;\r | |
38 | EFI_HANDLE mSmmVariableHandle = NULL;\r | |
39 | EFI_HANDLE mVariableHandle = NULL;\r | |
40 | BOOLEAN mAtRuntime = FALSE;\r | |
41 | EFI_GUID mZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};\r | |
42 | \r | |
43 | EFI_SMM_VARIABLE_PROTOCOL gSmmVariable = {\r | |
44 | VariableServiceGetVariable,\r | |
45 | VariableServiceGetNextVariableName,\r | |
46 | VariableServiceSetVariable,\r | |
47 | VariableServiceQueryVariableInfo\r | |
48 | };\r | |
49 | \r | |
50 | \r | |
51 | /**\r | |
52 | Return TRUE if ExitBootServices () has been called.\r | |
53 | \r | |
54 | @retval TRUE If ExitBootServices () has been called.\r | |
55 | **/\r | |
56 | BOOLEAN\r | |
57 | AtRuntime (\r | |
58 | VOID\r | |
59 | )\r | |
60 | {\r | |
61 | return mAtRuntime;\r | |
62 | }\r | |
63 | \r | |
64 | /**\r | |
65 | Initializes a basic mutual exclusion lock.\r | |
66 | \r | |
67 | This function initializes a basic mutual exclusion lock to the released state \r | |
68 | and returns the lock. Each lock provides mutual exclusion access at its task \r | |
69 | priority level. Since there is no preemption or multiprocessor support in EFI,\r | |
70 | acquiring the lock only consists of raising to the locks TPL.\r | |
71 | If Lock is NULL, then ASSERT().\r | |
72 | If Priority is not a valid TPL value, then ASSERT().\r | |
73 | \r | |
74 | @param Lock A pointer to the lock data structure to initialize.\r | |
75 | @param Priority EFI TPL is associated with the lock.\r | |
76 | \r | |
77 | @return The lock.\r | |
78 | \r | |
79 | **/\r | |
80 | EFI_LOCK *\r | |
81 | InitializeLock (\r | |
82 | IN OUT EFI_LOCK *Lock,\r | |
83 | IN EFI_TPL Priority\r | |
84 | )\r | |
85 | {\r | |
86 | return Lock;\r | |
87 | }\r | |
88 | \r | |
89 | /**\r | |
90 | Acquires lock only at boot time. Simply returns at runtime.\r | |
91 | \r | |
92 | This is a temperary function that will be removed when\r | |
93 | EfiAcquireLock() in UefiLib can handle the call in UEFI\r | |
94 | Runtimer driver in RT phase.\r | |
95 | It calls EfiAcquireLock() at boot time, and simply returns\r | |
96 | at runtime.\r | |
97 | \r | |
98 | @param Lock A pointer to the lock to acquire.\r | |
99 | \r | |
100 | **/\r | |
101 | VOID\r | |
102 | AcquireLockOnlyAtBootTime (\r | |
103 | IN EFI_LOCK *Lock\r | |
104 | )\r | |
105 | {\r | |
106 | \r | |
107 | }\r | |
108 | \r | |
109 | \r | |
110 | /**\r | |
111 | Releases lock only at boot time. Simply returns at runtime.\r | |
112 | \r | |
113 | This is a temperary function which will be removed when\r | |
114 | EfiReleaseLock() in UefiLib can handle the call in UEFI\r | |
115 | Runtimer driver in RT phase.\r | |
116 | It calls EfiReleaseLock() at boot time and simply returns\r | |
117 | at runtime.\r | |
118 | \r | |
119 | @param Lock A pointer to the lock to release.\r | |
120 | \r | |
121 | **/\r | |
122 | VOID\r | |
123 | ReleaseLockOnlyAtBootTime (\r | |
124 | IN EFI_LOCK *Lock\r | |
125 | )\r | |
126 | {\r | |
127 | \r | |
128 | }\r | |
129 | \r | |
130 | /**\r | |
131 | Retrive the SMM Fault Tolerent Write protocol interface.\r | |
132 | \r | |
133 | @param[out] FtwProtocol The interface of SMM Ftw protocol\r | |
134 | \r | |
135 | @retval EFI_SUCCESS The SMM FTW protocol instance was found and returned in FtwProtocol.\r | |
136 | @retval EFI_NOT_FOUND The SMM FTW protocol instance was not found.\r | |
137 | @retval EFI_INVALID_PARAMETER SarProtocol is NULL.\r | |
138 | \r | |
139 | **/\r | |
140 | EFI_STATUS\r | |
141 | GetFtwProtocol (\r | |
142 | OUT VOID **FtwProtocol\r | |
143 | )\r | |
144 | {\r | |
145 | EFI_STATUS Status;\r | |
146 | \r | |
147 | //\r | |
148 | // Locate Smm Fault Tolerent Write protocol\r | |
149 | //\r | |
150 | Status = gSmst->SmmLocateProtocol (\r | |
151 | &gEfiSmmFaultTolerantWriteProtocolGuid, \r | |
152 | NULL, \r | |
153 | FtwProtocol\r | |
154 | );\r | |
155 | return Status;\r | |
156 | }\r | |
157 | \r | |
158 | \r | |
159 | /**\r | |
160 | Retrive the SMM FVB protocol interface by HANDLE.\r | |
161 | \r | |
162 | @param[in] FvBlockHandle The handle of SMM FVB protocol that provides services for\r | |
163 | reading, writing, and erasing the target block.\r | |
164 | @param[out] FvBlock The interface of SMM FVB protocol\r | |
165 | \r | |
166 | @retval EFI_SUCCESS The interface information for the specified protocol was returned.\r | |
167 | @retval EFI_UNSUPPORTED The device does not support the SMM FVB protocol.\r | |
168 | @retval EFI_INVALID_PARAMETER FvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.\r | |
169 | \r | |
170 | **/\r | |
171 | EFI_STATUS\r | |
172 | GetFvbByHandle (\r | |
173 | IN EFI_HANDLE FvBlockHandle,\r | |
174 | OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock\r | |
175 | )\r | |
176 | {\r | |
177 | //\r | |
178 | // To get the SMM FVB protocol interface on the handle\r | |
179 | //\r | |
180 | return gSmst->SmmHandleProtocol (\r | |
181 | FvBlockHandle,\r | |
182 | &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r | |
183 | (VOID **) FvBlock\r | |
184 | );\r | |
185 | }\r | |
186 | \r | |
187 | \r | |
188 | /**\r | |
189 | Function returns an array of handles that support the SMM FVB protocol\r | |
190 | in a buffer allocated from pool. \r | |
191 | \r | |
192 | @param[out] NumberHandles The number of handles returned in Buffer.\r | |
193 | @param[out] Buffer A pointer to the buffer to return the requested\r | |
194 | array of handles that support SMM FVB protocol.\r | |
195 | \r | |
196 | @retval EFI_SUCCESS The array of handles was returned in Buffer, and the number of\r | |
197 | handles in Buffer was returned in NumberHandles.\r | |
198 | @retval EFI_NOT_FOUND No SMM FVB handle was found.\r | |
199 | @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the matching results.\r | |
200 | @retval EFI_INVALID_PARAMETER NumberHandles is NULL or Buffer is NULL.\r | |
201 | \r | |
202 | **/\r | |
203 | EFI_STATUS\r | |
204 | GetFvbCountAndBuffer (\r | |
205 | OUT UINTN *NumberHandles,\r | |
206 | OUT EFI_HANDLE **Buffer\r | |
207 | )\r | |
208 | {\r | |
209 | EFI_STATUS Status;\r | |
210 | UINTN BufferSize;\r | |
211 | \r | |
212 | if ((NumberHandles == NULL) || (Buffer == NULL)) {\r | |
213 | return EFI_INVALID_PARAMETER;\r | |
214 | }\r | |
215 | \r | |
216 | BufferSize = 0;\r | |
217 | *NumberHandles = 0;\r | |
218 | *Buffer = NULL;\r | |
219 | Status = gSmst->SmmLocateHandle (\r | |
220 | ByProtocol,\r | |
221 | &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r | |
222 | NULL,\r | |
223 | &BufferSize,\r | |
224 | *Buffer\r | |
225 | );\r | |
226 | if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) {\r | |
227 | return EFI_NOT_FOUND;\r | |
228 | }\r | |
229 | \r | |
230 | *Buffer = AllocatePool (BufferSize);\r | |
231 | if (*Buffer == NULL) {\r | |
232 | return EFI_OUT_OF_RESOURCES;\r | |
233 | }\r | |
234 | \r | |
235 | Status = gSmst->SmmLocateHandle (\r | |
236 | ByProtocol,\r | |
237 | &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r | |
238 | NULL,\r | |
239 | &BufferSize,\r | |
240 | *Buffer\r | |
241 | );\r | |
242 | \r | |
243 | *NumberHandles = BufferSize / sizeof(EFI_HANDLE);\r | |
244 | if (EFI_ERROR(Status)) {\r | |
245 | *NumberHandles = 0;\r | |
246 | }\r | |
247 | \r | |
248 | return Status;\r | |
249 | }\r | |
250 | \r | |
251 | \r | |
252 | /**\r | |
253 | Get the variable statistics information from the information buffer pointed by gVariableInfo.\r | |
254 | \r | |
dc204d5a JY |
255 | Caution: This function may be invoked at SMM runtime.\r |
256 | InfoEntry and InfoSize are external input. Care must be taken to make sure not security issue at runtime.\r | |
257 | \r | |
648f98d1 | 258 | @param[in, out] InfoEntry A pointer to the buffer of variable information entry.\r |
259 | On input, point to the variable information returned last time. if \r | |
260 | InfoEntry->VendorGuid is zero, return the first information.\r | |
261 | On output, point to the next variable information.\r | |
262 | @param[in, out] InfoSize On input, the size of the variable information buffer.\r | |
263 | On output, the returned variable information size.\r | |
264 | \r | |
265 | @retval EFI_SUCCESS The variable information is found and returned successfully.\r | |
266 | @retval EFI_UNSUPPORTED No variable inoformation exists in variable driver. The \r | |
267 | PcdVariableCollectStatistics should be set TRUE to support it.\r | |
268 | @retval EFI_BUFFER_TOO_SMALL The buffer is too small to hold the next variable information.\r | |
269 | @retval EFI_INVALID_PARAMETER Input parameter is invalid.\r | |
0c18794e | 270 | \r |
271 | **/\r | |
272 | EFI_STATUS\r | |
273 | SmmVariableGetStatistics (\r | |
274 | IN OUT VARIABLE_INFO_ENTRY *InfoEntry,\r | |
275 | IN OUT UINTN *InfoSize\r | |
276 | )\r | |
277 | {\r | |
278 | VARIABLE_INFO_ENTRY *VariableInfo;\r | |
279 | UINTN NameLength;\r | |
280 | UINTN StatisticsInfoSize;\r | |
281 | CHAR16 *InfoName;\r | |
282 | \r | |
648f98d1 | 283 | if (InfoEntry == NULL) {\r |
284 | return EFI_INVALID_PARAMETER;\r | |
285 | }\r | |
286 | \r | |
0c18794e | 287 | VariableInfo = gVariableInfo; \r |
288 | if (VariableInfo == NULL) {\r | |
289 | return EFI_UNSUPPORTED;\r | |
290 | }\r | |
291 | \r | |
292 | StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + StrSize (VariableInfo->Name);\r | |
12373f2c | 293 | if (*InfoSize < StatisticsInfoSize) {\r |
0c18794e | 294 | *InfoSize = StatisticsInfoSize;\r |
295 | return EFI_BUFFER_TOO_SMALL;\r | |
296 | }\r | |
297 | InfoName = (CHAR16 *)(InfoEntry + 1);\r | |
298 | \r | |
299 | if (CompareGuid (&InfoEntry->VendorGuid, &mZeroGuid)) {\r | |
300 | //\r | |
301 | // Return the first variable info\r | |
302 | //\r | |
303 | CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));\r | |
304 | CopyMem (InfoName, VariableInfo->Name, StrSize (VariableInfo->Name));\r | |
305 | *InfoSize = StatisticsInfoSize;\r | |
306 | return EFI_SUCCESS;\r | |
307 | }\r | |
308 | \r | |
309 | //\r | |
310 | // Get the next variable info\r | |
311 | //\r | |
312 | while (VariableInfo != NULL) {\r | |
313 | if (CompareGuid (&VariableInfo->VendorGuid, &InfoEntry->VendorGuid)) {\r | |
314 | NameLength = StrSize (VariableInfo->Name);\r | |
315 | if (NameLength == StrSize (InfoName)) {\r | |
316 | if (CompareMem (VariableInfo->Name, InfoName, NameLength) == 0) {\r | |
317 | //\r | |
318 | // Find the match one\r | |
319 | //\r | |
320 | VariableInfo = VariableInfo->Next;\r | |
321 | break;\r | |
322 | }\r | |
323 | }\r | |
324 | }\r | |
325 | VariableInfo = VariableInfo->Next;\r | |
326 | };\r | |
327 | \r | |
328 | if (VariableInfo == NULL) {\r | |
329 | *InfoSize = 0;\r | |
330 | return EFI_SUCCESS;\r | |
331 | }\r | |
332 | \r | |
333 | //\r | |
334 | // Output the new variable info\r | |
335 | //\r | |
336 | StatisticsInfoSize = sizeof (VARIABLE_INFO_ENTRY) + StrSize (VariableInfo->Name);\r | |
337 | if (*InfoSize < StatisticsInfoSize) {\r | |
338 | *InfoSize = StatisticsInfoSize;\r | |
339 | return EFI_BUFFER_TOO_SMALL;\r | |
340 | }\r | |
341 | \r | |
342 | CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));\r | |
343 | CopyMem (InfoName, VariableInfo->Name, StrSize (VariableInfo->Name));\r | |
344 | *InfoSize = StatisticsInfoSize;\r | |
345 | \r | |
346 | return EFI_SUCCESS;\r | |
347 | }\r | |
348 | \r | |
349 | \r | |
350 | /**\r | |
351 | Communication service SMI Handler entry.\r | |
352 | \r | |
353 | This SMI handler provides services for the variable wrapper driver.\r | |
354 | \r | |
dc204d5a JY |
355 | Caution: This function may receive untrusted input.\r |
356 | This variable data and communicate buffer are external input, so this function will do basic validation.\r | |
357 | Each sub function VariableServiceGetVariable(), VariableServiceGetNextVariableName(), \r | |
358 | VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), ReclaimForOS(), \r | |
359 | SmmVariableGetStatistics() should also do validation based on its own knowledge.\r | |
360 | \r | |
0c18794e | 361 | @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r |
362 | @param[in] RegisterContext Points to an optional handler context which was specified when the\r | |
363 | handler was registered.\r | |
364 | @param[in, out] CommBuffer A pointer to a collection of data in memory that will\r | |
365 | be conveyed from a non-SMM environment into an SMM environment.\r | |
366 | @param[in, out] CommBufferSize The size of the CommBuffer.\r | |
367 | \r | |
368 | @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers \r | |
369 | should still be called.\r | |
370 | @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should \r | |
371 | still be called.\r | |
372 | @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still \r | |
373 | be called.\r | |
374 | @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.\r | |
648f98d1 | 375 | @retval EFI_INVALID_PARAMETER Input parameter is invalid.\r |
376 | \r | |
0c18794e | 377 | **/\r |
378 | EFI_STATUS\r | |
379 | EFIAPI\r | |
380 | SmmVariableHandler (\r | |
381 | IN EFI_HANDLE DispatchHandle,\r | |
382 | IN CONST VOID *RegisterContext,\r | |
383 | IN OUT VOID *CommBuffer,\r | |
384 | IN OUT UINTN *CommBufferSize\r | |
385 | )\r | |
386 | {\r | |
387 | EFI_STATUS Status;\r | |
388 | SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHeader;\r | |
389 | SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader;\r | |
390 | SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariableName;\r | |
391 | SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo;\r | |
392 | VARIABLE_INFO_ENTRY *VariableInfo;\r | |
393 | UINTN InfoSize;\r | |
394 | \r | |
648f98d1 | 395 | if (CommBuffer == NULL) {\r |
396 | return EFI_INVALID_PARAMETER;\r | |
397 | }\r | |
0c18794e | 398 | \r |
399 | SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer;\r | |
400 | switch (SmmVariableFunctionHeader->Function) {\r | |
401 | case SMM_VARIABLE_FUNCTION_GET_VARIABLE:\r | |
402 | SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) SmmVariableFunctionHeader->Data; \r | |
403 | Status = VariableServiceGetVariable (\r | |
404 | SmmVariableHeader->Name,\r | |
405 | &SmmVariableHeader->Guid,\r | |
406 | &SmmVariableHeader->Attributes,\r | |
407 | &SmmVariableHeader->DataSize,\r | |
408 | (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize\r | |
409 | );\r | |
410 | break;\r | |
411 | \r | |
412 | case SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME:\r | |
413 | GetNextVariableName = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *) SmmVariableFunctionHeader->Data;\r | |
414 | Status = VariableServiceGetNextVariableName (\r | |
415 | &GetNextVariableName->NameSize,\r | |
416 | GetNextVariableName->Name,\r | |
417 | &GetNextVariableName->Guid\r | |
418 | );\r | |
419 | break;\r | |
420 | \r | |
421 | case SMM_VARIABLE_FUNCTION_SET_VARIABLE:\r | |
422 | SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) SmmVariableFunctionHeader->Data;\r | |
423 | Status = VariableServiceSetVariable (\r | |
424 | SmmVariableHeader->Name,\r | |
425 | &SmmVariableHeader->Guid,\r | |
426 | SmmVariableHeader->Attributes,\r | |
427 | SmmVariableHeader->DataSize,\r | |
428 | (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize\r | |
429 | );\r | |
430 | break;\r | |
431 | \r | |
432 | case SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO:\r | |
433 | QueryVariableInfo = (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *) SmmVariableFunctionHeader->Data;\r | |
434 | Status = VariableServiceQueryVariableInfo (\r | |
435 | QueryVariableInfo->Attributes,\r | |
436 | &QueryVariableInfo->MaximumVariableStorageSize,\r | |
437 | &QueryVariableInfo->RemainingVariableStorageSize,\r | |
438 | &QueryVariableInfo->MaximumVariableSize\r | |
439 | );\r | |
440 | break;\r | |
441 | \r | |
442 | case SMM_VARIABLE_FUNCTION_READY_TO_BOOT:\r | |
443 | ReclaimForOS ();\r | |
444 | Status = EFI_SUCCESS;\r | |
445 | break;\r | |
446 | \r | |
447 | case SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE:\r | |
448 | mAtRuntime = TRUE;\r | |
449 | Status = EFI_SUCCESS;\r | |
450 | break;\r | |
451 | \r | |
452 | case SMM_VARIABLE_FUNCTION_GET_STATISTICS:\r | |
453 | VariableInfo = (VARIABLE_INFO_ENTRY *) SmmVariableFunctionHeader->Data;\r | |
454 | InfoSize = *CommBufferSize - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_HEADER, Data);\r | |
455 | Status = SmmVariableGetStatistics (VariableInfo, &InfoSize);\r | |
456 | *CommBufferSize = InfoSize + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_HEADER, Data);\r | |
457 | break;\r | |
458 | \r | |
459 | default:\r | |
460 | ASSERT (FALSE);\r | |
461 | Status = EFI_UNSUPPORTED;\r | |
462 | }\r | |
463 | \r | |
464 | SmmVariableFunctionHeader->ReturnStatus = Status;\r | |
465 | \r | |
466 | return EFI_SUCCESS;\r | |
467 | }\r | |
468 | \r | |
469 | \r | |
470 | /**\r | |
471 | SMM Fault Tolerant Write protocol notification event handler.\r | |
472 | \r | |
473 | Non-Volatile variable write may needs FTW protocol to reclaim when \r | |
474 | writting variable.\r | |
475 | \r | |
476 | @param Protocol Points to the protocol's unique identifier\r | |
477 | @param Interface Points to the interface instance\r | |
478 | @param Handle The handle on which the interface was installed\r | |
479 | \r | |
480 | @retval EFI_SUCCESS SmmEventCallback runs successfully\r | |
481 | @retval EFI_NOT_FOUND The Fvb protocol for variable is not found.\r | |
482 | \r | |
483 | **/\r | |
484 | EFI_STATUS\r | |
485 | EFIAPI\r | |
486 | SmmFtwNotificationEvent (\r | |
487 | IN CONST EFI_GUID *Protocol,\r | |
488 | IN VOID *Interface,\r | |
489 | IN EFI_HANDLE Handle\r | |
490 | )\r | |
491 | {\r | |
492 | EFI_STATUS Status;\r | |
493 | EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r | |
494 | EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r | |
495 | EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r | |
496 | \r | |
497 | if (mVariableModuleGlobal->FvbInstance != NULL) {\r | |
498 | return EFI_SUCCESS;\r | |
499 | }\r | |
500 | \r | |
501 | //\r | |
502 | // Ensure SMM FTW protocol is installed.\r | |
503 | //\r | |
504 | Status = GetFtwProtocol ((VOID **)&FtwProtocol);\r | |
505 | if (EFI_ERROR (Status)) {\r | |
506 | return Status;\r | |
507 | }\r | |
508 | \r | |
509 | //\r | |
510 | // Find the proper FVB protocol for variable.\r | |
511 | //\r | |
512 | NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageVariableBase64);\r | |
513 | if (NvStorageVariableBase == 0) {\r | |
514 | NvStorageVariableBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageVariableBase);\r | |
515 | }\r | |
516 | Status = GetFvbInfoByAddress (NvStorageVariableBase, NULL, &FvbProtocol);\r | |
517 | if (EFI_ERROR (Status)) {\r | |
518 | return EFI_NOT_FOUND;\r | |
519 | }\r | |
520 | \r | |
521 | mVariableModuleGlobal->FvbInstance = FvbProtocol;\r | |
522 | \r | |
523 | Status = VariableWriteServiceInitialize ();\r | |
524 | ASSERT_EFI_ERROR (Status);\r | |
525 | \r | |
526 | //\r | |
527 | // Notify the variable wrapper driver the variable write service is ready\r | |
528 | //\r | |
529 | Status = gBS->InstallProtocolInterface (\r | |
530 | &mSmmVariableHandle,\r | |
531 | &gSmmVariableWriteGuid,\r | |
532 | EFI_NATIVE_INTERFACE,\r | |
533 | NULL\r | |
534 | );\r | |
535 | ASSERT_EFI_ERROR (Status);\r | |
536 | \r | |
537 | return EFI_SUCCESS;\r | |
538 | }\r | |
539 | \r | |
540 | \r | |
541 | /**\r | |
542 | Variable Driver main entry point. The Variable driver places the 4 EFI\r | |
543 | runtime services in the EFI System Table and installs arch protocols \r | |
544 | for variable read and write services being available. It also registers\r | |
545 | a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
546 | \r | |
547 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
548 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
549 | \r | |
550 | @retval EFI_SUCCESS Variable service successfully initialized.\r | |
551 | \r | |
552 | **/\r | |
553 | EFI_STATUS\r | |
554 | EFIAPI\r | |
555 | VariableServiceInitialize (\r | |
556 | IN EFI_HANDLE ImageHandle,\r | |
557 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
558 | )\r | |
559 | {\r | |
560 | EFI_STATUS Status;\r | |
561 | EFI_HANDLE VariableHandle;\r | |
562 | VOID *SmmFtwRegistration;\r | |
563 | \r | |
564 | //\r | |
565 | // Variable initialize.\r | |
566 | //\r | |
567 | Status = VariableCommonInitialize ();\r | |
568 | ASSERT_EFI_ERROR (Status);\r | |
569 | \r | |
570 | //\r | |
571 | // Install the Smm Variable Protocol on a new handle.\r | |
572 | //\r | |
573 | VariableHandle = NULL;\r | |
574 | Status = gSmst->SmmInstallProtocolInterface (\r | |
575 | &VariableHandle,\r | |
576 | &gEfiSmmVariableProtocolGuid,\r | |
577 | EFI_NATIVE_INTERFACE,\r | |
578 | &gSmmVariable\r | |
579 | );\r | |
580 | ASSERT_EFI_ERROR (Status);\r | |
581 | \r | |
582 | ///\r | |
583 | /// Register SMM variable SMI handler\r | |
584 | ///\r | |
585 | VariableHandle = NULL;\r | |
586 | Status = gSmst->SmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle);\r | |
587 | ASSERT_EFI_ERROR (Status);\r | |
588 | \r | |
589 | //\r | |
590 | // Notify the variable wrapper driver the variable service is ready\r | |
591 | //\r | |
592 | Status = SystemTable->BootServices->InstallProtocolInterface (\r | |
593 | &mVariableHandle,\r | |
594 | &gEfiSmmVariableProtocolGuid,\r | |
595 | EFI_NATIVE_INTERFACE,\r | |
596 | &gSmmVariable\r | |
597 | );\r | |
598 | ASSERT_EFI_ERROR (Status);\r | |
599 | \r | |
600 | //\r | |
601 | // Register FtwNotificationEvent () notify function.\r | |
602 | // \r | |
603 | Status = gSmst->SmmRegisterProtocolNotify (\r | |
604 | &gEfiSmmFaultTolerantWriteProtocolGuid,\r | |
605 | SmmFtwNotificationEvent,\r | |
606 | &SmmFtwRegistration\r | |
607 | );\r | |
608 | ASSERT_EFI_ERROR (Status);\r | |
609 | \r | |
610 | SmmFtwNotificationEvent (NULL, NULL, NULL);\r | |
611 | \r | |
612 | return EFI_SUCCESS;\r | |
613 | }\r | |
614 | \r | |
615 | \r |