Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- hw/acpi/acpi_gen_utils.c | 26 ++++++++++++++++++++++++++ include/hw/acpi/acpi_gen_utils.h | 1 + 2 files changed, 27 insertions(+)
diff --git a/hw/acpi/acpi_gen_utils.c b/hw/acpi/acpi_gen_utils.c index 6bd7974..920d8c2 100644 --- a/hw/acpi/acpi_gen_utils.c +++ b/hw/acpi/acpi_gen_utils.c @@ -561,6 +561,32 @@ AcpiAml acpi_field(const char *name, acpiFieldFlags 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 var = aml_allocate_internal(0, NON_BLOCK); + va_list ap, va_len; + char *s; + int len; + + va_start(ap, name_format); + va_copy(va_len, ap); + len = vsnprintf(NULL, 0, name_format, va_len); + va_end(va_len); + len += 1; + s = g_new(typeof(*s), len); + + 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 */ + g_free(s); + + return var; +} + /* ACPI 5.0: 20.2.6.2 Local Objects Encoding: Local0Op */ AcpiAml acpi_local0(void) { diff --git a/include/hw/acpi/acpi_gen_utils.h b/include/hw/acpi/acpi_gen_utils.h index 8261ee5..c823fb8 100644 --- a/include/hw/acpi/acpi_gen_utils.h +++ b/include/hw/acpi/acpi_gen_utils.h @@ -58,6 +58,7 @@ AcpiAml acpi_io(acpiIODecode dec, uint16_t min_base, uint16_t max_base, 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 GCC_FMT_ATTR(1, 2) acpi_string(const char *name_format, ...); AcpiAml acpi_local0(void); /* Block ASL object primitives */ -- 1.8.3.1