xref: /openbmc/qemu/include/hw/acpi/aml-build.h (revision 3dd156435369153c1c1d890b9ef525f1d033a971)
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 {
32214ae59fSIgor Mammedov     aml_byte_acc = 1,
33214ae59fSIgor Mammedov } AmlFieldFlags;
34214ae59fSIgor Mammedov 
35214ae59fSIgor Mammedov typedef enum {
3631127938SIgor Mammedov     aml_system_memory = 0x00,
3731127938SIgor Mammedov     aml_system_io = 0x01,
3831127938SIgor Mammedov } AmlRegionSpace;
3931127938SIgor Mammedov 
400f2707e4SIgor Mammedov /**
410f2707e4SIgor Mammedov  * init_aml_allocator:
420f2707e4SIgor Mammedov  *
430f2707e4SIgor Mammedov  * Called for initializing API allocator which allow to use
440f2707e4SIgor Mammedov  * AML API.
450f2707e4SIgor Mammedov  * Returns: toplevel container which accumulates all other
460f2707e4SIgor Mammedov  * AML elements for a table.
470f2707e4SIgor Mammedov  */
480f2707e4SIgor Mammedov Aml *init_aml_allocator(void);
490f2707e4SIgor Mammedov 
500f2707e4SIgor Mammedov /**
510f2707e4SIgor Mammedov  * free_aml_allocator:
520f2707e4SIgor Mammedov  *
530f2707e4SIgor Mammedov  * Releases all elements used by AML API, frees associated memory
540f2707e4SIgor Mammedov  * and invalidates AML allocator. After this call @init_aml_allocator
550f2707e4SIgor Mammedov  * should be called again if AML API is to be used again.
560f2707e4SIgor Mammedov  */
570f2707e4SIgor Mammedov void free_aml_allocator(void);
580f2707e4SIgor Mammedov 
590f2707e4SIgor Mammedov /**
600f2707e4SIgor Mammedov  * aml_append:
610f2707e4SIgor Mammedov  * @parent_ctx: context to which @child element is added
620f2707e4SIgor Mammedov  * @child: element that is copied into @parent_ctx context
630f2707e4SIgor Mammedov  *
640f2707e4SIgor Mammedov  * Joins Aml elements together and helps to construct AML tables
650f2707e4SIgor Mammedov  * Examle of usage:
660f2707e4SIgor Mammedov  *   Aml *table = aml_def_block("SSDT", ...);
670f2707e4SIgor Mammedov  *   Aml *sb = aml_scope("\_SB");
680f2707e4SIgor Mammedov  *   Aml *dev = aml_device("PCI0");
690f2707e4SIgor Mammedov  *
700f2707e4SIgor Mammedov  *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
710f2707e4SIgor Mammedov  *   aml_append(sb, dev);
720f2707e4SIgor Mammedov  *   aml_append(table, sb);
730f2707e4SIgor Mammedov  */
740f2707e4SIgor Mammedov void aml_append(Aml *parent_ctx, Aml *child);
750f2707e4SIgor Mammedov 
763c054bd5SIgor Mammedov /* non block AML object primitives */
773c054bd5SIgor Mammedov Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
783c054bd5SIgor Mammedov Aml *aml_name_decl(const char *name, Aml *val);
79b25af5adSIgor Mammedov Aml *aml_return(Aml *val);
80295a515dSIgor Mammedov Aml *aml_int(const uint64_t val);
817193f3a6SIgor Mammedov Aml *aml_arg(int pos);
82c263b3f7SIgor Mammedov Aml *aml_store(Aml *val, Aml *target);
83926f5aaeSIgor Mammedov Aml *aml_and(Aml *arg1, Aml *arg2);
8434189453SIgor Mammedov Aml *aml_notify(Aml *arg1, Aml *arg2);
853f3992b7SIgor Mammedov Aml *aml_call1(const char *method, Aml *arg1);
863f3992b7SIgor Mammedov Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
873f3992b7SIgor Mammedov Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
883f3992b7SIgor Mammedov Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
8952fa397cSIgor Mammedov Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
9052fa397cSIgor Mammedov             uint8_t aln, uint8_t len);
9131127938SIgor Mammedov Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
9231127938SIgor Mammedov                           uint32_t offset, uint32_t len);
93214ae59fSIgor Mammedov Aml *aml_named_field(const char *name, unsigned length);
94b8a5d689SIgor Mammedov Aml *aml_local(int num);
95d5e5830fSIgor Mammedov Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
9615e44e56SIgor Mammedov Aml *aml_equal(Aml *arg1, Aml *arg2);
97*3dd15643SIgor Mammedov Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
98*3dd15643SIgor Mammedov                    const char *name_format, ...) GCC_FMT_ATTR(4, 5);
993c054bd5SIgor Mammedov 
1002ef7c27bSIgor Mammedov /* Block AML object primitives */
1012ef7c27bSIgor Mammedov Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
102be06ebd0SIgor Mammedov Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
103ea2407d7SIgor Mammedov Aml *aml_method(const char *name, int arg_count);
10432acac9eSIgor Mammedov Aml *aml_if(Aml *predicate);
1053bfa74a7SIgor Mammedov Aml *aml_package(uint8_t num_elements);
10604b8da54SIgor Mammedov Aml *aml_buffer(void);
107ad4a80bcSIgor Mammedov Aml *aml_resource_template(void);
108214ae59fSIgor Mammedov Aml *aml_field(const char *name, AmlFieldFlags flags);
109a678508eSIgor Mammedov Aml *aml_varpackage(uint32_t num_elements);
1102ef7c27bSIgor Mammedov 
1110f2707e4SIgor Mammedov /* other helpers */
11219934e0eSIgor Mammedov GArray *build_alloc_array(void);
11319934e0eSIgor Mammedov void build_free_array(GArray *array);
11419934e0eSIgor Mammedov void build_prepend_byte(GArray *array, uint8_t val);
11519934e0eSIgor Mammedov void build_append_byte(GArray *array, uint8_t val);
11619934e0eSIgor Mammedov void build_append_array(GArray *array, GArray *val);
11719934e0eSIgor Mammedov 
11819934e0eSIgor Mammedov void GCC_FMT_ATTR(2, 3)
119eae8bdedSIgor Mammedov build_append_namestring(GArray *array, const char *format, ...);
12019934e0eSIgor Mammedov 
12119fff2d4SIgor Mammedov void
12219fff2d4SIgor Mammedov build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
123661875e9SIgor Mammedov void build_package(GArray *package, uint8_t op);
124295a515dSIgor Mammedov void build_append_int(GArray *table, uint64_t value);
12519934e0eSIgor Mammedov void build_extop_package(GArray *package, uint8_t op);
12619934e0eSIgor Mammedov 
12719934e0eSIgor Mammedov #endif
128