diff options
-rw-r--r-- | hw/acpi/aml-build.c | 20 | ||||
-rw-r--r-- | include/hw/acpi/aml-build.h | 3 |
2 files changed, 17 insertions, 6 deletions
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index d7edda1..cc883cc 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -158,10 +158,10 @@ enum { PACKAGE_LENGTH_4BYTE_SHIFT = 20, }; -void build_prepend_package_length(GArray *package) +void +build_prepend_package_length(GArray *package, unsigned length, bool incl_self) { uint8_t byte; - unsigned length = package->len; unsigned length_bytes; if (length + 1 < (1 << PACKAGE_LENGTH_1BYTE_SHIFT)) { @@ -174,8 +174,18 @@ void build_prepend_package_length(GArray *package) length_bytes = 4; } - /* PkgLength is the length of the inclusive length of the data. */ - length += length_bytes; + /* + * NamedField uses PkgLength encoding but it doesn't include length + * of PkgLength itself. + */ + if (incl_self) { + /* + * PkgLength is the length of the inclusive length of the data + * and PkgLength's length itself when used for terms with + * explitit length. + */ + length += length_bytes; + } switch (length_bytes) { case 1: @@ -208,7 +218,7 @@ void build_prepend_package_length(GArray *package) void build_package(GArray *package, uint8_t op) { - build_prepend_package_length(package); + build_prepend_package_length(package, package->len, true); build_prepend_byte(package, op); } diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 298e2ef..b7f491e 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -99,7 +99,8 @@ void build_append_array(GArray *array, GArray *val); void GCC_FMT_ATTR(2, 3) build_append_namestring(GArray *array, const char *format, ...); -void build_prepend_package_length(GArray *package); +void +build_prepend_package_length(GArray *package, unsigned length, bool incl_self); void build_package(GArray *package, uint8_t op); void build_append_int(GArray *table, uint64_t value); void build_extop_package(GArray *package, uint8_t op); |