Merge branch 'intelfb-patches' of master.kernel.org:/pub/scm/linux/kernel/git/airlied...
[pandora-kernel.git] / arch / frv / mm / init.c
1 /* init.c: memory initialisation for FRV
2  *
3  * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  *
11  * Derived from:
12  *  - linux/arch/m68knommu/mm/init.c
13  *    - Copyright (C) 1998  D. Jeff Dionne <jeff@lineo.ca>, Kenneth Albanowski <kjahds@kjahds.com>,
14  *    - Copyright (C) 2000  Lineo, Inc.  (www.lineo.com)
15  *  - linux/arch/m68k/mm/init.c
16  *    - Copyright (C) 1995  Hamish Macdonald
17  */
18
19 #include <linux/signal.h>
20 #include <linux/sched.h>
21 #include <linux/pagemap.h>
22 #include <linux/swap.h>
23 #include <linux/mm.h>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
26 #include <linux/types.h>
27 #include <linux/bootmem.h>
28 #include <linux/highmem.h>
29
30 #include <asm/setup.h>
31 #include <asm/segment.h>
32 #include <asm/page.h>
33 #include <asm/pgtable.h>
34 #include <asm/system.h>
35 #include <asm/mmu_context.h>
36 #include <asm/virtconvert.h>
37 #include <asm/sections.h>
38 #include <asm/tlb.h>
39
40 #undef DEBUG
41
42 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
43
44 /*
45  * BAD_PAGE is the page that is used for page faults when linux
46  * is out-of-memory. Older versions of linux just did a
47  * do_exit(), but using this instead means there is less risk
48  * for a process dying in kernel mode, possibly leaving a inode
49  * unused etc..
50  *
51  * BAD_PAGETABLE is the accompanying page-table: it is initialized
52  * to point to BAD_PAGE entries.
53  *
54  * ZERO_PAGE is a special page that is used for zero-initialized
55  * data and COW.
56  */
57 static unsigned long empty_bad_page_table;
58 static unsigned long empty_bad_page;
59 unsigned long empty_zero_page;
60
61 /*****************************************************************************/
62 /*
63  *
64  */
65 void show_mem(void)
66 {
67         unsigned long i;
68         int free = 0, total = 0, reserved = 0, shared = 0;
69
70         printk("\nMem-info:\n");
71         show_free_areas();
72         i = max_mapnr;
73         while (i-- > 0) {
74                 struct page *page = &mem_map[i];
75
76                 total++;
77                 if (PageReserved(page))
78                         reserved++;
79                 else if (!page_count(page))
80                         free++;
81                 else
82                         shared += page_count(page) - 1;
83         }
84
85         printk("%d pages of RAM\n",total);
86         printk("%d free pages\n",free);
87         printk("%d reserved pages\n",reserved);
88         printk("%d pages shared\n",shared);
89
90 } /* end show_mem() */
91
92 /*****************************************************************************/
93 /*
94  * paging_init() continues the virtual memory environment setup which
95  * was begun by the code in arch/head.S.
96  * The parameters are pointers to where to stick the starting and ending
97  * addresses  of available kernel virtual memory.
98  */
99 void __init paging_init(void)
100 {
101         unsigned long zones_size[MAX_NR_ZONES] = {0, };
102
103         /* allocate some pages for kernel housekeeping tasks */
104         empty_bad_page_table    = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
105         empty_bad_page          = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
106         empty_zero_page         = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
107
108         memset((void *) empty_zero_page, 0, PAGE_SIZE);
109
110 #ifdef CONFIG_HIGHMEM
111         if (num_physpages - num_mappedpages) {
112                 pgd_t *pge;
113                 pud_t *pue;
114                 pmd_t *pme;
115
116                 pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE);
117
118                 memset(pkmap_page_table, 0, PAGE_SIZE);
119
120                 pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE);
121                 pue = pud_offset(pge, PKMAP_BASE);
122                 pme = pmd_offset(pue, PKMAP_BASE);
123                 __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE);
124         }
125 #endif
126
127         /* distribute the allocatable pages across the various zones and pass them to the allocator
128          */
129         zones_size[ZONE_DMA]     = max_low_pfn - min_low_pfn;
130         zones_size[ZONE_NORMAL]  = 0;
131 #ifdef CONFIG_HIGHMEM
132         zones_size[ZONE_HIGHMEM] = num_physpages - num_mappedpages;
133 #endif
134
135         free_area_init(zones_size);
136
137 #ifdef CONFIG_MMU
138         /* initialise init's MMU context */
139         init_new_context(&init_task, &init_mm);
140 #endif
141
142 } /* end paging_init() */
143
144 /*****************************************************************************/
145 /*
146  *
147  */
148 void __init mem_init(void)
149 {
150         unsigned long npages = (memory_end - memory_start) >> PAGE_SHIFT;
151         unsigned long tmp;
152 #ifdef CONFIG_MMU
153         unsigned long loop, pfn;
154         int datapages = 0;
155 #endif
156         int codek = 0, datak = 0;
157
158         /* this will put all memory onto the freelists */
159         totalram_pages = free_all_bootmem();
160
161 #ifdef CONFIG_MMU
162         for (loop = 0 ; loop < npages ; loop++)
163                 if (PageReserved(&mem_map[loop]))
164                         datapages++;
165
166 #ifdef CONFIG_HIGHMEM
167         for (pfn = num_physpages - 1; pfn >= num_mappedpages; pfn--) {
168                 struct page *page = &mem_map[pfn];
169
170                 ClearPageReserved(page);
171                 init_page_count(page);
172                 __free_page(page);
173                 totalram_pages++;
174         }
175 #endif
176
177         codek = ((unsigned long) &_etext - (unsigned long) &_stext) >> 10;
178         datak = datapages << (PAGE_SHIFT - 10);
179
180 #else
181         codek = (_etext - _stext) >> 10;
182         datak = 0; //(_ebss - _sdata) >> 10;
183 #endif
184
185         tmp = nr_free_pages() << PAGE_SHIFT;
186         printk("Memory available: %luKiB/%luKiB RAM, %luKiB/%luKiB ROM (%dKiB kernel code, %dKiB data)\n",
187                tmp >> 10,
188                npages << (PAGE_SHIFT - 10),
189                (rom_length > 0) ? ((rom_length >> 10) - codek) : 0,
190                rom_length >> 10,
191                codek,
192                datak
193                );
194
195 } /* end mem_init() */
196
197 /*****************************************************************************/
198 /*
199  * free the memory that was only required for initialisation
200  */
201 void __init free_initmem(void)
202 {
203 #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
204         unsigned long start, end, addr;
205
206         start = PAGE_ALIGN((unsigned long) &__init_begin);      /* round up */
207         end   = ((unsigned long) &__init_end) & PAGE_MASK;      /* round down */
208
209         /* next to check that the page we free is not a partial page */
210         for (addr = start; addr < end; addr += PAGE_SIZE) {
211                 ClearPageReserved(virt_to_page(addr));
212                 init_page_count(virt_to_page(addr));
213                 free_page(addr);
214                 totalram_pages++;
215         }
216
217         printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
218                (end - start) >> 10, start, end);
219 #endif
220 } /* end free_initmem() */
221
222 /*****************************************************************************/
223 /*
224  * free the initial ramdisk memory
225  */
226 #ifdef CONFIG_BLK_DEV_INITRD
227 void __init free_initrd_mem(unsigned long start, unsigned long end)
228 {
229         int pages = 0;
230         for (; start < end; start += PAGE_SIZE) {
231                 ClearPageReserved(virt_to_page(start));
232                 init_page_count(virt_to_page(start));
233                 free_page(start);
234                 totalram_pages++;
235                 pages++;
236         }
237         printk("Freeing initrd memory: %dKiB freed\n", (pages * PAGE_SIZE) >> 10);
238 } /* end free_initrd_mem() */
239 #endif