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
10 #include <linux/config.h>
11 #include <linux/signal.h>
12 #include <linux/sched.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>
24 #include <asm/setup.h>
25 #include <asm/uaccess.h>
27 #include <asm/pgalloc.h>
28 #include <asm/system.h>
29 #include <asm/machdep.h>
32 #include <asm/atari_stram.h>
35 static unsigned long totalram_pages
= 0;
38 void mmu_emu_reserve_pages(unsigned long max_page
);
41 int do_check_pgt_cache(int low
, int high
)
44 if(pgtable_cache_size
> high
) {
47 freed
+= free_pmd_slow(get_pmd_fast());
49 free_pte_slow(get_pte_fast()), freed
++;
50 } while(pgtable_cache_size
> low
);
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
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
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
;
89 int free
= 0, total
= 0, reserved
= 0, nonshared
= 0, shared
= 0;
92 printk("\nMem-info:\n");
94 printk("Free swap: %6dkB\n",nr_swap_pages
<<(PAGE_SHIFT
-10));
98 if (PageReserved(mem_map
+i
))
100 else if (PageSwapCache(mem_map
+i
))
102 else if (!page_count(mem_map
+i
))
104 else if (page_count(mem_map
+i
) == 1)
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
);
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)
136 max_mapnr
= num_physpages
= MAP_NR(high_memory
);
140 atari_stram_reserve_pages( start_mem
);
144 /* reserve rom pages */
145 mmu_emu_reserve_pages(max_mapnr
);
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
) {
155 if (virt_to_phys ((void *)tmp
) >= mach_max_dma_address
)
156 clear_bit(PG_DMA
, &mem_map
[MAP_NR(tmp
)].flags
);
159 if (PageReserved(mem_map
+MAP_NR(tmp
))) {
160 if (tmp
>= (unsigned long)&_text
161 && tmp
< (unsigned long)&_etext
)
163 else if (tmp
>= (unsigned long) &__init_begin
164 && tmp
< (unsigned long) &__init_end
)
171 set_page_count(mem_map
+MAP_NR(tmp
), 1);
172 #ifdef CONFIG_BLK_DEV_INITRD
174 (tmp
< (initrd_start
& PAGE_MASK
) || tmp
>= initrd_end
))
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 */
190 init_pointer_table((unsigned long)zero_pgtable
);
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);
210 printk ("Freeing initrd memory: %ldk freed\n", (end
- start
) >> 10);
214 void si_meminfo(struct sysinfo
*val
)
219 val
->totalram
= totalram_pages
;
221 val
->freeram
= nr_free_pages();
222 val
->bufferram
= atomic_read(&buffermem_pages
);
224 if (PageReserved(mem_map
+i
))
227 if (!page_count(mem_map
+i
))
229 val
->sharedram
+= page_count(mem_map
+i
) - 1;