aml-build.h 3.0 KB
Newer Older
1 2 3 4 5 6 7
#ifndef HW_ACPI_GEN_UTILS_H
#define HW_ACPI_GEN_UTILS_H

#include <stdint.h>
#include <glib.h>
#include "qemu/compiler.h"

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
typedef enum {
    AML_NO_OPCODE = 0,/* has only data */
    AML_OPCODE,       /* has opcode optionally followed by data */
    AML_PACKAGE,      /* has opcode and uses PkgLength for its length */
    AML_EXT_PACKAGE,  /* ame as AML_PACKAGE but also has 'ExOpPrefix' */
    AML_BUFFER,       /* data encoded as 'DefBuffer' */
    AML_RES_TEMPLATE, /* encoded as ResourceTemplate macro */
} AmlBlockFlags;

struct Aml {
    GArray *buf;

    /*< private >*/
    uint8_t op;
    AmlBlockFlags block_flags;
};
typedef struct Aml Aml;

/**
 * init_aml_allocator:
 *
 * Called for initializing API allocator which allow to use
 * AML API.
 * Returns: toplevel container which accumulates all other
 * AML elements for a table.
 */
Aml *init_aml_allocator(void);

/**
 * free_aml_allocator:
 *
 * Releases all elements used by AML API, frees associated memory
 * and invalidates AML allocator. After this call @init_aml_allocator
 * should be called again if AML API is to be used again.
 */
void free_aml_allocator(void);

/**
 * aml_append:
 * @parent_ctx: context to which @child element is added
 * @child: element that is copied into @parent_ctx context
 *
 * Joins Aml elements together and helps to construct AML tables
 * Examle of usage:
 *   Aml *table = aml_def_block("SSDT", ...);
 *   Aml *sb = aml_scope("\_SB");
 *   Aml *dev = aml_device("PCI0");
 *
 *   aml_append(dev, aml_name_decl("HID", aml_eisaid("PNP0A03")));
 *   aml_append(sb, dev);
 *   aml_append(table, sb);
 */
void aml_append(Aml *parent_ctx, Aml *child);

62 63 64
/* non block AML object primitives */
Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
Aml *aml_name_decl(const char *name, Aml *val);
I
Igor Mammedov 已提交
65
Aml *aml_return(Aml *val);
I
Igor Mammedov 已提交
66
Aml *aml_int(const uint64_t val);
I
Igor Mammedov 已提交
67
Aml *aml_arg(int pos);
I
Igor Mammedov 已提交
68
Aml *aml_store(Aml *val, Aml *target);
I
Igor Mammedov 已提交
69
Aml *aml_and(Aml *arg1, Aml *arg2);
I
Igor Mammedov 已提交
70
Aml *aml_notify(Aml *arg1, Aml *arg2);
71 72 73 74
Aml *aml_call1(const char *method, Aml *arg1);
Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
Aml *aml_call3(const char *method, Aml *arg1, Aml *arg2, Aml *arg3);
Aml *aml_call4(const char *method, Aml *arg1, Aml *arg2, Aml *arg3, Aml *arg4);
75

I
Igor Mammedov 已提交
76 77
/* Block AML object primitives */
Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
I
Igor Mammedov 已提交
78
Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
I
Igor Mammedov 已提交
79
Aml *aml_method(const char *name, int arg_count);
I
Igor Mammedov 已提交
80
Aml *aml_if(Aml *predicate);
I
Igor Mammedov 已提交
81
Aml *aml_package(uint8_t num_elements);
I
Igor Mammedov 已提交
82

83
/* other helpers */
84 85 86 87 88 89 90
GArray *build_alloc_array(void);
void build_free_array(GArray *array);
void build_prepend_byte(GArray *array, uint8_t val);
void build_append_byte(GArray *array, uint8_t val);
void build_append_array(GArray *array, GArray *val);

void GCC_FMT_ATTR(2, 3)
91
build_append_namestring(GArray *array, const char *format, ...);
92

93 94
void build_prepend_package_length(GArray *package);
void build_package(GArray *package, uint8_t op);
I
Igor Mammedov 已提交
95
void build_append_int(GArray *table, uint64_t value);
96 97 98
void build_extop_package(GArray *package, uint8_t op);

#endif