SecurityPkg-Opal(1): Use fixed SMM communication buffer in OPAL password lib.
authorEric Dong <eric.dong@intel.com>
Fri, 22 Apr 2016 07:36:36 +0000 (15:36 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Fri, 29 Apr 2016 04:49:23 +0000 (12:49 +0800)
This patch enhance OPAL password lib SMM communication by using fixed
SMM communication buffer.

Update OPAL password lib to consume EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
as fixed communication buffer for SMM communication.

This is designed to meet Microsoft WSMT table definition on FIXED_COMM_BUFFERS
requirement.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
SecurityPkg/Library/OpalPasswordSupportLib/OpalPasswordSupportLib.c
SecurityPkg/Library/OpalPasswordSupportLib/OpalPasswordSupportLib.inf
SecurityPkg/Library/OpalPasswordSupportLib/OpalPasswordSupportNotify.h

index eead27fbe022831f2e72bb68ed9cf2ea12cb8ced..837582359e4f7b8ad228f63e0e71524eb72f6921 100644 (file)
@@ -401,8 +401,36 @@ OpalInitCommunicateBuffer (
   EFI_SMM_COMMUNICATE_HEADER                *SmmCommunicateHeader;\r
   OPAL_SMM_COMMUNICATE_HEADER               *SmmFunctionHeader;\r
   VOID                                      *Buffer;\r
+  EDKII_PI_SMM_COMMUNICATION_REGION_TABLE   *SmmCommRegionTable;\r
+  EFI_MEMORY_DESCRIPTOR                     *SmmCommMemRegion;\r
+  UINTN                                     Index;\r
+  UINTN                                     Size;\r
+  EFI_STATUS                                Status;\r
+\r
+  Buffer = NULL;\r
+  Status = EfiGetSystemConfigurationTable (\r
+             &gEdkiiPiSmmCommunicationRegionTableGuid,\r
+             (VOID **) &SmmCommRegionTable\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
 \r
-  Buffer = AllocateZeroPool (DataSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + OFFSET_OF (OPAL_SMM_COMMUNICATE_HEADER, Data));\r
+  ASSERT (SmmCommRegionTable != NULL);\r
+  SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) (SmmCommRegionTable + 1);\r
+  Size = 0;\r
+  for (Index = 0; Index < SmmCommRegionTable->NumberOfEntries; Index++) {\r
+    if (SmmCommMemRegion->Type == EfiConventionalMemory) {\r
+      Size = EFI_PAGES_TO_SIZE ((UINTN) SmmCommMemRegion->NumberOfPages);\r
+      if (Size >= (DataSize + OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + OFFSET_OF (OPAL_SMM_COMMUNICATE_HEADER, Data))) {\r
+        break;\r
+      }\r
+    }\r
+    SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);\r
+  }\r
+  ASSERT (Index < SmmCommRegionTable->NumberOfEntries);\r
+\r
+  Buffer = (VOID*)(UINTN)SmmCommMemRegion->PhysicalStart;\r
   ASSERT (Buffer != NULL);\r
 \r
   SmmCommunicateHeader = (EFI_SMM_COMMUNICATE_HEADER *) Buffer;\r
@@ -513,8 +541,6 @@ OpalSupportSendPasword(
 \r
 EXIT:\r
   ZeroMem(Parameter, Length);\r
-  FreePool(Buffer);\r
-\r
   return Status;\r
 }\r
 \r
index 274366bcf91dd5b9872e056c9933fe1cc4f2c1eb..b7831356e5dd9f79b2f1ee6b3fe1070c97aebb83 100644 (file)
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
   SecurityPkg/SecurityPkg.dec\r
 \r
 [Protocols]\r
   gEfiStorageSecurityCommandProtocolGuid                         ## CONSUMES\r
   gEfiSmmCommunicationProtocolGuid                               ## CONSUMES\r
   gEfiSmmBase2ProtocolGuid                                       ## CONSUMES # only for SMM version\r
+\r
+[Guids]\r
+  gEdkiiPiSmmCommunicationRegionTableGuid       ## CONSUMES ## SystemTable\r
index 59c1214d8c5f773c3f1b2c5f025d3e9035697d63..f0ad3a1136123f43b79696afb1a4969ea173dca6 100644 (file)
@@ -19,7 +19,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <PiSmm.h>\r
 \r
 #include <Uefi/UefiAcpiDataTable.h>\r
-\r
+#include <Guid/PiSmmCommunicationRegionTable.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r