1#ifndef HW_ACPI_AML_BUILD_H
2#define HW_ACPI_AML_BUILD_H
3
4#include "hw/acpi/acpi-defs.h"
5#include "hw/acpi/bios-linker-loader.h"
6
7
8#define ACPI_BUILD_TABLE_MAX_SIZE 0x200000
9
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"
16
17#define AML_NOTIFY_METHOD "NTFY"
18
19typedef enum {
20 AML_NO_OPCODE = 0,
21 AML_OPCODE,
22 AML_PACKAGE,
23 AML_EXT_PACKAGE,
24 AML_BUFFER,
25 AML_RES_TEMPLATE,
26} AmlBlockFlags;
27
28struct Aml {
29 GArray *buf;
30
31
32 uint8_t op;
33 AmlBlockFlags block_flags;
34};
35typedef struct Aml Aml;
36
37typedef enum {
38 AML_COMPATIBILITY = 0,
39 AML_TYPEA = 1,
40 AML_TYPEB = 2,
41 AML_TYPEF = 3,
42} AmlDmaType;
43
44typedef enum {
45 AML_NOTBUSMASTER = 0,
46 AML_BUSMASTER = 1,
47} AmlDmaBusMaster;
48
49typedef enum {
50 AML_TRANSFER8 = 0,
51 AML_TRANSFER8_16 = 1,
52 AML_TRANSFER16 = 2,
53} AmlTransferSize;
54
55typedef enum {
56 AML_DECODE10 = 0,
57 AML_DECODE16 = 1,
58} AmlIODecode;
59
60typedef enum {
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,
67} AmlAccessType;
68
69typedef enum {
70 AML_NOLOCK = 0,
71 AML_LOCK = 1,
72} AmlLockRule;
73
74typedef enum {
75 AML_PRESERVE = 0,
76 AML_WRITE_AS_ONES = 1,
77 AML_WRITE_AS_ZEROS = 2,
78} AmlUpdateRule;
79
80typedef enum {
81 AML_SYSTEM_MEMORY = 0X00,
82 AML_SYSTEM_IO = 0X01,
83 AML_PCI_CONFIG = 0X02,
84} AmlRegionSpace;
85
86typedef enum {
87 AML_MEMORY_RANGE = 0,
88 AML_IO_RANGE = 1,
89 AML_BUS_NUMBER_RANGE = 2,
90} AmlResourceType;
91
92typedef enum {
93 AML_SUB_DECODE = 1 << 1,
94 AML_POS_DECODE = 0
95} AmlDecode;
96
97typedef enum {
98 AML_MAX_FIXED = 1 << 3,
99 AML_MAX_NOT_FIXED = 0,
100} AmlMaxFixed;
101
102typedef enum {
103 AML_MIN_FIXED = 1 << 2,
104 AML_MIN_NOT_FIXED = 0
105} AmlMinFixed;
106
107
108
109
110
111typedef enum {
112 AML_ISA_ONLY = 1,
113 AML_NON_ISA_ONLY = 2,
114 AML_ENTIRE_RANGE = 3,
115} AmlISARanges;
116
117
118
119
120
121typedef enum {
122 AML_NON_CACHEABLE = 0,
123 AML_CACHEABLE = 1,
124 AML_WRITE_COMBINING = 2,
125 AML_PREFETCHABLE = 3,
126} AmlCacheable;
127
128
129
130
131
132typedef enum {
133 AML_READ_ONLY = 0,
134 AML_READ_WRITE = 1,
135} AmlReadAndWrite;
136
137
138
139
140
141typedef enum {
142 AML_CONSUMER_PRODUCER = 0,
143 AML_CONSUMER = 1,
144} AmlConsumerAndProducer;
145
146
147
148
149
150typedef enum {
151 AML_LEVEL = 0,
152 AML_EDGE = 1,
153} AmlLevelAndEdge;
154
155
156
157
158
159typedef enum {
160 AML_ACTIVE_HIGH = 0,
161 AML_ACTIVE_LOW = 1,
162} AmlActiveHighAndLow;
163
164
165
166
167
168typedef enum {
169 AML_EXCLUSIVE = 0,
170 AML_SHARED = 1,
171 AML_EXCLUSIVE_AND_WAKE = 2,
172 AML_SHARED_AND_WAKE = 3,
173} AmlShared;
174
175
176typedef enum {
177 AML_NOTSERIALIZED = 0,
178 AML_SERIALIZED = 1,
179} AmlSerializeFlag;
180
181
182
183
184
185typedef enum {
186 AML_INTERRUPT_CONNECTION = 0,
187 AML_IO_CONNECTION = 1,
188} AmlGpioConnectionType;
189
190
191
192
193
194typedef enum {
195 AML_PULL_DEFAULT = 0,
196 AML_PULL_UP = 1,
197 AML_PULL_DOWN = 2,
198 AML_PULL_NONE = 3,
199} AmlPinConfig;
200
201typedef 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
208typedef
209struct AcpiBuildTables {
210 GArray *table_data;
211 GArray *rsdp;
212 GArray *tcpalog;
213 BIOSLinker *linker;
214} AcpiBuildTables;
215
216
217
218
219
220
221
222
223
224Aml *init_aml_allocator(void);
225
226
227
228
229
230
231
232
233void free_aml_allocator(void);
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250void aml_append(Aml *parent_ctx, Aml *child);
251
252
253Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
254Aml *aml_name_decl(const char *name, Aml *val);
255Aml *aml_debug(void);
256Aml *aml_return(Aml *val);
257Aml *aml_int(const uint64_t val);
258Aml *aml_arg(int pos);
259Aml *aml_to_integer(Aml *arg);
260Aml *aml_to_hexstring(Aml *src, Aml *dst);
261Aml *aml_to_buffer(Aml *src, Aml *dst);
262Aml *aml_store(Aml *val, Aml *target);
263Aml *aml_and(Aml *arg1, Aml *arg2, Aml *dst);
264Aml *aml_or(Aml *arg1, Aml *arg2, Aml *dst);
265Aml *aml_lor(Aml *arg1, Aml *arg2);
266Aml *aml_shiftleft(Aml *arg1, Aml *count);
267Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst);
268Aml *aml_lless(Aml *arg1, Aml *arg2);
269Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst);
270Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst);
271Aml *aml_increment(Aml *arg);
272Aml *aml_decrement(Aml *arg);
273Aml *aml_index(Aml *arg1, Aml *idx);
274Aml *aml_notify(Aml *arg1, Aml *arg2);
275Aml *aml_call0(const char *method);
276Aml *aml_call1(const char *method, Aml *arg1);
277Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
278Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
279Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
280Aml *aml_call5(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4,
281 Aml *arg5);
282Aml *aml_gpio_int(AmlConsumerAndProducer con_and_pro,
283 AmlLevelAndEdge edge_level,
284 AmlActiveHighAndLow active_level, AmlShared shared,
285 AmlPinConfig pin_config, uint16_t debounce_timeout,
286 const uint32_t pin_list[], uint32_t pin_count,
287 const char *resource_source_name,
288 const uint8_t *vendor_data, uint16_t vendor_data_len);
289Aml *aml_memory32_fixed(uint32_t addr, uint32_t size,
290 AmlReadAndWrite read_and_write);
291Aml *aml_interrupt(AmlConsumerAndProducer con_and_pro,
292 AmlLevelAndEdge level_and_edge,
293 AmlActiveHighAndLow high_and_low, AmlShared shared,
294 uint32_t *irq_list, uint8_t irq_count);
295Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
296 uint8_t aln, uint8_t len);
297Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
298 Aml *offset, uint32_t len);
299Aml *aml_irq_no_flags(uint8_t irq);
300Aml *aml_named_field(const char *name, unsigned length);
301Aml *aml_reserved_field(unsigned length);
302Aml *aml_local(int num);
303Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
304Aml *aml_lnot(Aml *arg);
305Aml *aml_equal(Aml *arg1, Aml *arg2);
306Aml *aml_lgreater(Aml *arg1, Aml *arg2);
307Aml *aml_lgreater_equal(Aml *arg1, Aml *arg2);
308Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
309 const char *name_format, ...) GCC_FMT_ATTR(4, 5);
310Aml *aml_eisaid(const char *str);
311Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
312 AmlDecode dec, uint16_t addr_gran,
313 uint16_t addr_min, uint16_t addr_max,
314 uint16_t addr_trans, uint16_t len);
315Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
316 AmlDecode dec, AmlISARanges isa_ranges,
317 uint16_t addr_gran, uint16_t addr_min,
318 uint16_t addr_max, uint16_t addr_trans,
319 uint16_t len);
320Aml *aml_dword_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
321 AmlDecode dec, AmlISARanges isa_ranges,
322 uint32_t addr_gran, uint32_t addr_min,
323 uint32_t addr_max, uint32_t addr_trans,
324 uint32_t len);
325Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
326 AmlMaxFixed max_fixed, AmlCacheable cacheable,
327 AmlReadAndWrite read_and_write,
328 uint32_t addr_gran, uint32_t addr_min,
329 uint32_t addr_max, uint32_t addr_trans,
330 uint32_t len);
331Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
332 AmlMaxFixed max_fixed, AmlCacheable cacheable,
333 AmlReadAndWrite read_and_write,
334 uint64_t addr_gran, uint64_t addr_min,
335 uint64_t addr_max, uint64_t addr_trans,
336 uint64_t len);
337Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz,
338 uint8_t channel);
339Aml *aml_sleep(uint64_t msec);
340
341
342Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
343Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
344Aml *aml_method(const char *name, int arg_count, AmlSerializeFlag sflag);
345Aml *aml_if(Aml *predicate);
346Aml *aml_else(void);
347Aml *aml_while(Aml *predicate);
348Aml *aml_package(uint8_t num_elements);
349Aml *aml_buffer(int buffer_size, uint8_t *byte_list);
350Aml *aml_resource_template(void);
351Aml *aml_field(const char *name, AmlAccessType type, AmlLockRule lock,
352 AmlUpdateRule rule);
353Aml *aml_mutex(const char *name, uint8_t sync_level);
354Aml *aml_acquire(Aml *mutex, uint16_t timeout);
355Aml *aml_release(Aml *mutex);
356Aml *aml_alias(const char *source_object, const char *alias_object);
357Aml *aml_create_field(Aml *srcbuf, Aml *bit_index, Aml *num_bits,
358 const char *name);
359Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name);
360Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name);
361Aml *aml_varpackage(uint32_t num_elements);
362Aml *aml_touuid(const char *uuid);
363Aml *aml_unicode(const char *str);
364Aml *aml_refof(Aml *arg);
365Aml *aml_derefof(Aml *arg);
366Aml *aml_sizeof(Aml *arg);
367Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target);
368Aml *aml_object_type(Aml *object);
369
370void build_append_int_noprefix(GArray *table, uint64_t value, int size);
371void
372build_header(BIOSLinker *linker, GArray *table_data,
373 AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
374 const char *oem_id, const char *oem_table_id);
375void *acpi_data_push(GArray *table_data, unsigned size);
376unsigned acpi_data_len(GArray *table);
377void acpi_add_table(GArray *table_offsets, GArray *table_data);
378void acpi_build_tables_init(AcpiBuildTables *tables);
379void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
380void
381build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
382 const char *oem_id, const char *oem_table_id);
383
384int
385build_append_named_dword(GArray *array, const char *name_format, ...)
386GCC_FMT_ATTR(2, 3);
387
388void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
389 uint64_t len, int node, MemoryAffinityFlags flags);
390
391#endif
392