blob: 1daf97fd7c992a95981c01674ea9b94012fc609c [file] [log] [blame]
David Howellsb920de12008-02-08 04:19:31 -08001/* MN10300 Memory management initialisation
2 *
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Modified by David Howells (dhowells@redhat.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
11 */
12#include <linux/signal.h>
13#include <linux/sched.h>
14#include <linux/kernel.h>
15#include <linux/errno.h>
16#include <linux/string.h>
17#include <linux/types.h>
18#include <linux/ptrace.h>
19#include <linux/mman.h>
David Howellsb920de12008-02-08 04:19:31 -080020#include <linux/fs.h>
21#include <linux/mm.h>
22#include <linux/swap.h>
23#include <linux/smp.h>
24#include <linux/init.h>
25#include <linux/initrd.h>
26#include <linux/highmem.h>
27#include <linux/pagemap.h>
28#include <linux/bootmem.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/gfp.h>
David Howellsb920de12008-02-08 04:19:31 -080030
31#include <asm/processor.h>
32#include <asm/system.h>
33#include <asm/uaccess.h>
34#include <asm/pgtable.h>
35#include <asm/pgalloc.h>
36#include <asm/dma.h>
37#include <asm/tlb.h>
38#include <asm/sections.h>
39
40DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
41
42unsigned long highstart_pfn, highend_pfn;
43
44/*
45 * set up paging
46 */
47void __init paging_init(void)
48{
49 unsigned long zones_size[MAX_NR_ZONES] = {0,};
50 pte_t *ppte;
51 int loop;
52
53 /* main kernel space -> RAM mapping is handled as 1:1 transparent by
54 * the MMU */
55 memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
56 memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes));
57
58 /* load the VMALLOC area PTE table addresses into the kernel PGD */
59 ppte = kernel_vmalloc_ptes;
60 for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE);
61 loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE);
62 loop++
63 ) {
64 set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE));
65 ppte += PAGE_SIZE / sizeof(pte_t);
66 }
67
68 /* declare the sizes of the RAM zones (only use the normal zone) */
69 zones_size[ZONE_NORMAL] =
Johannes Weiner3560e242008-07-23 21:28:09 -070070 contig_page_data.bdata->node_low_pfn -
71 contig_page_data.bdata->node_min_pfn;
David Howellsb920de12008-02-08 04:19:31 -080072
73 /* pass the memory from the bootmem allocator to the main allocator */
74 free_area_init(zones_size);
75
David Howells492e6752010-10-27 17:28:49 +010076 local_flush_tlb_all();
David Howellsb920de12008-02-08 04:19:31 -080077}
78
79/*
80 * transfer all the memory from the bootmem allocator to the runtime allocator
81 */
82void __init mem_init(void)
83{
84 int codesize, reservedpages, datasize, initsize;
85 int tmp;
86
Stoyan Gaydarov292aa142010-10-27 17:28:33 +010087 BUG_ON(!mem_map);
David Howellsb920de12008-02-08 04:19:31 -080088
Johannes Weiner3560e242008-07-23 21:28:09 -070089#define START_PFN (contig_page_data.bdata->node_min_pfn)
David Howellsb920de12008-02-08 04:19:31 -080090#define MAX_LOW_PFN (contig_page_data.bdata->node_low_pfn)
91
92 max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
93 high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE);
94
95 /* clear the zero-page */
96 memset(empty_zero_page, 0, PAGE_SIZE);
97
98 /* this will put all low memory onto the freelists */
99 totalram_pages += free_all_bootmem();
100
101 reservedpages = 0;
102 for (tmp = 0; tmp < num_physpages; tmp++)
103 if (PageReserved(&mem_map[tmp]))
104 reservedpages++;
105
106 codesize = (unsigned long) &_etext - (unsigned long) &_stext;
107 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
108 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
109
110 printk(KERN_INFO
111 "Memory: %luk/%luk available"
112 " (%dk kernel code, %dk reserved, %dk data, %dk init,"
113 " %ldk highmem)\n",
Geert Uytterhoevencc013a82009-09-21 17:02:36 -0700114 nr_free_pages() << (PAGE_SHIFT - 10),
David Howellsb920de12008-02-08 04:19:31 -0800115 max_mapnr << (PAGE_SHIFT - 10),
116 codesize >> 10,
117 reservedpages << (PAGE_SHIFT - 10),
118 datasize >> 10,
119 initsize >> 10,
Andreas Fenkart4b529402010-01-08 14:42:31 -0800120 totalhigh_pages << (PAGE_SHIFT - 10));
David Howellsb920de12008-02-08 04:19:31 -0800121}
122
123/*
124 *
125 */
126void free_init_pages(char *what, unsigned long begin, unsigned long end)
127{
128 unsigned long addr;
129
130 for (addr = begin; addr < end; addr += PAGE_SIZE) {
131 ClearPageReserved(virt_to_page(addr));
132 init_page_count(virt_to_page(addr));
133 memset((void *) addr, 0xcc, PAGE_SIZE);
134 free_page(addr);
135 totalram_pages++;
136 }
137 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
138}
139
140/*
141 * recycle memory containing stuff only required for initialisation
142 */
143void free_initmem(void)
144{
145 free_init_pages("unused kernel memory",
146 (unsigned long) &__init_begin,
147 (unsigned long) &__init_end);
148}
149
150/*
151 * dispose of the memory on which the initial ramdisk resided
152 */
153#ifdef CONFIG_BLK_DEV_INITRD
154void free_initrd_mem(unsigned long start, unsigned long end)
155{
156 free_init_pages("initrd memory", start, end);
157}
158#endif