blob: 6af25a9577eda6fb965baf26126ad1a39d42557c [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
6/* Useful helpers to tell whether the code is executing in bootblock,
7 * romstage, ramstage or SMM.
8 */
9
Julius Werner99f46832018-05-16 14:14:04 -070010#if defined(__DECOMPRESSOR__)
11#define ENV_DECOMPRESSOR 1
12#define ENV_BOOTBLOCK 0
13#define ENV_ROMSTAGE 0
14#define ENV_RAMSTAGE 0
15#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070016#define ENV_SEPARATE_VERSTAGE 0
Julius Werner99f46832018-05-16 14:14:04 -070017#define ENV_RMODULE 0
18#define ENV_POSTCAR 0
19#define ENV_LIBAGESA 0
20#define ENV_STRING "decompressor"
21
22#elif defined(__BOOTBLOCK__)
23#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020024#define ENV_BOOTBLOCK 1
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
Aaron Durbindde76292015-09-05 12:59:26 -050029#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050030#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020031#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060032#define ENV_STRING "bootblock"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020033
Patrick Georgi815f4bf2015-04-28 22:43:31 +020034#elif defined(__ROMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070035#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020036#define ENV_BOOTBLOCK 0
37#define ENV_ROMSTAGE 1
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 "romstage"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020045
46#elif defined(__SMM__)
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 0
50#define ENV_RAMSTAGE 0
51#define ENV_SMM 1
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 "smm"
Patrick Georgicc8171f2015-04-28 22:26:23 +020057
Julius Werner21a40532020-04-21 16:03:53 -070058/*
59 * NOTE: "verstage" code may either run as a separate stage or linked into the
60 * bootblock/romstage, depending on the setting of CONFIG_SEPARATE_VERSTAGE. The
61 * ENV_SEPARATE_VERSTAGE macro will only return true for "verstage" code when
62 * CONFIG_SEPARATE_VERSTAGE=y, otherwise that code will have ENV_BOOTBLOCK or
63 * ENV_ROMSTAGE set (depending on the CONFIG_VBOOT_STARTS_IN_... options).
64 */
Patrick Georgicc8171f2015-04-28 22:26:23 +020065#elif defined(__VERSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070066#define ENV_DECOMPRESSOR 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020067#define ENV_BOOTBLOCK 0
68#define ENV_ROMSTAGE 0
69#define ENV_RAMSTAGE 0
70#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070071#define ENV_SEPARATE_VERSTAGE 1
Aaron Durbindde76292015-09-05 12:59:26 -050072#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050073#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020074#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060075#define ENV_STRING "verstage"
Furquan Shaikhabde3b52014-08-26 15:39:51 -070076
Aaron Durbincd96c5c2015-09-04 16:28:15 -050077#elif defined(__RAMSTAGE__)
Julius Werner99f46832018-05-16 14:14:04 -070078#define ENV_DECOMPRESSOR 0
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020079#define ENV_BOOTBLOCK 0
80#define ENV_ROMSTAGE 0
81#define ENV_RAMSTAGE 1
82#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070083#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050084#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050085#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020086#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060087#define ENV_STRING "ramstage"
Aaron Durbindde76292015-09-05 12:59:26 -050088
89#elif defined(__RMODULE__)
Julius Werner99f46832018-05-16 14:14:04 -070090#define ENV_DECOMPRESSOR 0
Aaron Durbindde76292015-09-05 12:59:26 -050091#define ENV_BOOTBLOCK 0
92#define ENV_ROMSTAGE 0
93#define ENV_RAMSTAGE 0
94#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -070095#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050096#define ENV_RMODULE 1
Aaron Durbin7f8afe02016-03-18 12:21:23 -050097#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020098#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060099#define ENV_STRING "rmodule"
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500100
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500101#elif defined(__POSTCAR__)
Julius Werner99f46832018-05-16 14:14:04 -0700102#define ENV_DECOMPRESSOR 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500103#define ENV_BOOTBLOCK 0
104#define ENV_ROMSTAGE 0
105#define ENV_RAMSTAGE 0
106#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700107#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500108#define ENV_RMODULE 0
109#define ENV_POSTCAR 1
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200110#define ENV_LIBAGESA 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500111#define ENV_STRING "postcar"
112
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200113#elif defined(__LIBAGESA__)
Julius Werner99f46832018-05-16 14:14:04 -0700114#define ENV_DECOMPRESSOR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200115#define ENV_BOOTBLOCK 0
116#define ENV_ROMSTAGE 0
117#define ENV_RAMSTAGE 0
118#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700119#define ENV_SEPARATE_VERSTAGE 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200120#define ENV_RMODULE 0
121#define ENV_POSTCAR 0
122#define ENV_LIBAGESA 1
123#define ENV_STRING "libagesa"
124
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500125#else
126/*
127 * Default case of nothing set for random blob generation using
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200128 * create_class_compiler that isn't bound to a stage.
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500129 */
Julius Werner99f46832018-05-16 14:14:04 -0700130#define ENV_DECOMPRESSOR 0
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500131#define ENV_BOOTBLOCK 0
132#define ENV_ROMSTAGE 0
133#define ENV_RAMSTAGE 0
134#define ENV_SMM 0
Julius Werner21a40532020-04-21 16:03:53 -0700135#define ENV_SEPARATE_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500136#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500137#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200138#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600139#define ENV_STRING "UNKNOWN"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200140#endif
Kyösti Mälkkief844012013-06-25 23:17:43 +0300141
Julius Wernerd3634c12015-11-13 13:28:41 -0800142/* Define helpers about the current architecture, based on toolchain.inc. */
143
144#if defined(__ARCH_arm__)
145#define ENV_ARM 1
146#define ENV_ARM64 0
147#if __COREBOOT_ARM_ARCH__ == 4
148#define ENV_ARMV4 1
149#define ENV_ARMV7 0
150#elif __COREBOOT_ARM_ARCH__ == 7
151#define ENV_ARMV4 0
152#define ENV_ARMV7 1
Hakim Giydan43e5b572016-09-08 10:13:59 -0700153#if defined(__COREBOOT_ARM_V7_A__)
154#define ENV_ARMV7_A 1
155#define ENV_ARMV7_M 0
156#define ENV_ARMV7_R 0
157#elif defined(__COREBOOT_ARM_V7_M__)
158#define ENV_ARMV7_A 0
159#define ENV_ARMV7_M 1
160#define ENV_ARMV7_R 0
161#elif defined(__COREBOOT_ARM_V7_R__)
162#define ENV_ARMV7_A 0
163#define ENV_ARMV7_M 0
164#define ENV_ARMV7_R 1
165#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800166#else
167#define ENV_ARMV4 0
168#define ENV_ARMV7 0
169#endif
170#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800171#define ENV_RISCV 0
172#define ENV_X86 0
173#define ENV_X86_32 0
174#define ENV_X86_64 0
175
176#elif defined(__ARCH_arm64__)
177#define ENV_ARM 0
178#define ENV_ARM64 1
179#define ENV_ARMV4 0
180#define ENV_ARMV7 0
181#if __COREBOOT_ARM_ARCH__ == 8
182#define ENV_ARMV8 1
183#else
184#define ENV_ARMV8 0
185#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800186#define ENV_RISCV 0
187#define ENV_X86 0
188#define ENV_X86_32 0
189#define ENV_X86_64 0
190
191#elif defined(__ARCH_riscv__)
192#define ENV_ARM 0
193#define ENV_ARM64 0
194#define ENV_ARMV4 0
195#define ENV_ARMV7 0
196#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800197#define ENV_RISCV 1
198#define ENV_X86 0
199#define ENV_X86_32 0
200#define ENV_X86_64 0
201
202#elif defined(__ARCH_x86_32__)
203#define ENV_ARM 0
204#define ENV_ARM64 0
205#define ENV_ARMV4 0
206#define ENV_ARMV7 0
207#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800208#define ENV_RISCV 0
209#define ENV_X86 1
210#define ENV_X86_32 1
211#define ENV_X86_64 0
212
213#elif defined(__ARCH_x86_64__)
214#define ENV_ARM 0
215#define ENV_ARM64 0
216#define ENV_ARMV4 0
217#define ENV_ARMV7 0
218#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800219#define ENV_RISCV 0
220#define ENV_X86 1
221#define ENV_X86_32 0
222#define ENV_X86_64 1
223
224#else
225#define ENV_ARM 0
226#define ENV_ARM64 0
227#define ENV_ARMV4 0
228#define ENV_ARMV7 0
229#define ENV_ARMV8 0
Julius Wernerd3634c12015-11-13 13:28:41 -0800230#define ENV_RISCV 0
231#define ENV_X86 0
232#define ENV_X86_32 0
233#define ENV_X86_64 0
234
235#endif
236
Subrata Banik63022032019-05-11 20:12:20 +0530237#if CONFIG(RAMPAYLOAD)
238/* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
239#define ENV_PAYLOAD_LOADER ENV_POSTCAR
240#else
Ronald G. Minnich42493482019-05-09 17:09:25 +0000241/* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
242 * For now, that is the ramstage. */
243#define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
Subrata Banik63022032019-05-11 20:12:20 +0530244#endif
Ronald G. Minnich42493482019-05-09 17:09:25 +0000245
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300246#define ENV_ROMSTAGE_OR_BEFORE \
Kyösti Mälkkif704b542019-09-14 14:59:38 +0300247 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
Julius Werner21a40532020-04-21 16:03:53 -0700248 (ENV_SEPARATE_VERSTAGE && CONFIG(VBOOT_STARTS_IN_BOOTBLOCK)))
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300249
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300250#if CONFIG(ARCH_X86)
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300251/* Indicates memory layout is determined with arch/x86/car.ld. */
Martin Roth8418fd42019-04-22 16:26:23 -0600252#define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300253/* No .data sections with execute-in-place from ROM. */
254#define ENV_STAGE_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
Kyösti Mälkkia165c072019-08-22 09:44:44 +0300255/* No .bss sections for stage with CAR teardown. */
Arthur Heymans8601afb2019-11-20 22:25:30 +0100256#define ENV_STAGE_HAS_BSS_SECTION 1
Kyösti Mälkkif2cc52b2019-08-21 07:15:38 +0300257#else
258/* Both .data and .bss, sometimes SRAM not DRAM. */
259#define ENV_STAGE_HAS_DATA_SECTION 1
260#define ENV_STAGE_HAS_BSS_SECTION 1
261#define ENV_CACHE_AS_RAM 0
262#endif
263
264/* Currently rmodules, ramstage and smm have heap. */
265#define ENV_STAGE_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
266
Patrick Rudolpha626d272018-04-18 10:13:32 +0200267/**
268 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
269 * PCI, PNP and CPU functions operate without use of devicetree. The reason
270 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
271 * no known requirement that devicetree would be needed during that stage.
272 *
273 * For ramstage individual source file may define __SIMPLE_DEVICE__
274 * before including any header files to force that particular source
275 * be built with simple device model.
Patrick Rudolpha626d272018-04-18 10:13:32 +0200276 */
277
Kyösti Mälkki21160a72019-08-17 17:29:36 +0300278#if !ENV_RAMSTAGE
Patrick Rudolpha626d272018-04-18 10:13:32 +0200279#define __SIMPLE_DEVICE__
280#endif
281
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200282#endif /* _RULES_H */