Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* init.c: memory initialisation for FRV |
| 2 | * |
| 3 | * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 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. |
| 10 | * |
| 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 |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/signal.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/pagemap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Adrian Bunk | fb56f0f | 2008-05-23 13:05:00 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include <asm/setup.h> |
| 33 | #include <asm/segment.h> |
| 34 | #include <asm/page.h> |
| 35 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/mmu_context.h> |
| 37 | #include <asm/virtconvert.h> |
| 38 | #include <asm/sections.h> |
| 39 | #include <asm/tlb.h> |
| 40 | |
| 41 | #undef DEBUG |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
| 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.. |
| 49 | * |
| 50 | * BAD_PAGETABLE is the accompanying page-table: it is initialized |
| 51 | * to point to BAD_PAGE entries. |
| 52 | * |
| 53 | * ZERO_PAGE is a special page that is used for zero-initialized |
| 54 | * data and COW. |
| 55 | */ |
| 56 | static unsigned long empty_bad_page_table; |
| 57 | static unsigned long empty_bad_page; |
Adrian Bunk | fb56f0f | 2008-05-23 13:05:00 -0700 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | unsigned long empty_zero_page; |
Adrian Bunk | fb56f0f | 2008-05-23 13:05:00 -0700 | [diff] [blame] | 60 | EXPORT_SYMBOL(empty_zero_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /*****************************************************************************/ |
| 63 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 68 | */ |
| 69 | void __init paging_init(void) |
| 70 | { |
Christoph Lameter | f06a968 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 71 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 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); |
| 77 | |
| 78 | memset((void *) empty_zero_page, 0, PAGE_SIZE); |
| 79 | |
David Howells | 8080f23 | 2005-11-28 13:43:51 -0800 | [diff] [blame] | 80 | #ifdef CONFIG_HIGHMEM |
Jiang Liu | 3f2b73c | 2013-07-03 15:03:55 -0700 | [diff] [blame] | 81 | if (get_num_physpages() - num_mappedpages) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | pgd_t *pge; |
| 83 | pud_t *pue; |
| 84 | pmd_t *pme; |
| 85 | |
| 86 | pkmap_page_table = alloc_bootmem_pages(PAGE_SIZE); |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 92 | } |
| 93 | #endif |
| 94 | |
| 95 | /* distribute the allocatable pages across the various zones and pass them to the allocator |
| 96 | */ |
David Howells | fa64275 | 2007-02-28 20:11:58 -0800 | [diff] [blame] | 97 | zones_size[ZONE_NORMAL] = max_low_pfn - min_low_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | #ifdef CONFIG_HIGHMEM |
Jiang Liu | 3f2b73c | 2013-07-03 15:03:55 -0700 | [diff] [blame] | 99 | zones_size[ZONE_HIGHMEM] = get_num_physpages() - num_mappedpages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif |
| 101 | |
| 102 | free_area_init(zones_size); |
| 103 | |
| 104 | #ifdef CONFIG_MMU |
| 105 | /* initialise init's MMU context */ |
| 106 | init_new_context(&init_task, &init_mm); |
| 107 | #endif |
| 108 | |
| 109 | } /* end paging_init() */ |
| 110 | |
| 111 | /*****************************************************************************/ |
| 112 | /* |
| 113 | * |
| 114 | */ |
| 115 | void __init mem_init(void) |
| 116 | { |
Jiang Liu | 3f2b73c | 2013-07-03 15:03:55 -0700 | [diff] [blame] | 117 | unsigned long code_size = _etext - _stext; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Jiang Liu | 0516f88 | 2013-04-29 15:06:37 -0700 | [diff] [blame] | 119 | /* this will put all low memory onto the freelists */ |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 120 | free_all_bootmem(); |
Jiang Liu | 3f2b73c | 2013-07-03 15:03:55 -0700 | [diff] [blame] | 121 | #if defined(CONFIG_MMU) && defined(CONFIG_HIGHMEM) |
| 122 | { |
| 123 | unsigned long pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Jiang Liu | 3f2b73c | 2013-07-03 15:03:55 -0700 | [diff] [blame] | 125 | for (pfn = get_num_physpages() - 1; |
| 126 | pfn >= num_mappedpages; pfn--) |
| 127 | free_highmem_page(&mem_map[pfn]); |
| 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | #endif |
| 130 | |
Jiang Liu | 3f2b73c | 2013-07-03 15:03:55 -0700 | [diff] [blame] | 131 | mem_init_print_info(NULL); |
| 132 | if (rom_length > 0 && rom_length >= code_size) |
| 133 | printk("Memory available: %luKiB/%luKiB ROM\n", |
| 134 | (rom_length - code_size) >> 10, rom_length >> 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } /* end mem_init() */ |
| 136 | |
| 137 | /*****************************************************************************/ |
| 138 | /* |
| 139 | * free the memory that was only required for initialisation |
| 140 | */ |
David Howells | e4fc5a1 | 2007-11-06 21:54:44 +0000 | [diff] [blame] | 141 | void free_initmem(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | #if defined(CONFIG_RAMKERNEL) && !defined(CONFIG_PROTECT_KERNEL) |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 144 | free_initmem_default(-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | #endif |
| 146 | } /* end free_initmem() */ |
| 147 | |
| 148 | /*****************************************************************************/ |
| 149 | /* |
| 150 | * free the initial ramdisk memory |
| 151 | */ |
| 152 | #ifdef CONFIG_BLK_DEV_INITRD |
| 153 | void __init free_initrd_mem(unsigned long start, unsigned long end) |
| 154 | { |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 155 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } /* end free_initrd_mem() */ |
| 157 | #endif |