qemu/include/hw/acpi/aml-build.h
Igor Mammedov 19fff2d405 acpi: include PkgLength size only when requested
Named/Reserved{Field} definition uses PkgLength [1] encoding to specify
field length, however it doesn't include size of PkgLength field itself,
while other block objects that have explicit length of its body account
for PkgLength size while encoding it [2].
This special casing isn't mentioned in ACPI spec, but that's what 'iasl'
compiles NamedField to so add extra argument to build_prepend_pkg_length()
to allow it handle the case.

--
1. ACPI Spec 5.0, 20.2.5.2 Named Objects Encoding, page 822
2. ACPI Spec 5.0, 5.4 Definition Block Encoding

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2015-02-26 13:04:14 +01:00

109 lines
3.3 KiB
C

#ifndef HW_ACPI_GEN_UTILS_H
#define HW_ACPI_GEN_UTILS_H
#include <stdint.h>
#include <glib.h>
#include "qemu/compiler.h"
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;
typedef enum {
aml_decode10 = 0,
aml_decode16 = 1,
} AmlIODecode;
/**
* 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);
/* 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);
Aml *aml_return(Aml *val);
Aml *aml_int(const uint64_t val);
Aml *aml_arg(int pos);
Aml *aml_store(Aml *val, Aml *target);
Aml *aml_and(Aml *arg1, Aml *arg2);
Aml *aml_notify(Aml *arg1, Aml *arg2);
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);
Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,
uint8_t aln, uint8_t len);
/* Block AML object primitives */
Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
Aml *aml_method(const char *name, int arg_count);
Aml *aml_if(Aml *predicate);
Aml *aml_package(uint8_t num_elements);
Aml *aml_buffer(void);
Aml *aml_resource_template(void);
/* other helpers */
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)
build_append_namestring(GArray *array, const char *format, ...);
void
build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
void build_package(GArray *package, uint8_t op);
void build_append_int(GArray *table, uint64_t value);
void build_extop_package(GArray *package, uint8_t op);
#endif