diff mbox series

[v3,09/22] memory-device: drop get_region_size()

Message ID 20180920103243.28474-10-david@redhat.com (mailing list archive)
State New, archived
Headers show
Series memory-device: complete refactoring + virtio-pmem | expand

Commit Message

David Hildenbrand Sept. 20, 2018, 10:32 a.m. UTC
We now have get_memory_region(), which can be used generically to detect
the region size. Use memory_device_get_region_size() where
get_region_size() was used and use memory_device_get_region_size() as
callback for get_plugged_size() (pc-dimm only for now).

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

Comments

David Gibson Sept. 21, 2018, 5:19 a.m. UTC | #1
On Thu, Sep 20, 2018 at 12:32:30PM +0200, David Hildenbrand wrote:
> We now have get_memory_region(), which can be used generically to detect
> the region size. Use memory_device_get_region_size() where
> get_region_size() was used and use memory_device_get_region_size() as
> callback for get_plugged_size() (pc-dimm only for now).

The commit message reads a little oddly.  I'm guessing it was written
before you split out the introduction of the
memory_device_get_region_size() wrapper into an earlier patch?

> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

Nonetheless,

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


> ---
>  hw/mem/memory-device.c         | 11 +++++++++--
>  hw/mem/pc-dimm.c               | 18 +-----------------
>  include/hw/mem/memory-device.h |  3 ---
>  3 files changed, 10 insertions(+), 22 deletions(-)
> 
> diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
> index 2fa68b3730..1ab28e42cf 100644
> --- a/hw/mem/memory-device.c
> +++ b/hw/mem/memory-device.c
> @@ -270,9 +270,16 @@ void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
>  uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
>                                         Error **errp)
>  {
> -    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
> +    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
> +    MemoryRegion *mr;
>  
> -    return mdc->get_region_size(md, errp);
> +    /* dropping const here is fine as we don't touch the memory region */
> +    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
> +    if (!mr) {
> +        return 0;
> +    }
> +
> +    return memory_region_size(mr);
>  }
>  
>  static const TypeInfo memory_device_info = {
> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index 49ad8bac2d..95c3c4bd76 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -235,21 +235,6 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
>      return dimm->addr;
>  }
>  
> -static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
> -                                           Error **errp)
> -{
> -    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
> -    MemoryRegion *mr;
> -
> -    /* dropping const here is fine as we don't touch the memory region */
> -    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
> -    if (!mr) {
> -        return 0;
> -    }
> -
> -    return memory_region_size(mr);
> -}
> -
>  static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
>                                                    Error **errp)
>  {
> @@ -301,8 +286,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data)
>  
>      mdc->get_addr = pc_dimm_md_get_addr;
>      /* for a dimm plugged_size == region_size */
> -    mdc->get_plugged_size = pc_dimm_md_get_region_size;
> -    mdc->get_region_size = pc_dimm_md_get_region_size;
> +    mdc->get_plugged_size = memory_device_get_region_size;
>      mdc->get_memory_region = pc_dimm_md_get_memory_region;
>      mdc->fill_device_info = pc_dimm_md_fill_device_info;
>  }
> diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
> index 0feed4ec0d..64df232919 100644
> --- a/include/hw/mem/memory-device.h
> +++ b/include/hw/mem/memory-device.h
> @@ -36,8 +36,6 @@ typedef struct MemoryDeviceState {
>   * assigned yet.
>   * @get_plugged_size: The amount of memory provided by this @md currently
>   * usable ("plugged") by the guest.
> - * @get_region_size: The size of the memory region of the @md that's mapped
> - * in guest physical memory at @get_addr.
>   * @get_memory_region: The memory region of the @md of the @md that's
>   * mapped in guest physical memory at @get_addr. If a @md is ever composed
>   * of multiple successive memory regions, a covering memory region is to
> @@ -51,7 +49,6 @@ typedef struct MemoryDeviceClass {
>      /* public */
>      uint64_t (*get_addr)(const MemoryDeviceState *md);
>      uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
> -    uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
>      MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
>      void (*fill_device_info)(const MemoryDeviceState *md,
>                               MemoryDeviceInfo *info);
David Hildenbrand Sept. 21, 2018, 7:19 a.m. UTC | #2
On 21/09/2018 07:19, David Gibson wrote:
> On Thu, Sep 20, 2018 at 12:32:30PM +0200, David Hildenbrand wrote:
>> We now have get_memory_region(), which can be used generically to detect
>> the region size. Use memory_device_get_region_size() where
>> get_region_size() was used and use memory_device_get_region_size() as
>> callback for get_plugged_size() (pc-dimm only for now).
> 
> The commit message reads a little oddly.  I'm guessing it was written
> before you split out the introduction of the
> memory_device_get_region_size() wrapper into an earlier patch?

Guess I changed it a couple of times while figuring out a way to do the
transformations as cleanly as possible.

"There are no remaining users of get_region_size() except
memory_device_get_region_size() itself. We can make
memory_device_get_region_size() work directly on get_memory_region()
instead and drop get_region_size().

In addition, we can now use memory_device_get_region_size() in pc-dimm
code to implement get_plugged_size()".

Thanks!

> 
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> Nonetheless,
> 
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
>
Igor Mammedov Sept. 24, 2018, 1:27 p.m. UTC | #3
On Fri, 21 Sep 2018 09:19:17 +0200
David Hildenbrand <david@redhat.com> wrote:

> On 21/09/2018 07:19, David Gibson wrote:
> > On Thu, Sep 20, 2018 at 12:32:30PM +0200, David Hildenbrand wrote:  
> >> We now have get_memory_region(), which can be used generically to detect
> >> the region size. Use memory_device_get_region_size() where
> >> get_region_size() was used and use memory_device_get_region_size() as
> >> callback for get_plugged_size() (pc-dimm only for now).  
> > 
> > The commit message reads a little oddly.  I'm guessing it was written
> > before you split out the introduction of the
> > memory_device_get_region_size() wrapper into an earlier patch?  
> 
> Guess I changed it a couple of times while figuring out a way to do the
> transformations as cleanly as possible.
> 
> "There are no remaining users of get_region_size() except
> memory_device_get_region_size() itself. We can make
> memory_device_get_region_size() work directly on get_memory_region()
> instead and drop get_region_size().
> 
> In addition, we can now use memory_device_get_region_size() in pc-dimm
> code to implement get_plugged_size()".
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> 
> Thanks!
> 
> >   
> >>
> >> Signed-off-by: David Hildenbrand <david@redhat.com>  
> > 
> > Nonetheless,
> > 
> > Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> >   
> 
>
diff mbox series

Patch

diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c
index 2fa68b3730..1ab28e42cf 100644
--- a/hw/mem/memory-device.c
+++ b/hw/mem/memory-device.c
@@ -270,9 +270,16 @@  void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr)
 uint64_t memory_device_get_region_size(const MemoryDeviceState *md,
                                        Error **errp)
 {
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
+    MemoryRegion *mr;
 
-    return mdc->get_region_size(md, errp);
+    /* dropping const here is fine as we don't touch the memory region */
+    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
+    if (!mr) {
+        return 0;
+    }
+
+    return memory_region_size(mr);
 }
 
 static const TypeInfo memory_device_info = {
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 49ad8bac2d..95c3c4bd76 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -235,21 +235,6 @@  static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
     return dimm->addr;
 }
 
-static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md,
-                                           Error **errp)
-{
-    MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md);
-    MemoryRegion *mr;
-
-    /* dropping const here is fine as we don't touch the memory region */
-    mr = mdc->get_memory_region((MemoryDeviceState *)md, errp);
-    if (!mr) {
-        return 0;
-    }
-
-    return memory_region_size(mr);
-}
-
 static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
                                                   Error **errp)
 {
@@ -301,8 +286,7 @@  static void pc_dimm_class_init(ObjectClass *oc, void *data)
 
     mdc->get_addr = pc_dimm_md_get_addr;
     /* for a dimm plugged_size == region_size */
-    mdc->get_plugged_size = pc_dimm_md_get_region_size;
-    mdc->get_region_size = pc_dimm_md_get_region_size;
+    mdc->get_plugged_size = memory_device_get_region_size;
     mdc->get_memory_region = pc_dimm_md_get_memory_region;
     mdc->fill_device_info = pc_dimm_md_fill_device_info;
 }
diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h
index 0feed4ec0d..64df232919 100644
--- a/include/hw/mem/memory-device.h
+++ b/include/hw/mem/memory-device.h
@@ -36,8 +36,6 @@  typedef struct MemoryDeviceState {
  * assigned yet.
  * @get_plugged_size: The amount of memory provided by this @md currently
  * usable ("plugged") by the guest.
- * @get_region_size: The size of the memory region of the @md that's mapped
- * in guest physical memory at @get_addr.
  * @get_memory_region: The memory region of the @md of the @md that's
  * mapped in guest physical memory at @get_addr. If a @md is ever composed
  * of multiple successive memory regions, a covering memory region is to
@@ -51,7 +49,6 @@  typedef struct MemoryDeviceClass {
     /* public */
     uint64_t (*get_addr)(const MemoryDeviceState *md);
     uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp);
-    uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp);
     MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp);
     void (*fill_device_info)(const MemoryDeviceState *md,
                              MemoryDeviceInfo *info);