xref: /freebsd/sys/dev/coreboot/corebootio.h (revision 5f74217c05a99f38a31a6e4950220964595d4ac8)
1 /*
2  * Copyright (c) 2026 Abdelkader Boudih <freebsd@seuros.com>
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 /*
8  * coreboot(4) userland-visible definitions.
9  *
10  * This header is safe to include from both kernel and userland code.
11  * It contains the /dev/cbmem ioctl interface, CBMEM ID constants,
12  * and timestamp structures needed by the cbmem(8) utility.
13  */
14 
15 #ifndef _DEV_COREBOOT_COREBOOT_IOCTL_H_
16 #define _DEV_COREBOOT_COREBOOT_IOCTL_H_
17 
18 #include <sys/types.h>
19 #include <sys/ioccom.h>
20 
21 /*
22  * CBMEM ID constants (from coreboot's BSD-3-Clause cbmem_id.h).
23  * Used for human-readable CBMEM entry names in sysctl and ioctl output.
24  */
25 #define CBMEM_ID_ACPI			0x41435049
26 #define CBMEM_ID_ACPI_GNVS		0x474e5653
27 #define CBMEM_ID_AFTER_CAR		0xc4787a93
28 #define CBMEM_ID_CBTABLE		0x43425442
29 #define CBMEM_ID_CBTABLE_FWD		0x43425443
30 #define CBMEM_ID_CBFS_RO_MCACHE	0x524d5346
31 #define CBMEM_ID_CBFS_RW_MCACHE	0x574d5346
32 #define CBMEM_ID_CONSOLE		0x434f4e53
33 #define CBMEM_ID_ELOG			0x454c4f47
34 #define CBMEM_ID_FMAP			0x464d4150
35 #define CBMEM_ID_FREESPACE		0x46524545
36 #define CBMEM_ID_FSP_RESERVED_MEMORY	0x46535052
37 #define CBMEM_ID_FSP_RUNTIME		0x52505346
38 #define CBMEM_ID_FSPM_VERSION		0x56505346
39 #define CBMEM_ID_IGD_OPREGION		0x4f444749
40 #define CBMEM_ID_IMD_ROOT		0xff4017ff
41 #define CBMEM_ID_IMD_SMALL		0x53a11439
42 #define CBMEM_ID_MEMINFO		0x494d454d
43 #define CBMEM_ID_MPTABLE		0x534d5054
44 #define CBMEM_ID_MRCDATA		0x4d524344
45 #define CBMEM_ID_PIRQ			0x49525154
46 #define CBMEM_ID_POWER_STATE		0x50535454
47 #define CBMEM_ID_RAM_OOPS		0x05430095
48 #define CBMEM_ID_RAMSTAGE		0x9a357a9e
49 #define CBMEM_ID_REFCODE		0x04efc0de
50 #define CBMEM_ID_RESUME			0x5245534d
51 #define CBMEM_ID_ROMSTAGE_INFO		0x47545352
52 #define CBMEM_ID_ROMSTAGE_RAM_STACK	0x90357ac4
53 #define CBMEM_ID_ROOT			0xff4007ff
54 #define CBMEM_ID_SMBIOS			0x534d4254
55 #define CBMEM_ID_SMM_COMBUFFER		0x53534d32
56 #define CBMEM_ID_SMM_SAVE_SPACE		0x07e9acee
57 #define CBMEM_ID_TIMESTAMP		0x54494d45
58 #define CBMEM_ID_TPM_CB_LOG		0x54435041
59 #define CBMEM_ID_VBOOT_WORKBUF		0x78007343
60 #define CBMEM_ID_VPD			0x56504420
61 
62 #define CB_MAX_CBMEM_ENTRIES	64
63 
64 /*
65  * /dev/cbmem ioctl interface
66  */
67 struct cbmem_entry_info {
68 	uint32_t	id;
69 	uint64_t	address;
70 	uint32_t	size;
71 	char		name[16];
72 };
73 
74 struct cbmem_list {
75 	uint32_t	count;
76 	struct cbmem_entry_info entries[CB_MAX_CBMEM_ENTRIES];
77 };
78 
79 struct cbmem_read_req {
80 	uint32_t	id;
81 	uint64_t	offset;
82 	uint32_t	size;
83 	void		*buffer;
84 };
85 
86 #define CBMEM_IOC_LIST	_IOR('C', 1, struct cbmem_list)
87 #define CBMEM_IOC_READ	_IOWR('C', 2, struct cbmem_read_req)
88 
89 /*
90  * Timestamp structures - stored in a CBMEM region.
91  * Used by both the kernel driver and cbmem(8) utility.
92  */
93 struct cb_timestamp_entry {
94 	uint32_t	entry_id;
95 	int64_t		entry_stamp;
96 } __packed;
97 
98 struct cb_timestamp_table {
99 	uint64_t	base_time;
100 	uint16_t	max_entries;
101 	uint16_t	tick_freq_mhz;
102 	uint32_t	num_entries;
103 	struct cb_timestamp_entry entries[];
104 } __packed;
105 
106 /*
107  * TPM CB log structures - stored in a CBMEM region.
108  * Used by both the kernel driver and cbmem(8) utility.
109  */
110 struct tpm_cb_log_entry {
111 	uint32_t	pcr;
112 	uint32_t	event_type;
113 	uint8_t		digest[20];	/* SHA-1 */
114 	uint32_t	data_len;
115 } __packed;
116 
117 struct tpm_cb_log_table {
118 	uint16_t	max_entries;
119 	uint16_t	num_entries;
120 	uint32_t	entry_size;
121 } __packed;
122 
123 #endif /* _DEV_COREBOOT_COREBOOT_IOCTL_H_ */
124