init.c revision 1c395176962176660bb108f90e97e1686cfe0d85
1/* MN10300 Memory management initialisation 2 * 3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd. 4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 5 * Modified by David Howells (dhowells@redhat.com) 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public Licence 9 * as published by the Free Software Foundation; either version 10 * 2 of the Licence, or (at your option) any later version. 11 */ 12#include <linux/signal.h> 13#include <linux/sched.h> 14#include <linux/kernel.h> 15#include <linux/errno.h> 16#include <linux/string.h> 17#include <linux/types.h> 18#include <linux/ptrace.h> 19#include <linux/mman.h> 20#include <linux/fs.h> 21#include <linux/mm.h> 22#include <linux/swap.h> 23#include <linux/smp.h> 24#include <linux/init.h> 25#include <linux/initrd.h> 26#include <linux/highmem.h> 27#include <linux/pagemap.h> 28#include <linux/bootmem.h> 29#include <linux/gfp.h> 30 31#include <asm/processor.h> 32#include <asm/system.h> 33#include <asm/uaccess.h> 34#include <asm/pgtable.h> 35#include <asm/pgalloc.h> 36#include <asm/dma.h> 37#include <asm/tlb.h> 38#include <asm/sections.h> 39 40unsigned long highstart_pfn, highend_pfn; 41 42#ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT 43static struct vm_struct user_iomap_vm; 44#endif 45 46/* 47 * set up paging 48 */ 49void __init paging_init(void) 50{ 51 unsigned long zones_size[MAX_NR_ZONES] = {0,}; 52 pte_t *ppte; 53 int loop; 54 55 /* main kernel space -> RAM mapping is handled as 1:1 transparent by 56 * the MMU */ 57 memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir)); 58 memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes)); 59 60 /* load the VMALLOC area PTE table addresses into the kernel PGD */ 61 ppte = kernel_vmalloc_ptes; 62 for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE); 63 loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE); 64 loop++ 65 ) { 66 set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE)); 67 ppte += PAGE_SIZE / sizeof(pte_t); 68 } 69 70 /* declare the sizes of the RAM zones (only use the normal zone) */ 71 zones_size[ZONE_NORMAL] = 72 contig_page_data.bdata->node_low_pfn - 73 contig_page_data.bdata->node_min_pfn; 74 75 /* pass the memory from the bootmem allocator to the main allocator */ 76 free_area_init(zones_size); 77 78#ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT 79 /* The Atomic Operation Unit registers need to be mapped to userspace 80 * for all processes. The following uses vm_area_register_early() to 81 * reserve the first page of the vmalloc area and sets the pte for that 82 * page. 83 * 84 * glibc hardcodes this virtual mapping, so we're pretty much stuck with 85 * it from now on. 86 */ 87 user_iomap_vm.flags = VM_USERMAP; 88 user_iomap_vm.size = 1 << PAGE_SHIFT; 89 vm_area_register_early(&user_iomap_vm, PAGE_SIZE); 90 ppte = kernel_vmalloc_ptes; 91 set_pte(ppte, pfn_pte(USER_ATOMIC_OPS_PAGE_ADDR >> PAGE_SHIFT, 92 PAGE_USERIO)); 93#endif 94 95 local_flush_tlb_all(); 96} 97 98/* 99 * transfer all the memory from the bootmem allocator to the runtime allocator 100 */ 101void __init mem_init(void) 102{ 103 int codesize, reservedpages, datasize, initsize; 104 int tmp; 105 106 BUG_ON(!mem_map); 107 108#define START_PFN (contig_page_data.bdata->node_min_pfn) 109#define MAX_LOW_PFN (contig_page_data.bdata->node_low_pfn) 110 111 max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN; 112 high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE); 113 114 /* clear the zero-page */ 115 memset(empty_zero_page, 0, PAGE_SIZE); 116 117 /* this will put all low memory onto the freelists */ 118 totalram_pages += free_all_bootmem(); 119 120 reservedpages = 0; 121 for (tmp = 0; tmp < num_physpages; tmp++) 122 if (PageReserved(&mem_map[tmp])) 123 reservedpages++; 124 125 codesize = (unsigned long) &_etext - (unsigned long) &_stext; 126 datasize = (unsigned long) &_edata - (unsigned long) &_etext; 127 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; 128 129 printk(KERN_INFO 130 "Memory: %luk/%luk available" 131 " (%dk kernel code, %dk reserved, %dk data, %dk init," 132 " %ldk highmem)\n", 133 nr_free_pages() << (PAGE_SHIFT - 10), 134 max_mapnr << (PAGE_SHIFT - 10), 135 codesize >> 10, 136 reservedpages << (PAGE_SHIFT - 10), 137 datasize >> 10, 138 initsize >> 10, 139 totalhigh_pages << (PAGE_SHIFT - 10)); 140} 141 142/* 143 * 144 */ 145void free_init_pages(char *what, unsigned long begin, unsigned long end) 146{ 147 unsigned long addr; 148 149 for (addr = begin; addr < end; addr += PAGE_SIZE) { 150 ClearPageReserved(virt_to_page(addr)); 151 init_page_count(virt_to_page(addr)); 152 memset((void *) addr, 0xcc, PAGE_SIZE); 153 free_page(addr); 154 totalram_pages++; 155 } 156 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); 157} 158 159/* 160 * recycle memory containing stuff only required for initialisation 161 */ 162void free_initmem(void) 163{ 164 free_init_pages("unused kernel memory", 165 (unsigned long) &__init_begin, 166 (unsigned long) &__init_end); 167} 168 169/* 170 * dispose of the memory on which the initial ramdisk resided 171 */ 172#ifdef CONFIG_BLK_DEV_INITRD 173void free_initrd_mem(unsigned long start, unsigned long end) 174{ 175 free_init_pages("initrd memory", start, end); 176} 177#endif 178