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 | |
| 22 | #define EFI_TCG2_PROTOCOL_GUID \ |
| 23 | EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ |
| 24 | 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) |
| 25 | |
| 26 | /* TPMV2 only */ |
| 27 | #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002 |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 28 | #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001 |
| 29 | #define PE_COFF_IMAGE 0x0000000000000010 |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 30 | |
Masahisa Kojima | b807491 | 2021-09-03 10:55:52 +0900 | [diff] [blame^] | 31 | #define EFI_TCG2_MAX_PCR_INDEX 23 |
| 32 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 33 | /* Algorithm Registry */ |
| 34 | #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001 |
| 35 | #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002 |
| 36 | #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004 |
| 37 | #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008 |
| 38 | #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010 |
| 39 | |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 40 | #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1 |
| 41 | |
| 42 | #define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE |
| 43 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 44 | typedef u32 efi_tcg_event_log_bitmap; |
| 45 | typedef u32 efi_tcg_event_log_format; |
| 46 | typedef u32 efi_tcg_event_algorithm_bitmap; |
| 47 | |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 48 | /** |
| 49 | * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version |
| 50 | * @major: major version |
| 51 | * @minor: minor version |
| 52 | */ |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 53 | struct efi_tcg2_version { |
| 54 | u8 major; |
| 55 | u8 minor; |
| 56 | }; |
| 57 | |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 58 | /** |
| 59 | * struct tdEFI_TCG2_EVENT_HEADER - structure of EFI TCG2 event header |
| 60 | * @header_size: size of the event header |
| 61 | * @header_version: header version |
| 62 | * @pcr_index: index of the PCR that is extended |
| 63 | * @event_type: type of the event that is extended |
| 64 | */ |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 65 | struct efi_tcg2_event_header { |
| 66 | u32 header_size; |
| 67 | u16 header_version; |
| 68 | u32 pcr_index; |
| 69 | u32 event_type; |
| 70 | } __packed; |
| 71 | |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 72 | /** |
| 73 | * struct tdEFI_TCG2_EVENT - structure of EFI TCG2 event |
| 74 | * @size: total size of the event including the size component, the header |
| 75 | * and the event data |
| 76 | * @header: event header |
| 77 | * @event: event to add |
| 78 | */ |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 79 | struct efi_tcg2_event { |
| 80 | u32 size; |
| 81 | struct efi_tcg2_event_header header; |
| 82 | u8 event[]; |
| 83 | } __packed; |
| 84 | |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 85 | /** |
| 86 | * struct tdUEFI_IMAGE_LOAD_EVENT - structure of PE/COFF image measurement |
| 87 | * @image_location_in_memory: image address |
| 88 | * @image_length_in_memory: image size |
| 89 | * @image_link_time_address: image link time address |
| 90 | * @length_of_device_path: devive path size |
| 91 | * @device_path: device path |
| 92 | */ |
Masahisa Kojima | 70be5a6 | 2021-05-26 12:09:58 +0900 | [diff] [blame] | 93 | struct uefi_image_load_event { |
| 94 | efi_physical_addr_t image_location_in_memory; |
| 95 | u64 image_length_in_memory; |
| 96 | u64 image_link_time_address; |
| 97 | u64 length_of_device_path; |
| 98 | struct efi_device_path device_path[]; |
| 99 | }; |
| 100 | |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 101 | /** |
| 102 | * struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY - protocol capability information |
| 103 | * @size: allocated size of the structure |
| 104 | * @structure_version: version of this structure |
| 105 | * @protocol_version: version of the EFI TCG2 protocol. |
| 106 | * @hash_algorithm_bitmap: supported hash algorithms |
| 107 | * @supported_event_logs: bitmap of supported event log formats |
| 108 | * @tpm_present_flag: false = TPM not present |
| 109 | * @max_command_size: max size (in bytes) of a command |
| 110 | * that can be sent to the TPM |
| 111 | * @max_response_size: max size (in bytes) of a response that |
| 112 | * can be provided by the TPM |
| 113 | * @manufacturer_id: 4-byte Vendor ID |
| 114 | * @number_of_pcr_banks: maximum number of PCR banks |
| 115 | * @active_pcr_banks: bitmap of currently active |
| 116 | * PCR banks (hashing algorithms). |
| 117 | */ |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 118 | struct efi_tcg2_boot_service_capability { |
| 119 | u8 size; |
| 120 | struct efi_tcg2_version structure_version; |
| 121 | struct efi_tcg2_version protocol_version; |
| 122 | efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap; |
| 123 | efi_tcg_event_log_bitmap supported_event_logs; |
| 124 | u8 tpm_present_flag; |
| 125 | u16 max_command_size; |
| 126 | u16 max_response_size; |
| 127 | u32 manufacturer_id; |
| 128 | u32 number_of_pcr_banks; |
| 129 | efi_tcg_event_algorithm_bitmap active_pcr_banks; |
| 130 | }; |
| 131 | |
Masahisa Kojima | 6ddffec | 2021-09-03 10:55:51 +0900 | [diff] [blame] | 132 | /* up to and including the vendor ID (manufacturer_id) field */ |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 133 | #define boot_service_capability_min \ |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 134 | offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks) |
| 135 | |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 136 | #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03" |
| 137 | #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2 |
| 138 | #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0 |
| 139 | #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2 |
| 140 | |
| 141 | /** |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 142 | * struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 143 | * |
| 144 | * @algorithm_id: algorithm defined in enum tpm2_algorithms |
| 145 | * @digest_size: size of the algorithm |
| 146 | */ |
| 147 | struct tcg_efi_spec_id_event_algorithm_size { |
| 148 | u16 algorithm_id; |
| 149 | u16 digest_size; |
| 150 | } __packed; |
| 151 | |
| 152 | /** |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 153 | * struct TCG_EfiSpecIDEventStruct - content of the event log header |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 154 | * |
| 155 | * @signature: signature, set to Spec ID Event03 |
| 156 | * @platform_class: class defined in TCG ACPI Specification |
| 157 | * Client Common Header. |
| 158 | * @spec_version_minor: minor version |
| 159 | * @spec_version_major: major version |
| 160 | * @spec_version_errata: major version |
| 161 | * @uintn_size: size of the efi_uintn_t fields used in various |
| 162 | * data structures used in this specification. |
| 163 | * 0x01 indicates u32 and 0x02 indicates u64 |
| 164 | * @number_of_algorithms: hashing algorithms used in this event log |
| 165 | * @digest_sizes: array of number_of_algorithms pairs |
| 166 | * 1st member defines the algorithm id |
| 167 | * 2nd member defines the algorithm size |
| 168 | * @vendor_info_size: size in bytes for vendor specific info |
| 169 | * @vendor_info: vendor specific info |
| 170 | */ |
| 171 | struct tcg_efi_spec_id_event { |
| 172 | u8 signature[16]; |
| 173 | u32 platform_class; |
| 174 | u8 spec_version_minor; |
| 175 | u8 spec_version_major; |
| 176 | u8 spec_errata; |
| 177 | u8 uintn_size; |
| 178 | u32 number_of_algorithms; |
| 179 | struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS]; |
| 180 | u8 vendor_info_size; |
| 181 | /* U-Boot does not provide any vendor info */ |
| 182 | u8 vendor_info[]; |
| 183 | } __packed; |
| 184 | |
| 185 | /** |
Masahisa Kojima | 852c53f | 2021-08-13 16:12:43 +0900 | [diff] [blame] | 186 | * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 187 | * @version: version number for this structure |
| 188 | * @number_of_events: number of events recorded after invocation of |
| 189 | * GetEventLog() |
| 190 | * @event: List of events of type tcg_pcr_event2 |
| 191 | */ |
| 192 | struct efi_tcg2_final_events_table { |
| 193 | u64 version; |
| 194 | u64 number_of_events; |
| 195 | struct tcg_pcr_event2 event[]; |
| 196 | }; |
| 197 | |
Masahisa Kojima | 1d2a656 | 2021-08-13 16:12:39 +0900 | [diff] [blame] | 198 | /** |
| 199 | * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable |
| 200 | * @variable_name: The vendorGUID parameter in the |
| 201 | * GetVariable() API. |
| 202 | * @unicode_name_length: The length in CHAR16 of the Unicode name of |
| 203 | * the variable. |
| 204 | * @variable_data_length: The size of the variable data. |
| 205 | * @unicode_name: The CHAR16 unicode name of the variable |
| 206 | * without NULL-terminator. |
| 207 | * @variable_data: The data parameter of the efi variable |
| 208 | * in the GetVariable() API. |
| 209 | */ |
| 210 | struct efi_tcg2_uefi_variable_data { |
| 211 | efi_guid_t variable_name; |
| 212 | u64 unicode_name_length; |
| 213 | u64 variable_data_length; |
| 214 | u16 unicode_name[1]; |
| 215 | u8 variable_data[1]; |
| 216 | }; |
| 217 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 218 | struct efi_tcg2_protocol { |
| 219 | efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this, |
| 220 | struct efi_tcg2_boot_service_capability *capability); |
| 221 | efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this, |
| 222 | efi_tcg_event_log_format log_format, |
| 223 | u64 *event_log_location, u64 *event_log_last_entry, |
| 224 | bool *event_log_truncated); |
| 225 | 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] | 226 | u64 flags, |
| 227 | efi_physical_addr_t data_to_hash, |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 228 | u64 data_to_hash_len, |
| 229 | struct efi_tcg2_event *efi_tcg_event); |
| 230 | efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this, |
| 231 | u32 input_parameter_block_size, |
| 232 | u8 *input_parameter_block, |
| 233 | u32 output_parameter_block_size, |
| 234 | u8 *output_parameter_block); |
| 235 | efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 236 | u32 *active_pcr_banks); |
| 237 | efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 238 | u32 active_pcr_banks); |
| 239 | efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 240 | u32 *operation_present, |
| 241 | u32 *response); |
| 242 | }; |
| 243 | #endif |