1 /*
2  * This file is part of the libpayload project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * SPDX-License-Identifier:	BSD-3-Clause
7  */
8 
9 #ifndef _COREBOOT_TABLES_H
10 #define _COREBOOT_TABLES_H
11 
12 struct cbuint64 {
13 	u32 lo;
14 	u32 hi;
15 };
16 
17 struct cb_header {
18 	u8 signature[4];
19 	u32 header_bytes;
20 	u32 header_checksum;
21 	u32 table_bytes;
22 	u32 table_checksum;
23 	u32 table_entries;
24 };
25 
26 struct cb_record {
27 	u32 tag;
28 	u32 size;
29 };
30 
31 #define CB_TAG_UNUSED			0x0000
32 #define CB_TAG_MEMORY			0x0001
33 
34 struct cb_memory_range {
35 	struct cbuint64 start;
36 	struct cbuint64 size;
37 	u32 type;
38 };
39 
40 #define CB_MEM_RAM			1
41 #define CB_MEM_RESERVED			2
42 #define CB_MEM_ACPI			3
43 #define CB_MEM_NVS			4
44 #define CB_MEM_UNUSABLE			5
45 #define CB_MEM_VENDOR_RSVD		6
46 #define CB_MEM_TABLE			16
47 
48 struct cb_memory {
49 	u32 tag;
50 	u32 size;
51 	struct cb_memory_range map[0];
52 };
53 
54 #define CB_TAG_HWRPB			0x0002
55 
56 struct cb_hwrpb {
57 	u32 tag;
58 	u32 size;
59 	u64 hwrpb;
60 };
61 
62 #define CB_TAG_MAINBOARD		0x0003
63 
64 struct cb_mainboard {
65 	u32 tag;
66 	u32 size;
67 	u8 vendor_idx;
68 	u8 part_number_idx;
69 	u8 strings[0];
70 };
71 
72 #define CB_TAG_VERSION			0x0004
73 #define CB_TAG_EXTRA_VERSION		0x0005
74 #define CB_TAG_BUILD			0x0006
75 #define CB_TAG_COMPILE_TIME		0x0007
76 #define CB_TAG_COMPILE_BY		0x0008
77 #define CB_TAG_COMPILE_HOST		0x0009
78 #define CB_TAG_COMPILE_DOMAIN		0x000a
79 #define CB_TAG_COMPILER			0x000b
80 #define CB_TAG_LINKER			0x000c
81 #define CB_TAG_ASSEMBLER		0x000d
82 
83 struct cb_string {
84 	u32 tag;
85 	u32 size;
86 	u8 string[0];
87 };
88 
89 #define CB_TAG_SERIAL			0x000f
90 
91 struct cb_serial {
92 	u32 tag;
93 	u32 size;
94 #define CB_SERIAL_TYPE_IO_MAPPED	1
95 #define CB_SERIAL_TYPE_MEMORY_MAPPED	2
96 	u32 type;
97 	u32 baseaddr;
98 	u32 baud;
99 };
100 
101 #define CB_TAG_CONSOLE			0x0010
102 
103 struct cb_console {
104 	u32 tag;
105 	u32 size;
106 	u16 type;
107 };
108 
109 #define CB_TAG_CONSOLE_SERIAL8250	0
110 #define CB_TAG_CONSOLE_VGA		1 /* OBSOLETE */
111 #define CB_TAG_CONSOLE_BTEXT		2 /* OBSOLETE */
112 #define CB_TAG_CONSOLE_LOGBUF		3
113 #define CB_TAG_CONSOLE_SROM		4 /* OBSOLETE */
114 #define CB_TAG_CONSOLE_EHCI		5
115 
116 #define CB_TAG_FORWARD			0x0011
117 
118 struct cb_forward {
119 	u32 tag;
120 	u32 size;
121 	u64 forward;
122 };
123 
124 #define CB_TAG_FRAMEBUFFER		0x0012
125 
126 struct cb_framebuffer {
127 	u32 tag;
128 	u32 size;
129 	u64 physical_address;
130 	u32 x_resolution;
131 	u32 y_resolution;
132 	u32 bytes_per_line;
133 	u8 bits_per_pixel;
134 	u8 red_mask_pos;
135 	u8 red_mask_size;
136 	u8 green_mask_pos;
137 	u8 green_mask_size;
138 	u8 blue_mask_pos;
139 	u8 blue_mask_size;
140 	u8 reserved_mask_pos;
141 	u8 reserved_mask_size;
142 };
143 
144 #define CB_TAG_GPIO			0x0013
145 #define GPIO_MAX_NAME_LENGTH		16
146 
147 struct cb_gpio {
148 	u32 port;
149 	u32 polarity;
150 	u32 value;
151 	u8 name[GPIO_MAX_NAME_LENGTH];
152 };
153 
154 struct cb_gpios {
155 	u32 tag;
156 	u32 size;
157 	u32 count;
158 	struct cb_gpio gpios[0];
159 };
160 
161 #define CB_TAG_FDT			0x0014
162 
163 struct cb_fdt {
164 	uint32_t tag;
165 	uint32_t size;	/* size of the entire entry */
166 	/* the actual FDT gets placed here */
167 };
168 
169 #define CB_TAG_VDAT			0x0015
170 
171 struct cb_vdat {
172 	uint32_t tag;
173 	uint32_t size;	/* size of the entire entry */
174 	void *vdat_addr;
175 	uint32_t vdat_size;
176 };
177 
178 #define CB_TAG_TIMESTAMPS		0x0016
179 #define CB_TAG_CBMEM_CONSOLE		0x0017
180 #define CB_TAG_MRC_CACHE		0x0018
181 
182 struct cb_cbmem_tab {
183 	uint32_t tag;
184 	uint32_t size;
185 	void *cbmem_tab;
186 };
187 
188 #define CB_TAG_VBNV			0x0019
189 
190 struct cb_vbnv {
191 	uint32_t tag;
192 	uint32_t size;
193 	uint32_t vbnv_start;
194 	uint32_t vbnv_size;
195 };
196 
197 #define CB_TAG_CMOS_OPTION_TABLE	0x00c8
198 
199 struct cb_cmos_option_table {
200 	u32 tag;
201 	u32 size;
202 	u32 header_length;
203 };
204 
205 #define CB_TAG_OPTION			0x00c9
206 
207 #define CMOS_MAX_NAME_LENGTH		32
208 
209 struct cb_cmos_entries {
210 	u32 tag;
211 	u32 size;
212 	u32 bit;
213 	u32 length;
214 	u32 config;
215 	u32 config_id;
216 	u8 name[CMOS_MAX_NAME_LENGTH];
217 };
218 
219 #define CB_TAG_OPTION_ENUM		0x00ca
220 #define CMOS_MAX_TEXT_LENGTH		32
221 
222 struct cb_cmos_enums {
223 	u32 tag;
224 	u32 size;
225 	u32 config_id;
226 	u32 value;
227 	u8 text[CMOS_MAX_TEXT_LENGTH];
228 };
229 
230 #define CB_TAG_OPTION_DEFAULTS		0x00cb
231 #define CMOS_IMAGE_BUFFER_SIZE		128
232 
233 struct cb_cmos_defaults {
234 	u32 tag;
235 	u32 size;
236 	u32 name_length;
237 	u8 name[CMOS_MAX_NAME_LENGTH];
238 	u8 default_set[CMOS_IMAGE_BUFFER_SIZE];
239 };
240 
241 #define CB_TAG_OPTION_CHECKSUM		0x00cc
242 #define CHECKSUM_NONE			0
243 #define CHECKSUM_PCBIOS			1
244 
245 struct	cb_cmos_checksum {
246 	u32 tag;
247 	u32 size;
248 	u32 range_start;
249 	u32 range_end;
250 	u32 location;
251 	u32 type;
252 };
253 
254 /* Helpful macros */
255 
256 #define MEM_RANGE_COUNT(_rec) \
257 	(((_rec)->size - sizeof(*(_rec))) / sizeof((_rec)->map[0]))
258 
259 #define MEM_RANGE_PTR(_rec, _idx) \
260 	(((u8 *) (_rec)) + sizeof(*(_rec)) \
261 	+ (sizeof((_rec)->map[0]) * (_idx)))
262 
263 #define MB_VENDOR_STRING(_mb) \
264 	(((unsigned char *) ((_mb)->strings)) + (_mb)->vendor_idx)
265 
266 #define MB_PART_STRING(_mb) \
267 	(((unsigned char *) ((_mb)->strings)) + (_mb)->part_number_idx)
268 
269 #define UNPACK_CB64(_in) \
270 	((((u64) _in.hi) << 32) | _in.lo)
271 
272 #define CBMEM_TOC_RESERVED		512
273 #define MAX_CBMEM_ENTRIES		16
274 #define CBMEM_MAGIC			0x434f5245
275 
276 struct cbmem_entry {
277 	u32 magic;
278 	u32 id;
279 	u64 base;
280 	u64 size;
281 } __packed;
282 
283 #define CBMEM_ID_FREESPACE		0x46524545
284 #define CBMEM_ID_GDT			0x4c474454
285 #define CBMEM_ID_ACPI			0x41435049
286 #define CBMEM_ID_CBTABLE		0x43425442
287 #define CBMEM_ID_PIRQ			0x49525154
288 #define CBMEM_ID_MPTABLE		0x534d5054
289 #define CBMEM_ID_RESUME			0x5245534d
290 #define CBMEM_ID_RESUME_SCRATCH		0x52455343
291 #define CBMEM_ID_SMBIOS			0x534d4254
292 #define CBMEM_ID_TIMESTAMP		0x54494d45
293 #define CBMEM_ID_MRCDATA		0x4d524344
294 #define CBMEM_ID_CONSOLE		0x434f4e53
295 #define CBMEM_ID_NONE			0x00000000
296 
297 /**
298  * high_table_reserve() - reserve configuration table in high memory
299  *
300  * This reserves configuration table in high memory.
301  *
302  * @return:	always 0
303  */
304 int high_table_reserve(void);
305 
306 /**
307  * high_table_malloc() - allocate configuration table in high memory
308  *
309  * This allocates configuration table in high memory.
310  *
311  * @bytes:	size of configuration table to be allocated
312  * @return:	pointer to configuration table in high memory
313  */
314 void *high_table_malloc(size_t bytes);
315 
316 /**
317  * write_coreboot_table() - write coreboot table
318  *
319  * This writes coreboot table at a given address.
320  *
321  * @addr:	start address to write coreboot table
322  * @cfg_tables:	pointer to configuration table memory area
323  */
324 void write_coreboot_table(u32 addr, struct memory_area *cfg_tables);
325 
326 #endif
327