Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * Copyright 2004-2009 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 4 | * Licensed under the GPL-2 or later. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 7 | #include <linux/gfp.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 8 | #include <linux/swap.h> |
| 9 | #include <linux/bootmem.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 10 | #include <linux/uaccess.h> |
Paul Gortmaker | 8dc7a9c | 2011-08-09 11:05:22 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 12 | #include <asm/bfin-global.h> |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 13 | #include <asm/pda.h> |
| 14 | #include <asm/cplbinit.h> |
Robin Getz | 837ec2d | 2009-07-07 20:17:09 +0000 | [diff] [blame] | 15 | #include <asm/early_printk.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 16 | #include "blackfin_sram.h" |
| 17 | |
| 18 | /* |
Mike Frysinger | f074e48 | 2009-04-23 21:28:32 +0000 | [diff] [blame] | 19 | * 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 Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 21 | */ |
Mike Frysinger | f074e48 | 2009-04-23 21:28:32 +0000 | [diff] [blame] | 22 | char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); |
| 23 | EXPORT_SYMBOL(empty_zero_page); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 24 | |
Graf Yang | f82e0a0 | 2009-04-08 08:30:22 +0000 | [diff] [blame] | 25 | #ifndef CONFIG_EXCEPTION_L1_SCRATCH |
| 26 | #if defined CONFIG_SYSCALL_TAB_L1 |
| 27 | __attribute__((l1_data)) |
| 28 | #endif |
| 29 | static unsigned long exception_stack[NR_CPUS][1024]; |
| 30 | #endif |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 31 | |
| 32 | struct blackfin_pda cpu_pda[NR_CPUS]; |
| 33 | EXPORT_SYMBOL(cpu_pda); |
| 34 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 35 | /* |
| 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 Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 41 | void __init paging_init(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 42 | { |
| 43 | /* |
Mike Frysinger | d012ce2 | 2009-04-23 22:17:37 +0000 | [diff] [blame] | 44 | * make sure start_mem is page aligned, otherwise bootmem and |
| 45 | * page_alloc get different views of the world |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 46 | */ |
| 47 | unsigned long end_mem = memory_end & PAGE_MASK; |
| 48 | |
Mike Frysinger | d012ce2 | 2009-04-23 22:17:37 +0000 | [diff] [blame] | 49 | unsigned long zones_size[MAX_NR_ZONES] = { |
| 50 | [0] = 0, |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 51 | [ZONE_DMA] = (end_mem - CONFIG_PHY_RAM_BASE_ADDRESS) >> PAGE_SHIFT, |
Mike Frysinger | d012ce2 | 2009-04-23 22:17:37 +0000 | [diff] [blame] | 52 | [ZONE_NORMAL] = 0, |
| 53 | #ifdef CONFIG_HIGHMEM |
| 54 | [ZONE_HIGHMEM] = 0, |
| 55 | #endif |
| 56 | }; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 57 | |
Mike Frysinger | d012ce2 | 2009-04-23 22:17:37 +0000 | [diff] [blame] | 58 | /* Set up SFC/DFC registers (user data space) */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 59 | set_fs(KERNEL_DS); |
| 60 | |
Mike Frysinger | d012ce2 | 2009-04-23 22:17:37 +0000 | [diff] [blame] | 61 | pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n", |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 62 | PAGE_ALIGN(memory_start), end_mem); |
Bob Liu | b5affb0 | 2012-05-16 17:37:24 +0800 | [diff] [blame] | 63 | free_area_init_node(0, zones_size, |
| 64 | CONFIG_PHY_RAM_BASE_ADDRESS >> PAGE_SHIFT, NULL); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Mike Frysinger | 8e2a769 | 2009-03-05 18:45:07 +0800 | [diff] [blame] | 67 | asmlinkage void __init init_pda(void) |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 68 | { |
| 69 | unsigned int cpu = raw_smp_processor_id(); |
| 70 | |
Robin Getz | 837ec2d | 2009-07-07 20:17:09 +0000 | [diff] [blame] | 71 | early_shadow_stamp(); |
| 72 | |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 73 | /* 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 Yang | f82e0a0 | 2009-04-08 08:30:22 +0000 | [diff] [blame] | 79 | #ifdef CONFIG_EXCEPTION_L1_SCRATCH |
| 80 | cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \ |
| 81 | L1_SCRATCH_LENGTH); |
| 82 | #else |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 83 | cpu_pda[cpu].ex_stack = exception_stack[cpu + 1]; |
Graf Yang | f82e0a0 | 2009-04-08 08:30:22 +0000 | [diff] [blame] | 84 | #endif |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 85 | |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 86 | #ifdef CONFIG_SMP |
| 87 | cpu_pda[cpu].imask = 0x1f; |
| 88 | #endif |
| 89 | } |
| 90 | |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 91 | void __init mem_init(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 92 | { |
Jiang Liu | d9d7e76 | 2013-07-03 15:03:51 -0700 | [diff] [blame] | 93 | char buf[64]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 94 | |
Jiang Liu | d9d7e76 | 2013-07-03 15:03:51 -0700 | [diff] [blame] | 95 | 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 Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 98 | |
Jiang Liu | ed8a36f | 2013-04-29 15:06:33 -0700 | [diff] [blame] | 99 | /* This will put all low memory onto the freelists. */ |
Jiang Liu | 0c98853 | 2013-07-03 15:03:24 -0700 | [diff] [blame] | 100 | free_all_bootmem(); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 101 | |
Jiang Liu | d9d7e76 | 2013-07-03 15:03:51 -0700 | [diff] [blame] | 102 | snprintf(buf, sizeof(buf) - 1, "%uK DMA", DMA_UNCACHED_REGION >> 10); |
| 103 | mem_init_print_info(buf); |
Sonic Zhang | 5d481f4 | 2008-07-19 14:51:31 +0800 | [diff] [blame] | 104 | } |
| 105 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 106 | #ifdef CONFIG_BLK_DEV_INITRD |
Mike Frysinger | 321f6e0 | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 107 | void __init free_initrd_mem(unsigned long start, unsigned long end) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 108 | { |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 109 | #ifndef CONFIG_MPU |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 110 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 111 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 112 | } |
| 113 | #endif |
| 114 | |
Fabian Frederick | bd721ea | 2016-08-02 14:03:33 -0700 | [diff] [blame] | 115 | void __ref free_initmem(void) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 116 | { |
Bernd Schmidt | b97b8a9 | 2008-01-27 18:39:16 +0800 | [diff] [blame] | 117 | #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 118 | free_initmem_default(-1); |
Sonic Zhang | 46284cd | 2010-09-20 11:06:18 +0000 | [diff] [blame] | 119 | if (memory_start == (unsigned long)(&__init_end)) |
| 120 | memory_start = (unsigned long)(&__init_begin); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 121 | #endif |
| 122 | } |