[Qemu-devel] [PATCH] vl: Clean up unnecessary boot_order complications

2013-10-01 Thread armbru
From: Markus Armbruster arm...@redhat.com

Messed up in commit 8281abd.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 vl.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/vl.c b/vl.c
index 983cdc6..7e1f408 100644
--- a/vl.c
+++ b/vl.c
@@ -2825,7 +2825,7 @@ int main(int argc, char **argv, char **envp)
 const char *icount_option = NULL;
 const char *initrd_filename;
 const char *kernel_filename, *kernel_cmdline;
-const char *boot_order = NULL;
+const char *boot_order;
 DisplayState *ds;
 int cyls, heads, secs, translation;
 QemuOpts *hda_opts = NULL, *opts, *machine_opts;
@@ -4050,9 +4050,7 @@ int main(int argc, char **argv, char **envp)
 initrd_filename = qemu_opt_get(machine_opts, initrd);
 kernel_cmdline = qemu_opt_get(machine_opts, append);
 
-if (!boot_order) {
-boot_order = machine-default_boot_order;
-}
+boot_order = machine-default_boot_order;
 opts = qemu_opts_find(qemu_find_opts(boot-opts), NULL);
 if (opts) {
 char *normal_boot_order;
-- 
1.8.1.4




[Qemu-devel] [PATCH 0/2] Improve -device command line help some more

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

Marcel's recent improvements (commit dbd94f8..125ee0e) go in the right
direction, but there are issues (see PATCH 1/2), and I find the
resulting help output still hard to read.

This series redoes the help printing part of Marcel's series.  Result
looks like this (moxie picked as example for brevity):

$ qemu-system-moxie -device help
Controller/Bridge/Hub devices:
name usb-host, bus usb-bus
name usb-hub, bus usb-bus

Storage devices:
name scsi-block, bus SCSI, desc SCSI block device passthrough
name scsi-cd, bus SCSI, desc virtual SCSI CD-ROM
name scsi-disk, bus SCSI, desc virtual SCSI disk or CD-ROM (legacy)
name scsi-generic, bus SCSI, desc pass through generic scsi device 
(/dev/sg*)
name scsi-hd, bus SCSI, desc virtual SCSI disk

Input devices:
name isa-serial, bus ISA
name usb-kbd, bus usb-bus
name usb-mouse, bus usb-bus
name usb-tablet, bus usb-bus

Misc devices:
name smbus-eeprom, bus i2c-bus
name usb-redir, bus usb-bus

Additionally, info qdm is again just like device_add help with
no-user devices included.

Markus Armbruster (2):
  Mostly revert qemu-help: Sort devices by logical functionality
  qdev-monitor: Group device_add help and info qdm by category

 include/hw/qdev-core.h | 16 --
 qdev-monitor.c | 85 --
 2 files changed, 47 insertions(+), 54 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH 1/2] Mostly revert qemu-help: Sort devices by logical functionality

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

This reverts most of commit 3d1237fb2ab4edb926c717767bb5e31d6053a7c5.

The commit claims to sort the output of -device help by
functionality rather than alphabetical.  Issues:

* The output was unsorted before, not alphabetically sorted.
  Misleading, but harmless enough.

* The commit doesn't just sort the output of -device help as it
  claims, it adds categories to each line of -device help, and it
  prints devices once per category.  In particular, devices without a
  category aren't shown anymore.  Maybe such devices should not exist,
  but they do.  Regression.

* Categories are also added to the output of info qdm.  Silent
  change, not nice.  Output remains unsorted, unlike -device help.

I'm going to reimplement the feature we actually want, without the
warts.  Reverting the flawed commit first should make it easier to
review.  However, I can't revert it completely, since DeviceClass
member categories has been put to use.  So leave that part in.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 include/hw/qdev-core.h | 16 
 qdev-monitor.c | 48 +---
 2 files changed, 9 insertions(+), 55 deletions(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index a62f231..e191ca0 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -30,22 +30,6 @@ typedef enum DeviceCategory {
 DEVICE_CATEGORY_MAX
 } DeviceCategory;
 
-static inline const char *qdev_category_get_name(DeviceCategory category)
-{
-static const char *category_names[DEVICE_CATEGORY_MAX] = {
-[DEVICE_CATEGORY_BRIDGE]  = Controller/Bridge/Hub,
-[DEVICE_CATEGORY_USB] = USB,
-[DEVICE_CATEGORY_STORAGE] = Storage,
-[DEVICE_CATEGORY_NETWORK] = Network,
-[DEVICE_CATEGORY_INPUT]   = Input,
-[DEVICE_CATEGORY_DISPLAY] = Display,
-[DEVICE_CATEGORY_SOUND]   = Sound,
-[DEVICE_CATEGORY_MISC]= Misc,
-};
-
-return category_names[category];
-};
-
 typedef int (*qdev_initfn)(DeviceState *dev);
 typedef int (*qdev_event)(DeviceState *dev);
 typedef void (*qdev_resetfn)(DeviceState *dev);
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 410cdcb..e5adf6c 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -75,27 +75,24 @@ static bool qdev_class_has_alias(DeviceClass *dc)
 return (qdev_class_get_alias(dc) != NULL);
 }
 
-static void qdev_print_class_devinfo(DeviceClass *dc)
+static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
 {
-DeviceCategory category;
+DeviceClass *dc;
+bool *show_no_user = opaque;
+
+dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
 
-if (!dc) {
+if (!dc || (show_no_user  !*show_no_user  dc-no_user)) {
 return;
 }
 
-error_printf(name \%s\, object_class_get_name(OBJECT_CLASS(dc)));
+error_printf(name \%s\, object_class_get_name(klass));
 if (dc-bus_type) {
 error_printf(, bus %s, dc-bus_type);
 }
 if (qdev_class_has_alias(dc)) {
 error_printf(, alias \%s\, qdev_class_get_alias(dc));
 }
-error_printf(, categories);
-for (category = 0; category  DEVICE_CATEGORY_MAX; ++category) {
-if (test_bit(category, dc-categories)) {
-error_printf( \%s\, qdev_category_get_name(category));
-}
-}
 if (dc-desc) {
 error_printf(, desc \%s\, dc-desc);
 }
@@ -105,15 +102,6 @@ static void qdev_print_class_devinfo(DeviceClass *dc)
 error_printf(\n);
 }
 
-static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
-{
-DeviceClass *dc;
-
-dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
-
-qdev_print_class_devinfo(dc);
-}
-
 static int set_property(const char *name, const char *value, void *opaque)
 {
 DeviceState *dev = opaque;
@@ -151,21 +139,6 @@ static const char *find_typename_by_alias(const char 
*alias)
 return NULL;
 }
 
-static void qdev_print_category_devices(DeviceCategory category)
-{
-DeviceClass *dc;
-GSList *list, *curr;
-
-list = object_class_get_list(TYPE_DEVICE, false);
-for (curr = list; curr; curr = g_slist_next(curr)) {
-dc = (DeviceClass *)object_class_dynamic_cast(curr-data, TYPE_DEVICE);
-if (!dc-no_user  test_bit(category, dc-categories)) {
-qdev_print_class_devinfo(dc);
-}
-}
-g_slist_free(list);
-}
-
 int qdev_device_help(QemuOpts *opts)
 {
 const char *driver;
@@ -174,11 +147,8 @@ int qdev_device_help(QemuOpts *opts)
 
 driver = qemu_opt_get(opts, driver);
 if (driver  is_help_option(driver)) {
-DeviceCategory category;
-for (category = 0; category  DEVICE_CATEGORY_MAX; ++category) {
-qdev_print_category_devices(category);
-}
-
+bool show_no_user = false;
+object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, 
show_no_user);
 return 1;
 }
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 2/2] qdev-monitor: Group device_add help and info qdm by category

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

Output is a long, unsorted list.  Not very helpful.  Print one list
per device category instead, with a header line identifying the
category, plus a list of uncategorized devices.  Print each list in
case-insenitive alphabetical order.

Devices with multiple categories are listed multiple times.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qdev-monitor.c | 67 ++
 1 file changed, 53 insertions(+), 14 deletions(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index e5adf6c..a02c925 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -75,18 +75,9 @@ static bool qdev_class_has_alias(DeviceClass *dc)
 return (qdev_class_get_alias(dc) != NULL);
 }
 
-static void qdev_print_devinfo(ObjectClass *klass, void *opaque)
+static void qdev_print_devinfo(DeviceClass *dc)
 {
-DeviceClass *dc;
-bool *show_no_user = opaque;
-
-dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE);
-
-if (!dc || (show_no_user  !*show_no_user  dc-no_user)) {
-return;
-}
-
-error_printf(name \%s\, object_class_get_name(klass));
+error_printf(name \%s\, object_class_get_name(OBJECT_CLASS(dc)));
 if (dc-bus_type) {
 error_printf(, bus %s, dc-bus_type);
 }
@@ -102,6 +93,55 @@ static void qdev_print_devinfo(ObjectClass *klass, void 
*opaque)
 error_printf(\n);
 }
 
+static gint devinfo_cmp(gconstpointer a, gconstpointer b)
+{
+return strcasecmp(object_class_get_name((ObjectClass *)a),
+  object_class_get_name((ObjectClass *)b));
+}
+
+static void qdev_print_devinfos(bool show_no_user)
+{
+static const char *cat_name[DEVICE_CATEGORY_MAX + 1] = {
+[DEVICE_CATEGORY_BRIDGE]  = Controller/Bridge/Hub,
+[DEVICE_CATEGORY_USB] = USB,
+[DEVICE_CATEGORY_STORAGE] = Storage,
+[DEVICE_CATEGORY_NETWORK] = Network,
+[DEVICE_CATEGORY_INPUT]   = Input,
+[DEVICE_CATEGORY_DISPLAY] = Display,
+[DEVICE_CATEGORY_SOUND]   = Sound,
+[DEVICE_CATEGORY_MISC]= Misc,
+[DEVICE_CATEGORY_MAX] = Uncategorized,
+};
+GSList *list, *elt;
+int i;
+bool cat_printed;
+
+list = g_slist_sort(object_class_get_list(TYPE_DEVICE, false),
+devinfo_cmp);
+
+for (i = 0; i = DEVICE_CATEGORY_MAX; i++) {
+cat_printed = false;
+for (elt = list; elt; elt = elt-next) {
+DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, elt-data,
+ TYPE_DEVICE);
+if ((i  DEVICE_CATEGORY_MAX
+ ? !test_bit(i, dc-categories)
+ : !bitmap_empty(dc-categories, DEVICE_CATEGORY_MAX))
+|| (!show_no_user  dc-no_user)) {
+continue;
+}
+if (!cat_printed) {
+error_printf(%s%s devices:\n, i ? \n : ,
+ cat_name[i]);
+cat_printed = true;
+}
+qdev_print_devinfo(dc);
+}
+}
+
+g_slist_free(list);
+}
+
 static int set_property(const char *name, const char *value, void *opaque)
 {
 DeviceState *dev = opaque;
@@ -147,8 +187,7 @@ int qdev_device_help(QemuOpts *opts)
 
 driver = qemu_opt_get(opts, driver);
 if (driver  is_help_option(driver)) {
-bool show_no_user = false;
-object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, 
show_no_user);
+qdev_print_devinfos(false);
 return 1;
 }
 
@@ -587,7 +626,7 @@ void do_info_qtree(Monitor *mon, const QDict *qdict)
 
 void do_info_qdm(Monitor *mon, const QDict *qdict)
 {
-object_class_foreach(qdev_print_devinfo, TYPE_DEVICE, false, NULL);
+qdev_print_devinfos(true);
 }
 
 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
-- 
1.8.1.4




[Qemu-devel] [PATCH RFC 2/9] sysbus: Set cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

device_add plugs devices into suitable bus.  For real buses, that
actually connects the device.  For sysbus, the connections need to be
made separately, and device_add can't do that.  The device would be
left unconncected, and could not possibly work.

Many, but not all sysbus devices alreasy set
cannot_instantiate_with_device_add_yet in their class init function.

Set it in their abstract base's class init function
sysbus_device_class_init(), and remove the now redundant assignments
from device class init functions.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/alpha/typhoon.c | 2 --
 hw/arm/versatilepb.c   | 1 -
 hw/audio/pl041.c   | 1 -
 hw/core/sysbus.c   | 7 +++
 hw/display/pl110.c | 1 -
 hw/dma/pl080.c | 1 -
 hw/i386/kvm/clock.c| 1 -
 hw/i386/kvmvapic.c | 1 -
 hw/intc/arm_gic.c  | 1 -
 hw/intc/arm_gic_common.c   | 1 -
 hw/intc/arm_gic_kvm.c  | 1 -
 hw/intc/ioapic_common.c| 1 -
 hw/intc/pl190.c| 1 -
 hw/isa/isa-bus.c   | 1 -
 hw/misc/arm_l2x0.c | 1 -
 hw/nvram/fw_cfg.c  | 1 -
 hw/pci-host/bonito.c   | 2 --
 hw/pci-host/grackle.c  | 2 --
 hw/pci-host/piix.c | 1 -
 hw/pci-host/prep.c | 1 -
 hw/ppc/spapr_vio.c | 2 --
 hw/s390x/ipl.c | 1 -
 hw/s390x/s390-virtio-bus.c | 2 --
 hw/s390x/virtio-ccw.c  | 2 --
 hw/sd/pl181.c  | 1 -
 hw/timer/arm_mptimer.c | 1 -
 hw/timer/hpet.c| 1 -
 hw/timer/pl031.c   | 1 -
 28 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 40798d0..bb58a22 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -934,11 +934,9 @@ static int typhoon_pcihost_init(SysBusDevice *dev)
 
 static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
 {
-DeviceClass *dc = DEVICE_CLASS(klass);
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index bb0c0ba..aef2bde 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,6 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 8ba661a..ed82be5 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -632,7 +632,6 @@ static void pl041_device_class_init(ObjectClass *klass, 
void *data)
 
 k-init = pl041_init;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = pl041_device_reset;
 dc-vmsd = vmstate_pl041;
 dc-props = pl041_device_properties;
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index b84cd4a..6e880a8 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -257,6 +257,13 @@ static void sysbus_device_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *k = DEVICE_CLASS(klass);
 k-init = sysbus_device_init;
 k-bus_type = TYPE_SYSTEM_BUS;
+/*
+ * device_add plugs devices into suitable bus.  For real buses,
+ * that actually connects the device.  For sysbus, the connections
+ * need to be made separately, and device_add can't do that.  The
+ * device would be left unconncected, and could not possibly work.
+ */
+k-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sysbus_device_type_info = {
diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 7ad5972..ab689e9 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -496,7 +496,6 @@ static void pl110_class_init(ObjectClass *klass, void *data)
 
 k-init = pl110_initfn;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl110;
 }
 
diff --git a/hw/dma/pl080.c b/hw/dma/pl080.c
index a515621..cb7bda9 100644
--- a/hw/dma/pl080.c
+++ b/hw/dma/pl080.c
@@ -381,7 +381,6 @@ static void pl080_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl080;
 }
 
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index abd2ce8..892aa02 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -114,7 +114,6 @@ static void kvmclock_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = kvmclock_realize;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 

[Qemu-devel] [PATCH RFC 4/9] pci-host: Consistently set cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work.  Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.

Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless.  We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.

It's already set for Bonito, grackle, i440FX, and raven.  Document
why.

Set it for the others: dec-21154, e500-host-bridge, gt64120_pci,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/mips/gt64xxx_pci.c   |  5 +
 hw/pci-bridge/dec.c |  5 +
 hw/pci-host/apb.c   |  5 +
 hw/pci-host/bonito.c|  6 +-
 hw/pci-host/grackle.c   |  6 +-
 hw/pci-host/piix.c  |  6 +-
 hw/pci-host/ppce500.c   |  5 +
 hw/pci-host/prep.c  |  6 +-
 hw/pci-host/q35.c   |  5 +
 hw/pci-host/uninorth.c  | 20 
 hw/pci-host/versatile.c |  5 +
 hw/ppc/ppc4xx_pci.c |  5 +
 hw/sh4/sh_pci.c |  5 +
 13 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 3da2e67..4756bf1 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -1157,6 +1157,11 @@ static void gt64120_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
 k-revision = 0x10;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+k-parent_class.cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo gt64120_pci_info = {
diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index e5e3be8..e27ecfc 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -123,6 +123,11 @@ static void dec_21154_pci_host_class_init(ObjectClass 
*klass, void *data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_PCI;
 k-is_bridge = 1;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+k-parent_class.cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo dec_21154_pci_host_info = {
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index 92f289f..b8df0a6 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -521,6 +521,11 @@ static void pbm_pci_host_class_init(ObjectClass *klass, 
void *data)
 k-vendor_id = PCI_VENDOR_ID_SUN;
 k-device_id = PCI_DEVICE_ID_SUN_SABRE;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+k-parent_class.cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pbm_pci_host_info = {
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index bfb9820..902441f 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -806,8 +806,12 @@ static void bonito_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x01;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_bonito;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo bonito_info = {
diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
index c178375..7d95821 100644
--- a/hw/pci-host/grackle.c
+++ b/hw/pci-host/grackle.c
@@ -130,7 +130,11 @@ static void grackle_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
 k-revision  = 0x00;
 k-class_id  = PCI_CLASS_BRIDGE_HOST;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo grackle_pci_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 21ffe97..8089fd6 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -698,8 +698,12 @@ static void i440fx_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_i440fx;
+/*
+ 

[Qemu-devel] [PATCH RFC 0/9] Clean up and fix no_user

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

Note: this series is on top of my Improve -device command line help
some more series.  You can also get it from branch no-user at
git://repo.or.cz/qemu/armbru.git

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

We used to protect users from such badness by marking devices where
device_add cannot possibly work no-user, and refusing to device_add
them.  Anthony silently broke the protection in v1.1.  He has rejected
attempts to unbreak it with the argument that the protection makes it
impossible to wire devices together with configuration, not code, and
that the protection is being misused[*].

On the former, I disagree.  The problem isn't protecting users from
devices that cannot be wired up that way, it's devices that cannot be
wired up that way.

On the latter, Anthony has a point: the purpose of the no-user flag
isn't obvious, and some of its uses are suspect.

So, instead of just fixing the regression, this RFC series first
explores how to address that point.  PATCH 1 clarifies the purpose of
no-user.  PATCH 2-8 clean up and document its user.  PATCH 9 fixes the
regression.

This is RFC because a few unclear uses are left after PATCH 2-8:
kvm-i8259, piix3-ide, piix3-ide-xen, piix4-ide, via-ide, and abstract
TYPE_CPU.  Please chime in with arguments why these should or should
not be available with -device.

[*] Thread
https://lists.nongnu.org/archive/html/qemu-devel/2013-01/msg00717.html
and
https://lists.nongnu.org/archive/html/qemu-devel/2013-03/msg00437.html

Markus Armbruster (9):
  qdev: Replace no_user by cannot_instantiate_with_device_add_yet
  sysbus: Set cannot_instantiate_with_device_add_yet
  apic: Document why cannot_instantiate_with_device_add_yet
  pci-host: Consistently set cannot_instantiate_with_device_add_yet
  ich9: Document why cannot_instantiate_with_device_add_yet
  piix3 piix4: Document why cannot_instantiate_with_device_add_yet
  vt82c686: Document why cannot_instantiate_with_device_add_yet
  isa: Clean up use of cannot_instantiate_with_device_add_yet
  qdev: Do not let the user try to device_add when it cannot work

 hw/acpi/piix4.c|  7 ++-
 hw/alpha/typhoon.c |  2 --
 hw/arm/versatilepb.c   |  1 -
 hw/audio/pcspk.c   |  3 ++-
 hw/audio/pl041.c   |  1 -
 hw/block/fdc.c |  1 -
 hw/core/sysbus.c   |  7 +++
 hw/display/pl110.c |  1 -
 hw/dma/pl080.c |  1 -
 hw/i2c/smbus_ich9.c|  6 +-
 hw/i386/kvm/clock.c|  1 -
 hw/i386/kvm/i8259.c|  1 +
 hw/i386/kvmvapic.c |  1 -
 hw/i386/pc.c   |  1 -
 hw/ide/piix.c  |  6 +++---
 hw/ide/via.c   |  2 +-
 hw/input/pckbd.c   |  1 -
 hw/input/vmmouse.c |  3 ++-
 hw/intc/apic_common.c  |  6 +-
 hw/intc/arm_gic.c  |  1 -
 hw/intc/arm_gic_common.c   |  1 -
 hw/intc/arm_gic_kvm.c  |  1 -
 hw/intc/i8259.c|  2 ++
 hw/intc/i8259_common.c |  1 -
 hw/intc/ioapic_common.c|  1 -
 hw/intc/pl190.c|  1 -
 hw/isa/isa-bus.c   |  1 -
 hw/isa/lpc_ich9.c  |  7 +--
 hw/isa/piix4.c |  6 +-
 hw/isa/vt82c686.c  |  6 +-
 hw/mips/gt64xxx_pci.c  |  5 +
 hw/misc/arm_l2x0.c |  1 -
 hw/misc/vmport.c   |  3 ++-
 hw/nvram/fw_cfg.c  |  1 -
 hw/pci-bridge/dec.c|  5 +
 hw/pci-host/apb.c  |  5 +
 hw/pci-host/bonito.c   |  8 +---
 hw/pci-host/grackle.c  |  8 +---
 hw/pci-host/piix.c | 19 +++
 hw/pci-host/ppce500.c  |  5 +
 hw/pci-host/prep.c |  7 +--
 hw/pci-host/q35.c  |  5 +
 hw/pci-host/uninorth.c | 20 
 hw/pci-host/versatile.c|  5 +
 hw/ppc/ppc4xx_pci.c|  5 +
 hw/ppc/spapr_vio.c |  2 --
 hw/s390x/ipl.c |  1 -
 hw/s390x/s390-virtio-bus.c |  2 --
 hw/s390x/virtio-ccw.c  |  2 --
 hw/sd/pl181.c  |  1 -
 hw/sh4/sh_pci.c|  5 +
 hw/timer/arm_mptimer.c |  1 -
 hw/timer/hpet.c|  1 -
 hw/timer/i8254_common.c|  1 -
 hw/timer/m48t59.c  |  1 -
 hw/timer/mc146818rtc.c |  1 -
 hw/timer/pl031.c   |  1 -
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  7 ---
 qom/cpu.c  |  2 +-
 60 files changed, 158 insertions(+), 65 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH RFC 9/9] qdev: Do not let the user try to device_add when it cannot work

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

Such devices have always been unavailable and omitted from the list of
available devices shown by device_add help.  Until commit 18b6dad
silently broke the former, setting up nasty traps for unwary users,
like this one:

$ qemu-system-x86_64 -nodefaults -monitor stdio -display none
QEMU 1.6.50 monitor - type 'help' for more information
(qemu) device_add apic
Segmentation fault (core dumped)

I call that a regression.  Fix it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qdev-monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 36f6f09..c538fec 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 }
 }
 
-if (!obj) {
+if (!obj || DEVICE_CLASS(obj)-cannot_instantiate_with_device_add_yet) {
 qerror_report(QERR_INVALID_PARAMETER_VALUE, driver, device type);
 return NULL;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH RFC 3/9] apic: Document why cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com


Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/intc/apic_common.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ea420c7..aaef054 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -386,9 +386,13 @@ static void apic_common_class_init(ObjectClass *klass, 
void *data)
 
 dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = apic_properties_common;
 idc-init = apic_init_common;
+/*
+ * Reason: APIC and CPU need to be wired up by
+ * x86_cpu_apic_create()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo apic_common_type = {
-- 
1.8.1.4




[Qemu-devel] [PATCH RFC 6/9] piix3 piix4: Document why cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

A PIIX3/PIIX4 southbridge has multiple functions.  We model each
function as a separate qdev.  Two of them need some special wiring set
up in pc_init1() or mips_malta_init() to work: the ISA bridge at 01.0,
and the SMBus controller at 01.3.

Additionally, the IDE controller at 01.1 has always had
cannot_instantiate_with_device_add_yet set, but it's not obvious to me
why, so keep /* FIXME explain why */ for them.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  7 ++-
 hw/isa/piix4.c |  6 +-
 hw/pci-host/piix.c | 12 ++--
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index c29a703..c0ad010 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,9 +508,14 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+dc-cannot_instantiate_with_device_add_yet = true;
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_pm_info = {
diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index d9dac61..def6fe3 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -113,8 +113,12 @@ static void piix4_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_piix4;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 8089fd6..1526fd4 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -644,7 +644,6 @@ static void piix3_class_init(ObjectClass *klass, void *data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config;
@@ -652,6 +651,11 @@ static void piix3_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix3_info = {
@@ -668,7 +672,6 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config_xen;
@@ -676,6 +679,11 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 };
 
 static const TypeInfo piix3_xen_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH RFC 8/9] isa: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

Drop it when there's no obvious reason why device_add could not work.
Else keep and document why.

* isa-fdc, port92, i8042, m48t59_isa, mc146818rtc, isa-pit, kvm-pit:
  drop (the last two by dropping it from their abstract base
  pit-common)

* pcspk: keep because of pointer property pit, and because realize
  sets global pcspk_state

* vmmouse: keep because of pointer property ps2_mouse

* vmport: keep because realize sets global port_state

* pic-common, isa-i8259, kvm-i8259: move from abstract base pic-common
  to its subtypes, keep in isa-i8259 because init sets global isa_pic
  and slave_pic, keep in kvm-i8259 with /* FIXME explain why */

Perhaps I should split this patch.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/audio/pcspk.c| 3 ++-
 hw/block/fdc.c  | 1 -
 hw/i386/kvm/i8259.c | 1 +
 hw/i386/pc.c| 1 -
 hw/input/pckbd.c| 1 -
 hw/input/vmmouse.c  | 3 ++-
 hw/intc/i8259.c | 2 ++
 hw/intc/i8259_common.c  | 1 -
 hw/misc/vmport.c| 3 ++-
 hw/timer/i8254_common.c | 1 -
 hw/timer/m48t59.c   | 1 -
 hw/timer/mc146818rtc.c  | 1 -
 12 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 8e3e178..f980d66 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,8 +192,9 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
+/* Reason: pointer property pit, realize sets global pcspk_state */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pcspk_info = {
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 86f4920..592b58f 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2234,7 +2234,6 @@ static void isabus_fdc_class_init(ObjectClass *klass, 
void *data)
 
 dc-realize = isabus_fdc_realize;
 dc-fw_name = fdc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = fdctrl_external_reset_isa;
 dc-vmsd = vmstate_isa_fdc;
 dc-props = isa_fdc_properties;
diff --git a/hw/i386/kvm/i8259.c b/hw/i386/kvm/i8259.c
index 53e3ca8..6aa343a 100644
--- a/hw/i386/kvm/i8259.c
+++ b/hw/i386/kvm/i8259.c
@@ -144,6 +144,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void 
*data)
 dc-realize   = kvm_pic_realize;
 k-pre_save   = kvm_pic_get;
 k-post_load  = kvm_pic_put;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo kvm_i8259_info = {
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index fe33843..bebda79 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -544,7 +544,6 @@ static void port92_class_initfn(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-realize = port92_realizefn;
 dc-reset = port92_reset;
 dc-vmsd = vmstate_port92_isa;
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index dee31a6..655b8c5 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -522,7 +522,6 @@ static void i8042_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = i8042_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_kbd_isa;
 }
 
diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c
index 600e4a2..6a50533 100644
--- a/hw/input/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -282,10 +282,11 @@ static void vmmouse_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = vmmouse_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = vmmouse_reset;
 dc-vmsd = vmstate_vmmouse;
 dc-props = vmmouse_properties;
+/* Reason: pointer property ps2_mouse */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo vmmouse_info = {
diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c
index c6f248b..3321d10 100644
--- a/hw/intc/i8259.c
+++ b/hw/intc/i8259.c
@@ -504,6 +504,8 @@ static void i8259_class_init(ObjectClass *klass, void *data)
 k-parent_realize = dc-realize;
 dc-realize = pic_realize;
 dc-reset = pic_reset;
+/* Reason: init sets global isa_pic, slave_pic */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo i8259_info = {
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index 2acdbfe..0e35c14 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -135,7 +135,6 @@ static void pic_common_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-vmsd = vmstate_pic_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* 

[Qemu-devel] [PATCH RFC 1/9] qdev: Replace no_user by cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

DeviceClass member no_user used to make device models unavailable with
-device / device_add, but that regressed in commit 18b6dad.  All
that's left is the device model is still omitted from help.

Attempts to fix the regression have been rejected with the argument
that the purpose of no_user isn't clear, and it's prone to misuse.

This commit clarifies no_user's purpose.  Anthony suggested to rename
it cannot_instantiate_with_device_add_yet_due_to_internal_bugs, which
I shorten somewhat to keep checkpatch happy.  While there, make it
bool.

Every use of cannot_instantiate_with_device_add_yet gets a FIXME
comment asking for rationale.  The next few commits will clean them
up, either by providing a rationale, or by getting rid of the use.

With that done, the regression fix is hopefully acceptable.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  2 +-
 hw/alpha/typhoon.c |  2 +-
 hw/arm/versatilepb.c   |  2 +-
 hw/audio/pcspk.c   |  2 +-
 hw/audio/pl041.c   |  2 +-
 hw/block/fdc.c |  2 +-
 hw/display/pl110.c |  2 +-
 hw/dma/pl080.c |  2 +-
 hw/i2c/smbus_ich9.c|  2 +-
 hw/i386/kvm/clock.c|  2 +-
 hw/i386/kvmvapic.c |  2 +-
 hw/i386/pc.c   |  2 +-
 hw/ide/piix.c  |  6 +++---
 hw/ide/via.c   |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/vmmouse.c |  2 +-
 hw/intc/apic_common.c  |  2 +-
 hw/intc/arm_gic.c  |  2 +-
 hw/intc/arm_gic_common.c   |  2 +-
 hw/intc/arm_gic_kvm.c  |  2 +-
 hw/intc/i8259_common.c |  2 +-
 hw/intc/ioapic_common.c|  2 +-
 hw/intc/pl190.c|  2 +-
 hw/isa/isa-bus.c   |  2 +-
 hw/isa/lpc_ich9.c  |  2 +-
 hw/isa/piix4.c |  2 +-
 hw/isa/vt82c686.c  |  2 +-
 hw/misc/arm_l2x0.c |  2 +-
 hw/misc/vmport.c   |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/bonito.c   |  4 ++--
 hw/pci-host/grackle.c  |  4 ++--
 hw/pci-host/piix.c |  8 
 hw/pci-host/prep.c |  4 ++--
 hw/ppc/spapr_vio.c |  2 +-
 hw/s390x/ipl.c |  2 +-
 hw/s390x/s390-virtio-bus.c |  2 +-
 hw/s390x/virtio-ccw.c  |  2 +-
 hw/sd/pl181.c  |  2 +-
 hw/timer/arm_mptimer.c |  2 +-
 hw/timer/hpet.c|  2 +-
 hw/timer/i8254_common.c|  2 +-
 hw/timer/m48t59.c  |  2 +-
 hw/timer/mc146818rtc.c |  2 +-
 hw/timer/pl031.c   |  2 +-
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  5 +++--
 qom/cpu.c  |  2 +-
 48 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b46bd5e..c29a703 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,7 +508,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
 }
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index aac9a32..40798d0 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -938,7 +938,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index f7e8b7e..bb0c0ba 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,7 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 9004ce3..8e3e178 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,7 +192,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
 }
 
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 5393b52..8ba661a 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -632,7 +632,7 @@ static void pl041_device_class_init(ObjectClass *klass, 
void *data)
 
 k-init = pl041_init;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = pl041_device_reset;
 dc-vmsd = vmstate_pl041;
 

[Qemu-devel] [PATCH RFC 5/9] ich9: Document why cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

An ICH9 southbridge contains several PCI devices, some of them with
multiple functions.  We model each function as a separate qdev.  Two
of them need some special wiring set up in pc_q35_init() to work: the
LPC controller at 00:1f.0, and the SMBus controller at 00:1f.3.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/i2c/smbus_ich9.c | 6 +-
 hw/isa/lpc_ich9.c   | 7 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index c1ffa34..8d47eaf 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -97,11 +97,15 @@ static void ich9_smb_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_6;
 k-revision = ICH9_A2_SMB_REVISION;
 k-class_id = PCI_CLASS_SERIAL_SMBUS;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_ich9_smbus;
 dc-desc = ICH9 SMBUS Bridge;
 k-init = ich9_smbus_initfn;
 k-config_write = ich9_smbus_write_config;
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index ad841b5..d00d698 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -604,14 +604,17 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-reset = ich9_lpc_reset;
 k-init = ich9_lpc_initfn;
 dc-vmsd = vmstate_ich9_lpc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-config_write = ich9_lpc_config_write;
 dc-desc = ICH9 LPC bridge;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_8;
 k-revision = ICH9_A2_LPC_REVISION;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
-
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo ich9_lpc_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH RFC 7/9] vt82c686: Document why cannot_instantiate_with_device_add_yet

2013-10-10 Thread armbru
From: Markus Armbruster arm...@redhat.com

A VT82C686B southbridge has multiple functions.  We model each
function as a separate qdev.  One of them need some special wiring set
up in mips_fulong2e_init() to work: the ISA bridge at 05.0.

Additionally, the IDE controller at 05.1 has always had
cannot_instantiate_with_device_add_yet set, but it's not obvious to me
why, so keep /* FIXME explain why */ for them.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/isa/vt82c686.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 3e8ec80..ec7c259 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -480,8 +480,12 @@ static void via_class_init(ObjectClass *klass, void *data)
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 k-revision = 0x40;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_via;
+/*
+ * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
+ * e.g. by mips_fulong2e_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo via_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 04/10] apic: Document why cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com


Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/intc/apic_common.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ea420c7..aaef054 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -386,9 +386,13 @@ static void apic_common_class_init(ObjectClass *klass, 
void *data)
 
 dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = apic_properties_common;
 idc-init = apic_init_common;
+/*
+ * Reason: APIC and CPU need to be wired up by
+ * x86_cpu_apic_create()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo apic_common_type = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 00/10] Clean up and fix no_user

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

We used to protect users from such badness by marking devices where
device_add cannot possibly work no-user, and refusing to device_add
them.  Anthony silently broke the protection in v1.1.  He has rejected
attempts to unbreak it with the argument that the protection makes it
impossible to wire devices together with configuration, not code, and
that the protection is being misused[*].

On the former, I disagree.  The problem isn't protecting users from
devices that cannot be wired up that way, it's devices that cannot be
wired up that way.

On the latter, Anthony has a point: the purpose of the no-user flag
isn't obvious, and some of its uses are suspect.

So, instead of just fixing the regression, this series first addresses
that point.  PATCH 1 clarifies the purpose of no-user.  PATCH 2-9
clean up and document its use.  PATCH 10 fixes the regression.

Markus Armbruster (10):
  qdev: Replace no_user by cannot_instantiate_with_device_add_yet
  sysbus: Set cannot_instantiate_with_device_add_yet
  cpu: Document why cannot_instantiate_with_device_add_yet
  apic: Document why cannot_instantiate_with_device_add_yet
  pci-host: Consistently set cannot_instantiate_with_device_add_yet
  ich9: Document why cannot_instantiate_with_device_add_yet
  piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet
  vt82c686: Clean up use of cannot_instantiate_with_device_add_yet
  isa: Clean up use of cannot_instantiate_with_device_add_yet
  qdev: Do not let the user try to device_add when it cannot work

 hw/acpi/piix4.c|  7 ++-
 hw/alpha/typhoon.c |  2 --
 hw/arm/versatilepb.c   |  1 -
 hw/audio/pcspk.c   |  3 ++-
 hw/audio/pl041.c   |  1 -
 hw/block/fdc.c |  1 -
 hw/core/sysbus.c   |  7 +++
 hw/display/pl110.c |  1 -
 hw/dma/pl080.c |  1 -
 hw/i2c/smbus_ich9.c|  6 +-
 hw/i386/kvm/clock.c|  1 -
 hw/i386/kvmvapic.c |  1 -
 hw/i386/pc.c   |  1 -
 hw/ide/piix.c  |  3 ---
 hw/ide/via.c   |  1 -
 hw/input/pckbd.c   |  1 -
 hw/input/vmmouse.c |  3 ++-
 hw/intc/apic_common.c  |  6 +-
 hw/intc/arm_gic.c  |  1 -
 hw/intc/arm_gic_common.c   |  1 -
 hw/intc/arm_gic_kvm.c  |  1 -
 hw/intc/i8259_common.c |  8 +++-
 hw/intc/ioapic_common.c|  1 -
 hw/intc/pl190.c|  1 -
 hw/isa/isa-bus.c   |  1 -
 hw/isa/lpc_ich9.c  |  7 +--
 hw/isa/piix4.c |  6 +-
 hw/isa/vt82c686.c  |  6 +-
 hw/mips/gt64xxx_pci.c  |  5 +
 hw/misc/arm_l2x0.c |  1 -
 hw/misc/vmport.c   |  3 ++-
 hw/nvram/fw_cfg.c  |  1 -
 hw/pci-bridge/dec.c|  5 +
 hw/pci-host/apb.c  |  5 +
 hw/pci-host/bonito.c   |  8 +---
 hw/pci-host/grackle.c  |  8 +---
 hw/pci-host/piix.c | 19 +++
 hw/pci-host/ppce500.c  |  5 +
 hw/pci-host/prep.c |  7 +--
 hw/pci-host/q35.c  |  5 +
 hw/pci-host/uninorth.c | 20 
 hw/pci-host/versatile.c|  5 +
 hw/ppc/ppc4xx_pci.c|  5 +
 hw/ppc/spapr_vio.c |  2 --
 hw/s390x/ipl.c |  1 -
 hw/s390x/s390-virtio-bus.c |  2 --
 hw/s390x/virtio-ccw.c  |  2 --
 hw/sd/pl181.c  |  1 -
 hw/sh4/sh_pci.c|  5 +
 hw/timer/arm_mptimer.c |  1 -
 hw/timer/hpet.c|  1 -
 hw/timer/i8254_common.c|  1 -
 hw/timer/m48t59.c  |  1 -
 hw/timer/mc146818rtc.c |  1 -
 hw/timer/pl031.c   |  1 -
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  7 ---
 qom/cpu.c  |  6 +-
 58 files changed, 162 insertions(+), 65 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH 08/10] vt82c686: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

A VT82C686B southbridge has multiple functions.  We model each
function as a separate qdev.  One of them need some special wiring set
up in mips_fulong2e_init() to work: the ISA bridge at 05.0.

The IDE controller at 05.1 (via-ide) has always had
cannot_instantiate_with_device_add_yet set, but there is no obvious
reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/via.c  | 1 -
 hw/isa/vt82c686.c | 6 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index b556c14..198123b 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -225,7 +225,6 @@ static void via_ide_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x06;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo via_ide_info = {
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 3e8ec80..ec7c259 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -480,8 +480,12 @@ static void via_class_init(ObjectClass *klass, void *data)
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 k-revision = 0x40;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_via;
+/*
+ * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
+ * e.g. by mips_fulong2e_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo via_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 02/10] sysbus: Set cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

device_add plugs devices into suitable bus.  For real buses, that
actually connects the device.  For sysbus, the connections need to be
made separately, and device_add can't do that.  The device would be
left unconncected, and could not possibly work.

Many, but not all sysbus devices alreasy set
cannot_instantiate_with_device_add_yet in their class init function.

Set it in their abstract base's class init function
sysbus_device_class_init(), and remove the now redundant assignments
from device class init functions.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/alpha/typhoon.c | 2 --
 hw/arm/versatilepb.c   | 1 -
 hw/audio/pl041.c   | 1 -
 hw/core/sysbus.c   | 7 +++
 hw/display/pl110.c | 1 -
 hw/dma/pl080.c | 1 -
 hw/i386/kvm/clock.c| 1 -
 hw/i386/kvmvapic.c | 1 -
 hw/intc/arm_gic.c  | 1 -
 hw/intc/arm_gic_common.c   | 1 -
 hw/intc/arm_gic_kvm.c  | 1 -
 hw/intc/ioapic_common.c| 1 -
 hw/intc/pl190.c| 1 -
 hw/isa/isa-bus.c   | 1 -
 hw/misc/arm_l2x0.c | 1 -
 hw/nvram/fw_cfg.c  | 1 -
 hw/pci-host/bonito.c   | 2 --
 hw/pci-host/grackle.c  | 2 --
 hw/pci-host/piix.c | 1 -
 hw/pci-host/prep.c | 1 -
 hw/ppc/spapr_vio.c | 2 --
 hw/s390x/ipl.c | 1 -
 hw/s390x/s390-virtio-bus.c | 2 --
 hw/s390x/virtio-ccw.c  | 2 --
 hw/sd/pl181.c  | 1 -
 hw/timer/arm_mptimer.c | 1 -
 hw/timer/hpet.c| 1 -
 hw/timer/pl031.c   | 1 -
 28 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 60987ed..71a5a37 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -934,11 +934,9 @@ static int typhoon_pcihost_init(SysBusDevice *dev)
 
 static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
 {
-DeviceClass *dc = DEVICE_CLASS(klass);
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index bb0c0ba..aef2bde 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,6 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 8ba661a..ed82be5 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -632,7 +632,6 @@ static void pl041_device_class_init(ObjectClass *klass, 
void *data)
 
 k-init = pl041_init;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = pl041_device_reset;
 dc-vmsd = vmstate_pl041;
 dc-props = pl041_device_properties;
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index b84cd4a..6e880a8 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -257,6 +257,13 @@ static void sysbus_device_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *k = DEVICE_CLASS(klass);
 k-init = sysbus_device_init;
 k-bus_type = TYPE_SYSTEM_BUS;
+/*
+ * device_add plugs devices into suitable bus.  For real buses,
+ * that actually connects the device.  For sysbus, the connections
+ * need to be made separately, and device_add can't do that.  The
+ * device would be left unconncected, and could not possibly work.
+ */
+k-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sysbus_device_type_info = {
diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 7ad5972..ab689e9 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -496,7 +496,6 @@ static void pl110_class_init(ObjectClass *klass, void *data)
 
 k-init = pl110_initfn;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl110;
 }
 
diff --git a/hw/dma/pl080.c b/hw/dma/pl080.c
index a515621..cb7bda9 100644
--- a/hw/dma/pl080.c
+++ b/hw/dma/pl080.c
@@ -381,7 +381,6 @@ static void pl080_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl080;
 }
 
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index abd2ce8..892aa02 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -114,7 +114,6 @@ static void kvmclock_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = kvmclock_realize;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 

[Qemu-devel] [PATCH 09/10] isa: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

Drop it when there's no obvious reason why device_add could not work.
Else keep and document why.

* isa-fdc, port92, i8042, m48t59_isa, mc146818rtc, isa-pit, kvm-pit:
  drop (from the last two by dropping it from their abstract base
  pit-common)

* pcspk: keep because of pointer property pit, and because realize
  sets global pcspk_state

* vmmouse: keep because of pointer property ps2_mouse

* vmport: keep because realize sets global port_state

* isa-i8259, kvm-i8259: keep (in their abstract base pic-common),
  because the PICs need additional wiring: its IRQ input lines are set
  up by board code, and the wiring of the slave to the master is
  hard-coded in device model code.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/audio/pcspk.c| 3 ++-
 hw/block/fdc.c  | 1 -
 hw/i386/pc.c| 1 -
 hw/input/pckbd.c| 1 -
 hw/input/vmmouse.c  | 3 ++-
 hw/intc/i8259_common.c  | 8 +++-
 hw/misc/vmport.c| 3 ++-
 hw/timer/i8254_common.c | 1 -
 hw/timer/m48t59.c   | 1 -
 hw/timer/mc146818rtc.c  | 1 -
 10 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 8e3e178..f980d66 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,8 +192,9 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
+/* Reason: pointer property pit, realize sets global pcspk_state */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pcspk_info = {
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 86f4920..592b58f 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2234,7 +2234,6 @@ static void isabus_fdc_class_init(ObjectClass *klass, 
void *data)
 
 dc-realize = isabus_fdc_realize;
 dc-fw_name = fdc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = fdctrl_external_reset_isa;
 dc-vmsd = vmstate_isa_fdc;
 dc-props = isa_fdc_properties;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index fe33843..bebda79 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -544,7 +544,6 @@ static void port92_class_initfn(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-realize = port92_realizefn;
 dc-reset = port92_reset;
 dc-vmsd = vmstate_port92_isa;
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index dee31a6..655b8c5 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -522,7 +522,6 @@ static void i8042_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = i8042_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_kbd_isa;
 }
 
diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c
index 600e4a2..6a50533 100644
--- a/hw/input/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -282,10 +282,11 @@ static void vmmouse_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = vmmouse_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = vmmouse_reset;
 dc-vmsd = vmstate_vmmouse;
 dc-props = vmmouse_properties;
+/* Reason: pointer property ps2_mouse */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo vmmouse_info = {
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index 2acdbfe..9d29399 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -135,9 +135,15 @@ static void pic_common_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-vmsd = vmstate_pic_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pic_properties_common;
 dc-realize = pic_common_realize;
+/*
+ * Reason: unlike ordinary ISA devices, the PICs need additional
+ * wiring: its IRQ input lines are set up by board code, and the
+ * wiring of the slave to the master is hard-coded in device model
+ * code.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pic_common_type = {
diff --git a/hw/misc/vmport.c b/hw/misc/vmport.c
index 94ae6ae..cd5716a 100644
--- a/hw/misc/vmport.c
+++ b/hw/misc/vmport.c
@@ -162,7 +162,8 @@ static void vmport_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = vmport_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/* Reason: realize sets global port_state */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo 

[Qemu-devel] [PATCH 01/10] qdev: Replace no_user by cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

To protect users from such badness, DeviceClass member no_user used to
make device models unavailable with -device / device_add, but that
regressed in commit 18b6dad.  The device model is still omitted from
help, but is available anyway.

Attempts to fix the regression have been rejected with the argument
that the purpose of no_user isn't clear, and it's prone to misuse.

This commit clarifies no_user's purpose.  Anthony suggested to rename
it cannot_instantiate_with_device_add_yet_due_to_internal_bugs, which
I shorten somewhat to keep checkpatch happy.  While there, make it
bool.

Every use of cannot_instantiate_with_device_add_yet gets a FIXME
comment asking for rationale.  The next few commits will clean them
all up, either by providing a rationale, or by getting rid of the use.

With that done, the regression fix is hopefully acceptable.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  2 +-
 hw/alpha/typhoon.c |  2 +-
 hw/arm/versatilepb.c   |  2 +-
 hw/audio/pcspk.c   |  2 +-
 hw/audio/pl041.c   |  2 +-
 hw/block/fdc.c |  2 +-
 hw/display/pl110.c |  2 +-
 hw/dma/pl080.c |  2 +-
 hw/i2c/smbus_ich9.c|  2 +-
 hw/i386/kvm/clock.c|  2 +-
 hw/i386/kvmvapic.c |  2 +-
 hw/i386/pc.c   |  2 +-
 hw/ide/piix.c  |  6 +++---
 hw/ide/via.c   |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/vmmouse.c |  2 +-
 hw/intc/apic_common.c  |  2 +-
 hw/intc/arm_gic.c  |  2 +-
 hw/intc/arm_gic_common.c   |  2 +-
 hw/intc/arm_gic_kvm.c  |  2 +-
 hw/intc/i8259_common.c |  2 +-
 hw/intc/ioapic_common.c|  2 +-
 hw/intc/pl190.c|  2 +-
 hw/isa/isa-bus.c   |  2 +-
 hw/isa/lpc_ich9.c  |  2 +-
 hw/isa/piix4.c |  2 +-
 hw/isa/vt82c686.c  |  2 +-
 hw/misc/arm_l2x0.c |  2 +-
 hw/misc/vmport.c   |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/bonito.c   |  4 ++--
 hw/pci-host/grackle.c  |  4 ++--
 hw/pci-host/piix.c |  8 
 hw/pci-host/prep.c |  4 ++--
 hw/ppc/spapr_vio.c |  2 +-
 hw/s390x/ipl.c |  2 +-
 hw/s390x/s390-virtio-bus.c |  2 +-
 hw/s390x/virtio-ccw.c  |  2 +-
 hw/sd/pl181.c  |  2 +-
 hw/timer/arm_mptimer.c |  2 +-
 hw/timer/hpet.c|  2 +-
 hw/timer/i8254_common.c|  2 +-
 hw/timer/m48t59.c  |  2 +-
 hw/timer/mc146818rtc.c |  2 +-
 hw/timer/pl031.c   |  2 +-
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  5 +++--
 qom/cpu.c  |  2 +-
 48 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b46bd5e..c29a703 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,7 +508,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
 }
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 59e1bb8..60987ed 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -938,7 +938,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index f7e8b7e..bb0c0ba 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,7 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 9004ce3..8e3e178 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,7 +192,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
 }
 
diff --git a/hw/audio/pl041.c 

[Qemu-devel] [PATCH 10/10] qdev: Do not let the user try to device_add when it cannot work

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

Such devices have always been unavailable and omitted from the list of
available devices shown by device_add help.  Until commit 18b6dad
silently broke the former, setting up nasty traps for unwary users,
like this one:

$ qemu-system-x86_64 -nodefaults -monitor stdio -display none
QEMU 1.6.50 monitor - type 'help' for more information
(qemu) device_add apic
Segmentation fault (core dumped)

I call that a regression.  Fix it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qdev-monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 36f6f09..c538fec 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 }
 }
 
-if (!obj) {
+if (!obj || DEVICE_CLASS(obj)-cannot_instantiate_with_device_add_yet) {
 qerror_report(QERR_INVALID_PARAMETER_VALUE, driver, device type);
 return NULL;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH 03/10] cpu: Document why cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com


Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qom/cpu.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qom/cpu.c b/qom/cpu.c
index 09c15e6..6e0d54e 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -254,7 +254,11 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k-gdb_read_register = cpu_common_gdb_read_register;
 k-gdb_write_register = cpu_common_gdb_write_register;
 dc-realize = cpu_common_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/*
+ * Reason: CPUs still need special care by board code: wiring up
+ * IRQs, adding reset handlers, halting non-first CPUS, ...
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo cpu_type_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 06/10] ich9: Document why cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

An ICH9 southbridge contains several PCI devices, some of them with
multiple functions.  We model each function as a separate qdev.  Two
of them need some special wiring set up in pc_q35_init() to work: the
LPC controller at 00:1f.0, and the SMBus controller at 00:1f.3.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/i2c/smbus_ich9.c | 6 +-
 hw/isa/lpc_ich9.c   | 7 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index c1ffa34..8d47eaf 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -97,11 +97,15 @@ static void ich9_smb_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_6;
 k-revision = ICH9_A2_SMB_REVISION;
 k-class_id = PCI_CLASS_SERIAL_SMBUS;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_ich9_smbus;
 dc-desc = ICH9 SMBUS Bridge;
 k-init = ich9_smbus_initfn;
 k-config_write = ich9_smbus_write_config;
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index ad841b5..d00d698 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -604,14 +604,17 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-reset = ich9_lpc_reset;
 k-init = ich9_lpc_initfn;
 dc-vmsd = vmstate_ich9_lpc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-config_write = ich9_lpc_config_write;
 dc-desc = ICH9 LPC bridge;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_8;
 k-revision = ICH9_A2_LPC_REVISION;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
-
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo ich9_lpc_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 07/10] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

A PIIX3/PIIX4 southbridge has multiple functions.  We model each
function as a separate qdev.  Two of them need some special wiring set
up in pc_init1() or mips_malta_init() to work: the ISA bridge at 01.0,
and the SMBus controller at 01.3.

The IDE controller at 01.1 (piix3-ide, piix3-ide-xen, piix4-ide) has
always had cannot_instantiate_with_device_add_yet set, but there is no
obvious reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  7 ++-
 hw/ide/piix.c  |  3 ---
 hw/isa/piix4.c |  6 +-
 hw/pci-host/piix.c | 12 ++--
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index c29a703..c0ad010 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,9 +508,14 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+dc-cannot_instantiate_with_device_add_yet = true;
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_pm_info = {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 27b08e1..9b5960b 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -248,7 +248,6 @@ static void piix3_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix3_ide_info = {
@@ -267,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-unplug = pci_piix3_xen_ide_unplug;
 }
 
@@ -289,7 +287,6 @@ static void piix4_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix4_ide_info = {
diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index d9dac61..def6fe3 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -113,8 +113,12 @@ static void piix4_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_piix4;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 8089fd6..1526fd4 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -644,7 +644,6 @@ static void piix3_class_init(ObjectClass *klass, void *data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config;
@@ -652,6 +651,11 @@ static void piix3_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix3_info = {
@@ -668,7 +672,6 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config_xen;
@@ -676,6 +679,11 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 };
 
 static const TypeInfo piix3_xen_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 05/10] pci-host: Consistently set cannot_instantiate_with_device_add_yet

2013-10-17 Thread armbru
From: Markus Armbruster arm...@redhat.com

Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work.  Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.

Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless.  We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.

It's already set for Bonito, grackle, i440FX, and raven.  Document
why.

Set it for the others: dec-21154, e500-host-bridge, gt64120_pci,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/mips/gt64xxx_pci.c   |  5 +
 hw/pci-bridge/dec.c |  5 +
 hw/pci-host/apb.c   |  5 +
 hw/pci-host/bonito.c|  6 +-
 hw/pci-host/grackle.c   |  6 +-
 hw/pci-host/piix.c  |  6 +-
 hw/pci-host/ppce500.c   |  5 +
 hw/pci-host/prep.c  |  6 +-
 hw/pci-host/q35.c   |  5 +
 hw/pci-host/uninorth.c  | 20 
 hw/pci-host/versatile.c |  5 +
 hw/ppc/ppc4xx_pci.c |  5 +
 hw/sh4/sh_pci.c |  5 +
 13 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 3da2e67..4756bf1 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -1157,6 +1157,11 @@ static void gt64120_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
 k-revision = 0x10;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+k-parent_class.cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo gt64120_pci_info = {
diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index e5e3be8..e27ecfc 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -123,6 +123,11 @@ static void dec_21154_pci_host_class_init(ObjectClass 
*klass, void *data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_PCI;
 k-is_bridge = 1;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+k-parent_class.cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo dec_21154_pci_host_info = {
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index 92f289f..b8df0a6 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -521,6 +521,11 @@ static void pbm_pci_host_class_init(ObjectClass *klass, 
void *data)
 k-vendor_id = PCI_VENDOR_ID_SUN;
 k-device_id = PCI_DEVICE_ID_SUN_SABRE;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+k-parent_class.cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pbm_pci_host_info = {
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index bfb9820..902441f 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -806,8 +806,12 @@ static void bonito_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x01;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_bonito;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo bonito_info = {
diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
index c178375..7d95821 100644
--- a/hw/pci-host/grackle.c
+++ b/hw/pci-host/grackle.c
@@ -130,7 +130,11 @@ static void grackle_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
 k-revision  = 0x00;
 k-class_id  = PCI_CLASS_BRIDGE_HOST;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo grackle_pci_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 21ffe97..8089fd6 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -698,8 +698,12 @@ static void i440fx_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_i440fx;
+/*
+ 

[Qemu-devel] [PATCH v2 04/10] apic: Document why cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/intc/apic_common.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ea420c7..aaef054 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -386,9 +386,13 @@ static void apic_common_class_init(ObjectClass *klass, 
void *data)
 
 dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = apic_properties_common;
 idc-init = apic_init_common;
+/*
+ * Reason: APIC and CPU need to be wired up by
+ * x86_cpu_apic_create()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo apic_common_type = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 00/10] Clean up and fix no_user

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

We used to protect users from such badness by marking devices where
device_add cannot possibly work no-user, and refusing to device_add
them.  Anthony silently broke the protection in v1.1.  He has rejected
attempts to unbreak it with the argument that the protection makes it
impossible to wire devices together with configuration, not code, and
that the protection is being misused[*].

On the former, I disagree.  The problem isn't protecting users from
devices that cannot be wired up that way, it's devices that cannot be
wired up that way.

On the latter, Anthony has a point: the purpose of the no-user flag
isn't obvious, and some of its uses are suspect.

So, instead of just fixing the regression, this series first addresses
that point.  PATCH 1 clarifies the purpose of no-user.  PATCH 2-9
clean up and document its use.  PATCH 10 fixes the regression.

The series makes following devices available with device_add:
* PCI [PATCH 07-08]: piix3-ide, piix3-ide-xen, piix4-ide, via-ide
* ISA [PATCH 09]: i8042, isa-fdc

The following devices are made unavailable:
* PCI [PATCH 05]: dec-21154, e500-host-bridge, gt64120_pci, mch,
  pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
  uni-north-internal-pci, uni-north-pci, versatile_pci_host
* Sysbus [PATCH 02]: ARM,bitband-memory, SUNW,CS4231, SUNW,fdtwo,
  SUNW,tcx, a15mpcore_priv, a9-scu, a9mpcore_priv, apc,
  arm11mpcore_priv, cadence_gem, cadence_ttc, cadence_uart,
  cfi.pflash01, cfi.pflash02, cuda, dec-21154-sysbus, ds1225y,
  e500-ccsr, e500-pcihost, e500-spin, eccmemctl, empty_slot, escc,
  esp, etraxfs,pic, etraxfs,serial, etraxfs,timer, etraxfs-eth,
  exynos4210-ehci-usb, exynos4210.combiner, exynos4210.fimd,
  exynos4210.gic, exynos4210.i2c, exynos4210.irq_gate, exynos4210.mct,
  exynos4210.pmu, exynos4210.pwm, exynos4210.rtc, exynos4210.uart,
  fusbh200-ehci-usb, generic-sdhci, gpio_i2c, grlib,apbuart,
  grlib,gptimer, grlib,irqmp, gt64120, highbank-regs, icc-bridge,
  imx-serial, imx.epit, imx.gpt, imx_avic, imx_ccm, integrator_core,
  integrator_pic, integrator_pit, iommu, jazz-led, lan9118, lance,
  lm32-juart, lm32-pic, lm32-sys, lm32-timer, lm32-uart, m48t59,
  macio-ide, macio-nvram, macio_idreg, mainstone-fpga, memory,
  milkymist-ac97, milkymist-hpdmc, milkymist-memcard,
  milkymist-minimac2, milkymist-pfpu, milkymist-softusb,
  milkymist-sysctl, milkymist-tmu2, milkymist-uart, milkymist-vgafb,
  mips-malta, mipsnet, mmio-ide, mpc8544-guts, musicpal-misc,
  musicpal_gpio, musicpal_key, musicpal_lcd, mv88w8618_audio,
  mv88w8618_eth, mv88w8618_flashcfg, mv88w8618_pic, mv88w8618_pit,
  mv88w8618_wlan, omap-gpio, omap-intc, omap2-gpio, omap2-intc,
  omap_i2c, onenand, open_eth, openpic, openprom, pbm, pl011,
  pl011_luminary, pl022, pl050_keyboard, pl050_mouse, pl061,
  pl061_luminary, pl330, ppc4xx-pcihost, puv3_dma, puv3_gpio,
  puv3_intc, puv3_ost, puv3_pm, pxa25x-timer, pxa27x-timer,
  pxa2xx-dma, pxa2xx-gpio, pxa2xx-ssp, pxa2xx_i2c, pxa2xx_pic,
  pxa2xx_rtc, q35-pcihost, realview_gic, realview_mpcore,
  realview_pci, realview_sysctl, s390-sclp-event-facility, scoop,
  sh_pci, sl-nand, slavio_intctl, slavio_misc, slavio_timer,
  smc91c111, sp804, spapr-pci-host-bridge, sparc32_dma,
  spitz-keyboard, stellaris-adc, stellaris-gptm, stellaris-i2c,
  stellaris_enet, strongarm-gpio, strongarm-ppc, strongarm-rtc,
  strongarm-ssp, strongarm-uart, strongarm_pic, sysbus-ahci,
  sysbus-fdc, sysbus-g364, sysbus-ohci, tcx_afx, tegra2-ehci-usb,
  tusb6010, u3-agp-pcihost, uni-north-agp-pcihost,
  uni-north-internal-pci-pcihost, uni-north-pci-pcihost,
  versatile_i2c, versatile_pci, virtio-mmio, xgmac, xics,
  xilinx,zynq_slcr, xlnx,ps7-usb, xlnx.axi-dma, xlnx.ps7-qspi,
  xlnx.ps7-spi, xlnx.xps-ethernetlite, xlnx.xps-intc, xlnx.xps-spi,
  xlnx.xps-timer, xlnx.xps-uartlite

v2: address Peter Maydell's review
* Some commit messages improved
* Use QOM cast macros instead of .parent_class [PATCH 05]
* keep cannot_instantiate_with_device_add_yet for port92, isa-pit,
  kvm-pit, m48t59_isa, mc146818rtc [PATCH 09]

Markus Armbruster (10):
  qdev: Replace no_user by cannot_instantiate_with_device_add_yet
  sysbus: Set cannot_instantiate_with_device_add_yet
  cpu: Document why cannot_instantiate_with_device_add_yet
  apic: Document why cannot_instantiate_with_device_add_yet
  pci-host: Consistently set cannot_instantiate_with_device_add_yet
  ich9: Document why cannot_instantiate_with_device_add_yet
  piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet
  vt82c686: Clean up use of cannot_instantiate_with_device_add_yet
  isa: Clean up 

[Qemu-devel] [PATCH v2 03/10] cpu: Document why cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 qom/cpu.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qom/cpu.c b/qom/cpu.c
index 09c15e6..6e0d54e 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -254,7 +254,11 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k-gdb_read_register = cpu_common_gdb_read_register;
 k-gdb_write_register = cpu_common_gdb_write_register;
 dc-realize = cpu_common_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/*
+ * Reason: CPUs still need special care by board code: wiring up
+ * IRQs, adding reset handlers, halting non-first CPUS, ...
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo cpu_type_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 08/10] vt82c686: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

A VT82C686B southbridge has multiple functions.  We model each
function as a separate qdev.  One of them need some special wiring set
up in mips_fulong2e_init() to work: the ISA bridge at 05.0.

The IDE controller at 05.1 (via-ide) has always had
cannot_instantiate_with_device_add_yet set, but there is no obvious
reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/ide/via.c  | 1 -
 hw/isa/vt82c686.c | 6 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index b556c14..198123b 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -225,7 +225,6 @@ static void via_ide_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x06;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo via_ide_info = {
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 3e8ec80..ec7c259 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -480,8 +480,12 @@ static void via_class_init(ObjectClass *klass, void *data)
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 k-revision = 0x40;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_via;
+/*
+ * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
+ * e.g. by mips_fulong2e_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo via_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 10/10] qdev: Do not let the user try to device_add when it cannot work

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Such devices have always been unavailable and omitted from the list of
available devices shown by device_add help.  Until commit 18b6dad
silently broke the former, setting up nasty traps for unwary users,
like this one:

$ qemu-system-x86_64 -nodefaults -monitor stdio -display none
QEMU 1.6.50 monitor - type 'help' for more information
(qemu) device_add apic
Segmentation fault (core dumped)

I call that a regression.  Fix it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qdev-monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 36f6f09..c538fec 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 }
 }
 
-if (!obj) {
+if (!obj || DEVICE_CLASS(obj)-cannot_instantiate_with_device_add_yet) {
 qerror_report(QERR_INVALID_PARAMETER_VALUE, driver, device type);
 return NULL;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 06/10] ich9: Document why cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

An ICH9 southbridge contains several PCI devices, some of them with
multiple functions.  We model each function as a separate qdev.  Two
of them need some special wiring set up in pc_q35_init() to work: the
LPC controller at 00:1f.0, and the SMBus controller at 00:1f.3.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/i2c/smbus_ich9.c | 6 +-
 hw/isa/lpc_ich9.c   | 7 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index c1ffa34..8d47eaf 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -97,11 +97,15 @@ static void ich9_smb_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_6;
 k-revision = ICH9_A2_SMB_REVISION;
 k-class_id = PCI_CLASS_SERIAL_SMBUS;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_ich9_smbus;
 dc-desc = ICH9 SMBUS Bridge;
 k-init = ich9_smbus_initfn;
 k-config_write = ich9_smbus_write_config;
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index ad841b5..d00d698 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -604,14 +604,17 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-reset = ich9_lpc_reset;
 k-init = ich9_lpc_initfn;
 dc-vmsd = vmstate_ich9_lpc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-config_write = ich9_lpc_config_write;
 dc-desc = ICH9 LPC bridge;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_8;
 k-revision = ICH9_A2_LPC_REVISION;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
-
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo ich9_lpc_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 05/10] pci-host: Consistently set cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work.  Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.

Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless.  We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.

It's already set for Bonito, grackle, i440FX, and raven.  Document
why.

Set it for the others: dec-21154, e500-host-bridge, gt64120_pci, mch,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/mips/gt64xxx_pci.c   |  6 ++
 hw/pci-bridge/dec.c |  6 ++
 hw/pci-host/apb.c   |  6 ++
 hw/pci-host/bonito.c|  6 +-
 hw/pci-host/grackle.c   |  6 +-
 hw/pci-host/piix.c  |  6 +-
 hw/pci-host/ppce500.c   |  5 +
 hw/pci-host/prep.c  |  6 +-
 hw/pci-host/q35.c   |  5 +
 hw/pci-host/uninorth.c  | 24 
 hw/pci-host/versatile.c |  6 ++
 hw/ppc/ppc4xx_pci.c |  5 +
 hw/sh4/sh_pci.c |  6 ++
 13 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 3da2e67..6398514 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -1151,12 +1151,18 @@ static int gt64120_pci_init(PCIDevice *d)
 static void gt64120_pci_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = gt64120_pci_init;
 k-vendor_id = PCI_VENDOR_ID_MARVELL;
 k-device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
 k-revision = 0x10;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo gt64120_pci_info = {
diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index e5e3be8..a6ca940 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -116,6 +116,7 @@ static int dec_21154_pci_host_init(PCIDevice *d)
 static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = dec_21154_pci_host_init;
 k-vendor_id = PCI_VENDOR_ID_DEC;
@@ -123,6 +124,11 @@ static void dec_21154_pci_host_class_init(ObjectClass 
*klass, void *data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_PCI;
 k-is_bridge = 1;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo dec_21154_pci_host_info = {
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index 92f289f..1b399dd 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -516,11 +516,17 @@ static int pbm_pci_host_init(PCIDevice *d)
 static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = pbm_pci_host_init;
 k-vendor_id = PCI_VENDOR_ID_SUN;
 k-device_id = PCI_DEVICE_ID_SUN_SABRE;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pbm_pci_host_info = {
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index bfb9820..902441f 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -806,8 +806,12 @@ static void bonito_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x01;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_bonito;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo bonito_info = {
diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
index c178375..7d95821 100644
--- a/hw/pci-host/grackle.c
+++ b/hw/pci-host/grackle.c
@@ -130,7 +130,11 @@ static void grackle_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
 k-revision  = 0x00;
 k-class_id  = PCI_CLASS_BRIDGE_HOST;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain 

[Qemu-devel] [PATCH v2 07/10] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

A PIIX3/PIIX4 southbridge has multiple functions.  We model each
function as a separate qdev.  Two of them need some special wiring set
up in pc_init1() or mips_malta_init() to work: the ISA bridge at 01.0,
and the SMBus controller at 01.3.

The IDE controller at 01.1 (piix3-ide, piix3-ide-xen, piix4-ide) has
always had cannot_instantiate_with_device_add_yet set, but there is no
obvious reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  7 ++-
 hw/ide/piix.c  |  3 ---
 hw/isa/piix4.c |  6 +-
 hw/pci-host/piix.c | 12 ++--
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index c29a703..c0ad010 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,9 +508,14 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+dc-cannot_instantiate_with_device_add_yet = true;
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_pm_info = {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 27b08e1..9b5960b 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -248,7 +248,6 @@ static void piix3_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix3_ide_info = {
@@ -267,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-unplug = pci_piix3_xen_ide_unplug;
 }
 
@@ -289,7 +287,6 @@ static void piix4_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix4_ide_info = {
diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index d9dac61..def6fe3 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -113,8 +113,12 @@ static void piix4_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_piix4;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 8089fd6..1526fd4 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -644,7 +644,6 @@ static void piix3_class_init(ObjectClass *klass, void *data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config;
@@ -652,6 +651,11 @@ static void piix3_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix3_info = {
@@ -668,7 +672,6 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config_xen;
@@ -676,6 +679,11 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 };
 
 static const TypeInfo piix3_xen_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 09/10] isa: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Drop it when there's no obvious reason why device_add could not work.
Else keep and document why.

* isa-fdc: drop

* i8042: drop, even though its I/O base is hardcoded (because you
  could conceivably still add one to a board that has none), and even
  though PC board code wires up the A20 line (because that wiring is
  optional)

* port92: keep because it needs additional wiring by port92_init()

* mc146818rtc: keep because it needs to be wired up by rtc_init()

* m48t59_isa: keep because needs to be wired up by m48t59_init_isa()

* isa-pit, kvm-pit: keep (in their abstract base pic-common) because
  the PIT needs additional wiring by board code, depending on HPET
  presence

* pcspk: keep because of pointer property pit, and because realize
  sets global pcspk_state

* vmmouse: keep because of pointer property ps2_mouse

* vmport: keep because realize sets global port_state

* isa-i8259, kvm-i8259: keep (in their abstract base pic-common),
  because the PICs' IRQ input lines are set up by board code, and the
  wiring of the slave to the master is hard-coded in device model code

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/audio/pcspk.c| 3 ++-
 hw/block/fdc.c  | 1 -
 hw/i386/pc.c| 7 ++-
 hw/input/pckbd.c| 1 -
 hw/input/vmmouse.c  | 3 ++-
 hw/intc/i8259_common.c  | 8 +++-
 hw/misc/vmport.c| 3 ++-
 hw/timer/i8254_common.c | 7 ++-
 hw/timer/m48t59.c   | 3 ++-
 hw/timer/mc146818rtc.c  | 3 ++-
 10 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 8e3e178..f980d66 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,8 +192,9 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
+/* Reason: pointer property pit, realize sets global pcspk_state */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pcspk_info = {
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 86f4920..592b58f 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2234,7 +2234,6 @@ static void isabus_fdc_class_init(ObjectClass *klass, 
void *data)
 
 dc-realize = isabus_fdc_realize;
 dc-fw_name = fdc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = fdctrl_external_reset_isa;
 dc-vmsd = vmstate_isa_fdc;
 dc-props = isa_fdc_properties;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index fe33843..20402ba 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -544,10 +544,15 @@ static void port92_class_initfn(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-realize = port92_realizefn;
 dc-reset = port92_reset;
 dc-vmsd = vmstate_port92_isa;
+/*
+ * Reason: unlike ordinary ISA devices, this one needs additional
+ * wiring: its A20 output line needs to be wired up by
+ * port92_init().
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo port92_info = {
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index dee31a6..655b8c5 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -522,7 +522,6 @@ static void i8042_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = i8042_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_kbd_isa;
 }
 
diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c
index 600e4a2..6a50533 100644
--- a/hw/input/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -282,10 +282,11 @@ static void vmmouse_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = vmmouse_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = vmmouse_reset;
 dc-vmsd = vmstate_vmmouse;
 dc-props = vmmouse_properties;
+/* Reason: pointer property ps2_mouse */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo vmmouse_info = {
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index 2acdbfe..9d29399 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -135,9 +135,15 @@ static void pic_common_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-vmsd = vmstate_pic_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pic_properties_common;
 dc-realize = pic_common_realize;
+/*
+ * Reason: unlike ordinary ISA devices, the PICs need additional
+ * wiring: its IRQ input lines are set up by board code, and the
+ * wiring 

[Qemu-devel] [PATCH v2 01/10] qdev: Replace no_user by cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

To protect users from such badness, DeviceClass member no_user used to
make device models unavailable with -device / device_add, but that
regressed in commit 18b6dad.  The device model is still omitted from
help, but is available anyway.

Attempts to fix the regression have been rejected with the argument
that the purpose of no_user isn't clear, and it's prone to misuse.

This commit clarifies no_user's purpose.  Anthony suggested to rename
it cannot_instantiate_with_device_add_yet_due_to_internal_bugs, which
I shorten somewhat to keep checkpatch happy.  While there, make it
bool.

Every use of cannot_instantiate_with_device_add_yet gets a FIXME
comment asking for rationale.  The next few commits will clean them
all up, either by providing a rationale, or by getting rid of the use.

With that done, the regression fix is hopefully acceptable.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  2 +-
 hw/alpha/typhoon.c |  2 +-
 hw/arm/versatilepb.c   |  2 +-
 hw/audio/pcspk.c   |  2 +-
 hw/audio/pl041.c   |  2 +-
 hw/block/fdc.c |  2 +-
 hw/display/pl110.c |  2 +-
 hw/dma/pl080.c |  2 +-
 hw/i2c/smbus_ich9.c|  2 +-
 hw/i386/kvm/clock.c|  2 +-
 hw/i386/kvmvapic.c |  2 +-
 hw/i386/pc.c   |  2 +-
 hw/ide/piix.c  |  6 +++---
 hw/ide/via.c   |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/vmmouse.c |  2 +-
 hw/intc/apic_common.c  |  2 +-
 hw/intc/arm_gic.c  |  2 +-
 hw/intc/arm_gic_common.c   |  2 +-
 hw/intc/arm_gic_kvm.c  |  2 +-
 hw/intc/i8259_common.c |  2 +-
 hw/intc/ioapic_common.c|  2 +-
 hw/intc/pl190.c|  2 +-
 hw/isa/isa-bus.c   |  2 +-
 hw/isa/lpc_ich9.c  |  2 +-
 hw/isa/piix4.c |  2 +-
 hw/isa/vt82c686.c  |  2 +-
 hw/misc/arm_l2x0.c |  2 +-
 hw/misc/vmport.c   |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/bonito.c   |  4 ++--
 hw/pci-host/grackle.c  |  4 ++--
 hw/pci-host/piix.c |  8 
 hw/pci-host/prep.c |  4 ++--
 hw/ppc/spapr_vio.c |  2 +-
 hw/s390x/ipl.c |  2 +-
 hw/s390x/s390-virtio-bus.c |  2 +-
 hw/s390x/virtio-ccw.c  |  2 +-
 hw/sd/pl181.c  |  2 +-
 hw/timer/arm_mptimer.c |  2 +-
 hw/timer/hpet.c|  2 +-
 hw/timer/i8254_common.c|  2 +-
 hw/timer/m48t59.c  |  2 +-
 hw/timer/mc146818rtc.c |  2 +-
 hw/timer/pl031.c   |  2 +-
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  5 +++--
 qom/cpu.c  |  2 +-
 48 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b46bd5e..c29a703 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,7 +508,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
 }
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 59e1bb8..60987ed 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -938,7 +938,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index f7e8b7e..bb0c0ba 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,7 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 9004ce3..8e3e178 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,7 +192,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
 }
 
diff --git a/hw/audio/pl041.c 

[Qemu-devel] [PATCH v2 02/10] sysbus: Set cannot_instantiate_with_device_add_yet

2013-10-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

device_add plugs devices into suitable bus.  For real buses, that
actually connects the device.  For sysbus, the connections need to be
made separately, and device_add can't do that.  The device would be
left unconnected, and could not possibly work.

Quite a few, but not all sysbus devices already set
cannot_instantiate_with_device_add_yet in their class init function.

Set it in their abstract base's class init function
sysbus_device_class_init(), and remove the now redundant assignments
from device class init functions.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/alpha/typhoon.c | 2 --
 hw/arm/versatilepb.c   | 1 -
 hw/audio/pl041.c   | 1 -
 hw/core/sysbus.c   | 7 +++
 hw/display/pl110.c | 1 -
 hw/dma/pl080.c | 1 -
 hw/i386/kvm/clock.c| 1 -
 hw/i386/kvmvapic.c | 1 -
 hw/intc/arm_gic.c  | 1 -
 hw/intc/arm_gic_common.c   | 1 -
 hw/intc/arm_gic_kvm.c  | 1 -
 hw/intc/ioapic_common.c| 1 -
 hw/intc/pl190.c| 1 -
 hw/isa/isa-bus.c   | 1 -
 hw/misc/arm_l2x0.c | 1 -
 hw/nvram/fw_cfg.c  | 1 -
 hw/pci-host/bonito.c   | 2 --
 hw/pci-host/grackle.c  | 2 --
 hw/pci-host/piix.c | 1 -
 hw/pci-host/prep.c | 1 -
 hw/ppc/spapr_vio.c | 2 --
 hw/s390x/ipl.c | 1 -
 hw/s390x/s390-virtio-bus.c | 2 --
 hw/s390x/virtio-ccw.c  | 2 --
 hw/sd/pl181.c  | 1 -
 hw/timer/arm_mptimer.c | 1 -
 hw/timer/hpet.c| 1 -
 hw/timer/pl031.c   | 1 -
 28 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 60987ed..71a5a37 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -934,11 +934,9 @@ static int typhoon_pcihost_init(SysBusDevice *dev)
 
 static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
 {
-DeviceClass *dc = DEVICE_CLASS(klass);
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index bb0c0ba..aef2bde 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,6 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 8ba661a..ed82be5 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -632,7 +632,6 @@ static void pl041_device_class_init(ObjectClass *klass, 
void *data)
 
 k-init = pl041_init;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = pl041_device_reset;
 dc-vmsd = vmstate_pl041;
 dc-props = pl041_device_properties;
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index b84cd4a..6e880a8 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -257,6 +257,13 @@ static void sysbus_device_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *k = DEVICE_CLASS(klass);
 k-init = sysbus_device_init;
 k-bus_type = TYPE_SYSTEM_BUS;
+/*
+ * device_add plugs devices into suitable bus.  For real buses,
+ * that actually connects the device.  For sysbus, the connections
+ * need to be made separately, and device_add can't do that.  The
+ * device would be left unconncected, and could not possibly work.
+ */
+k-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sysbus_device_type_info = {
diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 7ad5972..ab689e9 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -496,7 +496,6 @@ static void pl110_class_init(ObjectClass *klass, void *data)
 
 k-init = pl110_initfn;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl110;
 }
 
diff --git a/hw/dma/pl080.c b/hw/dma/pl080.c
index a515621..cb7bda9 100644
--- a/hw/dma/pl080.c
+++ b/hw/dma/pl080.c
@@ -381,7 +381,6 @@ static void pl080_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl080;
 }
 
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index abd2ce8..892aa02 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -114,7 +114,6 @@ static void kvmclock_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = kvmclock_realize;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */

[Qemu-devel] [PATCH v3 1/2] hw: Pass QEMUMachine to its init() method

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Put it in QEMUMachineInitArgs, so I don't have to touch every board.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 include/hw/boards.h | 7 +--
 vl.c| 3 ++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/hw/boards.h b/include/hw/boards.h
index 5a7ae9f..2151460 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -6,7 +6,10 @@
 #include sysemu/blockdev.h
 #include hw/qdev.h
 
+typedef struct QEMUMachine QEMUMachine;
+
 typedef struct QEMUMachineInitArgs {
+const QEMUMachine *machine;
 ram_addr_t ram_size;
 const char *boot_order;
 const char *kernel_filename;
@@ -21,7 +24,7 @@ typedef void QEMUMachineResetFunc(void);
 
 typedef void QEMUMachineHotAddCPUFunc(const int64_t id, Error **errp);
 
-typedef struct QEMUMachine {
+struct QEMUMachine {
 const char *name;
 const char *alias;
 const char *desc;
@@ -43,7 +46,7 @@ typedef struct QEMUMachine {
 GlobalProperty *compat_props;
 struct QEMUMachine *next;
 const char *hw_version;
-} QEMUMachine;
+};
 
 int qemu_register_machine(QEMUMachine *m);
 QEMUMachine *find_default_machine(void);
diff --git a/vl.c b/vl.c
index b42ac67..63338e4 100644
--- a/vl.c
+++ b/vl.c
@@ -4236,7 +4236,8 @@ int main(int argc, char **argv, char **envp)
 
 qdev_machine_init();
 
-QEMUMachineInitArgs args = { .ram_size = ram_size,
+QEMUMachineInitArgs args = { .machine = machine,
+ .ram_size = ram_size,
  .boot_order = boot_order,
  .kernel_filename = kernel_filename,
  .kernel_cmdline = kernel_cmdline,
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 2/2] smbios: Set system manufacturer, product version by default

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Currently, we get SeaBIOS defaults: manufacturer Bochs, product Bochs,
no version.  Best SeaBIOS can do, but we can provide better defaults:
manufacturer QEMU, product  version taken from QEMUMachine desc and
name.

Take care to do this only for new machine types, of course.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/i386/pc_piix.c|  9 +
 hw/i386/pc_q35.c |  7 +++
 hw/i386/smbios.c | 14 ++
 include/hw/i386/smbios.h |  2 ++
 4 files changed, 32 insertions(+)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index c6042c7..417ad33 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -28,6 +28,7 @@
 #include hw/loader.h
 #include hw/i386/pc.h
 #include hw/i386/apic.h
+#include hw/i386/smbios.h
 #include hw/pci/pci.h
 #include hw/pci/pci_ids.h
 #include hw/usb.h
@@ -59,6 +60,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
 static bool has_pvpanic;
 static bool has_pci_info = true;
+static bool smbios_type1_defaults = true;
 
 /* PC hardware initialisation */
 static void pc_init1(QEMUMachineInitArgs *args,
@@ -124,6 +126,10 @@ static void pc_init1(QEMUMachineInitArgs *args,
 guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
 guest_info-has_pci_info = has_pci_info;
 guest_info-isapc_ram_fw = !pci_enabled;
+if (smbios_type1_defaults) {
+smbios_set_type1_defaults(QEMU, args-machine-desc,
+  args-machine-name);
+}
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
@@ -240,6 +246,7 @@ static void pc_compat_1_6(QEMUMachineInitArgs *args)
 {
 has_pci_info = false;
 rom_file_in_ram = false;
+smbios_type1_defaults = false;
 }
 
 static void pc_compat_1_5(QEMUMachineInitArgs *args)
@@ -304,6 +311,7 @@ static void pc_init_pci_1_2(QEMUMachineInitArgs *args)
 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
 {
 has_pci_info = false;
+smbios_type1_defaults = false;
 disable_kvm_pv_eoi();
 enable_compat_apic_id_mode();
 pc_init1(args, 1, 0);
@@ -312,6 +320,7 @@ static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs 
*args)
 static void pc_init_isa(QEMUMachineInitArgs *args)
 {
 has_pci_info = false;
+smbios_type1_defaults = false;
 if (!args-cpu_model) {
 args-cpu_model = 486;
 }
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index ca84e1c..9e3213f 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -39,6 +39,7 @@
 #include hw/pci-host/q35.h
 #include exec/address-spaces.h
 #include hw/i386/ich9.h
+#include hw/i386/smbios.h
 #include hw/ide/pci.h
 #include hw/ide/ahci.h
 #include hw/usb.h
@@ -49,6 +50,7 @@
 
 static bool has_pvpanic;
 static bool has_pci_info = true;
+static bool smbios_type1_defaults = true;
 
 /* PC hardware initialisation */
 static void pc_q35_init(QEMUMachineInitArgs *args)
@@ -111,6 +113,10 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
 guest_info-has_pci_info = has_pci_info;
 guest_info-isapc_ram_fw = false;
+if (smbios_type1_defaults) {
+smbios_set_type1_defaults(QEMU, args-machine-desc,
+  args-machine-name);
+}
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
@@ -224,6 +230,7 @@ static void pc_compat_1_6(QEMUMachineInitArgs *args)
 {
 has_pci_info = false;
 rom_file_in_ram = false;
+smbios_type1_defaults = false;
 }
 
 static void pc_compat_1_5(QEMUMachineInitArgs *args)
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index d3f1ee6..e8f41ad 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -256,6 +256,20 @@ static void smbios_build_type_1_fields(void)
 }
 }
 
+void smbios_set_type1_defaults(const char *manufacturer,
+   const char *product, const char *version)
+{
+if (!type1.manufacturer) {
+type1.manufacturer = manufacturer;
+}
+if (!type1.product) {
+type1.product = product;
+}
+if (!type1.version) {
+type1.version = version;
+}
+}
+
 uint8_t *smbios_get_table(size_t *length)
 {
 if (!smbios_immutable) {
diff --git a/include/hw/i386/smbios.h b/include/hw/i386/smbios.h
index b08ec71..18fb970 100644
--- a/include/hw/i386/smbios.h
+++ b/include/hw/i386/smbios.h
@@ -16,6 +16,8 @@
 #include qemu/option.h
 
 void smbios_entry_add(QemuOpts *opts);
+void smbios_set_type1_defaults(const char *manufacturer,
+   const char *product, const char *version);
 uint8_t *smbios_get_table(size_t *length);
 
 /*
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 0/2] smbios nicer defaults for DMI type 1 (System)

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Currently, we get SeaBIOS defaults: manufacturer Bochs, product Bochs,
no version.  Best SeaBIOS can do, but we can provide better defaults:
manufacturer QEMU, product  version taken from QEMUMachine desc and
name.

This series used to be called [PATCH v2 0/7] smbios cleanup  nicer
defaults for type 1, but its cleanup parts [0-5/7] already went in.

Andreas didn't like [PATCH v2 6/7] vl: Set current_machine early,
and suggested to put he machine into QEMUMachineInitArgs.  PATCH 1/2
does exactly that, replacing v2's PATCH 6/7.  PATCH 2/2 is v2's PATCH
7/7 rebased on top.

Michael didn't like the way I suppress the nicer defaults for old
machine types via static bool smbios_type1_defaults, and thought it
would be nicer to have it in QEMUMachine or some device.  I considered
this, but decided to stick to smbios_type1_defaults, because

1. There is no suitable device.
2. I'd rather not extend QEMUMachine with target-specific stuff.
3. A static bool whose default value gets flipped by some QEMUMachine
   init() methods is what we commonly do in such cases, so let's stick
   to that.

v3: Do it the way Andreas suggested
v2: Rebase, only last patch had conflicts

Markus Armbruster (2):
  hw: Pass QEMUMachine to its init() method
  smbios: Set system manufacturer, product  version by default

 hw/i386/pc_piix.c|  9 +
 hw/i386/pc_q35.c |  7 +++
 hw/i386/smbios.c | 14 ++
 include/hw/boards.h  |  7 +--
 include/hw/i386/smbios.h |  2 ++
 vl.c |  3 ++-
 6 files changed, 39 insertions(+), 3 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH v3 00/10] Clean up and fix no_user

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

We used to protect users from such badness by marking devices where
device_add cannot possibly work no-user, and refusing to device_add
them.  Anthony silently broke the protection in v1.1.  He has rejected
attempts to unbreak it with the argument that the protection makes it
impossible to wire devices together with configuration, not code, and
that the protection is being misused[*].

On the former, I disagree.  The problem isn't protecting users from
devices that cannot be wired up that way, it's devices that cannot be
wired up that way.

On the latter, Anthony has a point: the purpose of the no-user flag
isn't obvious, and some of its uses are suspect.

So, instead of just fixing the regression, this series first addresses
that point.  PATCH 1 clarifies the purpose of no-user.  PATCH 2-9
clean up and document its use.  PATCH 10 fixes the regression.

The series makes following devices available with device_add:
* PCI [PATCH 07-08]: piix3-ide, piix3-ide-xen, piix4-ide, via-ide
* ISA [PATCH 09]: i8042, isa-fdc

The following devices are made unavailable:
* PCI [PATCH 05]: dec-21154, e500-host-bridge, gt64120_pci, mch,
  pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
  uni-north-internal-pci, uni-north-pci, versatile_pci_host
* Sysbus [PATCH 02]: ARM,bitband-memory, SUNW,CS4231, SUNW,fdtwo,
  SUNW,tcx, a15mpcore_priv, a9-scu, a9mpcore_priv, apc,
  arm11mpcore_priv, cadence_gem, cadence_ttc, cadence_uart,
  cfi.pflash01, cfi.pflash02, cuda, dec-21154-sysbus, ds1225y,
  e500-ccsr, e500-pcihost, e500-spin, eccmemctl, empty_slot, escc,
  esp, etraxfs,pic, etraxfs,serial, etraxfs,timer, etraxfs-eth,
  exynos4210-ehci-usb, exynos4210.combiner, exynos4210.fimd,
  exynos4210.gic, exynos4210.i2c, exynos4210.irq_gate, exynos4210.mct,
  exynos4210.pmu, exynos4210.pwm, exynos4210.rtc, exynos4210.uart,
  fusbh200-ehci-usb, generic-sdhci, gpio_i2c, grlib,apbuart,
  grlib,gptimer, grlib,irqmp, gt64120, highbank-regs, icc-bridge,
  imx-serial, imx.epit, imx.gpt, imx_avic, imx_ccm, integrator_core,
  integrator_pic, integrator_pit, iommu, jazz-led, lan9118, lance,
  lm32-juart, lm32-pic, lm32-sys, lm32-timer, lm32-uart, m48t59,
  macio-ide, macio-nvram, macio_idreg, mainstone-fpga, memory,
  milkymist-ac97, milkymist-hpdmc, milkymist-memcard,
  milkymist-minimac2, milkymist-pfpu, milkymist-softusb,
  milkymist-sysctl, milkymist-tmu2, milkymist-uart, milkymist-vgafb,
  mips-malta, mipsnet, mmio-ide, mpc8544-guts, musicpal-misc,
  musicpal_gpio, musicpal_key, musicpal_lcd, mv88w8618_audio,
  mv88w8618_eth, mv88w8618_flashcfg, mv88w8618_pic, mv88w8618_pit,
  mv88w8618_wlan, omap-gpio, omap-intc, omap2-gpio, omap2-intc,
  omap_i2c, onenand, open_eth, openpic, openprom, pbm, pl011,
  pl011_luminary, pl022, pl050_keyboard, pl050_mouse, pl061,
  pl061_luminary, pl330, ppc4xx-pcihost, puv3_dma, puv3_gpio,
  puv3_intc, puv3_ost, puv3_pm, pxa25x-timer, pxa27x-timer,
  pxa2xx-dma, pxa2xx-gpio, pxa2xx-ssp, pxa2xx_i2c, pxa2xx_pic,
  pxa2xx_rtc, q35-pcihost, realview_gic, realview_mpcore,
  realview_pci, realview_sysctl, s390-sclp-event-facility, scoop,
  sh_pci, sl-nand, slavio_intctl, slavio_misc, slavio_timer,
  smc91c111, sp804, spapr-pci-host-bridge, sparc32_dma,
  spitz-keyboard, stellaris-adc, stellaris-gptm, stellaris-i2c,
  stellaris_enet, strongarm-gpio, strongarm-ppc, strongarm-rtc,
  strongarm-ssp, strongarm-uart, strongarm_pic, sysbus-ahci,
  sysbus-fdc, sysbus-g364, sysbus-ohci, tcx_afx, tegra2-ehci-usb,
  tusb6010, u3-agp-pcihost, uni-north-agp-pcihost,
  uni-north-internal-pci-pcihost, uni-north-pci-pcihost,
  versatile_i2c, versatile_pci, virtio-mmio, xgmac, xics,
  xilinx,zynq_slcr, xlnx,ps7-usb, xlnx.axi-dma, xlnx.ps7-qspi,
  xlnx.ps7-spi, xlnx.xps-ethernetlite, xlnx.xps-intc, xlnx.xps-spi,
  xlnx.xps-timer, xlnx.xps-uartlite

v3: address Eric Blake's and Marcel Apfelbaum's review
* Clean up a harmless editing accident in PATCH 07
* Simplify PATCH 10 slightly
v2: address Peter Maydell's review
* Some commit messages improved
* Use QOM cast macros instead of .parent_class [PATCH 05]
* keep cannot_instantiate_with_device_add_yet for port92, isa-pit,
  kvm-pit, m48t59_isa, mc146818rtc [PATCH 09]

Markus Armbruster (10):
  qdev: Replace no_user by cannot_instantiate_with_device_add_yet
  sysbus: Set cannot_instantiate_with_device_add_yet
  cpu: Document why cannot_instantiate_with_device_add_yet
  apic: Document why cannot_instantiate_with_device_add_yet
  pci-host: Consistently set cannot_instantiate_with_device_add_yet
  ich9: Document why cannot_instantiate_with_device_add_yet
  piix3 piix4: Clean 

[Qemu-devel] [PATCH v3 03/10] cpu: Document why cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 qom/cpu.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qom/cpu.c b/qom/cpu.c
index 09c15e6..6e0d54e 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -254,7 +254,11 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k-gdb_read_register = cpu_common_gdb_read_register;
 k-gdb_write_register = cpu_common_gdb_write_register;
 dc-realize = cpu_common_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/*
+ * Reason: CPUs still need special care by board code: wiring up
+ * IRQs, adding reset handlers, halting non-first CPUS, ...
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo cpu_type_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 02/10] sysbus: Set cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

device_add plugs devices into suitable bus.  For real buses, that
actually connects the device.  For sysbus, the connections need to be
made separately, and device_add can't do that.  The device would be
left unconnected, and could not possibly work.

Quite a few, but not all sysbus devices already set
cannot_instantiate_with_device_add_yet in their class init function.

Set it in their abstract base's class init function
sysbus_device_class_init(), and remove the now redundant assignments
from device class init functions.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/alpha/typhoon.c | 2 --
 hw/arm/versatilepb.c   | 1 -
 hw/audio/pl041.c   | 1 -
 hw/core/sysbus.c   | 7 +++
 hw/display/pl110.c | 1 -
 hw/dma/pl080.c | 1 -
 hw/i386/kvm/clock.c| 1 -
 hw/i386/kvmvapic.c | 1 -
 hw/intc/arm_gic.c  | 1 -
 hw/intc/arm_gic_common.c   | 1 -
 hw/intc/arm_gic_kvm.c  | 1 -
 hw/intc/ioapic_common.c| 1 -
 hw/intc/pl190.c| 1 -
 hw/isa/isa-bus.c   | 1 -
 hw/misc/arm_l2x0.c | 1 -
 hw/nvram/fw_cfg.c  | 1 -
 hw/pci-host/bonito.c   | 2 --
 hw/pci-host/grackle.c  | 2 --
 hw/pci-host/piix.c | 1 -
 hw/pci-host/prep.c | 1 -
 hw/ppc/spapr_vio.c | 2 --
 hw/s390x/ipl.c | 1 -
 hw/s390x/s390-virtio-bus.c | 2 --
 hw/s390x/virtio-ccw.c  | 2 --
 hw/sd/pl181.c  | 1 -
 hw/timer/arm_mptimer.c | 1 -
 hw/timer/hpet.c| 1 -
 hw/timer/pl031.c   | 1 -
 28 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 60987ed..71a5a37 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -934,11 +934,9 @@ static int typhoon_pcihost_init(SysBusDevice *dev)
 
 static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
 {
-DeviceClass *dc = DEVICE_CLASS(klass);
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index bb0c0ba..aef2bde 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,6 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 8ba661a..ed82be5 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -632,7 +632,6 @@ static void pl041_device_class_init(ObjectClass *klass, 
void *data)
 
 k-init = pl041_init;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = pl041_device_reset;
 dc-vmsd = vmstate_pl041;
 dc-props = pl041_device_properties;
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index b84cd4a..6e880a8 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -257,6 +257,13 @@ static void sysbus_device_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *k = DEVICE_CLASS(klass);
 k-init = sysbus_device_init;
 k-bus_type = TYPE_SYSTEM_BUS;
+/*
+ * device_add plugs devices into suitable bus.  For real buses,
+ * that actually connects the device.  For sysbus, the connections
+ * need to be made separately, and device_add can't do that.  The
+ * device would be left unconncected, and could not possibly work.
+ */
+k-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sysbus_device_type_info = {
diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 7ad5972..ab689e9 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -496,7 +496,6 @@ static void pl110_class_init(ObjectClass *klass, void *data)
 
 k-init = pl110_initfn;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl110;
 }
 
diff --git a/hw/dma/pl080.c b/hw/dma/pl080.c
index a515621..cb7bda9 100644
--- a/hw/dma/pl080.c
+++ b/hw/dma/pl080.c
@@ -381,7 +381,6 @@ static void pl080_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl080;
 }
 
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index abd2ce8..892aa02 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -114,7 +114,6 @@ static void kvmclock_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = kvmclock_realize;
-

[Qemu-devel] [PATCH v3 01/10] qdev: Replace no_user by cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

To protect users from such badness, DeviceClass member no_user used to
make device models unavailable with -device / device_add, but that
regressed in commit 18b6dad.  The device model is still omitted from
help, but is available anyway.

Attempts to fix the regression have been rejected with the argument
that the purpose of no_user isn't clear, and it's prone to misuse.

This commit clarifies no_user's purpose.  Anthony suggested to rename
it cannot_instantiate_with_device_add_yet_due_to_internal_bugs, which
I shorten somewhat to keep checkpatch happy.  While there, make it
bool.

Every use of cannot_instantiate_with_device_add_yet gets a FIXME
comment asking for rationale.  The next few commits will clean them
all up, either by providing a rationale, or by getting rid of the use.

With that done, the regression fix is hopefully acceptable.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/acpi/piix4.c|  2 +-
 hw/alpha/typhoon.c |  2 +-
 hw/arm/versatilepb.c   |  2 +-
 hw/audio/pcspk.c   |  2 +-
 hw/audio/pl041.c   |  2 +-
 hw/block/fdc.c |  2 +-
 hw/display/pl110.c |  2 +-
 hw/dma/pl080.c |  2 +-
 hw/i2c/smbus_ich9.c|  2 +-
 hw/i386/kvm/clock.c|  2 +-
 hw/i386/kvmvapic.c |  2 +-
 hw/i386/pc.c   |  2 +-
 hw/ide/piix.c  |  6 +++---
 hw/ide/via.c   |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/vmmouse.c |  2 +-
 hw/intc/apic_common.c  |  2 +-
 hw/intc/arm_gic.c  |  2 +-
 hw/intc/arm_gic_common.c   |  2 +-
 hw/intc/arm_gic_kvm.c  |  2 +-
 hw/intc/i8259_common.c |  2 +-
 hw/intc/ioapic_common.c|  2 +-
 hw/intc/pl190.c|  2 +-
 hw/isa/isa-bus.c   |  2 +-
 hw/isa/lpc_ich9.c  |  2 +-
 hw/isa/piix4.c |  2 +-
 hw/isa/vt82c686.c  |  2 +-
 hw/misc/arm_l2x0.c |  2 +-
 hw/misc/vmport.c   |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/bonito.c   |  4 ++--
 hw/pci-host/grackle.c  |  4 ++--
 hw/pci-host/piix.c |  8 
 hw/pci-host/prep.c |  4 ++--
 hw/ppc/spapr_vio.c |  2 +-
 hw/s390x/ipl.c |  2 +-
 hw/s390x/s390-virtio-bus.c |  2 +-
 hw/s390x/virtio-ccw.c  |  2 +-
 hw/sd/pl181.c  |  2 +-
 hw/timer/arm_mptimer.c |  2 +-
 hw/timer/hpet.c|  2 +-
 hw/timer/i8254_common.c|  2 +-
 hw/timer/m48t59.c  |  2 +-
 hw/timer/mc146818rtc.c |  2 +-
 hw/timer/pl031.c   |  2 +-
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  5 +++--
 qom/cpu.c  |  2 +-
 48 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b46bd5e..c29a703 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,7 +508,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
 }
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 59e1bb8..60987ed 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -938,7 +938,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index f7e8b7e..bb0c0ba 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,7 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 9004ce3..8e3e178 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,7 +192,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
 

[Qemu-devel] [PATCH v3 04/10] apic: Document why cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/intc/apic_common.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ea420c7..aaef054 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -386,9 +386,13 @@ static void apic_common_class_init(ObjectClass *klass, 
void *data)
 
 dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = apic_properties_common;
 idc-init = apic_init_common;
+/*
+ * Reason: APIC and CPU need to be wired up by
+ * x86_cpu_apic_create()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo apic_common_type = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 05/10] pci-host: Consistently set cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work.  Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.

Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless.  We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.

It's already set for Bonito, grackle, i440FX, and raven.  Document
why.

Set it for the others: dec-21154, e500-host-bridge, gt64120_pci, mch,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/mips/gt64xxx_pci.c   |  6 ++
 hw/pci-bridge/dec.c |  6 ++
 hw/pci-host/apb.c   |  6 ++
 hw/pci-host/bonito.c|  6 +-
 hw/pci-host/grackle.c   |  6 +-
 hw/pci-host/piix.c  |  6 +-
 hw/pci-host/ppce500.c   |  5 +
 hw/pci-host/prep.c  |  6 +-
 hw/pci-host/q35.c   |  5 +
 hw/pci-host/uninorth.c  | 24 
 hw/pci-host/versatile.c |  6 ++
 hw/ppc/ppc4xx_pci.c |  5 +
 hw/sh4/sh_pci.c |  6 ++
 13 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 3da2e67..6398514 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -1151,12 +1151,18 @@ static int gt64120_pci_init(PCIDevice *d)
 static void gt64120_pci_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = gt64120_pci_init;
 k-vendor_id = PCI_VENDOR_ID_MARVELL;
 k-device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
 k-revision = 0x10;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo gt64120_pci_info = {
diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index e5e3be8..a6ca940 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -116,6 +116,7 @@ static int dec_21154_pci_host_init(PCIDevice *d)
 static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = dec_21154_pci_host_init;
 k-vendor_id = PCI_VENDOR_ID_DEC;
@@ -123,6 +124,11 @@ static void dec_21154_pci_host_class_init(ObjectClass 
*klass, void *data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_PCI;
 k-is_bridge = 1;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo dec_21154_pci_host_info = {
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index 92f289f..1b399dd 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -516,11 +516,17 @@ static int pbm_pci_host_init(PCIDevice *d)
 static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = pbm_pci_host_init;
 k-vendor_id = PCI_VENDOR_ID_SUN;
 k-device_id = PCI_DEVICE_ID_SUN_SABRE;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pbm_pci_host_info = {
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index bfb9820..902441f 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -806,8 +806,12 @@ static void bonito_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x01;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_bonito;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo bonito_info = {
diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
index c178375..7d95821 100644
--- a/hw/pci-host/grackle.c
+++ b/hw/pci-host/grackle.c
@@ -130,7 +130,11 @@ static void grackle_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
 k-revision  = 0x00;
 k-class_id  = PCI_CLASS_BRIDGE_HOST;
-

[Qemu-devel] [PATCH v3 06/10] ich9: Document why cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

An ICH9 southbridge contains several PCI devices, some of them with
multiple functions.  We model each function as a separate qdev.  Two
of them need some special wiring set up in pc_q35_init() to work: the
LPC controller at 00:1f.0, and the SMBus controller at 00:1f.3.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/i2c/smbus_ich9.c | 6 +-
 hw/isa/lpc_ich9.c   | 7 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index c1ffa34..8d47eaf 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -97,11 +97,15 @@ static void ich9_smb_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_6;
 k-revision = ICH9_A2_SMB_REVISION;
 k-class_id = PCI_CLASS_SERIAL_SMBUS;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_ich9_smbus;
 dc-desc = ICH9 SMBUS Bridge;
 k-init = ich9_smbus_initfn;
 k-config_write = ich9_smbus_write_config;
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index ad841b5..d00d698 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -604,14 +604,17 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-reset = ich9_lpc_reset;
 k-init = ich9_lpc_initfn;
 dc-vmsd = vmstate_ich9_lpc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-config_write = ich9_lpc_config_write;
 dc-desc = ICH9 LPC bridge;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_8;
 k-revision = ICH9_A2_LPC_REVISION;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
-
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo ich9_lpc_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 10/10] qdev: Do not let the user try to device_add when it cannot work

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Such devices have always been unavailable and omitted from the list of
available devices shown by device_add help.  Until commit 18b6dad
silently broke the former, setting up nasty traps for unwary users,
like this one:

$ qemu-system-x86_64 -nodefaults -monitor stdio -display none
QEMU 1.6.50 monitor - type 'help' for more information
(qemu) device_add apic
Segmentation fault (core dumped)

I call that a regression.  Fix it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qdev-monitor.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index 36f6f09..d3d87a3 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,13 +477,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 }
 }
 
-if (!obj) {
+k = DEVICE_CLASS(obj);
+
+if (!k || k-cannot_instantiate_with_device_add_yet) {
 qerror_report(QERR_INVALID_PARAMETER_VALUE, driver, device type);
 return NULL;
 }
 
-k = DEVICE_CLASS(obj);
-
 /* find bus */
 path = qemu_opt_get(opts, bus);
 if (path != NULL) {
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 08/10] vt82c686: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

A VT82C686B southbridge has multiple functions.  We model each
function as a separate qdev.  One of them need some special wiring set
up in mips_fulong2e_init() to work: the ISA bridge at 05.0.

The IDE controller at 05.1 (via-ide) has always had
cannot_instantiate_with_device_add_yet set, but there is no obvious
reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/ide/via.c  | 1 -
 hw/isa/vt82c686.c | 6 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index b556c14..198123b 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -225,7 +225,6 @@ static void via_ide_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x06;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo via_ide_info = {
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 3e8ec80..ec7c259 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -480,8 +480,12 @@ static void via_class_init(ObjectClass *klass, void *data)
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 k-revision = 0x40;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_via;
+/*
+ * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
+ * e.g. by mips_fulong2e_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo via_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 07/10] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

A PIIX3/PIIX4 southbridge has multiple functions.  We model each
function as a separate qdev.  Two of them need some special wiring set
up in pc_init1() or mips_malta_init() to work: the ISA bridge at 01.0,
and the SMBus controller at 01.3.

The IDE controller at 01.1 (piix3-ide, piix3-ide-xen, piix4-ide) has
always had cannot_instantiate_with_device_add_yet set, but there is no
obvious reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/acpi/piix4.c|  6 +-
 hw/ide/piix.c  |  3 ---
 hw/isa/piix4.c |  6 +-
 hw/pci-host/piix.c | 12 ++--
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index c29a703..368a76b 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -508,9 +508,13 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_pm_info = {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 27b08e1..9b5960b 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -248,7 +248,6 @@ static void piix3_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix3_ide_info = {
@@ -267,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-unplug = pci_piix3_xen_ide_unplug;
 }
 
@@ -289,7 +287,6 @@ static void piix4_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix4_ide_info = {
diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index d9dac61..def6fe3 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -113,8 +113,12 @@ static void piix4_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_piix4;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 8089fd6..1526fd4 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -644,7 +644,6 @@ static void piix3_class_init(ObjectClass *klass, void *data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config;
@@ -652,6 +651,11 @@ static void piix3_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix3_info = {
@@ -668,7 +672,6 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config_xen;
@@ -676,6 +679,11 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 };
 
 static const TypeInfo piix3_xen_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 09/10] isa: Clean up use of cannot_instantiate_with_device_add_yet

2013-10-30 Thread armbru
From: Markus Armbruster arm...@redhat.com

Drop it when there's no obvious reason why device_add could not work.
Else keep and document why.

* isa-fdc: drop

* i8042: drop, even though its I/O base is hardcoded (because you
  could conceivably still add one to a board that has none), and even
  though PC board code wires up the A20 line (because that wiring is
  optional)

* port92: keep because it needs additional wiring by port92_init()

* mc146818rtc: keep because it needs to be wired up by rtc_init()

* m48t59_isa: keep because needs to be wired up by m48t59_init_isa()

* isa-pit, kvm-pit: keep (in their abstract base pic-common) because
  the PIT needs additional wiring by board code, depending on HPET
  presence

* pcspk: keep because of pointer property pit, and because realize
  sets global pcspk_state

* vmmouse: keep because of pointer property ps2_mouse

* vmport: keep because realize sets global port_state

* isa-i8259, kvm-i8259: keep (in their abstract base pic-common),
  because the PICs' IRQ input lines are set up by board code, and the
  wiring of the slave to the master is hard-coded in device model code

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/audio/pcspk.c| 3 ++-
 hw/block/fdc.c  | 1 -
 hw/i386/pc.c| 7 ++-
 hw/input/pckbd.c| 1 -
 hw/input/vmmouse.c  | 3 ++-
 hw/intc/i8259_common.c  | 8 +++-
 hw/misc/vmport.c| 3 ++-
 hw/timer/i8254_common.c | 7 ++-
 hw/timer/m48t59.c   | 3 ++-
 hw/timer/mc146818rtc.c  | 3 ++-
 10 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 8e3e178..f980d66 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,8 +192,9 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
+/* Reason: pointer property pit, realize sets global pcspk_state */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pcspk_info = {
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 86f4920..592b58f 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2234,7 +2234,6 @@ static void isabus_fdc_class_init(ObjectClass *klass, 
void *data)
 
 dc-realize = isabus_fdc_realize;
 dc-fw_name = fdc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = fdctrl_external_reset_isa;
 dc-vmsd = vmstate_isa_fdc;
 dc-props = isa_fdc_properties;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index fe33843..20402ba 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -544,10 +544,15 @@ static void port92_class_initfn(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-realize = port92_realizefn;
 dc-reset = port92_reset;
 dc-vmsd = vmstate_port92_isa;
+/*
+ * Reason: unlike ordinary ISA devices, this one needs additional
+ * wiring: its A20 output line needs to be wired up by
+ * port92_init().
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo port92_info = {
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index dee31a6..655b8c5 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -522,7 +522,6 @@ static void i8042_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = i8042_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_kbd_isa;
 }
 
diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c
index 600e4a2..6a50533 100644
--- a/hw/input/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -282,10 +282,11 @@ static void vmmouse_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = vmmouse_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = vmmouse_reset;
 dc-vmsd = vmstate_vmmouse;
 dc-props = vmmouse_properties;
+/* Reason: pointer property ps2_mouse */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo vmmouse_info = {
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index 2acdbfe..9d29399 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -135,9 +135,15 @@ static void pic_common_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-vmsd = vmstate_pic_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pic_properties_common;
 dc-realize = pic_common_realize;
+/*
+ * Reason: unlike ordinary ISA devices, the PICs need additional
+ * wiring: its IRQ input lines are set up by board code, and the
+ * wiring 

[Qemu-devel] [PATCH] trace-events: Clean up with scripts/cleanup-trace-events.pl again

2013-09-13 Thread armbru
From: Markus Armbruster arm...@redhat.com

Event qxl_render_blit_guest_primary_initialized is unused since commit
c58c7b9, drop it.

Commit 42e5b4c moved hw/ppc/xics.c to hw/intc/xics.c without updating
the comment in trace-events.

scripts/cleanup-trace-events.pl trace-events | diff trace-events is
now clean again.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 trace-events | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/trace-events b/trace-events
index d4dba24..9a1347b 100644
--- a/trace-events
+++ b/trace-events
@@ -1109,7 +1109,6 @@ qemu_spice_wakeup(uint32_t qid) %d
 qemu_spice_create_update(uint32_t left, uint32_t right, uint32_t top, uint32_t 
bottom) lr %d - %d,  tb - %d - %d
 
 # hw/display/qxl-render.c
-qxl_render_blit_guest_primary_initialized(void) 
 qxl_render_blit(int32_t stride, int32_t left, int32_t right, int32_t top, 
int32_t bottom) stride=%d [%d, %d, %d, %d]
 qxl_render_guest_primary_resized(int32_t width, int32_t height, int32_t 
stride, int32_t bytes_pp, int32_t bits_pp) %dx%d, stride %d, bpp %d, depth %d
 qxl_render_update_area_done(void *cookie) %p
@@ -1122,7 +1121,7 @@ spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned 
ioa, unsigned intr) q
 spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) 
@%PRIx64=%PRIx64 IRQ %u
 spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) %s PIN%d IRQ %u
 
-# hw/ppc/xics.c
+# hw/intc/xics.c
 xics_icp_check_ipi(int server, uint8_t mfrr) CPU %d can take IPI mfrr=%#x
 xics_icp_accept(uint32_t old_xirr, uint32_t new_xirr) icp_accept: XIRR 
%#PRIx32-%#PRIx32
 xics_icp_eoi(int server, uint32_t xirr, uint32_t new_xirr) icp_eoi: server %d 
given XIRR %#PRIx32 new XIRR %#PRIx32
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 0/2] tests: Fixes for in-tree build

2013-09-24 Thread armbru
From: Markus Armbruster arm...@redhat.com

Hasn't gotten maintainer attention for two months.  Retrying via
qemu-trivial.

v3: Trivially rebased
v2: Nominate for qemu-stable (Andreas)

Markus Armbruster (2):
  tests: Fix schema parser test for in-tree build
  tests: Update .gitignore for test-int128 and test-bitops

 tests/.gitignore | 3 +++
 tests/Makefile   | 8 
 2 files changed, 7 insertions(+), 4 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH v3 2/2] tests: Update .gitignore for test-int128 and test-bitops

2013-09-24 Thread armbru
From: Markus Armbruster arm...@redhat.com

Forgotten in commit 6046c62 and 3464700.

Cc: qemu-sta...@nongnu.org
Reviewed-by: Andreas Färber afaer...@suse.de
Reviewed-by: Laszlo Ersek ler...@redhat.com
Signed-off-by: Markus Armbruster arm...@redhat.com
---
 tests/.gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/.gitignore b/tests/.gitignore
index 75f06a1..425757c 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -5,9 +5,11 @@ check-qjson
 check-qlist
 check-qstring
 test-aio
+test-bitops
 test-throttle
 test-cutils
 test-hbitmap
+test-int128
 test-iov
 test-mul64
 test-qapi-types.[ch]
-- 
1.8.1.4




[Qemu-devel] [PATCH v3 1/2] tests: Fix schema parser test for in-tree build

2013-09-24 Thread armbru
From: Markus Armbruster arm...@redhat.com

Commit 4f193e3 added the test, but screwed up in-tree builds
(SRCDIR=.): the tests's output overwrites the expected output, and is
thus compared to itself.

Cc: qemu-sta...@nongnu.org
Reported-by: Laszlo Ersek ler...@redhat.com
Reviewed-by: Andreas Färber afaer...@suse.de
Reviewed-by: Laszlo Ersek ler...@redhat.com
Signed-off-by: Markus Armbruster arm...@redhat.com
---
 tests/.gitignore | 1 +
 tests/Makefile   | 8 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/.gitignore b/tests/.gitignore
index ae5280e..75f06a1 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -21,3 +21,4 @@ test-thread-pool
 test-x86-cpuid
 test-xbzrle
 *-test
+qapi-schema/*.test.*
diff --git a/tests/Makefile b/tests/Makefile
index 994fef1..915ae5e 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -261,10 +261,10 @@ check-tests/test-qapi.py: tests/test-qapi.py
 
 .PHONY: $(patsubst %, check-%, $(check-qapi-schema-y))
 $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: 
$(SRC_PATH)/%.json
-   $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) 
$(SRC_PATH)/tests/qapi-schema/test-qapi.py $^ $*.out 2$*.err; echo $$? 
$*.exit,   TEST  $*.out)
-   @diff -q $(SRC_PATH)/$*.out $*.out
-   @diff -q $(SRC_PATH)/$*.err $*.err
-   @diff -q $(SRC_PATH)/$*.exit $*.exit
+   $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) 
$(SRC_PATH)/tests/qapi-schema/test-qapi.py $^ $*.test.out 2$*.test.err; echo 
$$? $*.test.exit,   TEST  $*.out)
+   @diff -q $(SRC_PATH)/$*.out $*.test.out
+   @diff -q $(SRC_PATH)/$*.err $*.test.err
+   @diff -q $(SRC_PATH)/$*.exit $*.test.exit
 
 # Consolidated targets
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 0/9] Clean up IDE after completion of qdevification

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Obvious cleanups possible since we no longer have the special case of
a non-qdevified controller.

v2:
* Dropped PATCH 1/10 ide: Break all non-qdevified controllers
  Andreas qdevified them since; thanks!
* Series renamed from Drop code for non-qdevified IDE, and clean up
* Trivially rebased

Markus Armbruster (9):
  ide: Move IDEDevice pointer from IDEBus to IDEState
  ide: Use IDEState member dev for device connected test
  ide: Don't block-align IDEState member smart_selftest_data
  ide: Drop redundant IDEState member bs
  ide: Drop redundant IDEState geometry members
  ide: Drop redundant IDEState member version
  ide: Drop redundant IDEState member drive_serial_str
  ide: Drop redundant IDEState member model
  ide: Drop redundant IDEState member wwn

 hw/ide/ahci.c   |  19 +++--
 hw/ide/atapi.c  |  39 +
 hw/ide/core.c   | 235 +++-
 hw/ide/internal.h   |  15 +---
 hw/ide/macio.c  |  26 +++---
 hw/ide/microdrive.c |   2 +-
 hw/ide/piix.c   |   4 -
 hw/ide/qdev.c   |  50 ++-
 8 files changed, 181 insertions(+), 209 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH v2 3/9] ide: Don't block-align IDEState member smart_selftest_data

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

All uses are simple array subscripts.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 0022cc5..2ed7cb8 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2164,8 +2164,7 @@ static void ide_init1(IDEBus *bus, int unit)
 s-io_buffer = qemu_memalign(2048, s-io_buffer_total_len);
 memset(s-io_buffer, 0, s-io_buffer_total_len);
 
-s-smart_selftest_data = qemu_blockalign(s-bs, 512);
-memset(s-smart_selftest_data, 0, 512);
+s-smart_selftest_data = g_malloc0(512);
 
 s-sector_write_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
ide_sector_write_timer_cb, s);
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 1/9] ide: Move IDEDevice pointer from IDEBus to IDEState

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com


Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/core.c |  2 +-
 hw/ide/internal.h |  3 +--
 hw/ide/qdev.c | 12 +++-
 3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index e1f4c33..2d382b2 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -79,7 +79,7 @@ static void ide_identify(IDEState *s)
 {
 uint16_t *p;
 unsigned int oldsize;
-IDEDevice *dev = s-unit ? s-bus-slave : s-bus-master;
+IDEDevice *dev = s-dev;
 
 if (s-identify_set) {
memcpy(s-io_buffer, s-identify_data, sizeof(s-identify_data));
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 0567a52..908d91d 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -341,6 +341,7 @@ enum ide_dma_cmd {
 /* NOTE: IDEState represents in fact one drive */
 struct IDEState {
 IDEBus *bus;
+IDEDevice *dev;
 uint8_t unit;
 /* ide config */
 IDEDriveKind drive_kind;
@@ -447,8 +448,6 @@ struct IDEDMA {
 
 struct IDEBus {
 BusState qbus;
-IDEDevice *master;
-IDEDevice *slave;
 IDEState ifs[2];
 int bus_id;
 int max_units;
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 18c4b7e..6ea1698 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -76,7 +76,7 @@ static int ide_qdev_init(DeviceState *qdev)
 goto err;
 }
 if (dev-unit == -1) {
-dev-unit = bus-master ? 1 : 0;
+dev-unit = bus-ifs[0].dev ? 1 : 0;
 }
 
 if (dev-unit = bus-max_units) {
@@ -87,18 +87,12 @@ static int ide_qdev_init(DeviceState *qdev)
 
 switch (dev-unit) {
 case 0:
-if (bus-master) {
-error_report(IDE unit %d is in use, dev-unit);
-goto err;
-}
-bus-master = dev;
-break;
 case 1:
-if (bus-slave) {
+if (bus-ifs[dev-unit].dev) {
 error_report(IDE unit %d is in use, dev-unit);
 goto err;
 }
-bus-slave = dev;
+bus-ifs[dev-unit].dev = dev;
 break;
 default:
 error_report(Invalid IDE unit %d, dev-unit);
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 8/9] ide: Drop redundant IDEState member model

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

It's a copy of dev-serial.  The copy was needed for non-qdevified
controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only
cleared the copy of bs).  Begs the question whether stale data could
have been used after unplug.  As far as I can tell, the copy was used
only when the copy of bs was non-null, thus no bug there.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/core.c | 22 +++---
 hw/ide/internal.h |  2 --
 hw/ide/qdev.c | 16 +++-
 3 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 153e7cf..be5be61 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -99,7 +99,7 @@ static void ide_identify(IDEState *s)
 put_le16(p + 21, 512); /* cache size in sectors */
 put_le16(p + 22, 4); /* ecc bytes */
 padstr((char *)(p + 23), s-dev-version, 8); /* firmware version */
-padstr((char *)(p + 27), s-drive_model_str, 40); /* model */
+padstr((char *)(p + 27), s-dev-model, 40);  /* model */
 #if MAX_MULT_SECTORS  1
 put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
 #endif
@@ -203,7 +203,7 @@ static void ide_atapi_identify(IDEState *s)
 put_le16(p + 21, 512); /* cache size in sectors */
 put_le16(p + 22, 4); /* ecc bytes */
 padstr((char *)(p + 23), s-dev-version, 8); /* firmware version */
-padstr((char *)(p + 27), s-drive_model_str, 40); /* model */
+padstr((char *)(p + 27), s-dev-model, 40);  /* model */
 put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
 #ifdef USE_DMA_CDROM
 put_le16(p + 49, 1  9 | 1  8); /* DMA and LBA supported */
@@ -260,7 +260,7 @@ static void ide_cfata_identify(IDEState *s)
 padstr((char *)(p + 10), s-dev-serial, 20); /* serial number */
 put_le16(p + 22, 0x0004);  /* ECC bytes */
 padstr((char *) (p + 23), s-dev-version, 8); /* Firmware Revision */
-padstr((char *) (p + 27), s-drive_model_str, 40);/* Model number */
+padstr((char *) (p + 27), s-dev-model, 40);  /* Model number */
 #if MAX_MULT_SECTORS  1
 put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
 #else
@@ -2089,7 +2089,6 @@ static const BlockDevOps ide_cd_block_ops = {
 };
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   const char *model,
uint64_t wwn)
 {
 BlockDriverState *bs = s-dev-conf.bs;
@@ -2119,21 +2118,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
 return -1;
 }
 }
-if (model) {
-pstrcpy(s-drive_model_str, sizeof(s-drive_model_str), model);
-} else {
-switch (kind) {
-case IDE_CD:
-strcpy(s-drive_model_str, QEMU DVD-ROM);
-break;
-case IDE_CFATA:
-strcpy(s-drive_model_str, QEMU MICRODRIVE);
-break;
-default:
-strcpy(s-drive_model_str, QEMU HARDDISK);
-break;
-}
-}
 
 ide_reset(s);
 bdrv_iostatus_enable(bs);
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index f6b5b7a..c4a5773 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -350,7 +350,6 @@ struct IDEState {
 int identify_set;
 uint8_t identify_data[512];
 int drive_serial;
-char drive_model_str[41];
 uint64_t wwn;
 /* ide regs */
 uint8_t feature;
@@ -543,7 +542,6 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t 
val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   const char *model,
uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index c1a4cb6..915bc27 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -168,8 +168,22 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind 
kind)
 dev-version = g_strdup(qemu_get_version());
 }
 
+if (!dev-model) {
+switch (kind) {
+case IDE_CD:
+dev-model = g_strdup(QEMU DVD-ROM);
+break;
+case IDE_CFATA:
+dev-model = g_strdup(QEMU MICRODRIVE);
+break;
+default:
+dev-model = g_strdup(QEMU HARDDISK);
+break;
+}
+}
+
 if (ide_init_drive(s, kind,
-   dev-model, dev-wwn)  0) {
+   dev-wwn)  0) {
 return -1;
 }
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 4/9] ide: Drop redundant IDEState member bs

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

It's a copy of dev-conf.bs.  The copy was needed for non-qdevified
controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy.  We'll get back
to that in the next few commits.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/ahci.c | 11 +-
 hw/ide/atapi.c| 37 ++---
 hw/ide/core.c | 62 ++-
 hw/ide/internal.h |  3 +--
 hw/ide/macio.c| 26 ---
 hw/ide/piix.c |  4 
 hw/ide/qdev.c |  2 +-
 7 files changed, 76 insertions(+), 69 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index eb6a6fe..1afc37e 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -735,7 +735,7 @@ static void ncq_cb(void *opaque, int ret)
 DPRINTF(ncq_tfs-drive-port_no, NCQ transfer tag %d finished\n,
 ncq_tfs-tag);
 
-bdrv_acct_done(ncq_tfs-drive-port.ifs[0].bs, ncq_tfs-acct);
+bdrv_acct_done(ncq_tfs-drive-port.ifs[0].dev-conf.bs, ncq_tfs-acct);
 qemu_sglist_destroy(ncq_tfs-sglist);
 ncq_tfs-used = 0;
 }
@@ -746,6 +746,7 @@ static void process_ncq_command(AHCIState *s, int port, 
uint8_t *cmd_fis,
 NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
 uint8_t tag = ncq_fis-tag  3;
 NCQTransferState *ncq_tfs = s-dev[port].ncq_tfs[tag];
+BlockDriverState *bs = ncq_tfs-drive-port.ifs[0].dev-conf.bs;
 
 if (ncq_tfs-used) {
 /* error - already in use */
@@ -785,9 +786,9 @@ static void process_ncq_command(AHCIState *s, int port, 
uint8_t *cmd_fis,
 DPRINTF(port, tag %d aio read %PRId64\n,
 ncq_tfs-tag, ncq_tfs-lba);
 
-dma_acct_start(ncq_tfs-drive-port.ifs[0].bs, ncq_tfs-acct,
+dma_acct_start(bs, ncq_tfs-acct,
ncq_tfs-sglist, BDRV_ACCT_READ);
-ncq_tfs-aiocb = dma_bdrv_read(ncq_tfs-drive-port.ifs[0].bs,
+ncq_tfs-aiocb = dma_bdrv_read(bs,
ncq_tfs-sglist, ncq_tfs-lba,
ncq_cb, ncq_tfs);
 break;
@@ -798,9 +799,9 @@ static void process_ncq_command(AHCIState *s, int port, 
uint8_t *cmd_fis,
 DPRINTF(port, tag %d aio write %PRId64\n,
 ncq_tfs-tag, ncq_tfs-lba);
 
-dma_acct_start(ncq_tfs-drive-port.ifs[0].bs, ncq_tfs-acct,
+dma_acct_start(bs, ncq_tfs-acct,
ncq_tfs-sglist, BDRV_ACCT_WRITE);
-ncq_tfs-aiocb = dma_bdrv_write(ncq_tfs-drive-port.ifs[0].bs,
+ncq_tfs-aiocb = dma_bdrv_write(bs,
 ncq_tfs-sglist, ncq_tfs-lba,
 ncq_cb, ncq_tfs);
 break;
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index f7d2009..3dc2de0 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -106,18 +106,19 @@ static void cd_data_to_raw(uint8_t *buf, int lba)
 
 static int cd_read_sector(IDEState *s, int lba, uint8_t *buf, int sector_size)
 {
+BlockDriverState *bs = s-dev-conf.bs;
 int ret;
 
 switch(sector_size) {
 case 2048:
-bdrv_acct_start(s-bs, s-acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
-ret = bdrv_read(s-bs, (int64_t)lba  2, buf, 4);
-bdrv_acct_done(s-bs, s-acct);
+bdrv_acct_start(bs, s-acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ret = bdrv_read(bs, (int64_t)lba  2, buf, 4);
+bdrv_acct_done(bs, s-acct);
 break;
 case 2352:
-bdrv_acct_start(s-bs, s-acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
-ret = bdrv_read(s-bs, (int64_t)lba  2, buf + 16, 4);
-bdrv_acct_done(s-bs, s-acct);
+bdrv_acct_start(bs, s-acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+ret = bdrv_read(bs, (int64_t)lba  2, buf + 16, 4);
+bdrv_acct_done(bs, s-acct);
 if (ret  0)
 return ret;
 cd_data_to_raw(buf, lba);
@@ -253,7 +254,7 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int 
max_size)
 s-io_buffer_index = 0;
 
 if (s-atapi_dma) {
-bdrv_acct_start(s-bs, s-acct, size, BDRV_ACCT_READ);
+bdrv_acct_start(s-dev-conf.bs, s-acct, size, BDRV_ACCT_READ);
 s-status = READY_STAT | SEEK_STAT | DRQ_STAT;
 s-bus-dma-ops-start_dma(s-bus-dma, s,
ide_atapi_cmd_read_dma_cb);
@@ -349,13 +350,13 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int 
ret)
 s-bus-dma-iov.iov_len = n * 4 * 512;
 qemu_iovec_init_external(s-bus-dma-qiov, s-bus-dma-iov, 1);
 
-s-bus-dma-aiocb = bdrv_aio_readv(s-bs, (int64_t)s-lba  2,
+s-bus-dma-aiocb = bdrv_aio_readv(s-dev-conf.bs, (int64_t)s-lba  2,
s-bus-dma-qiov, n * 4,
ide_atapi_cmd_read_dma_cb, s);
 return;
 
 eot:
-bdrv_acct_done(s-bs, s-acct);
+bdrv_acct_done(s-dev-conf.bs, 

[Qemu-devel] [PATCH v2 5/9] ide: Drop redundant IDEState geometry members

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Members cylinders, heads, sectors, chs_trans are copies of
dev-conf.cyls, dev-conf.heads, dev-conf.secs, dev-chs_trans.
Copies were needed for non-qdevified controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copies (it only
cleared the copy of bs).  Begs the question whether stale data could
have been used after unplug.  As far as I can tell, the copies were
used only when the copy of bs was non-null, thus no bug there.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/core.c | 52 
 hw/ide/internal.h |  5 +
 hw/ide/qdev.c | 12 +---
 3 files changed, 30 insertions(+), 39 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 448dcbd..275df4b 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -89,11 +89,11 @@ static void ide_identify(IDEState *s)
 memset(s-io_buffer, 0, 512);
 p = (uint16_t *)s-io_buffer;
 put_le16(p + 0, 0x0040);
-put_le16(p + 1, s-cylinders);
-put_le16(p + 3, s-heads);
-put_le16(p + 4, 512 * s-sectors); /* XXX: retired, remove ? */
+put_le16(p + 1, s-dev-conf.cyls);
+put_le16(p + 3, s-dev-conf.heads);
+put_le16(p + 4, 512 * s-dev-conf.secs); /* XXX: retired, remove ? */
 put_le16(p + 5, 512); /* XXX: retired, remove ? */
-put_le16(p + 6, s-sectors);
+put_le16(p + 6, s-dev-conf.secs);
 padstr((char *)(p + 10), s-drive_serial_str, 20); /* serial number */
 put_le16(p + 20, 3); /* XXX: retired, remove ? */
 put_le16(p + 21, 512); /* cache size in sectors */
@@ -108,10 +108,10 @@ static void ide_identify(IDEState *s)
 put_le16(p + 51, 0x200); /* PIO transfer cycle */
 put_le16(p + 52, 0x200); /* DMA transfer cycle */
 put_le16(p + 53, 1 | (1  1) | (1  2)); /* words 54-58,64-70,88 are 
valid */
-put_le16(p + 54, s-cylinders);
-put_le16(p + 55, s-heads);
-put_le16(p + 56, s-sectors);
-oldsize = s-cylinders * s-heads * s-sectors;
+put_le16(p + 54, s-dev-conf.cyls);
+put_le16(p + 55, s-dev-conf.heads);
+put_le16(p + 56, s-dev-conf.secs);
+oldsize = s-dev-conf.cyls * s-dev-conf.heads * s-dev-conf.secs;
 put_le16(p + 57, oldsize);
 put_le16(p + 58, oldsize  16);
 if (s-mult_sectors)
@@ -249,12 +249,12 @@ static void ide_cfata_identify(IDEState *s)
 
 memset(p, 0, sizeof(s-identify_data));
 
-cur_sec = s-cylinders * s-heads * s-sectors;
+cur_sec = s-dev-conf.cyls * s-dev-conf.heads * s-dev-conf.secs;
 
 put_le16(p + 0, 0x848a);   /* CF Storage Card signature */
-put_le16(p + 1, s-cylinders); /* Default cylinders */
-put_le16(p + 3, s-heads); /* Default heads */
-put_le16(p + 6, s-sectors);   /* Default sectors per track */
+put_le16(p + 1, s-dev-conf.cyls); /* Default cylinders */
+put_le16(p + 3, s-dev-conf.heads);/* Default heads */
+put_le16(p + 6, s-dev-conf.secs); /* Default sectors per track */
 put_le16(p + 7, s-nb_sectors  16);  /* Sectors per card */
 put_le16(p + 8, s-nb_sectors);/* Sectors per card */
 padstr((char *)(p + 10), s-drive_serial_str, 20); /* serial number */
@@ -270,9 +270,9 @@ static void ide_cfata_identify(IDEState *s)
 put_le16(p + 51, 0x0002);  /* PIO cycle timing mode */
 put_le16(p + 52, 0x0001);  /* DMA cycle timing mode */
 put_le16(p + 53, 0x0003);  /* Translation params valid */
-put_le16(p + 54, s-cylinders);/* Current cylinders */
-put_le16(p + 55, s-heads);/* Current heads */
-put_le16(p + 56, s-sectors);  /* Current sectors */
+put_le16(p + 54, s-dev-conf.cyls);/* Current cylinders */
+put_le16(p + 55, s-dev-conf.heads);   /* Current heads */
+put_le16(p + 56, s-dev-conf.secs);/* Current sectors */
 put_le16(p + 57, cur_sec); /* Current capacity */
 put_le16(p + 58, cur_sec  16);   /* Current capacity */
 if (s-mult_sectors)   /* Multiple sector setting */
@@ -462,8 +462,10 @@ int64_t ide_get_sector(IDEState *s)
((int64_t) s-lcyl  8) | s-sector;
}
 } else {
-sector_num = ((s-hcyl  8) | s-lcyl) * s-heads * s-sectors +
-(s-select  0x0f) * s-sectors + (s-sector - 1);
+sector_num =
+(((s-hcyl  8) | s-lcyl) * s-dev-conf.heads
+ + (s-select  0x0f)) * s-dev-conf.secs
++ (s-sector - 1);
 }
 return sector_num;
 }
@@ -486,12 +488,12 @@ void ide_set_sector(IDEState *s, int64_t sector_num)
s-hob_hcyl = sector_num  40;
}
 } else {
-cyl = sector_num / (s-heads * s-sectors);
-r = sector_num % (s-heads * s-sectors);
+cyl = sector_num / (s-dev-conf.heads * s-dev-conf.secs);
+r = sector_num % 

[Qemu-devel] [PATCH v2 6/9] ide: Drop redundant IDEState member version

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

It's a copy of dev-version.  The copy was needed for non-qdevified
controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only
cleared the copy of bs).  Begs the question whether stale data could
have been used after unplug.  As far as I can tell, the copy was used
only when the copy of bs was non-null, thus no bug there.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/atapi.c|  2 +-
 hw/ide/core.c | 14 --
 hw/ide/internal.h |  3 +--
 hw/ide/qdev.c |  9 +
 4 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 3dc2de0..f20b3a6 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -634,7 +634,7 @@ static void cmd_inquiry(IDEState *s, uint8_t *buf)
 buf[7] = 0; /* reserved */
 padstr8(buf + 8, 8, QEMU);
 padstr8(buf + 16, 16, QEMU DVD-ROM);
-padstr8(buf + 32, 4, s-version);
+padstr8(buf + 32, 4, s-dev-version);
 ide_atapi_cmd_reply(s, 36, max_len);
 }
 
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 275df4b..31e696c 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -98,7 +98,7 @@ static void ide_identify(IDEState *s)
 put_le16(p + 20, 3); /* XXX: retired, remove ? */
 put_le16(p + 21, 512); /* cache size in sectors */
 put_le16(p + 22, 4); /* ecc bytes */
-padstr((char *)(p + 23), s-version, 8); /* firmware version */
+padstr((char *)(p + 23), s-dev-version, 8); /* firmware version */
 padstr((char *)(p + 27), s-drive_model_str, 40); /* model */
 #if MAX_MULT_SECTORS  1
 put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
@@ -202,7 +202,7 @@ static void ide_atapi_identify(IDEState *s)
 put_le16(p + 20, 3); /* buffer type */
 put_le16(p + 21, 512); /* cache size in sectors */
 put_le16(p + 22, 4); /* ecc bytes */
-padstr((char *)(p + 23), s-version, 8); /* firmware version */
+padstr((char *)(p + 23), s-dev-version, 8); /* firmware version */
 padstr((char *)(p + 27), s-drive_model_str, 40); /* model */
 put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
 #ifdef USE_DMA_CDROM
@@ -259,7 +259,7 @@ static void ide_cfata_identify(IDEState *s)
 put_le16(p + 8, s-nb_sectors);/* Sectors per card */
 padstr((char *)(p + 10), s-drive_serial_str, 20); /* serial number */
 put_le16(p + 22, 0x0004);  /* ECC bytes */
-padstr((char *) (p + 23), s-version, 8);  /* Firmware Revision */
+padstr((char *) (p + 23), s-dev-version, 8); /* Firmware Revision */
 padstr((char *) (p + 27), s-drive_model_str, 40);/* Model number */
 #if MAX_MULT_SECTORS  1
 put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
@@ -2089,7 +2089,7 @@ static const BlockDevOps ide_cd_block_ops = {
 };
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   const char *version, const char *serial, const char *model,
+   const char *serial, const char *model,
uint64_t wwn)
 {
 BlockDriverState *bs = s-dev-conf.bs;
@@ -2141,12 +2141,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
 }
 }
 
-if (version) {
-pstrcpy(s-version, sizeof(s-version), version);
-} else {
-pstrcpy(s-version, sizeof(s-version), qemu_get_version());
-}
-
 ide_reset(s);
 bdrv_iostatus_enable(bs);
 return 0;
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 7a39d44..4c0fb8e 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -372,7 +372,6 @@ struct IDEState {
 
 /* set for lba48 access */
 uint8_t lba48;
-char version[9];
 /* ATAPI specific */
 struct unreported_events events;
 uint8_t sense_key;
@@ -545,7 +544,7 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t 
val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   const char *version, const char *serial, const char *model,
+   const char *serial, const char *model,
uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index c233d66..0326360 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -160,14 +160,15 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind 
kind)
 return -1;
 }
 
+if (!dev-version) {
+dev-version = g_strdup(qemu_get_version());
+}
+
 if (ide_init_drive(s, kind,
-   dev-version, dev-serial, dev-model, dev-wwn)  0) {
+   dev-serial, dev-model, dev-wwn)  0) {
 return -1;
 }
 
-if (!dev-version) {
-dev-version = g_strdup(s-version);
-}
 if (!dev-serial) {
 dev-serial = g_strdup(s-drive_serial_str);
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 2/9] ide: Use IDEState member dev for device connected test

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Testing dev is more obvious than testing bs, in my opinion.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/ahci.c   |  8 
 hw/ide/core.c   | 56 -
 hw/ide/microdrive.c |  2 +-
 hw/ide/qdev.c   |  2 +-
 4 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index fbea9e8..eb6a6fe 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -85,7 +85,7 @@ static uint32_t  ahci_port_read(AHCIState *s, int port, int 
offset)
 val = pr-sig;
 break;
 case PORT_SCR_STAT:
-if (s-dev[port].port.ifs[0].bs) {
+if (s-dev[port].port.ifs[0].dev) {
 val = SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP |
   SATA_SCR_SSTATUS_SPD_GEN1 | SATA_SCR_SSTATUS_IPM_ACTIVE;
 } else {
@@ -497,7 +497,7 @@ static void ahci_reset_port(AHCIState *s, int port)
 d-init_d2h_sent = false;
 
 ide_state = s-dev[port].port.ifs[0];
-if (!ide_state-bs) {
+if (!ide_state-dev) {
 return;
 }
 
@@ -523,7 +523,7 @@ static void ahci_reset_port(AHCIState *s, int port)
 }
 
 s-dev[port].port_state = STATE_RUN;
-if (!ide_state-bs) {
+if (!ide_state-dev) {
 s-dev[port].port_regs.sig = 0;
 ide_state-status = SEEK_STAT | WRERR_STAT;
 } else if (ide_state-drive_kind == IDE_CD) {
@@ -851,7 +851,7 @@ static int handle_cmd(AHCIState *s, int port, int slot)
 /* The device we are working for */
 ide_state = s-dev[port].port.ifs[0];
 
-if (!ide_state-bs) {
+if (!ide_state-dev) {
 DPRINTF(port, error: guest accessed unused port);
 goto out;
 }
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 2d382b2..0022cc5 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -312,7 +312,7 @@ static void ide_set_signature(IDEState *s)
 if (s-drive_kind == IDE_CD) {
 s-lcyl = 0x14;
 s-hcyl = 0xeb;
-} else if (s-bs) {
+} else if (s-dev) {
 s-lcyl = 0;
 s-hcyl = 0;
 } else {
@@ -818,7 +818,7 @@ static void ide_flush_cb(void *opaque, int ret)
 
 void ide_flush_cache(IDEState *s)
 {
-if (s-bs == NULL) {
+if (!s-dev) {
 ide_flush_cb(s, 0);
 return;
 }
@@ -1022,7 +1022,7 @@ static bool cmd_data_set_management(IDEState *s, uint8_t 
cmd)
 {
 switch (s-feature) {
 case DSM_TRIM:
-if (s-bs) {
+if (s-dev) {
 ide_sector_start_dma(s, IDE_DMA_TRIM);
 return false;
 }
@@ -1035,7 +1035,7 @@ static bool cmd_data_set_management(IDEState *s, uint8_t 
cmd)
 
 static bool cmd_identify(IDEState *s, uint8_t cmd)
 {
-if (s-bs  s-drive_kind != IDE_CD) {
+if (s-dev  s-drive_kind != IDE_CD) {
 if (s-drive_kind != IDE_CFATA) {
 ide_identify(s);
 } else {
@@ -1085,7 +1085,7 @@ static bool cmd_read_multiple(IDEState *s, uint8_t cmd)
 {
 bool lba48 = (cmd == WIN_MULTREAD_EXT);
 
-if (!s-bs || !s-mult_sectors) {
+if (!s-dev || !s-mult_sectors) {
 ide_abort_command(s);
 return true;
 }
@@ -1101,7 +1101,7 @@ static bool cmd_write_multiple(IDEState *s, uint8_t cmd)
 bool lba48 = (cmd == WIN_MULTWRITE_EXT);
 int n;
 
-if (!s-bs || !s-mult_sectors) {
+if (!s-dev || !s-mult_sectors) {
 ide_abort_command(s);
 return true;
 }
@@ -1129,7 +1129,7 @@ static bool cmd_read_pio(IDEState *s, uint8_t cmd)
 return true;
 }
 
-if (!s-bs) {
+if (!s-dev) {
 ide_abort_command(s);
 return true;
 }
@@ -1145,7 +1145,7 @@ static bool cmd_write_pio(IDEState *s, uint8_t cmd)
 {
 bool lba48 = (cmd == WIN_WRITE_EXT);
 
-if (!s-bs) {
+if (!s-dev) {
 ide_abort_command(s);
 return true;
 }
@@ -1165,7 +1165,7 @@ static bool cmd_read_dma(IDEState *s, uint8_t cmd)
 {
 bool lba48 = (cmd == WIN_READDMA_EXT);
 
-if (!s-bs) {
+if (!s-dev) {
 ide_abort_command(s);
 return true;
 }
@@ -1180,7 +1180,7 @@ static bool cmd_write_dma(IDEState *s, uint8_t cmd)
 {
 bool lba48 = (cmd == WIN_WRITEDMA_EXT);
 
-if (!s-bs) {
+if (!s-dev) {
 ide_abort_command(s);
 return true;
 }
@@ -1231,7 +1231,7 @@ static bool cmd_set_features(IDEState *s, uint8_t cmd)
 {
 uint16_t *identify_data;
 
-if (!s-bs) {
+if (!s-dev) {
 ide_abort_command(s);
 return true;
 }
@@ -1710,8 +1710,9 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 #endif
 s = idebus_active_if(bus);
 /* ignore commands to non existent slave */
-if (s != bus-ifs  !s-bs)
+if (s != bus-ifs  !s-dev) {
 return;
+}
 
 /* Only DEVICE RESET is allowed while BSY or/and DRQ are set */
 if ((s-status  (BUSY_STAT|DRQ_STAT))  val != WIN_DEVICE_RESET)
@@ -1755,8 +1756,8 @@ uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
 ret = 0xff;
 break;
 case 1:
- 

[Qemu-devel] [PATCH v2 9/9] ide: Drop redundant IDEState member wwn

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

It's a copy of dev-wwn.  The copy was needed for non-qdevified
controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only
cleared the copy of bs).  Begs the question whether stale data could
have been used after unplug.  As far as I can tell, the copy was used
only when the copy of bs was non-null, thus no bug there.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/core.c | 18 --
 hw/ide/internal.h |  4 +---
 hw/ide/qdev.c |  3 +--
 3 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index be5be61..008d9bc 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -142,7 +142,7 @@ static void ide_identify(IDEState *s)
 /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
 put_le16(p + 83, (1  14) | (1  13) | (1 12) | (1  10));
 /* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */
-if (s-wwn) {
+if (s-dev-wwn) {
 put_le16(p + 84, (1  14) | (1  8) | 0);
 } else {
 put_le16(p + 84, (1  14) | 0);
@@ -156,7 +156,7 @@ static void ide_identify(IDEState *s)
 /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
 put_le16(p + 86, (1  13) | (1 12) | (1  10));
 /* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */
-if (s-wwn) {
+if (s-dev-wwn) {
 put_le16(p + 87, (1  14) | (1  8) | 0);
 } else {
 put_le16(p + 87, (1  14) | 0);
@@ -170,12 +170,12 @@ static void ide_identify(IDEState *s)
 
 if (dev  dev-conf.physical_block_size)
 put_le16(p + 106, 0x6000 | get_physical_block_exp(dev-conf));
-if (s-wwn) {
+if (s-dev-wwn) {
 /* LE 16-bit words 111-108 contain 64-bit World Wide Name */
-put_le16(p + 108, s-wwn  48);
-put_le16(p + 109, s-wwn  32);
-put_le16(p + 110, s-wwn  16);
-put_le16(p + 111, s-wwn);
+put_le16(p + 108, s-dev-wwn  48);
+put_le16(p + 109, s-dev-wwn  32);
+put_le16(p + 110, s-dev-wwn  16);
+put_le16(p + 111, s-dev-wwn);
 }
 if (dev  dev-conf.discard_granularity) {
 put_le16(p + 169, 1); /* TRIM support */
@@ -2088,8 +2088,7 @@ static const BlockDevOps ide_cd_block_ops = {
 .is_medium_locked = ide_cd_is_medium_locked,
 };
 
-int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   uint64_t wwn)
+int ide_init_drive(IDEState *s, IDEDriveKind kind)
 {
 BlockDriverState *bs = s-dev-conf.bs;
 uint64_t nb_sectors;
@@ -2098,7 +2097,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
 
 bdrv_get_geometry(bs, nb_sectors);
 s-nb_sectors = nb_sectors;
-s-wwn = wwn;
 /* The SMART values should be preserved across power cycles
but they aren't.  */
 s-smart_enabled = 1;
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index c4a5773..95ea75c 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -350,7 +350,6 @@ struct IDEState {
 int identify_set;
 uint8_t identify_data[512];
 int drive_serial;
-uint64_t wwn;
 /* ide regs */
 uint8_t feature;
 uint8_t error;
@@ -541,8 +540,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
-int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   uint64_t wwn);
+int ide_init_drive(IDEState *s, IDEDriveKind kind);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
 
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 915bc27..17404b8 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -182,8 +182,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
 }
 }
 
-if (ide_init_drive(s, kind,
-   dev-wwn)  0) {
+if (ide_init_drive(s, kind)  0) {
 return -1;
 }
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 7/9] ide: Drop redundant IDEState member drive_serial_str

2013-11-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

It's a copy of dev-serial.  The copy was needed for non-qdevified
controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only
cleared the copy of bs).  Begs the question whether stale data could
have been used after unplug.  As far as I can tell, the copy was used
only when the copy of bs was non-null, thus no bug there.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/ide/core.c | 14 --
 hw/ide/internal.h |  3 +--
 hw/ide/qdev.c | 10 +-
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 31e696c..153e7cf 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -94,7 +94,7 @@ static void ide_identify(IDEState *s)
 put_le16(p + 4, 512 * s-dev-conf.secs); /* XXX: retired, remove ? */
 put_le16(p + 5, 512); /* XXX: retired, remove ? */
 put_le16(p + 6, s-dev-conf.secs);
-padstr((char *)(p + 10), s-drive_serial_str, 20); /* serial number */
+padstr((char *)(p + 10), s-dev-serial, 20); /* serial number */
 put_le16(p + 20, 3); /* XXX: retired, remove ? */
 put_le16(p + 21, 512); /* cache size in sectors */
 put_le16(p + 22, 4); /* ecc bytes */
@@ -198,7 +198,7 @@ static void ide_atapi_identify(IDEState *s)
 p = (uint16_t *)s-io_buffer;
 /* Removable CDROM, 50us response, 12 byte packets */
 put_le16(p + 0, (2  14) | (5  8) | (1  7) | (2  5) | (0  0));
-padstr((char *)(p + 10), s-drive_serial_str, 20); /* serial number */
+padstr((char *)(p + 10), s-dev-serial, 20); /* serial number */
 put_le16(p + 20, 3); /* buffer type */
 put_le16(p + 21, 512); /* cache size in sectors */
 put_le16(p + 22, 4); /* ecc bytes */
@@ -257,7 +257,7 @@ static void ide_cfata_identify(IDEState *s)
 put_le16(p + 6, s-dev-conf.secs); /* Default sectors per track */
 put_le16(p + 7, s-nb_sectors  16);  /* Sectors per card */
 put_le16(p + 8, s-nb_sectors);/* Sectors per card */
-padstr((char *)(p + 10), s-drive_serial_str, 20); /* serial number */
+padstr((char *)(p + 10), s-dev-serial, 20); /* serial number */
 put_le16(p + 22, 0x0004);  /* ECC bytes */
 padstr((char *) (p + 23), s-dev-version, 8); /* Firmware Revision */
 padstr((char *) (p + 27), s-drive_model_str, 40);/* Model number */
@@ -2089,7 +2089,7 @@ static const BlockDevOps ide_cd_block_ops = {
 };
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   const char *serial, const char *model,
+   const char *model,
uint64_t wwn)
 {
 BlockDriverState *bs = s-dev-conf.bs;
@@ -2119,12 +2119,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
 return -1;
 }
 }
-if (serial) {
-pstrcpy(s-drive_serial_str, sizeof(s-drive_serial_str), serial);
-} else {
-snprintf(s-drive_serial_str, sizeof(s-drive_serial_str),
- QM%05d, s-drive_serial);
-}
 if (model) {
 pstrcpy(s-drive_model_str, sizeof(s-drive_model_str), model);
 } else {
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 4c0fb8e..f6b5b7a 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -350,7 +350,6 @@ struct IDEState {
 int identify_set;
 uint8_t identify_data[512];
 int drive_serial;
-char drive_serial_str[21];
 char drive_model_str[41];
 uint64_t wwn;
 /* ide regs */
@@ -544,7 +543,7 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t 
val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-   const char *serial, const char *model,
+   const char *model,
uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 0326360..c1a4cb6 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -160,19 +160,19 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind 
kind)
 return -1;
 }
 
+if (!dev-serial) {
+dev-serial = g_strdup_printf(QM%05d, s-drive_serial);
+}
+
 if (!dev-version) {
 dev-version = g_strdup(qemu_get_version());
 }
 
 if (ide_init_drive(s, kind,
-   dev-serial, dev-model, dev-wwn)  0) {
+   dev-model, dev-wwn)  0) {
 return -1;
 }
 
-if (!dev-serial) {
-dev-serial = g_strdup(s-drive_serial_str);
-}
-
 add_boot_device_path(dev-conf.bootindex, dev-qdev,
  dev-unit ? /disk@1 : /disk@0);
 
-- 
1.8.1.4




[Qemu-devel] [PATCH] trace-events: Clean up after removal of old usb-host code

2013-11-25 Thread armbru
From: Markus Armbruster arm...@redhat.com

Commit b5613fd neglected to drop the trace events along with the code.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 trace-events | 13 -
 1 file changed, 13 deletions(-)

diff --git a/trace-events b/trace-events
index 8695e9e..14c7c92 100644
--- a/trace-events
+++ b/trace-events
@@ -427,45 +427,32 @@ usb_uas_tmf_abort_task(int addr, uint16_t tag, uint16_t 
task_tag) dev %d, tag 0
 usb_uas_tmf_logical_unit_reset(int addr, uint16_t tag, int lun) dev %d, tag 
0x%x, lun %d
 usb_uas_tmf_unsupported(int addr, uint16_t tag, uint32_t function) dev %d, 
tag 0x%x, function 0x%x
 
-# hw/usb/host-linux.c
 # hw/usb/host-libusb.c
 usb_host_open_started(int bus, int addr) dev %d:%d
 usb_host_open_success(int bus, int addr) dev %d:%d
 usb_host_open_failure(int bus, int addr) dev %d:%d
-usb_host_disconnect(int bus, int addr) dev %d:%d
 usb_host_close(int bus, int addr) dev %d:%d
 usb_host_attach_kernel(int bus, int addr, int interface) dev %d:%d, if %d
 usb_host_detach_kernel(int bus, int addr, int interface) dev %d:%d, if %d
 usb_host_set_address(int bus, int addr, int config) dev %d:%d, address %d
 usb_host_set_config(int bus, int addr, int config) dev %d:%d, config %d
 usb_host_set_interface(int bus, int addr, int interface, int alt) dev %d:%d, 
interface %d, alt %d
-usb_host_claim_interfaces(int bus, int addr, int config, int nif) dev %d:%d, 
config %d, nif %d
 usb_host_claim_interface(int bus, int addr, int config, int interface) dev 
%d:%d, config %d, if %d
-usb_host_release_interfaces(int bus, int addr) dev %d:%d
 usb_host_release_interface(int bus, int addr, int interface) dev %d:%d, if %d
 usb_host_req_control(int bus, int addr, void *p, int req, int value, int 
index) dev %d:%d, packet %p, req 0x%x, value %d, index %d
 usb_host_req_data(int bus, int addr, void *p, int in, int ep, int size) dev 
%d:%d, packet %p, in %d, ep %d, size %d
 usb_host_req_complete(int bus, int addr, void *p, int status, int length) dev 
%d:%d, packet %p, status %d, length %d
 usb_host_req_emulated(int bus, int addr, void *p, int status) dev %d:%d, 
packet %p, status %d
 usb_host_req_canceled(int bus, int addr, void *p) dev %d:%d, packet %p
-usb_host_urb_submit(int bus, int addr, void *aurb, int length, int more) dev 
%d:%d, aurb %p, length %d, more %d
-usb_host_urb_complete(int bus, int addr, void *aurb, int status, int length, 
int more) dev %d:%d, aurb %p, status %d, length %d, more %d
-usb_host_urb_canceled(int bus, int addr, void *aurb) dev %d:%d, aurb %p
-usb_host_ep_set_halt(int bus, int addr, int ep) dev %d:%d, ep %d
-usb_host_ep_clear_halt(int bus, int addr, int ep) dev %d:%d, ep %d
 usb_host_iso_start(int bus, int addr, int ep) dev %d:%d, ep %d
 usb_host_iso_stop(int bus, int addr, int ep) dev %d:%d, ep %d
 usb_host_iso_out_of_bufs(int bus, int addr, int ep) dev %d:%d, ep %d
-usb_host_iso_many_urbs(int bus, int addr, int count) dev %d:%d, count %d
 usb_host_reset(int bus, int addr) dev %d:%d
 usb_host_auto_scan_enabled(void)
 usb_host_auto_scan_disabled(void)
-usb_host_claim_port(int bus, int hub, int port) bus %d, hub addr %d, port %d
-usb_host_parse_device(int bus, int addr, int vendor, int product) dev %d:%d, 
id %04x:%04x
 usb_host_parse_config(int bus, int addr, int value, int active) dev %d:%d, 
value %d, active %d
 usb_host_parse_interface(int bus, int addr, int num, int alt, int active) dev 
%d:%d, num %d, alt %d, active %d
 usb_host_parse_endpoint(int bus, int addr, int ep, const char *dir, const char 
*type, int active) dev %d:%d, ep %d, %s, %s, active %d
-usb_host_parse_unknown(int bus, int addr, int len, int type) dev %d:%d, len 
%d, type %d
 usb_host_parse_error(int bus, int addr, const char *errmsg) dev %d:%d, msg %s
 
 # hw/scsi/scsi-bus.c
-- 
1.8.1.4




[Qemu-devel] [PATCH] qdev-monitor: device_add crashes on non-device driver name, fix

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

Watch this:

$ upstream-qemu -nodefaults -S -display none -monitor stdio
QEMU 1.7.50 monitor - type 'help' for more information
(qemu) device_add rng-egd
/work/armbru/qemu/qdev-monitor.c:491:qdev_device_add: Object 0x2089b00 is 
not an instance of type device
Aborted (core dumped)

Crashes because rng-egd exists, but isn't a subtype of TYPE_DEVICE.
Broken in commit 18b6dad.

Cc: qemu-sta...@nongnu.org
Signed-off-by: Markus Armbruster arm...@redhat.com
---
 qdev-monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index dc37a43..90a0cea 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 }
 }
 
-if (!oc) {
+if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
 qerror_report(QERR_INVALID_PARAMETER_VALUE, driver, device type);
 return NULL;
 }
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 04/10] apic: Document why cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/intc/apic_common.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index ea420c7..aaef054 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -386,9 +386,13 @@ static void apic_common_class_init(ObjectClass *klass, 
void *data)
 
 dc-vmsd = vmstate_apic_common;
 dc-reset = apic_reset_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = apic_properties_common;
 idc-init = apic_init_common;
+/*
+ * Reason: APIC and CPU need to be wired up by
+ * x86_cpu_apic_create()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo apic_common_type = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 00/10] Clean up and fix no_user

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

We used to protect users from such badness by marking devices where
device_add cannot possibly work no-user, and refusing to device_add
them.  Anthony silently broke the protection in v1.1.  He has rejected
attempts to unbreak it with the argument that the protection makes it
impossible to wire devices together with configuration, not code, and
that the protection is being misused[*].

On the former, I disagree.  The problem isn't protecting users from
devices that cannot be wired up that way, it's devices that cannot be
wired up that way.

On the latter, Anthony has a point: the purpose of the no-user flag
isn't obvious, and some of its uses are suspect.

So, instead of just fixing the regression, this series first addresses
that point.  PATCH 1 clarifies the purpose of no-user.  PATCH 2-9
clean up and document its use.  PATCH 10 fixes the regression.

The series makes following devices available with device_add:
* PCI [PATCH 07-08]: piix3-ide, piix3-ide-xen, piix4-ide, via-ide
* ISA [PATCH 09]: i8042, isa-fdc

The following devices are made unavailable:
* PCI [PATCH 05]: dec-21154, e500-host-bridge, gt64120_pci, mch,
  pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
  uni-north-internal-pci, uni-north-pci, versatile_pci_host
* Sysbus [PATCH 02]: ARM,bitband-memory, SUNW,CS4231, SUNW,fdtwo,
  SUNW,tcx, a15mpcore_priv, a9-scu, a9mpcore_priv, apc,
  arm11mpcore_priv, cadence_gem, cadence_ttc, cadence_uart,
  cfi.pflash01, cfi.pflash02, cuda, dec-21154-sysbus, ds1225y,
  e500-ccsr, e500-pcihost, e500-spin, eccmemctl, empty_slot, escc,
  esp, etraxfs,pic, etraxfs,serial, etraxfs,timer, etraxfs-eth,
  exynos4210-ehci-usb, exynos4210.combiner, exynos4210.fimd,
  exynos4210.gic, exynos4210.i2c, exynos4210.irq_gate, exynos4210.mct,
  exynos4210.pmu, exynos4210.pwm, exynos4210.rtc, exynos4210.uart,
  fusbh200-ehci-usb, generic-sdhci, gpio_i2c, grlib,apbuart,
  grlib,gptimer, grlib,irqmp, gt64120, highbank-regs, icc-bridge,
  imx-serial, imx.epit, imx.gpt, imx_avic, imx_ccm, integrator_core,
  integrator_pic, integrator_pit, iommu, jazz-led, lan9118, lance,
  lm32-juart, lm32-pic, lm32-sys, lm32-timer, lm32-uart, m48t59,
  macio-ide, macio-nvram, macio_idreg, mainstone-fpga, memory,
  milkymist-ac97, milkymist-hpdmc, milkymist-memcard,
  milkymist-minimac2, milkymist-pfpu, milkymist-softusb,
  milkymist-sysctl, milkymist-tmu2, milkymist-uart, milkymist-vgafb,
  mips-malta, mipsnet, mmio-ide, mpc8544-guts, musicpal-misc,
  musicpal_gpio, musicpal_key, musicpal_lcd, mv88w8618_audio,
  mv88w8618_eth, mv88w8618_flashcfg, mv88w8618_pic, mv88w8618_pit,
  mv88w8618_wlan, omap-gpio, omap-intc, omap2-gpio, omap2-intc,
  omap_i2c, onenand, open_eth, openpic, openprom, pbm, pl011,
  pl011_luminary, pl022, pl050_keyboard, pl050_mouse, pl061,
  pl061_luminary, pl330, ppc4xx-pcihost, puv3_dma, puv3_gpio,
  puv3_intc, puv3_ost, puv3_pm, pxa25x-timer, pxa27x-timer,
  pxa2xx-dma, pxa2xx-gpio, pxa2xx-ssp, pxa2xx_i2c, pxa2xx_pic,
  pxa2xx_rtc, q35-pcihost, realview_gic, realview_mpcore,
  realview_pci, realview_sysctl, s390-sclp-event-facility, scoop,
  sh_pci, sl-nand, slavio_intctl, slavio_misc, slavio_timer,
  smc91c111, sp804, spapr-pci-host-bridge, sparc32_dma,
  spitz-keyboard, stellaris-adc, stellaris-gptm, stellaris-i2c,
  stellaris_enet, strongarm-gpio, strongarm-ppc, strongarm-rtc,
  strongarm-ssp, strongarm-uart, strongarm_pic, sysbus-ahci,
  sysbus-fdc, sysbus-g364, sysbus-ohci, tcx_afx, tegra2-ehci-usb,
  tusb6010, u3-agp-pcihost, uni-north-agp-pcihost,
  uni-north-internal-pci-pcihost, uni-north-pci-pcihost,
  versatile_i2c, versatile_pci, virtio-mmio, xgmac, xics,
  xilinx,zynq_slcr, xlnx,ps7-usb, xlnx.axi-dma, xlnx.ps7-qspi,
  xlnx.ps7-spi, xlnx.xps-ethernetlite, xlnx.xps-intc, xlnx.xps-spi,
  xlnx.xps-timer, xlnx.xps-uartlite

v4: straightforward rebase (only PATCH 10/10 conflicts)
v3: address Eric Blake's and Marcel Apfelbaum's review
* Clean up a harmless editing accident in PATCH 07
* Simplify PATCH 10 slightly
v2: address Peter Maydell's review
* Some commit messages improved
* Use QOM cast macros instead of .parent_class [PATCH 05]
* keep cannot_instantiate_with_device_add_yet for port92, isa-pit,
  kvm-pit, m48t59_isa, mc146818rtc [PATCH 09]

Markus Armbruster (10):
  qdev: Replace no_user by cannot_instantiate_with_device_add_yet
  sysbus: Set cannot_instantiate_with_device_add_yet
  cpu: Document why cannot_instantiate_with_device_add_yet
  apic: Document why cannot_instantiate_with_device_add_yet
  pci-host: Consistently set cannot_instantiate_with_device_add_yet
  ich9: Document why 

[Qemu-devel] [PATCH v4 06/10] ich9: Document why cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

An ICH9 southbridge contains several PCI devices, some of them with
multiple functions.  We model each function as a separate qdev.  Two
of them need some special wiring set up in pc_q35_init() to work: the
LPC controller at 00:1f.0, and the SMBus controller at 00:1f.3.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/i2c/smbus_ich9.c | 6 +-
 hw/isa/lpc_ich9.c   | 7 +--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c
index c1ffa34..8d47eaf 100644
--- a/hw/i2c/smbus_ich9.c
+++ b/hw/i2c/smbus_ich9.c
@@ -97,11 +97,15 @@ static void ich9_smb_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_6;
 k-revision = ICH9_A2_SMB_REVISION;
 k-class_id = PCI_CLASS_SERIAL_SMBUS;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_ich9_smbus;
 dc-desc = ICH9 SMBUS Bridge;
 k-init = ich9_smbus_initfn;
 k-config_write = ich9_smbus_write_config;
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 i2c_bus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base)
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index c1ca4d4..51ce12d 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -644,14 +644,17 @@ static void ich9_lpc_class_init(ObjectClass *klass, void 
*data)
 dc-reset = ich9_lpc_reset;
 k-init = ich9_lpc_initfn;
 dc-vmsd = vmstate_ich9_lpc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-config_write = ich9_lpc_config_write;
 dc-desc = ICH9 LPC bridge;
 k-vendor_id = PCI_VENDOR_ID_INTEL;
 k-device_id = PCI_DEVICE_ID_INTEL_ICH9_8;
 k-revision = ICH9_A2_LPC_REVISION;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
-
+/*
+ * Reason: part of ICH9 southbridge, needs to be wired up by
+ * pc_q35_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo ich9_lpc_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 08/10] vt82c686: Clean up use of cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

A VT82C686B southbridge has multiple functions.  We model each
function as a separate qdev.  One of them need some special wiring set
up in mips_fulong2e_init() to work: the ISA bridge at 05.0.

The IDE controller at 05.1 (via-ide) has always had
cannot_instantiate_with_device_add_yet set, but there is no obvious
reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 hw/ide/via.c  | 1 -
 hw/isa/vt82c686.c | 6 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index b556c14..198123b 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -225,7 +225,6 @@ static void via_ide_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x06;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo via_ide_info = {
diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index b06d15e..e639357 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -480,8 +480,12 @@ static void via_class_init(ObjectClass *klass, void *data)
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 k-revision = 0x40;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_via;
+/*
+ * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
+ * e.g. by mips_fulong2e_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo via_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 09/10] isa: Clean up use of cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

Drop it when there's no obvious reason why device_add could not work.
Else keep and document why.

* isa-fdc: drop

* i8042: drop, even though its I/O base is hardcoded (because you
  could conceivably still add one to a board that has none), and even
  though PC board code wires up the A20 line (because that wiring is
  optional)

* port92: keep because it needs additional wiring by port92_init()

* mc146818rtc: keep because it needs to be wired up by rtc_init()

* m48t59_isa: keep because needs to be wired up by m48t59_init_isa()

* isa-pit, kvm-pit: keep (in their abstract base pic-common) because
  the PIT needs additional wiring by board code, depending on HPET
  presence

* pcspk: keep because of pointer property pit, and because realize
  sets global pcspk_state

* vmmouse: keep because of pointer property ps2_mouse

* vmport: keep because realize sets global port_state

* isa-i8259, kvm-i8259: keep (in their abstract base pic-common),
  because the PICs' IRQ input lines are set up by board code, and the
  wiring of the slave to the master is hard-coded in device model code

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/audio/pcspk.c| 3 ++-
 hw/block/fdc.c  | 1 -
 hw/i386/pc.c| 7 ++-
 hw/input/pckbd.c| 1 -
 hw/input/vmmouse.c  | 3 ++-
 hw/intc/i8259_common.c  | 8 +++-
 hw/misc/vmport.c| 3 ++-
 hw/timer/i8254_common.c | 7 ++-
 hw/timer/m48t59.c   | 3 ++-
 hw/timer/mc146818rtc.c  | 3 ++-
 10 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 8e3e178..f980d66 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,8 +192,9 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
+/* Reason: pointer property pit, realize sets global pcspk_state */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pcspk_info = {
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 86f4920..592b58f 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2234,7 +2234,6 @@ static void isabus_fdc_class_init(ObjectClass *klass, 
void *data)
 
 dc-realize = isabus_fdc_realize;
 dc-fw_name = fdc;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = fdctrl_external_reset_isa;
 dc-vmsd = vmstate_isa_fdc;
 dc-props = isa_fdc_properties;
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 3b46d0e..f5759f9 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -547,10 +547,15 @@ static void port92_class_initfn(ObjectClass *klass, void 
*data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-realize = port92_realizefn;
 dc-reset = port92_reset;
 dc-vmsd = vmstate_port92_isa;
+/*
+ * Reason: unlike ordinary ISA devices, this one needs additional
+ * wiring: its A20 output line needs to be wired up by
+ * port92_init().
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo port92_info = {
diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c
index dee31a6..655b8c5 100644
--- a/hw/input/pckbd.c
+++ b/hw/input/pckbd.c
@@ -522,7 +522,6 @@ static void i8042_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = i8042_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_kbd_isa;
 }
 
diff --git a/hw/input/vmmouse.c b/hw/input/vmmouse.c
index 600e4a2..6a50533 100644
--- a/hw/input/vmmouse.c
+++ b/hw/input/vmmouse.c
@@ -282,10 +282,11 @@ static void vmmouse_class_initfn(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = vmmouse_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = vmmouse_reset;
 dc-vmsd = vmstate_vmmouse;
 dc-props = vmmouse_properties;
+/* Reason: pointer property ps2_mouse */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo vmmouse_info = {
diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c
index 2acdbfe..9d29399 100644
--- a/hw/intc/i8259_common.c
+++ b/hw/intc/i8259_common.c
@@ -135,9 +135,15 @@ static void pic_common_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-vmsd = vmstate_pic_common;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pic_properties_common;
 dc-realize = pic_common_realize;
+/*
+ * Reason: unlike ordinary ISA devices, the PICs need additional
+ * wiring: its IRQ input lines are set up by board code, and the
+ * wiring 

[Qemu-devel] [PATCH v4 02/10] sysbus: Set cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

device_add plugs devices into suitable bus.  For real buses, that
actually connects the device.  For sysbus, the connections need to be
made separately, and device_add can't do that.  The device would be
left unconnected, and could not possibly work.

Quite a few, but not all sysbus devices already set
cannot_instantiate_with_device_add_yet in their class init function.

Set it in their abstract base's class init function
sysbus_device_class_init(), and remove the now redundant assignments
from device class init functions.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/alpha/typhoon.c | 2 --
 hw/arm/versatilepb.c   | 1 -
 hw/audio/pl041.c   | 1 -
 hw/core/sysbus.c   | 7 +++
 hw/display/pl110.c | 1 -
 hw/dma/pl080.c | 1 -
 hw/i386/kvm/clock.c| 1 -
 hw/i386/kvmvapic.c | 1 -
 hw/intc/arm_gic.c  | 1 -
 hw/intc/arm_gic_common.c   | 1 -
 hw/intc/arm_gic_kvm.c  | 1 -
 hw/intc/ioapic_common.c| 1 -
 hw/intc/pl190.c| 1 -
 hw/isa/isa-bus.c   | 1 -
 hw/misc/arm_l2x0.c | 1 -
 hw/nvram/fw_cfg.c  | 1 -
 hw/pci-host/bonito.c   | 2 --
 hw/pci-host/grackle.c  | 2 --
 hw/pci-host/piix.c | 1 -
 hw/pci-host/prep.c | 1 -
 hw/ppc/spapr_vio.c | 2 --
 hw/s390x/ipl.c | 1 -
 hw/s390x/s390-virtio-bus.c | 2 --
 hw/s390x/virtio-ccw.c  | 2 --
 hw/sd/pl181.c  | 1 -
 hw/timer/arm_mptimer.c | 1 -
 hw/timer/hpet.c| 1 -
 hw/timer/pl031.c   | 1 -
 28 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 60987ed..71a5a37 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -934,11 +934,9 @@ static int typhoon_pcihost_init(SysBusDevice *dev)
 
 static void typhoon_pcihost_class_init(ObjectClass *klass, void *data)
 {
-DeviceClass *dc = DEVICE_CLASS(klass);
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index bb0c0ba..aef2bde 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,6 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pl041.c b/hw/audio/pl041.c
index 8ba661a..ed82be5 100644
--- a/hw/audio/pl041.c
+++ b/hw/audio/pl041.c
@@ -632,7 +632,6 @@ static void pl041_device_class_init(ObjectClass *klass, 
void *data)
 
 k-init = pl041_init;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-reset = pl041_device_reset;
 dc-vmsd = vmstate_pl041;
 dc-props = pl041_device_properties;
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 146f50a..ed0477b 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -257,6 +257,13 @@ static void sysbus_device_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *k = DEVICE_CLASS(klass);
 k-init = sysbus_device_init;
 k-bus_type = TYPE_SYSTEM_BUS;
+/*
+ * device_add plugs devices into suitable bus.  For real buses,
+ * that actually connects the device.  For sysbus, the connections
+ * need to be made separately, and device_add can't do that.  The
+ * device would be left unconncected, and could not possibly work.
+ */
+k-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sysbus_device_type_info = {
diff --git a/hw/display/pl110.c b/hw/display/pl110.c
index 7ad5972..ab689e9 100644
--- a/hw/display/pl110.c
+++ b/hw/display/pl110.c
@@ -496,7 +496,6 @@ static void pl110_class_init(ObjectClass *klass, void *data)
 
 k-init = pl110_initfn;
 set_bit(DEVICE_CATEGORY_DISPLAY, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl110;
 }
 
diff --git a/hw/dma/pl080.c b/hw/dma/pl080.c
index a515621..cb7bda9 100644
--- a/hw/dma/pl080.c
+++ b/hw/dma/pl080.c
@@ -381,7 +381,6 @@ static void pl080_class_init(ObjectClass *oc, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(oc);
 
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_pl080;
 }
 
diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index abd2ce8..892aa02 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -114,7 +114,6 @@ static void kvmclock_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc-realize = kvmclock_realize;
-

[Qemu-devel] [PATCH v4 03/10] cpu: Document why cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 qom/cpu.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/qom/cpu.c b/qom/cpu.c
index 09c15e6..6e0d54e 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -254,7 +254,11 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k-gdb_read_register = cpu_common_gdb_read_register;
 k-gdb_write_register = cpu_common_gdb_write_register;
 dc-realize = cpu_common_realizefn;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
+/*
+ * Reason: CPUs still need special care by board code: wiring up
+ * IRQs, adding reset handlers, halting non-first CPUS, ...
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo cpu_type_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 10/10] qdev: Do not let the user try to device_add when it cannot work

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

Such devices have always been unavailable and omitted from the list of
available devices shown by device_add help.  Until commit 18b6dad
silently broke the former, setting up nasty traps for unwary users,
like this one:

$ qemu-system-x86_64 -nodefaults -monitor stdio -display none
QEMU 1.6.50 monitor - type 'help' for more information
(qemu) device_add apic
Segmentation fault (core dumped)

I call that a regression.  Fix it.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 qdev-monitor.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/qdev-monitor.c b/qdev-monitor.c
index e6825ba..177b849 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -490,6 +490,11 @@ DeviceState *qdev_device_add(QemuOpts *opts)
 }
 
 dc = DEVICE_CLASS(oc);
+if (dc-cannot_instantiate_with_device_add_yet) {
+qerror_report(QERR_INVALID_PARAMETER_VALUE, driver,
+  pluggable device type);
+return NULL;
+}
 
 /* find bus */
 path = qemu_opt_get(opts, bus);
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 05/10] pci-host: Consistently set cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work.  Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.

Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless.  We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.

It's already set for Bonito, grackle, i440FX, and raven.  Document
why.

Set it for the others: dec-21154, e500-host-bridge, gt64120_pci, mch,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/mips/gt64xxx_pci.c   |  6 ++
 hw/pci-bridge/dec.c |  6 ++
 hw/pci-host/apb.c   |  6 ++
 hw/pci-host/bonito.c|  6 +-
 hw/pci-host/grackle.c   |  6 +-
 hw/pci-host/piix.c  |  6 +-
 hw/pci-host/ppce500.c   |  5 +
 hw/pci-host/prep.c  |  6 +-
 hw/pci-host/q35.c   |  5 +
 hw/pci-host/uninorth.c  | 24 
 hw/pci-host/versatile.c |  6 ++
 hw/ppc/ppc4xx_pci.c |  5 +
 hw/sh4/sh_pci.c |  6 ++
 13 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c
index 3da2e67..6398514 100644
--- a/hw/mips/gt64xxx_pci.c
+++ b/hw/mips/gt64xxx_pci.c
@@ -1151,12 +1151,18 @@ static int gt64120_pci_init(PCIDevice *d)
 static void gt64120_pci_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = gt64120_pci_init;
 k-vendor_id = PCI_VENDOR_ID_MARVELL;
 k-device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
 k-revision = 0x10;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo gt64120_pci_info = {
diff --git a/hw/pci-bridge/dec.c b/hw/pci-bridge/dec.c
index e5e3be8..a6ca940 100644
--- a/hw/pci-bridge/dec.c
+++ b/hw/pci-bridge/dec.c
@@ -116,6 +116,7 @@ static int dec_21154_pci_host_init(PCIDevice *d)
 static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = dec_21154_pci_host_init;
 k-vendor_id = PCI_VENDOR_ID_DEC;
@@ -123,6 +124,11 @@ static void dec_21154_pci_host_class_init(ObjectClass 
*klass, void *data)
 k-revision = 0x02;
 k-class_id = PCI_CLASS_BRIDGE_PCI;
 k-is_bridge = 1;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo dec_21154_pci_host_info = {
diff --git a/hw/pci-host/apb.c b/hw/pci-host/apb.c
index 92f289f..1b399dd 100644
--- a/hw/pci-host/apb.c
+++ b/hw/pci-host/apb.c
@@ -516,11 +516,17 @@ static int pbm_pci_host_init(PCIDevice *d)
 static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+DeviceClass *dc = DEVICE_CLASS(klass);
 
 k-init = pbm_pci_host_init;
 k-vendor_id = PCI_VENDOR_ID_SUN;
 k-device_id = PCI_DEVICE_ID_SUN_SABRE;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo pbm_pci_host_info = {
diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c
index bfb9820..902441f 100644
--- a/hw/pci-host/bonito.c
+++ b/hw/pci-host/bonito.c
@@ -806,8 +806,12 @@ static void bonito_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x01;
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 dc-desc = Host bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_bonito;
+/*
+ * PCI-facing part of the host bridge, not usable without the
+ * host-facing part, which can't be device_add'ed, yet.
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo bonito_info = {
diff --git a/hw/pci-host/grackle.c b/hw/pci-host/grackle.c
index c178375..7d95821 100644
--- a/hw/pci-host/grackle.c
+++ b/hw/pci-host/grackle.c
@@ -130,7 +130,11 @@ static void grackle_pci_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
 k-revision  = 0x00;
 k-class_id  = PCI_CLASS_BRIDGE_HOST;
-

[Qemu-devel] [PATCH v4 01/10] qdev: Replace no_user by cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

In an ideal world, machines can be built by wiring devices together
with configuration, not code.  Unfortunately, that's not the world we
live in right now.  We still have quite a few devices that need to be
wired up by code.  If you try to device_add such a device, it'll fail
in sometimes mysterious ways.  If you're lucky, you get an
unmysterious immediate crash.

To protect users from such badness, DeviceClass member no_user used to
make device models unavailable with -device / device_add, but that
regressed in commit 18b6dad.  The device model is still omitted from
help, but is available anyway.

Attempts to fix the regression have been rejected with the argument
that the purpose of no_user isn't clear, and it's prone to misuse.

This commit clarifies no_user's purpose.  Anthony suggested to rename
it cannot_instantiate_with_device_add_yet_due_to_internal_bugs, which
I shorten somewhat to keep checkpatch happy.  While there, make it
bool.

Every use of cannot_instantiate_with_device_add_yet gets a FIXME
comment asking for rationale.  The next few commits will clean them
all up, either by providing a rationale, or by getting rid of the use.

With that done, the regression fix is hopefully acceptable.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/acpi/piix4.c|  2 +-
 hw/alpha/typhoon.c |  2 +-
 hw/arm/versatilepb.c   |  2 +-
 hw/audio/pcspk.c   |  2 +-
 hw/audio/pl041.c   |  2 +-
 hw/block/fdc.c |  2 +-
 hw/display/pl110.c |  2 +-
 hw/dma/pl080.c |  2 +-
 hw/i2c/smbus_ich9.c|  2 +-
 hw/i386/kvm/clock.c|  2 +-
 hw/i386/kvmvapic.c |  2 +-
 hw/i386/pc.c   |  2 +-
 hw/ide/piix.c  |  6 +++---
 hw/ide/via.c   |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/vmmouse.c |  2 +-
 hw/intc/apic_common.c  |  2 +-
 hw/intc/arm_gic.c  |  2 +-
 hw/intc/arm_gic_common.c   |  2 +-
 hw/intc/arm_gic_kvm.c  |  2 +-
 hw/intc/i8259_common.c |  2 +-
 hw/intc/ioapic_common.c|  2 +-
 hw/intc/pl190.c|  2 +-
 hw/isa/isa-bus.c   |  2 +-
 hw/isa/lpc_ich9.c  |  2 +-
 hw/isa/piix4.c |  2 +-
 hw/isa/vt82c686.c  |  2 +-
 hw/misc/arm_l2x0.c |  2 +-
 hw/misc/vmport.c   |  2 +-
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/bonito.c   |  4 ++--
 hw/pci-host/grackle.c  |  4 ++--
 hw/pci-host/piix.c |  8 
 hw/pci-host/prep.c |  4 ++--
 hw/ppc/spapr_vio.c |  2 +-
 hw/s390x/ipl.c |  2 +-
 hw/s390x/s390-virtio-bus.c |  2 +-
 hw/s390x/virtio-ccw.c  |  2 +-
 hw/sd/pl181.c  |  2 +-
 hw/timer/arm_mptimer.c |  2 +-
 hw/timer/hpet.c|  2 +-
 hw/timer/i8254_common.c|  2 +-
 hw/timer/m48t59.c  |  2 +-
 hw/timer/mc146818rtc.c |  2 +-
 hw/timer/pl031.c   |  2 +-
 include/hw/qdev-core.h | 13 -
 qdev-monitor.c |  5 +++--
 qom/cpu.c  |  2 +-
 48 files changed, 69 insertions(+), 57 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 93849c8..dd11534 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -544,7 +544,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
 }
diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 59e1bb8..60987ed 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -938,7 +938,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = typhoon_pcihost_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo typhoon_pcihost_info = {
diff --git a/hw/arm/versatilepb.c b/hw/arm/versatilepb.c
index f7e8b7e..bb0c0ba 100644
--- a/hw/arm/versatilepb.c
+++ b/hw/arm/versatilepb.c
@@ -390,7 +390,7 @@ static void vpb_sic_class_init(ObjectClass *klass, void 
*data)
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
 
 k-init = vpb_sic_init;
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_vpb_sic;
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 9004ce3..8e3e178 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -192,7 +192,7 @@ static void pcspk_class_initfn(ObjectClass *klass, void 
*data)
 
 dc-realize = pcspk_realizefn;
 set_bit(DEVICE_CATEGORY_SOUND, dc-categories);
-dc-no_user = 1;
+dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-props = pcspk_properties;
 

[Qemu-devel] [PATCH v4 07/10] piix3 piix4: Clean up use of cannot_instantiate_with_device_add_yet

2013-11-28 Thread armbru
From: Markus Armbruster arm...@redhat.com

A PIIX3/PIIX4 southbridge has multiple functions.  We model each
function as a separate qdev.  Two of them need some special wiring set
up in pc_init1() or mips_malta_init() to work: the ISA bridge at 01.0,
and the SMBus controller at 01.3.

The IDE controller at 01.1 (piix3-ide, piix3-ide-xen, piix4-ide) has
always had cannot_instantiate_with_device_add_yet set, but there is no
obvious reason why device_add could not work for them.  Drop it.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Marcel Apfelbaum marce...@redhat.com
---
 hw/acpi/piix4.c|  6 +-
 hw/ide/piix.c  |  3 ---
 hw/isa/piix4.c |  6 +-
 hw/pci-host/piix.c | 12 ++--
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index dd11534..9e8a89c 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -544,9 +544,13 @@ static void piix4_pm_class_init(ObjectClass *klass, void 
*data)
 k-revision = 0x03;
 k-class_id = PCI_CLASS_BRIDGE_OTHER;
 dc-desc = PM;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_acpi;
 dc-props = piix4_pm_properties;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_pm_info = {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 27b08e1..9b5960b 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -248,7 +248,6 @@ static void piix3_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix3_ide_info = {
@@ -267,7 +266,6 @@ static void piix3_ide_xen_class_init(ObjectClass *klass, 
void *data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371SB_1;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-unplug = pci_piix3_xen_ide_unplug;
 }
 
@@ -289,7 +287,6 @@ static void piix4_ide_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB;
 k-class_id = PCI_CLASS_STORAGE_IDE;
 set_bit(DEVICE_CATEGORY_STORAGE, dc-categories);
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 }
 
 static const TypeInfo piix4_ide_info = {
diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c
index d9dac61..def6fe3 100644
--- a/hw/isa/piix4.c
+++ b/hw/isa/piix4.c
@@ -113,8 +113,12 @@ static void piix4_class_init(ObjectClass *klass, void 
*data)
 k-device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 dc-desc = ISA bridge;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 dc-vmsd = vmstate_piix4;
+/*
+ * Reason: part of PIIX4 southbridge, needs to be wired up,
+ * e.g. by mips_malta_init()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix4_info = {
diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 38ca7b7..a9351dd 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -653,7 +653,6 @@ static void piix3_class_init(ObjectClass *klass, void *data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config;
@@ -661,6 +660,11 @@ static void piix3_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo piix3_info = {
@@ -677,7 +681,6 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 
 dc-desc= ISA bridge;
 dc-vmsd= vmstate_piix3;
-dc-cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
 k-no_hotplug   = 1;
 k-init = piix3_initfn;
 k-config_write = piix3_write_config_xen;
@@ -685,6 +688,11 @@ static void piix3_xen_class_init(ObjectClass *klass, void 
*data)
 /* 82371SB PIIX3 PCI-to-ISA bridge (Step A1) */
 k-device_id= PCI_DEVICE_ID_INTEL_82371SB_0;
 k-class_id = PCI_CLASS_BRIDGE_ISA;
+/*
+ * Reason: part of PIIX3 southbridge, needs to be wired up by
+ * pc_piix.c's pc_init1()
+ */
+dc-cannot_instantiate_with_device_add_yet = true;
 };
 
 static const TypeInfo piix3_xen_info = {
-- 
1.8.1.4




[Qemu-devel] [PATCH 0/2] Pointer properties and device_add

2013-11-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Pointer properties can be set only by code, not by device_add.  A
device with a pointer property can't work with device_add only unless
the property may remain null.  cannot_instantiate_with_device_add_yet
needs to be set then.  PATCH 1/2 sets it when needed and else
documents why not.  PATCH 2/2 documents this for future users of
pointer properties.

This applies on top of my [PATCH v4 00/10] Clean up and fix no_user
series.

Markus Armbruster (2):
  hw: cannot_instantiate_with_device_add_yet due to pointer props
  qdev: Document that pointer properties kill device_add

 hw/audio/marvell_88w8618.c   |  2 ++
 hw/dma/sparc32_dma.c |  2 ++
 hw/gpio/omap_gpio.c  |  4 
 hw/i2c/omap_i2c.c|  2 ++
 hw/i2c/smbus_eeprom.c|  2 ++
 hw/intc/etraxfs_pic.c|  4 
 hw/intc/grlib_irqmp.c|  2 ++
 hw/intc/omap_intc.c  |  4 
 hw/net/etraxfs_eth.c |  2 ++
 hw/net/lance.c   |  2 ++
 include/hw/qdev-properties.h | 17 +
 11 files changed, 43 insertions(+)

-- 
1.8.1.4




[Qemu-devel] [PATCH 2/2] qdev: Document that pointer properties kill device_add

2013-11-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Ask users of DEFINE_PROP_PTR() to set
cannot_instantiate_with_device_add_yet, or explain why it's not
needed.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 include/hw/qdev-properties.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 692f82e..77c6f7c 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -122,8 +122,25 @@ extern PropertyInfo qdev_prop_arraylen;
 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)   \
 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
 
+/*
+ * Please avoid pointer properties.  If you must use them, you must
+ * cover them in their device's class init function as follows:
+ *
+ * - If the property must be set, the device cannot be used with
+ *   device_add, so add code like this:
+ *   |* Reason: pointer property NAME-OF-YOUR-PROP *|
+ *   DeviceClass *dc = DEVICE_CLASS(class);
+ *   dc-cannot_instantiate_with_device_add_yet = true;
+ *
+ * - If the property may safely remain null, document it like this:
+ *   |*
+ ** Note: pointer property interrupt_vector may remain null, thus
+ ** no need for dc-cannot_instantiate_with_device_add_yet = true;
+ **|
+ */
 #define DEFINE_PROP_PTR(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
+
 #define DEFINE_PROP_CHR(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
 #define DEFINE_PROP_STRING(_n, _s, _f) \
-- 
1.8.1.4




[Qemu-devel] [PATCH 1/2] hw: cannot_instantiate_with_device_add_yet due to pointer props

2013-11-29 Thread armbru
From: Markus Armbruster arm...@redhat.com

Pointer properties can be set only by code, not by device_add.  A
device with a pointer property can work with device_add only when the
property may remain null.

This is the case for property interrupt_vector of device
etraxfs,pic.  Add a comment there.

Set cannot_instantiate_with_device_add_yet for the other devices with
pointer properties, with a comment explaining why.

Juha Riihimäki and Peter Maydell deserve my thanks for making pointer
property must not remain null blatantly obvious in the OMAP devices.

Only device smbus-eeprom is actually changed.  The others are all
sysbus devices, which get cannot_instantiate_with_device_add_yet set
in their abstract base's class init function.  Setting it again in
their class init function is technically redundant, but serves as
insurance for when sysbus devices become available with device_add,
and as documentation.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/audio/marvell_88w8618.c | 2 ++
 hw/dma/sparc32_dma.c   | 2 ++
 hw/gpio/omap_gpio.c| 4 
 hw/i2c/omap_i2c.c  | 2 ++
 hw/i2c/smbus_eeprom.c  | 2 ++
 hw/intc/etraxfs_pic.c  | 4 
 hw/intc/grlib_irqmp.c  | 2 ++
 hw/intc/omap_intc.c| 4 
 hw/net/etraxfs_eth.c   | 2 ++
 hw/net/lance.c | 2 ++
 10 files changed, 26 insertions(+)

diff --git a/hw/audio/marvell_88w8618.c b/hw/audio/marvell_88w8618.c
index 97194ce..cdce238 100644
--- a/hw/audio/marvell_88w8618.c
+++ b/hw/audio/marvell_88w8618.c
@@ -288,6 +288,8 @@ static void mv88w8618_audio_class_init(ObjectClass *klass, 
void *data)
 dc-reset = mv88w8618_audio_reset;
 dc-vmsd = mv88w8618_audio_vmsd;
 dc-props = mv88w8618_audio_properties;
+/* Reason: pointer property wm8750 */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo mv88w8618_audio_info = {
diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index 2a92ffb..eac338f 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -304,6 +304,8 @@ static void sparc32_dma_class_init(ObjectClass *klass, void 
*data)
 dc-reset = dma_reset;
 dc-vmsd = vmstate_dma;
 dc-props = sparc32_dma_properties;
+/* Reason: pointer property iommu_opaque */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sparc32_dma_info = {
diff --git a/hw/gpio/omap_gpio.c b/hw/gpio/omap_gpio.c
index b8f572b..938782a 100644
--- a/hw/gpio/omap_gpio.c
+++ b/hw/gpio/omap_gpio.c
@@ -759,6 +759,8 @@ static void omap_gpio_class_init(ObjectClass *klass, void 
*data)
 k-init = omap_gpio_init;
 dc-reset = omap_gpif_reset;
 dc-props = omap_gpio_properties;
+/* Reason: pointer property clk */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo omap_gpio_info = {
@@ -788,6 +790,8 @@ static void omap2_gpio_class_init(ObjectClass *klass, void 
*data)
 k-init = omap2_gpio_init;
 dc-reset = omap2_gpif_reset;
 dc-props = omap2_gpio_properties;
+/* Reason: pointer properties iclk, fclk0, ..., fclk5 */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo omap2_gpio_info = {
diff --git a/hw/i2c/omap_i2c.c b/hw/i2c/omap_i2c.c
index f528b2b..2d8e2b7 100644
--- a/hw/i2c/omap_i2c.c
+++ b/hw/i2c/omap_i2c.c
@@ -475,6 +475,8 @@ static void omap_i2c_class_init(ObjectClass *klass, void 
*data)
 k-init = omap_i2c_init;
 dc-props = omap_i2c_properties;
 dc-reset = omap_i2c_reset;
+/* Reason: pointer properties iclk, fclk */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo omap_i2c_info = {
diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c
index 0154283..0218f8a 100644
--- a/hw/i2c/smbus_eeprom.c
+++ b/hw/i2c/smbus_eeprom.c
@@ -121,6 +121,8 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, 
void *data)
 sc-write_data = eeprom_write_data;
 sc-read_data = eeprom_read_data;
 dc-props = smbus_eeprom_properties;
+/* Reason: pointer property data */
+dc-cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo smbus_eeprom_info = {
diff --git a/hw/intc/etraxfs_pic.c b/hw/intc/etraxfs_pic.c
index e02da53..636262b 100644
--- a/hw/intc/etraxfs_pic.c
+++ b/hw/intc/etraxfs_pic.c
@@ -170,6 +170,10 @@ static void etraxfs_pic_class_init(ObjectClass *klass, 
void *data)
 
 k-init = etraxfs_pic_init;
 dc-props = etraxfs_pic_properties;
+/*
+ * Note: pointer property interrupt_vector may remain null, thus
+ * no need for dc-cannot_instantiate_with_device_add_yet = true;
+ */
 }
 
 static const TypeInfo etraxfs_pic_info = {
diff --git a/hw/intc/grlib_irqmp.c b/hw/intc/grlib_irqmp.c
index 42e00bc..d1813f7 100644
--- a/hw/intc/grlib_irqmp.c
+++ b/hw/intc/grlib_irqmp.c
@@ -355,6 +355,8 @@ static void grlib_irqmp_class_init(ObjectClass *klass, void 
*data)
 k-init = grlib_irqmp_init;
 dc-reset = grlib_irqmp_reset;
 dc-props = 

[Qemu-devel] [PATCH v4 0/6] Clean up bogus default boot order

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

The first five patches are admittedly related to the stated purpose of
this series pretty much only by I can't stand perpetuating this
stupid crap.  Max Filippov and Peter Maydell already cleaned up
Xtensa and ARM the same way.

v4:
* Rebase
v3:
* Rebase
* Don't screw up default CPU model for machine isapc in 1/6
v2:
* Straightforward rebase
* PATCH 6 improved commit message (Alex)

Markus Armbruster (6):
  pc: Don't prematurely explode QEMUMachineInitArgs
  pc: Don't explode QEMUMachineInitArgs into local variables needlessly
  sun4: Don't prematurely explode QEMUMachineInitArgs
  ppc: Don't explode QEMUMachineInitArgs into local variables needlessly
  ppc: Don't duplicate QEMUMachineInitArgs in PPCE500Params
  hw: Clean up bogus default boot order

 hw/alpha/dp264.c |   1 -
 hw/arm/collie.c  |   1 -
 hw/arm/exynos4_boards.c  |   2 -
 hw/arm/gumstix.c |   2 -
 hw/arm/highbank.c|   2 -
 hw/arm/integratorcp.c|   1 -
 hw/arm/kzm.c |   1 -
 hw/arm/mainstone.c   |   1 -
 hw/arm/musicpal.c|   1 -
 hw/arm/nseries.c |   6 +-
 hw/arm/omap_sx1.c|   2 -
 hw/arm/palm.c|   1 -
 hw/arm/realview.c|   4 -
 hw/arm/spitz.c   |   4 -
 hw/arm/stellaris.c   |   2 -
 hw/arm/tosa.c|   1 -
 hw/arm/versatilepb.c |   2 -
 hw/arm/vexpress.c|   2 -
 hw/arm/xilinx_zynq.c |   1 -
 hw/arm/z2.c  |   1 -
 hw/core/null-machine.c   |   1 -
 hw/cris/axis_dev88.c |   1 -
 hw/i386/pc_piix.c|  95 --
 hw/i386/pc_q35.c |  28 +++
 hw/i386/xen_machine_pv.c |   1 -
 hw/lm32/lm32_boards.c|   2 -
 hw/lm32/milkymist.c  |   1 -
 hw/m68k/an5206.c |   1 -
 hw/m68k/dummy_m68k.c |   1 -
 hw/m68k/mcf5208.c|   1 -
 hw/microblaze/petalogix_ml605_mmu.c  |   1 -
 hw/microblaze/petalogix_s3adsp1800_mmu.c |   1 -
 hw/mips/mips_fulong2e.c  |   1 -
 hw/mips/mips_jazz.c  |   2 -
 hw/mips/mips_malta.c |   1 -
 hw/mips/mips_mipssim.c   |   1 -
 hw/mips/mips_r4k.c   |   1 -
 hw/openrisc/openrisc_sim.c   |   1 -
 hw/ppc/e500.c|  35 +
 hw/ppc/e500.h|  13 +--
 hw/ppc/e500plat.c|  15 +---
 hw/ppc/mac_newworld.c|   4 +-
 hw/ppc/mac_oldworld.c|   4 +-
 hw/ppc/mpc8544ds.c   |  15 +---
 hw/ppc/ppc405_boards.c   |   2 -
 hw/ppc/ppc440_bamboo.c   |   1 -
 hw/ppc/prep.c|   4 +-
 hw/ppc/spapr.c   |   4 +-
 hw/ppc/virtex_ml507.c|   1 -
 hw/s390x/s390-virtio-ccw.c   |   1 -
 hw/s390x/s390-virtio.c   |   1 -
 hw/sh4/r2d.c |   1 -
 hw/sh4/shix.c|   1 -
 hw/sparc/leon3.c |   1 -
 hw/sparc/sun4m.c | 131 ---
 hw/sparc64/sun4u.c   |  58 +-
 hw/unicore32/puv3.c  |   1 -
 hw/xtensa/xtensa_lx60.c  |   2 -
 hw/xtensa/xtensa_sim.c   |   1 -
 include/hw/boards.h  |   7 +-
 vl.c |   4 +-
 61 files changed, 133 insertions(+), 353 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH v4 4/6] ppc: Don't explode QEMUMachineInitArgs into local variables needlessly

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Don't explode when the variable is used just once, and never changed.

Signed-off-by: Markus Armbruster arm...@redhat.com
Acked-by: Alexander Graf ag...@suse.de
---
 hw/ppc/e500plat.c  | 18 ++
 hw/ppc/mpc8544ds.c | 18 ++
 2 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/hw/ppc/e500plat.c b/hw/ppc/e500plat.c
index c852995..a78de07 100644
--- a/hw/ppc/e500plat.c
+++ b/hw/ppc/e500plat.c
@@ -30,19 +30,13 @@ static void e500plat_fixup_devtree(PPCE500Params *params, 
void *fdt)
 
 static void e500plat_init(QEMUMachineInitArgs *args)
 {
-ram_addr_t ram_size = args-ram_size;
-const char *boot_device = args-boot_device;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
 PPCE500Params params = {
-.ram_size = ram_size,
-.boot_device = boot_device,
-.kernel_filename = kernel_filename,
-.kernel_cmdline = kernel_cmdline,
-.initrd_filename = initrd_filename,
-.cpu_model = cpu_model,
+.ram_size = args-ram_size,
+.boot_device = args-boot_device,
+.kernel_filename = args-kernel_filename,
+.kernel_cmdline = args-kernel_cmdline,
+.initrd_filename = args-initrd_filename,
+.cpu_model = args-cpu_model,
 .pci_first_slot = 0x1,
 .pci_nr_slots = PCI_SLOT_MAX - 1,
 .fixup_devtree = e500plat_fixup_devtree,
diff --git a/hw/ppc/mpc8544ds.c b/hw/ppc/mpc8544ds.c
index 444da02..4e551af 100644
--- a/hw/ppc/mpc8544ds.c
+++ b/hw/ppc/mpc8544ds.c
@@ -28,19 +28,13 @@ static void mpc8544ds_fixup_devtree(PPCE500Params *params, 
void *fdt)
 
 static void mpc8544ds_init(QEMUMachineInitArgs *args)
 {
-ram_addr_t ram_size = args-ram_size;
-const char *boot_device = args-boot_device;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
 PPCE500Params params = {
-.ram_size = ram_size,
-.boot_device = boot_device,
-.kernel_filename = kernel_filename,
-.kernel_cmdline = kernel_cmdline,
-.initrd_filename = initrd_filename,
-.cpu_model = cpu_model,
+.ram_size = args-ram_size,
+.boot_device = args-boot_device,
+.kernel_filename = args-kernel_filename,
+.kernel_cmdline = args-kernel_cmdline,
+.initrd_filename = args-initrd_filename,
+.cpu_model = args-cpu_model,
 .pci_first_slot = 0x11,
 .pci_nr_slots = 2,
 .fixup_devtree = mpc8544ds_fixup_devtree,
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 2/6] pc: Don't explode QEMUMachineInitArgs into local variables needlessly

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Don't explode when the variable is used just a few times, and never
changed.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/i386/pc_q35.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 10e770e..f636c65 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -52,12 +52,6 @@ static bool has_pci_info = true;
 /* PC hardware initialisation */
 static void pc_q35_init(QEMUMachineInitArgs *args)
 {
-ram_addr_t ram_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
-const char *boot_device = args-boot_device;
 ram_addr_t below_4g_mem_size, above_4g_mem_size;
 Q35PCIHost *q35_host;
 PCIHostState *phb;
@@ -85,17 +79,17 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 object_property_add_child(qdev_get_machine(), icc-bridge,
   OBJECT(icc_bridge), NULL);
 
-pc_cpus_init(cpu_model, icc_bridge);
+pc_cpus_init(args-cpu_model, icc_bridge);
 pc_acpi_init(q35-acpi-dsdt.aml);
 
 kvmclock_create();
 
-if (ram_size = 0xb000) {
-above_4g_mem_size = ram_size - 0xb000;
+if (args-ram_size = 0xb000) {
+above_4g_mem_size = args-ram_size - 0xb000;
 below_4g_mem_size = 0xb000;
 } else {
 above_4g_mem_size = 0;
-below_4g_mem_size = ram_size;
+below_4g_mem_size = args-ram_size;
 }
 
 /* pci enabled */
@@ -114,8 +108,10 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
-pc_memory_init(get_system_memory(), kernel_filename, kernel_cmdline,
-   initrd_filename, below_4g_mem_size, above_4g_mem_size,
+pc_memory_init(get_system_memory(),
+   args-kernel_filename, args-kernel_cmdline,
+   args-initrd_filename,
+   below_4g_mem_size, above_4g_mem_size,
rom_memory, ram_memory, guest_info);
 }
 
@@ -203,7 +199,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 0xb100),
   8, NULL, 0);
 
-pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
+pc_cmos_init(below_4g_mem_size, above_4g_mem_size, args-boot_device,
  floppy, idebus[0], idebus[1], rtc_state);
 
 /* the rest devices to which pci devfn is automatically assigned */
-- 
1.8.1.4




[Qemu-devel] [PATCH v4 1/6] pc: Don't prematurely explode QEMUMachineInitArgs

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Don't explode QEMUMachineInitArgs before passing it to pc_init1().

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/i386/pc_piix.c | 65 ++-
 1 file changed, 16 insertions(+), 49 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6e1e654..2ae7f95 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -60,14 +60,9 @@ static bool has_pvpanic;
 static bool has_pci_info = true;
 
 /* PC hardware initialisation */
-static void pc_init1(MemoryRegion *system_memory,
+static void pc_init1(QEMUMachineInitArgs *args,
+ MemoryRegion *system_memory,
  MemoryRegion *system_io,
- ram_addr_t ram_size,
- const char *boot_device,
- const char *kernel_filename,
- const char *kernel_cmdline,
- const char *initrd_filename,
- const char *cpu_model,
  int pci_enabled,
  int kvmclock_enabled)
 {
@@ -102,18 +97,18 @@ static void pc_init1(MemoryRegion *system_memory,
 object_property_add_child(qdev_get_machine(), icc-bridge,
   OBJECT(icc_bridge), NULL);
 
-pc_cpus_init(cpu_model, icc_bridge);
+pc_cpus_init(args-cpu_model, icc_bridge);
 
 if (kvm_enabled()  kvmclock_enabled) {
 kvmclock_create();
 }
 
-if (ram_size = 0xe000 ) {
-above_4g_mem_size = ram_size - 0xe000;
+if (args-ram_size = 0xe000) {
+above_4g_mem_size = args-ram_size - 0xe000;
 below_4g_mem_size = 0xe000;
 } else {
 above_4g_mem_size = 0;
-below_4g_mem_size = ram_size;
+below_4g_mem_size = args-ram_size;
 }
 
 if (pci_enabled) {
@@ -132,7 +127,8 @@ static void pc_init1(MemoryRegion *system_memory,
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
 fw_cfg = pc_memory_init(system_memory,
-   kernel_filename, kernel_cmdline, initrd_filename,
+   args-kernel_filename, args-kernel_cmdline,
+   args-initrd_filename,
below_4g_mem_size, above_4g_mem_size,
rom_memory, ram_memory, guest_info);
 }
@@ -148,7 +144,7 @@ static void pc_init1(MemoryRegion *system_memory,
 
 if (pci_enabled) {
 pci_bus = i440fx_init(i440fx_state, piix3_devfn, isa_bus, gsi,
-  system_memory, system_io, ram_size,
+  system_memory, system_io, args-ram_size,
   below_4g_mem_size,
   0x1ULL - below_4g_mem_size,
   above_4g_mem_size,
@@ -207,7 +203,7 @@ static void pc_init1(MemoryRegion *system_memory,
 }
 }
 
-pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
+pc_cmos_init(below_4g_mem_size, above_4g_mem_size, args-boot_device,
  floppy, idebus[0], idebus[1], rtc_state);
 
 if (pci_enabled  usb_enabled(false)) {
@@ -236,17 +232,7 @@ static void pc_init1(MemoryRegion *system_memory,
 
 static void pc_init_pci(QEMUMachineInitArgs *args)
 {
-ram_addr_t ram_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
-const char *boot_device = args-boot_device;
-pc_init1(get_system_memory(),
- get_system_io(),
- ram_size, boot_device,
- kernel_filename, kernel_cmdline,
- initrd_filename, cpu_model, 1, 1);
+pc_init1(args, get_system_memory(), get_system_io(), 1, 1);
 }
 
 static void pc_init_pci_1_6(QEMUMachineInitArgs *args)
@@ -291,40 +277,21 @@ static void pc_init_pci_1_0(QEMUMachineInitArgs *args)
 /* PC init function for pc-0.10 to pc-0.13, and reused by xenfv */
 static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs *args)
 {
-ram_addr_t ram_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
-const char *boot_device = args-boot_device;
 has_pci_info = false;
 disable_kvm_pv_eoi();
 enable_compat_apic_id_mode();
-pc_init1(get_system_memory(),
- get_system_io(),
- ram_size, boot_device,
- kernel_filename, kernel_cmdline,
- initrd_filename, cpu_model, 1, 0);
+pc_init1(args, get_system_memory(), get_system_io(), 1, 0);
 }
 
 static void pc_init_isa(QEMUMachineInitArgs *args)
 {
-ram_addr_t ram_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = 

[Qemu-devel] [PATCH v4 3/6] sun4: Don't prematurely explode QEMUMachineInitArgs

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Don't explode QEMUMachineInitArgs before passing it to
sun4m_hw_init(), sun4uv_init().

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/sparc/sun4m.c   | 113 -
 hw/sparc64/sun4u.c |  52 +++-
 2 files changed, 40 insertions(+), 125 deletions(-)

diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 942ca37..36ef36f 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -836,12 +836,10 @@ static void dummy_fdc_tc(void *opaque, int irq, int level)
 {
 }
 
-static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
-  const char *boot_device,
-  const char *kernel_filename,
-  const char *kernel_cmdline,
-  const char *initrd_filename, const char *cpu_model)
+static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
+  QEMUMachineInitArgs *args)
 {
+const char *cpu_model = args-cpu_model;
 unsigned int i;
 void *iommu, *espdma, *ledma, *nvram;
 qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
@@ -867,10 +865,10 @@ static void sun4m_hw_init(const struct sun4m_hwdef 
*hwdef, ram_addr_t RAM_size,
 
 
 /* set up devices */
-ram_init(0, RAM_size, hwdef-max_mem);
+ram_init(0, args-ram_size, hwdef-max_mem);
 /* models without ECC don't trap when missing ram is accessed */
 if (!hwdef-ecc_base) {
-empty_slot_init(RAM_size, hwdef-max_mem - RAM_size);
+empty_slot_init(args-ram_size, hwdef-max_mem - args-ram_size);
 }
 
 prom_init(hwdef-slavio_base, bios_name);
@@ -993,11 +991,12 @@ static void sun4m_hw_init(const struct sun4m_hwdef 
*hwdef, ram_addr_t RAM_size,
 empty_slot_init(hwdef-bpp_base, 0x20);
 }
 
-kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
-RAM_size);
+kernel_size = sun4m_load_kernel(args-kernel_filename,
+args-initrd_filename,
+args-ram_size);
 
-nvram_init(nvram, (uint8_t *)nd_table[0].macaddr, kernel_cmdline,
-   boot_device, RAM_size, kernel_size, graphic_width,
+nvram_init(nvram, (uint8_t *)nd_table[0].macaddr, args-kernel_cmdline,
+   args-boot_device, args-ram_size, kernel_size, graphic_width,
graphic_height, graphic_depth, hwdef-nvram_machine_id,
Sun4m);
 
@@ -1015,19 +1014,20 @@ static void sun4m_hw_init(const struct sun4m_hwdef 
*hwdef, ram_addr_t RAM_size,
 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_HEIGHT, graphic_height);
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
-if (kernel_cmdline) {
+if (args-kernel_cmdline) {
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
-pstrcpy_targphys(cmdline, CMDLINE_ADDR, TARGET_PAGE_SIZE, 
kernel_cmdline);
-fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
+pstrcpy_targphys(cmdline, CMDLINE_ADDR, TARGET_PAGE_SIZE,
+ args-kernel_cmdline);
+fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, args-kernel_cmdline);
 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
-   strlen(kernel_cmdline) + 1);
+   strlen(args-kernel_cmdline) + 1);
 } else {
 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
 }
 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
-fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
+fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, args-boot_device[0]);
 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
 }
 
@@ -1291,118 +1291,55 @@ static const struct sun4m_hwdef sun4m_hwdefs[] = {
 /* SPARCstation 5 hardware initialisation */
 static void ss5_init(QEMUMachineInitArgs *args)
 {
-ram_addr_t RAM_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
-const char *boot_device = args-boot_device;
-sun4m_hw_init(sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
-  kernel_cmdline, initrd_filename, cpu_model);
+sun4m_hw_init(sun4m_hwdefs[0], args);
 }
 
 /* SPARCstation 10 hardware initialisation */
 static void ss10_init(QEMUMachineInitArgs *args)
 {
-ram_addr_t RAM_size = args-ram_size;
-const char *cpu_model = args-cpu_model;
-const char *kernel_filename = args-kernel_filename;
-const char *kernel_cmdline = args-kernel_cmdline;
-const char *initrd_filename = args-initrd_filename;
-

[Qemu-devel] [PATCH v4 5/6] ppc: Don't duplicate QEMUMachineInitArgs in PPCE500Params

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Pass on the generic arguments unadulterated, and the machine-specific
ones as separate argument.

Signed-off-by: Markus Armbruster arm...@redhat.com
Acked-by: Alexander Graf ag...@suse.de
---
 hw/ppc/e500.c  | 35 ++-
 hw/ppc/e500.h  | 13 +++--
 hw/ppc/e500plat.c  |  8 +---
 hw/ppc/mpc8544ds.c |  8 +---
 4 files changed, 23 insertions(+), 41 deletions(-)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index f00a62a..e79612b 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -124,13 +124,14 @@ static void dt_serial_create(void *fdt, unsigned long 
long offset,
 }
 
 static int ppce500_load_device_tree(CPUPPCState *env,
+QEMUMachineInitArgs *args,
 PPCE500Params *params,
 hwaddr addr,
 hwaddr initrd_base,
 hwaddr initrd_size)
 {
 int ret = -1;
-uint64_t mem_reg_property[] = { 0, cpu_to_be64(params-ram_size) };
+uint64_t mem_reg_property[] = { 0, cpu_to_be64(args-ram_size) };
 int fdt_size;
 void *fdt;
 uint8_t hypercall[16];
@@ -205,7 +206,7 @@ static int ppce500_load_device_tree(CPUPPCState *env,
 }
 
 ret = qemu_devtree_setprop_string(fdt, /chosen, bootargs,
-  params-kernel_cmdline);
+  args-kernel_cmdline);
 if (ret  0)
 fprintf(stderr, couldn't set /chosen/bootargs\n);
 
@@ -559,7 +560,7 @@ static qemu_irq *ppce500_init_mpic(PPCE500Params *params, 
MemoryRegion *ccsr,
 return mpic;
 }
 
-void ppce500_init(PPCE500Params *params)
+void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params *params)
 {
 MemoryRegion *address_space_mem = get_system_memory();
 MemoryRegion *ram = g_new(MemoryRegion, 1);
@@ -584,8 +585,8 @@ void ppce500_init(PPCE500Params *params)
 PPCE500CCSRState *ccsr;
 
 /* Setup CPUs */
-if (params-cpu_model == NULL) {
-params-cpu_model = e500v2_v30;
+if (args-cpu_model == NULL) {
+args-cpu_model = e500v2_v30;
 }
 
 irqs = g_malloc0(smp_cpus * sizeof(qemu_irq *));
@@ -595,7 +596,7 @@ void ppce500_init(PPCE500Params *params)
 CPUState *cs;
 qemu_irq *input;
 
-cpu = cpu_ppc_init(params-cpu_model);
+cpu = cpu_ppc_init(args-cpu_model);
 if (cpu == NULL) {
 fprintf(stderr, Unable to initialize CPU!\n);
 exit(1);
@@ -634,7 +635,7 @@ void ppce500_init(PPCE500Params *params)
 
 /* Fixup Memory size on a alignment boundary */
 ram_size = ~(RAM_SIZES_ALIGN - 1);
-params-ram_size = ram_size;
+args-ram_size = ram_size;
 
 /* Register Memory */
 memory_region_init_ram(ram, NULL, mpc8544ds.ram, ram_size);
@@ -701,11 +702,11 @@ void ppce500_init(PPCE500Params *params)
 sysbus_create_simple(e500-spin, MPC8544_SPIN_BASE, NULL);
 
 /* Load kernel. */
-if (params-kernel_filename) {
-kernel_size = load_uimage(params-kernel_filename, entry,
+if (args-kernel_filename) {
+kernel_size = load_uimage(args-kernel_filename, entry,
   loadaddr, NULL);
 if (kernel_size  0) {
-kernel_size = load_elf(params-kernel_filename, NULL, NULL,
+kernel_size = load_elf(args-kernel_filename, NULL, NULL,
elf_entry, elf_lowaddr, NULL, 1,
ELF_MACHINE, 0);
 entry = elf_entry;
@@ -714,7 +715,7 @@ void ppce500_init(PPCE500Params *params)
 /* XXX try again as binary */
 if (kernel_size  0) {
 fprintf(stderr, qemu: could not load kernel '%s'\n,
-params-kernel_filename);
+args-kernel_filename);
 exit(1);
 }
 
@@ -726,14 +727,14 @@ void ppce500_init(PPCE500Params *params)
 }
 
 /* Load initrd. */
-if (params-initrd_filename) {
+if (args-initrd_filename) {
 initrd_base = (cur_base + INITRD_LOAD_PAD)  ~INITRD_PAD_MASK;
-initrd_size = load_image_targphys(params-initrd_filename, initrd_base,
+initrd_size = load_image_targphys(args-initrd_filename, initrd_base,
   ram_size - initrd_base);
 
 if (initrd_size  0) {
 fprintf(stderr, qemu: could not load initial ram disk '%s'\n,
-params-initrd_filename);
+args-initrd_filename);
 exit(1);
 }
 
@@ -741,12 +742,12 @@ void ppce500_init(PPCE500Params *params)
 }
 
 /* If we're loading a kernel directly, we must load the device tree too. */
-if (params-kernel_filename) {
+if (args-kernel_filename) {
 struct boot_info *boot_info;
 int dt_size;
 
-dt_size = ppce500_load_device_tree(env, params, dt_base, initrd_base,
-   

[Qemu-devel] [PATCH v4 6/6] hw: Clean up bogus default boot order

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

We set default boot order cad in every single machine definition
except pseries and moxiesim, even though very few boards actually
care for boot order, and cad makes sense for even fewer.

Machines that care:

* pc and its variants

  Accept up to three letters 'a', 'b' (undocumented alias for 'a'),
  'c', 'd' and 'n'.  Reject all others (fatal with -boot).

* nseries (n800, n810)

  Check whether order starts with 'n'.  Silently ignored otherwise.

* prep, g3beige, mac99

  Extract the first character the machine understands (subset of
  'a'..'f').  Silently ignored otherwise.

* spapr

  Accept an arbitrary string (vl.c restricts it to contain only
  'a'..'p', no duplicates).

* sun4[mdc]

  Use the first character.  Silently ignored otherwise.

Strip characters these machines ignore from their default boot order.

For all other machines, remove the unused default boot order
alltogether.

Note that my rename of QEMUMachine member boot_order to
default_boot_order and QEMUMachineInitArgs member boot_device to
boot_order has a welcome side effect: it makes every use of boot
orders visible in this patch, for easy review.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/alpha/dp264.c |  1 -
 hw/arm/collie.c  |  1 -
 hw/arm/exynos4_boards.c  |  2 --
 hw/arm/gumstix.c |  2 --
 hw/arm/highbank.c|  2 --
 hw/arm/integratorcp.c|  1 -
 hw/arm/kzm.c |  1 -
 hw/arm/mainstone.c   |  1 -
 hw/arm/musicpal.c|  1 -
 hw/arm/nseries.c |  6 +++---
 hw/arm/omap_sx1.c|  2 --
 hw/arm/palm.c|  1 -
 hw/arm/realview.c|  4 
 hw/arm/spitz.c   |  4 
 hw/arm/stellaris.c   |  2 --
 hw/arm/tosa.c|  1 -
 hw/arm/versatilepb.c |  2 --
 hw/arm/vexpress.c|  2 --
 hw/arm/xilinx_zynq.c |  1 -
 hw/arm/z2.c  |  1 -
 hw/core/null-machine.c   |  1 -
 hw/cris/axis_dev88.c |  1 -
 hw/i386/pc_piix.c| 32 
 hw/i386/pc_q35.c |  8 
 hw/i386/xen_machine_pv.c |  1 -
 hw/lm32/lm32_boards.c|  2 --
 hw/lm32/milkymist.c  |  1 -
 hw/m68k/an5206.c |  1 -
 hw/m68k/dummy_m68k.c |  1 -
 hw/m68k/mcf5208.c|  1 -
 hw/microblaze/petalogix_ml605_mmu.c  |  1 -
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  1 -
 hw/mips/mips_fulong2e.c  |  1 -
 hw/mips/mips_jazz.c  |  2 --
 hw/mips/mips_malta.c |  1 -
 hw/mips/mips_mipssim.c   |  1 -
 hw/mips/mips_r4k.c   |  1 -
 hw/openrisc/openrisc_sim.c   |  1 -
 hw/ppc/e500plat.c|  1 -
 hw/ppc/mac_newworld.c|  4 ++--
 hw/ppc/mac_oldworld.c|  4 ++--
 hw/ppc/mpc8544ds.c   |  1 -
 hw/ppc/ppc405_boards.c   |  2 --
 hw/ppc/ppc440_bamboo.c   |  1 -
 hw/ppc/prep.c|  4 ++--
 hw/ppc/spapr.c   |  4 ++--
 hw/ppc/virtex_ml507.c|  1 -
 hw/s390x/s390-virtio-ccw.c   |  1 -
 hw/s390x/s390-virtio.c   |  1 -
 hw/sh4/r2d.c |  1 -
 hw/sh4/shix.c|  1 -
 hw/sparc/leon3.c |  1 -
 hw/sparc/sun4m.c | 22 +++---
 hw/sparc64/sun4u.c   | 10 +-
 hw/unicore32/puv3.c  |  1 -
 hw/xtensa/xtensa_lx60.c  |  2 --
 hw/xtensa/xtensa_sim.c   |  1 -
 include/hw/boards.h  |  7 ++-
 vl.c |  4 ++--
 59 files changed, 51 insertions(+), 119 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index 95fde61..20795ac 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -173,7 +173,6 @@ static QEMUMachine clipper_machine = {
 .init = clipper_init,
 .max_cpus = 4,
 .is_default = 1,
-DEFAULT_MACHINE_OPTIONS,
 };
 
 static void clipper_machine_init(void)
diff --git a/hw/arm/collie.c b/hw/arm/collie.c
index a19857a..8878b0e 100644
--- a/hw/arm/collie.c
+++ b/hw/arm/collie.c
@@ -62,7 +62,6 @@ static QEMUMachine collie_machine = {
 .name = collie,
 .desc = Collie PDA (SA-1110),
 .init = collie_init,
-DEFAULT_MACHINE_OPTIONS,
 };
 
 static void collie_machine_init(void)
diff --git a/hw/arm/exynos4_boards.c 

[Qemu-devel] [PATCH v2 3/7] smbios: Improve diagnostics for conflicting entries

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

We allow either tables or fields for the same type.  Makes sense,
because SeaBIOS uses fields only when no tables are present.

We do this by searching the SMBIOS blob for a previously added table
or field.  Error messages look like this:

qemu-system-x86_64: -smbios type=1,serial=42: SMBIOS type 1 table already 
defined, cannot add field

User needs to know that table is defined by -smbios file=..., and
field by -smbios type=...

Instead of searching the blob, record additions of interest, and check
that.  Simpler, and makes better error messages possible:

qemu-system-x86_64: -smbios file=smbios_type_1.bin: Can't mix file= and 
type= for same type
qemu-system-x86_64: -smbios type=1,serial=42,serial=99: This is the 
conflicting setting

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 hw/i386/smbios.c | 43 +--
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index a113f8b..7908c47 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -48,6 +48,12 @@ static uint8_t *smbios_entries;
 static size_t smbios_entries_len;
 static int smbios_type4_count = 0;
 
+static struct {
+bool seen;
+int headertype;
+Location loc;
+} first_opt[2];
+
 static QemuOptsList qemu_smbios_opts = {
 .name = smbios,
 .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head),
@@ -159,35 +165,20 @@ uint8_t *smbios_get_table(size_t *length)
  */
 static void smbios_check_collision(int type, int entry)
 {
-uint16_t *num_entries = (uint16_t *)smbios_entries;
-struct smbios_header *header;
-char *p;
-int i;
-
-if (!num_entries)
-return;
-
-p = (char *)(num_entries + 1);
-
-for (i = 0; i  *num_entries; i++) {
-header = (struct smbios_header *)p;
-if (entry == SMBIOS_TABLE_ENTRY  header-type == SMBIOS_FIELD_ENTRY) 
{
-struct smbios_field *field = (void *)header;
-if (type == field-type) {
-error_report(SMBIOS type %d field already defined, 
- cannot add table, type);
-exit(1);
-}
-} else if (entry == SMBIOS_FIELD_ENTRY 
-   header-type == SMBIOS_TABLE_ENTRY) {
-struct smbios_structure_header *table = (void *)(header + 1);
-if (type == table-type) {
-error_report(SMBIOS type %d table already defined, 
- cannot add field, type);
+if (type  ARRAY_SIZE(first_opt)) {
+if (first_opt[type].seen) {
+if (first_opt[type].headertype != entry) {
+error_report(Can't mix file= and type= for same type);
+loc_push_restore(first_opt[type].loc);
+error_report(This is the conflicting setting);
+loc_pop(first_opt[type].loc);
 exit(1);
 }
+} else {
+first_opt[type].seen = true;
+first_opt[type].headertype = entry;
+loc_save(first_opt[type].loc);
 }
-p += le16_to_cpu(header-length);
 }
 }
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 2/7] smbios: Convert to QemuOpts

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

So that it can be set in config file for -readconfig.

This tightens parsing of -smbios, and makes it more consistent with
other options: unknown parameters are rejected, numbers with trailing
junk are rejected, when a parameter is given multiple times, last
rather than first wins, ...

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 arch_init.c|   4 +-
 hw/i386/smbios.c   | 211 -
 include/hw/i386/smbios.h   |   4 +-
 include/sysemu/arch_init.h |   2 +-
 vl.c   |   3 +-
 5 files changed, 180 insertions(+), 44 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 1ddead0..96477fd 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1133,10 +1133,10 @@ void do_acpitable_option(const QemuOpts *opts)
 #endif
 }
 
-void do_smbios_option(const char *optarg)
+void do_smbios_option(QemuOpts *opts)
 {
 #ifdef TARGET_I386
-smbios_entry_add(optarg);
+smbios_entry_add(opts);
 #endif
 }
 
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index 0608aee..a113f8b 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -2,9 +2,11 @@
  * SMBIOS Support
  *
  * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
+ * Copyright (C) 2013 Red Hat, Inc.
  *
  * Authors:
  *  Alex Williamson alex.william...@hp.com
+ *  Markus Armbruster arm...@redhat.com
  *
  * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.
@@ -13,6 +15,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
+#include qemu/config-file.h
 #include qemu/error-report.h
 #include sysemu/sysemu.h
 #include hw/i386/smbios.h
@@ -41,11 +44,100 @@ struct smbios_table {
 #define SMBIOS_FIELD_ENTRY 0
 #define SMBIOS_TABLE_ENTRY 1
 
-
 static uint8_t *smbios_entries;
 static size_t smbios_entries_len;
 static int smbios_type4_count = 0;
 
+static QemuOptsList qemu_smbios_opts = {
+.name = smbios,
+.head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head),
+.desc = {
+/*
+ * no elements = accept any params
+ * validation will happen later
+ */
+{ /* end of list */ }
+}
+};
+
+static const QemuOptDesc qemu_smbios_file_opts[] = {
+{
+.name = file,
+.type = QEMU_OPT_STRING,
+.help = binary file containing an SMBIOS element,
+},
+{ /* end of list */ }
+};
+
+static const QemuOptDesc qemu_smbios_type0_opts[] = {
+{
+.name = type,
+.type = QEMU_OPT_NUMBER,
+.help = SMBIOS element type,
+},{
+.name = vendor,
+.type = QEMU_OPT_STRING,
+.help = vendor name,
+},{
+.name = version,
+.type = QEMU_OPT_STRING,
+.help = version number,
+},{
+.name = date,
+.type = QEMU_OPT_STRING,
+.help = release date,
+},{
+.name = release,
+.type = QEMU_OPT_STRING,
+.help = revision number,
+},
+{ /* end of list */ }
+};
+
+static const QemuOptDesc qemu_smbios_type1_opts[] = {
+{
+.name = type,
+.type = QEMU_OPT_NUMBER,
+.help = SMBIOS element type,
+},{
+.name = manufacturer,
+.type = QEMU_OPT_STRING,
+.help = manufacturer name,
+},{
+.name = product,
+.type = QEMU_OPT_STRING,
+.help = product name,
+},{
+.name = version,
+.type = QEMU_OPT_STRING,
+.help = version number,
+},{
+.name = serial,
+.type = QEMU_OPT_STRING,
+.help = serial number,
+},{
+.name = uuid,
+.type = QEMU_OPT_STRING,
+.help = UUID,
+},{
+.name = sku,
+.type = QEMU_OPT_STRING,
+.help = SKU number,
+},{
+.name = family,
+.type = QEMU_OPT_STRING,
+.help = family name,
+},
+{ /* end of list */ }
+};
+
+static void smbios_register_config(void)
+{
+qemu_add_opts(qemu_smbios_opts);
+}
+
+machine_init(smbios_register_config);
+
 static void smbios_validate_table(void)
 {
 if (smbios_type4_count  smbios_type4_count != smp_cpus) {
@@ -124,23 +216,30 @@ void smbios_add_field(int type, int offset, const void 
*data, size_t len)
 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
 }
 
-static void smbios_build_type_0_fields(const char *t)
+static void smbios_build_type_0_fields(QemuOpts *opts)
 {
-char buf[1024];
+const char *val;
 unsigned char major, minor;
 
-if (get_param_value(buf, sizeof(buf), vendor, t))
+val = qemu_opt_get(opts, vendor);
+if (val) {
 smbios_add_field(0, offsetof(struct smbios_type_0, vendor_str),
- buf, strlen(buf) + 1);
-if (get_param_value(buf, sizeof(buf), version, t))
+ val, strlen(val) + 1);
+}
+val = qemu_opt_get(opts, version);
+if (val) {
 

[Qemu-devel] [PATCH v2 5/7] smbios: Factor out smbios_maybe_add_str()

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 hw/i386/smbios.c | 61 +++-
 1 file changed, 25 insertions(+), 36 deletions(-)

diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index fb1b27b..a2eb9bf 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -210,21 +210,22 @@ static void smbios_add_field(int type, int offset, const 
void *data, size_t len)
 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
 }
 
-static void smbios_build_type_0_fields(void)
+static void smbios_maybe_add_str(int type, int offset, const char *data)
 {
-if (type0.vendor) {
-smbios_add_field(0, offsetof(struct smbios_type_0, vendor_str),
- type0.vendor, strlen(type0.vendor) + 1);
-}
-if (type0.version) {
-smbios_add_field(0, offsetof(struct smbios_type_0, bios_version_str),
- type0.version, strlen(type0.version) + 1);
+if (data) {
+smbios_add_field(type, offset, data, strlen(data) + 1);
 }
-if (type0.date) {
-smbios_add_field(0, offsetof(struct smbios_type_0,
+}
+
+static void smbios_build_type_0_fields(void)
+{
+smbios_maybe_add_str(0, offsetof(struct smbios_type_0, vendor_str),
+ type0.vendor);
+smbios_maybe_add_str(0, offsetof(struct smbios_type_0, bios_version_str),
+ type0.version);
+smbios_maybe_add_str(0, offsetof(struct smbios_type_0,
  bios_release_date_str),
- type0.date, strlen(type0.date) + 1);
-}
+ type0.date);
 if (type0.have_major_minor) {
 smbios_add_field(0, offsetof(struct smbios_type_0,
  system_bios_major_release),
@@ -237,30 +238,18 @@ static void smbios_build_type_0_fields(void)
 
 static void smbios_build_type_1_fields(void)
 {
-if (type1.manufacturer) {
-smbios_add_field(1, offsetof(struct smbios_type_1, manufacturer_str),
- type1.manufacturer, strlen(type1.manufacturer) + 1);
-}
-if (type1.product) {
-smbios_add_field(1, offsetof(struct smbios_type_1, product_name_str),
- type1.product, strlen(type1.product) + 1);
-}
-if (type1.version) {
-smbios_add_field(1, offsetof(struct smbios_type_1, version_str),
- type1.version, strlen(type1.version) + 1);
-}
-if (type1.serial) {
-smbios_add_field(1, offsetof(struct smbios_type_1, serial_number_str),
- type1.serial, strlen(type1.serial) + 1);
-}
-if (type1.sku) {
-smbios_add_field(1, offsetof(struct smbios_type_1, sku_number_str),
- type1.sku, strlen(type1.sku) + 1);
-}
-if (type1.family) {
-smbios_add_field(1, offsetof(struct smbios_type_1, family_str),
- type1.family, strlen(type1.family) + 1);
-}
+smbios_maybe_add_str(1, offsetof(struct smbios_type_1, manufacturer_str),
+ type1.manufacturer);
+smbios_maybe_add_str(1, offsetof(struct smbios_type_1, product_name_str),
+ type1.product);
+smbios_maybe_add_str(1, offsetof(struct smbios_type_1, version_str),
+ type1.version);
+smbios_maybe_add_str(1, offsetof(struct smbios_type_1, serial_number_str),
+ type1.serial);
+smbios_maybe_add_str(1, offsetof(struct smbios_type_1, sku_number_str),
+ type1.sku);
+smbios_maybe_add_str(1, offsetof(struct smbios_type_1, family_str),
+ type1.family);
 if (qemu_uuid_set) {
 smbios_add_field(1, offsetof(struct smbios_type_1, uuid),
  qemu_uuid, 16);
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 4/7] smbios: Make multiple -smbios type= accumulate sanely

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Currently, -smbios type=T,NAME=VAL,... adds one field (T,NAME) with
value VAL to fw_cfg for each unique NAME.  If NAME occurs multiple
times, the last one's VAL is used (before the QemuOpts conversion, the
first one was used).

Multiple -smbios can add multiple fields with the same (T, NAME).
SeaBIOS reads all of them from fw_cfg, but uses only the first field
(T, NAME).  The others are ignored.

First one wins, subsequent ones get ignored silently isn't nice.  We
commonly let the last option win.  Useful, because it lets you
-readconfig first, then selectively override with command line
options.

Clean up -smbios to work the common way.  Accumulate the settings,
with later ones overwriting earlier ones.  Put the result into fw_cfg
(no more useless duplicates).

Bonus cleanup: qemu_uuid_parse() no longer sets SMBIOS system uuid by
side effect.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 arch_init.c  |   3 -
 hw/i386/smbios.c | 152 ---
 include/hw/i386/smbios.h |   1 -
 include/sysemu/sysemu.h  |   1 +
 vl.c |   2 +
 5 files changed, 94 insertions(+), 65 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 96477fd..3cb1caf 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1112,9 +1112,6 @@ int qemu_uuid_parse(const char *str, uint8_t *uuid)
 if (ret != 16) {
 return -1;
 }
-#ifdef TARGET_I386
-smbios_add_field(1, offsetof(struct smbios_type_1, uuid), uuid, 16);
-#endif
 return 0;
 }
 
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index 7908c47..fb1b27b 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -47,6 +47,7 @@ struct smbios_table {
 static uint8_t *smbios_entries;
 static size_t smbios_entries_len;
 static int smbios_type4_count = 0;
+static bool smbios_immutable;
 
 static struct {
 bool seen;
@@ -54,6 +55,17 @@ static struct {
 Location loc;
 } first_opt[2];
 
+static struct {
+const char *vendor, *version, *date;
+bool have_major_minor;
+uint8_t major, minor;
+} type0;
+
+static struct {
+const char *manufacturer, *product, *version, *serial, *sku, *family;
+/* uuid is in qemu_uuid[] */
+} type1;
+
 static QemuOptsList qemu_smbios_opts = {
 .name = smbios,
 .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head),
@@ -152,13 +164,6 @@ static void smbios_validate_table(void)
 }
 }
 
-uint8_t *smbios_get_table(size_t *length)
-{
-smbios_validate_table();
-*length = smbios_entries_len;
-return smbios_entries;
-}
-
 /*
  * To avoid unresolvable overlaps in data, don't allow both
  * tables and fields for the same smbios type.
@@ -182,12 +187,10 @@ static void smbios_check_collision(int type, int entry)
 }
 }
 
-void smbios_add_field(int type, int offset, const void *data, size_t len)
+static void smbios_add_field(int type, int offset, const void *data, size_t 
len)
 {
 struct smbios_field *field;
 
-smbios_check_collision(type, SMBIOS_FIELD_ENTRY);
-
 if (!smbios_entries) {
 smbios_entries_len = sizeof(uint16_t);
 smbios_entries = g_malloc0(smbios_entries_len);
@@ -207,82 +210,81 @@ void smbios_add_field(int type, int offset, const void 
*data, size_t len)
 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
 }
 
-static void smbios_build_type_0_fields(QemuOpts *opts)
+static void smbios_build_type_0_fields(void)
 {
-const char *val;
-unsigned char major, minor;
-
-val = qemu_opt_get(opts, vendor);
-if (val) {
+if (type0.vendor) {
 smbios_add_field(0, offsetof(struct smbios_type_0, vendor_str),
- val, strlen(val) + 1);
+ type0.vendor, strlen(type0.vendor) + 1);
 }
-val = qemu_opt_get(opts, version);
-if (val) {
+if (type0.version) {
 smbios_add_field(0, offsetof(struct smbios_type_0, bios_version_str),
- val, strlen(val) + 1);
+ type0.version, strlen(type0.version) + 1);
 }
-val = qemu_opt_get(opts, date);
-if (val) {
+if (type0.date) {
 smbios_add_field(0, offsetof(struct smbios_type_0,
  bios_release_date_str),
- val, strlen(val) + 1);
+ type0.date, strlen(type0.date) + 1);
 }
-val = qemu_opt_get(opts, release);
-if (val) {
-if (sscanf(val, %hhu.%hhu, major, minor) != 2) {
-error_report(Invalid release);
-exit(1);
-}
+if (type0.have_major_minor) {
 smbios_add_field(0, offsetof(struct smbios_type_0,
  system_bios_major_release),
- major, 1);
+ type0.major, 1);
 smbios_add_field(0, offsetof(struct smbios_type_0,
  system_bios_minor_release),
-   

[Qemu-devel] [PATCH v2 6/7] vl: Set current_machine early

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

I'd like to access QEMUMachine from a QEMUMachine init() method, which
is currently not possible.  Instead of passing it as an argument, I
simply set current_machine earlier.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 vl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index ba3084c..258e164 100644
--- a/vl.c
+++ b/vl.c
@@ -3897,6 +3897,7 @@ int main(int argc, char **argv, char **envp)
 fprintf(stderr, No machine found.\n);
 exit(1);
 }
+current_machine = machine;
 
 if (machine-hw_version) {
 qemu_set_version(machine-hw_version);
@@ -4325,8 +4326,6 @@ int main(int argc, char **argv, char **envp)
 
 set_numa_modes();
 
-current_machine = machine;
-
 /* init USB devices */
 if (usb_enabled(false)) {
 if (foreach_device_config(DEV_USB, usb_parse)  0)
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 1/7] smbios: Normalize smbios_entry_add()'s error handling to exit(1)

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

It exits on all error conditions but one, where it returns -1.
Normalize, and return void.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 arch_init.c  |  4 +---
 hw/i386/smbios.c | 10 +-
 include/hw/i386/smbios.h |  2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 68a7ab7..1ddead0 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -1136,9 +1136,7 @@ void do_acpitable_option(const QemuOpts *opts)
 void do_smbios_option(const char *optarg)
 {
 #ifdef TARGET_I386
-if (smbios_entry_add(optarg)  0) {
-exit(1);
-}
+smbios_entry_add(optarg);
 #endif
 }
 
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index e708cb8..0608aee 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -183,7 +183,7 @@ static void smbios_build_type_1_fields(const char *t)
  buf, strlen(buf) + 1);
 }
 
-int smbios_entry_add(const char *t)
+void smbios_entry_add(const char *t)
 {
 char buf[1024];
 
@@ -222,7 +222,7 @@ int smbios_entry_add(const char *t)
 smbios_entries_len += sizeof(*table) + size;
 (*(uint16_t *)smbios_entries) =
 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1);
-return 0;
+return;
 }
 
 if (get_param_value(buf, sizeof(buf), type, t)) {
@@ -230,10 +230,10 @@ int smbios_entry_add(const char *t)
 switch (type) {
 case 0:
 smbios_build_type_0_fields(t);
-return 0;
+return;
 case 1:
 smbios_build_type_1_fields(t);
-return 0;
+return;
 default:
 error_report(Don't know how to build fields for SMBIOS type %ld,
  type);
@@ -242,5 +242,5 @@ int smbios_entry_add(const char *t)
 }
 
 error_report(Must specify type= or file=);
-return -1;
+exit(1);
 }
diff --git a/include/hw/i386/smbios.h b/include/hw/i386/smbios.h
index 9babeaf..56c6108 100644
--- a/include/hw/i386/smbios.h
+++ b/include/hw/i386/smbios.h
@@ -13,7 +13,7 @@
  *
  */
 
-int smbios_entry_add(const char *t);
+void smbios_entry_add(const char *t);
 void smbios_add_field(int type, int offset, const void *data, size_t len);
 uint8_t *smbios_get_table(size_t *length);
 
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 0/7] smbios cleanup nicer defaults for type 1

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

This gets rid of one of the last get_param_value() users, makes
multiple -smbios work sanely, cleans up the gross side effect in
qemu_uuid_parse(), and more.  Topped off with a little feature in the
last patch.

v2: Rebase, only last patch had conflicts

Markus Armbruster (7):
  smbios: Normalize smbios_entry_add()'s error handling to exit(1)
  smbios: Convert to QemuOpts
  smbios: Improve diagnostics for conflicting entries
  smbios: Make multiple -smbios type= accumulate sanely
  smbios: Factor out smbios_maybe_add_str()
  vl: Set current_machine early
  smbios: Set system manufacturer, product  version by default

 arch_init.c|   9 +-
 hw/i386/pc.c   |   6 +-
 hw/i386/pc_piix.c  |   5 +
 hw/i386/pc_q35.c   |   3 +
 hw/i386/smbios.c   | 349 -
 include/hw/i386/pc.h   |   1 +
 include/hw/i386/smbios.h   |   7 +-
 include/sysemu/arch_init.h |   2 +-
 include/sysemu/sysemu.h|   1 +
 vl.c   |   8 +-
 10 files changed, 276 insertions(+), 115 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH v2 7/7] smbios: Set system manufacturer, product version by default

2013-08-16 Thread armbru
From: Markus Armbruster arm...@redhat.com

Currently, we get SeaBIOS defaults: manufacturer Bochs, product Bochs,
no version.  Best SeaBIOS can do, but we can provide better defaults:
manufacturer QEMU, product  version taken from QEMUMachine desc and
name.

Take care to do this only for new machine types, of course.

Signed-off-by: Markus Armbruster arm...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 hw/i386/pc.c |  6 +++---
 hw/i386/pc_piix.c|  5 +
 hw/i386/pc_q35.c |  3 +++
 hw/i386/smbios.c | 12 +++-
 include/hw/i386/pc.h |  1 +
 include/hw/i386/smbios.h |  2 +-
 6 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index e8bc8ce..eb7ffc4 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -604,7 +604,7 @@ static unsigned int pc_apic_id_limit(unsigned int max_cpus)
 return x86_cpu_apic_id_from_index(max_cpus - 1) + 1;
 }
 
-static FWCfgState *bochs_bios_init(void)
+static FWCfgState *bochs_bios_init(bool smbios_type1_defaults)
 {
 FWCfgState *fw_cfg;
 uint8_t *smbios_table;
@@ -635,7 +635,7 @@ static FWCfgState *bochs_bios_init(void)
  acpi_tables, acpi_tables_len);
 fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override());
 
-smbios_table = smbios_get_table(smbios_len);
+smbios_table = smbios_get_table(smbios_len, smbios_type1_defaults);
 if (smbios_table)
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
  smbios_table, smbios_len);
@@ -1155,7 +1155,7 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,
 option_rom_mr,
 1);
 
-fw_cfg = bochs_bios_init();
+fw_cfg = bochs_bios_init(guest_info-smbios_type1_defaults);
 rom_set_fw(fw_cfg);
 
 if (linux_boot) {
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6e1e654..2a621ef 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -58,6 +58,7 @@ static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
 static bool has_pvpanic;
 static bool has_pci_info = true;
+static bool smbios_type1_defaults = true;
 
 /* PC hardware initialisation */
 static void pc_init1(MemoryRegion *system_memory,
@@ -128,6 +129,7 @@ static void pc_init1(MemoryRegion *system_memory,
 guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
 guest_info-has_pci_info = has_pci_info;
 guest_info-isapc_ram_fw = !pci_enabled;
+guest_info-smbios_type1_defaults = smbios_type1_defaults;
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
@@ -258,6 +260,7 @@ static void pc_init_pci_1_6(QEMUMachineInitArgs *args)
 static void pc_init_pci_1_5(QEMUMachineInitArgs *args)
 {
 has_pvpanic = true;
+smbios_type1_defaults = false;
 pc_init_pci_1_6(args);
 }
 
@@ -298,6 +301,7 @@ static void pc_init_pci_no_kvmclock(QEMUMachineInitArgs 
*args)
 const char *initrd_filename = args-initrd_filename;
 const char *boot_device = args-boot_device;
 has_pci_info = false;
+smbios_type1_defaults = false;
 disable_kvm_pv_eoi();
 enable_compat_apic_id_mode();
 pc_init1(get_system_memory(),
@@ -316,6 +320,7 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 const char *initrd_filename = args-initrd_filename;
 const char *boot_device = args-boot_device;
 has_pci_info = false;
+smbios_type1_defaults = false;
 if (cpu_model == NULL)
 cpu_model = 486;
 disable_kvm_pv_eoi();
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 10e770e..05bce55 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -48,6 +48,7 @@
 
 static bool has_pvpanic;
 static bool has_pci_info = true;
+static bool smbios_type1_defaults = true;
 
 /* PC hardware initialisation */
 static void pc_q35_init(QEMUMachineInitArgs *args)
@@ -111,6 +112,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
 guest_info = pc_guest_info_init(below_4g_mem_size, above_4g_mem_size);
 guest_info-has_pci_info = has_pci_info;
 guest_info-isapc_ram_fw = false;
+guest_info-smbios_type1_defaults = smbios_type1_defaults;
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
@@ -227,6 +229,7 @@ static void pc_q35_init_1_6(QEMUMachineInitArgs *args)
 static void pc_q35_init_1_5(QEMUMachineInitArgs *args)
 {
 has_pvpanic = true;
+smbios_type1_defaults = false;
 pc_q35_init_1_6(args);
 }
 
diff --git a/hw/i386/smbios.c b/hw/i386/smbios.c
index a2eb9bf..e6413a5 100644
--- a/hw/i386/smbios.c
+++ b/hw/i386/smbios.c
@@ -18,6 +18,7 @@
 #include qemu/config-file.h
 #include qemu/error-report.h
 #include sysemu/sysemu.h
+#include hw/boards.h
 #include hw/i386/smbios.h
 #include hw/loader.h
 
@@ -256,9 +257,18 @@ static void smbios_build_type_1_fields(void)
 }
 }
 
-uint8_t *smbios_get_table(size_t *length)
+uint8_t *smbios_get_table(size_t *length, bool type1_defaults)
 {
 if (!smbios_immutable) {
+   

[Qemu-devel] [PATCH 1/1] virtio-scsi: Make type virtio-scsi-common abstract

2013-08-19 Thread armbru
From: Markus Armbruster arm...@redhat.com

It's the abstract base of virtio-scsi-device and vhost-scsi.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 hw/scsi/virtio-scsi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 05da56b..a9ee17b 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -692,6 +692,7 @@ static const TypeInfo virtio_scsi_common_info = {
 .name = TYPE_VIRTIO_SCSI_COMMON,
 .parent = TYPE_VIRTIO_DEVICE,
 .instance_size = sizeof(VirtIOSCSICommon),
+.abstract = true,
 .class_init = virtio_scsi_common_class_init,
 };
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 1/2] tests: Fix schema parser test for in-tree build

2013-08-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Commit 4f193e3 added the test, but screwed up in-tree builds
(SRCDIR=.): the tests's output overwrites the expected output, and is
thus compared to itself.

Reported-by: Laszlo Ersek ler...@redhat.com
Signed-off-by: Markus Armbruster arm...@redhat.com
---
 tests/.gitignore | 1 +
 tests/Makefile   | 8 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/.gitignore b/tests/.gitignore
index fb05c2a..d9c2ef4 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -19,3 +19,4 @@ test-thread-pool
 test-x86-cpuid
 test-xbzrle
 *-test
+qapi-schema/*.test.*
diff --git a/tests/Makefile b/tests/Makefile
index d044908..ad98439 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -247,10 +247,10 @@ check-tests/test-qapi.py: tests/test-qapi.py
 
 .PHONY: $(patsubst %, check-%, $(check-qapi-schema-y))
 $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: 
$(SRC_PATH)/%.json
-   $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) 
$(SRC_PATH)/tests/qapi-schema/test-qapi.py $^ $*.out 2$*.err; echo $$? 
$*.exit,   TEST  $*.out)
-   @diff -q $(SRC_PATH)/$*.out $*.out
-   @diff -q $(SRC_PATH)/$*.err $*.err
-   @diff -q $(SRC_PATH)/$*.exit $*.exit
+   $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) 
$(SRC_PATH)/tests/qapi-schema/test-qapi.py $^ $*.test.out 2$*.test.err; echo 
$$? $*.test.exit,   TEST  $*.out)
+   @diff -q $(SRC_PATH)/$*.out $*.test.out
+   @diff -q $(SRC_PATH)/$*.err $*.test.err
+   @diff -q $(SRC_PATH)/$*.exit $*.test.exit
 
 # Consolidated targets
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 0/2] tests: Fixes for in-tree build

2013-08-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Markus Armbruster (2):
  tests: Fix schema parser test for in-tree build
  tests: Update .gitignore for test-int128 and test-bitops

 tests/.gitignore | 3 +++
 tests/Makefile   | 8 
 2 files changed, 7 insertions(+), 4 deletions(-)

-- 
1.8.1.4




[Qemu-devel] [PATCH 2/2] tests: Update .gitignore for test-int128 and test-bitops

2013-08-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Forgotten in commit 6046c62 and 3464700.

Signed-off-by: Markus Armbruster arm...@redhat.com
---
 tests/.gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/.gitignore b/tests/.gitignore
index d9c2ef4..9ac044d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -5,8 +5,10 @@ check-qjson
 check-qlist
 check-qstring
 test-aio
+test-bitops
 test-cutils
 test-hbitmap
+test-int128
 test-iov
 test-mul64
 test-qapi-types.[ch]
-- 
1.8.1.4




[Qemu-devel] [PATCH v2 1/2] tests: Fix schema parser test for in-tree build

2013-08-20 Thread armbru
From: Markus Armbruster arm...@redhat.com

Commit 4f193e3 added the test, but screwed up in-tree builds
(SRCDIR=.): the tests's output overwrites the expected output, and is
thus compared to itself.

Cc: qemu-sta...@nongnu.org
Reported-by: Laszlo Ersek ler...@redhat.com
Reviewed-by: Andreas Färber afaer...@suse.de
Signed-off-by: Markus Armbruster arm...@redhat.com
---
 tests/.gitignore | 1 +
 tests/Makefile   | 8 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/.gitignore b/tests/.gitignore
index fb05c2a..d9c2ef4 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -19,3 +19,4 @@ test-thread-pool
 test-x86-cpuid
 test-xbzrle
 *-test
+qapi-schema/*.test.*
diff --git a/tests/Makefile b/tests/Makefile
index d044908..ad98439 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -247,10 +247,10 @@ check-tests/test-qapi.py: tests/test-qapi.py
 
 .PHONY: $(patsubst %, check-%, $(check-qapi-schema-y))
 $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: 
$(SRC_PATH)/%.json
-   $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) 
$(SRC_PATH)/tests/qapi-schema/test-qapi.py $^ $*.out 2$*.err; echo $$? 
$*.exit,   TEST  $*.out)
-   @diff -q $(SRC_PATH)/$*.out $*.out
-   @diff -q $(SRC_PATH)/$*.err $*.err
-   @diff -q $(SRC_PATH)/$*.exit $*.exit
+   $(call quiet-command, PYTHONPATH=$(SRC_PATH)/scripts $(PYTHON) 
$(SRC_PATH)/tests/qapi-schema/test-qapi.py $^ $*.test.out 2$*.test.err; echo 
$$? $*.test.exit,   TEST  $*.out)
+   @diff -q $(SRC_PATH)/$*.out $*.test.out
+   @diff -q $(SRC_PATH)/$*.err $*.test.err
+   @diff -q $(SRC_PATH)/$*.exit $*.test.exit
 
 # Consolidated targets
 
-- 
1.8.1.4




  1   2   >