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 UINTN mVariableBufferPayloadSize
;
56 EFI_LOCK mVariableServicesLock
;
59 Acquires lock only at boot time. Simply returns at runtime.
61 This is a temperary function that will be removed when
62 EfiAcquireLock() in UefiLib can handle the call in UEFI
63 Runtimer driver in RT phase.
64 It calls EfiAcquireLock() at boot time, and simply returns
67 @param Lock A pointer to the lock to acquire.
71 AcquireLockOnlyAtBootTime (
75 if (!EfiAtRuntime ()) {
76 EfiAcquireLock (Lock
);
81 Releases lock only at boot time. Simply returns at runtime.
83 This is a temperary function which will be removed when
84 EfiReleaseLock() in UefiLib can handle the call in UEFI
85 Runtimer driver in RT phase.
86 It calls EfiReleaseLock() at boot time and simply returns
89 @param Lock A pointer to the lock to release.
93 ReleaseLockOnlyAtBootTime (
97 if (!EfiAtRuntime ()) {
98 EfiReleaseLock (Lock
);
103 Initialize the communicate buffer using DataSize and Function.
105 The communicate size is: SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE +
108 Caution: This function may receive untrusted input.
109 The data size external input, so this function will validate it carefully to avoid buffer overflow.
111 @param[out] DataPtr Points to the data in the communicate buffer.
112 @param[in] DataSize The data size to send to SMM.
113 @param[in] Function The function number to initialize the communicate header.
115 @retval EFI_INVALID_PARAMETER The data size is too big.
116 @retval EFI_SUCCESS Find the specified variable.
120 InitCommunicateBuffer (
121 OUT VOID
**DataPtr OPTIONAL
,
126 EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
;
127 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
130 if (DataSize
+ SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
> mVariableBufferSize
) {
131 return EFI_INVALID_PARAMETER
;
134 SmmCommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) mVariableBuffer
;
135 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
136 SmmCommunicateHeader
->MessageLength
= DataSize
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
138 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) SmmCommunicateHeader
->Data
;
139 SmmVariableFunctionHeader
->Function
= Function
;
140 if (DataPtr
!= NULL
) {
141 *DataPtr
= SmmVariableFunctionHeader
->Data
;
149 Send the data in communicate buffer to SMM.
151 @param[in] DataSize This size of the function header and the data.
153 @retval EFI_SUCCESS Success is returned from the functin in SMM.
154 @retval Others Failure is returned from the function in SMM.
158 SendCommunicateBuffer (
164 EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
;
165 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
167 CommSize
= DataSize
+ SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
168 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, mVariableBufferPhysical
, &CommSize
);
169 ASSERT_EFI_ERROR (Status
);
171 SmmCommunicateHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) mVariableBuffer
;
172 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*)SmmCommunicateHeader
->Data
;
173 return SmmVariableFunctionHeader
->ReturnStatus
;
178 This code finds variable in storage blocks (Volatile or Non-Volatile).
180 Caution: This function may receive untrusted input.
181 The data size is external input, so this function will validate it carefully to avoid buffer overflow.
183 @param[in] VariableName Name of Variable to be found.
184 @param[in] VendorGuid Variable vendor GUID.
185 @param[out] Attributes Attribute value of the variable found.
186 @param[in, out] DataSize Size of Data found. If size is less than the
187 data, this value contains the required size.
188 @param[out] Data Data pointer.
190 @retval EFI_INVALID_PARAMETER Invalid parameter.
191 @retval EFI_SUCCESS Find the specified variable.
192 @retval EFI_NOT_FOUND Not found.
193 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
198 RuntimeServiceGetVariable (
199 IN CHAR16
*VariableName
,
200 IN EFI_GUID
*VendorGuid
,
201 OUT UINT32
*Attributes OPTIONAL
,
202 IN OUT UINTN
*DataSize
,
208 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
*SmmVariableHeader
;
210 UINTN VariableNameSize
;
212 if (VariableName
== NULL
|| VendorGuid
== NULL
|| DataSize
== NULL
) {
213 return EFI_INVALID_PARAMETER
;
216 if ((*DataSize
!= 0) && (Data
== NULL
)) {
217 return EFI_INVALID_PARAMETER
;
220 TempDataSize
= *DataSize
;
221 VariableNameSize
= StrSize (VariableName
);
224 // If VariableName exceeds SMM payload limit. Return failure
226 if (VariableNameSize
> mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
)) {
227 return EFI_INVALID_PARAMETER
;
230 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
233 // Init the communicate buffer. The buffer data size is:
234 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
236 if (TempDataSize
> mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - VariableNameSize
) {
238 // If output data buffer exceed SMM payload limit. Trim output buffer to SMM payload size
240 TempDataSize
= mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - VariableNameSize
;
242 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) + VariableNameSize
+ TempDataSize
;
244 Status
= InitCommunicateBuffer ((VOID
**)&SmmVariableHeader
, PayloadSize
, SMM_VARIABLE_FUNCTION_GET_VARIABLE
);
245 if (EFI_ERROR (Status
)) {
248 ASSERT (SmmVariableHeader
!= NULL
);
250 CopyGuid (&SmmVariableHeader
->Guid
, VendorGuid
);
251 SmmVariableHeader
->DataSize
= TempDataSize
;
252 SmmVariableHeader
->NameSize
= VariableNameSize
;
253 if (Attributes
== NULL
) {
254 SmmVariableHeader
->Attributes
= 0;
256 SmmVariableHeader
->Attributes
= *Attributes
;
258 CopyMem (SmmVariableHeader
->Name
, VariableName
, SmmVariableHeader
->NameSize
);
263 Status
= SendCommunicateBuffer (PayloadSize
);
266 // Get data from SMM.
268 if (Status
== EFI_SUCCESS
|| Status
== EFI_BUFFER_TOO_SMALL
) {
270 // SMM CommBuffer DataSize can be a trimed value
271 // Only update DataSize when needed
273 *DataSize
= SmmVariableHeader
->DataSize
;
275 if (Attributes
!= NULL
) {
276 *Attributes
= SmmVariableHeader
->Attributes
;
279 if (EFI_ERROR (Status
)) {
283 CopyMem (Data
, (UINT8
*)SmmVariableHeader
->Name
+ SmmVariableHeader
->NameSize
, SmmVariableHeader
->DataSize
);
286 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
292 This code Finds the Next available variable.
294 @param[in, out] VariableNameSize Size of the variable name.
295 @param[in, out] VariableName Pointer to variable name.
296 @param[in, out] VendorGuid Variable Vendor Guid.
298 @retval EFI_INVALID_PARAMETER Invalid parameter.
299 @retval EFI_SUCCESS Find the specified variable.
300 @retval EFI_NOT_FOUND Not found.
301 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
306 RuntimeServiceGetNextVariableName (
307 IN OUT UINTN
*VariableNameSize
,
308 IN OUT CHAR16
*VariableName
,
309 IN OUT EFI_GUID
*VendorGuid
314 SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
*SmmGetNextVariableName
;
315 UINTN OutVariableNameSize
;
316 UINTN InVariableNameSize
;
318 if (VariableNameSize
== NULL
|| VariableName
== NULL
|| VendorGuid
== NULL
) {
319 return EFI_INVALID_PARAMETER
;
322 OutVariableNameSize
= *VariableNameSize
;
323 InVariableNameSize
= StrSize (VariableName
);
326 // If input string exceeds SMM payload limit. Return failure
328 if (InVariableNameSize
> mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
)) {
329 return EFI_INVALID_PARAMETER
;
332 AcquireLockOnlyAtBootTime(&mVariableServicesLock
);
335 // Init the communicate buffer. The buffer data size is:
336 // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
338 if (OutVariableNameSize
> mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
)) {
340 // If output buffer exceed SMM payload limit. Trim output buffer to SMM payload size
342 OutVariableNameSize
= mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
);
345 // Payload should be Guid + NameSize + MAX of Input & Output buffer
347 PayloadSize
= OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME
, Name
) + MAX (OutVariableNameSize
, InVariableNameSize
);
349 Status
= InitCommunicateBuffer ((VOID
**)&SmmGetNextVariableName
, PayloadSize
, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME
);
350 if (EFI_ERROR (Status
)) {
353 ASSERT (SmmGetNextVariableName
!= NULL
);
356 // SMM comm buffer->NameSize is buffer size for return string
358 SmmGetNextVariableName
->NameSize
= OutVariableNameSize
;
360 CopyGuid (&SmmGetNextVariableName
->Guid
, VendorGuid
);
364 CopyMem (SmmGetNextVariableName
->Name
, VariableName
, InVariableNameSize
);
365 if (OutVariableNameSize
> InVariableNameSize
) {
366 ZeroMem ((UINT8
*) SmmGetNextVariableName
->Name
+ InVariableNameSize
, OutVariableNameSize
- InVariableNameSize
);
372 Status
= SendCommunicateBuffer (PayloadSize
);
375 // Get data from SMM.
377 if (Status
== EFI_SUCCESS
|| Status
== EFI_BUFFER_TOO_SMALL
) {
379 // SMM CommBuffer NameSize can be a trimed value
380 // Only update VariableNameSize when needed
382 *VariableNameSize
= SmmGetNextVariableName
->NameSize
;
384 if (EFI_ERROR (Status
)) {
388 CopyGuid (VendorGuid
, &SmmGetNextVariableName
->Guid
);
389 CopyMem (VariableName
, SmmGetNextVariableName
->Name
, SmmGetNextVariableName
->NameSize
);
392 ReleaseLockOnlyAtBootTime (&mVariableServicesLock
);
397 This code sets variable in storage blocks (Volatile or Non-Volatile).
399 Caution: This function may receive untrusted input.
400 The data size and data are external input, so this function will validate it carefully to avoid buffer overflow.
402 @param[in] VariableName Name of Variable to be found.
403 @param[in] VendorGuid Variable vendor GUID.
404 @param[in] Attributes Attribute value of the variable found
405 @param[in] DataSize Size of Data found. If size is less than the
406 data, this value contains the required size.
407 @param[in] Data Data pointer.
409 @retval EFI_INVALID_PARAMETER Invalid parameter.
410 @retval EFI_SUCCESS Set successfully.
411 @retval EFI_OUT_OF_RESOURCES Resource not enough to set variable.
412 @retval EFI_NOT_FOUND Not found.
413 @retval EFI_WRITE_PROTECTED Variable is read-only.
418 RuntimeServiceSetVariable (
419 IN CHAR16
*VariableName
,
420 IN EFI_GUID
*VendorGuid
,
421 IN UINT32 Attributes
,
428 SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
*SmmVariableHeader
;
429 UINTN VariableNameSize
;
432 // Check input parameters.
434 if (VariableName
== NULL
|| VariableName
[0] == 0 || VendorGuid
== NULL
) {
435 return EFI_INVALID_PARAMETER
;
438 if (DataSize
!= 0 && Data
== NULL
) {
439 return EFI_INVALID_PARAMETER
;
442 VariableNameSize
= StrSize (VariableName
);
445 // If VariableName or DataSize exceeds SMM payload limit. Return failure
447 if ((VariableNameSize
> mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
)) ||
448 (DataSize
> mVariableBufferPayloadSize
- OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - VariableNameSize
)){
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
) + VariableNameSize
+ 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
= VariableNameSize
;
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 communicate buffer.
660 mVariableBufferPayloadSize
= MAX (PcdGet32 (PcdMaxVariableSize
), PcdGet32 (PcdMaxHardwareErrorVariableSize
)) +
661 OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE
, Name
) - sizeof (VARIABLE_HEADER
);
662 mVariableBufferSize
= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
+ mVariableBufferPayloadSize
;
663 mVariableBuffer
= AllocateRuntimePool (mVariableBufferSize
);
664 ASSERT (mVariableBuffer
!= NULL
);
667 // Save the buffer physical address used for SMM conmunication.
669 mVariableBufferPhysical
= mVariableBuffer
;
671 gRT
->GetVariable
= RuntimeServiceGetVariable
;
672 gRT
->GetNextVariableName
= RuntimeServiceGetNextVariableName
;
673 gRT
->SetVariable
= RuntimeServiceSetVariable
;
674 gRT
->QueryVariableInfo
= RuntimeServiceQueryVariableInfo
;
677 // Install the Variable Architectural Protocol on a new handle.
679 Status
= gBS
->InstallProtocolInterface (
681 &gEfiVariableArchProtocolGuid
,
682 EFI_NATIVE_INTERFACE
,
685 ASSERT_EFI_ERROR (Status
);
690 SMM Non-Volatile variable write service is ready notify event handler.
692 @param[in] Event Event whose notification function is being invoked.
693 @param[in] Context Pointer to the notification function's context.
698 SmmVariableWriteReady (
707 // Check whether the protocol is installed or not.
709 Status
= gBS
->LocateProtocol (&gSmmVariableWriteGuid
, NULL
, (VOID
**) &ProtocolOps
);
710 if (EFI_ERROR (Status
)) {
714 Status
= gBS
->InstallProtocolInterface (
716 &gEfiVariableWriteArchProtocolGuid
,
717 EFI_NATIVE_INTERFACE
,
720 ASSERT_EFI_ERROR (Status
);
725 Variable Driver main entry point. The Variable driver places the 4 EFI
726 runtime services in the EFI System Table and installs arch protocols
727 for variable read and write services being available. It also registers
728 a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
730 @param[in] ImageHandle The firmware allocated handle for the EFI image.
731 @param[in] SystemTable A pointer to the EFI System Table.
733 @retval EFI_SUCCESS Variable service successfully initialized.
738 VariableSmmRuntimeInitialize (
739 IN EFI_HANDLE ImageHandle
,
740 IN EFI_SYSTEM_TABLE
*SystemTable
743 VOID
*SmmVariableRegistration
;
744 VOID
*SmmVariableWriteRegistration
;
745 EFI_EVENT OnReadyToBootEvent
;
746 EFI_EVENT ExitBootServiceEvent
;
748 EfiInitializeLock (&mVariableServicesLock
, TPL_NOTIFY
);
751 // Smm variable service is ready
753 EfiCreateProtocolNotifyEvent (
754 &gEfiSmmVariableProtocolGuid
,
758 &SmmVariableRegistration
762 // Smm Non-Volatile variable write service is ready
764 EfiCreateProtocolNotifyEvent (
765 &gSmmVariableWriteGuid
,
767 SmmVariableWriteReady
,
769 &SmmVariableWriteRegistration
773 // Register the event to reclaim variable for OS usage.
775 EfiCreateEventReadyToBootEx (
783 // Register the event to inform SMM variable that it is at runtime.
790 &gEfiEventExitBootServicesGuid
,
791 &ExitBootServiceEvent
795 // Register the event to convert the pointer for runtime.
800 VariableAddressChangeEvent
,
802 &gEfiEventVirtualAddressChangeGuid
,
803 &mVirtualAddressChangeEvent