blob: 355b87aa6b9322da7c1e5074e0eb5170fe6d5de3 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Copyright 2004-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07005 */
6
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/gfp.h>
Bryan Wu1394f032007-05-06 14:50:22 -07008#include <linux/swap.h>
9#include <linux/bootmem.h>
Mike Frysinger1f83b8f2007-07-12 22:58:21 +080010#include <linux/uaccess.h>
Bryan Wu1394f032007-05-06 14:50:22 -070011#include <asm/bfin-global.h>
Graf Yang8f658732008-11-18 17:48:22 +080012#include <asm/pda.h>
13#include <asm/cplbinit.h>
Robin Getz837ec2d2009-07-07 20:17:09 +000014#include <asm/early_printk.h>
Bryan Wu1394f032007-05-06 14:50:22 -070015#include "blackfin_sram.h"
16
17/*
18 * BAD_PAGE is the page that is used for page faults when linux
19 * is out-of-memory. Older versions of linux just did a
20 * do_exit(), but using this instead means there is less risk
21 * for a process dying in kernel mode, possibly leaving a inode
22 * unused etc..
23 *
24 * BAD_PAGETABLE is the accompanying page-table: it is initialized
25 * to point to BAD_PAGE entries.
26 *
27 * ZERO_PAGE is a special page that is used for zero-initialized
28 * data and COW.
29 */
30static unsigned long empty_bad_page_table;
31
32static unsigned long empty_bad_page;
33
Graf Yangf82e0a02009-04-08 08:30:22 +000034static unsigned long empty_zero_page;
Bryan Wu1394f032007-05-06 14:50:22 -070035
Graf Yangf82e0a02009-04-08 08:30:22 +000036#ifndef CONFIG_EXCEPTION_L1_SCRATCH
37#if defined CONFIG_SYSCALL_TAB_L1
38__attribute__((l1_data))
39#endif
40static unsigned long exception_stack[NR_CPUS][1024];
41#endif
Graf Yang8f658732008-11-18 17:48:22 +080042
43struct blackfin_pda cpu_pda[NR_CPUS];
44EXPORT_SYMBOL(cpu_pda);
45
Bryan Wu1394f032007-05-06 14:50:22 -070046/*
47 * paging_init() continues the virtual memory environment setup which
48 * was begun by the code in arch/head.S.
49 * The parameters are pointers to where to stick the starting and ending
50 * addresses of available kernel virtual memory.
51 */
Mike Frysinger321f6e02007-06-11 15:31:30 +080052void __init paging_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -070053{
54 /*
55 * make sure start_mem is page aligned, otherwise bootmem and
56 * page_alloc get different views og the world
57 */
58 unsigned long end_mem = memory_end & PAGE_MASK;
59
60 pr_debug("start_mem is %#lx virtual_end is %#lx\n", PAGE_ALIGN(memory_start), end_mem);
61
62 /*
63 * initialize the bad page table and bad page to point
64 * to a couple of allocated pages
65 */
66 empty_bad_page_table = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
67 empty_bad_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
68 empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
69 memset((void *)empty_zero_page, 0, PAGE_SIZE);
70
71 /*
72 * Set up SFC/DFC registers (user data space)
73 */
74 set_fs(KERNEL_DS);
75
76 pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
77 PAGE_ALIGN(memory_start), end_mem);
78
79 {
80 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
81
Aubrey Lie3defff2007-05-21 18:09:11 +080082 zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT;
83 zones_size[ZONE_NORMAL] = 0;
Bryan Wu1394f032007-05-06 14:50:22 -070084#ifdef CONFIG_HIGHMEM
85 zones_size[ZONE_HIGHMEM] = 0;
86#endif
87 free_area_init(zones_size);
88 }
89}
90
Mike Frysinger8e2a7692009-03-05 18:45:07 +080091asmlinkage void __init init_pda(void)
Graf Yang8f658732008-11-18 17:48:22 +080092{
93 unsigned int cpu = raw_smp_processor_id();
94
Robin Getz837ec2d2009-07-07 20:17:09 +000095 early_shadow_stamp();
96
Graf Yang8f658732008-11-18 17:48:22 +080097 /* Initialize the PDA fields holding references to other parts
98 of the memory. The content of such memory is still
99 undefined at the time of the call, we are only setting up
100 valid pointers to it. */
101 memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
102
103 cpu_pda[0].next = &cpu_pda[1];
104 cpu_pda[1].next = &cpu_pda[0];
105
Graf Yangf82e0a02009-04-08 08:30:22 +0000106#ifdef CONFIG_EXCEPTION_L1_SCRATCH
107 cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
108 L1_SCRATCH_LENGTH);
109#else
Graf Yang8f658732008-11-18 17:48:22 +0800110 cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
Graf Yangf82e0a02009-04-08 08:30:22 +0000111#endif
Graf Yang8f658732008-11-18 17:48:22 +0800112
Graf Yang8f658732008-11-18 17:48:22 +0800113#ifdef CONFIG_SMP
114 cpu_pda[cpu].imask = 0x1f;
115#endif
116}
117
Mike Frysinger321f6e02007-06-11 15:31:30 +0800118void __init mem_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700119{
120 unsigned int codek = 0, datak = 0, initk = 0;
Yi Liee7883b2008-01-27 19:56:17 +0800121 unsigned int reservedpages = 0, freepages = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700122 unsigned long tmp;
Bryan Wu1394f032007-05-06 14:50:22 -0700123 unsigned long start_mem = memory_start;
124 unsigned long end_mem = memory_end;
125
126 end_mem &= PAGE_MASK;
127 high_memory = (void *)end_mem;
128
129 start_mem = PAGE_ALIGN(start_mem);
130 max_mapnr = num_physpages = MAP_NR(high_memory);
Yi Li856783b2008-02-09 02:26:01 +0800131 printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
Bryan Wu1394f032007-05-06 14:50:22 -0700132
133 /* This will put all memory onto the freelists. */
134 totalram_pages = free_all_bootmem();
135
Yi Liee7883b2008-01-27 19:56:17 +0800136 reservedpages = 0;
137 for (tmp = 0; tmp < max_mapnr; tmp++)
138 if (PageReserved(pfn_to_page(tmp)))
139 reservedpages++;
140 freepages = max_mapnr - reservedpages;
Bryan Wu1394f032007-05-06 14:50:22 -0700141
Yi Liee7883b2008-01-27 19:56:17 +0800142 /* do not count in kernel image between _rambase and _ramstart */
143 reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
Jie Zhang41ba6532009-06-16 09:48:33 +0000144#if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
Yi Li856783b2008-02-09 02:26:01 +0800145 reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
Yi Liee7883b2008-01-27 19:56:17 +0800146#endif
147
148 codek = (_etext - _stext) >> 10;
149 initk = (__init_end - __init_begin) >> 10;
150 datak = ((_ramstart - _rambase) >> 10) - codek - initk;
151
Bryan Wu1394f032007-05-06 14:50:22 -0700152 printk(KERN_INFO
Yi Liee7883b2008-01-27 19:56:17 +0800153 "Memory available: %luk/%luk RAM, "
Yi Li856783b2008-02-09 02:26:01 +0800154 "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
Yi Liee7883b2008-01-27 19:56:17 +0800155 (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
Yi Li856783b2008-02-09 02:26:01 +0800156 initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
Sonic Zhang5d481f42008-07-19 14:51:31 +0800157}
158
Bryan Wuc0514892008-02-29 12:02:10 +0800159static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
Mike Frysinger1d189472007-07-12 12:32:00 +0800160{
161 unsigned long addr;
162 /* next to check that the page we free is not a partial page */
163 for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
164 ClearPageReserved(virt_to_page(addr));
165 init_page_count(virt_to_page(addr));
166 free_page(addr);
167 totalram_pages++;
168 }
169 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
170}
171
Bryan Wu1394f032007-05-06 14:50:22 -0700172#ifdef CONFIG_BLK_DEV_INITRD
Mike Frysinger321f6e02007-06-11 15:31:30 +0800173void __init free_initrd_mem(unsigned long start, unsigned long end)
Bryan Wu1394f032007-05-06 14:50:22 -0700174{
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800175#ifndef CONFIG_MPU
Mike Frysinger1d189472007-07-12 12:32:00 +0800176 free_init_pages("initrd memory", start, end);
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800177#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700178}
179#endif
180
Bryan Wuc0514892008-02-29 12:02:10 +0800181void __init_refok free_initmem(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700182{
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800183#if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
Mike Frysinger1d189472007-07-12 12:32:00 +0800184 free_init_pages("unused kernel memory",
185 (unsigned long)(&__init_begin),
186 (unsigned long)(&__init_end));
Bryan Wu1394f032007-05-06 14:50:22 -0700187#endif
188}