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