xref: /openbmc/qemu/include/hw/acpi/aml-build.h (revision e2ea299b01fbd9d4d0262cfbfcbdbd02ada984a5)
119934e0eSIgor Mammedov #ifndef HW_ACPI_GEN_UTILS_H
219934e0eSIgor Mammedov #define HW_ACPI_GEN_UTILS_H
319934e0eSIgor Mammedov 
419934e0eSIgor Mammedov #include <stdint.h>
519934e0eSIgor Mammedov #include <glib.h>
619934e0eSIgor Mammedov #include "qemu/compiler.h"
719934e0eSIgor Mammedov 
80f2707e4SIgor Mammedov typedef enum {
90f2707e4SIgor Mammedov     AML_NO_OPCODE = 0,/* has only data */
100f2707e4SIgor Mammedov     AML_OPCODE,       /* has opcode optionally followed by data */
110f2707e4SIgor Mammedov     AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
120f2707e4SIgor Mammedov     AML_EXT_PACKAGE,  /* ame as AML_PACKAGE but also has 'ExOpPrefix' */
130f2707e4SIgor Mammedov     AML_BUFFER,       /* data encoded as 'DefBuffer' */
140f2707e4SIgor Mammedov     AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
150f2707e4SIgor Mammedov } AmlBlockFlags;
160f2707e4SIgor Mammedov 
170f2707e4SIgor Mammedov struct Aml {
180f2707e4SIgor Mammedov     GArray *buf;
190f2707e4SIgor Mammedov 
200f2707e4SIgor Mammedov     /*< private >*/
210f2707e4SIgor Mammedov     uint8_t op;
220f2707e4SIgor Mammedov     AmlBlockFlags block_flags;
230f2707e4SIgor Mammedov };
240f2707e4SIgor Mammedov typedef struct Aml Aml;
250f2707e4SIgor Mammedov 
2652fa397cSIgor Mammedov typedef enum {
2752fa397cSIgor Mammedov     aml_decode10 = 0,
2852fa397cSIgor Mammedov     aml_decode16 = 1,
2952fa397cSIgor Mammedov } AmlIODecode;
3052fa397cSIgor Mammedov 
3131127938SIgor Mammedov typedef enum {
32*e2ea299bSIgor Mammedov     aml_any_acc = 0,
33214ae59fSIgor Mammedov     aml_byte_acc = 1,
34*e2ea299bSIgor Mammedov     aml_word_acc = 2,
35*e2ea299bSIgor Mammedov     aml_dword_acc = 3,
36*e2ea299bSIgor Mammedov     aml_qword_acc = 4,
37*e2ea299bSIgor Mammedov     aml_buffer_acc = 5,
38214ae59fSIgor Mammedov } AmlFieldFlags;
39214ae59fSIgor Mammedov 
40214ae59fSIgor Mammedov typedef enum {
4131127938SIgor Mammedov     aml_system_memory = 0x00,
4231127938SIgor Mammedov     aml_system_io = 0x01,
4331127938SIgor Mammedov } AmlRegionSpace;
4431127938SIgor Mammedov 
450f2707e4SIgor Mammedov /**
460f2707e4SIgor Mammedov  * init_aml_allocator:
470f2707e4SIgor Mammedov  *
480f2707e4SIgor Mammedov  * Called for initializing API allocator which allow to use
490f2707e4SIgor Mammedov  * AML API.
500f2707e4SIgor Mammedov  * Returns: toplevel container which accumulates all other
510f2707e4SIgor Mammedov  * AML elements for a table.
520f2707e4SIgor Mammedov  */
530f2707e4SIgor Mammedov Aml *init_aml_allocator(void);
540f2707e4SIgor Mammedov 
550f2707e4SIgor Mammedov /**
560f2707e4SIgor Mammedov  * free_aml_allocator:
570f2707e4SIgor Mammedov  *
580f2707e4SIgor Mammedov  * Releases all elements used by AML API, frees associated memory
590f2707e4SIgor Mammedov  * and invalidates AML allocator. After this call @init_aml_allocator
600f2707e4SIgor Mammedov  * should be called again if AML API is to be used again.
610f2707e4SIgor Mammedov  */
620f2707e4SIgor Mammedov void free_aml_allocator(void);
630f2707e4SIgor Mammedov 
640f2707e4SIgor Mammedov /**
650f2707e4SIgor Mammedov  * aml_append:
660f2707e4SIgor Mammedov  * @parent_ctx: context to which @child element is added
670f2707e4SIgor Mammedov  * @child: element that is copied into @parent_ctx context
680f2707e4SIgor Mammedov  *
690f2707e4SIgor Mammedov  * Joins Aml elements together and helps to construct AML tables
700f2707e4SIgor Mammedov  * Examle of usage:
710f2707e4SIgor Mammedov  *   Aml *table = aml_def_block("SSDT", ...);
720f2707e4SIgor Mammedov  *   Aml *sb = aml_scope("\_SB");
730f2707e4SIgor Mammedov  *   Aml *dev = aml_device("PCI0");
740f2707e4SIgor Mammedov  *
750f2707e4SIgor Mammedov  *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
760f2707e4SIgor Mammedov  *   aml_append(sb, dev);
770f2707e4SIgor Mammedov  *   aml_append(table, sb);
780f2707e4SIgor Mammedov  */
790f2707e4SIgor Mammedov void aml_append(Aml *parent_ctx, Aml *child);
800f2707e4SIgor Mammedov 
813c054bd5SIgor Mammedov /* non block AML object primitives */
823c054bd5SIgor Mammedov Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
833c054bd5SIgor Mammedov Aml *aml_name_decl(const char *name, Aml *val);
84b25af5adSIgor Mammedov Aml *aml_return(Aml *val);
85295a515dSIgor Mammedov Aml *aml_int(const uint64_t val);
867193f3a6SIgor Mammedov Aml *aml_arg(int pos);
87c263b3f7SIgor Mammedov Aml *aml_store(Aml *val, Aml *target);
88926f5aaeSIgor Mammedov Aml *aml_and(Aml *arg1, Aml *arg2);
8934189453SIgor Mammedov Aml *aml_notify(Aml *arg1, Aml *arg2);
903f3992b7SIgor Mammedov Aml *aml_call1(const char *method, Aml *arg1);
913f3992b7SIgor Mammedov Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
923f3992b7SIgor Mammedov Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
933f3992b7SIgor Mammedov Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
9452fa397cSIgor Mammedov Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
9552fa397cSIgor Mammedov             uint8_t aln, uint8_t len);
9631127938SIgor Mammedov Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
9731127938SIgor Mammedov                           uint32_t offset, uint32_t len);
98214ae59fSIgor Mammedov Aml *aml_named_field(const char *name, unsigned length);
99*e2ea299bSIgor Mammedov Aml *aml_reserved_field(unsigned length);
100b8a5d689SIgor Mammedov Aml *aml_local(int num);
101d5e5830fSIgor Mammedov Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
10215e44e56SIgor Mammedov Aml *aml_equal(Aml *arg1, Aml *arg2);
1033dd15643SIgor Mammedov Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
1043dd15643SIgor Mammedov                    const char *name_format, ...) GCC_FMT_ATTR(4, 5);
105a7891dacSIgor Mammedov Aml *aml_eisaid(const char *str);
1063c054bd5SIgor Mammedov 
1072ef7c27bSIgor Mammedov /* Block AML object primitives */
1082ef7c27bSIgor Mammedov Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
109be06ebd0SIgor Mammedov Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
110ea2407d7SIgor Mammedov Aml *aml_method(const char *name, int arg_count);
11132acac9eSIgor Mammedov Aml *aml_if(Aml *predicate);
1123bfa74a7SIgor Mammedov Aml *aml_package(uint8_t num_elements);
11304b8da54SIgor Mammedov Aml *aml_buffer(void);
114ad4a80bcSIgor Mammedov Aml *aml_resource_template(void);
115214ae59fSIgor Mammedov Aml *aml_field(const char *name, AmlFieldFlags flags);
116a678508eSIgor Mammedov Aml *aml_varpackage(uint32_t num_elements);
1172ef7c27bSIgor Mammedov 
1180f2707e4SIgor Mammedov /* other helpers */
11919934e0eSIgor Mammedov GArray *build_alloc_array(void);
12019934e0eSIgor Mammedov void build_free_array(GArray *array);
12119934e0eSIgor Mammedov void build_prepend_byte(GArray *array, uint8_t val);
12219934e0eSIgor Mammedov void build_append_byte(GArray *array, uint8_t val);
12319934e0eSIgor Mammedov void build_append_array(GArray *array, GArray *val);
12419934e0eSIgor Mammedov 
12519934e0eSIgor Mammedov void GCC_FMT_ATTR(2, 3)
126eae8bdedSIgor Mammedov build_append_namestring(GArray *array, const char *format, ...);
12719934e0eSIgor Mammedov 
12819fff2d4SIgor Mammedov void
12919fff2d4SIgor Mammedov build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
130661875e9SIgor Mammedov void build_package(GArray *package, uint8_t op);
131295a515dSIgor Mammedov void build_append_int(GArray *table, uint64_t value);
13219934e0eSIgor Mammedov void build_extop_package(GArray *package, uint8_t op);
13319934e0eSIgor Mammedov 
13419934e0eSIgor Mammedov #endif
135