Documentation: Fix sphinx configuration
[coreboot.git] / src / include / rules.h
blobbe72e9ea069dd95d6f162f124de51f0be3fe4b9d
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef _RULES_H
4 #define _RULES_H
6 #if defined(__TIMELESS__)
7 #define ENV_TIMELESS 1
8 #else
9 #define ENV_TIMELESS 0
10 #endif
12 /* Useful helpers to tell whether the code is executing in bootblock,
13 * romstage, ramstage or SMM.
16 #if defined(__DECOMPRESSOR__)
17 #define ENV_DECOMPRESSOR 1
18 #define ENV_BOOTBLOCK 0
19 #define ENV_ROMSTAGE 0
20 #define ENV_RAMSTAGE 0
21 #define ENV_SMM 0
22 #define ENV_SEPARATE_VERSTAGE 0
23 #define ENV_RMODULE 0
24 #define ENV_POSTCAR 0
25 #define ENV_LIBAGESA 0
26 #define ENV_STRING "decompressor"
28 #elif defined(__BOOTBLOCK__)
29 #define ENV_DECOMPRESSOR 0
30 #define ENV_BOOTBLOCK 1
31 #define ENV_ROMSTAGE 0
32 #define ENV_RAMSTAGE 0
33 #define ENV_SMM 0
34 #define ENV_SEPARATE_VERSTAGE 0
35 #define ENV_RMODULE 0
36 #define ENV_POSTCAR 0
37 #define ENV_LIBAGESA 0
38 #define ENV_STRING "bootblock"
40 #elif defined(__ROMSTAGE__)
41 #define ENV_DECOMPRESSOR 0
42 #define ENV_BOOTBLOCK 0
43 #define ENV_ROMSTAGE 1
44 #define ENV_RAMSTAGE 0
45 #define ENV_SMM 0
46 #define ENV_SEPARATE_VERSTAGE 0
47 #define ENV_RMODULE 0
48 #define ENV_POSTCAR 0
49 #define ENV_LIBAGESA 0
50 #define ENV_STRING "romstage"
52 #elif defined(__SMM__)
53 #define ENV_DECOMPRESSOR 0
54 #define ENV_BOOTBLOCK 0
55 #define ENV_ROMSTAGE 0
56 #define ENV_RAMSTAGE 0
57 #define ENV_SMM 1
58 #define ENV_SEPARATE_VERSTAGE 0
59 #define ENV_RMODULE 0
60 #define ENV_POSTCAR 0
61 #define ENV_LIBAGESA 0
62 #define ENV_STRING "smm"
65 * NOTE: "verstage" code may either run as a separate stage or linked into the
66 * bootblock/romstage, depending on the setting of CONFIG_SEPARATE_VERSTAGE. The
67 * ENV_SEPARATE_VERSTAGE macro will only return true for "verstage" code when
68 * CONFIG_SEPARATE_VERSTAGE=y, otherwise that code will have ENV_BOOTBLOCK or
69 * ENV_ROMSTAGE set (depending on the CONFIG_VBOOT_STARTS_IN_... options).
71 #elif defined(__VERSTAGE__)
72 #define ENV_DECOMPRESSOR 0
73 #define ENV_BOOTBLOCK 0
74 #define ENV_ROMSTAGE 0
75 #define ENV_RAMSTAGE 0
76 #define ENV_SMM 0
77 #define ENV_SEPARATE_VERSTAGE 1
78 #define ENV_RMODULE 0
79 #define ENV_POSTCAR 0
80 #define ENV_LIBAGESA 0
81 #define ENV_STRING "verstage"
83 #elif defined(__RAMSTAGE__)
84 #define ENV_DECOMPRESSOR 0
85 #define ENV_BOOTBLOCK 0
86 #define ENV_ROMSTAGE 0
87 #define ENV_RAMSTAGE 1
88 #define ENV_SMM 0
89 #define ENV_SEPARATE_VERSTAGE 0
90 #define ENV_RMODULE 0
91 #define ENV_POSTCAR 0
92 #define ENV_LIBAGESA 0
93 #define ENV_STRING "ramstage"
95 #elif defined(__RMODULE__)
96 #define ENV_DECOMPRESSOR 0
97 #define ENV_BOOTBLOCK 0
98 #define ENV_ROMSTAGE 0
99 #define ENV_RAMSTAGE 0
100 #define ENV_SMM 0
101 #define ENV_SEPARATE_VERSTAGE 0
102 #define ENV_RMODULE 1
103 #define ENV_POSTCAR 0
104 #define ENV_LIBAGESA 0
105 #define ENV_STRING "rmodule"
107 #elif defined(__POSTCAR__)
108 #define ENV_DECOMPRESSOR 0
109 #define ENV_BOOTBLOCK 0
110 #define ENV_ROMSTAGE 0
111 #define ENV_RAMSTAGE 0
112 #define ENV_SMM 0
113 #define ENV_SEPARATE_VERSTAGE 0
114 #define ENV_RMODULE 0
115 #define ENV_POSTCAR 1
116 #define ENV_LIBAGESA 0
117 #define ENV_STRING "postcar"
119 #elif defined(__LIBAGESA__)
120 #define ENV_DECOMPRESSOR 0
121 #define ENV_BOOTBLOCK 0
122 #define ENV_ROMSTAGE 0
123 #define ENV_RAMSTAGE 0
124 #define ENV_SMM 0
125 #define ENV_SEPARATE_VERSTAGE 0
126 #define ENV_RMODULE 0
127 #define ENV_POSTCAR 0
128 #define ENV_LIBAGESA 1
129 #define ENV_STRING "libagesa"
131 #else
133 * Default case of nothing set for random blob generation using
134 * create_class_compiler that isn't bound to a stage.
136 #define ENV_DECOMPRESSOR 0
137 #define ENV_BOOTBLOCK 0
138 #define ENV_ROMSTAGE 0
139 #define ENV_RAMSTAGE 0
140 #define ENV_SMM 0
141 #define ENV_SEPARATE_VERSTAGE 0
142 #define ENV_RMODULE 0
143 #define ENV_POSTCAR 0
144 #define ENV_LIBAGESA 0
145 #define ENV_STRING "UNKNOWN"
146 #endif
148 /* Define helpers about the current architecture, based on toolchain.inc. */
150 #if defined(__ARCH_arm__)
151 #define ENV_ARM 1
152 #define ENV_ARM64 0
153 #if __COREBOOT_ARM_ARCH__ == 4
154 #define ENV_ARMV4 1
155 #define ENV_ARMV7 0
156 #elif __COREBOOT_ARM_ARCH__ == 7
157 #define ENV_ARMV4 0
158 #define ENV_ARMV7 1
159 #if defined(__COREBOOT_ARM_V7_A__)
160 #define ENV_ARMV7_A 1
161 #define ENV_ARMV7_M 0
162 #define ENV_ARMV7_R 0
163 #elif defined(__COREBOOT_ARM_V7_M__)
164 #define ENV_ARMV7_A 0
165 #define ENV_ARMV7_M 1
166 #define ENV_ARMV7_R 0
167 #elif defined(__COREBOOT_ARM_V7_R__)
168 #define ENV_ARMV7_A 0
169 #define ENV_ARMV7_M 0
170 #define ENV_ARMV7_R 1
171 #endif
172 #else
173 #define ENV_ARMV4 0
174 #define ENV_ARMV7 0
175 #endif
176 #define ENV_ARMV8 0
177 #define ENV_RISCV 0
178 #define ENV_X86 0
179 #define ENV_X86_32 0
180 #define ENV_X86_64 0
182 #elif defined(__ARCH_arm64__)
183 #define ENV_ARM 0
184 #define ENV_ARM64 1
185 #define ENV_ARMV4 0
186 #define ENV_ARMV7 0
187 #if __COREBOOT_ARM_ARCH__ == 8
188 #define ENV_ARMV8 1
189 #else
190 #define ENV_ARMV8 0
191 #endif
192 #define ENV_RISCV 0
193 #define ENV_X86 0
194 #define ENV_X86_32 0
195 #define ENV_X86_64 0
197 #elif defined(__ARCH_riscv__)
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_RISCV 1
204 #define ENV_X86 0
205 #define ENV_X86_32 0
206 #define ENV_X86_64 0
208 #elif defined(__ARCH_x86_32__)
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 0
215 #define ENV_X86 1
216 #define ENV_X86_32 1
217 #define ENV_X86_64 0
219 #elif defined(__ARCH_x86_64__)
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 0
228 #define ENV_X86_64 1
230 #else
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 0
238 #define ENV_X86_32 0
239 #define ENV_X86_64 0
241 #endif
243 #if CONFIG(RAMPAYLOAD)
244 /* ENV_PAYLOAD_LOADER is set to ENV_POSTCAR when CONFIG_RAMPAYLOAD is enabled */
245 #define ENV_PAYLOAD_LOADER ENV_POSTCAR
246 #else
247 /* ENV_PAYLOAD_LOADER is set when you are in a stage that loads the payload.
248 * For now, that is the ramstage. */
249 #define ENV_PAYLOAD_LOADER ENV_RAMSTAGE
250 #endif
252 #define ENV_ROMSTAGE_OR_BEFORE \
253 (ENV_DECOMPRESSOR || ENV_BOOTBLOCK || ENV_ROMSTAGE || \
254 (ENV_SEPARATE_VERSTAGE && !CONFIG(VBOOT_STARTS_IN_ROMSTAGE)))
256 #if ENV_X86
257 /* Indicates memory layout is determined with arch/x86/car.ld. */
258 #define ENV_CACHE_AS_RAM (ENV_ROMSTAGE_OR_BEFORE && !CONFIG(RESET_VECTOR_IN_RAM))
259 /* No .data sections with execute-in-place from ROM. */
260 #define ENV_STAGE_HAS_DATA_SECTION !ENV_CACHE_AS_RAM
261 #else
262 /* Both .data and .bss, sometimes SRAM not DRAM. */
263 #define ENV_STAGE_HAS_DATA_SECTION 1
264 #define ENV_CACHE_AS_RAM 0
265 #endif
267 /* Currently rmodules, ramstage and smm have heap. */
268 #define ENV_STAGE_HAS_HEAP_SECTION (ENV_RMODULE || ENV_RAMSTAGE || ENV_SMM)
270 /* Set USER_SPACE in the makefile for the rare code that runs in userspace */
271 #if defined(__USER_SPACE__)
272 #define ENV_USER_SPACE 1
273 #else
274 #define ENV_USER_SPACE 0
275 #endif
278 * For pre-DRAM stages and post-CAR always build with simple device model, ie.
279 * PCI, PNP and CPU functions operate without use of devicetree. The reason
280 * post-CAR utilizes __SIMPLE_DEVICE__ is for simplicity. Currently there's
281 * no known requirement that devicetree would be needed during that stage.
283 * For ramstage individual source file may define __SIMPLE_DEVICE__
284 * before including any header files to force that particular source
285 * be built with simple device model.
288 #if !ENV_RAMSTAGE
289 #define __SIMPLE_DEVICE__
290 #endif
292 #endif /* _RULES_H */