]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c
1. delete Include/Guid/VariableInfo.h
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / Variable.c
index 2d6d428636cc6dca510aeeb92cf658bfa599b45e..d25fe038aa6800fc40e2e247b50fab72d88c8dab 100644 (file)
@@ -3,7 +3,7 @@
   Implement all four UEFI Runtime Variable services for the nonvolatile\r
   and volatile storage space and install variable architecture protocol.\r
   \r
-Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2009, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -36,9 +36,7 @@ VARIABLE_CACHE_ENTRY mVariableCache[] = {
   }\r
 };\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED VARIABLE_INFO_ENTRY *gVariableInfo = NULL;\r
-\r
-\r
+VARIABLE_INFO_ENTRY *gVariableInfo = NULL;\r
 \r
 /**\r
   Acquires lock only at boot time. Simply returns at runtime.\r
@@ -135,10 +133,11 @@ UpdateVariableInfo (
 \r
       CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);\r
       gVariableInfo->Name = AllocatePool (StrLen (VariableName));\r
+      ASSERT (gVariableInfo->Name != NULL);\r
       StrCpy (gVariableInfo->Name, VariableName);\r
       gVariableInfo->Volatile = Volatile;\r
 \r
-      gBS->InstallConfigurationTable (&gEfiVariableInfoGuid, gVariableInfo);\r
+      gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
     }\r
 \r
     \r
@@ -172,6 +171,7 @@ UpdateVariableInfo (
 \r
         CopyGuid (&Entry->Next->VendorGuid, VendorGuid);\r
         Entry->Next->Name = AllocatePool (StrLen (VariableName));\r
+        ASSERT (Entry->Next->Name != NULL);\r
         StrCpy (Entry->Next->Name, VariableName);\r
         Entry->Next->Volatile = Volatile;\r
       }\r
@@ -362,16 +362,19 @@ GetVariableStoreStatus (
   IN VARIABLE_STORE_HEADER *VarStoreHeader\r
   )\r
 {\r
-  if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE &&\r
+  if (CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid) &&\r
       VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&\r
       VarStoreHeader->State == VARIABLE_STORE_HEALTHY\r
       ) {\r
 \r
     return EfiValid;\r
-  } else if (VarStoreHeader->Signature == 0xffffffff &&\r
-           VarStoreHeader->Size == 0xffffffff &&\r
-           VarStoreHeader->Format == 0xff &&\r
-           VarStoreHeader->State == 0xff\r
+  } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&\r
+             ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&\r
+             ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&\r
+             ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&\r
+             VarStoreHeader->Size == 0xffffffff &&\r
+             VarStoreHeader->Format == 0xff &&\r
+             VarStoreHeader->State == 0xff\r
           ) {\r
 \r
     return EfiRaw;\r
@@ -747,7 +750,7 @@ Reclaim (
 \r
   @param[in] VariableName  Name of variable\r
   @param[in] VendorGuid    Guid of variable\r
-  @param[in] Attribute     Attribue of the variable\r
+  @param[in] Attributes    Attribues of the variable\r
   @param[in] DataSize      Size of data. 0 means delete\r
   @param[in] Data          Variable data\r
 \r
@@ -765,7 +768,9 @@ UpdateVariableCache (
   UINTN                     Index;\r
 \r
   if (EfiAtRuntime ()) {\r
+    //\r
     // Don't use the cache at runtime\r
+    // \r
     return;\r
   }\r
 \r
@@ -774,7 +779,9 @@ UpdateVariableCache (
       if (StrCmp (VariableName, Entry->Name) == 0) { \r
         Entry->Attributes = Attributes;\r
         if (DataSize == 0) {\r
+          //\r
           // Delete Case\r
+          //\r
           if (Entry->DataSize != 0) {\r
             FreePool (Entry->Data);\r
           }\r
@@ -783,6 +790,8 @@ UpdateVariableCache (
           CopyMem (Entry->Data, Data, DataSize);\r
         } else {\r
           Entry->Data = AllocatePool (DataSize);\r
+          ASSERT (Entry->Data != NULL);\r
+\r
           Entry->DataSize = DataSize;\r
           CopyMem (Entry->Data, Data, DataSize);\r
         }\r
@@ -921,7 +930,7 @@ FindVariable (
       if (Variable[Index]->State == VAR_ADDED || \r
           Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)\r
          ) {\r
-        if (!EfiAtRuntime () || (Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+        if (!EfiAtRuntime () || ((Variable[Index]->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {\r
           if (VariableName[0] == 0) {\r
             if (Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
               InDeletedVariable     = Variable[Index];\r
@@ -939,7 +948,7 @@ FindVariable (
               Point = (VOID *) GetVariableNamePtr (Variable[Index]);\r
 \r
               ASSERT (NameSizeOfVariable (Variable[Index]) != 0);\r
-              if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable[Index]))) {\r
+              if (CompareMem (VariableName, Point, NameSizeOfVariable (Variable[Index])) == 0) {\r
                 if (Variable[Index]->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {\r
                   InDeletedVariable     = Variable[Index];\r
                   InDeletedStorageIndex = Index;\r
@@ -1128,7 +1137,7 @@ RuntimeServiceGetNextVariableName (
     // Variable is found\r
     //\r
     if (IsValidVariableHeader (Variable.CurrPtr) && Variable.CurrPtr->State == VAR_ADDED) {\r
-      if (!(EfiAtRuntime () && !(Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {\r
+      if ((EfiAtRuntime () && ((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) == 0) {\r
         VarNameSize = NameSizeOfVariable (Variable.CurrPtr);\r
         ASSERT (VarNameSize != 0);\r
 \r
@@ -1219,21 +1228,21 @@ RuntimeServiceSetVariable (
 \r
   //\r
   //  The size of the VariableName, including the Unicode Null in bytes plus\r
-  //  the DataSize is limited to maximum size of MAX_HARDWARE_ERROR_VARIABLE_SIZE (32K)\r
-  //  bytes for HwErrRec, and MAX_VARIABLE_SIZE (1024) bytes for the others.\r
+  //  the DataSize is limited to maximum size of FixedPcdGet32(PcdMaxHardwareErrorVariableSize)\r
+  //  bytes for HwErrRec, and FixedPcdGet32(PcdMaxVariableSize) bytes for the others.\r
   //\r
   if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
-    if ((DataSize > MAX_HARDWARE_ERROR_VARIABLE_SIZE) ||                                                       \r
-        (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > MAX_HARDWARE_ERROR_VARIABLE_SIZE)) {\r
+    if ((DataSize > FixedPcdGet32(PcdMaxHardwareErrorVariableSize)) ||                                                       \r
+        (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > FixedPcdGet32(PcdMaxHardwareErrorVariableSize))) {\r
       return EFI_INVALID_PARAMETER;\r
     }    \r
   } else {\r
   //\r
   //  The size of the VariableName, including the Unicode Null in bytes plus\r
-  //  the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes.\r
+  //  the DataSize is limited to maximum size of FixedPcdGet32(PcdMaxVariableSize) bytes.\r
   //\r
-    if ((DataSize > MAX_VARIABLE_SIZE) ||\r
-        (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > MAX_VARIABLE_SIZE)) {\r
+    if ((DataSize > FixedPcdGet32(PcdMaxVariableSize)) ||\r
+        (sizeof (VARIABLE_HEADER) + StrSize (VariableName) + DataSize > FixedPcdGet32(PcdMaxVariableSize))) {\r
       return EFI_INVALID_PARAMETER;\r
     }  \r
   }  \r
@@ -1286,7 +1295,7 @@ RuntimeServiceSetVariable (
       //\r
       // Only variable have NV attribute can be updated/deleted in Runtime\r
       //\r
-      if (!(Variable.CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE)) {\r
+      if ((Variable.CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) {\r
         Status = EFI_INVALID_PARAMETER;\r
         goto Done;      \r
       }\r
@@ -1364,7 +1373,7 @@ RuntimeServiceSetVariable (
     // Only variable have NV|RT attribute can be created in Runtime\r
     //\r
     if (EfiAtRuntime () &&\r
-        (!(Attributes & EFI_VARIABLE_RUNTIME_ACCESS) || !(Attributes & EFI_VARIABLE_NON_VOLATILE))) {\r
+        (((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0) || ((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0))) {\r
       Status = EFI_INVALID_PARAMETER;\r
       goto Done;\r
     }         \r
@@ -1385,7 +1394,7 @@ RuntimeServiceSetVariable (
   //\r
   NextVariable = GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase));\r
 \r
-  SetMem (NextVariable, SCRATCH_SIZE, 0xff);\r
+  SetMem (NextVariable, FixedPcdGet32(PcdMaxVariableSize), 0xff);\r
 \r
   NextVariable->StartId     = VARIABLE_DATA;\r
   NextVariable->Attributes  = Attributes;\r
@@ -1420,7 +1429,7 @@ RuntimeServiceSetVariable (
   // include pad size.\r
   //\r
   VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize);\r
-  if (Attributes & EFI_VARIABLE_NON_VOLATILE) {\r
+  if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) {\r
     //\r
     // Create a nonvolatile variable\r
     //\r
@@ -1655,7 +1664,7 @@ RuntimeServiceQueryVariableInfo (
     // Make sure if runtime bit is set, boot service bit is set also.\r
     //\r
     return EFI_INVALID_PARAMETER;\r
-  } else if (EfiAtRuntime () && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) {\r
+  } else if (EfiAtRuntime () && ((Attributes & EFI_VARIABLE_RUNTIME_ACCESS) == 0)) {\r
     //\r
     // Make sure RT Attribute is set if we are in Runtime phase.\r
     //\r
@@ -1684,15 +1693,15 @@ RuntimeServiceQueryVariableInfo (
   *RemainingVariableStorageSize = VariableStoreHeader->Size - sizeof (VARIABLE_STORE_HEADER);\r
 \r
   //\r
-  // Let *MaximumVariableSize be MAX_VARIABLE_SIZE with the exception of the variable header size.\r
+  // Let *MaximumVariableSize be FixedPcdGet32(PcdMaxVariableSize) with the exception of the variable header size.\r
   //\r
-  *MaximumVariableSize = MAX_VARIABLE_SIZE - sizeof (VARIABLE_HEADER);\r
+  *MaximumVariableSize = FixedPcdGet32(PcdMaxVariableSize) - sizeof (VARIABLE_HEADER);\r
 \r
   //\r
   // Harware error record variable needs larger size.\r
   //\r
   if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) == EFI_VARIABLE_HARDWARE_ERROR_RECORD) {\r
-    *MaximumVariableSize = MAX_HARDWARE_ERROR_VARIABLE_SIZE - sizeof (VARIABLE_HEADER);\r
+    *MaximumVariableSize = FixedPcdGet32(PcdMaxHardwareErrorVariableSize) - sizeof (VARIABLE_HEADER);\r
   }\r
 \r
   //\r
@@ -1829,13 +1838,13 @@ VariableCommonInitialize (
   //\r
   // Allocate memory for volatile variable store\r
   //\r
-  VolatileVariableStore = AllocateRuntimePool (VARIABLE_STORE_SIZE + SCRATCH_SIZE);\r
+  VolatileVariableStore = AllocateRuntimePool (FixedPcdGet32(PcdVariableStoreSize) + FixedPcdGet32(PcdMaxVariableSize));\r
   if (VolatileVariableStore == NULL) {\r
     FreePool (mVariableModuleGlobal);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  SetMem (VolatileVariableStore, VARIABLE_STORE_SIZE + SCRATCH_SIZE, 0xff);\r
+  SetMem (VolatileVariableStore, FixedPcdGet32(PcdVariableStoreSize) + FixedPcdGet32(PcdMaxVariableSize), 0xff);\r
 \r
   //\r
   //  Variable Specific Data\r
@@ -1843,8 +1852,8 @@ VariableCommonInitialize (
   mVariableModuleGlobal->VariableGlobal.VolatileVariableBase = (EFI_PHYSICAL_ADDRESS) (UINTN) VolatileVariableStore;\r
   mVariableModuleGlobal->VolatileLastVariableOffset = (UINTN) GetStartPointer (VolatileVariableStore) - (UINTN) VolatileVariableStore;\r
 \r
-  VolatileVariableStore->Signature                  = VARIABLE_STORE_SIGNATURE;\r
-  VolatileVariableStore->Size                       = VARIABLE_STORE_SIZE;\r
+  CopyGuid (&VolatileVariableStore->Signature, &gEfiVariableGuid);\r
+  VolatileVariableStore->Size                       = FixedPcdGet32(PcdVariableStoreSize);\r
   VolatileVariableStore->Format                     = VARIABLE_STORE_FORMATTED;\r
   VolatileVariableStore->State                      = VARIABLE_STORE_HEALTHY;\r
   VolatileVariableStore->Reserved                   = 0;\r
@@ -2055,11 +2064,12 @@ VariableServiceInitialize (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  Status = gBS->CreateEvent (\r
-                  EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\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