blob: 89fdd21cb2ef66f8b9e0bf48ff22a02fd49e0a46 [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
Ben Gardneraa5f5b12015-11-19 10:48:47 -060030#define ENV_STRING "bootblock"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020031
Patrick Georgi815f4bf2015-04-28 22:43:31 +020032#elif defined(__ROMSTAGE__)
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020033#define ENV_BOOTBLOCK 0
34#define ENV_ROMSTAGE 1
35#define ENV_RAMSTAGE 0
36#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020037#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050038#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050039#define ENV_POSTCAR 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060040#define ENV_STRING "romstage"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020041
42#elif defined(__SMM__)
43#define ENV_BOOTBLOCK 0
44#define ENV_ROMSTAGE 0
45#define ENV_RAMSTAGE 0
46#define ENV_SMM 1
Patrick Georgicc8171f2015-04-28 22:26:23 +020047#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050048#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050049#define ENV_POSTCAR 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060050#define ENV_STRING "smm"
Patrick Georgicc8171f2015-04-28 22:26:23 +020051
52#elif defined(__VERSTAGE__)
53#define ENV_BOOTBLOCK 0
54#define ENV_ROMSTAGE 0
55#define ENV_RAMSTAGE 0
56#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020057#define ENV_VERSTAGE 1
Aaron Durbindde76292015-09-05 12:59:26 -050058#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050059#define ENV_POSTCAR 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060060#define ENV_STRING "verstage"
Furquan Shaikhabde3b52014-08-26 15:39:51 -070061
Aaron Durbincd96c5c2015-09-04 16:28:15 -050062#elif defined(__RAMSTAGE__)
Kyösti Mälkkie8792be2014-02-26 15:19:04 +020063#define ENV_BOOTBLOCK 0
64#define ENV_ROMSTAGE 0
65#define ENV_RAMSTAGE 1
66#define ENV_SMM 0
Patrick Georgicc8171f2015-04-28 22:26:23 +020067#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -050068#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -050069#define ENV_POSTCAR 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060070#define ENV_STRING "ramstage"
Aaron Durbindde76292015-09-05 12:59:26 -050071
72#elif defined(__RMODULE__)
73#define ENV_BOOTBLOCK 0
74#define ENV_ROMSTAGE 0
75#define ENV_RAMSTAGE 0
76#define ENV_SMM 0
Aaron Durbindde76292015-09-05 12:59:26 -050077#define ENV_VERSTAGE 0
78#define ENV_RMODULE 1
Aaron Durbin7f8afe02016-03-18 12:21:23 -050079#define ENV_POSTCAR 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -060080#define ENV_STRING "rmodule"
Aaron Durbincd96c5c2015-09-04 16:28:15 -050081
Aaron Durbin7f8afe02016-03-18 12:21:23 -050082#elif defined(__POSTCAR__)
83#define ENV_BOOTBLOCK 0
84#define ENV_ROMSTAGE 0
85#define ENV_RAMSTAGE 0
86#define ENV_SMM 0
87#define ENV_VERSTAGE 0
88#define ENV_RMODULE 0
89#define ENV_POSTCAR 1
90#define ENV_STRING "postcar"
91
Aaron Durbincd96c5c2015-09-04 16:28:15 -050092#else
93/*
94 * Default case of nothing set for random blob generation using
95 * create_class_compiler that isn't bound to a stage. Also AGESA
96 * apparently builds things compeletely separate from coreboot's
97 * build infrastructure -- hardcoding its own rules.
98 */
99#define ENV_BOOTBLOCK 0
100#define ENV_ROMSTAGE 0
101#define ENV_RAMSTAGE 0
102#define ENV_SMM 0
Aaron Durbincd96c5c2015-09-04 16:28:15 -0500103#define ENV_VERSTAGE 0
Aaron Durbindde76292015-09-05 12:59:26 -0500104#define ENV_RMODULE 0
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500105#define ENV_POSTCAR 0
Ben Gardneraa5f5b12015-11-19 10:48:47 -0600106#define ENV_STRING "UNKNOWN"
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200107#endif
Kyösti Mälkkief844012013-06-25 23:17:43 +0300108
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500109/* For pre-DRAM stages and post-CAR always build with simple device model, ie.
110 * PCI, PNP and CPU functions operate without use of devicetree. The reason
111 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
112 * no known requirement that devicetree would be needed during that stage.
Kyösti Mälkkief844012013-06-25 23:17:43 +0300113 *
114 * For ramstage individual source file may define __SIMPLE_DEVICE__
115 * before including any header files to force that particular source
116 * be built with simple device model.
117 */
118
Aaron Durbin7f8afe02016-03-18 12:21:23 -0500119#if defined(__PRE_RAM__) || ENV_SMM || ENV_POSTCAR
Kyösti Mälkkief844012013-06-25 23:17:43 +0300120#define __SIMPLE_DEVICE__
121#endif
122
Julius Wernerd3634c12015-11-13 13:28:41 -0800123/* Define helpers about the current architecture, based on toolchain.inc. */
124
125#if defined(__ARCH_arm__)
126#define ENV_ARM 1
127#define ENV_ARM64 0
128#if __COREBOOT_ARM_ARCH__ == 4
129#define ENV_ARMV4 1
130#define ENV_ARMV7 0
131#elif __COREBOOT_ARM_ARCH__ == 7
132#define ENV_ARMV4 0
133#define ENV_ARMV7 1
134#else
135#define ENV_ARMV4 0
136#define ENV_ARMV7 0
137#endif
138#define ENV_ARMV8 0
139#define ENV_MIPS 0
140#define ENV_RISCV 0
141#define ENV_X86 0
142#define ENV_X86_32 0
143#define ENV_X86_64 0
144
145#elif defined(__ARCH_arm64__)
146#define ENV_ARM 0
147#define ENV_ARM64 1
148#define ENV_ARMV4 0
149#define ENV_ARMV7 0
150#if __COREBOOT_ARM_ARCH__ == 8
151#define ENV_ARMV8 1
152#else
153#define ENV_ARMV8 0
154#endif
155#define ENV_MIPS 0
156#define ENV_RISCV 0
157#define ENV_X86 0
158#define ENV_X86_32 0
159#define ENV_X86_64 0
160
161#elif defined(__ARCH_mips__)
162#define ENV_ARM 0
163#define ENV_ARM64 0
164#define ENV_ARMV4 0
165#define ENV_ARMV7 0
166#define ENV_ARMV8 0
167#define ENV_MIPS 1
168#define ENV_RISCV 0
169#define ENV_X86 0
170#define ENV_X86_32 0
171#define ENV_X86_64 0
172
173#elif defined(__ARCH_riscv__)
174#define ENV_ARM 0
175#define ENV_ARM64 0
176#define ENV_ARMV4 0
177#define ENV_ARMV7 0
178#define ENV_ARMV8 0
179#define ENV_MIPS 0
180#define ENV_RISCV 1
181#define ENV_X86 0
182#define ENV_X86_32 0
183#define ENV_X86_64 0
184
185#elif defined(__ARCH_x86_32__)
186#define ENV_ARM 0
187#define ENV_ARM64 0
188#define ENV_ARMV4 0
189#define ENV_ARMV7 0
190#define ENV_ARMV8 0
191#define ENV_MIPS 0
192#define ENV_RISCV 0
193#define ENV_X86 1
194#define ENV_X86_32 1
195#define ENV_X86_64 0
196
197#elif defined(__ARCH_x86_64__)
198#define ENV_ARM 0
199#define ENV_ARM64 0
200#define ENV_ARMV4 0
201#define ENV_ARMV7 0
202#define ENV_ARMV8 0
203#define ENV_MIPS 0
204#define ENV_RISCV 0
205#define ENV_X86 1
206#define ENV_X86_32 0
207#define ENV_X86_64 1
208
209#else
210#define ENV_ARM 0
211#define ENV_ARM64 0
212#define ENV_ARMV4 0
213#define ENV_ARMV7 0
214#define ENV_ARMV8 0
215#define ENV_MIPS 0
216#define ENV_RISCV 0
217#define ENV_X86 0
218#define ENV_X86_32 0
219#define ENV_X86_64 0
220
221#endif
222
Kyösti Mälkkie8792be2014-02-26 15:19:04 +0200223#endif /* _RULES_H */