Commit | Line | Data |
---|---|---|
1394f032 | 1 | /* |
96f1050d | 2 | * Copyright 2004-2009 Analog Devices Inc. |
1394f032 | 3 | * |
96f1050d | 4 | * Licensed under the GPL-2 or later. |
1394f032 BW |
5 | */ |
6 | ||
5a0e3ad6 | 7 | #include <linux/gfp.h> |
1394f032 BW |
8 | #include <linux/swap.h> |
9 | #include <linux/bootmem.h> | |
1f83b8f1 | 10 | #include <linux/uaccess.h> |
8dc7a9c8 | 11 | #include <linux/export.h> |
1394f032 | 12 | #include <asm/bfin-global.h> |
8f65873e GY |
13 | #include <asm/pda.h> |
14 | #include <asm/cplbinit.h> | |
837ec2d5 | 15 | #include <asm/early_printk.h> |
1394f032 BW |
16 | #include "blackfin_sram.h" |
17 | ||
18 | /* | |
f074e48e MF |
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. | |
1394f032 | 21 | */ |
f074e48e MF |
22 | char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); |
23 | EXPORT_SYMBOL(empty_zero_page); | |
1394f032 | 24 | |
f82e0a0c GY |
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 | |
8f65873e GY |
31 | |
32 | struct blackfin_pda cpu_pda[NR_CPUS]; | |
33 | EXPORT_SYMBOL(cpu_pda); | |
34 | ||
1394f032 BW |
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 | */ | |
321f6e0f | 41 | void __init paging_init(void) |
1394f032 BW |
42 | { |
43 | /* | |
d012ce22 MF |
44 | * make sure start_mem is page aligned, otherwise bootmem and |
45 | * page_alloc get different views of the world | |
1394f032 BW |
46 | */ |
47 | unsigned long end_mem = memory_end & PAGE_MASK; | |
48 | ||
d012ce22 MF |
49 | unsigned long zones_size[MAX_NR_ZONES] = { |
50 | [0] = 0, | |
b5affb01 | 51 | [ZONE_DMA] = (end_mem - CONFIG_PHY_RAM_BASE_ADDRESS) >> PAGE_SHIFT, |
d012ce22 MF |
52 | [ZONE_NORMAL] = 0, |
53 | #ifdef CONFIG_HIGHMEM | |
54 | [ZONE_HIGHMEM] = 0, | |
55 | #endif | |
56 | }; | |
1394f032 | 57 | |
d012ce22 | 58 | /* Set up SFC/DFC registers (user data space) */ |
1394f032 BW |
59 | set_fs(KERNEL_DS); |
60 | ||
d012ce22 | 61 | pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n", |
1394f032 | 62 | PAGE_ALIGN(memory_start), end_mem); |
b5affb01 BL |
63 | free_area_init_node(0, zones_size, |
64 | CONFIG_PHY_RAM_BASE_ADDRESS >> PAGE_SHIFT, NULL); | |
1394f032 BW |
65 | } |
66 | ||
8e2a7694 | 67 | asmlinkage void __init init_pda(void) |
8f65873e GY |
68 | { |
69 | unsigned int cpu = raw_smp_processor_id(); | |
70 | ||
837ec2d5 RG |
71 | early_shadow_stamp(); |
72 | ||
8f65873e GY |
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 | ||
f82e0a0c GY |
79 | #ifdef CONFIG_EXCEPTION_L1_SCRATCH |
80 | cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \ | |
81 | L1_SCRATCH_LENGTH); | |
82 | #else | |
8f65873e | 83 | cpu_pda[cpu].ex_stack = exception_stack[cpu + 1]; |
f82e0a0c | 84 | #endif |
8f65873e | 85 | |
8f65873e GY |
86 | #ifdef CONFIG_SMP |
87 | cpu_pda[cpu].imask = 0x1f; | |
88 | #endif | |
89 | } | |
90 | ||
321f6e0f | 91 | void __init mem_init(void) |
1394f032 BW |
92 | { |
93 | unsigned int codek = 0, datak = 0, initk = 0; | |
ee7883b7 | 94 | unsigned int reservedpages = 0, freepages = 0; |
1394f032 | 95 | unsigned long tmp; |
1394f032 BW |
96 | unsigned long start_mem = memory_start; |
97 | unsigned long end_mem = memory_end; | |
98 | ||
99 | end_mem &= PAGE_MASK; | |
100 | high_memory = (void *)end_mem; | |
101 | ||
102 | start_mem = PAGE_ALIGN(start_mem); | |
103 | max_mapnr = num_physpages = MAP_NR(high_memory); | |
856783b3 | 104 | printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages); |
1394f032 BW |
105 | |
106 | /* This will put all memory onto the freelists. */ | |
107 | totalram_pages = free_all_bootmem(); | |
108 | ||
ee7883b7 | 109 | reservedpages = 0; |
b5affb01 | 110 | for (tmp = ARCH_PFN_OFFSET; tmp < max_mapnr; tmp++) |
ee7883b7 YL |
111 | if (PageReserved(pfn_to_page(tmp))) |
112 | reservedpages++; | |
b5affb01 | 113 | freepages = max_mapnr - ARCH_PFN_OFFSET - reservedpages; |
ee7883b7 YL |
114 | |
115 | /* do not count in kernel image between _rambase and _ramstart */ | |
116 | reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT; | |
41ba653f | 117 | #if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263) |
856783b3 | 118 | reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT; |
ee7883b7 YL |
119 | #endif |
120 | ||
1394f032 | 121 | codek = (_etext - _stext) >> 10; |
1394f032 | 122 | initk = (__init_end - __init_begin) >> 10; |
ee7883b7 | 123 | datak = ((_ramstart - _rambase) >> 10) - codek - initk; |
1394f032 | 124 | |
1394f032 | 125 | printk(KERN_INFO |
ee7883b7 | 126 | "Memory available: %luk/%luk RAM, " |
856783b3 | 127 | "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n", |
b5affb01 | 128 | (unsigned long) freepages << (PAGE_SHIFT-10), (_ramend - CONFIG_PHY_RAM_BASE_ADDRESS) >> 10, |
856783b3 | 129 | initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10))); |
5d481f49 SZ |
130 | } |
131 | ||
c051489d | 132 | static void __init free_init_pages(const char *what, unsigned long begin, unsigned long end) |
1394f032 | 133 | { |
1d189474 MF |
134 | unsigned long addr; |
135 | /* next to check that the page we free is not a partial page */ | |
136 | for (addr = begin; addr + PAGE_SIZE <= end; addr += PAGE_SIZE) { | |
137 | ClearPageReserved(virt_to_page(addr)); | |
138 | init_page_count(virt_to_page(addr)); | |
139 | free_page(addr); | |
1394f032 | 140 | totalram_pages++; |
1394f032 | 141 | } |
1d189474 MF |
142 | printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); |
143 | } | |
144 | ||
145 | #ifdef CONFIG_BLK_DEV_INITRD | |
146 | void __init free_initrd_mem(unsigned long start, unsigned long end) | |
147 | { | |
b97b8a99 | 148 | #ifndef CONFIG_MPU |
1d189474 | 149 | free_init_pages("initrd memory", start, end); |
b97b8a99 | 150 | #endif |
1394f032 BW |
151 | } |
152 | #endif | |
153 | ||
c051489d | 154 | void __init_refok free_initmem(void) |
1394f032 | 155 | { |
b97b8a99 | 156 | #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU |
1d189474 MF |
157 | free_init_pages("unused kernel memory", |
158 | (unsigned long)(&__init_begin), | |
159 | (unsigned long)(&__init_end)); | |
46284cd6 SZ |
160 | |
161 | if (memory_start == (unsigned long)(&__init_end)) | |
162 | memory_start = (unsigned long)(&__init_begin); | |
1394f032 BW |
163 | #endif |
164 | } |