blob: 81bb08ceec18372e16110a86fe38b7ca441ba383 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern void init_pointer_table(unsigned long ptable);
73
74/* References to section boundaries */
75
Roman Zippel12d810c2007-05-31 00:40:54 -070076extern char _text[], _etext[];
77extern char __init_begin[], __init_end[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79extern pmd_t *zero_pgtable;
80
81void __init mem_init(void)
82{
Roman Zippel12d810c2007-05-31 00:40:54 -070083 pg_data_t *pgdat;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 int codepages = 0;
85 int datapages = 0;
86 int initpages = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#ifdef CONFIG_ATARI
90 if (MACH_IS_ATARI)
91 atari_stram_mem_init_hook();
92#endif
93
94 /* this will put all memory onto the freelists */
Roman Zippel12d810c2007-05-31 00:40:54 -070095 totalram_pages = num_physpages = 0;
96 for_each_online_pgdat(pgdat) {
97 num_physpages += pgdat->node_present_pages;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Roman Zippel12d810c2007-05-31 00:40:54 -070099 totalram_pages += free_all_bootmem_node(pgdat);
100 for (i = 0; i < pgdat->node_spanned_pages; i++) {
101 struct page *page = pgdat->node_mem_map + i;
102 char *addr = page_to_virt(page);
103
104 if (!PageReserved(page))
105 continue;
106 if (addr >= _text &&
107 addr < _etext)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 codepages++;
Roman Zippel12d810c2007-05-31 00:40:54 -0700109 else if (addr >= __init_begin &&
110 addr < __init_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 initpages++;
112 else
113 datapages++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115 }
116
117#ifndef CONFIG_SUN3
118 /* insert pointer tables allocated so far into the tablelist */
119 init_pointer_table((unsigned long)kernel_pg_dir);
120 for (i = 0; i < PTRS_PER_PGD; i++) {
121 if (pgd_present(kernel_pg_dir[i]))
122 init_pointer_table(__pgd_page(kernel_pg_dir[i]));
123 }
124
125 /* insert also pointer table that we used to unmap the zero page */
126 if (zero_pgtable)
127 init_pointer_table((unsigned long)zero_pgtable);
128#endif
129
130 printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
131 (unsigned long)nr_free_pages() << (PAGE_SHIFT-10),
Roman Zippel12d810c2007-05-31 00:40:54 -0700132 totalram_pages << (PAGE_SHIFT-10),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 codepages << (PAGE_SHIFT-10),
134 datapages << (PAGE_SHIFT-10),
135 initpages << (PAGE_SHIFT-10));
136}
137
138#ifdef CONFIG_BLK_DEV_INITRD
139void free_initrd_mem(unsigned long start, unsigned long end)
140{
141 int pages = 0;
142 for (; start < end; start += PAGE_SIZE) {
143 ClearPageReserved(virt_to_page(start));
Nick Piggin7835e982006-03-22 00:08:40 -0800144 init_page_count(virt_to_page(start));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 free_page(start);
146 totalram_pages++;
147 pages++;
148 }
149 printk ("Freeing initrd memory: %dk freed\n", pages);
150}
151#endif