Commit d9d7e769815c9cb66c8a4b144f066bb957ebd98e

Authored by Jiang Liu
Committed by Linus Torvalds
1 parent 6703bdf669

mm/blackfin: prepare for removing num_physpages and simplify mem_init()

Prepare for removing num_physpages and simplify mem_init().

Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Bob Liu <lliubbo@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 6 additions and 32 deletions Inline Diff

arch/blackfin/mm/init.c
1 /* 1 /*
2 * Copyright 2004-2009 Analog Devices Inc. 2 * Copyright 2004-2009 Analog Devices Inc.
3 * 3 *
4 * Licensed under the GPL-2 or later. 4 * Licensed under the GPL-2 or later.
5 */ 5 */
6 6
7 #include <linux/gfp.h> 7 #include <linux/gfp.h>
8 #include <linux/swap.h> 8 #include <linux/swap.h>
9 #include <linux/bootmem.h> 9 #include <linux/bootmem.h>
10 #include <linux/uaccess.h> 10 #include <linux/uaccess.h>
11 #include <linux/export.h> 11 #include <linux/export.h>
12 #include <asm/bfin-global.h> 12 #include <asm/bfin-global.h>
13 #include <asm/pda.h> 13 #include <asm/pda.h>
14 #include <asm/cplbinit.h> 14 #include <asm/cplbinit.h>
15 #include <asm/early_printk.h> 15 #include <asm/early_printk.h>
16 #include "blackfin_sram.h" 16 #include "blackfin_sram.h"
17 17
18 /* 18 /*
19 * ZERO_PAGE is a special page that is used for zero-initialized data and COW. 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. 20 * Let the bss do its zero-init magic so we don't have to do it ourselves.
21 */ 21 */
22 char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); 22 char empty_zero_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
23 EXPORT_SYMBOL(empty_zero_page); 23 EXPORT_SYMBOL(empty_zero_page);
24 24
25 #ifndef CONFIG_EXCEPTION_L1_SCRATCH 25 #ifndef CONFIG_EXCEPTION_L1_SCRATCH
26 #if defined CONFIG_SYSCALL_TAB_L1 26 #if defined CONFIG_SYSCALL_TAB_L1
27 __attribute__((l1_data)) 27 __attribute__((l1_data))
28 #endif 28 #endif
29 static unsigned long exception_stack[NR_CPUS][1024]; 29 static unsigned long exception_stack[NR_CPUS][1024];
30 #endif 30 #endif
31 31
32 struct blackfin_pda cpu_pda[NR_CPUS]; 32 struct blackfin_pda cpu_pda[NR_CPUS];
33 EXPORT_SYMBOL(cpu_pda); 33 EXPORT_SYMBOL(cpu_pda);
34 34
35 /* 35 /*
36 * paging_init() continues the virtual memory environment setup which 36 * paging_init() continues the virtual memory environment setup which
37 * was begun by the code in arch/head.S. 37 * was begun by the code in arch/head.S.
38 * The parameters are pointers to where to stick the starting and ending 38 * The parameters are pointers to where to stick the starting and ending
39 * addresses of available kernel virtual memory. 39 * addresses of available kernel virtual memory.
40 */ 40 */
41 void __init paging_init(void) 41 void __init paging_init(void)
42 { 42 {
43 /* 43 /*
44 * make sure start_mem is page aligned, otherwise bootmem and 44 * make sure start_mem is page aligned, otherwise bootmem and
45 * page_alloc get different views of the world 45 * page_alloc get different views of the world
46 */ 46 */
47 unsigned long end_mem = memory_end & PAGE_MASK; 47 unsigned long end_mem = memory_end & PAGE_MASK;
48 48
49 unsigned long zones_size[MAX_NR_ZONES] = { 49 unsigned long zones_size[MAX_NR_ZONES] = {
50 [0] = 0, 50 [0] = 0,
51 [ZONE_DMA] = (end_mem - CONFIG_PHY_RAM_BASE_ADDRESS) >> PAGE_SHIFT, 51 [ZONE_DMA] = (end_mem - CONFIG_PHY_RAM_BASE_ADDRESS) >> PAGE_SHIFT,
52 [ZONE_NORMAL] = 0, 52 [ZONE_NORMAL] = 0,
53 #ifdef CONFIG_HIGHMEM 53 #ifdef CONFIG_HIGHMEM
54 [ZONE_HIGHMEM] = 0, 54 [ZONE_HIGHMEM] = 0,
55 #endif 55 #endif
56 }; 56 };
57 57
58 /* Set up SFC/DFC registers (user data space) */ 58 /* Set up SFC/DFC registers (user data space) */
59 set_fs(KERNEL_DS); 59 set_fs(KERNEL_DS);
60 60
61 pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n", 61 pr_debug("free_area_init -> start_mem is %#lx virtual_end is %#lx\n",
62 PAGE_ALIGN(memory_start), end_mem); 62 PAGE_ALIGN(memory_start), end_mem);
63 free_area_init_node(0, zones_size, 63 free_area_init_node(0, zones_size,
64 CONFIG_PHY_RAM_BASE_ADDRESS >> PAGE_SHIFT, NULL); 64 CONFIG_PHY_RAM_BASE_ADDRESS >> PAGE_SHIFT, NULL);
65 } 65 }
66 66
67 asmlinkage void __init init_pda(void) 67 asmlinkage void __init init_pda(void)
68 { 68 {
69 unsigned int cpu = raw_smp_processor_id(); 69 unsigned int cpu = raw_smp_processor_id();
70 70
71 early_shadow_stamp(); 71 early_shadow_stamp();
72 72
73 /* Initialize the PDA fields holding references to other parts 73 /* Initialize the PDA fields holding references to other parts
74 of the memory. The content of such memory is still 74 of the memory. The content of such memory is still
75 undefined at the time of the call, we are only setting up 75 undefined at the time of the call, we are only setting up
76 valid pointers to it. */ 76 valid pointers to it. */
77 memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu])); 77 memset(&cpu_pda[cpu], 0, sizeof(cpu_pda[cpu]));
78 78
79 #ifdef CONFIG_EXCEPTION_L1_SCRATCH 79 #ifdef CONFIG_EXCEPTION_L1_SCRATCH
80 cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \ 80 cpu_pda[cpu].ex_stack = (unsigned long *)(L1_SCRATCH_START + \
81 L1_SCRATCH_LENGTH); 81 L1_SCRATCH_LENGTH);
82 #else 82 #else
83 cpu_pda[cpu].ex_stack = exception_stack[cpu + 1]; 83 cpu_pda[cpu].ex_stack = exception_stack[cpu + 1];
84 #endif 84 #endif
85 85
86 #ifdef CONFIG_SMP 86 #ifdef CONFIG_SMP
87 cpu_pda[cpu].imask = 0x1f; 87 cpu_pda[cpu].imask = 0x1f;
88 #endif 88 #endif
89 } 89 }
90 90
91 void __init mem_init(void) 91 void __init mem_init(void)
92 { 92 {
93 unsigned int codek = 0, datak = 0, initk = 0; 93 char buf[64];
94 unsigned int reservedpages = 0, freepages = 0;
95 unsigned long tmp;
96 unsigned long start_mem = memory_start;
97 unsigned long end_mem = memory_end;
98 94
99 end_mem &= PAGE_MASK; 95 high_memory = (void *)(memory_end & PAGE_MASK);
100 high_memory = (void *)end_mem; 96 max_mapnr = MAP_NR(high_memory);
97 printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", max_mapnr);
101 98
102 start_mem = PAGE_ALIGN(start_mem);
103 max_mapnr = num_physpages = MAP_NR(high_memory);
104 printk(KERN_DEBUG "Kernel managed physical pages: %lu\n", num_physpages);
105
106 /* This will put all low memory onto the freelists. */ 99 /* This will put all low memory onto the freelists. */
107 free_all_bootmem(); 100 free_all_bootmem();
108 101
109 reservedpages = 0; 102 snprintf(buf, sizeof(buf) - 1, "%uK DMA", DMA_UNCACHED_REGION >> 10);
110 for (tmp = ARCH_PFN_OFFSET; tmp < max_mapnr; tmp++) 103 mem_init_print_info(buf);
111 if (PageReserved(pfn_to_page(tmp)))
112 reservedpages++;
113 freepages = max_mapnr - ARCH_PFN_OFFSET - reservedpages;
114
115 /* do not count in kernel image between _rambase and _ramstart */
116 reservedpages -= (_ramstart - _rambase) >> PAGE_SHIFT;
117 #if (defined(CONFIG_BFIN_EXTMEM_ICACHEABLE) && ANOMALY_05000263)
118 reservedpages += (_ramend - memory_end - DMA_UNCACHED_REGION) >> PAGE_SHIFT;
119 #endif
120
121 codek = (_etext - _stext) >> 10;
122 initk = (__init_end - __init_begin) >> 10;
123 datak = ((_ramstart - _rambase) >> 10) - codek - initk;
124
125 printk(KERN_INFO
126 "Memory available: %luk/%luk RAM, "
127 "(%uk init code, %uk kernel code, %uk data, %uk dma, %uk reserved)\n",
128 (unsigned long) freepages << (PAGE_SHIFT-10), (_ramend - CONFIG_PHY_RAM_BASE_ADDRESS) >> 10,
129 initk, codek, datak, DMA_UNCACHED_REGION >> 10, (reservedpages << (PAGE_SHIFT-10)));
130 } 104 }
131 105
132 #ifdef CONFIG_BLK_DEV_INITRD 106 #ifdef CONFIG_BLK_DEV_INITRD
133 void __init free_initrd_mem(unsigned long start, unsigned long end) 107 void __init free_initrd_mem(unsigned long start, unsigned long end)
134 { 108 {
135 #ifndef CONFIG_MPU 109 #ifndef CONFIG_MPU
136 free_reserved_area((void *)start, (void *)end, -1, "initrd"); 110 free_reserved_area((void *)start, (void *)end, -1, "initrd");
137 #endif 111 #endif
138 } 112 }
139 #endif 113 #endif
140 114
141 void __init_refok free_initmem(void) 115 void __init_refok free_initmem(void)
142 { 116 {
143 #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU 117 #if defined CONFIG_RAMKERNEL && !defined CONFIG_MPU
144 free_initmem_default(-1); 118 free_initmem_default(-1);
145 if (memory_start == (unsigned long)(&__init_end)) 119 if (memory_start == (unsigned long)(&__init_end))
146 memory_start = (unsigned long)(&__init_begin); 120 memory_start = (unsigned long)(&__init_begin);
147 #endif 121 #endif
148 } 122 }