1 /*
2 * linux/arch/m68k/mm/init.c
3 *
4 * Copyright (C) 1995 Hamish Macdonald
5 *
6 * Contains common initialization routines, specific init code moved
7 * to motorola.c and sun3mmu.c
8 */
9
10 #include <linux/module.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 #include <linux/gfp.h>
21
22 #include <asm/setup.h>
23 #include <asm/uaccess.h>
24 #include <asm/page.h>
25 #include <asm/pgalloc.h>
26 #include <asm/traps.h>
27 #include <asm/machdep.h>
28 #include <asm/io.h>
29 #ifdef CONFIG_ATARI
30 #include <asm/atari_stram.h>
31 #endif
32 #include <asm/sections.h>
33 #include <asm/tlb.h>
34
35 pg_data_t pg_data_map[MAX_NUMNODES];
36 EXPORT_SYMBOL(pg_data_map);
37
38 int m68k_virt_to_node_shift;
39
40 #ifndef CONFIG_SINGLE_MEMORY_CHUNK
41 pg_data_t *pg_data_table[65];
42 EXPORT_SYMBOL(pg_data_table);
43 #endif
44
m68k_setup_node(int node)45 void __init m68k_setup_node(int node)
46 {
47 #ifndef CONFIG_SINGLE_MEMORY_CHUNK
48 struct mem_info *info = m68k_memory + node;
49 int i, end;
50
51 i = (unsigned long)phys_to_virt(info->addr) >> __virt_to_node_shift();
52 end = (unsigned long)phys_to_virt(info->addr + info->size - 1) >> __virt_to_node_shift();
53 for (; i <= end; i++) {
54 if (pg_data_table[i])
55 printk("overlap at %u for chunk %u\n", i, node);
56 pg_data_table[i] = pg_data_map + node;
57 }
58 #endif
59 pg_data_map[node].bdata = bootmem_node_data + node;
60 node_set_online(node);
61 }
62
63
64 /*
65 * ZERO_PAGE is a special page that is used for zero-initialized
66 * data and COW.
67 */
68
69 void *empty_zero_page;
70 EXPORT_SYMBOL(empty_zero_page);
71
72 extern void init_pointer_table(unsigned long ptable);
73
74 /* References to section boundaries */
75
76 extern pmd_t *zero_pgtable;
77
78 #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
79 #define VECTORS &vectors[0]
80 #else
81 #define VECTORS _ramvec
82 #endif
83
print_memmap(void)84 void __init print_memmap(void)
85 {
86 #define UL(x) ((unsigned long) (x))
87 #define MLK(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 10
88 #define MLM(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 20
89 #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), 1024)
90
91 pr_notice("Virtual kernel memory layout:\n"
92 " vector : 0x%08lx - 0x%08lx (%4ld KiB)\n"
93 " kmap : 0x%08lx - 0x%08lx (%4ld MiB)\n"
94 " vmalloc : 0x%08lx - 0x%08lx (%4ld MiB)\n"
95 " lowmem : 0x%08lx - 0x%08lx (%4ld MiB)\n"
96 " .init : 0x%p" " - 0x%p" " (%4d KiB)\n"
97 " .text : 0x%p" " - 0x%p" " (%4d KiB)\n"
98 " .data : 0x%p" " - 0x%p" " (%4d KiB)\n"
99 " .bss : 0x%p" " - 0x%p" " (%4d KiB)\n",
100 MLK(VECTORS, VECTORS + 256),
101 MLM(KMAP_START, KMAP_END),
102 MLM(VMALLOC_START, VMALLOC_END),
103 MLM(PAGE_OFFSET, (unsigned long)high_memory),
104 MLK_ROUNDUP(__init_begin, __init_end),
105 MLK_ROUNDUP(_stext, _etext),
106 MLK_ROUNDUP(_sdata, _edata),
107 MLK_ROUNDUP(_sbss, _ebss));
108 }
109
mem_init(void)110 void __init mem_init(void)
111 {
112 pg_data_t *pgdat;
113 int codepages = 0;
114 int datapages = 0;
115 int initpages = 0;
116 int i;
117
118 /* this will put all memory onto the freelists */
119 totalram_pages = num_physpages = 0;
120 for_each_online_pgdat(pgdat) {
121 num_physpages += pgdat->node_present_pages;
122
123 totalram_pages += free_all_bootmem_node(pgdat);
124 for (i = 0; i < pgdat->node_spanned_pages; i++) {
125 struct page *page = pgdat->node_mem_map + i;
126 char *addr = page_to_virt(page);
127
128 if (!PageReserved(page))
129 continue;
130 if (addr >= _text &&
131 addr < _etext)
132 codepages++;
133 else if (addr >= __init_begin &&
134 addr < __init_end)
135 initpages++;
136 else
137 datapages++;
138 }
139 }
140
141 #if !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE)
142 /* insert pointer tables allocated so far into the tablelist */
143 init_pointer_table((unsigned long)kernel_pg_dir);
144 for (i = 0; i < PTRS_PER_PGD; i++) {
145 if (pgd_present(kernel_pg_dir[i]))
146 init_pointer_table(__pgd_page(kernel_pg_dir[i]));
147 }
148
149 /* insert also pointer table that we used to unmap the zero page */
150 if (zero_pgtable)
151 init_pointer_table((unsigned long)zero_pgtable);
152 #endif
153
154 printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
155 nr_free_pages() << (PAGE_SHIFT-10),
156 totalram_pages << (PAGE_SHIFT-10),
157 codepages << (PAGE_SHIFT-10),
158 datapages << (PAGE_SHIFT-10),
159 initpages << (PAGE_SHIFT-10));
160 print_memmap();
161 }
162
163 #ifdef CONFIG_BLK_DEV_INITRD
free_initrd_mem(unsigned long start,unsigned long end)164 void free_initrd_mem(unsigned long start, unsigned long end)
165 {
166 int pages = 0;
167 for (; start < end; start += PAGE_SIZE) {
168 ClearPageReserved(virt_to_page(start));
169 init_page_count(virt_to_page(start));
170 free_page(start);
171 totalram_pages++;
172 pages++;
173 }
174 printk ("Freeing initrd memory: %dk freed\n", pages);
175 }
176 #endif
177