Import 2.3.50pre1
[davej-history.git] / arch / m68k / mm / init.c
blob4e6b282659b58a728e75471a54733224247ca4dc
1 /*
2 * linux/arch/m68k/mm/init.c
4 * Copyright (C) 1995 Hamish Macdonald
6 * Contains common initialization routines, specific init code moved
7 * to motorola.c and sun3mmu.c
8 */
10 #include <linux/config.h>
11 #include <linux/signal.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/swap.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/types.h>
18 #include <linux/init.h>
19 #include <linux/bootmem.h>
20 #ifdef CONFIG_BLK_DEV_RAM
21 #include <linux/blk.h>
22 #endif
24 #include <asm/setup.h>
25 #include <asm/uaccess.h>
26 #include <asm/page.h>
27 #include <asm/pgalloc.h>
28 #include <asm/system.h>
29 #include <asm/machdep.h>
30 #include <asm/io.h>
31 #ifdef CONFIG_ATARI
32 #include <asm/atari_stram.h>
33 #endif
35 static unsigned long totalram_pages = 0;
37 #ifdef CONFIG_SUN3
38 void mmu_emu_reserve_pages(unsigned long max_page);
39 #endif
41 int do_check_pgt_cache(int low, int high)
43 int freed = 0;
44 if(pgtable_cache_size > high) {
45 do {
46 if(pmd_quicklist)
47 freed += free_pmd_slow(get_pmd_fast());
48 if(pte_quicklist)
49 free_pte_slow(get_pte_fast()), freed++;
50 } while(pgtable_cache_size > low);
52 return freed;
56 * BAD_PAGE is the page that is used for page faults when linux
57 * is out-of-memory. Older versions of linux just did a
58 * do_exit(), but using this instead means there is less risk
59 * for a process dying in kernel mode, possibly leaving an inode
60 * unused etc..
62 * BAD_PAGETABLE is the accompanying page-table: it is initialized
63 * to point to BAD_PAGE entries.
65 * ZERO_PAGE is a special page that is used for zero-initialized
66 * data and COW.
68 unsigned long empty_bad_page_table;
70 pte_t *__bad_pagetable(void)
72 memset((void *)empty_bad_page_table, 0, PAGE_SIZE);
73 return (pte_t *)empty_bad_page_table;
76 unsigned long empty_bad_page;
78 pte_t __bad_page(void)
80 memset ((void *)empty_bad_page, 0, PAGE_SIZE);
81 return pte_mkdirty(__mk_pte(empty_bad_page, PAGE_SHARED));
84 unsigned long empty_zero_page;
86 void show_mem(void)
88 unsigned long i;
89 int free = 0, total = 0, reserved = 0, nonshared = 0, shared = 0;
90 int cached = 0;
92 printk("\nMem-info:\n");
93 show_free_areas();
94 printk("Free swap: %6dkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
95 i = max_mapnr;
96 while (i-- > 0) {
97 total++;
98 if (PageReserved(mem_map+i))
99 reserved++;
100 else if (PageSwapCache(mem_map+i))
101 cached++;
102 else if (!page_count(mem_map+i))
103 free++;
104 else if (page_count(mem_map+i) == 1)
105 nonshared++;
106 else
107 shared += page_count(mem_map+i) - 1;
109 printk("%d pages of RAM\n",total);
110 printk("%d free pages\n",free);
111 printk("%d reserved pages\n",reserved);
112 printk("%d pages nonshared\n",nonshared);
113 printk("%d pages shared\n",shared);
114 printk("%d pages swap cached\n",cached);
115 printk("%ld pages in page table cache\n",pgtable_cache_size);
116 show_buffers();
119 extern void init_pointer_table(unsigned long ptable);
121 /* References to section boundaries */
123 extern char _text, _etext, _edata, __bss_start, _end;
124 extern char __init_begin, __init_end;
126 extern pmd_t *zero_pgtable;
128 void __init mem_init(void)
130 int codepages = 0;
131 int datapages = 0;
132 int initpages = 0;
133 unsigned long tmp;
134 int i;
136 max_mapnr = num_physpages = MAP_NR(high_memory);
138 #ifdef CONFIG_ATARI
139 if (MACH_IS_ATARI)
140 atari_stram_reserve_pages( start_mem );
141 #endif
143 #ifdef CONFIG_SUN3
144 /* reserve rom pages */
145 mmu_emu_reserve_pages(max_mapnr);
146 #endif
148 /* this will put all memory onto the freelists */
149 totalram_pages = free_all_bootmem();
150 printk("tp:%ld\n", totalram_pages);
152 for (tmp = PAGE_OFFSET ; tmp < (unsigned long)high_memory; tmp += PAGE_SIZE) {
153 #if 0
154 #ifndef CONFIG_SUN3
155 if (virt_to_phys ((void *)tmp) >= mach_max_dma_address)
156 clear_bit(PG_DMA, &mem_map[MAP_NR(tmp)].flags);
157 #endif
158 #endif
159 if (PageReserved(mem_map+MAP_NR(tmp))) {
160 if (tmp >= (unsigned long)&_text
161 && tmp < (unsigned long)&_etext)
162 codepages++;
163 else if (tmp >= (unsigned long) &__init_begin
164 && tmp < (unsigned long) &__init_end)
165 initpages++;
166 else
167 datapages++;
168 continue;
170 #if 0
171 set_page_count(mem_map+MAP_NR(tmp), 1);
172 #ifdef CONFIG_BLK_DEV_INITRD
173 if (!initrd_start ||
174 (tmp < (initrd_start & PAGE_MASK) || tmp >= initrd_end))
175 #endif
176 free_page(tmp);
177 #endif
180 #ifndef CONFIG_SUN3
181 /* insert pointer tables allocated so far into the tablelist */
182 init_pointer_table((unsigned long)kernel_pg_dir);
183 for (i = 0; i < PTRS_PER_PGD; i++) {
184 if (pgd_present(kernel_pg_dir[i]))
185 init_pointer_table(__pgd_page(kernel_pg_dir[i]));
188 /* insert also pointer table that we used to unmap the zero page */
189 if (zero_pgtable)
190 init_pointer_table((unsigned long)zero_pgtable);
191 #endif
193 printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
194 (unsigned long)nr_free_pages() << (PAGE_SHIFT-10),
195 max_mapnr << (PAGE_SHIFT-10),
196 codepages << (PAGE_SHIFT-10),
197 datapages << (PAGE_SHIFT-10),
198 initpages << (PAGE_SHIFT-10));
201 #ifdef CONFIG_BLK_DEV_INITRD
202 void free_initrd_mem(unsigned long start, unsigned long end)
204 for (; start < end; start += PAGE_SIZE) {
205 ClearPageReserved(mem_map + MAP_NR(start));
206 set_page_count(mem_map+MAP_NR(start), 1);
207 free_page(start);
208 totalram_pages++;
210 printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
212 #endif
214 void si_meminfo(struct sysinfo *val)
216 unsigned long i;
218 i = max_mapnr;
219 val->totalram = totalram_pages;
220 val->sharedram = 0;
221 val->freeram = nr_free_pages();
222 val->bufferram = atomic_read(&buffermem_pages);
223 while (i-- > 0) {
224 if (PageReserved(mem_map+i))
225 continue;
226 val->totalram++;
227 if (!page_count(mem_map+i))
228 continue;
229 val->sharedram += page_count(mem_map+i) - 1;
231 val->totalhigh = 0;
232 val->freehigh = 0;
233 return;