]>
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 | * | |
12 | */ | |
13 | ||
14 | #include "qemu-common.h" | |
15 | #include "sys-queue.h" | |
16 | #include "module.h" | |
17 | ||
18 | typedef struct ModuleEntry | |
19 | { | |
20 | module_init_type type; | |
21 | void (*init)(void); | |
22 | TAILQ_ENTRY(ModuleEntry) node; | |
23 | } ModuleEntry; | |
24 | ||
f7897430 | 25 | typedef TAILQ_HEAD(, ModuleEntry) ModuleTypeList; |
0bfe3ca5 | 26 | |
f7897430 | 27 | static ModuleTypeList init_type_list[MODULE_INIT_MAX]; |
0bfe3ca5 | 28 | |
f7897430 | 29 | static void init_types(void) |
0bfe3ca5 | 30 | { |
f7897430 AL |
31 | static int inited; |
32 | int i; | |
0bfe3ca5 | 33 | |
f7897430 AL |
34 | if (inited) { |
35 | return; | |
0bfe3ca5 AL |
36 | } |
37 | ||
f7897430 AL |
38 | for (i = 0; i < MODULE_INIT_MAX; i++) { |
39 | TAILQ_INIT(&init_type_list[i]); | |
40 | } | |
0bfe3ca5 | 41 | |
f7897430 AL |
42 | inited = 1; |
43 | } | |
0bfe3ca5 | 44 | |
0bfe3ca5 | 45 | |
f7897430 AL |
46 | static ModuleTypeList *find_type(module_init_type type) |
47 | { | |
48 | ModuleTypeList *l; | |
0bfe3ca5 | 49 | |
f7897430 AL |
50 | init_types(); |
51 | ||
52 | l = &init_type_list[type]; | |
0bfe3ca5 | 53 | |
f7897430 | 54 | return l; |
0bfe3ca5 AL |
55 | } |
56 | ||
57 | void register_module_init(void (*fn)(void), module_init_type type) | |
58 | { | |
59 | ModuleEntry *e; | |
60 | ModuleTypeList *l; | |
61 | ||
62 | e = qemu_mallocz(sizeof(*e)); | |
63 | e->init = fn; | |
64 | ||
f7897430 | 65 | l = find_type(type); |
0bfe3ca5 | 66 | |
f7897430 | 67 | TAILQ_INSERT_TAIL(l, e, node); |
0bfe3ca5 AL |
68 | } |
69 | ||
70 | void module_call_init(module_init_type type) | |
71 | { | |
72 | ModuleTypeList *l; | |
73 | ModuleEntry *e; | |
74 | ||
f7897430 | 75 | l = find_type(type); |
0bfe3ca5 | 76 | |
f7897430 | 77 | TAILQ_FOREACH(e, l, node) { |
0bfe3ca5 AL |
78 | e->init(); |
79 | } | |
80 | } |