]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/EmuRuntimeDxe/InitVariable.c
MdeModulePkg Variable: Align TPL level for (Smm)EndOfDxe callback
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / EmuRuntimeDxe / InitVariable.c
index efff41c25345c686101180e81e4451d0b532bb91..309a4b8dbfeb61e8b2e599b0a7dcd7aa1c6dc826 100644 (file)
@@ -1,7 +1,10 @@
-/*++\r
+/** @file\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+  Implment all four UEFI runtime variable services and \r
+  install variable architeture protocol.\r
+  \r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -9,53 +12,72 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
+**/\r
 \r
-  InitVariable.c\r
-\r
-Abstract:\r
+#include "Variable.h"\r
 \r
-Revision History\r
+EFI_EVENT   mVirtualAddressChangeEvent = NULL;\r
 \r
---*/\r
+/**\r
 \r
-#include "Variable.h"\r
+  This code finds variable in storage blocks (Volatile or Non-Volatile).\r
 \r
-//\r
-// Don't use module globals after the SetVirtualAddress map is signaled\r
-//\r
-extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
+  @param VariableName               Name of Variable to be found.\r
+  @param VendorGuid                 Variable vendor GUID.\r
+  @param Attributes                 Attribute value of the variable found.\r
+  @param DataSize                   Size of Data found. If size is less than the\r
+                                    data, this value contains the required size.\r
+  @param Data                       The buffer to return the contents of the variable. May be NULL\r
+                                    with a zero DataSize in order to determine the size buffer needed.\r
+                      \r
+  @return EFI_INVALID_PARAMETER     Invalid parameter\r
+  @return EFI_SUCCESS               Find the specified variable\r
+  @return EFI_NOT_FOUND             Not found\r
+  @return EFI_BUFFER_TO_SMALL       DataSize is too small for the result\r
 \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeServiceGetVariable (\r
   IN CHAR16        *VariableName,\r
-  IN EFI_GUID      * VendorGuid,\r
+  IN EFI_GUID      *VendorGuid,\r
   OUT UINT32       *Attributes OPTIONAL,\r
   IN OUT UINTN     *DataSize,\r
-  OUT VOID         *Data\r
+  OUT VOID         *Data OPTIONAL\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
 {\r
-  return GetVariable (\r
+  return EmuGetVariable (\r
           VariableName,\r
           VendorGuid,\r
           Attributes OPTIONAL,\r
           DataSize,\r
           Data,\r
-          &mVariableModuleGlobal->VariableGlobal[Physical],\r
-          mVariableModuleGlobal->FvbInstance\r
+          &mVariableModuleGlobal->VariableGlobal[Physical]\r
           );\r
 }\r
 \r
+/**\r
+\r
+  This code Finds the Next available variable.\r
+\r
+  @param  VariableNameSize       The size of the VariableName buffer. The size must be large enough to fit input\r
+                                 string supplied in VariableName buffer.\r
+  @param  VariableName           On input, supplies the last VariableName that was returned by GetNextVariableName().\r
+                                 On output, returns the Null-terminated Unicode string of the current variable.\r
+  @param  VendorGuid             On input, supplies the last VendorGuid that was returned by GetNextVariableName().\r
+                                 On output, returns the VendorGuid of the current variable.\r
+\r
+  @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_NOT_FOUND          The next variable was not found.\r
+  @retval EFI_BUFFER_TOO_SMALL   The VariableNameSize is too small for the result.\r
+                                 VariableNameSize has been updated with the size needed to complete the request.\r
+  @retval EFI_INVALID_PARAMETER  VariableNameSize or VariableName or VendorGuid is NULL.\r
+  @retval EFI_INVALID_PARAMETER  The input values of VariableName and VendorGuid are not a name and\r
+                                 GUID of an existing variable.\r
+  @retval EFI_INVALID_PARAMETER  Null-terminator is not found in the first VariableNameSize bytes of\r
+                                 the input VariableName buffer.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeServiceGetNextVariableName (\r
@@ -63,25 +85,33 @@ RuntimeServiceGetNextVariableName (
   IN OUT CHAR16    *VariableName,\r
   IN OUT EFI_GUID  *VendorGuid\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
 {\r
-  return GetNextVariableName (\r
+  return EmuGetNextVariableName (\r
           VariableNameSize,\r
           VariableName,\r
           VendorGuid,\r
-          &mVariableModuleGlobal->VariableGlobal[Physical],\r
-          mVariableModuleGlobal->FvbInstance\r
+          &mVariableModuleGlobal->VariableGlobal[Physical]\r
           );\r
 }\r
 \r
+/**\r
+\r
+  This code sets variable in storage blocks (Volatile or Non-Volatile).\r
+\r
+  @param VariableName                     Name of Variable to be found\r
+  @param VendorGuid                       Variable vendor GUID\r
+  @param Attributes                       Attribute value of the variable found\r
+  @param DataSize                         Size of Data found. If size is less than the\r
+                                          data, this value contains the required size.\r
+  @param Data                             Data pointer\r
+\r
+  @return EFI_INVALID_PARAMETER           Invalid parameter\r
+  @return EFI_SUCCESS                     Set successfully\r
+  @return EFI_OUT_OF_RESOURCES            Resource not enough to set variable\r
+  @return EFI_NOT_FOUND                   Not found\r
+  @return EFI_WRITE_PROTECTED             Variable is read-only\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeServiceSetVariable (\r
@@ -91,17 +121,8 @@ RuntimeServiceSetVariable (
   IN UINTN         DataSize,\r
   IN VOID          *Data\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
 {\r
-  return SetVariable (\r
+  return EmuSetVariable (\r
           VariableName,\r
           VendorGuid,\r
           Attributes,\r
@@ -109,11 +130,28 @@ Returns:
           Data,\r
           &mVariableModuleGlobal->VariableGlobal[Physical],\r
           &mVariableModuleGlobal->VolatileLastVariableOffset,\r
-          &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
-          mVariableModuleGlobal->FvbInstance\r
+          &mVariableModuleGlobal->NonVolatileLastVariableOffset\r
           );\r
 }\r
 \r
+/**\r
+\r
+  This code returns information about the EFI variables.\r
+\r
+  @param Attributes                     Attributes bitmask to specify the type of variables\r
+                                        on which to return information.\r
+  @param MaximumVariableStorageSize     Pointer to the maximum size of the storage space available\r
+                                        for the EFI variables associated with the attributes specified.\r
+  @param RemainingVariableStorageSize   Pointer to the remaining size of the storage space available\r
+                                        for EFI variables associated with the attributes specified.\r
+  @param MaximumVariableSize            Pointer to the maximum size of an individual EFI variables\r
+                                        associated with the attributes specified.\r
+\r
+  @return EFI_INVALID_PARAMETER         An invalid combination of attribute bits was supplied.\r
+  @return EFI_SUCCESS                   Query successfully.\r
+  @return EFI_UNSUPPORTED               The attribute is not supported on this platform.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 RuntimeServiceQueryVariableInfo (\r
@@ -122,42 +160,36 @@ RuntimeServiceQueryVariableInfo (
   OUT UINT64                 *RemainingVariableStorageSize,\r
   OUT UINT64                 *MaximumVariableSize\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
 {\r
-  return QueryVariableInfo (\r
+  return EmuQueryVariableInfo (\r
           Attributes,\r
           MaximumVariableStorageSize,\r
           RemainingVariableStorageSize,\r
           MaximumVariableSize,\r
-          &mVariableModuleGlobal->VariableGlobal[Physical],\r
-          mVariableModuleGlobal->FvbInstance\r
+          &mVariableModuleGlobal->VariableGlobal[Physical]\r
           );\r
 }\r
 \r
+/**\r
+  Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
+\r
+  This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
+  It convers pointer to new virtual address.\r
+\r
+  @param  Event        Event whose notification function is being invoked.\r
+  @param  Context      Pointer to the notification function's context.\r
+\r
+**/\r
 VOID\r
 EFIAPI\r
 VariableClassAddressChangeEvent (\r
   IN EFI_EVENT        Event,\r
   IN VOID             *Context\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
 {\r
+  EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r
+  EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r
+  EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r
   EfiConvertPointer (\r
     0x0,\r
     (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase\r
@@ -169,21 +201,24 @@ Returns:
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
 }\r
 \r
+/**\r
+  EmuVariable Driver main entry point. The Variable driver places the 4 EFI\r
+  runtime services in the EFI System Table and installs arch protocols \r
+  for variable read and write services being available. It also registers\r
+  notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       Variable service successfully initialized.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 VariableServiceInitialize (\r
   IN EFI_HANDLE         ImageHandle,\r
   IN EFI_SYSTEM_TABLE   *SystemTable\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
---*/\r
 {\r
   EFI_HANDLE  NewHandle;\r
   EFI_STATUS  Status;\r
@@ -210,5 +245,15 @@ Returns:
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  VariableClassAddressChangeEvent,\r
+                  NULL,\r
+                  &gEfiEventVirtualAddressChangeGuid,\r
+                  &mVirtualAddressChangeEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return EFI_SUCCESS;\r
 }\r