xref: /openbmc/qemu/include/hw/acpi/aml-build.h (revision 214ae59f8e1c33db0f3fbbc4347bb3dacc6ce876)
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*214ae59fSIgor Mammedov     aml_byte_acc = 1,
33*214ae59fSIgor Mammedov } AmlFieldFlags;
34*214ae59fSIgor Mammedov 
35*214ae59fSIgor 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);
93*214ae59fSIgor Mammedov Aml *aml_named_field(const char *name, unsigned length);
943c054bd5SIgor Mammedov 
952ef7c27bSIgor Mammedov /* Block AML object primitives */
962ef7c27bSIgor Mammedov Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
97be06ebd0SIgor Mammedov Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
98ea2407d7SIgor Mammedov Aml *aml_method(const char *name, int arg_count);
9932acac9eSIgor Mammedov Aml *aml_if(Aml *predicate);
1003bfa74a7SIgor Mammedov Aml *aml_package(uint8_t num_elements);
10104b8da54SIgor Mammedov Aml *aml_buffer(void);
102ad4a80bcSIgor Mammedov Aml *aml_resource_template(void);
103*214ae59fSIgor Mammedov Aml *aml_field(const char *name, AmlFieldFlags flags);
1042ef7c27bSIgor Mammedov 
1050f2707e4SIgor Mammedov /* other helpers */
10619934e0eSIgor Mammedov GArray *build_alloc_array(void);
10719934e0eSIgor Mammedov void build_free_array(GArray *array);
10819934e0eSIgor Mammedov void build_prepend_byte(GArray *array, uint8_t val);
10919934e0eSIgor Mammedov void build_append_byte(GArray *array, uint8_t val);
11019934e0eSIgor Mammedov void build_append_array(GArray *array, GArray *val);
11119934e0eSIgor Mammedov 
11219934e0eSIgor Mammedov void GCC_FMT_ATTR(2, 3)
113eae8bdedSIgor Mammedov build_append_namestring(GArray *array, const char *format, ...);
11419934e0eSIgor Mammedov 
11519fff2d4SIgor Mammedov void
11619fff2d4SIgor Mammedov build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
117661875e9SIgor Mammedov void build_package(GArray *package, uint8_t op);
118295a515dSIgor Mammedov void build_append_int(GArray *table, uint64_t value);
11919934e0eSIgor Mammedov void build_extop_package(GArray *package, uint8_t op);
12019934e0eSIgor Mammedov 
12119934e0eSIgor Mammedov #endif
122