2 Implement all four UEFI Runtime Variable services for the nonvolatile
3 and volatile storage space and install variable architecture protocol
4 based on SMM variable module.
6 Caution: This module requires additional review when modified.
7 This driver will have external input - variable data.
8 This external input must be validated carefully to avoid security issue like
9 buffer overflow, integer overflow.
11 RuntimeServiceGetVariable() and RuntimeServiceSetVariable() are external API
12 to receive data buffer. The size should be checked carefully.
14 InitCommunicateBuffer() is really function to check the variable data size.
16 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
17 This program and the accompanying materials
18 are licensed and made available under the terms and conditions of the BSD License
19 which accompanies this distribution. The full text of the license may be found at
20 http://opensource.org/licenses/bsd-license.php
22 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
23 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 #include <Protocol/VariableWrite.h>
29 #include <Protocol/Variable.h>
30 #include <Protocol/SmmCommunication.h>
31 #include <Protocol/SmmVariable.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiRuntimeServicesTableLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiDriverEntryPoint.h>
37 #include <Library/UefiRuntimeLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/DebugLib.h>
40 #include <Library/PcdLib.h>
41 #include <Library/UefiLib.h>
42 #include <Library/BaseLib.h>
44 #include <Guid/EventGroup.h>
45 #include <Guid/AuthenticatedVariableFormat.h>
46 #include <Guid/SmmVariableCommon.h>
48 EFI_HANDLE mHandle
= NULL
;
49 EFI_SMM_VARIABLE_PROTOCOL
*mSmmVariable
= NULL
;
50 EFI_EVENT mVirtualAddressChangeEvent
= NULL
;
51 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
52 UINT8
*mVariableBuffer
= NULL
;
53 UINT8
*mVariableBufferPhysical
= NULL
;
54 UINTN mVariableBufferSize
;
55 EFI_LOCK mVariableServicesLock
;
58 Acquires lock only at boot time. Simply returns at runtime.
60 This is a temperary function that will be removed when
61 EfiAcquireLock() in UefiLib can handle the call in UEFI
62 Runtimer driver in RT phase.
63 It calls EfiAcquireLock() at boot time, and simply returns
66 @param Lock A pointer to the lock to acquire.
70 AcquireLockOnlyAtBootTime (
74 if (!EfiAtRuntime ()) {
75 EfiAcquireLock (Lock
);
80 Releases lock only at boot time. Simply returns at runtime.
82 This is a temperary function which will be removed when
83 EfiReleaseLock() in UefiLib can handle the call in UEFI
84 Runtimer driver in RT phase.
85 It calls EfiReleaseLock() at boot time and simply returns
88 @param Lock A pointer to the lock to release.
92 ReleaseLockOnlyAtBootTime (
96 if (!EfiAtRuntime ()) {
97 EfiReleaseLock (Lock
);
102 Initialize the communicate buffer using DataSize and Function.
104 The communicate size is: SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE +
107 Caution: This function may receive untrusted input.
108 The data size external input, so this function will validate it carefully to avoid buffer overflow.
110 @param[out] DataPtr Points to the data in the communicate buffer.
111 @param[in] DataSize The data size to send to SMM.
112 @param[in] Function The function number to initialize the communicate header.
114 @retval EFI_INVALID_PARAMETER The data size is too big.
115 @retval EFI_SUCCESS Find the specified variable.
119 InitCommunicateBuffer (
120 OUT VOID
**DataPtr OPTIONAL
,
125 EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
;
126 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
129 if (DataSize
+ SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
> mVariableBufferSize
) {
130 return EFI_INVALID_PARAMETER
;
133 SmmCommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) mVariableBuffer
;
134 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
135 SmmCommunicateHeader
->MessageLength
= DataSize
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
137 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) SmmCommunicateHeader
->Data
;
138 SmmVariableFunctionHeader
->Function
= Function
;
139 if (DataPtr
!= NULL
) {
140 *DataPtr
= SmmVariableFunctionHeader
->Data
;
148 Send the data in communicate buffer to SMM.
150 @param[in] DataSize This size of the function header and the data.
152 @retval EFI_SUCCESS Success is returned from the functin in SMM.
153 @retval Others Failure is returned from the function in SMM.
157 SendCommunicateBuffer (
163 EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
;
164 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
166 CommSize
= DataSize
+ SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
167 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, mVariableBufferPhysical
, &CommSize
);
168 ASSERT_EFI_ERROR (Status
);
170 SmmCommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) mVariableBuffer
;
171 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*)SmmCommunicateHeader
->Data
;
172 return SmmVariableFunctionHeader
->ReturnStatus
;
177 This code finds variable in storage blocks (Volatile or Non-Volatile).
179 Caution: This function may receive untrusted input.
180 The data size is external input, so this function will validate it carefully to avoid buffer overflow.
182 @param[in] VariableName Name of Variable to be found.
183 @param[in] VendorGuid Variable vendor GUID.
184 @param[out] Attributes Attribute value of the variable found.
185 @param[in, out] DataSize Size of Data found. If size is less than the
186 data, this value contains the required size.
187 @param[out] Data Data pointer.
189 @retval EFI_INVALID_PARAMETER Invalid parameter.
190 @retval EFI_SUCCESS Find the specified variable.
191 @retval EFI_NOT_FOUND Not found.
192 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
197 RuntimeServiceGetVariable (
198 IN CHAR16
*VariableName
,
199 IN EFI_GUID
*VendorGuid
,
200 OUT UINT32
*Attributes OPTIONAL
,
201 IN OUT UINTN
*DataSize
,
207 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
*SmmVariableHeader
;
208 UINTN SmmCommBufPayloadSize
;
211 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
212 return EFI_INVALID_PARAMETER
;
215 if ((*DataSize
!= 0) && (Data
== NULL
)) {
216 return EFI_INVALID_PARAMETER
;
220 // SMM Communication Buffer max payload size
222 SmmCommBufPayloadSize
= mVariableBufferSize
- (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
);
223 TempDataSize
= *DataSize
;
226 // If VariableName exceeds SMM payload limit. Return failure
228 if (StrSize (VariableName
) > SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
)) {
229 return EFI_INVALID_PARAMETER
;
232 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
235 // Init the communicate buffer. The buffer data size is:
236 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
238 if (TempDataSize
> SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - StrSize (VariableName
)) {
240 // If output data buffer exceed SMM payload limit. Trim output buffer to SMM payload size
242 TempDataSize
= SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - StrSize (VariableName
);
244 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + StrSize (VariableName
) + TempDataSize
;
246 Status
= InitCommunicateBuffer ((VOID
**)&SmmVariableHeader
, PayloadSize
, SMM_VARIABLE_FUNCTION_GET_VARIABLE
);
247 if (EFI_ERROR (Status
)) {
250 ASSERT (SmmVariableHeader
!= NULL
);
252 CopyGuid (&SmmVariableHeader
->Guid
, VendorGuid
);
253 SmmVariableHeader
->DataSize
= TempDataSize
;
254 SmmVariableHeader
->NameSize
= StrSize (VariableName
);
255 if (Attributes
== NULL
) {
256 SmmVariableHeader
->Attributes
= 0;
258 SmmVariableHeader
->Attributes
= *Attributes
;
260 CopyMem (SmmVariableHeader
->Name
, VariableName
, SmmVariableHeader
->NameSize
);
265 Status
= SendCommunicateBuffer (PayloadSize
);
268 // Get data from SMM.
270 if (Status
== EFI_SUCCESS
|| Status
== EFI_BUFFER_TOO_SMALL
) {
272 // SMM CommBuffer DataSize can be a trimed value
273 // Only update DataSize when needed
275 *DataSize
= SmmVariableHeader
->DataSize
;
277 if (Attributes
!= NULL
) {
278 *Attributes
= SmmVariableHeader
->Attributes
;
281 if (EFI_ERROR (Status
)) {
285 CopyMem (Data
, (UINT8
*)SmmVariableHeader
->Name
+ SmmVariableHeader
->NameSize
, SmmVariableHeader
->DataSize
);
288 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
294 This code Finds the Next available variable.
296 @param[in, out] VariableNameSize Size of the variable name.
297 @param[in, out] VariableName Pointer to variable name.
298 @param[in, out] VendorGuid Variable Vendor Guid.
300 @retval EFI_INVALID_PARAMETER Invalid parameter.
301 @retval EFI_SUCCESS Find the specified variable.
302 @retval EFI_NOT_FOUND Not found.
303 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
308 RuntimeServiceGetNextVariableName (
309 IN OUT UINTN
*VariableNameSize
,
310 IN OUT CHAR16
*VariableName
,
311 IN OUT EFI_GUID
*VendorGuid
316 SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
*SmmGetNextVariableName
;
317 UINTN SmmCommBufPayloadSize
;
319 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
320 return EFI_INVALID_PARAMETER
;
324 // SMM Communication Buffer max payload size
326 SmmCommBufPayloadSize
= mVariableBufferSize
- (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
);
329 // If input string exceeds SMM payload limit. Return failure
331 if (StrSize (VariableName
) > SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
)) {
332 return EFI_INVALID_PARAMETER
;
335 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
338 // Init the communicate buffer. The buffer data size is:
339 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
341 if (*VariableNameSize
> SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
)) {
343 // If output buffer exceed SMM payload limit. Trim output buffer to SMM payload size
345 *VariableNameSize
= SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
);
348 // Payload should be Guid + NameSize + MAX of Input & Output buffer
350 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
) + MAX (*VariableNameSize
, StrSize (VariableName
));
352 Status
= InitCommunicateBuffer ((VOID
**)&SmmGetNextVariableName
, PayloadSize
, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME
);
353 if (EFI_ERROR (Status
)) {
356 ASSERT (SmmGetNextVariableName
!= NULL
);
359 // SMM comm buffer->NameSize is buffer size for return string
361 SmmGetNextVariableName
->NameSize
= *VariableNameSize
;
363 CopyGuid (&SmmGetNextVariableName
->Guid
, VendorGuid
);
367 CopyMem (SmmGetNextVariableName
->Name
, VariableName
, StrSize (VariableName
));
372 Status
= SendCommunicateBuffer (PayloadSize
);
375 // Get data from SMM.
377 *VariableNameSize
= SmmGetNextVariableName
->NameSize
;
378 if (EFI_ERROR (Status
)) {
382 CopyGuid (VendorGuid
, &SmmGetNextVariableName
->Guid
);
383 CopyMem (VariableName
, SmmGetNextVariableName
->Name
, SmmGetNextVariableName
->NameSize
);
386 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
391 This code sets variable in storage blocks (Volatile or Non-Volatile).
393 Caution: This function may receive untrusted input.
394 The data size and data are external input, so this function will validate it carefully to avoid buffer overflow.
396 @param[in] VariableName Name of Variable to be found.
397 @param[in] VendorGuid Variable vendor GUID.
398 @param[in] Attributes Attribute value of the variable found
399 @param[in] DataSize Size of Data found. If size is less than the
400 data, this value contains the required size.
401 @param[in] Data Data pointer.
403 @retval EFI_INVALID_PARAMETER Invalid parameter.
404 @retval EFI_SUCCESS Set successfully.
405 @retval EFI_OUT_OF_RESOURCES Resource not enough to set variable.
406 @retval EFI_NOT_FOUND Not found.
407 @retval EFI_WRITE_PROTECTED Variable is read-only.
412 RuntimeServiceSetVariable (
413 IN CHAR16
*VariableName
,
414 IN EFI_GUID
*VendorGuid
,
415 IN UINT32 Attributes
,
422 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
*SmmVariableHeader
;
425 // Check input parameters.
427 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
428 return EFI_INVALID_PARAMETER
;
431 if (DataSize
!= 0 && Data
== NULL
) {
432 return EFI_INVALID_PARAMETER
;
435 if (DataSize
>= mVariableBufferSize
) {
437 // DataSize may be near MAX_ADDRESS incorrectly, this can cause the computed PayLoadSize to
438 // overflow to a small value and pass the check in InitCommunicateBuffer().
439 // To protect against this vulnerability, return EFI_INVALID_PARAMETER if DataSize is >= mVariableBufferSize.
440 // And there will be further check to ensure the total size is also not > mVariableBufferSize.
442 return EFI_INVALID_PARAMETER
;
445 if ((UINTN
)(~0) - StrSize (VariableName
) < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + DataSize
) {
447 // Prevent PayloadSize overflow
449 return EFI_INVALID_PARAMETER
;
452 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
455 // Init the communicate buffer. The buffer data size is:
456 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
458 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + StrSize (VariableName
) + DataSize
;
459 Status
= InitCommunicateBuffer ((VOID
**)&SmmVariableHeader
, PayloadSize
, SMM_VARIABLE_FUNCTION_SET_VARIABLE
);
460 if (EFI_ERROR (Status
)) {
463 ASSERT (SmmVariableHeader
!= NULL
);
465 CopyGuid ((EFI_GUID
*) &SmmVariableHeader
->Guid
, VendorGuid
);
466 SmmVariableHeader
->DataSize
= DataSize
;
467 SmmVariableHeader
->NameSize
= StrSize (VariableName
);
468 SmmVariableHeader
->Attributes
= Attributes
;
469 CopyMem (SmmVariableHeader
->Name
, VariableName
, SmmVariableHeader
->NameSize
);
470 CopyMem ((UINT8
*) SmmVariableHeader
->Name
+ SmmVariableHeader
->NameSize
, Data
, DataSize
);
475 Status
= SendCommunicateBuffer (PayloadSize
);
478 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
484 This code returns information about the EFI variables.
486 @param[in] Attributes Attributes bitmask to specify the type of variables
487 on which to return information.
488 @param[out] MaximumVariableStorageSize Pointer to the maximum size of the storage space available
489 for the EFI variables associated with the attributes specified.
490 @param[out] RemainingVariableStorageSize Pointer to the remaining size of the storage space available
491 for EFI variables associated with the attributes specified.
492 @param[out] MaximumVariableSize Pointer to the maximum size of an individual EFI variables
493 associated with the attributes specified.
495 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
496 @retval EFI_SUCCESS Query successfully.
497 @retval EFI_UNSUPPORTED The attribute is not supported on this platform.
502 RuntimeServiceQueryVariableInfo (
503 IN UINT32 Attributes
,
504 OUT UINT64
*MaximumVariableStorageSize
,
505 OUT UINT64
*RemainingVariableStorageSize
,
506 OUT UINT64
*MaximumVariableSize
511 SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO
*SmmQueryVariableInfo
;
513 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
514 return EFI_INVALID_PARAMETER
;
517 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
520 // Init the communicate buffer. The buffer data size is:
521 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize;
523 PayloadSize
= sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO
);
524 Status
= InitCommunicateBuffer ((VOID
**)&SmmQueryVariableInfo
, PayloadSize
, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO
);
525 if (EFI_ERROR (Status
)) {
528 ASSERT (SmmQueryVariableInfo
!= NULL
);
530 SmmQueryVariableInfo
->Attributes
= Attributes
;
535 Status
= SendCommunicateBuffer (PayloadSize
);
536 if (EFI_ERROR (Status
)) {
541 // Get data from SMM.
543 *MaximumVariableSize
= SmmQueryVariableInfo
->MaximumVariableSize
;
544 *MaximumVariableStorageSize
= SmmQueryVariableInfo
->MaximumVariableStorageSize
;
545 *RemainingVariableStorageSize
= SmmQueryVariableInfo
->RemainingVariableStorageSize
;
548 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
554 Exit Boot Services Event notification handler.
556 Notify SMM variable driver about the event.
558 @param[in] Event Event whose notification function is being invoked.
559 @param[in] Context Pointer to the notification function's context.
570 // Init the communicate buffer. The buffer data size is:
571 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE.
573 InitCommunicateBuffer (NULL
, 0, SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE
);
578 SendCommunicateBuffer (0);
583 On Ready To Boot Services Event notification handler.
585 Notify SMM variable driver about the event.
587 @param[in] Event Event whose notification function is being invoked
588 @param[in] Context Pointer to the notification function's context
599 // Init the communicate buffer. The buffer data size is:
600 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE.
602 InitCommunicateBuffer (NULL
, 0, SMM_VARIABLE_FUNCTION_READY_TO_BOOT
);
607 SendCommunicateBuffer (0);
612 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
614 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
615 It convers pointer to new virtual address.
617 @param[in] Event Event whose notification function is being invoked.
618 @param[in] Context Pointer to the notification function's context.
623 VariableAddressChangeEvent (
628 EfiConvertPointer (0x0, (VOID
**) &mVariableBuffer
);
629 EfiConvertPointer (0x0, (VOID
**) &mSmmCommunication
);
634 Initialize variable service and install Variable Architectural protocol.
636 @param[in] Event Event whose notification function is being invoked.
637 @param[in] Context Pointer to the notification function's context.
649 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**)&mSmmVariable
);
650 if (EFI_ERROR (Status
)) {
654 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
655 ASSERT_EFI_ERROR (Status
);
658 // Allocate memory for variable store.
660 mVariableBufferSize
= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
661 mVariableBufferSize
+= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
));
662 mVariableBuffer
= AllocateRuntimePool (mVariableBufferSize
);
663 ASSERT (mVariableBuffer
!= NULL
);
666 // Save the buffer physical address used for SMM conmunication.
668 mVariableBufferPhysical
= mVariableBuffer
;
670 gRT
->GetVariable
= RuntimeServiceGetVariable
;
671 gRT
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
672 gRT
->SetVariable
= RuntimeServiceSetVariable
;
673 gRT
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
676 // Install the Variable Architectural Protocol on a new handle.
678 Status
= gBS
->InstallProtocolInterface (
680 &gEfiVariableArchProtocolGuid
,
681 EFI_NATIVE_INTERFACE
,
684 ASSERT_EFI_ERROR (Status
);
689 SMM Non-Volatile variable write service is ready notify event handler.
691 @param[in] Event Event whose notification function is being invoked.
692 @param[in] Context Pointer to the notification function's context.
697 SmmVariableWriteReady (
706 // Check whether the protocol is installed or not.
708 Status
= gBS
->LocateProtocol (&gSmmVariableWriteGuid
, NULL
, (VOID
**) &ProtocolOps
);
709 if (EFI_ERROR (Status
)) {
713 Status
= gBS
->InstallProtocolInterface (
715 &gEfiVariableWriteArchProtocolGuid
,
716 EFI_NATIVE_INTERFACE
,
719 ASSERT_EFI_ERROR (Status
);
724 Variable Driver main entry point. The Variable driver places the 4 EFI
725 runtime services in the EFI System Table and installs arch protocols
726 for variable read and write services being available. It also registers
727 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
729 @param[in] ImageHandle The firmware allocated handle for the EFI image.
730 @param[in] SystemTable A pointer to the EFI System Table.
732 @retval EFI_SUCCESS Variable service successfully initialized.
737 VariableSmmRuntimeInitialize (
738 IN EFI_HANDLE ImageHandle
,
739 IN EFI_SYSTEM_TABLE
*SystemTable
742 VOID
*SmmVariableRegistration
;
743 VOID
*SmmVariableWriteRegistration
;
744 EFI_EVENT OnReadyToBootEvent
;
745 EFI_EVENT ExitBootServiceEvent
;
747 EfiInitializeLock (&mVariableServicesLock
, TPL_NOTIFY
);
750 // Smm variable service is ready
752 EfiCreateProtocolNotifyEvent (
753 &gEfiSmmVariableProtocolGuid
,
757 &SmmVariableRegistration
761 // Smm Non-Volatile variable write service is ready
763 EfiCreateProtocolNotifyEvent (
764 &gSmmVariableWriteGuid
,
766 SmmVariableWriteReady
,
768 &SmmVariableWriteRegistration
772 // Register the event to reclaim variable for OS usage.
774 EfiCreateEventReadyToBootEx (
782 // Register the event to inform SMM variable that it is at runtime.
789 &gEfiEventExitBootServicesGuid
,
790 &ExitBootServiceEvent
794 // Register the event to convert the pointer for runtime.
799 VariableAddressChangeEvent
,
801 &gEfiEventVirtualAddressChangeGuid
,
802 &mVirtualAddressChangeEvent