From nobody Sun Nov 9 22:00:36 2025 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 1552046010783311.9326969057263; Fri, 8 Mar 2019 03:53:30 -0800 (PST) Received: from localhost ([127.0.0.1]:41656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2E42-0006Qv-Nk for importer@patchew.org; Fri, 08 Mar 2019 06:53:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2Dvj-0008Ij-Jg for qemu-devel@nongnu.org; Fri, 08 Mar 2019 06:44:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2Dvc-00061E-D1 for qemu-devel@nongnu.org; Fri, 08 Mar 2019 06:44:44 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:43510 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2DvX-0005Qp-Ib; Fri, 08 Mar 2019 06:44:35 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3C91F3B6384287646624; Fri, 8 Mar 2019 19:44:33 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Fri, 8 Mar 2019 19:44:23 +0800 From: Shameer Kolothum To: , , , , , , , Date: Fri, 8 Mar 2019 11:42:13 +0000 Message-ID: <20190308114218.26692-7-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20190308114218.26692-1-shameerali.kolothum.thodi@huawei.com> References: <20190308114218.26692-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 v2 06/11] hw/arm/virt: Add ACPI support for device memory cold-plug 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: linuxarm@huawei.com, xuwei5@hisilicon.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 adds support to build the aml code so that Guest can see the cold-plugged device memory. Signed-off-by: Shameer Kolothum --- default-configs/arm-softmmu.mak | 1 + hw/arm/virt-acpi-build.c | 9 +++++++++ hw/arm/virt-acpi.c | 23 +++++++++++++++++++++++ hw/arm/virt.c | 11 +++++++++++ include/hw/arm/virt.h | 2 ++ 5 files changed, 46 insertions(+) diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index fbc4564..b3bac25 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -167,3 +167,4 @@ CONFIG_HIGHBANK=3Dy CONFIG_MUSICPAL=3Dy CONFIG_MEM_DEVICE=3Dy CONFIG_DIMM=3Dy +CONFIG_ACPI_MEMORY_HOTPLUG=3Dy diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index d7e2e48..87d66da 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -40,6 +40,7 @@ #include "hw/loader.h" #include "hw/hw.h" #include "hw/acpi/aml-build.h" +#include "hw/acpi/memory_hotplug.h" #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" #include "hw/arm/virt.h" @@ -49,6 +50,13 @@ #define ARM_SPI_BASE 32 #define ACPI_POWER_BUTTON_DEVICE "PWRB" =20 +static void acpi_dsdt_add_memory_hotplug(Aml *scope, MachineState *ms) +{ + uint32_t nr_mem =3D ms->ram_slots; + + build_memory_hotplug_aml(scope, nr_mem, "\\_SB", NULL, AML_SYSTEM_MEMO= RY); +} + static void acpi_dsdt_add_cpus(Aml *scope, int smp_cpus) { uint16_t i; @@ -740,6 +748,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) * the RTC ACPI device at all when using UEFI. */ scope =3D aml_scope("\\_SB"); + acpi_dsdt_add_memory_hotplug(scope, MACHINE(vms)); acpi_dsdt_add_cpus(scope, vms->smp_cpus); acpi_dsdt_add_uart(scope, &memmap[VIRT_UART], (irqmap[VIRT_UART] + ARM_SPI_BASE)); diff --git a/hw/arm/virt-acpi.c b/hw/arm/virt-acpi.c index df8a02b..18ebe94 100644 --- a/hw/arm/virt-acpi.c +++ b/hw/arm/virt-acpi.c @@ -26,9 +26,11 @@ #include "hw/arm/virt.h" =20 #include "hw/acpi/acpi.h" +#include "hw/acpi/memory_hotplug.h" =20 typedef struct VirtAcpiState { SysBusDevice parent_obj; + MemHotplugState memhp_state; } VirtAcpiState; =20 #define TYPE_VIRT_ACPI "virt-acpi" @@ -44,6 +46,16 @@ static const VMStateDescription vmstate_acpi =3D { static void virt_device_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + VirtAcpiState *s =3D VIRT_ACPI(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))); + } } =20 static void virt_device_unplug_request_cb(HotplugHandler *hotplug_dev, @@ -62,6 +74,15 @@ static void virt_send_ged(AcpiDeviceIf *adev, AcpiEventS= tatusBits ev) =20 static void virt_device_realize(DeviceState *dev, Error **errp) { + VirtMachineState *vms =3D VIRT_MACHINE(qdev_get_machine()); + const MemMapEntry *memmap =3D vms->memmap; + VirtAcpiState *s =3D VIRT_ACPI(dev); + + if (s->memhp_state.is_enabled) { + acpi_memory_hotplug_init(get_system_memory(), OBJECT(dev), + &s->memhp_state, + memmap[VIRT_PCDIMM_ACPI].base); + } } =20 DeviceState *virt_acpi_init(void) @@ -70,6 +91,8 @@ DeviceState *virt_acpi_init(void) } =20 static Property virt_acpi_properties[] =3D { + DEFINE_PROP_BOOL("memory-hotplug-support", VirtAcpiState, + memhp_state.is_enabled, true), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 40a1273..9427f4f 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -133,6 +133,7 @@ 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, 0x00010000 }, [VIRT_MMIO] =3D { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, @@ -1648,6 +1649,8 @@ static void machvirt_init(MachineState *machine) =20 create_platform_bus(vms, pic); =20 + vms->acpi =3D virt_acpi_init(); + vms->bootinfo.ram_size =3D machine->ram_size; vms->bootinfo.kernel_filename =3D machine->kernel_filename; vms->bootinfo.kernel_cmdline =3D machine->kernel_cmdline; @@ -1832,11 +1835,19 @@ static void virt_memory_pre_plug(HotplugHandler *ho= tplug_dev, DeviceState *dev, static void virt_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { + HotplugHandlerClass *hhc; VirtMachineState *vms =3D VIRT_MACHINE(hotplug_dev); Error *local_err =3D NULL; =20 pc_dimm_plug(PC_DIMM(dev), MACHINE(vms), &local_err); + if (local_err) { + goto out; + } + + hhc =3D HOTPLUG_HANDLER_GET_CLASS(vms->acpi); + hhc->plug(HOTPLUG_HANDLER(vms->acpi), dev, &error_abort); =20 +out: error_propagate(errp, local_err); } =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 6076167..e46a051 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -77,6 +77,7 @@ enum { VIRT_GPIO, VIRT_SECURE_UART, VIRT_SECURE_MEM, + VIRT_PCDIMM_ACPI, VIRT_LOWMEMMAP_LAST, }; =20 @@ -132,6 +133,7 @@ typedef struct { uint32_t iommu_phandle; int psci_conduit; hwaddr highest_gpa; + DeviceState *acpi; } VirtMachineState; =20 #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM) --=20 2.7.4