acpi: add aml_int() term

* 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 <imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Igor Mammedov 2015-02-18 19:14:21 +00:00 committed by Michael S. Tsirkin
parent 3c054bd51a
commit 295a515df0
3 changed files with 30 additions and 29 deletions

View file

@ -218,44 +218,34 @@ void build_extop_package(GArray *package, uint8_t op)
build_prepend_byte(package, 0x5B); /* ExtOpPrefix */ 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; 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) { for (i = 0; i < size; ++i) {
build_append_byte(table, value & 0xFF); build_append_byte(table, value & 0xFF);
value = value >> 8; value = value >> 8;
} }
} }
void build_append_int(GArray *table, uint32_t value) void build_append_int(GArray *table, uint64_t value)
{ {
if (value == 0x00) { if (value == 0x00) {
build_append_byte(table, 0x00); /* ZeroOp */ build_append_byte(table, 0x00); /* ZeroOp */
} else if (value == 0x01) { } else if (value == 0x01) {
build_append_byte(table, 0x01); /* OneOp */ build_append_byte(table, 0x01); /* OneOp */
} else if (value <= 0xFF) { } 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) { } 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 { } else {
build_append_value(table, value, 4); build_append_byte(table, 0x0E); /* QWordPrefix */
build_append_int_noprefix(table, value, 8);
} }
} }
@ -365,6 +355,17 @@ Aml *aml_scope(const char *name_format, ...)
return var; return var;
} }
/*
* 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 * helper to construct NameString, which returns Aml object
* for using with aml_append or other aml_* terms * for using with aml_append or other aml_* terms

View file

@ -304,14 +304,14 @@ static void build_append_and_cleanup_method(GArray *device, GArray *method)
static void build_append_notify_target_ifequal(GArray *method, static void build_append_notify_target_ifequal(GArray *method,
GArray *target_name, GArray *target_name,
uint32_t value, int size) uint32_t value)
{ {
GArray *notify = build_alloc_array(); GArray *notify = build_alloc_array();
uint8_t op = 0xA0; /* IfOp */ uint8_t op = 0xA0; /* IfOp */
build_append_byte(notify, 0x93); /* LEqualOp */ build_append_byte(notify, 0x93); /* LEqualOp */
build_append_byte(notify, 0x68); /* Arg0Op */ 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_byte(notify, 0x86); /* NotifyOp */
build_append_array(notify, target_name); build_append_array(notify, target_name);
build_append_byte(notify, 0x69); /* Arg1Op */ build_append_byte(notify, 0x69); /* Arg1Op */
@ -580,7 +580,7 @@ build_append_notify_method(GArray *device, const char *name,
GArray *target = build_alloc_array(); GArray *target = build_alloc_array();
build_append_namestring(target, format, i); build_append_namestring(target, format, i);
assert(i < 256); /* Fits in 1 byte */ 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); build_free_array(target);
} }
@ -715,11 +715,11 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
bus->parent_dev->devfn); bus->parent_dev->devfn);
build_append_byte(bus_table, 0x08); /* NameOp */ build_append_byte(bus_table, 0x08); /* NameOp */
build_append_namestring(bus_table, "_SUN"); 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_byte(bus_table, 0x08); /* NameOp */
build_append_namestring(bus_table, "_ADR"); build_append_namestring(bus_table, "_ADR");
build_append_value(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) | build_append_int(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
PCI_FUNC(bus->parent_dev->devfn), 4); PCI_FUNC(bus->parent_dev->devfn));
} else { } else {
op = 0x10; /* ScopeOp */; op = 0x10; /* ScopeOp */;
build_append_namestring(bus_table, "PCI0"); build_append_namestring(bus_table, "PCI0");

View file

@ -62,6 +62,7 @@ void aml_append(Aml *parent_ctx, Aml *child);
/* non block AML object primitives */ /* non block AML object primitives */
Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2); Aml *aml_name(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
Aml *aml_name_decl(const char *name, Aml *val); Aml *aml_name_decl(const char *name, Aml *val);
Aml *aml_int(const uint64_t val);
/* Block AML object primitives */ /* Block AML object primitives */
Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2); 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_prepend_package_length(GArray *package);
void build_package(GArray *package, uint8_t op); 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, uint64_t value);
void build_append_int(GArray *table, uint32_t value);
void build_extop_package(GArray *package, uint8_t op); void build_extop_package(GArray *package, uint8_t op);
#endif #endif