blob: bb4e8fff4b556f14751e9502d407b6c3398679bf [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/*
Mike Frysingerf074e482009-04-23 21:28:32 +000018 * ZERO_PAGE is a special page that is used for zero-initialized data and COW.
19 * Let the bss do its zero-init magic so we don't have to do it ourselves.
Bryan Wu1394f032007-05-06 14:50:22 -070020 */
Mike Frysingerf074e482009-04-23 21:28:32 +000021char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
22EXPORT_SYMBOL(empty_zero_page);
Bryan Wu1394f032007-05-06 14:50:22 -070023
Graf Yangf82e0a02009-04-08 08:30:22 +000024#ifndef CONFIG_EXCEPTION_L1_SCRATCH
25#if defined CONFIG_SYSCALL_TAB_L1
26__attribute__((l1_data))
27#endif
28static unsigned long exception_stack[NR_CPUS][1024];
29#endif
Graf Yang8f658732008-11-18 17:48:22 +080030
31struct blackfin_pda cpu_pda[NR_CPUS];
32EXPORT_SYMBOL(cpu_pda);
33
Bryan Wu1394f032007-05-06 14:50:22 -070034/*
35 * paging_init() continues the virtual memory environment setup which
36 * was begun by the code in arch/head.S.
37 * The parameters are pointers to where to stick the starting and ending
38 * addresses of available kernel virtual memory.
39 */
Mike Frysinger321f6e02007-06-11 15:31:30 +080040void __init paging_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -070041{
42 /*
Mike Frysingerd012ce22009-04-23 22:17:37 +000043 * make sure start_mem is page aligned, otherwise bootmem and
44 * page_alloc get different views of the world
Bryan Wu1394f032007-05-06 14:50:22 -070045 */
46 unsigned long end_mem = memory_end & PAGE_MASK;
47
Mike Frysingerd012ce22009-04-23 22:17:37 +000048 unsigned long zones_size[MAX_NR_ZONES] = {
49 [0] = 0,
50 [ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT,
51 [ZONE_NORMAL] = 0,
52#ifdef CONFIG_HIGHMEM
53 [ZONE_HIGHMEM] = 0,
54#endif
55 };
Bryan Wu1394f032007-05-06 14:50:22 -070056
Mike Frysingerd012ce22009-04-23 22:17:37 +000057 /* Set up SFC/DFC registers (user data space) */
Bryan Wu1394f032007-05-06 14:50:22 -070058 set_fs(KERNEL_DS);
59
Mike Frysingerd012ce22009-04-23 22:17:37 +000060 pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -070061 PAGE_ALIGN(memory_start), end_mem);
Mike Frysingerd012ce22009-04-23 22:17:37 +000062 free_area_init(zones_size);
Bryan Wu1394f032007-05-06 14:50:22 -070063}
64
Mike Frysinger8e2a7692009-03-05 18:45:07 +080065asmlinkage void __init init_pda(void)
Graf Yang8f658732008-11-18 17:48:22 +080066{
67 unsigned int cpu = raw_smp_processor_id();
68
Robin Getz837ec2d2009-07-07 20:17:09 +000069 early_shadow_stamp();
70
Graf Yang8f658732008-11-18 17:48:22 +080071 /* Initialize the PDA fields holding references to other parts
72 of the memory. The content of such memory is still
73 undefined at the time of the call, we are only setting up
74 valid pointers to it. */
75 memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
76
77 cpu_pda[0].next = &cpu_pda[1];
78 cpu_pda[1].next = &cpu_pda[0];
79
Graf Yangf82e0a02009-04-08 08:30:22 +000080#ifdef CONFIG_EXCEPTION_L1_SCRATCH
81 cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
82 L1_SCRATCH_LENGTH);
83#else
Graf Yang8f658732008-11-18 17:48:22 +080084 cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
Graf Yangf82e0a02009-04-08 08:30:22 +000085#endif
Graf Yang8f658732008-11-18 17:48:22 +080086
Graf Yang8f658732008-11-18 17:48:22 +080087#ifdef CONFIG_SMP
88 cpu_pda[cpu].imask = 0x1f;
89#endif
90}
91
Mike Frysinger321f6e02007-06-11 15:31:30 +080092void __init mem_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -070093{
94 unsigned int codek = 0, datak = 0, initk = 0;
Yi Liee7883b2008-01-27 19:56:17 +080095 unsigned int reservedpages = 0, freepages = 0;
Bryan Wu1394f032007-05-06 14:50:22 -070096 unsigned long tmp;
Bryan Wu1394f032007-05-06 14:50:22 -070097 unsigned long start_mem = memory_start;
98 unsigned long end_mem = memory_end;
99
100 end_mem &= PAGE_MASK;
101 high_memory = (void *)end_mem;
102
103 start_mem = PAGE_ALIGN(start_mem);
104 max_mapnr = num_physpages = MAP_NR(high_memory);
Yi Li856783b2008-02-09 02:26:01 +0800105 printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
Bryan Wu1394f032007-05-06 14:50:22 -0700106
107 /* This will put all memory onto the freelists. */
108 totalram_pages = free_all_bootmem();
109
Yi Liee7883b2008-01-27 19:56:17 +0800110 reservedpages = 0;
111 for (tmp = 0; tmp < max_mapnr; tmp++)
112 if (PageReserved(pfn_to_page(tmp)))
113 reservedpages++;
114 freepages = max_mapnr - reservedpages;
Bryan Wu1394f032007-05-06 14:50:22 -0700115
Yi Liee7883b2008-01-27 19:56:17 +0800116 /* do not count in kernel image between _rambase and _ramstart */
117 reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
Jie Zhang41ba6532009-06-16 09:48:33 +0000118#if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
Yi Li856783b2008-02-09 02:26:01 +0800119 reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
Yi Liee7883b2008-01-27 19:56:17 +0800120#endif
121
122 codek = (_etext - _stext) >> 10;
123 initk = (__init_end - __init_begin) >> 10;
124 datak = ((_ramstart - _rambase) >> 10) - codek - initk;
125
Bryan Wu1394f032007-05-06 14:50:22 -0700126 printk(KERN_INFO
Yi Liee7883b2008-01-27 19:56:17 +0800127 "Memory available: %luk/%luk RAM, "
Yi Li856783b2008-02-09 02:26:01 +0800128 "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
Yi Liee7883b2008-01-27 19:56:17 +0800129 (unsigned long) freepages << (PAGE_SHIFT-10), _ramend >> 10,
Yi Li856783b2008-02-09 02:26:01 +0800130 initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
Sonic Zhang5d481f42008-07-19 14:51:31 +0800131}
132
Bryan Wuc0514892008-02-29 12:02:10 +0800133static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end)
Mike Frysinger1d189472007-07-12 12:32:00 +0800134{
135 unsigned long addr;
136 /* next to check that the page we free is not a partial page */
137 for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) {
138 ClearPageReserved(virt_to_page(addr));
139 init_page_count(virt_to_page(addr));
140 free_page(addr);
141 totalram_pages++;
142 }
143 printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
144}
145
Bryan Wu1394f032007-05-06 14:50:22 -0700146#ifdef CONFIG_BLK_DEV_INITRD
Mike Frysinger321f6e02007-06-11 15:31:30 +0800147void __init free_initrd_mem(unsigned long start, unsigned long end)
Bryan Wu1394f032007-05-06 14:50:22 -0700148{
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800149#ifndef CONFIG_MPU
Mike Frysinger1d189472007-07-12 12:32:00 +0800150 free_init_pages("initrd memory", start, end);
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800151#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700152}
153#endif
154
Bryan Wuc0514892008-02-29 12:02:10 +0800155void __init_refok free_initmem(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700156{
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800157#if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
Mike Frysinger1d189472007-07-12 12:32:00 +0800158 free_init_pages("unused kernel memory",
159 (unsigned long)(&__init_begin),
160 (unsigned long)(&__init_end));
Bryan Wu1394f032007-05-06 14:50:22 -0700161#endif
162}