3 Implement all four UEFI Runtime Variable services for the nonvolatile
4 and volatile storage space and install variable architecture protocol
5 based on SMM variable module.
7 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Protocol/VariableWrite.h>
19 #include <Protocol/Variable.h>
20 #include <Protocol/SmmCommunication.h>
21 #include <Protocol/SmmVariable.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/UefiRuntimeServicesTableLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiRuntimeLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/PcdLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseLib.h>
34 #include <Guid/EventGroup.h>
35 #include <Guid/VariableFormat.h>
36 #include <Guid/SmmVariableCommon.h>
38 EFI_HANDLE mHandle
= NULL
;
39 EFI_SMM_VARIABLE_PROTOCOL
*mSmmVariable
= NULL
;
40 EFI_EVENT mVirtualAddressChangeEvent
= NULL
;
41 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
42 UINT8
*mVariableBuffer
= NULL
;
43 UINT8
*mVariableBufferPhysical
= NULL
;
44 UINTN mVariableBufferSize
;
45 EFI_LOCK mVariableServicesLock
;
48 Acquires lock only at boot time. Simply returns at runtime.
50 This is a temperary function that will be removed when
51 EfiAcquireLock() in UefiLib can handle the call in UEFI
52 Runtimer driver in RT phase.
53 It calls EfiAcquireLock() at boot time, and simply returns
56 @param Lock A pointer to the lock to acquire.
60 AcquireLockOnlyAtBootTime (
64 if (!EfiAtRuntime ()) {
65 EfiAcquireLock (Lock
);
70 Releases lock only at boot time. Simply returns at runtime.
72 This is a temperary function which will be removed when
73 EfiReleaseLock() in UefiLib can handle the call in UEFI
74 Runtimer driver in RT phase.
75 It calls EfiReleaseLock() at boot time and simply returns
78 @param Lock A pointer to the lock to release.
82 ReleaseLockOnlyAtBootTime (
86 if (!EfiAtRuntime ()) {
87 EfiReleaseLock (Lock
);
92 Initialize the communicate buffer using DataSize and Function.
94 The communicate size is: SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE +
97 @param[out] DataPtr Points to the data in the communicate buffer.
98 @param[in] DataSize The data size to send to SMM.
99 @param[in] Function The function number to initialize the communicate header.
101 @retval EFI_INVALID_PARAMETER The data size is too big.
102 @retval EFI_SUCCESS Find the specified variable.
106 InitCommunicateBuffer (
107 OUT VOID
**DataPtr OPTIONAL
,
112 EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
;
113 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
116 if (DataSize
+ SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
> mVariableBufferSize
) {
117 return EFI_INVALID_PARAMETER
;
120 SmmCommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) mVariableBuffer
;
121 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
122 SmmCommunicateHeader
->MessageLength
= DataSize
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
124 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) SmmCommunicateHeader
->Data
;
125 SmmVariableFunctionHeader
->Function
= Function
;
126 if (DataPtr
!= NULL
) {
127 *DataPtr
= SmmVariableFunctionHeader
->Data
;
135 Send the data in communicate buffer to SMM.
137 @param[in] DataSize This size of the function header and the data.
139 @retval EFI_SUCCESS Success is returned from the functin in SMM.
140 @retval Others Failure is returned from the function in SMM.
144 SendCommunicateBuffer (
150 EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
;
151 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
153 CommSize
= DataSize
+ SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
154 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, mVariableBufferPhysical
, &CommSize
);
155 ASSERT_EFI_ERROR (Status
);
157 SmmCommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) mVariableBuffer
;
158 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*)SmmCommunicateHeader
->Data
;
159 return SmmVariableFunctionHeader
->ReturnStatus
;
164 This code finds variable in storage blocks (Volatile or Non-Volatile).
166 @param[in] VariableName Name of Variable to be found.
167 @param[in] VendorGuid Variable vendor GUID.
168 @param[out] Attributes Attribute value of the variable found.
169 @param[in, out] DataSize Size of Data found. If size is less than the
170 data, this value contains the required size.
171 @param[out] Data Data pointer.
173 @retval EFI_INVALID_PARAMETER Invalid parameter.
174 @retval EFI_SUCCESS Find the specified variable.
175 @retval EFI_NOT_FOUND Not found.
176 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
181 RuntimeServiceGetVariable (
182 IN CHAR16
*VariableName
,
183 IN EFI_GUID
*VendorGuid
,
184 OUT UINT32
*Attributes OPTIONAL
,
185 IN OUT UINTN
*DataSize
,
191 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
*SmmVariableHeader
;
192 UINTN SmmCommBufPayloadSize
;
195 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
196 return EFI_INVALID_PARAMETER
;
199 if ((*DataSize
!= 0) && (Data
== NULL
)) {
200 return EFI_INVALID_PARAMETER
;
204 // SMM Communication Buffer max payload size
206 SmmCommBufPayloadSize
= mVariableBufferSize
- (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
);
207 TempDataSize
= *DataSize
;
210 // If VariableName exceeds SMM payload limit. Return failure
212 if (StrSize (VariableName
) > SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
)) {
213 return EFI_INVALID_PARAMETER
;
216 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
219 // Init the communicate buffer. The buffer data size is:
220 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
222 if (TempDataSize
> SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - StrSize (VariableName
)) {
224 // If output data buffer exceed SMM payload limit. Trim output buffer to SMM payload size
226 TempDataSize
= SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - StrSize (VariableName
);
228 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + StrSize (VariableName
) + TempDataSize
;
230 Status
= InitCommunicateBuffer ((VOID
**)&SmmVariableHeader
, PayloadSize
, SMM_VARIABLE_FUNCTION_GET_VARIABLE
);
231 if (EFI_ERROR (Status
)) {
234 ASSERT (SmmVariableHeader
!= NULL
);
236 CopyGuid (&SmmVariableHeader
->Guid
, VendorGuid
);
237 SmmVariableHeader
->DataSize
= TempDataSize
;
238 SmmVariableHeader
->NameSize
= StrSize (VariableName
);
239 if (Attributes
== NULL
) {
240 SmmVariableHeader
->Attributes
= 0;
242 SmmVariableHeader
->Attributes
= *Attributes
;
244 CopyMem (SmmVariableHeader
->Name
, VariableName
, SmmVariableHeader
->NameSize
);
249 Status
= SendCommunicateBuffer (PayloadSize
);
252 // Get data from SMM.
254 if (Status
== EFI_SUCCESS
|| Status
== EFI_BUFFER_TOO_SMALL
) {
256 // SMM CommBuffer DataSize can be a trimed value
257 // Only update DataSize when needed
259 *DataSize
= SmmVariableHeader
->DataSize
;
261 if (Attributes
!= NULL
) {
262 *Attributes
= SmmVariableHeader
->Attributes
;
265 if (EFI_ERROR (Status
)) {
269 CopyMem (Data
, (UINT8
*)SmmVariableHeader
->Name
+ SmmVariableHeader
->NameSize
, SmmVariableHeader
->DataSize
);
272 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
278 This code Finds the Next available variable.
280 @param[in, out] VariableNameSize Size of the variable name.
281 @param[in, out] VariableName Pointer to variable name.
282 @param[in, out] VendorGuid Variable Vendor Guid.
284 @retval EFI_INVALID_PARAMETER Invalid parameter.
285 @retval EFI_SUCCESS Find the specified variable.
286 @retval EFI_NOT_FOUND Not found.
287 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
292 RuntimeServiceGetNextVariableName (
293 IN OUT UINTN
*VariableNameSize
,
294 IN OUT CHAR16
*VariableName
,
295 IN OUT EFI_GUID
*VendorGuid
300 SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
*SmmGetNextVariableName
;
301 UINTN SmmCommBufPayloadSize
;
303 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
304 return EFI_INVALID_PARAMETER
;
308 // SMM Communication Buffer max payload size
310 SmmCommBufPayloadSize
= mVariableBufferSize
- (SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
);
313 // If input string exceeds SMM payload limit. Return failure
315 if (StrSize (VariableName
) > SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
)) {
316 return EFI_INVALID_PARAMETER
;
319 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
322 // Init the communicate buffer. The buffer data size is:
323 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
325 if (*VariableNameSize
> SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
)) {
327 // If output buffer exceed SMM payload limit. Trim output buffer to SMM payload size
329 *VariableNameSize
= SmmCommBufPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
);
332 // Payload should be Guid + NameSize + MAX of Input & Output buffer
334 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
) + MAX (*VariableNameSize
, StrSize (VariableName
));
337 Status
= InitCommunicateBuffer ((VOID
**)&SmmGetNextVariableName
, PayloadSize
, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME
);
338 if (EFI_ERROR (Status
)) {
341 ASSERT (SmmGetNextVariableName
!= NULL
);
344 // SMM comm buffer->NameSize is buffer size for return string
346 SmmGetNextVariableName
->NameSize
= *VariableNameSize
;
348 CopyGuid (&SmmGetNextVariableName
->Guid
, VendorGuid
);
352 CopyMem (SmmGetNextVariableName
->Name
, VariableName
, StrSize (VariableName
));
357 Status
= SendCommunicateBuffer (PayloadSize
);
360 // Get data from SMM.
362 *VariableNameSize
= SmmGetNextVariableName
->NameSize
;
363 if (EFI_ERROR (Status
)) {
367 CopyGuid (VendorGuid
, &SmmGetNextVariableName
->Guid
);
368 CopyMem (VariableName
, SmmGetNextVariableName
->Name
, SmmGetNextVariableName
->NameSize
);
371 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
376 This code sets variable in storage blocks (Volatile or Non-Volatile).
378 @param[in] VariableName Name of Variable to be found.
379 @param[in] VendorGuid Variable vendor GUID.
380 @param[in] Attributes Attribute value of the variable found
381 @param[in] DataSize Size of Data found. If size is less than the
382 data, this value contains the required size.
383 @param[in] Data Data pointer.
385 @retval EFI_INVALID_PARAMETER Invalid parameter.
386 @retval EFI_SUCCESS Set successfully.
387 @retval EFI_OUT_OF_RESOURCES Resource not enough to set variable.
388 @retval EFI_NOT_FOUND Not found.
389 @retval EFI_WRITE_PROTECTED Variable is read-only.
394 RuntimeServiceSetVariable (
395 IN CHAR16
*VariableName
,
396 IN EFI_GUID
*VendorGuid
,
397 IN UINT32 Attributes
,
404 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
*SmmVariableHeader
;
407 // Check input parameters.
409 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
410 return EFI_INVALID_PARAMETER
;
413 if (DataSize
!= 0 && Data
== NULL
) {
414 return EFI_INVALID_PARAMETER
;
417 if (DataSize
>= mVariableBufferSize
) {
419 // DataSize may be near MAX_ADDRESS incorrectly, this can cause the computed PayLoadSize to
420 // overflow to a small value and pass the check in InitCommunicateBuffer().
421 // To protect against this vulnerability, return EFI_INVALID_PARAMETER if DataSize is >= mVariableBufferSize.
422 // And there will be further check to ensure the total size is also not > mVariableBufferSize.
424 return EFI_INVALID_PARAMETER
;
427 if ((UINTN
)(~0) - StrSize (VariableName
) < OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + DataSize
) {
429 // Prevent PayloadSize overflow
431 return EFI_INVALID_PARAMETER
;
434 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
437 // Init the communicate buffer. The buffer data size is:
438 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
440 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + StrSize (VariableName
) + DataSize
;
441 Status
= InitCommunicateBuffer ((VOID
**)&SmmVariableHeader
, PayloadSize
, SMM_VARIABLE_FUNCTION_SET_VARIABLE
);
442 if (EFI_ERROR (Status
)) {
445 ASSERT (SmmVariableHeader
!= NULL
);
447 CopyGuid ((EFI_GUID
*) &SmmVariableHeader
->Guid
, VendorGuid
);
448 SmmVariableHeader
->DataSize
= DataSize
;
449 SmmVariableHeader
->NameSize
= StrSize (VariableName
);
450 SmmVariableHeader
->Attributes
= Attributes
;
451 CopyMem (SmmVariableHeader
->Name
, VariableName
, SmmVariableHeader
->NameSize
);
452 CopyMem ((UINT8
*) SmmVariableHeader
->Name
+ SmmVariableHeader
->NameSize
, Data
, DataSize
);
457 Status
= SendCommunicateBuffer (PayloadSize
);
460 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
466 This code returns information about the EFI variables.
468 @param[in] Attributes Attributes bitmask to specify the type of variables
469 on which to return information.
470 @param[out] MaximumVariableStorageSize Pointer to the maximum size of the storage space available
471 for the EFI variables associated with the attributes specified.
472 @param[out] RemainingVariableStorageSize Pointer to the remaining size of the storage space available
473 for EFI variables associated with the attributes specified.
474 @param[out] MaximumVariableSize Pointer to the maximum size of an individual EFI variables
475 associated with the attributes specified.
477 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
478 @retval EFI_SUCCESS Query successfully.
479 @retval EFI_UNSUPPORTED The attribute is not supported on this platform.
484 RuntimeServiceQueryVariableInfo (
485 IN UINT32 Attributes
,
486 OUT UINT64
*MaximumVariableStorageSize
,
487 OUT UINT64
*RemainingVariableStorageSize
,
488 OUT UINT64
*MaximumVariableSize
493 SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO
*SmmQueryVariableInfo
;
495 if(MaximumVariableStorageSize
== NULL
|| RemainingVariableStorageSize
== NULL
|| MaximumVariableSize
== NULL
|| Attributes
== 0) {
496 return EFI_INVALID_PARAMETER
;
499 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
502 // Init the communicate buffer. The buffer data size is:
503 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize;
505 PayloadSize
= sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO
);
506 Status
= InitCommunicateBuffer ((VOID
**)&SmmQueryVariableInfo
, PayloadSize
, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO
);
507 if (EFI_ERROR (Status
)) {
510 ASSERT (SmmQueryVariableInfo
!= NULL
);
512 SmmQueryVariableInfo
->Attributes
= Attributes
;
517 Status
= SendCommunicateBuffer (PayloadSize
);
518 if (EFI_ERROR (Status
)) {
523 // Get data from SMM.
525 *MaximumVariableSize
= SmmQueryVariableInfo
->MaximumVariableSize
;
526 *MaximumVariableStorageSize
= SmmQueryVariableInfo
->MaximumVariableStorageSize
;
527 *RemainingVariableStorageSize
= SmmQueryVariableInfo
->RemainingVariableStorageSize
;
530 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
536 Exit Boot Services Event notification handler.
538 Notify SMM variable driver about the event.
540 @param[in] Event Event whose notification function is being invoked.
541 @param[in] Context Pointer to the notification function's context.
552 // Init the communicate buffer. The buffer data size is:
553 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE.
555 InitCommunicateBuffer (NULL
, 0, SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE
);
560 SendCommunicateBuffer (0);
565 On Ready To Boot Services Event notification handler.
567 Notify SMM variable driver about the event.
569 @param[in] Event Event whose notification function is being invoked
570 @param[in] Context Pointer to the notification function's context
581 // Init the communicate buffer. The buffer data size is:
582 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE.
584 InitCommunicateBuffer (NULL
, 0, SMM_VARIABLE_FUNCTION_READY_TO_BOOT
);
589 SendCommunicateBuffer (0);
594 Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
596 This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
597 It convers pointer to new virtual address.
599 @param[in] Event Event whose notification function is being invoked.
600 @param[in] Context Pointer to the notification function's context.
605 VariableAddressChangeEvent (
610 EfiConvertPointer (0x0, (VOID
**) &mVariableBuffer
);
611 EfiConvertPointer (0x0, (VOID
**) &mSmmCommunication
);
616 Initialize variable service and install Variable Architectural protocol.
618 @param[in] Event Event whose notification function is being invoked.
619 @param[in] Context Pointer to the notification function's context.
631 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**)&mSmmVariable
);
632 if (EFI_ERROR (Status
)) {
636 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
637 ASSERT_EFI_ERROR (Status
);
640 // Allocate memory for variable store.
642 mVariableBufferSize
= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
643 mVariableBufferSize
+= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
));
644 mVariableBuffer
= AllocateRuntimePool (mVariableBufferSize
);
645 ASSERT (mVariableBuffer
!= NULL
);
648 // Save the buffer physical address used for SMM conmunication.
650 mVariableBufferPhysical
= mVariableBuffer
;
652 gRT
->GetVariable
= RuntimeServiceGetVariable
;
653 gRT
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
654 gRT
->SetVariable
= RuntimeServiceSetVariable
;
655 gRT
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
658 // Install the Variable Architectural Protocol on a new handle.
660 Status
= gBS
->InstallProtocolInterface (
662 &gEfiVariableArchProtocolGuid
,
663 EFI_NATIVE_INTERFACE
,
666 ASSERT_EFI_ERROR (Status
);
671 SMM Non-Volatile variable write service is ready notify event handler.
673 @param[in] Event Event whose notification function is being invoked.
674 @param[in] Context Pointer to the notification function's context.
679 SmmVariableWriteReady (
688 // Check whether the protocol is installed or not.
690 Status
= gBS
->LocateProtocol (&gSmmVariableWriteGuid
, NULL
, (VOID
**) &ProtocolOps
);
691 if (EFI_ERROR (Status
)) {
695 Status
= gBS
->InstallProtocolInterface (
697 &gEfiVariableWriteArchProtocolGuid
,
698 EFI_NATIVE_INTERFACE
,
701 ASSERT_EFI_ERROR (Status
);
706 Variable Driver main entry point. The Variable driver places the 4 EFI
707 runtime services in the EFI System Table and installs arch protocols
708 for variable read and write services being available. It also registers
709 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
711 @param[in] ImageHandle The firmware allocated handle for the EFI image.
712 @param[in] SystemTable A pointer to the EFI System Table.
714 @retval EFI_SUCCESS Variable service successfully initialized.
719 VariableSmmRuntimeInitialize (
720 IN EFI_HANDLE ImageHandle
,
721 IN EFI_SYSTEM_TABLE
*SystemTable
724 VOID
*SmmVariableRegistration
;
725 VOID
*SmmVariableWriteRegistration
;
726 EFI_EVENT OnReadyToBootEvent
;
727 EFI_EVENT ExitBootServiceEvent
;
729 EfiInitializeLock (&mVariableServicesLock
, TPL_NOTIFY
);
732 // Smm variable service is ready
734 EfiCreateProtocolNotifyEvent (
735 &gEfiSmmVariableProtocolGuid
,
739 &SmmVariableRegistration
743 // Smm Non-Volatile variable write service is ready
745 EfiCreateProtocolNotifyEvent (
746 &gSmmVariableWriteGuid
,
748 SmmVariableWriteReady
,
750 &SmmVariableWriteRegistration
754 // Register the event to reclaim variable for OS usage.
756 EfiCreateEventReadyToBootEx (
764 // Register the event to inform SMM variable that it is at runtime.
771 &gEfiEventExitBootServicesGuid
,
772 &ExitBootServiceEvent
776 // Register the event to convert the pointer for runtime.
781 VariableAddressChangeEvent
,
783 &gEfiEventVirtualAddressChangeGuid
,
784 &mVirtualAddressChangeEvent