2009-05-14 20:29:53 +02: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2009-09-12 09:36:22 +02:00
|
|
|
#include "qemu-queue.h"
|
2009-05-14 20:29:53 +02:00
|
|
|
#include "module.h"
|
|
|
|
|
|
|
|
typedef struct ModuleEntry
|
|
|
|
{
|
|
|
|
module_init_type type;
|
|
|
|
void (*init)(void);
|
2009-09-12 09:36:22 +02:00
|
|
|
QTAILQ_ENTRY(ModuleEntry) node;
|
2009-05-14 20:29:53 +02:00
|
|
|
} ModuleEntry;
|
|
|
|
|
2009-09-12 09:36:22 +02:00
|
|
|
typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList;
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
static ModuleTypeList init_type_list[MODULE_INIT_MAX];
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
static void init_types(void)
|
2009-05-14 20:29:53 +02:00
|
|
|
{
|
2009-05-15 00:57:31 +02:00
|
|
|
static int inited;
|
|
|
|
int i;
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
if (inited) {
|
|
|
|
return;
|
2009-05-14 20:29:53 +02:00
|
|
|
}
|
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
for (i = 0; i < MODULE_INIT_MAX; i++) {
|
2009-09-12 09:36:22 +02:00
|
|
|
QTAILQ_INIT(&init_type_list[i]);
|
2009-05-15 00:57:31 +02:00
|
|
|
}
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
inited = 1;
|
|
|
|
}
|
2009-05-14 20:29:53 +02:00
|
|
|
|
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
static ModuleTypeList *find_type(module_init_type type)
|
|
|
|
{
|
|
|
|
ModuleTypeList *l;
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
init_types();
|
|
|
|
|
|
|
|
l = &init_type_list[type];
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
return l;
|
2009-05-14 20:29:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void register_module_init(void (*fn)(void), module_init_type type)
|
|
|
|
{
|
|
|
|
ModuleEntry *e;
|
|
|
|
ModuleTypeList *l;
|
|
|
|
|
2011-08-21 05:09:37 +02:00
|
|
|
e = g_malloc0(sizeof(*e));
|
2009-05-14 20:29:53 +02:00
|
|
|
e->init = fn;
|
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
l = find_type(type);
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-09-12 09:36:22 +02:00
|
|
|
QTAILQ_INSERT_TAIL(l, e, node);
|
2009-05-14 20:29:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void module_call_init(module_init_type type)
|
|
|
|
{
|
|
|
|
ModuleTypeList *l;
|
|
|
|
ModuleEntry *e;
|
|
|
|
|
2009-05-15 00:57:31 +02:00
|
|
|
l = find_type(type);
|
2009-05-14 20:29:53 +02:00
|
|
|
|
2009-09-12 09:36:22 +02:00
|
|
|
QTAILQ_FOREACH(e, l, node) {
|
2009-05-14 20:29:53 +02:00
|
|
|
e->init();
|
|
|
|
}
|
|
|
|
}
|