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