5 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Hartmut Penner (hp@de.ibm.com)
8 * Derived from "arch/i386/mm/init.c"
9 * Copyright (C) 1995 Linus Torvalds
12 #include <linux/config.h>
13 #include <linux/signal.h>
14 #include <linux/sched.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/types.h>
19 #include <linux/ptrace.h>
20 #include <linux/mman.h>
22 #include <linux/swap.h>
23 #include <linux/smp.h>
24 #include <linux/init.h>
25 #include <linux/pagemap.h>
26 #include <linux/bootmem.h>
28 #include <asm/processor.h>
29 #include <asm/system.h>
30 #include <asm/uaccess.h>
31 #include <asm/pgtable.h>
32 #include <asm/pgalloc.h>
34 #include <asm/lowcore.h>
36 #include <asm/tlbflush.h>
38 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
40 pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
41 char empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
43 void diag10(unsigned long addr)
45 if (addr >= 0x7ff00000)
52 ".section __ex_table,\"a\"\n"
61 ".section __ex_table,\"a\"\n"
71 int i, total = 0, reserved = 0;
72 int shared = 0, cached = 0;
74 printk("Mem-info:\n");
76 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
80 if (PageReserved(mem_map+i))
82 else if (PageSwapCache(mem_map+i))
84 else if (page_count(mem_map+i))
85 shared += page_count(mem_map+i) - 1;
87 printk("%d pages of RAM\n",total);
88 printk("%d reserved pages\n",reserved);
89 printk("%d pages shared\n",shared);
90 printk("%d pages swap cached\n",cached);
93 /* References to section boundaries */
95 extern unsigned long _text;
96 extern unsigned long _etext;
97 extern unsigned long _edata;
98 extern unsigned long __bss_start;
99 extern unsigned long _end;
101 extern unsigned long __init_begin;
102 extern unsigned long __init_end;
105 * paging_init() sets up the page tables
108 #ifndef CONFIG_ARCH_S390X
109 void __init paging_init(void)
116 unsigned long pfn = 0;
117 unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE;
118 static const int ssm_mask = 0x04000000L;
120 /* unmap whole virtual address space */
122 pg_dir = swapper_pg_dir;
124 for (i=0;i<KERNEL_PGD_PTRS;i++)
125 pmd_clear((pmd_t*)pg_dir++);
128 * map whole physical memory to virtual memory (identity mapping)
131 pg_dir = swapper_pg_dir;
133 while (pfn < max_low_pfn) {
135 * pg_table is physical at this point
137 pg_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
139 pg_dir->pgd0 = (_PAGE_TABLE | __pa(pg_table));
140 pg_dir->pgd1 = (_PAGE_TABLE | (__pa(pg_table)+1024));
141 pg_dir->pgd2 = (_PAGE_TABLE | (__pa(pg_table)+2048));
142 pg_dir->pgd3 = (_PAGE_TABLE | (__pa(pg_table)+3072));
145 for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) {
146 pte = pfn_pte(pfn, PAGE_KERNEL);
147 if (pfn >= max_low_pfn)
148 pte_clear(&init_mm, 0, &pte);
149 set_pte(pg_table, pte);
154 S390_lowcore.kernel_asce = pgdir_k;
156 /* enable virtual mapping in kernel mode */
157 __asm__ __volatile__(" LCTL 1,1,%0\n"
161 : : "m" (pgdir_k), "m" (ssm_mask));
166 unsigned long zones_size[MAX_NR_ZONES] = { 0, 0, 0};
168 zones_size[ZONE_DMA] = max_low_pfn;
169 free_area_init(zones_size);
174 #else /* CONFIG_ARCH_S390X */
175 void __init paging_init(void)
182 unsigned long pfn = 0;
183 unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) |
185 static const int ssm_mask = 0x04000000L;
187 unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
188 unsigned long dma_pfn, high_pfn;
190 dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
191 high_pfn = max_low_pfn;
193 if (dma_pfn > high_pfn)
194 zones_size[ZONE_DMA] = high_pfn;
196 zones_size[ZONE_DMA] = dma_pfn;
197 zones_size[ZONE_NORMAL] = high_pfn - dma_pfn;
200 /* Initialize mem_map[]. */
201 free_area_init(zones_size);
205 * map whole physical memory to virtual memory (identity mapping)
208 pg_dir = swapper_pg_dir;
210 for (i = 0 ; i < PTRS_PER_PGD ; i++,pg_dir++) {
212 if (pfn >= max_low_pfn) {
217 pm_dir = (pmd_t *) alloc_bootmem_low_pages(PAGE_SIZE*4);
218 pgd_populate(&init_mm, pg_dir, pm_dir);
220 for (j = 0 ; j < PTRS_PER_PMD ; j++,pm_dir++) {
221 if (pfn >= max_low_pfn) {
226 pt_dir = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
227 pmd_populate_kernel(&init_mm, pm_dir, pt_dir);
229 for (k = 0 ; k < PTRS_PER_PTE ; k++,pt_dir++) {
230 pte = pfn_pte(pfn, PAGE_KERNEL);
231 if (pfn >= max_low_pfn) {
232 pte_clear(&init_mm, 0, &pte);
235 set_pte(pt_dir, pte);
241 S390_lowcore.kernel_asce = pgdir_k;
243 /* enable virtual mapping in kernel mode */
244 __asm__ __volatile__("lctlg 1,1,%0\n\t"
248 : :"m" (pgdir_k), "m" (ssm_mask));
254 #endif /* CONFIG_ARCH_S390X */
256 void __init mem_init(void)
258 unsigned long codesize, reservedpages, datasize, initsize;
260 max_mapnr = num_physpages = max_low_pfn;
261 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
263 /* clear the zero-page */
264 memset(empty_zero_page, 0, PAGE_SIZE);
266 /* this will put all low memory onto the freelists */
267 totalram_pages += free_all_bootmem();
271 codesize = (unsigned long) &_etext - (unsigned long) &_text;
272 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
273 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
274 printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
275 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
276 max_mapnr << (PAGE_SHIFT-10),
278 reservedpages << (PAGE_SHIFT-10),
283 void free_initmem(void)
287 addr = (unsigned long)(&__init_begin);
288 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
289 ClearPageReserved(virt_to_page(addr));
290 set_page_count(virt_to_page(addr), 1);
294 printk ("Freeing unused kernel memory: %ldk freed\n",
295 ((unsigned long)&__init_end - (unsigned long)&__init_begin) >> 10);
298 #ifdef CONFIG_BLK_DEV_INITRD
299 void free_initrd_mem(unsigned long start, unsigned long end)
302 printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
303 for (; start < end; start += PAGE_SIZE) {
304 ClearPageReserved(virt_to_page(start));
305 set_page_count(virt_to_page(start), 1);