hw/pci: Display correct size for unmapped BARs in HMP 'info pci'
PATCH 1/1 hw/pci: Display correct size for unmapped BARs in HMP 'info pci'
When a BAR is not mapped, the displayed size is shifted by 1 byte:
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin A
BAR0: I/O at 0xffffffffffffffff [0x001e].
BAR1: 32 bit memory at 0xffffffffffffffff [0x0000001e]. <===
BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. <===
id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at 0x10000000 [0x11ffffff].
BAR1: 32 bit memory at 0x12050000 [0x12050fff].
BAR6: 32 bit memory at 0xffffffffffffffff [0x0000fffe]. <===
id ""Only substract this byte when the BAR is mapped to display the correct size:
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin A
BAR0: I/O at 0xffffffffffffffff [0x001f].
BAR1: 32 bit memory at 0xffffffffffffffff [0x0000001f]. <===
BAR6: 32 bit memory at 0xffffffffffffffff [0x0003ffff]. <===
id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at 0x10000000 [0x11ffffff].
BAR1: 32 bit memory at 0x12050000 [0x12050fff].
BAR6: 32 bit memory at 0xffffffffffffffff [0x0000ffff]. <===
id ""--- hw/pci/pci-hmp-cmds.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci/pci-hmp-cmds.c +4 -2
@@ -75,22 +75,24 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)for (region = dev->regions; region; region = region->next) {uint64_t addr, size; +bool mapped; addr = region->value->address; size = region->value->size; + mapped = addr !=-1 ;monitor_printf (mon," BAR%" PRId64": " , region->value->bar);if (!strcmp (region->value->type,"io" )) {monitor_printf (mon,"I/O at 0x%04" PRIx64" [0x%04" PRIx64"].\n" , - addr, addr + size -1 ); + addr, addr + size + (mapped ?-1 :0 )); }else {monitor_printf (mon,"%d bit%s memory at 0x%08" PRIx64" [0x%08" PRIx64"].\n" , region->value->mem_type_64 ?64 :32 , region->value->prefetch ?" prefetchable" :"" , - addr, addr + size -1 ); + addr, addr + size + (mapped ?-1 :0 )); } }
Signature · 1 line
2.38.1
Quoted 52 lines · Philippe Mathieu-Daudé
When a BAR is not mapped, the displayed size is shifted by 1 byte:
(qemu) info pci
...
Bus 0, device 11, function 0:Ethernet controller: PCI device 1022:2000 PCI subsystem 0000:0000 IRQ 10, pin A BAR0: I/O at 0xffffffffffffffff [0x001e]. BAR1: 32 bit memory at 0xffffffffffffffff [0x0000001e]. <=== BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. <=== id "" Bus 0, device 18, function 0: VGA controller: PCI device 1013:00b8 PCI subsystem 1af4:1100 BAR0: 32 bit prefetchable memory at 0x10000000 [0x11ffffff]. BAR1: 32 bit memory at 0x12050000 [0x12050fff]. BAR6: 32 bit memory at 0xffffffffffffffff [0x0000fffe]. <=== id ""Only substract this byte when the BAR is mapped to display the correct size:
(qemu) info pci
...
Bus 0, device 11, function 0:Ethernet controller: PCI device 1022:2000 PCI subsystem 0000:0000 IRQ 10, pin A BAR0: I/O at 0xffffffffffffffff [0x001f]. BAR1: 32 bit memory at 0xffffffffffffffff [0x0000001f]. <=== BAR6: 32 bit memory at 0xffffffffffffffff [0x0003ffff]. <=== id "" Bus 0, device 18, function 0: VGA controller: PCI device 1013:00b8 PCI subsystem 1af4:1100 BAR0: 32 bit prefetchable memory at 0x10000000 [0x11ffffff]. BAR1: 32 bit memory at 0x12050000 [0x12050fff]. BAR6: 32 bit memory at 0xffffffffffffffff [0x0000ffff]. <=== id ""Fixes 0ac32c8375 ("PCI interrupt support - 'info pci' monitor command")Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/pci/pci-hmp-cmds.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)hw/pci/pci-hmp-cmds.c +0
-0
hw/pci/pci-hmp-cmds.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 81
Quoted 7 lines
hw/pci/pci-hmp-cmds.c +1
-0@@ -75,22 +75,24 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)for (region = dev->regions; region; region = region->next) {uint64_t addr, size; +bool mapped; addr = region->value->address; size = region->value->size;
As size is not used for anything else, you could adjust the value here once either as
size = region->value->size - (addr != -1 ? 1 : 0);
or in an if then you don't need the bool and tweak the value when printing. This looks simpler to me.
Regards,
BALATON Zoltan
Quoted 20 lines
hw/pci/pci-hmp-cmds.c +3
-2+ mapped = addr !=-1 ;monitor_printf (mon," BAR%" PRId64": " , region->value->bar);if (!strcmp (region->value->type,"io" )) {monitor_printf (mon,"I/O at 0x%04" PRIx64" [0x%04" PRIx64"].\n" , - addr, addr + size -1 ); + addr, addr + size + (mapped ?-1 :0 )); }else {monitor_printf (mon,"%d bit%s memory at 0x%08" PRIx64" [0x%08" PRIx64"].\n" , region->value->mem_type_64 ?64 :32 , region->value->prefetch ?" prefetchable" :"" , - addr, addr + size -1 ); + addr, addr + size + (mapped ?-1 :0 )); } }
Quoted 59 lines · BALATON Zoltan
Quoted 58 lines · Philippe Mathieu-Daudé
When a BAR is not mapped, the displayed size is shifted by 1 byte:
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin A
BAR0: I/O at0xffffffffffffffff[0x001e].
BAR1: 32 bit memory at0xffffffffffffffff[0x0000001e]. <===
BAR6: 32 bit memory at0xffffffffffffffff[0x0003fffe]. <=== id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at0x10000000[0x11ffffff].
BAR1: 32 bit memory at0x12050000[0x12050fff].
BAR6: 32 bit memory at0xffffffffffffffff[0x0000fffe]. <=== id ""Only substract this byte when the BAR is mapped to display the correct size:
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin A
BAR0: I/O at0xffffffffffffffff[0x001f].
BAR1: 32 bit memory at0xffffffffffffffff[0x0000001f]. <===
BAR6: 32 bit memory at0xffffffffffffffff[0x0003ffff]. <=== id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at0x10000000[0x11ffffff].
BAR1: 32 bit memory at0x12050000[0x12050fff].
BAR6: 32 bit memory at0xffffffffffffffff[0x0000ffff]. <=== id ""Fixes 0ac32c8375 ("PCI interrupt support - 'info pci' monitor command")Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/pci/pci-hmp-cmds.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)hw/pci/pci-hmp-cmds.c +1
-0@@ -75,22 +75,24 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) for (region = dev->regions; region; region = region->next) { uint64_t addr, size; + bool mapped;
Quoted 8 lines
hw/pci/pci-hmp-cmds.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 81
Quoted 2 lines
hw/pci/pci-hmp-cmds.c +0
-0addr = region->value->address; size = region->value->size;As size is not used for anything else, you could adjust the value here once either as
size =
region->value->size- (addr != -1 ? 1 : 0);or in an if then you don't need the bool and tweak the value when printing. This looks simpler to me.
Good idea, thanks!
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
When a BAR is not mapped, the displayed size is shifted by 1 byte:
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin A
BAR0: I/O at0xffffffffffffffff[0x001e].
BAR1: 32 bit memory at0xffffffffffffffff[0x0000001e]. <===
BAR6: 32 bit memory at0xffffffffffffffff[0x0003fffe]. <=== id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at0x10000000[0x11ffffff].
BAR1: 32 bit memory at0x12050000[0x12050fff].
BAR6: 32 bit memory at0xffffffffffffffff[0x0000fffe]. <=== id ""Only substract this byte when the BAR is mapped to display the correct size:
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin AQuoted 8 lines
Quoted 8 lines
BAR0: I/O at
0xffffffffffffffff[0x001f].
BAR1: 32 bit memory at0xffffffffffffffff[0x0000001f]. <===
BAR6: 32 bit memory at0xffffffffffffffff[0x0003ffff]. <=== id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at0x10000000[0x11ffffff].
Hmm actually here 0x11ffffff isn't the size but the higher address,
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
BAR1: 32 bit memory at
0x12050000[0x12050fff].
BAR6: 32 bit memory at0xffffffffffffffff[0x0000ffff]. <===
while here this is the size. Confusing. Wouldn't it be simpler to only display the size?
Quoted 29 lines
Quoted 19 lines
Quoted 19 lines
id ""
Fixes 0ac32c8375 ("PCI interrupt support - 'info pci' monitor command")Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/pci/pci-hmp-cmds.c| 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)hw/pci/pci-hmp-cmds.c +1
-0@@ -75,22 +75,24 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) for (region = dev->regions; region; region = region->next) { uint64_t addr, size; + bool mapped;Quoted 8 lines
hw/pci/pci-hmp-cmds.c static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev) · line 81
Quoted 2 lines
hw/pci/pci-hmp-cmds.c +0
-0addr = region->value->address; size = region->value->size;As size is not used for anything else, you could adjust the value here once either as
size =
region->value->size- (addr != -1 ? 1 : 0);or in an if then you don't need the bool and tweak the value when printing. This looks simpler to me.
Good idea, thanks!
Quoted 41 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · BALATON Zoltan
Quoted 23 lines · Philippe Mathieu-Daudé
When a BAR is not mapped, the displayed size is shifted by 1 byte:
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin A
BAR0: I/O at0xffffffffffffffff[0x001e].
BAR1: 32 bit memory at0xffffffffffffffff[0x0000001e]. <===
BAR6: 32 bit memory at0xffffffffffffffff[0x0003fffe]. <=== id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at0x10000000[0x11ffffff].
BAR1: 32 bit memory at0x12050000[0x12050fff].
BAR6: 32 bit memory at0xffffffffffffffff[0x0000fffe]. <=== id ""Only substract this byte when the BAR is mapped to display the correct size:
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
(qemu) info pci
...
Bus 0, device 11, function 0:
Ethernet controller: PCI device 1022:2000
PCI subsystem 0000:0000
IRQ 10, pin AQuoted 8 lines
Quoted 8 lines
BAR0: I/O at
0xffffffffffffffff[0x001f].
BAR1: 32 bit memory at0xffffffffffffffff[0x0000001f]. <===
BAR6: 32 bit memory at0xffffffffffffffff[0x0003ffff]. <=== id ""
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at0x10000000[0x11ffffff].
Quoted 7 lines
Hmm actually here
0x11ffffffisn't the size but the higher address,Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
BAR1: 32 bit memory at
0x12050000[0x12050fff].
BAR6: 32 bit memory at0xffffffffffffffff[0x0000ffff]. <===while here this is the size. Confusing. Wouldn't it be simpler to only display the size?
Or range and size:
Bus 0, device 18, function 0:
VGA controller: PCI device 1013:00b8
PCI subsystem 1af4:1100
BAR0: 32 bit prefetchable memory at 0x10000000-0x12000000
[0x02000000]
BAR1: 32 bit memory at 0x12050000-0x12051000 [0x00001000]
BAR6: 32 bit memory at 0xffffffffffffffff-0xffffffffffffffff [0x00010000]