]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/m68k/mm/init.c
m68k: merge MMU and non-MMU versions of mm/init.c
[mirror_ubuntu-bionic-kernel.git] / arch / m68k / mm / init.c
CommitLineData
dd1cb3a7
GU
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/*
36 * ZERO_PAGE is a special page that is used for zero-initialized
37 * data and COW.
38 */
39void *empty_zero_page;
40EXPORT_SYMBOL(empty_zero_page);
41
66d857b0 42#ifdef CONFIG_MMU
dd1cb3a7
GU
43
44pg_data_t pg_data_map[MAX_NUMNODES];
45EXPORT_SYMBOL(pg_data_map);
46
47int m68k_virt_to_node_shift;
48
49#ifndef CONFIG_SINGLE_MEMORY_CHUNK
50pg_data_t *pg_data_table[65];
51EXPORT_SYMBOL(pg_data_table);
52#endif
53
54void __init m68k_setup_node(int node)
55{
56#ifndef CONFIG_SINGLE_MEMORY_CHUNK
57 struct mem_info *info = m68k_memory + node;
58 int i, end;
59
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++) {
63 if (pg_data_table[i])
64 printk("overlap at %u for chunk %u\n", i, node);
65 pg_data_table[i] = pg_data_map + node;
66 }
67#endif
68 pg_data_map[node].bdata = bootmem_node_data + node;
69 node_set_online(node);
70}
71
72extern void init_pointer_table(unsigned long ptable);
73extern pmd_t *zero_pgtable;
74
75#else /* CONFIG_MMU */
76
77/*
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.
82 */
83void __init paging_init(void)
84{
85 /*
86 * Make sure start_mem is page aligned, otherwise bootmem and
87 * page_alloc get different views of the world.
88 */
89 unsigned long end_mem = memory_end & PAGE_MASK;
90 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
91
92 high_memory = (void *) end_mem;
93
94 empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
95 memset(empty_zero_page, 0, PAGE_SIZE);
96
97 /*
98 * Set up SFC/DFC registers (user data space).
99 */
100 set_fs (USER_DS);
101
102 zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
103 free_area_init(zones_size);
104}
105
106void free_initmem(void)
107{
108#ifdef CONFIG_RAMKERNEL
109 unsigned long addr;
110
111 /*
112 * The following code should be cool even if these sections
113 * are not page aligned.
114 */
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));
120 free_page(addr);
121 totalram_pages++;
122 }
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));
127#endif
128}
129
130#endif /* CONFIG_MMU */
131
132#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
133#define VECTORS &vectors[0]
66d857b0 134#else
dd1cb3a7
GU
135#define VECTORS _ramvec
136#endif
137
138void __init print_memmap(void)
139{
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)
144
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));
162}
163
164void __init mem_init(void)
165{
166 pg_data_t *pgdat;
167 int codepages = 0;
168 int datapages = 0;
169 int initpages = 0;
170 int i;
171
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;
176
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);
181
182 if (!PageReserved(page))
183 continue;
184 if (addr >= _text &&
185 addr < _etext)
186 codepages++;
187 else if (addr >= __init_begin &&
188 addr < __init_end)
189 initpages++;
190 else
191 datapages++;
192 }
193 }
194
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]));
201 }
202
203 /* insert also pointer table that we used to unmap the zero page */
204 if (zero_pgtable)
205 init_pointer_table((unsigned long)zero_pgtable);
206#endif
207
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));
214 print_memmap();
215}
216
217#ifdef CONFIG_BLK_DEV_INITRD
218void free_initrd_mem(unsigned long start, unsigned long end)
219{
220 int pages = 0;
221 for (; start < end; start += PAGE_SIZE) {
222 ClearPageReserved(virt_to_page(start));
223 init_page_count(virt_to_page(start));
224 free_page(start);
225 totalram_pages++;
226 pages++;
227 }
228 pr_notice("Freeing initrd memory: %dk freed\n",
229 pages << (PAGE_SHIFT - 10));
230}
1da177e4 231#endif