mm: move bootmem descriptors definition to a single place
[linux-2.6.git] / arch / m68k / mm / init.c
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
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
33 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
34
35 pg_data_t pg_data_map[MAX_NUMNODES];
36 EXPORT_SYMBOL(pg_data_map);
37
38 int m68k_virt_to_node_shift;
39
40 #ifndef CONFIG_SINGLE_MEMORY_CHUNK
41 pg_data_t *pg_data_table[65];
42 EXPORT_SYMBOL(pg_data_table);
43 #endif
44
45 void __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
69 void *empty_zero_page;
70 EXPORT_SYMBOL(empty_zero_page);
71
72 void show_mem(void)
73 {
74         pg_data_t *pgdat;
75         int free = 0, total = 0, reserved = 0, shared = 0;
76         int cached = 0;
77         int i;
78
79         printk("\nMem-info:\n");
80         show_free_areas();
81         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);
100 }
101
102 extern void init_pointer_table(unsigned long ptable);
103
104 /* References to section boundaries */
105
106 extern char _text[], _etext[];
107 extern char __init_begin[], __init_end[];
108
109 extern pmd_t *zero_pgtable;
110
111 void __init mem_init(void)
112 {
113         pg_data_t *pgdat;
114         int codepages = 0;
115         int datapages = 0;
116         int initpages = 0;
117         int i;
118
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 */
125         totalram_pages = num_physpages = 0;
126         for_each_online_pgdat(pgdat) {
127                 num_physpages += pgdat->node_present_pages;
128
129                 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)
138                                 codepages++;
139                         else if (addr >= __init_begin &&
140                                  addr < __init_end)
141                                 initpages++;
142                         else
143                                 datapages++;
144                 }
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),
162                totalram_pages << (PAGE_SHIFT-10),
163                codepages << (PAGE_SHIFT-10),
164                datapages << (PAGE_SHIFT-10),
165                initpages << (PAGE_SHIFT-10));
166 }
167
168 #ifdef CONFIG_BLK_DEV_INITRD
169 void 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));
174                 init_page_count(virt_to_page(start));
175                 free_page(start);
176                 totalram_pages++;
177                 pages++;
178         }
179         printk ("Freeing initrd memory: %dk freed\n", pages);
180 }
181 #endif