blob: 79f5f94d4800649930bc581d67db4241246999c9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Roman Zippel12d810c2007-05-31 00:40:54 -070010#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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
21#include <asm/setup.h>
22#include <asm/uaccess.h>
23#include <asm/page.h>
24#include <asm/pgalloc.h>
25#include <asm/system.h>
26#include <asm/machdep.h>
27#include <asm/io.h>
28#ifdef CONFIG_ATARI
29#include <asm/atari_stram.h>
30#endif
31#include <asm/tlb.h>
32
33DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
34
Roman Zippel12d810c2007-05-31 00:40:54 -070035pg_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
Al Viro66a3f822007-07-20 04:33:28 +010045void __init m68k_setup_node(int node)
Roman Zippel12d810c2007-05-31 00:40:54 -070046{
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
Johannes Weinerb61bfa32008-07-23 21:26:55 -070059 pg_data_map[node].bdata = bootmem_node_data + node;
Roman Zippel12d810c2007-05-31 00:40:54 -070060 node_set_online(node);
61}
62
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064/*
65 * ZERO_PAGE is a special page that is used for zero-initialized
66 * data and COW.
67 */
68
69void *empty_zero_page;
Aneesh Kumar K.V5fcf4302008-04-29 08:11:12 -040070EXPORT_SYMBOL(empty_zero_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72void show_mem(void)
73{
Roman Zippel12d810c2007-05-31 00:40:54 -070074 pg_data_t *pgdat;
75 int free = 0, total = 0, reserved = 0, shared = 0;
76 int cached = 0;
77 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Roman Zippel12d810c2007-05-31 00:40:54 -070079 printk("\nMem-info:\n");
80 show_free_areas();
Roman Zippel12d810c2007-05-31 00:40:54 -070081 for_each_online_pgdat(pgdat) {
82 for (i = 0; i < pgdat->node_spanned_pages; i++) {
83 struct page *page = pgdat->node_mem_map + i;
84 total++;
85 if (PageReserved(page))
86 reserved++;
87 else if (PageSwapCache(page))
88 cached++;
89 else if (!page_count(page))
90 free++;
91 else
92 shared += page_count(page) - 1;
93 }
94 }
95 printk("%d pages of RAM\n",total);
96 printk("%d free pages\n",free);
97 printk("%d reserved pages\n",reserved);
98 printk("%d pages shared\n",shared);
99 printk("%d pages swap cached\n",cached);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102extern void init_pointer_table(unsigned long ptable);
103
104/* References to section boundaries */
105
Roman Zippel12d810c2007-05-31 00:40:54 -0700106extern char _text[], _etext[];
107extern char __init_begin[], __init_end[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109extern pmd_t *zero_pgtable;
110
111void __init mem_init(void)
112{
Roman Zippel12d810c2007-05-31 00:40:54 -0700113 pg_data_t *pgdat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 int codepages = 0;
115 int datapages = 0;
116 int initpages = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119#ifdef CONFIG_ATARI
120 if (MACH_IS_ATARI)
121 atari_stram_mem_init_hook();
122#endif
123
124 /* this will put all memory onto the freelists */
Roman Zippel12d810c2007-05-31 00:40:54 -0700125 totalram_pages = num_physpages = 0;
126 for_each_online_pgdat(pgdat) {
127 num_physpages += pgdat->node_present_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Roman Zippel12d810c2007-05-31 00:40:54 -0700129 totalram_pages += free_all_bootmem_node(pgdat);
130 for (i = 0; i < pgdat->node_spanned_pages; i++) {
131 struct page *page = pgdat->node_mem_map + i;
132 char *addr = page_to_virt(page);
133
134 if (!PageReserved(page))
135 continue;
136 if (addr >= _text &&
137 addr < _etext)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 codepages++;
Roman Zippel12d810c2007-05-31 00:40:54 -0700139 else if (addr >= __init_begin &&
140 addr < __init_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 initpages++;
142 else
143 datapages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145 }
146
147#ifndef CONFIG_SUN3
148 /* insert pointer tables allocated so far into the tablelist */
149 init_pointer_table((unsigned long)kernel_pg_dir);
150 for (i = 0; i < PTRS_PER_PGD; i++) {
151 if (pgd_present(kernel_pg_dir[i]))
152 init_pointer_table(__pgd_page(kernel_pg_dir[i]));
153 }
154
155 /* insert also pointer table that we used to unmap the zero page */
156 if (zero_pgtable)
157 init_pointer_table((unsigned long)zero_pgtable);
158#endif
159
160 printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
161 (unsigned long)nr_free_pages() << (PAGE_SHIFT-10),
Roman Zippel12d810c2007-05-31 00:40:54 -0700162 totalram_pages << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 codepages << (PAGE_SHIFT-10),
164 datapages << (PAGE_SHIFT-10),
165 initpages << (PAGE_SHIFT-10));
166}
167
168#ifdef CONFIG_BLK_DEV_INITRD
169void free_initrd_mem(unsigned long start, unsigned long end)
170{
171 int pages = 0;
172 for (; start < end; start += PAGE_SIZE) {
173 ClearPageReserved(virt_to_page(start));
Nick Piggin7835e982006-03-22 00:08:40 -0800174 init_page_count(virt_to_page(start));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 free_page(start);
176 totalram_pages++;
177 pages++;
178 }
179 printk ("Freeing initrd memory: %dk freed\n", pages);
180}
181#endif