1 #ifndef HW_ACPI_GEN_UTILS_H
2 #define HW_ACPI_GEN_UTILS_H
6 #include "qemu/compiler.h"
7 #include "hw/acpi/acpi-defs.h"
9 /* Reserve RAM space for tables: add another order of magnitude. */
10 #define ACPI_BUILD_TABLE_MAX_SIZE 0x200000
12 #define ACPI_BUILD_APPNAME "Bochs"
13 #define ACPI_BUILD_APPNAME6 "BOCHS "
14 #define ACPI_BUILD_APPNAME4 "BXPC"
16 #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables"
17 #define ACPI_BUILD_RSDP_FILE "etc/acpi/rsdp"
18 #define ACPI_BUILD_TPMLOG_FILE "etc/tpm/log"
21 AML_NO_OPCODE
= 0,/* has only data */
22 AML_OPCODE
, /* has opcode optionally followed by data */
23 AML_PACKAGE
, /* has opcode and uses PkgLength for its length */
24 AML_EXT_PACKAGE
, /* Same as AML_PACKAGE but also has 'ExOpPrefix' */
25 AML_BUFFER
, /* data encoded as 'DefBuffer' */
26 AML_RES_TEMPLATE
, /* encoded as ResourceTemplate macro */
34 AmlBlockFlags block_flags
;
36 typedef struct Aml Aml
;
54 AML_WRITE_AS_ONES
= 1,
55 AML_WRITE_AS_ZEROS
= 2,
59 AML_SYSTEM_MEMORY
= 0X00,
66 AML_BUS_NUMBER_RANGE
= 2,
70 AML_SUB_DECODE
= 1 << 1,
75 AML_MAX_FIXED
= 1 << 3,
76 AML_MAX_NOT_FIXED
= 0,
80 AML_MIN_FIXED
= 1 << 2,
85 * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
86 * _RNG field definition
95 * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
96 * _MEM field definition
99 AML_NON_CACHEABLE
= 0,
101 AML_WRITE_COMBINING
= 2,
102 AML_PREFETCHABLE
= 3,
106 * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
107 * _RW field definition
115 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
116 * Interrupt Vector Flags Bits[0] Consumer/Producer
119 AML_CONSUMER_PRODUCER
= 0,
121 } AmlConsumerAndProducer
;
124 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
125 * _HE field definition
133 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
134 * _LL field definition
139 } AmlActiveHighAndLow
;
142 * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition
143 * _SHR field definition
148 AML_EXCLUSIVE_AND_WAKE
= 2,
149 AML_SHARED_AND_WAKE
= 3,
153 struct AcpiBuildTables
{
161 * init_aml_allocator:
163 * Called for initializing API allocator which allow to use
165 * Returns: toplevel container which accumulates all other
166 * AML elements for a table.
168 Aml
*init_aml_allocator(void);
171 * free_aml_allocator:
173 * Releases all elements used by AML API, frees associated memory
174 * and invalidates AML allocator. After this call @init_aml_allocator
175 * should be called again if AML API is to be used again.
177 void free_aml_allocator(void);
181 * @parent_ctx: context to which @child element is added
182 * @child: element that is copied into @parent_ctx context
184 * Joins Aml elements together and helps to construct AML tables
186 * Aml *table = aml_def_block("SSDT", ...);
187 * Aml *sb = aml_scope("\\_SB");
188 * Aml *dev = aml_device("PCI0");
190 * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
191 * aml_append(sb, dev);
192 * aml_append(table, sb);
194 void aml_append(Aml
*parent_ctx
, Aml
*child
);
196 /* non block AML object primitives */
197 Aml
*aml_name(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
198 Aml
*aml_name_decl(const char *name
, Aml
*val
);
199 Aml
*aml_return(Aml
*val
);
200 Aml
*aml_int(const uint64_t val
);
201 Aml
*aml_arg(int pos
);
202 Aml
*aml_store(Aml
*val
, Aml
*target
);
203 Aml
*aml_and(Aml
*arg1
, Aml
*arg2
);
204 Aml
*aml_notify(Aml
*arg1
, Aml
*arg2
);
205 Aml
*aml_call1(const char *method
, Aml
*arg1
);
206 Aml
*aml_call2(const char *method
, Aml
*arg1
, Aml
*arg2
);
207 Aml
*aml_call3(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
);
208 Aml
*aml_call4(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
, Aml
*arg4
);
209 Aml
*aml_memory32_fixed(uint32_t addr
, uint32_t size
,
210 AmlReadAndWrite read_and_write
);
211 Aml
*aml_interrupt(AmlConsumerAndProducer con_and_pro
,
212 AmlLevelAndEdge level_and_edge
,
213 AmlActiveHighAndLow high_and_low
, AmlShared shared
,
215 Aml
*aml_io(AmlIODecode dec
, uint16_t min_base
, uint16_t max_base
,
216 uint8_t aln
, uint8_t len
);
217 Aml
*aml_operation_region(const char *name
, AmlRegionSpace rs
,
218 uint32_t offset
, uint32_t len
);
219 Aml
*aml_irq_no_flags(uint8_t irq
);
220 Aml
*aml_named_field(const char *name
, unsigned length
);
221 Aml
*aml_reserved_field(unsigned length
);
222 Aml
*aml_local(int num
);
223 Aml
*aml_string(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
224 Aml
*aml_equal(Aml
*arg1
, Aml
*arg2
);
225 Aml
*aml_processor(uint8_t proc_id
, uint32_t pblk_addr
, uint8_t pblk_len
,
226 const char *name_format
, ...) GCC_FMT_ATTR(4, 5);
227 Aml
*aml_eisaid(const char *str
);
228 Aml
*aml_word_bus_number(AmlMinFixed min_fixed
, AmlMaxFixed max_fixed
,
229 AmlDecode dec
, uint16_t addr_gran
,
230 uint16_t addr_min
, uint16_t addr_max
,
231 uint16_t addr_trans
, uint16_t len
);
232 Aml
*aml_word_io(AmlMinFixed min_fixed
, AmlMaxFixed max_fixed
,
233 AmlDecode dec
, AmlISARanges isa_ranges
,
234 uint16_t addr_gran
, uint16_t addr_min
,
235 uint16_t addr_max
, uint16_t addr_trans
,
237 Aml
*aml_dword_memory(AmlDecode dec
, AmlMinFixed min_fixed
,
238 AmlMaxFixed max_fixed
, AmlCacheable cacheable
,
239 AmlReadAndWrite read_and_write
,
240 uint32_t addr_gran
, uint32_t addr_min
,
241 uint32_t addr_max
, uint32_t addr_trans
,
243 Aml
*aml_qword_memory(AmlDecode dec
, AmlMinFixed min_fixed
,
244 AmlMaxFixed max_fixed
, AmlCacheable cacheable
,
245 AmlReadAndWrite read_and_write
,
246 uint64_t addr_gran
, uint64_t addr_min
,
247 uint64_t addr_max
, uint64_t addr_trans
,
250 /* Block AML object primitives */
251 Aml
*aml_scope(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
252 Aml
*aml_device(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
253 Aml
*aml_method(const char *name
, int arg_count
);
254 Aml
*aml_if(Aml
*predicate
);
255 Aml
*aml_package(uint8_t num_elements
);
256 Aml
*aml_buffer(void);
257 Aml
*aml_resource_template(void);
258 Aml
*aml_field(const char *name
, AmlAccessType type
, AmlUpdateRule rule
);
259 Aml
*aml_varpackage(uint32_t num_elements
);
262 build_header(GArray
*linker
, GArray
*table_data
,
263 AcpiTableHeader
*h
, const char *sig
, int len
, uint8_t rev
);
264 void *acpi_data_push(GArray
*table_data
, unsigned size
);
265 unsigned acpi_data_len(GArray
*table
);
266 void acpi_add_table(GArray
*table_offsets
, GArray
*table_data
);
267 void acpi_build_tables_init(AcpiBuildTables
*tables
);
268 void acpi_build_tables_cleanup(AcpiBuildTables
*tables
, bool mfre
);
270 build_rsdt(GArray
*table_data
, GArray
*linker
, GArray
*table_offsets
);