qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support
@ 2014-07-02 18:01 Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file Alexander Graf
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

Platforms without ISA and/or PCI have had a seriously hard time in the dynamic
device creation world of QEMU. Devices on these were modeled as SysBus devices
which can only be instantiated in machine files, not through -device.

Why is that so?

For Sysbus devices we didn't know who should be responsible for mapping them
when the machine file didn't do it. Turns out, the machine file is the perfect
place to map them even when it doesn't create them :).

This patch set enables machine files to declare sysbus device creation via the
-device command line option as possible. With this we can (in the machine file)
map sysbus devices to whatever the machine thinks is fitting.

Some times users do want to specify manually where to map a device. This is
very useful when you want to have stable offsets in memory and irq space.
This patch set adds support for "user mapping hints" that the machine can use
to map a device at a certain location.

As example this patch set only enables the eTSEC device on the e500plat machine
type. This device was not possible to get added to the machine at all.

  $ qemu-system-ppc -nographic -M ppce500 -device eTSEC,netdev=nd \
                    -netdev user,id=nd

The idea can easily be extended to any sysbus device on any machine type though.


This patch set is based on previous ideas and discussions, most notably:

  https://lists.gnu.org/archive/html/qemu-devel/2013-07/msg03614.html
  https://lists.gnu.org/archive/html/qemu-devel/2014-06/msg00849.html



v1 -> v2:

  - new patch: qom: Move property helpers to own file
  - reworked patch: qom: Expose property helpers for get/set of integers
  - new patch: qom: Add generic object property g_free helper
  - new patch: PPC: Fix default config ordering and add eTSEC for ppc64
  - Rename DECLARE_INTEGER_VISITOR to DECLARE_PROP_SET_GET
  - Make macro take name and type arguments, enabling generation of "bool"
    types later
  - make irq and pio properties uint64
  - ensure qom exposed pointers don't change due to realloc
  - fix sysbus_pass_irq
  - make properties write-once, not write-before-realize
  - make props only available via qom, no state pointers left
  - use bool in MachineClass rather than property
  - access sysbus properties via qom
  - move platform bus definitions to params
  - move platform bus to 36bit address space
  - make naming more consistent
  - remove device_type from platform bus dt node
  - remove id field in dt generation
  - fix device name (base on reg for value after @)
  - use qom properties to fetch mmio and irq props
  - remove useless interrupt-parent
  - make interrupts level triggered

Alexander Graf (9):
  qom: Move property helpers to own file
  qom: macroify integer property helpers
  qom: Expose property helpers for get/set of integers
  qom: Add generic object property g_free helper
  sysbus: Add user map hints
  sysbus: Make devices spawnable via -device
  PPC: e500: Support dynamically spawned sysbus devices
  e500: Add support for eTSEC in device tree
  PPC: Fix default config ordering and add eTSEC for ppc64

 backends/hostmem-file.c           |   1 +
 backends/hostmem.c                |   1 +
 backends/rng-egd.c                |   1 +
 backends/rng-random.c             |   1 +
 backends/rng.c                    |   1 +
 backends/tpm.c                    |   1 +
 default-configs/ppc-softmmu.mak   |   4 +-
 default-configs/ppc64-softmmu.mak |   3 +-
 hw/acpi/ich9.c                    |   1 +
 hw/acpi/pcihp.c                   |   1 +
 hw/acpi/piix4.c                   |   1 +
 hw/core/machine.c                 |  44 ++++++
 hw/core/qdev.c                    |   1 +
 hw/core/sysbus.c                  |  50 +++++--
 hw/i386/acpi-build.c              |   1 +
 hw/isa/lpc_ich9.c                 |   1 +
 hw/ppc/e500.c                     | 288 ++++++++++++++++++++++++++++++++++++++
 hw/ppc/e500.h                     |   5 +
 hw/ppc/e500plat.c                 |   6 +
 hw/ppc/spapr.c                    |   1 +
 include/hw/boards.h               |   8 +-
 include/hw/sysbus.h               |   1 +
 include/qom/object.h              |  85 -----------
 include/qom/property.h            | 244 ++++++++++++++++++++++++++++++++
 memory.c                          |   1 +
 qom/Makefile.objs                 |   2 +-
 qom/object.c                      | 206 +--------------------------
 qom/property.c                    | 179 +++++++++++++++++++++++
 target-i386/cpu.c                 |   1 +
 ui/console.c                      |   1 +
 vl.c                              |   1 +
 31 files changed, 842 insertions(+), 300 deletions(-)
 create mode 100644 include/qom/property.h
 create mode 100644 qom/property.c

-- 
1.8.1.4

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-31 13:46   ` Peter Crosthwaite
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers Alexander Graf
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

We have accumulated a number of friendly helpers that make registration
of properties easier. However, their number is only increasing and they
start to clutter the core object.c file.

So let's move them into a separate C file and thus ensure that we have
room to grow :).

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 backends/hostmem-file.c |   1 +
 backends/hostmem.c      |   1 +
 backends/rng-egd.c      |   1 +
 backends/rng-random.c   |   1 +
 backends/rng.c          |   1 +
 backends/tpm.c          |   1 +
 hw/acpi/ich9.c          |   1 +
 hw/acpi/pcihp.c         |   1 +
 hw/acpi/piix4.c         |   1 +
 hw/core/machine.c       |   1 +
 hw/core/qdev.c          |   1 +
 hw/i386/acpi-build.c    |   1 +
 hw/isa/lpc_ich9.c       |   1 +
 hw/ppc/spapr.c          |   1 +
 include/qom/object.h    |  85 -------------------
 include/qom/property.h  | 104 ++++++++++++++++++++++++
 memory.c                |   1 +
 qom/Makefile.objs       |   2 +-
 qom/object.c            | 197 ++------------------------------------------
 qom/property.c          | 212 ++++++++++++++++++++++++++++++++++++++++++++++++
 target-i386/cpu.c       |   1 +
 ui/console.c            |   1 +
 22 files changed, 340 insertions(+), 277 deletions(-)
 create mode 100644 include/qom/property.h
 create mode 100644 qom/property.c

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 5179994..5a944a3 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -13,6 +13,7 @@
 #include "sysemu/hostmem.h"
 #include "sysemu/sysemu.h"
 #include "qom/object_interfaces.h"
+#include "qom/property.h"
 
 /* hostmem-file.c */
 /**
diff --git a/backends/hostmem.c b/backends/hostmem.c
index ca10c51..18fc8ba 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -16,6 +16,7 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/config-file.h"
 #include "qom/object_interfaces.h"
+#include "qom/property.h"
 
 #ifdef CONFIG_NUMA
 #include <numaif.h>
diff --git a/backends/rng-egd.c b/backends/rng-egd.c
index 25bb3b4..f055ac1 100644
--- a/backends/rng-egd.c
+++ b/backends/rng-egd.c
@@ -14,6 +14,7 @@
 #include "sysemu/char.h"
 #include "qapi/qmp/qerror.h"
 #include "hw/qdev.h" /* just for DEFINE_PROP_CHR */
+#include "qom/property.h"
 
 #define TYPE_RNG_EGD "rng-egd"
 #define RNG_EGD(obj) OBJECT_CHECK(RngEgd, (obj), TYPE_RNG_EGD)
diff --git a/backends/rng-random.c b/backends/rng-random.c
index 601d9dc..c7f3ff7 100644
--- a/backends/rng-random.c
+++ b/backends/rng-random.c
@@ -14,6 +14,7 @@
 #include "sysemu/rng.h"
 #include "qapi/qmp/qerror.h"
 #include "qemu/main-loop.h"
+#include "qom/property.h"
 
 struct RndRandom
 {
diff --git a/backends/rng.c b/backends/rng.c
index 0f2fc11..7b82894 100644
--- a/backends/rng.c
+++ b/backends/rng.c
@@ -13,6 +13,7 @@
 #include "sysemu/rng.h"
 #include "qapi/qmp/qerror.h"
 #include "qom/object_interfaces.h"
+#include "qom/property.h"
 
 void rng_backend_request_entropy(RngBackend *s, size_t size,
                                  EntropyReceiveFunc *receive_entropy,
diff --git a/backends/tpm.c b/backends/tpm.c
index 01860c4..769a9b8 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -17,6 +17,7 @@
 #include "sysemu/tpm.h"
 #include "qemu/thread.h"
 #include "sysemu/tpm_backend_int.h"
+#include "qom/property.h"
 
 enum TpmType tpm_backend_get_type(TPMBackend *s)
 {
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index e7d6c77..2c1eb13 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -32,6 +32,7 @@
 #include "hw/acpi/acpi.h"
 #include "sysemu/kvm.h"
 #include "exec/address-spaces.h"
+#include "qom/property.h"
 
 #include "hw/i386/ich9.h"
 #include "hw/mem/pc-dimm.h"
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index fae663a..641378b 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -36,6 +36,7 @@
 #include "exec/address-spaces.h"
 #include "hw/pci/pci_bus.h"
 #include "qom/qom-qobject.h"
+#include "qom/property.h"
 #include "qapi/qmp/qint.h"
 
 //#define DEBUG
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b72b34e..fc7d5b3 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -36,6 +36,7 @@
 #include "hw/mem/pc-dimm.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/acpi_dev_interface.h"
+#include "qom/property.h"
 
 //#define DEBUG
 
diff --git a/hw/core/machine.c b/hw/core/machine.c
index cbba679..c25cc07 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -12,6 +12,7 @@
 
 #include "hw/boards.h"
 #include "qapi/visitor.h"
+#include "qom/property.h"
 
 static char *machine_get_accel(Object *obj, Error **errp)
 {
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 3bdda8e..a4dca33 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -35,6 +35,7 @@
 #include "hw/hotplug.h"
 #include "hw/boards.h"
 #include "qapi-event.h"
+#include "qom/property.h"
 
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index ebc5f03..f95464c 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -51,6 +51,7 @@
 
 #include "qapi/qmp/qint.h"
 #include "qom/qom-qobject.h"
+#include "qom/property.h"
 
 typedef struct AcpiCpuInfo {
     DECLARE_BITMAP(found_cpus, ACPI_CPU_HOTPLUG_ID_LIMIT);
diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c
index b846d81..5682234 100644
--- a/hw/isa/lpc_ich9.c
+++ b/hw/isa/lpc_ich9.c
@@ -45,6 +45,7 @@
 #include "hw/pci/pci_bus.h"
 #include "exec/address-spaces.h"
 #include "sysemu/sysemu.h"
+#include "qom/property.h"
 
 static int ich9_lpc_sci_irq(ICH9LPCState *lpc);
 
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index a23c0f0..071ae14 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -35,6 +35,7 @@
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
 #include "qom/cpu.h"
+#include "qom/property.h"
 
 #include "hw/boards.h"
 #include "hw/ppc/ppc.h"
diff --git a/include/qom/object.h b/include/qom/object.h
index 8a05a81..4216b07 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1170,91 +1170,6 @@ void object_property_add_link(Object *obj, const char *name,
                               Error **errp);
 
 /**
- * object_property_add_str:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @get: the getter or NULL if the property is write-only.  This function must
- *   return a string to be freed by g_free().
- * @set: the setter or NULL if the property is read-only
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add a string property using getters/setters.  This function will add a
- * property of type 'string'.
- */
-void object_property_add_str(Object *obj, const char *name,
-                             char *(*get)(Object *, Error **),
-                             void (*set)(Object *, const char *, Error **),
-                             Error **errp);
-
-/**
- * object_property_add_bool:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @get: the getter or NULL if the property is write-only.
- * @set: the setter or NULL if the property is read-only
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add a bool property using getters/setters.  This function will add a
- * property of type 'bool'.
- */
-void object_property_add_bool(Object *obj, const char *name,
-                              bool (*get)(Object *, Error **),
-                              void (*set)(Object *, bool, Error **),
-                              Error **errp);
-
-/**
- * object_property_add_uint8_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory.  This function will add a
- * property of type 'uint8'.
- */
-void object_property_add_uint8_ptr(Object *obj, const char *name,
-                                   const uint8_t *v, Error **errp);
-
-/**
- * object_property_add_uint16_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory.  This function will add a
- * property of type 'uint16'.
- */
-void object_property_add_uint16_ptr(Object *obj, const char *name,
-                                    const uint16_t *v, Error **errp);
-
-/**
- * object_property_add_uint32_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory.  This function will add a
- * property of type 'uint32'.
- */
-void object_property_add_uint32_ptr(Object *obj, const char *name,
-                                    const uint32_t *v, Error **errp);
-
-/**
- * object_property_add_uint64_ptr:
- * @obj: the object to add a property to
- * @name: the name of the property
- * @v: pointer to value
- * @errp: if an error occurs, a pointer to an area to store the error
- *
- * Add an integer property in memory.  This function will add a
- * property of type 'uint64'.
- */
-void object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v, Error **Errp);
-
-/**
  * object_property_add_alias:
  * @obj: the object to add a property to
  * @name: the name of the property
diff --git a/include/qom/property.h b/include/qom/property.h
new file mode 100644
index 0000000..bb09523
--- /dev/null
+++ b/include/qom/property.h
@@ -0,0 +1,104 @@
+/*
+ * QEMU Object Model, property helpers
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_PROPERTY_H
+#define QEMU_PROPERTY_H
+
+#include "qom/object.h"
+
+/**
+ * object_property_add_str:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @get: the getter or NULL if the property is write-only.  This function must
+ *   return a string to be freed by g_free().
+ * @set: the setter or NULL if the property is read-only
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add a string property using getters/setters.  This function will add a
+ * property of type 'string'.
+ */
+void object_property_add_str(Object *obj, const char *name,
+                             char *(*get)(Object *, Error **),
+                             void (*set)(Object *, const char *, Error **),
+                             Error **errp);
+
+/**
+ * object_property_add_bool:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @get: the getter or NULL if the property is write-only.
+ * @set: the setter or NULL if the property is read-only
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add a bool property using getters/setters.  This function will add a
+ * property of type 'bool'.
+ */
+void object_property_add_bool(Object *obj, const char *name,
+                              bool (*get)(Object *, Error **),
+                              void (*set)(Object *, bool, Error **),
+                              Error **errp);
+
+/**
+ * object_property_add_uint8_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory.  This function will add a
+ * property of type 'uint8'.
+ */
+void object_property_add_uint8_ptr(Object *obj, const char *name,
+                                   const uint8_t *v, Error **errp);
+
+/**
+ * object_property_add_uint16_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory.  This function will add a
+ * property of type 'uint16'.
+ */
+void object_property_add_uint16_ptr(Object *obj, const char *name,
+                                    const uint16_t *v, Error **errp);
+
+/**
+ * object_property_add_uint32_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory.  This function will add a
+ * property of type 'uint32'.
+ */
+void object_property_add_uint32_ptr(Object *obj, const char *name,
+                                    const uint32_t *v, Error **errp);
+
+/**
+ * object_property_add_uint64_ptr:
+ * @obj: the object to add a property to
+ * @name: the name of the property
+ * @v: pointer to value
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Add an integer property in memory.  This function will add a
+ * property of type 'uint64'.
+ */
+void object_property_add_uint64_ptr(Object *obj, const char *name,
+                                    const uint64_t *v, Error **Errp);
+
+#endif /* !QEMU_PROPERTY_H */
diff --git a/memory.c b/memory.c
index 64d7176..ab1471b 100644
--- a/memory.c
+++ b/memory.c
@@ -19,6 +19,7 @@
 #include "qapi/visitor.h"
 #include "qemu/bitops.h"
 #include "qom/object.h"
+#include "qom/property.h"
 #include "trace.h"
 #include <assert.h>
 
diff --git a/qom/Makefile.objs b/qom/Makefile.objs
index 985003b..bbd5359 100644
--- a/qom/Makefile.objs
+++ b/qom/Makefile.objs
@@ -1,3 +1,3 @@
-common-obj-y = object.o container.o qom-qobject.o
+common-obj-y = object.o container.o qom-qobject.o property.o
 common-obj-y += cpu.o
 common-obj-y += object_interfaces.o
diff --git a/qom/object.c b/qom/object.c
index 0e8267b..94a19ce 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -11,6 +11,7 @@
  */
 
 #include "qom/object.h"
+#include "qom/property.h"
 #include "qemu-common.h"
 #include "qapi/visitor.h"
 #include "qapi-visit.h"
@@ -1376,197 +1377,6 @@ Object *object_resolve_path(const char *path, bool *ambiguous)
     return object_resolve_path_type(path, TYPE_OBJECT, ambiguous);
 }
 
-typedef struct StringProperty
-{
-    char *(*get)(Object *, Error **);
-    void (*set)(Object *, const char *, Error **);
-} StringProperty;
-
-static void property_get_str(Object *obj, Visitor *v, void *opaque,
-                             const char *name, Error **errp)
-{
-    StringProperty *prop = opaque;
-    char *value;
-
-    value = prop->get(obj, errp);
-    if (value) {
-        visit_type_str(v, &value, name, errp);
-        g_free(value);
-    }
-}
-
-static void property_set_str(Object *obj, Visitor *v, void *opaque,
-                             const char *name, Error **errp)
-{
-    StringProperty *prop = opaque;
-    char *value;
-    Error *local_err = NULL;
-
-    visit_type_str(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-
-    prop->set(obj, value, errp);
-    g_free(value);
-}
-
-static void property_release_str(Object *obj, const char *name,
-                                 void *opaque)
-{
-    StringProperty *prop = opaque;
-    g_free(prop);
-}
-
-void object_property_add_str(Object *obj, const char *name,
-                           char *(*get)(Object *, Error **),
-                           void (*set)(Object *, const char *, Error **),
-                           Error **errp)
-{
-    Error *local_err = NULL;
-    StringProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-    prop->set = set;
-
-    object_property_add(obj, name, "string",
-                        get ? property_get_str : NULL,
-                        set ? property_set_str : NULL,
-                        property_release_str,
-                        prop, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        g_free(prop);
-    }
-}
-
-typedef struct BoolProperty
-{
-    bool (*get)(Object *, Error **);
-    void (*set)(Object *, bool, Error **);
-} BoolProperty;
-
-static void property_get_bool(Object *obj, Visitor *v, void *opaque,
-                              const char *name, Error **errp)
-{
-    BoolProperty *prop = opaque;
-    bool value;
-
-    value = prop->get(obj, errp);
-    visit_type_bool(v, &value, name, errp);
-}
-
-static void property_set_bool(Object *obj, Visitor *v, void *opaque,
-                              const char *name, Error **errp)
-{
-    BoolProperty *prop = opaque;
-    bool value;
-    Error *local_err = NULL;
-
-    visit_type_bool(v, &value, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-
-    prop->set(obj, value, errp);
-}
-
-static void property_release_bool(Object *obj, const char *name,
-                                  void *opaque)
-{
-    BoolProperty *prop = opaque;
-    g_free(prop);
-}
-
-void object_property_add_bool(Object *obj, const char *name,
-                              bool (*get)(Object *, Error **),
-                              void (*set)(Object *, bool, Error **),
-                              Error **errp)
-{
-    Error *local_err = NULL;
-    BoolProperty *prop = g_malloc0(sizeof(*prop));
-
-    prop->get = get;
-    prop->set = set;
-
-    object_property_add(obj, name, "bool",
-                        get ? property_get_bool : NULL,
-                        set ? property_set_bool : NULL,
-                        property_release_bool,
-                        prop, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        g_free(prop);
-    }
-}
-
-static char *qdev_get_type(Object *obj, Error **errp)
-{
-    return g_strdup(object_get_typename(obj));
-}
-
-static void property_get_uint8_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint8_t value = *(uint8_t *)opaque;
-    visit_type_uint8(v, &value, name, errp);
-}
-
-static void property_get_uint16_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint16_t value = *(uint16_t *)opaque;
-    visit_type_uint16(v, &value, name, errp);
-}
-
-static void property_get_uint32_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint32_t value = *(uint32_t *)opaque;
-    visit_type_uint32(v, &value, name, errp);
-}
-
-static void property_get_uint64_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint64_t value = *(uint64_t *)opaque;
-    visit_type_uint64(v, &value, name, errp);
-}
-
-void object_property_add_uint8_ptr(Object *obj, const char *name,
-                                   const uint8_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint8", property_get_uint8_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint16_ptr(Object *obj, const char *name,
-                                    const uint16_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint16", property_get_uint16_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint32_ptr(Object *obj, const char *name,
-                                    const uint32_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint32", property_get_uint32_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint64", property_get_uint64_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
 typedef struct {
     Object *target_obj;
     const char *target_name;
@@ -1638,6 +1448,11 @@ void object_property_add_alias(Object *obj, const char *name,
     g_free(prop_type);
 }
 
+static char *qdev_get_type(Object *obj, Error **errp)
+{
+    return g_strdup(object_get_typename(obj));
+}
+
 static void object_instance_init(Object *obj)
 {
     object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
diff --git a/qom/property.c b/qom/property.c
new file mode 100644
index 0000000..9e7c92a
--- /dev/null
+++ b/qom/property.c
@@ -0,0 +1,212 @@
+/*
+ * QEMU Object Model, property helpers
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qom/property.h"
+#include "qemu-common.h"
+#include "qapi/visitor.h"
+#include "qapi-visit.h"
+#include "qapi/string-input-visitor.h"
+#include "qapi/string-output-visitor.h"
+#include "qapi/qmp/qerror.h"
+#include "trace.h"
+
+#include "qom/qom-qobject.h"
+#include "qapi/qmp/qobject.h"
+#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qint.h"
+#include "qapi/qmp/qstring.h"
+
+typedef struct StringProperty
+{
+    char *(*get)(Object *, Error **);
+    void (*set)(Object *, const char *, Error **);
+} StringProperty;
+
+static void property_get_str(Object *obj, Visitor *v, void *opaque,
+                             const char *name, Error **errp)
+{
+    StringProperty *prop = opaque;
+    char *value;
+
+    value = prop->get(obj, errp);
+    if (value) {
+        visit_type_str(v, &value, name, errp);
+        g_free(value);
+    }
+}
+
+static void property_set_str(Object *obj, Visitor *v, void *opaque,
+                             const char *name, Error **errp)
+{
+    StringProperty *prop = opaque;
+    char *value;
+    Error *local_err = NULL;
+
+    visit_type_str(v, &value, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    prop->set(obj, value, errp);
+    g_free(value);
+}
+
+static void property_release_str(Object *obj, const char *name,
+                                 void *opaque)
+{
+    StringProperty *prop = opaque;
+    g_free(prop);
+}
+
+void object_property_add_str(Object *obj, const char *name,
+                           char *(*get)(Object *, Error **),
+                           void (*set)(Object *, const char *, Error **),
+                           Error **errp)
+{
+    Error *local_err = NULL;
+    StringProperty *prop = g_malloc0(sizeof(*prop));
+
+    prop->get = get;
+    prop->set = set;
+
+    object_property_add(obj, name, "string",
+                        get ? property_get_str : NULL,
+                        set ? property_set_str : NULL,
+                        property_release_str,
+                        prop, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        g_free(prop);
+    }
+}
+
+typedef struct BoolProperty
+{
+    bool (*get)(Object *, Error **);
+    void (*set)(Object *, bool, Error **);
+} BoolProperty;
+
+static void property_get_bool(Object *obj, Visitor *v, void *opaque,
+                              const char *name, Error **errp)
+{
+    BoolProperty *prop = opaque;
+    bool value;
+
+    value = prop->get(obj, errp);
+    visit_type_bool(v, &value, name, errp);
+}
+
+static void property_set_bool(Object *obj, Visitor *v, void *opaque,
+                              const char *name, Error **errp)
+{
+    BoolProperty *prop = opaque;
+    bool value;
+    Error *local_err = NULL;
+
+    visit_type_bool(v, &value, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    prop->set(obj, value, errp);
+}
+
+static void property_release_bool(Object *obj, const char *name,
+                                  void *opaque)
+{
+    BoolProperty *prop = opaque;
+    g_free(prop);
+}
+
+void object_property_add_bool(Object *obj, const char *name,
+                              bool (*get)(Object *, Error **),
+                              void (*set)(Object *, bool, Error **),
+                              Error **errp)
+{
+    Error *local_err = NULL;
+    BoolProperty *prop = g_malloc0(sizeof(*prop));
+
+    prop->get = get;
+    prop->set = set;
+
+    object_property_add(obj, name, "bool",
+                        get ? property_get_bool : NULL,
+                        set ? property_set_bool : NULL,
+                        property_release_bool,
+                        prop, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        g_free(prop);
+    }
+}
+
+static void property_get_uint8_ptr(Object *obj, Visitor *v,
+                                   void *opaque, const char *name,
+                                   Error **errp)
+{
+    uint8_t value = *(uint8_t *)opaque;
+    visit_type_uint8(v, &value, name, errp);
+}
+
+static void property_get_uint16_ptr(Object *obj, Visitor *v,
+                                   void *opaque, const char *name,
+                                   Error **errp)
+{
+    uint16_t value = *(uint16_t *)opaque;
+    visit_type_uint16(v, &value, name, errp);
+}
+
+static void property_get_uint32_ptr(Object *obj, Visitor *v,
+                                   void *opaque, const char *name,
+                                   Error **errp)
+{
+    uint32_t value = *(uint32_t *)opaque;
+    visit_type_uint32(v, &value, name, errp);
+}
+
+static void property_get_uint64_ptr(Object *obj, Visitor *v,
+                                   void *opaque, const char *name,
+                                   Error **errp)
+{
+    uint64_t value = *(uint64_t *)opaque;
+    visit_type_uint64(v, &value, name, errp);
+}
+
+void object_property_add_uint8_ptr(Object *obj, const char *name,
+                                   const uint8_t *v, Error **errp)
+{
+    object_property_add(obj, name, "uint8", property_get_uint8_ptr,
+                        NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint16_ptr(Object *obj, const char *name,
+                                    const uint16_t *v, Error **errp)
+{
+    object_property_add(obj, name, "uint16", property_get_uint16_ptr,
+                        NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint32_ptr(Object *obj, const char *name,
+                                    const uint32_t *v, Error **errp)
+{
+    object_property_add(obj, name, "uint32", property_get_uint32_ptr,
+                        NULL, NULL, (void *)v, errp);
+}
+
+void object_property_add_uint64_ptr(Object *obj, const char *name,
+                                    const uint64_t *v, Error **errp)
+{
+    object_property_add(obj, name, "uint64", property_get_uint64_ptr,
+                        NULL, NULL, (void *)v, errp);
+}
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 45c662d..1ae6fe5 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -43,6 +43,7 @@
 
 #include "sysemu/sysemu.h"
 #include "hw/qdev-properties.h"
+#include "qom/property.h"
 #include "hw/cpu/icc_bus.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/xen/xen.h"
diff --git a/ui/console.c b/ui/console.c
index ab84549..25ac4ff 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -28,6 +28,7 @@
 #include "qmp-commands.h"
 #include "sysemu/char.h"
 #include "trace.h"
+#include "qom/property.h"
 
 #define DEFAULT_BACKSCROLL 512
 #define CONSOLE_CURSOR_PERIOD 500
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-31 13:44   ` Peter Crosthwaite
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 3/9] qom: Expose property helpers for get/set of integers Alexander Graf
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

We have a bunch of nice helpers that allow us to easily register an integer
field as QOM property. However, we have those duplicated for every integer
size available.

This is very cumbersome (and prone to bugs) to work with and extend, so let's
strip out the only difference there is (the size) and generate the actual
functions via a macro.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - Rename DECLARE_INTEGER_VISITOR to DECLARE_PROP_SET_GET
  - Make macro take name and type arguments, enabling generation of "bool"
    types later
---
 qom/property.c | 82 +++++++++++++++++-----------------------------------------
 1 file changed, 24 insertions(+), 58 deletions(-)

diff --git a/qom/property.c b/qom/property.c
index 9e7c92a..944daff 100644
--- a/qom/property.c
+++ b/qom/property.c
@@ -151,62 +151,28 @@ void object_property_add_bool(Object *obj, const char *name,
     }
 }
 
-static void property_get_uint8_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint8_t value = *(uint8_t *)opaque;
-    visit_type_uint8(v, &value, name, errp);
-}
-
-static void property_get_uint16_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint16_t value = *(uint16_t *)opaque;
-    visit_type_uint16(v, &value, name, errp);
-}
-
-static void property_get_uint32_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint32_t value = *(uint32_t *)opaque;
-    visit_type_uint32(v, &value, name, errp);
-}
-
-static void property_get_uint64_ptr(Object *obj, Visitor *v,
-                                   void *opaque, const char *name,
-                                   Error **errp)
-{
-    uint64_t value = *(uint64_t *)opaque;
-    visit_type_uint64(v, &value, name, errp);
-}
+#define DECLARE_PROP_SET_GET(name, valtype)                                    \
+                                                                               \
+static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v,       \
+                                                void *opaque,                  \
+                                                const char *name,              \
+                                                Error **errp)                  \
+{                                                                              \
+    valtype value = *(valtype *)opaque;                                        \
+    glue(visit_type_,name)(v, &value, name, errp);                             \
+}                                                                              \
+                                                                               \
+void glue(glue(object_property_add_,name),_ptr)(Object *obj, const char *name, \
+                                                const valtype *v,              \
+                                                Error **errp)                  \
+{                                                                              \
+    ObjectPropertyAccessor *get = glue(glue(property_get_,name),_ptr);         \
+    object_property_add(obj, name, stringify(name), get, NULL, NULL, (void *)v,\
+                        errp);                                                 \
+}                                                                              \
+
+DECLARE_PROP_SET_GET(uint8, uint8_t)
+DECLARE_PROP_SET_GET(uint16, uint16_t)
+DECLARE_PROP_SET_GET(uint32, uint32_t)
+DECLARE_PROP_SET_GET(uint64, uint64_t)
 
-void object_property_add_uint8_ptr(Object *obj, const char *name,
-                                   const uint8_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint8", property_get_uint8_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint16_ptr(Object *obj, const char *name,
-                                    const uint16_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint16", property_get_uint16_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint32_ptr(Object *obj, const char *name,
-                                    const uint32_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint32", property_get_uint32_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-
-void object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v, Error **errp)
-{
-    object_property_add(obj, name, "uint64", property_get_uint64_ptr,
-                        NULL, NULL, (void *)v, errp);
-}
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 3/9] qom: Expose property helpers for get/set of integers
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 4/9] qom: Add generic object property g_free helper Alexander Graf
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

We have helper functions to easily expose integers as QOM object properties.
However, these are read only.

This patch makes the getter function world accessible and adds a generic
setter for integer properties.

We can use these later with the generic object_property_add to not dupliate
simple logic all over the place.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 include/qom/property.h | 128 +++++++++++++++++++++++++++++++++++++++++++++++++
 qom/property.c         |  14 +++++-
 2 files changed, 140 insertions(+), 2 deletions(-)

diff --git a/include/qom/property.h b/include/qom/property.h
index bb09523..470c722 100644
--- a/include/qom/property.h
+++ b/include/qom/property.h
@@ -63,6 +63,38 @@ void object_property_add_uint8_ptr(Object *obj, const char *name,
                                    const uint8_t *v, Error **errp);
 
 /**
+ * object_property_get_uint8_ptr:
+ * @obj: the object to get the property from
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value we write the result to
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to read an integer value of type 'uint8' into the visitor.
+ * Use this as the 'get' argument in object_property_add if your field is a
+ * uint8_t value.
+ */
+void object_property_get_uint8_ptr(Object *obj, struct Visitor *v,
+                                   void *opaque, const char *name,
+                                   Error **errp);
+
+/**
+ * object_property_set_uint8_ptr:
+ * @obj: the object to set the property in
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to set an integer value of type 'uint8' to a given value.
+ * Use this as the 'set' argument in object_property_add if your field is a
+ * uint8_t value.
+ */
+void object_property_set_uint8_ptr(Object *obj, struct Visitor *v,
+                                   void *opaque, const char *name,
+                                   Error **errp);
+
+/**
  * object_property_add_uint16_ptr:
  * @obj: the object to add a property to
  * @name: the name of the property
@@ -76,6 +108,38 @@ void object_property_add_uint16_ptr(Object *obj, const char *name,
                                     const uint16_t *v, Error **errp);
 
 /**
+ * object_property_get_uint16_ptr:
+ * @obj: the object to get the property from
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value we write the result to
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to read an integer value of type 'uint16' into the visitor.
+ * Use this as the 'get' argument in object_property_add if your field is a
+ * uint16_t value.
+ */
+void object_property_get_uint16_ptr(Object *obj, struct Visitor *v,
+                                    void *opaque, const char *name,
+                                    Error **errp);
+
+/**
+ * object_property_set_uint16_ptr:
+ * @obj: the object to set the property in
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to set an integer value of type 'uint16' to a given value.
+ * Use this as the 'set' argument in object_property_add if your field is a
+ * uint16_t value.
+ */
+void object_property_set_uint16_ptr(Object *obj, struct Visitor *v,
+                                    void *opaque, const char *name,
+                                    Error **errp);
+
+/**
  * object_property_add_uint32_ptr:
  * @obj: the object to add a property to
  * @name: the name of the property
@@ -89,6 +153,38 @@ void object_property_add_uint32_ptr(Object *obj, const char *name,
                                     const uint32_t *v, Error **errp);
 
 /**
+ * object_property_get_uint32_ptr:
+ * @obj: the object to get the property from
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value we write the result to
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to read an integer value of type 'uint32' into the visitor.
+ * Use this as the 'get' argument in object_property_add if your field is a
+ * uint32_t value.
+ */
+void object_property_get_uint32_ptr(Object *obj, struct Visitor *v,
+                                    void *opaque, const char *name,
+                                    Error **errp);
+
+/**
+ * object_property_set_uint32_ptr:
+ * @obj: the object to set the property in
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to set an integer value of type 'uint32' to a given value.
+ * Use this as the 'set' argument in object_property_add if your field is a
+ * uint32_t value.
+ */
+void object_property_set_uint32_ptr(Object *obj, struct Visitor *v,
+                                    void *opaque, const char *name,
+                                    Error **errp);
+
+/**
  * object_property_add_uint64_ptr:
  * @obj: the object to add a property to
  * @name: the name of the property
@@ -101,4 +197,36 @@ void object_property_add_uint32_ptr(Object *obj, const char *name,
 void object_property_add_uint64_ptr(Object *obj, const char *name,
                                     const uint64_t *v, Error **Errp);
 
+/**
+ * object_property_get_uint64_ptr:
+ * @obj: the object to get the property from
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value we write the result to
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to read an integer value of type 'uint64' into the visitor.
+ * Use this as the 'get' argument in object_property_add if your field is a
+ * uint64_t value.
+ */
+void object_property_get_uint64_ptr(Object *obj, struct Visitor *v,
+                                    void *opaque, const char *name,
+                                    Error **errp);
+
+/**
+ * object_property_set_uint64_ptr:
+ * @obj: the object to set the property in
+ * @v: visitor to the property
+ * @opaque: pointer to the integer value
+ * @name: name of the property
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Visitor function to set an integer value of type 'uint64' to a given value.
+ * Use this as the 'set' argument in object_property_add if your field is a
+ * uint64_t value.
+ */
+void object_property_set_uint64_ptr(Object *obj, struct Visitor *v,
+                                    void *opaque, const char *name,
+                                    Error **errp);
+
 #endif /* !QEMU_PROPERTY_H */
diff --git a/qom/property.c b/qom/property.c
index 944daff..b4f27e9 100644
--- a/qom/property.c
+++ b/qom/property.c
@@ -153,7 +153,7 @@ void object_property_add_bool(Object *obj, const char *name,
 
 #define DECLARE_PROP_SET_GET(name, valtype)                                    \
                                                                                \
-static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v,       \
+void glue(glue(object_property_get_,name),_ptr)(Object *obj, Visitor *v,       \
                                                 void *opaque,                  \
                                                 const char *name,              \
                                                 Error **errp)                  \
@@ -162,11 +162,21 @@ static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v,       \
     glue(visit_type_,name)(v, &value, name, errp);                             \
 }                                                                              \
                                                                                \
+void glue(glue(object_property_set_,name),_ptr)(Object *obj, Visitor *v,       \
+                                                void *opaque,                  \
+                                                const char *name,              \
+                                                Error **errp)                  \
+{                                                                              \
+    valtype value;                                                             \
+    glue(visit_type_,name)(v, &value, name, errp);                             \
+    *(valtype *)opaque = value;                                                \
+}                                                                              \
+                                                                               \
 void glue(glue(object_property_add_,name),_ptr)(Object *obj, const char *name, \
                                                 const valtype *v,              \
                                                 Error **errp)                  \
 {                                                                              \
-    ObjectPropertyAccessor *get = glue(glue(property_get_,name),_ptr);         \
+    ObjectPropertyAccessor *get = glue(glue(object_property_get_,name),_ptr);  \
     object_property_add(obj, name, stringify(name), get, NULL, NULL, (void *)v,\
                         errp);                                                 \
 }                                                                              \
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 4/9] qom: Add generic object property g_free helper
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
                   ` (2 preceding siblings ...)
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 3/9] qom: Expose property helpers for get/set of integers Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 5/9] sysbus: Add user map hints Alexander Graf
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

A good amount of properties are really just g_new / g_malloc allocated memory.
There's no reason we need to have different release helpers for all of those.

This patch introduces a new g_free() based helper for property release and
replaces existing duplicated code implementations in object.c as well as
property.c with it.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 include/qom/property.h | 12 ++++++++++++
 qom/object.c           |  9 +--------
 qom/property.c         | 17 ++++-------------
 3 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/include/qom/property.h b/include/qom/property.h
index 470c722..52675ba 100644
--- a/include/qom/property.h
+++ b/include/qom/property.h
@@ -229,4 +229,16 @@ void object_property_set_uint64_ptr(Object *obj, struct Visitor *v,
                                     void *opaque, const char *name,
                                     Error **errp);
 
+/**
+ * object_property_release_g_free:
+ * @obj: the object that owns the property
+ * @name: name of the property
+ * @opaque: pointer to glib allocated memory
+ *
+ * Generic helper function to free a property using g_free(). Use this if you
+ * want to make sure that your property is properly g_free()'d when the property
+ * gets released.
+ */
+void object_property_release_g_free(Object *obj, const char *name, void *opaque);
+
 #endif /* !QEMU_PROPERTY_H */
diff --git a/qom/object.c b/qom/object.c
index 94a19ce..b3dabb2 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1406,13 +1406,6 @@ static Object *property_resolve_alias(Object *obj, void *opaque,
     return object_resolve_path_component(prop->target_obj, prop->target_name);
 }
 
-static void property_release_alias(Object *obj, const char *name, void *opaque)
-{
-    AliasProperty *prop = opaque;
-
-    g_free(prop);
-}
-
 void object_property_add_alias(Object *obj, const char *name,
                                Object *target_obj, const char *target_name,
                                Error **errp)
@@ -1441,7 +1434,7 @@ void object_property_add_alias(Object *obj, const char *name,
     op = object_property_add(obj, name, prop_type,
                              property_get_alias,
                              property_set_alias,
-                             property_release_alias,
+                             object_property_release_g_free,
                              prop, errp);
     op->resolve = property_resolve_alias;
 
diff --git a/qom/property.c b/qom/property.c
index b4f27e9..ce80a17 100644
--- a/qom/property.c
+++ b/qom/property.c
@@ -61,11 +61,9 @@ static void property_set_str(Object *obj, Visitor *v, void *opaque,
     g_free(value);
 }
 
-static void property_release_str(Object *obj, const char *name,
-                                 void *opaque)
+void object_property_release_g_free(Object *obj, const char *name, void *opaque)
 {
-    StringProperty *prop = opaque;
-    g_free(prop);
+    g_free(opaque);
 }
 
 void object_property_add_str(Object *obj, const char *name,
@@ -82,7 +80,7 @@ void object_property_add_str(Object *obj, const char *name,
     object_property_add(obj, name, "string",
                         get ? property_get_str : NULL,
                         set ? property_set_str : NULL,
-                        property_release_str,
+                        object_property_release_g_free,
                         prop, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
@@ -122,13 +120,6 @@ static void property_set_bool(Object *obj, Visitor *v, void *opaque,
     prop->set(obj, value, errp);
 }
 
-static void property_release_bool(Object *obj, const char *name,
-                                  void *opaque)
-{
-    BoolProperty *prop = opaque;
-    g_free(prop);
-}
-
 void object_property_add_bool(Object *obj, const char *name,
                               bool (*get)(Object *, Error **),
                               void (*set)(Object *, bool, Error **),
@@ -143,7 +134,7 @@ void object_property_add_bool(Object *obj, const char *name,
     object_property_add(obj, name, "bool",
                         get ? property_get_bool : NULL,
                         set ? property_set_bool : NULL,
-                        property_release_bool,
+                        object_property_release_g_free,
                         prop, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 5/9] sysbus: Add user map hints
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
                   ` (3 preceding siblings ...)
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 4/9] qom: Add generic object property g_free helper Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 6/9] sysbus: Make devices spawnable via -device Alexander Graf
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

We want to give the user the ability to tell our machine file where he wants
to have devices mapped to. This patch adds code to create these hints
dynamically and expose them as object properties that can only be modified
before device realization.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - make irq and pio properties uint64
  - ensure qom exposed pointers don't change due to realloc
  - fix sysbus_pass_irq
  - make properties write-once, not write-before-realize
  - make props only available via qom, no state pointers left
---
 hw/core/sysbus.c    | 43 ++++++++++++++++++++++++++++++++++++++++---
 include/hw/sysbus.h |  1 +
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index f4e760d..e551e16 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -20,6 +20,7 @@
 #include "hw/sysbus.h"
 #include "monitor/monitor.h"
 #include "exec/address-spaces.h"
+#include "qom/property.h"
 
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *sysbus_get_fw_dev_path(DeviceState *dev);
@@ -86,6 +87,34 @@ void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
     sysbus_mmio_map_common(dev, n, addr, true, priority);
 }
 
+static void sysbus_property_set_uint64_ptr(Object *obj, Visitor *v,
+                                           void *opaque, const char *name,
+                                           Error **errp)
+{
+    uint64_t *valp = opaque;
+
+    if (*valp != SYSBUS_DYNAMIC) {
+        error_setg(errp, "Attempt to set property '%s' twice", name);
+        return;
+    }
+
+    object_property_set_uint64_ptr(obj, v, opaque, name, errp);
+}
+
+static void sysbus_init_int64_prop(SysBusDevice *dev, const char *propstr,
+                                   int n)
+{
+    char *name = g_strdup_printf(propstr, n);
+    Object *obj = OBJECT(dev);
+    uint64_t *user_val = g_new(uint64_t, 1);
+
+    *user_val = SYSBUS_DYNAMIC;
+
+    object_property_add(obj, name, "uint64", object_property_get_uint64_ptr,
+                        sysbus_property_set_uint64_ptr,
+                        object_property_release_g_free, user_val, NULL);
+}
+
 /* Request an IRQ source.  The actual IRQ object may be populated later.  */
 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)
 {
@@ -94,6 +123,8 @@ void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)
     assert(dev->num_irq < QDEV_MAX_IRQ);
     n = dev->num_irq++;
     dev->irqp[n] = p;
+
+    sysbus_init_int64_prop(dev, "irq[%d]", n);
 }
 
 /* Pass IRQs from a target device.  */
@@ -101,9 +132,8 @@ void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target)
 {
     int i;
     assert(dev->num_irq == 0);
-    dev->num_irq = target->num_irq;
     for (i = 0; i < dev->num_irq; i++) {
-        dev->irqp[i] = target->irqp[i];
+        sysbus_init_irq(dev, target->irqp[i]);
     }
 }
 
@@ -115,6 +145,8 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory)
     n = dev->num_mmio++;
     dev->mmio[n].addr = -1;
     dev->mmio[n].memory = memory;
+
+    sysbus_init_int64_prop(dev, "mmio[%d]", n);
 }
 
 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n)
@@ -127,8 +159,13 @@ void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size)
     pio_addr_t i;
 
     for (i = 0; i < size; i++) {
+        int n;
+
         assert(dev->num_pio < QDEV_MAX_PIO);
-        dev->pio[dev->num_pio++] = ioport++;
+        n = dev->num_pio++;
+        dev->pio[n] = ioport++;
+
+        sysbus_init_int64_prop(dev, "pio[%d]", n);
     }
 }
 
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index f5aaa05..533184a 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -9,6 +9,7 @@
 #define QDEV_MAX_MMIO 32
 #define QDEV_MAX_PIO 32
 #define QDEV_MAX_IRQ 512
+#define SYSBUS_DYNAMIC -1ULL
 
 #define TYPE_SYSTEM_BUS "System"
 #define SYSTEM_BUS(obj) OBJECT_CHECK(IDEBus, (obj), TYPE_IDE_BUS)
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 6/9] sysbus: Make devices spawnable via -device
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
                   ` (4 preceding siblings ...)
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 5/9] sysbus: Add user map hints Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

Now that we can properly map sysbus devices that haven't been connected to
something forcefully by C code, we can allow the -device command line option
to spawn them.

For machines that don't implement dynamic sysbus assignment in their board
files we add a new bool "has_dynamic_sysbus" to the machine class.
When that property is false (default), we bail out when we see dynamically
spawned sysbus devices, like we did before.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - use bool in MachineClass rather than property
---
 hw/core/machine.c   | 43 +++++++++++++++++++++++++++++++++++++++++++
 hw/core/sysbus.c    |  7 -------
 include/hw/boards.h |  8 ++++++--
 vl.c                |  1 +
 4 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index c25cc07..713c9d8 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -13,6 +13,9 @@
 #include "hw/boards.h"
 #include "qapi/visitor.h"
 #include "qom/property.h"
+#include "hw/sysbus.h"
+#include "sysemu/sysemu.h"
+#include "qemu/error-report.h"
 
 static char *machine_get_accel(Object *obj, Error **errp)
 {
@@ -236,8 +239,44 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp)
     ms->firmware = g_strdup(value);
 }
 
+static int search_for_sysbus_device(Object *obj, void *opaque)
+{
+    if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) {
+        /* Container or different device, traverse it for children */
+        return object_child_foreach(obj, search_for_sysbus_device, opaque);
+    }
+
+    error_report("Device '%s' can not be handled by this machine",
+                 qdev_fw_name(DEVICE(obj)));
+    exit(1);
+}
+
+static void machine_init_notify(Notifier *notifier, void *data)
+{
+    Object *machine = qdev_get_machine();
+    ObjectClass *oc = object_get_class(machine);
+    MachineClass *mc = MACHINE_CLASS(oc);
+    Object *container;
+
+    if (mc->has_dynamic_sysbus) {
+        /* Our machine can handle dynamic sysbus devices, we're all good */
+        return;
+    }
+
+    /*
+     * Loop through all dynamically created devices and check whether there
+     * are sysbus devices among them. If there are, error out.
+     */
+    container = container_get(machine, "/peripheral");
+    search_for_sysbus_device(container, NULL);
+    container = container_get(machine, "/peripheral-anon");
+    search_for_sysbus_device(container, NULL);
+}
+
 static void machine_initfn(Object *obj)
 {
+    MachineState *ms = MACHINE(obj);
+
     object_property_add_str(obj, "accel",
                             machine_get_accel, machine_set_accel, NULL);
     object_property_add_bool(obj, "kernel_irqchip",
@@ -275,6 +314,10 @@ static void machine_initfn(Object *obj)
     object_property_add_bool(obj, "usb", machine_get_usb, machine_set_usb, NULL);
     object_property_add_str(obj, "firmware",
                             machine_get_firmware, machine_set_firmware, NULL);
+
+    /* Register notifier when init is done for sysbus sanity checks */
+    ms->sysbus_notifier.notify = machine_init_notify;
+    qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
 }
 
 static void machine_finalize(Object *obj)
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index e551e16..aacc446 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -294,13 +294,6 @@ 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 unconnected, and could not possibly work.
-     */
-    k->cannot_instantiate_with_device_add_yet = true;
 }
 
 static const TypeInfo sysbus_device_type_info = {
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 605a970..9514c62 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -35,7 +35,8 @@ struct QEMUMachine {
         use_sclp:1,
         no_floppy:1,
         no_cdrom:1,
-        no_sdcard:1;
+        no_sdcard:1,
+        has_dynamic_sysbus:1;
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
@@ -93,7 +94,8 @@ struct MachineClass {
         use_sclp:1,
         no_floppy:1,
         no_cdrom:1,
-        no_sdcard:1;
+        no_sdcard:1,
+        has_dynamic_sysbus:1;
     int is_default;
     const char *default_machine_opts;
     const char *default_boot_order;
@@ -110,6 +112,8 @@ struct MachineClass {
 struct MachineState {
     /*< private >*/
     Object parent_obj;
+    Notifier sysbus_notifier;
+
     /*< public >*/
 
     char *accel;
diff --git a/vl.c b/vl.c
index 6e084c2..1df8d4e 100644
--- a/vl.c
+++ b/vl.c
@@ -1569,6 +1569,7 @@ static void machine_class_init(ObjectClass *oc, void *data)
     mc->no_floppy = qm->no_floppy;
     mc->no_cdrom = qm->no_cdrom;
     mc->no_sdcard = qm->no_sdcard;
+    mc->has_dynamic_sysbus = qm->has_dynamic_sysbus;
     mc->is_default = qm->is_default;
     mc->default_machine_opts = qm->default_machine_opts;
     mc->default_boot_order = qm->default_boot_order;
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
                   ` (5 preceding siblings ...)
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 6/9] sysbus: Make devices spawnable via -device Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-30 14:55   ` Peter Maydell
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 8/9] e500: Add support for eTSEC in device tree Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 9/9] PPC: Fix default config ordering and add eTSEC for ppc64 Alexander Graf
  8 siblings, 1 reply; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

For e500 our approach to supporting dynamically spawned sysbus devices is to
create a simple bus from the guest's point of view within which we map those
devices dynamically.

We allocate memory regions always within the "platform" hole in address
space and map IRQs to predetermined IRQ lines that are reserved for platform
device usage.

This maps really nicely into device tree logic, so we can just tell the
guest about our virtual simple bus in device tree as well.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - access sysbus properties via qom
  - move platform bus definitions to params
  - move platform bus to 36bit address space
  - make naming more consistent
  - remove device_type from platform bus dt node
  - remove id field in dt generation
---
 hw/ppc/e500.c     | 251 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/ppc/e500.h     |   5 ++
 hw/ppc/e500plat.c |   6 ++
 3 files changed, 262 insertions(+)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index bb2e75f..f7fe41c 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -36,6 +36,7 @@
 #include "exec/address-spaces.h"
 #include "qemu/host-utils.h"
 #include "hw/pci-host/ppce500.h"
+#include "qemu/error-report.h"
 
 #define EPAPR_MAGIC                (0x45504150)
 #define BINARY_DEVICE_TREE_FILE    "mpc8544ds.dtb"
@@ -47,6 +48,8 @@
 
 #define RAM_SIZES_ALIGN            (64UL << 20)
 
+#define E500_PLATFORM_BUS_PAGE_SHIFT 12
+
 /* TODO: parameterize */
 #define MPC8544_CCSRBAR_BASE       0xE0000000ULL
 #define MPC8544_CCSRBAR_SIZE       0x00100000ULL
@@ -122,6 +125,76 @@ static void dt_serial_create(void *fdt, unsigned long long offset,
     }
 }
 
+typedef struct PlatformDevtreeData {
+    void *fdt;
+    const char *mpic;
+    int irq_start;
+    const char *node;
+} PlatformDevtreeData;
+
+static int sysbus_device_create_devtree(Object *obj, void *opaque)
+{
+    PlatformDevtreeData *data = opaque;
+    Object *dev;
+    SysBusDevice *sbdev;
+    bool matched = false;
+
+    dev = object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE);
+    sbdev = (SysBusDevice *)dev;
+
+    if (!sbdev) {
+        /* Container, traverse it for children */
+        return object_child_foreach(obj, sysbus_device_create_devtree, data);
+    }
+
+    if (!matched) {
+        error_report("Device %s is not supported by this machine yet.",
+                     qdev_fw_name(DEVICE(dev)));
+        exit(1);
+    }
+
+    return 0;
+}
+
+static void platform_bus_create_devtree(PPCE500Params *params, void *fdt,
+                                        const char *mpic)
+{
+    gchar *node = g_strdup_printf("/platform@%"PRIx64, params->platform_bus_base);
+    const char platcomp[] = "qemu,platform\0simple-bus";
+    PlatformDevtreeData data;
+    Object *container;
+    uint64_t addr = params->platform_bus_base;
+    uint64_t size = params->platform_bus_size;
+    int irq_start = params->platform_bus_first_irq;
+
+    /* Create a /platform node that we can put all devices into */
+
+    qemu_fdt_add_subnode(fdt, node);
+    qemu_fdt_setprop(fdt, node, "compatible", platcomp, sizeof(platcomp));
+
+    /* Our platform bus region is less than 32bit big, so 1 cell is enough for
+       address and size */
+    qemu_fdt_setprop_cells(fdt, node, "#size-cells", 1);
+    qemu_fdt_setprop_cells(fdt, node, "#address-cells", 1);
+    qemu_fdt_setprop_cells(fdt, node, "ranges", 0, addr >> 32, addr, size);
+
+    qemu_fdt_setprop_phandle(fdt, node, "interrupt-parent", mpic);
+
+    /* Loop through all devices and create nodes for known ones */
+
+    data.fdt = fdt;
+    data.mpic = mpic;
+    data.irq_start = irq_start;
+    data.node = node;
+
+    container = container_get(qdev_get_machine(), "/peripheral");
+    sysbus_device_create_devtree(container, &data);
+    container = container_get(qdev_get_machine(), "/peripheral-anon");
+    sysbus_device_create_devtree(container, &data);
+
+    g_free(node);
+}
+
 static int ppce500_load_device_tree(MachineState *machine,
                                     PPCE500Params *params,
                                     hwaddr addr,
@@ -379,6 +452,10 @@ static int ppce500_load_device_tree(MachineState *machine,
     qemu_fdt_setprop_cell(fdt, pci, "#address-cells", 3);
     qemu_fdt_setprop_string(fdt, "/aliases", "pci0", pci);
 
+    if (params->has_platform_bus) {
+        platform_bus_create_devtree(params, fdt, mpic);
+    }
+
     params->fixup_devtree(params, fdt);
 
     if (toplevel_compat) {
@@ -618,6 +695,169 @@ static qemu_irq *ppce500_init_mpic(PPCE500Params *params, MemoryRegion *ccsr,
     return mpic;
 }
 
+typedef struct PlatformBusNotifier {
+    Notifier notifier;
+    MemoryRegion *address_space_mem;
+    qemu_irq *mpic;
+    PPCE500Params params;
+} PlatformBusNotifier;
+
+typedef struct PlatformBusInitData {
+    unsigned long *used_irqs;
+    unsigned long *used_mem;
+    MemoryRegion *mem;
+    qemu_irq *irqs;
+    int device_count;
+    PPCE500Params *params;
+} PlatformBusInitData;
+
+static int platform_bus_map_irq(PPCE500Params *params, SysBusDevice *sbdev,
+                                int n, unsigned long *used_irqs,
+                                qemu_irq *platform_irqs)
+{
+    int max_irqs = params->platform_bus_num_irqs;
+    char *prop = g_strdup_printf("irq[%d]", n);
+    int irqn = object_property_get_int(OBJECT(sbdev), prop, NULL);
+
+    if (irqn == SYSBUS_DYNAMIC) {
+        /* Find the first available IRQ */
+        irqn = find_first_zero_bit(used_irqs, max_irqs);
+    }
+
+    if ((irqn >= max_irqs) || test_and_set_bit(irqn, used_irqs)) {
+        hw_error("e500: IRQ %d is already allocated or no free IRQ left", irqn);
+    }
+
+    sysbus_connect_irq(sbdev, n, platform_irqs[irqn]);
+    object_property_set_int(OBJECT(sbdev), irqn, prop, NULL);
+
+    g_free(prop);
+    return 0;
+}
+
+static int platform_bus_map_mmio(PPCE500Params *params, SysBusDevice *sbdev,
+                                 int n, unsigned long *used_mem,
+                                 MemoryRegion *pmem)
+{
+    MemoryRegion *device_mem = sbdev->mmio[n].memory;
+    uint64_t size = memory_region_size(device_mem);
+    uint64_t page_size = (1 << E500_PLATFORM_BUS_PAGE_SHIFT);
+    uint64_t page_mask = page_size - 1;
+    uint64_t size_pages = (size + page_mask) >> E500_PLATFORM_BUS_PAGE_SHIFT;
+    uint64_t max_size = params->platform_bus_size;
+    uint64_t max_pages = max_size >> E500_PLATFORM_BUS_PAGE_SHIFT;
+    char *prop = g_strdup_printf("mmio[%d]", n);
+    hwaddr addr = object_property_get_int(OBJECT(sbdev), prop, NULL);
+    int page;
+    int i;
+
+    page = addr >> E500_PLATFORM_BUS_PAGE_SHIFT;
+    if (addr == SYSBUS_DYNAMIC) {
+        uint64_t size_pages_align;
+
+        /* Align the region to at least its own size granularity */
+        if (is_power_of_2(size_pages)) {
+            size_pages_align = size_pages;
+        } else {
+            size_pages_align = pow2floor(size_pages) << 1;
+        }
+
+        /* Find the first available region that fits */
+        page = bitmap_find_next_zero_area(used_mem, max_pages, 0, size_pages,
+                                          size_pages_align);
+
+        addr = (uint64_t)page << E500_PLATFORM_BUS_PAGE_SHIFT;
+    }
+
+    if (page >= max_pages || test_bit(page, used_mem) ||
+        (find_next_bit(used_mem, max_pages, page) < size_pages)) {
+        hw_error("e500: Memory [%"PRIx64":%"PRIx64" is already allocated or "
+                 "no slot left", addr, size);
+    }
+
+    for (i = page; i < (page + size_pages); i++) {
+        set_bit(i, used_mem);
+    }
+
+    memory_region_add_subregion(pmem, addr, device_mem);
+    sbdev->mmio[n].addr = addr;
+    object_property_set_int(OBJECT(sbdev), addr, prop, NULL);
+
+    g_free(prop);
+    return 0;
+}
+
+static int sysbus_device_check(Object *obj, void *opaque)
+{
+    PlatformBusInitData *init = opaque;
+    Object *dev;
+    SysBusDevice *sbdev;
+    int i;
+
+    dev = object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE);
+    sbdev = (SysBusDevice *)dev;
+
+    if (!sbdev) {
+        /* Container, traverse it for children */
+        return object_child_foreach(obj, sysbus_device_check, opaque);
+    }
+
+    /* Connect sysbus device to virtual platform bus */
+    for (i = 0; i < sbdev->num_irq; i++) {
+        if (!sbdev->irqp[i]) {
+            /* This IRQ is an incoming IRQ, we can't wire those here */
+            continue;
+        }
+        platform_bus_map_irq(init->params, sbdev, i, init->used_irqs, init->irqs);
+    }
+
+    for (i = 0; i < sbdev->num_mmio; i++) {
+        platform_bus_map_mmio(init->params, sbdev, i, init->used_mem, init->mem);
+    }
+
+    return 0;
+}
+
+static void platform_bus_init(PPCE500Params *params,
+                              MemoryRegion *address_space_mem,
+                              qemu_irq *mpic)
+{
+    uint64_t max_size = params->platform_bus_size;
+    uint64_t max_pages = max_size >> E500_PLATFORM_BUS_PAGE_SHIFT;
+    DECLARE_BITMAP(used_irqs, params->platform_bus_num_irqs);
+    DECLARE_BITMAP(used_mem, max_pages);
+    MemoryRegion *platform_region = g_new(MemoryRegion, 1);
+    Object *container;
+    PlatformBusInitData init = {
+        .used_irqs = used_irqs,
+        .used_mem = used_mem,
+        .mem = platform_region,
+        .irqs = &mpic[params->platform_bus_first_irq],
+        .params = params,
+    };
+
+    memory_region_init(platform_region, NULL, "platform devices",
+                       params->platform_bus_size);
+
+    bitmap_clear(used_irqs, 0, params->platform_bus_num_irqs);
+    bitmap_clear(used_mem, 0, max_pages);
+
+    /* Loop through all sysbus devices that were spawened outside the machine */
+    container = container_get(qdev_get_machine(), "/peripheral");
+    sysbus_device_check(container, &init);
+    container = container_get(qdev_get_machine(), "/peripheral-anon");
+    sysbus_device_check(container, &init);
+
+    memory_region_add_subregion(address_space_mem, params->platform_bus_base,
+                                platform_region);
+}
+
+static void platform_bus_init_notify(Notifier *notifier, void *data)
+{
+    PlatformBusNotifier *pn = (PlatformBusNotifier *)notifier;
+    platform_bus_init(&pn->params, pn->address_space_mem, pn->mpic);
+}
+
 void ppce500_init(MachineState *machine, PPCE500Params *params)
 {
     MemoryRegion *address_space_mem = get_system_memory();
@@ -770,6 +1010,17 @@ void ppce500_init(MachineState *machine, PPCE500Params *params)
         cur_base = (32 * 1024 * 1024);
     }
 
+    /* Platform Devices */
+    if (params->has_platform_bus) {
+        PlatformBusNotifier *notifier = g_new(PlatformBusNotifier, 1);
+
+        notifier->notifier.notify = platform_bus_init_notify;
+        notifier->address_space_mem = address_space_mem;
+        notifier->mpic = mpic;
+        notifier->params = *params;
+        qemu_add_machine_init_done_notifier(&notifier->notifier);
+    }
+
     /* Load kernel. */
     if (machine->kernel_filename) {
         kernel_base = cur_base;
diff --git a/hw/ppc/e500.h b/hw/ppc/e500.h
index 08b25fa..f1b2766 100644
--- a/hw/ppc/e500.h
+++ b/hw/ppc/e500.h
@@ -11,6 +11,11 @@ typedef struct PPCE500Params {
     void (*fixup_devtree)(struct PPCE500Params *params, void *fdt);
 
     int mpic_version;
+    bool has_platform_bus;
+    hwaddr platform_bus_base;
+    hwaddr platform_bus_size;
+    int platform_bus_first_irq;
+    int platform_bus_num_irqs;
 } PPCE500Params;
 
 void ppce500_init(MachineState *machine, PPCE500Params *params);
diff --git a/hw/ppc/e500plat.c b/hw/ppc/e500plat.c
index 27df31d..befe1d1 100644
--- a/hw/ppc/e500plat.c
+++ b/hw/ppc/e500plat.c
@@ -35,6 +35,11 @@ static void e500plat_init(MachineState *machine)
         .pci_nr_slots = PCI_SLOT_MAX - 1,
         .fixup_devtree = e500plat_fixup_devtree,
         .mpic_version = OPENPIC_MODEL_FSL_MPIC_42,
+        .has_platform_bus = true,
+        .platform_bus_base = 0xf00000000ULL,
+        .platform_bus_size = (128ULL * 1024 * 1024),
+        .platform_bus_first_irq = 5,
+        .platform_bus_num_irqs = 10,
     };
 
     /* Older KVM versions don't support EPR which breaks guests when we announce
@@ -51,6 +56,7 @@ static QEMUMachine e500plat_machine = {
     .desc = "generic paravirt e500 platform",
     .init = e500plat_init,
     .max_cpus = 32,
+    .has_dynamic_sysbus = true,
 };
 
 static void e500plat_machine_init(void)
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 8/9] e500: Add support for eTSEC in device tree
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
                   ` (6 preceding siblings ...)
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 9/9] PPC: Fix default config ordering and add eTSEC for ppc64 Alexander Graf
  8 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

This patch adds support to expose eTSEC devices in the dynamically created
guest facing device tree. This allows us to expose eTSEC devices into guests
without changes in the machine file.

Because we can now tell the guest about eTSEC devices this patch allows the
user to specify eTSEC devices via -device at all.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v1 -> v2:

  - fix device name (base on reg for value after @)
  - use qom properties to fetch mmio and irq props
  - remove useless interrupt-parent
  - make interrupts level triggered
---
 hw/ppc/e500.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index f7fe41c..cbabcdf 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -37,6 +37,7 @@
 #include "qemu/host-utils.h"
 #include "hw/pci-host/ppce500.h"
 #include "qemu/error-report.h"
+#include "hw/net/fsl_etsec/etsec.h"
 
 #define EPAPR_MAGIC                (0x45504150)
 #define BINARY_DEVICE_TREE_FILE    "mpc8544ds.dtb"
@@ -132,6 +133,37 @@ typedef struct PlatformDevtreeData {
     const char *node;
 } PlatformDevtreeData;
 
+static int create_devtree_etsec(eTSEC *etsec, PlatformDevtreeData *data)
+{
+    Object *obj = OBJECT(etsec);
+    uint64_t mmio0 = object_property_get_int(obj, "mmio[0]", NULL);
+    uint64_t irq0 = object_property_get_int(obj, "irq[0]", NULL);
+    uint64_t irq1 = object_property_get_int(obj, "irq[1]", NULL);
+    uint64_t irq2 = object_property_get_int(obj, "irq[2]", NULL);
+    gchar *node = g_strdup_printf("/platform/ethernet@%"PRIx64, mmio0);
+    gchar *group = g_strdup_printf("%s/queue-group", node);
+    void *fdt = data->fdt;
+
+    qemu_fdt_add_subnode(fdt, node);
+    qemu_fdt_setprop_string(fdt, node, "device_type", "network");
+    qemu_fdt_setprop_string(fdt, node, "compatible", "fsl,etsec2");
+    qemu_fdt_setprop_string(fdt, node, "model", "eTSEC");
+    qemu_fdt_setprop(fdt, node, "local-mac-address", etsec->conf.macaddr.a, 6);
+    qemu_fdt_setprop_cells(fdt, node, "fixed-link", 0, 1, 1000, 0, 0);
+
+    qemu_fdt_add_subnode(fdt, group);
+    qemu_fdt_setprop_cells(fdt, group, "reg", mmio0, 0x1000);
+    qemu_fdt_setprop_cells(fdt, group, "interrupts",
+        data->irq_start + irq0, 0x2,
+        data->irq_start + irq1, 0x2,
+        data->irq_start + irq2, 0x2);
+
+    g_free(node);
+    g_free(group);
+
+    return 0;
+}
+
 static int sysbus_device_create_devtree(Object *obj, void *opaque)
 {
     PlatformDevtreeData *data = opaque;
@@ -147,6 +179,11 @@ static int sysbus_device_create_devtree(Object *obj, void *opaque)
         return object_child_foreach(obj, sysbus_device_create_devtree, data);
     }
 
+    if (object_dynamic_cast(obj, TYPE_ETSEC_COMMON)) {
+        create_devtree_etsec(ETSEC_COMMON(dev), data);
+        matched = true;
+    }
+
     if (!matched) {
         error_report("Device %s is not supported by this machine yet.",
                      qdev_fw_name(DEVICE(dev)));
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH v2 9/9] PPC: Fix default config ordering and add eTSEC for ppc64
  2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
                   ` (7 preceding siblings ...)
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 8/9] e500: Add support for eTSEC in device tree Alexander Graf
@ 2014-07-02 18:01 ` Alexander Graf
  8 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-02 18:01 UTC (permalink / raw)
  To: qemu-ppc
  Cc: peter.maydell, peter.crosthwaite, eric.auger, qemu-devel,
	sean.stalley, pbonzini, afaerber

We messed up the ordering in our default configs for PPC. The top entries
are generic entries, then come sections that indicate that features are only
in because of a special feature (such as PReP).

Fix the ordering again and while at it add eTSEC support to the ppc64 target
so that we can spawn eTSEC adapters with qemu-system-ppc64.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 default-configs/ppc-softmmu.mak   | 4 ++--
 default-configs/ppc64-softmmu.mak | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index 33f8d84..d725b23 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -45,8 +45,8 @@ CONFIG_PREP=y
 CONFIG_MAC=y
 CONFIG_E500=y
 CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM))
+CONFIG_ETSEC=y
+CONFIG_LIBDECNUMBER=y
 # For PReP
 CONFIG_MC146818RTC=y
-CONFIG_ETSEC=y
 CONFIG_ISA_TESTDEV=y
-CONFIG_LIBDECNUMBER=y
diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-softmmu.mak
index 37a15b7..bd30d69 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -46,6 +46,8 @@ CONFIG_PREP=y
 CONFIG_MAC=y
 CONFIG_E500=y
 CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM))
+CONFIG_ETSEC=y
+CONFIG_LIBDECNUMBER=y
 # For pSeries
 CONFIG_XICS=$(CONFIG_PSERIES)
 CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM))
@@ -58,4 +60,3 @@ CONFIG_I82374=y
 CONFIG_I8257=y
 CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
-CONFIG_LIBDECNUMBER=y
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
@ 2014-07-30 14:55   ` Peter Maydell
  2014-07-31  4:07     ` Peter Crosthwaite
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Maydell @ 2014-07-30 14:55 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Peter Crosthwaite, Eric Auger, QEMU Developers,
	qemu-ppc@nongnu.org, sean.stalley, Paolo Bonzini,
	Andreas Färber

On 2 July 2014 19:01, Alexander Graf <agraf@suse.de> wrote:
> For e500 our approach to supporting dynamically spawned sysbus devices is to
> create a simple bus from the guest's point of view within which we map those
> devices dynamically.
>
> +    /* Connect sysbus device to virtual platform bus */
> +    for (i = 0; i < sbdev->num_irq; i++) {
> +        if (!sbdev->irqp[i]) {
> +            /* This IRQ is an incoming IRQ, we can't wire those here */

I don't understand this comment -- sysbus IRQs are all outbound
by definition. Lines going in to a device are GPIOs. (Ideally we
should get rid of "sysbus IRQs" completely and just use named
inbound GPIOs for everything.)

Also, sbdev->irqp[] is private to the sysbus implementation, so
you shouldn't be fishing about in it in the platform code.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices
  2014-07-30 14:55   ` Peter Maydell
@ 2014-07-31  4:07     ` Peter Crosthwaite
  0 siblings, 0 replies; 15+ messages in thread
From: Peter Crosthwaite @ 2014-07-31  4:07 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Eric Auger, QEMU Developers, Alexander Graf, qemu-ppc@nongnu.org,
	Stalley, Sean, Paolo Bonzini, Andreas Färber

On Thu, Jul 31, 2014 at 12:55 AM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 2 July 2014 19:01, Alexander Graf <agraf@suse.de> wrote:
>> For e500 our approach to supporting dynamically spawned sysbus devices is to
>> create a simple bus from the guest's point of view within which we map those
>> devices dynamically.
>>
>> +    /* Connect sysbus device to virtual platform bus */
>> +    for (i = 0; i < sbdev->num_irq; i++) {
>> +        if (!sbdev->irqp[i]) {
>> +            /* This IRQ is an incoming IRQ, we can't wire those here */
>
> I don't understand this comment -- sysbus IRQs are all outbound
> by definition. Lines going in to a device are GPIOs. (Ideally we
> should get rid of "sysbus IRQs" completely and just use named
> inbound GPIOs for everything.)
>

I have some patches in this area. Will post shortly cc you and Alex.

> Also, sbdev->irqp[] is private to the sysbus implementation, so
> you shouldn't be fishing about in it in the platform code.
>

And this is in the crosshairs of that work:

@@ -47,8 +49,6 @@ struct SysBusDevice {
     /*< public >*/

     int num_irq;
-    qemu_irq irqs[QDEV_MAX_IRQ];
-    qemu_irq *irqp[QDEV_MAX_IRQ];


Regards,
Peter

> thanks
> -- PMM
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers Alexander Graf
@ 2014-07-31 13:44   ` Peter Crosthwaite
  0 siblings, 0 replies; 15+ messages in thread
From: Peter Crosthwaite @ 2014-07-31 13:44 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Peter Maydell, Eric Auger, qemu-devel@nongnu.org Developers,
	qemu-ppc Mailing List, Stalley, Sean, Paolo Bonzini,
	Andreas Färber

On Thu, Jul 3, 2014 at 4:01 AM, Alexander Graf <agraf@suse.de> wrote:
> We have a bunch of nice helpers that allow us to easily register an integer
> field as QOM property. However, we have those duplicated for every integer
> size available.
>
> This is very cumbersome (and prone to bugs) to work with and extend, so let's
> strip out the only difference there is (the size) and generate the actual
> functions via a macro.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
>

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>
> v1 -> v2:
>
>   - Rename DECLARE_INTEGER_VISITOR to DECLARE_PROP_SET_GET
>   - Make macro take name and type arguments, enabling generation of "bool"
>     types later
> ---
>  qom/property.c | 82 +++++++++++++++++-----------------------------------------
>  1 file changed, 24 insertions(+), 58 deletions(-)
>
> diff --git a/qom/property.c b/qom/property.c
> index 9e7c92a..944daff 100644
> --- a/qom/property.c
> +++ b/qom/property.c
> @@ -151,62 +151,28 @@ void object_property_add_bool(Object *obj, const char *name,
>      }
>  }
>
> -static void property_get_uint8_ptr(Object *obj, Visitor *v,
> -                                   void *opaque, const char *name,
> -                                   Error **errp)
> -{
> -    uint8_t value = *(uint8_t *)opaque;
> -    visit_type_uint8(v, &value, name, errp);
> -}
> -
> -static void property_get_uint16_ptr(Object *obj, Visitor *v,
> -                                   void *opaque, const char *name,
> -                                   Error **errp)
> -{
> -    uint16_t value = *(uint16_t *)opaque;
> -    visit_type_uint16(v, &value, name, errp);
> -}
> -
> -static void property_get_uint32_ptr(Object *obj, Visitor *v,
> -                                   void *opaque, const char *name,
> -                                   Error **errp)
> -{
> -    uint32_t value = *(uint32_t *)opaque;
> -    visit_type_uint32(v, &value, name, errp);
> -}
> -
> -static void property_get_uint64_ptr(Object *obj, Visitor *v,
> -                                   void *opaque, const char *name,
> -                                   Error **errp)
> -{
> -    uint64_t value = *(uint64_t *)opaque;
> -    visit_type_uint64(v, &value, name, errp);
> -}
> +#define DECLARE_PROP_SET_GET(name, valtype)                                    \
> +                                                                               \
> +static void glue(glue(property_get_,name),_ptr)(Object *obj, Visitor *v,       \
> +                                                void *opaque,                  \
> +                                                const char *name,              \
> +                                                Error **errp)                  \
> +{                                                                              \
> +    valtype value = *(valtype *)opaque;                                        \
> +    glue(visit_type_,name)(v, &value, name, errp);                             \
> +}                                                                              \
> +                                                                               \
> +void glue(glue(object_property_add_,name),_ptr)(Object *obj, const char *name, \
> +                                                const valtype *v,              \
> +                                                Error **errp)                  \
> +{                                                                              \
> +    ObjectPropertyAccessor *get = glue(glue(property_get_,name),_ptr);         \
> +    object_property_add(obj, name, stringify(name), get, NULL, NULL, (void *)v,\
> +                        errp);                                                 \
> +}                                                                              \
> +
> +DECLARE_PROP_SET_GET(uint8, uint8_t)
> +DECLARE_PROP_SET_GET(uint16, uint16_t)
> +DECLARE_PROP_SET_GET(uint32, uint32_t)
> +DECLARE_PROP_SET_GET(uint64, uint64_t)
>
> -void object_property_add_uint8_ptr(Object *obj, const char *name,
> -                                   const uint8_t *v, Error **errp)
> -{
> -    object_property_add(obj, name, "uint8", property_get_uint8_ptr,
> -                        NULL, NULL, (void *)v, errp);
> -}
> -
> -void object_property_add_uint16_ptr(Object *obj, const char *name,
> -                                    const uint16_t *v, Error **errp)
> -{
> -    object_property_add(obj, name, "uint16", property_get_uint16_ptr,
> -                        NULL, NULL, (void *)v, errp);
> -}
> -
> -void object_property_add_uint32_ptr(Object *obj, const char *name,
> -                                    const uint32_t *v, Error **errp)
> -{
> -    object_property_add(obj, name, "uint32", property_get_uint32_ptr,
> -                        NULL, NULL, (void *)v, errp);
> -}
> -
> -void object_property_add_uint64_ptr(Object *obj, const char *name,
> -                                    const uint64_t *v, Error **errp)
> -{
> -    object_property_add(obj, name, "uint64", property_get_uint64_ptr,
> -                        NULL, NULL, (void *)v, errp);
> -}
> --
> 1.8.1.4
>
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file
  2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file Alexander Graf
@ 2014-07-31 13:46   ` Peter Crosthwaite
  2014-07-31 14:12     ` Alexander Graf
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Crosthwaite @ 2014-07-31 13:46 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Peter Maydell, Eric Auger, qemu-devel@nongnu.org Developers,
	qemu-ppc Mailing List, Stalley, Sean, Paolo Bonzini,
	Andreas Färber

On Thu, Jul 3, 2014 at 4:01 AM, Alexander Graf <agraf@suse.de> wrote:
> We have accumulated a number of friendly helpers that make registration
> of properties easier. However, their number is only increasing and they
> start to clutter the core object.c file.
>
> So let's move them into a separate C file and thus ensure that we have
> room to grow :).
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  backends/hostmem-file.c |   1 +
>  backends/hostmem.c      |   1 +
>  backends/rng-egd.c      |   1 +
>  backends/rng-random.c   |   1 +
>  backends/rng.c          |   1 +
>  backends/tpm.c          |   1 +
>  hw/acpi/ich9.c          |   1 +
>  hw/acpi/pcihp.c         |   1 +
>  hw/acpi/piix4.c         |   1 +
>  hw/core/machine.c       |   1 +
>  hw/core/qdev.c          |   1 +
>  hw/i386/acpi-build.c    |   1 +
>  hw/isa/lpc_ich9.c       |   1 +
>  hw/ppc/spapr.c          |   1 +
>  include/qom/object.h    |  85 -------------------
>  include/qom/property.h  | 104 ++++++++++++++++++++++++
>  memory.c                |   1 +
>  qom/Makefile.objs       |   2 +-
>  qom/object.c            | 197 ++------------------------------------------
>  qom/property.c          | 212 ++++++++++++++++++++++++++++++++++++++++++++++++
>  target-i386/cpu.c       |   1 +
>  ui/console.c            |   1 +
>  22 files changed, 340 insertions(+), 277 deletions(-)
>  create mode 100644 include/qom/property.h
>  create mode 100644 qom/property.c
>

> - * object_property_add_uint64_ptr:
> - * @obj: the object to add a property to
> - * @name: the name of the property
> - * @v: pointer to value
> - * @errp: if an error occurs, a pointer to an area to store the error
> - *
> - * Add an integer property in memory.  This function will add a
> - * property of type 'uint64'.
> - */
> -void object_property_add_uint64_ptr(Object *obj, const char *name,
> -                                    const uint64_t *v, Error **Errp);
> -
> -/**
>   * object_property_add_alias:

Any reason to not migrate alias and link props as well?

Regards,
Peter

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file
  2014-07-31 13:46   ` Peter Crosthwaite
@ 2014-07-31 14:12     ` Alexander Graf
  0 siblings, 0 replies; 15+ messages in thread
From: Alexander Graf @ 2014-07-31 14:12 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: Peter Maydell, Eric Auger, qemu-devel@nongnu.org Developers,
	qemu-ppc Mailing List, Stalley, Sean, Paolo Bonzini,
	Andreas Färber


On 31.07.14 15:46, Peter Crosthwaite wrote:
> On Thu, Jul 3, 2014 at 4:01 AM, Alexander Graf <agraf@suse.de> wrote:
>> We have accumulated a number of friendly helpers that make registration
>> of properties easier. However, their number is only increasing and they
>> start to clutter the core object.c file.
>>
>> So let's move them into a separate C file and thus ensure that we have
>> room to grow :).
>>
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> ---
>>   backends/hostmem-file.c |   1 +
>>   backends/hostmem.c      |   1 +
>>   backends/rng-egd.c      |   1 +
>>   backends/rng-random.c   |   1 +
>>   backends/rng.c          |   1 +
>>   backends/tpm.c          |   1 +
>>   hw/acpi/ich9.c          |   1 +
>>   hw/acpi/pcihp.c         |   1 +
>>   hw/acpi/piix4.c         |   1 +
>>   hw/core/machine.c       |   1 +
>>   hw/core/qdev.c          |   1 +
>>   hw/i386/acpi-build.c    |   1 +
>>   hw/isa/lpc_ich9.c       |   1 +
>>   hw/ppc/spapr.c          |   1 +
>>   include/qom/object.h    |  85 -------------------
>>   include/qom/property.h  | 104 ++++++++++++++++++++++++
>>   memory.c                |   1 +
>>   qom/Makefile.objs       |   2 +-
>>   qom/object.c            | 197 ++------------------------------------------
>>   qom/property.c          | 212 ++++++++++++++++++++++++++++++++++++++++++++++++
>>   target-i386/cpu.c       |   1 +
>>   ui/console.c            |   1 +
>>   22 files changed, 340 insertions(+), 277 deletions(-)
>>   create mode 100644 include/qom/property.h
>>   create mode 100644 qom/property.c
>>
>> - * object_property_add_uint64_ptr:
>> - * @obj: the object to add a property to
>> - * @name: the name of the property
>> - * @v: pointer to value
>> - * @errp: if an error occurs, a pointer to an area to store the error
>> - *
>> - * Add an integer property in memory.  This function will add a
>> - * property of type 'uint64'.
>> - */
>> -void object_property_add_uint64_ptr(Object *obj, const char *name,
>> -                                    const uint64_t *v, Error **Errp);
>> -
>> -/**
>>    * object_property_add_alias:
> Any reason to not migrate alias and link props as well?

IIRC I tried, but there were more interdependencies inside the same 
file. So I went with the easy ones (that I cared about) first and left 
the rest as exercise for the reader :).


Alex

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-07-31 14:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-02 18:01 [Qemu-devel] [PATCH v2 0/9] Dynamic sysbus device allocation support Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 1/9] qom: Move property helpers to own file Alexander Graf
2014-07-31 13:46   ` Peter Crosthwaite
2014-07-31 14:12     ` Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 2/9] qom: macroify integer property helpers Alexander Graf
2014-07-31 13:44   ` Peter Crosthwaite
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 3/9] qom: Expose property helpers for get/set of integers Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 4/9] qom: Add generic object property g_free helper Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 5/9] sysbus: Add user map hints Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 6/9] sysbus: Make devices spawnable via -device Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 7/9] PPC: e500: Support dynamically spawned sysbus devices Alexander Graf
2014-07-30 14:55   ` Peter Maydell
2014-07-31  4:07     ` Peter Crosthwaite
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 8/9] e500: Add support for eTSEC in device tree Alexander Graf
2014-07-02 18:01 ` [Qemu-devel] [PATCH v2 9/9] PPC: Fix default config ordering and add eTSEC for ppc64 Alexander Graf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).