[v3,01/21] qom: Register QOM infrastructure early

Submitted by Andreas Färber on Feb. 3, 2012, 2:59 a.m.

Details

Message ID 1328237992-14953-2-git-send-email-afaerber@suse.de
State New
Headers show

Commit Message

Andreas Färber Feb. 3, 2012, 2:59 a.m.
QOM TYPE_INTERFACE was registered with device_init(), whose
constructors are executed rather late in vl.c's main().

Rename the module init type from DEVICE to QOM and call it very early
so that QOM can safely be used for machines and CPUs.

device_init() is left for legacy types. New ones should use type_init().

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
---
 module.h |    5 +++--
 vl.c     |    4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

Comments

Anthony Liguori Feb. 6, 2012, 7:14 p.m.
On 02/02/2012 08:59 PM, Andreas Färber wrote:
> QOM TYPE_INTERFACE was registered with device_init(), whose
> constructors are executed rather late in vl.c's main().
>
> Rename the module init type from DEVICE to QOM and call it very early
> so that QOM can safely be used for machines and CPUs.
>
> device_init() is left for legacy types. New ones should use type_init().

There are no legacy device_init users.  Everything can (and should) be converted 
to type_init() and MODULE_INIT_QOM can be invoked very early.

Regards,

Anthony Liguori

Patch hide | download patch | download mbox

diff --git a/module.h b/module.h
index ef66730..56391a5 100644
--- a/module.h
+++ b/module.h
@@ -21,15 +21,16 @@  static void __attribute__((constructor)) do_qemu_init_ ## function(void) {  \
 }
 
 typedef enum {
+    MODULE_INIT_QOM,
     MODULE_INIT_BLOCK,
-    MODULE_INIT_DEVICE,
     MODULE_INIT_MACHINE,
     MODULE_INIT_QAPI,
     MODULE_INIT_MAX
 } module_init_type;
 
+#define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define block_init(function) module_init(function, MODULE_INIT_BLOCK)
-#define device_init(function) module_init(function, MODULE_INIT_DEVICE)
+#define device_init(function) module_init(function, MODULE_INIT_QOM)
 #define machine_init(function) module_init(function, MODULE_INIT_MACHINE)
 #define qapi_init(function) module_init(function, MODULE_INIT_QAPI)
 
diff --git a/vl.c b/vl.c
index 2d464cf..8f2fc3c 100644
--- a/vl.c
+++ b/vl.c
@@ -2221,6 +2221,8 @@  int main(int argc, char **argv, char **envp)
 #endif
     }
 
+    module_call_init(MODULE_INIT_QOM);
+
     runstate_init();
 
     init_clocks();
@@ -3357,8 +3359,6 @@  int main(int argc, char **argv, char **envp)
     if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
         exit(1);
 
-    module_call_init(MODULE_INIT_DEVICE);
-
     /* must be after qdev registration but before machine init */
     if (vga_model) {
         select_vgahw(vga_model);