PageRenderTime 28ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/arch/sh64/mm/init.c

https://bitbucket.org/evzijst/gittest
C | 196 lines | 108 code | 27 blank | 61 comment | 10 complexity | 660e75b20c346fdb4a1abf4835ed8a8f MD5 | raw file
  1/*
  2 * This file is subject to the terms and conditions of the GNU General Public
  3 * License.  See the file "COPYING" in the main directory of this archive
  4 * for more details.
  5 *
  6 * arch/sh64/mm/init.c
  7 *
  8 * Copyright (C) 2000, 2001  Paolo Alberelli
  9 * Copyright (C) 2003, 2004  Paul Mundt
 10 *
 11 */
 12
 13#include <linux/init.h>
 14#include <linux/rwsem.h>
 15#include <linux/mm.h>
 16#include <linux/swap.h>
 17#include <linux/bootmem.h>
 18
 19#include <asm/mmu_context.h>
 20#include <asm/page.h>
 21#include <asm/pgalloc.h>
 22#include <asm/pgtable.h>
 23#include <asm/tlb.h>
 24
 25#ifdef CONFIG_BLK_DEV_INITRD
 26#include <linux/blk.h>
 27#endif
 28
 29DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 30
 31/*
 32 * Cache of MMU context last used.
 33 */
 34unsigned long mmu_context_cache;
 35pgd_t * mmu_pdtp_cache;
 36int after_bootmem = 0;
 37
 38/*
 39 * BAD_PAGE is the page that is used for page faults when linux
 40 * is out-of-memory. Older versions of linux just did a
 41 * do_exit(), but using this instead means there is less risk
 42 * for a process dying in kernel mode, possibly leaving an inode
 43 * unused etc..
 44 *
 45 * BAD_PAGETABLE is the accompanying page-table: it is initialized
 46 * to point to BAD_PAGE entries.
 47 *
 48 * ZERO_PAGE is a special page that is used for zero-initialized
 49 * data and COW.
 50 */
 51
 52extern unsigned char empty_zero_page[PAGE_SIZE];
 53extern unsigned char empty_bad_page[PAGE_SIZE];
 54extern pte_t empty_bad_pte_table[PTRS_PER_PTE];
 55extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
 56
 57extern char _text, _etext, _edata, __bss_start, _end;
 58extern char __init_begin, __init_end;
 59
 60/* It'd be good if these lines were in the standard header file. */
 61#define START_PFN	(NODE_DATA(0)->bdata->node_boot_start >> PAGE_SHIFT)
 62#define MAX_LOW_PFN	(NODE_DATA(0)->bdata->node_low_pfn)
 63
 64
 65void show_mem(void)
 66{
 67	int i, total = 0, reserved = 0;
 68	int shared = 0, cached = 0;
 69
 70	printk("Mem-info:\n");
 71	show_free_areas();
 72	printk("Free swap:       %6ldkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
 73	i = max_mapnr;
 74	while (i-- > 0) {
 75		total++;
 76		if (PageReserved(mem_map+i))
 77			reserved++;
 78		else if (PageSwapCache(mem_map+i))
 79			cached++;
 80		else if (page_count(mem_map+i))
 81			shared += page_count(mem_map+i) - 1;
 82	}
 83	printk("%d pages of RAM\n",total);
 84	printk("%d reserved pages\n",reserved);
 85	printk("%d pages shared\n",shared);
 86	printk("%d pages swap cached\n",cached);
 87	printk("%ld pages in page table cache\n",pgtable_cache_size);
 88}
 89
 90/*
 91 * paging_init() sets up the page tables.
 92 *
 93 * head.S already did a lot to set up address translation for the kernel.
 94 * Here we comes with:
 95 * . MMU enabled
 96 * . ASID set (SR)
 97 * .  some 512MB regions being mapped of which the most relevant here is:
 98 *   . CACHED segment (ASID 0 [irrelevant], shared AND NOT user)
 99 * . possible variable length regions being mapped as:
100 *   . UNCACHED segment (ASID 0 [irrelevant], shared AND NOT user)
101 * . All of the memory regions are placed, independently from the platform
102 *   on high addresses, above 0x80000000.
103 * . swapper_pg_dir is already cleared out by the .space directive
104 *   in any case swapper does not require a real page directory since
105 *   it's all kernel contained.
106 *
107 * Those pesky NULL-reference errors in the kernel are then
108 * dealt with by not mapping address 0x00000000 at all.
109 *
110 */
111void __init paging_init(void)
112{
113	unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
114
115	pgd_init((unsigned long)swapper_pg_dir);
116	pgd_init((unsigned long)swapper_pg_dir +
117		 sizeof(pgd_t) * USER_PTRS_PER_PGD);
118
119	mmu_context_cache = MMU_CONTEXT_FIRST_VERSION;
120
121        /*
122	 * All memory is good as ZONE_NORMAL (fall-through) and ZONE_DMA.
123         */
124	zones_size[ZONE_DMA] = MAX_LOW_PFN - START_PFN;
125	NODE_DATA(0)->node_mem_map = NULL;
126	free_area_init_node(0, NODE_DATA(0), zones_size, __MEMORY_START >> PAGE_SHIFT, 0);
127}
128
129void __init mem_init(void)
130{
131	int codesize, reservedpages, datasize, initsize;
132	int tmp;
133
134	max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
135	high_memory = (void *)__va(MAX_LOW_PFN * PAGE_SIZE);
136
137	/*
138         * Clear the zero-page.
139         * This is not required but we might want to re-use
140         * this very page to pass boot parameters, one day.
141         */
142	memset(empty_zero_page, 0, PAGE_SIZE);
143
144	/* this will put all low memory onto the freelists */
145	totalram_pages += free_all_bootmem_node(NODE_DATA(0));
146	reservedpages = 0;
147	for (tmp = 0; tmp < num_physpages; tmp++)
148		/*
149		 * Only count reserved RAM pages
150		 */
151		if (PageReserved(mem_map+tmp))
152			reservedpages++;
153
154	after_bootmem = 1;
155
156	codesize =  (unsigned long) &_etext - (unsigned long) &_text;
157	datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
158	initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
159
160	printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n",
161		(unsigned long) nr_free_pages() << (PAGE_SHIFT-10),
162		max_mapnr << (PAGE_SHIFT-10),
163		codesize >> 10,
164		reservedpages << (PAGE_SHIFT-10),
165		datasize >> 10,
166		initsize >> 10);
167}
168
169void free_initmem(void)
170{
171	unsigned long addr;
172
173	addr = (unsigned long)(&__init_begin);
174	for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
175		ClearPageReserved(virt_to_page(addr));
176		set_page_count(virt_to_page(addr), 1);
177		free_page(addr);
178		totalram_pages++;
179	}
180	printk ("Freeing unused kernel memory: %ldk freed\n", (&__init_end - &__init_begin) >> 10);
181}
182
183#ifdef CONFIG_BLK_DEV_INITRD
184void free_initrd_mem(unsigned long start, unsigned long end)
185{
186	unsigned long p;
187	for (p = start; p < end; p += PAGE_SIZE) {
188		ClearPageReserved(virt_to_page(p));
189		set_page_count(virt_to_page(p), 1);
190		free_page(p);
191		totalram_pages++;
192	}
193	printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10);
194}
195#endif
196