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