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