blob: 612f131ecfeb90eb832f1cf516ae4b24784c321b [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Kyösti Mälkkief844012013-06-25 23:17:43 +03003
Kyösti Mälkkie8792be2014-02-26 15:19:04 +02004#ifndef _RULES_H
5#define _RULES_H
6
7/* Useful helpers to tell whether the code is executing in bootblock,
8 * romstage, ramstage or SMM.
9 */
10
Julius Werner99f46832018-05-16 14:14:04 -070011#if defined(__DECOMPRESSOR__)
12#define ENV_DECOMPRESSOR 1
13#define ENV_BOOTBLOCK 0
14#define ENV_ROMSTAGE 0
15#define ENV_RAMSTAGE 0
16#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070017#define ENV_SEPARATE_VERSTAGE 0
Julius Werner99f46832018-05-16 14:14:04 -070018#define ENV_RMODULE 0
19#define ENV_POSTCAR 0
20#define ENV_LIBAGESA 0
21#define ENV_STRING "decompressor"
22
23#elif defined(__BOOTBLOCK__)
24#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020025#define ENV_BOOTBLOCK 1
26#define ENV_ROMSTAGE 0
27#define ENV_RAMSTAGE 0
28#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070029#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050030#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050031#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020032#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060033#define ENV_STRING "bootblock"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020034
Patrick Georgi815f4bf2015-04-28 22:43:31 +020035#elif defined(__ROMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070036#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020037#define ENV_BOOTBLOCK 0
38#define ENV_ROMSTAGE 1
39#define ENV_RAMSTAGE 0
40#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070041#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050042#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050043#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020044#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060045#define ENV_STRING "romstage"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020046
47#elif defined(__SMM__)
Julius Werner99f46832018-05-16 14:14:04 -070048#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020049#define ENV_BOOTBLOCK 0
50#define ENV_ROMSTAGE 0
51#define ENV_RAMSTAGE 0
52#define ENV_SMM 1
Julius Werner21a40532020-04-21 16:03:53 -070053#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050054#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050055#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020056#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060057#define ENV_STRING "smm"
Patrick Georgicc8171f2015-04-28 22:26:23 +020058
Julius Werner21a40532020-04-21 16:03:53 -070059/*
60 * NOTE: "verstage" code may either run as a separate stage or linked into the
61 * bootblock/romstage, depending on the setting of CONFIG_SEPARATE_VERSTAGE. The
62 * ENV_SEPARATE_VERSTAGE macro will only return true for "verstage" code when
63 * CONFIG_SEPARATE_VERSTAGE=y, otherwise that code will have ENV_BOOTBLOCK or
64 * ENV_ROMSTAGE set (depending on the CONFIG_VBOOT_STARTS_IN_... options).
65 */
Patrick Georgicc8171f2015-04-28 22:26:23 +020066#elif defined(__VERSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070067#define ENV_DECOMPRESSOR 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020068#define ENV_BOOTBLOCK 0
69#define ENV_ROMSTAGE 0
70#define ENV_RAMSTAGE 0
71#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070072#define ENV_SEPARATE_VERSTAGE 1
Aaron Durbindde76292015-09-05 12:59:26 -050073#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050074#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020075#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060076#define ENV_STRING "verstage"
Furquan Shaikhabde3b52014-08-26 15:39:51 -070077
Aaron Durbincd96c5c2015-09-04 16:28:15 -050078#elif defined(__RAMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070079#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020080#define ENV_BOOTBLOCK 0
81#define ENV_ROMSTAGE 0
82#define ENV_RAMSTAGE 1
83#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070084#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050085#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050086#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020087#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060088#define ENV_STRING "ramstage"
Aaron Durbindde76292015-09-05 12:59:26 -050089
90#elif defined(__RMODULE__)
Julius Werner99f46832018-05-16 14:14:04 -070091#define ENV_DECOMPRESSOR 0
Aaron Durbindde76292015-09-05 12:59:26 -050092#define ENV_BOOTBLOCK 0
93#define ENV_ROMSTAGE 0
94#define ENV_RAMSTAGE 0
95#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070096#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050097#define ENV_RMODULE 1
Aaron Durbin7f8afe02016-03-18 12:21:23 -050098#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020099#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600100#define ENV_STRING "rmodule"
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500101
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500102#elif defined(__POSTCAR__)
Julius Werner99f46832018-05-16 14:14:04 -0700103#define ENV_DECOMPRESSOR 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500104#define ENV_BOOTBLOCK 0
105#define ENV_ROMSTAGE 0
106#define ENV_RAMSTAGE 0
107#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700108#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500109#define ENV_RMODULE 0
110#define ENV_POSTCAR 1
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200111#define ENV_LIBAGESA 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500112#define ENV_STRING "postcar"
113
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200114#elif defined(__LIBAGESA__)
Julius Werner99f46832018-05-16 14:14:04 -0700115#define ENV_DECOMPRESSOR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200116#define ENV_BOOTBLOCK 0
117#define ENV_ROMSTAGE 0
118#define ENV_RAMSTAGE 0
119#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700120#define ENV_SEPARATE_VERSTAGE 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200121#define ENV_RMODULE 0
122#define ENV_POSTCAR 0
123#define ENV_LIBAGESA 1
124#define ENV_STRING "libagesa"
125
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500126#else
127/*
128 * Default case of nothing set for random blob generation using
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200129 * create_class_compiler that isn't bound to a stage.
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500130 */
Julius Werner99f46832018-05-16 14:14:04 -0700131#define ENV_DECOMPRESSOR 0
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500132#define ENV_BOOTBLOCK 0
133#define ENV_ROMSTAGE 0
134#define ENV_RAMSTAGE 0
135#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700136#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500137#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500138#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200139#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600140#define ENV_STRING "UNKNOWN"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200141#endif
Kyösti Mälkkief844012013-06-25 23:17:43 +0300142
Julius Wernerd3634c12015-11-13 13:28:41 -0800143/* Define helpers about the current architecture, based on toolchain.inc. */
144
145#if defined(__ARCH_arm__)
146#define ENV_ARM 1
147#define ENV_ARM64 0
148#if __COREBOOT_ARM_ARCH__ == 4
149#define ENV_ARMV4 1
150#define ENV_ARMV7 0
151#elif __COREBOOT_ARM_ARCH__ == 7
152#define ENV_ARMV4 0
153#define ENV_ARMV7 1
Hakim Giydan43e5b572016-09-08 10:13:59 -0700154#if defined(__COREBOOT_ARM_V7_A__)
155#define ENV_ARMV7_A 1
156#define ENV_ARMV7_M 0
157#define ENV_ARMV7_R 0
158#elif defined(__COREBOOT_ARM_V7_M__)
159#define ENV_ARMV7_A 0
160#define ENV_ARMV7_M 1
161#define ENV_ARMV7_R 0
162#elif defined(__COREBOOT_ARM_V7_R__)
163#define ENV_ARMV7_A 0
164#define ENV_ARMV7_M 0
165#define ENV_ARMV7_R 1
166#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800167#else
168#define ENV_ARMV4 0
169#define ENV_ARMV7 0
170#endif
171#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800172#define ENV_RISCV 0
173#define ENV_X86 0
174#define ENV_X86_32 0
175#define ENV_X86_64 0
176
177#elif defined(__ARCH_arm64__)
178#define ENV_ARM 0
179#define ENV_ARM64 1
180#define ENV_ARMV4 0
181#define ENV_ARMV7 0
182#if __COREBOOT_ARM_ARCH__ == 8
183#define ENV_ARMV8 1
184#else
185#define ENV_ARMV8 0
186#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800187#define ENV_RISCV 0
188#define ENV_X86 0
189#define ENV_X86_32 0
190#define ENV_X86_64 0
191
192#elif defined(__ARCH_riscv__)
193#define ENV_ARM 0
194#define ENV_ARM64 0
195#define ENV_ARMV4 0
196#define ENV_ARMV7 0
197#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800198#define ENV_RISCV 1
199#define ENV_X86 0
200#define ENV_X86_32 0
201#define ENV_X86_64 0
202
203#elif defined(__ARCH_x86_32__)
204#define ENV_ARM 0
205#define ENV_ARM64 0
206#define ENV_ARMV4 0
207#define ENV_ARMV7 0
208#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800209#define ENV_RISCV 0
210#define ENV_X86 1
211#define ENV_X86_32 1
212#define ENV_X86_64 0
213
214#elif defined(__ARCH_x86_64__)
215#define ENV_ARM 0
216#define ENV_ARM64 0
217#define ENV_ARMV4 0
218#define ENV_ARMV7 0
219#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800220#define ENV_RISCV 0
221#define ENV_X86 1
222#define ENV_X86_32 0
223#define ENV_X86_64 1
224
225#else
226#define ENV_ARM 0
227#define ENV_ARM64 0
228#define ENV_ARMV4 0
229#define ENV_ARMV7 0
230#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800231#define ENV_RISCV 0
232#define ENV_X86 0
233#define ENV_X86_32 0
234#define ENV_X86_64 0
235
236#endif
237
Subrata Banik63022032019-05-11 20:12:20 +0530238#if CONFIG(RAMPAYLOAD)
239/* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
240#define ENV_PAYLOAD_LOADER ENV_POSTCAR
241#else
Ronald G. Minnich42493482019-05-09 17:09:25 +0000242/* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
243 * For now, that is the ramstage. */
244#define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
Subrata Banik63022032019-05-11 20:12:20 +0530245#endif
Ronald G. Minnich42493482019-05-09 17:09:25 +0000246
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300247#define ENV_ROMSTAGE_OR_BEFORE \
Kyösti Mälkkif704b542019-09-14 14:59:38 +0300248 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
Julius Werner21a40532020-04-21 16:03:53 -0700249 (ENV_SEPARATE_VERSTAGE && CONFIG(VBOOT_STARTS_IN_BOOTBLOCK)))
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300250
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300251#if CONFIG(ARCH_X86)
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300252/* Indicates memory layout is determined with arch/x86/car.ld. */
Martin Roth8418fd42019-04-22 16:26:23 -0600253#define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300254/* No .data sections with execute-in-place from ROM. */
255#define ENV_STAGE_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
Kyösti Mälkkia165c072019-08-22 09:44:44 +0300256/* No .bss sections for stage with CAR teardown. */
Arthur Heymans8601afb2019-11-20 22:25:30 +0100257#define ENV_STAGE_HAS_BSS_SECTION 1
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300258#else
259/* Both .data and .bss, sometimes SRAM not DRAM. */
260#define ENV_STAGE_HAS_DATA_SECTION 1
261#define ENV_STAGE_HAS_BSS_SECTION 1
262#define ENV_CACHE_AS_RAM 0
263#endif
264
265/* Currently rmodules, ramstage and smm have heap. */
266#define ENV_STAGE_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
267
Patrick Rudolpha626d272018-04-18 10:13:32 +0200268/**
269 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
270 * PCI, PNP and CPU functions operate without use of devicetree. The reason
271 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
272 * no known requirement that devicetree would be needed during that stage.
273 *
274 * For ramstage individual source file may define __SIMPLE_DEVICE__
275 * before including any header files to force that particular source
276 * be built with simple device model.
Patrick Rudolpha626d272018-04-18 10:13:32 +0200277 */
278
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300279#if !ENV_RAMSTAGE
Patrick Rudolpha626d272018-04-18 10:13:32 +0200280#define __SIMPLE_DEVICE__
281#endif
282
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200283#endif /* _RULES_H */