mn10300/PCI: Remove unused pci_root_bus
[linux-2.6/btrfs-unstable.git] / arch / frv / mm / init.c
blob92e97b0894a68bbebcc138bf93305b69624c0ee7
1 /* init.c: memory initialisation for FRV
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
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
19 #include <linux/signal.h>
20 #include <linux/sched.h>
21 #include <linux/pagemap.h>
22 #include <linux/gfp.h>
23 #include <linux/swap.h>
24 #include <linux/mm.h>
25 #include <linux/kernel.h>
26 #include <linux/string.h>
27 #include <linux/types.h>
28 #include <linux/bootmem.h>
29 #include <linux/highmem.h>
30 #include <linux/module.h>
32 #include <asm/setup.h>
33 #include <asm/segment.h>
34 #include <asm/page.h>
35 #include <asm/pgtable.h>
36 #include <asm/mmu_context.h>
37 #include <asm/virtconvert.h>
38 #include <asm/sections.h>
39 #include <asm/tlb.h>
41 #undef DEBUG
44 * BAD_PAGE is the page that is used for page faults when linux
45 * is out-of-memory. Older versions of linux just did a
46 * do_exit(), but using this instead means there is less risk
47 * for a process dying in kernel mode, possibly leaving a inode
48 * unused etc..
50 * BAD_PAGETABLE is the accompanying page-table: it is initialized
51 * to point to BAD_PAGE entries.
53 * ZERO_PAGE is a special page that is used for zero-initialized
54 * data and COW.
56 static unsigned long empty_bad_page_table;
57 static unsigned long empty_bad_page;
59 unsigned long empty_zero_page;
60 EXPORT_SYMBOL(empty_zero_page);
62 /*****************************************************************************/
64 * paging_init() continues the virtual memory environment setup which
65 * was begun by the code in arch/head.S.
66 * The parameters are pointers to where to stick the starting and ending
67 * addresses of available kernel virtual memory.
69 void __init paging_init(void)
71 unsigned long zones_size[MAX_NR_ZONES] = {0, };
73 /* allocate some pages for kernel housekeeping tasks */
74 empty_bad_page_table = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
75 empty_bad_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
76 empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
78 memset((void *) empty_zero_page, 0, PAGE_SIZE);
80 #ifdef CONFIG_HIGHMEM
81 if (num_physpages - num_mappedpages) {
82 pgd_t *pge;
83 pud_t *pue;
84 pmd_t *pme;
86 pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE);
88 pge = swapper_pg_dir + pgd_index_k(PKMAP_BASE);
89 pue = pud_offset(pge, PKMAP_BASE);
90 pme = pmd_offset(pue, PKMAP_BASE);
91 __set_pmd(pme, virt_to_phys(pkmap_page_table) | _PAGE_TABLE);
93 #endif
95 /* distribute the allocatable pages across the various zones and pass them to the allocator
97 zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn;
98 #ifdef CONFIG_HIGHMEM
99 zones_size[ZONE_HIGHMEM] = num_physpages - num_mappedpages;
100 #endif
102 free_area_init(zones_size);
104 #ifdef CONFIG_MMU
105 /* initialise init's MMU context */
106 init_new_context(&init_task, &init_mm);
107 #endif
109 } /* end paging_init() */
111 /*****************************************************************************/
115 void __init mem_init(void)
117 unsigned long npages = (memory_end - memory_start) >> PAGE_SHIFT;
118 unsigned long tmp;
119 #ifdef CONFIG_MMU
120 unsigned long loop, pfn;
121 int datapages = 0;
122 #endif
123 int codek = 0, datak = 0;
125 /* this will put all memory onto the freelists */
126 totalram_pages = free_all_bootmem();
128 #ifdef CONFIG_MMU
129 for (loop = 0 ; loop < npages ; loop++)
130 if (PageReserved(&mem_map[loop]))
131 datapages++;
133 #ifdef CONFIG_HIGHMEM
134 for (pfn = num_physpages - 1; pfn >= num_mappedpages; pfn--) {
135 struct page *page = &mem_map[pfn];
137 ClearPageReserved(page);
138 init_page_count(page);
139 __free_page(page);
140 totalram_pages++;
142 #endif
144 codek = ((unsigned long) &_etext - (unsigned long) &_stext) >> 10;
145 datak = datapages << (PAGE_SHIFT - 10);
147 #else
148 codek = (_etext - _stext) >> 10;
149 datak = 0; //(__bss_stop - _sdata) >> 10;
150 #endif
152 tmp = nr_free_pages() << PAGE_SHIFT;
153 printk("Memory available: %luKiB/%luKiB RAM, %luKiB/%luKiB ROM (%dKiB kernel code, %dKiB data)\n",
154 tmp >> 10,
155 npages << (PAGE_SHIFT - 10),
156 (rom_length > 0) ? ((rom_length >> 10) - codek) : 0,
157 rom_length >> 10,
158 codek,
159 datak
162 } /* end mem_init() */
164 /*****************************************************************************/
166 * free the memory that was only required for initialisation
168 void free_initmem(void)
170 #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL)
171 unsigned long start, end, addr;
173 start = PAGE_ALIGN((unsigned long) &__init_begin); /* round up */
174 end = ((unsigned long) &__init_end) & PAGE_MASK; /* round down */
176 /* next to check that the page we free is not a partial page */
177 for (addr = start; addr < end; addr += PAGE_SIZE) {
178 ClearPageReserved(virt_to_page(addr));
179 init_page_count(virt_to_page(addr));
180 free_page(addr);
181 totalram_pages++;
184 printk("Freeing unused kernel memory: %ldKiB freed (0x%lx - 0x%lx)\n",
185 (end - start) >> 10, start, end);
186 #endif
187 } /* end free_initmem() */
189 /*****************************************************************************/
191 * free the initial ramdisk memory
193 #ifdef CONFIG_BLK_DEV_INITRD
194 void __init free_initrd_mem(unsigned long start, unsigned long end)
196 int pages = 0;
197 for (; start < end; start += PAGE_SIZE) {
198 ClearPageReserved(virt_to_page(start));
199 init_page_count(virt_to_page(start));
200 free_page(start);
201 totalram_pages++;
202 pages++;
204 printk("Freeing initrd memory: %dKiB freed\n", (pages * PAGE_SIZE) >> 10);
205 } /* end free_initrd_mem() */
206 #endif