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