blob: a501838233abb5aa9bcc281a24e683dd9fa2935f [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>
Jiang Liu8be65852013-04-29 15:06:40 -070031#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33pgd_t swapper_pg_dir[1024];
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
36 * Cache of MMU context last used.
37 */
38#ifndef CONFIG_SMP
39unsigned long mmu_context_cache_dat;
40#else
41unsigned long mmu_context_cache_dat[NR_CPUS];
42#endif
43static unsigned long hole_pages;
44
45/*
46 * function prototype
47 */
48void __init paging_init(void);
49void __init mem_init(void);
50void free_initmem(void);
51#ifdef CONFIG_BLK_DEV_INITRD
52void free_initrd_mem(unsigned long, unsigned long);
53#endif
54
55/* It'd be good if these lines were in the standard header file. */
Johannes Weiner3560e242008-07-23 21:28:09 -070056#define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
58
59#ifndef CONFIG_DISCONTIGMEM
60unsigned long __init zone_sizes_init(void)
61{
Christoph Lameterf06a9682006-09-25 23:31:10 -070062 unsigned long zones_size[MAX_NR_ZONES] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 unsigned long max_dma;
64 unsigned long low;
65 unsigned long start_pfn;
66
67#ifdef CONFIG_MMU
68 start_pfn = START_PFN(0);
69 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
70 low = MAX_LOW_PFN(0);
71
72 if (low < max_dma){
73 zones_size[ZONE_DMA] = low - start_pfn;
74 zones_size[ZONE_NORMAL] = 0;
75 } else {
76 zones_size[ZONE_DMA] = low - start_pfn;
77 zones_size[ZONE_NORMAL] = low - max_dma;
78 }
79#else
80 zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
81 zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
82 start_pfn = __MEMORY_START >> PAGE_SHIFT;
83#endif /* CONFIG_MMU */
84
Johannes Weiner9109fb72008-07-23 21:27:20 -070085 free_area_init_node(0, zones_size, start_pfn, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 return 0;
88}
89#else /* CONFIG_DISCONTIGMEM */
90extern unsigned long zone_sizes_init(void);
91#endif /* CONFIG_DISCONTIGMEM */
92
93/*======================================================================*
94 * paging_init() : sets up the page tables
95 *======================================================================*/
96void __init paging_init(void)
97{
98#ifdef CONFIG_MMU
99 int i;
100 pgd_t *pg_dir;
101
102 /* We don't need kernel mapping as hardware support that. */
103 pg_dir = swapper_pg_dir;
104
105 for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
106 pgd_val(pg_dir[i]) = 0;
107#endif /* CONFIG_MMU */
108 hole_pages = zone_sizes_init();
109}
110
111int __init reservedpages_count(void)
112{
113 int reservedpages, nid, i;
114
115 reservedpages = 0;
Dave Hansen208d54e2005-10-29 18:16:52 -0700116 for_each_online_node(nid) {
117 unsigned long flags;
118 pgdat_resize_lock(NODE_DATA(nid), &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++)
Dave Hansen408fde82005-06-23 00:07:37 -0700120 if (PageReserved(nid_page_nr(nid, i)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 reservedpages++;
Dave Hansen208d54e2005-10-29 18:16:52 -0700122 pgdat_resize_unlock(NODE_DATA(nid), &flags);
123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 return reservedpages;
126}
127
128/*======================================================================*
129 * mem_init() :
130 * orig : arch/sh/mm/init.c
131 *======================================================================*/
132void __init mem_init(void)
133{
134 int codesize, reservedpages, datasize, initsize;
135 int nid;
136#ifndef CONFIG_MMU
137 extern unsigned long memory_end;
138#endif
139
140 num_physpages = 0;
141 for_each_online_node(nid)
142 num_physpages += MAX_LOW_PFN(nid) - START_PFN(nid) + 1;
143
144 num_physpages -= hole_pages;
145
146#ifndef CONFIG_DISCONTIGMEM
147 max_mapnr = num_physpages;
148#endif /* CONFIG_DISCONTIGMEM */
149
150#ifdef CONFIG_MMU
151 high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
152#else
153 high_memory = (void *)(memory_end & PAGE_MASK);
154#endif /* CONFIG_MMU */
155
156 /* clear the zero-page */
157 memset(empty_zero_page, 0, PAGE_SIZE);
158
159 /* this will put all low memory onto the freelists */
160 for_each_online_node(nid)
Jiang Liu0c988532013-07-03 15:03:24 -0700161 free_all_bootmem_node(NODE_DATA(nid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 reservedpages = reservedpages_count() - hole_pages;
164 codesize = (unsigned long) &_etext - (unsigned long)&_text;
165 datasize = (unsigned long) &_edata - (unsigned long)&_etext;
166 initsize = (unsigned long) &__init_end - (unsigned long)&__init_begin;
167
168 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
169 "%dk reserved, %dk data, %dk init)\n",
Geert Uytterhoevencc013a82009-09-21 17:02:36 -0700170 nr_free_pages() << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 num_physpages << (PAGE_SHIFT-10),
172 codesize >> 10,
173 reservedpages << (PAGE_SHIFT-10),
174 datasize >> 10,
175 initsize >> 10);
176}
177
178/*======================================================================*
179 * free_initmem() :
180 * orig : arch/sh/mm/init.c
181 *======================================================================*/
182void free_initmem(void)
183{
Jiang Liudbe67df2013-07-03 15:02:51 -0700184 free_initmem_default(-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
187#ifdef CONFIG_BLK_DEV_INITRD
188/*======================================================================*
189 * free_initrd_mem() :
190 * orig : arch/sh/mm/init.c
191 *======================================================================*/
192void free_initrd_mem(unsigned long start, unsigned long end)
193{
Jiang Liudbe67df2013-07-03 15:02:51 -0700194 free_reserved_area((void *)start, (void *)end, -1, "initrd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196#endif