2 * linux/arch/nios2nommu/mm/init.c
4 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
5 * Kenneth Albanowski <kjahds@kjahds.com>,
6 * Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
7 * Copyright (C) 2004 Microtronix Datacom Ltd
11 * linux/arch/m68k/mm/init.c
13 * Copyright (C) 1995 Hamish Macdonald
15 * JAN/1999 -- hacked to support ColdFire (gerg@snapgear.com)
16 * DEC/2000 -- linux 2.4 support <davidm@snapgear.com>
17 * Jan/20/2004 dgt NiosII
21 #include <linux/signal.h>
22 #include <linux/sched.h>
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/string.h>
26 #include <linux/types.h>
27 #include <linux/ptrace.h>
28 #include <linux/mman.h>
30 #include <linux/swap.h>
31 #include <linux/init.h>
32 #include <linux/highmem.h>
33 #include <linux/pagemap.h>
34 #include <linux/bootmem.h>
35 #include <linux/slab.h>
37 #include <asm/setup.h>
38 #include <asm/segment.h>
40 #include <asm/pgtable.h>
41 #include <asm/system.h>
42 //;dgt2;#include <asm/machdep.h>
43 //;dgt2;#include <asm/shglcore.h>
47 extern void die_if_kernel(char *,struct pt_regs
*,long);
48 extern void free_initmem(void);
51 * BAD_PAGE is the page that is used for page faults when linux
52 * is out-of-memory. Older versions of linux just did a
53 * do_exit(), but using this instead means there is less risk
54 * for a process dying in kernel mode, possibly leaving a inode
57 * BAD_PAGETABLE is the accompanying page-table: it is initialized
58 * to point to BAD_PAGE entries.
60 * ZERO_PAGE is a special page that is used for zero-initialized
63 static unsigned long empty_bad_page_table
;
65 static unsigned long empty_bad_page
;
67 unsigned long empty_zero_page
;
69 extern unsigned long rom_length
;
74 int free
= 0, total
= 0, reserved
= 0, shared
= 0;
77 printk(KERN_INFO
"\nMem-info:\n");
82 if (PageReserved(mem_map
+i
))
84 else if (PageSwapCache(mem_map
+i
))
86 else if (!page_count(mem_map
+i
))
89 shared
+= page_count(mem_map
+i
) - 1;
91 printk(KERN_INFO
"%d pages of RAM\n",total
);
92 printk(KERN_INFO
"%d free pages\n",free
);
93 printk(KERN_INFO
"%d reserved pages\n",reserved
);
94 printk(KERN_INFO
"%d pages shared\n",shared
);
95 printk(KERN_INFO
"%d pages swap cached\n",cached
);
98 extern unsigned long memory_start
;
99 extern unsigned long memory_end
;
102 * paging_init() continues the virtual memory environment setup which
103 * was begun by the code in arch/head.S.
104 * The parameters are pointers to where to stick the starting and ending
105 * addresses of available kernel virtual memory.
107 void paging_init(void)
110 * Make sure start_mem is page aligned, otherwise bootmem and
111 * page_alloc get different views of the world.
114 unsigned long start_mem
= PAGE_ALIGN(memory_start
);
116 unsigned long end_mem
= memory_end
& PAGE_MASK
;
119 printk (KERN_DEBUG
"start_mem is %#lx\nvirtual_end is %#lx\n",
124 * Initialize the bad page table and bad page to point
125 * to a couple of allocated pages.
127 empty_bad_page_table
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
128 empty_bad_page
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
129 empty_zero_page
= (unsigned long)alloc_bootmem_pages(PAGE_SIZE
);
130 memset((void *)empty_zero_page
, 0, PAGE_SIZE
);
133 * Set up SFC/DFC registers (user data space).
138 printk (KERN_DEBUG
"before free_area_init\n");
140 printk (KERN_DEBUG
"free_area_init -> start_mem is %#lx\nvirtual_end is %#lx\n",
145 unsigned long zones_size
[MAX_NR_ZONES
] = {0, };
147 zones_size
[ZONE_DMA
] = (end_mem
- PAGE_OFFSET
) >> PAGE_SHIFT
;
148 zones_size
[ZONE_NORMAL
] = 0;
149 #ifdef CONFIG_HIGHMEM
150 zones_size
[ZONE_HIGHMEM
] = 0;
152 free_area_init(zones_size
);
158 int codek
= 0, datak
= 0, initk
= 0;
160 extern char _etext
, _stext
, _sdata
, _ebss
, __init_begin
, __init_end
;
161 extern unsigned char _ramend
, _rambase
;
162 unsigned long start_mem
= memory_start
; /* DAVIDM - these must start at end of kernel */
163 unsigned long end_mem
= memory_end
; /* DAVIDM - this must not include kernel stack at top */
166 printk(KERN_DEBUG
"Mem_init: start=%lx, end=%lx\n", start_mem
, end_mem
);
169 end_mem
&= PAGE_MASK
;
170 high_memory
= (void *) end_mem
;
172 start_mem
= PAGE_ALIGN(start_mem
);
173 max_mapnr
= num_physpages
= MAP_NR(high_memory
);
175 /* this will put all memory onto the freelists */
176 totalram_pages
= free_all_bootmem();
178 codek
= (&_etext
- &_stext
) >> 10;
179 datak
= (&_ebss
- &_sdata
) >> 10;
180 initk
= (&__init_begin
- &__init_end
) >> 10;
182 tmp
= nr_free_pages() << PAGE_SHIFT
;
183 printk(KERN_INFO
"Memory available: %luk/%luk RAM, %luk/%luk ROM (%dk kernel code, %dk data)\n",
185 (&_ramend
- &_rambase
) >> 10,
186 (rom_length
> 0) ? ((rom_length
>> 10) - codek
) : 0,
194 #ifdef CONFIG_BLK_DEV_INITRD
195 void free_initrd_mem(unsigned long start
, unsigned long end
)
198 for (; start
< end
; start
+= PAGE_SIZE
) {
199 ClearPageReserved(virt_to_page(start
));
200 init_page_count(virt_to_page(start
));
205 printk (KERN_NOTICE
"Freeing initrd memory: %dk freed\n", pages
);
212 #ifdef CONFIG_RAMKERNEL
214 extern char __init_begin
, __init_end
;
216 * The following code should be cool even if these sections
217 * are not page aligned.
219 addr
= PAGE_ALIGN((unsigned long)(&__init_begin
));
220 /* next to check that the page we free is not a partial page */
221 for (; addr
+ PAGE_SIZE
< (unsigned long)(&__init_end
); addr
+=PAGE_SIZE
) {
222 ClearPageReserved(virt_to_page(addr
));
223 init_page_count(virt_to_page(addr
));
227 printk(KERN_NOTICE
"Freeing unused kernel memory: %ldk freed (0x%x - 0x%x)\n",
228 (addr
- PAGE_ALIGN((long) &__init_begin
)) >> 10,
229 (int)(PAGE_ALIGN((unsigned long)(&__init_begin
))),
230 (int)(addr
- PAGE_SIZE
));