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 | |
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>
-rw-r--r-- | init/Makefile | 2 | ||||
-rw-r--r-- | init/dyn_array.c | 124 | ||||
-rw-r--r-- | init/main.c | 118 |
3 files changed, 125 insertions, 119 deletions
diff --git a/init/Makefile b/init/Makefile index 4a243df426f7..dc5eeca6eb6d 100644 --- a/init/Makefile +++ b/init/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for the linux kernel. | 2 | # Makefile for the linux kernel. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y := main.o version.o mounts.o | 5 | obj-y := main.o dyn_array.o version.o mounts.o |
6 | ifneq ($(CONFIG_BLK_DEV_INITRD),y) | 6 | ifneq ($(CONFIG_BLK_DEV_INITRD),y) |
7 | obj-y += noinitramfs.o | 7 | obj-y += noinitramfs.o |
8 | else | 8 | else |
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 | } | ||
diff --git a/init/main.c b/init/main.c index 0d2e60144f83..e81cf427d9c7 100644 --- a/init/main.c +++ b/init/main.c | |||
@@ -542,124 +542,6 @@ void __init __weak thread_info_cache_init(void) | |||
542 | { | 542 | { |
543 | } | 543 | } |
544 | 544 | ||
545 | void pre_alloc_dyn_array(void) | ||
546 | { | ||
547 | #ifdef CONFIG_HAVE_DYN_ARRAY | ||
548 | unsigned long total_size = 0, size, phys; | ||
549 | unsigned long max_align = 1; | ||
550 | struct dyn_array **daa; | ||
551 | char *ptr; | ||
552 | |||
553 | /* get the total size at first */ | ||
554 | for (daa = __dyn_array_start ; daa < __dyn_array_end; daa++) { | ||
555 | struct dyn_array *da = *daa; | ||
556 | |||
557 | size = da->size * (*da->nr); | ||
558 | print_fn_descriptor_symbol("dyn_array %s ", da->name); | ||
559 | printk(KERN_CONT "size:%#lx nr:%d align:%#lx\n", | ||
560 | da->size, *da->nr, da->align); | ||
561 | total_size += roundup(size, da->align); | ||
562 | if (da->align > max_align) | ||
563 | max_align = da->align; | ||
564 | } | ||
565 | if (total_size) | ||
566 | printk(KERN_DEBUG "dyn_array total_size: %#lx\n", | ||
567 | total_size); | ||
568 | else | ||
569 | return; | ||
570 | |||
571 | /* allocate them all together */ | ||
572 | max_align = max_t(unsigned long, max_align, PAGE_SIZE); | ||
573 | ptr = __alloc_bootmem_nopanic(total_size, max_align, 0); | ||
574 | if (!ptr) | ||
575 | panic("Can not alloc dyn_alloc\n"); | ||
576 | |||
577 | phys = virt_to_phys(ptr); | ||
578 | for (daa = __dyn_array_start ; daa < __dyn_array_end; daa++) { | ||
579 | struct dyn_array *da = *daa; | ||
580 | |||
581 | size = da->size * (*da->nr); | ||
582 | print_fn_descriptor_symbol("dyn_array %s ", da->name); | ||
583 | |||
584 | phys = roundup(phys, da->align); | ||
585 | *da->name = phys_to_virt(phys); | ||
586 | printk(KERN_CONT " ==> [%#lx - %#lx]\n", phys, phys + size); | ||
587 | |||
588 | phys += size; | ||
589 | |||
590 | if (da->init_work) | ||
591 | da->init_work(da); | ||
592 | } | ||
593 | #else | ||
594 | #ifdef CONFIF_GENERIC_HARDIRQS | ||
595 | unsigned int i; | ||
596 | |||
597 | for (i = 0; i < NR_IRQS; i++) | ||
598 | irq_desc[i].irq = i; | ||
599 | #endif | ||
600 | #endif | ||
601 | } | ||
602 | |||
603 | unsigned long per_cpu_dyn_array_size(unsigned long *align) | ||
604 | { | ||
605 | unsigned long total_size = 0; | ||
606 | #ifdef CONFIG_HAVE_DYN_ARRAY | ||
607 | unsigned long size; | ||
608 | struct dyn_array **daa; | ||
609 | unsigned max_align = 1; | ||
610 | |||
611 | for (daa = __per_cpu_dyn_array_start ; daa < __per_cpu_dyn_array_end; daa++) { | ||
612 | struct dyn_array *da = *daa; | ||
613 | |||
614 | size = da->size * (*da->nr); | ||
615 | print_fn_descriptor_symbol("per_cpu_dyn_array %s ", da->name); | ||
616 | printk(KERN_CONT "size:%#lx nr:%d align:%#lx\n", | ||
617 | da->size, *da->nr, da->align); | ||
618 | total_size += roundup(size, da->align); | ||
619 | if (da->align > max_align) | ||
620 | max_align = da->align; | ||
621 | } | ||
622 | if (total_size) { | ||
623 | printk(KERN_DEBUG "per_cpu_dyn_array total_size: %#lx\n", | ||
624 | total_size); | ||
625 | *align = max_align; | ||
626 | } | ||
627 | #endif | ||
628 | return total_size; | ||
629 | } | ||
630 | |||
631 | void per_cpu_alloc_dyn_array(int cpu, char *ptr) | ||
632 | { | ||
633 | #ifdef CONFIG_HAVE_DYN_ARRAY | ||
634 | unsigned long size, phys; | ||
635 | struct dyn_array **daa; | ||
636 | unsigned long addr; | ||
637 | void **array; | ||
638 | |||
639 | phys = virt_to_phys(ptr); | ||
640 | for (daa = __per_cpu_dyn_array_start ; daa < __per_cpu_dyn_array_end; daa++) { | ||
641 | struct dyn_array *da = *daa; | ||
642 | |||
643 | size = da->size * (*da->nr); | ||
644 | print_fn_descriptor_symbol("per_cpu_dyn_array %s ", da->name); | ||
645 | |||
646 | phys = roundup(phys, da->align); | ||
647 | addr = (unsigned long)da->name; | ||
648 | addr += per_cpu_offset(cpu); | ||
649 | array = (void **)addr; | ||
650 | *array = phys_to_virt(phys); | ||
651 | *da->name = *array; /* so init_work could use it directly */ | ||
652 | printk(KERN_CONT " ==> [%#lx - %#lx]\n", phys, phys + size); | ||
653 | |||
654 | phys += size; | ||
655 | |||
656 | if (da->init_work) { | ||
657 | da->init_work(da); | ||
658 | } | ||
659 | } | ||
660 | #endif | ||
661 | } | ||
662 | |||
663 | asmlinkage void __init start_kernel(void) | 545 | asmlinkage void __init start_kernel(void) |
664 | { | 546 | { |
665 | char * command_line; | 547 | char * command_line; |