1*e960cb4cSWarner Losh /** @file 2*e960cb4cSWarner Losh TCG Service Protocol as defined in TCG_EFI_Protocol_1_22_Final 3*e960cb4cSWarner Losh See http://trustedcomputinggroup.org for the latest specification 4*e960cb4cSWarner Losh 5*e960cb4cSWarner Losh Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> 6*e960cb4cSWarner Losh SPDX-License-Identifier: BSD-2-Clause-Patent 7*e960cb4cSWarner Losh 8*e960cb4cSWarner Losh **/ 9*e960cb4cSWarner Losh 10*e960cb4cSWarner Losh #ifndef _TCG_SERVICE_PROTOCOL_H_ 11*e960cb4cSWarner Losh #define _TCG_SERVICE_PROTOCOL_H_ 12*e960cb4cSWarner Losh 13*e960cb4cSWarner Losh #include <IndustryStandard/UefiTcgPlatform.h> 14*e960cb4cSWarner Losh 15*e960cb4cSWarner Losh #define EFI_TCG_PROTOCOL_GUID \ 16*e960cb4cSWarner Losh {0xf541796d, 0xa62e, 0x4954, { 0xa7, 0x75, 0x95, 0x84, 0xf6, 0x1b, 0x9c, 0xdd } } 17*e960cb4cSWarner Losh 18*e960cb4cSWarner Losh typedef struct _EFI_TCG_PROTOCOL EFI_TCG_PROTOCOL; 19*e960cb4cSWarner Losh 20*e960cb4cSWarner Losh typedef struct { 21*e960cb4cSWarner Losh UINT8 Major; 22*e960cb4cSWarner Losh UINT8 Minor; 23*e960cb4cSWarner Losh UINT8 RevMajor; 24*e960cb4cSWarner Losh UINT8 RevMinor; 25*e960cb4cSWarner Losh } TCG_VERSION; 26*e960cb4cSWarner Losh 27*e960cb4cSWarner Losh typedef struct _TCG_EFI_BOOT_SERVICE_CAPABILITY { 28*e960cb4cSWarner Losh UINT8 Size; /// Size of this structure. 29*e960cb4cSWarner Losh TCG_VERSION StructureVersion; 30*e960cb4cSWarner Losh TCG_VERSION ProtocolSpecVersion; 31*e960cb4cSWarner Losh UINT8 HashAlgorithmBitmap; /// Hash algorithms . 32*e960cb4cSWarner Losh /// This protocol is capable of : 01=SHA-1. 33*e960cb4cSWarner Losh BOOLEAN TPMPresentFlag; /// 00h = TPM not present. 34*e960cb4cSWarner Losh BOOLEAN TPMDeactivatedFlag; /// 01h = TPM currently deactivated. 35*e960cb4cSWarner Losh } TCG_EFI_BOOT_SERVICE_CAPABILITY; 36*e960cb4cSWarner Losh 37*e960cb4cSWarner Losh typedef UINT32 TCG_ALGORITHM_ID; 38*e960cb4cSWarner Losh 39*e960cb4cSWarner Losh /** 40*e960cb4cSWarner Losh This service provides EFI protocol capability information, state information 41*e960cb4cSWarner Losh about the TPM, and Event Log state information. 42*e960cb4cSWarner Losh 43*e960cb4cSWarner Losh @param This Indicates the calling context 44*e960cb4cSWarner Losh @param ProtocolCapability The callee allocates memory for a TCG_BOOT_SERVICE_CAPABILITY 45*e960cb4cSWarner Losh structure and fills in the fields with the EFI protocol 46*e960cb4cSWarner Losh capability information and the current TPM state information. 47*e960cb4cSWarner Losh @param TCGFeatureFlags This is a pointer to the feature flags. No feature 48*e960cb4cSWarner Losh flags are currently defined so this parameter 49*e960cb4cSWarner Losh MUST be set to 0. However, in the future, 50*e960cb4cSWarner Losh feature flags may be defined that, for example, 51*e960cb4cSWarner Losh enable hash algorithm agility. 52*e960cb4cSWarner Losh @param EventLogLocation This is a pointer to the address of the event log in memory. 53*e960cb4cSWarner Losh @param EventLogLastEntry If the Event Log contains more than one entry, 54*e960cb4cSWarner Losh this is a pointer to the address of the start of 55*e960cb4cSWarner Losh the last entry in the event log in memory. 56*e960cb4cSWarner Losh 57*e960cb4cSWarner Losh @retval EFI_SUCCESS The operation completed successfully. 58*e960cb4cSWarner Losh @retval EFI_INVALID_PARAMETER ProtocolCapability does not match TCG capability. 59*e960cb4cSWarner Losh **/ 60*e960cb4cSWarner Losh typedef 61*e960cb4cSWarner Losh EFI_STATUS 62*e960cb4cSWarner Losh (EFIAPI *EFI_TCG_STATUS_CHECK)( 63*e960cb4cSWarner Losh IN EFI_TCG_PROTOCOL *This, 64*e960cb4cSWarner Losh OUT TCG_EFI_BOOT_SERVICE_CAPABILITY 65*e960cb4cSWarner Losh *ProtocolCapability, 66*e960cb4cSWarner Losh OUT UINT32 *TCGFeatureFlags, 67*e960cb4cSWarner Losh OUT EFI_PHYSICAL_ADDRESS *EventLogLocation, 68*e960cb4cSWarner Losh OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry 69*e960cb4cSWarner Losh ); 70*e960cb4cSWarner Losh 71*e960cb4cSWarner Losh /** 72*e960cb4cSWarner Losh This service abstracts the capability to do a hash operation on a data buffer. 73*e960cb4cSWarner Losh 74*e960cb4cSWarner Losh @param This Indicates the calling context. 75*e960cb4cSWarner Losh @param HashData The pointer to the data buffer to be hashed. 76*e960cb4cSWarner Losh @param HashDataLen The length of the data buffer to be hashed. 77*e960cb4cSWarner Losh @param AlgorithmId Identification of the Algorithm to use for the hashing operation. 78*e960cb4cSWarner Losh @param HashedDataLen Resultant length of the hashed data. 79*e960cb4cSWarner Losh @param HashedDataResult Resultant buffer of the hashed data. 80*e960cb4cSWarner Losh 81*e960cb4cSWarner Losh @retval EFI_SUCCESS The operation completed successfully. 82*e960cb4cSWarner Losh @retval EFI_INVALID_PARAMETER HashDataLen is NULL. 83*e960cb4cSWarner Losh @retval EFI_INVALID_PARAMETER HashDataLenResult is NULL. 84*e960cb4cSWarner Losh @retval EFI_OUT_OF_RESOURCES Cannot allocate buffer of size *HashedDataLen. 85*e960cb4cSWarner Losh @retval EFI_UNSUPPORTED AlgorithmId not supported. 86*e960cb4cSWarner Losh @retval EFI_BUFFER_TOO_SMALL *HashedDataLen < sizeof (TCG_DIGEST). 87*e960cb4cSWarner Losh **/ 88*e960cb4cSWarner Losh typedef 89*e960cb4cSWarner Losh EFI_STATUS 90*e960cb4cSWarner Losh (EFIAPI *EFI_TCG_HASH_ALL)( 91*e960cb4cSWarner Losh IN EFI_TCG_PROTOCOL *This, 92*e960cb4cSWarner Losh IN UINT8 *HashData, 93*e960cb4cSWarner Losh IN UINT64 HashDataLen, 94*e960cb4cSWarner Losh IN TCG_ALGORITHM_ID AlgorithmId, 95*e960cb4cSWarner Losh IN OUT UINT64 *HashedDataLen, 96*e960cb4cSWarner Losh IN OUT UINT8 **HashedDataResult 97*e960cb4cSWarner Losh ); 98*e960cb4cSWarner Losh 99*e960cb4cSWarner Losh /** 100*e960cb4cSWarner Losh This service abstracts the capability to add an entry to the Event Log. 101*e960cb4cSWarner Losh 102*e960cb4cSWarner Losh @param This Indicates the calling context 103*e960cb4cSWarner Losh @param TCGLogData The pointer to the start of the data buffer containing 104*e960cb4cSWarner Losh the TCG_PCR_EVENT data structure. All fields in 105*e960cb4cSWarner Losh this structure are properly filled by the caller. 106*e960cb4cSWarner Losh @param EventNumber The event number of the event just logged. 107*e960cb4cSWarner Losh @param Flags Indicates additional flags. Only one flag has been 108*e960cb4cSWarner Losh defined at this time, which is 0x01 and means the 109*e960cb4cSWarner Losh extend operation should not be performed. All 110*e960cb4cSWarner Losh other bits are reserved. 111*e960cb4cSWarner Losh 112*e960cb4cSWarner Losh @retval EFI_SUCCESS The operation completed successfully. 113*e960cb4cSWarner Losh @retval EFI_OUT_OF_RESOURCES Insufficient memory in the event log to complete this action. 114*e960cb4cSWarner Losh **/ 115*e960cb4cSWarner Losh typedef 116*e960cb4cSWarner Losh EFI_STATUS 117*e960cb4cSWarner Losh (EFIAPI *EFI_TCG_LOG_EVENT)( 118*e960cb4cSWarner Losh IN EFI_TCG_PROTOCOL *This, 119*e960cb4cSWarner Losh IN TCG_PCR_EVENT *TCGLogData, 120*e960cb4cSWarner Losh IN OUT UINT32 *EventNumber, 121*e960cb4cSWarner Losh IN UINT32 Flags 122*e960cb4cSWarner Losh ); 123*e960cb4cSWarner Losh 124*e960cb4cSWarner Losh /** 125*e960cb4cSWarner Losh This service is a proxy for commands to the TPM. 126*e960cb4cSWarner Losh 127*e960cb4cSWarner Losh @param This Indicates the calling context. 128*e960cb4cSWarner Losh @param TpmInputParameterBlockSize Size of the TPM input parameter block. 129*e960cb4cSWarner Losh @param TpmInputParameterBlock The pointer to the TPM input parameter block. 130*e960cb4cSWarner Losh @param TpmOutputParameterBlockSize Size of the TPM output parameter block. 131*e960cb4cSWarner Losh @param TpmOutputParameterBlock The pointer to the TPM output parameter block. 132*e960cb4cSWarner Losh 133*e960cb4cSWarner Losh @retval EFI_SUCCESS The operation completed successfully. 134*e960cb4cSWarner Losh @retval EFI_INVALID_PARAMETER Invalid ordinal. 135*e960cb4cSWarner Losh @retval EFI_UNSUPPORTED Current Task Priority Level >= EFI_TPL_CALLBACK. 136*e960cb4cSWarner Losh @retval EFI_TIMEOUT The TIS timed-out. 137*e960cb4cSWarner Losh **/ 138*e960cb4cSWarner Losh typedef 139*e960cb4cSWarner Losh EFI_STATUS 140*e960cb4cSWarner Losh (EFIAPI *EFI_TCG_PASS_THROUGH_TO_TPM)( 141*e960cb4cSWarner Losh IN EFI_TCG_PROTOCOL *This, 142*e960cb4cSWarner Losh IN UINT32 TpmInputParameterBlockSize, 143*e960cb4cSWarner Losh IN UINT8 *TpmInputParameterBlock, 144*e960cb4cSWarner Losh IN UINT32 TpmOutputParameterBlockSize, 145*e960cb4cSWarner Losh IN UINT8 *TpmOutputParameterBlock 146*e960cb4cSWarner Losh ); 147*e960cb4cSWarner Losh 148*e960cb4cSWarner Losh /** 149*e960cb4cSWarner Losh This service abstracts the capability to do a hash operation on a data buffer, extend a specific TPM PCR with the hash result, and add an entry to the Event Log 150*e960cb4cSWarner Losh 151*e960cb4cSWarner Losh @param This Indicates the calling context 152*e960cb4cSWarner Losh @param HashData The physical address of the start of the data buffer 153*e960cb4cSWarner Losh to be hashed, extended, and logged. 154*e960cb4cSWarner Losh @param HashDataLen The length, in bytes, of the buffer referenced by HashData 155*e960cb4cSWarner Losh @param AlgorithmId Identification of the Algorithm to use for the hashing operation 156*e960cb4cSWarner Losh @param TCGLogData The physical address of the start of the data 157*e960cb4cSWarner Losh buffer containing the TCG_PCR_EVENT data structure. 158*e960cb4cSWarner Losh @param EventNumber The event number of the event just logged. 159*e960cb4cSWarner Losh @param EventLogLastEntry The physical address of the first byte of the entry 160*e960cb4cSWarner Losh just placed in the Event Log. If the Event Log was 161*e960cb4cSWarner Losh empty when this function was called then this physical 162*e960cb4cSWarner Losh address will be the same as the physical address of 163*e960cb4cSWarner Losh the start of the Event Log. 164*e960cb4cSWarner Losh 165*e960cb4cSWarner Losh @retval EFI_SUCCESS The operation completed successfully. 166*e960cb4cSWarner Losh @retval EFI_UNSUPPORTED AlgorithmId != TPM_ALG_SHA. 167*e960cb4cSWarner Losh @retval EFI_UNSUPPORTED Current TPL >= EFI_TPL_CALLBACK. 168*e960cb4cSWarner Losh @retval EFI_DEVICE_ERROR The command was unsuccessful. 169*e960cb4cSWarner Losh **/ 170*e960cb4cSWarner Losh typedef 171*e960cb4cSWarner Losh EFI_STATUS 172*e960cb4cSWarner Losh (EFIAPI *EFI_TCG_HASH_LOG_EXTEND_EVENT)( 173*e960cb4cSWarner Losh IN EFI_TCG_PROTOCOL *This, 174*e960cb4cSWarner Losh IN EFI_PHYSICAL_ADDRESS HashData, 175*e960cb4cSWarner Losh IN UINT64 HashDataLen, 176*e960cb4cSWarner Losh IN TCG_ALGORITHM_ID AlgorithmId, 177*e960cb4cSWarner Losh IN OUT TCG_PCR_EVENT *TCGLogData, 178*e960cb4cSWarner Losh IN OUT UINT32 *EventNumber, 179*e960cb4cSWarner Losh OUT EFI_PHYSICAL_ADDRESS *EventLogLastEntry 180*e960cb4cSWarner Losh ); 181*e960cb4cSWarner Losh 182*e960cb4cSWarner Losh /// 183*e960cb4cSWarner Losh /// The EFI_TCG Protocol abstracts TCG activity. 184*e960cb4cSWarner Losh /// 185*e960cb4cSWarner Losh struct _EFI_TCG_PROTOCOL { 186*e960cb4cSWarner Losh EFI_TCG_STATUS_CHECK StatusCheck; 187*e960cb4cSWarner Losh EFI_TCG_HASH_ALL HashAll; 188*e960cb4cSWarner Losh EFI_TCG_LOG_EVENT LogEvent; 189*e960cb4cSWarner Losh EFI_TCG_PASS_THROUGH_TO_TPM PassThroughToTpm; 190*e960cb4cSWarner Losh EFI_TCG_HASH_LOG_EXTEND_EVENT HashLogExtendEvent; 191*e960cb4cSWarner Losh }; 192*e960cb4cSWarner Losh 193*e960cb4cSWarner Losh extern EFI_GUID gEfiTcgProtocolGuid; 194*e960cb4cSWarner Losh 195*e960cb4cSWarner Losh #endif 196