David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 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> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/gfp.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 30 | |
| 31 | #include <asm/processor.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 32 | #include <asm/uaccess.h> |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/pgalloc.h> |
| 35 | #include <asm/dma.h> |
| 36 | #include <asm/tlb.h> |
| 37 | #include <asm/sections.h> |
| 38 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 39 | unsigned long highstart_pfn, highend_pfn; |
| 40 | |
Mark Salter | 5a226c6 | 2010-10-27 17:28:56 +0100 | [diff] [blame] | 41 | #ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT |
| 42 | static struct vm_struct user_iomap_vm; |
| 43 | #endif |
| 44 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 45 | /* |
| 46 | * set up paging |
| 47 | */ |
| 48 | void __init paging_init(void) |
| 49 | { |
| 50 | unsigned long zones_size[MAX_NR_ZONES] = {0,}; |
| 51 | pte_t *ppte; |
| 52 | int loop; |
| 53 | |
| 54 | /* main kernel space -> RAM mapping is handled as 1:1 transparent by |
| 55 | * the MMU */ |
| 56 | memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir)); |
| 57 | memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes)); |
| 58 | |
| 59 | /* load the VMALLOC area PTE table addresses into the kernel PGD */ |
| 60 | ppte = kernel_vmalloc_ptes; |
| 61 | for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE); |
| 62 | loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE); |
| 63 | loop++ |
| 64 | ) { |
| 65 | set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE)); |
| 66 | ppte += PAGE_SIZE / sizeof(pte_t); |
| 67 | } |
| 68 | |
| 69 | /* declare the sizes of the RAM zones (only use the normal zone) */ |
| 70 | zones_size[ZONE_NORMAL] = |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 71 | contig_page_data.bdata->node_low_pfn - |
| 72 | contig_page_data.bdata->node_min_pfn; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 73 | |
| 74 | /* pass the memory from the bootmem allocator to the main allocator */ |
| 75 | free_area_init(zones_size); |
| 76 | |
Mark Salter | 5a226c6 | 2010-10-27 17:28:56 +0100 | [diff] [blame] | 77 | #ifdef CONFIG_MN10300_HAS_ATOMIC_OPS_UNIT |
| 78 | /* The Atomic Operation Unit registers need to be mapped to userspace |
| 79 | * for all processes. The following uses vm_area_register_early() to |
| 80 | * reserve the first page of the vmalloc area and sets the pte for that |
| 81 | * page. |
| 82 | * |
| 83 | * glibc hardcodes this virtual mapping, so we're pretty much stuck with |
| 84 | * it from now on. |
| 85 | */ |
| 86 | user_iomap_vm.flags = VM_USERMAP; |
| 87 | user_iomap_vm.size = 1 << PAGE_SHIFT; |
| 88 | vm_area_register_early(&user_iomap_vm, PAGE_SIZE); |
| 89 | ppte = kernel_vmalloc_ptes; |
| 90 | set_pte(ppte, pfn_pte(USER_ATOMIC_OPS_PAGE_ADDR >> PAGE_SHIFT, |
| 91 | PAGE_USERIO)); |
| 92 | #endif |
| 93 | |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame] | 94 | local_flush_tlb_all(); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * transfer all the memory from the bootmem allocator to the runtime allocator |
| 99 | */ |
| 100 | void __init mem_init(void) |
| 101 | { |
| 102 | int codesize, reservedpages, datasize, initsize; |
| 103 | int tmp; |
| 104 | |
Stoyan Gaydarov | 292aa14 | 2010-10-27 17:28:33 +0100 | [diff] [blame] | 105 | BUG_ON(!mem_map); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 106 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 107 | #define START_PFN (contig_page_data.bdata->node_min_pfn) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 108 | #define MAX_LOW_PFN (contig_page_data.bdata->node_low_pfn) |
| 109 | |
| 110 | max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN; |
| 111 | high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE); |
| 112 | |
| 113 | /* clear the zero-page */ |
| 114 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 115 | |
| 116 | /* this will put all low memory onto the freelists */ |
| 117 | totalram_pages += free_all_bootmem(); |
| 118 | |
| 119 | reservedpages = 0; |
| 120 | for (tmp = 0; tmp < num_physpages; tmp++) |
| 121 | if (PageReserved(&mem_map[tmp])) |
| 122 | reservedpages++; |
| 123 | |
| 124 | codesize = (unsigned long) &_etext - (unsigned long) &_stext; |
| 125 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 126 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 127 | |
| 128 | printk(KERN_INFO |
| 129 | "Memory: %luk/%luk available" |
| 130 | " (%dk kernel code, %dk reserved, %dk data, %dk init," |
| 131 | " %ldk highmem)\n", |
Geert Uytterhoeven | cc013a8 | 2009-09-21 17:02:36 -0700 | [diff] [blame] | 132 | nr_free_pages() << (PAGE_SHIFT - 10), |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 133 | max_mapnr << (PAGE_SHIFT - 10), |
| 134 | codesize >> 10, |
| 135 | reservedpages << (PAGE_SHIFT - 10), |
| 136 | datasize >> 10, |
| 137 | initsize >> 10, |
Andreas Fenkart | 4b52940 | 2010-01-08 14:42:31 -0800 | [diff] [blame] | 138 | totalhigh_pages << (PAGE_SHIFT - 10)); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 142 | * recycle memory containing stuff only required for initialisation |
| 143 | */ |
| 144 | void free_initmem(void) |
| 145 | { |
Jiang Liu | 32ce012 | 2013-04-29 15:06:44 -0700 | [diff] [blame] | 146 | free_initmem_default(POISON_FREE_INITMEM); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* |
| 150 | * dispose of the memory on which the initial ramdisk resided |
| 151 | */ |
| 152 | #ifdef CONFIG_BLK_DEV_INITRD |
| 153 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 154 | { |
Jiang Liu | 1119969 | 2013-07-03 15:02:48 -0700 | [diff] [blame^] | 155 | free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM, |
| 156 | "initrd"); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 157 | } |
| 158 | #endif |