2015-01-30 16:29:36 +03:00
|
|
|
#ifndef HW_ACPI_GEN_UTILS_H
|
|
|
|
#define HW_ACPI_GEN_UTILS_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include "qemu/compiler.h"
|
|
|
|
|
2015-02-18 22:14:14 +03:00
|
|
|
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;
|
|
|
|
|
2015-02-18 22:14:32 +03:00
|
|
|
typedef enum {
|
|
|
|
aml_decode10 = 0,
|
|
|
|
aml_decode16 = 1,
|
|
|
|
} AmlIODecode;
|
|
|
|
|
2015-02-18 22:14:35 +03:00
|
|
|
typedef enum {
|
|
|
|
aml_byte_acc = 1,
|
|
|
|
} AmlFieldFlags;
|
|
|
|
|
2015-02-18 22:14:34 +03:00
|
|
|
typedef enum {
|
|
|
|
aml_system_memory = 0x00,
|
|
|
|
aml_system_io = 0x01,
|
|
|
|
} AmlRegionSpace;
|
|
|
|
|
2015-02-18 22:14:14 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2015-02-18 22:14:20 +03:00
|
|
|
/* 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);
|
2015-02-18 22:14:22 +03:00
|
|
|
Aml *aml_return(Aml *val);
|
2015-02-18 22:14:21 +03:00
|
|
|
Aml *aml_int(const uint64_t val);
|
2015-02-18 22:14:23 +03:00
|
|
|
Aml *aml_arg(int pos);
|
2015-02-18 22:14:24 +03:00
|
|
|
Aml *aml_store(Aml *val, Aml *target);
|
2015-02-18 22:14:25 +03:00
|
|
|
Aml *aml_and(Aml *arg1, Aml *arg2);
|
2015-02-18 22:14:26 +03:00
|
|
|
Aml *aml_notify(Aml *arg1, Aml *arg2);
|
2015-02-18 22:14:27 +03:00
|
|
|
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);
|
2015-02-18 22:14:32 +03:00
|
|
|
Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
|
|
|
|
uint8_t aln, uint8_t len);
|
2015-02-18 22:14:34 +03:00
|
|
|
Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
|
|
|
|
uint32_t offset, uint32_t len);
|
2015-02-18 22:14:35 +03:00
|
|
|
Aml *aml_named_field(const char *name, unsigned length);
|
2015-02-18 22:14:36 +03:00
|
|
|
Aml *aml_local(int num);
|
2015-02-18 22:14:37 +03:00
|
|
|
Aml *aml_string(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
|
2015-02-18 22:14:40 +03:00
|
|
|
Aml *aml_equal(Aml *arg1, Aml *arg2);
|
2015-02-18 22:14:41 +03:00
|
|
|
Aml *aml_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len,
|
|
|
|
const char *name_format, ...) GCC_FMT_ATTR(4, 5);
|
2015-02-18 22:14:20 +03:00
|
|
|
|
2015-02-18 22:14:15 +03:00
|
|
|
/* Block AML object primitives */
|
|
|
|
Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
|
2015-02-18 22:14:17 +03:00
|
|
|
Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
|
2015-02-18 22:14:18 +03:00
|
|
|
Aml *aml_method(const char *name, int arg_count);
|
2015-02-18 22:14:19 +03:00
|
|
|
Aml *aml_if(Aml *predicate);
|
2015-02-18 22:14:28 +03:00
|
|
|
Aml *aml_package(uint8_t num_elements);
|
2015-02-18 22:14:30 +03:00
|
|
|
Aml *aml_buffer(void);
|
2015-02-18 22:14:31 +03:00
|
|
|
Aml *aml_resource_template(void);
|
2015-02-18 22:14:35 +03:00
|
|
|
Aml *aml_field(const char *name, AmlFieldFlags flags);
|
2015-02-18 22:14:39 +03:00
|
|
|
Aml *aml_varpackage(uint32_t num_elements);
|
2015-02-18 22:14:15 +03:00
|
|
|
|
2015-02-18 22:14:14 +03:00
|
|
|
/* other helpers */
|
2015-01-30 16:29:36 +03:00
|
|
|
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)
|
2015-01-30 16:29:37 +03:00
|
|
|
build_append_namestring(GArray *array, const char *format, ...);
|
2015-01-30 16:29:36 +03:00
|
|
|
|
2015-02-18 22:14:33 +03:00
|
|
|
void
|
|
|
|
build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
|
2015-01-30 16:29:38 +03:00
|
|
|
void build_package(GArray *package, uint8_t op);
|
2015-02-18 22:14:21 +03:00
|
|
|
void build_append_int(GArray *table, uint64_t value);
|
2015-01-30 16:29:36 +03:00
|
|
|
void build_extop_package(GArray *package, uint8_t op);
|
|
|
|
|
|
|
|
#endif
|