From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Luiz Capitulino <lcapitulino@redhat.com>,
Fam Zheng <famz@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
wenchaoqemu@gmail.com
Subject: [Qemu-devel] [PATCH v4 18/19] qapi: Drop inline subtype in query-pci
Date: Fri, 19 Sep 2014 16:25:03 -0600 [thread overview]
Message-ID: <1411165504-18198-19-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1411165504-18198-1-git-send-email-eblake@redhat.com>
A future patch will be using a 'name':{dictionary} entry in the
QAPI schema to specify a default value for an optional argument;
but existing use of inline substructs conflicts with that goal.
This patch fixes one of only two commands relying on nested
subtypes, by breaking the nesting into an explicit type. The
QMP wire format is unaffected by this change.
Prefer the safer g_new0() while making the conversion, and reduce
some long lines.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
hmp.c | 26 ++++++++--------
hw/pci/pci.c | 42 ++++++++++++++------------
qapi-schema.json | 90 ++++++++++++++++++++++++++++++++++++++------------------
3 files changed, 98 insertions(+), 60 deletions(-)
diff --git a/hmp.c b/hmp.c
index 23fc3da..3d0c23f 100644
--- a/hmp.c
+++ b/hmp.c
@@ -553,14 +553,14 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
dev->slot, dev->function);
monitor_printf(mon, " ");
- if (dev->class_info.has_desc) {
- monitor_printf(mon, "%s", dev->class_info.desc);
+ if (dev->class_info->has_desc) {
+ monitor_printf(mon, "%s", dev->class_info->desc);
} else {
- monitor_printf(mon, "Class %04" PRId64, dev->class_info.q_class);
+ monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
}
monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
- dev->id.vendor, dev->id.device);
+ dev->id->vendor, dev->id->device);
if (dev->has_irq) {
monitor_printf(mon, " IRQ %" PRId64 ".\n", dev->irq);
@@ -568,25 +568,25 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
if (dev->has_pci_bridge) {
monitor_printf(mon, " BUS %" PRId64 ".\n",
- dev->pci_bridge->bus.number);
+ dev->pci_bridge->bus->number);
monitor_printf(mon, " secondary bus %" PRId64 ".\n",
- dev->pci_bridge->bus.secondary);
+ dev->pci_bridge->bus->secondary);
monitor_printf(mon, " subordinate bus %" PRId64 ".\n",
- dev->pci_bridge->bus.subordinate);
+ dev->pci_bridge->bus->subordinate);
monitor_printf(mon, " IO range [0x%04"PRIx64", 0x%04"PRIx64"]\n",
- dev->pci_bridge->bus.io_range->base,
- dev->pci_bridge->bus.io_range->limit);
+ dev->pci_bridge->bus->io_range->base,
+ dev->pci_bridge->bus->io_range->limit);
monitor_printf(mon,
" memory range [0x%08"PRIx64", 0x%08"PRIx64"]\n",
- dev->pci_bridge->bus.memory_range->base,
- dev->pci_bridge->bus.memory_range->limit);
+ dev->pci_bridge->bus->memory_range->base,
+ dev->pci_bridge->bus->memory_range->limit);
monitor_printf(mon, " prefetchable memory range "
"[0x%08"PRIx64", 0x%08"PRIx64"]\n",
- dev->pci_bridge->bus.prefetchable_range->base,
- dev->pci_bridge->bus.prefetchable_range->limit);
+ dev->pci_bridge->bus->prefetchable_range->base,
+ dev->pci_bridge->bus->prefetchable_range->limit);
}
for (region = dev->regions; region; region = region->next) {
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 6ce75aa..5922fd4 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1441,24 +1441,26 @@ static PciBridgeInfo *qmp_query_pci_bridge(PCIDevice *dev, PCIBus *bus,
int bus_num)
{
PciBridgeInfo *info;
+ PciMemoryRange *range;
- info = g_malloc0(sizeof(*info));
+ info = g_new0(PciBridgeInfo, 1);
- info->bus.number = dev->config[PCI_PRIMARY_BUS];
- info->bus.secondary = dev->config[PCI_SECONDARY_BUS];
- info->bus.subordinate = dev->config[PCI_SUBORDINATE_BUS];
+ info->bus = g_new0(PciBusInfo, 1);
+ info->bus->number = dev->config[PCI_PRIMARY_BUS];
+ info->bus->secondary = dev->config[PCI_SECONDARY_BUS];
+ info->bus->subordinate = dev->config[PCI_SUBORDINATE_BUS];
- info->bus.io_range = g_malloc0(sizeof(*info->bus.io_range));
- info->bus.io_range->base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO);
- info->bus.io_range->limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO);
+ range = info->bus->io_range = g_new0(PciMemoryRange, 1);
+ range->base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_IO);
+ range->limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_IO);
- info->bus.memory_range = g_malloc0(sizeof(*info->bus.memory_range));
- info->bus.memory_range->base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY);
- info->bus.memory_range->limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY);
+ range = info->bus->memory_range = g_new0(PciMemoryRange, 1);
+ range->base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_SPACE_MEMORY);
+ range->limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_SPACE_MEMORY);
- info->bus.prefetchable_range = g_malloc0(sizeof(*info->bus.prefetchable_range));
- info->bus.prefetchable_range->base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_MEM_PREFETCH);
- info->bus.prefetchable_range->limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_MEM_PREFETCH);
+ range = info->bus->prefetchable_range = g_new0(PciMemoryRange, 1);
+ range->base = pci_bridge_get_base(dev, PCI_BASE_ADDRESS_MEM_PREFETCH);
+ range->limit = pci_bridge_get_limit(dev, PCI_BASE_ADDRESS_MEM_PREFETCH);
if (dev->config[PCI_SECONDARY_BUS] != 0) {
PCIBus *child_bus = pci_find_bus_nr(bus, dev->config[PCI_SECONDARY_BUS]);
@@ -1479,21 +1481,23 @@ static PciDeviceInfo *qmp_query_pci_device(PCIDevice *dev, PCIBus *bus,
uint8_t type;
int class;
- info = g_malloc0(sizeof(*info));
+ info = g_new0(PciDeviceInfo, 1);
info->bus = bus_num;
info->slot = PCI_SLOT(dev->devfn);
info->function = PCI_FUNC(dev->devfn);
+ info->class_info = g_new0(PciDeviceClass, 1);
class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
- info->class_info.q_class = class;
+ info->class_info->q_class = class;
desc = get_class_desc(class);
if (desc->desc) {
- info->class_info.has_desc = true;
- info->class_info.desc = g_strdup(desc->desc);
+ info->class_info->has_desc = true;
+ info->class_info->desc = g_strdup(desc->desc);
}
- info->id.vendor = pci_get_word(dev->config + PCI_VENDOR_ID);
- info->id.device = pci_get_word(dev->config + PCI_DEVICE_ID);
+ info->id = g_new0(PciDeviceId, 1);
+ info->id->vendor = pci_get_word(dev->config + PCI_VENDOR_ID);
+ info->id->device = pci_get_word(dev->config + PCI_DEVICE_ID);
info->regions = qmp_query_pci_regions(dev);
info->qdev_id = g_strdup(dev->qdev.id ? dev->qdev.id : "");
diff --git a/qapi-schema.json b/qapi-schema.json
index 0b612bf..e00f91b 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -943,36 +943,75 @@
'*prefetch': 'bool', '*mem_type_64': 'bool' } }
##
+# @PciBusInfo:
+#
+# Information about a bus of a PCI Bridge device
+#
+# @number: primary bus interface number. This should be the number of the
+# bus the device resides on.
+#
+# @secondary: secondary bus interface number. This is the number of the
+# main bus for the bridge
+#
+# @subordinate: This is the highest number bus that resides below the
+# bridge.
+#
+# @io_range: The PIO range for all devices on this bridge
+#
+# @memory_range: The MMIO range for all devices on this bridge
+#
+# @prefetchable_range: The range of prefetchable MMIO for all devices on
+# this bridge
+#
+# Since: 2.2
+##
+{ 'type': 'PciBusInfo',
+ 'data': {'number': 'int', 'secondary': 'int', 'subordinate': 'int',
+ 'io_range': 'PciMemoryRange',
+ 'memory_range': 'PciMemoryRange',
+ 'prefetchable_range': 'PciMemoryRange' } }
+
+##
# @PciBridgeInfo:
#
# Information about a PCI Bridge device
#
-# @bus.number: primary bus interface number. This should be the number of the
-# bus the device resides on.
-#
-# @bus.secondary: secondary bus interface number. This is the number of the
-# main bus for the bridge
-#
-# @bus.subordinate: This is the highest number bus that resides below the
-# bridge.
-#
-# @bus.io_range: The PIO range for all devices on this bridge
-#
-# @bus.memory_range: The MMIO range for all devices on this bridge
-#
-# @bus.prefetchable_range: The range of prefetchable MMIO for all devices on
-# this bridge
+# @bus: information about the bus the device resides on
#
# @devices: a list of @PciDeviceInfo for each device on this bridge
#
# Since: 0.14.0
##
{ 'type': 'PciBridgeInfo',
- 'data': {'bus': { 'number': 'int', 'secondary': 'int', 'subordinate': 'int',
- 'io_range': 'PciMemoryRange',
- 'memory_range': 'PciMemoryRange',
- 'prefetchable_range': 'PciMemoryRange' },
- '*devices': ['PciDeviceInfo']} }
+ 'data': {'bus': 'PciBusInfo', '*devices': ['PciDeviceInfo']} }
+
+##
+# @PciDeviceClass:
+#
+# Information about the Class of a PCI device
+#
+# @desc: #optional a string description of the device's class
+#
+# @class: the class code of the device
+#
+# Since: 2.2
+##
+{ 'type': 'PciDeviceClass',
+ 'data': {'*desc': 'str', 'class': 'int'} }
+
+##
+# @PciDeviceId:
+#
+# Information about the Id of a PCI device
+#
+# @device: the PCI device id
+#
+# @vendor: the PCI vendor id
+#
+# Since: 2.2
+##
+{ 'type': 'PciDeviceId',
+ 'data': {'device': 'int', 'vendor': 'int'} }
##
# @PciDeviceInfo:
@@ -985,13 +1024,9 @@
#
# @function: the function of the slot used by the device
#
-# @class_info.desc: #optional a string description of the device's class
+# @class_info: the class of the device
#
-# @class_info.class: the class code of the device
-#
-# @id.device: the PCI device id
-#
-# @id.vendor: the PCI vendor id
+# @id: the PCI device id
#
# @irq: #optional if an IRQ is assigned to the device, the IRQ number
#
@@ -1008,8 +1043,7 @@
##
{ 'type': 'PciDeviceInfo',
'data': {'bus': 'int', 'slot': 'int', 'function': 'int',
- 'class_info': {'*desc': 'str', 'class': 'int'},
- 'id': {'device': 'int', 'vendor': 'int'},
+ 'class_info': 'PciDeviceClass', 'id': 'PciDeviceId',
'*irq': 'int', 'qdev_id': 'str', '*pci_bridge': 'PciBridgeInfo',
'regions': ['PciMemoryRegion']} }
--
1.9.3
next prev parent reply other threads:[~2014-09-19 22:25 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 22:24 [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 01/19] qapi: Consistent whitespace in tests/Makefile Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 02/19] qapi: Ignore files created during make check Eric Blake
2014-09-23 8:07 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 03/19] qapi: Update docs given recent event, spacing fixes Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 04/19] qapi: Document type-safety considerations Eric Blake
2014-09-22 12:37 ` Markus Armbruster
2014-09-22 16:53 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 05/19] qapi: Add some enum tests Eric Blake
2014-09-22 12:43 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 06/19] qapi: Better error messages for bad enums Eric Blake
2014-09-23 14:23 ` Markus Armbruster
2014-09-23 15:59 ` Eric Blake
2014-09-24 7:46 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 07/19] qapi: Add some expr tests Eric Blake
2014-09-23 14:26 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 08/19] qapi: Better error messages for bad expressions Eric Blake
2014-09-23 14:56 ` Markus Armbruster
2014-09-23 16:11 ` Eric Blake
2014-09-24 7:34 ` Markus Armbruster
2014-09-24 9:25 ` Kevin Wolf
2014-09-24 11:14 ` Markus Armbruster
2014-09-26 9:15 ` Markus Armbruster
2014-09-26 9:25 ` Kevin Wolf
2014-09-26 11:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 09/19] qapi: Add tests of redefined expressions Eric Blake
2014-09-24 11:24 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 10/19] qapi: Better error messages for duplicated expressions Eric Blake
2014-09-24 11:58 ` Markus Armbruster
2014-09-24 14:10 ` Eric Blake
2014-09-24 15:29 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 11/19] qapi: Add tests of type bypass Eric Blake
2014-09-24 16:10 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 7:34 ` Markus Armbruster
2014-09-25 8:06 ` Markus Armbruster
2014-09-25 14:00 ` Eric Blake
2014-09-25 16:19 ` Markus Armbruster
2015-03-23 15:33 ` [Qemu-devel] RFC: 'alternate' qapi top-level expression [was: [PATCH v4 12/19] qapi: Add some type check tests] Eric Blake
2015-03-23 19:28 ` Markus Armbruster
2014-09-25 13:54 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 16:12 ` Markus Armbruster
2014-09-25 16:32 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 13/19] qapi: More rigourous checking of types Eric Blake
2014-09-26 9:26 ` Markus Armbruster
2014-09-29 8:27 ` Markus Armbruster
2014-09-29 14:26 ` Eric Blake
2014-09-29 14:35 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 14/19] qapi: More rigorous checking for type safety bypass Eric Blake
2014-09-29 8:38 ` Markus Armbruster
2014-09-29 14:33 ` Eric Blake
2014-09-29 16:35 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 15/19] qapi: Merge UserDefTwo and UserDefNested in tests Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 16/19] qapi: Drop tests for inline subtypes Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 17/19] qapi: Drop inline subtype in query-version Eric Blake
2014-09-30 17:40 ` Markus Armbruster
2014-09-19 22:25 ` Eric Blake [this message]
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 19/19] qapi: Drop support for inline subtypes Eric Blake
2014-09-30 17:47 ` Markus Armbruster
2014-09-26 15:42 ` [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411165504-18198-19-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wenchaoqemu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).