xref: /rk3399_ARM-atf/include/drivers/measured_boot/event_log/tcg.h (revision 1f6cf1e4477f1a0132e7361f17de8b2492608673)
1d89bec83SSandrine Bailleux /*
2ff1e42e2SManish V Badarkhe  * Copyright (c) 2020-2022, Arm Limited. All rights reserved.
3d89bec83SSandrine Bailleux  *
4d89bec83SSandrine Bailleux  * SPDX-License-Identifier: BSD-3-Clause
5d89bec83SSandrine Bailleux  */
6d89bec83SSandrine Bailleux 
7d89bec83SSandrine Bailleux #ifndef TCG_H
8d89bec83SSandrine Bailleux #define TCG_H
9d89bec83SSandrine Bailleux 
10d89bec83SSandrine Bailleux #include <stdint.h>
11*e9529e46SRaghu Krishnamurthy #include <common/sha_common_macros.h>
12d89bec83SSandrine Bailleux 
13d89bec83SSandrine Bailleux #define TCG_ID_EVENT_SIGNATURE_03	"Spec ID Event03"
14d89bec83SSandrine Bailleux #define TCG_STARTUP_LOCALITY_SIGNATURE	"StartupLocality"
15d89bec83SSandrine Bailleux 
16d89bec83SSandrine Bailleux #define TCG_SPEC_VERSION_MAJOR_TPM2   2
17d89bec83SSandrine Bailleux #define TCG_SPEC_VERSION_MINOR_TPM2   0
18d89bec83SSandrine Bailleux #define TCG_SPEC_ERRATA_TPM2          2
19d89bec83SSandrine Bailleux 
20d89bec83SSandrine Bailleux /*
21d89bec83SSandrine Bailleux  * Event types
22d89bec83SSandrine Bailleux  * Ref. Table 9 Events
23d89bec83SSandrine Bailleux  * TCG PC Client Platform Firmware Profile Specification.
24d89bec83SSandrine Bailleux  */
25d89bec83SSandrine Bailleux #define EV_PREBOOT_CERT				U(0x00000000)
26d89bec83SSandrine Bailleux #define EV_POST_CODE				U(0x00000001)
27d89bec83SSandrine Bailleux #define	EV_UNUSED				U(0x00000002)
28d89bec83SSandrine Bailleux #define EV_NO_ACTION				U(0x00000003)
29d89bec83SSandrine Bailleux #define EV_SEPARATOR				U(0x00000004)
30d89bec83SSandrine Bailleux #define EV_ACTION				U(0x00000005)
31d89bec83SSandrine Bailleux #define	EV_EVENT_TAG				U(0x00000006)
32d89bec83SSandrine Bailleux #define EV_S_CRTM_CONTENTS			U(0x00000007)
33d89bec83SSandrine Bailleux #define EV_S_CRTM_VERSION			U(0x00000008)
34d89bec83SSandrine Bailleux #define EV_CPU_MICROCODE			U(0x00000009)
35d89bec83SSandrine Bailleux #define EV_PLATFORM_CONFIG_FLAGS		U(0x0000000A)
36d89bec83SSandrine Bailleux #define EV_TABLE_OF_DEVICES			U(0x0000000B)
37d89bec83SSandrine Bailleux #define EV_COMPACT_HASH				U(0x0000000C)
38d89bec83SSandrine Bailleux #define	EV_IPL					U(0x0000000D)
39d89bec83SSandrine Bailleux #define	EV_IPL_PARTITION_DATA			U(0x0000000E)
40d89bec83SSandrine Bailleux #define EV_NONHOST_CODE				U(0x0000000F)
41d89bec83SSandrine Bailleux #define EV_NONHOST_CONFIG			U(0x00000010)
42d89bec83SSandrine Bailleux #define EV_NONHOST_INFO				U(0x00000011)
43d89bec83SSandrine Bailleux #define EV_OMIT_BOOT_DEVICE_EVENTS		U(0x00000012)
44d89bec83SSandrine Bailleux #define	EV_EFI_EVENT_BASE			U(0x80000000)
45d89bec83SSandrine Bailleux #define	EV_EFI_VARIABLE_DRIVER_CONFIG		U(0x80000001)
46d89bec83SSandrine Bailleux #define EV_EFI_VARIABLE_BOOT			U(0x80000002)
47d89bec83SSandrine Bailleux #define	EV_EFI_BOOT_SERVICES_APPLICATION	U(0x80000003)
48d89bec83SSandrine Bailleux #define	EV_EFI_BOOT_SERVICES_DRIVER		U(0x80000004)
49d89bec83SSandrine Bailleux #define	EV_EFI_RUNTIME_SERVICES_DRIVER		U(0x80000005)
50d89bec83SSandrine Bailleux #define	EV_EFI_GPT_EVENT			U(0x80000006)
51d89bec83SSandrine Bailleux #define	EV_EFI_ACTION				U(0x80000007)
52d89bec83SSandrine Bailleux #define	EV_EFI_PLATFORM_FIRMWARE_BLOB		U(0x80000008)
53d89bec83SSandrine Bailleux #define	EV_EFI_HANDOFF_TABLES			U(0x80000009)
54d89bec83SSandrine Bailleux #define	EV_EFI_HCRTM_EVENT			U(0x80000010)
55d89bec83SSandrine Bailleux #define	EV_EFI_VARIABLE_AUTHORITY		U(0x800000E0)
56d89bec83SSandrine Bailleux 
57d89bec83SSandrine Bailleux /*
58d89bec83SSandrine Bailleux  * TPM_ALG_ID constants.
59d89bec83SSandrine Bailleux  * Ref. Table 9 - Definition of (UINT16) TPM_ALG_ID Constants
60d89bec83SSandrine Bailleux  * Trusted Platform Module Library. Part 2: Structures
61d89bec83SSandrine Bailleux  */
62d89bec83SSandrine Bailleux #define TPM_ALG_SHA256		0x000B
63d89bec83SSandrine Bailleux #define TPM_ALG_SHA384		0x000C
64d89bec83SSandrine Bailleux #define TPM_ALG_SHA512		0x000D
65d89bec83SSandrine Bailleux 
66d89bec83SSandrine Bailleux /* TCG Platform Type */
67d89bec83SSandrine Bailleux #define PLATFORM_CLASS_CLIENT   0
68d89bec83SSandrine Bailleux #define PLATFORM_CLASS_SERVER   1
69d89bec83SSandrine Bailleux 
70d89bec83SSandrine Bailleux enum {
71d89bec83SSandrine Bailleux 	/*
72d89bec83SSandrine Bailleux 	 * SRTM, BIOS, Host Platform Extensions, Embedded
73d89bec83SSandrine Bailleux 	 * Option ROMs and PI Drivers
74d89bec83SSandrine Bailleux 	 */
75d89bec83SSandrine Bailleux 	PCR_0 = 0,
76d89bec83SSandrine Bailleux 	/* Host Platform Configuration */
77d89bec83SSandrine Bailleux 	PCR_1,
78d89bec83SSandrine Bailleux 	/* UEFI driver and application Code */
79d89bec83SSandrine Bailleux 	PCR_2,
80d89bec83SSandrine Bailleux 	/* UEFI driver and application Configuration and Data */
81d89bec83SSandrine Bailleux 	PCR_3,
82d89bec83SSandrine Bailleux 	/* UEFI Boot Manager Code (usually the MBR) and Boot Attempts */
83d89bec83SSandrine Bailleux 	PCR_4,
84d89bec83SSandrine Bailleux 	/*
85d89bec83SSandrine Bailleux 	 * Boot Manager Code Configuration and Data (for use
86d89bec83SSandrine Bailleux 	 * by the Boot Manager Code) and GPT/Partition Table
87d89bec83SSandrine Bailleux 	 */
88d89bec83SSandrine Bailleux 	PCR_5,
89d89bec83SSandrine Bailleux 	/* Host Platform Manufacturer Specific */
90d89bec83SSandrine Bailleux 	PCR_6,
91d89bec83SSandrine Bailleux 	/* Secure Boot Policy */
92d89bec83SSandrine Bailleux 	PCR_7,
93d89bec83SSandrine Bailleux 	/* 8-15: Defined for use by the Static OS */
94d89bec83SSandrine Bailleux 	PCR_8,
95d89bec83SSandrine Bailleux 	/* Debug */
96ff1e42e2SManish V Badarkhe 	PCR_16 = 16,
97ff1e42e2SManish V Badarkhe 
98ff1e42e2SManish V Badarkhe 	/* D-CRTM-measurements by DRTM implementation */
99ff1e42e2SManish V Badarkhe 	PCR_17 = 17,
100ff1e42e2SManish V Badarkhe 	/* DCE measurements by DRTM implementation */
101ff1e42e2SManish V Badarkhe 	PCR_18 = 18
102d89bec83SSandrine Bailleux };
103d89bec83SSandrine Bailleux 
104d89bec83SSandrine Bailleux #pragma pack(push, 1)
105d89bec83SSandrine Bailleux 
106d89bec83SSandrine Bailleux /*
107d89bec83SSandrine Bailleux  * PCR Event Header
108d89bec83SSandrine Bailleux  * TCG EFI Protocol Specification
109d89bec83SSandrine Bailleux  * 5.3 Event Log Header
110d89bec83SSandrine Bailleux  */
111d89bec83SSandrine Bailleux typedef struct {
112d89bec83SSandrine Bailleux 	/* PCRIndex:
113d89bec83SSandrine Bailleux 	 * The PCR Index to which this event is extended
114d89bec83SSandrine Bailleux 	 */
115d89bec83SSandrine Bailleux 	uint32_t	pcr_index;
116d89bec83SSandrine Bailleux 
117d89bec83SSandrine Bailleux 	/* EventType:
118d89bec83SSandrine Bailleux 	 * SHALL be an EV_NO_ACTION event
119d89bec83SSandrine Bailleux 	 */
120d89bec83SSandrine Bailleux 	uint32_t	event_type;
121d89bec83SSandrine Bailleux 
122d89bec83SSandrine Bailleux 	/* SHALL be 20 Bytes of 0x00 */
123d89bec83SSandrine Bailleux 	uint8_t		digest[SHA1_DIGEST_SIZE];
124d89bec83SSandrine Bailleux 
125d89bec83SSandrine Bailleux 	/* The size of the event */
126d89bec83SSandrine Bailleux 	uint32_t	event_size;
127d89bec83SSandrine Bailleux 
128d89bec83SSandrine Bailleux 	/* SHALL be a TCG_EfiSpecIdEvent */
129d89bec83SSandrine Bailleux 	uint8_t		event[];	/* [event_data_size] */
130d89bec83SSandrine Bailleux } tcg_pcr_event_t;
131d89bec83SSandrine Bailleux 
132d89bec83SSandrine Bailleux /*
133d89bec83SSandrine Bailleux  * Log Header Entry Data
134d89bec83SSandrine Bailleux  * Ref. Table 14 TCG_EfiSpecIdEventAlgorithmSize
135d89bec83SSandrine Bailleux  * TCG PC Client Platform Firmware Profile 9.4.5.1
136d89bec83SSandrine Bailleux  */
137d89bec83SSandrine Bailleux typedef struct {
138d89bec83SSandrine Bailleux 	/* Algorithm ID (hashAlg) of the Hash used by BIOS */
139d89bec83SSandrine Bailleux 	uint16_t	algorithm_id;
140d89bec83SSandrine Bailleux 
141d89bec83SSandrine Bailleux 	/* The size of the digest produced by the implemented Hash algorithm */
142d89bec83SSandrine Bailleux 	uint16_t	digest_size;
143d89bec83SSandrine Bailleux } id_event_algorithm_size_t;
144d89bec83SSandrine Bailleux 
145d89bec83SSandrine Bailleux /*
146d89bec83SSandrine Bailleux  * TCG_EfiSpecIdEvent structure
147d89bec83SSandrine Bailleux  * Ref. Table 15 TCG_EfiSpecIdEvent
148d89bec83SSandrine Bailleux  * TCG PC Client Platform Firmware Profile 9.4.5.1
149d89bec83SSandrine Bailleux  */
150d89bec83SSandrine Bailleux typedef struct {
151d89bec83SSandrine Bailleux 	/*
152d89bec83SSandrine Bailleux 	 * The NUL-terminated ASCII string "Spec ID Event03".
153d89bec83SSandrine Bailleux 	 * SHALL be set to {0x53, 0x70, 0x65, 0x63, 0x20, 0x49, 0x44,
154d89bec83SSandrine Bailleux 	 * 0x20, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x33, 0x00}.
155d89bec83SSandrine Bailleux 	 */
156d89bec83SSandrine Bailleux 	uint8_t		signature[16];
157d89bec83SSandrine Bailleux 
158d89bec83SSandrine Bailleux 	/*
159d89bec83SSandrine Bailleux 	 * The value for the Platform Class.
160d89bec83SSandrine Bailleux 	 * The enumeration is defined in the TCG ACPI Specification Client
161d89bec83SSandrine Bailleux 	 * Common Header.
162d89bec83SSandrine Bailleux 	 */
163d89bec83SSandrine Bailleux 	uint32_t	platform_class;
164d89bec83SSandrine Bailleux 
165d89bec83SSandrine Bailleux 	/*
166d89bec83SSandrine Bailleux 	 * The PC Client Platform Profile Specification minor version number
167d89bec83SSandrine Bailleux 	 * this BIOS supports.
168d89bec83SSandrine Bailleux 	 * Any BIOS supporting this version (2.0) MUST set this value to 0x00.
169d89bec83SSandrine Bailleux 	 */
170d89bec83SSandrine Bailleux 	uint8_t		spec_version_minor;
171d89bec83SSandrine Bailleux 
172d89bec83SSandrine Bailleux 	/*
173d89bec83SSandrine Bailleux 	 * The PC Client Platform Profile Specification major version number
174d89bec83SSandrine Bailleux 	 * this BIOS supports.
175d89bec83SSandrine Bailleux 	 * Any BIOS supporting this version (2.0) MUST set this value to 0x02.
176d89bec83SSandrine Bailleux 	 */
177d89bec83SSandrine Bailleux 	uint8_t		spec_version_major;
178d89bec83SSandrine Bailleux 
179d89bec83SSandrine Bailleux 	/*
180d89bec83SSandrine Bailleux 	 * The PC Client Platform Profile Specification errata version number
181d89bec83SSandrine Bailleux 	 * this BIOS supports.
182d89bec83SSandrine Bailleux 	 * Any BIOS supporting this version (2.0) MUST set this value to 0x02.
183d89bec83SSandrine Bailleux 	 */
184d89bec83SSandrine Bailleux 	uint8_t		spec_errata;
185d89bec83SSandrine Bailleux 
186d89bec83SSandrine Bailleux 	/*
187d89bec83SSandrine Bailleux 	 * Specifies the size of the UINTN fields used in various data
188d89bec83SSandrine Bailleux 	 * structures used in this specification.
189d89bec83SSandrine Bailleux 	 * 0x01 indicates UINT32 and 0x02 indicates UINT64.
190d89bec83SSandrine Bailleux 	 */
191d89bec83SSandrine Bailleux 	uint8_t		uintn_size;
192d89bec83SSandrine Bailleux 
193d89bec83SSandrine Bailleux 	/*
194d89bec83SSandrine Bailleux 	 * The number of Hash algorithms in the digestSizes field.
195d89bec83SSandrine Bailleux 	 * This field MUST be set to a value of 0x01 or greater.
196d89bec83SSandrine Bailleux 	 */
197d89bec83SSandrine Bailleux 	uint32_t	number_of_algorithms;
198d89bec83SSandrine Bailleux 
199d89bec83SSandrine Bailleux 	/*
200d89bec83SSandrine Bailleux 	 * Each TCG_EfiSpecIdEventAlgorithmSize SHALL contain an algorithmId
201d89bec83SSandrine Bailleux 	 * and digestSize for each hash algorithm used in the TCG_PCR_EVENT2
202d89bec83SSandrine Bailleux 	 * structure, the first of which is a Hash algorithmID and the second
203d89bec83SSandrine Bailleux 	 * is the size of the respective digest.
204d89bec83SSandrine Bailleux 	 */
205d89bec83SSandrine Bailleux 	id_event_algorithm_size_t    digest_size[]; /* number_of_algorithms */
206d89bec83SSandrine Bailleux } id_event_struct_header_t;
207d89bec83SSandrine Bailleux 
208d89bec83SSandrine Bailleux typedef struct {
209d89bec83SSandrine Bailleux 	/*
210d89bec83SSandrine Bailleux 	 * Size in bytes of the VendorInfo field.
211d89bec83SSandrine Bailleux 	 * Maximum value MUST be FFh bytes.
212d89bec83SSandrine Bailleux 	 */
213d89bec83SSandrine Bailleux 	uint8_t		vendor_info_size;
214d89bec83SSandrine Bailleux 
215d89bec83SSandrine Bailleux 	/*
216d89bec83SSandrine Bailleux 	 * Provided for use by Platform Firmware implementer. The value might
217d89bec83SSandrine Bailleux 	 * be used, for example, to provide more detailed information about the
218d89bec83SSandrine Bailleux 	 * specific BIOS such as BIOS revision numbers, etc. The values within
219d89bec83SSandrine Bailleux 	 * this field are not standardized and are implementer-specific.
220d89bec83SSandrine Bailleux 	 * Platform-specific or -unique information MUST NOT be provided in
221d89bec83SSandrine Bailleux 	 * this field.
222d89bec83SSandrine Bailleux 	 *
223d89bec83SSandrine Bailleux 	 */
224d89bec83SSandrine Bailleux 	uint8_t		vendor_info[];	/* [vendorInfoSize] */
225d89bec83SSandrine Bailleux } id_event_struct_data_t;
226d89bec83SSandrine Bailleux 
227d89bec83SSandrine Bailleux typedef struct {
228d89bec83SSandrine Bailleux 	id_event_struct_header_t	struct_header;
229d89bec83SSandrine Bailleux 	id_event_struct_data_t		struct_data;
230d89bec83SSandrine Bailleux } id_event_struct_t;
231d89bec83SSandrine Bailleux 
232d89bec83SSandrine Bailleux typedef struct {
233d89bec83SSandrine Bailleux 	tcg_pcr_event_t			header;
234d89bec83SSandrine Bailleux 	id_event_struct_header_t	struct_header;
235d89bec83SSandrine Bailleux } id_event_headers_t;
236d89bec83SSandrine Bailleux 
237d89bec83SSandrine Bailleux /* TPMT_HA Structure */
238d89bec83SSandrine Bailleux typedef struct {
239d89bec83SSandrine Bailleux 	/* Selector of the hash contained in the digest that implies
240d89bec83SSandrine Bailleux 	 * the size of the digest
241d89bec83SSandrine Bailleux 	 */
242d89bec83SSandrine Bailleux 	uint16_t	algorithm_id;	/* AlgorithmId */
243d89bec83SSandrine Bailleux 
244d89bec83SSandrine Bailleux 	/* Digest, depends on AlgorithmId */
245d89bec83SSandrine Bailleux 	uint8_t		digest[];	/* Digest[] */
246d89bec83SSandrine Bailleux } tpmt_ha;
247d89bec83SSandrine Bailleux 
248d89bec83SSandrine Bailleux /*
249d89bec83SSandrine Bailleux  * TPML_DIGEST_VALUES Structure
250d89bec83SSandrine Bailleux  */
251d89bec83SSandrine Bailleux typedef struct {
252d89bec83SSandrine Bailleux 	/* The number of digests in the list */
253d89bec83SSandrine Bailleux 	uint32_t	count;			/* Count */
254d89bec83SSandrine Bailleux 
255d89bec83SSandrine Bailleux 	/* The list of tagged digests, as sent to the TPM as part of a
256d89bec83SSandrine Bailleux 	 * TPM2_PCR_Extend or as received from a TPM2_PCR_Event command
257d89bec83SSandrine Bailleux 	 */
258d89bec83SSandrine Bailleux 	tpmt_ha		digests[];		/* Digests[Count] */
259d89bec83SSandrine Bailleux } tpml_digest_values;
260d89bec83SSandrine Bailleux 
261d89bec83SSandrine Bailleux /*
262d89bec83SSandrine Bailleux  * TCG_PCR_EVENT2 header
263d89bec83SSandrine Bailleux  */
264d89bec83SSandrine Bailleux typedef struct {
265d89bec83SSandrine Bailleux 	 /* The PCR Index to which this event was extended */
266d89bec83SSandrine Bailleux 	uint32_t		pcr_index;	/* PCRIndex */
267d89bec83SSandrine Bailleux 
268d89bec83SSandrine Bailleux 	/* Type of event */
269d89bec83SSandrine Bailleux 	uint32_t		event_type;	/* EventType */
270d89bec83SSandrine Bailleux 
271d89bec83SSandrine Bailleux 	/* Digests:
272d89bec83SSandrine Bailleux 	 * A counted list of tagged digests, which contain the digest of
273d89bec83SSandrine Bailleux 	 * the event data (or external data) for all active PCR banks
274d89bec83SSandrine Bailleux 	 */
275d89bec83SSandrine Bailleux 	tpml_digest_values	digests;	/* Digests */
276d89bec83SSandrine Bailleux } event2_header_t;
277d89bec83SSandrine Bailleux 
278d89bec83SSandrine Bailleux typedef struct event2_data {
279d89bec83SSandrine Bailleux 	/* The size of the event data */
280d89bec83SSandrine Bailleux 	uint32_t		event_size;	/* EventSize */
281d89bec83SSandrine Bailleux 
282d89bec83SSandrine Bailleux 	/* The data of the event */
283d89bec83SSandrine Bailleux 	uint8_t			event[];	/* Event[EventSize] */
284d89bec83SSandrine Bailleux } event2_data_t;
285d89bec83SSandrine Bailleux 
286d89bec83SSandrine Bailleux /*
287d89bec83SSandrine Bailleux  * Startup Locality Event
288d89bec83SSandrine Bailleux  * Ref. TCG PC Client Platform Firmware Profile 9.4.5.3
289d89bec83SSandrine Bailleux  */
290d89bec83SSandrine Bailleux typedef struct {
291d89bec83SSandrine Bailleux 	/*
292d89bec83SSandrine Bailleux 	 * The NUL-terminated ASCII string "StartupLocality" SHALL be
293d89bec83SSandrine Bailleux 	 * set to {0x53 0x74 0x61 0x72 0x74 0x75 0x70 0x4C 0x6F 0x63
294d89bec83SSandrine Bailleux 	 * 0x61 0x6C 0x69 0x74 0x79 0x00}
295d89bec83SSandrine Bailleux 	 */
296d89bec83SSandrine Bailleux 	uint8_t		signature[16];
297d89bec83SSandrine Bailleux 
298d89bec83SSandrine Bailleux 	/* The Locality Indicator which sent the TPM2_Startup command */
299d89bec83SSandrine Bailleux 	uint8_t		startup_locality;
300d89bec83SSandrine Bailleux } startup_locality_event_t;
301d89bec83SSandrine Bailleux 
302d89bec83SSandrine Bailleux #pragma pack(pop)
303d89bec83SSandrine Bailleux 
304d89bec83SSandrine Bailleux #endif /* TCG_H */
305