Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- hw/acpi/acpi-build-utils.c | 446 +++++++++++++++++++------------------ hw/i386/acpi-build.c | 270 +++++++++++----------- include/hw/acpi/acpi-build-utils.h | 84 +++---- 3 files changed, 401 insertions(+), 399 deletions(-)
diff --git a/hw/acpi/acpi-build-utils.c b/hw/acpi/acpi-build-utils.c index 59873e3..5bfb74d 100644 --- a/hw/acpi/acpi-build-utils.c +++ b/hw/acpi/acpi-build-utils.c @@ -290,64 +290,66 @@ static void build_prepend_int(GArray *array, uint32_t value) build_free_array(data); } -void aml_append(AcpiAml *parent_ctx, AcpiAml child) +void aml_append(AcpiAml *parent_ctx, AcpiAml *child) { - switch (child.block_flags) { + switch (child->block_flags) { case EXT_PACKAGE: - build_extop_package(child.buf, child.op); + build_extop_package(child->buf, child->op); break; case PACKAGE: - build_package(child.buf, child.op); + build_package(child->buf, child->op); break; case RES_TEMPLATE: - build_append_byte(child.buf, 0x79); /* EndTag */ + build_append_byte(child->buf, 0x79); /* EndTag */ /* * checksum operations is treated as succeeded if checksum * field is zero. [ACPI Spec 5.0, 6.4.2.9 End Tag] */ - build_append_byte(child.buf, 0); + build_append_byte(child->buf, 0); /* fall through, to pack resources in buffer */ case BUFFER: - build_prepend_int(child.buf, child.buf->len); - build_package(child.buf, child.op); + build_prepend_int(child->buf, child->buf->len); + build_package(child->buf, child->op); break; case DEF_BLOCK: { uint8_t *start = (uint8_t *)parent_ctx->buf->data + parent_ctx->buf->len; - uint32_t le32_len = cpu_to_le32(child.buf->len); + uint32_t le32_len = cpu_to_le32(child->buf->len); /* create linker entry for the DefinitionBlock */ bios_linker_loader_add_checksum(parent_ctx->linker, ACPI_BUILD_TABLE_FILE, parent_ctx->buf->data, - start, child.buf->len, start + 9 /* checksum offset */); + start, child->buf->len, start + 9 /* checksum offset */); /* set DefinitionBlock length at TableLength offset*/ - memcpy(child.buf->data + 4, &le32_len, sizeof le32_len); + memcpy(child->buf->data + 4, &le32_len, sizeof le32_len); break; } default: break; } - build_append_array(parent_ctx->buf, child.buf); - build_free_array(child.buf); + build_append_array(parent_ctx->buf, child->buf); + build_free_array(child->buf); } -static AcpiAml aml_allocate_internal(uint8_t op, AcpiBlockFlags flags) +static AcpiAml *aml_allocate_internal(uint8_t op, AcpiBlockFlags flags) { - AcpiAml var = { .op = op, .block_flags = flags }; - var.buf = build_alloc_array(); + AcpiAml *var = g_malloc0(sizeof(AcpiAml)); + var->op = op; + var->block_flags = flags; + var->buf = build_alloc_array(); return var; } /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefReturn */ -AcpiAml acpi_return(AcpiAml val) +AcpiAml *acpi_return(AcpiAml *val) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0xA4); /* ReturnOp */ - aml_append(&var, val); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0xA4); /* ReturnOp */ + aml_append(var, val); return var; } @@ -355,10 +357,10 @@ AcpiAml acpi_return(AcpiAml val) * ACPI 5.0: 20.2.3 Data Objects Encoding: * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp */ -AcpiAml acpi_int(const uint64_t val) +AcpiAml *acpi_int(const uint64_t val) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_int(var.buf, val); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_int(var->buf, val); return var; } @@ -366,129 +368,129 @@ AcpiAml acpi_int(const uint64_t val) * help to construct NameString, which return AcpiAml object * for using with other aml_append or other acpi_* terms */ -AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...) +AcpiAml GCC_FMT_ATTR(1, 2) *acpi_name(const char *name_format, ...) { va_list ap; - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); va_start(ap, name_format); - build_append_namestringv(var.buf, name_format, ap); + build_append_namestringv(var->buf, name_format, ap); va_end(ap); return var; } /* ACPI 5.0: 20.2.5.1 Namespace Modifier Objects Encoding: DefName */ -AcpiAml acpi_name_decl(const char *name, AcpiAml val) +AcpiAml *acpi_name_decl(const char *name, AcpiAml *val) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x08); - build_append_namestring(var.buf, "%s", name); - aml_append(&var, val); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x08); + build_append_namestring(var->buf, "%s", name); + aml_append(var, val); return var; } /* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg0Op */ -AcpiAml acpi_arg0(void) +AcpiAml *acpi_arg0(void) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x68); /* ARG0 op */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x68); /* ARG0 op */ return var; } /* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg1Op */ -AcpiAml acpi_arg1(void) +AcpiAml *acpi_arg1(void) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x69); /* ARG1 op */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x69); /* ARG1 op */ return var; } /* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg2Op */ -AcpiAml acpi_arg2(void) +AcpiAml *acpi_arg2(void) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x6A); /* ARG2 op */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x6A); /* ARG2 op */ return var; } /* ACPI 5.0: 20.2.6.1 Arg Objects Encoding: Arg3Op */ -AcpiAml acpi_arg3(void) +AcpiAml *acpi_arg3(void) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x6B); /* ARG3 op */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x6B); /* ARG3 op */ return var; } /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefStore */ -AcpiAml acpi_store(AcpiAml val, AcpiAml target) +AcpiAml *acpi_store(AcpiAml *val, AcpiAml *target) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x70); /* StoreOp */ - aml_append(&var, val); - aml_append(&var, target); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x70); /* StoreOp */ + aml_append(var, val); + aml_append(var, target); return var; } /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefAnd */ -AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2) +AcpiAml *acpi_and(AcpiAml *arg1, AcpiAml *arg2) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x7B); /* AndOp */ - aml_append(&var, arg1); - aml_append(&var, arg2); - build_append_int(var.buf, 0x00); /* NullNameOp */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x7B); /* AndOp */ + aml_append(var, arg1); + aml_append(var, arg2); + build_append_int(var->buf, 0x00); /* NullNameOp */ return var; } /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefNotify */ -AcpiAml acpi_notify(AcpiAml arg1, AcpiAml arg2) +AcpiAml *acpi_notify(AcpiAml *arg1, AcpiAml *arg2) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x86); /* NotifyOp */ - aml_append(&var, arg1); - aml_append(&var, arg2); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x86); /* NotifyOp */ + aml_append(var, arg1); + aml_append(var, arg2); return var; } /* helper to call method with 1 argument */ -AcpiAml acpi_call1(const char *method, AcpiAml arg1) +AcpiAml *acpi_call1(const char *method, AcpiAml *arg1) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_namestring(var.buf, "%s", method); - aml_append(&var, arg1); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_namestring(var->buf, "%s", method); + aml_append(var, arg1); return var; } /* helper to call method with 2 arguments */ -AcpiAml acpi_call2(const char *method, AcpiAml arg1, AcpiAml arg2) +AcpiAml *acpi_call2(const char *method, AcpiAml *arg1, AcpiAml *arg2) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_namestring(var.buf, "%s", method); - aml_append(&var, arg1); - aml_append(&var, arg2); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_namestring(var->buf, "%s", method); + aml_append(var, arg1); + aml_append(var, arg2); return var; } /* helper to call method with 3 arguments */ -AcpiAml acpi_call3(const char *method, AcpiAml arg1, AcpiAml arg2, AcpiAml arg3) +AcpiAml *acpi_call3(const char *method, AcpiAml* arg1, AcpiAml *arg2, AcpiAml *arg3) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_namestring(var.buf, "%s", method); - aml_append(&var, arg1); - aml_append(&var, arg2); - aml_append(&var, arg3); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_namestring(var->buf, "%s", method); + aml_append(var, arg1); + aml_append(var, arg2); + aml_append(var, arg3); return var; } /* helper to call method with 4 arguments */ -AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2, - AcpiAml arg3, AcpiAml arg4) +AcpiAml *acpi_call4(const char *method, AcpiAml *arg1, AcpiAml *arg2, + AcpiAml *arg3, AcpiAml *arg4) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_namestring(var.buf, "%s", method); - aml_append(&var, arg1); - aml_append(&var, arg2); - aml_append(&var, arg3); - aml_append(&var, arg4); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_namestring(var->buf, "%s", method); + aml_append(var, arg1); + aml_append(var, arg2); + aml_append(var, arg3); + aml_append(var, arg4); return var; } @@ -496,18 +498,18 @@ AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2, * ACPI 5.0: 19.5.62 IO (IO Resource Descriptor Macro) * 6.4.2 Small Resource Data Type */ -AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base, +AcpiAml *acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x47); /* IO port descriptor */ - build_append_byte(var.buf, dec); - build_append_byte(var.buf, min_base & 0xff); - build_append_byte(var.buf, (min_base >> 8) & 0xff); - build_append_byte(var.buf, max_base & 0xff); - build_append_byte(var.buf, (max_base >> 8) & 0xff); - build_append_byte(var.buf, aln); - build_append_byte(var.buf, len); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x47); /* IO port descriptor */ + build_append_byte(var->buf, dec); + build_append_byte(var->buf, min_base & 0xff); + build_append_byte(var->buf, (min_base >> 8) & 0xff); + build_append_byte(var->buf, max_base & 0xff); + build_append_byte(var->buf, (max_base >> 8) & 0xff); + build_append_byte(var->buf, aln); + build_append_byte(var->buf, len); return var; } @@ -515,139 +517,139 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base, * ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro) * 6.4.2.1 IRQ Descriptor */ -AcpiAml acpi_iqr_no_flags(uint8_t irq) +AcpiAml *acpi_iqr_no_flags(uint8_t irq) { uint16_t irq_mask; - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); assert(irq < 16); - build_append_byte(var.buf, 0x22); /* IRQ descriptor 2 byte form */ + build_append_byte(var->buf, 0x22); /* IRQ descriptor 2 byte form */ irq_mask = 1U << irq; - build_append_byte(var.buf, irq_mask & 0xFF); /* IRQ mask bits[7:0] */ - build_append_byte(var.buf, irq_mask >> 8); /* IRQ mask bits[15:8] */ + build_append_byte(var->buf, irq_mask & 0xFF); /* IRQ mask bits[7:0] */ + build_append_byte(var->buf, irq_mask >> 8); /* IRQ mask bits[15:8] */ return var; } /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefLEqual */ -AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2) +AcpiAml *acpi_equal(AcpiAml *arg1, AcpiAml *arg2) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x93); /* LequalOp */ - aml_append(&var, arg1); - aml_append(&var, arg2); - build_append_int(var.buf, 0x00); /* NullNameOp */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x93); /* LequalOp */ + aml_append(var, arg1); + aml_append(var, arg2); + build_append_int(var->buf, 0x00); /* NullNameOp */ return var; } /* ACPI 5.0: 20.2.5.3 Type 1 Opcodes Encoding: DefIfElse */ -AcpiAml acpi_if(AcpiAml predicate) +AcpiAml *acpi_if(AcpiAml *predicate) { - AcpiAml var = aml_allocate_internal(0xA0 /* IfOp */, PACKAGE); - aml_append(&var, predicate); + AcpiAml *var = aml_allocate_internal(0xA0 /* IfOp */, PACKAGE); + aml_append(var, predicate); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefMethod */ -AcpiAml acpi_method(const char *name, int arg_count) +AcpiAml *acpi_method(const char *name, int arg_count) { - AcpiAml var = aml_allocate_internal(0x14 /* MethodOp */, PACKAGE); - build_append_namestring(var.buf, "%s", name); - build_append_byte(var.buf, arg_count); /* MethodFlags: ArgCount */ + AcpiAml *var = aml_allocate_internal(0x14 /* MethodOp */, PACKAGE); + build_append_namestring(var->buf, "%s", name); + build_append_byte(var->buf, arg_count); /* MethodFlags: ArgCount */ return var; } /* ACPI 5.0: 20.2.5.1 Namespace Modifier Objects Encoding: DefScope */ -AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...) +AcpiAml GCC_FMT_ATTR(1, 2) *acpi_scope(const char *name_format, ...) { va_list ap; - AcpiAml var = aml_allocate_internal(0x10 /* ScopeOp */, PACKAGE); + AcpiAml *var = aml_allocate_internal(0x10 /* ScopeOp */, PACKAGE); va_start(ap, name_format); - build_append_namestringv(var.buf, name_format, ap); + build_append_namestringv(var->buf, name_format, ap); va_end(ap); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefDevice */ -AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...) +AcpiAml GCC_FMT_ATTR(1, 2) *acpi_device(const char *name_format, ...) { va_list ap; - AcpiAml var = aml_allocate_internal(0x82 /* DeviceOp */, EXT_PACKAGE); + AcpiAml *var = aml_allocate_internal(0x82 /* DeviceOp */, EXT_PACKAGE); va_start(ap, name_format); - build_append_namestringv(var.buf, name_format, ap); + build_append_namestringv(var->buf, name_format, ap); va_end(ap); return var; } /* ResourceTemplate marcos helper */ -AcpiAml acpi_resource_template(void) +AcpiAml *acpi_resource_template(void) { /* ResourceTemplate is a buffer of Resources with EndTag at the end */ - AcpiAml var = aml_allocate_internal(0x11 /* BufferOp */, RES_TEMPLATE); + AcpiAml *var = aml_allocate_internal(0x11 /* BufferOp */, RES_TEMPLATE); return var; } /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefBuffer */ -AcpiAml acpi_buffer(void) +AcpiAml *acpi_buffer(void) { - AcpiAml var = aml_allocate_internal(0x11 /* BufferOp */, BUFFER); + AcpiAml *var = aml_allocate_internal(0x11 /* BufferOp */, BUFFER); return var; } /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefPackage */ -AcpiAml acpi_package(uint8_t num_elements) +AcpiAml *acpi_package(uint8_t num_elements) { - AcpiAml var = aml_allocate_internal(0x12 /* PackageOp */, PACKAGE); - build_append_byte(var.buf, num_elements); + AcpiAml *var = aml_allocate_internal(0x12 /* PackageOp */, PACKAGE); + build_append_byte(var->buf, num_elements); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefOpRegion */ -AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs, +AcpiAml *acpi_operation_region(const char *name, acpiRegionSpace rs, uint32_t offset, uint32_t len) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x5B); /* ExtOpPrefix */ - build_append_byte(var.buf, 0x80); /* OpRegionOp */ - build_append_namestring(var.buf, "%s", name); - build_append_byte(var.buf, rs); - build_append_int(var.buf, offset); - build_append_int(var.buf, len); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ + build_append_byte(var->buf, 0x80); /* OpRegionOp */ + build_append_namestring(var->buf, "%s", name); + build_append_byte(var->buf, rs); + build_append_int(var->buf, offset); + build_append_int(var->buf, len); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: NamedField */ -AcpiAml acpi_named_field(const char *name, unsigned length) +AcpiAml *acpi_named_field(const char *name, unsigned length) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_nameseg(var.buf, "%s", name); - build_append_pkg_length(var.buf, length, false); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_nameseg(var->buf, "%s", name); + build_append_pkg_length(var->buf, length, false); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: ReservedField */ -AcpiAml acpi_reserved_field(unsigned length) +AcpiAml *acpi_reserved_field(unsigned length) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); /* ReservedField := 0x00 PkgLength */ - build_append_byte(var.buf, 0x00); - build_append_pkg_length(var.buf, length, false); + build_append_byte(var->buf, 0x00); + build_append_pkg_length(var->buf, length, false); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefField */ -AcpiAml acpi_field(const char *name, acpiFieldFlags flags) +AcpiAml *acpi_field(const char *name, acpiFieldFlags flags) { - AcpiAml var = aml_allocate_internal(0x81 /* FieldOp */, EXT_PACKAGE); - build_append_namestring(var.buf, "%s", name); - build_append_byte(var.buf, flags); + AcpiAml *var = aml_allocate_internal(0x81 /* FieldOp */, EXT_PACKAGE); + build_append_namestring(var->buf, "%s", name); + build_append_byte(var->buf, flags); return var; } /* ACPI 5.0: 20.2.3 Data Objects Encoding: String */ -AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...) +AcpiAml GCC_FMT_ATTR(1, 2) *acpi_string(const char *name_format, ...) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); va_list ap, va_len; char *s; int len; @@ -662,47 +664,47 @@ AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...) len = vsnprintf(s, len, name_format, ap); va_end(ap); - build_append_byte(var.buf, 0x0D); /* StringPrefix */ - g_array_append_vals(var.buf, s, len); - build_append_byte(var.buf, 0x0); /* NullChar */ + build_append_byte(var->buf, 0x0D); /* StringPrefix */ + g_array_append_vals(var->buf, s, len); + build_append_byte(var->buf, 0x0); /* NullChar */ g_free(s); return var; } /* ACPI 5.0: 20.2.6.2 Local Objects Encoding: Local0Op */ -AcpiAml acpi_local0(void) +AcpiAml *acpi_local0(void) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x60); /* Local0Op */ + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); + build_append_byte(var->buf, 0x60); /* Local0Op */ return var; } /* ACPI 5.0: 20.2.5.4 Type 2 Opcodes Encoding: DefVarPackage */ -AcpiAml acpi_varpackage(uint32_t num_elements) +AcpiAml *acpi_varpackage(uint32_t num_elements) { - AcpiAml var = aml_allocate_internal(0x13 /* VarPackageOp */, PACKAGE); - build_append_int(var.buf, num_elements); + AcpiAml *var = aml_allocate_internal(0x13 /* VarPackageOp */, PACKAGE); + build_append_int(var->buf, num_elements); return var; } /* ACPI 5.0: 20.2.5.2 Named Objects Encoding: DefProcessor */ AcpiAml GCC_FMT_ATTR(4, 5) -acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len, +*acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len, const char *name_format, ...) { va_list ap; - AcpiAml var = aml_allocate_internal(0x83 /* ProcessorOp */, EXT_PACKAGE); + AcpiAml *var = aml_allocate_internal(0x83 /* ProcessorOp */, EXT_PACKAGE); va_start(ap, name_format); - build_append_namestringv(var.buf, name_format, ap); + build_append_namestringv(var->buf, name_format, ap); va_end(ap); - build_append_byte(var.buf, proc_id); /* ProcID */ + build_append_byte(var->buf, proc_id); /* ProcID */ /* PblkAddr */ - build_append_byte(var.buf, pblk_addr & 0xFF); - build_append_byte(var.buf, (pblk_addr >> 8) & 0xFF); - build_append_byte(var.buf, (pblk_addr >> 16) & 0xFF); - build_append_byte(var.buf, (pblk_addr >> 24) & 0xFF); - build_append_byte(var.buf, pblk_len); /* PblkLen */ + build_append_byte(var->buf, pblk_addr & 0xFF); + build_append_byte(var->buf, (pblk_addr >> 8) & 0xFF); + build_append_byte(var->buf, (pblk_addr >> 16) & 0xFF); + build_append_byte(var->buf, (pblk_addr >> 24) & 0xFF); + build_append_byte(var->buf, pblk_len); /* PblkLen */ return var; } @@ -716,9 +718,9 @@ static uint8_t Hex2Digit(char c) } /* ACPI 5.0: 19.5.36 EISAID (EISA ID String To Integer Conversion Macro) */ -AcpiAml acpi_eisaid(const char *str) +AcpiAml *acpi_eisaid(const char *str) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); uint32_t id; g_assert(strlen(str) == 7); @@ -730,102 +732,102 @@ AcpiAml acpi_eisaid(const char *str) Hex2Digit(str[5]) << 4 | Hex2Digit(str[6]); - build_append_byte(var.buf, 0x0C); /* DWordPrefix */ - build_append_value(var.buf, bswap32(id), sizeof(id)); + build_append_byte(var->buf, 0x0C); /* DWordPrefix */ + build_append_value(var->buf, bswap32(id), sizeof(id)); return var; } /* ACPI 5.0: 6.4.3.5.3 Word Address Space Descriptor */ -static AcpiAml +static AcpiAml * acpi_as_desc_header(acpiResourceType type, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, uint8_t type_flags) { uint8_t flags = max_fixed | min_fixed | dec; - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, type); - build_append_byte(var.buf, flags); - build_append_byte(var.buf, type_flags); /* Type Specific Flags */ + build_append_byte(var->buf, type); + build_append_byte(var->buf, flags); + build_append_byte(var->buf, type_flags); /* Type Specific Flags */ return var; } /* ACPI 5.0: 6.4.3.5.3 Word Address Space Descriptor */ -static AcpiAml acpi_word_as_desc(acpiResourceType type, acpiMinFixed min_fixed, +static AcpiAml *acpi_word_as_desc(acpiResourceType type, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, uint16_t addr_gran, uint16_t addr_min, uint16_t addr_max, uint16_t addr_trans, uint16_t len, uint8_t type_flags) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x88); /* Word Address Space Descriptor */ + build_append_byte(var->buf, 0x88); /* Word Address Space Descriptor */ /* minimum length since we do not encode optional fields */ - build_append_byte(var.buf, 0x0D); - build_append_byte(var.buf, 0x0); + build_append_byte(var->buf, 0x0D); + build_append_byte(var->buf, 0x0); - aml_append(&var, + aml_append(var, acpi_as_desc_header(type, min_fixed, max_fixed, dec, type_flags)); - build_append_value(var.buf, addr_gran, sizeof(addr_gran)); - build_append_value(var.buf, addr_min, sizeof(addr_min)); - build_append_value(var.buf, addr_max, sizeof(addr_max)); - build_append_value(var.buf, addr_trans, sizeof(addr_trans)); - build_append_value(var.buf, len, sizeof(len)); + build_append_value(var->buf, addr_gran, sizeof(addr_gran)); + build_append_value(var->buf, addr_min, sizeof(addr_min)); + build_append_value(var->buf, addr_max, sizeof(addr_max)); + build_append_value(var->buf, addr_trans, sizeof(addr_trans)); + build_append_value(var->buf, len, sizeof(len)); return var; } /* ACPI 5.0: 6.4.3.5.2 DWord Address Space Descriptor */ -static AcpiAml acpi_dword_as_desc(acpiResourceType type, acpiMinFixed min_fixed, +static AcpiAml *acpi_dword_as_desc(acpiResourceType type, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, uint32_t addr_gran, uint32_t addr_min, uint32_t addr_max, uint32_t addr_trans, uint32_t len, uint8_t type_flags) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x87); /* DWord Address Space Descriptor */ + build_append_byte(var->buf, 0x87); /* DWord Address Space Descriptor */ /* minimum length since we do not encode optional fields */ - build_append_byte(var.buf, 23); - build_append_byte(var.buf, 0x0); + build_append_byte(var->buf, 23); + build_append_byte(var->buf, 0x0); - aml_append(&var, + aml_append(var, acpi_as_desc_header(type, min_fixed, max_fixed, dec, type_flags)); - build_append_value(var.buf, addr_gran, sizeof(addr_gran)); - build_append_value(var.buf, addr_min, sizeof(addr_min)); - build_append_value(var.buf, addr_max, sizeof(addr_max)); - build_append_value(var.buf, addr_trans, sizeof(addr_trans)); - build_append_value(var.buf, len, sizeof(len)); + build_append_value(var->buf, addr_gran, sizeof(addr_gran)); + build_append_value(var->buf, addr_min, sizeof(addr_min)); + build_append_value(var->buf, addr_max, sizeof(addr_max)); + build_append_value(var->buf, addr_trans, sizeof(addr_trans)); + build_append_value(var->buf, len, sizeof(len)); return var; } /* ACPI 5.0: 6.4.3.5.1 QWord Address Space Descriptor */ -static AcpiAml acpi_qword_as_desc(acpiResourceType type, acpiMinFixed min_fixed, +static AcpiAml *acpi_qword_as_desc(acpiResourceType type, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, uint64_t addr_gran, uint64_t addr_min, uint64_t addr_max, uint64_t addr_trans, uint64_t len, uint8_t type_flags) { - AcpiAml var = aml_allocate_internal(0, NON_BLOCK); + AcpiAml *var = aml_allocate_internal(0, NON_BLOCK); - build_append_byte(var.buf, 0x8A); /* QWord Address Space Descriptor */ + build_append_byte(var->buf, 0x8A); /* QWord Address Space Descriptor */ /* minimum length since we do not encode optional fields */ - build_append_byte(var.buf, 0x2B); - build_append_byte(var.buf, 0x0); + build_append_byte(var->buf, 0x2B); + build_append_byte(var->buf, 0x0); - aml_append(&var, + aml_append(var, acpi_as_desc_header(type, min_fixed, max_fixed, dec, type_flags)); - build_append_value(var.buf, addr_gran, sizeof(addr_gran)); - build_append_value(var.buf, addr_min, sizeof(addr_min)); - build_append_value(var.buf, addr_max, sizeof(addr_max)); - build_append_value(var.buf, addr_trans, sizeof(addr_trans)); - build_append_value(var.buf, len, sizeof(len)); + build_append_value(var->buf, addr_gran, sizeof(addr_gran)); + build_append_value(var->buf, addr_min, sizeof(addr_min)); + build_append_value(var->buf, addr_max, sizeof(addr_max)); + build_append_value(var->buf, addr_trans, sizeof(addr_trans)); + build_append_value(var->buf, len, sizeof(len)); return var; } /* * ACPI 5.0: 19.5.141 WordBusNumber (Word Bus Number Resource Descriptor Macro) */ -AcpiAml acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, +AcpiAml *acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, uint16_t addr_gran, uint16_t addr_min, uint16_t addr_max, uint16_t addr_trans, uint16_t len) @@ -836,7 +838,7 @@ AcpiAml acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, } /* ACPI 5.0: 19.5.142 WordIO (Word IO Resource Descriptor Macro) */ -AcpiAml acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, +AcpiAml *acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, acpiISARanges isa_ranges, uint16_t addr_gran, uint16_t addr_min, uint16_t addr_max, uint16_t addr_trans, @@ -849,7 +851,7 @@ AcpiAml acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, } /* ACPI 5.0: 19.5.34 DWordMemory (DWord Memory Resource Descriptor Macro) */ -AcpiAml acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed, +AcpiAml *acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiCacheble cacheable, acpiReadAndWrite read_and_write, uint32_t addr_gran, uint32_t addr_min, @@ -864,7 +866,7 @@ AcpiAml acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed, } /* ACPI 5.0: 19.5.102 QWordMemory (QWord Memory Resource Descriptor Macro) */ -AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed, +AcpiAml *acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiCacheble cacheable, acpiReadAndWrite read_and_write, uint64_t addr_gran, uint64_t addr_min, @@ -879,32 +881,32 @@ AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed, } /* ACPI 5.0: 20.2.1 Table and Table Header Encoding */ -AcpiAml acpi_def_block(const char *signature, uint8_t revision, +AcpiAml *acpi_def_block(const char *signature, uint8_t revision, const char *oem_id, const char *oem_table_id, uint32_t oem_revision) { int len; - AcpiAml var = aml_allocate_internal(0, DEF_BLOCK); + AcpiAml *var = aml_allocate_internal(0, DEF_BLOCK); assert(strlen(signature) == 4); - g_array_append_vals(var.buf, signature, 4); - build_append_value(var.buf, 0, 4); /* Length place holder */ - build_append_byte(var.buf, revision); - build_append_byte(var.buf, 0); /* place holder for Checksum */ + g_array_append_vals(var->buf, signature, 4); + build_append_value(var->buf, 0, 4); /* Length place holder */ + build_append_byte(var->buf, revision); + build_append_byte(var->buf, 0); /* place holder for Checksum */ len = strlen(oem_id); assert(len <= 6); - g_array_append_vals(var.buf, oem_id, len); - g_array_append_vals(var.buf, "\0\0\0\0\0\0\0\0", 6 - len); + g_array_append_vals(var->buf, oem_id, len); + g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 6 - len); len = strlen(oem_table_id); assert(len <= 8); - g_array_append_vals(var.buf, oem_table_id, len); - g_array_append_vals(var.buf, "\0\0\0\0\0\0\0\0", 8 - len); + g_array_append_vals(var->buf, oem_table_id, len); + g_array_append_vals(var->buf, "\0\0\0\0\0\0\0\0", 8 - len); - build_append_value(var.buf, oem_revision, 4); - g_array_append_vals(var.buf, ACPI_BUILD_APPNAME4, 4); /* asl_compiler_id */ - build_append_value(var.buf, 1, 4); /* asl_compiler_revision */ + build_append_value(var->buf, oem_revision, 4); + g_array_append_vals(var->buf, ACPI_BUILD_APPNAME4, 4); /* asl_compiler_id */ + build_append_value(var->buf, 1, 4); /* asl_compiler_revision */ return var; } diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index f66da5d..c7f492e 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -493,18 +493,18 @@ static void acpi_set_pci_info(void) static void build_append_pcihp_notify_entry(AcpiAml *method, int slot) { - AcpiAml if_ctx; + AcpiAml *if_ctx; int32_t devfn = PCI_DEVFN(slot, 0); if_ctx = acpi_if(acpi_and(acpi_arg0(), acpi_int(0x1U << slot))); - aml_append(&if_ctx, acpi_notify(acpi_name("S%.02X", devfn), acpi_arg1())); + aml_append(if_ctx, acpi_notify(acpi_name("S%.02X", devfn), acpi_arg1())); aml_append(method, if_ctx); } static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, bool pcihp_bridge_en) { - AcpiAml dev, notify_method, method; + AcpiAml *dev, *notify_method, *method; QObject *bsel; PCIBus *sec; int i; @@ -527,22 +527,22 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, if (!pdev) { if (bsel) { dev = acpi_device("S%.02X", PCI_DEVFN(slot, 0)); - aml_append(&dev, acpi_name_decl("_SUN", acpi_int(slot))); - aml_append(&dev, acpi_name_decl("_ADR", acpi_int(slot << 16))); + aml_append(dev, acpi_name_decl("_SUN", acpi_int(slot))); + aml_append(dev, acpi_name_decl("_ADR", acpi_int(slot << 16))); method = acpi_method("_EJ0", 1); - aml_append(&method, + aml_append(method, acpi_call2("PCEJ", acpi_name("BSEL"), acpi_name("_SUN")) ); - aml_append(&dev, method); + aml_append(dev, method); aml_append(parent_scope, dev); - build_append_pcihp_notify_entry(¬ify_method, slot); + build_append_pcihp_notify_entry(notify_method, slot); } else { /* no much sense to create empty non hotpluggable slots, * but it's what original code did before. TODO: remove it. */ dev = acpi_device("S%.02X", PCI_DEVFN(slot, 0)); - aml_append(&dev, acpi_name_decl("_ADR", acpi_int(slot << 16))); + aml_append(dev, acpi_name_decl("_ADR", acpi_int(slot << 16))); aml_append(parent_scope, dev); } continue; @@ -557,7 +557,7 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, bridge_in_acpi = pc->is_bridge && pcihp_bridge_en; dev = acpi_device("S%.02X", PCI_DEVFN(slot, 0)); - aml_append(&dev, acpi_name_decl("_ADR", acpi_int(slot << 16))); + aml_append(dev, acpi_name_decl("_ADR", acpi_int(slot << 16))); if (pc->class_id == PCI_CLASS_DISPLAY_VGA) { int s3d = 0; @@ -567,27 +567,27 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, } method = acpi_method("_S1D", 0); - aml_append(&method, acpi_return(acpi_int(0))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_int(0))); + aml_append(dev, method); method = acpi_method("_S2D", 0); - aml_append(&method, acpi_return(acpi_int(0))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_int(0))); + aml_append(dev, method); method = acpi_method("_S3D", 0); - aml_append(&method, acpi_return(acpi_int(s3d))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_int(s3d))); + aml_append(dev, method); } else if (dc->hotpluggable && !bridge_in_acpi) { - aml_append(&dev, acpi_name_decl("_SUN", acpi_int(slot))); + aml_append(dev, acpi_name_decl("_SUN", acpi_int(slot))); method = acpi_method("_EJ0", 1); - aml_append(&method, + aml_append(method, acpi_call2("PCEJ", acpi_name("BSEL"), acpi_name("_SUN")) ); - aml_append(&dev, method); + aml_append(dev, method); if (bsel) { - build_append_pcihp_notify_entry(¬ify_method, slot); + build_append_pcihp_notify_entry(notify_method, slot); } } else { /* When hotplug for bridges is enabled, bridges that are @@ -596,7 +596,7 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, if (bridge_in_acpi) { PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); - build_append_pci_bus_devices(&dev, sec_bus, pcihp_bridge_en); + build_append_pci_bus_devices(dev, sec_bus, pcihp_bridge_en); } } aml_append(parent_scope, dev); @@ -614,12 +614,12 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, /* If bus supports hotplug select it and notify about local events */ if (bsel) { int64_t bsel_val = qint_get_int(qobject_to_qint(bsel)); - aml_append(&method, acpi_store(acpi_int(bsel_val), acpi_name("BNUM"))); - aml_append(&method, + aml_append(method, acpi_store(acpi_int(bsel_val), acpi_name("BNUM"))); + aml_append(method, acpi_call2("DVNT", acpi_name("PCIU"), acpi_int(1) /* Device Check */) ); - aml_append(&method, + aml_append(method, acpi_call2("DVNT", acpi_name("PCID"), acpi_int(3)/* Eject Request */) ); @@ -630,7 +630,7 @@ static void build_append_pci_bus_devices(AcpiAml *parent_scope, PCIBus *bus, QLIST_FOREACH(sec, &bus->child, sibling) { int32_t devfn = sec->parent_dev->devfn; - aml_append(&method, acpi_name("^S%.02X.PCNT", devfn)); + aml_append(method, acpi_name("^S%.02X.PCNT", devfn)); } } aml_append(parent_scope, method); @@ -644,7 +644,7 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, MachineState *machine = MACHINE(qdev_get_machine()); uint32_t nr_mem = machine->ram_slots; unsigned acpi_cpus = guest_info->apic_id_limit; - AcpiAml pkg, scope, dev, method, crs, field, ifctx, ssdt; + AcpiAml *pkg, *scope, *dev, *method, *crs, *field, *ifctx, *ssdt; int i; /* The current AML generator can cover the APIC ID range [0..255], @@ -659,93 +659,93 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, scope = acpi_scope("\\_SB.PCI0"); /* build PCI0._CRS */ crs = acpi_resource_template(); - aml_append(&crs, + aml_append(crs, acpi_word_bus_number(acpi_min_fixed, acpi_max_fixed, acpi_pos_decode, 0x0000, 0x0000, 0x00FF, 0x0000, 0x0100)); - aml_append(&crs, acpi_io(acpi_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08)); + aml_append(crs, acpi_io(acpi_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08)); - aml_append(&crs, + aml_append(crs, acpi_word_io(acpi_min_fixed, acpi_max_fixed, acpi_pos_decode, acpi_entire_range, 0x0000, 0x0000, 0x0CF7, 0x0000, 0x0CF8)); - aml_append(&crs, + aml_append(crs, acpi_word_io(acpi_min_fixed, acpi_max_fixed, acpi_pos_decode, acpi_entire_range, 0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300)); - aml_append(&crs, + aml_append(crs, acpi_dword_memory(acpi_pos_decode, acpi_min_fixed, acpi_max_fixed, acpi_cacheable, acpi_ReadWrite, 0, 0x000A0000, 0x000BFFFF, 0, 0x00020000)); - aml_append(&crs, + aml_append(crs, acpi_dword_memory(acpi_pos_decode, acpi_min_fixed, acpi_max_fixed, acpi_non_cacheable, acpi_ReadWrite, 0, pci->w32.begin, pci->w32.end - 1, 0, pci->w32.end - pci->w32.begin)); if (pci->w64.begin) { - aml_append(&crs, + aml_append(crs, acpi_qword_memory(acpi_pos_decode, acpi_min_fixed, acpi_max_fixed, acpi_cacheable, acpi_ReadWrite, 0, pci->w64.begin, pci->w64.end - 1, 0, pci->w64.end - pci->w64.begin)); } - aml_append(&scope, acpi_name_decl("_CRS", crs)); + aml_append(scope, acpi_name_decl("_CRS", crs)); /* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev = acpi_device("PHPR"); - aml_append(&dev, acpi_name_decl("_HID", acpi_string("PNP0A06"))); - aml_append(&dev, + aml_append(dev, acpi_name_decl("_HID", acpi_string("PNP0A06"))); + aml_append(dev, acpi_name_decl("_UID", acpi_string("PCI Hotplug resources"))); /* device present, functioning, decoding, not shown in UI */ - aml_append(&dev, acpi_name_decl("_STA", acpi_int(0xB))); + aml_append(dev, acpi_name_decl("_STA", acpi_int(0xB))); crs = acpi_resource_template(); - aml_append(&crs, + aml_append(crs, acpi_io(acpi_decode16, pm->pcihp_io_base, pm->pcihp_io_base, 1, pm->pcihp_io_len) ); - aml_append(&dev, acpi_name_decl("_CRS", crs)); - aml_append(&scope, dev); + aml_append(dev, acpi_name_decl("_CRS", crs)); + aml_append(scope, dev); } - aml_append(&ssdt, scope); + aml_append(ssdt, scope); /* create S3_ / S4_ / S5_ packages if necessary */ scope = acpi_scope("\\"); if (!pm->s3_disabled) { pkg = acpi_package(4); - aml_append(&pkg, acpi_int(1)); /* PM1a_CNT.SLP_TYP */ - aml_append(&pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */ - aml_append(&pkg, acpi_int(0)); /* reserved */ - aml_append(&pkg, acpi_int(0)); /* reserved */ - aml_append(&scope, acpi_name_decl("_S3", pkg)); + aml_append(pkg, acpi_int(1)); /* PM1a_CNT.SLP_TYP */ + aml_append(pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */ + aml_append(pkg, acpi_int(0)); /* reserved */ + aml_append(pkg, acpi_int(0)); /* reserved */ + aml_append(scope, acpi_name_decl("_S3", pkg)); } if (!pm->s4_disabled) { pkg = acpi_package(4); - aml_append(&pkg, acpi_int(pm->s4_val)); /* PM1a_CNT.SLP_TYP */ - aml_append(&pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */ - aml_append(&pkg, acpi_int(0)); /* reserved */ - aml_append(&pkg, acpi_int(0)); /* reserved */ - aml_append(&scope, acpi_name_decl("_S4", pkg)); + aml_append(pkg, acpi_int(pm->s4_val)); /* PM1a_CNT.SLP_TYP */ + aml_append(pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */ + aml_append(pkg, acpi_int(0)); /* reserved */ + aml_append(pkg, acpi_int(0)); /* reserved */ + aml_append(scope, acpi_name_decl("_S4", pkg)); } pkg = acpi_package(4); - aml_append(&pkg, acpi_int(0)); /* PM1a_CNT.SLP_TYP */ - aml_append(&pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */ - aml_append(&pkg, acpi_int(0)); /* reserved */ - aml_append(&pkg, acpi_int(0)); /* reserved */ - aml_append(&scope, acpi_name_decl("_S5", pkg)); - aml_append(&ssdt, scope); + aml_append(pkg, acpi_int(0)); /* PM1a_CNT.SLP_TYP */ + aml_append(pkg, acpi_int(0)); /* PM1b_CNT.SLP_TYP not impl. */ + aml_append(pkg, acpi_int(0)); /* reserved */ + aml_append(pkg, acpi_int(0)); /* reserved */ + aml_append(scope, acpi_name_decl("_S5", pkg)); + aml_append(ssdt, scope); if (misc->applesmc_io_base) { scope = acpi_scope("\\_SB.PCI0.ISA"); dev = acpi_device("SMC"); - aml_append(&dev, acpi_name_decl("_HID", acpi_eisaid("APP0001"))); + aml_append(dev, acpi_name_decl("_HID", acpi_eisaid("APP0001"))); /* device present, functioning, decoding, not shown in UI */ - aml_append(&dev, acpi_name_decl("_STA", acpi_int(0xB))); + aml_append(dev, acpi_name_decl("_STA", acpi_int(0xB))); crs = acpi_resource_template(); - aml_append(&crs, + aml_append(crs, acpi_io(acpi_decode16, misc->applesmc_io_base, misc->applesmc_io_base, @@ -753,88 +753,88 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, APPLESMC_MAX_DATA_LENGTH ) ); - aml_append(&crs, acpi_iqr_no_flags(6)); - aml_append(&dev, acpi_name_decl("_CRS", crs)); + aml_append(crs, acpi_iqr_no_flags(6)); + aml_append(dev, acpi_name_decl("_CRS", crs)); - aml_append(&scope, dev); - aml_append(&ssdt, scope); + aml_append(scope, dev); + aml_append(ssdt, scope); } if (misc->pvpanic_port) { scope = acpi_scope("\\_SB.PCI0.ISA"); dev = acpi_device("PEVR"); - aml_append(&dev, acpi_name_decl("_HID", acpi_string("QEMU0002"))); + aml_append(dev, acpi_name_decl("_HID", acpi_string("QEMU0002"))); crs = acpi_resource_template(); - aml_append(&crs, + aml_append(crs, acpi_io(acpi_decode16, misc->pvpanic_port, misc->pvpanic_port, 1, 1) ); - aml_append(&dev, acpi_name_decl("_CRS", crs)); + aml_append(dev, acpi_name_decl("_CRS", crs)); - aml_append(&dev, acpi_operation_region("PEOR", acpi_system_io, + aml_append(dev, acpi_operation_region("PEOR", acpi_system_io, misc->pvpanic_port, 1)); field = acpi_field("PEOR", acpi_byte_acc); - aml_append(&field, acpi_named_field("PEPT", 8)); - aml_append(&dev, field); + aml_append(field, acpi_named_field("PEPT", 8)); + aml_append(dev, field); method = acpi_method("RDPT", 0); - aml_append(&method, acpi_store(acpi_name("PEPT"), acpi_local0())); - aml_append(&method, acpi_return(acpi_local0())); - aml_append(&dev, method); + aml_append(method, acpi_store(acpi_name("PEPT"), acpi_local0())); + aml_append(method, acpi_return(acpi_local0())); + aml_append(dev, method); method = acpi_method("WRPT", 1); - aml_append(&method, acpi_store(acpi_arg0(), acpi_name("PEPT"))); - aml_append(&dev, method); + aml_append(method, acpi_store(acpi_arg0(), acpi_name("PEPT"))); + aml_append(dev, method); - aml_append(&scope, dev); - aml_append(&ssdt, scope); + aml_append(scope, dev); + aml_append(ssdt, scope); } { - AcpiAml sb_scope = acpi_scope("_SB"); + AcpiAml *sb_scope = acpi_scope("_SB"); /* create PCI0.PRES device and its _CRS to reserve CPU hotplug MMIO */ dev = acpi_device("PCI0." stringify(CPU_HOTPLUG_RESOURCE_DEVICE)); - aml_append(&dev, acpi_name_decl("_HID", acpi_eisaid("PNP0A06"))); - aml_append(&dev, + aml_append(dev, acpi_name_decl("_HID", acpi_eisaid("PNP0A06"))); + aml_append(dev, acpi_name_decl("_UID", acpi_string("CPU Hotplug resources")) ); /* device present, functioning, decoding, not shown in UI */ - aml_append(&dev, acpi_name_decl("_STA", acpi_int(0xB))); + aml_append(dev, acpi_name_decl("_STA", acpi_int(0xB))); crs = acpi_resource_template(); - aml_append(&crs, + aml_append(crs, acpi_io(acpi_decode16, pm->cpu_hp_io_base, pm->cpu_hp_io_base, 1, pm->cpu_hp_io_len) ); - aml_append(&dev, acpi_name_decl("_CRS", crs)); - aml_append(&sb_scope, dev); + aml_append(dev, acpi_name_decl("_CRS", crs)); + aml_append(sb_scope, dev); /* declare CPU hotplug MMIO region and PRS field to access it */ - aml_append(&sb_scope, acpi_operation_region( + aml_append(sb_scope, acpi_operation_region( "PRST", acpi_system_io, pm->cpu_hp_io_base, pm->cpu_hp_io_len)); field = acpi_field("PRST", acpi_byte_acc); - aml_append(&field, acpi_named_field("PRS", 256)); - aml_append(&sb_scope, field); + aml_append(field, acpi_named_field("PRS", 256)); + aml_append(sb_scope, field); /* build Processor object for each processor */ for (i = 0; i < acpi_cpus; i++) { dev = acpi_processor(i, 0, 0, "CP%.02X", i); method = acpi_method("_MAT", 0); - aml_append(&method, acpi_return(acpi_call1("CPMA", acpi_int(i)))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_call1("CPMA", acpi_int(i)))); + aml_append(dev, method); method = acpi_method("_STA", 0); - aml_append(&method, acpi_return(acpi_call1("CPST", acpi_int(i)))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_call1("CPST", acpi_int(i)))); + aml_append(dev, method); method = acpi_method("_EJ0", 1); - aml_append(&method, + aml_append(method, acpi_return(acpi_call2("CPEJ", acpi_int(i), acpi_arg0())) ); - aml_append(&dev, method); + aml_append(dev, method); - aml_append(&sb_scope, dev); + aml_append(sb_scope, dev); } /* build this code: @@ -844,12 +844,12 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, method = acpi_method("NTFY", 2); for (i = 0; i < acpi_cpus; i++) { ifctx = acpi_if(acpi_equal(acpi_arg0(), acpi_int(i))); - aml_append(&ifctx, + aml_append(ifctx, acpi_notify(acpi_name("CP%.02X", i), acpi_arg1()) ); - aml_append(&method, ifctx); + aml_append(method, ifctx); } - aml_append(&sb_scope, method); + aml_append(sb_scope, method); /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" * @@ -863,93 +863,93 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, for (i = 0; i < acpi_cpus; i++) { uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00; - aml_append(&pkg, acpi_int(b)); + aml_append(pkg, acpi_int(b)); } - aml_append(&sb_scope, acpi_name_decl("CPON", pkg)); + aml_append(sb_scope, acpi_name_decl("CPON", pkg)); /* build memory devices */ assert(nr_mem <= ACPI_MAX_RAM_SLOTS); scope = acpi_scope("\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE)); - aml_append(&scope, + aml_append(scope, acpi_name_decl(stringify(MEMORY_SLOTS_NUMBER), acpi_int(nr_mem)) ); crs = acpi_resource_template(); - aml_append(&crs, + aml_append(crs, acpi_io(acpi_decode16, pm->mem_hp_io_base, pm->mem_hp_io_base, 0, pm->mem_hp_io_len) ); - aml_append(&scope, acpi_name_decl("_CRS", crs)); + aml_append(scope, acpi_name_decl("_CRS", crs)); - aml_append(&scope, acpi_operation_region( + aml_append(scope, acpi_operation_region( stringify(MEMORY_HOTPLUG_IO_REGION), acpi_system_io, pm->mem_hp_io_base, pm->mem_hp_io_len) ); field = acpi_field(stringify(MEMORY_HOTPLUG_IO_REGION), acpi_dword_acc); - aml_append(&field, /* read only */ + aml_append(field, /* read only */ acpi_named_field(stringify(MEMORY_SLOT_ADDR_LOW), 32)); - aml_append(&field, /* read only */ + aml_append(field, /* read only */ acpi_named_field(stringify(MEMORY_SLOT_ADDR_HIGH), 32)); - aml_append(&field, /* read only */ + aml_append(field, /* read only */ acpi_named_field(stringify(MEMORY_SLOT_SIZE_LOW), 32)); - aml_append(&field, /* read only */ + aml_append(field, /* read only */ acpi_named_field(stringify(MEMORY_SLOT_SIZE_HIGH), 32)); - aml_append(&field, /* read only */ + aml_append(field, /* read only */ acpi_named_field(stringify(MEMORY_SLOT_PROXIMITY), 32)); - aml_append(&scope, field); + aml_append(scope, field); field = acpi_field(stringify(MEMORY_HOTPLUG_IO_REGION), acpi_byte_acc); - aml_append(&field, acpi_reserved_field(160 /* Offset(20) */)); - aml_append(&field, /* 1 if enabled, read only */ + aml_append(field, acpi_reserved_field(160 /* Offset(20) */)); + aml_append(field, /* 1 if enabled, read only */ acpi_named_field(stringify(MEMORY_SLOT_ENABLED), 1)); - aml_append(&field, + aml_append(field, /*(read) 1 if has a insert event. (write) 1 to clear event */ acpi_named_field(stringify(MEMORY_SLOT_INSERT_EVENT), 1)); - aml_append(&scope, field); + aml_append(scope, field); field = acpi_field(stringify(MEMORY_HOTPLUG_IO_REGION), acpi_dword_acc); - aml_append(&field, /* DIMM selector, write only */ + aml_append(field, /* DIMM selector, write only */ acpi_named_field(stringify(MEMORY_SLOT_SLECTOR), 32)); - aml_append(&field, /* _OST event code, write only */ + aml_append(field, /* _OST event code, write only */ acpi_named_field(stringify(MEMORY_SLOT_OST_EVENT), 32)); - aml_append(&field, /* _OST status code, write only */ + aml_append(field, /* _OST status code, write only */ acpi_named_field(stringify(MEMORY_SLOT_OST_STATUS), 32)); - aml_append(&scope, field); + aml_append(scope, field); - aml_append(&sb_scope, scope); + aml_append(sb_scope, scope); for (i = 0; i < nr_mem; i++) { #define BASEPATH "\\_SB.PCI0." stringify(MEMORY_HOTPLUG_DEVICE) "." const char *s; dev = acpi_device("MP%02X", i); - aml_append(&dev, acpi_name_decl("_UID", acpi_string("0x%02X", i))); - aml_append(&dev, acpi_name_decl("_HID", acpi_eisaid("PNP0C80"))); + aml_append(dev, acpi_name_decl("_UID", acpi_string("0x%02X", i))); + aml_append(dev, acpi_name_decl("_HID", acpi_eisaid("PNP0C80"))); method = acpi_method("_CRS", 0); s = BASEPATH stringify(MEMORY_SLOT_CRS_METHOD); - aml_append(&method, acpi_return(acpi_call1(s, acpi_name("_UID")))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_call1(s, acpi_name("_UID")))); + aml_append(dev, method); method = acpi_method("_STA", 0); s = BASEPATH stringify(MEMORY_SLOT_STATUS_METHOD); - aml_append(&method, acpi_return(acpi_call1(s, acpi_name("_UID")))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_call1(s, acpi_name("_UID")))); + aml_append(dev, method); method = acpi_method("_PXM", 0); s = BASEPATH stringify(MEMORY_SLOT_PROXIMITY_METHOD); - aml_append(&method, acpi_return(acpi_call1(s, acpi_name("_UID")))); - aml_append(&dev, method); + aml_append(method, acpi_return(acpi_call1(s, acpi_name("_UID")))); + aml_append(dev, method); method = acpi_method("_OST", 3); s = BASEPATH stringify(MEMORY_SLOT_OST_METHOD); - aml_append(&method, acpi_return(acpi_call4( + aml_append(method, acpi_return(acpi_call4( s, acpi_name("_UID"), acpi_arg0(), acpi_arg1(), acpi_arg2() ))); - aml_append(&dev, method); + aml_append(dev, method); - aml_append(&sb_scope, dev); + aml_append(sb_scope, dev); } /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) { @@ -958,12 +958,12 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, method = acpi_method(stringify(MEMORY_SLOT_NOTIFY_METHOD), 2); for (i = 0; i < nr_mem; i++) { ifctx = acpi_if(acpi_equal(acpi_arg0(), acpi_int(i))); - aml_append(&ifctx, + aml_append(ifctx, acpi_notify(acpi_name("MP%.02X", i), acpi_arg1()) ); - aml_append(&method, ifctx); + aml_append(method, ifctx); } - aml_append(&sb_scope, method); + aml_append(sb_scope, method); { Object *pci_host; @@ -978,12 +978,12 @@ build_ssdt(AcpiAml *table_aml, GArray *linker, if (bus) { scope = acpi_scope("PCI0"); /* Scan all PCI buses. Generate tables to support hotplug. */ - build_append_pci_bus_devices(&scope, bus, + build_append_pci_bus_devices(scope, bus, pm->pcihp_bridge_en); - aml_append(&sb_scope, scope); + aml_append(sb_scope, scope); } } - aml_append(&ssdt, sb_scope); + aml_append(ssdt, sb_scope); } aml_append(table_aml, ssdt); diff --git a/include/hw/acpi/acpi-build-utils.h b/include/hw/acpi/acpi-build-utils.h index d39b5b1..0e068f1 100644 --- a/include/hw/acpi/acpi-build-utils.h +++ b/include/hw/acpi/acpi-build-utils.h @@ -95,56 +95,56 @@ typedef enum { } acpiReadAndWrite; -void aml_append(AcpiAml *parent_ctx, AcpiAml child); +void aml_append(AcpiAml *parent_ctx, AcpiAml *child); /* non block ASL object primitives */ -AcpiAml acpi_return(AcpiAml val); -AcpiAml acpi_int(const uint64_t val); -AcpiAml GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...); -AcpiAml acpi_name_decl(const char *name, AcpiAml val); -AcpiAml acpi_arg0(void); -AcpiAml acpi_arg1(void); -AcpiAml acpi_arg2(void); -AcpiAml acpi_arg3(void); -AcpiAml acpi_store(AcpiAml val, AcpiAml target); -AcpiAml acpi_and(AcpiAml arg1, AcpiAml arg2); -AcpiAml acpi_notify(AcpiAml arg1, AcpiAml arg2); -AcpiAml acpi_call1(const char *method, AcpiAml arg1); -AcpiAml acpi_call2(const char *method, AcpiAml arg1, AcpiAml arg2); -AcpiAml acpi_call3(const char *method, AcpiAml arg1, AcpiAml arg2, - AcpiAml arg3); -AcpiAml acpi_call4(const char *method, AcpiAml arg1, AcpiAml arg2, - AcpiAml arg3, AcpiAml arg4); -AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base, +AcpiAml *acpi_return(AcpiAml *val); +AcpiAml *acpi_int(const uint64_t val); +AcpiAml *GCC_FMT_ATTR(1, 2) acpi_name(const char *name_format, ...); +AcpiAml *acpi_name_decl(const char *name, AcpiAml *val); +AcpiAml *acpi_arg0(void); +AcpiAml *acpi_arg1(void); +AcpiAml *acpi_arg2(void); +AcpiAml *acpi_arg3(void); +AcpiAml *acpi_store(AcpiAml *val, AcpiAml *target); +AcpiAml *acpi_and(AcpiAml *arg1, AcpiAml *arg2); +AcpiAml *acpi_notify(AcpiAml *arg1, AcpiAml *arg2); +AcpiAml *acpi_call1(const char *method, AcpiAml *arg1); +AcpiAml *acpi_call2(const char *method, AcpiAml *arg1, AcpiAml *arg2); +AcpiAml *acpi_call3(const char *method, AcpiAml *arg1, AcpiAml *arg2, + AcpiAml *arg3); +AcpiAml *acpi_call4(const char *method, AcpiAml *arg1, AcpiAml *arg2, + AcpiAml *arg3, AcpiAml *arg4); +AcpiAml *acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len); -AcpiAml acpi_iqr_no_flags(uint8_t irq); -AcpiAml acpi_operation_region(const char *name, acpiRegionSpace rs, +AcpiAml *acpi_iqr_no_flags(uint8_t irq); +AcpiAml *acpi_operation_region(const char *name, acpiRegionSpace rs, uint32_t offset, uint32_t len); -AcpiAml acpi_named_field(const char *name, unsigned length); -AcpiAml acpi_reserved_field(unsigned length); -AcpiAml GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...); -AcpiAml acpi_local0(void); -AcpiAml acpi_equal(AcpiAml arg1, AcpiAml arg2); -AcpiAml GCC_FMT_ATTR(4, 5) +AcpiAml *acpi_named_field(const char *name, unsigned length); +AcpiAml *acpi_reserved_field(unsigned length); +AcpiAml *GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...); +AcpiAml *acpi_local0(void); +AcpiAml *acpi_equal(AcpiAml *arg1, AcpiAml *arg2); +AcpiAml *GCC_FMT_ATTR(4, 5) acpi_processor(uint8_t proc_id, uint32_t pblk_addr, uint8_t pblk_len, const char *name_format, ...); -AcpiAml acpi_eisaid(const char *str); -AcpiAml acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, +AcpiAml *acpi_eisaid(const char *str); +AcpiAml *acpi_word_bus_number(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, uint16_t addr_gran, uint16_t addr_min, uint16_t addr_max, uint16_t addr_trans, uint16_t len); -AcpiAml acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, +AcpiAml *acpi_word_io(acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiDecode dec, acpiISARanges isa_ranges, uint16_t addr_gran, uint16_t addr_min, uint16_t addr_max, uint16_t addr_trans, uint16_t len); -AcpiAml acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed, +AcpiAml *acpi_dword_memory(acpiDecode dec, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiCacheble cacheable, acpiReadAndWrite read_and_write, uint32_t addr_gran, uint32_t addr_min, uint32_t addr_max, uint32_t addr_trans, uint32_t len); -AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed, +AcpiAml *acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed, acpiMaxFixed max_fixed, acpiCacheble cacheable, acpiReadAndWrite read_and_write, uint64_t addr_gran, uint64_t addr_min, @@ -152,18 +152,18 @@ AcpiAml acpi_qword_memory(acpiDecode dec, acpiMinFixed min_fixed, uint64_t len); /* Block ASL object primitives */ -AcpiAml acpi_def_block(const char *signature, uint8_t revision, +AcpiAml *acpi_def_block(const char *signature, uint8_t revision, const char *oem_id, const char *oem_table_id, uint32_t oem_revision); -AcpiAml acpi_if(AcpiAml predicate); -AcpiAml acpi_method(const char *name, int arg_count); -AcpiAml GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...); -AcpiAml GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...); -AcpiAml acpi_buffer(void); -AcpiAml acpi_resource_template(void); -AcpiAml acpi_package(uint8_t num_elements); -AcpiAml acpi_field(const char *name, acpiFieldFlags flags); -AcpiAml acpi_varpackage(uint32_t num_elements); +AcpiAml *acpi_if(AcpiAml *predicate); +AcpiAml *acpi_method(const char *name, int arg_count); +AcpiAml *GCC_FMT_ATTR(1, 2) acpi_scope(const char *name_format, ...); +AcpiAml *GCC_FMT_ATTR(1, 2) acpi_device(const char *name_format, ...); +AcpiAml *acpi_buffer(void); +AcpiAml *acpi_resource_template(void); +AcpiAml *acpi_package(uint8_t num_elements); +AcpiAml *acpi_field(const char *name, acpiFieldFlags flags); +AcpiAml *acpi_varpackage(uint32_t num_elements); /* other helpers */ GArray *build_alloc_array(void); -- 1.8.3.1