[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term |
Date: |
Wed, 18 Feb 2015 19:14:21 +0000 |
* factor out ACPI const int packing out of build_append_value()
and rename build_append_value() to build_append_int_noprefix()
it will be reused for adding a plain integer value into AML.
will be used by is aml_processor() and CRS macro helpers
* extend build_append_int{_noprefix}() to support 64-bit values
it will be used PCI for generating 64bit _CRS entries
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/acpi/aml-build.c | 43 ++++++++++++++++++++++---------------------
hw/i386/acpi-build.c | 12 ++++++------
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 cb00a1b..aaa80e5 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 c66fe56..bf34415 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 946aece..a385132 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
--
1.8.3.1
- [Qemu-devel] [PATCH v4 00/42] ACPI refactoring: replace template patching with C AML API, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 06/42] acpi: add aml_if() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 01/42] acpi: introduce AML composer aml_append(), Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 02/42] acpi: add aml_scope() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 07/42] acpi: add aml_name() & aml_name_decl() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 08/42] acpi: add aml_int() term,
Igor Mammedov <=
- [Qemu-devel] [PATCH v4 05/42] acpi: add aml_method() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 11/42] acpi: add aml_store() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 03/42] pc: acpi-build: use aml_scope() for \_SB scope, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 09/42] acpi: add aml_return() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 13/42] acpi: add aml_notify() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 04/42] acpi: add aml_device() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 10/42] acpi: add aml_arg() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 12/42] acpi: add aml_and() term, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 14/42] acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers, Igor Mammedov, 2015/02/18
- [Qemu-devel] [PATCH v4 18/42] acpi: add aml_resource_template() helper, Igor Mammedov, 2015/02/18