blob: 7ed88809913b05a70032de108807eb56cb35c446 [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>
Ilias Apalodimas590fef62020-11-11 11:18:11 +020020#include <tpm-v2.h>
Ilias Apalodimasca615322024-06-23 14:48:14 +030021#include <tpm_tcg2.h>
Ilias Apalodimas590fef62020-11-11 11:18:11 +020022
Ilias Apalodimas590fef62020-11-11 11:18:11 +020023/* TPMV2 only */
24#define TCG2_EVENT_LOG_FORMAT_TCG_2 0x00000002
Ilias Apalodimas967650d2020-11-30 11:47:40 +020025#define EFI_TCG2_EXTEND_ONLY 0x0000000000000001
26#define PE_COFF_IMAGE 0x0000000000000010
Ilias Apalodimas590fef62020-11-11 11:18:11 +020027
Masahisa Kojimab8074912021-09-03 10:55:52 +090028#define EFI_TCG2_MAX_PCR_INDEX 23
Ilias Apalodimas967650d2020-11-30 11:47:40 +020029#define EFI_TCG2_FINAL_EVENTS_TABLE_VERSION 1
30
Ilias Apalodimas590fef62020-11-11 11:18:11 +020031typedef u32 efi_tcg_event_log_bitmap;
32typedef u32 efi_tcg_event_log_format;
33typedef u32 efi_tcg_event_algorithm_bitmap;
34
Masahisa Kojima852c53f2021-08-13 16:12:43 +090035/**
36 * struct tdEFI_TCG2_VERSION - structure of EFI TCG2 version
37 * @major: major version
38 * @minor: minor version
39 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +020040struct efi_tcg2_version {
41 u8 major;
42 u8 minor;
43};
44
Masahisa Kojima852c53f2021-08-13 16:12:43 +090045/**
46 * struct tdEFI_TCG2_EVENT_HEADER - structure of EFI TCG2 event header
47 * @header_size: size of the event header
48 * @header_version: header version
49 * @pcr_index: index of the PCR that is extended
50 * @event_type: type of the event that is extended
51 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +020052struct efi_tcg2_event_header {
53 u32 header_size;
54 u16 header_version;
55 u32 pcr_index;
56 u32 event_type;
57} __packed;
58
Masahisa Kojima852c53f2021-08-13 16:12:43 +090059/**
60 * struct tdEFI_TCG2_EVENT - structure of EFI TCG2 event
61 * @size: total size of the event including the size component, the header
62 * and the event data
63 * @header: event header
64 * @event: event to add
65 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +020066struct efi_tcg2_event {
67 u32 size;
68 struct efi_tcg2_event_header header;
69 u8 event[];
70} __packed;
71
Masahisa Kojima852c53f2021-08-13 16:12:43 +090072/**
73 * struct tdUEFI_IMAGE_LOAD_EVENT - structure of PE/COFF image measurement
74 * @image_location_in_memory: image address
75 * @image_length_in_memory: image size
76 * @image_link_time_address: image link time address
77 * @length_of_device_path: devive path size
78 * @device_path: device path
79 */
Masahisa Kojima70be5a62021-05-26 12:09:58 +090080struct uefi_image_load_event {
81 efi_physical_addr_t image_location_in_memory;
82 u64 image_length_in_memory;
83 u64 image_link_time_address;
84 u64 length_of_device_path;
85 struct efi_device_path device_path[];
86};
87
Masahisa Kojima852c53f2021-08-13 16:12:43 +090088/**
89 * struct tdEFI_TCG2_BOOT_SERVICE_CAPABILITY - protocol capability information
90 * @size: allocated size of the structure
91 * @structure_version: version of this structure
92 * @protocol_version: version of the EFI TCG2 protocol.
93 * @hash_algorithm_bitmap: supported hash algorithms
94 * @supported_event_logs: bitmap of supported event log formats
95 * @tpm_present_flag: false = TPM not present
96 * @max_command_size: max size (in bytes) of a command
97 * that can be sent to the TPM
98 * @max_response_size: max size (in bytes) of a response that
99 * can be provided by the TPM
100 * @manufacturer_id: 4-byte Vendor ID
101 * @number_of_pcr_banks: maximum number of PCR banks
102 * @active_pcr_banks: bitmap of currently active
103 * PCR banks (hashing algorithms).
104 */
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200105struct efi_tcg2_boot_service_capability {
106 u8 size;
107 struct efi_tcg2_version structure_version;
108 struct efi_tcg2_version protocol_version;
109 efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap;
110 efi_tcg_event_log_bitmap supported_event_logs;
111 u8 tpm_present_flag;
112 u16 max_command_size;
113 u16 max_response_size;
114 u32 manufacturer_id;
115 u32 number_of_pcr_banks;
116 efi_tcg_event_algorithm_bitmap active_pcr_banks;
117};
118
Masahisa Kojima6ddffec2021-09-03 10:55:51 +0900119/* up to and including the vendor ID (manufacturer_id) field */
Masahisa Kojima9cc82932021-09-06 12:04:12 +0900120#define BOOT_SERVICE_CAPABILITY_MIN \
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200121 offsetof(struct efi_tcg2_boot_service_capability, number_of_pcr_banks)
122
Ilias Apalodimas967650d2020-11-30 11:47:40 +0200123/**
Masahisa Kojima852c53f2021-08-13 16:12:43 +0900124 * struct tdEFI_TCG2_FINAL_EVENTS_TABLE - log entries after Get Event Log
Ilias Apalodimas967650d2020-11-30 11:47:40 +0200125 * @version: version number for this structure
126 * @number_of_events: number of events recorded after invocation of
127 * GetEventLog()
128 * @event: List of events of type tcg_pcr_event2
129 */
130struct efi_tcg2_final_events_table {
131 u64 version;
132 u64 number_of_events;
133 struct tcg_pcr_event2 event[];
134};
135
Masahisa Kojima1d2a6562021-08-13 16:12:39 +0900136/**
137 * struct tdUEFI_VARIABLE_DATA - event log structure of UEFI variable
138 * @variable_name: The vendorGUID parameter in the
139 * GetVariable() API.
140 * @unicode_name_length: The length in CHAR16 of the Unicode name of
141 * the variable.
142 * @variable_data_length: The size of the variable data.
143 * @unicode_name: The CHAR16 unicode name of the variable
Heinrich Schuchardt700c8ac2024-04-11 00:50:43 +0200144 * without NULL-terminator followed by data.
Masahisa Kojima1d2a6562021-08-13 16:12:39 +0900145 */
146struct efi_tcg2_uefi_variable_data {
147 efi_guid_t variable_name;
148 u64 unicode_name_length;
149 u64 variable_data_length;
Heinrich Schuchardt700c8ac2024-04-11 00:50:43 +0200150 u16 unicode_name[];
151 // u8 variable_data[];
Masahisa Kojima1d2a6562021-08-13 16:12:39 +0900152};
153
Masahisa Kojimacd1fe7d2021-10-26 17:27:24 +0900154/**
155 * struct tdUEFI_HANDOFF_TABLE_POINTERS2 - event log structure of SMBOIS tables
156 * @table_description_size: size of table description
157 * @table_description: table description
158 * @number_of_tables: number of uefi configuration table
159 * @table_entry: uefi configuration table entry
160 */
161#define SMBIOS_HANDOFF_TABLE_DESC "SmbiosTable"
162struct smbios_handoff_table_pointers2 {
163 u8 table_description_size;
164 u8 table_description[sizeof(SMBIOS_HANDOFF_TABLE_DESC)];
165 u64 number_of_tables;
166 struct efi_configuration_table table_entry[];
167} __packed;
168
Masahisa Kojima6460c3e2021-10-26 17:27:25 +0900169/**
170 * struct tdUEFI_GPT_DATA - event log structure of industry standard tables
171 * @uefi_partition_header: gpt partition header
172 * @number_of_partitions: the number of partition
173 * @partitions: partition entries
174 */
175struct efi_gpt_data {
176 gpt_header uefi_partition_header;
177 u64 number_of_partitions;
178 gpt_entry partitions[];
179} __packed;
180
Etienne Carriereb9064352023-02-16 17:29:48 +0100181/**
182 * struct tdUEFI_PLATFORM_FIRMWARE_BLOB2
183 * @blob_description_size: Byte size of @data
184 * @data: Description data
185 */
186struct uefi_platform_firmware_blob2 {
187 u8 blob_description_size;
188 u8 data[];
189} __packed;
190
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200191struct efi_tcg2_protocol {
192 efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this,
193 struct efi_tcg2_boot_service_capability *capability);
194 efi_status_t (EFIAPI * get_eventlog)(struct efi_tcg2_protocol *this,
195 efi_tcg_event_log_format log_format,
196 u64 *event_log_location, u64 *event_log_last_entry,
197 bool *event_log_truncated);
198 efi_status_t (EFIAPI * hash_log_extend_event)(struct efi_tcg2_protocol *this,
Ilias Apalodimas967650d2020-11-30 11:47:40 +0200199 u64 flags,
200 efi_physical_addr_t data_to_hash,
Ilias Apalodimas590fef62020-11-11 11:18:11 +0200201 u64 data_to_hash_len,
202 struct efi_tcg2_event *efi_tcg_event);
203 efi_status_t (EFIAPI * submit_command)(struct efi_tcg2_protocol *this,
204 u32 input_parameter_block_size,
205 u8 *input_parameter_block,
206 u32 output_parameter_block_size,
207 u8 *output_parameter_block);
208 efi_status_t (EFIAPI * get_active_pcr_banks)(struct efi_tcg2_protocol *this,
209 u32 *active_pcr_banks);
210 efi_status_t (EFIAPI * set_active_pcr_banks)(struct efi_tcg2_protocol *this,
211 u32 active_pcr_banks);
212 efi_status_t (EFIAPI * get_result_of_set_active_pcr_banks)(struct efi_tcg2_protocol *this,
213 u32 *operation_present,
214 u32 *response);
215};
216#endif