blob: f0e05bce92f2533ee8dc78ade768595d825646df [file] [log] [blame]
Greg Ungererdd1cb3a2012-10-24 22:36:27 +10001/*
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
Greg Ungerer66d857b2011-03-22 13:39:27 +100042#ifdef CONFIG_MMU
Greg Ungererdd1cb3a2012-10-24 22:36:27 +100043
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
Greg Ungererf50bf882012-10-23 13:40:36 +1000106#endif /* CONFIG_MMU */
107
Greg Ungererdd1cb3a2012-10-24 22:36:27 +1000108void free_initmem(void)
109{
Greg Ungererf50bf882012-10-23 13:40:36 +1000110#ifndef CONFIG_MMU_SUN3
Greg Ungererdd1cb3a2012-10-24 22:36:27 +1000111 unsigned long addr;
112
Greg Ungererf50bf882012-10-23 13:40:36 +1000113 addr = (unsigned long) __init_begin;
114 for (; addr < ((unsigned long) __init_end); addr += PAGE_SIZE) {
Greg Ungererdd1cb3a2012-10-24 22:36:27 +1000115 ClearPageReserved(virt_to_page(addr));
116 init_page_count(virt_to_page(addr));
117 free_page(addr);
118 totalram_pages++;
119 }
120 pr_notice("Freeing unused kernel memory: %luk freed (0x%x - 0x%x)\n",
Greg Ungererf50bf882012-10-23 13:40:36 +1000121 (addr - (unsigned long) __init_begin) >> 10,
122 (unsigned int) __init_begin, (unsigned int) __init_end);
123#endif /* CONFIG_MMU_SUN3 */
Greg Ungererdd1cb3a2012-10-24 22:36:27 +1000124}
125
Greg Ungererdd1cb3a2012-10-24 22:36:27 +1000126#if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE)
127#define VECTORS &vectors[0]
Greg Ungerer66d857b2011-03-22 13:39:27 +1000128#else
Greg Ungererdd1cb3a2012-10-24 22:36:27 +1000129#define VECTORS _ramvec
130#endif
131
132void __init print_memmap(void)
133{
134#define UL(x) ((unsigned long) (x))
135#define MLK(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 10
136#define MLM(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 20
137#define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), 1024)
138
139 pr_notice("Virtual kernel memory layout:\n"
140 " vector : 0x%08lx - 0x%08lx (%4ld KiB)\n"
141 " kmap : 0x%08lx - 0x%08lx (%4ld MiB)\n"
142 " vmalloc : 0x%08lx - 0x%08lx (%4ld MiB)\n"
143 " lowmem : 0x%08lx - 0x%08lx (%4ld MiB)\n"
144 " .init : 0x%p" " - 0x%p" " (%4d KiB)\n"
145 " .text : 0x%p" " - 0x%p" " (%4d KiB)\n"
146 " .data : 0x%p" " - 0x%p" " (%4d KiB)\n"
147 " .bss : 0x%p" " - 0x%p" " (%4d KiB)\n",
148 MLK(VECTORS, VECTORS + 256),
149 MLM(KMAP_START, KMAP_END),
150 MLM(VMALLOC_START, VMALLOC_END),
151 MLM(PAGE_OFFSET, (unsigned long)high_memory),
152 MLK_ROUNDUP(__init_begin, __init_end),
153 MLK_ROUNDUP(_stext, _etext),
154 MLK_ROUNDUP(_sdata, _edata),
155 MLK_ROUNDUP(__bss_start, __bss_stop));
156}
157
158void __init mem_init(void)
159{
160 pg_data_t *pgdat;
161 int codepages = 0;
162 int datapages = 0;
163 int initpages = 0;
164 int i;
165
166 /* this will put all memory onto the freelists */
167 totalram_pages = num_physpages = 0;
168 for_each_online_pgdat(pgdat) {
169 num_physpages += pgdat->node_present_pages;
170
171 totalram_pages += free_all_bootmem_node(pgdat);
172 for (i = 0; i < pgdat->node_spanned_pages; i++) {
173 struct page *page = pgdat->node_mem_map + i;
174 char *addr = page_to_virt(page);
175
176 if (!PageReserved(page))
177 continue;
178 if (addr >= _text &&
179 addr < _etext)
180 codepages++;
181 else if (addr >= __init_begin &&
182 addr < __init_end)
183 initpages++;
184 else
185 datapages++;
186 }
187 }
188
189#if !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE)
190 /* insert pointer tables allocated so far into the tablelist */
191 init_pointer_table((unsigned long)kernel_pg_dir);
192 for (i = 0; i < PTRS_PER_PGD; i++) {
193 if (pgd_present(kernel_pg_dir[i]))
194 init_pointer_table(__pgd_page(kernel_pg_dir[i]));
195 }
196
197 /* insert also pointer table that we used to unmap the zero page */
198 if (zero_pgtable)
199 init_pointer_table((unsigned long)zero_pgtable);
200#endif
201
202 pr_info("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
203 nr_free_pages() << (PAGE_SHIFT-10),
204 totalram_pages << (PAGE_SHIFT-10),
205 codepages << (PAGE_SHIFT-10),
206 datapages << (PAGE_SHIFT-10),
207 initpages << (PAGE_SHIFT-10));
208 print_memmap();
209}
210
211#ifdef CONFIG_BLK_DEV_INITRD
212void free_initrd_mem(unsigned long start, unsigned long end)
213{
214 int pages = 0;
215 for (; start < end; start += PAGE_SIZE) {
216 ClearPageReserved(virt_to_page(start));
217 init_page_count(virt_to_page(start));
218 free_page(start);
219 totalram_pages++;
220 pages++;
221 }
222 pr_notice("Freeing initrd memory: %dk freed\n",
223 pages << (PAGE_SHIFT - 10));
224}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#endif