s390/mem_detect: limit memory detection loop to "mem=" parameter
[deliverable/linux.git] / arch / s390 / mm / init.c
CommitLineData
1da177e4 1/*
1da177e4 2 * S390 version
a53c8fab 3 * Copyright IBM Corp. 1999
1da177e4
LT
4 * Author(s): Hartmut Penner (hp@de.ibm.com)
5 *
6 * Derived from "arch/i386/mm/init.c"
7 * Copyright (C) 1995 Linus Torvalds
8 */
9
1da177e4
LT
10#include <linux/signal.h>
11#include <linux/sched.h>
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/string.h>
15#include <linux/types.h>
16#include <linux/ptrace.h>
17#include <linux/mman.h>
18#include <linux/mm.h>
19#include <linux/swap.h>
20#include <linux/smp.h>
21#include <linux/init.h>
22#include <linux/pagemap.h>
23#include <linux/bootmem.h>
d882b172 24#include <linux/pfn.h>
028d9b3c 25#include <linux/poison.h>
2b67fc46 26#include <linux/initrd.h>
3a4c5d59 27#include <linux/export.h>
5a0e3ad6 28#include <linux/gfp.h>
1da177e4 29#include <asm/processor.h>
1da177e4
LT
30#include <asm/uaccess.h>
31#include <asm/pgtable.h>
32#include <asm/pgalloc.h>
33#include <asm/dma.h>
34#include <asm/lowcore.h>
35#include <asm/tlb.h>
36#include <asm/tlbflush.h>
d882b172 37#include <asm/sections.h>
a0616cde 38#include <asm/ctl_reg.h>
1da177e4 39
1da177e4 40pgd_t swapper_pg_dir[PTRS_PER_PGD] __attribute__((__aligned__(PAGE_SIZE)));
1485c5c8 41
238ec4ef 42unsigned long empty_zero_page, zero_page_mask;
1485c5c8 43EXPORT_SYMBOL(empty_zero_page);
1da177e4 44
0999f119 45static void __init setup_zero_pages(void)
238ec4ef
MS
46{
47 struct cpuid cpu_id;
48 unsigned int order;
238ec4ef
MS
49 struct page *page;
50 int i;
51
52 get_cpu_id(&cpu_id);
53 switch (cpu_id.machine) {
54 case 0x9672: /* g5 */
55 case 0x2064: /* z900 */
56 case 0x2066: /* z900 */
57 case 0x2084: /* z990 */
58 case 0x2086: /* z990 */
59 case 0x2094: /* z9-109 */
60 case 0x2096: /* z9-109 */
61 order = 0;
62 break;
63 case 0x2097: /* z10 */
64 case 0x2098: /* z10 */
7919e91b
MS
65 case 0x2817: /* z196 */
66 case 0x2818: /* z196 */
238ec4ef
MS
67 order = 2;
68 break;
7919e91b
MS
69 case 0x2827: /* zEC12 */
70 default:
71 order = 5;
72 break;
238ec4ef 73 }
7919e91b
MS
74 /* Limit number of empty zero pages for small memory sizes */
75 if (order > 2 && totalram_pages <= 16384)
76 order = 2;
238ec4ef
MS
77
78 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
79 if (!empty_zero_page)
80 panic("Out of memory in setup_zero_pages");
81
82 page = virt_to_page((void *) empty_zero_page);
83 split_page(page, order);
84 for (i = 1 << order; i > 0; i--) {
0999f119 85 mark_page_reserved(page);
238ec4ef
MS
86 page++;
87 }
88
0999f119 89 zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
238ec4ef
MS
90}
91
1da177e4
LT
92/*
93 * paging_init() sets up the page tables
94 */
1da177e4
LT
95void __init paging_init(void)
96{
39b742f9 97 unsigned long max_zone_pfns[MAX_NR_ZONES];
14045ebf 98 unsigned long pgd_type, asce_bits;
d882b172 99
3610cce8 100 init_mm.pgd = swapper_pg_dir;
f4eb07c1 101#ifdef CONFIG_64BIT
14045ebf
MS
102 if (VMALLOC_END > (1UL << 42)) {
103 asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
104 pgd_type = _REGION2_ENTRY_EMPTY;
105 } else {
106 asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
107 pgd_type = _REGION3_ENTRY_EMPTY;
108 }
f4eb07c1 109#else
14045ebf 110 asce_bits = _ASCE_TABLE_LENGTH;
3610cce8 111 pgd_type = _SEGMENT_ENTRY_EMPTY;
f4eb07c1 112#endif
14045ebf 113 S390_lowcore.kernel_asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
3610cce8
MS
114 clear_table((unsigned long *) init_mm.pgd, pgd_type,
115 sizeof(unsigned long)*2048);
f4eb07c1 116 vmem_map_init();
1da177e4 117
1da177e4 118 /* enable virtual mapping in kernel mode */
3610cce8
MS
119 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
120 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
121 __ctl_load(S390_lowcore.kernel_asce, 13, 13);
df9ee292 122 arch_local_irq_restore(4UL << (BITS_PER_LONG - 8));
1da177e4 123
050eef36
MS
124 atomic_set(&init_mm.context.attach_count, 1);
125
17f34580
HC
126 sparse_memory_present_with_active_regions(MAX_NUMNODES);
127 sparse_init();
39b742f9
HC
128 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
129 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
130 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
131 free_area_init_nodes(max_zone_pfns);
1da177e4 132}
1da177e4
LT
133
134void __init mem_init(void)
135{
136 unsigned long codesize, reservedpages, datasize, initsize;
137
138 max_mapnr = num_physpages = max_low_pfn;
139 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
140
45e576b1
MS
141 /* Setup guest page hinting */
142 cmma_init();
143
1da177e4
LT
144 /* this will put all low memory onto the freelists */
145 totalram_pages += free_all_bootmem();
0999f119 146 setup_zero_pages(); /* Setup zeroed pages. */
1da177e4
LT
147
148 reservedpages = 0;
149
150 codesize = (unsigned long) &_etext - (unsigned long) &_text;
151 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
152 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
153 printk("Memory: %luk/%luk available (%ldk kernel code, %ldk reserved, %ldk data, %ldk init)\n",
cc013a88 154 nr_free_pages() << (PAGE_SHIFT-10),
1da177e4
LT
155 max_mapnr << (PAGE_SHIFT-10),
156 codesize >> 10,
157 reservedpages << (PAGE_SHIFT-10),
158 datasize >>10,
159 initsize >> 10);
d882b172 160 printk("Write protected kernel read-only data: %#lx - %#lx\n",
162e006e
HC
161 (unsigned long)&_stext,
162 PFN_ALIGN((unsigned long)&_eshared) - 1);
1da177e4
LT
163}
164
d96221ab
HC
165void free_initmem(void)
166{
0999f119 167 free_initmem_default(0);
1da177e4
LT
168}
169
170#ifdef CONFIG_BLK_DEV_INITRD
5e249d6e 171void __init free_initrd_mem(unsigned long start, unsigned long end)
1da177e4 172{
0999f119 173 free_reserved_area(start, end, POISON_FREE_INITMEM, "initrd");
1da177e4
LT
174}
175#endif
421c175c
HC
176
177#ifdef CONFIG_MEMORY_HOTPLUG
178int arch_add_memory(int nid, u64 start, u64 size)
179{
892365ab
GS
180 unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
181 unsigned long start_pfn = PFN_DOWN(start);
182 unsigned long size_pages = PFN_DOWN(size);
421c175c
HC
183 struct zone *zone;
184 int rc;
185
421c175c
HC
186 rc = vmem_add_mapping(start, size);
187 if (rc)
188 return rc;
892365ab
GS
189 for_each_zone(zone) {
190 if (zone_idx(zone) != ZONE_MOVABLE) {
191 /* Add range within existing zone limits */
192 zone_start_pfn = zone->zone_start_pfn;
193 zone_end_pfn = zone->zone_start_pfn +
194 zone->spanned_pages;
195 } else {
196 /* Add remaining range to ZONE_MOVABLE */
197 zone_start_pfn = start_pfn;
198 zone_end_pfn = start_pfn + size_pages;
199 }
200 if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
201 continue;
202 nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
203 zone_end_pfn - start_pfn : size_pages;
204 rc = __add_pages(nid, zone, start_pfn, nr_pages);
205 if (rc)
206 break;
207 start_pfn += nr_pages;
208 size_pages -= nr_pages;
209 if (!size_pages)
210 break;
211 }
421c175c
HC
212 if (rc)
213 vmem_remove_mapping(start, size);
214 return rc;
215}
24d335ca
WC
216
217#ifdef CONFIG_MEMORY_HOTREMOVE
218int arch_remove_memory(u64 start, u64 size)
219{
220 /*
221 * There is no hardware or firmware interface which could trigger a
222 * hot memory remove on s390. So there is nothing that needs to be
223 * implemented.
224 */
225 return -EBUSY;
226}
227#endif
421c175c 228#endif /* CONFIG_MEMORY_HOTPLUG */
This page took 0.601816 seconds and 5 git commands to generate.