blob: 34a3d4a0434688f7feb096959efd3e6884f09017 [file] [log] [blame]
Ilias Apalodimas590fef62020-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 Kojima852c53f2021-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 Apalodimas590fef62020-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 Kojima70be5a62021-05-26 12:09:58 +090019#include <efi_api.h>
Tom Rini84c92972025-05-21 16:51:17 -060020#include <part_efi.h>
Ilias Apalodimas590fef62020-11-11 11:18:11 +020021#include <tpm-v2.h>
Ilias Apalodimasca615322024-06-23 14:48:14 +030022#include <tpm_tcg2.h>
Ilias Apalodimas590fef62020-11-11 11:18:11 +020023
Ilias Apalodimas590fef62020-11-11 11:18:11 +020024/* TPMV2 only */
25#define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
Ilias Apalodimas967650d2020-11-30 11:47:40 +020026#define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
27#define PE_COFF_IMAGE 0x0000000000000010
Ilias Apalodimas590fef62020-11-11 11:18:11 +020028
Masahisa Kojimab8074912021-09-03 10:55:52 +090029#define EFI_TCG2_MAX_PCR_INDEX 23
Ilias Apalodimas967650d2020-11-30 11:47:40 +020030#define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
31
Ilias Apalodimas590fef62020-11-11 11:18:11 +020032typedef u32 efi_tcg_event_log_bitmap;
33typedef u32 efi_tcg_event_log_format;
34typedef u32 efi_tcg_event_algorithm_bitmap;
35
Masahisa Kojima852c53f2021-08-13 16:12:43 +090036/**
37 * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version
38 * @major: major version
39 * @minor: minor version
40 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +020041struct efi_tcg2_version {
42 u8 major;
43 u8 minor;
44};
45
Masahisa Kojima852c53f2021-08-13 16:12:43 +090046/**
47 * struct tdEFI_TCG2_EVENT_HEADER - structure of EFI TCG2 event header
48 * @header_size: size of the event header
49 * @header_version: header version
50 * @pcr_index: index of the PCR that is extended
51 * @event_type: type of the event that is extended
52 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +020053struct efi_tcg2_event_header {
54 u32 header_size;
55 u16 header_version;
56 u32 pcr_index;
57 u32 event_type;
58} __packed;
59
Masahisa Kojima852c53f2021-08-13 16:12:43 +090060/**
61 * struct tdEFI_TCG2_EVENT - structure of EFI TCG2 event
62 * @size: total size of the event including the size component, the header
63 * and the event data
64 * @header: event header
65 * @event: event to add
66 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +020067struct efi_tcg2_event {
68 u32 size;
69 struct efi_tcg2_event_header header;
70 u8 event[];
71} __packed;
72
Masahisa Kojima852c53f2021-08-13 16:12:43 +090073/**
74 * struct tdUEFI_IMAGE_LOAD_EVENT - structure of PE/COFF image measurement
75 * @image_location_in_memory: image address
76 * @image_length_in_memory: image size
77 * @image_link_time_address: image link time address
78 * @length_of_device_path: devive path size
79 * @device_path: device path
80 */
Masahisa Kojima70be5a62021-05-26 12:09:58 +090081struct uefi_image_load_event {
82 efi_physical_addr_t image_location_in_memory;
83 u64 image_length_in_memory;
84 u64 image_link_time_address;
85 u64 length_of_device_path;
86 struct efi_device_path device_path[];
87};
88
Masahisa Kojima852c53f2021-08-13 16:12:43 +090089/**
90 * struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY - protocol capability information
91 * @size: allocated size of the structure
92 * @structure_version: version of this structure
93 * @protocol_version: version of the EFI TCG2 protocol.
94 * @hash_algorithm_bitmap: supported hash algorithms
95 * @supported_event_logs: bitmap of supported event log formats
96 * @tpm_present_flag: false = TPM not present
97 * @max_command_size: max size (in bytes) of a command
98 * that can be sent to the TPM
99 * @max_response_size: max size (in bytes) of a response that
100 * can be provided by the TPM
101 * @manufacturer_id: 4-byte Vendor ID
102 * @number_of_pcr_banks: maximum number of PCR banks
103 * @active_pcr_banks: bitmap of currently active
104 * PCR banks (hashing algorithms).
105 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200106struct efi_tcg2_boot_service_capability {
107 u8 size;
108 struct efi_tcg2_version structure_version;
109 struct efi_tcg2_version protocol_version;
110 efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap;
111 efi_tcg_event_log_bitmap supported_event_logs;
112 u8 tpm_present_flag;
113 u16 max_command_size;
114 u16 max_response_size;
115 u32 manufacturer_id;
116 u32 number_of_pcr_banks;
117 efi_tcg_event_algorithm_bitmap active_pcr_banks;
118};
119
Masahisa Kojima6ddffec2021-09-03 10:55:51 +0900120/* up to and including the vendor ID (manufacturer_id) field */
Masahisa Kojima9cc82932021-09-06 12:04:12 +0900121#define BOOT_SERVICE_CAPABILITY_MIN \
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200122 offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
123
Ilias Apalodimas967650d2020-11-30 11:47:40 +0200124/**
Masahisa Kojima852c53f2021-08-13 16:12:43 +0900125 * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log
Ilias Apalodimas967650d2020-11-30 11:47:40 +0200126 * @version: version number for this structure
127 * @number_of_events: number of events recorded after invocation of
128 * GetEventLog()
129 * @event: List of events of type tcg_pcr_event2
130 */
131struct efi_tcg2_final_events_table {
132 u64 version;
133 u64 number_of_events;
134 struct tcg_pcr_event2 event[];
135};
136
Masahisa Kojima1d2a6562021-08-13 16:12:39 +0900137/**
138 * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable
139 * @variable_name: The vendorGUID parameter in the
140 * GetVariable() API.
141 * @unicode_name_length: The length in CHAR16 of the Unicode name of
142 * the variable.
143 * @variable_data_length: The size of the variable data.
144 * @unicode_name: The CHAR16 unicode name of the variable
Heinrich Schuchardt700c8ac2024-04-11 00:50:43 +0200145 * without NULL-terminator followed by data.
Masahisa Kojima1d2a6562021-08-13 16:12:39 +0900146 */
147struct efi_tcg2_uefi_variable_data {
148 efi_guid_t variable_name;
149 u64 unicode_name_length;
150 u64 variable_data_length;
Heinrich Schuchardt700c8ac2024-04-11 00:50:43 +0200151 u16 unicode_name[];
152 // u8 variable_data[];
Masahisa Kojima1d2a6562021-08-13 16:12:39 +0900153};
154
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900155/**
156 * struct tdUEFI_HANDOFF_TABLE_POINTERS2 - event log structure of SMBOIS tables
157 * @table_description_size: size of table description
158 * @table_description: table description
159 * @number_of_tables: number of uefi configuration table
160 * @table_entry: uefi configuration table entry
161 */
162#define SMBIOS_HANDOFF_TABLE_DESC "SmbiosTable"
163struct smbios_handoff_table_pointers2 {
164 u8 table_description_size;
165 u8 table_description[sizeof(SMBIOS_HANDOFF_TABLE_DESC)];
166 u64 number_of_tables;
167 struct efi_configuration_table table_entry[];
168} __packed;
169
Masahisa Kojima6460c3e2021-10-26 17:27:25 +0900170/**
171 * struct tdUEFI_GPT_DATA - event log structure of industry standard tables
172 * @uefi_partition_header: gpt partition header
173 * @number_of_partitions: the number of partition
174 * @partitions: partition entries
175 */
176struct efi_gpt_data {
177 gpt_header uefi_partition_header;
178 u64 number_of_partitions;
179 gpt_entry partitions[];
180} __packed;
181
Etienne Carriereb9064352023-02-16 17:29:48 +0100182/**
183 * struct tdUEFI_PLATFORM_FIRMWARE_BLOB2
184 * @blob_description_size: Byte size of @data
185 * @data: Description data
186 */
187struct uefi_platform_firmware_blob2 {
188 u8 blob_description_size;
189 u8 data[];
190} __packed;
191
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200192struct efi_tcg2_protocol {
193 efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
194 struct efi_tcg2_boot_service_capability *capability);
195 efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this,
196 efi_tcg_event_log_format log_format,
197 u64 *event_log_location, u64 *event_log_last_entry,
198 bool *event_log_truncated);
199 efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this,
Ilias Apalodimas967650d2020-11-30 11:47:40 +0200200 u64 flags,
201 efi_physical_addr_t data_to_hash,
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200202 u64 data_to_hash_len,
203 struct efi_tcg2_event *efi_tcg_event);
204 efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this,
205 u32 input_parameter_block_size,
206 u8 *input_parameter_block,
207 u32 output_parameter_block_size,
208 u8 *output_parameter_block);
209 efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this,
210 u32 *active_pcr_banks);
211 efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this,
212 u32 active_pcr_banks);
213 efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this,
214 u32 *operation_present,
215 u32 *response);
216};
217#endif