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 * This file refers the following TCG specification. 7 * - TCG PC Client Platform Firmware Profile Specification 8 * https://trustedcomputinggroup.org/resource/pc-client-specific-platform-firmware-profile-specification/ 9 * 10 * - TCG EFI Protocol Specification 11 * https://trustedcomputinggroup.org/resource/tcg-efi-protocol-specification/ 12 * 13 * Copyright (c) 2020, Linaro Limited 14 */ 15 16 #if !defined _EFI_TCG2_PROTOCOL_H_ 17 #define _EFI_TCG2_PROTOCOL_H_ 18 19 #include <efi_api.h> 20 #include <part_efi.h> 21 #include <tpm-v2.h> 22 #include <tpm_tcg2.h> 23 24 /* TPMV2 only */ 25 #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002 26 #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001 27 #define PE_COFF_IMAGE 0x0000000000000010 28 29 #define EFI_TCG2_MAX_PCR_INDEX 23 30 #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1 31 32 typedef u32 efi_tcg_event_log_bitmap; 33 typedef u32 efi_tcg_event_log_format; 34 typedef u32 efi_tcg_event_algorithm_bitmap; 35 36 /** 37 * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version 38 * @major: major version 39 * @minor: minor version 40 */ 41 struct efi_tcg2_version { 42 u8 major; 43 u8 minor; 44 }; 45 46 /** 47 * struct tdEFI_TCG2_EVENT_HEADER - structure of EFI TCG2 event header 48 * @header_size: size of the event header 49 * @header_version: header version 50 * @pcr_index: index of the PCR that is extended 51 * @event_type: type of the event that is extended 52 */ 53 struct efi_tcg2_event_header { 54 u32 header_size; 55 u16 header_version; 56 u32 pcr_index; 57 u32 event_type; 58 } __packed; 59 60 /** 61 * struct tdEFI_TCG2_EVENT - structure of EFI TCG2 event 62 * @size: total size of the event including the size component, the header 63 * and the event data 64 * @header: event header 65 * @event: event to add 66 */ 67 struct efi_tcg2_event { 68 u32 size; 69 struct efi_tcg2_event_header header; 70 u8 event[]; 71 } __packed; 72 73 /** 74 * struct tdUEFI_IMAGE_LOAD_EVENT - structure of PE/COFF image measurement 75 * @image_location_in_memory: image address 76 * @image_length_in_memory: image size 77 * @image_link_time_address: image link time address 78 * @length_of_device_path: devive path size 79 * @device_path: device path 80 */ 81 struct uefi_image_load_event { 82 efi_physical_addr_t image_location_in_memory; 83 u64 image_length_in_memory; 84 u64 image_link_time_address; 85 u64 length_of_device_path; 86 struct efi_device_path device_path[]; 87 }; 88 89 /** 90 * struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY - protocol capability information 91 * @size: allocated size of the structure 92 * @structure_version: version of this structure 93 * @protocol_version: version of the EFI TCG2 protocol. 94 * @hash_algorithm_bitmap: supported hash algorithms 95 * @supported_event_logs: bitmap of supported event log formats 96 * @tpm_present_flag: false = TPM not present 97 * @max_command_size: max size (in bytes) of a command 98 * that can be sent to the TPM 99 * @max_response_size: max size (in bytes) of a response that 100 * can be provided by the TPM 101 * @manufacturer_id: 4-byte Vendor ID 102 * @number_of_pcr_banks: maximum number of PCR banks 103 * @active_pcr_banks: bitmap of currently active 104 * PCR banks (hashing algorithms). 105 */ 106 struct efi_tcg2_boot_service_capability { 107 u8 size; 108 struct efi_tcg2_version structure_version; 109 struct efi_tcg2_version protocol_version; 110 efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap; 111 efi_tcg_event_log_bitmap supported_event_logs; 112 u8 tpm_present_flag; 113 u16 max_command_size; 114 u16 max_response_size; 115 u32 manufacturer_id; 116 u32 number_of_pcr_banks; 117 efi_tcg_event_algorithm_bitmap active_pcr_banks; 118 }; 119 120 /* up to and including the vendor ID (manufacturer_id) field */ 121 #define BOOT_SERVICE_CAPABILITY_MIN \ 122 offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks) 123 124 /** 125 * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log 126 * @version: version number for this structure 127 * @number_of_events: number of events recorded after invocation of 128 * GetEventLog() 129 * @event: List of events of type tcg_pcr_event2 130 */ 131 struct efi_tcg2_final_events_table { 132 u64 version; 133 u64 number_of_events; 134 struct tcg_pcr_event2 event[]; 135 }; 136 137 /** 138 * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable 139 * @variable_name: The vendorGUID parameter in the 140 * GetVariable() API. 141 * @unicode_name_length: The length in CHAR16 of the Unicode name of 142 * the variable. 143 * @variable_data_length: The size of the variable data. 144 * @unicode_name: The CHAR16 unicode name of the variable 145 * without NULL-terminator followed by data. 146 */ 147 struct efi_tcg2_uefi_variable_data { 148 efi_guid_t variable_name; 149 u64 unicode_name_length; 150 u64 variable_data_length; 151 u16 unicode_name[]; 152 // u8 variable_data[]; 153 }; 154 155 /** 156 * struct tdUEFI_HANDOFF_TABLE_POINTERS2 - event log structure of SMBOIS tables 157 * @table_description_size: size of table description 158 * @table_description: table description 159 * @number_of_tables: number of uefi configuration table 160 * @table_entry: uefi configuration table entry 161 */ 162 #define SMBIOS_HANDOFF_TABLE_DESC "SmbiosTable" 163 struct smbios_handoff_table_pointers2 { 164 u8 table_description_size; 165 u8 table_description[sizeof(SMBIOS_HANDOFF_TABLE_DESC)]; 166 u64 number_of_tables; 167 struct efi_configuration_table table_entry[]; 168 } __packed; 169 170 /** 171 * struct tdUEFI_GPT_DATA - event log structure of industry standard tables 172 * @uefi_partition_header: gpt partition header 173 * @number_of_partitions: the number of partition 174 * @partitions: partition entries 175 */ 176 struct efi_gpt_data { 177 gpt_header uefi_partition_header; 178 u64 number_of_partitions; 179 gpt_entry partitions[]; 180 } __packed; 181 182 /** 183 * struct tdUEFI_PLATFORM_FIRMWARE_BLOB2 184 * @blob_description_size: Byte size of @data 185 * @data: Description data 186 */ 187 struct uefi_platform_firmware_blob2 { 188 u8 blob_description_size; 189 u8 data[]; 190 } __packed; 191 192 struct efi_tcg2_protocol { 193 efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this, 194 struct efi_tcg2_boot_service_capability *capability); 195 efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this, 196 efi_tcg_event_log_format log_format, 197 u64 *event_log_location, u64 *event_log_last_entry, 198 bool *event_log_truncated); 199 efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this, 200 u64 flags, 201 efi_physical_addr_t data_to_hash, 202 u64 data_to_hash_len, 203 struct efi_tcg2_event *efi_tcg_event); 204 efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this, 205 u32 input_parameter_block_size, 206 u8 *input_parameter_block, 207 u32 output_parameter_block_size, 208 u8 *output_parameter_block); 209 efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this, 210 u32 *active_pcr_banks); 211 efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this, 212 u32 active_pcr_banks); 213 efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this, 214 u32 *operation_present, 215 u32 *response); 216 }; 217 #endif 218