2009-05-14 22:29:53 +04:00
|
|
|
/*
|
|
|
|
* QEMU Module Infrastructure
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2009
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
2012-01-13 20:44:23 +04:00
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2009-05-14 22:29:53 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2009-09-12 11:36:22 +04:00
|
|
|
#include "qemu-queue.h"
|
2009-05-14 22:29:53 +04:00
|
|
|
#include "module.h"
|
|
|
|
|
|
|
|
typedef struct ModuleEntry
|
|
|
|
{
|
|
|
|
void (*init)(void);
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_ENTRY(ModuleEntry) node;
|
2009-05-14 22:29:53 +04:00
|
|
|
} ModuleEntry;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList;
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
static ModuleTypeList init_type_list[MODULE_INIT_MAX];
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
static void init_types(void)
|
2009-05-14 22:29:53 +04:00
|
|
|
{
|
2009-05-15 02:57:31 +04:00
|
|
|
static int inited;
|
|
|
|
int i;
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
if (inited) {
|
|
|
|
return;
|
2009-05-14 22:29:53 +04:00
|
|
|
}
|
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
for (i = 0; i < MODULE_INIT_MAX; i++) {
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_INIT(&init_type_list[i]);
|
2009-05-15 02:57:31 +04:00
|
|
|
}
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
inited = 1;
|
|
|
|
}
|
2009-05-14 22:29:53 +04:00
|
|
|
|
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
static ModuleTypeList *find_type(module_init_type type)
|
|
|
|
{
|
|
|
|
ModuleTypeList *l;
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
init_types();
|
|
|
|
|
|
|
|
l = &init_type_list[type];
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
return l;
|
2009-05-14 22:29:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void register_module_init(void (*fn)(void), module_init_type type)
|
|
|
|
{
|
|
|
|
ModuleEntry *e;
|
|
|
|
ModuleTypeList *l;
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
e = g_malloc0(sizeof(*e));
|
2009-05-14 22:29:53 +04:00
|
|
|
e->init = fn;
|
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
l = find_type(type);
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_INSERT_TAIL(l, e, node);
|
2009-05-14 22:29:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void module_call_init(module_init_type type)
|
|
|
|
{
|
|
|
|
ModuleTypeList *l;
|
|
|
|
ModuleEntry *e;
|
|
|
|
|
2009-05-15 02:57:31 +04:00
|
|
|
l = find_type(type);
|
2009-05-14 22:29:53 +04:00
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_FOREACH(e, l, node) {
|
2009-05-14 22:29:53 +04:00
|
|
|
e->init();
|
|
|
|
}
|
|
|
|
}
|