From nobody Tue Nov 4 18:49:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530834875585670.6568665556116; Thu, 5 Jul 2018 16:54:35 -0700 (PDT) Received: from localhost ([::1]:55196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbE4v-0006zH-Jt for importer@patchew.org; Thu, 05 Jul 2018 19:54:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbE3s-0006ek-8g for qemu-devel@nongnu.org; Thu, 05 Jul 2018 19:53:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbE3r-00086a-1C for qemu-devel@nongnu.org; Thu, 05 Jul 2018 19:53:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38204 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fbE3k-0007qZ-6w; Thu, 05 Jul 2018 19:53:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6E95401B212; Thu, 5 Jul 2018 23:53:10 +0000 (UTC) Received: from redhat.com (ovpn-124-6.rdu2.redhat.com [10.10.124.6]) by smtp.corp.redhat.com (Postfix) with SMTP id 1D65876D0; Thu, 5 Jul 2018 23:53:09 +0000 (UTC) Date: Fri, 6 Jul 2018 02:53:09 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180705235305.124423-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 05 Jul 2018 23:53:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 05 Jul 2018 23:53:10 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] acpi: generalize aml_package / aml_varpackage X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Igor Mammedov , qemu-arm@nongnu.org, Shannon Zhao Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" VarPackage can accept an expression evaluating to int, not just an int. Change the API to make it more generic. Further, rather than have users call the correct API depending on value passed, use either PackageOp or VarPackageOp automatically. Signed-off-by: Michael S. Tsirkin Reviewed-by: Igor Mammedov --- include/hw/acpi/aml-build.h | 4 ++-- hw/acpi/aml-build.c | 18 ++++++++++++++---- hw/acpi/cpu_hotplug.c | 11 ++--------- hw/arm/virt-acpi-build.c | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 10c7946028..7cf2cf64bf 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -360,7 +360,7 @@ Aml *aml_method(const char *name, int arg_count, AmlSer= ializeFlag sflag); Aml *aml_if(Aml *predicate); Aml *aml_else(void); Aml *aml_while(Aml *predicate); -Aml *aml_package(uint8_t num_elements); +Aml *aml_package(uint64_t num_elements); Aml *aml_buffer(int buffer_size, uint8_t *byte_list); Aml *aml_resource_template(void); Aml *aml_field(const char *name, AmlAccessType type, AmlLockRule lock, @@ -373,7 +373,7 @@ Aml *aml_create_field(Aml *srcbuf, Aml *bit_index, Aml = *num_bits, const char *name); Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name); Aml *aml_create_qword_field(Aml *srcbuf, Aml *index, const char *name); -Aml *aml_varpackage(uint32_t num_elements); +Aml *aml_varpackage(Aml *num_elements); Aml *aml_touuid(const char *uuid); Aml *aml_unicode(const char *str); Aml *aml_refof(Aml *arg); diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index def62b3112..1996768b40 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1016,9 +1016,19 @@ Aml *aml_buffer(int buffer_size, uint8_t *byte_list) } =20 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefPackage */ -Aml *aml_package(uint8_t num_elements) +/* Note: The ability to create variable-sized packages was first + * introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages + * with up to 255 elements. Windows guests up to win2k8 fail when + * VarPackageOp is used. + */ +Aml *aml_package(uint64_t num_elements) { - Aml *var =3D aml_bundle(0x12 /* PackageOp */, AML_PACKAGE); + Aml *var; + + if (num_elements > 0xFF) + return aml_varpackage(aml_int(num_elements)); + + var =3D aml_bundle(0x12 /* PackageOp */, AML_PACKAGE); build_append_byte(var->buf, num_elements); return var; } @@ -1136,10 +1146,10 @@ Aml *aml_local(int num) } =20 /* ACPI 2.0a: 17.2.2 Data Objects Encoding: DefVarPackage */ -Aml *aml_varpackage(uint32_t num_elements) +Aml *aml_varpackage(Aml *num_elements) { Aml *var =3D aml_bundle(0x13 /* VarPackageOp */, AML_PACKAGE); - build_append_int(var->buf, num_elements); + aml_append(var, num_elements); return var; } =20 diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c index 5243918125..f8246fca6f 100644 --- a/hw/acpi/cpu_hotplug.c +++ b/hw/acpi/cpu_hotplug.c @@ -309,15 +309,8 @@ void build_legacy_cpu_hotplug_aml(Aml *ctx, MachineSta= te *machine, } aml_append(sb_scope, method); =20 - /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" - * - * Note: The ability to create variable-sized packages was first - * introduced in ACPI 2.0. ACPI 1.0 only allowed fixed-size packages - * ith up to 255 elements. Windows guests up to win2k8 fail when - * VarPackageOp is used. - */ - pkg =3D pcms->apic_id_limit <=3D 255 ? aml_package(pcms->apic_id_limit= ) : - aml_varpackage(pcms->apic_id_limit); + /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */ + pkg =3D aml_package(pcms->apic_id_limit); =20 for (i =3D 0, apic_idx =3D 0; i < apic_ids->len; i++) { int apic_id =3D apic_ids->cpus[i].arch_id; diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 6ea47e2588..2adb1de378 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -174,7 +174,7 @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapE= ntry *memmap, aml_append(dev, aml_name_decl("_CCA", aml_int(1))); =20 /* Declare the PCI Routing Table. */ - Aml *rt_pkg =3D aml_varpackage(nr_pcie_buses * PCI_NUM_PINS); + Aml *rt_pkg =3D aml_package(nr_pcie_buses * PCI_NUM_PINS); for (bus_no =3D 0; bus_no < nr_pcie_buses; bus_no++) { for (i =3D 0; i < PCI_NUM_PINS; i++) { int gsi =3D (i + bus_no) % PCI_NUM_PINS; --=20 MST