blob: b59cd7c3261abe2253cccf5bf8ef279e92019bcd [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>
Paul Gortmaker8dc7a9c2011-08-09 11:05:22 -040011#include <linux/export.h>
Bryan Wu1394f032007-05-06 14:50:22 -070012#include <asm/bfin-global.h>
Graf Yang8f658732008-11-18 17:48:22 +080013#include <asm/pda.h>
14#include <asm/cplbinit.h>
Robin Getz837ec2d2009-07-07 20:17:09 +000015#include <asm/early_printk.h>
Bryan Wu1394f032007-05-06 14:50:22 -070016#include "blackfin_sram.h"
17
18/*
Mike Frysingerf074e482009-04-23 21:28:32 +000019 * ZERO_PAGE is a special page that is used for zero-initialized data and COW.
20 * Let the bss do its zero-init magic so we don't have to do it ourselves.
Bryan Wu1394f032007-05-06 14:50:22 -070021 */
Mike Frysingerf074e482009-04-23 21:28:32 +000022char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
23EXPORT_SYMBOL(empty_zero_page);
Bryan Wu1394f032007-05-06 14:50:22 -070024
Graf Yangf82e0a02009-04-08 08:30:22 +000025#ifndef CONFIG_EXCEPTION_L1_SCRATCH
26#if defined CONFIG_SYSCALL_TAB_L1
27__attribute__((l1_data))
28#endif
29static unsigned long exception_stack[NR_CPUS][1024];
30#endif
Graf Yang8f658732008-11-18 17:48:22 +080031
32struct blackfin_pda cpu_pda[NR_CPUS];
33EXPORT_SYMBOL(cpu_pda);
34
Bryan Wu1394f032007-05-06 14:50:22 -070035/*
36 * paging_init() continues the virtual memory environment setup which
37 * was begun by the code in arch/head.S.
38 * The parameters are pointers to where to stick the starting and ending
39 * addresses of available kernel virtual memory.
40 */
Mike Frysinger321f6e02007-06-11 15:31:30 +080041void __init paging_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -070042{
43 /*
Mike Frysingerd012ce22009-04-23 22:17:37 +000044 * make sure start_mem is page aligned, otherwise bootmem and
45 * page_alloc get different views of the world
Bryan Wu1394f032007-05-06 14:50:22 -070046 */
47 unsigned long end_mem = memory_end & PAGE_MASK;
48
Mike Frysingerd012ce22009-04-23 22:17:37 +000049 unsigned long zones_size[MAX_NR_ZONES] = {
50 [0] = 0,
Bob Liub5affb02012-05-16 17:37:24 +080051 [ZONE_DMA] = (end_mem - CONFIG_PHY_RAM_BASE_ADDRESS) >> PAGE_SHIFT,
Mike Frysingerd012ce22009-04-23 22:17:37 +000052 [ZONE_NORMAL] = 0,
53#ifdef CONFIG_HIGHMEM
54 [ZONE_HIGHMEM] = 0,
55#endif
56 };
Bryan Wu1394f032007-05-06 14:50:22 -070057
Mike Frysingerd012ce22009-04-23 22:17:37 +000058 /* Set up SFC/DFC registers (user data space) */
Bryan Wu1394f032007-05-06 14:50:22 -070059 set_fs(KERNEL_DS);
60
Mike Frysingerd012ce22009-04-23 22:17:37 +000061 pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
Bryan Wu1394f032007-05-06 14:50:22 -070062 PAGE_ALIGN(memory_start), end_mem);
Bob Liub5affb02012-05-16 17:37:24 +080063 free_area_init_node(0, zones_size,
64 CONFIG_PHY_RAM_BASE_ADDRESS >> PAGE_SHIFT, NULL);
Bryan Wu1394f032007-05-06 14:50:22 -070065}
66
Mike Frysinger8e2a7692009-03-05 18:45:07 +080067asmlinkage void __init init_pda(void)
Graf Yang8f658732008-11-18 17:48:22 +080068{
69 unsigned int cpu = raw_smp_processor_id();
70
Robin Getz837ec2d2009-07-07 20:17:09 +000071 early_shadow_stamp();
72
Graf Yang8f658732008-11-18 17:48:22 +080073 /* Initialize the PDA fields holding references to other parts
74 of the memory. The content of such memory is still
75 undefined at the time of the call, we are only setting up
76 valid pointers to it. */
77 memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
78
Graf Yangf82e0a02009-04-08 08:30:22 +000079#ifdef CONFIG_EXCEPTION_L1_SCRATCH
80 cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
81 L1_SCRATCH_LENGTH);
82#else
Graf Yang8f658732008-11-18 17:48:22 +080083 cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
Graf Yangf82e0a02009-04-08 08:30:22 +000084#endif
Graf Yang8f658732008-11-18 17:48:22 +080085
Graf Yang8f658732008-11-18 17:48:22 +080086#ifdef CONFIG_SMP
87 cpu_pda[cpu].imask = 0x1f;
88#endif
89}
90
Mike Frysinger321f6e02007-06-11 15:31:30 +080091void __init mem_init(void)
Bryan Wu1394f032007-05-06 14:50:22 -070092{
Jiang Liud9d7e762013-07-03 15:03:51 -070093 char buf[64];
Bryan Wu1394f032007-05-06 14:50:22 -070094
Jiang Liud9d7e762013-07-03 15:03:51 -070095 high_memory = (void *)(memory_end & PAGE_MASK);
96 max_mapnr = MAP_NR(high_memory);
97 printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", max_mapnr);
Bryan Wu1394f032007-05-06 14:50:22 -070098
Jiang Liued8a36f2013-04-29 15:06:33 -070099 /* This will put all low memory onto the freelists. */
Jiang Liu0c988532013-07-03 15:03:24 -0700100 free_all_bootmem();
Bryan Wu1394f032007-05-06 14:50:22 -0700101
Jiang Liud9d7e762013-07-03 15:03:51 -0700102 snprintf(buf, sizeof(buf) - 1, "%uK DMA", DMA_UNCACHED_REGION >> 10);
103 mem_init_print_info(buf);
Sonic Zhang5d481f42008-07-19 14:51:31 +0800104}
105
Bryan Wu1394f032007-05-06 14:50:22 -0700106#ifdef CONFIG_BLK_DEV_INITRD
Mike Frysinger321f6e02007-06-11 15:31:30 +0800107void __init free_initrd_mem(unsigned long start, unsigned long end)
Bryan Wu1394f032007-05-06 14:50:22 -0700108{
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800109#ifndef CONFIG_MPU
Jiang Liudbe67df2013-07-03 15:02:51 -0700110 free_reserved_area((void *)start, (void *)end, -1, "initrd");
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800111#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700112}
113#endif
114
Fabian Frederickbd721ea2016-08-02 14:03:33 -0700115void __ref free_initmem(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700116{
Bernd Schmidtb97b8a92008-01-27 18:39:16 +0800117#if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
Jiang Liudbe67df2013-07-03 15:02:51 -0700118 free_initmem_default(-1);
Sonic Zhang46284cd2010-09-20 11:06:18 +0000119 if (memory_start == (unsigned long)(&__init_end))
120 memory_start = (unsigned long)(&__init_begin);
Bryan Wu1394f032007-05-06 14:50:22 -0700121#endif
122}