[ALSA] version 1.0.11rc4
[sfrench/cifs-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/config.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 /*
36  * ZERO_PAGE is a special page that is used for zero-initialized
37  * data and COW.
38  */
39
40 void *empty_zero_page;
41
42 void show_mem(void)
43 {
44     unsigned long i;
45     int free = 0, total = 0, reserved = 0, shared = 0;
46     int cached = 0;
47
48     printk("\nMem-info:\n");
49     show_free_areas();
50     printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
51     i = max_mapnr;
52     while (i-- > 0) {
53         total++;
54         if (PageReserved(mem_map+i))
55             reserved++;
56         else if (PageSwapCache(mem_map+i))
57             cached++;
58         else if (!page_count(mem_map+i))
59             free++;
60         else
61             shared += page_count(mem_map+i) - 1;
62     }
63     printk("%d pages of RAM\n",total);
64     printk("%d free pages\n",free);
65     printk("%d reserved pages\n",reserved);
66     printk("%d pages shared\n",shared);
67     printk("%d pages swap cached\n",cached);
68 }
69
70 extern void init_pointer_table(unsigned long ptable);
71
72 /* References to section boundaries */
73
74 extern char _text, _etext, _edata, __bss_start, _end;
75 extern char __init_begin, __init_end;
76
77 extern pmd_t *zero_pgtable;
78
79 void __init mem_init(void)
80 {
81         int codepages = 0;
82         int datapages = 0;
83         int initpages = 0;
84         unsigned long tmp;
85 #ifndef CONFIG_SUN3
86         int i;
87 #endif
88
89         max_mapnr = num_physpages = (((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT);
90
91 #ifdef CONFIG_ATARI
92         if (MACH_IS_ATARI)
93                 atari_stram_mem_init_hook();
94 #endif
95
96         /* this will put all memory onto the freelists */
97         totalram_pages = free_all_bootmem();
98
99         for (tmp = PAGE_OFFSET ; tmp < (unsigned long)high_memory; tmp += PAGE_SIZE) {
100                 if (PageReserved(virt_to_page(tmp))) {
101                         if (tmp >= (unsigned long)&_text
102                             && tmp < (unsigned long)&_etext)
103                                 codepages++;
104                         else if (tmp >= (unsigned long) &__init_begin
105                                  && tmp < (unsigned long) &__init_end)
106                                 initpages++;
107                         else
108                                 datapages++;
109                         continue;
110                 }
111         }
112
113 #ifndef CONFIG_SUN3
114         /* insert pointer tables allocated so far into the tablelist */
115         init_pointer_table((unsigned long)kernel_pg_dir);
116         for (i = 0; i < PTRS_PER_PGD; i++) {
117                 if (pgd_present(kernel_pg_dir[i]))
118                         init_pointer_table(__pgd_page(kernel_pg_dir[i]));
119         }
120
121         /* insert also pointer table that we used to unmap the zero page */
122         if (zero_pgtable)
123                 init_pointer_table((unsigned long)zero_pgtable);
124 #endif
125
126         printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n",
127                (unsigned long)nr_free_pages() << (PAGE_SHIFT-10),
128                max_mapnr << (PAGE_SHIFT-10),
129                codepages << (PAGE_SHIFT-10),
130                datapages << (PAGE_SHIFT-10),
131                initpages << (PAGE_SHIFT-10));
132 }
133
134 #ifdef CONFIG_BLK_DEV_INITRD
135 void free_initrd_mem(unsigned long start, unsigned long end)
136 {
137         int pages = 0;
138         for (; start < end; start += PAGE_SIZE) {
139                 ClearPageReserved(virt_to_page(start));
140                 set_page_count(virt_to_page(start), 1);
141                 free_page(start);
142                 totalram_pages++;
143                 pages++;
144         }
145         printk ("Freeing initrd memory: %dk freed\n", pages);
146 }
147 #endif