diff options
author | Yinghai Lu <yhlu.kernel@gmail.com> | 2008-08-19 23:50:54 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-10-16 10:52:58 -0400 |
commit | e7f5ed8d6e921c6200ce5e2549a86db629f2dd11 (patch) | |
tree | 377e3a1876d3c8bf7703794e94a769e112808cc7 /init/dyn_array.c | |
parent | 2b46b37de73296018da02c2a421ac2a9cbccfa9f (diff) |
dyn_array: split dyn_array functions from init/main.c
Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'init/dyn_array.c')
-rw-r--r-- | init/dyn_array.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/init/dyn_array.c b/init/dyn_array.c new file mode 100644 index 000000000000..c4cd902a1180 --- /dev/null +++ b/init/dyn_array.c | |||
@@ -0,0 +1,124 @@ | |||
1 | #include <linux/types.h> | ||
2 | #include <linux/kernel.h> | ||
3 | #include <linux/kallsyms.h> | ||
4 | #include <linux/init.h> | ||
5 | #include <linux/bootmem.h> | ||
6 | #include <linux/irq.h> | ||
7 | |||
8 | void __init pre_alloc_dyn_array(void) | ||
9 | { | ||
10 | #ifdef CONFIG_HAVE_DYN_ARRAY | ||
11 | unsigned long total_size = 0, size, phys; | ||
12 | unsigned long max_align = 1; | ||
13 | struct dyn_array **daa; | ||
14 | char *ptr; | ||
15 | |||
16 | /* get the total size at first */ | ||
17 | for (daa = __dyn_array_start ; daa < __dyn_array_end; daa++) { | ||
18 | struct dyn_array *da = *daa; | ||
19 | |||
20 | size = da->size * (*da->nr); | ||
21 | print_fn_descriptor_symbol("dyn_array %s ", da->name); | ||
22 | printk(KERN_CONT "size:%#lx nr:%d align:%#lx\n", | ||
23 | da->size, *da->nr, da->align); | ||
24 | total_size += roundup(size, da->align); | ||
25 | if (da->align > max_align) | ||
26 | max_align = da->align; | ||
27 | } | ||
28 | if (total_size) | ||
29 | printk(KERN_DEBUG "dyn_array total_size: %#lx\n", | ||
30 | total_size); | ||
31 | else | ||
32 | return; | ||
33 | |||
34 | /* allocate them all together */ | ||
35 | max_align = max_t(unsigned long, max_align, PAGE_SIZE); | ||
36 | ptr = __alloc_bootmem_nopanic(total_size, max_align, 0); | ||
37 | if (!ptr) | ||
38 | panic("Can not alloc dyn_alloc\n"); | ||
39 | |||
40 | phys = virt_to_phys(ptr); | ||
41 | for (daa = __dyn_array_start ; daa < __dyn_array_end; daa++) { | ||
42 | struct dyn_array *da = *daa; | ||
43 | |||
44 | size = da->size * (*da->nr); | ||
45 | print_fn_descriptor_symbol("dyn_array %s ", da->name); | ||
46 | |||
47 | phys = roundup(phys, da->align); | ||
48 | *da->name = phys_to_virt(phys); | ||
49 | printk(KERN_CONT " ==> [%#lx - %#lx]\n", phys, phys + size); | ||
50 | |||
51 | phys += size; | ||
52 | |||
53 | if (da->init_work) | ||
54 | da->init_work(da); | ||
55 | } | ||
56 | #else | ||
57 | #ifdef CONFIF_GENERIC_HARDIRQS | ||
58 | unsigned int i; | ||
59 | |||
60 | for (i = 0; i < NR_IRQS; i++) | ||
61 | irq_desc[i].irq = i; | ||
62 | #endif | ||
63 | #endif | ||
64 | } | ||
65 | |||
66 | unsigned long __init per_cpu_dyn_array_size(unsigned long *align) | ||
67 | { | ||
68 | unsigned long total_size = 0; | ||
69 | #ifdef CONFIG_HAVE_DYN_ARRAY | ||
70 | unsigned long size; | ||
71 | struct dyn_array **daa; | ||
72 | unsigned max_align = 1; | ||
73 | |||
74 | for (daa = __per_cpu_dyn_array_start ; daa < __per_cpu_dyn_array_end; daa++) { | ||
75 | struct dyn_array *da = *daa; | ||
76 | |||
77 | size = da->size * (*da->nr); | ||
78 | print_fn_descriptor_symbol("per_cpu_dyn_array %s ", da->name); | ||
79 | printk(KERN_CONT "size:%#lx nr:%d align:%#lx\n", | ||
80 | da->size, *da->nr, da->align); | ||
81 | total_size += roundup(size, da->align); | ||
82 | if (da->align > max_align) | ||
83 | max_align = da->align; | ||
84 | } | ||
85 | if (total_size) { | ||
86 | printk(KERN_DEBUG "per_cpu_dyn_array total_size: %#lx\n", | ||
87 | total_size); | ||
88 | *align = max_align; | ||
89 | } | ||
90 | #endif | ||
91 | return total_size; | ||
92 | } | ||
93 | |||
94 | void __init per_cpu_alloc_dyn_array(int cpu, char *ptr) | ||
95 | { | ||
96 | #ifdef CONFIG_HAVE_DYN_ARRAY | ||
97 | unsigned long size, phys; | ||
98 | struct dyn_array **daa; | ||
99 | unsigned long addr; | ||
100 | void **array; | ||
101 | |||
102 | phys = virt_to_phys(ptr); | ||
103 | for (daa = __per_cpu_dyn_array_start ; daa < __per_cpu_dyn_array_end; daa++) { | ||
104 | struct dyn_array *da = *daa; | ||
105 | |||
106 | size = da->size * (*da->nr); | ||
107 | print_fn_descriptor_symbol("per_cpu_dyn_array %s ", da->name); | ||
108 | |||
109 | phys = roundup(phys, da->align); | ||
110 | addr = (unsigned long)da->name; | ||
111 | addr += per_cpu_offset(cpu); | ||
112 | array = (void **)addr; | ||
113 | *array = phys_to_virt(phys); | ||
114 | *da->name = *array; /* so init_work could use it directly */ | ||
115 | printk(KERN_CONT " ==> [%#lx - %#lx]\n", phys, phys + size); | ||
116 | |||
117 | phys += size; | ||
118 | |||
119 | if (da->init_work) { | ||
120 | da->init_work(da); | ||
121 | } | ||
122 | } | ||
123 | #endif | ||
124 | } | ||