it allows to build table tree by assigning child AML objects to parent AML object and reuse the same AML objects multiple times.
When table is build and added to ACPI tables blob, it will create the same parent->child relation, and when ACPI tables blob is destroyed (object_unref()), it will automatically cleanup all children AML objects that has been created for it. Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- hw/acpi/acpi-build-utils.c | 31 +++++++++++++++++++++++++++++++ include/hw/acpi/acpi-build-utils.h | 13 +++++++++++++ 2 files changed, 44 insertions(+) diff --git a/hw/acpi/acpi-build-utils.c b/hw/acpi/acpi-build-utils.c index 5bfb74d..1041865 100644 --- a/hw/acpi/acpi-build-utils.c +++ b/hw/acpi/acpi-build-utils.c @@ -27,6 +27,7 @@ #include "hw/acpi/acpi-build-utils.h" #include "qemu/bswap.h" #include "hw/acpi/bios-linker-loader.h" +#include "qemu/module.h" GArray *build_alloc_array(void) { @@ -910,3 +911,33 @@ AcpiAml *acpi_def_block(const char *signature, uint8_t revision, return var; } + +static void aml_object_initfn(Object *obj) { + AcpiAml *aml = AML_OBJECT(obj); + + aml->buf = build_alloc_array(); +} + +static void aml_object_finalize(Object *obj) { + AcpiAml *aml = AML_OBJECT(obj); + + build_free_array(aml->buf); + memset(aml, 0, sizeof(*aml)); +} + +static const TypeInfo aml_object_type_info = { + .name = TYPE_AML_OBJECT, + .parent = TYPE_UNOWNED_OBJECT, + .instance_size = sizeof(AcpiAml), + .instance_init = aml_object_initfn, + .instance_finalize = aml_object_finalize, + .abstract = false, + .class_size = sizeof(AcpiAmlClass), +}; + +static void aml_register_types(void) +{ + type_register_static(&aml_object_type_info); +} + +type_init(aml_register_types) diff --git a/include/hw/acpi/acpi-build-utils.h b/include/hw/acpi/acpi-build-utils.h index 0e068f1..c36ddb6 100644 --- a/include/hw/acpi/acpi-build-utils.h +++ b/include/hw/acpi/acpi-build-utils.h @@ -4,6 +4,7 @@ #include <stdint.h> #include <glib.h> #include "qemu/compiler.h" +#include "qom/object.h" typedef enum { NON_BLOCK, @@ -17,13 +18,25 @@ typedef enum { #define ACPI_BUILD_TABLE_FILE "etc/acpi/tables" #define ACPI_BUILD_APPNAME4 "BXPC" +#define TYPE_AML_OBJECT "aml-object" +#define AML_OBJECT(obj) OBJECT_CHECK(AcpiAml, (obj), TYPE_AML_OBJECT) +#define AML_OBJECT_CLASS(klass) \ + OBJECT_CLASS_CHECK(AcpiAmlClass, (klass), TYPE_AML_OBJECT) +#define AML_OBJECT_GET_CLASS \ + OBJECT_GET_CLASS(AcpiAmlClass, (obj), TYPE_AML_OBJECT) + typedef struct AcpiAml { + Object parent_obj; GArray *buf; uint8_t op; AcpiBlockFlags block_flags; GArray *linker; } AcpiAml; +typedef struct AcpiAmlClass { + ObjectClass parent_class; +} AcpiAmlClass; + typedef enum { acpi_decode10 = 0, acpi_decode16 = 1, -- 1.8.3.1