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 struct AcpiBuildTables
{
123 * init_aml_allocator:
125 * Called for initializing API allocator which allow to use
127 * Returns: toplevel container which accumulates all other
128 * AML elements for a table.
130 Aml
*init_aml_allocator(void);
133 * free_aml_allocator:
135 * Releases all elements used by AML API, frees associated memory
136 * and invalidates AML allocator. After this call @init_aml_allocator
137 * should be called again if AML API is to be used again.
139 void free_aml_allocator(void);
143 * @parent_ctx: context to which @child element is added
144 * @child: element that is copied into @parent_ctx context
146 * Joins Aml elements together and helps to construct AML tables
148 * Aml *table = aml_def_block("SSDT", ...);
149 * Aml *sb = aml_scope("\\_SB");
150 * Aml *dev = aml_device("PCI0");
152 * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
153 * aml_append(sb, dev);
154 * aml_append(table, sb);
156 void aml_append(Aml
*parent_ctx
, Aml
*child
);
158 /* non block AML object primitives */
159 Aml
*aml_name(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
160 Aml
*aml_name_decl(const char *name
, Aml
*val
);
161 Aml
*aml_return(Aml
*val
);
162 Aml
*aml_int(const uint64_t val
);
163 Aml
*aml_arg(int pos
);
164 Aml
*aml_store(Aml
*val
, Aml
*target
);
165 Aml
*aml_and(Aml
*arg1
, Aml
*arg2
);
166 Aml
*aml_notify(Aml
*arg1
, Aml
*arg2
);
167 Aml
*aml_call1(const char *method
, Aml
*arg1
);
168 Aml
*aml_call2(const char *method
, Aml
*arg1
, Aml
*arg2
);
169 Aml
*aml_call3(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
);
170 Aml
*aml_call4(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
, Aml
*arg4
);
171 Aml
*aml_io(AmlIODecode dec
, uint16_t min_base
, uint16_t max_base
,
172 uint8_t aln
, uint8_t len
);
173 Aml
*aml_operation_region(const char *name
, AmlRegionSpace rs
,
174 uint32_t offset
, uint32_t len
);
175 Aml
*aml_irq_no_flags(uint8_t irq
);
176 Aml
*aml_named_field(const char *name
, unsigned length
);
177 Aml
*aml_reserved_field(unsigned length
);
178 Aml
*aml_local(int num
);
179 Aml
*aml_string(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
180 Aml
*aml_equal(Aml
*arg1
, Aml
*arg2
);
181 Aml
*aml_processor(uint8_t proc_id
, uint32_t pblk_addr
, uint8_t pblk_len
,
182 const char *name_format
, ...) GCC_FMT_ATTR(4, 5);
183 Aml
*aml_eisaid(const char *str
);
184 Aml
*aml_word_bus_number(AmlMinFixed min_fixed
, AmlMaxFixed max_fixed
,
185 AmlDecode dec
, uint16_t addr_gran
,
186 uint16_t addr_min
, uint16_t addr_max
,
187 uint16_t addr_trans
, uint16_t len
);
188 Aml
*aml_word_io(AmlMinFixed min_fixed
, AmlMaxFixed max_fixed
,
189 AmlDecode dec
, AmlISARanges isa_ranges
,
190 uint16_t addr_gran
, uint16_t addr_min
,
191 uint16_t addr_max
, uint16_t addr_trans
,
193 Aml
*aml_dword_memory(AmlDecode dec
, AmlMinFixed min_fixed
,
194 AmlMaxFixed max_fixed
, AmlCacheble cacheable
,
195 AmlReadAndWrite read_and_write
,
196 uint32_t addr_gran
, uint32_t addr_min
,
197 uint32_t addr_max
, uint32_t addr_trans
,
199 Aml
*aml_qword_memory(AmlDecode dec
, AmlMinFixed min_fixed
,
200 AmlMaxFixed max_fixed
, AmlCacheble cacheable
,
201 AmlReadAndWrite read_and_write
,
202 uint64_t addr_gran
, uint64_t addr_min
,
203 uint64_t addr_max
, uint64_t addr_trans
,
206 /* Block AML object primitives */
207 Aml
*aml_scope(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
208 Aml
*aml_device(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
209 Aml
*aml_method(const char *name
, int arg_count
);
210 Aml
*aml_if(Aml
*predicate
);
211 Aml
*aml_package(uint8_t num_elements
);
212 Aml
*aml_buffer(void);
213 Aml
*aml_resource_template(void);
214 Aml
*aml_field(const char *name
, AmlAccessType type
, AmlUpdateRule rule
);
215 Aml
*aml_varpackage(uint32_t num_elements
);
218 build_header(GArray
*linker
, GArray
*table_data
,
219 AcpiTableHeader
*h
, const char *sig
, int len
, uint8_t rev
);
220 void *acpi_data_push(GArray
*table_data
, unsigned size
);
221 unsigned acpi_data_len(GArray
*table
);
222 void acpi_add_table(GArray
*table_offsets
, GArray
*table_data
);
223 void acpi_build_tables_init(AcpiBuildTables
*tables
);
224 void acpi_build_tables_cleanup(AcpiBuildTables
*tables
, bool mfre
);