Commit | Line | Data |
---|---|---|
6bc9a396 CL |
1 | /* |
2 | * arch/score/mm/init.c | |
3 | * | |
4 | * Score Processor version. | |
5 | * | |
6 | * Copyright (C) 2009 Sunplus Core Technology Co., Ltd. | |
7 | * Lennox Wu <lennox.wu@sunplusct.com> | |
8 | * Chen Liqin <liqin.chen@sunplusct.com> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, see the file COPYING, or write | |
22 | * to the Free Software Foundation, Inc., | |
23 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
24 | */ | |
25 | ||
26 | #include <linux/errno.h> | |
27 | #include <linux/bootmem.h> | |
28 | #include <linux/kernel.h> | |
29 | #include <linux/init.h> | |
30 | #include <linux/mm.h> | |
31 | #include <linux/mman.h> | |
32 | #include <linux/pagemap.h> | |
33 | #include <linux/proc_fs.h> | |
34 | #include <linux/sched.h> | |
35 | #include <asm-generic/sections.h> | |
36 | ||
37 | #include <asm/tlb.h> | |
38 | ||
39 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); | |
40 | ||
41 | /* | |
42 | * We have up to 8 empty zeroed pages so we can map one of the right colour | |
43 | * when needed. | |
44 | */ | |
45 | unsigned long zero_page_mask; | |
46 | unsigned long empty_zero_page; | |
47 | EXPORT_SYMBOL_GPL(empty_zero_page); | |
48 | ||
49 | static struct kcore_list kcore_mem, kcore_vmalloc; | |
50 | ||
51 | unsigned long setup_zero_pages(void) | |
52 | { | |
53 | unsigned int order = 0; | |
54 | unsigned long size; | |
55 | struct page *page; | |
56 | ||
57 | empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order); | |
58 | if (!empty_zero_page) | |
59 | panic("Oh boy, that early out of memory?"); | |
60 | ||
61 | page = virt_to_page((void *) empty_zero_page); | |
62 | split_page(page, order); | |
63 | while (page < virt_to_page((void *) (empty_zero_page + | |
64 | (PAGE_SIZE << order)))) { | |
65 | SetPageReserved(page); | |
66 | page++; | |
67 | } | |
68 | ||
69 | size = PAGE_SIZE << order; | |
70 | zero_page_mask = (size - 1) & PAGE_MASK; | |
71 | ||
72 | return 1UL << order; | |
73 | } | |
74 | ||
75 | #ifndef CONFIG_NEED_MULTIPLE_NODES | |
76 | static int __init page_is_ram(unsigned long pagenr) | |
77 | { | |
78 | if (pagenr >= min_low_pfn && pagenr < max_low_pfn) | |
79 | return 1; | |
80 | else | |
81 | return 0; | |
82 | } | |
83 | ||
84 | void __init paging_init(void) | |
85 | { | |
86 | unsigned long max_zone_pfns[MAX_NR_ZONES]; | |
87 | unsigned long lastpfn; | |
88 | ||
89 | pagetable_init(); | |
90 | max_zone_pfns[ZONE_NORMAL] = max_low_pfn; | |
91 | lastpfn = max_low_pfn; | |
92 | free_area_init_nodes(max_zone_pfns); | |
93 | } | |
94 | ||
95 | void __init mem_init(void) | |
96 | { | |
97 | unsigned long codesize, reservedpages, datasize, initsize; | |
98 | unsigned long tmp, ram = 0; | |
99 | ||
100 | max_mapnr = max_low_pfn; | |
101 | high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT); | |
102 | totalram_pages += free_all_bootmem(); | |
103 | totalram_pages -= setup_zero_pages(); /* Setup zeroed pages. */ | |
104 | reservedpages = 0; | |
105 | ||
106 | for (tmp = 0; tmp < max_low_pfn; tmp++) | |
107 | if (page_is_ram(tmp)) { | |
108 | ram++; | |
109 | if (PageReserved(pfn_to_page(tmp))) | |
110 | reservedpages++; | |
111 | } | |
112 | ||
113 | num_physpages = ram; | |
114 | codesize = (unsigned long) &_etext - (unsigned long) &_text; | |
115 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; | |
116 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; | |
117 | ||
118 | kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT); | |
119 | kclist_add(&kcore_vmalloc, (void *) VMALLOC_START, | |
120 | VMALLOC_END - VMALLOC_START); | |
121 | ||
122 | printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, " | |
123 | "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n", | |
124 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), | |
125 | ram << (PAGE_SHIFT-10), codesize >> 10, | |
126 | reservedpages << (PAGE_SHIFT-10), datasize >> 10, | |
127 | initsize >> 10, | |
128 | (unsigned long) (totalhigh_pages << (PAGE_SHIFT-10))); | |
129 | } | |
130 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ | |
131 | ||
132 | void free_init_pages(const char *what, unsigned long begin, unsigned long end) | |
133 | { | |
134 | unsigned long pfn; | |
135 | ||
136 | for (pfn = PFN_UP(begin); pfn < PFN_DOWN(end); pfn++) { | |
137 | struct page *page = pfn_to_page(pfn); | |
138 | void *addr = phys_to_virt(PFN_PHYS(pfn)); | |
139 | ||
140 | ClearPageReserved(page); | |
141 | init_page_count(page); | |
142 | memset(addr, POISON_FREE_INITMEM, PAGE_SIZE); | |
143 | __free_page(page); | |
144 | totalram_pages++; | |
145 | } | |
146 | printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); | |
147 | } | |
148 | ||
149 | #ifdef CONFIG_BLK_DEV_INITRD | |
150 | void free_initrd_mem(unsigned long start, unsigned long end) | |
151 | { | |
152 | free_init_pages("initrd memory", | |
153 | virt_to_phys((void *) start), | |
154 | virt_to_phys((void *) end)); | |
155 | } | |
156 | #endif | |
157 | ||
158 | void __init_refok free_initmem(void) | |
159 | { | |
160 | free_init_pages("unused kernel memory", | |
161 | (unsigned long)__init_begin, (unsigned long)__init_end); | |
162 | } | |
163 | ||
164 | unsigned long pgd_current; | |
165 | ||
166 | #define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order))) | |
167 | ||
168 | /* | |
169 | * gcc 3.3 and older have trouble determining that PTRS_PER_PGD and PGD_ORDER | |
170 | * are constants. So we use the variants from asm-offset.h until that gcc | |
171 | * will officially be retired. | |
172 | */ | |
173 | pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER); |