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 #ifdef CONFIG_BLK_DEV_INITRD
26 #include <linux/blk.h>
28 #include <linux/pagemap.h>
29 #include <linux/bootmem.h>
31 #include <asm/processor.h>
32 #include <asm/system.h>
33 #include <asm/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/pgalloc.h>
37 #include <asm/lowcore.h>
40 mmu_gather_t mmu_gathers[NR_CPUS];
42 static unsigned long totalram_pages;
44 pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
45 char empty_zero_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
47 int do_check_pgt_cache(int low, int high)
50 if(pgtable_cache_size > high) {
53 free_pgd_slow(get_pgd_fast());
57 pmd_free_slow(pmd_alloc_one_fast(NULL, 0));
61 pte_free_slow(pte_alloc_one_fast(NULL, 0));
64 } while(pgtable_cache_size > low);
71 int i, total = 0, reserved = 0;
72 int shared = 0, cached = 0;
74 printk("Mem-info:\n");
76 printk("Free swap: %6dkB\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 += atomic_read(&mem_map[i].count) - 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);
91 printk("%ld pages in page table cache\n",pgtable_cache_size);
95 /* References to section boundaries */
97 extern unsigned long _text;
98 extern unsigned long _etext;
99 extern unsigned long _edata;
100 extern unsigned long __bss_start;
101 extern unsigned long _end;
103 extern unsigned long __init_begin;
104 extern unsigned long __init_end;
107 * paging_init() sets up the page tables - note that the first 4MB are
108 * already mapped by head.S.
109 * paging_init will erase this initial mapping
112 unsigned long last_valid_pfn;
114 void __init paging_init(void)
121 unsigned long address=0;
122 unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE;
123 unsigned long end_mem = (unsigned long) __va(max_low_pfn*PAGE_SIZE);
124 static const int ssm_mask = 0x04000000L;
126 /* unmap whole virtual address space */
128 pg_dir = swapper_pg_dir;
130 for (i=0;i<KERNEL_PGD_PTRS;i++)
131 pmd_clear((pmd_t*)pg_dir++);
134 * map whole physical memory to virtual memory (identity mapping)
137 pg_dir = swapper_pg_dir;
139 while (address < end_mem) {
141 * pg_table is physical at this point
143 pg_table = (pte_t *) alloc_bootmem_low_pages(PAGE_SIZE);
145 pg_dir->pgd0 = (_PAGE_TABLE | __pa(pg_table));
146 pg_dir->pgd1 = (_PAGE_TABLE | (__pa(pg_table)+1024));
147 pg_dir->pgd2 = (_PAGE_TABLE | (__pa(pg_table)+2048));
148 pg_dir->pgd3 = (_PAGE_TABLE | (__pa(pg_table)+3072));
151 for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) {
152 pte = mk_pte_phys(address, PAGE_KERNEL);
153 if (address >= end_mem)
155 set_pte(pg_table, pte);
156 address += PAGE_SIZE;
160 /* enable virtual mapping in kernel mode */
161 __asm__ __volatile__(" LCTL 1,1,%0\n"
165 : : "m" (pgdir_k), "m" (ssm_mask));
170 unsigned long zones_size[MAX_NR_ZONES] = { 0, 0, 0};
172 zones_size[ZONE_DMA] = max_low_pfn;
173 free_area_init(zones_size);
179 void __init mem_init(void)
181 int codesize, reservedpages, datasize, initsize;
183 max_mapnr = num_physpages = max_low_pfn;
184 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
186 /* clear the zero-page */
187 memset(empty_zero_page, 0, PAGE_SIZE);
189 /* this will put all low memory onto the freelists */
190 totalram_pages += free_all_bootmem();
194 codesize = (unsigned long) &_etext - (unsigned long) &_text;
195 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
196 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
197 printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n",
198 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
199 max_mapnr << (PAGE_SHIFT-10),
201 reservedpages << (PAGE_SHIFT-10),
206 void free_initmem(void)
210 addr = (unsigned long)(&__init_begin);
211 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
212 ClearPageReserved(virt_to_page(addr));
213 set_page_count(virt_to_page(addr), 1);
217 printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n",
218 (&__init_end - &__init_begin) >> 10);
221 #ifdef CONFIG_BLK_DEV_INITRD
222 void free_initrd_mem(unsigned long start, unsigned long end)
225 printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
226 for (; start < end; start += PAGE_SIZE) {
227 ClearPageReserved(virt_to_page(start));
228 set_page_count(virt_to_page(start), 1);
235 void si_meminfo(struct sysinfo *val)
237 val->totalram = totalram_pages;
239 val->freeram = nr_free_pages();
240 val->bufferram = atomic_read(&buffermem_pages);
243 val->mem_unit = PAGE_SIZE;