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