Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 29 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 30 | |
| 31 | /* |
| 32 | * Cache of MMU context last used. |
| 33 | */ |
| 34 | unsigned long mmu_context_cache; |
| 35 | pgd_t * mmu_pdtp_cache; |
| 36 | int 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 | |
| 52 | extern unsigned char empty_zero_page[PAGE_SIZE]; |
| 53 | extern unsigned char empty_bad_page[PAGE_SIZE]; |
| 54 | extern pte_t empty_bad_pte_table[PTRS_PER_PTE]; |
| 55 | extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; |
| 56 | |
| 57 | extern char _text, _etext, _edata, __bss_start, _end; |
| 58 | extern 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 | |
| 65 | void 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); |
Paul Mundt | 6c645ac | 2007-05-14 09:55:35 +0900 | [diff] [blame] | 87 | printk("%ld pages in page table cache\n", quicklist_total_size()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
| 111 | void __init paging_init(void) |
| 112 | { |
Christoph Lameter | f06a968 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 113 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Christoph Lameter | 339ba9b | 2007-02-10 01:43:13 -0800 | [diff] [blame] | 121 | zones_size[ZONE_NORMAL] = MAX_LOW_PFN - START_PFN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | NODE_DATA(0)->node_mem_map = NULL; |
| 123 | free_area_init_node(0, NODE_DATA(0), zones_size, __MEMORY_START >> PAGE_SHIFT, 0); |
| 124 | } |
| 125 | |
| 126 | void __init mem_init(void) |
| 127 | { |
| 128 | int codesize, reservedpages, datasize, initsize; |
| 129 | int tmp; |
| 130 | |
| 131 | max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN; |
| 132 | high_memory = (void *)__va(MAX_LOW_PFN * PAGE_SIZE); |
| 133 | |
| 134 | /* |
| 135 | * Clear the zero-page. |
| 136 | * This is not required but we might want to re-use |
| 137 | * this very page to pass boot parameters, one day. |
| 138 | */ |
| 139 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 140 | |
| 141 | /* this will put all low memory onto the freelists */ |
| 142 | totalram_pages += free_all_bootmem_node(NODE_DATA(0)); |
| 143 | reservedpages = 0; |
| 144 | for (tmp = 0; tmp < num_physpages; tmp++) |
| 145 | /* |
| 146 | * Only count reserved RAM pages |
| 147 | */ |
| 148 | if (PageReserved(mem_map+tmp)) |
| 149 | reservedpages++; |
| 150 | |
| 151 | after_bootmem = 1; |
| 152 | |
| 153 | codesize = (unsigned long) &_etext - (unsigned long) &_text; |
| 154 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 155 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 156 | |
| 157 | printk("Memory: %luk/%luk available (%dk kernel code, %dk reserved, %dk data, %dk init)\n", |
| 158 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 159 | max_mapnr << (PAGE_SHIFT-10), |
| 160 | codesize >> 10, |
| 161 | reservedpages << (PAGE_SHIFT-10), |
| 162 | datasize >> 10, |
| 163 | initsize >> 10); |
| 164 | } |
| 165 | |
| 166 | void free_initmem(void) |
| 167 | { |
| 168 | unsigned long addr; |
| 169 | |
| 170 | addr = (unsigned long)(&__init_begin); |
| 171 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { |
| 172 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 173 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | free_page(addr); |
| 175 | totalram_pages++; |
| 176 | } |
| 177 | printk ("Freeing unused kernel memory: %ldk freed\n", (&__init_end - &__init_begin) >> 10); |
| 178 | } |
| 179 | |
| 180 | #ifdef CONFIG_BLK_DEV_INITRD |
| 181 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 182 | { |
| 183 | unsigned long p; |
| 184 | for (p = start; p < end; p += PAGE_SIZE) { |
| 185 | ClearPageReserved(virt_to_page(p)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 186 | init_page_count(virt_to_page(p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | free_page(p); |
| 188 | totalram_pages++; |
| 189 | } |
| 190 | printk ("Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 191 | } |
| 192 | #endif |
| 193 | |