MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / arch / m32r / mm / init.c
bloba290e3793caf1e6c88729f5903cc59535c95a231
1 /*
2 * linux/arch/m32r/mm/init.c
4 * Copyright (c) 2001, 2002 Hitoshi Yamamoto
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
12 /* $Id$ */
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/mm.h>
17 #include <linux/pagemap.h>
18 #include <linux/bootmem.h>
19 #include <linux/swap.h>
20 #include <linux/highmem.h>
21 #include <asm/types.h>
22 #include <asm/processor.h>
23 #include <asm/bitops.h>
24 #include <asm/page.h>
25 #include <asm/pgtable.h>
26 #include <asm/pgalloc.h>
27 #include <asm/mmu_context.h>
28 #include <asm/setup.h>
29 #include <asm/tlb.h>
31 /* References to section boundaries */
32 extern char _text, _etext, _edata;
33 extern char __init_begin, __init_end;
35 pgd_t swapper_pg_dir[1024];
37 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
39 void show_mem(void)
41 int total = 0, reserved = 0;
42 int shared = 0, cached = 0;
43 int highmem = 0;
44 struct page *page;
45 pg_data_t *pgdat;
46 unsigned long i;
48 printk("Mem-info:\n");
49 show_free_areas();
50 printk("Free swap: %6ldkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
51 for_each_pgdat(pgdat) {
52 for (i = 0; i < pgdat->node_spanned_pages; ++i) {
53 page = pgdat->node_mem_map + i;
54 total++;
55 if (PageHighMem(page))
56 highmem++;
57 if (PageReserved(page))
58 reserved++;
59 else if (PageSwapCache(page))
60 cached++;
61 else if (page_count(page))
62 shared += page_count(page) - 1;
65 printk("%d pages of RAM\n", total);
66 printk("%d pages of HIGHMEM\n",highmem);
67 printk("%d reserved pages\n",reserved);
68 printk("%d pages shared\n",shared);
69 printk("%d pages swap cached\n",cached);
73 * Cache of MMU context last used.
75 #ifndef CONFIG_SMP
76 unsigned long mmu_context_cache_dat;
77 #else
78 unsigned long mmu_context_cache_dat[NR_CPUS];
79 #endif
80 static unsigned long hole_pages;
83 * function prototype
85 void __init paging_init(void);
86 void __init mem_init(void);
87 void free_initmem(void);
88 #ifdef CONFIG_BLK_DEV_INITRD
89 void free_initrd_mem(unsigned long, unsigned long);
90 #endif
92 /* It'd be good if these lines were in the standard header file. */
93 #define START_PFN(nid) \
94 (NODE_DATA(nid)->bdata->node_boot_start >> PAGE_SHIFT)
95 #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
97 #ifndef CONFIG_DISCONTIGMEM
98 unsigned long __init zone_sizes_init(void)
100 unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
101 unsigned long max_dma;
102 unsigned long low;
103 unsigned long start_pfn;
105 #ifdef CONFIG_MMU
106 start_pfn = START_PFN(0);
107 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
108 low = MAX_LOW_PFN(0);
110 if (low < max_dma){
111 zones_size[ZONE_DMA] = low - start_pfn;
112 zones_size[ZONE_NORMAL] = 0;
113 } else {
114 zones_size[ZONE_DMA] = low - start_pfn;
115 zones_size[ZONE_NORMAL] = low - max_dma;
117 #else
118 zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT;
119 zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT;
120 start_pfn = __MEMORY_START >> PAGE_SHIFT;
121 #endif /* CONFIG_MMU */
123 free_area_init_node(0, NODE_DATA(0), zones_size, start_pfn, 0);
125 mem_map = contig_page_data.node_mem_map;
127 return 0;
129 #else /* CONFIG_DISCONTIGMEM */
130 extern unsigned long zone_sizes_init(void);
131 #endif /* CONFIG_DISCONTIGMEM */
133 /*======================================================================*
134 * paging_init() : sets up the page tables
135 *======================================================================*/
136 void __init paging_init(void)
138 #ifdef CONFIG_MMU
139 int i;
140 pgd_t *pg_dir;
142 /* We don't need kernel mapping as hardware support that. */
143 pg_dir = swapper_pg_dir;
145 for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++)
146 pgd_val(pg_dir[i]) = 0;
147 #endif /* CONFIG_MMU */
148 hole_pages = zone_sizes_init();
151 int __init reservedpages_count(void)
153 int reservedpages, nid, i;
155 reservedpages = 0;
156 for (nid = 0 ; nid < numnodes ; nid++)
157 for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++)
158 if (PageReserved(NODE_DATA(nid)->node_mem_map + i))
159 reservedpages++;
161 return reservedpages;
164 /*======================================================================*
165 * mem_init() :
166 * orig : arch/sh/mm/init.c
167 *======================================================================*/
168 void __init mem_init(void)
170 int codesize, reservedpages, datasize, initsize;
171 int nid;
172 #ifndef CONFIG_MMU
173 extern unsigned long memory_end;
174 #endif
176 num_physpages = 0;
177 for (nid = 0 ; nid < numnodes ; nid++)
178 num_physpages += MAX_LOW_PFN(nid) - START_PFN(nid) + 1;
180 num_physpages -= hole_pages;
182 #ifndef CONFIG_DISCONTIGMEM
183 max_mapnr = num_physpages;
184 #endif /* CONFIG_DISCONTIGMEM */
186 #ifdef CONFIG_MMU
187 high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
188 #else
189 high_memory = (void *)(memory_end & PAGE_MASK);
190 #endif /* CONFIG_MMU */
192 /* clear the zero-page */
193 memset(empty_zero_page, 0, PAGE_SIZE);
195 /* this will put all low memory onto the freelists */
196 for (nid = 0 ; nid < numnodes ; nid++)
197 totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
199 reservedpages = reservedpages_count() - hole_pages;
200 codesize = (unsigned long) &_etext - (unsigned long)&_text;
201 datasize = (unsigned long) &_edata - (unsigned long)&_etext;
202 initsize = (unsigned long) &__init_end - (unsigned long)&__init_begin;
204 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
205 "%dk reserved, %dk data, %dk init)\n",
206 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
207 num_physpages << (PAGE_SHIFT-10),
208 codesize >> 10,
209 reservedpages << (PAGE_SHIFT-10),
210 datasize >> 10,
211 initsize >> 10);
214 /*======================================================================*
215 * free_initmem() :
216 * orig : arch/sh/mm/init.c
217 *======================================================================*/
218 void free_initmem(void)
220 unsigned long addr;
222 addr = (unsigned long)(&__init_begin);
223 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
224 ClearPageReserved(virt_to_page(addr));
225 set_page_count(virt_to_page(addr), 1);
226 free_page(addr);
227 totalram_pages++;
229 printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", \
230 (int)(&__init_end - &__init_begin) >> 10);
233 #ifdef CONFIG_BLK_DEV_INITRD
234 /*======================================================================*
235 * free_initrd_mem() :
236 * orig : arch/sh/mm/init.c
237 *======================================================================*/
238 void free_initrd_mem(unsigned long start, unsigned long end)
240 unsigned long p;
241 for (p = start; p < end; p += PAGE_SIZE) {
242 ClearPageReserved(virt_to_page(p));
243 set_page_count(virt_to_page(p), 1);
244 free_page(p);
245 totalram_pages++;
247 printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
249 #endif