Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / xtensa / mm / init.c
blob31b2ff2baef767970685dc871075854519787b95
1 /*
2 * arch/xtensa/mm/init.c
4 * Derived from MIPS, PPC.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
10 * Copyright (C) 2001 - 2005 Tensilica Inc.
12 * Chris Zankel <chris@zankel.net>
13 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
14 * Marc Gauthier
15 * Kevin Chea
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/bootmem.h>
21 #include <linux/swap.h>
22 #include <linux/mman.h>
23 #include <linux/nodemask.h>
24 #include <linux/mm.h>
25 #include <linux/slab.h>
27 #include <asm/pgtable.h>
28 #include <asm/bootparam.h>
29 #include <asm/mmu_context.h>
30 #include <asm/tlb.h>
31 #include <asm/page.h>
32 #include <asm/pgalloc.h>
35 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
37 /* References to section boundaries */
39 extern char _ftext, _etext, _fdata, _edata, _rodata_end;
40 extern char __init_begin, __init_end;
43 * mem_reserve(start, end, must_exist)
45 * Reserve some memory from the memory pool.
47 * Parameters:
48 * start Start of region,
49 * end End of region,
50 * must_exist Must exist in memory pool.
52 * Returns:
53 * 0 (memory area couldn't be mapped)
54 * -1 (success)
57 int __init mem_reserve(unsigned long start, unsigned long end, int must_exist)
59 int i;
61 if (start == end)
62 return 0;
64 start = start & PAGE_MASK;
65 end = PAGE_ALIGN(end);
67 for (i = 0; i < sysmem.nr_banks; i++)
68 if (start < sysmem.bank[i].end
69 && end >= sysmem.bank[i].start)
70 break;
72 if (i == sysmem.nr_banks) {
73 if (must_exist)
74 printk (KERN_WARNING "mem_reserve: [0x%0lx, 0x%0lx) "
75 "not in any region!\n", start, end);
76 return 0;
79 if (start > sysmem.bank[i].start) {
80 if (end < sysmem.bank[i].end) {
81 /* split entry */
82 if (sysmem.nr_banks >= SYSMEM_BANKS_MAX)
83 panic("meminfo overflow\n");
84 sysmem.bank[sysmem.nr_banks].start = end;
85 sysmem.bank[sysmem.nr_banks].end = sysmem.bank[i].end;
86 sysmem.nr_banks++;
88 sysmem.bank[i].end = start;
89 } else {
90 if (end < sysmem.bank[i].end)
91 sysmem.bank[i].start = end;
92 else {
93 /* remove entry */
94 sysmem.nr_banks--;
95 sysmem.bank[i].start = sysmem.bank[sysmem.nr_banks].start;
96 sysmem.bank[i].end = sysmem.bank[sysmem.nr_banks].end;
99 return -1;
104 * Initialize the bootmem system and give it all the memory we have available.
107 void __init bootmem_init(void)
109 unsigned long pfn;
110 unsigned long bootmap_start, bootmap_size;
111 int i;
113 max_low_pfn = max_pfn = 0;
114 min_low_pfn = ~0;
116 for (i=0; i < sysmem.nr_banks; i++) {
117 pfn = PAGE_ALIGN(sysmem.bank[i].start) >> PAGE_SHIFT;
118 if (pfn < min_low_pfn)
119 min_low_pfn = pfn;
120 pfn = PAGE_ALIGN(sysmem.bank[i].end - 1) >> PAGE_SHIFT;
121 if (pfn > max_pfn)
122 max_pfn = pfn;
125 if (min_low_pfn > max_pfn)
126 panic("No memory found!\n");
128 max_low_pfn = max_pfn < MAX_MEM_PFN >> PAGE_SHIFT ?
129 max_pfn : MAX_MEM_PFN >> PAGE_SHIFT;
131 /* Find an area to use for the bootmem bitmap. */
133 bootmap_size = bootmem_bootmap_pages(max_low_pfn) << PAGE_SHIFT;
134 bootmap_start = ~0;
136 for (i=0; i<sysmem.nr_banks; i++)
137 if (sysmem.bank[i].end - sysmem.bank[i].start >= bootmap_size) {
138 bootmap_start = sysmem.bank[i].start;
139 break;
142 if (bootmap_start == ~0UL)
143 panic("Cannot find %ld bytes for bootmap\n", bootmap_size);
145 /* Reserve the bootmem bitmap area */
147 mem_reserve(bootmap_start, bootmap_start + bootmap_size, 1);
148 bootmap_size = init_bootmem_node(NODE_DATA(0), min_low_pfn,
149 bootmap_start >> PAGE_SHIFT,
150 max_low_pfn);
152 /* Add all remaining memory pieces into the bootmem map */
154 for (i=0; i<sysmem.nr_banks; i++)
155 free_bootmem(sysmem.bank[i].start,
156 sysmem.bank[i].end - sysmem.bank[i].start);
161 void __init paging_init(void)
163 unsigned long zones_size[MAX_NR_ZONES];
164 int i;
166 /* All pages are DMA-able, so we put them all in the DMA zone. */
168 zones_size[ZONE_DMA] = max_low_pfn;
169 for (i = 1; i < MAX_NR_ZONES; i++)
170 zones_size[i] = 0;
172 #ifdef CONFIG_HIGHMEM
173 zones_size[ZONE_HIGHMEM] = max_pfn - max_low_pfn;
174 #endif
176 /* Initialize the kernel's page tables. */
178 memset(swapper_pg_dir, 0, PAGE_SIZE);
180 free_area_init(zones_size);
184 * Flush the mmu and reset associated register to default values.
187 void __init init_mmu (void)
189 /* Writing zeros to the <t>TLBCFG special registers ensure
190 * that valid values exist in the register. For existing
191 * PGSZID<w> fields, zero selects the first element of the
192 * page-size array. For nonexistent PGSZID<w> fields, zero is
193 * the best value to write. Also, when changing PGSZID<w>
194 * fields, the corresponding TLB must be flushed.
196 set_itlbcfg_register (0);
197 set_dtlbcfg_register (0);
198 flush_tlb_all ();
200 /* Set rasid register to a known value. */
202 set_rasid_register (ASID_USER_FIRST);
204 /* Set PTEVADDR special register to the start of the page
205 * table, which is in kernel mappable space (ie. not
206 * statically mapped). This register's value is undefined on
207 * reset.
209 set_ptevaddr_register (PGTABLE_START);
213 * Initialize memory pages.
216 void __init mem_init(void)
218 unsigned long codesize, reservedpages, datasize, initsize;
219 unsigned long highmemsize, tmp, ram;
221 max_mapnr = num_physpages = max_low_pfn;
222 high_memory = (void *) __va(max_mapnr << PAGE_SHIFT);
223 highmemsize = 0;
225 #ifdef CONFIG_HIGHMEM
226 #error HIGHGMEM not implemented in init.c
227 #endif
229 totalram_pages += free_all_bootmem();
231 reservedpages = ram = 0;
232 for (tmp = 0; tmp < max_low_pfn; tmp++) {
233 ram++;
234 if (PageReserved(mem_map+tmp))
235 reservedpages++;
238 codesize = (unsigned long) &_etext - (unsigned long) &_ftext;
239 datasize = (unsigned long) &_edata - (unsigned long) &_fdata;
240 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
242 printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, "
243 "%ldk data, %ldk init %ldk highmem)\n",
244 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
245 ram << (PAGE_SHIFT-10),
246 codesize >> 10,
247 reservedpages << (PAGE_SHIFT-10),
248 datasize >> 10,
249 initsize >> 10,
250 highmemsize >> 10);
253 void
254 free_reserved_mem(void *start, void *end)
256 for (; start < end; start += PAGE_SIZE) {
257 ClearPageReserved(virt_to_page(start));
258 init_page_count(virt_to_page(start));
259 free_page((unsigned long)start);
260 totalram_pages++;
264 #ifdef CONFIG_BLK_DEV_INITRD
265 extern int initrd_is_mapped;
267 void free_initrd_mem(unsigned long start, unsigned long end)
269 if (initrd_is_mapped) {
270 free_reserved_mem((void*)start, (void*)end);
271 printk ("Freeing initrd memory: %ldk freed\n",(end-start)>>10);
274 #endif
276 void free_initmem(void)
278 free_reserved_mem(&__init_begin, &__init_end);
279 printk("Freeing unused kernel memory: %dk freed\n",
280 (&__init_end - &__init_begin) >> 10);
283 void show_mem(void)
285 int i, free = 0, total = 0, reserved = 0;
286 int shared = 0, cached = 0;
288 printk("Mem-info:\n");
289 show_free_areas();
290 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
291 i = max_mapnr;
292 while (i-- > 0) {
293 total++;
294 if (PageReserved(mem_map+i))
295 reserved++;
296 else if (PageSwapCache(mem_map+i))
297 cached++;
298 else if (!page_count(mem_map + i))
299 free++;
300 else
301 shared += page_count(mem_map + i) - 1;
303 printk("%d pages of RAM\n", total);
304 printk("%d reserved pages\n", reserved);
305 printk("%d pages shared\n", shared);
306 printk("%d pages swap cached\n",cached);
307 printk("%d free pages\n", free);
310 struct kmem_cache *pgtable_cache __read_mostly;
312 <<<<<<< HEAD:arch/xtensa/mm/init.c
313 static void pgd_ctor(void *addr, struct kmem_cache *cache, unsigned long flags)
314 =======
315 static void pgd_ctor(struct kmem_cache *cache, void* addr)
316 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/xtensa/mm/init.c
318 pte_t* ptep = (pte_t*)addr;
319 int i;
321 for (i = 0; i < 1024; i++, ptep++)
322 pte_clear(NULL, 0, ptep);
326 void __init pgtable_cache_init(void)
328 pgtable_cache = kmem_cache_create("pgd",
329 PAGE_SIZE, PAGE_SIZE,
330 SLAB_HWCACHE_ALIGN,
331 pgd_ctor);