From patchwork Tue Jul 10 00:01:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941753 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41Pj7Q2YVJz9s2L for ; Tue, 10 Jul 2018 10:02:26 +1000 (AEST) Received: from localhost ([::1]:44956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg6p-00018k-MY for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:02:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg62-00018E-NC for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg60-0001nj-37 for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38462 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 1fcg5z-0001nV-UK for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 740154023470 for ; Tue, 10 Jul 2018 00:01:31 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id 3404E2156892; Tue, 10 Jul 2018 00:01:31 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:30 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-2-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 00:01:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 00:01:31 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 hack dontapply v2 1/7] acpi: aml: add aml_register() 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: imammedo@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Based on a patch by Igor Mammedov. Signed-off-by: Igor Mammedov Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/aml-build.h | 5 +++++ hw/acpi/aml-build.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 6c36903c0a..10c7946028 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -346,6 +346,11 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed, uint64_t len); Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel); +Aml *aml_register(AmlAddressSpace as, + uint8_t bit_width, + uint8_t bit_offset, + uint64_t address, + uint8_t access_size); Aml *aml_sleep(uint64_t msec); /* Block AML object primitives */ diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 1e43cd736d..def62b3112 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -874,6 +874,27 @@ Aml *aml_irq_no_flags(uint8_t irq) return var; } +/* + * ACPI: 2.0: 16.2.4.16 ASL Macro for Generic Register Descriptor + * + * access_size comes from: + * ACPI 3.0: 17.5.98 Register (Generic Register Resource Descriptor Macro) + */ +Aml *aml_register(AmlAddressSpace as, + uint8_t bit_width, + uint8_t bit_offset, + uint64_t address, + uint8_t access_size) +{ + Aml *var = aml_alloc(); + + build_append_byte(var->buf, 0x82); /* Generic Register Descriptor */ + build_append_byte(var->buf, 0x0C); /* Length, bits[7:0] */ + build_append_byte(var->buf, 0x0); /* Length, bits[15:8] */ + build_append_gas(var->buf, as, bit_width, bit_offset, access_size, address); + return var; +} + /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLNot */ Aml *aml_lnot(Aml *arg) { From patchwork Tue Jul 10 00:01:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41PjC328XHz9s1R for ; Tue, 10 Jul 2018 10:05:35 +1000 (AEST) Received: from localhost ([::1]:44974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg9s-0003uj-OW for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:05:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg65-00019M-GV for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg64-0001px-4y for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51378 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 1fcg60-0001nu-NH; Mon, 09 Jul 2018 20:01:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30594808255B; Tue, 10 Jul 2018 00:01:32 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id B11A92026D65; Tue, 10 Jul 2018 00:01:31 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:31 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-3-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 00:01:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 00:01:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 hack dontapply v2 2/7] 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 , ehabkost@redhat.com, pbonzini@redhat.com, qemu-arm@nongnu.org, Shannon Zhao , imammedo@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- include/hw/acpi/aml-build.h | 4 ++-- hw/acpi/aml-build.c | 19 +++++++++++++++---- hw/acpi/cpu_hotplug.c | 11 ++--------- hw/arm/virt-acpi-build.c | 2 +- 4 files changed, 20 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, AmlSerializeFlag 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..7165f19585 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1016,9 +1016,20 @@ Aml *aml_buffer(int buffer_size, uint8_t *byte_list) } /* 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 = aml_bundle(0x12 /* PackageOp */, AML_PACKAGE); + Aml *var; + + if (num_elements > 0xFF) { + return aml_varpackage(aml_int(num_elements)); + } + + var = aml_bundle(0x12 /* PackageOp */, AML_PACKAGE); build_append_byte(var->buf, num_elements); return var; } @@ -1136,10 +1147,10 @@ Aml *aml_local(int num) } /* 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 = aml_bundle(0x13 /* VarPackageOp */, AML_PACKAGE); - build_append_int(var->buf, num_elements); + aml_append(var, num_elements); return var; } 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, MachineState *machine, } aml_append(sb_scope, method); - /* 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 = pcms->apic_id_limit <= 255 ? aml_package(pcms->apic_id_limit) : - aml_varpackage(pcms->apic_id_limit); + /* build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" */ + pkg = aml_package(pcms->apic_id_limit); for (i = 0, apic_idx = 0; i < apic_ids->len; i++) { int apic_id = 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 MemMapEntry *memmap, aml_append(dev, aml_name_decl("_CCA", aml_int(1))); /* Declare the PCI Routing Table. */ - Aml *rt_pkg = aml_varpackage(nr_pcie_buses * PCI_NUM_PINS); + Aml *rt_pkg = aml_package(nr_pcie_buses * PCI_NUM_PINS); for (bus_no = 0; bus_no < nr_pcie_buses; bus_no++) { for (i = 0; i < PCI_NUM_PINS; i++) { int gsi = (i + bus_no) % PCI_NUM_PINS; From patchwork Tue Jul 10 00:01:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941755 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41Pj7T4WfKz9s0W for ; Tue, 10 Jul 2018 10:02:29 +1000 (AEST) Received: from localhost ([::1]:44958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg6t-0001AX-7u for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:02:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg62-00018F-Nd for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg61-0001o9-Ab for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36408 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 1fcg61-0001o5-5Q for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:33 -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 AA3CB400138A for ; Tue, 10 Jul 2018 00:01:32 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id 6CBAD16873; Tue, 10 Jul 2018 00:01:32 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:32 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-4-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> 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.7]); Tue, 10 Jul 2018 00:01:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 10 Jul 2018 00:01:32 +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 hack dontapply v2 3/7] acpi: aml_load/aml_unload 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: imammedo@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Dynamic loading/unloading of tables. Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/aml-build.h | 2 ++ hw/acpi/aml-build.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 7cf2cf64bf..f764f71e25 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -381,6 +381,8 @@ Aml *aml_derefof(Aml *arg); Aml *aml_sizeof(Aml *arg); Aml *aml_concatenate(Aml *source1, Aml *source2, Aml *target); Aml *aml_object_type(Aml *object); +Aml *aml_load(const char *name, Aml *ddbhandle); +Aml *aml_unload(Aml *ddbhandle); void build_append_int_noprefix(GArray *table, uint64_t value, int size); void diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 7165f19585..ce691c1618 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1552,6 +1552,27 @@ Aml *aml_object_type(Aml *object) return var; } +/* ACPI 2.0: 17.2.4.3 Type 1 Opcodes Encoding: DefLoad */ +Aml *aml_load(const char *name, Aml *ddbhandle) +{ + Aml *var = aml_alloc(); + build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ + build_append_byte(var->buf, 0x20); /* LoadOp */ + aml_append(var, aml_name("%s", name)); + aml_append(var, ddbhandle); + return var; +} + +/* ACPI 2.0: 17.2.4.3 Type 1 Opcodes Encoding: DefUnload */ +Aml *aml_unload(Aml *ddbhandle) +{ + Aml *var = aml_alloc(); + build_append_byte(var->buf, 0x5B); /* ExtOpPrefix */ + build_append_byte(var->buf, 0x2A); /* UnloadOp */ + aml_append(var, ddbhandle); + return var; +} + void build_header(BIOSLinker *linker, GArray *table_data, AcpiTableHeader *h, const char *sig, int len, uint8_t rev, From patchwork Tue Jul 10 00:01:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41Pj7R5RQGz9s0W for ; Tue, 10 Jul 2018 10:02:27 +1000 (AEST) Received: from localhost ([::1]:44957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg6r-00019H-BS for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:02:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg62-00018B-MZ for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg61-0001oL-RV for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:34 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41010 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 1fcg61-0001oD-MU for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34F7D87AC4 for ; Tue, 10 Jul 2018 00:01:33 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id E691A111D3CF; Tue, 10 Jul 2018 00:01:32 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:32 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-5-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 00:01:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 10 Jul 2018 00:01:33 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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 hack dontapply v2 4/7] acpi: export acpi_checksum 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: imammedo@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" For most tables we supply to guests checksum is calculated by the bios at load time. However, when table needs to be changed later dynamically, QEMU has to calculate the checksum. Export acpi_checksum so ACPI generation code can re-use it. Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/acpi.h | 2 ++ hw/acpi/core.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h index c20ace0d0b..957a064d58 100644 --- a/include/hw/acpi/acpi.h +++ b/include/hw/acpi/acpi.h @@ -148,6 +148,8 @@ struct ACPIREGS { Notifier wakeup; }; +int acpi_checksum(const uint8_t *data, int len); + /* PM_TMR */ void acpi_pm_tmr_update(ACPIREGS *ar, bool enable); void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar); diff --git a/hw/acpi/core.c b/hw/acpi/core.c index b8d39012cd..ae24d104d4 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -72,7 +72,7 @@ static void acpi_register_config(void) opts_init(acpi_register_config); -static int acpi_checksum(const uint8_t *data, int len) +int acpi_checksum(const uint8_t *data, int len) { int sum, i; sum = 0; From patchwork Tue Jul 10 00:01:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941756 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41Pj7q5hpyz9s0W for ; Tue, 10 Jul 2018 10:02:47 +1000 (AEST) Received: from localhost ([::1]:44961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg7B-0001Nu-AX for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:02:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36051) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg63-00018H-6u for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg62-0001of-Db for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55024 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 1fcg62-0001oR-8I for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BABD140122D5 for ; Tue, 10 Jul 2018 00:01:33 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id 7BFE42156892; Tue, 10 Jul 2018 00:01:33 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:33 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-6-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 10 Jul 2018 00:01:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 10 Jul 2018 00:01:33 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 hack dontapply v2 5/7] acpi: init header without linking 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: imammedo@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" build_header inits the table header and then adds it to list for checksumming and linking into XSDT. Dynamically loaded SSDTs are not linked into XSDT so they just need the header initialized. Split out the relevant part of build_header so it can be invoked externally for this purpose. Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/aml-build.h | 3 +++ hw/acpi/aml-build.c | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index f764f71e25..0371a96c46 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -389,6 +389,9 @@ void build_header(BIOSLinker *linker, GArray *table_data, AcpiTableHeader *h, const char *sig, int len, uint8_t rev, const char *oem_id, const char *oem_table_id); +void +acpi_init_header(AcpiTableHeader *h, const char *sig, int len, uint8_t rev, + const char *oem_id, const char *oem_table_id); void *acpi_data_push(GArray *table_data, unsigned size); unsigned acpi_data_len(GArray *table); void acpi_add_table(GArray *table_offsets, GArray *table_data); diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index ce691c1618..02f9710caa 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1574,12 +1574,9 @@ Aml *aml_unload(Aml *ddbhandle) } void -build_header(BIOSLinker *linker, GArray *table_data, - AcpiTableHeader *h, const char *sig, int len, uint8_t rev, - const char *oem_id, const char *oem_table_id) +acpi_init_header(AcpiTableHeader *h, const char *sig, int len, uint8_t rev, + const char *oem_id, const char *oem_table_id) { - unsigned tbl_offset = (char *)h - table_data->data; - unsigned checksum_offset = (char *)&h->checksum - table_data->data; memcpy(&h->signature, sig, 4); h->length = cpu_to_le32(len); h->revision = rev; @@ -1600,6 +1597,17 @@ build_header(BIOSLinker *linker, GArray *table_data, h->oem_revision = cpu_to_le32(1); memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4); h->asl_compiler_revision = cpu_to_le32(1); +} + +void +build_header(BIOSLinker *linker, GArray *table_data, + AcpiTableHeader *h, const char *sig, int len, uint8_t rev, + const char *oem_id, const char *oem_table_id) +{ + unsigned tbl_offset = (char *)h - table_data->data; + unsigned checksum_offset = (char *)&h->checksum - table_data->data; + + acpi_init_header(h, sig, len, rev, oem_id, oem_table_id); /* Checksum to be filled in by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE, tbl_offset, len, checksum_offset); From patchwork Tue Jul 10 00:01:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41PjG82FYcz9s1R for ; Tue, 10 Jul 2018 10:08:16 +1000 (AEST) Received: from localhost ([::1]:44991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcgCT-0006Gu-UR for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:08:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg64-00018i-Fe for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg62-0001pH-Vd for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51386 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 1fcg62-0001oj-Pa for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:34 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43E3C814F0B6 for ; Tue, 10 Jul 2018 00:01:34 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id 02E882026D65; Tue, 10 Jul 2018 00:01:33 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:33 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-7-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 00:01:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 00:01:34 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 hack dontapply v2 6/7] acpi: aml generation for _CST 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: imammedo@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This adds a method called CCST under CPUS. Each CPU will add _CST calling in turn CCST from there. As _CST needs to change across migration, we use dynamic loading of tables as follows: - a special scratch buffer, 4K in size is requested from bios through the loader. - each time CCST executes, buffer address is passed to QEMU which will write an SSDT table with the _CST package into the buffer. - table is then loaded and a package named \\_SB.CPUS.CSTL is loaded from there. - table is unloaded, package is then returned to caller In this way, QEMU can change the package across migration. It will then notify the OSPM which will re-evaluate _CST. In this proof of concept patch, package generation itself is still a stub, and change notifications are missing. Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/cst.h | 8 ++ hw/acpi/cst.c | 173 ++++++++++++++++++++++++++++++++++++++++++ hw/acpi/Makefile.objs | 2 +- 3 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 include/hw/acpi/cst.h create mode 100644 hw/acpi/cst.c diff --git a/include/hw/acpi/cst.h b/include/hw/acpi/cst.h new file mode 100644 index 0000000000..2e40e87881 --- /dev/null +++ b/include/hw/acpi/cst.h @@ -0,0 +1,8 @@ +#ifndef HW_ACPI_CST_H +#define HW_ACPI_CST_H + +#include "hw/acpi/bios-linker-loader.h" + +void cst_build_acpi(GArray *table_data, BIOSLinker *linker, uint16_t ioport); +void cst_register(FWCfgState *s, uint16_t ioport); +#endif diff --git a/hw/acpi/cst.c b/hw/acpi/cst.c new file mode 100644 index 0000000000..20dd80aef8 --- /dev/null +++ b/hw/acpi/cst.c @@ -0,0 +1,173 @@ +#include "qemu/osdep.h" +#include "exec/address-spaces.h" +#include "hw/acpi/aml-build.h" +#include "hw/acpi/cst.h" +#include "hw/acpi/acpi.h" +#include "hw/nvram/fw_cfg.h" + +#define ACPI_SCRATCH_BUFFER_NAME "etc/scratch" + +/* Hack! Incomplete! */ +static Aml *build_cst_package(void) +{ + int i; + Aml *crs; + Aml *pkg; + int cs_num = 3; + + pkg = aml_package(cs_num + 1); /* # of ACPI Cx states + state count */ + aml_append(pkg, aml_int(cs_num)); /* # of ACPI Cx states */ + + for (i = 0; i < cs_num; i++) { + Aml *cstate = aml_package(4); + + crs = aml_resource_template(); + aml_append(crs, aml_register(AML_AS_SYSTEM_IO, + 0x8, + 0x0, + 0x100, + 0x1)); + aml_append(cstate, crs); + aml_append(cstate, aml_int(i + 1)); /* Cx ACPI state */ + aml_append(cstate, aml_int((i + 1) * 10)); /* Latency */ + aml_append(cstate, aml_int(cs_num - i - 1));/* Power */ + aml_append(pkg, cstate); + } + + return pkg; +} + +static GArray *cst_scratch; + +/* + * Add an SSDT with a dynamic method named CCST. The method uses the specified + * ioport to load a table from QEMU, then returns an object named CSTL from + * it. + * Everything is scoped under \\_SB.CPUS.CSTP. + */ +void cst_build_acpi(GArray *table_data, BIOSLinker *linker, uint16_t ioport) +{ + Aml *ssdt, *scope, *field, *method; + uint32_t cstp_offset; + + /* Put this in a separate SSDT table */ + ssdt = init_aml_allocator(); + + /* Reserve space for header */ + acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader)); + + cstp_offset = table_data->len + + build_append_named_dword(ssdt->buf, "\\_SB.CPUS.CSTP"); + scope = aml_scope("\\_SB.CPUS"); + { + /* buffer in reserved memory to load the table from */ + aml_append(scope, aml_operation_region("CSTB", AML_SYSTEM_MEMORY, + aml_name("\\_SB.CPUS.CSTP"), + 4096)); + /* write address here to update the table in memory */ + aml_append(scope, aml_operation_region("CSTR", AML_SYSTEM_IO, + aml_int(ioport), + 4)); + field = aml_field("CSTR", AML_DWORD_ACC, AML_LOCK, + AML_WRITE_AS_ZEROS); + { + aml_append(field, aml_named_field("CSTU", 32)); + } + aml_append(scope, field); + method = aml_method("CCST", 0, AML_SERIALIZED); + { + Aml *ddbhandle = aml_local(0); + Aml *cst = aml_local(1); + /* Write buffer address to update table in memory. */ + aml_append(method, aml_store(aml_name("CSTP"), aml_name("CSTU"))); + aml_append(method, aml_load("CSTB", ddbhandle)); + aml_append(method, aml_store(aml_name("CSTL"), cst)); + aml_append(method, aml_unload(ddbhandle)); + aml_append(method, aml_return(cst)); + } + aml_append(scope, method); + } + aml_append(ssdt, scope); + g_array_append_vals(table_data, ssdt->buf->data, ssdt->buf->len); + + /* Why page boundary? no special reason right now but seems like + * a good idea for future extensions. + */ + bios_linker_loader_alloc(linker, ACPI_SCRATCH_BUFFER_NAME, cst_scratch, + 4096, false /* page boundary, high memory */); + /* Patch address of allocated memory into the AML so OSPM can retrieve + * and read it. + */ + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_TABLE_FILE, cstp_offset, sizeof(uint32_t), + ACPI_SCRATCH_BUFFER_NAME, 0); + + //table_data->data[cstp_offset] = 0x8; /* hack */ + + build_header(linker, table_data, + (void *)(table_data->data + table_data->len - ssdt->buf->len), + "SSDT", ssdt->buf->len, 1, NULL, "CSTSSDT"); + + free_aml_allocator(); +} + +static GArray *cst_ssdt; + +static void cst_ssdt_setup(void) +{ + AcpiTableHeader *dyn_ssdt_hdr; + Aml *dyn_ssdt = init_aml_allocator(); + + /* Reserve space for header */ + acpi_data_push(dyn_ssdt->buf, sizeof(AcpiTableHeader)); + aml_append(dyn_ssdt, aml_name_decl("\\_SB.CPUS.CSTL", build_cst_package())); + + dyn_ssdt_hdr = (AcpiTableHeader *)dyn_ssdt->buf->data; + + acpi_init_header(dyn_ssdt_hdr, "SSDT", dyn_ssdt->buf->len, 1, NULL, "DYNSSDT"); + + dyn_ssdt_hdr->checksum = acpi_checksum((uint8_t *)dyn_ssdt_hdr, + dyn_ssdt->buf->len); + + /* dyn_ssdt->buf will be freed. copy to cst_ssdt */ + cst_ssdt = g_array_new(false, true, 1); + g_array_append_vals(cst_ssdt, dyn_ssdt->buf->data, dyn_ssdt->buf->len); + + free_aml_allocator(); +} + +/* Update CST in system memory */ +static void cst_ioport_write(void *opaque, hwaddr addr, uint64_t data, unsigned size) +{ + assert(cst_ssdt); + + cpu_physical_memory_write(data, cst_ssdt->data, cst_ssdt->len); +} + +static const MemoryRegionOps cst_ops = { + .write = cst_ioport_write, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static MemoryRegion cst_mr; + +void cst_register(FWCfgState *s, uint16_t ioport) +{ + cst_ssdt_setup(); + + /* Allocate guest scratch memory for the table */ + cst_scratch = g_array_new(false, true, 1); + acpi_data_push(cst_scratch, 4096); + fw_cfg_add_file(s, ACPI_SCRATCH_BUFFER_NAME, cst_scratch->data, + cst_scratch->len); + + /* setup io to trigger updates */ + memory_region_init_io(&cst_mr, NULL, &cst_ops, NULL, "cst-update-request", 4); + memory_region_add_subregion(get_system_io(), ioport, &cst_mr); +} + +/* TODO: API to notify guest of changes */ diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 11c35bcb44..0119367455 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -1,5 +1,5 @@ ifeq ($(CONFIG_ACPI),y) -common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o +common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o cst.o common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o From patchwork Tue Jul 10 00:01:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941759 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41PjCL11Gvz9s1R for ; Tue, 10 Jul 2018 10:05:49 +1000 (AEST) Received: from localhost ([::1]:44977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcgA7-00045E-He for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 20:05:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcg64-00018j-Ph for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcg63-0001pe-Hr for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38466 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 1fcg63-0001pM-By for qemu-devel@nongnu.org; Mon, 09 Jul 2018 20:01:35 -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 D12974023470; Tue, 10 Jul 2018 00:01:34 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id 806CC16874; Tue, 10 Jul 2018 00:01:34 +0000 (UTC) Date: Tue, 10 Jul 2018 03:01:34 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710000024.542612-8-mst@redhat.com> References: <20180710000024.542612-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> 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]); Tue, 10 Jul 2018 00:01:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 10 Jul 2018 00:01:34 +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 hack dontapply v2 7/7] pc: HACK: acpi: tie in _CST object to Processor 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: imammedo@redhat.com, Richard Henderson , ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Based on patch by Igor Mammedov. This is a hack: we definitely shouldn't do it unconditionally, and initialization should be handled differently (through an isa device?). io port to use should depend on the PC type and should be documented. Notifications should be supported. Signed-off-by: Michael S. Tsirkin --- include/hw/i386/pc.h | 5 +++++ hw/acpi/cpu.c | 5 +++++ hw/i386/acpi-build.c | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 316230e570..83b3a84322 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -20,6 +20,11 @@ #define HPET_INTCAP "hpet-intcap" +typedef struct PCCstate { + uint32_t latency; + uint32_t hint; +} PCCstate; + /** * PCMachineState: * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c index 5ae595ecbe..e9e207b033 100644 --- a/hw/acpi/cpu.c +++ b/hw/acpi/cpu.c @@ -561,6 +561,11 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, aml_int(arch_ids->cpus[i].props.node_id))); } + if (1) { + method = aml_method("_CST", 0, AML_NOTSERIALIZED); + aml_append(method, aml_return(aml_call0("CCST"))); + aml_append(dev, method); + } aml_append(cpus_dev, dev); } } diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index fff1059a31..da2c830db7 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -64,6 +64,7 @@ #include "hw/i386/intel_iommu.h" #include "hw/acpi/ipmi.h" +#include "hw/acpi/cst.h" /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and * -M pc-i440fx-2.0. Even if the actual amount of AML generated grows @@ -1840,7 +1841,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, build_legacy_cpu_hotplug_aml(dsdt, machine, pm->cpu_hp_io_base); } else { CPUHotplugFeatures opts = { - .apci_1_compatible = true, .has_legacy_cphp = true + .apci_1_compatible = true, .has_legacy_cphp = true, }; build_cpus_aml(dsdt, machine, opts, pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02"); @@ -2693,6 +2694,10 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) tables->vmgenid, tables->linker); } + /* TODO: get a free ioport. This one is PIIX specific. */ + acpi_add_table(table_offsets, tables_blob); + cst_build_acpi(tables_blob, tables->linker, 0xaf20); + if (misc.has_hpet) { acpi_add_table(table_offsets, tables_blob); build_hpet(tables_blob, tables->linker); @@ -2891,6 +2896,9 @@ void acpi_setup(void) build_state = g_malloc0(sizeof *build_state); + /* TODO: this is not the best place to do it */ + cst_register(pcms->fw_cfg, 0xaf20); + acpi_build_tables_init(&tables); acpi_build(&tables, MACHINE(pcms)); From patchwork Tue Jul 10 01:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 941788 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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 41PlX23mLcz9ryt for ; Tue, 10 Jul 2018 11:50:25 +1000 (AEST) Received: from localhost ([::1]:45306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fchnJ-0005xK-Sm for incoming@patchwork.ozlabs.org; Mon, 09 Jul 2018 21:50:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fchmm-0005v2-2m for qemu-devel@nongnu.org; Mon, 09 Jul 2018 21:49:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fchmk-0006W8-AA for qemu-devel@nongnu.org; Mon, 09 Jul 2018 21:49:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54166 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 1fchmk-0006Vx-4C for qemu-devel@nongnu.org; Mon, 09 Jul 2018 21:49:46 -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 A66DC818F049 for ; Tue, 10 Jul 2018 01:49:45 +0000 (UTC) Received: from redhat.com (ovpn-120-239.rdu2.redhat.com [10.10.120.239]) by smtp.corp.redhat.com (Postfix) with SMTP id 6A2C37C4E; Tue, 10 Jul 2018 01:49:45 +0000 (UTC) Date: Tue, 10 Jul 2018 04:49:45 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20180710014756.548217-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180710000024.542612-1-mst@redhat.com> 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.8]); Tue, 10 Jul 2018 01:49:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 10 Jul 2018 01:49:45 +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 hack dontapply v2 8/7 untested] acpi: support cst change notifications 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: Igor Mammedov , ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" (Ab)use cpu hotplug event infrastructure to report per-CPU _CST change events. Signed-off-by: Michael S. Tsirkin --- Untested infrastructure to notify about _CST changes. include/hw/acpi/cpu.h | 4 ++++ hw/acpi/cpu.c | 39 +++++++++++++++++++++++++++++++++++---- hw/acpi/trace-events | 3 ++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/include/hw/acpi/cpu.h b/include/hw/acpi/cpu.h index 89ce172941..31e20c590b 100644 --- a/include/hw/acpi/cpu.h +++ b/include/hw/acpi/cpu.h @@ -22,6 +22,7 @@ typedef struct AcpiCpuStatus { uint64_t arch_id; bool is_inserting; bool is_removing; + bool is_cst_changing; uint32_t ost_event; uint32_t ost_status; } AcpiCpuStatus; @@ -37,6 +38,9 @@ typedef struct CPUHotplugState { void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, CPUHotplugState *cpu_st, DeviceState *dev, Error **errp); +void acpi_cpu_change_cst(HotplugHandler *hotplug_dev, + CPUHotplugState *cpu_st, DeviceState *dev, Error **errp); + void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, CPUHotplugState *cpu_st, DeviceState *dev, Error **errp); diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c index e9e207b033..6dc0cfb901 100644 --- a/hw/acpi/cpu.c +++ b/hw/acpi/cpu.c @@ -66,6 +66,7 @@ static uint64_t cpu_hotplug_rd(void *opaque, hwaddr addr, unsigned size) val |= cdev->cpu ? 1 : 0; val |= cdev->is_inserting ? 2 : 0; val |= cdev->is_removing ? 4 : 0; + val |= cdev->is_cst_changing ? 0x10 : 0; trace_cpuhp_acpi_read_flags(cpu_st->selector, val); break; case ACPI_CPU_CMD_DATA_OFFSET_RW: @@ -126,6 +127,9 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data, dev = DEVICE(cdev->cpu); hotplug_ctrl = qdev_get_hotplug_handler(dev); hotplug_handler_unplug(hotplug_ctrl, dev, NULL); + } else if (data & 0x10) { + cdev->is_cst_changing = false; + trace_cpuhp_acpi_clear_cst_evt(cpu_st->selector); } break; case ACPI_CPU_CMD_OFFSET_WR: @@ -137,10 +141,12 @@ static void cpu_hotplug_wr(void *opaque, hwaddr addr, uint64_t data, do { cdev = &cpu_st->devs[iter]; - if (cdev->is_inserting || cdev->is_removing) { + if (cdev->is_inserting || cdev->is_removing || + cdev->is_cst_changing) { cpu_st->selector = iter; trace_cpuhp_acpi_cpu_has_events(cpu_st->selector, - cdev->is_inserting, cdev->is_removing); + cdev->is_inserting, cdev->is_removing, + cdev->is_cst_changing); break; } iter = iter + 1 < cpu_st->dev_count ? iter + 1 : 0; @@ -237,6 +243,18 @@ void acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, } } +void acpi_cpu_change_cst(HotplugHandler *hotplug_dev, + CPUHotplugState *cpu_st, DeviceState *dev, Error **errp) +{ + AcpiCpuStatus *cdev = get_cpu_status(cpu_st, dev); + if (!cdev) { + return; + } + + cdev->is_cst_changing = true; + acpi_send_event(DEVICE(hotplug_dev), ACPI_CPU_HOTPLUG_STATUS); +} + void acpi_cpu_unplug_request_cb(HotplugHandler *hotplug_dev, CPUHotplugState *cpu_st, DeviceState *dev, Error **errp) @@ -273,6 +291,7 @@ static const VMStateDescription vmstate_cpuhp_sts = { .fields = (VMStateField[]) { VMSTATE_BOOL(is_inserting, AcpiCpuStatus), VMSTATE_BOOL(is_removing, AcpiCpuStatus), + VMSTATE_BOOL(is_cst_changing, AcpiCpuStatus), VMSTATE_UINT32(ost_event, AcpiCpuStatus), VMSTATE_UINT32(ost_status, AcpiCpuStatus), VMSTATE_END_OF_LIST() @@ -309,6 +328,7 @@ const VMStateDescription vmstate_cpu_hotplug = { #define CPU_INSERT_EVENT "CINS" #define CPU_REMOVE_EVENT "CRMV" #define CPU_EJECT_EVENT "CEJ0" +#define CPU_CSTATE_EVENT "CSTE" void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, hwaddr io_base, @@ -361,7 +381,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, aml_append(field, aml_named_field(CPU_REMOVE_EVENT, 1)); /* initiates device eject, write only */ aml_append(field, aml_named_field(CPU_EJECT_EVENT, 1)); - aml_append(field, aml_reserved_field(4)); + aml_append(field, aml_named_field(CPU_CSTATE_EVENT, 1)); + aml_append(field, aml_reserved_field(3)); aml_append(field, aml_named_field(CPU_COMMAND, 8)); aml_append(cpu_ctrl_dev, field); @@ -396,6 +417,7 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, Aml *ins_evt = aml_name("%s.%s", cphp_res_path, CPU_INSERT_EVENT); Aml *rm_evt = aml_name("%s.%s", cphp_res_path, CPU_REMOVE_EVENT); Aml *ej_evt = aml_name("%s.%s", cphp_res_path, CPU_EJECT_EVENT); + Aml *cst_evt = aml_name("%s.%s", cphp_res_path, CPU_CSTATE_EVENT); aml_append(cpus_dev, aml_name_decl("_HID", aml_string("ACPI0010"))); aml_append(cpus_dev, aml_name_decl("_CID", aml_eisaid("PNP0A05"))); @@ -450,17 +472,26 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts, Aml *has_event = aml_local(0); Aml *dev_chk = aml_int(1); Aml *eject_req = aml_int(3); + Aml *cst_changed = aml_int(0x81); /* Re-evaluate _CST: ACPI 2.0: 8.3.2 _CST (C States) */ Aml *next_cpu_cmd = aml_int(CPHP_GET_NEXT_CPU_WITH_EVENT_CMD); aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); aml_append(method, aml_store(one, has_event)); while_ctx = aml_while(aml_equal(has_event, one)); { - /* clear loop exit condition, ins_evt/rm_evt checks + /* clear loop exit condition, ins_evt/rm_evt/cst_evt checks * will set it to 1 while next_cpu_cmd returns a CPU * with events */ aml_append(while_ctx, aml_store(zero, has_event)); aml_append(while_ctx, aml_store(next_cpu_cmd, cpu_cmd)); + ifctx = aml_if(aml_equal(cst_evt, one)); + { + aml_append(ifctx, + aml_call2(CPU_NOTIFY_METHOD, cpu_data, cst_changed)); + aml_append(ifctx, aml_store(one, cst_evt)); + aml_append(ifctx, aml_store(one, has_event)); + } + aml_append(while_ctx, ifctx); ifctx = aml_if(aml_equal(ins_evt, one)); { aml_append(ifctx, diff --git a/hw/acpi/trace-events b/hw/acpi/trace-events index df0024f8b2..d9ea0dc0e3 100644 --- a/hw/acpi/trace-events +++ b/hw/acpi/trace-events @@ -23,9 +23,10 @@ cpuhp_acpi_read_flags(uint32_t idx, uint8_t flags) "idx[0x%"PRIx32"] flags: 0x%" cpuhp_acpi_write_idx(uint32_t idx) "set active cpu idx: 0x%"PRIx32 cpuhp_acpi_write_cmd(uint32_t idx, uint8_t cmd) "idx[0x%"PRIx32"] cmd: 0x%"PRIx8 cpuhp_acpi_read_cmd_data(uint32_t idx, uint32_t data) "idx[0x%"PRIx32"] data: 0x%"PRIx32 -cpuhp_acpi_cpu_has_events(uint32_t idx, bool ins, bool rm) "idx[0x%"PRIx32"] inserting: %d, removing: %d" +cpuhp_acpi_cpu_has_events(uint32_t idx, bool ins, bool rm, bool cst) "idx[0x%"PRIx32"] inserting: %d, removing: %d, cst: %d" cpuhp_acpi_clear_inserting_evt(uint32_t idx) "idx[0x%"PRIx32"]" cpuhp_acpi_clear_remove_evt(uint32_t idx) "idx[0x%"PRIx32"]" +cpuhp_acpi_clear_cst_evt(uint32_t idx) "idx[0x%"PRIx32"]" cpuhp_acpi_ejecting_invalid_cpu(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_ejecting_cpu(uint32_t idx) "0x%"PRIx32 cpuhp_acpi_write_ost_ev(uint32_t slot, uint32_t ev) "idx[0x%"PRIx32"] OST EVENT: 0x%"PRIx32