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
14 #include <linux/init.h>
15 #include <linux/kernel.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>
25 #include <asm/pgtable.h>
26 #include <asm/pgalloc.h>
27 #include <asm/mmu_context.h>
28 #include <asm/setup.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
);
41 int total
= 0, reserved
= 0;
42 int shared
= 0, cached
= 0;
48 printk("Mem-info:\n");
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
;
55 if (PageHighMem(page
))
57 if (PageReserved(page
))
59 else if (PageSwapCache(page
))
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.
76 unsigned long mmu_context_cache_dat
;
78 unsigned long mmu_context_cache_dat
[NR_CPUS
];
80 static unsigned long hole_pages
;
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);
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
;
103 unsigned long start_pfn
;
106 start_pfn
= START_PFN(0);
107 max_dma
= virt_to_phys((char *)MAX_DMA_ADDRESS
) >> PAGE_SHIFT
;
108 low
= MAX_LOW_PFN(0);
111 zones_size
[ZONE_DMA
] = low
- start_pfn
;
112 zones_size
[ZONE_NORMAL
] = 0;
114 zones_size
[ZONE_DMA
] = low
- start_pfn
;
115 zones_size
[ZONE_NORMAL
] = low
- max_dma
;
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
;
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)
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
;
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
))
161 return reservedpages
;
164 /*======================================================================*
166 * orig : arch/sh/mm/init.c
167 *======================================================================*/
168 void __init
mem_init(void)
170 int codesize
, reservedpages
, datasize
, initsize
;
173 extern unsigned long memory_end
;
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 */
187 high_memory
= (void *)__va(PFN_PHYS(MAX_LOW_PFN(0)));
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),
209 reservedpages
<< (PAGE_SHIFT
-10),
214 /*======================================================================*
216 * orig : arch/sh/mm/init.c
217 *======================================================================*/
218 void free_initmem(void)
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);
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
)
241 for (p
= start
; p
< end
; p
+= PAGE_SIZE
) {
242 ClearPageReserved(virt_to_page(p
));
243 set_page_count(virt_to_page(p
), 1);
247 printk (KERN_INFO
"Freeing initrd memory: %ldk freed\n", (end
- start
) >> 10);