Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: arch/blackfin/mm/init.c |
| 3 | * Based on: |
| 4 | * Author: |
| 5 | * |
| 6 | * Created: |
| 7 | * Description: |
| 8 | * |
| 9 | * Modified: |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 10 | * Copyright 2004-2007 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 11 | * |
| 12 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, see the file COPYING, or write |
| 26 | * to the Free Software Foundation, Inc., |
| 27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 | */ |
| 29 | |
| 30 | #include <linux/swap.h> |
| 31 | #include <linux/bootmem.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 32 | #include <linux/uaccess.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 33 | #include <asm/bfin-global.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 34 | #include <asm/l1layout.h> |
| 35 | #include "blackfin_sram.h" |
| 36 | |
| 37 | /* |
| 38 | * BAD_PAGE is the page that is used for page faults when linux |
| 39 | * is out-of-memory. Older versions of linux just did a |
| 40 | * do_exit(), but using this instead means there is less risk |
| 41 | * for a process dying in kernel mode, possibly leaving a inode |
| 42 | * unused etc.. |
| 43 | * |
| 44 | * BAD_PAGETABLE is the accompanying page-table: it is initialized |
| 45 | * to point to BAD_PAGE entries. |
| 46 | * |
| 47 | * ZERO_PAGE is a special page that is used for zero-initialized |
| 48 | * data and COW. |
| 49 | */ |
| 50 | static unsigned long empty_bad_page_table; |
| 51 | |
| 52 | static unsigned long empty_bad_page; |
| 53 | |
| 54 | unsigned long empty_zero_page; |
| 55 | |
Robin Getz | b76f987 | 2007-10-10 17:25:15 +0800 | [diff] [blame] | 56 | void show_mem(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 57 | { |
| 58 | unsigned long i; |
| 59 | int free = 0, total = 0, reserved = 0, shared = 0; |
| 60 | |
| 61 | int cached = 0; |
| 62 | printk(KERN_INFO "Mem-info:\n"); |
| 63 | show_free_areas(); |
| 64 | i = max_mapnr; |
| 65 | while (i-- > 0) { |
| 66 | total++; |
| 67 | if (PageReserved(mem_map + i)) |
| 68 | reserved++; |
| 69 | else if (PageSwapCache(mem_map + i)) |
| 70 | cached++; |
| 71 | else if (!page_count(mem_map + i)) |
| 72 | free++; |
| 73 | else |
| 74 | shared += page_count(mem_map + i) - 1; |
| 75 | } |
| 76 | printk(KERN_INFO "%d pages of RAM\n", total); |
| 77 | printk(KERN_INFO "%d free pages\n", free); |
| 78 | printk(KERN_INFO "%d reserved pages\n", reserved); |
| 79 | printk(KERN_INFO "%d pages shared\n", shared); |
| 80 | printk(KERN_INFO "%d pages swap cached\n", cached); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * paging_init() continues the virtual memory environment setup which |
| 85 | * was begun by the code in arch/head.S. |
| 86 | * The parameters are pointers to where to stick the starting and ending |
| 87 | * addresses of available kernel virtual memory. |
| 88 | */ |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 89 | void __init paging_init(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 90 | { |
| 91 | /* |
| 92 | * make sure start_mem is page aligned, otherwise bootmem and |
| 93 | * page_alloc get different views og the world |
| 94 | */ |
| 95 | unsigned long end_mem = memory_end & PAGE_MASK; |
| 96 | |
| 97 | pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem); |
| 98 | |
| 99 | /* |
| 100 | * initialize the bad page table and bad page to point |
| 101 | * to a couple of allocated pages |
| 102 | */ |
| 103 | empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
| 104 | empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
| 105 | empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
| 106 | memset((void *)empty_zero_page, 0, PAGE_SIZE); |
| 107 | |
| 108 | /* |
| 109 | * Set up SFC/DFC registers (user data space) |
| 110 | */ |
| 111 | set_fs(KERNEL_DS); |
| 112 | |
| 113 | pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n", |
| 114 | PAGE_ALIGN(memory_start), end_mem); |
| 115 | |
| 116 | { |
| 117 | unsigned long zones_size[MAX_NR_ZONES] = { 0, }; |
| 118 | |
Aubrey Li | e3defff | 2007-05-21 18:09:11 +0800 | [diff] [blame] | 119 | zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT; |
| 120 | zones_size[ZONE_NORMAL] = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 121 | #ifdef CONFIG_HIGHMEM |
| 122 | zones_size[ZONE_HIGHMEM] = 0; |
| 123 | #endif |
| 124 | free_area_init(zones_size); |
| 125 | } |
| 126 | } |
| 127 | |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 128 | void __init mem_init(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 129 | { |
| 130 | unsigned int codek = 0, datak = 0, initk = 0; |
Yi Li | ee7883b | 2008-01-27 19:56:17 +0800 | [diff] [blame] | 131 | unsigned int reservedpages = 0, freepages = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 132 | unsigned long tmp; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 133 | unsigned long start_mem = memory_start; |
| 134 | unsigned long end_mem = memory_end; |
| 135 | |
| 136 | end_mem &= PAGE_MASK; |
| 137 | high_memory = (void *)end_mem; |
| 138 | |
| 139 | start_mem = PAGE_ALIGN(start_mem); |
| 140 | max_mapnr = num_physpages = MAP_NR(high_memory); |
Yi Li | ee7883b | 2008-01-27 19:56:17 +0800 | [diff] [blame] | 141 | printk(KERN_INFO "Kernel managed physical pages: %lu\n", |
| 142 | num_physpages); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 143 | |
| 144 | /* This will put all memory onto the freelists. */ |
| 145 | totalram_pages = free_all_bootmem(); |
| 146 | |
Yi Li | ee7883b | 2008-01-27 19:56:17 +0800 | [diff] [blame] | 147 | reservedpages = 0; |
| 148 | for (tmp = 0; tmp < max_mapnr; tmp++) |
| 149 | if (PageReserved(pfn_to_page(tmp))) |
| 150 | reservedpages++; |
| 151 | freepages = max_mapnr - reservedpages; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 152 | |
Yi Li | ee7883b | 2008-01-27 19:56:17 +0800 | [diff] [blame] | 153 | /* do not count in kernel image between _rambase and _ramstart */ |
| 154 | reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT; |
| 155 | #if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263) |
| 156 | reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> |
| 157 | PAGE_SHIFT; |
| 158 | #endif |
| 159 | |
| 160 | codek = (_etext - _stext) >> 10; |
| 161 | initk = (__init_end - __init_begin) >> 10; |
| 162 | datak = ((_ramstart - _rambase) >> 10) - codek - initk; |
| 163 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 164 | printk(KERN_INFO |
Yi Li | ee7883b | 2008-01-27 19:56:17 +0800 | [diff] [blame] | 165 | "Memory available: %luk/%luk RAM, " |
| 166 | "(%uk init code, %uk kernel code, " |
| 167 | "%uk data, %uk dma, %uk reserved)\n", |
| 168 | (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10, |
| 169 | initk, codek, datak, DMA_UNCACHED_REGION >> 10, |
| 170 | (reservedpages << (PAGE_SHIFT-10))); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 171 | |
| 172 | /* Initialize the blackfin L1 Memory. */ |
| 173 | l1sram_init(); |
| 174 | l1_data_sram_init(); |
| 175 | l1_inst_sram_init(); |
| 176 | |
| 177 | /* Allocate this once; never free it. We assume this gives us a |
| 178 | pointer to the start of L1 scratchpad memory; panic if it |
| 179 | doesn't. */ |
| 180 | tmp = (unsigned long)l1sram_alloc(sizeof(struct l1_scratch_task_info)); |
| 181 | if (tmp != (unsigned long)L1_SCRATCH_TASK_INFO) { |
| 182 | printk(KERN_EMERG "mem_init(): Did not get the right address from l1sram_alloc: %08lx != %08lx\n", |
| 183 | tmp, (unsigned long)L1_SCRATCH_TASK_INFO); |
| 184 | panic("No L1, time to give up\n"); |
| 185 | } |
| 186 | } |
| 187 | |
Mike Frysinger | 1d18947 | 2007-07-12 12:32:00 +0800 | [diff] [blame] | 188 | static __init void free_init_pages(const char *what, unsigned long begin, unsigned long end) |
| 189 | { |
| 190 | unsigned long addr; |
| 191 | /* next to check that the page we free is not a partial page */ |
| 192 | for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) { |
| 193 | ClearPageReserved(virt_to_page(addr)); |
| 194 | init_page_count(virt_to_page(addr)); |
| 195 | free_page(addr); |
| 196 | totalram_pages++; |
| 197 | } |
| 198 | printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); |
| 199 | } |
| 200 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 201 | #ifdef CONFIG_BLK_DEV_INITRD |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 202 | void __init free_initrd_mem(unsigned long start, unsigned long end) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 203 | { |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 204 | #ifndef CONFIG_MPU |
Mike Frysinger | 1d18947 | 2007-07-12 12:32:00 +0800 | [diff] [blame] | 205 | free_init_pages("initrd memory", start, end); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 206 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 207 | } |
| 208 | #endif |
| 209 | |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 210 | void __init free_initmem(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 211 | { |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 212 | #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU |
Mike Frysinger | 1d18947 | 2007-07-12 12:32:00 +0800 | [diff] [blame] | 213 | free_init_pages("unused kernel memory", |
| 214 | (unsigned long)(&__init_begin), |
| 215 | (unsigned long)(&__init_end)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 216 | #endif |
| 217 | } |