]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add the TPL raise/restore code for VariableSmmRuntimeDxe to avoid variable services...
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 Jan 2013 02:07:14 +0000 (02:07 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 Jan 2013 02:07:14 +0000 (02:07 +0000)
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14038 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
SecurityPkg/VariableAuthenticated/RuntimeDxe/VariableSmmRuntimeDxe.c

index 442fe1dad77022731c1671e9c3f643d7fe5b2beb..e4d3aca1938de0a8b4fffe588a865626c77427c3 100644 (file)
@@ -4,7 +4,7 @@
   and volatile storage space and install variable architecture protocol\r
   based on SMM variable module.\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2012, 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
@@ -42,7 +42,51 @@ EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication          = NULL;
 UINT8                           *mVariableBuffer            = NULL;\r
 UINT8                           *mVariableBufferPhysical    = NULL;\r
 UINTN                            mVariableBufferSize;\r
+EFI_LOCK                         mVariableServicesLock;\r
 \r
+/**\r
+  Acquires lock only at boot time. Simply returns at runtime.\r
+\r
+  This is a temperary function that will be removed when\r
+  EfiAcquireLock() in UefiLib can handle the call in UEFI\r
+  Runtimer driver in RT phase.\r
+  It calls EfiAcquireLock() at boot time, and simply returns\r
+  at runtime.\r
+\r
+  @param  Lock         A pointer to the lock to acquire.\r
+\r
+**/\r
+VOID\r
+AcquireLockOnlyAtBootTime (\r
+  IN EFI_LOCK                             *Lock\r
+  )\r
+{\r
+  if (!EfiAtRuntime ()) {\r
+    EfiAcquireLock (Lock);\r
+  }\r
+}\r
+\r
+/**\r
+  Releases lock only at boot time. Simply returns at runtime.\r
+\r
+  This is a temperary function which will be removed when\r
+  EfiReleaseLock() in UefiLib can handle the call in UEFI\r
+  Runtimer driver in RT phase.\r
+  It calls EfiReleaseLock() at boot time and simply returns\r
+  at runtime.\r
+\r
+  @param  Lock         A pointer to the lock to release.\r
+\r
+**/\r
+VOID\r
+ReleaseLockOnlyAtBootTime (\r
+  IN EFI_LOCK                             *Lock\r
+  )\r
+{\r
+  if (!EfiAtRuntime ()) {\r
+    EfiReleaseLock (Lock);\r
+  }\r
+}\r
 \r
 /**\r
   Initialize the communicate buffer using DataSize and Function.\r
@@ -153,15 +197,17 @@ RuntimeServiceGetVariable (
   if ((*DataSize != 0) && (Data == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
+\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
-  // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize + DataSize.\r
+  // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
   //\r
   PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + StrSize (VariableName) + *DataSize;\r
   Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmVariableHeader != NULL);\r
 \r
@@ -189,11 +235,13 @@ RuntimeServiceGetVariable (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   CopyMem (Data, (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize, SmmVariableHeader->DataSize);\r
 \r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return Status;\r
 }\r
 \r
@@ -226,7 +274,9 @@ RuntimeServiceGetNextVariableName (
   if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
+\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
   // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
@@ -234,7 +284,7 @@ RuntimeServiceGetNextVariableName (
   PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + *VariableNameSize; \r
   Status = InitCommunicateBuffer ((VOID **)&SmmGetNextVariableName, PayloadSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmGetNextVariableName != NULL);\r
 \r
@@ -252,12 +302,14 @@ RuntimeServiceGetNextVariableName (
   //\r
   *VariableNameSize = SmmGetNextVariableName->NameSize;    \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   \r
   CopyGuid (VendorGuid, &SmmGetNextVariableName->Guid);\r
   CopyMem (VariableName, SmmGetNextVariableName->Name, SmmGetNextVariableName->NameSize);  \r
 \r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return Status;\r
 }\r
 \r
@@ -302,7 +354,9 @@ RuntimeServiceSetVariable (
   if (DataSize != 0 && Data == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
   // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
@@ -310,7 +364,7 @@ RuntimeServiceSetVariable (
   PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + StrSize (VariableName) + DataSize;\r
   Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_SET_VARIABLE);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmVariableHeader != NULL);\r
 \r
@@ -325,7 +379,9 @@ RuntimeServiceSetVariable (
   // Send data to SMM.\r
   //\r
   Status = SendCommunicateBuffer (PayloadSize);\r
\r
+\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return Status;\r
 }\r
 \r
@@ -363,7 +419,9 @@ RuntimeServiceQueryVariableInfo (
   if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
+\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
   // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize;\r
@@ -371,7 +429,7 @@ RuntimeServiceQueryVariableInfo (
   PayloadSize = sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO);\r
   Status = InitCommunicateBuffer ((VOID **)&SmmQueryVariableInfo, PayloadSize, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmQueryVariableInfo != NULL);\r
 \r
@@ -382,7 +440,7 @@ RuntimeServiceQueryVariableInfo (
   //\r
   Status = SendCommunicateBuffer (PayloadSize);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -391,7 +449,9 @@ RuntimeServiceQueryVariableInfo (
   *MaximumVariableSize          = SmmQueryVariableInfo->MaximumVariableSize;\r
   *MaximumVariableStorageSize   = SmmQueryVariableInfo->MaximumVariableStorageSize;\r
   *RemainingVariableStorageSize = SmmQueryVariableInfo->RemainingVariableStorageSize; \r
\r
+\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -589,7 +649,9 @@ VariableSmmRuntimeInitialize (
   VOID                                      *SmmVariableWriteRegistration;\r
   EFI_EVENT                                 OnReadyToBootEvent;\r
   EFI_EVENT                                 ExitBootServiceEvent;\r
-  \r
+\r
+  EfiInitializeLock (&mVariableServicesLock, TPL_NOTIFY);\r
+\r
   //\r
   // Smm variable service is ready\r
   //\r
index 2ef44e3a11295b1ac7c629128bd476a83c9f7f77..1c06edd8cfe4f659230ba37d4c4215d51f774df0 100644 (file)
@@ -52,7 +52,51 @@ EFI_SMM_COMMUNICATION_PROTOCOL  *mSmmCommunication          = NULL;
 UINT8                           *mVariableBuffer            = NULL;\r
 UINT8                           *mVariableBufferPhysical    = NULL;\r
 UINTN                            mVariableBufferSize;\r
+EFI_LOCK                         mVariableServicesLock;\r
 \r
+/**\r
+  Acquires lock only at boot time. Simply returns at runtime.\r
+\r
+  This is a temperary function that will be removed when\r
+  EfiAcquireLock() in UefiLib can handle the call in UEFI\r
+  Runtimer driver in RT phase.\r
+  It calls EfiAcquireLock() at boot time, and simply returns\r
+  at runtime.\r
+\r
+  @param  Lock         A pointer to the lock to acquire.\r
+\r
+**/\r
+VOID\r
+AcquireLockOnlyAtBootTime (\r
+  IN EFI_LOCK                             *Lock\r
+  )\r
+{\r
+  if (!EfiAtRuntime ()) {\r
+    EfiAcquireLock (Lock);\r
+  }\r
+}\r
+\r
+/**\r
+  Releases lock only at boot time. Simply returns at runtime.\r
+\r
+  This is a temperary function which will be removed when\r
+  EfiReleaseLock() in UefiLib can handle the call in UEFI\r
+  Runtimer driver in RT phase.\r
+  It calls EfiReleaseLock() at boot time and simply returns\r
+  at runtime.\r
+\r
+  @param  Lock         A pointer to the lock to release.\r
+\r
+**/\r
+VOID\r
+ReleaseLockOnlyAtBootTime (\r
+  IN EFI_LOCK                             *Lock\r
+  )\r
+{\r
+  if (!EfiAtRuntime ()) {\r
+    EfiReleaseLock (Lock);\r
+  }\r
+}\r
 \r
 /**\r
   Initialize the communicate buffer using DataSize and Function.\r
@@ -169,15 +213,17 @@ RuntimeServiceGetVariable (
   if ((*DataSize != 0) && (Data == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
+\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
-  // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize + DataSize.\r
+  // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
   //\r
   PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + StrSize (VariableName) + *DataSize;\r
   Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmVariableHeader != NULL);\r
 \r
@@ -205,11 +251,13 @@ RuntimeServiceGetVariable (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   CopyMem (Data, (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize, SmmVariableHeader->DataSize);\r
 \r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return Status;\r
 }\r
 \r
@@ -242,7 +290,9 @@ RuntimeServiceGetNextVariableName (
   if (VariableNameSize == NULL || VariableName == NULL || VendorGuid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
+\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
   // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
@@ -250,7 +300,7 @@ RuntimeServiceGetNextVariableName (
   PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + *VariableNameSize; \r
   Status = InitCommunicateBuffer ((VOID **)&SmmGetNextVariableName, PayloadSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmGetNextVariableName != NULL);\r
 \r
@@ -268,12 +318,14 @@ RuntimeServiceGetNextVariableName (
   //\r
   *VariableNameSize = SmmGetNextVariableName->NameSize;    \r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   \r
   CopyGuid (VendorGuid, &SmmGetNextVariableName->Guid);\r
   CopyMem (VariableName, SmmGetNextVariableName->Name, SmmGetNextVariableName->NameSize);  \r
 \r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return Status;\r
 }\r
 \r
@@ -321,7 +373,9 @@ RuntimeServiceSetVariable (
   if (DataSize != 0 && Data == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
   // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.\r
@@ -329,7 +383,7 @@ RuntimeServiceSetVariable (
   PayloadSize = OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + StrSize (VariableName) + DataSize;\r
   Status = InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSize, SMM_VARIABLE_FUNCTION_SET_VARIABLE);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmVariableHeader != NULL);\r
 \r
@@ -344,7 +398,9 @@ RuntimeServiceSetVariable (
   // Send data to SMM.\r
   //\r
   Status = SendCommunicateBuffer (PayloadSize);\r
\r
+\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return Status;\r
 }\r
 \r
@@ -382,7 +438,9 @@ RuntimeServiceQueryVariableInfo (
   if(MaximumVariableStorageSize == NULL || RemainingVariableStorageSize == NULL || MaximumVariableSize == NULL || Attributes == 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
+  AcquireLockOnlyAtBootTime(&mVariableServicesLock);\r
+\r
   //\r
   // Init the communicate buffer. The buffer data size is:\r
   // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + PayloadSize;\r
@@ -390,7 +448,7 @@ RuntimeServiceQueryVariableInfo (
   PayloadSize = sizeof (SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO);\r
   Status = InitCommunicateBuffer ((VOID **)&SmmQueryVariableInfo, PayloadSize, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
   ASSERT (SmmQueryVariableInfo != NULL);\r
 \r
@@ -401,7 +459,7 @@ RuntimeServiceQueryVariableInfo (
   //\r
   Status = SendCommunicateBuffer (PayloadSize);\r
   if (EFI_ERROR (Status)) {\r
-    return Status;\r
+    goto Done;\r
   }\r
 \r
   //\r
@@ -410,7 +468,9 @@ RuntimeServiceQueryVariableInfo (
   *MaximumVariableSize          = SmmQueryVariableInfo->MaximumVariableSize;\r
   *MaximumVariableStorageSize   = SmmQueryVariableInfo->MaximumVariableStorageSize;\r
   *RemainingVariableStorageSize = SmmQueryVariableInfo->RemainingVariableStorageSize; \r
\r
+\r
+Done:\r
+  ReleaseLockOnlyAtBootTime (&mVariableServicesLock);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -608,7 +668,9 @@ VariableSmmRuntimeInitialize (
   VOID                                      *SmmVariableWriteRegistration;\r
   EFI_EVENT                                 OnReadyToBootEvent;\r
   EFI_EVENT                                 ExitBootServiceEvent;\r
-  \r
+\r
+  EfiInitializeLock (&mVariableServicesLock, TPL_NOTIFY);\r
+\r
   //\r
   // Smm variable service is ready\r
   //\r