xref: /openbmc/qemu/include/hw/acpi/aml-build.h (revision 31127938f496f56eb05dc407a31e4c5941fb436a)
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 
31*31127938SIgor Mammedov typedef enum {
32*31127938SIgor Mammedov     aml_system_memory = 0x00,
33*31127938SIgor Mammedov     aml_system_io = 0x01,
34*31127938SIgor Mammedov } AmlRegionSpace;
35*31127938SIgor Mammedov 
360f2707e4SIgor Mammedov /**
370f2707e4SIgor Mammedov  * init_aml_allocator:
380f2707e4SIgor Mammedov  *
390f2707e4SIgor Mammedov  * Called for initializing API allocator which allow to use
400f2707e4SIgor Mammedov  * AML API.
410f2707e4SIgor Mammedov  * Returns: toplevel container which accumulates all other
420f2707e4SIgor Mammedov  * AML elements for a table.
430f2707e4SIgor Mammedov  */
440f2707e4SIgor Mammedov Aml *init_aml_allocator(void);
450f2707e4SIgor Mammedov 
460f2707e4SIgor Mammedov /**
470f2707e4SIgor Mammedov  * free_aml_allocator:
480f2707e4SIgor Mammedov  *
490f2707e4SIgor Mammedov  * Releases all elements used by AML API, frees associated memory
500f2707e4SIgor Mammedov  * and invalidates AML allocator. After this call @init_aml_allocator
510f2707e4SIgor Mammedov  * should be called again if AML API is to be used again.
520f2707e4SIgor Mammedov  */
530f2707e4SIgor Mammedov void free_aml_allocator(void);
540f2707e4SIgor Mammedov 
550f2707e4SIgor Mammedov /**
560f2707e4SIgor Mammedov  * aml_append:
570f2707e4SIgor Mammedov  * @parent_ctx: context to which @child element is added
580f2707e4SIgor Mammedov  * @child: element that is copied into @parent_ctx context
590f2707e4SIgor Mammedov  *
600f2707e4SIgor Mammedov  * Joins Aml elements together and helps to construct AML tables
610f2707e4SIgor Mammedov  * Examle of usage:
620f2707e4SIgor Mammedov  *   Aml *table = aml_def_block("SSDT", ...);
630f2707e4SIgor Mammedov  *   Aml *sb = aml_scope("\_SB");
640f2707e4SIgor Mammedov  *   Aml *dev = aml_device("PCI0");
650f2707e4SIgor Mammedov  *
660f2707e4SIgor Mammedov  *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
670f2707e4SIgor Mammedov  *   aml_append(sb, dev);
680f2707e4SIgor Mammedov  *   aml_append(table, sb);
690f2707e4SIgor Mammedov  */
700f2707e4SIgor Mammedov void aml_append(Aml *parent_ctx, Aml *child);
710f2707e4SIgor Mammedov 
723c054bd5SIgor Mammedov /* non block AML object primitives */
733c054bd5SIgor Mammedov Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
743c054bd5SIgor Mammedov Aml *aml_name_decl(const char *name, Aml *val);
75b25af5adSIgor Mammedov Aml *aml_return(Aml *val);
76295a515dSIgor Mammedov Aml *aml_int(const uint64_t val);
777193f3a6SIgor Mammedov Aml *aml_arg(int pos);
78c263b3f7SIgor Mammedov Aml *aml_store(Aml *val, Aml *target);
79926f5aaeSIgor Mammedov Aml *aml_and(Aml *arg1, Aml *arg2);
8034189453SIgor Mammedov Aml *aml_notify(Aml *arg1, Aml *arg2);
813f3992b7SIgor Mammedov Aml *aml_call1(const char *method, Aml *arg1);
823f3992b7SIgor Mammedov Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
833f3992b7SIgor Mammedov Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
843f3992b7SIgor Mammedov Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
8552fa397cSIgor Mammedov Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
8652fa397cSIgor Mammedov             uint8_t aln, uint8_t len);
87*31127938SIgor Mammedov Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
88*31127938SIgor Mammedov                           uint32_t offset, uint32_t len);
893c054bd5SIgor Mammedov 
902ef7c27bSIgor Mammedov /* Block AML object primitives */
912ef7c27bSIgor Mammedov Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
92be06ebd0SIgor Mammedov Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
93ea2407d7SIgor Mammedov Aml *aml_method(const char *name, int arg_count);
9432acac9eSIgor Mammedov Aml *aml_if(Aml *predicate);
953bfa74a7SIgor Mammedov Aml *aml_package(uint8_t num_elements);
9604b8da54SIgor Mammedov Aml *aml_buffer(void);
97ad4a80bcSIgor Mammedov Aml *aml_resource_template(void);
982ef7c27bSIgor Mammedov 
990f2707e4SIgor Mammedov /* other helpers */
10019934e0eSIgor Mammedov GArray *build_alloc_array(void);
10119934e0eSIgor Mammedov void build_free_array(GArray *array);
10219934e0eSIgor Mammedov void build_prepend_byte(GArray *array, uint8_t val);
10319934e0eSIgor Mammedov void build_append_byte(GArray *array, uint8_t val);
10419934e0eSIgor Mammedov void build_append_array(GArray *array, GArray *val);
10519934e0eSIgor Mammedov 
10619934e0eSIgor Mammedov void GCC_FMT_ATTR(2, 3)
107eae8bdedSIgor Mammedov build_append_namestring(GArray *array, const char *format, ...);
10819934e0eSIgor Mammedov 
10919fff2d4SIgor Mammedov void
11019fff2d4SIgor Mammedov build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
111661875e9SIgor Mammedov void build_package(GArray *package, uint8_t op);
112295a515dSIgor Mammedov void build_append_int(GArray *table, uint64_t value);
11319934e0eSIgor Mammedov void build_extop_package(GArray *package, uint8_t op);
11419934e0eSIgor Mammedov 
11519934e0eSIgor Mammedov #endif
116