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 #include <linux/init.h>
13 #include <linux/kernel.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>
21 #include <linux/pfn.h>
22 #include <linux/gfp.h>
23 #include <asm/types.h>
24 #include <asm/processor.h>
26 #include <asm/pgtable.h>
27 #include <asm/pgalloc.h>
28 #include <asm/mmu_context.h>
29 #include <asm/setup.h>
32 /* References to section boundaries */
33 extern char _text
, _etext
, _edata
;
34 extern char __init_begin
, __init_end
;
36 pgd_t swapper_pg_dir
[1024];
38 DEFINE_PER_CPU(struct mmu_gather
, mmu_gathers
);
41 * Cache of MMU context last used.
44 unsigned long mmu_context_cache_dat
;
46 unsigned long mmu_context_cache_dat
[NR_CPUS
];
48 static unsigned long hole_pages
;
53 void __init
paging_init(void);
54 void __init
mem_init(void);
55 void free_initmem(void);
56 #ifdef CONFIG_BLK_DEV_INITRD
57 void free_initrd_mem(unsigned long, unsigned long);
60 /* It'd be good if these lines were in the standard header file. */
61 #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn)
62 #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn)
64 #ifndef CONFIG_DISCONTIGMEM
65 unsigned long __init
zone_sizes_init(void)
67 unsigned long zones_size
[MAX_NR_ZONES
] = {0, };
68 unsigned long max_dma
;
70 unsigned long start_pfn
;
73 start_pfn
= START_PFN(0);
74 max_dma
= virt_to_phys((char *)MAX_DMA_ADDRESS
) >> PAGE_SHIFT
;
78 zones_size
[ZONE_DMA
] = low
- start_pfn
;
79 zones_size
[ZONE_NORMAL
] = 0;
81 zones_size
[ZONE_DMA
] = low
- start_pfn
;
82 zones_size
[ZONE_NORMAL
] = low
- max_dma
;
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 */
90 free_area_init_node(0, zones_size
, start_pfn
, 0);
94 #else /* CONFIG_DISCONTIGMEM */
95 extern unsigned long zone_sizes_init(void);
96 #endif /* CONFIG_DISCONTIGMEM */
98 /*======================================================================*
99 * paging_init() : sets up the page tables
100 *======================================================================*/
101 void __init
paging_init(void)
107 /* We don't need kernel mapping as hardware support that. */
108 pg_dir
= swapper_pg_dir
;
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();
116 int __init
reservedpages_count(void)
118 int reservedpages
, nid
, i
;
121 for_each_online_node(nid
) {
123 pgdat_resize_lock(NODE_DATA(nid
), &flags
);
124 for (i
= 0 ; i
< MAX_LOW_PFN(nid
) - START_PFN(nid
) ; i
++)
125 if (PageReserved(nid_page_nr(nid
, i
)))
127 pgdat_resize_unlock(NODE_DATA(nid
), &flags
);
130 return reservedpages
;
133 /*======================================================================*
135 * orig : arch/sh/mm/init.c
136 *======================================================================*/
137 void __init
mem_init(void)
139 int codesize
, reservedpages
, datasize
, initsize
;
142 extern unsigned long memory_end
;
146 for_each_online_node(nid
)
147 num_physpages
+= MAX_LOW_PFN(nid
) - START_PFN(nid
) + 1;
149 num_physpages
-= hole_pages
;
151 #ifndef CONFIG_DISCONTIGMEM
152 max_mapnr
= num_physpages
;
153 #endif /* CONFIG_DISCONTIGMEM */
156 high_memory
= (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
158 high_memory
= (void *)(memory_end
& PAGE_MASK
);
159 #endif /* CONFIG_MMU */
161 /* clear the zero-page */
162 memset(empty_zero_page
, 0, PAGE_SIZE
);
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
));
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
;
173 printk(KERN_INFO
"Memory: %luk/%luk available (%dk kernel code, "
174 "%dk reserved, %dk data, %dk init)\n",
175 nr_free_pages() << (PAGE_SHIFT
-10),
176 num_physpages
<< (PAGE_SHIFT
-10),
178 reservedpages
<< (PAGE_SHIFT
-10),
183 /*======================================================================*
185 * orig : arch/sh/mm/init.c
186 *======================================================================*/
187 void free_initmem(void)
191 addr
= (unsigned long)(&__init_begin
);
192 for (; addr
< (unsigned long)(&__init_end
); addr
+= PAGE_SIZE
) {
193 ClearPageReserved(virt_to_page(addr
));
194 init_page_count(virt_to_page(addr
));
198 printk (KERN_INFO
"Freeing unused kernel memory: %dk freed\n", \
199 (int)(&__init_end
- &__init_begin
) >> 10);
202 #ifdef CONFIG_BLK_DEV_INITRD
203 /*======================================================================*
204 * free_initrd_mem() :
205 * orig : arch/sh/mm/init.c
206 *======================================================================*/
207 void free_initrd_mem(unsigned long start
, unsigned long end
)
210 for (p
= start
; p
< end
; p
+= PAGE_SIZE
) {
211 ClearPageReserved(virt_to_page(p
));
212 init_page_count(virt_to_page(p
));
216 printk (KERN_INFO
"Freeing initrd memory: %ldk freed\n", (end
- start
) >> 10);