diff mbox series

[PATCH-for-5.2,3/3] hw/misc/unimp: Display the offset with width of the region size

Message ID 20200807143705.30066-4-f4bug@amsat.org
State New
Headers show
Series hw/misc/unimp: Improve how offset/value are displayed | expand

Commit Message

Philippe Mathieu-Daudé Aug. 7, 2020, 2:37 p.m. UTC
To have a better idea of how big is the region where the offset
belongs, display the value with the width of the region size
(i.e. a region of 0x1000 bytes uses 0x000 format).

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/hw/misc/unimp.h |  1 +
 hw/misc/unimp.c         | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

Comments

Richard Henderson Aug. 12, 2020, 5:34 p.m. UTC | #1
On 8/7/20 7:37 AM, Philippe Mathieu-Daudé wrote:
> +    s->offset_fmt_width = ROUND_UP(64 - clz64(s->size - 1), 4) >> 2;

Better with DIV_ROUND_UP, I think.  Otherwise,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Philippe Mathieu-Daudé Aug. 12, 2020, 6:52 p.m. UTC | #2
On 8/12/20 7:34 PM, Richard Henderson wrote:
> On 8/7/20 7:37 AM, Philippe Mathieu-Daudé wrote:
>> +    s->offset_fmt_width = ROUND_UP(64 - clz64(s->size - 1), 4) >> 2;
> 
> Better with DIV_ROUND_UP, I think.  Otherwise,

Thanks for the tip! (and for reviewing the other series) :)

> 
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> 
> r~
>
diff mbox series

Patch

diff --git a/include/hw/misc/unimp.h b/include/hw/misc/unimp.h
index 4c1d13c9bf..c63968a2cd 100644
--- a/include/hw/misc/unimp.h
+++ b/include/hw/misc/unimp.h
@@ -20,6 +20,7 @@ 
 typedef struct {
     SysBusDevice parent_obj;
     MemoryRegion iomem;
+    unsigned offset_fmt_width;
     char *name;
     uint64_t size;
 } UnimplementedDeviceState;
diff --git a/hw/misc/unimp.c b/hw/misc/unimp.c
index b4b318db1c..7146bfaf77 100644
--- a/hw/misc/unimp.c
+++ b/hw/misc/unimp.c
@@ -23,8 +23,8 @@  static uint64_t unimp_read(void *opaque, hwaddr offset, unsigned size)
     UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque);
 
     qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read  "
-                  "(size %d, offset 0x%" HWADDR_PRIx ")\n",
-                  s->name, size, offset);
+                  "(size %d, offset 0x%0*" HWADDR_PRIx ")\n",
+                  s->name, size, s->offset_fmt_width, offset);
     return 0;
 }
 
@@ -34,9 +34,9 @@  static void unimp_write(void *opaque, hwaddr offset,
     UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque);
 
     qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
-                  "(size %d, offset 0x%" HWADDR_PRIx
+                  "(size %d, offset 0x%0*" HWADDR_PRIx
                   ", value 0x%0*" PRIx64 ")\n",
-                  s->name, size, offset, size << 1, value);
+                  s->name, size, s->offset_fmt_width, offset, size << 1, value);
 }
 
 static const MemoryRegionOps unimp_ops = {
@@ -63,6 +63,8 @@  static void unimp_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    s->offset_fmt_width = ROUND_UP(64 - clz64(s->size - 1), 4) >> 2;
+
     memory_region_init_io(&s->iomem, OBJECT(s), &unimp_ops, s,
                           s->name, s->size);
     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);