]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhance TcgSmm driver to handle potential SetVariable failure case.
authorgdong1 <gdong1@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 11 May 2012 05:10:57 +0000 (05:10 +0000)
committergdong1 <gdong1@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 11 May 2012 05:10:57 +0000 (05:10 +0000)
Signed-off-by: Dong Guo <guo.dong@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Yao Jiewen <jiewen.yao@intel.com>
Reviewed-by: Ouyang Qian <qian.ouyang@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13309 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Tcg/TcgSmm/TcgSmm.c
SecurityPkg/Tcg/TcgSmm/TcgSmm.h [new file with mode: 0644]
SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
SecurityPkg/Tcg/TcgSmm/Tpm.asl

index 0e18357b16287da20a13a02c0436fe445ea1ccd8..dd6d89f695fc7310a1279a90c8f75210f364f234 100644 (file)
@@ -2,7 +2,7 @@
   It updates TPM items in ACPI table and registers SMI callback\r
   functions for physical presence and ClearMemory.\r
 \r
-Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 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
@@ -13,54 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-\r
-#include <PiDxe.h>\r
-#include <IndustryStandard/Acpi.h>\r
-#include <Guid/PhysicalPresenceData.h>\r
-#include <Guid/MemoryOverwriteControl.h>\r
-#include <Protocol/SmmSwDispatch2.h>\r
-#include <Protocol/AcpiTable.h>\r
-#include <Protocol/SmmVariable.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/SmmServicesTableLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/DxeServicesLib.h>\r
-\r
-#pragma pack(1)\r
-typedef struct {\r
-  UINT8                  SoftwareSmi;\r
-  UINT32                 Parameter;\r
-  UINT32                 Response;\r
-  UINT32                 Request;\r
-  UINT32                 LastRequest;\r
-  UINT32                 ReturnCode;\r
-} PHYSICAL_PRESENCE_NVS;\r
-\r
-typedef struct {\r
-  UINT8                  SoftwareSmi;\r
-  UINT32                 Parameter;\r
-  UINT32                 Request;\r
-} MEMORY_CLEAR_NVS;\r
-\r
-typedef struct {\r
-  PHYSICAL_PRESENCE_NVS  PhysicalPresence;\r
-  MEMORY_CLEAR_NVS       MemoryClear;\r
-} TCG_NVS;\r
-\r
-typedef struct {\r
-  UINT8                  OpRegionOp;\r
-  UINT32                 NameString;\r
-  UINT8                  RegionSpace;\r
-  UINT8                  DWordPrefix;\r
-  UINT32                 RegionOffset;\r
-  UINT8                  BytePrefix;\r
-  UINT8                  RegionLen;\r
-} AML_OP_REGION_32_8;\r
-#pragma pack()\r
+#include "TcgSmm.h"\r
 \r
 EFI_SMM_VARIABLE_PROTOCOL  *mSmmVariable;\r
 TCG_NVS                    *mTcgNvs;\r
@@ -109,23 +62,16 @@ PhysicalPresenceCallback (
   }\r
 \r
   DEBUG ((EFI_D_INFO, "[TPM] PP callback, Parameter = %x\n", mTcgNvs->PhysicalPresence.Parameter));\r
-  if (mTcgNvs->PhysicalPresence.Parameter == 5) {\r
-    //\r
-    // Return TPM Operation Response to OS Environment\r
-    //\r
+  if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) {\r
     mTcgNvs->PhysicalPresence.LastRequest = PpData.LastPPRequest;\r
     mTcgNvs->PhysicalPresence.Response    = PpData.PPResponse;\r
-\r
-  } else if ((mTcgNvs->PhysicalPresence.Parameter == 2) || (mTcgNvs->PhysicalPresence.Parameter == 7)) {\r
-    //\r
-    // Submit TPM Operation Request to Pre-OS Environment\r
-    //\r
-\r
+  } else if ((mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS) \r
+          || (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2)) {\r
     if (mTcgNvs->PhysicalPresence.Request == PHYSICAL_PRESENCE_SET_OPERATOR_AUTH) {\r
       //\r
-      // This command requires UI to prompt user for Auth data, NOT implemented.\r
+      // This command requires UI to prompt user for Auth data.\r
       //\r
-      mTcgNvs->PhysicalPresence.ReturnCode = 1;\r
+      mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_NOT_IMPLEMENTED;\r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -142,17 +88,11 @@ PhysicalPresenceCallback (
     }\r
 \r
     if (EFI_ERROR (Status)) { \r
-      //\r
-      // General failure.\r
-      //\r
-      mTcgNvs->PhysicalPresence.ReturnCode = 2;\r
+      mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_GENERAL_FAILURE;\r
       return EFI_SUCCESS;\r
     }\r
-    mTcgNvs->PhysicalPresence.ReturnCode = 0;\r
-  } else if (mTcgNvs->PhysicalPresence.Parameter == 8) {\r
-    // \r
-    // Get User Confirmation Status for Operation\r
-    //\r
+    mTcgNvs->PhysicalPresence.ReturnCode = PP_SUBMIT_REQUEST_SUCCESS;\r
+  } else if (mTcgNvs->PhysicalPresence.Parameter == ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST) {\r
     Flags = PpData.Flags;  \r
     RequestConfirmed = FALSE;\r
 \r
@@ -202,22 +142,15 @@ PhysicalPresenceCallback (
       case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:\r
         //\r
         // This command requires UI to prompt user for Auth data\r
-        // Here it is NOT implemented\r
         //\r
-        mTcgNvs->PhysicalPresence.ReturnCode = 0\r
+        mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_NOT_IMPLEMENTED\r
         return EFI_SUCCESS;\r
     }\r
 \r
     if (RequestConfirmed) {\r
-      //\r
-      // Allowed and physically present user not required \r
-      //\r
-      mTcgNvs->PhysicalPresence.ReturnCode = 4;\r
+      mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_ALLOWED_AND_PPUSER_NOT_REQUIRED;\r
     } else {\r
-      //\r
-      // Allowed and physically present user required \r
-      //\r
-      mTcgNvs->PhysicalPresence.ReturnCode = 3;\r
+      mTcgNvs->PhysicalPresence.ReturnCode = PP_REQUEST_ALLOWED_AND_PPUSER_REQUIRED;\r
     }    \r
   } \r
 \r
@@ -251,15 +184,10 @@ MemoryClearCallback (
   UINTN                          DataSize;\r
   UINT8                          MorControl;\r
 \r
-  if (mTcgNvs->MemoryClear.Parameter == 1) {\r
-    //\r
-    // Called from ACPI _DSM method, save the MOR data to variable.\r
-    //\r
+  mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_SUCCESS;\r
+  if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE) {\r
     MorControl = (UINT8) mTcgNvs->MemoryClear.Request;\r
-  } else if (mTcgNvs->MemoryClear.Parameter == 2) {\r
-    //\r
-    // Called from ACPI _PTS method, setup ClearMemory flags if needed.\r
-    //\r
+  } else if (mTcgNvs->MemoryClear.Parameter == ACPI_FUNCTION_PTS_CLEAR_MOR_BIT) {\r
     DataSize = sizeof (UINT8);\r
     Status = mSmmVariable->SmmGetVariable (\r
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r
@@ -269,7 +197,6 @@ MemoryClearCallback (
                              &MorControl\r
                              );\r
     if (EFI_ERROR (Status)) {\r
-      ASSERT (Status == EFI_NOT_FOUND);\r
       return EFI_SUCCESS;\r
     }\r
 \r
@@ -287,7 +214,9 @@ MemoryClearCallback (
                            DataSize,\r
                            &MorControl\r
                            );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) { \r
+    mTcgNvs->MemoryClear.ReturnCode = MOR_REQUEST_GENERAL_FAILURE;\r
+  }\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -324,7 +253,6 @@ AssignOpRegion (
        OpRegion  = (AML_OP_REGION_32_8 *) ((UINT8 *) OpRegion + 1)) {\r
     if ((OpRegion->OpRegionOp  == AML_EXT_REGION_OP) && \r
         (OpRegion->NameString  == Name) &&\r
-        (OpRegion->RegionLen   == Size) &&\r
         (OpRegion->DWordPrefix == AML_DWORD_PREFIX) &&\r
         (OpRegion->BytePrefix  == AML_BYTE_PREFIX)) {\r
 \r
@@ -332,6 +260,7 @@ AssignOpRegion (
       ASSERT_EFI_ERROR (Status);\r
       ZeroMem ((VOID *)(UINTN)MemoryAddress, Size);\r
       OpRegion->RegionOffset = (UINT32) (UINTN) MemoryAddress;\r
+      OpRegion->RegionLen    = (UINT8) Size;\r
       break;\r
     }\r
   }\r
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
new file mode 100644 (file)
index 0000000..1706132
--- /dev/null
@@ -0,0 +1,110 @@
+/** @file\r
+  The header file for TCG SMM driver.\r
+  \r
+Copyright (c) 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
+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
+\r
+**/\r
+\r
+#ifndef __TCG_SMM_H__\r
+#define __TCG_SMM_H__\r
+\r
+#include <PiDxe.h>\r
+#include <IndustryStandard/Acpi.h>\r
+#include <Guid/PhysicalPresenceData.h>\r
+#include <Guid/MemoryOverwriteControl.h>\r
+#include <Protocol/SmmSwDispatch2.h>\r
+#include <Protocol/AcpiTable.h>\r
+#include <Protocol/SmmVariable.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/SmmServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DxeServicesLib.h>\r
+\r
+#pragma pack(1)\r
+typedef struct {\r
+  UINT8                  SoftwareSmi;\r
+  UINT32                 Parameter;\r
+  UINT32                 Response;\r
+  UINT32                 Request;\r
+  UINT32                 LastRequest;\r
+  UINT32                 ReturnCode;\r
+} PHYSICAL_PRESENCE_NVS;\r
+\r
+typedef struct {\r
+  UINT8                  SoftwareSmi;\r
+  UINT32                 Parameter;\r
+  UINT32                 Request;\r
+  UINT32                 ReturnCode;\r
+} MEMORY_CLEAR_NVS;\r
+\r
+typedef struct {\r
+  PHYSICAL_PRESENCE_NVS  PhysicalPresence;\r
+  MEMORY_CLEAR_NVS       MemoryClear;\r
+} TCG_NVS;\r
+\r
+typedef struct {\r
+  UINT8                  OpRegionOp;\r
+  UINT32                 NameString;\r
+  UINT8                  RegionSpace;\r
+  UINT8                  DWordPrefix;\r
+  UINT32                 RegionOffset;\r
+  UINT8                  BytePrefix;\r
+  UINT8                  RegionLen;\r
+} AML_OP_REGION_32_8;\r
+#pragma pack()\r
+\r
+//\r
+// The definition for TCG physical presence ACPI function\r
+//\r
+#define ACPI_FUNCTION_GET_PHYSICAL_PRESENCE_INTERFACE_VERSION      1\r
+#define ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS                       2\r
+#define ACPI_FUNCTION_GET_PENDING_REQUEST_BY_OS                    3\r
+#define ACPI_FUNCTION_GET_PLATFORM_ACTION_TO_TRANSITION_TO_BIOS    4\r
+#define ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS                5\r
+#define ACPI_FUNCTION_SUBMIT_PREFERRED_USER_LANGUAGE               6\r
+#define ACPI_FUNCTION_SUBMIT_REQUEST_TO_BIOS_2                     7\r
+#define ACPI_FUNCTION_GET_USER_CONFIRMATION_STATUS_FOR_REQUEST     8\r
+\r
+//\r
+// The return code for Get User Confirmation Status for Operation\r
+//\r
+#define PP_REQUEST_NOT_IMPLEMENTED                                 0\r
+#define PP_REQUEST_BIOS_ONLY                                       1\r
+#define PP_REQUEST_BLOCKED                                         2\r
+#define PP_REQUEST_ALLOWED_AND_PPUSER_REQUIRED                     3\r
+#define PP_REQUEST_ALLOWED_AND_PPUSER_NOT_REQUIRED                 4\r
+\r
+//\r
+// The return code for Sumbit TPM Request to Pre-OS Environment\r
+// and Sumbit TPM Request to Pre-OS Environment 2\r
+//\r
+#define PP_SUBMIT_REQUEST_SUCCESS                                  0\r
+#define PP_SUBMIT_REQUEST_NOT_IMPLEMENTED                          1\r
+#define PP_SUBMIT_REQUEST_GENERAL_FAILURE                          2\r
+#define PP_SUBMIT_REQUEST_BLOCKED_BY_BIOS_SETTINGS                 3\r
+\r
+\r
+//\r
+// The definition for TCG MOR\r
+//\r
+#define ACPI_FUNCTION_DSM_MEMORY_CLEAR_INTERFACE                   1\r
+#define ACPI_FUNCTION_PTS_CLEAR_MOR_BIT                            2\r
+\r
+//\r
+// The return code for Memory Clear Interface Functions\r
+//\r
+#define MOR_REQUEST_SUCCESS                                        0\r
+#define MOR_REQUEST_GENERAL_FAILURE                                1\r
+\r
+#endif  // __TCG_SMM_H__\r
index c8e7092e73807125c3e12ef6562b6d5363327cfb..9e5751a430d9ba026e3c8f87f595b5f9fb498b8d 100644 (file)
@@ -3,7 +3,7 @@
 #  registers SMI callback functions for physical presence and \r
 #  MemoryClear to handle the requests from ACPI method.\r
 #\r
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2011 - 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
@@ -24,6 +24,7 @@
 \r
 [Sources]\r
   TcgSmm.c\r
+  TcgSmm.h\r
   Tpm.asl\r
 \r
 [Packages]\r
index 47a68ca61a2f6867fec51441bb874f5873878564..6dafa0277dc71d2e78dbd8e4c5de5f868a70299c 100644 (file)
@@ -2,7 +2,7 @@
   The TPM definition block in ACPI table for physical presence  \r
   and MemoryClear.\r
 \r
-Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 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
@@ -64,9 +64,9 @@ DefinitionBlock (
 \r
       //\r
       // Operational region for TPM support, TPM Physical Presence and TPM Memory Clear\r
-      // Region Offset to be fixed at runtime\r
+      // Region Offset 0xFFFF0000 and Length 0xF0 will be fixed in C code.\r
       //\r
-      OperationRegion (TNVS, SystemMemory, 0xFFFF0000, 0x1E)\r
+      OperationRegion (TNVS, SystemMemory, 0xFFFF0000, 0xF0)\r
       Field (TNVS, AnyAcc, NoLock, Preserve)\r
       {\r
         PPIN,   8,  //   Software SMI for Physical Presence Interface\r
@@ -77,7 +77,8 @@ DefinitionBlock (
         FRET,   32, //   Physical Presence function return code\r
         MCIN,   8,  //   Software SMI for Memory Clear Interface\r
         MCIP,   32, //   Used for save the Mor paramter\r
-        MORD,   32  //   Memory Overwrite Request Data\r
+        MORD,   32, //   Memory Overwrite Request Data\r
+        MRET,   32  //   Memory Overwrite function return code\r
       }\r
 \r
       Method (PTS, 1, Serialized)\r
@@ -313,7 +314,7 @@ DefinitionBlock (
             // Triggle the SMI interrupt\r
             //\r
             Store (MCIN, IOB2)\r
-            Return (0)\r
+            Return (MRET)\r
           }\r
           Default {BreakPoint}\r
         }\r