1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Defines data structures and APIs that allow an OS to interact with UEFI 4 * firmware to query information about the device 5 * 6 * Copyright (c) 2020, Linaro Limited 7 */ 8 9 #if !defined _EFI_TCG2_PROTOCOL_H_ 10 #define _EFI_TCG2_PROTOCOL_H_ 11 12 #include <tpm-v2.h> 13 14 #define EFI_TCG2_PROTOCOL_GUID \ 15 EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ 16 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) 17 18 /* TPMV2 only */ 19 #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002 20 #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001 21 #define PE_COFF_IMAGE 0x0000000000000010 22 23 /* Algorithm Registry */ 24 #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001 25 #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002 26 #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004 27 #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008 28 #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010 29 30 #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1 31 32 #define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE 33 34 typedef u32 efi_tcg_event_log_bitmap; 35 typedef u32 efi_tcg_event_log_format; 36 typedef u32 efi_tcg_event_algorithm_bitmap; 37 38 struct efi_tcg2_version { 39 u8 major; 40 u8 minor; 41 }; 42 43 struct efi_tcg2_event_header { 44 u32 header_size; 45 u16 header_version; 46 u32 pcr_index; 47 u32 event_type; 48 } __packed; 49 50 struct efi_tcg2_event { 51 u32 size; 52 struct efi_tcg2_event_header header; 53 u8 event[]; 54 } __packed; 55 56 struct efi_tcg2_boot_service_capability { 57 u8 size; 58 struct efi_tcg2_version structure_version; 59 struct efi_tcg2_version protocol_version; 60 efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap; 61 efi_tcg_event_log_bitmap supported_event_logs; 62 u8 tpm_present_flag; 63 u16 max_command_size; 64 u16 max_response_size; 65 u32 manufacturer_id; 66 u32 number_of_pcr_banks; 67 efi_tcg_event_algorithm_bitmap active_pcr_banks; 68 }; 69 70 #define boot_service_capability_min \ 71 sizeof(struct efi_tcg2_boot_service_capability) - \ 72 offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks) 73 74 #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03" 75 #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2 76 #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0 77 #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2 78 79 /** 80 * struct TCG_EfiSpecIdEventAlgorithmSize 81 * 82 * @algorithm_id: algorithm defined in enum tpm2_algorithms 83 * @digest_size: size of the algorithm 84 */ 85 struct tcg_efi_spec_id_event_algorithm_size { 86 u16 algorithm_id; 87 u16 digest_size; 88 } __packed; 89 90 /** 91 * struct TCG_EfiSpecIDEventStruct 92 * 93 * @signature: signature, set to Spec ID Event03 94 * @platform_class: class defined in TCG ACPI Specification 95 * Client Common Header. 96 * @spec_version_minor: minor version 97 * @spec_version_major: major version 98 * @spec_version_errata: major version 99 * @uintn_size: size of the efi_uintn_t fields used in various 100 * data structures used in this specification. 101 * 0x01 indicates u32 and 0x02 indicates u64 102 * @number_of_algorithms: hashing algorithms used in this event log 103 * @digest_sizes: array of number_of_algorithms pairs 104 * 1st member defines the algorithm id 105 * 2nd member defines the algorithm size 106 * @vendor_info_size: size in bytes for vendor specific info 107 * @vendor_info: vendor specific info 108 */ 109 struct tcg_efi_spec_id_event { 110 u8 signature[16]; 111 u32 platform_class; 112 u8 spec_version_minor; 113 u8 spec_version_major; 114 u8 spec_errata; 115 u8 uintn_size; 116 u32 number_of_algorithms; 117 struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS]; 118 u8 vendor_info_size; 119 /* U-Boot does not provide any vendor info */ 120 u8 vendor_info[]; 121 } __packed; 122 123 /** 124 * struct tdEFI_TCG2_FINAL_EVENTS_TABLE 125 * @version: version number for this structure 126 * @number_of_events: number of events recorded after invocation of 127 * GetEventLog() 128 * @event: List of events of type tcg_pcr_event2 129 */ 130 struct efi_tcg2_final_events_table { 131 u64 version; 132 u64 number_of_events; 133 struct tcg_pcr_event2 event[]; 134 }; 135 136 struct efi_tcg2_protocol { 137 efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this, 138 struct efi_tcg2_boot_service_capability *capability); 139 efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this, 140 efi_tcg_event_log_format log_format, 141 u64 *event_log_location, u64 *event_log_last_entry, 142 bool *event_log_truncated); 143 efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this, 144 u64 flags, 145 efi_physical_addr_t data_to_hash, 146 u64 data_to_hash_len, 147 struct efi_tcg2_event *efi_tcg_event); 148 efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this, 149 u32 input_parameter_block_size, 150 u8 *input_parameter_block, 151 u32 output_parameter_block_size, 152 u8 *output_parameter_block); 153 efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this, 154 u32 *active_pcr_banks); 155 efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this, 156 u32 active_pcr_banks); 157 efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this, 158 u32 *operation_present, 159 u32 *response); 160 }; 161 #endif 162