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> | |
fbd85b0e | 35 | #include <linux/initrd.h> |
6bc9a396 | 36 | |
fbd85b0e | 37 | #include <asm/sections.h> |
6bc9a396 CL |
38 | #include <asm/tlb.h> |
39 | ||
40 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); | |
41 | ||
6bc9a396 CL |
42 | unsigned long empty_zero_page; |
43 | EXPORT_SYMBOL_GPL(empty_zero_page); | |
44 | ||
45 | static struct kcore_list kcore_mem, kcore_vmalloc; | |
46 | ||
fbd85b0e | 47 | static unsigned long setup_zero_page(void) |
6bc9a396 | 48 | { |
6bc9a396 CL |
49 | struct page *page; |
50 | ||
fbd85b0e | 51 | empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, 0); |
6bc9a396 CL |
52 | if (!empty_zero_page) |
53 | panic("Oh boy, that early out of memory?"); | |
54 | ||
55 | page = virt_to_page((void *) empty_zero_page); | |
fbd85b0e | 56 | SetPageReserved(page); |
6bc9a396 | 57 | |
fbd85b0e | 58 | return 1UL; |
6bc9a396 CL |
59 | } |
60 | ||
61 | #ifndef CONFIG_NEED_MULTIPLE_NODES | |
62 | static int __init page_is_ram(unsigned long pagenr) | |
63 | { | |
64 | if (pagenr >= min_low_pfn && pagenr < max_low_pfn) | |
65 | return 1; | |
66 | else | |
67 | return 0; | |
68 | } | |
69 | ||
70 | void __init paging_init(void) | |
71 | { | |
72 | unsigned long max_zone_pfns[MAX_NR_ZONES]; | |
73 | unsigned long lastpfn; | |
74 | ||
75 | pagetable_init(); | |
76 | max_zone_pfns[ZONE_NORMAL] = max_low_pfn; | |
77 | lastpfn = max_low_pfn; | |
78 | free_area_init_nodes(max_zone_pfns); | |
79 | } | |
80 | ||
81 | void __init mem_init(void) | |
82 | { | |
83 | unsigned long codesize, reservedpages, datasize, initsize; | |
84 | unsigned long tmp, ram = 0; | |
85 | ||
6bc9a396 CL |
86 | high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT); |
87 | totalram_pages += free_all_bootmem(); | |
fbd85b0e | 88 | totalram_pages -= setup_zero_page(); /* Setup zeroed pages. */ |
6bc9a396 CL |
89 | reservedpages = 0; |
90 | ||
91 | for (tmp = 0; tmp < max_low_pfn; tmp++) | |
92 | if (page_is_ram(tmp)) { | |
93 | ram++; | |
94 | if (PageReserved(pfn_to_page(tmp))) | |
95 | reservedpages++; | |
96 | } | |
97 | ||
98 | num_physpages = ram; | |
99 | codesize = (unsigned long) &_etext - (unsigned long) &_text; | |
100 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; | |
101 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; | |
102 | ||
6bc9a396 CL |
103 | printk(KERN_INFO "Memory: %luk/%luk available (%ldk kernel code, " |
104 | "%ldk reserved, %ldk data, %ldk init, %ldk highmem)\n", | |
105 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), | |
106 | ram << (PAGE_SHIFT-10), codesize >> 10, | |
107 | reservedpages << (PAGE_SHIFT-10), datasize >> 10, | |
108 | initsize >> 10, | |
4b529401 | 109 | totalhigh_pages << (PAGE_SHIFT-10)); |
6bc9a396 CL |
110 | } |
111 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ | |
112 | ||
fbd85b0e | 113 | static void free_init_pages(const char *what, unsigned long begin, unsigned long end) |
6bc9a396 CL |
114 | { |
115 | unsigned long pfn; | |
116 | ||
117 | for (pfn = PFN_UP(begin); pfn < PFN_DOWN(end); pfn++) { | |
118 | struct page *page = pfn_to_page(pfn); | |
119 | void *addr = phys_to_virt(PFN_PHYS(pfn)); | |
120 | ||
121 | ClearPageReserved(page); | |
122 | init_page_count(page); | |
123 | memset(addr, POISON_FREE_INITMEM, PAGE_SIZE); | |
124 | __free_page(page); | |
125 | totalram_pages++; | |
126 | } | |
127 | printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); | |
128 | } | |
129 | ||
130 | #ifdef CONFIG_BLK_DEV_INITRD | |
131 | void free_initrd_mem(unsigned long start, unsigned long end) | |
132 | { | |
133 | free_init_pages("initrd memory", | |
fbd85b0e AB |
134 | virt_to_phys((void *) start), |
135 | virt_to_phys((void *) end)); | |
6bc9a396 CL |
136 | } |
137 | #endif | |
138 | ||
139 | void __init_refok free_initmem(void) | |
140 | { | |
141 | free_init_pages("unused kernel memory", | |
d8aa899b CL |
142 | __pa(&__init_begin), |
143 | __pa(&__init_end)); | |
6bc9a396 CL |
144 | } |
145 | ||
146 | unsigned long pgd_current; | |
147 | ||
148 | #define __page_aligned(order) __attribute__((__aligned__(PAGE_SIZE<<order))) | |
149 | ||
150 | /* | |
151 | * gcc 3.3 and older have trouble determining that PTRS_PER_PGD and PGD_ORDER | |
152 | * are constants. So we use the variants from asm-offset.h until that gcc | |
153 | * will officially be retired. | |
154 | */ | |
d8aa899b | 155 | pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PTE_ORDER); |
6bc9a396 | 156 | pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER); |