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