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/module.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 #include <linux/gfp.h>
22 #include <asm/setup.h>
23 #include <asm/uaccess.h>
25 #include <asm/pgalloc.h>
26 #include <asm/traps.h>
27 #include <asm/machdep.h>
30 #include <asm/atari_stram.h>
32 #include <asm/sections.h>
36 * ZERO_PAGE is a special page that is used for zero-initialized
39 void *empty_zero_page;
40 EXPORT_SYMBOL(empty_zero_page);
44 pg_data_t pg_data_map[MAX_NUMNODES];
45 EXPORT_SYMBOL(pg_data_map);
47 int m68k_virt_to_node_shift;
49 #ifndef CONFIG_SINGLE_MEMORY_CHUNK
50 pg_data_t *pg_data_table[65];
51 EXPORT_SYMBOL(pg_data_table);
54 void __init m68k_setup_node(int node)
56 #ifndef CONFIG_SINGLE_MEMORY_CHUNK
57 struct mem_info *info = m68k_memory + node;
60 i = (unsigned long)phys_to_virt(info->addr) >> __virt_to_node_shift();
61 end = (unsigned long)phys_to_virt(info->addr + info->size - 1) >> __virt_to_node_shift();
62 for (; i <= end; i++) {
64 printk("overlap at %u for chunk %u\n", i, node);
65 pg_data_table[i] = pg_data_map + node;
68 pg_data_map[node].bdata = bootmem_node_data + node;
69 node_set_online(node);
72 extern void init_pointer_table(unsigned long ptable);
73 extern pmd_t *zero_pgtable;
75 #else /* CONFIG_MMU */
78 * paging_init() continues the virtual memory environment setup which
79 * was begun by the code in arch/head.S.
80 * The parameters are pointers to where to stick the starting and ending
81 * addresses of available kernel virtual memory.
83 void __init paging_init(void)
86 * Make sure start_mem is page aligned, otherwise bootmem and
87 * page_alloc get different views of the world.
89 unsigned long end_mem = memory_end & PAGE_MASK;
90 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
92 high_memory = (void *) end_mem;
94 empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
95 memset(empty_zero_page, 0, PAGE_SIZE);
98 * Set up SFC/DFC registers (user data space).
102 zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
103 free_area_init(zones_size);
106 void free_initmem(void)
108 #ifdef CONFIG_RAMKERNEL
112 * The following code should be cool even if these sections
113 * are not page aligned.
115 addr = PAGE_ALIGN((unsigned long) __init_begin);
116 /* next to check that the page we free is not a partial page */
117 for (; addr + PAGE_SIZE < ((unsigned long) __init_end); addr += PAGE_SIZE) {
118 ClearPageReserved(virt_to_page(addr));
119 init_page_count(virt_to_page(addr));
123 pr_notice("Freeing unused kernel memory: %luk freed (0x%x - 0x%x)\n",
124 (addr - PAGE_ALIGN((unsigned long) __init_begin)) >> 10,
125 (int)(PAGE_ALIGN((unsigned long) __init_begin)),
126 (int)(addr - PAGE_SIZE));
130 #endif /* CONFIG_MMU */
132 #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
133 #define VECTORS &vectors[0]
135 #define VECTORS _ramvec
138 void __init print_memmap(void)
140 #define UL(x) ((unsigned long) (x))
141 #define MLK(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 10
142 #define MLM(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 20
143 #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), 1024)
145 pr_notice("Virtual kernel memory layout:\n"
146 " vector : 0x%08lx - 0x%08lx (%4ld KiB)\n"
147 " kmap : 0x%08lx - 0x%08lx (%4ld MiB)\n"
148 " vmalloc : 0x%08lx - 0x%08lx (%4ld MiB)\n"
149 " lowmem : 0x%08lx - 0x%08lx (%4ld MiB)\n"
150 " .init : 0x%p" " - 0x%p" " (%4d KiB)\n"
151 " .text : 0x%p" " - 0x%p" " (%4d KiB)\n"
152 " .data : 0x%p" " - 0x%p" " (%4d KiB)\n"
153 " .bss : 0x%p" " - 0x%p" " (%4d KiB)\n",
154 MLK(VECTORS, VECTORS + 256),
155 MLM(KMAP_START, KMAP_END),
156 MLM(VMALLOC_START, VMALLOC_END),
157 MLM(PAGE_OFFSET, (unsigned long)high_memory),
158 MLK_ROUNDUP(__init_begin, __init_end),
159 MLK_ROUNDUP(_stext, _etext),
160 MLK_ROUNDUP(_sdata, _edata),
161 MLK_ROUNDUP(__bss_start, __bss_stop));
164 void __init mem_init(void)
172 /* this will put all memory onto the freelists */
173 totalram_pages = num_physpages = 0;
174 for_each_online_pgdat(pgdat) {
175 num_physpages += pgdat->node_present_pages;
177 totalram_pages += free_all_bootmem_node(pgdat);
178 for (i = 0; i < pgdat->node_spanned_pages; i++) {
179 struct page *page = pgdat->node_mem_map + i;
180 char *addr = page_to_virt(page);
182 if (!PageReserved(page))
187 else if (addr >= __init_begin &&
195 #if !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE)
196 /* insert pointer tables allocated so far into the tablelist */
197 init_pointer_table((unsigned long)kernel_pg_dir);
198 for (i = 0; i < PTRS_PER_PGD; i++) {
199 if (pgd_present(kernel_pg_dir[i]))
200 init_pointer_table(__pgd_page(kernel_pg_dir[i]));
203 /* insert also pointer table that we used to unmap the zero page */
205 init_pointer_table((unsigned long)zero_pgtable);
208 pr_info("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
209 nr_free_pages() << (PAGE_SHIFT-10),
210 totalram_pages << (PAGE_SHIFT-10),
211 codepages << (PAGE_SHIFT-10),
212 datapages << (PAGE_SHIFT-10),
213 initpages << (PAGE_SHIFT-10));
217 #ifdef CONFIG_BLK_DEV_INITRD
218 void free_initrd_mem(unsigned long start, unsigned long end)
221 for (; start < end; start += PAGE_SIZE) {
222 ClearPageReserved(virt_to_page(start));
223 init_page_count(virt_to_page(start));
228 pr_notice("Freeing initrd memory: %dk freed\n",
229 pages << (PAGE_SHIFT - 10));