blob: 874306dc112b0ec5e7137f658fee8e0222d1ffd5 [file] [log] [blame]
Ilias Apalodimasc1c02102020-11-11 11:18:11 +02001/* 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 Kojima7685d172021-08-13 16:12:43 +09006 * 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 Apalodimasc1c02102020-11-11 11:18:11 +020013 * Copyright (c) 2020, Linaro Limited
14 */
15
16#if !defined _EFI_TCG2_PROTOCOL_H_
17#define _EFI_TCG2_PROTOCOL_H_
18
Masahisa Kojima163a0d72021-05-26 12:09:58 +090019#include <efi_api.h>
Ilias Apalodimasc1c02102020-11-11 11:18:11 +020020#include <tpm-v2.h>
21
Ilias Apalodimasc1c02102020-11-11 11:18:11 +020022/* TPMV2 only */
23#define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +020024#define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
25#define PE_COFF_IMAGE 0x0000000000000010
Ilias Apalodimasc1c02102020-11-11 11:18:11 +020026
Masahisa Kojima538c0f22021-09-03 10:55:52 +090027#define EFI_TCG2_MAX_PCR_INDEX 23
28
Ilias Apalodimasc1c02102020-11-11 11:18:11 +020029/* 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 Apalodimasc8d0fd52020-11-30 11:47:40 +020036#define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
37
38#define TPM2_EVENT_LOG_SIZE CONFIG_EFI_TCG2_PROTOCOL_EVENTLOG_SIZE
39
Ilias Apalodimasc1c02102020-11-11 11:18:11 +020040typedef u32 efi_tcg_event_log_bitmap;
41typedef u32 efi_tcg_event_log_format;
42typedef u32 efi_tcg_event_algorithm_bitmap;
43
Masahisa Kojima7685d172021-08-13 16:12:43 +090044/**
45 * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version
46 * @major: major version
47 * @minor: minor version
48 */
Ilias Apalodimasc1c02102020-11-11 11:18:11 +020049struct efi_tcg2_version {
50 u8 major;
51 u8 minor;
52};
53
Masahisa Kojima7685d172021-08-13 16:12:43 +090054/**
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 Apalodimasc1c02102020-11-11 11:18:11 +020061struct efi_tcg2_event_header {
62 u32 header_size;
63 u16 header_version;
64 u32 pcr_index;
65 u32 event_type;
66} __packed;
67
Masahisa Kojima7685d172021-08-13 16:12:43 +090068/**
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 Apalodimasc1c02102020-11-11 11:18:11 +020075struct efi_tcg2_event {
76 u32 size;
77 struct efi_tcg2_event_header header;
78 u8 event[];
79} __packed;
80
Masahisa Kojima7685d172021-08-13 16:12:43 +090081/**
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 Kojima163a0d72021-05-26 12:09:58 +090089struct 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 Kojima7685d172021-08-13 16:12:43 +090097/**
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 Apalodimasc1c02102020-11-11 11:18:11 +0200114struct 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 Kojimadb3ed2c2021-09-03 10:55:51 +0900128/* up to and including the vendor ID (manufacturer_id) field */
Masahisa Kojimabad49da2021-09-06 12:04:12 +0900129#define BOOT_SERVICE_CAPABILITY_MIN \
Ilias Apalodimasc1c02102020-11-11 11:18:11 +0200130 offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
131
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200132#define TCG_EFI_SPEC_ID_EVENT_SIGNATURE_03 "Spec ID Event03"
133#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MAJOR_TPM2 2
134#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_MINOR_TPM2 0
135#define TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2 2
136
137/**
Masahisa Kojima7685d172021-08-13 16:12:43 +0900138 * struct TCG_EfiSpecIdEventAlgorithmSize - hashing algorithm information
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200139 *
140 * @algorithm_id: algorithm defined in enum tpm2_algorithms
141 * @digest_size: size of the algorithm
142 */
143struct tcg_efi_spec_id_event_algorithm_size {
144 u16 algorithm_id;
145 u16 digest_size;
146} __packed;
147
148/**
Masahisa Kojima7685d172021-08-13 16:12:43 +0900149 * struct TCG_EfiSpecIDEventStruct - content of the event log header
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200150 *
151 * @signature: signature, set to Spec ID Event03
152 * @platform_class: class defined in TCG ACPI Specification
153 * Client Common Header.
154 * @spec_version_minor: minor version
155 * @spec_version_major: major version
156 * @spec_version_errata: major version
157 * @uintn_size: size of the efi_uintn_t fields used in various
158 * data structures used in this specification.
159 * 0x01 indicates u32 and 0x02 indicates u64
160 * @number_of_algorithms: hashing algorithms used in this event log
161 * @digest_sizes: array of number_of_algorithms pairs
162 * 1st member defines the algorithm id
163 * 2nd member defines the algorithm size
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200164 */
165struct tcg_efi_spec_id_event {
166 u8 signature[16];
167 u32 platform_class;
168 u8 spec_version_minor;
169 u8 spec_version_major;
170 u8 spec_errata;
171 u8 uintn_size;
172 u32 number_of_algorithms;
Ruchika Gupta346cee32021-09-14 12:14:31 +0530173 struct tcg_efi_spec_id_event_algorithm_size digest_sizes[];
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200174} __packed;
175
176/**
Masahisa Kojima7685d172021-08-13 16:12:43 +0900177 * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200178 * @version: version number for this structure
179 * @number_of_events: number of events recorded after invocation of
180 * GetEventLog()
181 * @event: List of events of type tcg_pcr_event2
182 */
183struct efi_tcg2_final_events_table {
184 u64 version;
185 u64 number_of_events;
186 struct tcg_pcr_event2 event[];
187};
188
Masahisa Kojimacfbcf052021-08-13 16:12:39 +0900189/**
190 * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable
191 * @variable_name: The vendorGUID parameter in the
192 * GetVariable() API.
193 * @unicode_name_length: The length in CHAR16 of the Unicode name of
194 * the variable.
195 * @variable_data_length: The size of the variable data.
196 * @unicode_name: The CHAR16 unicode name of the variable
197 * without NULL-terminator.
198 * @variable_data: The data parameter of the efi variable
199 * in the GetVariable() API.
200 */
201struct efi_tcg2_uefi_variable_data {
202 efi_guid_t variable_name;
203 u64 unicode_name_length;
204 u64 variable_data_length;
205 u16 unicode_name[1];
206 u8 variable_data[1];
207};
208
Masahisa Kojima3d49ee82021-10-26 17:27:24 +0900209/**
210 * struct tdUEFI_HANDOFF_TABLE_POINTERS2 - event log structure of SMBOIS tables
211 * @table_description_size: size of table description
212 * @table_description: table description
213 * @number_of_tables: number of uefi configuration table
214 * @table_entry: uefi configuration table entry
215 */
216#define SMBIOS_HANDOFF_TABLE_DESC "SmbiosTable"
217struct smbios_handoff_table_pointers2 {
218 u8 table_description_size;
219 u8 table_description[sizeof(SMBIOS_HANDOFF_TABLE_DESC)];
220 u64 number_of_tables;
221 struct efi_configuration_table table_entry[];
222} __packed;
223
Masahisa Kojimace3dbc52021-10-26 17:27:25 +0900224/**
225 * struct tdUEFI_GPT_DATA - event log structure of industry standard tables
226 * @uefi_partition_header: gpt partition header
227 * @number_of_partitions: the number of partition
228 * @partitions: partition entries
229 */
230struct efi_gpt_data {
231 gpt_header uefi_partition_header;
232 u64 number_of_partitions;
233 gpt_entry partitions[];
234} __packed;
235
Ilias Apalodimasc1c02102020-11-11 11:18:11 +0200236struct efi_tcg2_protocol {
237 efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
238 struct efi_tcg2_boot_service_capability *capability);
239 efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this,
240 efi_tcg_event_log_format log_format,
241 u64 *event_log_location, u64 *event_log_last_entry,
242 bool *event_log_truncated);
243 efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this,
Ilias Apalodimasc8d0fd52020-11-30 11:47:40 +0200244 u64 flags,
245 efi_physical_addr_t data_to_hash,
Ilias Apalodimasc1c02102020-11-11 11:18:11 +0200246 u64 data_to_hash_len,
247 struct efi_tcg2_event *efi_tcg_event);
248 efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this,
249 u32 input_parameter_block_size,
250 u8 *input_parameter_block,
251 u32 output_parameter_block_size,
252 u8 *output_parameter_block);
253 efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this,
254 u32 *active_pcr_banks);
255 efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this,
256 u32 active_pcr_banks);
257 efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this,
258 u32 *operation_present,
259 u32 *response);
260};
261#endif