blob: 0f212318a6cb4facd28326b2b8898075fe0ee6b7 [file] [log] [blame]
Kyösti Mälkkief844012013-06-25 23:17:43 +03001/*
2 * This file is part of the coreboot project.
3 *
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Kyösti Mälkkief844012013-06-25 23:17:43 +030013 */
14
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020015#ifndef _RULES_H
16#define _RULES_H
17
18/* Useful helpers to tell whether the code is executing in bootblock,
19 * romstage, ramstage or SMM.
20 */
21
Patrick Georgi56b83092015-04-02 19:44:19 +020022#if defined(__BOOTBLOCK__)
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020023#define ENV_BOOTBLOCK 1
24#define ENV_ROMSTAGE 0
25#define ENV_RAMSTAGE 0
26#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020027#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050028#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050029#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020030#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060031#define ENV_STRING "bootblock"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020032
Patrick Georgi815f4bf2015-04-28 22:43:31 +020033#elif defined(__ROMSTAGE__)
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020034#define ENV_BOOTBLOCK 0
35#define ENV_ROMSTAGE 1
36#define ENV_RAMSTAGE 0
37#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020038#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050039#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050040#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020041#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060042#define ENV_STRING "romstage"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020043
44#elif defined(__SMM__)
45#define ENV_BOOTBLOCK 0
46#define ENV_ROMSTAGE 0
47#define ENV_RAMSTAGE 0
48#define ENV_SMM 1
Patrick Georgicc8171f2015-04-28 22:26:23 +020049#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050050#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050051#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020052#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060053#define ENV_STRING "smm"
Patrick Georgicc8171f2015-04-28 22:26:23 +020054
55#elif defined(__VERSTAGE__)
56#define ENV_BOOTBLOCK 0
57#define ENV_ROMSTAGE 0
58#define ENV_RAMSTAGE 0
59#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020060#define ENV_VERSTAGE 1
Aaron Durbindde76292015-09-05 12:59:26 -050061#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050062#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020063#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060064#define ENV_STRING "verstage"
Furquan Shaikhabde3b52014-08-26 15:39:51 -070065
Aaron Durbincd96c5c2015-09-04 16:28:15 -050066#elif defined(__RAMSTAGE__)
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020067#define ENV_BOOTBLOCK 0
68#define ENV_ROMSTAGE 0
69#define ENV_RAMSTAGE 1
70#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020071#define ENV_VERSTAGE 0
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 "ramstage"
Aaron Durbindde76292015-09-05 12:59:26 -050076
77#elif defined(__RMODULE__)
78#define ENV_BOOTBLOCK 0
79#define ENV_ROMSTAGE 0
80#define ENV_RAMSTAGE 0
81#define ENV_SMM 0
Aaron Durbindde76292015-09-05 12:59:26 -050082#define ENV_VERSTAGE 0
83#define ENV_RMODULE 1
Aaron Durbin7f8afe02016-03-18 12:21:23 -050084#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +020085#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060086#define ENV_STRING "rmodule"
Aaron Durbincd96c5c2015-09-04 16:28:15 -050087
Aaron Durbin7f8afe02016-03-18 12:21:23 -050088#elif defined(__POSTCAR__)
89#define ENV_BOOTBLOCK 0
90#define ENV_ROMSTAGE 0
91#define ENV_RAMSTAGE 0
92#define ENV_SMM 0
93#define ENV_VERSTAGE 0
94#define ENV_RMODULE 0
95#define ENV_POSTCAR 1
Kyösti Mälkkia405a582017-03-02 13:01:58 +020096#define ENV_LIBAGESA 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050097#define ENV_STRING "postcar"
98
Kyösti Mälkkia405a582017-03-02 13:01:58 +020099#elif defined(__LIBAGESA__)
100#define ENV_BOOTBLOCK 0
101#define ENV_ROMSTAGE 0
102#define ENV_RAMSTAGE 0
103#define ENV_SMM 0
104#define ENV_VERSTAGE 0
105#define ENV_RMODULE 0
106#define ENV_POSTCAR 0
107#define ENV_LIBAGESA 1
108#define ENV_STRING "libagesa"
109
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500110#else
111/*
112 * Default case of nothing set for random blob generation using
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200113 * create_class_compiler that isn't bound to a stage.
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500114 */
115#define ENV_BOOTBLOCK 0
116#define ENV_ROMSTAGE 0
117#define ENV_RAMSTAGE 0
118#define ENV_SMM 0
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500119#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500120#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500121#define ENV_POSTCAR 0
Kyösti Mälkkia405a582017-03-02 13:01:58 +0200122#define ENV_LIBAGESA 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600123#define ENV_STRING "UNKNOWN"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200124#endif
Kyösti Mälkkief844012013-06-25 23:17:43 +0300125
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500126/* For pre-DRAM stages and post-CAR always build with simple device model, ie.
127 * PCI, PNP and CPU functions operate without use of devicetree. The reason
128 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
129 * no known requirement that devicetree would be needed during that stage.
Kyösti Mälkkief844012013-06-25 23:17:43 +0300130 *
131 * For ramstage individual source file may define __SIMPLE_DEVICE__
132 * before including any header files to force that particular source
133 * be built with simple device model.
134 */
135
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500136#if defined(__PRE_RAM__) || ENV_SMM || ENV_POSTCAR
Kyösti Mälkkief844012013-06-25 23:17:43 +0300137#define __SIMPLE_DEVICE__
138#endif
139
Julius Wernerd3634c12015-11-13 13:28:41 -0800140/* Define helpers about the current architecture, based on toolchain.inc. */
141
142#if defined(__ARCH_arm__)
143#define ENV_ARM 1
144#define ENV_ARM64 0
145#if __COREBOOT_ARM_ARCH__ == 4
146#define ENV_ARMV4 1
147#define ENV_ARMV7 0
148#elif __COREBOOT_ARM_ARCH__ == 7
149#define ENV_ARMV4 0
150#define ENV_ARMV7 1
Hakim Giydan43e5b572016-09-08 10:13:59 -0700151#if defined(__COREBOOT_ARM_V7_A__)
152#define ENV_ARMV7_A 1
153#define ENV_ARMV7_M 0
154#define ENV_ARMV7_R 0
155#elif defined(__COREBOOT_ARM_V7_M__)
156#define ENV_ARMV7_A 0
157#define ENV_ARMV7_M 1
158#define ENV_ARMV7_R 0
159#elif defined(__COREBOOT_ARM_V7_R__)
160#define ENV_ARMV7_A 0
161#define ENV_ARMV7_M 0
162#define ENV_ARMV7_R 1
163#endif
Julius Wernerd3634c12015-11-13 13:28:41 -0800164#else
165#define ENV_ARMV4 0
166#define ENV_ARMV7 0
167#endif
168#define ENV_ARMV8 0
169#define ENV_MIPS 0
170#define ENV_RISCV 0
171#define ENV_X86 0
172#define ENV_X86_32 0
173#define ENV_X86_64 0
174
175#elif defined(__ARCH_arm64__)
176#define ENV_ARM 0
177#define ENV_ARM64 1
178#define ENV_ARMV4 0
179#define ENV_ARMV7 0
180#if __COREBOOT_ARM_ARCH__ == 8
181#define ENV_ARMV8 1
182#else
183#define ENV_ARMV8 0
184#endif
185#define ENV_MIPS 0
186#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_mips__)
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
197#define ENV_MIPS 1
198#define ENV_RISCV 0
199#define ENV_X86 0
200#define ENV_X86_32 0
201#define ENV_X86_64 0
202
203#elif defined(__ARCH_riscv__)
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
209#define ENV_MIPS 0
210#define ENV_RISCV 1
211#define ENV_X86 0
212#define ENV_X86_32 0
213#define ENV_X86_64 0
214
215#elif defined(__ARCH_x86_32__)
216#define ENV_ARM 0
217#define ENV_ARM64 0
218#define ENV_ARMV4 0
219#define ENV_ARMV7 0
220#define ENV_ARMV8 0
221#define ENV_MIPS 0
222#define ENV_RISCV 0
223#define ENV_X86 1
224#define ENV_X86_32 1
225#define ENV_X86_64 0
226
227#elif defined(__ARCH_x86_64__)
228#define ENV_ARM 0
229#define ENV_ARM64 0
230#define ENV_ARMV4 0
231#define ENV_ARMV7 0
232#define ENV_ARMV8 0
233#define ENV_MIPS 0
234#define ENV_RISCV 0
235#define ENV_X86 1
236#define ENV_X86_32 0
237#define ENV_X86_64 1
238
239#else
240#define ENV_ARM 0
241#define ENV_ARM64 0
242#define ENV_ARMV4 0
243#define ENV_ARMV7 0
244#define ENV_ARMV8 0
245#define ENV_MIPS 0
246#define ENV_RISCV 0
247#define ENV_X86 0
248#define ENV_X86_32 0
249#define ENV_X86_64 0
250
251#endif
252
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200253#endif /* _RULES_H */