blob: 0708284f85fb3d690d4e649366ea056282a171b8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#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>
Adrian Bunkfb56f0f2008-05-23 13:05:00 -070029#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31#include <asm/setup.h>
32#include <asm/segment.h>
33#include <asm/page.h>
34#include <asm/pgtable.h>
35#include <asm/system.h>
36#include <asm/mmu_context.h>
37#include <asm/virtconvert.h>
38#include <asm/sections.h>
39#include <asm/tlb.h>
40
41#undef DEBUG
42
43DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
44
45/*
46 * BAD_PAGE is the page that is used for page faults when linux
47 * is out-of-memory. Older versions of linux just did a
48 * do_exit(), but using this instead means there is less risk
49 * for a process dying in kernel mode, possibly leaving a inode
50 * unused etc..
51 *
52 * BAD_PAGETABLE is the accompanying page-table: it is initialized
53 * to point to BAD_PAGE entries.
54 *
55 * ZERO_PAGE is a special page that is used for zero-initialized
56 * data and COW.
57 */
58static unsigned long empty_bad_page_table;
59static unsigned long empty_bad_page;
Adrian Bunkfb56f0f2008-05-23 13:05:00 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061unsigned long empty_zero_page;
Adrian Bunkfb56f0f2008-05-23 13:05:00 -070062EXPORT_SYMBOL(empty_zero_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/*****************************************************************************/
65/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 * paging_init() continues the virtual memory environment setup which
67 * was begun by the code in arch/head.S.
68 * The parameters are pointers to where to stick the starting and ending
69 * addresses of available kernel virtual memory.
70 */
71void __init paging_init(void)
72{
Christoph Lameterf06a9682006-09-25 23:31:10 -070073 unsigned long zones_size[MAX_NR_ZONES] = {0, };
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75 /* allocate some pages for kernel housekeeping tasks */
76 empty_bad_page_table = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
77 empty_bad_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
78 empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
79
80 memset((void *) empty_zero_page, 0, PAGE_SIZE);
81
David Howells8080f232005-11-28 13:43:51 -080082#ifdef CONFIG_HIGHMEM
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (num_physpages - num_mappedpages) {
84 pgd_t *pge;
85 pud_t *pue;
86 pmd_t *pme;
87
88 pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE);
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE);
91 pue = pud_offset(pge, PKMAP_BASE);
92 pme = pmd_offset(pue, PKMAP_BASE);
93 __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE);
94 }
95#endif
96
97 /* distribute the allocatable pages across the various zones and pass them to the allocator
98 */
David Howellsfa642752007-02-28 20:11:58 -080099 zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#ifdef CONFIG_HIGHMEM
101 zones_size[ZONE_HIGHMEM] = num_physpages - num_mappedpages;
102#endif
103
104 free_area_init(zones_size);
105
106#ifdef CONFIG_MMU
107 /* initialise init's MMU context */
108 init_new_context(&init_task, &init_mm);
109#endif
110
111} /* end paging_init() */
112
113/*****************************************************************************/
114/*
115 *
116 */
117void __init mem_init(void)
118{
119 unsigned long npages = (memory_end - memory_start) >> PAGE_SHIFT;
120 unsigned long tmp;
121#ifdef CONFIG_MMU
122 unsigned long loop, pfn;
123 int datapages = 0;
124#endif
125 int codek = 0, datak = 0;
126
127 /* this will put all memory onto the freelists */
128 totalram_pages = free_all_bootmem();
129
130#ifdef CONFIG_MMU
131 for (loop = 0 ; loop < npages ; loop++)
132 if (PageReserved(&mem_map[loop]))
133 datapages++;
134
135#ifdef CONFIG_HIGHMEM
136 for (pfn = num_physpages - 1; pfn >= num_mappedpages; pfn--) {
137 struct page *page = &mem_map[pfn];
138
139 ClearPageReserved(page);
Nick Piggin7835e982006-03-22 00:08:40 -0800140 init_page_count(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 __free_page(page);
142 totalram_pages++;
143 }
144#endif
145
146 codek = ((unsigned long) &_etext - (unsigned long) &_stext) >> 10;
147 datak = datapages << (PAGE_SHIFT - 10);
148
149#else
150 codek = (_etext - _stext) >> 10;
151 datak = 0; //(_ebss - _sdata) >> 10;
152#endif
153
154 tmp = nr_free_pages() << PAGE_SHIFT;
155 printk("Memory available: %luKiB/%luKiB RAM, %luKiB/%luKiB ROM (%dKiB kernel code, %dKiB data)\n",
156 tmp >> 10,
157 npages << (PAGE_SHIFT - 10),
158 (rom_length > 0) ? ((rom_length >> 10) - codek) : 0,
159 rom_length >> 10,
160 codek,
161 datak
162 );
163
164} /* end mem_init() */
165
166/*****************************************************************************/
167/*
168 * free the memory that was only required for initialisation
169 */
David Howellse4fc5a12007-11-06 21:54:44 +0000170void free_initmem(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172#if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
173 unsigned long start, end, addr;
174
175 start = PAGE_ALIGN((unsigned long) &__init_begin); /* round up */
176 end = ((unsigned long) &__init_end) & PAGE_MASK; /* round down */
177
178 /* next to check that the page we free is not a partial page */
179 for (addr = start; addr < end; addr += PAGE_SIZE) {
180 ClearPageReserved(virt_to_page(addr));
Nick Piggin7835e982006-03-22 00:08:40 -0800181 init_page_count(virt_to_page(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 free_page(addr);
183 totalram_pages++;
184 }
185
186 printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
187 (end - start) >> 10, start, end);
188#endif
189} /* end free_initmem() */
190
191/*****************************************************************************/
192/*
193 * free the initial ramdisk memory
194 */
195#ifdef CONFIG_BLK_DEV_INITRD
196void __init free_initrd_mem(unsigned long start, unsigned long end)
197{
198 int pages = 0;
199 for (; start < end; start += PAGE_SIZE) {
200 ClearPageReserved(virt_to_page(start));
Nick Piggin7835e982006-03-22 00:08:40 -0800201 init_page_count(virt_to_page(start));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 free_page(start);
203 totalram_pages++;
204 pages++;
205 }
206 printk("Freeing initrd memory: %dKiB freed\n", (pages * PAGE_SIZE) >> 10);
207} /* end free_initrd_mem() */
208#endif