1 /** @file
2   This library is used by other modules to measure Firmware to TPM.
3 
4 Copyright (c) 2020, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _TCG_EVENTLOGRECORD_LIB_H_
10 #define _TCG_EVENTLOGRECORD_LIB_H_
11 
12 #include <Uefi.h>
13 
14 #pragma pack (1)
15 
16 #define PLATFORM_FIRMWARE_BLOB_DESC "Fv(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)"
17 typedef struct {
18   UINT8                             BlobDescriptionSize;
19   UINT8                             BlobDescription[sizeof(PLATFORM_FIRMWARE_BLOB_DESC)];
20   EFI_PHYSICAL_ADDRESS              BlobBase;
21   UINT64                            BlobLength;
22 } PLATFORM_FIRMWARE_BLOB2_STRUCT;
23 
24 #define HANDOFF_TABLE_POINTER_DESC  "1234567890ABCDEF"
25 typedef struct {
26   UINT8                             TableDescriptionSize;
27   UINT8                             TableDescription[sizeof(HANDOFF_TABLE_POINTER_DESC)];
28   UINT64                            NumberOfTables;
29   EFI_CONFIGURATION_TABLE           TableEntry[1];
30 } HANDOFF_TABLE_POINTERS2_STRUCT;
31 
32 #pragma pack ()
33 
34 /**
35   Get the FvName from the FV header.
36 
37   Causion: The FV is untrusted input.
38 
39   @param[in]  FvBase            Base address of FV image.
40   @param[in]  FvLength          Length of FV image.
41 
42   @return FvName pointer
43   @retval NULL   FvName is NOT found
44 **/
45 VOID *
46 TpmMeasurementGetFvName (
47   IN EFI_PHYSICAL_ADDRESS           FvBase,
48   IN UINT64                         FvLength
49   );
50 
51 /**
52   Measure a FirmwareBlob.
53 
54   @param[in]  PcrIndex                PCR Index.
55   @param[in]  Description             Description for this FirmwareBlob.
56   @param[in]  FirmwareBlobBase        Base address of this FirmwareBlob.
57   @param[in]  FirmwareBlobLength      Size in bytes of this FirmwareBlob.
58 
59   @retval EFI_SUCCESS           Operation completed successfully.
60   @retval EFI_UNSUPPORTED       TPM device not available.
61   @retval EFI_OUT_OF_RESOURCES  Out of memory.
62   @retval EFI_DEVICE_ERROR      The operation was unsuccessful.
63 */
64 EFI_STATUS
65 EFIAPI
66 MeasureFirmwareBlob (
67   IN UINT32                         PcrIndex,
68   IN CHAR8                          *Description OPTIONAL,
69   IN EFI_PHYSICAL_ADDRESS           FirmwareBlobBase,
70   IN UINT64                         FirmwareBlobLength
71   );
72 
73 /**
74   Measure a HandoffTable.
75 
76   @param[in]  PcrIndex                PcrIndex of the measurement.
77   @param[in]  Description             Description for this HandoffTable.
78   @param[in]  TableGuid               GUID of this HandoffTable.
79   @param[in]  TableAddress            Base address of this HandoffTable.
80   @param[in]  TableLength             Size in bytes of this HandoffTable.
81 
82   @retval EFI_SUCCESS           Operation completed successfully.
83   @retval EFI_UNSUPPORTED       TPM device not available.
84   @retval EFI_OUT_OF_RESOURCES  Out of memory.
85   @retval EFI_DEVICE_ERROR      The operation was unsuccessful.
86 */
87 EFI_STATUS
88 EFIAPI
89 MeasureHandoffTable (
90   IN UINT32                         PcrIndex,
91   IN CHAR8                          *Description OPTIONAL,
92   IN EFI_GUID                       *TableGuid,
93   IN VOID                           *TableAddress,
94   IN UINTN                          TableLength
95   );
96 
97 #endif
98