]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
SecurityPkg: Fix spelling errors
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Smm / Tcg2Smm.c
index 4a1a293bfcd3dda32f46c7c61e1772db3dd69a75..bd786bf4791fb8c792ebb55cd0fd56a254a2516b 100644 (file)
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.\r
 \r
 Copyright (c) 2015 - 2018, 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
-http://opensource.org/licenses/bsd-license.php\r
-\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
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "Tcg2Smm.h"\r
 \r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  EFI_ACPI_DESCRIPTION_HEADER Header;\r
+  // Flags field is replaced in version 4 and above\r
+  //    BIT0~15:  PlatformClass      This field is only valid for version 4 and above\r
+  //    BIT16~31: Reserved\r
+  UINT32                      Flags;\r
+  UINT64                      AddressOfControlArea;\r
+  UINT32                      StartMethod;\r
+  UINT8                       PlatformSpecificParameters[12];  // size up to 12\r
+  UINT32                      Laml;                          // Optional\r
+  UINT64                      Lasa;                          // Optional\r
+} EFI_TPM2_ACPI_TABLE_V4;\r
+\r
+#pragma pack()\r
 \r
-EFI_TPM2_ACPI_TABLE  mTpm2AcpiTemplate = {\r
+EFI_TPM2_ACPI_TABLE_V4  mTpm2AcpiTemplate = {\r
   {\r
     EFI_ACPI_5_0_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE,\r
     sizeof (mTpm2AcpiTemplate),\r
@@ -259,7 +269,7 @@ UpdatePPVersion (
 \r
 /**\r
   Patch interrupt resources returned by TPM _PRS. ResourceTemplate to patch is determined by input\r
-  interrupt buffer size. BufferSize, PkgLength and interrupt descirptor in ByteList need to be patched\r
+  interrupt buffer size. BufferSize, PkgLength and interrupt descriptor in ByteList need to be patched\r
 \r
   @param[in, out] Table            The TPM item in ACPI table.\r
   @param[in]      IrqBuffer        Input new IRQ buffer.\r
@@ -294,7 +304,7 @@ UpdatePossibleResource (
   // to patch TPM ACPI object _PRS returned ResourceTemplate() containing 2 resource descriptors and an auto appended End Tag\r
   //\r
   //  AML data is organized by following rule.\r
-  //  Code need to patch BufferSize and PkgLength and interrupt descirptor in ByteList\r
+  //  Code need to patch BufferSize and PkgLength and interrupt descriptor in ByteList\r
   //\r
   // =============  Buffer ====================\r
   //           DefBuffer := BufferOp PkgLength BufferSize ByteList\r
@@ -311,8 +321,8 @@ UpdatePossibleResource (
   //                               <bit 3-0: Least significant package length nybble>\r
   //\r
   //==============BufferSize==================\r
-  //        BufferSize := Integar\r
-  //           Integar := ByteConst|WordConst|DwordConst....\r
+  //        BufferSize := Integer\r
+  //           Integer := ByteConst|WordConst|DwordConst....\r
   //\r
   //           ByteConst := BytePrefix ByteData\r
   //\r
@@ -361,7 +371,7 @@ UpdatePossibleResource (
       }\r
 \r
       //\r
-      // Include Memory32Fixed Descritor (12 Bytes) + Interrupt Descriptor header(5 Bytes) + End Tag(2 Bytes)\r
+      // Include Memory32Fixed Descriptor (12 Bytes) + Interrupt Descriptor header(5 Bytes) + End Tag(2 Bytes)\r
       //\r
       NewPkgLength += 19 + IrqBuffserSize;\r
       if (NewPkgLength > 63) {\r
@@ -379,7 +389,7 @@ UpdatePossibleResource (
       *DataPtr = (UINT8)NewPkgLength;\r
 \r
       //\r
-      // 1.2 Patch BufferSize = sizeof(Memory32Fixed Descritor + Interrupt Descriptor + End Tag).\r
+      // 1.2 Patch BufferSize = sizeof(Memory32Fixed Descriptor + Interrupt Descriptor + End Tag).\r
       //      It is Little endian. So only patch lowest byte of BufferSize due to current interrupt number limit.\r
       //\r
       *(DataPtr + 2) = (UINT8)(IrqBuffserSize + 19);\r
@@ -435,7 +445,7 @@ UpdatePossibleResource (
         }\r
 \r
         //\r
-        // Include Memory32Fixed Descritor (12 Bytes) + Interrupt Descriptor header(5 Bytes) + End Tag(2  Bytes)\r
+        // Include Memory32Fixed Descriptor (12 Bytes) + Interrupt Descriptor header(5 Bytes) + End Tag(2  Bytes)\r
         //\r
         NewPkgLength += 19 + IrqBuffserSize;\r
 \r
@@ -451,7 +461,7 @@ UpdatePossibleResource (
         *(DataPtr + 1) = (UINT8)((NewPkgLength & 0xFF0) >> 4);\r
 \r
         //\r
-        // 2.2 Patch BufferSize = sizeof(Memory32Fixed Descritor + Interrupt Descriptor + End Tag).\r
+        // 2.2 Patch BufferSize = sizeof(Memory32Fixed Descriptor + Interrupt Descriptor + End Tag).\r
         //     It is Little endian. Only patch lowest byte of BufferSize due to current interrupt number limit.\r
         //\r
         *(DataPtr + 2 + ((*DataPtr & (BIT7|BIT6)) >> 6)) = (UINT8)(IrqBuffserSize + 19);\r
@@ -475,7 +485,7 @@ UpdatePossibleResource (
   //\r
   DataPtr += NewPkgLength - (5 + IrqBuffserSize + 2);\r
   //\r
-  //   3.1 Patch Length bit[7:0] of Interrupt descirptor patch interrupt descriptor\r
+  //   3.1 Patch Length bit[7:0] of Interrupt descriptor patch interrupt descriptor\r
   //\r
   *(DataPtr + 1) = (UINT8)(2 + IrqBuffserSize);\r
   //\r
@@ -488,7 +498,7 @@ UpdatePossibleResource (
   CopyMem(DataPtr + 5, IrqBuffer, IrqBuffserSize);\r
 \r
   //\r
-  // 4. Jump over Interrupt descirptor and Patch END Tag, set Checksum field to 0\r
+  // 4. Jump over Interrupt descriptor and Patch END Tag, set Checksum field to 0\r
   //\r
   DataPtr       += 5 + IrqBuffserSize;\r
   *DataPtr       = ACPI_END_TAG_DESCRIPTOR;\r
@@ -705,7 +715,7 @@ PublishAcpiTable (
   mTcgNvs->IsShortFormPkgLength = IsShortFormPkgLength;\r
 \r
   //\r
-  // Publish the TPM ACPI table. Table is re-checksumed.\r
+  // Publish the TPM ACPI table. Table is re-checksummed.\r
   //\r
   Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTable);\r
   ASSERT_EFI_ERROR (Status);\r
@@ -754,6 +764,16 @@ PublishTpm2 (
     DEBUG((DEBUG_INFO, "Tpm2 ACPI table PlatformClass is %d\n", (mTpm2AcpiTemplate.Flags & 0x0000FFFF)));\r
   }\r
 \r
+  mTpm2AcpiTemplate.Laml = PcdGet32(PcdTpm2AcpiTableLaml);\r
+  mTpm2AcpiTemplate.Lasa = PcdGet64(PcdTpm2AcpiTableLasa);\r
+  if ((mTpm2AcpiTemplate.Header.Revision < EFI_TPM2_ACPI_TABLE_REVISION_4) ||\r
+      (mTpm2AcpiTemplate.Laml == 0) || (mTpm2AcpiTemplate.Lasa == 0)) {\r
+    //\r
+    // If version is smaller than 4 or Laml/Lasa is not valid, rollback to original Length.\r
+    //\r
+    mTpm2AcpiTemplate.Header.Length = sizeof(EFI_TPM2_ACPI_TABLE);\r
+  }\r
+\r
   //\r
   // Measure to PCR[0] with event EV_POST_CODE ACPI DATA\r
   //\r
@@ -763,7 +783,7 @@ PublishTpm2 (
     EV_POSTCODE_INFO_ACPI_DATA,\r
     ACPI_DATA_LEN,\r
     &mTpm2AcpiTemplate,\r
-    sizeof(mTpm2AcpiTemplate)\r
+    mTpm2AcpiTemplate.Header.Length\r
     );\r
 \r
   InterfaceType = PcdGet8(PcdActiveTpmInterfaceType);\r
@@ -801,7 +821,7 @@ PublishTpm2 (
   Status = AcpiTable->InstallAcpiTable (\r
                         AcpiTable,\r
                         &mTpm2AcpiTemplate,\r
-                        sizeof(mTpm2AcpiTemplate),\r
+                        mTpm2AcpiTemplate.Header.Length,\r
                         &TableKey\r
                         );\r
   ASSERT_EFI_ERROR (Status);\r