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