]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add HSTI support.
authorYao, Jiewen <jiewen.yao@intel.com>
Mon, 19 Jan 2015 06:08:23 +0000 (06:08 +0000)
committerjyao1 <jyao1@Edk2>
Mon, 19 Jan 2015 06:08:23 +0000 (06:08 +0000)
Add HSTI header file and a library to assist HSTI table creation.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <jiewen.yao@intel.com>
Reviewed-by: "Gao, Liming" <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16621 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/IndustryStandard/Hsti.h [new file with mode: 0644]
MdePkg/Include/Library/HstiLib.h [new file with mode: 0644]
MdePkg/Library/DxeHstiLib/DxeHstiLib.inf [new file with mode: 0644]
MdePkg/Library/DxeHstiLib/DxeHstiLib.uni [new file with mode: 0644]
MdePkg/Library/DxeHstiLib/HstiAip.c [new file with mode: 0644]
MdePkg/Library/DxeHstiLib/HstiDxe.c [new file with mode: 0644]
MdePkg/Library/DxeHstiLib/HstiDxe.h [new file with mode: 0644]
MdePkg/MdePkg.dec
MdePkg/MdePkg.dsc

diff --git a/MdePkg/Include/IndustryStandard/Hsti.h b/MdePkg/Include/IndustryStandard/Hsti.h
new file mode 100644 (file)
index 0000000..1f11855
--- /dev/null
@@ -0,0 +1,82 @@
+/** @file\r
+  Support for HSTI 1.0 specification, defined at \r
+  Microsoft Hardware Security Testability Specification.\r
+\r
+  Copyright (c) 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
+  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 __HSTI_H__\r
+#define __HSTI_H__\r
+\r
+#pragma pack(1)\r
+\r
+#define ADAPTER_INFO_PLATFORM_SECURITY_GUID \\r
+  {0x6be272c7, 0x1320, 0x4ccd, { 0x90, 0x17, 0xd4, 0x61, 0x2c, 0x01, 0x2b, 0x25 }}\r
+\r
+#define PLATFORM_SECURITY_VERSION_VNEXTCS         0x00000003\r
+\r
+#define PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE 0x00000001  // IHV\r
+#define PLATFORM_SECURITY_ROLE_PLATFORM_IBV       0x00000002\r
+#define PLATFORM_SECURITY_ROLE_IMPLEMENTOR_OEM    0x00000003 \r
+#define PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM    0x00000004  \r
+\r
+typedef struct {\r
+  //\r
+  //  Return PLATFORM_SECURITY_VERSION_VNEXTCS\r
+  //\r
+  UINT32  Version;\r
+  //\r
+  // The role of the publisher of this interface.  Reference platform designers\r
+  // such as IHVs and IBVs are expected to return PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE\r
+  // and PLATFORM_SECURITY_ROLE_PLATFORM_IBV respectively.\r
+  // If the test modules from the designers are unable to fully verify all\r
+  // security features, then the platform implementers, OEMs and ODMs, will\r
+  // need to publish this interface with a role of Implementer.\r
+  //\r
+  UINT32  Role;\r
+  //\r
+  // Human readable vendor, model, & version of this implementation.\r
+  //\r
+  CHAR16  ImplementationID[256];\r
+  //\r
+  // The size in bytes of the SecurityFeaturesRequired and SecurityFeaturesEnabled arrays.\r
+  // The arrays must be the same size.\r
+  //\r
+  UINT32  SecurityFeaturesSize;\r
+  //\r
+  // IHV-defined bitfield corresponding to all security features which must be\r
+  // implemented to meet the security requirements defined by PLATFORM_SECURITY_VERSION Version.\r
+  //\r
+//UINT8   SecurityFeaturesRequired[];     //Ignored for non-IHV\r
+  //\r
+  // Publisher-defined bitfield corresponding to all security features which\r
+  // have implemented programmatic tests in this module.\r
+  //\r
+//UINT8   SecurityFeaturesImplemented[];\r
+  //\r
+  // Publisher-defined bitfield corresponding to all security features which\r
+  // have been verified implemented by this implementation.\r
+  //\r
+//UINT8   SecurityFeaturesVerified[];\r
+  //\r
+  // A Null-terminated string, one failure per line (CR/LF terminated), with a\r
+  // unique identifier that the OEM/ODM can use to locate the documentation\r
+  // which will describe the steps to remediate the failure - a URL to the\r
+  // documentation is recommended.\r
+  //\r
+//CHAR16       ErrorString[];\r
+} ADAPTER_INFO_PLATFORM_SECURITY;\r
+\r
+#pragma pack()\r
+\r
+extern EFI_GUID gAdapterInfoPlatformSecurityGuid;\r
+\r
+#endif\r
diff --git a/MdePkg/Include/Library/HstiLib.h b/MdePkg/Include/Library/HstiLib.h
new file mode 100644 (file)
index 0000000..9af8817
--- /dev/null
@@ -0,0 +1,158 @@
+/** @file\r
+  Provides services to create, get and update HSTI table in AIP protocol.\r
+\r
+  Copyright (c) 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
+  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 __HSTI_LIB_H__\r
+#define __HSTI_LIB_H__\r
+\r
+/**\r
+  Publish HSTI table in AIP protocol.\r
+\r
+  One system should have only one PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE.\r
+\r
+  If the Role is NOT PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,\r
+  SecurityFeaturesRequired field will be ignored.\r
+\r
+  @param Hsti      HSTI data\r
+  @param HstiSize  HSTI size\r
+\r
+  @retval EFI_SUCCESS          The HSTI data is published in AIP protocol.\r
+  @retval EFI_ALREADY_STARTED  There is already HSTI table with Role and ImplementationID published in system.\r
+  @retval EFI_VOLUME_CORRUPTED The input HSTI data does not follow HSTI specification.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish HSTI data in AIP protocol.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibSetTable (\r
+  IN VOID                     *Hsti,\r
+  IN UINTN                    HstiSize\r
+  );\r
+\r
+/**\r
+  Search HSTI table in AIP protocol, and return the data.\r
+  This API will return the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param Hsti             HSTI data. This buffer is allocated by callee, and it\r
+                          is the responsibility of the caller to free it after\r
+                          using it.\r
+  @param HstiSize         HSTI size\r
+\r
+  @retval EFI_SUCCESS          The HSTI data in AIP protocol is returned.\r
+  @retval EFI_NOT_FOUND        There is not HSTI table with the Role and ImplementationID published in system.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibGetTable (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID OPTIONAL,\r
+  OUT VOID                    **Hsti,\r
+  OUT UINTN                   *HstiSize\r
+  );\r
+\r
+/**\r
+  Set FeaturesVerified in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ByteIndex        Byte index of FeaturesVerified of HSTI data.\r
+  @param BitMask          Bit mask of FeaturesVerified of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The FeaturesVerified of HSTI data updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_UNSUPPORTED      The ByteIndex is invalid.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibSetFeaturesVerified (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN UINT32                   ByteIndex,\r
+  IN UINT8                    BitMask\r
+  );\r
+\r
+/**\r
+  Clear FeaturesVerified in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ByteIndex        Byte index of FeaturesVerified of HSTI data.\r
+  @param BitMask          Bit mask of FeaturesVerified of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The FeaturesVerified of HSTI data updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_UNSUPPORTED      The ByteIndex is invalid.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibClearFeaturesVerified (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN UINT32                   ByteIndex,\r
+  IN UINT8                    BitMask\r
+  );\r
+\r
+/**\r
+  Append ErrorString in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ErrorString      ErrorString of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The ErrorString of HSTI data is updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibAppendErrorString (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN CHAR16                   *ErrorString\r
+  );\r
+\r
+/**\r
+  Set a new ErrorString in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ErrorString      ErrorString of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The ErrorString of HSTI data is updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibSetErrorString (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN CHAR16                   *ErrorString\r
+  );\r
+\r
+#endif\r
diff --git a/MdePkg/Library/DxeHstiLib/DxeHstiLib.inf b/MdePkg/Library/DxeHstiLib/DxeHstiLib.inf
new file mode 100644 (file)
index 0000000..a694c2c
--- /dev/null
@@ -0,0 +1,48 @@
+## @file\r
+# DXE instance of Hsti Library.\r
+#\r
+# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+#\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
+#  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
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeHstiLib\r
+  MODULE_UNI_FILE                = DxeHstiLib.uni\r
+  FILE_GUID                      = 7DE1C620-F587-4116-A36D-40F3467B9A0C\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = HstiLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
+\r
+[Sources]\r
+  HstiAip.c\r
+  HstiDxe.c\r
+  HstiDxe.h\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  DebugLib\r
+  UefiBootServicesTableLib\r
+\r
+[Guids]\r
+## SOMETIMES_PRODUCES ## GUID\r
+## SOMETIMES_CONSUMES ## GUID\r
+  gAdapterInfoPlatformSecurityGuid\r
+\r
+[Protocols]\r
+## SOMETIMES_PRODUCES\r
+## SOMETIMES_CONSUMES\r
+  gEfiAdapterInformationProtocolGuid\r
+\r
diff --git a/MdePkg/Library/DxeHstiLib/DxeHstiLib.uni b/MdePkg/Library/DxeHstiLib/DxeHstiLib.uni
new file mode 100644 (file)
index 0000000..d5b7a78
Binary files /dev/null and b/MdePkg/Library/DxeHstiLib/DxeHstiLib.uni differ
diff --git a/MdePkg/Library/DxeHstiLib/HstiAip.c b/MdePkg/Library/DxeHstiLib/HstiAip.c
new file mode 100644 (file)
index 0000000..5677cd3
--- /dev/null
@@ -0,0 +1,175 @@
+/** @file\r
+\r
+  Copyright (c) 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
+  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
+#include "HstiDxe.h"\r
+\r
+/**\r
+  Returns the current state information for the adapter.\r
+\r
+  This function returns information of type InformationType from the adapter.\r
+  If an adapter does not support the requested informational type, then\r
+  EFI_UNSUPPORTED is returned. \r
+\r
+  @param[in]  This                   A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.\r
+  @param[in]  InformationType        A pointer to an EFI_GUID that defines the contents of InformationBlock.\r
+  @param[out] InformationBlock       The service returns a pointer to the buffer with the InformationBlock\r
+                                     structure which contains details about the data specific to InformationType.\r
+  @param[out] InformationBlockSize   The driver returns the size of the InformationBlock in bytes.\r
+\r
+  @retval EFI_SUCCESS                The InformationType information was retrieved.\r
+  @retval EFI_UNSUPPORTED            The InformationType is not known.\r
+  @retval EFI_DEVICE_ERROR           The device reported an error.\r
+  @retval EFI_OUT_OF_RESOURCES       The request could not be completed due to a lack of resources.\r
+  @retval EFI_INVALID_PARAMETER      This is NULL. \r
+  @retval EFI_INVALID_PARAMETER      InformationBlock is NULL. \r
+  @retval EFI_INVALID_PARAMETER      InformationBlockSize is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiAipGetInfo (\r
+  IN  EFI_ADAPTER_INFORMATION_PROTOCOL  *This,\r
+  IN  EFI_GUID                          *InformationType,\r
+  OUT VOID                              **InformationBlock,\r
+  OUT UINTN                             *InformationBlockSize\r
+  )\r
+{\r
+  HSTI_AIP_PRIVATE_DATA  *HstiAip;\r
+\r
+  if ((This == NULL) || (InformationBlock == NULL) || (InformationBlockSize == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (!CompareGuid (InformationType, &gAdapterInfoPlatformSecurityGuid)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  HstiAip = HSTI_AIP_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  *InformationBlock = AllocateCopyPool (HstiAip->HstiSize, HstiAip->Hsti);\r
+  if (*InformationBlock == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  *InformationBlockSize = HstiAip->HstiSize;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Sets state information for an adapter.\r
+\r
+  This function sends information of type InformationType for an adapter.\r
+  If an adapter does not support the requested information type, then EFI_UNSUPPORTED\r
+  is returned.\r
+\r
+  @param[in]  This                   A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.\r
+  @param[in]  InformationType        A pointer to an EFI_GUID that defines the contents of InformationBlock.\r
+  @param[in]  InformationBlock       A pointer to the InformationBlock structure which contains details\r
+                                     about the data specific to InformationType.\r
+  @param[in]  InformationBlockSize   The size of the InformationBlock in bytes.\r
+\r
+  @retval EFI_SUCCESS                The information was received and interpreted successfully.\r
+  @retval EFI_UNSUPPORTED            The InformationType is not known.\r
+  @retval EFI_DEVICE_ERROR           The device reported an error.\r
+  @retval EFI_INVALID_PARAMETER      This is NULL.\r
+  @retval EFI_INVALID_PARAMETER      InformationBlock is NULL.\r
+  @retval EFI_WRITE_PROTECTED        The InformationType cannot be modified using EFI_ADAPTER_INFO_SET_INFO().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiAipSetInfo (\r
+  IN  EFI_ADAPTER_INFORMATION_PROTOCOL  *This,\r
+  IN  EFI_GUID                          *InformationType,\r
+  IN  VOID                              *InformationBlock,\r
+  IN  UINTN                             InformationBlockSize\r
+  )\r
+{\r
+  HSTI_AIP_PRIVATE_DATA  *HstiAip;\r
+  VOID                   *NewHsti;\r
+\r
+  if ((This == NULL) || (InformationBlock == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (!CompareGuid (InformationType, &gAdapterInfoPlatformSecurityGuid)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (!InternalHstiIsValidTable (InformationBlock, InformationBlockSize)) {\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+\r
+  HstiAip = HSTI_AIP_PRIVATE_DATA_FROM_THIS(This);\r
+\r
+  if (InformationBlockSize > HstiAip->HstiMaxSize) {\r
+    NewHsti = AllocateZeroPool (InformationBlockSize);\r
+    if (NewHsti == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    FreePool (HstiAip->Hsti);\r
+    HstiAip->Hsti = NewHsti;\r
+    HstiAip->HstiSize = 0;\r
+    HstiAip->HstiMaxSize = InformationBlockSize;\r
+  }\r
+\r
+  CopyMem (HstiAip->Hsti, InformationBlock, InformationBlockSize);\r
+  HstiAip->HstiSize = InformationBlockSize;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Get a list of supported information types for this instance of the protocol.\r
+\r
+  This function returns a list of InformationType GUIDs that are supported on an\r
+  adapter with this instance of EFI_ADAPTER_INFORMATION_PROTOCOL. The list is returned\r
+  in InfoTypesBuffer, and the number of GUID pointers in InfoTypesBuffer is returned in\r
+  InfoTypesBufferCount.\r
+\r
+  @param[in]  This                  A pointer to the EFI_ADAPTER_INFORMATION_PROTOCOL instance.\r
+  @param[out] InfoTypesBuffer       A pointer to the array of InformationType GUIDs that are supported\r
+                                    by This.\r
+  @param[out] InfoTypesBufferCount  A pointer to the number of GUIDs present in InfoTypesBuffer.\r
+\r
+  @retval EFI_SUCCESS               The list of information type GUIDs that are supported on this adapter was\r
+                                    returned in InfoTypesBuffer. The number of information type GUIDs was\r
+                                    returned in InfoTypesBufferCount.\r
+  @retval EFI_INVALID_PARAMETER     This is NULL.\r
+  @retval EFI_INVALID_PARAMETER     InfoTypesBuffer is NULL.\r
+  @retval EFI_INVALID_PARAMETER     InfoTypesBufferCount is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES      There is not enough pool memory to store the results.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiAipGetSupportedTypes (\r
+  IN  EFI_ADAPTER_INFORMATION_PROTOCOL  *This,\r
+  OUT EFI_GUID                          **InfoTypesBuffer,\r
+  OUT UINTN                             *InfoTypesBufferCount\r
+  )\r
+{\r
+  if ((This == NULL) || (InfoTypesBuffer == NULL) || (InfoTypesBufferCount == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *InfoTypesBuffer = AllocateCopyPool (sizeof(gAdapterInfoPlatformSecurityGuid), &gAdapterInfoPlatformSecurityGuid);\r
+  if (*InfoTypesBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  *InfoTypesBufferCount = 1;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol = {\r
+  HstiAipGetInfo,\r
+  HstiAipSetInfo,\r
+  HstiAipGetSupportedTypes,\r
+};\r
diff --git a/MdePkg/Library/DxeHstiLib/HstiDxe.c b/MdePkg/Library/DxeHstiLib/HstiDxe.c
new file mode 100644 (file)
index 0000000..c7a5769
--- /dev/null
@@ -0,0 +1,609 @@
+/** @file\r
+\r
+  Copyright (c) 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
+  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
+#include "HstiDxe.h"\r
+\r
+/**\r
+  Find HSTI table in AIP protocol, and return the data.\r
+  This API will return the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param HstiData         HSTI data. This buffer is allocated by callee, and it\r
+                          is the responsibility of the caller to free it after\r
+                          using it.\r
+  @param HstiSize         HSTI size\r
+\r
+  @return Aip             The AIP protocol having this HSTI.\r
+  @return NULL            There is not HSTI table with the Role and ImplementationID published in system.\r
+**/\r
+VOID *\r
+InternalHstiFindAip (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID OPTIONAL,\r
+  OUT VOID                    **HstiData OPTIONAL,\r
+  OUT UINTN                   *HstiSize OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL  *Aip;\r
+  UINTN                             NoHandles;\r
+  EFI_HANDLE                        *Handles;\r
+  UINTN                             Index;\r
+  EFI_GUID                          *InfoTypesBuffer;\r
+  UINTN                             InfoTypesBufferCount;\r
+  UINTN                             InfoTypesIndex;\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL  *AipCandidate;\r
+  VOID                              *InformationBlock;\r
+  UINTN                             InformationBlockSize;\r
+  ADAPTER_INFO_PLATFORM_SECURITY    *Hsti;\r
+\r
+  Status = gBS->LocateHandleBuffer (\r
+                  ByProtocol,\r
+                  &gEfiAdapterInformationProtocolGuid,\r
+                  NULL,\r
+                  &NoHandles,\r
+                  &Handles\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  Hsti = NULL;\r
+  Aip = NULL;\r
+  InformationBlock = NULL;\r
+  InformationBlockSize = 0;\r
+  for (Index = 0; Index < NoHandles; Index++) {\r
+    Status = gBS->HandleProtocol (\r
+                    Handles[Index],\r
+                    &gEfiAdapterInformationProtocolGuid,\r
+                    (VOID **)&Aip\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Check AIP\r
+    //\r
+    Status = Aip->GetSupportedTypes (\r
+                    Aip,\r
+                    &InfoTypesBuffer,\r
+                    &InfoTypesBufferCount\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    AipCandidate = NULL;\r
+    for (InfoTypesIndex = 0; InfoTypesIndex < InfoTypesBufferCount; InfoTypesIndex++) {\r
+      if (CompareGuid (&InfoTypesBuffer[InfoTypesIndex], &gAdapterInfoPlatformSecurityGuid)) {\r
+        AipCandidate = Aip;\r
+        break;\r
+      }\r
+    }\r
+    FreePool (InfoTypesBuffer);\r
+\r
+    if (AipCandidate == NULL) {\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Check HSTI Role\r
+    //\r
+    Aip = AipCandidate;\r
+    Status = Aip->GetInformation (\r
+                    Aip,\r
+                    &gAdapterInfoPlatformSecurityGuid,\r
+                    &InformationBlock,\r
+                    &InformationBlockSize\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      continue;\r
+    }\r
+\r
+    Hsti = InformationBlock;\r
+    if ((Hsti->Role == Role) && \r
+        ((ImplementationID == NULL) || (StrCmp (ImplementationID, Hsti->ImplementationID) == 0))) {\r
+      break;\r
+    } else {\r
+      Hsti = NULL;\r
+      FreePool (InformationBlock);\r
+      continue;\r
+    }\r
+  }\r
+  FreePool (Handles);\r
+\r
+  if (Hsti == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  if (HstiData != NULL) {\r
+    *HstiData = InformationBlock;\r
+  }\r
+  if (HstiSize != NULL) {\r
+    *HstiSize = InformationBlockSize;\r
+  }\r
+  return Aip;\r
+}\r
+\r
+/**\r
+  Return if input HSTI data follows HSTI specification.\r
+\r
+  @param HstiData  HSTI data\r
+  @param HstiSize  HSTI size\r
+\r
+  @retval TRUE  HSTI data follows HSTI specification.\r
+  @retval FALSE HSTI data does not follow HSTI specification.\r
+**/\r
+BOOLEAN\r
+InternalHstiIsValidTable (\r
+  IN VOID                     *HstiData,\r
+  IN UINTN                    HstiSize\r
+  )\r
+{\r
+  ADAPTER_INFO_PLATFORM_SECURITY  *Hsti;\r
+  UINTN                           Index;\r
+  CHAR16                          *ErrorString;\r
+  CHAR16                          ErrorChar;\r
+  UINTN                           ErrorStringSize;\r
+  UINTN                           ErrorStringLength;\r
+\r
+  Hsti = HstiData;\r
+\r
+  //\r
+  // basic check for header\r
+  //\r
+  if (HstiData == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "HstiData == NULL\n"));\r
+    return FALSE;\r
+  }\r
+  if (HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) {\r
+    DEBUG ((EFI_D_ERROR, "HstiSize < sizeof(ADAPTER_INFO_PLATFORM_SECURITY)\n"));\r
+    return FALSE;\r
+  }\r
+  if (((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < Hsti->SecurityFeaturesSize) {\r
+    DEBUG ((EFI_D_ERROR, "((HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY)) / 3) < SecurityFeaturesSize\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check Version\r
+  //\r
+  if (Hsti->Version != PLATFORM_SECURITY_VERSION_VNEXTCS) {\r
+    DEBUG ((EFI_D_ERROR, "Version != PLATFORM_SECURITY_VERSION_VNEXTCS\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check Role\r
+  //\r
+  if ((Hsti->Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE) ||\r
+      (Hsti->Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM)) {\r
+    DEBUG ((EFI_D_ERROR, "Role < PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE ||\n"));\r
+    DEBUG ((EFI_D_ERROR, "Role > PLATFORM_SECURITY_ROLE_IMPLEMENTOR_ODM\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Check ImplementationID\r
+  //\r
+  for (Index = 0; Index < sizeof(Hsti->ImplementationID); Index++) {\r
+    if (Hsti->ImplementationID[Index] == 0) {\r
+      break;\r
+    }\r
+  }\r
+  if (Index == sizeof(Hsti->ImplementationID)) {\r
+    DEBUG ((EFI_D_ERROR, "ImplementationID is no NUL CHAR\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  ErrorStringSize = HstiSize - sizeof(ADAPTER_INFO_PLATFORM_SECURITY) - Hsti->SecurityFeaturesSize * 3;\r
+  ErrorString = (CHAR16 *)((UINTN)Hsti + sizeof(ADAPTER_INFO_PLATFORM_SECURITY) - Hsti->SecurityFeaturesSize * 3);\r
+\r
+  //\r
+  // basic check for ErrorString\r
+  //\r
+  if (ErrorStringSize == 0) {\r
+    DEBUG ((EFI_D_ERROR, "ErrorStringSize == 0\n"));\r
+    return FALSE;\r
+  }\r
+  if ((ErrorStringSize & BIT0) != 0) {\r
+    DEBUG ((EFI_D_ERROR, "(ErrorStringSize & BIT0) != 0\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // ErrorString might not be CHAR16 aligned.\r
+  //\r
+  CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar));\r
+  for (ErrorStringLength = 0; (ErrorChar != 0) && (ErrorStringLength < (ErrorStringSize/2)); ErrorStringLength++) {\r
+    ErrorString++;\r
+    CopyMem (&ErrorChar, ErrorString, sizeof(ErrorChar));\r
+  }\r
+\r
+  //\r
+  // check the length of ErrorString\r
+  //\r
+  if (ErrorChar != 0) {\r
+    DEBUG ((EFI_D_ERROR, "ErrorString has no NUL CHAR\n"));\r
+    return FALSE;\r
+  }\r
+  if (ErrorStringLength == (ErrorStringSize/2)) {\r
+    DEBUG ((EFI_D_ERROR, "ErrorString Length incorrect\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+/**\r
+  Publish HSTI table in AIP protocol.\r
+\r
+  One system should have only one PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE.\r
+\r
+  If the Role is NOT PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,\r
+  SecurityFeaturesRequired field will be ignored.\r
+\r
+  @param Hsti      HSTI data\r
+  @param HstiSize  HSTI size\r
+\r
+  @retval EFI_SUCCESS          The HSTI data is published in AIP protocol.\r
+  @retval EFI_ALREADY_STARTED  There is already HSTI table with Role and ImplementationID published in system.\r
+  @retval EFI_VOLUME_CORRUPTED The input HSTI data does not follow HSTI specification.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to publish HSTI data in AIP protocol.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibSetTable (\r
+  IN VOID                     *Hsti,\r
+  IN UINTN                    HstiSize\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_HANDLE                       Handle;\r
+  HSTI_AIP_PRIVATE_DATA            *HstiAip;\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
+  UINT32                           Role;\r
+  CHAR16                           *ImplementationID;\r
+  UINT32                           SecurityFeaturesSize;\r
+  UINT8                            *SecurityFeaturesRequired;\r
+\r
+  if (!InternalHstiIsValidTable (Hsti, HstiSize)) {\r
+    return EFI_VOLUME_CORRUPTED;\r
+  }\r
+\r
+  Role = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->Role;\r
+  ImplementationID = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->ImplementationID;\r
+  Aip = InternalHstiFindAip (Role, ImplementationID, NULL, NULL);\r
+  if (Aip != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  HstiAip = AllocateZeroPool (sizeof(HSTI_AIP_PRIVATE_DATA));\r
+  if (HstiAip == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  HstiAip->Hsti = AllocateCopyPool (HstiSize, Hsti);\r
+  if (HstiAip == NULL) {\r
+    FreePool (HstiAip);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  if (Role != PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE) {\r
+    SecurityFeaturesRequired = (UINT8 *)HstiAip->Hsti + sizeof(ADAPTER_INFO_PLATFORM_SECURITY);\r
+    SecurityFeaturesSize = ((ADAPTER_INFO_PLATFORM_SECURITY *)Hsti)->SecurityFeaturesSize;\r
+    ZeroMem (SecurityFeaturesRequired, SecurityFeaturesSize);\r
+  }\r
+\r
+  HstiAip->Signature = HSTI_AIP_PRIVATE_SIGNATURE;\r
+  CopyMem (&HstiAip->Aip, &mAdapterInformationProtocol, sizeof(EFI_ADAPTER_INFORMATION_PROTOCOL));\r
+  HstiAip->HstiSize = HstiSize;\r
+  HstiAip->HstiMaxSize = HstiSize;\r
+  \r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiAdapterInformationProtocolGuid,\r
+                  &HstiAip->Aip,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (HstiAip->Hsti);\r
+    FreePool (HstiAip);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Search HSTI table in AIP protocol, and return the data.\r
+  This API will return the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param Hsti             HSTI data. This buffer is allocated by callee, and it\r
+                          is the responsibility of the caller to free it after\r
+                          using it.\r
+  @param HstiSize         HSTI size\r
+\r
+  @retval EFI_SUCCESS          The HSTI data in AIP protocol is returned.\r
+  @retval EFI_NOT_FOUND        There is not HSTI table with the Role and ImplementationID published in system.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibGetTable (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID OPTIONAL,\r
+  OUT VOID                    **Hsti,\r
+  OUT UINTN                   *HstiSize\r
+  )\r
+{\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
+\r
+  Aip = InternalHstiFindAip (Role, ImplementationID, Hsti, HstiSize);\r
+  if (Aip == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Record FeaturesVerified in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ByteIndex        Byte index of FeaturesVerified of HSTI data.\r
+  @param BitMask          Bit mask of FeaturesVerified of HSTI data.\r
+  @param Set              TRUE means to set the FeaturesVerified bit.\r
+                          FALSE means to clear the FeaturesVerified bit.\r
+\r
+  @retval EFI_SUCCESS          The FeaturesVerified of HSTI data updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_UNSUPPORTED      The ByteIndex is invalid.\r
+**/\r
+EFI_STATUS\r
+InternalHstiRecordFeaturesVerified (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN UINT32                   ByteIndex,\r
+  IN UINT8                    Bit,\r
+  IN BOOLEAN                  Set\r
+  )\r
+{\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
+  ADAPTER_INFO_PLATFORM_SECURITY   *Hsti;\r
+  UINTN                            HstiSize;\r
+  UINT8                            *SecurityFeaturesVerified;\r
+  EFI_STATUS                       Status;\r
+\r
+  Aip = InternalHstiFindAip (Role, ImplementationID, &Hsti, &HstiSize);\r
+  if (Aip == NULL) {\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  if (ByteIndex >= Hsti->SecurityFeaturesSize) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  SecurityFeaturesVerified = (UINT8 *)((UINTN)Hsti + sizeof(ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 2);\r
+\r
+  if (Set) {\r
+    SecurityFeaturesVerified[ByteIndex] = (UINT8)(SecurityFeaturesVerified[ByteIndex] | (Bit));\r
+  } else {\r
+    SecurityFeaturesVerified[ByteIndex] = (UINT8)(SecurityFeaturesVerified[ByteIndex] & (~Bit));\r
+  }\r
+\r
+  Status = Aip->SetInformation (\r
+                  Aip,\r
+                  &gAdapterInfoPlatformSecurityGuid,\r
+                  Hsti,\r
+                  HstiSize\r
+                  );\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Set FeaturesVerified in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ByteIndex        Byte index of FeaturesVerified of HSTI data.\r
+  @param BitMask          Bit mask of FeaturesVerified of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The FeaturesVerified of HSTI data updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_UNSUPPORTED      The ByteIndex is invalid.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibSetFeaturesVerified (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN UINT32                   ByteIndex,\r
+  IN UINT8                    BitMask\r
+  )\r
+{\r
+  return InternalHstiRecordFeaturesVerified (\r
+           Role,\r
+           ImplementationID,\r
+           ByteIndex,\r
+           BitMask,\r
+           TRUE\r
+           );\r
+}\r
+\r
+/**\r
+  Clear FeaturesVerified in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ByteIndex        Byte index of FeaturesVerified of HSTI data.\r
+  @param BitMask          Bit mask of FeaturesVerified of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The FeaturesVerified of HSTI data updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_UNSUPPORTED      The ByteIndex is invalid.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibClearFeaturesVerified (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN UINT32                   ByteIndex,\r
+  IN UINT8                    BitMask\r
+  )\r
+{\r
+  return InternalHstiRecordFeaturesVerified (\r
+           Role,\r
+           ImplementationID,\r
+           ByteIndex,\r
+           BitMask,\r
+           FALSE\r
+           );\r
+}\r
+\r
+/**\r
+  Record ErrorString in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ErrorString      ErrorString of HSTI data.\r
+  @param Append           TRUE means to append the ErrorString to HSTI table.\r
+                          FALSE means to set the ErrorString in HSTI table.\r
+\r
+  @retval EFI_SUCCESS          The ErrorString of HSTI data is published in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
+**/\r
+EFI_STATUS\r
+InternalHstiRecordErrorString (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN CHAR16                   *ErrorString,\r
+  IN BOOLEAN                  Append\r
+  )\r
+{\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL *Aip;\r
+  ADAPTER_INFO_PLATFORM_SECURITY   *Hsti;\r
+  UINTN                            HstiSize;\r
+  UINTN                            StringSize;\r
+  VOID                             *NewHsti;\r
+  UINTN                            NewHstiSize;\r
+  UINTN                            Offset;\r
+  EFI_STATUS                       Status;\r
+\r
+  Aip = InternalHstiFindAip (Role, ImplementationID, &Hsti, &HstiSize);\r
+  if (Aip == NULL) {\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  if (Append) {\r
+    Offset = HstiSize - sizeof(CHAR16);\r
+  } else {\r
+    Offset = sizeof(ADAPTER_INFO_PLATFORM_SECURITY) + Hsti->SecurityFeaturesSize * 3;\r
+  }\r
+  StringSize = StrSize (ErrorString);\r
+\r
+  NewHstiSize = Offset + StringSize;\r
+  NewHsti = AllocatePool (NewHstiSize);\r
+  if (NewHsti == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  CopyMem (NewHsti, Hsti, Offset);\r
+  CopyMem ((UINT8 *)NewHsti + Offset, ErrorString, StringSize);\r
+\r
+  Status = Aip->SetInformation (\r
+                  Aip,\r
+                  &gAdapterInfoPlatformSecurityGuid,\r
+                  NewHsti,\r
+                  NewHstiSize\r
+                  );\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Append ErrorString in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ErrorString      ErrorString of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The ErrorString of HSTI data is updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibAppendErrorString (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN CHAR16                   *ErrorString\r
+  )\r
+{\r
+  return InternalHstiRecordErrorString (\r
+           Role,\r
+           ImplementationID,\r
+           ErrorString,\r
+           TRUE\r
+           );\r
+}\r
+\r
+/**\r
+  Set a new ErrorString in published HSTI table.\r
+  This API will update the HSTI table with indicated Role and ImplementationID,\r
+  NULL ImplementationID means to find the first HSTI table with indicated Role.\r
+\r
+  @param Role             Role of HSTI data.\r
+  @param ImplementationID ImplementationID of HSTI data.\r
+                          NULL means find the first one match Role.\r
+  @param ErrorString      ErrorString of HSTI data.\r
+\r
+  @retval EFI_SUCCESS          The ErrorString of HSTI data is updated in AIP protocol.\r
+  @retval EFI_NOT_STARTED      There is not HSTI table with the Role and ImplementationID published in system.\r
+  @retval EFI_OUT_OF_RESOURCES There is not enough system resource to update ErrorString.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HstiLibSetErrorString (\r
+  IN UINT32                   Role,\r
+  IN CHAR16                   *ImplementationID, OPTIONAL\r
+  IN CHAR16                   *ErrorString\r
+  )\r
+{\r
+  return InternalHstiRecordErrorString (\r
+           Role,\r
+           ImplementationID,\r
+           ErrorString,\r
+           FALSE\r
+           );\r
+}\r
diff --git a/MdePkg/Library/DxeHstiLib/HstiDxe.h b/MdePkg/Library/DxeHstiLib/HstiDxe.h
new file mode 100644 (file)
index 0000000..aaa4a0c
--- /dev/null
@@ -0,0 +1,65 @@
+/** @file\r
+\r
+  Copyright (c) 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
+  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 _HSTI_DXE_H_\r
+#define _HSTI_DXE_H_\r
+\r
+#include <PiDxe.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <IndustryStandard/Hsti.h>\r
+\r
+#include <Protocol/AdapterInformation.h>\r
+\r
+#define HSTI_AIP_PRIVATE_SIGNATURE  SIGNATURE_32('H', 'S', 'T', 'I')\r
+\r
+typedef struct {\r
+  UINT32                            Signature;\r
+  LIST_ENTRY                        Link;\r
+  EFI_ADAPTER_INFORMATION_PROTOCOL  Aip;\r
+  VOID                              *Hsti;\r
+  UINTN                             HstiSize;\r
+  UINTN                             HstiMaxSize;\r
+} HSTI_AIP_PRIVATE_DATA;\r
+\r
+#define HSTI_AIP_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      HSTI_AIP_PRIVATE_DATA, \\r
+      Aip, \\r
+      HSTI_AIP_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+#define HSTI_DEFAULT_ERROR_STRING_LEN  255\r
+\r
+extern EFI_ADAPTER_INFORMATION_PROTOCOL mAdapterInformationProtocol;\r
+\r
+/**\r
+  Return if input HSTI data follows HSTI specification.\r
+\r
+  @param HstiData  HSTI data\r
+  @param HstiSize  HSTI size\r
+\r
+  @retval TRUE  HSTI data follows HSTI specification.\r
+  @retval FALSE HSTI data does not follow HSTI specification.\r
+**/\r
+BOOLEAN\r
+InternalHstiIsValidTable (\r
+  IN VOID                     *HstiData,\r
+  IN UINTN                    HstiSize\r
+  );\r
+\r
+#endif
\ No newline at end of file
index 1eb4346e1803906c01f897c90c32b1991c039d61..573277d51f07ca407b8648f430a2e58e0dd7202f 100644 (file)
@@ -4,7 +4,7 @@
 # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of\r
 # EFI1.10/UEFI2.4/PI1.3 and some Industry Standards.\r
 #\r
 # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of\r
 # EFI1.10/UEFI2.4/PI1.3 and some Industry Standards.\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available under\r
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available under\r
   ## Include/Guid/VectorHandoffTable.h\r
   gEfiVectorHandoffTableGuid        = { 0x996ec11c, 0x5397, 0x4e73, { 0xb5, 0x8f, 0x82, 0x7e, 0x52, 0x90, 0x6d, 0xef }}\r
 \r
   ## Include/Guid/VectorHandoffTable.h\r
   gEfiVectorHandoffTableGuid        = { 0x996ec11c, 0x5397, 0x4e73, { 0xb5, 0x8f, 0x82, 0x7e, 0x52, 0x90, 0x6d, 0xef }}\r
 \r
+  ## Include/IndustryStandard/Hsti.h\r
+  gAdapterInfoPlatformSecurityGuid  = {0x6be272c7, 0x1320, 0x4ccd, { 0x90, 0x17, 0xd4, 0x61, 0x2c, 0x01, 0x2b, 0x25 }}\r
+\r
 [Guids.IA32, Guids.X64]\r
   ## Include/Guid/Cper.h\r
   gEfiIa32X64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, { 0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }}\r
 [Guids.IA32, Guids.X64]\r
   ## Include/Guid/Cper.h\r
   gEfiIa32X64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, { 0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }}\r
index 14a339cd496f1a6789c1c4b0b243028d074bd637..6e527f4e0da55e08a096acd1c821f56dbc5b507b 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # EFI/PI MdePkg Package\r
 #\r
 ## @file\r
 # EFI/PI MdePkg Package\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 #\r
 #    This program and the accompanying materials\r
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 #\r
 #    This program and the accompanying materials\r
@@ -91,6 +91,7 @@
   MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf\r
   MdePkg/Library/DxeIoLibCpuIo2/DxeIoLibCpuIo2.inf\r
   MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
   MdePkg/Library/DxeSmbusLib/DxeSmbusLib.inf\r
   MdePkg/Library/DxeIoLibCpuIo2/DxeIoLibCpuIo2.inf\r
+  MdePkg/Library/DxeHstiLib/DxeHstiLib.inf\r
 \r
   MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf\r
 \r
 \r
   MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf\r
 \r