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