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 | * |
| 6 | * Copyright (c) 2020, Linaro Limited |
| 7 | */ |
| 8 | |
| 9 | #if !defined _EFI_TCG2_PROTOCOL_H_ |
| 10 | #define _EFI_TCG2_PROTOCOL_H_ |
| 11 | |
Masahisa Kojima | 70be5a6 | 2021-05-26 12:09:58 +0900 | [diff] [blame] | 12 | #include <efi_api.h> |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 13 | #include <tpm-v2.h> |
| 14 | |
| 15 | #define EFI_TCG2_PROTOCOL_GUID \ |
| 16 | EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \ |
| 17 | 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f) |
| 18 | |
| 19 | /* TPMV2 only */ |
| 20 | #define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002 |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 21 | #define EFI_TCG2_EXTEND_ONLY 0x0000000000000001 |
| 22 | #define PE_COFF_IMAGE 0x0000000000000010 |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 23 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 24 | /* Algorithm Registry */ |
| 25 | #define EFI_TCG2_BOOT_HASH_ALG_SHA1 0x00000001 |
| 26 | #define EFI_TCG2_BOOT_HASH_ALG_SHA256 0x00000002 |
| 27 | #define EFI_TCG2_BOOT_HASH_ALG_SHA384 0x00000004 |
| 28 | #define EFI_TCG2_BOOT_HASH_ALG_SHA512 0x00000008 |
| 29 | #define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x00000010 |
| 30 | |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 31 | #define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1 |
| 32 | |
| 33 | #define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE |
| 34 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 35 | typedef u32 efi_tcg_event_log_bitmap; |
| 36 | typedef u32 efi_tcg_event_log_format; |
| 37 | typedef u32 efi_tcg_event_algorithm_bitmap; |
| 38 | |
| 39 | struct efi_tcg2_version { |
| 40 | u8 major; |
| 41 | u8 minor; |
| 42 | }; |
| 43 | |
| 44 | struct efi_tcg2_event_header { |
| 45 | u32 header_size; |
| 46 | u16 header_version; |
| 47 | u32 pcr_index; |
| 48 | u32 event_type; |
| 49 | } __packed; |
| 50 | |
| 51 | struct efi_tcg2_event { |
| 52 | u32 size; |
| 53 | struct efi_tcg2_event_header header; |
| 54 | u8 event[]; |
| 55 | } __packed; |
| 56 | |
Masahisa Kojima | 70be5a6 | 2021-05-26 12:09:58 +0900 | [diff] [blame] | 57 | struct uefi_image_load_event { |
| 58 | efi_physical_addr_t image_location_in_memory; |
| 59 | u64 image_length_in_memory; |
| 60 | u64 image_link_time_address; |
| 61 | u64 length_of_device_path; |
| 62 | struct efi_device_path device_path[]; |
| 63 | }; |
| 64 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 65 | struct efi_tcg2_boot_service_capability { |
| 66 | u8 size; |
| 67 | struct efi_tcg2_version structure_version; |
| 68 | struct efi_tcg2_version protocol_version; |
| 69 | efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap; |
| 70 | efi_tcg_event_log_bitmap supported_event_logs; |
| 71 | u8 tpm_present_flag; |
| 72 | u16 max_command_size; |
| 73 | u16 max_response_size; |
| 74 | u32 manufacturer_id; |
| 75 | u32 number_of_pcr_banks; |
| 76 | efi_tcg_event_algorithm_bitmap active_pcr_banks; |
| 77 | }; |
| 78 | |
| 79 | #define boot_service_capability_min \ |
| 80 | sizeof(struct efi_tcg2_boot_service_capability) - \ |
| 81 | offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks) |
| 82 | |
Ilias Apalodimas | 967650d | 2020-11-30 11:47:40 +0200 | [diff] [blame] | 83 | #define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03" |
| 84 | #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2 |
| 85 | #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0 |
| 86 | #define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2 |
| 87 | |
| 88 | /** |
| 89 | * struct TCG_EfiSpecIdEventAlgorithmSize |
| 90 | * |
| 91 | * @algorithm_id: algorithm defined in enum tpm2_algorithms |
| 92 | * @digest_size: size of the algorithm |
| 93 | */ |
| 94 | struct tcg_efi_spec_id_event_algorithm_size { |
| 95 | u16 algorithm_id; |
| 96 | u16 digest_size; |
| 97 | } __packed; |
| 98 | |
| 99 | /** |
| 100 | * struct TCG_EfiSpecIDEventStruct |
| 101 | * |
| 102 | * @signature: signature, set to Spec ID Event03 |
| 103 | * @platform_class: class defined in TCG ACPI Specification |
| 104 | * Client Common Header. |
| 105 | * @spec_version_minor: minor version |
| 106 | * @spec_version_major: major version |
| 107 | * @spec_version_errata: major version |
| 108 | * @uintn_size: size of the efi_uintn_t fields used in various |
| 109 | * data structures used in this specification. |
| 110 | * 0x01 indicates u32 and 0x02 indicates u64 |
| 111 | * @number_of_algorithms: hashing algorithms used in this event log |
| 112 | * @digest_sizes: array of number_of_algorithms pairs |
| 113 | * 1st member defines the algorithm id |
| 114 | * 2nd member defines the algorithm size |
| 115 | * @vendor_info_size: size in bytes for vendor specific info |
| 116 | * @vendor_info: vendor specific info |
| 117 | */ |
| 118 | struct tcg_efi_spec_id_event { |
| 119 | u8 signature[16]; |
| 120 | u32 platform_class; |
| 121 | u8 spec_version_minor; |
| 122 | u8 spec_version_major; |
| 123 | u8 spec_errata; |
| 124 | u8 uintn_size; |
| 125 | u32 number_of_algorithms; |
| 126 | struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS]; |
| 127 | u8 vendor_info_size; |
| 128 | /* U-Boot does not provide any vendor info */ |
| 129 | u8 vendor_info[]; |
| 130 | } __packed; |
| 131 | |
| 132 | /** |
| 133 | * struct tdEFI_TCG2_FINAL_EVENTS_TABLE |
| 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 | |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 165 | struct efi_tcg2_protocol { |
| 166 | efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this, |
| 167 | struct efi_tcg2_boot_service_capability *capability); |
| 168 | efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this, |
| 169 | efi_tcg_event_log_format log_format, |
| 170 | u64 *event_log_location, u64 *event_log_last_entry, |
| 171 | bool *event_log_truncated); |
| 172 | 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] | 173 | u64 flags, |
| 174 | efi_physical_addr_t data_to_hash, |
Ilias Apalodimas | 590fef6 | 2020-11-11 11:18:11 +0200 | [diff] [blame] | 175 | u64 data_to_hash_len, |
| 176 | struct efi_tcg2_event *efi_tcg_event); |
| 177 | efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this, |
| 178 | u32 input_parameter_block_size, |
| 179 | u8 *input_parameter_block, |
| 180 | u32 output_parameter_block_size, |
| 181 | u8 *output_parameter_block); |
| 182 | efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 183 | u32 *active_pcr_banks); |
| 184 | efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 185 | u32 active_pcr_banks); |
| 186 | efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this, |
| 187 | u32 *operation_present, |
| 188 | u32 *response); |
| 189 | }; |
| 190 | #endif |