blob: 73e2205ebf5afba2c17ca848701c0ae026f52fab [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m32r/mm/init.c
3 *
4 * Copyright (c) 2001, 2002 Hitoshi Yamamoto
5 *
6 * Some code taken from sh version.
7 * Copyright (C) 1999 Niibe Yutaka
8 * Based on linux/arch/i386/mm/init.c:
9 * Copyright (C) 1995 Linus Torvalds
10 */
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/mm.h>
15#include <linux/pagemap.h>
16#include <linux/bootmem.h>
17#include <linux/swap.h>
18#include <linux/highmem.h>
19#include <linux/bitops.h>
20#include <linux/nodemask.h>
Dave Hansen22a98352006-03-27 01:16:04 -080021#include <linux/pfn.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/types.h>
24#include <asm/processor.h>
25#include <asm/page.h>
26#include <asm/pgtable.h>
27#include <asm/pgalloc.h>
28#include <asm/mmu_context.h>
29#include <asm/setup.h>
30#include <asm/tlb.h>
31
32/* References to section boundaries */
33extern char _text, _etext, _edata;
34extern char __init_begin, __init_end;
35
36pgd_t swapper_pg_dir[1024];
37
38DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/*
41 * Cache of MMU context last used.
42 */
43#ifndef CONFIG_SMP
44unsigned long mmu_context_cache_dat;
45#else
46unsigned long mmu_context_cache_dat[NR_CPUS];
47#endif
48static unsigned long hole_pages;
49
50/*
51 * function prototype
52 */
53void __init paging_init(void);
54void __init mem_init(void);
55void free_initmem(void);
56#ifdef CONFIG_BLK_DEV_INITRD
57void free_initrd_mem(unsigned long, unsigned long);
58#endif
59
60/* It'd be good if these lines were in the standard header file. */
Johannes Weiner3560e242008-07-23 21:28:09 -070061#define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
63
64#ifndef CONFIG_DISCONTIGMEM
65unsigned long __init zone_sizes_init(void)
66{
Christoph Lameterf06a9682006-09-25 23:31:10 -070067 unsigned long zones_size[MAX_NR_ZONES] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 unsigned long max_dma;
69 unsigned long low;
70 unsigned long start_pfn;
71
72#ifdef CONFIG_MMU
73 start_pfn = START_PFN(0);
74 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
75 low = MAX_LOW_PFN(0);
76
77 if (low < max_dma){
78 zones_size[ZONE_DMA] = low - start_pfn;
79 zones_size[ZONE_NORMAL] = 0;
80 } else {
81 zones_size[ZONE_DMA] = low - start_pfn;
82 zones_size[ZONE_NORMAL] = low - max_dma;
83 }
84#else
85 zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
86 zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
87 start_pfn = __MEMORY_START >> PAGE_SHIFT;
88#endif /* CONFIG_MMU */
89
Johannes Weiner9109fb72008-07-23 21:27:20 -070090 free_area_init_node(0, zones_size, start_pfn, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 return 0;
93}
94#else /* CONFIG_DISCONTIGMEM */
95extern unsigned long zone_sizes_init(void);
96#endif /* CONFIG_DISCONTIGMEM */
97
98/*======================================================================*
99 * paging_init() : sets up the page tables
100 *======================================================================*/
101void __init paging_init(void)
102{
103#ifdef CONFIG_MMU
104 int i;
105 pgd_t *pg_dir;
106
107 /* We don't need kernel mapping as hardware support that. */
108 pg_dir = swapper_pg_dir;
109
110 for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
111 pgd_val(pg_dir[i]) = 0;
112#endif /* CONFIG_MMU */
113 hole_pages = zone_sizes_init();
114}
115
116int __init reservedpages_count(void)
117{
118 int reservedpages, nid, i;
119
120 reservedpages = 0;
Dave Hansen208d54e2005-10-29 18:16:52 -0700121 for_each_online_node(nid) {
122 unsigned long flags;
123 pgdat_resize_lock(NODE_DATA(nid), &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++)
Dave Hansen408fde82005-06-23 00:07:37 -0700125 if (PageReserved(nid_page_nr(nid, i)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 reservedpages++;
Dave Hansen208d54e2005-10-29 18:16:52 -0700127 pgdat_resize_unlock(NODE_DATA(nid), &flags);
128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 return reservedpages;
131}
132
133/*======================================================================*
134 * mem_init() :
135 * orig : arch/sh/mm/init.c
136 *======================================================================*/
137void __init mem_init(void)
138{
139 int codesize, reservedpages, datasize, initsize;
140 int nid;
141#ifndef CONFIG_MMU
142 extern unsigned long memory_end;
143#endif
144
145 num_physpages = 0;
146 for_each_online_node(nid)
147 num_physpages += MAX_LOW_PFN(nid) - START_PFN(nid) + 1;
148
149 num_physpages -= hole_pages;
150
151#ifndef CONFIG_DISCONTIGMEM
152 max_mapnr = num_physpages;
153#endif /* CONFIG_DISCONTIGMEM */
154
155#ifdef CONFIG_MMU
156 high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
157#else
158 high_memory = (void *)(memory_end & PAGE_MASK);
159#endif /* CONFIG_MMU */
160
161 /* clear the zero-page */
162 memset(empty_zero_page, 0, PAGE_SIZE);
163
164 /* this will put all low memory onto the freelists */
165 for_each_online_node(nid)
166 totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
167
168 reservedpages = reservedpages_count() - hole_pages;
169 codesize = (unsigned long) &_etext - (unsigned long)&_text;
170 datasize = (unsigned long) &_edata - (unsigned long)&_etext;
171 initsize = (unsigned long) &__init_end - (unsigned long)&__init_begin;
172
173 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
174 "%dk reserved, %dk data, %dk init)\n",
Geert Uytterhoevencc013a82009-09-21 17:02:36 -0700175 nr_free_pages() << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 num_physpages << (PAGE_SHIFT-10),
177 codesize >> 10,
178 reservedpages << (PAGE_SHIFT-10),
179 datasize >> 10,
180 initsize >> 10);
181}
182
183/*======================================================================*
184 * free_initmem() :
185 * orig : arch/sh/mm/init.c
186 *======================================================================*/
187void free_initmem(void)
188{
189 unsigned long addr;
190
191 addr = (unsigned long)(&__init_begin);
192 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
193 ClearPageReserved(virt_to_page(addr));
Nick Piggin7835e982006-03-22 00:08:40 -0800194 init_page_count(virt_to_page(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 free_page(addr);
196 totalram_pages++;
197 }
198 printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", \
199 (int)(&__init_end - &__init_begin) >> 10);
200}
201
202#ifdef CONFIG_BLK_DEV_INITRD
203/*======================================================================*
204 * free_initrd_mem() :
205 * orig : arch/sh/mm/init.c
206 *======================================================================*/
207void free_initrd_mem(unsigned long start, unsigned long end)
208{
209 unsigned long p;
210 for (p = start; p < end; p += PAGE_SIZE) {
211 ClearPageReserved(virt_to_page(p));
Nick Piggin7835e982006-03-22 00:08:40 -0800212 init_page_count(virt_to_page(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 free_page(p);
214 totalram_pages++;
215 }
216 printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
217}
218#endif