Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/m68knommu/mm/init.c |
| 3 | * |
| 4 | * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, |
| 5 | * Kenneth Albanowski <kjahds@kjahds.com>, |
| 6 | * Copyright (C) 2000 Lineo, Inc. (www.lineo.com) |
| 7 | * |
| 8 | * Based on: |
| 9 | * |
| 10 | * linux/arch/m68k/mm/init.c |
| 11 | * |
| 12 | * Copyright (C) 1995 Hamish Macdonald |
| 13 | * |
| 14 | * JAN/1999 -- hacked to support ColdFire (gerg@snapgear.com) |
| 15 | * DEC/2000 -- linux 2.4 support <davidm@snapgear.com> |
| 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/signal.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/ptrace.h> |
| 25 | #include <linux/mman.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/swap.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/highmem.h> |
| 30 | #include <linux/pagemap.h> |
| 31 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include <asm/setup.h> |
| 35 | #include <asm/segment.h> |
| 36 | #include <asm/page.h> |
| 37 | #include <asm/pgtable.h> |
| 38 | #include <asm/system.h> |
| 39 | #include <asm/machdep.h> |
| 40 | |
| 41 | #undef DEBUG |
| 42 | |
| 43 | extern void die_if_kernel(char *,struct pt_regs *,long); |
| 44 | extern void free_initmem(void); |
| 45 | |
| 46 | /* |
| 47 | * BAD_PAGE is the page that is used for page faults when linux |
| 48 | * is out-of-memory. Older versions of linux just did a |
| 49 | * do_exit(), but using this instead means there is less risk |
| 50 | * for a process dying in kernel mode, possibly leaving a inode |
| 51 | * unused etc.. |
| 52 | * |
| 53 | * BAD_PAGETABLE is the accompanying page-table: it is initialized |
| 54 | * to point to BAD_PAGE entries. |
| 55 | * |
| 56 | * ZERO_PAGE is a special page that is used for zero-initialized |
| 57 | * data and COW. |
| 58 | */ |
| 59 | static unsigned long empty_bad_page_table; |
| 60 | |
| 61 | static unsigned long empty_bad_page; |
| 62 | |
| 63 | unsigned long empty_zero_page; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | extern unsigned long memory_start; |
| 66 | extern unsigned long memory_end; |
| 67 | |
| 68 | /* |
| 69 | * paging_init() continues the virtual memory environment setup which |
| 70 | * was begun by the code in arch/head.S. |
| 71 | * The parameters are pointers to where to stick the starting and ending |
| 72 | * addresses of available kernel virtual memory. |
| 73 | */ |
Greg Ungerer | f386c3c | 2007-10-24 12:03:46 +1000 | [diff] [blame] | 74 | void __init paging_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
| 76 | /* |
| 77 | * Make sure start_mem is page aligned, otherwise bootmem and |
| 78 | * page_alloc get different views of the world. |
| 79 | */ |
| 80 | #ifdef DEBUG |
| 81 | unsigned long start_mem = PAGE_ALIGN(memory_start); |
| 82 | #endif |
| 83 | unsigned long end_mem = memory_end & PAGE_MASK; |
| 84 | |
| 85 | #ifdef DEBUG |
| 86 | printk (KERN_DEBUG "start_mem is %#lx\nvirtual_end is %#lx\n", |
| 87 | start_mem, end_mem); |
| 88 | #endif |
| 89 | |
| 90 | /* |
| 91 | * Initialize the bad page table and bad page to point |
| 92 | * to a couple of allocated pages. |
| 93 | */ |
| 94 | empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
| 95 | empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
| 96 | empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
| 97 | memset((void *)empty_zero_page, 0, PAGE_SIZE); |
| 98 | |
| 99 | /* |
| 100 | * Set up SFC/DFC registers (user data space). |
| 101 | */ |
| 102 | set_fs (USER_DS); |
| 103 | |
| 104 | #ifdef DEBUG |
| 105 | printk (KERN_DEBUG "before free_area_init\n"); |
| 106 | |
| 107 | printk (KERN_DEBUG "free_area_init -> start_mem is %#lx\nvirtual_end is %#lx\n", |
| 108 | start_mem, end_mem); |
| 109 | #endif |
| 110 | |
| 111 | { |
Christoph Lameter | f06a968 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 112 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Greg Ungerer | dffc9ef | 2009-01-28 17:07:19 +1000 | [diff] [blame] | 114 | zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | free_area_init(zones_size); |
| 116 | } |
| 117 | } |
| 118 | |
Greg Ungerer | f386c3c | 2007-10-24 12:03:46 +1000 | [diff] [blame] | 119 | void __init mem_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
| 121 | int codek = 0, datak = 0, initk = 0; |
| 122 | unsigned long tmp; |
| 123 | extern char _etext, _stext, _sdata, _ebss, __init_begin, __init_end; |
| 124 | extern unsigned int _ramend, _rambase; |
| 125 | unsigned long len = _ramend - _rambase; |
| 126 | unsigned long start_mem = memory_start; /* DAVIDM - these must start at end of kernel */ |
| 127 | unsigned long end_mem = memory_end; /* DAVIDM - this must not include kernel stack at top */ |
| 128 | |
Joe Perches | 308e610 | 2009-05-15 10:59:37 -0700 | [diff] [blame] | 129 | pr_debug("Mem_init: start=%lx, end=%lx\n", start_mem, end_mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | end_mem &= PAGE_MASK; |
| 132 | high_memory = (void *) end_mem; |
| 133 | |
| 134 | start_mem = PAGE_ALIGN(start_mem); |
| 135 | max_mapnr = num_physpages = (((unsigned long) high_memory) - PAGE_OFFSET) >> PAGE_SHIFT; |
| 136 | |
| 137 | /* this will put all memory onto the freelists */ |
| 138 | totalram_pages = free_all_bootmem(); |
| 139 | |
| 140 | codek = (&_etext - &_stext) >> 10; |
| 141 | datak = (&_ebss - &_sdata) >> 10; |
| 142 | initk = (&__init_begin - &__init_end) >> 10; |
| 143 | |
| 144 | tmp = nr_free_pages() << PAGE_SHIFT; |
Greg Ungerer | 2082b47 | 2006-06-26 10:33:10 +1000 | [diff] [blame] | 145 | printk(KERN_INFO "Memory available: %luk/%luk RAM, (%dk kernel code, %dk data)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | tmp >> 10, |
| 147 | len >> 10, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | codek, |
| 149 | datak |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | #ifdef CONFIG_BLK_DEV_INITRD |
| 155 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 156 | { |
| 157 | int pages = 0; |
| 158 | for (; start < end; start += PAGE_SIZE) { |
| 159 | ClearPageReserved(virt_to_page(start)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 160 | init_page_count(virt_to_page(start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | free_page(start); |
| 162 | totalram_pages++; |
| 163 | pages++; |
| 164 | } |
Lennart Sorensen | cd15e8c | 2009-09-17 11:49:41 -0400 | [diff] [blame] | 165 | printk (KERN_NOTICE "Freeing initrd memory: %dk freed\n", pages * (PAGE_SIZE / 1024)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | #endif |
| 168 | |
| 169 | void |
| 170 | free_initmem() |
| 171 | { |
| 172 | #ifdef CONFIG_RAMKERNEL |
| 173 | unsigned long addr; |
| 174 | extern char __init_begin, __init_end; |
| 175 | /* |
| 176 | * The following code should be cool even if these sections |
| 177 | * are not page aligned. |
| 178 | */ |
| 179 | addr = PAGE_ALIGN((unsigned long)(&__init_begin)); |
| 180 | /* next to check that the page we free is not a partial page */ |
| 181 | for (; addr + PAGE_SIZE < (unsigned long)(&__init_end); addr +=PAGE_SIZE) { |
| 182 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 183 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | free_page(addr); |
| 185 | totalram_pages++; |
| 186 | } |
| 187 | printk(KERN_NOTICE "Freeing unused kernel memory: %ldk freed (0x%x - 0x%x)\n", |
| 188 | (addr - PAGE_ALIGN((long) &__init_begin)) >> 10, |
| 189 | (int)(PAGE_ALIGN((unsigned long)(&__init_begin))), |
| 190 | (int)(addr - PAGE_SIZE)); |
| 191 | #endif |
| 192 | } |
| 193 | |