]>
Commit | Line | Data |
---|---|---|
19934e0e IM |
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" | |
658c2718 SZ |
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 | ||
658c2718 SZ |
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" | |
19934e0e | 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 | ||
52fa397c | 37 | typedef enum { |
ff80dc7f SZ |
38 | AML_DECODE10 = 0, |
39 | AML_DECODE16 = 1, | |
52fa397c IM |
40 | } AmlIODecode; |
41 | ||
214ae59f | 42 | typedef enum { |
ff80dc7f SZ |
43 | AML_ANY_ACC = 0, |
44 | AML_BYTE_ACC = 1, | |
45 | AML_WORD_ACC = 2, | |
46 | AML_DWORD_ACC = 3, | |
47 | AML_QWORD_ACC = 4, | |
48 | AML_BUFFER_ACC = 5, | |
af509897 ZG |
49 | } AmlAccessType; |
50 | ||
51 | typedef enum { | |
ff80dc7f SZ |
52 | AML_PRESERVE = 0, |
53 | AML_WRITE_AS_ONES = 1, | |
54 | AML_WRITE_AS_ZEROS = 2, | |
af509897 | 55 | } AmlUpdateRule; |
214ae59f | 56 | |
31127938 | 57 | typedef enum { |
ff80dc7f SZ |
58 | AML_SYSTEM_MEMORY = 0X00, |
59 | AML_SYSTEM_IO = 0X01, | |
31127938 IM |
60 | } AmlRegionSpace; |
61 | ||
6ece7053 | 62 | typedef enum { |
ff80dc7f SZ |
63 | AML_MEMORY_RANGE = 0, |
64 | AML_IO_RANGE = 1, | |
65 | AML_BUS_NUMBER_RANGE = 2, | |
6ece7053 IM |
66 | } AmlResourceType; |
67 | ||
68 | typedef enum { | |
ff80dc7f SZ |
69 | AML_SUB_DECODE = 1 << 1, |
70 | AML_POS_DECODE = 0 | |
6ece7053 IM |
71 | } AmlDecode; |
72 | ||
73 | typedef enum { | |
ff80dc7f SZ |
74 | AML_MAX_FIXED = 1 << 3, |
75 | AML_MAX_NOT_FIXED = 0, | |
6ece7053 IM |
76 | } AmlMaxFixed; |
77 | ||
78 | typedef enum { | |
ff80dc7f SZ |
79 | AML_MIN_FIXED = 1 << 2, |
80 | AML_MIN_NOT_FIXED = 0 | |
6ece7053 IM |
81 | } AmlMinFixed; |
82 | ||
83 | /* | |
84 | * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions | |
85 | * _RNG field definition | |
86 | */ | |
87 | typedef enum { | |
ff80dc7f SZ |
88 | AML_ISA_ONLY = 1, |
89 | AML_NON_ISA_ONLY = 2, | |
90 | AML_ENTIRE_RANGE = 3, | |
6ece7053 IM |
91 | } AmlISARanges; |
92 | ||
93 | /* | |
94 | * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions | |
95 | * _MEM field definition | |
96 | */ | |
97 | typedef enum { | |
ff80dc7f SZ |
98 | AML_NON_CACHEABLE = 0, |
99 | AML_CACHEABLE = 1, | |
100 | AML_WRITE_COMBINING = 2, | |
101 | AML_PREFETCHABLE = 3, | |
102 | } AmlCacheable; | |
6ece7053 IM |
103 | |
104 | /* | |
105 | * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions | |
106 | * _RW field definition | |
107 | */ | |
108 | typedef enum { | |
ff80dc7f SZ |
109 | AML_READ_ONLY = 0, |
110 | AML_READ_WRITE = 1, | |
6ece7053 IM |
111 | } AmlReadAndWrite; |
112 | ||
205d1d1c SZ |
113 | /* |
114 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
115 | * Interrupt Vector Flags Bits[0] Consumer/Producer | |
116 | */ | |
117 | typedef enum { | |
118 | AML_CONSUMER_PRODUCER = 0, | |
119 | AML_CONSUMER = 1, | |
120 | } AmlConsumerAndProducer; | |
121 | ||
122 | /* | |
123 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
124 | * _HE field definition | |
125 | */ | |
126 | typedef enum { | |
127 | AML_LEVEL = 0, | |
128 | AML_EDGE = 1, | |
129 | } AmlLevelAndEdge; | |
130 | ||
131 | /* | |
132 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
133 | * _LL field definition | |
134 | */ | |
135 | typedef enum { | |
136 | AML_ACTIVE_HIGH = 0, | |
137 | AML_ACTIVE_LOW = 1, | |
138 | } AmlActiveHighAndLow; | |
139 | ||
140 | /* | |
141 | * ACPI 5.0: Table 6-187 Extended Interrupt Descriptor Definition | |
142 | * _SHR field definition | |
143 | */ | |
144 | typedef enum { | |
145 | AML_EXCLUSIVE = 0, | |
146 | AML_SHARED = 1, | |
147 | AML_EXCLUSIVE_AND_WAKE = 2, | |
148 | AML_SHARED_AND_WAKE = 3, | |
149 | } AmlShared; | |
150 | ||
658c2718 SZ |
151 | typedef |
152 | struct AcpiBuildTables { | |
153 | GArray *table_data; | |
154 | GArray *rsdp; | |
155 | GArray *tcpalog; | |
156 | GArray *linker; | |
157 | } AcpiBuildTables; | |
158 | ||
0f2707e4 IM |
159 | /** |
160 | * init_aml_allocator: | |
161 | * | |
162 | * Called for initializing API allocator which allow to use | |
163 | * AML API. | |
164 | * Returns: toplevel container which accumulates all other | |
165 | * AML elements for a table. | |
166 | */ | |
167 | Aml *init_aml_allocator(void); | |
168 | ||
169 | /** | |
170 | * free_aml_allocator: | |
171 | * | |
172 | * Releases all elements used by AML API, frees associated memory | |
173 | * and invalidates AML allocator. After this call @init_aml_allocator | |
174 | * should be called again if AML API is to be used again. | |
175 | */ | |
176 | void free_aml_allocator(void); | |
177 | ||
178 | /** | |
179 | * aml_append: | |
180 | * @parent_ctx: context to which @child element is added | |
181 | * @child: element that is copied into @parent_ctx context | |
182 | * | |
183 | * Joins Aml elements together and helps to construct AML tables | |
184 | * Examle of usage: | |
185 | * Aml *table = aml_def_block("SSDT", ...); | |
7824df38 | 186 | * Aml *sb = aml_scope("\\_SB"); |
0f2707e4 IM |
187 | * Aml *dev = aml_device("PCI0"); |
188 | * | |
189 | * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); | |
190 | * aml_append(sb, dev); | |
191 | * aml_append(table, sb); | |
192 | */ | |
193 | void aml_append(Aml *parent_ctx, Aml *child); | |
194 | ||
3c054bd5 IM |
195 | /* non block AML object primitives */ |
196 | Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2); | |
197 | Aml *aml_name_decl(const char *name, Aml *val); | |
b25af5ad | 198 | Aml *aml_return(Aml *val); |
295a515d | 199 | Aml *aml_int(const uint64_t val); |
7193f3a6 | 200 | Aml *aml_arg(int pos); |
c263b3f7 | 201 | Aml *aml_store(Aml *val, Aml *target); |
926f5aae | 202 | Aml *aml_and(Aml *arg1, Aml *arg2); |
922cc882 | 203 | Aml *aml_or(Aml *arg1, Aml *arg2); |
a57ddddd | 204 | Aml *aml_shiftleft(Aml *arg1, Aml *count); |
f7bd7b8e | 205 | Aml *aml_shiftright(Aml *arg1, Aml *count); |
96396e28 | 206 | Aml *aml_lless(Aml *arg1, Aml *arg2); |
c08cf070 | 207 | Aml *aml_add(Aml *arg1, Aml *arg2); |
af39d536 | 208 | Aml *aml_increment(Aml *arg); |
928b8996 | 209 | Aml *aml_index(Aml *arg1, Aml *idx); |
34189453 | 210 | Aml *aml_notify(Aml *arg1, Aml *arg2); |
3f3992b7 IM |
211 | Aml *aml_call1(const char *method, Aml *arg1); |
212 | Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2); | |
213 | Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3); | |
214 | Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4); | |
dc17ab1d SZ |
215 | Aml *aml_memory32_fixed(uint32_t addr, uint32_t size, |
216 | AmlReadAndWrite read_and_write); | |
205d1d1c SZ |
217 | Aml *aml_interrupt(AmlConsumerAndProducer con_and_pro, |
218 | AmlLevelAndEdge level_and_edge, | |
219 | AmlActiveHighAndLow high_and_low, AmlShared shared, | |
220 | uint32_t irq); | |
52fa397c IM |
221 | Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, |
222 | uint8_t aln, uint8_t len); | |
31127938 IM |
223 | Aml *aml_operation_region(const char *name, AmlRegionSpace rs, |
224 | uint32_t offset, uint32_t len); | |
70560453 | 225 | Aml *aml_irq_no_flags(uint8_t irq); |
214ae59f | 226 | Aml *aml_named_field(const char *name, unsigned length); |
e2ea299b | 227 | Aml *aml_reserved_field(unsigned length); |
b8a5d689 | 228 | Aml *aml_local(int num); |
d5e5830f | 229 | Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2); |
ea7df04a | 230 | Aml *aml_lnot(Aml *arg); |
15e44e56 | 231 | Aml *aml_equal(Aml *arg1, Aml *arg2); |
3dd15643 IM |
232 | Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len, |
233 | const char *name_format, ...) GCC_FMT_ATTR(4, 5); | |
a7891dac | 234 | Aml *aml_eisaid(const char *str); |
6ece7053 IM |
235 | Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, |
236 | AmlDecode dec, uint16_t addr_gran, | |
237 | uint16_t addr_min, uint16_t addr_max, | |
238 | uint16_t addr_trans, uint16_t len); | |
239 | Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, | |
240 | AmlDecode dec, AmlISARanges isa_ranges, | |
241 | uint16_t addr_gran, uint16_t addr_min, | |
242 | uint16_t addr_max, uint16_t addr_trans, | |
243 | uint16_t len); | |
616ef329 SZ |
244 | Aml *aml_dword_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed, |
245 | AmlDecode dec, AmlISARanges isa_ranges, | |
246 | uint32_t addr_gran, uint32_t addr_min, | |
247 | uint32_t addr_max, uint32_t addr_trans, | |
248 | uint32_t len); | |
6ece7053 | 249 | Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed, |
ff80dc7f | 250 | AmlMaxFixed max_fixed, AmlCacheable cacheable, |
6ece7053 IM |
251 | AmlReadAndWrite read_and_write, |
252 | uint32_t addr_gran, uint32_t addr_min, | |
253 | uint32_t addr_max, uint32_t addr_trans, | |
254 | uint32_t len); | |
255 | Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed, | |
ff80dc7f | 256 | AmlMaxFixed max_fixed, AmlCacheable cacheable, |
6ece7053 IM |
257 | AmlReadAndWrite read_and_write, |
258 | uint64_t addr_gran, uint64_t addr_min, | |
259 | uint64_t addr_max, uint64_t addr_trans, | |
260 | uint64_t len); | |
3c054bd5 | 261 | |
2ef7c27b IM |
262 | /* Block AML object primitives */ |
263 | Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2); | |
be06ebd0 | 264 | Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2); |
ea2407d7 | 265 | Aml *aml_method(const char *name, int arg_count); |
32acac9e | 266 | Aml *aml_if(Aml *predicate); |
467b07df | 267 | Aml *aml_else(void); |
68e6b0af | 268 | Aml *aml_while(Aml *predicate); |
3bfa74a7 | 269 | Aml *aml_package(uint8_t num_elements); |
ed8b5847 | 270 | Aml *aml_buffer(int buffer_size, uint8_t *byte_list); |
ad4a80bc | 271 | Aml *aml_resource_template(void); |
af509897 | 272 | Aml *aml_field(const char *name, AmlAccessType type, AmlUpdateRule rule); |
ed8176a3 | 273 | Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name); |
a678508e | 274 | Aml *aml_varpackage(uint32_t num_elements); |
b930fb9d | 275 | Aml *aml_touuid(const char *uuid); |
e1f776c4 | 276 | Aml *aml_unicode(const char *str); |
2ef7c27b | 277 | |
658c2718 SZ |
278 | void |
279 | build_header(GArray *linker, GArray *table_data, | |
280 | AcpiTableHeader *h, const char *sig, int len, uint8_t rev); | |
281 | void *acpi_data_push(GArray *table_data, unsigned size); | |
282 | unsigned acpi_data_len(GArray *table); | |
283 | void acpi_add_table(GArray *table_offsets, GArray *table_data); | |
284 | void acpi_build_tables_init(AcpiBuildTables *tables); | |
285 | void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre); | |
243bdb79 SZ |
286 | void |
287 | build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets); | |
658c2718 | 288 | |
19934e0e | 289 | #endif |