Commit | Line | Data |
---|---|---|
5f97f7f9 HS |
1 | /* |
2 | * Copyright (C) 2004-2006 Atmel Corporation | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License version 2 as | |
6 | * published by the Free Software Foundation. | |
7 | */ | |
8 | ||
9 | #include <linux/kernel.h> | |
10 | #include <linux/mm.h> | |
11 | #include <linux/swap.h> | |
12 | #include <linux/init.h> | |
5f97f7f9 | 13 | #include <linux/mmzone.h> |
8bd8974f | 14 | #include <linux/module.h> |
5f97f7f9 HS |
15 | #include <linux/bootmem.h> |
16 | #include <linux/pagemap.h> | |
5f97f7f9 HS |
17 | #include <linux/nodemask.h> |
18 | ||
19 | #include <asm/page.h> | |
20 | #include <asm/mmu_context.h> | |
21 | #include <asm/tlb.h> | |
22 | #include <asm/io.h> | |
23 | #include <asm/dma.h> | |
24 | #include <asm/setup.h> | |
25 | #include <asm/sections.h> | |
26 | ||
cfd23e93 HS |
27 | #define __page_aligned __attribute__((section(".data.page_aligned"))) |
28 | ||
5f97f7f9 HS |
29 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
30 | ||
cfd23e93 | 31 | pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned; |
5f97f7f9 HS |
32 | |
33 | struct page *empty_zero_page; | |
8bd8974f | 34 | EXPORT_SYMBOL(empty_zero_page); |
5f97f7f9 HS |
35 | |
36 | /* | |
37 | * Cache of MMU context last used. | |
38 | */ | |
39 | unsigned long mmu_context_cache = NO_CONTEXT; | |
40 | ||
5f97f7f9 HS |
41 | /* |
42 | * paging_init() sets up the page tables | |
43 | * | |
44 | * This routine also unmaps the page at virtual kernel address 0, so | |
45 | * that we can trap those pesky NULL-reference errors in the kernel. | |
46 | */ | |
47 | void __init paging_init(void) | |
48 | { | |
49 | extern unsigned long _evba; | |
50 | void *zero_page; | |
51 | int nid; | |
52 | ||
53 | /* | |
54 | * Make sure we can handle exceptions before enabling | |
55 | * paging. Not that we should ever _get_ any exceptions this | |
56 | * early, but you never know... | |
57 | */ | |
58 | printk("Exception vectors start at %p\n", &_evba); | |
59 | sysreg_write(EVBA, (unsigned long)&_evba); | |
60 | ||
61 | /* | |
62 | * Since we are ready to handle exceptions now, we should let | |
63 | * the CPU generate them... | |
64 | */ | |
65 | __asm__ __volatile__ ("csrf %0" : : "i"(SR_EM_BIT)); | |
66 | ||
67 | /* | |
68 | * Allocate the zero page. The allocator will panic if it | |
69 | * can't satisfy the request, so no need to check. | |
70 | */ | |
71 | zero_page = alloc_bootmem_low_pages_node(NODE_DATA(0), | |
72 | PAGE_SIZE); | |
73 | ||
ebe74597 HS |
74 | sysreg_write(PTBR, (unsigned long)swapper_pg_dir); |
75 | enable_mmu(); | |
76 | printk ("CPU: Paging enabled\n"); | |
5f97f7f9 HS |
77 | |
78 | for_each_online_node(nid) { | |
79 | pg_data_t *pgdat = NODE_DATA(nid); | |
80 | unsigned long zones_size[MAX_NR_ZONES]; | |
81 | unsigned long low, start_pfn; | |
82 | ||
3560e249 | 83 | start_pfn = pgdat->bdata->node_min_pfn; |
5f97f7f9 HS |
84 | low = pgdat->bdata->node_low_pfn; |
85 | ||
86 | memset(zones_size, 0, sizeof(zones_size)); | |
87 | zones_size[ZONE_NORMAL] = low - start_pfn; | |
88 | ||
89 | printk("Node %u: start_pfn = 0x%lx, low = 0x%lx\n", | |
90 | nid, start_pfn, low); | |
91 | ||
9109fb7b | 92 | free_area_init_node(nid, zones_size, start_pfn, NULL); |
5f97f7f9 HS |
93 | |
94 | printk("Node %u: mem_map starts at %p\n", | |
95 | pgdat->node_id, pgdat->node_mem_map); | |
96 | } | |
97 | ||
98 | mem_map = NODE_DATA(0)->node_mem_map; | |
99 | ||
5f97f7f9 HS |
100 | empty_zero_page = virt_to_page(zero_page); |
101 | flush_dcache_page(empty_zero_page); | |
102 | } | |
103 | ||
104 | void __init mem_init(void) | |
105 | { | |
106 | int codesize, reservedpages, datasize, initsize; | |
107 | int nid, i; | |
108 | ||
109 | reservedpages = 0; | |
110 | high_memory = NULL; | |
111 | ||
112 | /* this will put all low memory onto the freelists */ | |
113 | for_each_online_node(nid) { | |
114 | pg_data_t *pgdat = NODE_DATA(nid); | |
115 | unsigned long node_pages = 0; | |
116 | void *node_high_memory; | |
117 | ||
118 | num_physpages += pgdat->node_present_pages; | |
119 | ||
120 | if (pgdat->node_spanned_pages != 0) | |
121 | node_pages = free_all_bootmem_node(pgdat); | |
122 | ||
123 | totalram_pages += node_pages; | |
124 | ||
125 | for (i = 0; i < node_pages; i++) | |
126 | if (PageReserved(pgdat->node_mem_map + i)) | |
127 | reservedpages++; | |
128 | ||
129 | node_high_memory = (void *)((pgdat->node_start_pfn | |
130 | + pgdat->node_spanned_pages) | |
131 | << PAGE_SHIFT); | |
132 | if (node_high_memory > high_memory) | |
133 | high_memory = node_high_memory; | |
134 | } | |
135 | ||
136 | max_mapnr = MAP_NR(high_memory); | |
137 | ||
138 | codesize = (unsigned long)_etext - (unsigned long)_text; | |
139 | datasize = (unsigned long)_edata - (unsigned long)_data; | |
140 | initsize = (unsigned long)__init_end - (unsigned long)__init_begin; | |
141 | ||
142 | printk ("Memory: %luk/%luk available (%dk kernel code, " | |
143 | "%dk reserved, %dk data, %dk init)\n", | |
144 | (unsigned long)nr_free_pages() << (PAGE_SHIFT - 10), | |
145 | totalram_pages << (PAGE_SHIFT - 10), | |
146 | codesize >> 10, | |
147 | reservedpages << (PAGE_SHIFT - 10), | |
148 | datasize >> 10, | |
149 | initsize >> 10); | |
150 | } | |
151 | ||
152 | static inline void free_area(unsigned long addr, unsigned long end, char *s) | |
153 | { | |
154 | unsigned int size = (end - addr) >> 10; | |
155 | ||
156 | for (; addr < end; addr += PAGE_SIZE) { | |
157 | struct page *page = virt_to_page(addr); | |
158 | ClearPageReserved(page); | |
159 | init_page_count(page); | |
160 | free_page(addr); | |
161 | totalram_pages++; | |
162 | } | |
163 | ||
164 | if (size && s) | |
165 | printk(KERN_INFO "Freeing %s memory: %dK (%lx - %lx)\n", | |
166 | s, size, end - (size << 10), end); | |
167 | } | |
168 | ||
169 | void free_initmem(void) | |
170 | { | |
171 | free_area((unsigned long)__init_begin, (unsigned long)__init_end, | |
172 | "init"); | |
173 | } | |
174 | ||
175 | #ifdef CONFIG_BLK_DEV_INITRD | |
176 | ||
5f97f7f9 HS |
177 | void free_initrd_mem(unsigned long start, unsigned long end) |
178 | { | |
193fdd1a | 179 | free_area(start, end, "initrd"); |
5f97f7f9 HS |
180 | } |
181 | ||
5f97f7f9 | 182 | #endif |