diff options
-rw-r--r-- | hw/acpi/aml-build.c | 43 | ||||
-rw-r--r-- | hw/i386/acpi-build.c | 12 | ||||
-rw-r--r-- | include/hw/acpi/aml-build.h | 4 |
3 files changed, 30 insertions, 29 deletions
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index cb00a1ba80..aaa80e575c 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -218,44 +218,34 @@ void build_extop_package(GArray *package, uint8_t op) build_prepend_byte(package, 0x5B); /* ExtOpPrefix */ } -void build_append_value(GArray *table, uint32_t value, int size) +static void build_append_int_noprefix(GArray *table, uint64_t value, int size) { - uint8_t prefix; int i; - switch (size) { - case 1: - prefix = 0x0A; /* BytePrefix */ - break; - case 2: - prefix = 0x0B; /* WordPrefix */ - break; - case 4: - prefix = 0x0C; /* DWordPrefix */ - break; - default: - assert(0); - return; - } - build_append_byte(table, prefix); for (i = 0; i < size; ++i) { build_append_byte(table, value & 0xFF); value = value >> 8; } } -void build_append_int(GArray *table, uint32_t value) +void build_append_int(GArray *table, uint64_t value) { if (value == 0x00) { build_append_byte(table, 0x00); /* ZeroOp */ } else if (value == 0x01) { build_append_byte(table, 0x01); /* OneOp */ } else if (value <= 0xFF) { - build_append_value(table, value, 1); + build_append_byte(table, 0x0A); /* BytePrefix */ + build_append_int_noprefix(table, value, 1); } else if (value <= 0xFFFF) { - build_append_value(table, value, 2); + build_append_byte(table, 0x0B); /* WordPrefix */ + build_append_int_noprefix(table, value, 2); + } else if (value <= 0xFFFFFFFF) { + build_append_byte(table, 0x0C); /* DWordPrefix */ + build_append_int_noprefix(table, value, 4); } else { - build_append_value(table, value, 4); + build_append_byte(table, 0x0E); /* QWordPrefix */ + build_append_int_noprefix(table, value, 8); } } @@ -366,6 +356,17 @@ Aml *aml_scope(const char *name_format, ...) } /* + * ACPI 1.0b: 16.2.3 Data Objects Encoding: + * encodes: ByteConst, WordConst, DWordConst, QWordConst, ZeroOp, OneOp + */ +Aml *aml_int(const uint64_t val) +{ + Aml *var = aml_alloc(); + build_append_int(var->buf, val); + return var; +} + +/* * helper to construct NameString, which returns Aml object * for using with aml_append or other aml_* terms */ diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index c66fe568c1..bf344151f5 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -304,14 +304,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method) static void build_append_notify_target_ifequal(GArray *method, GArray *target_name, - uint32_t value, int size) + uint32_t value) { GArray *notify = build_alloc_array(); uint8_t op = 0xA0; /* IfOp */ build_append_byte(notify, 0x93); /* LEqualOp */ build_append_byte(notify, 0x68); /* Arg0Op */ - build_append_value(notify, value, size); + build_append_int(notify, value); build_append_byte(notify, 0x86); /* NotifyOp */ build_append_array(notify, target_name); build_append_byte(notify, 0x69); /* Arg1Op */ @@ -580,7 +580,7 @@ build_append_notify_method(GArray *device, const char *name, GArray *target = build_alloc_array(); build_append_namestring(target, format, i); assert(i < 256); /* Fits in 1 byte */ - build_append_notify_target_ifequal(method, target, i, 1); + build_append_notify_target_ifequal(method, target, i); build_free_array(target); } @@ -715,11 +715,11 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state) bus->parent_dev->devfn); build_append_byte(bus_table, 0x08); /* NameOp */ build_append_namestring(bus_table, "_SUN"); - build_append_value(bus_table, PCI_SLOT(bus->parent_dev->devfn), 1); + build_append_int(bus_table, PCI_SLOT(bus->parent_dev->devfn)); build_append_byte(bus_table, 0x08); /* NameOp */ build_append_namestring(bus_table, "_ADR"); - build_append_value(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) | - PCI_FUNC(bus->parent_dev->devfn), 4); + build_append_int(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) | + PCI_FUNC(bus->parent_dev->devfn)); } else { op = 0x10; /* ScopeOp */; build_append_namestring(bus_table, "PCI0"); diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 946aece4ba..a385132b8e 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -62,6 +62,7 @@ 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_int(const uint64_t val); /* Block AML object primitives */ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2); @@ -81,8 +82,7 @@ build_append_namestring(GArray *array, const char *format, ...); void build_prepend_package_length(GArray *package); void build_package(GArray *package, uint8_t op); -void build_append_value(GArray *table, uint32_t value, int size); -void build_append_int(GArray *table, uint32_t value); +void build_append_int(GArray *table, uint64_t value); void build_extop_package(GArray *package, uint8_t op); #endif |