From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554805993766863.2143700257237; Tue, 9 Apr 2019 03:33:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:38726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo3g-00076v-7V for importer@patchew.org; Tue, 09 Apr 2019 06:32:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo1t-00062Y-V8 for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo1s-0007HT-OX for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:01 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2259 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo1o-0007D0-GR; Tue, 09 Apr 2019 06:30:56 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6D9CC4AD5344516400E9; Tue, 9 Apr 2019 18:30:52 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:30:44 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:28 +0100 Message-ID: <20190409102935.28292-2-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [PATCH v4 1/8] hw/acpi: Make ACPI IO address space configurable 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is in preparation for adding support for ARM64 platforms where it doesn't use port mapped IO for ACPI IO space. Also move few MEMORY_* definitions to header so that other memory hotplug event signalling mechanisms (eg. Generic Event Device on HW-reduced acpi platforms) can use the same from their respective event handler code. Signed-off-by: Shameer Kolothum Reviewed-by: Eric Auger Reviewed-by: Igor Mammedov --- hw/acpi/memory_hotplug.c | 25 ++++++++++++++----------- hw/i386/acpi-build.c | 3 ++- include/hw/acpi/memory_hotplug.h | 9 +++++++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c index 297812d..c724f5f 100644 --- a/hw/acpi/memory_hotplug.c +++ b/hw/acpi/memory_hotplug.c @@ -29,12 +29,9 @@ #define MEMORY_SLOT_PROXIMITY_METHOD "MPXM" #define MEMORY_SLOT_EJECT_METHOD "MEJ0" #define MEMORY_SLOT_NOTIFY_METHOD "MTFY" -#define MEMORY_SLOT_SCAN_METHOD "MSCN" #define MEMORY_HOTPLUG_DEVICE "MHPD" -#define MEMORY_HOTPLUG_IO_LEN 24 -#define MEMORY_DEVICES_CONTAINER "\\_SB.MHPC" =20 -static uint16_t memhp_io_base; +static hwaddr memhp_io_base; =20 static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev) { @@ -209,7 +206,7 @@ static const MemoryRegionOps acpi_memory_hotplug_ops = =3D { }; =20 void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner, - MemHotplugState *state, uint16_t io_base) + MemHotplugState *state, hwaddr io_base) { MachineState *machine =3D MACHINE(qdev_get_machine()); =20 @@ -342,7 +339,8 @@ const VMStateDescription vmstate_memory_hotplug =3D { =20 void build_memory_hotplug_aml(Aml *table, uint32_t nr_mem, const char *res_root, - const char *event_handler_method) + const char *event_handler_method, + AmlRegionSpace rs) { int i; Aml *ifctx; @@ -365,14 +363,19 @@ void build_memory_hotplug_aml(Aml *table, uint32_t nr= _mem, aml_name_decl("_UID", aml_string("Memory hotplug resources"))); =20 crs =3D aml_resource_template(); - aml_append(crs, - aml_io(AML_DECODE16, memhp_io_base, memhp_io_base, 0, - MEMORY_HOTPLUG_IO_LEN) - ); + if (rs =3D=3D AML_SYSTEM_IO) { + aml_append(crs, + aml_io(AML_DECODE16, memhp_io_base, memhp_io_base, 0, + MEMORY_HOTPLUG_IO_LEN) + ); + } else { + aml_append(crs, aml_memory32_fixed(memhp_io_base, + MEMORY_HOTPLUG_IO_LEN, AML_READ_WRITE)); + } aml_append(mem_ctrl_dev, aml_name_decl("_CRS", crs)); =20 aml_append(mem_ctrl_dev, aml_operation_region( - MEMORY_HOTPLUG_IO_REGION, AML_SYSTEM_IO, + MEMORY_HOTPLUG_IO_REGION, rs, aml_int(memhp_io_base), MEMORY_HOTPLUG_IO_LEN) ); =20 diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 416da31..6d6de44 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1852,7 +1852,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, build_cpus_aml(dsdt, machine, opts, pm->cpu_hp_io_base, "\\_SB.PCI0", "\\_GPE._E02"); } - build_memory_hotplug_aml(dsdt, nr_mem, "\\_SB.PCI0", "\\_GPE._E03"); + build_memory_hotplug_aml(dsdt, nr_mem, "\\_SB.PCI0", + "\\_GPE._E03", AML_SYSTEM_IO); =20 scope =3D aml_scope("_GPE"); { diff --git a/include/hw/acpi/memory_hotplug.h b/include/hw/acpi/memory_hotp= lug.h index 77c6576..e3a4b89 100644 --- a/include/hw/acpi/memory_hotplug.h +++ b/include/hw/acpi/memory_hotplug.h @@ -5,6 +5,10 @@ #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" =20 +#define MEMORY_SLOT_SCAN_METHOD "MSCN" +#define MEMORY_DEVICES_CONTAINER "\\_SB.MHPC" +#define MEMORY_HOTPLUG_IO_LEN 24 + /** * MemStatus: * @is_removing: the memory device in slot has been requested to be ejecte= d. @@ -29,7 +33,7 @@ typedef struct MemHotplugState { } MemHotplugState; =20 void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner, - MemHotplugState *state, uint16_t io_base); + MemHotplugState *state, hwaddr io_base); =20 void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem= _st, DeviceState *dev, Error **errp); @@ -48,5 +52,6 @@ void acpi_memory_ospm_status(MemHotplugState *mem_st, ACP= IOSTInfoList ***list); =20 void build_memory_hotplug_aml(Aml *table, uint32_t nr_mem, const char *res_root, - const char *event_handler_method); + const char *event_handler_method, + AmlRegionSpace rs); #endif --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554805993692236.731741497367; Tue, 9 Apr 2019 03:33:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:38730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo3u-0007Gp-QP for importer@patchew.org; Tue, 09 Apr 2019 06:33:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo1v-00063h-6T for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo1u-0007I5-5y for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:03 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2260 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo1r-0007Gc-Pd; Tue, 09 Apr 2019 06:31:00 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8704FE86AAFF382C5120; Tue, 9 Apr 2019 18:30:57 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:30:47 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:29 +0100 Message-ID: <20190409102935.28292-3-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [PATCH v4 2/8] hw/acpi: Do not create memory hotplug method when handler is not defined 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Samuel Ortiz With Hardware-reduced ACPI, the GED device will manage ACPI hotplug entirely. As a consequence, make the memory specific events AML generation optional. The code will only be added when the method name is not NULL. Signed-off-by: Samuel Ortiz Signed-off-by: Shameer Kolothum Reviewed-by: Eric Auger --- hw/acpi/memory_hotplug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c index c724f5f..b74a5e2 100644 --- a/hw/acpi/memory_hotplug.c +++ b/hw/acpi/memory_hotplug.c @@ -719,10 +719,12 @@ void build_memory_hotplug_aml(Aml *table, uint32_t nr= _mem, } aml_append(table, dev_container); =20 - method =3D aml_method(event_handler_method, 0, AML_NOTSERIALIZED); - aml_append(method, - aml_call0(MEMORY_DEVICES_CONTAINER "." MEMORY_SLOT_SCAN_METHOD)); - aml_append(table, method); + if (event_handler_method) { + method =3D aml_method(event_handler_method, 0, AML_NOTSERIALIZED); + aml_append(method, + aml_call0(MEMORY_DEVICES_CONTAINER "." MEMORY_SLOT_SCAN= _METHOD)); + aml_append(table, method); + } =20 g_free(mhp_res_path); } --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554806133126868.4231121806675; Tue, 9 Apr 2019 03:35:33 -0700 (PDT) Received: from localhost ([127.0.0.1]:38758 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo6D-0000W1-12 for importer@patchew.org; Tue, 09 Apr 2019 06:35:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo21-0006AN-Co for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo1x-0007JJ-BC for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:09 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2261 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo1r-0007Ge-QG; Tue, 09 Apr 2019 06:31:00 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7E81A1F0682C1204B317; Tue, 9 Apr 2019 18:30:57 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:30:50 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:30 +0100 Message-ID: <20190409102935.28292-4-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [PATCH v4 3/8] hw/acpi: Add ACPI Generic Event Device Support 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Samuel Ortiz The ACPI Generic Event Device (GED) is a hardware-reduced specific device[ACPI v6.1 Section 5.6.9] that handles all platform events, including the hotplug ones.This patch generates the AML code that defines GEDs. Platforms need to specify their own GedEvent array to describe what kind of events they want to support through GED. Also this uses a a single interrupt for the GED device, relying on IO memory region to communicate the type of device affected by the interrupt. This way, we can support up to 32 events with a unique interrupt. This supports only memory hotplug for now. Signed-off-by: Samuel Ortiz Signed-off-by: Sebastien Boeuf Signed-off-by: Shameer Kolothum --- hw/acpi/Kconfig | 4 + hw/acpi/Makefile.objs | 1 + hw/acpi/generic_event_device.c | 311 +++++++++++++++++++++++++++++= ++++ include/hw/acpi/generic_event_device.h | 121 +++++++++++++ 4 files changed, 437 insertions(+) create mode 100644 hw/acpi/generic_event_device.c create mode 100644 include/hw/acpi/generic_event_device.h diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig index eca3bee..01a8b41 100644 --- a/hw/acpi/Kconfig +++ b/hw/acpi/Kconfig @@ -27,3 +27,7 @@ config ACPI_VMGENID bool default y depends on PC + +config ACPI_HW_REDUCED + bool + depends on ACPI diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 2d46e37..b753232 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) +=3D memory_hotplu= g.o common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) +=3D cpu.o common-obj-$(CONFIG_ACPI_NVDIMM) +=3D nvdimm.o common-obj-$(CONFIG_ACPI_VMGENID) +=3D vmgenid.o +common-obj-$(CONFIG_ACPI_HW_REDUCED) +=3D generic_event_device.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) +=3D acpi-stub.o =20 common-obj-y +=3D acpi_interface.o diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c new file mode 100644 index 0000000..856ca04 --- /dev/null +++ b/hw/acpi/generic_event_device.c @@ -0,0 +1,311 @@ +/* + * + * Copyright (c) 2018 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "exec/address-spaces.h" +#include "hw/sysbus.h" +#include "hw/acpi/acpi.h" +#include "hw/acpi/generic_event_device.h" +#include "hw/mem/pc-dimm.h" + +static Aml *ged_event_aml(const GedEvent *event) +{ + + if (!event) { + return NULL; + } + + switch (event->event) { + case GED_MEMORY_HOTPLUG: + /* We run a complete memory SCAN when getting a memory hotplug eve= nt */ + return aml_call0(MEMORY_DEVICES_CONTAINER "." MEMORY_SLOT_SCAN_MET= HOD); + default: + break; + } + + return NULL; +} + +/* + * The ACPI Generic Event Device (GED) is a hardware-reduced specific + * device[ACPI v6.1 Section 5.6.9] that handles all platform events, + * including the hotplug ones. Platforms need to specify their own + * GedEvent array to describe what kind of events they want to support + * through GED. This routine uses a single interrupt for the GED device, + * relying on IO memory region to communicate the type of device + * affected by the interrupt. This way, we can support up to 32 events + * with a unique interrupt. + */ +void build_ged_aml(Aml *table, const char *name, HotplugHandler *hotplug_d= ev, + uint32_t ged_irq, AmlRegionSpace rs) +{ + AcpiGedState *s =3D ACPI_GED(hotplug_dev); + GedEvent *ged_events =3D s->ged_events; + Aml *crs =3D aml_resource_template(); + Aml *evt, *field; + Aml *dev =3D aml_device("%s", name); + Aml *irq_sel =3D aml_local(0); + Aml *isel =3D aml_name(AML_GED_IRQ_SEL); + uint32_t i; + + if (!s->ged_base || !ged_events || !s->ged_events_size) { + return; + } + + /* _CRS interrupt */ + aml_append(crs, aml_interrupt(AML_CONSUMER, AML_EDGE, AML_ACTIVE_HIGH, + AML_EXCLUSIVE, &ged_irq, 1)); + /* + * For each GED event we: + * - Add an interrupt to the CRS section. + * - Add a conditional block for each event, inside a while loop. + * This is semantically equivalent to a switch/case implementation. + */ + evt =3D aml_method("_EVT", 1, AML_SERIALIZED); + { + Aml *ged_aml; + Aml *if_ctx; + + /* Local0 =3D ISEL */ + aml_append(evt, aml_store(isel, irq_sel)); + + /* + * Here we want to call a method for each supported GED event type. + * The resulting ASL code looks like: + * + * Local0 =3D ISEL + * If ((Local0 & irq0) =3D=3D irq0) + * { + * MethodEvent0() + * } + * + * If ((Local0 & irq1) =3D=3D irq1) + * { + * MethodEvent1() + * } + * ... + */ + + for (i =3D 0; i < s->ged_events_size; i++) { + ged_aml =3D ged_event_aml(&ged_events[i]); + if (!ged_aml) { + continue; + } + + /* If ((Local1 =3D=3D irq))*/ + if_ctx =3D aml_if(aml_equal(aml_and(irq_sel, + aml_int(ged_events[i].selector), NUL= L), + aml_int(ged_events[i].selector))); + { + /* AML for this specific type of event */ + aml_append(if_ctx, ged_aml); + } + + /* + * We append the first "if" to the "while" context. + * Other "if"s will be "elseif"s. + */ + aml_append(evt, if_ctx); + } + } + + aml_append(dev, aml_name_decl("_HID", aml_string("ACPI0013"))); + aml_append(dev, aml_name_decl("_UID", aml_string(GED_DEVICE))); + aml_append(dev, aml_name_decl("_CRS", crs)); + + /* Append IO region */ + aml_append(dev, aml_operation_region(AML_GED_IRQ_REG, rs, + aml_int(s->ged_base + ACPI_GED_IRQ_SEL_OFFSET), + ACPI_GED_IRQ_SEL_LEN)); + field =3D aml_field(AML_GED_IRQ_REG, AML_DWORD_ACC, AML_NOLOCK, + AML_WRITE_AS_ZEROS); + aml_append(field, aml_named_field(AML_GED_IRQ_SEL, + ACPI_GED_IRQ_SEL_LEN * 8)); + aml_append(dev, field); + + /* Append _EVT method */ + aml_append(dev, evt); + + aml_append(table, dev); +} + +/* Memory read by the GED _EVT AML dynamic method */ +static uint64_t ged_read(void *opaque, hwaddr addr, unsigned size) +{ + uint64_t val =3D 0; + GEDState *ged_st =3D opaque; + + switch (addr) { + case ACPI_GED_IRQ_SEL_OFFSET: + /* Read the selector value and reset it */ + qemu_mutex_lock(&ged_st->lock); + val =3D ged_st->sel; + ged_st->sel =3D 0; + qemu_mutex_unlock(&ged_st->lock); + break; + default: + break; + } + + return val; +} + +/* Nothing is expected to be written to the GED memory region */ +static void ged_write(void *opaque, hwaddr addr, uint64_t data, + unsigned int size) +{ +} + +static const MemoryRegionOps ged_ops =3D { + .read =3D ged_read, + .write =3D ged_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static void acpi_ged_event(GEDState *ged_st, uint32_t ged_irq_sel) +{ + /* + * Set the GED IRQ selector to the expected device type value. This + * way, the ACPI method will be able to trigger the right code based + * on a unique IRQ. + */ + qemu_mutex_lock(&ged_st->lock); + ged_st->sel =3D ged_irq_sel; + qemu_mutex_unlock(&ged_st->lock); + + /* Trigger the event by sending an interrupt to the guest. */ + qemu_irq_pulse(ged_st->gsi[ged_st->irq]); +} + +static void acpi_ged_init(MemoryRegion *as, DeviceState *dev, GEDState *ge= d_st) +{ + AcpiGedState *s =3D ACPI_GED(dev); + + assert(s->ged_base); + + ged_st->irq =3D s->ged_irq; + ged_st->gsi =3D s->gsi; + qemu_mutex_init(&ged_st->lock); + memory_region_init_io(&ged_st->io, OBJECT(dev), &ged_ops, ged_st, + "acpi-ged-event", ACPI_GED_REG_LEN); + memory_region_add_subregion(as, s->ged_base, &ged_st->io); +} + +static void acpi_ged_device_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + AcpiGedState *s =3D ACPI_GED(hotplug_dev); + + if (s->memhp_state.is_enabled && + object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + acpi_memory_plug_cb(hotplug_dev, &s->memhp_state, + dev, errp); + } else { + error_setg(errp, "virt: device plug request for unsupported device" + " type: %s", object_get_typename(OBJECT(dev))); + } +} + +static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev) +{ + AcpiGedState *s =3D ACPI_GED(adev); + uint32_t sel; + + if (ev & ACPI_MEMORY_HOTPLUG_STATUS) { + sel =3D ACPI_GED_IRQ_SEL_MEM; + } else { + /* Unknown event. Return without generating interrupt. */ + return; + } + + /* + * We inject the hotplug interrupt. The IRQ selector will make + * the difference from the ACPI table. + */ + acpi_ged_event(&s->ged_state, sel); +} + +static void acpi_ged_device_realize(DeviceState *dev, Error **errp) +{ + AcpiGedState *s =3D ACPI_GED(dev); + + if (s->memhp_state.is_enabled) { + acpi_memory_hotplug_init(get_system_memory(), OBJECT(dev), + &s->memhp_state, + s->memhp_base); + acpi_ged_init(get_system_memory(), dev, &s->ged_state); + } +} + +static Property acpi_ged_properties[] =3D { + /* + * Memory hotplug base address is a property of GED here, + * because GED handles memory hotplug event and MEMORY_HOTPLUG_DEVICE + * gets initialized when GED device is realized. + */ + DEFINE_PROP_UINT64("memhp-base", AcpiGedState, memhp_base, 0), + DEFINE_PROP_BOOL("memory-hotplug-support", AcpiGedState, + memhp_state.is_enabled, true), + DEFINE_PROP_PTR("gsi", AcpiGedState, gsi), + DEFINE_PROP_UINT64("ged-base", AcpiGedState, ged_base, 0), + DEFINE_PROP_UINT32("ged-irq", AcpiGedState, ged_irq, 0), + DEFINE_PROP_PTR("ged-events", AcpiGedState, ged_events), + DEFINE_PROP_UINT32("ged-events-size", AcpiGedState, ged_events_size, 0= ), + DEFINE_PROP_END_OF_LIST(), +}; + +static void acpi_ged_class_init(ObjectClass *class, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(class); + HotplugHandlerClass *hc =3D HOTPLUG_HANDLER_CLASS(class); + AcpiDeviceIfClass *adevc =3D ACPI_DEVICE_IF_CLASS(class); + + dc->desc =3D "ACPI"; + dc->props =3D acpi_ged_properties; + dc->realize =3D acpi_ged_device_realize; + + /* Reason: pointer properties "gsi" and "ged_events" */ + dc->user_creatable =3D false; + + hc->plug =3D acpi_ged_device_plug_cb; + + adevc->send_event =3D acpi_ged_send_event; +} + +static const TypeInfo acpi_ged_info =3D { + .name =3D TYPE_ACPI_GED, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(AcpiGedState), + .class_init =3D acpi_ged_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { TYPE_ACPI_DEVICE_IF }, + { } + } +}; + +static void acpi_ged_register_types(void) +{ + type_register_static(&acpi_ged_info); +} + +type_init(acpi_ged_register_types) diff --git a/include/hw/acpi/generic_event_device.h b/include/hw/acpi/gener= ic_event_device.h new file mode 100644 index 0000000..9c840d8 --- /dev/null +++ b/include/hw/acpi/generic_event_device.h @@ -0,0 +1,121 @@ +/* + * + * Copyright (c) 2018 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + * + * The ACPI Generic Event Device (GED) is a hardware-reduced specific + * device[ACPI v6.1 Section 5.6.9] that handles all platform events, + * including the hotplug ones. Generic Event Device allows platforms + * to handle interrupts in ACPI ASL statements. It follows a very + * similar approach like the _EVT method from GPIO events. All + * interrupts are listed in _CRS and the handler is written in _EVT + * method. Here, we use a single interrupt for the GED device, relying + * on IO memory region to communicate the type of device affected by + * the interrupt. This way, we can support up to 32 events with a + * unique interrupt. + * + * Here is an example. + * + * Device (\_SB.GED) + * { + * Name (_HID, "ACPI0013") + * Name (_UID, Zero) + * Name (_CRS, ResourceTemplate () + * { + * Interrupt (ResourceConsumer, Edge, ActiveHigh, Exclusive, ,, ) + * { + * 0x00000029, + * } + * }) + * OperationRegion (IREG, SystemMemory, 0x09080000, 0x04) + * Field (IREG, DWordAcc, NoLock, WriteAsZeros) + * { + * ISEL, 32 + * } + * + * Method (_EVT, 1, Serialized) // _EVT: Event + * { + * Local0 =3D ISEL // ISEL =3D IO memory region which specifies the + * // device type. + * If (((Local0 & irq0) =3D=3D irq0)) + * { + * MethodEvent0() + * } + * ElseIf ((Local0 & irq1) =3D=3D irq1) + * { + * MethodEvent1() + * } + * ... + * } + * } + * + */ + +#ifndef HW_ACPI_GED_H +#define HW_ACPI_GED_H + +#include "hw/acpi/memory_hotplug.h" + +#define TYPE_ACPI_GED "acpi-ged" +#define ACPI_GED(obj) \ + OBJECT_CHECK(AcpiGedState, (obj), TYPE_ACPI_GED) + +#define ACPI_GED_IRQ_SEL_OFFSET 0x0 +#define ACPI_GED_IRQ_SEL_LEN 0x4 +#define ACPI_GED_IRQ_SEL_MEM 0x1 +#define ACPI_GED_REG_LEN 0x4 + +#define GED_DEVICE "GED" +#define AML_GED_IRQ_REG "IREG" +#define AML_GED_IRQ_SEL "ISEL" + +typedef enum { + GED_MEMORY_HOTPLUG =3D 1, +} GedEventType; + +/* + * Platforms need to specify their own GedEvent array + * to describe what kind of events they want to support + * through GED. + */ +typedef struct GedEvent { + uint32_t selector; + GedEventType event; +} GedEvent; + +typedef struct GEDState { + MemoryRegion io; + uint32_t sel; + uint32_t irq; + qemu_irq *gsi; + QemuMutex lock; +} GEDState; + + +typedef struct AcpiGedState { + DeviceClass parent_obj; + MemHotplugState memhp_state; + hwaddr memhp_base; + void *gsi; + hwaddr ged_base; + GEDState ged_state; + uint32_t ged_irq; + void *ged_events; + uint32_t ged_events_size; +} AcpiGedState; + +void build_ged_aml(Aml *table, const char* name, HotplugHandler *hotplug_d= ev, + uint32_t ged_irq, AmlRegionSpace rs); + +#endif --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554806147737207.6527338065839; Tue, 9 Apr 2019 03:35:47 -0700 (PDT) Received: from localhost ([127.0.0.1]:38789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo6S-0000l2-PL for importer@patchew.org; Tue, 09 Apr 2019 06:35:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo24-0006DR-DB for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo23-0007Ky-9N for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:12 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:2201 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo1x-0007Ib-Qh; Tue, 09 Apr 2019 06:31:06 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9C82FEA73BA413BBCD14; Tue, 9 Apr 2019 18:31:02 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:30:54 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:31 +0100 Message-ID: <20190409102935.28292-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.190 Subject: [Qemu-devel] [PATCH v4 4/8] hw/arm/virt: Add memory hotplug framework 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Eric Auger This patch adds the memory hot-plug/hot-unplug infrastructure in machvirt. The device memory is not yet exposed to the Guest either though DT or ACPI and hence both cold/hot plug of memory is explicitly disabled for now. Signed-off-by: Eric Auger Signed-off-by: Kwangwoo Lee Signed-off-by: Shameer Kolothum --- default-configs/arm-softmmu.mak | 3 +++ hw/arm/virt.c | 45 +++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 613d19a..9f4b803 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -160,3 +160,6 @@ CONFIG_MUSICPAL=3Dy =20 # for realview and versatilepb CONFIG_LSI_SCSI_PCI=3Dy + +CONFIG_MEM_DEVICE=3Dy +CONFIG_DIMM=3Dy diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ce2664a..da516b3 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -61,6 +61,8 @@ #include "hw/arm/smmuv3.h" #include "hw/acpi/acpi.h" #include "target/arm/internals.h" +#include "hw/mem/pc-dimm.h" +#include "hw/mem/nvdimm.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -1806,6 +1808,34 @@ static const CPUArchIdList *virt_possible_cpu_arch_i= ds(MachineState *ms) return ms->possible_cpus; } =20 +static void virt_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState = *dev, + Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + error_setg(errp, "memory cold/hot plug is not yet supported"); + return; + } + + pc_dimm_pre_plug(PC_DIMM(dev), MACHINE(hotplug_dev), NULL, errp); +} + +static void virt_memory_plug(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(hotplug_dev); + + pc_dimm_plug(PC_DIMM(dev), MACHINE(vms), NULL); + +} + +static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + virt_memory_pre_plug(hotplug_dev, dev, errp); + } +} + static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -1817,12 +1847,23 @@ static void virt_machine_device_plug_cb(HotplugHand= ler *hotplug_dev, SYS_BUS_DEVICE(dev)); } } + if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { + virt_memory_plug(hotplug_dev, dev, errp); + } +} + +static void virt_machine_device_unplug_request_cb(HotplugHandler *hotplug_= dev, + DeviceState *dev, Error **errp) +{ + error_setg(errp, "device unplug request for unsupported device" + " type: %s", object_get_typename(OBJECT(dev))); } =20 static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *mach= ine, DeviceState *dev) { - if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE)) { + if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE) || + (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM))) { return HOTPLUG_HANDLER(machine); } =20 @@ -1886,7 +1927,9 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) mc->kvm_type =3D virt_kvm_type; assert(!mc->get_hotplug_handler); mc->get_hotplug_handler =3D virt_machine_get_hotplug_handler; + hc->pre_plug =3D virt_machine_device_pre_plug_cb; hc->plug =3D virt_machine_device_plug_cb; + hc->unplug_request =3D virt_machine_device_unplug_request_cb; } =20 static void virt_instance_init(Object *obj) --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554806309532161.5219649764323; Tue, 9 Apr 2019 03:38:29 -0700 (PDT) Received: from localhost ([127.0.0.1]:38834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo93-0003KK-87 for importer@patchew.org; Tue, 09 Apr 2019 06:38:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo28-0006H9-LE for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo27-0007Mq-2A for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:16 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:44070 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo23-0007KF-8m; Tue, 09 Apr 2019 06:31:11 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A9B5356529DF89A7538A; Tue, 9 Apr 2019 18:31:07 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:30:57 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:32 +0100 Message-ID: <20190409102935.28292-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH v4 5/8] hw/arm/virt: Enable device memory cold/hot plug with ACPI boot 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This initializes the GED device with base memory and irq, configures ged memory hotplug event and builds the corresponding aml code. GED irq routing to Guest is also enabled. With this, both hot and cold plug of device memory is enabled now for Guest with ACPI boot. Memory cold plug support with Guest DT boot is not yet supported. Signed-off-by: Shameer Kolothum --- default-configs/arm-softmmu.mak | 2 ++ hw/arm/virt-acpi-build.c | 9 ++++++ hw/arm/virt.c | 61 +++++++++++++++++++++++++++++++++++++= ++-- include/hw/arm/virt.h | 4 +++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 9f4b803..c9a9b34 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -163,3 +163,5 @@ CONFIG_LSI_SCSI_PCI=3Dy =20 CONFIG_MEM_DEVICE=3Dy CONFIG_DIMM=3Dy +CONFIG_ACPI_MEMORY_HOTPLUG=3Dy +CONFIG_ACPI_HW_REDUCED=3Dy diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index bf9c0bc..1ad394b 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -40,6 +40,8 @@ #include "hw/loader.h" #include "hw/hw.h" #include "hw/acpi/aml-build.h" +#include "hw/acpi/memory_hotplug.h" +#include "hw/acpi/generic_event_device.h" #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" #include "hw/arm/virt.h" @@ -727,6 +729,7 @@ static void build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { Aml *scope, *dsdt; + MachineState *ms =3D MACHINE(vms); const MemMapEntry *memmap =3D vms->memmap; const int *irqmap =3D vms->irqmap; =20 @@ -753,6 +756,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) (irqmap[VIRT_GPIO] + ARM_SPI_BASE)); acpi_dsdt_add_power_button(scope); =20 + build_ged_aml(scope, "\\_SB."GED_DEVICE, HOTPLUG_HANDLER(vms->acpi_dev= ), + irqmap[VIRT_ACPI_GED] + ARM_SPI_BASE, AML_SYSTEM_MEMORY); + + build_memory_hotplug_aml(scope, ms->ram_slots, "\\_SB", NULL, + AML_SYSTEM_MEMORY); + aml_append(dsdt, scope); =20 /* copy AML table into ACPI tables blob and patch header there */ diff --git a/hw/arm/virt.c b/hw/arm/virt.c index da516b3..8179b3e 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -63,6 +63,7 @@ #include "target/arm/internals.h" #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" +#include "hw/acpi/generic_event_device.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -133,6 +134,8 @@ static const MemMapEntry base_memmap[] =3D { [VIRT_GPIO] =3D { 0x09030000, 0x00001000 }, [VIRT_SECURE_UART] =3D { 0x09040000, 0x00001000 }, [VIRT_SMMU] =3D { 0x09050000, 0x00020000 }, + [VIRT_PCDIMM_ACPI] =3D { 0x09070000, MEMORY_HOTPLUG_IO_LEN }, + [VIRT_ACPI_GED] =3D { 0x09080000, ACPI_GED_REG_LEN }, [VIRT_MMIO] =3D { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, @@ -168,6 +171,7 @@ static const int a15irqmap[] =3D { [VIRT_PCIE] =3D 3, /* ... to 6 */ [VIRT_GPIO] =3D 7, [VIRT_SECURE_UART] =3D 8, + [VIRT_ACPI_GED] =3D 9, [VIRT_MMIO] =3D 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] =3D 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] =3D 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */ @@ -183,6 +187,13 @@ static const char *valid_cpus[] =3D { ARM_CPU_TYPE_NAME("max"), }; =20 +static GedEvent ged_events[] =3D { + { + .selector =3D ACPI_GED_IRQ_SEL_MEM, + .event =3D GED_MEMORY_HOTPLUG, + }, +}; + static bool cpu_type_valid(const char *cpu) { int i; @@ -516,6 +527,26 @@ static void fdt_add_pmu_nodes(const VirtMachineState *= vms) } } =20 +static inline DeviceState *create_acpi_ged(VirtMachineState *vms) +{ + DeviceState *dev; + + dev =3D DEVICE(object_new(TYPE_ACPI_GED)); + qdev_prop_set_uint64(dev, "memhp-base", + vms->memmap[VIRT_PCDIMM_ACPI].base); + qdev_prop_set_ptr(dev, "gsi", vms->gsi); + qdev_prop_set_uint64(dev, "ged-base", vms->memmap[VIRT_ACPI_GED].base); + qdev_prop_set_uint32(dev, "ged-irq", vms->irqmap[VIRT_ACPI_GED]); + qdev_prop_set_ptr(dev, "ged-events", ged_events); + qdev_prop_set_uint32(dev, "ged-events-size", ARRAY_SIZE(ged_events)); + + object_property_add_child(qdev_get_machine(), "acpi-ged", + OBJECT(dev), NULL); + qdev_init_nofail(dev); + + return dev; +} + static void create_its(VirtMachineState *vms, DeviceState *gicdev) { const char *itsclass =3D its_class_name(); @@ -555,6 +586,12 @@ static void create_v2m(VirtMachineState *vms, qemu_irq= *pic) fdt_add_v2m_gic_node(vms); } =20 +static void virt_gsi_handler(void *opaque, int n, int level) +{ + qemu_irq *gic_irq =3D opaque; + qemu_set_irq(gic_irq[n], level); +} + static void create_gic(VirtMachineState *vms, qemu_irq *pic) { /* We create a standalone GIC */ @@ -670,6 +707,8 @@ static void create_gic(VirtMachineState *vms, qemu_irq = *pic) pic[i] =3D qdev_get_gpio_in(gicdev, i); } =20 + vms->gsi =3D qemu_allocate_irqs(virt_gsi_handler, pic, NUM_IRQS); + fdt_add_gic_node(vms); =20 if (type =3D=3D 3 && vms->its) { @@ -1418,7 +1457,7 @@ static void machvirt_init(MachineState *machine) VirtMachineClass *vmc =3D VIRT_MACHINE_GET_CLASS(machine); MachineClass *mc =3D MACHINE_GET_CLASS(machine); const CPUArchIdList *possible_cpus; - qemu_irq pic[NUM_IRQS]; + qemu_irq *pic; MemoryRegion *sysmem =3D get_system_memory(); MemoryRegion *secure_sysmem =3D NULL; int n, virt_max_cpus; @@ -1614,6 +1653,7 @@ static void machvirt_init(MachineState *machine) =20 create_flash(vms, sysmem, secure_sysmem ? secure_sysmem : sysmem); =20 + pic =3D g_new0(qemu_irq, NUM_IRQS); create_gic(vms, pic); =20 fdt_add_pmu_nodes(vms); @@ -1644,6 +1684,8 @@ static void machvirt_init(MachineState *machine) =20 create_platform_bus(vms, pic); =20 + vms->acpi_dev =3D create_acpi_ged(vms); + vms->bootinfo.ram_size =3D machine->ram_size; vms->bootinfo.kernel_filename =3D machine->kernel_filename; vms->bootinfo.kernel_cmdline =3D machine->kernel_cmdline; @@ -1811,21 +1853,34 @@ static const CPUArchIdList *virt_possible_cpu_arch_= ids(MachineState *ms) static void virt_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState = *dev, Error **errp) { - if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { - error_setg(errp, "memory cold/hot plug is not yet supported"); + VirtMachineState *vms =3D VIRT_MACHINE(hotplug_dev); + const bool is_nvdimm =3D object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM); + + if (is_nvdimm) { + error_setg(errp, "nvdimm is not yet supported"); return; } =20 + if (!vms->acpi_dev) { + error_setg(errp, "memory hotplug is not enabled: missing acpi devi= ce"); + return; + } + + hotplug_handler_pre_plug(HOTPLUG_HANDLER(vms->acpi_dev), dev, errp); + pc_dimm_pre_plug(PC_DIMM(dev), MACHINE(hotplug_dev), NULL, errp); } =20 static void virt_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + HotplugHandlerClass *hhc; VirtMachineState *vms =3D VIRT_MACHINE(hotplug_dev); =20 pc_dimm_plug(PC_DIMM(dev), MACHINE(vms), NULL); =20 + hhc =3D HOTPLUG_HANDLER_GET_CLASS(vms->acpi_dev); + hhc->plug(HOTPLUG_HANDLER(vms->acpi_dev), dev, NULL); } =20 static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 507517c..9c6b0b1 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -77,6 +77,8 @@ enum { VIRT_GPIO, VIRT_SECURE_UART, VIRT_SECURE_MEM, + VIRT_PCDIMM_ACPI, + VIRT_ACPI_GED, VIRT_LOWMEMMAP_LAST, }; =20 @@ -132,6 +134,8 @@ typedef struct { uint32_t iommu_phandle; int psci_conduit; hwaddr highest_gpa; + DeviceState *acpi_dev; + qemu_irq *gsi; } VirtMachineState; =20 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM) --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554806295345124.38049923657559; Tue, 9 Apr 2019 03:38:15 -0700 (PDT) Received: from localhost ([127.0.0.1]:38832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo8r-0003Ab-Uf for importer@patchew.org; Tue, 09 Apr 2019 06:38:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo26-0006Fx-QS for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo25-0007MC-S3 for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:14 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:44064 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo23-0007KE-Ds; Tue, 09 Apr 2019 06:31:11 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A29B6350D2ABE355EA45; Tue, 9 Apr 2019 18:31:07 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:31:01 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:33 +0100 Message-ID: <20190409102935.28292-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.35 Subject: [Qemu-devel] [PATCH v4 6/8] hw/arm/virt-acpi-build: Add PC-DIMM in SRAT 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Generate Memory Affinity Structures for PC-DIMM ranges. Signed-off-by: Shameer Kolothum Signed-off-by: Eric Auger Reviewed-by: Igor Mammedov --- hw/arm/virt-acpi-build.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 1ad394b..1b9a9b9 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -518,6 +518,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) int i, srat_start; uint64_t mem_base; MachineClass *mc =3D MACHINE_GET_CLASS(vms); + MachineState *ms =3D MACHINE(vms); const CPUArchIdList *cpu_list =3D mc->possible_cpu_arch_ids(MACHINE(vm= s)); =20 srat_start =3D table_data->len; @@ -543,6 +544,14 @@ build_srat(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) } } =20 + if (ms->device_memory) { + numamem =3D acpi_data_push(table_data, sizeof *numamem); + build_srat_memory(numamem, ms->device_memory->base, + memory_region_size(&ms->device_memory->mr), + nb_numa_nodes - 1, + MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED= ); + } + build_header(linker, table_data, (void *)(table_data->data + srat_star= t), "SRAT", table_data->len - srat_start, 3, NULL, NULL); } --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554806159538111.18996818251708; Tue, 9 Apr 2019 03:35:59 -0700 (PDT) Received: from localhost ([127.0.0.1]:38796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo6g-00015G-Hl for importer@patchew.org; Tue, 09 Apr 2019 06:35:58 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo2C-0006Il-09 for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo2A-0007Oh-Sj for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:19 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:2262 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo26-0007Lz-Vz; Tue, 09 Apr 2019 06:31:15 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B321B80BFBB013806270; Tue, 9 Apr 2019 18:31:12 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:31:04 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:34 +0100 Message-ID: <20190409102935.28292-8-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.191 Subject: [Qemu-devel] [PATCH v4 7/8] hw/arm/boot: Add "hotpluggable" property to DT memory node 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently firmware has no way of differentiating the memory nodes and as a result device memory nodes might get exposed to Guest Kernel via UEFI GetMemoryMap() as early boot memory even if Guest boots with ACPI. This will prevent hot-unplug of the device memory. To address this, an additional "hotpluggable" property is introduced here similar to the MEM_AFFINITY_HOTPLUGGABLE flag used in ACPI SRAT table. Firmware can now check for "hotpluggable" property in the memory node and treat them differently. This is in preparation of exposing device memory nodes in DT. Signed-off-by: Shameer Kolothum --- hw/arm/boot.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index a830655..8c840ba 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -425,7 +425,7 @@ static void set_kernel_args_old(const struct arm_boot_i= nfo *info, =20 static int fdt_add_memory_node(void *fdt, uint32_t acells, hwaddr mem_base, uint32_t scells, hwaddr mem_len, - int numa_node_id) + int numa_node_id, bool hotplug) { char *nodename; int ret; @@ -444,6 +444,22 @@ static int fdt_add_memory_node(void *fdt, uint32_t ace= lls, hwaddr mem_base, ret =3D qemu_fdt_setprop_cell(fdt, nodename, "numa-node-id", numa_node_id); } + + /* + * Firmware has no way of differentiating the memory nodes currently + * and in the case of device memory nodes this is a problem if Guest + * boots with ACPI as these nodes might get exposed to Guest Kernel + * via UEFI GetMemoryMap() as early boot memory. This will prevent + * the memory being hot-unpluggable. To address this, an additional + * "hotpluggable" property is introduced here, similar to the + * MEM_AFFINITY_HOTPLUGGABLE flag used in ACPI SRAT table. + * Firmware can now check for "hotpluggable" property in the memory + * node and treat them differently. + */ + + if (hotplug) { + ret =3D qemu_fdt_setprop(fdt, nodename, "hotpluggable", NULL, 0); + } out: g_free(nodename); return ret; @@ -602,7 +618,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, for (i =3D 0; i < nb_numa_nodes; i++) { mem_len =3D numa_info[i].node_mem; rc =3D fdt_add_memory_node(fdt, acells, mem_base, - scells, mem_len, i); + scells, mem_len, i, false); if (rc < 0) { fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n", mem_base); @@ -613,7 +629,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_inf= o *binfo, } } else { rc =3D fdt_add_memory_node(fdt, acells, binfo->loader_start, - scells, binfo->ram_size, -1); + scells, binfo->ram_size, -1, false); if (rc < 0) { fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n", binfo->loader_start); --=20 2.7.4 From nobody Mon May 6 08:59:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1554806418184830.3140028042412; Tue, 9 Apr 2019 03:40:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:38866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDoAp-00050N-9V for importer@patchew.org; Tue, 09 Apr 2019 06:40:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDo2H-0006Nl-W8 for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDo2G-0007S6-Ub for qemu-devel@nongnu.org; Tue, 09 Apr 2019 06:31:25 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60594 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDo2C-0007Ob-Vd; Tue, 09 Apr 2019 06:31:21 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id C68807842779D2009383; Tue, 9 Apr 2019 18:31:17 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 18:31:08 +0800 From: Shameer Kolothum To: , , , Date: Tue, 9 Apr 2019 11:29:35 +0100 Message-ID: <20190409102935.28292-9-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> References: <20190409102935.28292-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.249.212.32 Subject: [Qemu-devel] [PATCH v4 8/8] hw/arm/boot: Expose the PC-DIMM nodes in the DT 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@linaro.org, sameo@linux.intel.com, ard.biesheuvel@linaro.org, linuxarm@huawei.com, xuwei5@hisilicon.com, shannon.zhaosl@gmail.com, sebastien.boeuf@intel.com, lersek@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch adds memory nodes corresponding to PC-DIMM regions. This will enable support for cold plugged device memory for Guests with DT boot. Signed-off-by: Shameer Kolothum Signed-off-by: Eric Auger --- hw/arm/boot.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 8c840ba..150e1ed 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -19,6 +19,7 @@ #include "sysemu/numa.h" #include "hw/boards.h" #include "hw/loader.h" +#include "hw/mem/memory-device.h" #include "elf.h" #include "sysemu/device_tree.h" #include "qemu/config-file.h" @@ -538,6 +539,41 @@ static void fdt_add_psci_node(void *fdt) qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); } =20 +static int fdt_add_hotpluggable_memory_nodes(void *fdt, + uint32_t acells, uint32_t sce= lls) { + MemoryDeviceInfoList *info, *info_list =3D qmp_memory_device_list(); + MemoryDeviceInfo *mi; + int ret =3D 0; + + for (info =3D info_list; info !=3D NULL; info =3D info->next) { + mi =3D info->value; + switch (mi->type) { + case MEMORY_DEVICE_INFO_KIND_DIMM: + { + PCDIMMDeviceInfo *di =3D mi->u.dimm.data; + + ret =3D fdt_add_memory_node(fdt, acells, di->addr, scells, + di->size, di->node, true); + if (ret) { + fprintf(stderr, + "couldn't add PCDIMM /memory@%"PRIx64" node\n", + di->addr); + goto out; + } + break; + } + default: + fprintf(stderr, "%s memory nodes are not yet supported\n", + MemoryDeviceInfoKind_str(mi->type)); + ret =3D -ENOENT; + goto out; + } + } +out: + qapi_free_MemoryDeviceInfoList(info_list); + return ret; +} + int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, hwaddr addr_limit, AddressSpace *as) { @@ -637,6 +673,12 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_in= fo *binfo, } } =20 + rc =3D fdt_add_hotpluggable_memory_nodes(fdt, acells, scells); + if (rc < 0) { + fprintf(stderr, "couldn't add hotpluggable memory nodes\n"); + goto fail; + } + rc =3D fdt_path_offset(fdt, "/chosen"); if (rc < 0) { qemu_fdt_add_subnode(fdt, "/chosen"); --=20 2.7.4