blob: ae8118ebb471dcec0108b13da9534797af4119ae [file] [log] [blame]
Angel Pons32859fc2020-04-02 23:48:27 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkkief844012013-06-25 23:17:43 +03002
Kyösti Mälkkie8792be2014-02-26 15:19:04 +02003#ifndef _RULES_H
4#define _RULES_H
5
Jakub Czapiga084ad932021-03-25 13:10:31 +01006#if defined(__TEST__)
7#define ENV_TEST 1
8#else
9#define ENV_TEST 0
10#endif
11
Angel Pons46451972020-06-08 15:52:03 +020012#if defined(__TIMELESS__)
13#define ENV_TIMELESS 1
14#else
15#define ENV_TIMELESS 0
16#endif
17
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020018/* Useful helpers to tell whether the code is executing in bootblock,
19 * romstage, ramstage or SMM.
20 */
21
Julius Werner99f46832018-05-16 14:14:04 -070022#if defined(__DECOMPRESSOR__)
23#define ENV_DECOMPRESSOR 1
24#define ENV_BOOTBLOCK 0
25#define ENV_ROMSTAGE 0
26#define ENV_RAMSTAGE 0
27#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070028#define ENV_SEPARATE_VERSTAGE 0
Julius Werner99f46832018-05-16 14:14:04 -070029#define ENV_RMODULE 0
30#define ENV_POSTCAR 0
31#define ENV_LIBAGESA 0
32#define ENV_STRING "decompressor"
33
34#elif defined(__BOOTBLOCK__)
35#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020036#define ENV_BOOTBLOCK 1
37#define ENV_ROMSTAGE 0
38#define ENV_RAMSTAGE 0
39#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070040#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050041#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050042#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020043#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060044#define ENV_STRING "bootblock"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020045
Patrick Georgi815f4bf2015-04-28 22:43:31 +020046#elif defined(__ROMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070047#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020048#define ENV_BOOTBLOCK 0
49#define ENV_ROMSTAGE 1
50#define ENV_RAMSTAGE 0
51#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070052#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050053#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050054#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020055#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060056#define ENV_STRING "romstage"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020057
58#elif defined(__SMM__)
Julius Werner99f46832018-05-16 14:14:04 -070059#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020060#define ENV_BOOTBLOCK 0
61#define ENV_ROMSTAGE 0
62#define ENV_RAMSTAGE 0
63#define ENV_SMM 1
Julius Werner21a40532020-04-21 16:03:53 -070064#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050065#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050066#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020067#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060068#define ENV_STRING "smm"
Patrick Georgicc8171f2015-04-28 22:26:23 +020069
Julius Werner21a40532020-04-21 16:03:53 -070070/*
71 * NOTE: "verstage" code may either run as a separate stage or linked into the
Martin Roth0639bff2020-11-09 13:13:27 -070072 * bootblock/romstage, depending on the setting of the VBOOT_SEPARATE_VERSTAGE
73 * kconfig option. The ENV_SEPARATE_VERSTAGE macro will only return true for
74 * "verstage" code when CONFIG(VBOOT_SEPARATE_VERSTAGE) is true, otherwise that
75 * code will have ENV_BOOTBLOCK or ENV_ROMSTAGE set (depending on the
76 * "VBOOT_STARTS_IN_"... kconfig options).
Julius Werner21a40532020-04-21 16:03:53 -070077 */
Patrick Georgicc8171f2015-04-28 22:26:23 +020078#elif defined(__VERSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070079#define ENV_DECOMPRESSOR 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020080#define ENV_BOOTBLOCK 0
81#define ENV_ROMSTAGE 0
82#define ENV_RAMSTAGE 0
83#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070084#define ENV_SEPARATE_VERSTAGE 1
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
Kangheui Won4b5c8b52020-10-07 14:29:38 +110088#if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
89#define ENV_STRING "verstage-before-bootblock"
90#else
Ben Gardneraa5f5b12015-11-19 10:48:47 -060091#define ENV_STRING "verstage"
Kangheui Won4b5c8b52020-10-07 14:29:38 +110092#endif
Furquan Shaikhabde3b52014-08-26 15:39:51 -070093
Aaron Durbincd96c5c2015-09-04 16:28:15 -050094#elif defined(__RAMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070095#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020096#define ENV_BOOTBLOCK 0
97#define ENV_ROMSTAGE 0
98#define ENV_RAMSTAGE 1
99#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700100#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500101#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500102#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200103#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600104#define ENV_STRING "ramstage"
Aaron Durbindde76292015-09-05 12:59:26 -0500105
106#elif defined(__RMODULE__)
Julius Werner99f46832018-05-16 14:14:04 -0700107#define ENV_DECOMPRESSOR 0
Aaron Durbindde76292015-09-05 12:59:26 -0500108#define ENV_BOOTBLOCK 0
109#define ENV_ROMSTAGE 0
110#define ENV_RAMSTAGE 0
111#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700112#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500113#define ENV_RMODULE 1
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500114#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200115#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600116#define ENV_STRING "rmodule"
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500117
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500118#elif defined(__POSTCAR__)
Julius Werner99f46832018-05-16 14:14:04 -0700119#define ENV_DECOMPRESSOR 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500120#define ENV_BOOTBLOCK 0
121#define ENV_ROMSTAGE 0
122#define ENV_RAMSTAGE 0
123#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700124#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500125#define ENV_RMODULE 0
126#define ENV_POSTCAR 1
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200127#define ENV_LIBAGESA 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500128#define ENV_STRING "postcar"
129
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200130#elif defined(__LIBAGESA__)
Julius Werner99f46832018-05-16 14:14:04 -0700131#define ENV_DECOMPRESSOR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200132#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
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200137#define ENV_RMODULE 0
138#define ENV_POSTCAR 0
139#define ENV_LIBAGESA 1
140#define ENV_STRING "libagesa"
141
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500142#else
143/*
144 * Default case of nothing set for random blob generation using
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200145 * create_class_compiler that isn't bound to a stage.
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500146 */
Julius Werner99f46832018-05-16 14:14:04 -0700147#define ENV_DECOMPRESSOR 0
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500148#define ENV_BOOTBLOCK 0
149#define ENV_ROMSTAGE 0
150#define ENV_RAMSTAGE 0
151#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700152#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500153#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500154#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200155#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600156#define ENV_STRING "UNKNOWN"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200157#endif
Kyösti Mälkkief844012013-06-25 23:17:43 +0300158
Julius Wernerd3634c12015-11-13 13:28:41 -0800159/* Define helpers about the current architecture, based on toolchain.inc. */
160
161#if defined(__ARCH_arm__)
162#define ENV_ARM 1
163#define ENV_ARM64 0
164#if __COREBOOT_ARM_ARCH__ == 4
165#define ENV_ARMV4 1
166#define ENV_ARMV7 0
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100167#define ENV_ARCH "armv4"
Julius Wernerd3634c12015-11-13 13:28:41 -0800168#elif __COREBOOT_ARM_ARCH__ == 7
169#define ENV_ARMV4 0
170#define ENV_ARMV7 1
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100171#define ENV_ARCH "armv7"
Hakim Giydan43e5b572016-09-08 10:13:59 -0700172#if defined(__COREBOOT_ARM_V7_A__)
173#define ENV_ARMV7_A 1
174#define ENV_ARMV7_M 0
175#define ENV_ARMV7_R 0
176#elif defined(__COREBOOT_ARM_V7_M__)
177#define ENV_ARMV7_A 0
178#define ENV_ARMV7_M 1
179#define ENV_ARMV7_R 0
180#elif defined(__COREBOOT_ARM_V7_R__)
181#define ENV_ARMV7_A 0
182#define ENV_ARMV7_M 0
183#define ENV_ARMV7_R 1
184#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800185#else
186#define ENV_ARMV4 0
187#define ENV_ARMV7 0
188#endif
189#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800190#define ENV_RISCV 0
191#define ENV_X86 0
192#define ENV_X86_32 0
193#define ENV_X86_64 0
194
195#elif defined(__ARCH_arm64__)
196#define ENV_ARM 0
197#define ENV_ARM64 1
198#define ENV_ARMV4 0
199#define ENV_ARMV7 0
200#if __COREBOOT_ARM_ARCH__ == 8
201#define ENV_ARMV8 1
202#else
203#define ENV_ARMV8 0
204#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800205#define ENV_RISCV 0
206#define ENV_X86 0
207#define ENV_X86_32 0
208#define ENV_X86_64 0
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100209#define ENV_ARCH "aarch64"
Julius Wernerd3634c12015-11-13 13:28:41 -0800210
211#elif defined(__ARCH_riscv__)
212#define ENV_ARM 0
213#define ENV_ARM64 0
214#define ENV_ARMV4 0
215#define ENV_ARMV7 0
216#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800217#define ENV_RISCV 1
218#define ENV_X86 0
219#define ENV_X86_32 0
220#define ENV_X86_64 0
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100221#define ENV_ARCH "riscv"
Julius Wernerd3634c12015-11-13 13:28:41 -0800222
223#elif defined(__ARCH_x86_32__)
224#define ENV_ARM 0
225#define ENV_ARM64 0
226#define ENV_ARMV4 0
227#define ENV_ARMV7 0
228#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800229#define ENV_RISCV 0
230#define ENV_X86 1
231#define ENV_X86_32 1
232#define ENV_X86_64 0
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100233#define ENV_ARCH "x86_32"
Julius Wernerd3634c12015-11-13 13:28:41 -0800234
235#elif defined(__ARCH_x86_64__)
236#define ENV_ARM 0
237#define ENV_ARM64 0
238#define ENV_ARMV4 0
239#define ENV_ARMV7 0
240#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800241#define ENV_RISCV 0
242#define ENV_X86 1
243#define ENV_X86_32 0
244#define ENV_X86_64 1
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100245#define ENV_ARCH "x86_64"
Julius Wernerd3634c12015-11-13 13:28:41 -0800246
247#else
248#define ENV_ARM 0
249#define ENV_ARM64 0
250#define ENV_ARMV4 0
251#define ENV_ARMV7 0
252#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800253#define ENV_RISCV 0
254#define ENV_X86 0
255#define ENV_X86_32 0
256#define ENV_X86_64 0
Patrick Rudolph5e5c1da2021-11-30 13:56:07 +0100257#define ENV_ARCH "unknown"
Julius Wernerd3634c12015-11-13 13:28:41 -0800258
259#endif
260
Subrata Banik63022032019-05-11 20:12:20 +0530261#if CONFIG(RAMPAYLOAD)
262/* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
263#define ENV_PAYLOAD_LOADER ENV_POSTCAR
264#else
Ronald G. Minnich42493482019-05-09 17:09:25 +0000265/* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
266 * For now, that is the ramstage. */
267#define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
Subrata Banik63022032019-05-11 20:12:20 +0530268#endif
Ronald G. Minnich42493482019-05-09 17:09:25 +0000269
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300270#define ENV_ROMSTAGE_OR_BEFORE \
Kyösti Mälkkif704b542019-09-14 14:59:38 +0300271 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
Martin Rothb9c2ecf2020-06-10 20:35:35 -0600272 (ENV_SEPARATE_VERSTAGE && !CONFIG(VBOOT_STARTS_IN_ROMSTAGE)))
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300273
Kyösti Mälkki7336f972020-06-08 06:05:03 +0300274#if ENV_X86
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300275/* Indicates memory layout is determined with arch/x86/car.ld. */
Martin Roth8418fd42019-04-22 16:26:23 -0600276#define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300277/* No .data sections with execute-in-place from ROM. */
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200278#define ENV_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300279#else
280/* Both .data and .bss, sometimes SRAM not DRAM. */
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200281#define ENV_HAS_DATA_SECTION 1
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300282#define ENV_CACHE_AS_RAM 0
283#endif
284
Arthur Heymans9efb0c02020-11-30 14:03:51 +0100285/* Indicates if the stage uses the _bss region defined in arch/x86/car.ld */
286#define ENV_SEPARATE_BSS (ENV_CACHE_AS_RAM && (ENV_BOOTBLOCK || !CONFIG(NO_XIP_EARLY_STAGES)))
287
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300288/* Currently rmodules, ramstage and smm have heap. */
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200289#define ENV_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300290
Martin Roth44d53472020-07-23 18:27:58 -0600291/* Set USER_SPACE in the makefile for the rare code that runs in userspace */
292#if defined(__USER_SPACE__)
293#define ENV_USER_SPACE 1
294#else
295#define ENV_USER_SPACE 0
296#endif
297
Martin Roth1594e8f2020-07-15 13:57:54 -0600298/* Define the first stage to run */
299#if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
300#define ENV_INITIAL_STAGE ENV_SEPARATE_VERSTAGE
301#else
302#define ENV_INITIAL_STAGE ENV_BOOTBLOCK
303#endif
304
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +0300305#define ENV_CREATES_CBMEM ENV_ROMSTAGE
306#define ENV_HAS_CBMEM (ENV_ROMSTAGE | ENV_POSTCAR | ENV_RAMSTAGE)
Kyösti Mälkki11cac782022-04-07 07:16:48 +0300307#define ENV_RAMINIT ENV_ROMSTAGE
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +0300308
Kyösti Mälkki04c32282021-11-10 03:10:58 +0200309#if ENV_X86
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200310#define ENV_HAS_SPINLOCKS !ENV_ROMSTAGE_OR_BEFORE
Kyösti Mälkki04c32282021-11-10 03:10:58 +0200311#elif ENV_RISCV
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200312#define ENV_HAS_SPINLOCKS 1
Kyösti Mälkki04c32282021-11-10 03:10:58 +0200313#else
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200314#define ENV_HAS_SPINLOCKS 0
Kyösti Mälkki04c32282021-11-10 03:10:58 +0200315#endif
316
317/* When set <arch/smp/spinlock.h> is included for the spinlock implementation. */
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200318#define ENV_SUPPORTS_SMP (CONFIG(SMP) && ENV_HAS_SPINLOCKS)
Kyösti Mälkki04c32282021-11-10 03:10:58 +0200319
Raul E Rangeld8f07c12021-11-22 13:43:49 -0700320#if ENV_X86 && CONFIG(COOP_MULTITASKING) && (ENV_RAMSTAGE || ENV_ROMSTAGE)
321/* TODO: Enable in all x86 stages */
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200322#define ENV_SUPPORTS_COOP 1
Raul E Rangeld8f07c12021-11-22 13:43:49 -0700323#else
Arthur Heymans6acc05e2022-05-12 18:01:13 +0200324#define ENV_SUPPORTS_COOP 0
Raul E Rangeld8f07c12021-11-22 13:43:49 -0700325#endif
326
Patrick Rudolpha626d272018-04-18 10:13:32 +0200327/**
328 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
329 * PCI, PNP and CPU functions operate without use of devicetree. The reason
330 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
331 * no known requirement that devicetree would be needed during that stage.
332 *
333 * For ramstage individual source file may define __SIMPLE_DEVICE__
334 * before including any header files to force that particular source
335 * be built with simple device model.
Patrick Rudolpha626d272018-04-18 10:13:32 +0200336 */
337
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300338#if !ENV_RAMSTAGE
Patrick Rudolpha626d272018-04-18 10:13:32 +0200339#define __SIMPLE_DEVICE__
340#endif
341
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200342#endif /* _RULES_H */