Skip to contentSkip to conversation

hw/misc/unimp: Improve how offset/value are displayed

PATCH Superseded Philippe Mathieu-Daudé 2 participants 8 messages Aug 7, 2020 – Aug 12, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hw/misc/unimp: Improve how offset/value are displayed

This series aims to ease looking at the '-d unimp' output reported by the UnimplementedDevice.

- read/write accesses are now aligned
- the value format width uses the access size
- the offset (address) uses the size of the memory region it belongs

Philippe Mathieu-Daudé (3):
hw/misc/unimp: Display value after offset hw/misc/unimp: Display the value with width of the access size hw/misc/unimp: Display the offset with width of the region size

 include/hw/misc/unimp.h |  1 +
 hw/misc/unimp.c         | 14 ++++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/3 hw/misc/unimp: Display value after offset

To better align the read/write accesses, display the value after the offset (read accesses only display the offset).

---
 hw/misc/unimp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/misc/unimp.c +4 -4
index bc4084d344..ee2e536c8b 100644
@@ -22,7 +22,7 @@ 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 "
+    qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read  "
                   "(size %d, offset 0x%" HWADDR_PRIx ")\n",
                   s->name, size, 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, value 0x%" PRIx64
-                  ", offset 0x%" HWADDR_PRIx ")\n",
-                  s->name, size, value, offset);
+                  "(size %d, offset 0x%" HWADDR_PRIx
+                  ", value 0x%" PRIx64 ")\n",
+                  s->name, size, offset, value);
 }
 
 static const MemoryRegionOps unimp_ops = {
Signature · 1 line
2.21.3
#3 lore raw

PATCH 2/3 hw/misc/unimp: Display the value with width of the access size

In reply to Philippe Mathieu-Daudé

To quickly notice the access size, display the value with the width of the access (i.e. 16-bit access is displayed 0x0000, while 8-bit access 0x00).

---
 hw/misc/unimp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/misc/unimp.c +2 -2
index ee2e536c8b..b4b318db1c 100644
@@ -35,8 +35,8 @@ static void unimp_write(void *opaque, hwaddr offset,
 
     qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
                   "(size %d, offset 0x%" HWADDR_PRIx
-                  ", value 0x%" PRIx64 ")\n",
-                  s->name, size, offset, value);
+                  ", value 0x%0*" PRIx64 ")\n",
+                  s->name, size, offset, size << 1, value);
 }
 
 static const MemoryRegionOps unimp_ops = {
Signature · 1 line
2.21.3
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH-for-5.2 2/3] hw/misc/unimp: Display the value with width of the access size

Quoted 8 lines · Philippe Mathieu-Daudé

To quickly notice the access size, display the value with the width of the access (i.e. 16-bit access is displayed 0x0000, while 8-bit access 0x00).

---
 hw/misc/unimp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

r~

#5 lore raw

PATCH 3/3 hw/misc/unimp: Display the offset with width of the region size

In reply to Philippe Mathieu-Daudé

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).

---
 include/hw/misc/unimp.h |  1 +
 hw/misc/unimp.c         | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
include/hw/misc/unimp.h +1 -0
index 4c1d13c9bf..c63968a2cd 100644
@@ -20,6 +20,7 @@
 typedef struct {
     SysBusDevice parent_obj;
     MemoryRegion iomem;
+    unsigned offset_fmt_width;
     char *name;
     uint64_t size;
 } UnimplementedDeviceState;
hw/misc/unimp.c +6 -4
index b4b318db1c..7146bfaf77 100644
@@ -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);
Signature · 1 line
2.21.3
Reviewed-by on v1 3/3
#6 lore raw

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

Quoted 1 line · Philippe Mathieu-Daudé

+ s->offset_fmt_width = ROUND_UP(64 - clz64(s->size - 1), 4) >> 2;

Better with DIV_ROUND_UP, I think. Otherwise,

r~

#7 lore raw

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

Quoted 4 lines · Richard Henderson
Quoted 1 line · Philippe Mathieu-Daudé

+ 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) :)

Quoted 6 lines

r~