]> Git Repo - qemu.git/blob - include/hw/acpi/aml-build.h
acpi add aml_dma()
[qemu.git] / include / hw / acpi / aml-build.h
1 #ifndef HW_ACPI_GEN_UTILS_H
2 #define HW_ACPI_GEN_UTILS_H
3
4 #include <stdint.h>
5 #include <glib.h>
6 #include "qemu/compiler.h"
7 #include "hw/acpi/acpi-defs.h"
8
9 /* Reserve RAM space for tables: add another order of magnitude. */
10 #define ACPI_BUILD_TABLE_MAX_SIZE         0x200000
11
12 #define ACPI_BUILD_APPNAME6 "BOCHS "
13 #define ACPI_BUILD_APPNAME4 "BXPC"
14
15 #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
16 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
17 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
18
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 */
23     AML_EXT_PACKAGE,  /* Same as AML_PACKAGE but also has 'ExOpPrefix' */
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
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
55 typedef enum {
56     AML_DECODE10 = 0,
57     AML_DECODE16 = 1,
58 } AmlIODecode;
59
60 typedef 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
69 typedef enum {
70     AML_NOLOCK = 0,
71     AML_LOCK = 1,
72 } AmlLockRule;
73
74 typedef enum {
75     AML_PRESERVE = 0,
76     AML_WRITE_AS_ONES = 1,
77     AML_WRITE_AS_ZEROS = 2,
78 } AmlUpdateRule;
79
80 typedef enum {
81     AML_SYSTEM_MEMORY = 0X00,
82     AML_SYSTEM_IO = 0X01,
83 } AmlRegionSpace;
84
85 typedef enum {
86     AML_MEMORY_RANGE = 0,
87     AML_IO_RANGE = 1,
88     AML_BUS_NUMBER_RANGE = 2,
89 } AmlResourceType;
90
91 typedef enum {
92     AML_SUB_DECODE = 1 << 1,
93     AML_POS_DECODE = 0
94 } AmlDecode;
95
96 typedef enum {
97     AML_MAX_FIXED = 1 << 3,
98     AML_MAX_NOT_FIXED = 0,
99 } AmlMaxFixed;
100
101 typedef enum {
102     AML_MIN_FIXED = 1 << 2,
103     AML_MIN_NOT_FIXED = 0
104 } AmlMinFixed;
105
106 /*
107  * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
108  * _RNG field definition
109  */
110 typedef enum {
111     AML_ISA_ONLY = 1,
112     AML_NON_ISA_ONLY = 2,
113     AML_ENTIRE_RANGE = 3,
114 } AmlISARanges;
115
116 /*
117  * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
118  * _MEM field definition
119  */
120 typedef enum {
121     AML_NON_CACHEABLE = 0,
122     AML_CACHEABLE = 1,
123     AML_WRITE_COMBINING = 2,
124     AML_PREFETCHABLE = 3,
125 } AmlCacheable;
126
127 /*
128  * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
129  * _RW field definition
130  */
131 typedef enum {
132     AML_READ_ONLY = 0,
133     AML_READ_WRITE = 1,
134 } AmlReadAndWrite;
135
136 /*
137  * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
138  * Interrupt Vector Flags Bits[0] Consumer/Producer
139  */
140 typedef enum {
141     AML_CONSUMER_PRODUCER = 0,
142     AML_CONSUMER = 1,
143 } AmlConsumerAndProducer;
144
145 /*
146  * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
147  * _HE field definition
148  */
149 typedef enum {
150     AML_LEVEL = 0,
151     AML_EDGE = 1,
152 } AmlLevelAndEdge;
153
154 /*
155  * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
156  * _LL field definition
157  */
158 typedef enum {
159     AML_ACTIVE_HIGH = 0,
160     AML_ACTIVE_LOW = 1,
161 } AmlActiveHighAndLow;
162
163 /*
164  * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
165  * _SHR field definition
166  */
167 typedef enum {
168     AML_EXCLUSIVE = 0,
169     AML_SHARED = 1,
170     AML_EXCLUSIVE_AND_WAKE = 2,
171     AML_SHARED_AND_WAKE = 3,
172 } AmlShared;
173
174 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: MethodFlags */
175 typedef enum {
176     AML_NOTSERIALIZED = 0,
177     AML_SERIALIZED = 1,
178 } AmlSerializeFlag;
179
180 /*
181  * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition
182  * GPIO Connection Type
183  */
184 typedef enum {
185     AML_INTERRUPT_CONNECTION = 0,
186     AML_IO_CONNECTION = 1,
187 } AmlGpioConnectionType;
188
189 /*
190  * ACPI 5.0: Table 6-189 GPIO Connection Descriptor Definition
191  * _PPI field definition
192  */
193 typedef enum {
194     AML_PULL_DEFAULT = 0,
195     AML_PULL_UP = 1,
196     AML_PULL_DOWN = 2,
197     AML_PULL_NONE = 3,
198 } AmlPinConfig;
199
200 typedef
201 struct AcpiBuildTables {
202     GArray *table_data;
203     GArray *rsdp;
204     GArray *tcpalog;
205     GArray *linker;
206 } AcpiBuildTables;
207
208 /**
209  * init_aml_allocator:
210  *
211  * Called for initializing API allocator which allow to use
212  * AML API.
213  * Returns: toplevel container which accumulates all other
214  * AML elements for a table.
215  */
216 Aml *init_aml_allocator(void);
217
218 /**
219  * free_aml_allocator:
220  *
221  * Releases all elements used by AML API, frees associated memory
222  * and invalidates AML allocator. After this call @init_aml_allocator
223  * should be called again if AML API is to be used again.
224  */
225 void free_aml_allocator(void);
226
227 /**
228  * aml_append:
229  * @parent_ctx: context to which @child element is added
230  * @child: element that is copied into @parent_ctx context
231  *
232  * Joins Aml elements together and helps to construct AML tables
233  * Examle of usage:
234  *   Aml *table = aml_def_block("SSDT", ...);
235  *   Aml *sb = aml_scope("\\_SB");
236  *   Aml *dev = aml_device("PCI0");
237  *
238  *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
239  *   aml_append(sb, dev);
240  *   aml_append(table, sb);
241  */
242 void aml_append(Aml *parent_ctx, Aml *child);
243
244 /* non block AML object primitives */
245 Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
246 Aml *aml_name_decl(const char *name, Aml *val);
247 Aml *aml_return(Aml *val);
248 Aml *aml_int(const uint64_t val);
249 Aml *aml_arg(int pos);
250 Aml *aml_to_integer(Aml *arg);
251 Aml *aml_to_hexstring(Aml *src, Aml *dst);
252 Aml *aml_to_buffer(Aml *src, Aml *dst);
253 Aml *aml_store(Aml *val, Aml *target);
254 Aml *aml_and(Aml *arg1, Aml *arg2);
255 Aml *aml_or(Aml *arg1, Aml *arg2);
256 Aml *aml_lor(Aml *arg1, Aml *arg2);
257 Aml *aml_shiftleft(Aml *arg1, Aml *count);
258 Aml *aml_shiftright(Aml *arg1, Aml *count, Aml *dst);
259 Aml *aml_lless(Aml *arg1, Aml *arg2);
260 Aml *aml_add(Aml *arg1, Aml *arg2, Aml *dst);
261 Aml *aml_subtract(Aml *arg1, Aml *arg2, Aml *dst);
262 Aml *aml_increment(Aml *arg);
263 Aml *aml_decrement(Aml *arg);
264 Aml *aml_index(Aml *arg1, Aml *idx);
265 Aml *aml_notify(Aml *arg1, Aml *arg2);
266 Aml *aml_call0(const char *method);
267 Aml *aml_call1(const char *method, Aml *arg1);
268 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
269 Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
270 Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
271 Aml *aml_gpio_int(AmlConsumerAndProducer con_and_pro,
272                   AmlLevelAndEdge edge_level,
273                   AmlActiveHighAndLow active_level, AmlShared shared,
274                   AmlPinConfig pin_config, uint16_t debounce_timeout,
275                   const uint32_t pin_list[], uint32_t pin_count,
276                   const char *resource_source_name,
277                   const uint8_t *vendor_data, uint16_t vendor_data_len);
278 Aml *aml_memory32_fixed(uint32_t addr, uint32_t size,
279                         AmlReadAndWrite read_and_write);
280 Aml *aml_interrupt(AmlConsumerAndProducer con_and_pro,
281                    AmlLevelAndEdge level_and_edge,
282                    AmlActiveHighAndLow high_and_low, AmlShared shared,
283                    uint32_t *irq_list, uint8_t irq_count);
284 Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
285             uint8_t aln, uint8_t len);
286 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
287                           uint32_t offset, uint32_t len);
288 Aml *aml_irq_no_flags(uint8_t irq);
289 Aml *aml_named_field(const char *name, unsigned length);
290 Aml *aml_reserved_field(unsigned length);
291 Aml *aml_local(int num);
292 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
293 Aml *aml_lnot(Aml *arg);
294 Aml *aml_equal(Aml *arg1, Aml *arg2);
295 Aml *aml_lgreater(Aml *arg1, Aml *arg2);
296 Aml *aml_lgreater_equal(Aml *arg1, Aml *arg2);
297 Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
298                    const char *name_format, ...) GCC_FMT_ATTR(4, 5);
299 Aml *aml_eisaid(const char *str);
300 Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
301                          AmlDecode dec, uint16_t addr_gran,
302                          uint16_t addr_min, uint16_t addr_max,
303                          uint16_t addr_trans, uint16_t len);
304 Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
305                  AmlDecode dec, AmlISARanges isa_ranges,
306                  uint16_t addr_gran, uint16_t addr_min,
307                  uint16_t addr_max, uint16_t addr_trans,
308                  uint16_t len);
309 Aml *aml_dword_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
310                  AmlDecode dec, AmlISARanges isa_ranges,
311                  uint32_t addr_gran, uint32_t addr_min,
312                  uint32_t addr_max, uint32_t addr_trans,
313                  uint32_t len);
314 Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
315                       AmlMaxFixed max_fixed, AmlCacheable cacheable,
316                       AmlReadAndWrite read_and_write,
317                       uint32_t addr_gran, uint32_t addr_min,
318                       uint32_t addr_max, uint32_t addr_trans,
319                       uint32_t len);
320 Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
321                       AmlMaxFixed max_fixed, AmlCacheable cacheable,
322                       AmlReadAndWrite read_and_write,
323                       uint64_t addr_gran, uint64_t addr_min,
324                       uint64_t addr_max, uint64_t addr_trans,
325                       uint64_t len);
326 Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz,
327              uint8_t channel);
328 Aml *aml_sleep(uint64_t msec);
329
330 /* Block AML object primitives */
331 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
332 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
333 Aml *aml_method(const char *name, int arg_count, AmlSerializeFlag sflag);
334 Aml *aml_if(Aml *predicate);
335 Aml *aml_else(void);
336 Aml *aml_while(Aml *predicate);
337 Aml *aml_package(uint8_t num_elements);
338 Aml *aml_buffer(int buffer_size, uint8_t *byte_list);
339 Aml *aml_resource_template(void);
340 Aml *aml_field(const char *name, AmlAccessType type, AmlLockRule lock,
341                AmlUpdateRule rule);
342 Aml *aml_mutex(const char *name, uint8_t sync_level);
343 Aml *aml_acquire(Aml *mutex, uint16_t timeout);
344 Aml *aml_release(Aml *mutex);
345 Aml *aml_alias(const char *source_object, const char *alias_object);
346 Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name);
347 Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name);
348 Aml *aml_varpackage(uint32_t num_elements);
349 Aml *aml_touuid(const char *uuid);
350 Aml *aml_unicode(const char *str);
351 Aml *aml_derefof(Aml *arg);
352 Aml *aml_sizeof(Aml *arg);
353
354 void
355 build_header(GArray *linker, GArray *table_data,
356              AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
357              const char *oem_table_id);
358 void *acpi_data_push(GArray *table_data, unsigned size);
359 unsigned acpi_data_len(GArray *table);
360 void acpi_add_table(GArray *table_offsets, GArray *table_data);
361 void acpi_build_tables_init(AcpiBuildTables *tables);
362 void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre);
363 void
364 build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets);
365
366 #endif
This page took 0.044136 seconds and 4 git commands to generate.