device/azalia_device.c: Add option to lock down GCAP
[coreboot.git] / src / include / rules.h
blobec3d22d7d1d6c6b7419d21634a38cb61648becd9
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef _RULES_H
4 #define _RULES_H
6 #if defined(__TEST__)
7 #define ENV_TEST 1
8 #else
9 #define ENV_TEST 0
10 #endif
12 #if defined(__TIMELESS__)
13 #define ENV_TIMELESS 1
14 #else
15 #define ENV_TIMELESS 0
16 #endif
18 /* Useful helpers to tell whether the code is executing in bootblock,
19 * romstage, ramstage or SMM.
22 #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
28 #define ENV_SEPARATE_VERSTAGE 0
29 #define ENV_RMODULE 0
30 #define ENV_POSTCAR 0
31 #define ENV_LIBAGESA 0
32 #define ENV_STRING "decompressor"
34 #elif defined(__BOOTBLOCK__)
35 #define ENV_DECOMPRESSOR 0
36 #define ENV_BOOTBLOCK 1
37 #define ENV_ROMSTAGE 0
38 #define ENV_RAMSTAGE 0
39 #define ENV_SMM 0
40 #define ENV_SEPARATE_VERSTAGE 0
41 #define ENV_RMODULE 0
42 #define ENV_POSTCAR 0
43 #define ENV_LIBAGESA 0
44 #define ENV_STRING "bootblock"
46 #elif defined(__ROMSTAGE__)
47 #define ENV_DECOMPRESSOR 0
48 #define ENV_BOOTBLOCK 0
49 #define ENV_ROMSTAGE 1
50 #define ENV_RAMSTAGE 0
51 #define ENV_SMM 0
52 #define ENV_SEPARATE_VERSTAGE 0
53 #define ENV_RMODULE 0
54 #define ENV_POSTCAR 0
55 #define ENV_LIBAGESA 0
56 #define ENV_STRING "romstage"
58 #elif defined(__SMM__)
59 #define ENV_DECOMPRESSOR 0
60 #define ENV_BOOTBLOCK 0
61 #define ENV_ROMSTAGE 0
62 #define ENV_RAMSTAGE 0
63 #define ENV_SMM 1
64 #define ENV_SEPARATE_VERSTAGE 0
65 #define ENV_RMODULE 0
66 #define ENV_POSTCAR 0
67 #define ENV_LIBAGESA 0
68 #define ENV_STRING "smm"
71 * NOTE: "verstage" code may either run as a separate stage or linked into the
72 * 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).
78 #elif defined(__VERSTAGE__)
79 #define ENV_DECOMPRESSOR 0
80 #define ENV_BOOTBLOCK 0
81 #define ENV_ROMSTAGE 0
82 #define ENV_RAMSTAGE 0
83 #define ENV_SMM 0
84 #define ENV_SEPARATE_VERSTAGE 1
85 #define ENV_RMODULE 0
86 #define ENV_POSTCAR 0
87 #define ENV_LIBAGESA 0
88 #if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
89 #define ENV_STRING "verstage-before-bootblock"
90 #else
91 #define ENV_STRING "verstage"
92 #endif
94 #elif defined(__RAMSTAGE__)
95 #define ENV_DECOMPRESSOR 0
96 #define ENV_BOOTBLOCK 0
97 #define ENV_ROMSTAGE 0
98 #define ENV_RAMSTAGE 1
99 #define ENV_SMM 0
100 #define ENV_SEPARATE_VERSTAGE 0
101 #define ENV_RMODULE 0
102 #define ENV_POSTCAR 0
103 #define ENV_LIBAGESA 0
104 #define ENV_STRING "ramstage"
106 #elif defined(__RMODULE__)
107 #define ENV_DECOMPRESSOR 0
108 #define ENV_BOOTBLOCK 0
109 #define ENV_ROMSTAGE 0
110 #define ENV_RAMSTAGE 0
111 #define ENV_SMM 0
112 #define ENV_SEPARATE_VERSTAGE 0
113 #define ENV_RMODULE 1
114 #define ENV_POSTCAR 0
115 #define ENV_LIBAGESA 0
116 #define ENV_STRING "rmodule"
118 #elif defined(__POSTCAR__)
119 #define ENV_DECOMPRESSOR 0
120 #define ENV_BOOTBLOCK 0
121 #define ENV_ROMSTAGE 0
122 #define ENV_RAMSTAGE 0
123 #define ENV_SMM 0
124 #define ENV_SEPARATE_VERSTAGE 0
125 #define ENV_RMODULE 0
126 #define ENV_POSTCAR 1
127 #define ENV_LIBAGESA 0
128 #define ENV_STRING "postcar"
130 #elif defined(__LIBAGESA__)
131 #define ENV_DECOMPRESSOR 0
132 #define ENV_BOOTBLOCK 0
133 #define ENV_ROMSTAGE 0
134 #define ENV_RAMSTAGE 0
135 #define ENV_SMM 0
136 #define ENV_SEPARATE_VERSTAGE 0
137 #define ENV_RMODULE 0
138 #define ENV_POSTCAR 0
139 #define ENV_LIBAGESA 1
140 #define ENV_STRING "libagesa"
142 #else
144 * Default case of nothing set for random blob generation using
145 * create_class_compiler that isn't bound to a stage.
147 #define ENV_DECOMPRESSOR 0
148 #define ENV_BOOTBLOCK 0
149 #define ENV_ROMSTAGE 0
150 #define ENV_RAMSTAGE 0
151 #define ENV_SMM 0
152 #define ENV_SEPARATE_VERSTAGE 0
153 #define ENV_RMODULE 0
154 #define ENV_POSTCAR 0
155 #define ENV_LIBAGESA 0
156 #define ENV_STRING "UNKNOWN"
157 #endif
159 /* Define helpers about the current architecture, based on toolchain.inc. */
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
167 #elif __COREBOOT_ARM_ARCH__ == 7
168 #define ENV_ARMV4 0
169 #define ENV_ARMV7 1
170 #if defined(__COREBOOT_ARM_V7_A__)
171 #define ENV_ARMV7_A 1
172 #define ENV_ARMV7_M 0
173 #define ENV_ARMV7_R 0
174 #elif defined(__COREBOOT_ARM_V7_M__)
175 #define ENV_ARMV7_A 0
176 #define ENV_ARMV7_M 1
177 #define ENV_ARMV7_R 0
178 #elif defined(__COREBOOT_ARM_V7_R__)
179 #define ENV_ARMV7_A 0
180 #define ENV_ARMV7_M 0
181 #define ENV_ARMV7_R 1
182 #endif
183 #else
184 #define ENV_ARMV4 0
185 #define ENV_ARMV7 0
186 #endif
187 #define ENV_ARMV8 0
188 #define ENV_RISCV 0
189 #define ENV_X86 0
190 #define ENV_X86_32 0
191 #define ENV_X86_64 0
193 #elif defined(__ARCH_arm64__)
194 #define ENV_ARM 0
195 #define ENV_ARM64 1
196 #define ENV_ARMV4 0
197 #define ENV_ARMV7 0
198 #if __COREBOOT_ARM_ARCH__ == 8
199 #define ENV_ARMV8 1
200 #else
201 #define ENV_ARMV8 0
202 #endif
203 #define ENV_RISCV 0
204 #define ENV_X86 0
205 #define ENV_X86_32 0
206 #define ENV_X86_64 0
208 #elif defined(__ARCH_riscv__)
209 #define ENV_ARM 0
210 #define ENV_ARM64 0
211 #define ENV_ARMV4 0
212 #define ENV_ARMV7 0
213 #define ENV_ARMV8 0
214 #define ENV_RISCV 1
215 #define ENV_X86 0
216 #define ENV_X86_32 0
217 #define ENV_X86_64 0
219 #elif defined(__ARCH_x86_32__)
220 #define ENV_ARM 0
221 #define ENV_ARM64 0
222 #define ENV_ARMV4 0
223 #define ENV_ARMV7 0
224 #define ENV_ARMV8 0
225 #define ENV_RISCV 0
226 #define ENV_X86 1
227 #define ENV_X86_32 1
228 #define ENV_X86_64 0
230 #elif defined(__ARCH_x86_64__)
231 #define ENV_ARM 0
232 #define ENV_ARM64 0
233 #define ENV_ARMV4 0
234 #define ENV_ARMV7 0
235 #define ENV_ARMV8 0
236 #define ENV_RISCV 0
237 #define ENV_X86 1
238 #define ENV_X86_32 0
239 #define ENV_X86_64 1
241 #else
242 #define ENV_ARM 0
243 #define ENV_ARM64 0
244 #define ENV_ARMV4 0
245 #define ENV_ARMV7 0
246 #define ENV_ARMV8 0
247 #define ENV_RISCV 0
248 #define ENV_X86 0
249 #define ENV_X86_32 0
250 #define ENV_X86_64 0
252 #endif
254 #if CONFIG(RAMPAYLOAD)
255 /* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
256 #define ENV_PAYLOAD_LOADER ENV_POSTCAR
257 #else
258 /* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
259 * For now, that is the ramstage. */
260 #define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
261 #endif
263 #define ENV_ROMSTAGE_OR_BEFORE \
264 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
265 (ENV_SEPARATE_VERSTAGE && !CONFIG(VBOOT_STARTS_IN_ROMSTAGE)))
267 #if ENV_X86
268 /* Indicates memory layout is determined with arch/x86/car.ld. */
269 #define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
270 /* No .data sections with execute-in-place from ROM. */
271 #define ENV_STAGE_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
272 #else
273 /* Both .data and .bss, sometimes SRAM not DRAM. */
274 #define ENV_STAGE_HAS_DATA_SECTION 1
275 #define ENV_CACHE_AS_RAM 0
276 #endif
278 /* Currently rmodules, ramstage and smm have heap. */
279 #define ENV_STAGE_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
281 /* Set USER_SPACE in the makefile for the rare code that runs in userspace */
282 #if defined(__USER_SPACE__)
283 #define ENV_USER_SPACE 1
284 #else
285 #define ENV_USER_SPACE 0
286 #endif
288 /* Define the first stage to run */
289 #if CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK)
290 #define ENV_INITIAL_STAGE ENV_SEPARATE_VERSTAGE
291 #else
292 #define ENV_INITIAL_STAGE ENV_BOOTBLOCK
293 #endif
296 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
297 * PCI, PNP and CPU functions operate without use of devicetree. The reason
298 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
299 * no known requirement that devicetree would be needed during that stage.
301 * For ramstage individual source file may define __SIMPLE_DEVICE__
302 * before including any header files to force that particular source
303 * be built with simple device model.
306 #if !ENV_RAMSTAGE
307 #define __SIMPLE_DEVICE__
308 #endif
310 #endif /* _RULES_H */