qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 00/10] CPU DeviceState v8
@ 2012-11-30 19:27 Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 01/10] create qemu-types.h for struct typedefs Eduardo Habkost
                   ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori


Changes on v8:
 - Use a simpler copyright header on qdev-properties-system.c
 - Use the new libqemustub.a mechanism instead of the (now exting)
   QEMU_WEAK_ALIAS mechanism
 - Move the reset-handler registration code to a new hw/reset.c file
 - This is based on afaerber's qom-cpu branch, that has some header cleanup
   changes. You can get the complete series in a git tree at:
   https://github.com/ehabkost/qemu-hacks/tree/cpu_qdev.v8
   git://github.com/ehabkost/qemu-hacks.git cpu_qdev.v8

v7:
 - Use the new QEMU_WEAK_ALIAS mechanism instead of the (now extinct)
   GCC_WEAK attribute (patches 20 and 21)

v6:
 - Simple rebase against latest qemu.git master
 - Patch 13: some new typedefs were added and others were removed
 - Patch 19: trivial rebase
v5:
 - Tons of header cleanups just to eliminate qlist.h <-> cpu-common.h circular
   dependency (patches 1-17)
 - Add copyright/license information to qdev-properties.c (patch 17)
 - Add copyright/license information to qdev-properties-system.c (patch 22)
 - use error_report()+abort() instead of hw_error() on qdev.c (patch 18)
 - Move qemu_[un]register_reset() and qemu_devices_reset() to qdev-core.c
   (patch 19)
 - Make vmstate_[un]register() weak stubs, instead of a new function (patch 20)
 - Make sysbus_get_default() weak stub, instead of new qbus reset (un)register
   functions (patch 21)
 - Eliminate qdev-system.c (all code is kept on qdev.c, now) (patch 22)
v4:
  - Add GCC_WEAK_DECL to functions that have GCC_WEAK versions
  - Updated the qdev_init_gpio_in() code on qdev-system.c to current version
  - Patch description updates (moved changelog below "---" and/or move info
    about changes made by different authors between SoB lines)
v3 (submitted by Igor):
  - rebased on top of 8b4a3df (today's master)
  - slight code reshuffling in (see commit's changelog)
     "qdev: separate core from the code used only by qemu-system-*"
     "move qemu_irq typedef out of cpu-common.h"
  - commit messages cleanup
v2:
  Removes the CONFIG_USER_ONLY ifdefs, and use weak symbols to move
  the vmstate and qemu_register_reset() handling to qdev-system.c

git tree for testing:
  https://github.com/ehabkost/qemu-hacks/tree/cpu_qdev.v8
  git://github.com/ehabkost/qemu-hacks.git cpu_qdev.v8

References to previous versions:
  v7: http://article.gmane.org/gmane.comp.emulators.qemu/179969
  v6: http://article.gmane.org/gmane.comp.emulators.qemu/179918
  v5: http://article.gmane.org/gmane.comp.emulators.qemu/177426
  v4: http://article.gmane.org/gmane.comp.emulators.qemu/176127
  v3: http://article.gmane.org/gmane.comp.emulators.qemu/175980
  v2: http://article.gmane.org/gmane.comp.emulators.qemu/173909
  v1: http://article.gmane.org/gmane.comp.emulators.qemu/166630


Eduardo Habkost (9):
  create qemu-types.h for struct typedefs
  sysemu.h: include qemu-types.h instead of qemu-common.h
  move -I$(SRC_PATH)/include compiler flag to Makefile.objs
  qdev: qdev_create(): use error_report() instead of hw_error()
  qdev: move reset handler list from vl.c to hw/reset.c
  qdev: add stubs for vmstate register/unregister functions
  qdev: add sysbus_get_default() stub
  qdev-properties.c: separate core from the code used only by
    qemu-system-*
  include qdev code into *-user, too

Igor Mammedov (1):
  qom: make CPU a child of DeviceState

 Makefile                    |   1 -
 Makefile.objs               |  23 ++-
 hw/Makefile.objs            |  12 +-
 hw/ac97.c                   |   1 +
 hw/acpi_ich9.c              |   1 +
 hw/acpi_piix4.c             |   1 +
 hw/adb.c                    |   1 +
 hw/arm_boot.c               |   1 +
 hw/armv7m.c                 |   1 +
 hw/bonito.c                 |   1 +
 hw/cirrus_vga.c             |   1 +
 hw/cris-boot.c              |   1 +
 hw/cs4231a.c                |   1 +
 hw/cuda.c                   |   1 +
 hw/dma.c                    |   1 +
 hw/dp8393x.c                |   1 +
 hw/eepro100.c               |   1 +
 hw/es1370.c                 |   1 +
 hw/etraxfs_timer.c          |   1 +
 hw/gt64xxx.c                |   1 +
 hw/heathrow_pic.c           |   1 +
 hw/hw.h                     |   5 -
 hw/ide/cmd646.c             |   1 +
 hw/ide/macio.c              |   1 +
 hw/ide/mmio.c               |   1 +
 hw/ide/piix.c               |   1 +
 hw/ide/via.c                |   1 +
 hw/leon3.c                  |   1 +
 hw/lm32_boards.c            |   1 +
 hw/lm832x.c                 |   1 +
 hw/loader.c                 |   1 +
 hw/mac_dbdma.c              |   1 +
 hw/mac_nvram.c              |   1 +
 hw/mc146818rtc.c            |   1 +
 hw/microblaze_boot.c        |   1 +
 hw/milkymist.c              |   1 +
 hw/mips_fulong2e.c          |   1 +
 hw/mips_jazz.c              |   1 +
 hw/mips_malta.c             |   1 +
 hw/mips_mipssim.c           |   1 +
 hw/mips_r4k.c               |   1 +
 hw/nseries.c                |   1 +
 hw/omap1.c                  |   1 +
 hw/omap2.c                  |   1 +
 hw/openpic.c                |   1 +
 hw/openrisc_sim.c           |   1 +
 hw/parallel.c               |   1 +
 hw/pc.c                     |   1 +
 hw/pckbd.c                  |   1 +
 hw/piix4.c                  |   1 +
 hw/piix_pci.c               |   1 +
 hw/ppc/e500.c               |   1 +
 hw/ppc405_boards.c          |   1 +
 hw/ppc405_uc.c              |   1 +
 hw/ppc440_bamboo.c          |   1 +
 hw/ppc4xx_devs.c            |   1 +
 hw/ppc4xx_pci.c             |   1 +
 hw/ppc_newworld.c           |   1 +
 hw/ppc_oldworld.c           |   1 +
 hw/ppc_prep.c               |   1 +
 hw/ppce500_spin.c           |   1 +
 hw/ps2.c                    |   1 +
 hw/qdev-core.h              |  11 +-
 hw/qdev-properties-system.c | 352 ++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev-properties.c        | 321 +---------------------------------------
 hw/qdev-properties.h        |   1 +
 hw/qdev.c                   |  22 +--
 hw/r2d.c                    |   1 +
 hw/rc4030.c                 |   1 +
 hw/reset.c                  |  43 ++++++
 hw/reset.h                  |  11 ++
 hw/s390-virtio-bus.c        |   1 +
 hw/serial.c                 |   1 +
 hw/spapr.c                  |   1 +
 hw/sun4m.c                  |   1 +
 hw/sun4u.c                  |   1 +
 hw/tsc2005.c                |   1 +
 hw/tsc210x.c                |   1 +
 hw/usb/hcd-ehci.c           |   1 +
 hw/usb/hcd-ohci.c           |   1 +
 hw/usb/hcd-uhci.c           |   1 +
 hw/vga.c                    |   1 +
 hw/virtex_ml507.c           |   1 +
 hw/vt82c686.c               |   1 +
 hw/xics.c                   |   1 +
 hw/xtensa_lx60.c            |   1 +
 hw/xtensa_sim.c             |   1 +
 include/qemu/cpu.h          |   6 +-
 kvm-all.c                   |   1 +
 qemu-common.h               |  52 +------
 qemu-types.h                |  61 ++++++++
 qom/cpu.c                   |   3 +-
 stubs/Makefile.objs         |   2 +
 stubs/sysbus.c              |   6 +
 stubs/vmstate.c             |  17 +++
 sysemu.h                    |   3 +-
 target-i386/cpu.c           |   1 +
 target-i386/kvm.c           |   1 +
 vl.c                        |  41 +-----
 xen-all.c                   |   1 +
 100 files changed, 616 insertions(+), 457 deletions(-)
 create mode 100644 hw/qdev-properties-system.c
 create mode 100644 hw/reset.c
 create mode 100644 hw/reset.h
 create mode 100644 qemu-types.h
 create mode 100644 stubs/sysbus.c
 create mode 100644 stubs/vmstate.c

-- 
1.7.11.7

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

* [Qemu-devel] [RFC 01/10] create qemu-types.h for struct typedefs
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 02/10] sysemu.h: include qemu-types.h instead of qemu-common.h Eduardo Habkost
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

Instead of keeping all those struct typedefs on qemu-common.h, move it
to a header that can be safely included by other headers, containing
only the struct typedefs and not pulling other dependencies.

Also, move some of the qdev-core.h typedefs to the new file, too, so
other headers don't need to include qdev-core.h only because of
DeviceState and other typedefs.

This will help us remove qemu-common.h dependencies from some headers
later.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qdev-core.h | 11 +----------
 qemu-common.h  | 52 +------------------------------------------------
 qemu-types.h   | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 61 deletions(-)
 create mode 100644 qemu-types.h

diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index fff7f0f..d672cca 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -3,20 +3,11 @@
 
 #include "qemu-queue.h"
 #include "qemu-option.h"
+#include "qemu-types.h"
 #include "qemu/object.h"
 #include "hw/irq.h"
 #include "error.h"
 
-typedef struct Property Property;
-
-typedef struct PropertyInfo PropertyInfo;
-
-typedef struct CompatProperty CompatProperty;
-
-typedef struct BusState BusState;
-
-typedef struct BusClass BusClass;
-
 enum DevState {
     DEV_STATE_CREATED = 1,
     DEV_STATE_INITIALIZED,
diff --git a/qemu-common.h b/qemu-common.h
index cef264c..e674786 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -14,6 +14,7 @@
 
 #include "compiler.h"
 #include "config-host.h"
+#include "qemu-types.h"
 
 #if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__ia64__)
 #define WORDS_ALIGNED
@@ -21,15 +22,6 @@
 
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
-typedef struct QEMUTimer QEMUTimer;
-typedef struct QEMUFile QEMUFile;
-typedef struct QEMUBH QEMUBH;
-typedef struct DeviceState DeviceState;
-
-struct Monitor;
-typedef struct Monitor Monitor;
-typedef struct MigrationParams MigrationParams;
-
 /* we put basic includes here to avoid repeating them in device drivers */
 #include <stdlib.h>
 #include <stdio.h>
@@ -258,48 +250,6 @@ struct ParallelIOArg {
 
 typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size);
 
-/* A load of opaque types so that device init declarations don't have to
-   pull in all the real definitions.  */
-typedef struct NICInfo NICInfo;
-typedef struct HCIInfo HCIInfo;
-typedef struct AudioState AudioState;
-typedef struct BlockDriverState BlockDriverState;
-typedef struct DriveInfo DriveInfo;
-typedef struct DisplayState DisplayState;
-typedef struct DisplayChangeListener DisplayChangeListener;
-typedef struct DisplaySurface DisplaySurface;
-typedef struct PixelFormat PixelFormat;
-typedef struct QemuConsole QemuConsole;
-typedef struct CharDriverState CharDriverState;
-typedef struct MACAddr MACAddr;
-typedef struct NetClientState NetClientState;
-typedef struct i2c_bus i2c_bus;
-typedef struct ISABus ISABus;
-typedef struct ISADevice ISADevice;
-typedef struct SMBusDevice SMBusDevice;
-typedef struct PCIHostState PCIHostState;
-typedef struct PCIExpressHost PCIExpressHost;
-typedef struct PCIBus PCIBus;
-typedef struct PCIDevice PCIDevice;
-typedef struct PCIExpressDevice PCIExpressDevice;
-typedef struct PCIBridge PCIBridge;
-typedef struct PCIEAERMsg PCIEAERMsg;
-typedef struct PCIEAERLog PCIEAERLog;
-typedef struct PCIEAERErr PCIEAERErr;
-typedef struct PCIEPort PCIEPort;
-typedef struct PCIESlot PCIESlot;
-typedef struct MSIMessage MSIMessage;
-typedef struct SerialState SerialState;
-typedef struct PCMCIACardState PCMCIACardState;
-typedef struct MouseTransformInfo MouseTransformInfo;
-typedef struct uWireSlave uWireSlave;
-typedef struct I2SCodec I2SCodec;
-typedef struct SSIBus SSIBus;
-typedef struct EventNotifier EventNotifier;
-typedef struct VirtIODevice VirtIODevice;
-typedef struct QEMUSGList QEMUSGList;
-typedef struct SHPCDevice SHPCDevice;
-
 typedef uint64_t pcibus_t;
 
 typedef enum LostTickPolicy {
diff --git a/qemu-types.h b/qemu-types.h
new file mode 100644
index 0000000..fd532a2
--- /dev/null
+++ b/qemu-types.h
@@ -0,0 +1,61 @@
+#ifndef QEMU_TYPEDEFS_H
+#define QEMU_TYPEDEFS_H
+
+/* A load of opaque types so that device init declarations don't have to
+   pull in all the real definitions.  */
+typedef struct QEMUTimer QEMUTimer;
+typedef struct QEMUFile QEMUFile;
+typedef struct QEMUBH QEMUBH;
+
+struct Monitor;
+typedef struct Monitor Monitor;
+typedef struct MigrationParams MigrationParams;
+
+typedef struct Property Property;
+typedef struct PropertyInfo PropertyInfo;
+typedef struct CompatProperty CompatProperty;
+typedef struct DeviceState DeviceState;
+typedef struct BusState BusState;
+typedef struct BusClass BusClass;
+
+typedef struct NICInfo NICInfo;
+typedef struct HCIInfo HCIInfo;
+typedef struct AudioState AudioState;
+typedef struct BlockDriverState BlockDriverState;
+typedef struct DriveInfo DriveInfo;
+typedef struct DisplayState DisplayState;
+typedef struct DisplayChangeListener DisplayChangeListener;
+typedef struct DisplaySurface DisplaySurface;
+typedef struct PixelFormat PixelFormat;
+typedef struct QemuConsole QemuConsole;
+typedef struct CharDriverState CharDriverState;
+typedef struct MACAddr MACAddr;
+typedef struct NetClientState NetClientState;
+typedef struct i2c_bus i2c_bus;
+typedef struct ISABus ISABus;
+typedef struct ISADevice ISADevice;
+typedef struct SMBusDevice SMBusDevice;
+typedef struct PCIHostState PCIHostState;
+typedef struct PCIExpressHost PCIExpressHost;
+typedef struct PCIBus PCIBus;
+typedef struct PCIDevice PCIDevice;
+typedef struct PCIExpressDevice PCIExpressDevice;
+typedef struct PCIBridge PCIBridge;
+typedef struct PCIEAERMsg PCIEAERMsg;
+typedef struct PCIEAERLog PCIEAERLog;
+typedef struct PCIEAERErr PCIEAERErr;
+typedef struct PCIEPort PCIEPort;
+typedef struct PCIESlot PCIESlot;
+typedef struct MSIMessage MSIMessage;
+typedef struct SerialState SerialState;
+typedef struct PCMCIACardState PCMCIACardState;
+typedef struct MouseTransformInfo MouseTransformInfo;
+typedef struct uWireSlave uWireSlave;
+typedef struct I2SCodec I2SCodec;
+typedef struct SSIBus SSIBus;
+typedef struct EventNotifier EventNotifier;
+typedef struct VirtIODevice VirtIODevice;
+typedef struct QEMUSGList QEMUSGList;
+typedef struct SHPCDevice SHPCDevice;
+
+#endif /* QEMU_TYPEDEFS_H */
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 02/10] sysemu.h: include qemu-types.h instead of qemu-common.h
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 01/10] create qemu-types.h for struct typedefs Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 03/10] move -I$(SRC_PATH)/include compiler flag to Makefile.objs Eduardo Habkost
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

It just needs the Monitor and DeviceState typedefs, so it doesn't need
all of qemu-common.h.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 sysemu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysemu.h b/sysemu.h
index f5ac664..ab1ef8b 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -2,7 +2,7 @@
 #define SYSEMU_H
 /* Misc. things related to the system emulator.  */
 
-#include "qemu-common.h"
+#include "qemu-types.h"
 #include "qemu-option.h"
 #include "qemu-queue.h"
 #include "qemu-timer.h"
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 03/10] move -I$(SRC_PATH)/include compiler flag to Makefile.objs
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 01/10] create qemu-types.h for struct typedefs Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 02/10] sysemu.h: include qemu-types.h instead of qemu-common.h Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 04/10] qdev: qdev_create(): use error_report() instead of hw_error() Eduardo Habkost
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

The flag is necessary for code that doesn't use the variables from
Makefile (but use Makefile.objs), like libcacard/ and stubs/.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 Makefile      |  1 -
 Makefile.objs | 15 +++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 9ecbcbb..739d9cd 100644
--- a/Makefile
+++ b/Makefile
@@ -145,7 +145,6 @@ audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
 
 QEMU_CFLAGS+=$(CURL_CFLAGS)
 
-QEMU_CFLAGS += -I$(SRC_PATH)/include
 
 ui/cocoa.o: ui/cocoa.m
 
diff --git a/Makefile.objs b/Makefile.objs
index 3c7abca..0a0a33a 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -1,4 +1,13 @@
 #######################################################################
+# general compiler flags
+
+QEMU_CFLAGS += $(GLIB_CFLAGS)
+QEMU_CFLAGS += -I$(SRC_PATH)/include
+
+vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
+vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
+
+#######################################################################
 # Stub library, linked in tools
 stub-obj-y = stubs/
 
@@ -236,12 +245,6 @@ universal-obj-y += $(qapi-obj-y)
 qga-obj-y = qga/ qemu-ga.o module.o qemu-tool.o
 qga-obj-$(CONFIG_POSIX) += qemu-sockets.o qemu-option.o
 
-vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
-
-vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
-
-QEMU_CFLAGS+=$(GLIB_CFLAGS)
-
 nested-vars += \
 	stub-obj-y \
 	qga-obj-y \
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 04/10] qdev: qdev_create(): use error_report() instead of hw_error()
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (2 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 03/10] move -I$(SRC_PATH)/include compiler flag to Makefile.objs Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c Eduardo Habkost
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

hw_error() is specific for fatal hardware emulation errors, not for
internal errors related to the qdev object/class abstraction or object
initialization.

Replace it with an error_report() call, followed by abort().

This will also help reduce dependencies of the qdev code (as hw_error()
is from cpus.o, and depends on the CPU list from exec.o).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/qdev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 788b4da..599382c 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -109,10 +109,12 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     dev = qdev_try_create(bus, name);
     if (!dev) {
         if (bus) {
-            hw_error("Unknown device '%s' for bus '%s'\n", name,
-                     object_get_typename(OBJECT(bus)));
+            error_report("Unknown device '%s' for bus '%s'\n", name,
+                         object_get_typename(OBJECT(bus)));
+            abort();
         } else {
-            hw_error("Unknown device '%s' for default sysbus\n", name);
+            error_report("Unknown device '%s' for default sysbus\n", name);
+            abort();
         }
     }
 
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (3 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 04/10] qdev: qdev_create(): use error_report() instead of hw_error() Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-12-03 20:19   ` Igor Mammedov
  2012-12-03 21:20   ` Igor Mammedov
  2012-11-30 19:27 ` [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions Eduardo Habkost
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

The core qdev code uses the reset handler list from vl.c, and
currently *-user has some hacks to make CPU reset work.

This moves qemu_register_reset(), qemu_unregister_reset() and
qemu_devices_reset() to a new file, hw/reset.c, that can be used by qdev
and by *-user.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/Makefile.objs     |  1 +
 hw/ac97.c            |  1 +
 hw/acpi_ich9.c       |  1 +
 hw/acpi_piix4.c      |  1 +
 hw/adb.c             |  1 +
 hw/arm_boot.c        |  1 +
 hw/armv7m.c          |  1 +
 hw/bonito.c          |  1 +
 hw/cirrus_vga.c      |  1 +
 hw/cris-boot.c       |  1 +
 hw/cs4231a.c         |  1 +
 hw/cuda.c            |  1 +
 hw/dma.c             |  1 +
 hw/dp8393x.c         |  1 +
 hw/eepro100.c        |  1 +
 hw/es1370.c          |  1 +
 hw/etraxfs_timer.c   |  1 +
 hw/gt64xxx.c         |  1 +
 hw/heathrow_pic.c    |  1 +
 hw/hw.h              |  5 -----
 hw/ide/cmd646.c      |  1 +
 hw/ide/macio.c       |  1 +
 hw/ide/mmio.c        |  1 +
 hw/ide/piix.c        |  1 +
 hw/ide/via.c         |  1 +
 hw/leon3.c           |  1 +
 hw/lm32_boards.c     |  1 +
 hw/lm832x.c          |  1 +
 hw/loader.c          |  1 +
 hw/mac_dbdma.c       |  1 +
 hw/mac_nvram.c       |  1 +
 hw/mc146818rtc.c     |  1 +
 hw/microblaze_boot.c |  1 +
 hw/milkymist.c       |  1 +
 hw/mips_fulong2e.c   |  1 +
 hw/mips_jazz.c       |  1 +
 hw/mips_malta.c      |  1 +
 hw/mips_mipssim.c    |  1 +
 hw/mips_r4k.c        |  1 +
 hw/nseries.c         |  1 +
 hw/omap1.c           |  1 +
 hw/omap2.c           |  1 +
 hw/openpic.c         |  1 +
 hw/openrisc_sim.c    |  1 +
 hw/parallel.c        |  1 +
 hw/pc.c              |  1 +
 hw/pckbd.c           |  1 +
 hw/piix4.c           |  1 +
 hw/piix_pci.c        |  1 +
 hw/ppc/e500.c        |  1 +
 hw/ppc405_boards.c   |  1 +
 hw/ppc405_uc.c       |  1 +
 hw/ppc440_bamboo.c   |  1 +
 hw/ppc4xx_devs.c     |  1 +
 hw/ppc4xx_pci.c      |  1 +
 hw/ppc_newworld.c    |  1 +
 hw/ppc_oldworld.c    |  1 +
 hw/ppc_prep.c        |  1 +
 hw/ppce500_spin.c    |  1 +
 hw/ps2.c             |  1 +
 hw/qdev.c            |  1 +
 hw/r2d.c             |  1 +
 hw/rc4030.c          |  1 +
 hw/reset.c           | 43 +++++++++++++++++++++++++++++++++++++++++++
 hw/reset.h           | 11 +++++++++++
 hw/s390-virtio-bus.c |  1 +
 hw/serial.c          |  1 +
 hw/spapr.c           |  1 +
 hw/sun4m.c           |  1 +
 hw/sun4u.c           |  1 +
 hw/tsc2005.c         |  1 +
 hw/tsc210x.c         |  1 +
 hw/usb/hcd-ehci.c    |  1 +
 hw/usb/hcd-ohci.c    |  1 +
 hw/usb/hcd-uhci.c    |  1 +
 hw/vga.c             |  1 +
 hw/virtex_ml507.c    |  1 +
 hw/vt82c686.c        |  1 +
 hw/xics.c            |  1 +
 hw/xtensa_lx60.c     |  1 +
 hw/xtensa_sim.c      |  1 +
 kvm-all.c            |  1 +
 sysemu.h             |  1 -
 target-i386/cpu.c    |  1 +
 target-i386/kvm.c    |  1 +
 vl.c                 | 41 +----------------------------------------
 xen-all.c            |  1 +
 87 files changed, 137 insertions(+), 46 deletions(-)
 create mode 100644 hw/reset.c
 create mode 100644 hw/reset.h

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index d581d8d..1dfed06 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -1,5 +1,6 @@
 common-obj-y = usb/ ide/
 common-obj-y += loader.o
+common-obj-y += reset.o
 common-obj-$(CONFIG_VIRTIO) += virtio-console.o
 common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
diff --git a/hw/ac97.c b/hw/ac97.c
index ce6a1dc..c37aaae 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -17,6 +17,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "audiodev.h"
 #include "audio/audio.h"
diff --git a/hw/acpi_ich9.c b/hw/acpi_ich9.c
index 61034d3..fc2ff2c 100644
--- a/hw/acpi_ich9.c
+++ b/hw/acpi_ich9.c
@@ -22,6 +22,7 @@
  *
  *  This is based on acpi.c.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 519269a..a022180 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -18,6 +18,7 @@
  * Contributions after 2012-01-13 are licensed under the terms of the
  * GNU GPL, version 2 or (at your option) any later version.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "apm.h"
diff --git a/hw/adb.c b/hw/adb.c
index 3b547f0..5f3d6dc 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "adb.h"
 #include "console.h"
diff --git a/hw/arm_boot.c b/hw/arm_boot.c
index 92e2cab..c608d1d 100644
--- a/hw/arm_boot.c
+++ b/hw/arm_boot.c
@@ -8,6 +8,7 @@
  */
 
 #include "config.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "arm-misc.h"
 #include "sysemu.h"
diff --git a/hw/armv7m.c b/hw/armv7m.c
index ce2ec9b..fca329c 100644
--- a/hw/armv7m.c
+++ b/hw/armv7m.c
@@ -7,6 +7,7 @@
  * This code is licensed under the GPL.
  */
 
+#include "hw/reset.h"
 #include "sysbus.h"
 #include "arm-misc.h"
 #include "loader.h"
diff --git a/hw/bonito.c b/hw/bonito.c
index 0bf6d4a..4080def 100644
--- a/hw/bonito.c
+++ b/hw/bonito.c
@@ -39,6 +39,7 @@
 
 #include <assert.h>
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "pci.h"
 #include "pc.h"
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 9bef96e..7e51cc4 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -26,6 +26,7 @@
  * Reference: Finn Thogersons' VGADOC4b
  *   available at http://home.worldonline.dk/~finth/
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "pci.h"
 #include "console.h"
diff --git a/hw/cris-boot.c b/hw/cris-boot.c
index b21326f..fc0c64b 100644
--- a/hw/cris-boot.c
+++ b/hw/cris-boot.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "loader.h"
 #include "elf.h"
diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 0257fd8..b54dfc1 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "audiodev.h"
 #include "audio/audio.h"
diff --git a/hw/cuda.c b/hw/cuda.c
index f1f408b..0e74501 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -22,6 +22,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc_mac.h"
 #include "adb.h"
diff --git a/hw/dma.c b/hw/dma.c
index d6aeac2..0232ceb 100644
--- a/hw/dma.c
+++ b/hw/dma.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "isa.h"
 
diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index 3f6386e..23fd09f 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -17,6 +17,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "qemu-timer.h"
 #include "net.h"
diff --git a/hw/eepro100.c b/hw/eepro100.c
index a189474..0c3e0dd 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -41,6 +41,7 @@
  */
 
 #include <stddef.h>             /* offsetof */
+#include "hw/reset.h"
 #include "hw.h"
 #include "pci.h"
 #include "net.h"
diff --git a/hw/es1370.c b/hw/es1370.c
index e0c9729..6c5466f 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -26,6 +26,7 @@
 /* #define VERBOSE_ES1370 */
 #define SILENT_ES1370
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "audiodev.h"
 #include "audio/audio.h"
diff --git a/hw/etraxfs_timer.c b/hw/etraxfs_timer.c
index f5601dc..cea5e00 100644
--- a/hw/etraxfs_timer.c
+++ b/hw/etraxfs_timer.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "sysbus.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "qemu-timer.h"
 #include "ptimer.h"
diff --git a/hw/gt64xxx.c b/hw/gt64xxx.c
index 95d491d..ecda9f9 100644
--- a/hw/gt64xxx.c
+++ b/hw/gt64xxx.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "mips.h"
 #include "pci.h"
diff --git a/hw/heathrow_pic.c b/hw/heathrow_pic.c
index b9ec8e7..b0e1a9d 100644
--- a/hw/heathrow_pic.c
+++ b/hw/heathrow_pic.c
@@ -22,6 +22,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc_mac.h"
 
diff --git a/hw/hw.h b/hw/hw.h
index f530f6f..fe057f0 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -37,11 +37,6 @@
 #endif
 #endif
 
-typedef void QEMUResetHandler(void *opaque);
-
-void qemu_register_reset(QEMUResetHandler *func, void *opaque);
-void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
-
 /* handler to set the boot_device order for a specific type of QEMUMachine */
 /* return 0 if success */
 typedef int QEMUBootSetHandler(void *opaque, const char *boot_devices);
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index 804db60..0666102 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -27,6 +27,7 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "dma.h"
 
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index d2edcc0..9fe3a9f 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -22,6 +22,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include <hw/hw.h>
 #include <hw/ppc_mac.h>
 #include <hw/mac_dbdma.h>
diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
index bcb26c8..4da8c6e 100644
--- a/hw/ide/mmio.c
+++ b/hw/ide/mmio.c
@@ -22,6 +22,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include <hw/hw.h>
 #include "block.h"
 #include "dma.h"
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 9431bad..b6c910a 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -28,6 +28,7 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "blockdev.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "dma.h"
 
diff --git a/hw/ide/via.c b/hw/ide/via.c
index efda173..9a5a991 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -28,6 +28,7 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "dma.h"
 
diff --git a/hw/leon3.c b/hw/leon3.c
index 7742738..d944641 100644
--- a/hw/leon3.c
+++ b/hw/leon3.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "qemu-timer.h"
 #include "ptimer.h"
diff --git a/hw/lm32_boards.c b/hw/lm32_boards.c
index 772cb8b..30ea613 100644
--- a/hw/lm32_boards.c
+++ b/hw/lm32_boards.c
@@ -18,6 +18,7 @@
  */
 
 #include "sysbus.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "net.h"
 #include "flash.h"
diff --git a/hw/lm832x.c b/hw/lm832x.c
index 8e09f9b..7f3fc0c 100644
--- a/hw/lm832x.c
+++ b/hw/lm832x.c
@@ -18,6 +18,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "i2c.h"
 #include "qemu-timer.h"
diff --git a/hw/loader.c b/hw/loader.c
index ba01ca6..dafbda4 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -42,6 +42,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "disas.h"
 #include "monitor.h"
diff --git a/hw/mac_dbdma.c b/hw/mac_dbdma.c
index e551156..e1f876f 100644
--- a/hw/mac_dbdma.c
+++ b/hw/mac_dbdma.c
@@ -36,6 +36,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "isa.h"
 #include "mac_dbdma.h"
diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index a0d14dd..90c848d 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -22,6 +22,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "firmware_abi.h"
 #include "sysemu.h"
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index c79fca7..5899be1 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "qemu-timer.h"
 #include "sysemu.h"
diff --git a/hw/microblaze_boot.c b/hw/microblaze_boot.c
index 02c349c..933a677 100644
--- a/hw/microblaze_boot.c
+++ b/hw/microblaze_boot.c
@@ -28,6 +28,7 @@
 #include "qemu-config.h"
 #include "qemu-common.h"
 #include "device_tree.h"
+#include "hw/reset.h"
 #include "loader.h"
 #include "elf.h"
 
diff --git a/hw/milkymist.c b/hw/milkymist.c
index 4c8111a..25eb0b8 100644
--- a/hw/milkymist.c
+++ b/hw/milkymist.c
@@ -18,6 +18,7 @@
  */
 
 #include "sysbus.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "net.h"
 #include "flash.h"
diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c
index 5fcf900..f14318f 100644
--- a/hw/mips_fulong2e.c
+++ b/hw/mips_fulong2e.c
@@ -18,6 +18,7 @@
  * http://www.loongsondeveloper.com/doc/Loongson2EUserGuide.pdf
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "serial.h"
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index 0847427..8e31187 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "mips.h"
 #include "mips_cpudevs.h"
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 4d2464a..8f96918 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "serial.h"
diff --git a/hw/mips_mipssim.c b/hw/mips_mipssim.c
index a95a3c1..1a7d3f6 100644
--- a/hw/mips_mipssim.c
+++ b/hw/mips_mipssim.c
@@ -24,6 +24,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "mips.h"
 #include "mips_cpudevs.h"
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index 325098a..a9c7a0f 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -7,6 +7,7 @@
  * All peripherial devices are attached to this "bus" with
  * the standard PC ISA addresses.
 */
+#include "hw/reset.h"
 #include "hw.h"
 #include "mips.h"
 #include "mips_cpudevs.h"
diff --git a/hw/nseries.c b/hw/nseries.c
index 2de8d21..5604e7c 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -28,6 +28,7 @@
 #include "i2c.h"
 #include "devices.h"
 #include "flash.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "bt.h"
 #include "loader.h"
diff --git a/hw/omap1.c b/hw/omap1.c
index 4d5815e..a5bac74 100644
--- a/hw/omap1.c
+++ b/hw/omap1.c
@@ -16,6 +16,7 @@
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "arm-misc.h"
 #include "omap.h"
diff --git a/hw/omap2.c b/hw/omap2.c
index 96aba71..10b0a1a 100644
--- a/hw/omap2.c
+++ b/hw/omap2.c
@@ -19,6 +19,7 @@
  */
 
 #include "blockdev.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "arm-misc.h"
 #include "omap.h"
diff --git a/hw/openpic.c b/hw/openpic.c
index 8b3784a..633a47a 100644
--- a/hw/openpic.c
+++ b/hw/openpic.c
@@ -33,6 +33,7 @@
  * Serial interrupts, as implemented in Raven chipset are not supported yet.
  *
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc_mac.h"
 #include "pci.h"
diff --git a/hw/openrisc_sim.c b/hw/openrisc_sim.c
index 23c66df..74b0594 100644
--- a/hw/openrisc_sim.c
+++ b/hw/openrisc_sim.c
@@ -18,6 +18,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "boards.h"
 #include "elf.h"
diff --git a/hw/parallel.c b/hw/parallel.c
index c4705bc..ba17a4e 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -22,6 +22,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "qemu-char.h"
 #include "isa.h"
diff --git a/hw/pc.c b/hw/pc.c
index 2b5bbbf..5f08c5e 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "serial.h"
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 5bb3e0a..6116b58 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "isa.h"
 #include "pc.h"
diff --git a/hw/piix4.c b/hw/piix4.c
index ce4eb0d..eb4d918 100644
--- a/hw/piix4.c
+++ b/hw/piix4.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index ba1b3de..e9c3b3b 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 6749fff..53f980a 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -18,6 +18,7 @@
 #include "qemu-common.h"
 #include "e500.h"
 #include "net.h"
+#include "hw/reset.h"
 #include "hw/hw.h"
 #include "hw/serial.h"
 #include "hw/pci.h"
diff --git a/hw/ppc405_boards.c b/hw/ppc405_boards.c
index 8dc693f..421cdc3 100644
--- a/hw/ppc405_boards.c
+++ b/hw/ppc405_boards.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc.h"
 #include "ppc405.h"
diff --git a/hw/ppc405_uc.c b/hw/ppc405_uc.c
index 0f458ef..3cd0e5b 100644
--- a/hw/ppc405_uc.c
+++ b/hw/ppc405_uc.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc.h"
 #include "ppc405.h"
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index cc85607..29d000b 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -14,6 +14,7 @@
 #include "config.h"
 #include "qemu-common.h"
 #include "net.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "pci.h"
 #include "boards.h"
diff --git a/hw/ppc4xx_devs.c b/hw/ppc4xx_devs.c
index bac8d87..4fbf2f7 100644
--- a/hw/ppc4xx_devs.c
+++ b/hw/ppc4xx_devs.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc.h"
 #include "ppc4xx.h"
diff --git a/hw/ppc4xx_pci.c b/hw/ppc4xx_pci.c
index d3ad6a0..a8f4b54 100644
--- a/hw/ppc4xx_pci.c
+++ b/hw/ppc4xx_pci.c
@@ -19,6 +19,7 @@
 /* This file implements emulation of the 32-bit PCI controller found in some
  * 4xx SoCs, such as the 440EP. */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc.h"
 #include "ppc4xx.h"
diff --git a/hw/ppc_newworld.c b/hw/ppc_newworld.c
index 664747e..dbe705e 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc_newworld.c
@@ -46,6 +46,7 @@
  * 0001:05:0c.0 IDE interface [0101]: Broadcom K2 SATA [1166:0240]
  *
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc.h"
 #include "ppc_mac.h"
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index e8138c0..dcb45a6 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -23,6 +23,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ppc.h"
 #include "ppc_mac.h"
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index bf15730..02ab5e3 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "nvram.h"
 #include "pc.h"
diff --git a/hw/ppce500_spin.c b/hw/ppce500_spin.c
index c1a155b..d6435d1 100644
--- a/hw/ppce500_spin.c
+++ b/hw/ppce500_spin.c
@@ -27,6 +27,7 @@
  *
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "sysemu.h"
 #include "sysbus.h"
diff --git a/hw/ps2.c b/hw/ps2.c
index f93cd24..c1b441d 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "ps2.h"
 #include "console.h"
diff --git a/hw/qdev.c b/hw/qdev.c
index 599382c..15b967d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -27,6 +27,7 @@
 
 #include "net.h"
 #include "qdev.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "error.h"
 #include "qapi/qapi-visit-core.h"
diff --git a/hw/r2d.c b/hw/r2d.c
index 66212e9..9ce2a8c 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -24,6 +24,7 @@
  */
 
 #include "sysbus.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "sh.h"
 #include "devices.h"
diff --git a/hw/rc4030.c b/hw/rc4030.c
index e0024c8..d175cf2 100644
--- a/hw/rc4030.c
+++ b/hw/rc4030.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "mips.h"
 #include "qemu-timer.h"
diff --git a/hw/reset.c b/hw/reset.c
new file mode 100644
index 0000000..5e34b80
--- /dev/null
+++ b/hw/reset.c
@@ -0,0 +1,43 @@
+#include "hw/reset.h"
+#include "qlist.h"
+
+typedef struct QEMUResetEntry {
+    QTAILQ_ENTRY(QEMUResetEntry) entry;
+    QEMUResetHandler *func;
+    void *opaque;
+} QEMUResetEntry;
+
+static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
+    QTAILQ_HEAD_INITIALIZER(reset_handlers);
+
+void qemu_register_reset(QEMUResetHandler *func, void *opaque)
+{
+    QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
+
+    re->func = func;
+    re->opaque = opaque;
+    QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
+}
+
+void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
+{
+    QEMUResetEntry *re;
+
+    QTAILQ_FOREACH(re, &reset_handlers, entry) {
+        if (re->func == func && re->opaque == opaque) {
+            QTAILQ_REMOVE(&reset_handlers, re, entry);
+            g_free(re);
+            return;
+        }
+    }
+}
+
+void qemu_devices_reset(void)
+{
+    QEMUResetEntry *re, *nre;
+
+    /* reset all devices */
+    QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
+        re->func(re->opaque);
+    }
+}
diff --git a/hw/reset.h b/hw/reset.h
new file mode 100644
index 0000000..fce4066
--- /dev/null
+++ b/hw/reset.h
@@ -0,0 +1,11 @@
+/* Device reset handler function registration, used by qdev and other code */
+#ifndef QDEV_RESET_H
+#define QDEV_RESET_H
+
+typedef void QEMUResetHandler(void *opaque);
+
+void qemu_register_reset(QEMUResetHandler *func, void *opaque);
+void qemu_unregister_reset(QEMUResetHandler *func, void *opaque);
+void qemu_devices_reset(void);
+
+#endif /* QDEV_RESET_H */
diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index e0ac2d1..699e07f 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -17,6 +17,7 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "block.h"
 #include "sysemu.h"
diff --git a/hw/serial.c b/hw/serial.c
index 60283ea..0254e1b 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -27,6 +27,7 @@
 #include "qemu-char.h"
 #include "qemu-timer.h"
 #include "exec-memory.h"
+#include "hw/reset.h"
 
 //#define DEBUG_SERIAL
 
diff --git a/hw/spapr.c b/hw/spapr.c
index ad3f0ea..97ca1e6 100644
--- a/hw/spapr.c
+++ b/hw/spapr.c
@@ -25,6 +25,7 @@
  *
  */
 #include "sysemu.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "elf.h"
 #include "net.h"
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 1a78676..e3e5958 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -27,6 +27,7 @@
 #include "nvram.h"
 #include "sparc32_dma.h"
 #include "fdc.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "net.h"
 #include "boards.h"
diff --git a/hw/sun4u.c b/hw/sun4u.c
index b2b51e3..e263e8e 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "pci.h"
 #include "apb_pci.h"
diff --git a/hw/tsc2005.c b/hw/tsc2005.c
index 9a500eb..f7a892d 100644
--- a/hw/tsc2005.c
+++ b/hw/tsc2005.c
@@ -18,6 +18,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "qemu-timer.h"
 #include "console.h"
diff --git a/hw/tsc210x.c b/hw/tsc210x.c
index 3c448a6..4e3ea2d 100644
--- a/hw/tsc210x.c
+++ b/hw/tsc210x.c
@@ -19,6 +19,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "audio/audio.h"
 #include "qemu-timer.h"
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 7df8e21..71e243f 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -28,6 +28,7 @@
  */
 
 #include "hw/usb/hcd-ehci.h"
+#include "hw/reset.h"
 
 /* Capability Registers Base Address - section 2.2 */
 #define CAPLENGTH        0x0000  /* 1-byte, 0x0001 reserved */
diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 64de906..ac75bbf 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -26,6 +26,7 @@
  *  o BIOS work to boot from USB storage
 */
 
+#include "hw/reset.h"
 #include "hw/hw.h"
 #include "qemu-timer.h"
 #include "hw/usb.h"
diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c
index 8e47803..b5437c8 100644
--- a/hw/usb/hcd-uhci.c
+++ b/hw/usb/hcd-uhci.c
@@ -25,6 +25,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw/hw.h"
 #include "hw/usb.h"
 #include "hw/pci.h"
diff --git a/hw/vga.c b/hw/vga.c
index 2b0200a..23f0aea 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -21,6 +21,7 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+#include "hw/reset.h"
 #include "hw.h"
 #include "vga.h"
 #include "console.h"
diff --git a/hw/virtex_ml507.c b/hw/virtex_ml507.c
index 6ab8fee..ba07f25 100644
--- a/hw/virtex_ml507.c
+++ b/hw/virtex_ml507.c
@@ -23,6 +23,7 @@
  */
 
 #include "sysbus.h"
+#include "hw/reset.h"
 #include "hw.h"
 #include "serial.h"
 #include "net.h"
diff --git a/hw/vt82c686.c b/hw/vt82c686.c
index 5d7c00c..671322d 100644
--- a/hw/vt82c686.c
+++ b/hw/vt82c686.c
@@ -10,6 +10,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "pc.h"
 #include "vt82c686.h"
diff --git a/hw/xics.c b/hw/xics.c
index 1da3106..673c8aa 100644
--- a/hw/xics.c
+++ b/hw/xics.c
@@ -25,6 +25,7 @@
  *
  */
 
+#include "hw/reset.h"
 #include "hw.h"
 #include "hw/spapr.h"
 #include "hw/xics.h"
diff --git a/hw/xtensa_lx60.c b/hw/xtensa_lx60.c
index 4c42edc..39b0d67 100644
--- a/hw/xtensa_lx60.c
+++ b/hw/xtensa_lx60.c
@@ -25,6 +25,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "boards.h"
 #include "loader.h"
diff --git a/hw/xtensa_sim.c b/hw/xtensa_sim.c
index 0d633e4..c30efc8 100644
--- a/hw/xtensa_sim.c
+++ b/hw/xtensa_sim.c
@@ -25,6 +25,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "boards.h"
 #include "loader.h"
diff --git a/kvm-all.c b/kvm-all.c
index 8e9a8d8..9a3010c 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -25,6 +25,7 @@
 #include "qemu-option.h"
 #include "qemu-config.h"
 #include "sysemu.h"
+#include "hw/reset.h"
 #include "hw/hw.h"
 #include "hw/msi.h"
 #include "gdbstub.h"
diff --git a/sysemu.h b/sysemu.h
index ab1ef8b..51f19cc 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -57,7 +57,6 @@ void qemu_system_vmstop_request(RunState reason);
 int qemu_shutdown_requested_get(void);
 int qemu_reset_requested_get(void);
 void qemu_system_killed(int signal, pid_t pid);
-void qemu_devices_reset(void);
 void qemu_system_reset(bool report);
 
 void qemu_add_exit_notifier(Notifier *notify);
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c6c2ca0..483a6fc 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -32,6 +32,7 @@
 
 #include "hyperv.h"
 
+#include "hw/reset.h"
 #include "hw/hw.h"
 #if defined(CONFIG_KVM)
 #include <linux/kvm_para.h>
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f669281..5f43232 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -21,6 +21,7 @@
 #include <linux/kvm_para.h>
 
 #include "qemu-common.h"
+#include "hw/reset.h"
 #include "sysemu.h"
 #include "kvm.h"
 #include "kvm_i386.h"
diff --git a/vl.c b/vl.c
index a3ab384..e053e6a 100644
--- a/vl.c
+++ b/vl.c
@@ -113,6 +113,7 @@ int main(int argc, char **argv)
 
 #include <glib.h>
 
+#include "hw/reset.h"
 #include "hw/hw.h"
 #include "hw/boards.h"
 #include "hw/usb.h"
@@ -1457,14 +1458,6 @@ void vm_start(void)
 
 /* reset/shutdown handler */
 
-typedef struct QEMUResetEntry {
-    QTAILQ_ENTRY(QEMUResetEntry) entry;
-    QEMUResetHandler *func;
-    void *opaque;
-} QEMUResetEntry;
-
-static QTAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
-    QTAILQ_HEAD_INITIALIZER(reset_handlers);
 static int reset_requested;
 static int shutdown_requested, shutdown_signal = -1;
 static pid_t shutdown_pid;
@@ -1561,38 +1554,6 @@ static bool qemu_vmstop_requested(RunState *r)
     return false;
 }
 
-void qemu_register_reset(QEMUResetHandler *func, void *opaque)
-{
-    QEMUResetEntry *re = g_malloc0(sizeof(QEMUResetEntry));
-
-    re->func = func;
-    re->opaque = opaque;
-    QTAILQ_INSERT_TAIL(&reset_handlers, re, entry);
-}
-
-void qemu_unregister_reset(QEMUResetHandler *func, void *opaque)
-{
-    QEMUResetEntry *re;
-
-    QTAILQ_FOREACH(re, &reset_handlers, entry) {
-        if (re->func == func && re->opaque == opaque) {
-            QTAILQ_REMOVE(&reset_handlers, re, entry);
-            g_free(re);
-            return;
-        }
-    }
-}
-
-void qemu_devices_reset(void)
-{
-    QEMUResetEntry *re, *nre;
-
-    /* reset all devices */
-    QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
-        re->func(re->opaque);
-    }
-}
-
 void qemu_system_reset(bool report)
 {
     if (current_machine && current_machine->reset) {
diff --git a/xen-all.c b/xen-all.c
index 046cc2a..7d2a79f 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -14,6 +14,7 @@
 #include "hw/pc.h"
 #include "hw/xen_common.h"
 #include "hw/xen_backend.h"
+#include "hw/reset.h"
 #include "qmp-commands.h"
 
 #include "range.h"
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (4 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-12-03 21:49   ` Igor Mammedov
  2012-11-30 19:27 ` [Qemu-devel] [RFC 07/10] qdev: add sysbus_get_default() stub Eduardo Habkost
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

Add vmstate stub functions, so that qdev.o can be used without savevm.o
when vmstate support is not necessary (i.e. by *-user).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Originally submitted as:
  Subject: qdev-core: isolate vmstate handling into separate functions

Changes v1 -> v2:
 - Add GCC_WEAK_DECL to function declarations

Changes v2 -> v3:
 - Subject: qdev: add weak aliases for vmstate handling on qdev.c
 - Make vmstate_register_with_alias_id()/vmstate_unregister()
   have GCC_WEAK versions, instead of creating a new function
 - Kept qdev_get_vmsd() inside qdev.c

Changss v3 -> v4:
 - Use the new QEMU_WEAK_ALIAS system instead of GCC_WEAK

Changes v4 -> v5:
 - Use the new libqemustub.a, instead of QEMU_WEAK_ALIAS

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 stubs/Makefile.objs |  1 +
 stubs/vmstate.c     | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 stubs/vmstate.c

diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 035b29a..5557079 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -5,4 +5,5 @@ stub-obj-y += fdset-get-fd.o
 stub-obj-y += fdset-remove-fd.o
 stub-obj-y += get-fd.o
 stub-obj-y += set-fd-handler.o
+stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
diff --git a/stubs/vmstate.c b/stubs/vmstate.c
new file mode 100644
index 0000000..bb17884
--- /dev/null
+++ b/stubs/vmstate.c
@@ -0,0 +1,17 @@
+#include "qemu-common.h"
+#include "vmstate.h"
+
+int vmstate_register_with_alias_id(DeviceState *dev,
+                                               int instance_id,
+                                               const VMStateDescription *vmsd,
+                                               void *base, int alias_id,
+                                               int required_for_version)
+{
+    return 0;
+}
+
+void vmstate_unregister(DeviceState *dev,
+                                    const VMStateDescription *vmsd,
+                                    void *opaque)
+{
+}
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 07/10] qdev: add sysbus_get_default() stub
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (5 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 08/10] qdev-properties.c: separate core from the code used only by qemu-system-* Eduardo Habkost
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

This version will be used on cases where sysbus.c is not compiled in
(e.g. *-user).

Note that code that uses NULL as the bus with qdev{_try,}_create()
implicitly uses sysbus_get_default() as the bus, and requires sysbus.c
to be compiled in.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
 - Use the new QEMU_WEAK_ALIAS mechanism, instead of GCC_WEAK

Changes v2 -> v3:
 - Use the new libqemustub.a mechanism, instead of QEMU_WEAK_ALIAS
---
 stubs/Makefile.objs | 1 +
 stubs/sysbus.c      | 6 ++++++
 2 files changed, 7 insertions(+)
 create mode 100644 stubs/sysbus.c

diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 5557079..a59885f 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -6,4 +6,5 @@ stub-obj-y += fdset-remove-fd.o
 stub-obj-y += get-fd.o
 stub-obj-y += set-fd-handler.o
 stub-obj-y += vmstate.o
+stub-obj-y += sysbus.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
diff --git a/stubs/sysbus.c b/stubs/sysbus.c
new file mode 100644
index 0000000..e134965
--- /dev/null
+++ b/stubs/sysbus.c
@@ -0,0 +1,6 @@
+#include "hw/qdev-core.h"
+
+BusState *sysbus_get_default(void)
+{
+    return NULL;
+}
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 08/10] qdev-properties.c: separate core from the code used only by qemu-system-*
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (6 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 07/10] qdev: add sysbus_get_default() stub Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 09/10] include qdev code into *-user, too Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 10/10] qom: make CPU a child of DeviceState Eduardo Habkost
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

This separates the qdev properties code in two parts:
 - qdev-properties.c, that contains most of the qdev properties code;
 - qdev-properties-system.c for code specific for qemu-system-*,
   containing:
   - Property types: drive, chr, netdev, vlan, that depend on code that
     won't be included on *-user
   - qemu_add_globals(), that depends on qemu-config.o.

This change should help on two things:
 - Allowing DeviceState to be used by *-user without pulling
   dependencies that are specific for qemu-system-*;
 - Writing qdev unit tests without pulling too many dependencies.

The copyright/license header for the new file is directly copied from
qdev-properties.c.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
[imammedo: keep qdev_get_child_bus() in hw/qdev.c]
[imammedo: put qdev_set_nic_properties() in hw/qdev-properties-system.c]
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
[ehabkost: updated the qdev_init_gpio_in() code on qdev-system.c to current
 version]
[ehabkost: added copyright/license information to new qdev*-system.c files]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Yes, there is "changelog" data before the "---" mark, but I believe that
in this case they are important to indicate authorship and the scope of
the Signed-off-by lines (so they need to get into the git commit
message).

Detailed changelog:

Changes v1 (ehabkost) -> v2 (imammedo):
 - keep qdev_get_child_bus() in hw/qdev.c
 - put qdev_set_nic_properties() in hw/qdev-properties-system.c

Changes v2 -> v3 (ehabkost):
 - updated the qdev_init_gpio_in() code on qdev-system.c to current
   version

Changes v3 -> v4 (ehabkost):
 - Added copyright/license information to qdev-properties-system.c
   (based on copyright/license of qdev-properties.c)
 - Whitespace change at the end of qdev-properties.c
 - Don't create qdev-system.c, now we can keep the qdev.c code as-is
   as the qdev.c dependencies were reduced
 - Rewrite patch description

Changes v4 -> v5 (ehabkost):
 - Remove large copyright header and instead just point to the original
   file it was based on
---
 hw/Makefile.objs            |   1 +
 hw/qdev-properties-system.c | 352 ++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev-properties.c        | 321 +---------------------------------------
 hw/qdev-properties.h        |   1 +
 hw/qdev.c                   |  13 --
 5 files changed, 355 insertions(+), 333 deletions(-)
 create mode 100644 hw/qdev-properties-system.c

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 1dfed06..0f7bfe0 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -186,6 +186,7 @@ common-obj-y += bt.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
 common-obj-y += bt-hci-csr.o
 common-obj-y += msmouse.o ps2.o
 common-obj-y += qdev.o qdev-properties.o qdev-monitor.o
+common-obj-y += qdev-properties-system.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 
 # xen backend driver support
diff --git a/hw/qdev-properties-system.c b/hw/qdev-properties-system.c
new file mode 100644
index 0000000..9a7e0b3
--- /dev/null
+++ b/hw/qdev-properties-system.c
@@ -0,0 +1,352 @@
+/*
+ * qdev property parsing and global properties
+ * (parts specific for qemu-system-*)
+ *
+ * This file is based on code from hw/qdev-properties.c from
+ * commit 4e68f7a0819f179c2ff90a60611806c789911cc2,
+ * Copyright (c) Gerd Hoffmann <kraxel@redhat.com> and other contributors.
+ *
+ * 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 "net.h"
+#include "qdev.h"
+#include "qerror.h"
+#include "blockdev.h"
+#include "hw/block-common.h"
+#include "net/hub.h"
+#include "qapi/qapi-visit-core.h"
+
+static void get_pointer(Object *obj, Visitor *v, Property *prop,
+                        const char *(*print)(void *ptr),
+                        const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    void **ptr = qdev_get_prop_ptr(dev, prop);
+    char *p;
+
+    p = (char *) (*ptr ? print(*ptr) : "");
+    visit_type_str(v, &p, name, errp);
+}
+
+static void set_pointer(Object *obj, Visitor *v, Property *prop,
+                        int (*parse)(DeviceState *dev, const char *str,
+                                     void **ptr),
+                        const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Error *local_err = NULL;
+    void **ptr = qdev_get_prop_ptr(dev, prop);
+    char *str;
+    int ret;
+
+    if (dev->state != DEV_STATE_CREATED) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+        return;
+    }
+
+    visit_type_str(v, &str, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (!*str) {
+        g_free(str);
+        *ptr = NULL;
+        return;
+    }
+    ret = parse(dev, str, ptr);
+    error_set_from_qdev_prop_error(errp, ret, dev, prop, str);
+    g_free(str);
+}
+
+/* --- drive --- */
+
+static int parse_drive(DeviceState *dev, const char *str, void **ptr)
+{
+    BlockDriverState *bs;
+
+    bs = bdrv_find(str);
+    if (bs == NULL)
+        return -ENOENT;
+    if (bdrv_attach_dev(bs, dev) < 0)
+        return -EEXIST;
+    *ptr = bs;
+    return 0;
+}
+
+static void release_drive(Object *obj, const char *name, void *opaque)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr) {
+        bdrv_detach_dev(*ptr, dev);
+        blockdev_auto_del(*ptr);
+    }
+}
+
+static const char *print_drive(void *ptr)
+{
+    return bdrv_get_device_name(ptr);
+}
+
+static void get_drive(Object *obj, Visitor *v, void *opaque,
+                      const char *name, Error **errp)
+{
+    get_pointer(obj, v, opaque, print_drive, name, errp);
+}
+
+static void set_drive(Object *obj, Visitor *v, void *opaque,
+                      const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_drive, name, errp);
+}
+
+PropertyInfo qdev_prop_drive = {
+    .name  = "drive",
+    .get   = get_drive,
+    .set   = set_drive,
+    .release = release_drive,
+};
+
+/* --- character device --- */
+
+static int parse_chr(DeviceState *dev, const char *str, void **ptr)
+{
+    CharDriverState *chr = qemu_chr_find(str);
+    if (chr == NULL) {
+        return -ENOENT;
+    }
+    if (chr->avail_connections < 1) {
+        return -EEXIST;
+    }
+    *ptr = chr;
+    --chr->avail_connections;
+    return 0;
+}
+
+static void release_chr(Object *obj, const char *name, void *opaque)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr) {
+        qemu_chr_add_handlers(*ptr, NULL, NULL, NULL, NULL);
+    }
+}
+
+
+static const char *print_chr(void *ptr)
+{
+    CharDriverState *chr = ptr;
+
+    return chr->label ? chr->label : "";
+}
+
+static void get_chr(Object *obj, Visitor *v, void *opaque,
+                    const char *name, Error **errp)
+{
+    get_pointer(obj, v, opaque, print_chr, name, errp);
+}
+
+static void set_chr(Object *obj, Visitor *v, void *opaque,
+                    const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_chr, name, errp);
+}
+
+PropertyInfo qdev_prop_chr = {
+    .name  = "chr",
+    .get   = get_chr,
+    .set   = set_chr,
+    .release = release_chr,
+};
+
+/* --- netdev device --- */
+
+static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
+{
+    NetClientState *netdev = qemu_find_netdev(str);
+
+    if (netdev == NULL) {
+        return -ENOENT;
+    }
+    if (netdev->peer) {
+        return -EEXIST;
+    }
+    *ptr = netdev;
+    return 0;
+}
+
+static const char *print_netdev(void *ptr)
+{
+    NetClientState *netdev = ptr;
+
+    return netdev->name ? netdev->name : "";
+}
+
+static void get_netdev(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    get_pointer(obj, v, opaque, print_netdev, name, errp);
+}
+
+static void set_netdev(Object *obj, Visitor *v, void *opaque,
+                       const char *name, Error **errp)
+{
+    set_pointer(obj, v, opaque, parse_netdev, name, errp);
+}
+
+PropertyInfo qdev_prop_netdev = {
+    .name  = "netdev",
+    .get   = get_netdev,
+    .set   = set_netdev,
+};
+
+void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
+{
+    qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
+    if (nd->netdev)
+        qdev_prop_set_netdev(dev, "netdev", nd->netdev);
+    if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED &&
+        object_property_find(OBJECT(dev), "vectors", NULL)) {
+        qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
+    }
+    nd->instantiated = 1;
+}
+
+/* --- vlan --- */
+
+static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+    NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr) {
+        int id;
+        if (!net_hub_id_for_client(*ptr, &id)) {
+            return snprintf(dest, len, "%d", id);
+        }
+    }
+
+    return snprintf(dest, len, "<null>");
+}
+
+static void get_vlan(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
+    int32_t id = -1;
+
+    if (*ptr) {
+        int hub_id;
+        if (!net_hub_id_for_client(*ptr, &hub_id)) {
+            id = hub_id;
+        }
+    }
+
+    visit_type_int32(v, &id, name, errp);
+}
+
+static void set_vlan(Object *obj, Visitor *v, void *opaque,
+                     const char *name, Error **errp)
+{
+    DeviceState *dev = DEVICE(obj);
+    Property *prop = opaque;
+    NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
+    Error *local_err = NULL;
+    int32_t id;
+    NetClientState *hubport;
+
+    if (dev->state != DEV_STATE_CREATED) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+        return;
+    }
+
+    visit_type_int32(v, &id, name, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    if (id == -1) {
+        *ptr = NULL;
+        return;
+    }
+
+    hubport = net_hub_port_find(id);
+    if (!hubport) {
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+                  name, prop->info->name);
+        return;
+    }
+    *ptr = hubport;
+}
+
+PropertyInfo qdev_prop_vlan = {
+    .name  = "vlan",
+    .print = print_vlan,
+    .get   = get_vlan,
+    .set   = set_vlan,
+};
+
+
+int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
+{
+    Error *errp = NULL;
+    const char *bdrv_name = value ? bdrv_get_device_name(value) : "";
+    object_property_set_str(OBJECT(dev), bdrv_name,
+                            name, &errp);
+    if (errp) {
+        qerror_report_err(errp);
+        error_free(errp);
+        return -1;
+    }
+    return 0;
+}
+
+void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value)
+{
+    if (qdev_prop_set_drive(dev, name, value) < 0) {
+        exit(1);
+    }
+}
+
+void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
+{
+    Error *errp = NULL;
+    assert(!value || value->label);
+    object_property_set_str(OBJECT(dev),
+                            value ? value->label : "", name, &errp);
+    assert_no_error(errp);
+}
+
+void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value)
+{
+    Error *errp = NULL;
+    assert(!value || value->name);
+    object_property_set_str(OBJECT(dev),
+                            value ? value->name : "", name, &errp);
+    assert_no_error(errp);
+}
+
+static int qdev_add_one_global(QemuOpts *opts, void *opaque)
+{
+    GlobalProperty *g;
+
+    g = g_malloc0(sizeof(*g));
+    g->driver   = qemu_opt_get(opts, "driver");
+    g->property = qemu_opt_get(opts, "property");
+    g->value    = qemu_opt_get(opts, "value");
+    qdev_prop_register_global(g);
+    return 0;
+}
+
+void qemu_add_globals(void)
+{
+    qemu_opts_foreach(qemu_find_opts("global"), qdev_add_one_global, NULL, 0);
+}
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 81d901c..9ec04be 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -13,49 +13,6 @@ void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
     return ptr;
 }
 
-static void get_pointer(Object *obj, Visitor *v, Property *prop,
-                        const char *(*print)(void *ptr),
-                        const char *name, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    void **ptr = qdev_get_prop_ptr(dev, prop);
-    char *p;
-
-    p = (char *) (*ptr ? print(*ptr) : "");
-    visit_type_str(v, &p, name, errp);
-}
-
-static void set_pointer(Object *obj, Visitor *v, Property *prop,
-                        int (*parse)(DeviceState *dev, const char *str,
-                                     void **ptr),
-                        const char *name, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Error *local_err = NULL;
-    void **ptr = qdev_get_prop_ptr(dev, prop);
-    char *str;
-    int ret;
-
-    if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_str(v, &str, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (!*str) {
-        g_free(str);
-        *ptr = NULL;
-        return;
-    }
-    ret = parse(dev, str, ptr);
-    error_set_from_qdev_prop_error(errp, ret, dev, prop, str);
-    g_free(str);
-}
-
 static void get_enum(Object *obj, Visitor *v, void *opaque,
                      const char *name, Error **errp)
 {
@@ -476,227 +433,6 @@ PropertyInfo qdev_prop_string = {
     .set   = set_string,
 };
 
-/* --- drive --- */
-
-static int parse_drive(DeviceState *dev, const char *str, void **ptr)
-{
-    BlockDriverState *bs;
-
-    bs = bdrv_find(str);
-    if (bs == NULL)
-        return -ENOENT;
-    if (bdrv_attach_dev(bs, dev) < 0)
-        return -EEXIST;
-    *ptr = bs;
-    return 0;
-}
-
-static void release_drive(Object *obj, const char *name, void *opaque)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
-
-    if (*ptr) {
-        bdrv_detach_dev(*ptr, dev);
-        blockdev_auto_del(*ptr);
-    }
-}
-
-static const char *print_drive(void *ptr)
-{
-    return bdrv_get_device_name(ptr);
-}
-
-static void get_drive(Object *obj, Visitor *v, void *opaque,
-                      const char *name, Error **errp)
-{
-    get_pointer(obj, v, opaque, print_drive, name, errp);
-}
-
-static void set_drive(Object *obj, Visitor *v, void *opaque,
-                      const char *name, Error **errp)
-{
-    set_pointer(obj, v, opaque, parse_drive, name, errp);
-}
-
-PropertyInfo qdev_prop_drive = {
-    .name  = "drive",
-    .get   = get_drive,
-    .set   = set_drive,
-    .release = release_drive,
-};
-
-/* --- character device --- */
-
-static int parse_chr(DeviceState *dev, const char *str, void **ptr)
-{
-    CharDriverState *chr = qemu_chr_find(str);
-    if (chr == NULL) {
-        return -ENOENT;
-    }
-    if (chr->avail_connections < 1) {
-        return -EEXIST;
-    }
-    *ptr = chr;
-    --chr->avail_connections;
-    return 0;
-}
-
-static void release_chr(Object *obj, const char *name, void *opaque)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
-
-    if (*ptr) {
-        qemu_chr_add_handlers(*ptr, NULL, NULL, NULL, NULL);
-    }
-}
-
-
-static const char *print_chr(void *ptr)
-{
-    CharDriverState *chr = ptr;
-
-    return chr->label ? chr->label : "";
-}
-
-static void get_chr(Object *obj, Visitor *v, void *opaque,
-                    const char *name, Error **errp)
-{
-    get_pointer(obj, v, opaque, print_chr, name, errp);
-}
-
-static void set_chr(Object *obj, Visitor *v, void *opaque,
-                    const char *name, Error **errp)
-{
-    set_pointer(obj, v, opaque, parse_chr, name, errp);
-}
-
-PropertyInfo qdev_prop_chr = {
-    .name  = "chr",
-    .get   = get_chr,
-    .set   = set_chr,
-    .release = release_chr,
-};
-
-/* --- netdev device --- */
-
-static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
-{
-    NetClientState *netdev = qemu_find_netdev(str);
-
-    if (netdev == NULL) {
-        return -ENOENT;
-    }
-    if (netdev->peer) {
-        return -EEXIST;
-    }
-    *ptr = netdev;
-    return 0;
-}
-
-static const char *print_netdev(void *ptr)
-{
-    NetClientState *netdev = ptr;
-
-    return netdev->name ? netdev->name : "";
-}
-
-static void get_netdev(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    get_pointer(obj, v, opaque, print_netdev, name, errp);
-}
-
-static void set_netdev(Object *obj, Visitor *v, void *opaque,
-                       const char *name, Error **errp)
-{
-    set_pointer(obj, v, opaque, parse_netdev, name, errp);
-}
-
-PropertyInfo qdev_prop_netdev = {
-    .name  = "netdev",
-    .get   = get_netdev,
-    .set   = set_netdev,
-};
-
-/* --- vlan --- */
-
-static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
-{
-    NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
-
-    if (*ptr) {
-        int id;
-        if (!net_hub_id_for_client(*ptr, &id)) {
-            return snprintf(dest, len, "%d", id);
-        }
-    }
-
-    return snprintf(dest, len, "<null>");
-}
-
-static void get_vlan(Object *obj, Visitor *v, void *opaque,
-                     const char *name, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
-    int32_t id = -1;
-
-    if (*ptr) {
-        int hub_id;
-        if (!net_hub_id_for_client(*ptr, &hub_id)) {
-            id = hub_id;
-        }
-    }
-
-    visit_type_int32(v, &id, name, errp);
-}
-
-static void set_vlan(Object *obj, Visitor *v, void *opaque,
-                     const char *name, Error **errp)
-{
-    DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
-    NetClientState **ptr = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
-    int32_t id;
-    NetClientState *hubport;
-
-    if (dev->state != DEV_STATE_CREATED) {
-        error_set(errp, QERR_PERMISSION_DENIED);
-        return;
-    }
-
-    visit_type_int32(v, &id, name, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
-        return;
-    }
-    if (id == -1) {
-        *ptr = NULL;
-        return;
-    }
-
-    hubport = net_hub_port_find(id);
-    if (!hubport) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE,
-                  name, prop->info->name);
-        return;
-    }
-    *ptr = hubport;
-}
-
-PropertyInfo qdev_prop_vlan = {
-    .name  = "vlan",
-    .print = print_vlan,
-    .get   = get_vlan,
-    .set   = set_vlan,
-};
-
 /* --- pointer --- */
 
 /* Not a proper property, just for dirty hacks.  TODO Remove it!  */
@@ -1158,44 +894,6 @@ void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value)
     assert_no_error(errp);
 }
 
-int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value)
-{
-    Error *errp = NULL;
-    const char *bdrv_name = value ? bdrv_get_device_name(value) : "";
-    object_property_set_str(OBJECT(dev), bdrv_name,
-                            name, &errp);
-    if (errp) {
-        qerror_report_err(errp);
-        error_free(errp);
-        return -1;
-    }
-    return 0;
-}
-
-void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value)
-{
-    if (qdev_prop_set_drive(dev, name, value) < 0) {
-        exit(1);
-    }
-}
-void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value)
-{
-    Error *errp = NULL;
-    assert(!value || value->label);
-    object_property_set_str(OBJECT(dev),
-                            value ? value->label : "", name, &errp);
-    assert_no_error(errp);
-}
-
-void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value)
-{
-    Error *errp = NULL;
-    assert(!value || value->name);
-    object_property_set_str(OBJECT(dev),
-                            value ? value->name : "", name, &errp);
-    assert_no_error(errp);
-}
-
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
 {
     Error *errp = NULL;
@@ -1231,7 +929,7 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
 
 static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(global_props);
 
-static void qdev_prop_register_global(GlobalProperty *prop)
+void qdev_prop_register_global(GlobalProperty *prop)
 {
     QTAILQ_INSERT_TAIL(&global_props, prop, next);
 }
@@ -1262,20 +960,3 @@ void qdev_prop_set_globals(DeviceState *dev)
         class = object_class_get_parent(class);
     } while (class);
 }
-
-static int qdev_add_one_global(QemuOpts *opts, void *opaque)
-{
-    GlobalProperty *g;
-
-    g = g_malloc0(sizeof(*g));
-    g->driver   = qemu_opt_get(opts, "driver");
-    g->property = qemu_opt_get(opts, "property");
-    g->value    = qemu_opt_get(opts, "value");
-    qdev_prop_register_global(g);
-    return 0;
-}
-
-void qemu_add_globals(void)
-{
-    qemu_opts_foreach(qemu_find_opts("global"), qdev_add_one_global, NULL, 0);
-}
diff --git a/hw/qdev-properties.h b/hw/qdev-properties.h
index 5b046ab..ddcf774 100644
--- a/hw/qdev-properties.h
+++ b/hw/qdev-properties.h
@@ -116,6 +116,7 @@ void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
 /* FIXME: Remove opaque pointer properties.  */
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 
+void qdev_prop_register_global(GlobalProperty *prop);
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
diff --git a/hw/qdev.c b/hw/qdev.c
index 15b967d..aaae3a4 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -25,7 +25,6 @@
    inherit from a particular bus (e.g. PCI or I2C) rather than
    this API directly.  */
 
-#include "net.h"
 #include "qdev.h"
 #include "hw/reset.h"
 #include "sysemu.h"
@@ -313,18 +312,6 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
     dev->gpio_out[n] = pin;
 }
 
-void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
-{
-    qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
-    if (nd->netdev)
-        qdev_prop_set_netdev(dev, "netdev", nd->netdev);
-    if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED &&
-        object_property_find(OBJECT(dev), "vectors", NULL)) {
-        qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
-    }
-    nd->instantiated = 1;
-}
-
 BusState *qdev_get_child_bus(DeviceState *dev, const char *name)
 {
     BusState *bus;
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 09/10] include qdev code into *-user, too
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (7 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 08/10] qdev-properties.c: separate core from the code used only by qemu-system-* Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  2012-11-30 19:27 ` [Qemu-devel] [RFC 10/10] qom: make CPU a child of DeviceState Eduardo Habkost
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

The code depends on some functions from qemu-option.o, so add
qemu-option.o to universal-obj-y to make sure it's included.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
 - Keep files on the hw/ directory
   (it's simply easier to keep them there, as qdev.o depends on irq.o)
 - Add a $(hw-core-obj-y) variable to Makefile.objs for the qdev core code
 - Add irq.o to the list of core qdev files
   (as now the gpio code is being kept inside qdev.c)

Changes v2 -> v3:
 - Add reset.o to hw-core-obj-y
---
 Makefile.objs    |  8 ++++++++
 hw/Makefile.objs | 12 +++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 0a0a33a..8fe4991 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -31,6 +31,13 @@ qom-obj-y = qom/
 universal-obj-y += $(qom-obj-y)
 
 #######################################################################
+# Core hw code (qdev core)
+hw-core-obj-y += hw/
+hw-core-obj-y += qemu-option.o
+
+universal-obj-y += $(hw-core-obj-y)
+
+#######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
 oslib-obj-y = osdep.o cutils.o qemu-timer-common.o
 oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
@@ -253,5 +260,6 @@ nested-vars += \
 	block-obj-y \
 	user-obj-y \
 	common-obj-y \
+	hw-core-obj-y \
 	extra-obj-y
 dummy := $(call unnest-vars)
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 0f7bfe0..b81436e 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -1,6 +1,13 @@
+# core qdev-related obj files, also used by *-user:
+hw-core-obj-y += qdev.o qdev-properties.o
+# irq.o needed for qdev GPIO handling:
+hw-core-obj-y += irq.o
+# reset.o used by qdev to register reset handlers:
+hw-core-obj-y += reset.o
+
+
 common-obj-y = usb/ ide/
 common-obj-y += loader.o
-common-obj-y += reset.o
 common-obj-$(CONFIG_VIRTIO) += virtio-console.o
 common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
 common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
@@ -159,7 +166,6 @@ common-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 common-obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/
 
 common-obj-y += usb/
-common-obj-y += irq.o
 common-obj-$(CONFIG_PTIMER) += ptimer.o
 common-obj-$(CONFIG_MAX7310) += max7310.o
 common-obj-$(CONFIG_WM8750) += wm8750.o
@@ -185,7 +191,7 @@ common-obj-$(CONFIG_SD) += sd.o
 common-obj-y += bt.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
 common-obj-y += bt-hci-csr.o
 common-obj-y += msmouse.o ps2.o
-common-obj-y += qdev.o qdev-properties.o qdev-monitor.o
+common-obj-y += qdev-monitor.o
 common-obj-y += qdev-properties-system.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 
-- 
1.7.11.7

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

* [Qemu-devel] [RFC 10/10] qom: make CPU a child of DeviceState
  2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
                   ` (8 preceding siblings ...)
  2012-11-30 19:27 ` [Qemu-devel] [RFC 09/10] include qdev code into *-user, too Eduardo Habkost
@ 2012-11-30 19:27 ` Eduardo Habkost
  9 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-11-30 19:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Anthony Liguori

From: Igor Mammedov <imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
[ehabkost: change CPU type declaration to hae TYPE_DEVICE as parent]
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Yes, there is "changelog" data before the "---" mark, but I believe that
in this case they are important to indicate authorship and the scope of
the Signed-off-by lines (so they need to get into the git commit
message).
---
 include/qemu/cpu.h | 6 +++---
 qom/cpu.c          | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 61b7698..bc004fd 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -20,7 +20,7 @@
 #ifndef QEMU_CPU_H
 #define QEMU_CPU_H
 
-#include "qemu/object.h"
+#include "hw/qdev-core.h"
 #include "qemu-thread.h"
 
 /**
@@ -46,7 +46,7 @@ typedef struct CPUState CPUState;
  */
 typedef struct CPUClass {
     /*< private >*/
-    ObjectClass parent_class;
+    DeviceClass parent_class;
     /*< public >*/
 
     void (*reset)(CPUState *cpu);
@@ -62,7 +62,7 @@ typedef struct CPUClass {
  */
 struct CPUState {
     /*< private >*/
-    Object parent_obj;
+    DeviceState parent_obj;
     /*< public >*/
 
     struct QemuThread *thread;
diff --git a/qom/cpu.c b/qom/cpu.c
index 5b36046..f59db7d 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -20,6 +20,7 @@
 
 #include "qemu/cpu.h"
 #include "qemu-common.h"
+#include "hw/qdev-core.h"
 
 void cpu_reset(CPUState *cpu)
 {
@@ -43,7 +44,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 
 static TypeInfo cpu_type_info = {
     .name = TYPE_CPU,
-    .parent = TYPE_OBJECT,
+    .parent = TYPE_DEVICE,
     .instance_size = sizeof(CPUState),
     .abstract = true,
     .class_size = sizeof(CPUClass),
-- 
1.7.11.7

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

* Re: [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c
  2012-11-30 19:27 ` [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c Eduardo Habkost
@ 2012-12-03 20:19   ` Igor Mammedov
  2012-12-03 21:20   ` Igor Mammedov
  1 sibling, 0 replies; 17+ messages in thread
From: Igor Mammedov @ 2012-12-03 20:19 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel

On Fri, 30 Nov 2012 17:27:17 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> The core qdev code uses the reset handler list from vl.c, and
> currently *-user has some hacks to make CPU reset work.
> 
> This moves qemu_register_reset(), qemu_unregister_reset() and
> qemu_devices_reset() to a new file, hw/reset.c, that can be used by qdev
> and by *-user.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  hw/Makefile.objs     |  1 +
>  hw/ac97.c            |  1 +
>  hw/acpi_ich9.c       |  1 +
patch doesn't apply to the current tree.


-- 
Regards,
  Igor

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

* Re: [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c
  2012-11-30 19:27 ` [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c Eduardo Habkost
  2012-12-03 20:19   ` Igor Mammedov
@ 2012-12-03 21:20   ` Igor Mammedov
  2012-12-03 22:46     ` Eduardo Habkost
  1 sibling, 1 reply; 17+ messages in thread
From: Igor Mammedov @ 2012-12-03 21:20 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, Anthony Liguori, Andreas Färber

On Fri, 30 Nov 2012 17:27:17 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> The core qdev code uses the reset handler list from vl.c, and
> currently *-user has some hacks to make CPU reset work.
> 
> This moves qemu_register_reset(), qemu_unregister_reset() and
> qemu_devices_reset() to a new file, hw/reset.c, that can be used by qdev
> and by *-user.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
[...]
> diff --git a/hw/reset.c b/hw/reset.c
> new file mode 100644
> index 0000000..5e34b80
> --- /dev/null
> +++ b/hw/reset.c
> @@ -0,0 +1,43 @@
> +#include "hw/reset.h"
> +#include "qlist.h"
missing #include <glib.h> for g_malloc/g_free

[...]
> diff --git a/xen-all.c b/xen-all.c
> index 046cc2a..7d2a79f 100644
> --- a/xen-all.c
> +++ b/xen-all.c
> @@ -14,6 +14,7 @@
>  #include "hw/pc.h"
>  #include "hw/xen_common.h"
>  #include "hw/xen_backend.h"
> +#include "hw/reset.h"
>  #include "qmp-commands.h"
>  
>  #include "range.h"
> -- 
> 1.7.11.7
> 
> 
Since you are going not include reset.o in *-user:
although dedicated reset.c is nice to have perhaps you can drop reset.c /it's
not very related to this series topic/ altogether to minimize scope of review
and limit patch only to reset.h and qemu_register_reset(),
qemu_unregister_reset() and qemu_devices_reset() stubs for *-user.

-- 
Regards,
  Igor

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

* Re: [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions
  2012-11-30 19:27 ` [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions Eduardo Habkost
@ 2012-12-03 21:49   ` Igor Mammedov
  2012-12-04 12:49     ` Eduardo Habkost
  0 siblings, 1 reply; 17+ messages in thread
From: Igor Mammedov @ 2012-12-03 21:49 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: pbonzini, qemu-devel, Anthony Liguori, Andreas Färber

On Fri, 30 Nov 2012 17:27:18 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:

> Add vmstate stub functions, so that qdev.o can be used without savevm.o
> when vmstate support is not necessary (i.e. by *-user).
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Originally submitted as:
>   Subject: qdev-core: isolate vmstate handling into separate functions
> 
> Changes v1 -> v2:
>  - Add GCC_WEAK_DECL to function declarations
> 
> Changes v2 -> v3:
>  - Subject: qdev: add weak aliases for vmstate handling on qdev.c
>  - Make vmstate_register_with_alias_id()/vmstate_unregister()
>    have GCC_WEAK versions, instead of creating a new function
>  - Kept qdev_get_vmsd() inside qdev.c
> 
> Changss v3 -> v4:
>  - Use the new QEMU_WEAK_ALIAS system instead of GCC_WEAK
> 
> Changes v4 -> v5:
>  - Use the new libqemustub.a, instead of QEMU_WEAK_ALIAS
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  stubs/Makefile.objs |  1 +
>  stubs/vmstate.c     | 17 +++++++++++++++++
>  2 files changed, 18 insertions(+)
>  create mode 100644 stubs/vmstate.c
> 
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 035b29a..5557079 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -5,4 +5,5 @@ stub-obj-y += fdset-get-fd.o
>  stub-obj-y += fdset-remove-fd.o
>  stub-obj-y += get-fd.o
>  stub-obj-y += set-fd-handler.o
> +stub-obj-y += vmstate.o
>  stub-obj-$(CONFIG_WIN32) += fd-register.o
> diff --git a/stubs/vmstate.c b/stubs/vmstate.c
> new file mode 100644
> index 0000000..bb17884
> --- /dev/null
> +++ b/stubs/vmstate.c
> @@ -0,0 +1,17 @@
> +#include "qemu-common.h"
> +#include "vmstate.h"
> +
> +int vmstate_register_with_alias_id(DeviceState *dev,
> +                                               int instance_id,
> +                                               const VMStateDescription *vmsd,
> +                                               void *base, int alias_id,
> +                                               int required_for_version)
> +{
> +    return 0;
> +}
> +
> +void vmstate_unregister(DeviceState *dev,
> +                                    const VMStateDescription *vmsd,
> +                                    void *opaque)
> +{
> +}
> -- 
> 1.7.11.7
> 
commit 3bc2f570ec9f description says, there should be a 1 object
file per stub /with a corresponding file name if 3bc2f570ec9f is used as a
model/.

Paolo,
 Is it ok to put several related stub functions in one file?

-- 
Regards,
  Igor

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

* Re: [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c
  2012-12-03 21:20   ` Igor Mammedov
@ 2012-12-03 22:46     ` Eduardo Habkost
  0 siblings, 0 replies; 17+ messages in thread
From: Eduardo Habkost @ 2012-12-03 22:46 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: qemu-devel, Anthony Liguori, Andreas Färber

On Mon, Dec 03, 2012 at 10:20:03PM +0100, Igor Mammedov wrote:
> On Fri, 30 Nov 2012 17:27:17 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > The core qdev code uses the reset handler list from vl.c, and
> > currently *-user has some hacks to make CPU reset work.
> > 
> > This moves qemu_register_reset(), qemu_unregister_reset() and
> > qemu_devices_reset() to a new file, hw/reset.c, that can be used by qdev
> > and by *-user.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> [...]
> > diff --git a/hw/reset.c b/hw/reset.c
> > new file mode 100644
> > index 0000000..5e34b80
> > --- /dev/null
> > +++ b/hw/reset.c
> > @@ -0,0 +1,43 @@
> > +#include "hw/reset.h"
> > +#include "qlist.h"
> missing #include <glib.h> for g_malloc/g_free
> 
> [...]
> > diff --git a/xen-all.c b/xen-all.c
> > index 046cc2a..7d2a79f 100644
> > --- a/xen-all.c
> > +++ b/xen-all.c
> > @@ -14,6 +14,7 @@
> >  #include "hw/pc.h"
> >  #include "hw/xen_common.h"
> >  #include "hw/xen_backend.h"
> > +#include "hw/reset.h"
> >  #include "qmp-commands.h"
> >  
> >  #include "range.h"
> > -- 
> > 1.7.11.7
> > 
> > 
> Since you are going not include reset.o in *-user:
> although dedicated reset.c is nice to have perhaps you can drop reset.c /it's
> not very related to this series topic/ altogether to minimize scope of review
> and limit patch only to reset.h and qemu_register_reset(),
> qemu_unregister_reset() and qemu_devices_reset() stubs for *-user.

I plan to remove this patch on the next respin of the series, and add
qemu_[un]register_reset() stubs to *-user instead. When I sent this
version of the series, I was still planning to include reset.o in
*-user.

-- 
Eduardo

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

* Re: [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions
  2012-12-03 21:49   ` Igor Mammedov
@ 2012-12-04 12:49     ` Eduardo Habkost
  2012-12-04 13:08       ` Paolo Bonzini
  0 siblings, 1 reply; 17+ messages in thread
From: Eduardo Habkost @ 2012-12-04 12:49 UTC (permalink / raw)
  To: Igor Mammedov; +Cc: pbonzini, qemu-devel, Anthony Liguori, Andreas Färber

On Mon, Dec 03, 2012 at 10:49:56PM +0100, Igor Mammedov wrote:
> On Fri, 30 Nov 2012 17:27:18 -0200
> Eduardo Habkost <ehabkost@redhat.com> wrote:
> 
> > Add vmstate stub functions, so that qdev.o can be used without savevm.o
> > when vmstate support is not necessary (i.e. by *-user).
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > Originally submitted as:
> >   Subject: qdev-core: isolate vmstate handling into separate functions
> > 
> > Changes v1 -> v2:
> >  - Add GCC_WEAK_DECL to function declarations
> > 
> > Changes v2 -> v3:
> >  - Subject: qdev: add weak aliases for vmstate handling on qdev.c
> >  - Make vmstate_register_with_alias_id()/vmstate_unregister()
> >    have GCC_WEAK versions, instead of creating a new function
> >  - Kept qdev_get_vmsd() inside qdev.c
> > 
> > Changss v3 -> v4:
> >  - Use the new QEMU_WEAK_ALIAS system instead of GCC_WEAK
> > 
> > Changes v4 -> v5:
> >  - Use the new libqemustub.a, instead of QEMU_WEAK_ALIAS
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  stubs/Makefile.objs |  1 +
> >  stubs/vmstate.c     | 17 +++++++++++++++++
> >  2 files changed, 18 insertions(+)
> >  create mode 100644 stubs/vmstate.c
> > 
> > diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> > index 035b29a..5557079 100644
> > --- a/stubs/Makefile.objs
> > +++ b/stubs/Makefile.objs
> > @@ -5,4 +5,5 @@ stub-obj-y += fdset-get-fd.o
> >  stub-obj-y += fdset-remove-fd.o
> >  stub-obj-y += get-fd.o
> >  stub-obj-y += set-fd-handler.o
> > +stub-obj-y += vmstate.o
> >  stub-obj-$(CONFIG_WIN32) += fd-register.o
> > diff --git a/stubs/vmstate.c b/stubs/vmstate.c
> > new file mode 100644
> > index 0000000..bb17884
> > --- /dev/null
> > +++ b/stubs/vmstate.c
> > @@ -0,0 +1,17 @@
> > +#include "qemu-common.h"
> > +#include "vmstate.h"
> > +
> > +int vmstate_register_with_alias_id(DeviceState *dev,
> > +                                               int instance_id,
> > +                                               const VMStateDescription *vmsd,
> > +                                               void *base, int alias_id,
> > +                                               int required_for_version)
> > +{
> > +    return 0;
> > +}
> > +
> > +void vmstate_unregister(DeviceState *dev,
> > +                                    const VMStateDescription *vmsd,
> > +                                    void *opaque)
> > +{
> > +}
> > -- 
> > 1.7.11.7
> > 
> commit 3bc2f570ec9f description says, there should be a 1 object
> file per stub /with a corresponding file name if 3bc2f570ec9f is used as a
> model/.

Well, the commit description says that "if you place each function in a
separate source file, object files for unused functions will not be
taken in", I don't see it as a requirement. In this case, pulling both
stubs is a feature: if a binary ends up using the vmstate_register stub,
we really want it to use the vmstate_unregister stub as well.

> 
> Paolo,
>  Is it ok to put several related stub functions in one file?
> 
> -- 
> Regards,
>   Igor
> 

-- 
Eduardo

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

* Re: [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions
  2012-12-04 12:49     ` Eduardo Habkost
@ 2012-12-04 13:08       ` Paolo Bonzini
  0 siblings, 0 replies; 17+ messages in thread
From: Paolo Bonzini @ 2012-12-04 13:08 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Igor Mammedov, qemu-devel, Anthony Liguori, Andreas Färber

Il 04/12/2012 13:49, Eduardo Habkost ha scritto:
> Well, the commit description says that "if you place each function in a
> separate source file, object files for unused functions will not be
> taken in", I don't see it as a requirement. In this case, pulling both
> stubs is a feature: if a binary ends up using the vmstate_register stub,
> we really want it to use the vmstate_unregister stub as well.

I think Eduardo is right.  In the beginning I was thinking more of
having one function per file, but then in some cases the functions are
clearly related.

For example, if you have monitor_printf/monitor_vprintf, you have two
choices:

- put both of them in the same file, as done here for vmstate.

- put each in a separate file.  In this case, it doesn't really make
sense to implement only one, so the monitor_printf stub should use
va_start/va_end to forward to monitor_vprintf.

In the second case, the monitor_printf stub is not even a stub anymore,
because the same function will always be usable.  This makes it much
better to put both of them in the same file, IMHO.

Paolo

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

end of thread, other threads:[~2012-12-04 23:11 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-30 19:27 [Qemu-devel] [RFC 00/10] CPU DeviceState v8 Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 01/10] create qemu-types.h for struct typedefs Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 02/10] sysemu.h: include qemu-types.h instead of qemu-common.h Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 03/10] move -I$(SRC_PATH)/include compiler flag to Makefile.objs Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 04/10] qdev: qdev_create(): use error_report() instead of hw_error() Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 05/10] qdev: move reset handler list from vl.c to hw/reset.c Eduardo Habkost
2012-12-03 20:19   ` Igor Mammedov
2012-12-03 21:20   ` Igor Mammedov
2012-12-03 22:46     ` Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 06/10] qdev: add stubs for vmstate register/unregister functions Eduardo Habkost
2012-12-03 21:49   ` Igor Mammedov
2012-12-04 12:49     ` Eduardo Habkost
2012-12-04 13:08       ` Paolo Bonzini
2012-11-30 19:27 ` [Qemu-devel] [RFC 07/10] qdev: add sysbus_get_default() stub Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 08/10] qdev-properties.c: separate core from the code used only by qemu-system-* Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 09/10] include qdev code into *-user, too Eduardo Habkost
2012-11-30 19:27 ` [Qemu-devel] [RFC 10/10] qom: make CPU a child of DeviceState Eduardo Habkost

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