From nobody Mon Feb 9 20:30:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524227842370341.904566754199; Fri, 20 Apr 2018 05:37:22 -0700 (PDT) Received: from localhost ([::1]:53814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9VHy-0000VF-H5 for importer@patchew.org; Fri, 20 Apr 2018 08:37:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9VFv-0007YB-Ra for qemu-devel@nongnu.org; Fri, 20 Apr 2018 08:35:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9VFs-0000Xy-VL for qemu-devel@nongnu.org; Fri, 20 Apr 2018 08:35:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49782 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 1f9VFs-0000Xn-PV; Fri, 20 Apr 2018 08:35:08 -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 5557E81A88A3; Fri, 20 Apr 2018 12:35:08 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-142.ams2.redhat.com [10.36.116.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id 560B5215CDA7; Fri, 20 Apr 2018 12:35:06 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Fri, 20 Apr 2018 14:34:55 +0200 Message-Id: <20180420123456.22196-3-david@redhat.com> In-Reply-To: <20180420123456.22196-1-david@redhat.com> References: <20180420123456.22196-1-david@redhat.com> 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.8]); Fri, 20 Apr 2018 12:35:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 20 Apr 2018 12:35:08 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@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 v3 2/3] machine: make MemoryHotplugState accessible via the machine 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: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , David Hildenbrand , Markus Armbruster , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Paolo Bonzini , Marcel Apfelbaum , Igor Mammedov , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's allow to query the MemoryHotplugState from the machine. This allows us to generically detect if a certain machine has support for memory devices, and to generically manage it (find free address range, plug/unplug a memory region). Signed-off-by: David Hildenbrand --- hw/i386/pc.c | 12 ++++++++++++ hw/ppc/spapr.c | 12 ++++++++++++ include/hw/boards.h | 16 ++++++++++++++++ include/hw/mem/pc-dimm.h | 12 +----------- 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index d36bac8c89..fa8862af33 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -2337,6 +2337,17 @@ static void x86_nmi(NMIState *n, int cpu_index, Erro= r **errp) } } =20 +static MemoryHotplugState *pc_machine_get_memory_hotplug_state(MachineStat= e *ms) +{ + PCMachineState *pcms =3D PC_MACHINE(ms); + + if (!pcms->hotplug_memory.base) { + /* hotplug not supported */ + return NULL; + } + return &pcms->hotplug_memory; +} + static void pc_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -2376,6 +2387,7 @@ static void pc_machine_class_init(ObjectClass *oc, vo= id *data) hc->unplug =3D pc_machine_device_unplug_cb; nc->nmi_monitor_handler =3D x86_nmi; mc->default_cpu_type =3D TARGET_DEFAULT_CPU_TYPE; + mc->get_memory_hotplug_state =3D pc_machine_get_memory_hotplug_state; =20 object_class_property_add(oc, PC_MACHINE_MEMHP_REGION_SIZE, "int", pc_machine_get_hotplug_memory_region_size, NULL, diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index a7428f7da7..7ccdb705b3 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3868,6 +3868,17 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id) return NULL; } =20 +static MemoryHotplugState *spapr_get_memory_hotplug_state(MachineState *ms) +{ + sPAPRMachineState *spapr =3D SPAPR_MACHINE(ms); + + if (!spapr->hotplug_memory.base) { + /* hotplug not supported */ + return NULL; + } + return &spapr->hotplug_memory; +} + static void spapr_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); @@ -3927,6 +3938,7 @@ static void spapr_machine_class_init(ObjectClass *oc,= void *data) * in which LMBs are represented and hot-added */ mc->numa_mem_align_shift =3D 28; + mc->get_memory_hotplug_state =3D spapr_get_memory_hotplug_state; =20 smc->default_caps.caps[SPAPR_CAP_HTM] =3D SPAPR_CAP_OFF; smc->default_caps.caps[SPAPR_CAP_VSX] =3D SPAPR_CAP_ON; diff --git a/include/hw/boards.h b/include/hw/boards.h index a609239112..447bdc7219 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -105,6 +105,17 @@ typedef struct { CPUArchId cpus[0]; } CPUArchIdList; =20 +/** + * MemoryHotplugState: + * @base: address in guest physical address space where hotplug memory + * address space begins. + * @mr: hotplug memory address space container + */ +typedef struct MemoryHotplugState { + hwaddr base; + MemoryRegion mr; +} MemoryHotplugState; + /** * MachineClass: * @max_cpus: maximum number of CPUs supported. Default: 1 @@ -156,6 +167,10 @@ typedef struct { * should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. + * @get_memory_hotplug_state: + * If a machine support memory hotplug, the returned data ontains + * information about the portion of guest physical address space + * where memory devices can be mapped to (e.g. to hotplug a pc-dimm). */ struct MachineClass { /*< private >*/ @@ -212,6 +227,7 @@ struct MachineClass { unsigned cpu_inde= x); const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine); int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx); + MemoryHotplugState *(*get_memory_hotplug_state)(MachineState *ms); }; =20 /** diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index e88073321f..8bda37adab 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -19,6 +19,7 @@ #include "exec/memory.h" #include "sysemu/hostmem.h" #include "hw/qdev.h" +#include "hw/boards.h" =20 #define TYPE_PC_DIMM "pc-dimm" #define PC_DIMM(obj) \ @@ -75,17 +76,6 @@ typedef struct PCDIMMDeviceClass { MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm); } PCDIMMDeviceClass; =20 -/** - * MemoryHotplugState: - * @base: address in guest physical address space where hotplug memory - * address space begins. - * @mr: hotplug memory address space container - */ -typedef struct MemoryHotplugState { - hwaddr base; - MemoryRegion mr; -} MemoryHotplugState; - uint64_t pc_dimm_get_free_addr(uint64_t address_space_start, uint64_t address_space_size, uint64_t *hint, uint64_t align, uint64_t si= ze, --=20 2.14.3