]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/TcgDxe/TcgDxe.c
SecurityPkg: Clean up source files
[mirror_edk2.git] / SecurityPkg / Tcg / TcgDxe / TcgDxe.c
index db7951cd9ad0f66ed26f207d31c2e41d2adef837..21837fe3d3506d66a5b0a8b8785fd3047b9088f9 100644 (file)
@@ -1,6 +1,6 @@
-/** @file  \r
+/** @file\r
   This module implements TCG EFI Protocol.\r
\r
+\r
 Caution: This module requires additional review when modified.\r
 This driver will have external input - TcgDxePassThroughToTpm\r
 This external input must be validated carefully to avoid security issue like\r
@@ -8,13 +8,14 @@ buffer overflow, integer overflow.
 \r
 TcgDxePassThroughToTpm() will receive untrusted input and do basic validation.\r
 \r
-Copyright (c) 2005 - 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
+Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<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
 \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+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
 **/\r
@@ -23,11 +24,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <IndustryStandard/Tpm12.h>\r
 #include <IndustryStandard/Acpi.h>\r
 #include <IndustryStandard/PeImage.h>\r
-#include <IndustryStandard/SmBios.h>\r
 #include <IndustryStandard/TcpaAcpi.h>\r
 \r
 #include <Guid/GlobalVariable.h>\r
-#include <Guid/SmBios.h>\r
 #include <Guid/HobList.h>\r
 #include <Guid/TcgEventHob.h>\r
 #include <Guid/EventGroup.h>\r
@@ -48,14 +47,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PrintLib.h>\r
-#include <Library/TpmCommLib.h>\r
+#include <Library/Tpm12DeviceLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/ReportStatusCodeLib.h>\r
-\r
-#include "TpmComm.h"\r
-\r
-#define  EFI_TCG_LOG_AREA_SIZE        0x10000\r
+#include <Library/Tpm12CommandLib.h>\r
+#include <Library/BaseCryptLib.h>\r
 \r
 #define TCG_DXE_DATA_FROM_THIS(this)  \\r
   BASE_CR (this, TCG_DXE_DATA, TcgProtocol)\r
@@ -67,7 +64,6 @@ typedef struct _TCG_DXE_DATA {
   EFI_TCG_SERVER_ACPI_TABLE         *TcgServerAcpiTable;\r
   UINTN                             EventLogSize;\r
   UINT8                             *LastEvent;\r
-  TIS_TPM_HANDLE                    TpmHandle;\r
 } TCG_DXE_DATA;\r
 \r
 \r
@@ -90,8 +86,8 @@ EFI_TCG_CLIENT_ACPI_TABLE           mTcgClientAcpiTemplate = {
 //\r
 // The following EFI_TCG_SERVER_ACPI_TABLE default setting is just one example,\r
 // the TPM device connectes to LPC, and also defined the ACPI _UID as 0xFF,\r
-// this _UID can be changed and should match with the _UID setting of the TPM \r
-// ACPI device object  \r
+// this _UID can be changed and should match with the _UID setting of the TPM\r
+// ACPI device object\r
 //\r
 EFI_TCG_SERVER_ACPI_TABLE           mTcgServerAcpiTemplate = {\r
   {\r
@@ -107,8 +103,8 @@ EFI_TCG_SERVER_ACPI_TABLE           mTcgServerAcpiTemplate = {
   0,                          // Reserved\r
   0,                          // Log Area Max Length\r
   (EFI_PHYSICAL_ADDRESS) (SIZE_4GB - 1), // Log Area Start Address\r
-  0x0100,                     // TCG Specification revision 1.0\r
-  2,                          // Device Flags\r
+  0x0120,                     // TCG Specification revision 1.2\r
+  0,                          // Device Flags\r
   0,                          // Interrupt Flags\r
   0,                          // GPE\r
   {0},                        // Reserved 3 bytes\r
@@ -118,7 +114,7 @@ EFI_TCG_SERVER_ACPI_TABLE           mTcgServerAcpiTemplate = {
     0,\r
     0,\r
     EFI_ACPI_3_0_BYTE,\r
-    TPM_BASE_ADDRESS          // Base Address\r
+    0                         // Base Address\r
   },\r
   0,                          // Reserved\r
   {0},                        // Configuration Address\r
@@ -213,26 +209,26 @@ GetProcessorsCpuLocation (
 }\r
 \r
 /**\r
-  This service provides EFI protocol capability information, state information \r
+  This service provides EFI protocol capability information, state information\r
   about the TPM, and Event Log state information.\r
 \r
   @param[in]  This               Indicates the calling context\r
-  @param[out] ProtocolCapability The callee allocates memory for a TCG_BOOT_SERVICE_CAPABILITY \r
-                                 structure and fills in the fields with the EFI protocol \r
+  @param[out] ProtocolCapability The callee allocates memory for a TCG_BOOT_SERVICE_CAPABILITY\r
+                                 structure and fills in the fields with the EFI protocol\r
                                  capability information and the current TPM state information.\r
-  @param[out] TCGFeatureFlags    This is a pointer to the feature flags. No feature \r
-                                 flags are currently defined so this parameter \r
-                                 MUST be set to 0. However, in the future, \r
-                                 feature flags may be defined that, for example, \r
+  @param[out] TCGFeatureFlags    This is a pointer to the feature flags. No feature\r
+                                 flags are currently defined so this parameter\r
+                                 MUST be set to 0. However, in the future,\r
+                                 feature flags may be defined that, for example,\r
                                  enable hash algorithm agility.\r
   @param[out] EventLogLocation   This is a pointer to the address of the event log in memory.\r
-  @param[out] EventLogLastEntry  If the Event Log contains more than one entry, \r
-                                 this is a pointer to the address of the start of \r
-                                 the last entry in the event log in memory. \r
+  @param[out] EventLogLastEntry  If the Event Log contains more than one entry,\r
+                                 this is a pointer to the address of the start of\r
+                                 the last entry in the event log in memory.\r
 \r
   @retval EFI_SUCCESS            Operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER  ProtocolCapability does not match TCG capability.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -275,23 +271,57 @@ TcgDxeStatusCheck (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+Single function calculates SHA1 digest value for all raw data. It\r
+combines Sha1Init(), Sha1Update() and Sha1Final().\r
+\r
+@param[in]  Data          Raw data to be digested.\r
+@param[in]  DataLen       Size of the raw data.\r
+@param[out] Digest        Pointer to a buffer that stores the final digest.\r
+\r
+@retval     EFI_SUCCESS   Always successfully calculate the final digest.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TpmCommHashAll (\r
+  IN  CONST UINT8       *Data,\r
+  IN        UINTN       DataLen,\r
+  OUT       TPM_DIGEST  *Digest\r
+  )\r
+{\r
+  VOID   *Sha1Ctx;\r
+  UINTN  CtxSize;\r
+\r
+  CtxSize = Sha1GetContextSize ();\r
+  Sha1Ctx = AllocatePool (CtxSize);\r
+  ASSERT (Sha1Ctx != NULL);\r
+\r
+  Sha1Init (Sha1Ctx);\r
+  Sha1Update (Sha1Ctx, Data, DataLen);\r
+  Sha1Final (Sha1Ctx, (UINT8 *)Digest);\r
+\r
+  FreePool (Sha1Ctx);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   This service abstracts the capability to do a hash operation on a data buffer.\r
-  \r
+\r
   @param[in]      This             Indicates the calling context\r
   @param[in]      HashData         Pointer to the data buffer to be hashed\r
   @param[in]      HashDataLen      Length of the data buffer to be hashed\r
   @param[in]      AlgorithmId      Identification of the Algorithm to use for the hashing operation\r
   @param[in, out] HashedDataLen    Resultant length of the hashed data\r
-  @param[in, out] HashedDataResult Resultant buffer of the hashed data  \r
-  \r
+  @param[in, out] HashedDataResult Resultant buffer of the hashed data\r
+\r
   @retval EFI_SUCCESS              Operation completed successfully.\r
   @retval EFI_INVALID_PARAMETER    HashDataLen is NULL.\r
   @retval EFI_INVALID_PARAMETER    HashDataLenResult is NULL.\r
   @retval EFI_OUT_OF_RESOURCES     Cannot allocate buffer of size *HashedDataLen.\r
   @retval EFI_UNSUPPORTED          AlgorithmId not supported.\r
   @retval EFI_BUFFER_TOO_SMALL     *HashedDataLen < sizeof (TCG_DIGEST).\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -324,9 +354,9 @@ TcgDxeHashAll (
       }\r
       *HashedDataLen = sizeof (TPM_DIGEST);\r
 \r
-         if (*HashedDataResult == NULL) {\r
-               *HashedDataResult = AllocatePool ((UINTN) *HashedDataLen);\r
-         } \r
+      if (*HashedDataResult == NULL) {\r
+        *HashedDataResult = AllocatePool ((UINTN) *HashedDataLen);\r
+      }\r
 \r
       return TpmCommHashAll (\r
                HashData,\r
@@ -338,13 +368,60 @@ TcgDxeHashAll (
   }\r
 }\r
 \r
+/**\r
+Add a new entry to the Event Log.\r
+\r
+@param[in, out] EventLogPtr   Pointer to the Event Log data.\r
+@param[in, out] LogSize       Size of the Event Log.\r
+@param[in]      MaxSize       Maximum size of the Event Log.\r
+@param[in]      NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.\r
+@param[in]      NewEventData  Pointer to the new event data.\r
+\r
+@retval EFI_SUCCESS           The new event log entry was added.\r
+@retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
+\r
+**/\r
+EFI_STATUS\r
+TpmCommLogEvent (\r
+  IN OUT  UINT8                     **EventLogPtr,\r
+  IN OUT  UINTN                     *LogSize,\r
+  IN      UINTN                     MaxSize,\r
+  IN      TCG_PCR_EVENT_HDR         *NewEventHdr,\r
+  IN      UINT8                     *NewEventData\r
+  )\r
+{\r
+  UINTN                            NewLogSize;\r
+\r
+  //\r
+  // Prevent Event Overflow\r
+  //\r
+  if ((UINTN) NewEventHdr->EventSize > MAX_UINTN - sizeof (*NewEventHdr)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  NewLogSize = sizeof (*NewEventHdr) + NewEventHdr->EventSize;\r
+  if (NewLogSize > MaxSize - *LogSize) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  *EventLogPtr += *LogSize;\r
+  *LogSize += NewLogSize;\r
+  CopyMem (*EventLogPtr, NewEventHdr, sizeof (*NewEventHdr));\r
+  CopyMem (\r
+    *EventLogPtr + sizeof (*NewEventHdr),\r
+    NewEventData,\r
+    NewEventHdr->EventSize\r
+    );\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Add a new entry to the Event Log.\r
 \r
   @param[in] TcgData       TCG_DXE_DATA structure.\r
-  @param[in] NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.  \r
-  @param[in] NewEventData  Pointer to the new event data.  \r
-  \r
+  @param[in] NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.\r
+  @param[in] NewEventData  Pointer to the new event data.\r
+\r
   @retval EFI_SUCCESS           The new event log entry was added.\r
   @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
 \r
@@ -382,18 +459,18 @@ TcgDxeLogEventI (
   This service abstracts the capability to add an entry to the Event Log.\r
 \r
   @param[in]      This           Indicates the calling context\r
-  @param[in]      TCGLogData     Pointer to the start of the data buffer containing \r
-                                 the TCG_PCR_EVENT data structure. All fields in \r
+  @param[in]      TCGLogData     Pointer to the start of the data buffer containing\r
+                                 the TCG_PCR_EVENT data structure. All fields in\r
                                  this structure are properly filled by the caller.\r
   @param[in, out] EventNumber    The event number of the event just logged\r
-  @param[in]      Flags          Indicate additional flags. Only one flag has been \r
-                                 defined at this time, which is 0x01 and means the \r
-                                 extend operation should not be performed. All \r
-                                 other bits are reserved. \r
\r
+  @param[in]      Flags          Indicate additional flags. Only one flag has been\r
+                                 defined at this time, which is 0x01 and means the\r
+                                 extend operation should not be performed. All\r
+                                 other bits are reserved.\r
+\r
   @retval EFI_SUCCESS            Operation completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES   Insufficient memory in the event log to complete this action.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -411,7 +488,7 @@ TcgDxeLogEvent (
   }\r
 \r
   TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
-  \r
+\r
   if (TcgData->BsCap.TPMDeactivatedFlag || (!TcgData->BsCap.TPMPresentFlag)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
@@ -435,7 +512,7 @@ TcgDxeLogEvent (
   @retval     EFI_INVALID_PARAMETER       Invalid ordinal.\r
   @retval     EFI_UNSUPPORTED             Current Task Priority Level  >= EFI_TPL_CALLBACK.\r
   @retval     EFI_TIMEOUT                 The TIS timed-out.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -447,24 +524,18 @@ TcgDxePassThroughToTpm (
   IN      UINT8                     *TpmOutputParameterBlock\r
   )\r
 {\r
-  TCG_DXE_DATA                      *TcgData;\r
-\r
-  if (TpmInputParameterBlock == NULL || \r
-      TpmOutputParameterBlock == NULL || \r
+  if (TpmInputParameterBlock == NULL ||\r
+      TpmOutputParameterBlock == NULL ||\r
       TpmInputParameterBlockSize == 0 ||\r
       TpmOutputParameterBlockSize == 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
-\r
-  return TisPcExecute (\r
-           TcgData->TpmHandle,\r
-           "%r%/%r",\r
+  return Tpm12SubmitCommand (\r
+           TpmInputParameterBlockSize,\r
            TpmInputParameterBlock,\r
-           (UINTN) TpmInputParameterBlockSize,\r
-           TpmOutputParameterBlock,\r
-           (UINTN) TpmOutputParameterBlockSize\r
+           &TpmOutputParameterBlockSize,\r
+           TpmOutputParameterBlock\r
            );\r
 }\r
 \r
@@ -473,11 +544,11 @@ TcgDxePassThroughToTpm (
   and add an entry to the Event Log.\r
 \r
   @param[in]      TcgData       TCG_DXE_DATA structure.\r
-  @param[in]      HashData      Physical address of the start of the data buffer \r
+  @param[in]      HashData      Physical address of the start of the data buffer\r
                                 to be hashed, extended, and logged.\r
   @param[in]      HashDataLen   The length, in bytes, of the buffer referenced by HashData\r
-  @param[in, out] NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.  \r
-  @param[in]      NewEventData  Pointer to the new event data.  \r
+  @param[in, out] NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data structure.\r
+  @param[in]      NewEventData  Pointer to the new event data.\r
 \r
   @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES  No enough memory to log the new event.\r
@@ -512,8 +583,7 @@ TcgDxeHashLogExtendEventI (
     }\r
   }\r
 \r
-  Status = TpmCommExtend (\r
-             TcgData->TpmHandle,\r
+  Status = Tpm12Extend (\r
              &NewEventHdr->Digest,\r
              NewEventHdr->PCRIndex,\r
              NULL\r
@@ -541,24 +611,24 @@ Done:
   extend a specific TPM PCR with the hash result, and add an entry to the Event Log\r
 \r
   @param[in]      This               Indicates the calling context\r
-  @param[in]      HashData           Physical address of the start of the data buffer \r
+  @param[in]      HashData           Physical address of the start of the data buffer\r
                                      to be hashed, extended, and logged.\r
   @param[in]      HashDataLen        The length, in bytes, of the buffer referenced by HashData\r
   @param[in]      AlgorithmId        Identification of the Algorithm to use for the hashing operation\r
-  @param[in, out] TCGLogData         The physical address of the start of the data \r
+  @param[in, out] TCGLogData         The physical address of the start of the data\r
                                      buffer containing the TCG_PCR_EVENT data structure.\r
   @param[in, out] EventNumber        The event number of the event just logged.\r
-  @param[out]     EventLogLastEntry  Physical address of the first byte of the entry \r
-                                     just placed in the Event Log. If the Event Log was \r
-                                     empty when this function was called then this physical \r
-                                     address will be the same as the physical address of \r
+  @param[out]     EventLogLastEntry  Physical address of the first byte of the entry\r
+                                     just placed in the Event Log. If the Event Log was\r
+                                     empty when this function was called then this physical\r
+                                     address will be the same as the physical address of\r
                                      the start of the Event Log.\r
 \r
   @retval EFI_SUCCESS                Operation completed successfully.\r
   @retval EFI_UNSUPPORTED            AlgorithmId != TPM_ALG_SHA.\r
   @retval EFI_UNSUPPORTED            Current TPL >= EFI_TPL_CALLBACK.\r
   @retval EFI_DEVICE_ERROR           The command was unsuccessful.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -580,15 +650,15 @@ TcgDxeHashLogExtendEvent (
   }\r
 \r
   TcgData = TCG_DXE_DATA_FROM_THIS (This);\r
-  \r
+\r
   if (TcgData->BsCap.TPMDeactivatedFlag || (!TcgData->BsCap.TPMPresentFlag)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
-    \r
+\r
   if (AlgorithmId != TPM_ALG_SHA) {\r
     return EFI_UNSUPPORTED;\r
   }\r
-  \r
+\r
   if (HashData == 0 && HashDataLen > 0) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -627,7 +697,6 @@ TCG_DXE_DATA                 mTcgDxeData = {
   &mTcgClientAcpiTemplate,\r
   &mTcgServerAcpiTemplate,\r
   0,\r
-  NULL,\r
   NULL\r
 };\r
 \r
@@ -648,14 +717,14 @@ SetupEventLog (
   TCG_PCR_EVENT         *TcgEvent;\r
   EFI_PEI_HOB_POINTERS  GuidHob;\r
   EFI_PHYSICAL_ADDRESS  Lasa;\r
-  \r
+\r
   if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_CLIENT) {\r
     Lasa = mTcgClientAcpiTemplate.Lasa;\r
-  \r
+\r
     Status = gBS->AllocatePages (\r
                     AllocateMaxAddress,\r
                     EfiACPIMemoryNVS,\r
-                    EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE),\r
+                    EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)),\r
                     &Lasa\r
                     );\r
     if (EFI_ERROR (Status)) {\r
@@ -663,19 +732,19 @@ SetupEventLog (
     }\r
     mTcgClientAcpiTemplate.Lasa = Lasa;\r
     //\r
-    // To initialize them as 0xFF is recommended \r
+    // To initialize them as 0xFF is recommended\r
     // because the OS can know the last entry for that.\r
     //\r
-    SetMem ((VOID *)(UINTN)mTcgClientAcpiTemplate.Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF);\r
-    mTcgClientAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE;\r
-  \r
+    SetMem ((VOID *)(UINTN)mTcgClientAcpiTemplate.Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF);\r
+    mTcgClientAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen);\r
+\r
   } else {\r
     Lasa = mTcgServerAcpiTemplate.Lasa;\r
-  \r
+\r
     Status = gBS->AllocatePages (\r
                     AllocateMaxAddress,\r
                     EfiACPIMemoryNVS,\r
-                    EFI_SIZE_TO_PAGES (EFI_TCG_LOG_AREA_SIZE),\r
+                    EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen)),\r
                     &Lasa\r
                     );\r
     if (EFI_ERROR (Status)) {\r
@@ -683,15 +752,15 @@ SetupEventLog (
     }\r
     mTcgServerAcpiTemplate.Lasa = Lasa;\r
     //\r
-    // To initialize them as 0xFF is recommended \r
+    // To initialize them as 0xFF is recommended\r
     // because the OS can know the last entry for that.\r
     //\r
-    SetMem ((VOID *)(UINTN)mTcgServerAcpiTemplate.Lasa, EFI_TCG_LOG_AREA_SIZE, 0xFF);\r
-    mTcgServerAcpiTemplate.Laml = EFI_TCG_LOG_AREA_SIZE;\r
+    SetMem ((VOID *)(UINTN)mTcgServerAcpiTemplate.Lasa, PcdGet32 (PcdTcgLogAreaMinLen), 0xFF);\r
+    mTcgServerAcpiTemplate.Laml = PcdGet32 (PcdTcgLogAreaMinLen);\r
   }\r
 \r
   GuidHob.Raw = GetHobList ();\r
-  while (!EFI_ERROR (Status) && \r
+  while (!EFI_ERROR (Status) &&\r
          (GuidHob.Raw = GetNextGuidHob (&gTcgEventEntryHobGuid, GuidHob.Raw)) != NULL) {\r
     TcgEvent    = GET_GUID_HOB_DATA (GuidHob.Guid);\r
     GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
@@ -708,8 +777,8 @@ SetupEventLog (
 /**\r
   Measure and log an action string, and extend the measurement result into PCR[5].\r
 \r
-  @param[in] String           A specific string that indicates an Action event.  \r
-  \r
+  @param[in] String           A specific string that indicates an Action event.\r
+\r
   @retval EFI_SUCCESS         Operation completed successfully.\r
   @retval EFI_DEVICE_ERROR    The operation was unsuccessful.\r
 \r
@@ -748,46 +817,17 @@ MeasureHandoffTables (
   )\r
 {\r
   EFI_STATUS                        Status;\r
-  SMBIOS_TABLE_ENTRY_POINT          *SmbiosTable;\r
   TCG_PCR_EVENT_HDR                 TcgEvent;\r
   EFI_HANDOFF_TABLE_POINTERS        HandoffTables;\r
   UINTN                             ProcessorNum;\r
   EFI_CPU_PHYSICAL_LOCATION         *ProcessorLocBuf;\r
 \r
   ProcessorLocBuf = NULL;\r
-\r
-  //\r
-  // Measure SMBIOS with EV_EFI_HANDOFF_TABLES to PCR[1]\r
-  //\r
-  Status = EfiGetSystemConfigurationTable (\r
-             &gEfiSmbiosTableGuid,\r
-             (VOID **) &SmbiosTable\r
-             );\r
-\r
-  if (!EFI_ERROR (Status) && SmbiosTable != NULL) {\r
-    TcgEvent.PCRIndex  = 1;\r
-    TcgEvent.EventType = EV_EFI_HANDOFF_TABLES;\r
-    TcgEvent.EventSize = sizeof (HandoffTables);\r
-\r
-    HandoffTables.NumberOfTables = 1;\r
-    HandoffTables.TableEntry[0].VendorGuid  = gEfiSmbiosTableGuid;\r
-    HandoffTables.TableEntry[0].VendorTable = SmbiosTable;\r
-\r
-    DEBUG ((DEBUG_INFO, "The Smbios Table starts at: 0x%x\n", SmbiosTable->TableAddress));\r
-    DEBUG ((DEBUG_INFO, "The Smbios Table size: 0x%x\n", SmbiosTable->TableLength));\r
-\r
-    Status = TcgDxeHashLogExtendEventI (\r
-               &mTcgDxeData,\r
-               (UINT8*)(UINTN)SmbiosTable->TableAddress,\r
-               SmbiosTable->TableLength,\r
-               &TcgEvent,\r
-               (UINT8*)&HandoffTables\r
-               );\r
-  }\r
+  Status = EFI_SUCCESS;\r
 \r
   if (PcdGet8 (PcdTpmPlatformClass) == TCG_PLATFORM_TYPE_SERVER) {\r
     //\r
-    // Tcg Server spec. \r
+    // Tcg Server spec.\r
     // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]\r
     //\r
     Status = GetProcessorsCpuLocation(&ProcessorLocBuf, &ProcessorNum);\r
@@ -819,7 +859,7 @@ MeasureHandoffTables (
 /**\r
   Measure and log Separator event, and extend the measurement result into a specific PCR.\r
 \r
-  @param[in] PCRIndex         PCR index.  \r
+  @param[in] PCRIndex         PCR index.\r
 \r
   @retval EFI_SUCCESS         Operation completed successfully.\r
   @retval EFI_DEVICE_ERROR    The operation was unsuccessful.\r
@@ -855,7 +895,7 @@ MeasureSeparatorEvent (
 \r
   @param[in]  VarName     A Null-terminated string that is the name of the vendor's variable.\r
   @param[in]  VendorGuid  A unique identifier for the vendor.\r
-  @param[out] VarSize     The size of the variable data.  \r
+  @param[out] VarSize     The size of the variable data.\r
 \r
   @return A pointer to the buffer to return the contents of the variable.Otherwise NULL.\r
 \r
@@ -904,13 +944,13 @@ ReadVariable (
 /**\r
   Measure and log an EFI variable, and extend the measurement result into a specific PCR.\r
 \r
-  @param[in]  PCRIndex          PCR Index.  \r
-  @param[in]  EventType         Event type.  \r
+  @param[in]  PCRIndex          PCR Index.\r
+  @param[in]  EventType         Event type.\r
   @param[in]  VarName           A Null-terminated string that is the name of the vendor's variable.\r
   @param[in]  VendorGuid        A unique identifier for the vendor.\r
-  @param[in]  VarData           The content of the variable data.  \r
-  @param[in]  VarSize           The size of the variable data.  \r
\r
+  @param[in]  VarData           The content of the variable data.\r
+  @param[in]  VarSize           The size of the variable data.\r
+\r
   @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Out of memory.\r
   @retval EFI_DEVICE_ERROR      The operation was unsuccessful.\r
@@ -959,8 +999,8 @@ MeasureVariable (
 \r
   Status = TcgDxeHashLogExtendEventI (\r
              &mTcgDxeData,\r
-             (UINT8*)VarData,\r
-             VarSize,\r
+             (UINT8*)VarLog,\r
+             TcgEvent.EventSize,\r
              &TcgEvent,\r
              (UINT8*)VarLog\r
              );\r
@@ -973,9 +1013,9 @@ MeasureVariable (
 \r
   @param[in]   VarName          A Null-terminated string that is the name of the vendor's variable.\r
   @param[in]   VendorGuid       A unique identifier for the vendor.\r
-  @param[out]  VarSize          The size of the variable data.  \r
-  @param[out]  VarData          Pointer to the content of the variable.  \r
\r
+  @param[out]  VarSize          The size of the variable data.\r
+  @param[out]  VarData          Pointer to the content of the variable.\r
+\r
   @retval EFI_SUCCESS           Operation completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES  Out of memory.\r
   @retval EFI_DEVICE_ERROR      The operation was unsuccessful.\r
@@ -1111,7 +1151,7 @@ OnReadyToBoot (
                EFI_CALLING_EFI_APPLICATION\r
                );\r
     if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION));\r
+      DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION));\r
     }\r
 \r
     //\r
@@ -1120,7 +1160,7 @@ OnReadyToBoot (
     for (PcrIndex = 0; PcrIndex < 8; PcrIndex++) {\r
       Status = MeasureSeparatorEvent (PcrIndex);\r
       if (EFI_ERROR (Status)) {\r
-        DEBUG ((EFI_D_ERROR, "Seperator Event not Measured. Error!\n"));\r
+        DEBUG ((DEBUG_ERROR, "Separator Event not Measured. Error!\n"));\r
       }\r
     }\r
 \r
@@ -1143,7 +1183,7 @@ OnReadyToBoot (
                EFI_RETURNING_FROM_EFI_APPLICATOIN\r
                );\r
     if (EFI_ERROR (Status)) {\r
-      DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN));\r
+      DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN));\r
     }\r
   }\r
 \r
@@ -1157,9 +1197,9 @@ OnReadyToBoot (
 /**\r
   Install TCG ACPI Table when ACPI Table Protocol is available.\r
 \r
-  A system's firmware uses an ACPI table to identify the system's TCG capabilities \r
-  to the Post-Boot environment. The information in this ACPI table is not guaranteed \r
-  to be valid until the Host Platform transitions from pre-boot state to post-boot state.  \r
+  A system's firmware uses an ACPI table to identify the system's TCG capabilities\r
+  to the Post-Boot environment. The information in this ACPI table is not guaranteed\r
+  to be valid until the Host Platform transitions from pre-boot state to post-boot state.\r
 \r
   @param[in]  Event     Event whose notification function is being invoked\r
   @param[in]  Context   Pointer to the notification function's context\r
@@ -1190,7 +1230,7 @@ InstallAcpiTable (
     mTcgClientAcpiTemplate.Header.CreatorId        = PcdGet32 (PcdAcpiDefaultCreatorId);\r
     mTcgClientAcpiTemplate.Header.CreatorRevision  = PcdGet32 (PcdAcpiDefaultCreatorRevision);\r
     //\r
-    // The ACPI table must be checksumed before calling the InstallAcpiTable() \r
+    // The ACPI table must be checksumed before calling the InstallAcpiTable()\r
     // service of the ACPI table protocol to install it.\r
     //\r
     Checksum = CalculateCheckSum8 ((UINT8 *)&mTcgClientAcpiTemplate, sizeof (mTcgClientAcpiTemplate));\r
@@ -1210,12 +1250,13 @@ InstallAcpiTable (
     mTcgServerAcpiTemplate.Header.CreatorId        = PcdGet32 (PcdAcpiDefaultCreatorId);\r
     mTcgServerAcpiTemplate.Header.CreatorRevision  = PcdGet32 (PcdAcpiDefaultCreatorRevision);\r
     //\r
-    // The ACPI table must be checksumed before calling the InstallAcpiTable() \r
+    // The ACPI table must be checksumed before calling the InstallAcpiTable()\r
     // service of the ACPI table protocol to install it.\r
     //\r
     Checksum = CalculateCheckSum8 ((UINT8 *)&mTcgServerAcpiTemplate, sizeof (mTcgServerAcpiTemplate));\r
     mTcgServerAcpiTemplate.Header.Checksum = Checksum;\r
 \r
+    mTcgServerAcpiTemplate.BaseAddress.Address = PcdGet64 (PcdTpmBaseAddress);\r
     Status = AcpiTable->InstallAcpiTable (\r
                             AcpiTable,\r
                             &mTcgServerAcpiTemplate,\r
@@ -1254,7 +1295,7 @@ OnExitBootServices (
              EFI_EXIT_BOOT_SERVICES_INVOCATION\r
              );\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION));\r
+    DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION));\r
   }\r
 \r
   //\r
@@ -1264,7 +1305,7 @@ OnExitBootServices (
              EFI_EXIT_BOOT_SERVICES_SUCCEEDED\r
              );\r
   if (EFI_ERROR (Status)){\r
-    DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED));\r
+    DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED));\r
   }\r
 }\r
 \r
@@ -1293,14 +1334,14 @@ OnExitBootServicesFailed (
              EFI_EXIT_BOOT_SERVICES_FAILED\r
              );\r
   if (EFI_ERROR (Status)){\r
-    DEBUG ((EFI_D_ERROR, "%s not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED));\r
+    DEBUG ((EFI_D_ERROR, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED));\r
   }\r
 }\r
 \r
 /**\r
   Get TPM Deactivated state.\r
 \r
-  @param[out] TPMDeactivatedFlag   Returns TPM Deactivated state.  \r
+  @param[out] TPMDeactivatedFlag   Returns TPM Deactivated state.\r
 \r
   @retval EFI_SUCCESS              Operation completed successfully.\r
   @retval EFI_DEVICE_ERROR         The operation was unsuccessful.\r
@@ -1308,20 +1349,15 @@ OnExitBootServicesFailed (
 **/\r
 EFI_STATUS\r
 GetTpmStatus (\r
-     OUT  BOOLEAN                   *TPMDeactivatedFlag\r
+  OUT BOOLEAN  *TPMDeactivatedFlag\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  TPM_STCLEAR_FLAGS                 VFlags;\r
+  EFI_STATUS         Status;\r
+  TPM_STCLEAR_FLAGS  VolatileFlags;\r
 \r
-  Status = TpmCommGetFlags (\r
-             mTcgDxeData.TpmHandle,\r
-             TPM_CAP_FLAG_VOLATILE,\r
-             &VFlags,\r
-             sizeof (VFlags)\r
-             );\r
+  Status = Tpm12GetCapabilityFlagVolatile (&VolatileFlags);\r
   if (!EFI_ERROR (Status)) {\r
-    *TPMDeactivatedFlag = VFlags.deactivated;\r
+    *TPMDeactivatedFlag = VolatileFlags.deactivated;\r
   }\r
 \r
   return Status;\r
@@ -1332,9 +1368,9 @@ GetTpmStatus (
 \r
   It publishes EFI TCG Protocol.\r
 \r
-  @param[in] ImageHandle  The firmware allocated handle for the EFI image.  \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
+\r
   @retval EFI_SUCCESS     The entry point is executed successfully.\r
   @retval other           Some error occurs when executing this entry point.\r
 \r
@@ -1355,24 +1391,22 @@ DriverEntry (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  mTcgDxeData.TpmHandle = (TIS_TPM_HANDLE)(UINTN)TPM_BASE_ADDRESS;\r
-  Status = TisPcRequestUseTpm (mTcgDxeData.TpmHandle);\r
+  if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {\r
+    DEBUG ((EFI_D_ERROR, "TPM error!\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Status = Tpm12RequestUseTpm ();\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "TPM not detected!\n"));\r
     return Status;\r
   }\r
 \r
-  if (GetFirstGuidHob (&gTpmErrorHobGuid) != NULL) {\r
-    mTcgDxeData.BsCap.TPMPresentFlag = FALSE;\r
-  }\r
-\r
   Status = GetTpmStatus (&mTcgDxeData.BsCap.TPMDeactivatedFlag);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((\r
       EFI_D_ERROR,\r
-      "Line %d in file " __FILE__ ":\n    "\r
-      "DriverEntry: TPM not working properly\n",\r
-      __LINE__\r
+      "DriverEntry: TPM not working properly\n"\r
       ));\r
     return Status;\r
   }\r
@@ -1410,7 +1444,7 @@ DriverEntry (
                     );\r
 \r
     //\r
-    // Measure Exit Boot Service failed \r
+    // Measure Exit Boot Service failed\r
     //\r
     Status = gBS->CreateEventEx (\r
                     EVT_NOTIFY_SIGNAL,\r
@@ -1426,6 +1460,6 @@ DriverEntry (
   // Install ACPI Table\r
   //\r
   EfiCreateProtocolNotifyEvent (&gEfiAcpiTableProtocolGuid, TPL_CALLBACK, InstallAcpiTable, NULL, &Registration);\r
-  \r
+\r
   return Status;\r
 }\r