]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
Use SmmMemLib to check communication buffer.
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableDxe.c
index 3cb2c6bcf309dcc6d632017fbafc1ac9c838117c..c5cef3194492ed73298e96e89cd66e0973f4c5b9 100644 (file)
@@ -3,7 +3,8 @@
   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 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (C) 2013, Red Hat, Inc.\r
+Copyright (c) 2006 - 2015, 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
@@ -21,8 +22,15 @@ extern VARIABLE_INFO_ENTRY     *gVariableInfo;
 EFI_HANDLE                     mHandle                    = NULL;\r
 EFI_EVENT                      mVirtualAddressChangeEvent = NULL;\r
 EFI_EVENT                      mFtwRegistration           = NULL;\r
+extern LIST_ENTRY              mLockedVariableList;\r
+extern LIST_ENTRY              mVarCheckVariableList;\r
+extern UINT32                  mNumberOfHandler;\r
+extern VAR_CHECK_SET_VARIABLE_CHECK_HANDLER *mHandlerTable;\r
 extern BOOLEAN                 mEndOfDxe;\r
 EDKII_VARIABLE_LOCK_PROTOCOL   mVariableLock              = { VariableLockRequestToLock };\r
+EDKII_VAR_CHECK_PROTOCOL       mVarCheck                  = { VarCheckRegisterSetVariableCheckHandler,\r
+                                                              VarCheckVariablePropertySet,\r
+                                                              VarCheckVariablePropertyGet };\r
 \r
 /**\r
   Return TRUE if ExitBootServices () has been called.\r
@@ -220,6 +228,9 @@ VariableClassAddressChangeEvent (
   IN VOID                                 *Context\r
   )\r
 {\r
+  EFI_STATUS     Status;\r
+  UINTN          Index;\r
+\r
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetBlockSize);\r
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetPhysicalAddress);\r
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->FvbInstance->GetAttributes);\r
@@ -236,6 +247,16 @@ VariableClassAddressChangeEvent (
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableGlobal.HobVariableBase);\r
   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
   EfiConvertPointer (0x0, (VOID **) &mNvVariableCache);  \r
+  EfiConvertPointer (0x0, (VOID **) &mHandlerTable);\r
+  for (Index = 0; Index < mNumberOfHandler; Index++) {\r
+    EfiConvertPointer (0x0, (VOID **) &mHandlerTable[Index]);\r
+  }\r
+\r
+  Status = EfiConvertList (0x0, &mLockedVariableList);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = EfiConvertList (0x0, &mVarCheckVariableList);\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 \r
@@ -261,6 +282,10 @@ OnReadyToBoot (
   // Set the End Of DXE bit in case the EFI_END_OF_DXE_EVENT_GROUP_GUID event is not signaled.\r
   //\r
   mEndOfDxe = TRUE;\r
+  //\r
+  // The initialization for variable quota.\r
+  //\r
+  InitializeVariableQuota ();\r
   ReclaimForOS ();\r
   if (FeaturePcdGet (PcdVariableCollectStatistics)) {\r
     gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
@@ -284,6 +309,13 @@ OnEndOfDxe (
   )\r
 {\r
   mEndOfDxe = TRUE;\r
+  //\r
+  // The initialization for variable quota.\r
+  //\r
+  InitializeVariableQuota ();\r
+  if (PcdGetBool (PcdReclaimVariableSpaceAtEndOfDxe)) {\r
+    ReclaimForOS ();\r
+  }\r
 }\r
 \r
 /**\r
@@ -312,6 +344,7 @@ FtwNotificationEvent (
   UINT64                                  Length;\r
   EFI_PHYSICAL_ADDRESS                    VariableStoreBase;\r
   UINT64                                  VariableStoreLength;\r
+  UINTN                                   FtwMaxBlockSize;\r
 \r
   //\r
   // Ensure FTW protocol is installed.\r
@@ -320,7 +353,12 @@ FtwNotificationEvent (
   if (EFI_ERROR (Status)) {\r
     return ;\r
   }\r
-  \r
+\r
+  Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
+  if (!EFI_ERROR (Status)) {\r
+    ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
+  }\r
+\r
   //\r
   // Find the proper FVB protocol for variable.\r
   //\r
@@ -337,7 +375,7 @@ FtwNotificationEvent (
   //\r
   // Mark the variable storage region of the FLASH as RUNTIME.\r
   //\r
-  VariableStoreBase   = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase;\r
+  VariableStoreBase   = NvStorageVariableBase + (((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(NvStorageVariableBase))->HeaderLength);\r
   VariableStoreLength = ((VARIABLE_STORE_HEADER *)(UINTN)VariableStoreBase)->Size;\r
   BaseAddress = VariableStoreBase & (~EFI_PAGE_MASK);\r
   Length      = VariableStoreLength + (VariableStoreBase - BaseAddress);\r
@@ -345,7 +383,7 @@ FtwNotificationEvent (
 \r
   Status      = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdDescriptor);\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((DEBUG_WARN, "Variable driver failed to add EFI_MEMORY_RUNTIME attribute to Flash.\n"));\r
+    DEBUG ((DEBUG_WARN, "Variable driver failed to get flash memory attribute.\n"));\r
   } else {\r
     Status = gDS->SetMemorySpaceAttributes (\r
                     BaseAddress,\r
@@ -413,6 +451,14 @@ VariableServiceInitialize (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mHandle,\r
+                  &gEdkiiVarCheckProtocolGuid,\r
+                  &mVarCheck,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   SystemTable->RuntimeServices->GetVariable         = VariableServiceGetVariable;\r
   SystemTable->RuntimeServices->GetNextVariableName = VariableServiceGetNextVariableName;\r
   SystemTable->RuntimeServices->SetVariable         = VariableServiceSetVariable;\r