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