]>
Commit | Line | Data |
---|---|---|
0bfe3ca5 AL |
1 | /* |
2 | * QEMU Module Infrastructure | |
3 | * | |
4 | * Copyright IBM, Corp. 2009 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <[email protected]> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
6b620ca3 PB |
12 | * Contributions after 2012-01-13 are licensed under the terms of the |
13 | * GNU GPL, version 2 or (at your option) any later version. | |
0bfe3ca5 AL |
14 | */ |
15 | ||
16 | #include "qemu-common.h" | |
72cf2d4f | 17 | #include "qemu-queue.h" |
0bfe3ca5 AL |
18 | #include "module.h" |
19 | ||
20 | typedef struct ModuleEntry | |
21 | { | |
22 | module_init_type type; | |
23 | void (*init)(void); | |
72cf2d4f | 24 | QTAILQ_ENTRY(ModuleEntry) node; |
0bfe3ca5 AL |
25 | } ModuleEntry; |
26 | ||
72cf2d4f | 27 | typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList; |
0bfe3ca5 | 28 | |
f7897430 | 29 | static ModuleTypeList init_type_list[MODULE_INIT_MAX]; |
0bfe3ca5 | 30 | |
f7897430 | 31 | static void init_types(void) |
0bfe3ca5 | 32 | { |
f7897430 AL |
33 | static int inited; |
34 | int i; | |
0bfe3ca5 | 35 | |
f7897430 AL |
36 | if (inited) { |
37 | return; | |
0bfe3ca5 AL |
38 | } |
39 | ||
f7897430 | 40 | for (i = 0; i < MODULE_INIT_MAX; i++) { |
72cf2d4f | 41 | QTAILQ_INIT(&init_type_list[i]); |
f7897430 | 42 | } |
0bfe3ca5 | 43 | |
f7897430 AL |
44 | inited = 1; |
45 | } | |
0bfe3ca5 | 46 | |
0bfe3ca5 | 47 | |
f7897430 AL |
48 | static ModuleTypeList *find_type(module_init_type type) |
49 | { | |
50 | ModuleTypeList *l; | |
0bfe3ca5 | 51 | |
f7897430 AL |
52 | init_types(); |
53 | ||
54 | l = &init_type_list[type]; | |
0bfe3ca5 | 55 | |
f7897430 | 56 | return l; |
0bfe3ca5 AL |
57 | } |
58 | ||
59 | void register_module_init(void (*fn)(void), module_init_type type) | |
60 | { | |
61 | ModuleEntry *e; | |
62 | ModuleTypeList *l; | |
63 | ||
7267c094 | 64 | e = g_malloc0(sizeof(*e)); |
0bfe3ca5 AL |
65 | e->init = fn; |
66 | ||
f7897430 | 67 | l = find_type(type); |
0bfe3ca5 | 68 | |
72cf2d4f | 69 | QTAILQ_INSERT_TAIL(l, e, node); |
0bfe3ca5 AL |
70 | } |
71 | ||
72 | void module_call_init(module_init_type type) | |
73 | { | |
74 | ModuleTypeList *l; | |
75 | ModuleEntry *e; | |
76 | ||
f7897430 | 77 | l = find_type(type); |
0bfe3ca5 | 78 | |
72cf2d4f | 79 | QTAILQ_FOREACH(e, l, node) { |
0bfe3ca5 AL |
80 | e->init(); |
81 | } | |
82 | } |