From patchwork Mon Feb 9 10:53:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 437891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EA785140129 for ; Mon, 9 Feb 2015 22:06:07 +1100 (AEDT) Received: from localhost ([::1]:60139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKmAI-000815-23 for incoming@patchwork.ozlabs.org; Mon, 09 Feb 2015 06:06:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKlzi-0004Se-Nv for qemu-devel@nongnu.org; Mon, 09 Feb 2015 05:55:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKlzf-00011A-8r for qemu-devel@nongnu.org; Mon, 09 Feb 2015 05:55:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKlzf-00010f-1W for qemu-devel@nongnu.org; Mon, 09 Feb 2015 05:55:07 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t19At3SB023375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 9 Feb 2015 05:55:03 -0500 Received: from dell-pet610-01.lab.eng.brq.redhat.com (dell-pet610-01.lab.eng.brq.redhat.com [10.34.42.20]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t19AsFMw027675; Mon, 9 Feb 2015 05:55:01 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Mon, 9 Feb 2015 10:53:50 +0000 Message-Id: <1423479254-15342-29-git-send-email-imammedo@redhat.com> In-Reply-To: <1423479254-15342-1-git-send-email-imammedo@redhat.com> References: <1423479254-15342-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: drjones@redhat.com, marcel.a@redhat.com, claudio.fontana@huawei.com, mst@redhat.com, zhaoshenglong@huawei.com Subject: [Qemu-devel] [PATCH v3 28/52] acpi: include PkgLength size only when requested X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Named/Reserved{Field} definition uses PkgLength [1] encoding to specify field length, however it doesn't include size of PkgLength field itself, while other block objects that have explicit length of its body account for PkgLength size while encoding it [2]. This special casing isn't mentioned in ACPI spec, but that's what 'iasl' compiles NamedField to so add extra argument to build_prepend_pkg_length() to allow it handle the case. --- 1. ACPI Spec 5.0, 20.2.5.2 Named Objects Encoding, page 822 2. ACPI Spec 5.0, 5.4 Definition Block Encoding Signed-off-by: Igor Mammedov --- hw/acpi/aml-build.c | 20 +++++++++++++++----- 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 a5d5b83..8c6b6a3 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -159,10 +159,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)) { @@ -175,8 +175,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: @@ -209,7 +219,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 3dab2b5..1c95845 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -113,7 +113,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_value(GArray *table, uint64_t value, int size); void build_append_int(GArray *table, uint64_t value);