diff mbox series

[v3,12/22] memory-device: complete factoring out plug handling

Message ID 20180920103243.28474-13-david@redhat.com
State New
Headers show
Series memory-device: complete refactoring + virtio-pmem | expand

Commit Message

David Hildenbrand Sept. 20, 2018, 10:32 a.m. UTC
With the new memory device functions in place, we can factor out
plugging of memory devices completely.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/mem/memory-device.c         | 10 +++++++---
 hw/mem/pc-dimm.c               |  8 +-------
 include/hw/mem/memory-device.h |  3 +--
 3 files changed, 9 insertions(+), 12 deletions(-)

Comments

David Gibson Sept. 21, 2018, 7 a.m. UTC | #1
On Thu, Sep 20, 2018 at 12:32:33PM +0200, David Hildenbrand wrote:
> With the new memory device functions in place, we can factor out
> plugging of memory devices completely.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  hw/mem/memory-device.c         | 10 +++++++---
>  hw/mem/pc-dimm.c               |  8 +-------
>  include/hw/mem/memory-device.h |  3 +--
>  3 files changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
> index ec20c8a2bc..34e92148ec 100644
> --- a/hw/mem/memory-device.c
> +++ b/hw/mem/memory-device.c
> @@ -275,10 +275,14 @@ out:
>      error_propagate(errp, local_err);
>  }
>  
> -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
> -                               uint64_t addr)
> +void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
>  {
> -    /* we expect a previous call to memory_device_get_free_addr() */
> +    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
> +    const uint64_t addr = mdc->get_addr(md);
> +    MemoryRegion *mr;
> +
> +    /* we expect a previous call to memory_device_pre_plug() */
> +    mr = mdc->get_memory_region(md, &error_abort);
>      g_assert(ms->device_memory);
>  
>      memory_region_add_subregion(&ms->device_memory->mr,
> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index 39dbb69f61..db8f71c672 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -63,16 +63,10 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
>  {
>      PCDIMMDevice *dimm = PC_DIMM(dev);
>      PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
> -    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev);
>      MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
>                                                                &error_abort);
> -    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort);
> -    uint64_t addr;
> -
> -    addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
> -                                    &error_abort);
>  
> -    memory_device_plug_region(machine, mr, addr);
> +    memory_device_plug(MEMORY_DEVICE(dev), machine);
>      vmstate_register_ram(vmstate_mr, dev);
>  }
>  
> diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
> index 2bb8c604b4..5ba36f98fb 100644
> --- a/include/hw/mem/memory-device.h
> +++ b/include/hw/mem/memory-device.h
> @@ -60,8 +60,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void);
>  uint64_t get_plugged_memory_size(void);
>  void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
>                              const uint64_t *legacy_align, Error **errp);
> -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
> -                               uint64_t addr);
> +void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
>  void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
>  uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
>                                         Error **errp);
Igor Mammedov Sept. 24, 2018, 1:49 p.m. UTC | #2
On Thu, 20 Sep 2018 12:32:33 +0200
David Hildenbrand <david@redhat.com> wrote:

> With the new memory device functions in place, we can factor out
> plugging of memory devices completely.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  hw/mem/memory-device.c         | 10 +++++++---
>  hw/mem/pc-dimm.c               |  8 +-------
>  include/hw/mem/memory-device.h |  3 +--
>  3 files changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
> index ec20c8a2bc..34e92148ec 100644
> --- a/hw/mem/memory-device.c
> +++ b/hw/mem/memory-device.c
> @@ -275,10 +275,14 @@ out:
>      error_propagate(errp, local_err);
>  }
>  
> -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
> -                               uint64_t addr)
> +void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
>  {
> -    /* we expect a previous call to memory_device_get_free_addr() */
> +    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
> +    const uint64_t addr = mdc->get_addr(md);
> +    MemoryRegion *mr;
> +
> +    /* we expect a previous call to memory_device_pre_plug() */
... 'succeed and can't fail at this point */

> +    mr = mdc->get_memory_region(md, &error_abort);
>      g_assert(ms->device_memory);
>  
>      memory_region_add_subregion(&ms->device_memory->mr,
> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index 39dbb69f61..db8f71c672 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -63,16 +63,10 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
>  {
>      PCDIMMDevice *dimm = PC_DIMM(dev);
>      PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
> -    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev);
>      MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
>                                                                &error_abort);
> -    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort);
> -    uint64_t addr;
> -
> -    addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
> -                                    &error_abort);
>  
> -    memory_device_plug_region(machine, mr, addr);
> +    memory_device_plug(MEMORY_DEVICE(dev), machine);
>      vmstate_register_ram(vmstate_mr, dev);
>  }
>  
> diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
> index 2bb8c604b4..5ba36f98fb 100644
> --- a/include/hw/mem/memory-device.h
> +++ b/include/hw/mem/memory-device.h
> @@ -60,8 +60,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void);
>  uint64_t get_plugged_memory_size(void);
>  void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
>                              const uint64_t *legacy_align, Error **errp);
> -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
> -                               uint64_t addr);
> +void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
>  void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
>  uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
>                                         Error **errp);
Otherwise looks good

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
diff mbox series

Patch

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index ec20c8a2bc..34e92148ec 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -275,10 +275,14 @@  out:
     error_propagate(errp, local_err);
 }
 
-void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
-                               uint64_t addr)
+void memory_device_plug(MemoryDeviceState *md, MachineState *ms)
 {
-    /* we expect a previous call to memory_device_get_free_addr() */
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    const uint64_t addr = mdc->get_addr(md);
+    MemoryRegion *mr;
+
+    /* we expect a previous call to memory_device_pre_plug() */
+    mr = mdc->get_memory_region(md, &error_abort);
     g_assert(ms->device_memory);
 
     memory_region_add_subregion(&ms->device_memory->mr,
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 39dbb69f61..db8f71c672 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -63,16 +63,10 @@  void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp)
 {
     PCDIMMDevice *dimm = PC_DIMM(dev);
     PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev);
     MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm,
                                                               &error_abort);
-    MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort);
-    uint64_t addr;
-
-    addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP,
-                                    &error_abort);
 
-    memory_device_plug_region(machine, mr, addr);
+    memory_device_plug(MEMORY_DEVICE(dev), machine);
     vmstate_register_ram(vmstate_mr, dev);
 }
 
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 2bb8c604b4..5ba36f98fb 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -60,8 +60,7 @@  MemoryDeviceInfoList *qmp_memory_device_list(void);
 uint64_t get_plugged_memory_size(void);
 void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms,
                             const uint64_t *legacy_align, Error **errp);
-void memory_device_plug_region(MachineState *ms, MemoryRegion *mr,
-                               uint64_t addr);
+void memory_device_plug(MemoryDeviceState *md, MachineState *ms);
 void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr);
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
                                        Error **errp);