aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Ungerer <gerg@uclinux.org>2012-10-24 08:36:27 -0400
committerGeert Uytterhoeven <geert@linux-m68k.org>2012-11-14 02:50:56 -0500
commitdd1cb3a7c43508c29e17836628090c0735bd3137 (patch)
tree9748ca968ed790ea1dbe513fc2c754ef4850b591
parent20e42aede9e7b78c2ffd8a03501e3090fbb78811 (diff)
m68k: merge MMU and non-MMU versions of mm/init.c
Some of the code in the existing mm/init_mm.c and mm/init_no.c files is the same, and if we merge them back to a single file we can save some code duplication. Although the old mem_init() code for non-MMU was a little different than the MMU version, it turns out we can use the same code. So I now we just use the MMU mem_init() code for all. It also means we now get identical console info messages for this code on kernel boot up. So merge the two files back into a single file. Signed-off-by: Greg Ungerer <gerg@uclinux.org> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
-rw-r--r--arch/m68k/mm/init.c230
-rw-r--r--arch/m68k/mm/init_mm.c176
-rw-r--r--arch/m68k/mm/init_no.c145
3 files changed, 228 insertions, 323 deletions
diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
index 27b5ce089a34..b0f201a409f3 100644
--- a/arch/m68k/mm/init.c
+++ b/arch/m68k/mm/init.c
@@ -1,5 +1,231 @@
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
1#ifdef CONFIG_MMU 42#ifdef CONFIG_MMU
2#include "init_mm.c" 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]
3#else 134#else
4#include "init_no.c" 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}
5#endif 231#endif
diff --git a/arch/m68k/mm/init_mm.c b/arch/m68k/mm/init_mm.c
deleted file mode 100644
index 282f9de68966..000000000000
--- a/arch/m68k/mm/init_mm.c
+++ /dev/null
@@ -1,176 +0,0 @@
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
35pg_data_t pg_data_map[MAX_NUMNODES];
36EXPORT_SYMBOL(pg_data_map);
37
38int m68k_virt_to_node_shift;
39
40#ifndef CONFIG_SINGLE_MEMORY_CHUNK
41pg_data_t *pg_data_table[65];
42EXPORT_SYMBOL(pg_data_table);
43#endif
44
45void __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
69void *empty_zero_page;
70EXPORT_SYMBOL(empty_zero_page);
71
72extern void init_pointer_table(unsigned long ptable);
73
74/* References to section boundaries */
75
76extern 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
84void __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(__bss_start, __bss_stop));
108}
109
110void __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
164void 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
diff --git a/arch/m68k/mm/init_no.c b/arch/m68k/mm/init_no.c
deleted file mode 100644
index 688e3664aea0..000000000000
--- a/arch/m68k/mm/init_no.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 * linux/arch/m68knommu/mm/init.c
3 *
4 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
5 * Kenneth Albanowski <kjahds@kjahds.com>,
6 * Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
7 *
8 * Based on:
9 *
10 * linux/arch/m68k/mm/init.c
11 *
12 * Copyright (C) 1995 Hamish Macdonald
13 *
14 * JAN/1999 -- hacked to support ColdFire (gerg@snapgear.com)
15 * DEC/2000 -- linux 2.4 support <davidm@snapgear.com>
16 */
17
18#include <linux/signal.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/string.h>
23#include <linux/types.h>
24#include <linux/ptrace.h>
25#include <linux/mman.h>
26#include <linux/mm.h>
27#include <linux/swap.h>
28#include <linux/init.h>
29#include <linux/highmem.h>
30#include <linux/pagemap.h>
31#include <linux/bootmem.h>
32#include <linux/gfp.h>
33
34#include <asm/setup.h>
35#include <asm/sections.h>
36#include <asm/segment.h>
37#include <asm/page.h>
38#include <asm/pgtable.h>
39#include <asm/machdep.h>
40
41/*
42 * ZERO_PAGE is a special page that is used for zero-initialized
43 * data and COW.
44 */
45void *empty_zero_page;
46
47/*
48 * paging_init() continues the virtual memory environment setup which
49 * was begun by the code in arch/head.S.
50 * The parameters are pointers to where to stick the starting and ending
51 * addresses of available kernel virtual memory.
52 */
53void __init paging_init(void)
54{
55 /*
56 * Make sure start_mem is page aligned, otherwise bootmem and
57 * page_alloc get different views of the world.
58 */
59 unsigned long end_mem = memory_end & PAGE_MASK;
60 unsigned long zones_size[MAX_NR_ZONES] = {0, };
61
62 empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
63 memset(empty_zero_page, 0, PAGE_SIZE);
64
65 /*
66 * Set up SFC/DFC registers (user data space).
67 */
68 set_fs (USER_DS);
69
70 zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
71 free_area_init(zones_size);
72}
73
74void __init mem_init(void)
75{
76 int codek = 0, datak = 0, initk = 0;
77 unsigned long tmp;
78 unsigned long len = _ramend - _rambase;
79 unsigned long start_mem = memory_start; /* DAVIDM - these must start at end of kernel */
80 unsigned long end_mem = memory_end; /* DAVIDM - this must not include kernel stack at top */
81
82 pr_debug("Mem_init: start=%lx, end=%lx\n", start_mem, end_mem);
83
84 end_mem &= PAGE_MASK;
85 high_memory = (void *) end_mem;
86
87 start_mem = PAGE_ALIGN(start_mem);
88 max_mapnr = num_physpages = (((unsigned long) high_memory) - PAGE_OFFSET) >> PAGE_SHIFT;
89
90 /* this will put all memory onto the freelists */
91 totalram_pages = free_all_bootmem();
92
93 codek = (_etext - _stext) >> 10;
94 datak = (__bss_stop - _sdata) >> 10;
95 initk = (__init_begin - __init_end) >> 10;
96
97 tmp = nr_free_pages() << PAGE_SHIFT;
98 printk(KERN_INFO "Memory available: %luk/%luk RAM, (%dk kernel code, %dk data)\n",
99 tmp >> 10,
100 len >> 10,
101 codek,
102 datak
103 );
104}
105
106
107#ifdef CONFIG_BLK_DEV_INITRD
108void free_initrd_mem(unsigned long start, unsigned long end)
109{
110 int pages = 0;
111 for (; start < end; start += PAGE_SIZE) {
112 ClearPageReserved(virt_to_page(start));
113 init_page_count(virt_to_page(start));
114 free_page(start);
115 totalram_pages++;
116 pages++;
117 }
118 pr_notice("Freeing initrd memory: %luk freed\n",
119 pages * (PAGE_SIZE / 1024));
120}
121#endif
122
123void free_initmem(void)
124{
125#ifdef CONFIG_RAMKERNEL
126 unsigned long addr;
127 /*
128 * The following code should be cool even if these sections
129 * are not page aligned.
130 */
131 addr = PAGE_ALIGN((unsigned long) __init_begin);
132 /* next to check that the page we free is not a partial page */
133 for (; addr + PAGE_SIZE < ((unsigned long) __init_end); addr += PAGE_SIZE) {
134 ClearPageReserved(virt_to_page(addr));
135 init_page_count(virt_to_page(addr));
136 free_page(addr);
137 totalram_pages++;
138 }
139 pr_notice("Freeing unused kernel memory: %luk freed (0x%x - 0x%x)\n",
140 (addr - PAGE_ALIGN((unsigned long) __init_begin)) >> 10,
141 (int)(PAGE_ALIGN((unsigned long) __init_begin)),
142 (int)(addr - PAGE_SIZE));
143#endif
144}
145