From nobody Thu Nov 6 10:20:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540476079354820.1770395605088; Thu, 25 Oct 2018 07:01:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9280FADAEF; Thu, 25 Oct 2018 14:01:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51EDE5D780; Thu, 25 Oct 2018 14:01:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DE33C4BB79; Thu, 25 Oct 2018 14:01:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9PDauog007843 for ; Thu, 25 Oct 2018 09:36:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2857A27C3A; Thu, 25 Oct 2018 13:36:56 +0000 (UTC) Received: from localhost (unknown [10.33.36.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8462E4F7D; Thu, 25 Oct 2018 13:36:33 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org Date: Thu, 25 Oct 2018 10:32:43 -0300 Message-Id: <20181025133301.16578-26-ehabkost@redhat.com> In-Reply-To: <20181025133301.16578-1-ehabkost@redhat.com> References: <20181025133301.16578-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: "Michael S. Tsirkin" , libvir-list@redhat.com, Jason Wang , Mark Cave-Ayland , Max Filippov , "Edgar E. Iglesias" , Rob Herring , David Hildenbrand , Alexander Graf , Marcel Apfelbaum , Richard Henderson , Artyom Tarasenko , Laurent Vivier , Thomas Huth , Eduardo Habkost , Alistair Francis , qemu-arm@nongnu.org, Paolo Bonzini , David Gibson , Xiao Guangrong , Peter Crosthwaite , Michael Walle , qemu-ppc@nongnu.org, Aleksandar Markovic , Igor Mammedov , Aurelien Jarno Subject: [libvirt] [PULL v2 25/43] memory-device: add and use memory_device_get_region_size() X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 25 Oct 2018 14:01:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand We will factor out get_memory_region() from pc-dimm to memory device code soon. Once that is done, get_region_size() can be implemented generically and essentially be replaced by memory_device_get_region_size (and work only on get_memory_region()). We have some users of get_memory_region() (spapr and pc-dimm code) that are only interested in the size. So let's rework them to use memory_device_get_region_size() first, then we can factor out get_memory_region() and eventually remove get_region_size() without touching the same code multiple times. Reviewed-by: David Gibson Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20181005092024.14344-10-david@redhat.com> Signed-off-by: Eduardo Habkost --- include/hw/mem/memory-device.h | 2 ++ hw/mem/memory-device.c | 13 ++++++++++--- hw/mem/pc-dimm.c | 10 ++++------ hw/ppc/spapr.c | 21 +++++++-------------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 0474a3dd11..898df3057d 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -83,5 +83,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, co= nst uint64_t *hint, void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); +uint64_t memory_device_get_region_size(const MemoryDeviceState *md, + Error **errp); =20 #endif diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index c1e1b81cf2..425830c65c 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -57,10 +57,9 @@ static int memory_device_used_region_size(Object *obj, v= oid *opaque) if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { const DeviceState *dev =3D DEVICE(obj); const MemoryDeviceState *md =3D MEMORY_DEVICE(obj); - const MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(obj); =20 if (dev->realized) { - *size +=3D mdc->get_region_size(md, &error_abort); + *size +=3D memory_device_get_region_size(md, &error_abort); } } =20 @@ -167,7 +166,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, = const uint64_t *hint, uint64_t md_size, md_addr; =20 md_addr =3D mdc->get_addr(md); - md_size =3D mdc->get_region_size(md, &error_abort); + md_size =3D memory_device_get_region_size(md, &error_abort); =20 if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { @@ -266,6 +265,14 @@ void memory_device_unplug_region(MachineState *ms, Mem= oryRegion *mr) memory_region_del_subregion(&ms->device_memory->mr, mr); } =20 +uint64_t memory_device_get_region_size(const MemoryDeviceState *md, + Error **errp) +{ + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_GET_CLASS(md); + + return mdc->get_region_size(md, errp); +} + static const TypeInfo memory_device_info =3D { .name =3D TYPE_MEMORY_DEVICE, .parent =3D TYPE_INTERFACE, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 130f78d0de..3e43ec8742 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -161,16 +161,14 @@ static Property pc_dimm_properties[] =3D { static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + Error *local_err =3D NULL; uint64_t value; - MemoryRegion *mr; - PCDIMMDevice *dimm =3D PC_DIMM(obj); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(obj); =20 - mr =3D ddc->get_memory_region(dimm, errp); - if (!mr) { + value =3D memory_device_get_region_size(MEMORY_DEVICE(obj), &local_err= ); + if (local_err) { + error_propagate(errp, local_err); return; } - value =3D memory_region_size(mr); =20 visit_type_uint64(v, name, &value, errp); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index c078347b66..c08130facb 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3128,12 +3128,10 @@ static void spapr_memory_plug(HotplugHandler *hotpl= ug_dev, DeviceState *dev, Error *local_err =3D NULL; sPAPRMachineState *ms =3D SPAPR_MACHINE(hotplug_dev); PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); uint64_t size, addr; uint32_t node; =20 - size =3D memory_region_size(mr); + size =3D memory_device_get_region_size(MEMORY_DEVICE(dev), &error_abor= t); =20 pc_dimm_plug(dimm, MACHINE(ms), &local_err); if (local_err) { @@ -3169,9 +3167,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hot= plug_dev, DeviceState *dev, const sPAPRMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(hotplug_dev); sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); Error *local_err =3D NULL; - MemoryRegion *mr; uint64_t size; Object *memdev; hwaddr pagesize; @@ -3181,11 +3177,11 @@ static void spapr_memory_pre_plug(HotplugHandler *h= otplug_dev, DeviceState *dev, return; } =20 - mr =3D ddc->get_memory_region(dimm, errp); - if (!mr) { + size =3D memory_device_get_region_size(MEMORY_DEVICE(dimm), &local_err= ); + if (local_err) { + error_propagate(errp, local_err); return; } - size =3D memory_region_size(mr); =20 if (size % SPAPR_MEMORY_BLOCK_SIZE) { error_setg(errp, "Hotplugged memory size must be a multiple of " @@ -3257,9 +3253,8 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_sta= te(sPAPRMachineState *ms, PCDIMMDevice *dimm) { sPAPRDRConnector *drc; - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); - uint64_t size =3D memory_region_size(mr); + uint64_t size =3D memory_device_get_region_size(MEMORY_DEVICE(dimm), + &error_abort); uint32_t nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; uint32_t avail_lmbs =3D 0; uint64_t addr_start, addr; @@ -3325,14 +3320,12 @@ static void spapr_memory_unplug_request(HotplugHand= ler *hotplug_dev, sPAPRMachineState *spapr =3D SPAPR_MACHINE(hotplug_dev); Error *local_err =3D NULL; PCDIMMDevice *dimm =3D PC_DIMM(dev); - PCDIMMDeviceClass *ddc =3D PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr =3D ddc->get_memory_region(dimm, &error_abort); uint32_t nr_lmbs; uint64_t size, addr_start, addr; int i; sPAPRDRConnector *drc; =20 - size =3D memory_region_size(mr); + size =3D memory_device_get_region_size(MEMORY_DEVICE(dimm), &error_abo= rt); nr_lmbs =3D size / SPAPR_MEMORY_BLOCK_SIZE; =20 addr_start =3D object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PRO= P, --=20 2.18.0.rc1.1.g3f1ff2140 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list