1 #ifndef HW_ACPI_GEN_UTILS_H
2 #define HW_ACPI_GEN_UTILS_H
6 #include "qemu/compiler.h"
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
, /* ame as AML_PACKAGE but also has 'ExOpPrefix' */
13 AML_BUFFER
, /* data encoded as 'DefBuffer' */
14 AML_RES_TEMPLATE
, /* encoded as ResourceTemplate macro */
22 AmlBlockFlags block_flags
;
24 typedef struct Aml Aml
;
29 * Called for initializing API allocator which allow to use
31 * Returns: toplevel container which accumulates all other
32 * AML elements for a table.
34 Aml
*init_aml_allocator(void);
39 * Releases all elements used by AML API, frees associated memory
40 * and invalidates AML allocator. After this call @init_aml_allocator
41 * should be called again if AML API is to be used again.
43 void free_aml_allocator(void);
47 * @parent_ctx: context to which @child element is added
48 * @child: element that is copied into @parent_ctx context
50 * Joins Aml elements together and helps to construct AML tables
52 * Aml *table = aml_def_block("SSDT", ...);
53 * Aml *sb = aml_scope("\_SB");
54 * Aml *dev = aml_device("PCI0");
56 * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
57 * aml_append(sb, dev);
58 * aml_append(table, sb);
60 void aml_append(Aml
*parent_ctx
, Aml
*child
);
62 /* non block AML object primitives */
63 Aml
*aml_name(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
64 Aml
*aml_name_decl(const char *name
, Aml
*val
);
65 Aml
*aml_return(Aml
*val
);
66 Aml
*aml_int(const uint64_t val
);
67 Aml
*aml_arg(int pos
);
68 Aml
*aml_store(Aml
*val
, Aml
*target
);
69 Aml
*aml_and(Aml
*arg1
, Aml
*arg2
);
70 Aml
*aml_notify(Aml
*arg1
, Aml
*arg2
);
71 Aml
*aml_call1(const char *method
, Aml
*arg1
);
72 Aml
*aml_call2(const char *method
, Aml
*arg1
, Aml
*arg2
);
73 Aml
*aml_call3(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
);
74 Aml
*aml_call4(const char *method
, Aml
*arg1
, Aml
*arg2
, Aml
*arg3
, Aml
*arg4
);
76 /* Block AML object primitives */
77 Aml
*aml_scope(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
78 Aml
*aml_device(const char *name_format
, ...) GCC_FMT_ATTR(1, 2);
79 Aml
*aml_method(const char *name
, int arg_count
);
80 Aml
*aml_if(Aml
*predicate
);
81 Aml
*aml_package(uint8_t num_elements
);
82 Aml
*aml_buffer(void);
83 Aml
*aml_resource_template(void);
86 GArray
*build_alloc_array(void);
87 void build_free_array(GArray
*array
);
88 void build_prepend_byte(GArray
*array
, uint8_t val
);
89 void build_append_byte(GArray
*array
, uint8_t val
);
90 void build_append_array(GArray
*array
, GArray
*val
);
92 void GCC_FMT_ATTR(2, 3)
93 build_append_namestring(GArray
*array
, const char *format
, ...);
95 void build_prepend_package_length(GArray
*package
);
96 void build_package(GArray
*package
, uint8_t op
);
97 void build_append_int(GArray
*table
, uint64_t value
);
98 void build_extop_package(GArray
*package
, uint8_t op
);