]>
Commit | Line | Data |
---|---|---|
121d0712 MA |
1 | #ifndef HW_ACPI_AML_BUILD_H |
2 | #define HW_ACPI_AML_BUILD_H | |
19934e0e | 3 | |
658c2718 | 4 | #include "hw/acpi/acpi-defs.h" |
0e9b9eda | 5 | #include "hw/acpi/bios-linker-loader.h" |
658c2718 SZ |
6 | |
7 | /* Reserve RAM space for tables: add another order of magnitude. */ | |
8 | #define ACPI_BUILD_TABLE_MAX_SIZE 0x200000 | |
9 | ||
658c2718 SZ |
10 | #define ACPI_BUILD_APPNAME6 "BOCHS " |
11 | #define ACPI_BUILD_APPNAME4 "BXPC" | |
12 | ||
13 | #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" | |
14 | #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp" | |
15 | #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log" | |
19934e0e | 16 | |
f294ecbc IM |
17 | #define AML_NOTIFY_METHOD "NTFY" |
18 | ||
0f2707e4 IM |
19 | typedef enum { |
20 | AML_NO_OPCODE = 0,/* has only data */ | |
21 | AML_OPCODE, /* has opcode optionally followed by data */ | |
22 | AML_PACKAGE, /* has opcode and uses PkgLength for its length */ | |
56521fb8 | 23 | AML_EXT_PACKAGE, /* Same as AML_PACKAGE but also has 'ExOpPrefix' */ |
0f2707e4 IM |
24 | AML_BUFFER, /* data encoded as 'DefBuffer' */ |
25 | AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */ | |
26 | } AmlBlockFlags; | |
27 | ||
28 | struct Aml { | |
29 | GArray *buf; | |
30 | ||
31 | /*< private >*/ | |
32 | uint8_t op; | |
33 | AmlBlockFlags block_flags; | |
34 | }; | |
35 | typedef struct Aml Aml; | |
36 | ||
a23b8872 IM |
37 | typedef enum { |
38 | AML_COMPATIBILITY = 0, | |
39 | AML_TYPEA = 1, | |
40 | AML_TYPEB = 2, | |
41 | AML_TYPEF = 3, | |
42 | } AmlDmaType; | |
43 | ||
44 | typedef enum { | |
45 | AML_NOTBUSMASTER = 0, | |
46 | AML_BUSMASTER = 1, | |
47 | } AmlDmaBusMaster; | |
48 | ||
49 | typedef enum { | |
50 | AML_TRANSFER8 = 0, | |
51 | AML_TRANSFER8_16 = 1, | |
52 | AML_TRANSFER16 = 2, | |
53 | } AmlTransferSize; | |
54 | ||
52fa397c | 55 | typedef enum { |
ff80dc7f SZ |
56 | AML_DECODE10 = 0, |
57 | AML_DECODE16 = 1, | |
52fa397c IM |
58 | } AmlIODecode; |
59 | ||
214ae59f | 60 | typedef enum { |
ff80dc7f SZ |
61 | AML_ANY_ACC = 0, |
62 | AML_BYTE_ACC = 1, | |
63 | AML_WORD_ACC = 2, | |
64 | AML_DWORD_ACC = 3, | |
65 | AML_QWORD_ACC = 4, | |
66 | AML_BUFFER_ACC = 5, | |
af509897 ZG |
67 | } AmlAccessType; |
68 | ||
36de884a IM |
69 | typedef enum { |
70 | AML_NOLOCK = 0, | |
71 | AML_LOCK = 1, | |
72 | } AmlLockRule; | |
73 | ||
af509897 | 74 | typedef enum { |
ff80dc7f SZ |
75 | AML_PRESERVE = 0, |
76 | AML_WRITE_AS_ONES = 1, | |
77 | AML_WRITE_AS_ZEROS = 2, | |
af509897 | 78 | } AmlUpdateRule; |
214ae59f | 79 | |
31127938 | 80 | typedef enum { |
ff80dc7f SZ |
81 | AML_SYSTEM_MEMORY = 0X00, |
82 | AML_SYSTEM_IO = 0X01, | |
e4db2798 | 83 | AML_PCI_CONFIG = 0X02, |
31127938 IM |
84 | } AmlRegionSpace; |
85 | ||
6ece7053 | 86 | typedef enum { |
ff80dc7f SZ |
87 | AML_MEMORY_RANGE = 0, |
88 | AML_IO_RANGE = 1, | |
89 | AML_BUS_NUMBER_RANGE = 2, | |
6ece7053 IM |
90 | } AmlResourceType; |
91 | ||
92 | typedef enum { | |
ff80dc7f SZ |
93 | AML_SUB_DECODE = 1 << 1, |
94 | AML_POS_DECODE = 0 | |
6ece7053 IM |
95 | } AmlDecode; |
96 | ||
97 | typedef enum { | |
ff80dc7f SZ |
98 | AML_MAX_FIXED = 1 << 3, |
99 | AML_MAX_NOT_FIXED = 0, | |
6ece7053 IM |
100 | } AmlMaxFixed; |
101 | ||
102 | typedef enum { | |
ff80dc7f SZ |
103 | AML_MIN_FIXED = 1 << 2, |
104 | AML_MIN_NOT_FIXED = 0 | |
6ece7053 IM |
105 | } AmlMinFixed; |
106 | ||
107 | /* | |
108 | * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions | |
109 | * _RNG field definition | |
110 | */ | |
111 | typedef enum { | |
ff80dc7f SZ |
112 | AML_ISA_ONLY = 1, |
113 | AML_NON_ISA_ONLY = 2, | |
114 | AML_ENTIRE_RANGE = 3, | |
6ece7053 IM |
115 | } AmlISARanges; |
116 | ||
117 | /* | |
118 | * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions | |
119 | * _MEM field definition | |
120 | */ | |
121 | typedef enum { | |
ff80dc7f SZ |
122 | AML_NON_CACHEABLE = 0, |
123 | AML_CACHEABLE = 1, | |
124 | AML_WRITE_COMBINING = 2, | |
125 | AML_PREFETCHABLE = 3, | |
126 | } AmlCacheable; | |
6ece7053 IM |
127 | |
128 | /* | |
129 | * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions | |
130 | * _RW field definition | |
131 | */ | |
132 | typedef enum { | |
ff80dc7f SZ |
133 | AML_READ_ONLY = 0, |
134 | AML_READ_WRITE = 1, | |
6ece7053 IM |
135 | } AmlReadAndWrite; |
136 | ||
205d1d1c SZ |
137 | /* |
138 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
139 | * Interrupt Vector Flags Bits[0] Consumer/Producer | |
140 | */ | |
141 | typedef enum { | |
142 | AML_CONSUMER_PRODUCER = 0, | |
143 | AML_CONSUMER = 1, | |
144 | } AmlConsumerAndProducer; | |
145 | ||
146 | /* | |
147 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
148 | * _HE field definition | |
149 | */ | |
150 | typedef enum { | |
151 | AML_LEVEL = 0, | |
152 | AML_EDGE = 1, | |
153 | } AmlLevelAndEdge; | |
154 | ||
155 | /* | |
156 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
157 | * _LL field definition | |
158 | */ | |
159 | typedef enum { | |
160 | AML_ACTIVE_HIGH = 0, | |
161 | AML_ACTIVE_LOW = 1, | |
162 | } AmlActiveHighAndLow; | |
163 | ||
164 | /* | |
165 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
166 | * _SHR field definition | |
167 | */ | |
168 | typedef enum { | |
169 | AML_EXCLUSIVE = 0, | |
170 | AML_SHARED = 1, | |
171 | AML_EXCLUSIVE_AND_WAKE = 2, | |
172 | AML_SHARED_AND_WAKE = 3, | |
173 | } AmlShared; | |
174 | ||
4dbfc881 XG |
175 | /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: MethodFlags */ |
176 | typedef enum { | |
177 | AML_NOTSERIALIZED = 0, | |
178 | AML_SERIALIZED = 1, | |
179 | } AmlSerializeFlag; | |
180 | ||
4ecdc746 SZ |
181 | /* |
182 | * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition | |
183 | * GPIO Connection Type | |
184 | */ | |
185 | typedef enum { | |
186 | AML_INTERRUPT_CONNECTION = 0, | |
187 | AML_IO_CONNECTION = 1, | |
188 | } AmlGpioConnectionType; | |
189 | ||
190 | /* | |
191 | * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition | |
192 | * _PPI field definition | |
193 | */ | |
194 | typedef enum { | |
195 | AML_PULL_DEFAULT = 0, | |
196 | AML_PULL_UP = 1, | |
197 | AML_PULL_DOWN = 2, | |
198 | AML_PULL_NONE = 3, | |
199 | } AmlPinConfig; | |
200 | ||
64b83136 SZ |
201 | typedef enum { |
202 | MEM_AFFINITY_NOFLAGS = 0, | |
203 | MEM_AFFINITY_ENABLED = (1 << 0), | |
204 | MEM_AFFINITY_HOTPLUGGABLE = (1 << 1), | |
205 | MEM_AFFINITY_NON_VOLATILE = (1 << 2), | |
206 | } MemoryAffinityFlags; | |
207 | ||
658c2718 SZ |
208 | typedef |
209 | struct AcpiBuildTables { | |
210 | GArray *table_data; | |
211 | GArray *rsdp; | |
212 | GArray *tcpalog; | |
c7809e6c | 213 | GArray *vmgenid; |
0e9b9eda | 214 | BIOSLinker *linker; |
658c2718 SZ |
215 | } AcpiBuildTables; |
216 | ||
0f2707e4 IM |
217 | /** |
218 | * init_aml_allocator: | |
219 | * | |
220 | * Called for initializing API allocator which allow to use | |
221 | * AML API. | |
222 | * Returns: toplevel container which accumulates all other | |
223 | * AML elements for a table. | |
224 | */ | |
225 | Aml *init_aml_allocator(void); | |
226 | ||
227 | /** | |
228 | * free_aml_allocator: | |
229 | * | |
230 | * Releases all elements used by AML API, frees associated memory | |
231 | * and invalidates AML allocator. After this call @init_aml_allocator | |
232 | * should be called again if AML API is to be used again. | |
233 | */ | |
234 | void free_aml_allocator(void); | |
235 | ||
236 | /** | |
237 | * aml_append: | |
238 | * @parent_ctx: context to which @child element is added | |
239 | * @child: element that is copied into @parent_ctx context | |
240 | * | |
241 | * Joins Aml elements together and helps to construct AML tables | |
242 | * Examle of usage: | |
243 | * Aml *table = aml_def_block("SSDT", ...); | |
7824df38 | 244 | * Aml *sb = aml_scope("\\_SB"); |
0f2707e4 IM |
245 | * Aml *dev = aml_device("PCI0"); |
246 | * | |
247 | * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); | |
248 | * aml_append(sb, dev); | |
249 | * aml_append(table, sb); | |
250 | */ | |
251 | void aml_append(Aml *parent_ctx, Aml *child); | |
252 | ||
3c054bd5 IM |
253 | /* non block AML object primitives */ |
254 | Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2); | |
255 | Aml *aml_name_decl(const char *name, Aml *val); | |
e8977414 | 256 | Aml *aml_debug(void); |
b25af5ad | 257 | Aml *aml_return(Aml *val); |
295a515d | 258 | Aml *aml_int(const uint64_t val); |
7193f3a6 | 259 | Aml *aml_arg(int pos); |
f411199d | 260 | Aml *aml_to_integer(Aml *arg); |
6d5ea945 | 261 | Aml *aml_to_hexstring(Aml *src, Aml *dst); |
25c1432e | 262 | Aml *aml_to_buffer(Aml *src, Aml *dst); |
c263b3f7 | 263 | Aml *aml_store(Aml *val, Aml *target); |
5530427f | 264 | Aml *aml_and(Aml *arg1, Aml *arg2, Aml *dst); |
ca3df95d | 265 | Aml *aml_or(Aml *arg1, Aml *arg2, Aml *dst); |
df241999 | 266 | Aml *aml_lor(Aml *arg1, Aml *arg2); |
a57ddddd | 267 | Aml *aml_shiftleft(Aml *arg1, Aml *count); |
c360639a | 268 | Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst); |
96396e28 | 269 | Aml *aml_lless(Aml *arg1, Aml *arg2); |
20ca5208 | 270 | Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst); |
7059eb42 | 271 | Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst); |
af39d536 | 272 | Aml *aml_increment(Aml *arg); |
7059eb42 | 273 | Aml *aml_decrement(Aml *arg); |
928b8996 | 274 | Aml *aml_index(Aml *arg1, Aml *idx); |
34189453 | 275 | Aml *aml_notify(Aml *arg1, Aml *arg2); |
7b38ba9c | 276 | Aml *aml_call0(const char *method); |
3f3992b7 IM |
277 | Aml *aml_call1(const char *method, Aml *arg1); |
278 | Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2); | |
279 | Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3); | |
280 | Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4); | |
052889b8 XG |
281 | Aml *aml_call5(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4, |
282 | Aml *arg5); | |
37d0e980 SZ |
283 | Aml *aml_gpio_int(AmlConsumerAndProducer con_and_pro, |
284 | AmlLevelAndEdge edge_level, | |
285 | AmlActiveHighAndLow active_level, AmlShared shared, | |
286 | AmlPinConfig pin_config, uint16_t debounce_timeout, | |
287 | const uint32_t pin_list[], uint32_t pin_count, | |
288 | const char *resource_source_name, | |
289 | const uint8_t *vendor_data, uint16_t vendor_data_len); | |
dc17ab1d SZ |
290 | Aml *aml_memory32_fixed(uint32_t addr, uint32_t size, |
291 | AmlReadAndWrite read_and_write); | |
205d1d1c SZ |
292 | Aml *aml_interrupt(AmlConsumerAndProducer con_and_pro, |
293 | AmlLevelAndEdge level_and_edge, | |
294 | AmlActiveHighAndLow high_and_low, AmlShared shared, | |
45fcf539 | 295 | uint32_t *irq_list, uint8_t irq_count); |
52fa397c IM |
296 | Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, |
297 | uint8_t aln, uint8_t len); | |
31127938 | 298 | Aml *aml_operation_region(const char *name, AmlRegionSpace rs, |
3f3009c0 | 299 | Aml *offset, uint32_t len); |
70560453 | 300 | Aml *aml_irq_no_flags(uint8_t irq); |
214ae59f | 301 | Aml *aml_named_field(const char *name, unsigned length); |
e2ea299b | 302 | Aml *aml_reserved_field(unsigned length); |
b8a5d689 | 303 | Aml *aml_local(int num); |
d5e5830f | 304 | Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2); |
ea7df04a | 305 | Aml *aml_lnot(Aml *arg); |
15e44e56 | 306 | Aml *aml_equal(Aml *arg1, Aml *arg2); |
dabad78b | 307 | Aml *aml_lgreater(Aml *arg1, Aml *arg2); |
2d3f667d | 308 | Aml *aml_lgreater_equal(Aml *arg1, Aml *arg2); |
3dd15643 IM |
309 | Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len, |
310 | const char *name_format, ...) GCC_FMT_ATTR(4, 5); | |
a7891dac | 311 | Aml *aml_eisaid(const char *str); |
6ece7053 IM |
312 | Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, |
313 | AmlDecode dec, uint16_t addr_gran, | |
314 | uint16_t addr_min, uint16_t addr_max, | |
315 | uint16_t addr_trans, uint16_t len); | |
316 | Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, | |
317 | AmlDecode dec, AmlISARanges isa_ranges, | |
318 | uint16_t addr_gran, uint16_t addr_min, | |
319 | uint16_t addr_max, uint16_t addr_trans, | |
320 | uint16_t len); | |
616ef329 SZ |
321 | Aml *aml_dword_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, |
322 | AmlDecode dec, AmlISARanges isa_ranges, | |
323 | uint32_t addr_gran, uint32_t addr_min, | |
324 | uint32_t addr_max, uint32_t addr_trans, | |
325 | uint32_t len); | |
6ece7053 | 326 | Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed, |
ff80dc7f | 327 | AmlMaxFixed max_fixed, AmlCacheable cacheable, |
6ece7053 IM |
328 | AmlReadAndWrite read_and_write, |
329 | uint32_t addr_gran, uint32_t addr_min, | |
330 | uint32_t addr_max, uint32_t addr_trans, | |
331 | uint32_t len); | |
332 | Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed, | |
ff80dc7f | 333 | AmlMaxFixed max_fixed, AmlCacheable cacheable, |
6ece7053 IM |
334 | AmlReadAndWrite read_and_write, |
335 | uint64_t addr_gran, uint64_t addr_min, | |
336 | uint64_t addr_max, uint64_t addr_trans, | |
337 | uint64_t len); | |
a23b8872 IM |
338 | Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, |
339 | uint8_t channel); | |
0073518d | 340 | Aml *aml_sleep(uint64_t msec); |
3c054bd5 | 341 | |
2ef7c27b IM |
342 | /* Block AML object primitives */ |
343 | Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2); | |
be06ebd0 | 344 | Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2); |
4dbfc881 | 345 | Aml *aml_method(const char *name, int arg_count, AmlSerializeFlag sflag); |
32acac9e | 346 | Aml *aml_if(Aml *predicate); |
467b07df | 347 | Aml *aml_else(void); |
68e6b0af | 348 | Aml *aml_while(Aml *predicate); |
3bfa74a7 | 349 | Aml *aml_package(uint8_t num_elements); |
ed8b5847 | 350 | Aml *aml_buffer(int buffer_size, uint8_t *byte_list); |
ad4a80bc | 351 | Aml *aml_resource_template(void); |
36de884a IM |
352 | Aml *aml_field(const char *name, AmlAccessType type, AmlLockRule lock, |
353 | AmlUpdateRule rule); | |
6e1db3f2 XG |
354 | Aml *aml_mutex(const char *name, uint8_t sync_level); |
355 | Aml *aml_acquire(Aml *mutex, uint16_t timeout); | |
356 | Aml *aml_release(Aml *mutex); | |
67a5c0fa | 357 | Aml *aml_alias(const char *source_object, const char *alias_object); |
39b6dbd8 XG |
358 | Aml *aml_create_field(Aml *srcbuf, Aml *bit_index, Aml *num_bits, |
359 | const char *name); | |
ed8176a3 | 360 | Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name); |
7e192a38 | 361 | Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name); |
a678508e | 362 | Aml *aml_varpackage(uint32_t num_elements); |
b930fb9d | 363 | Aml *aml_touuid(const char *uuid); |
e1f776c4 | 364 | Aml *aml_unicode(const char *str); |
7bc6fd24 | 365 | Aml *aml_refof(Aml *arg); |
95cb0661 | 366 | Aml *aml_derefof(Aml *arg); |
52483d14 | 367 | Aml *aml_sizeof(Aml *arg); |
9815cba5 | 368 | Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target); |
b265f27c | 369 | Aml *aml_object_type(Aml *object); |
2ef7c27b | 370 | |
fb9f5926 | 371 | void build_append_int_noprefix(GArray *table, uint64_t value, int size); |
658c2718 | 372 | void |
0e9b9eda | 373 | build_header(BIOSLinker *linker, GArray *table_data, |
8870ca0e | 374 | AcpiTableHeader *h, const char *sig, int len, uint8_t rev, |
37ad223c | 375 | const char *oem_id, const char *oem_table_id); |
658c2718 SZ |
376 | void *acpi_data_push(GArray *table_data, unsigned size); |
377 | unsigned acpi_data_len(GArray *table); | |
378 | void acpi_add_table(GArray *table_offsets, GArray *table_data); | |
379 | void acpi_build_tables_init(AcpiBuildTables *tables); | |
380 | void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre); | |
243bdb79 | 381 | void |
0e9b9eda | 382 | build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, |
51513558 | 383 | const char *oem_id, const char *oem_table_id); |
658c2718 | 384 | |
f2035491 | 385 | int |
8d0ac88e SW |
386 | build_append_named_dword(GArray *array, const char *name_format, ...) |
387 | GCC_FMT_ATTR(2, 3); | |
f2035491 | 388 | |
64b83136 SZ |
389 | void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base, |
390 | uint64_t len, int node, MemoryAffinityFlags flags); | |
391 | ||
19934e0e | 392 | #endif |