2 * QEMU Module Infrastructure
4 * Copyright IBM, Corp. 2009
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #include "qemu-common.h"
15 #include "sys-queue.h"
18 typedef struct ModuleEntry
20 module_init_type type
;
22 TAILQ_ENTRY(ModuleEntry
) node
;
25 typedef struct ModuleTypeList
27 module_init_type type
;
28 TAILQ_HEAD(, ModuleEntry
) entry_list
;
29 TAILQ_ENTRY(ModuleTypeList
) node
;
32 static TAILQ_HEAD(, ModuleTypeList
) init_type_list
;
34 static ModuleTypeList
*find_type_or_alloc(module_init_type type
, int alloc
)
38 TAILQ_FOREACH(n
, &init_type_list
, node
) {
43 if (!n
|| n
->type
!= type
) {
49 o
= qemu_mallocz(sizeof(*o
));
51 TAILQ_INIT(&o
->entry_list
);
54 TAILQ_INSERT_AFTER(&init_type_list
, n
, o
, node
);
56 TAILQ_INSERT_HEAD(&init_type_list
, o
, node
);
65 void register_module_init(void (*fn
)(void), module_init_type type
)
70 e
= qemu_mallocz(sizeof(*e
));
73 l
= find_type_or_alloc(type
, 1);
75 TAILQ_INSERT_TAIL(&l
->entry_list
, e
, node
);
78 void module_call_init(module_init_type type
)
83 l
= find_type_or_alloc(type
, 0);
88 TAILQ_FOREACH(e
, &l
->entry_list
, node
) {