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 8*0f2707e4SIgor Mammedov typedef enum { 9*0f2707e4SIgor Mammedov AML_NO_OPCODE = 0,/* has only data */ 10*0f2707e4SIgor Mammedov AML_OPCODE, /* has opcode optionally followed by data */ 11*0f2707e4SIgor Mammedov AML_PACKAGE, /* has opcode and uses PkgLength for its length */ 12*0f2707e4SIgor Mammedov AML_EXT_PACKAGE, /* ame as AML_PACKAGE but also has 'ExOpPrefix' */ 13*0f2707e4SIgor Mammedov AML_BUFFER, /* data encoded as 'DefBuffer' */ 14*0f2707e4SIgor Mammedov AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */ 15*0f2707e4SIgor Mammedov } AmlBlockFlags; 16*0f2707e4SIgor Mammedov 17*0f2707e4SIgor Mammedov struct Aml { 18*0f2707e4SIgor Mammedov GArray *buf; 19*0f2707e4SIgor Mammedov 20*0f2707e4SIgor Mammedov /*< private >*/ 21*0f2707e4SIgor Mammedov uint8_t op; 22*0f2707e4SIgor Mammedov AmlBlockFlags block_flags; 23*0f2707e4SIgor Mammedov }; 24*0f2707e4SIgor Mammedov typedef struct Aml Aml; 25*0f2707e4SIgor Mammedov 26*0f2707e4SIgor Mammedov /** 27*0f2707e4SIgor Mammedov * init_aml_allocator: 28*0f2707e4SIgor Mammedov * 29*0f2707e4SIgor Mammedov * Called for initializing API allocator which allow to use 30*0f2707e4SIgor Mammedov * AML API. 31*0f2707e4SIgor Mammedov * Returns: toplevel container which accumulates all other 32*0f2707e4SIgor Mammedov * AML elements for a table. 33*0f2707e4SIgor Mammedov */ 34*0f2707e4SIgor Mammedov Aml *init_aml_allocator(void); 35*0f2707e4SIgor Mammedov 36*0f2707e4SIgor Mammedov /** 37*0f2707e4SIgor Mammedov * free_aml_allocator: 38*0f2707e4SIgor Mammedov * 39*0f2707e4SIgor Mammedov * Releases all elements used by AML API, frees associated memory 40*0f2707e4SIgor Mammedov * and invalidates AML allocator. After this call @init_aml_allocator 41*0f2707e4SIgor Mammedov * should be called again if AML API is to be used again. 42*0f2707e4SIgor Mammedov */ 43*0f2707e4SIgor Mammedov void free_aml_allocator(void); 44*0f2707e4SIgor Mammedov 45*0f2707e4SIgor Mammedov /** 46*0f2707e4SIgor Mammedov * aml_append: 47*0f2707e4SIgor Mammedov * @parent_ctx: context to which @child element is added 48*0f2707e4SIgor Mammedov * @child: element that is copied into @parent_ctx context 49*0f2707e4SIgor Mammedov * 50*0f2707e4SIgor Mammedov * Joins Aml elements together and helps to construct AML tables 51*0f2707e4SIgor Mammedov * Examle of usage: 52*0f2707e4SIgor Mammedov * Aml *table = aml_def_block("SSDT", ...); 53*0f2707e4SIgor Mammedov * Aml *sb = aml_scope("\_SB"); 54*0f2707e4SIgor Mammedov * Aml *dev = aml_device("PCI0"); 55*0f2707e4SIgor Mammedov * 56*0f2707e4SIgor Mammedov * aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03"))); 57*0f2707e4SIgor Mammedov * aml_append(sb, dev); 58*0f2707e4SIgor Mammedov * aml_append(table, sb); 59*0f2707e4SIgor Mammedov */ 60*0f2707e4SIgor Mammedov void aml_append(Aml *parent_ctx, Aml *child); 61*0f2707e4SIgor Mammedov 62*0f2707e4SIgor Mammedov /* other helpers */ 6319934e0eSIgor Mammedov GArray *build_alloc_array(void); 6419934e0eSIgor Mammedov void build_free_array(GArray *array); 6519934e0eSIgor Mammedov void build_prepend_byte(GArray *array, uint8_t val); 6619934e0eSIgor Mammedov void build_append_byte(GArray *array, uint8_t val); 6719934e0eSIgor Mammedov void build_append_array(GArray *array, GArray *val); 6819934e0eSIgor Mammedov 6919934e0eSIgor Mammedov void GCC_FMT_ATTR(2, 3) 70eae8bdedSIgor Mammedov build_append_namestring(GArray *array, const char *format, ...); 7119934e0eSIgor Mammedov 72661875e9SIgor Mammedov void build_prepend_package_length(GArray *package); 73661875e9SIgor Mammedov void build_package(GArray *package, uint8_t op); 7419934e0eSIgor Mammedov void build_append_value(GArray *table, uint32_t value, int size); 7519934e0eSIgor Mammedov void build_append_int(GArray *table, uint32_t value); 7619934e0eSIgor Mammedov void build_extop_package(GArray *package, uint8_t op); 7719934e0eSIgor Mammedov 7819934e0eSIgor Mammedov #endif 79