xref: /openbmc/qemu/include/hw/acpi/aml-build.h (revision 81b07353c5e7ae9ae9360c357b7b4732b1cb03b4)
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"
7 
8 typedef enum {
9     AML_NO_OPCODE = 0,/* has only data */
10     AML_OPCODE,       /* has opcode optionally followed by data */
11     AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
12     AML_EXT_PACKAGE,  /* Same as AML_PACKAGE but also has 'ExOpPrefix' */
13     AML_BUFFER,       /* data encoded as 'DefBuffer' */
14     AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
15 } AmlBlockFlags;
16 
17 struct Aml {
18     GArray *buf;
19 
20     /*< private >*/
21     uint8_t op;
22     AmlBlockFlags block_flags;
23 };
24 typedef struct Aml Aml;
25 
26 typedef enum {
27     aml_decode10 = 0,
28     aml_decode16 = 1,
29 } AmlIODecode;
30 
31 typedef enum {
32     aml_any_acc = 0,
33     aml_byte_acc = 1,
34     aml_word_acc = 2,
35     aml_dword_acc = 3,
36     aml_qword_acc = 4,
37     aml_buffer_acc = 5,
38 } AmlFieldFlags;
39 
40 typedef enum {
41     aml_system_memory = 0x00,
42     aml_system_io = 0x01,
43 } AmlRegionSpace;
44 
45 typedef enum {
46     aml_memory_range = 0,
47     aml_io_range = 1,
48     aml_bus_number_range = 2,
49 } AmlResourceType;
50 
51 typedef enum {
52     aml_sub_decode = 1 << 1,
53     aml_pos_decode = 0
54 } AmlDecode;
55 
56 typedef enum {
57     aml_max_fixed = 1 << 3,
58     aml_max_not_fixed = 0,
59 } AmlMaxFixed;
60 
61 typedef enum {
62     aml_min_fixed = 1 << 2,
63     aml_min_not_fixed = 0
64 } AmlMinFixed;
65 
66 /*
67  * ACPI 1.0b: Table 6-26 I/O Resource Flag (Resource Type = 1) Definitions
68  * _RNG field definition
69  */
70 typedef enum {
71     aml_isa_only = 1,
72     aml_non_isa_only = 2,
73     aml_entire_range = 3,
74 } AmlISARanges;
75 
76 /*
77  * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
78  * _MEM field definition
79  */
80 typedef enum {
81     aml_non_cacheable = 0,
82     aml_cacheable = 1,
83     aml_write_combining = 2,
84     aml_prefetchable = 3,
85 } AmlCacheble;
86 
87 /*
88  * ACPI 1.0b: Table 6-25 Memory Resource Flag (Resource Type = 0) Definitions
89  * _RW field definition
90  */
91 typedef enum {
92     aml_ReadOnly = 0,
93     aml_ReadWrite = 1,
94 } AmlReadAndWrite;
95 
96 /**
97  * init_aml_allocator:
98  *
99  * Called for initializing API allocator which allow to use
100  * AML API.
101  * Returns: toplevel container which accumulates all other
102  * AML elements for a table.
103  */
104 Aml *init_aml_allocator(void);
105 
106 /**
107  * free_aml_allocator:
108  *
109  * Releases all elements used by AML API, frees associated memory
110  * and invalidates AML allocator. After this call @init_aml_allocator
111  * should be called again if AML API is to be used again.
112  */
113 void free_aml_allocator(void);
114 
115 /**
116  * aml_append:
117  * @parent_ctx: context to which @child element is added
118  * @child: element that is copied into @parent_ctx context
119  *
120  * Joins Aml elements together and helps to construct AML tables
121  * Examle of usage:
122  *   Aml *table = aml_def_block("SSDT", ...);
123  *   Aml *sb = aml_scope("\_SB");
124  *   Aml *dev = aml_device("PCI0");
125  *
126  *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
127  *   aml_append(sb, dev);
128  *   aml_append(table, sb);
129  */
130 void aml_append(Aml *parent_ctx, Aml *child);
131 
132 /* non block AML object primitives */
133 Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
134 Aml *aml_name_decl(const char *name, Aml *val);
135 Aml *aml_return(Aml *val);
136 Aml *aml_int(const uint64_t val);
137 Aml *aml_arg(int pos);
138 Aml *aml_store(Aml *val, Aml *target);
139 Aml *aml_and(Aml *arg1, Aml *arg2);
140 Aml *aml_notify(Aml *arg1, Aml *arg2);
141 Aml *aml_call1(const char *method, Aml *arg1);
142 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
143 Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
144 Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
145 Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
146             uint8_t aln, uint8_t len);
147 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
148                           uint32_t offset, uint32_t len);
149 Aml *aml_irq_no_flags(uint8_t irq);
150 Aml *aml_named_field(const char *name, unsigned length);
151 Aml *aml_reserved_field(unsigned length);
152 Aml *aml_local(int num);
153 Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
154 Aml *aml_equal(Aml *arg1, Aml *arg2);
155 Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
156                    const char *name_format, ...) GCC_FMT_ATTR(4, 5);
157 Aml *aml_eisaid(const char *str);
158 Aml *aml_word_bus_number(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
159                          AmlDecode dec, uint16_t addr_gran,
160                          uint16_t addr_min, uint16_t addr_max,
161                          uint16_t addr_trans, uint16_t len);
162 Aml *aml_word_io(AmlMinFixed min_fixed, AmlMaxFixed max_fixed,
163                  AmlDecode dec, AmlISARanges isa_ranges,
164                  uint16_t addr_gran, uint16_t addr_min,
165                  uint16_t addr_max, uint16_t addr_trans,
166                  uint16_t len);
167 Aml *aml_dword_memory(AmlDecode dec, AmlMinFixed min_fixed,
168                       AmlMaxFixed max_fixed, AmlCacheble cacheable,
169                       AmlReadAndWrite read_and_write,
170                       uint32_t addr_gran, uint32_t addr_min,
171                       uint32_t addr_max, uint32_t addr_trans,
172                       uint32_t len);
173 Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed,
174                       AmlMaxFixed max_fixed, AmlCacheble cacheable,
175                       AmlReadAndWrite read_and_write,
176                       uint64_t addr_gran, uint64_t addr_min,
177                       uint64_t addr_max, uint64_t addr_trans,
178                       uint64_t len);
179 
180 /* Block AML object primitives */
181 Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
182 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
183 Aml *aml_method(const char *name, int arg_count);
184 Aml *aml_if(Aml *predicate);
185 Aml *aml_package(uint8_t num_elements);
186 Aml *aml_buffer(void);
187 Aml *aml_resource_template(void);
188 Aml *aml_field(const char *name, AmlFieldFlags flags);
189 Aml *aml_varpackage(uint32_t num_elements);
190 
191 #endif
192