]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/s390/mm/init.c
Merge remote-tracking branches 'asoc/topic/inntel', 'asoc/topic/input', 'asoc/topic...
[mirror_ubuntu-bionic-kernel.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>
e5d709bb 24#include <linux/memory.h>
d882b172 25#include <linux/pfn.h>
028d9b3c 26#include <linux/poison.h>
2b67fc46 27#include <linux/initrd.h>
3a4c5d59 28#include <linux/export.h>
5a0e3ad6 29#include <linux/gfp.h>
199071f1 30#include <linux/memblock.h>
1da177e4 31#include <asm/processor.h>
1da177e4
LT
32#include <asm/uaccess.h>
33#include <asm/pgtable.h>
34#include <asm/pgalloc.h>
35#include <asm/dma.h>
36#include <asm/lowcore.h>
37#include <asm/tlb.h>
38#include <asm/tlbflush.h>
d882b172 39#include <asm/sections.h>
a0616cde 40#include <asm/ctl_reg.h>
e5d709bb 41#include <asm/sclp.h>
1da177e4 42
0ccb32c9 43pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);
1485c5c8 44
238ec4ef 45unsigned long empty_zero_page, zero_page_mask;
1485c5c8 46EXPORT_SYMBOL(empty_zero_page);
0b70068e 47EXPORT_SYMBOL(zero_page_mask);
1da177e4 48
0999f119 49static void __init setup_zero_pages(void)
238ec4ef 50{
238ec4ef 51 unsigned int order;
238ec4ef
MS
52 struct page *page;
53 int i;
54
c7e8b2c2
MS
55 /* Latest machines require a mapping granularity of 512KB */
56 order = 7;
57
7919e91b 58 /* Limit number of empty zero pages for small memory sizes */
1f6b83e5
MS
59 while (order > 2 && (totalram_pages >> 10) < (1UL << order))
60 order--;
238ec4ef
MS
61
62 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
63 if (!empty_zero_page)
64 panic("Out of memory in setup_zero_pages");
65
66 page = virt_to_page((void *) empty_zero_page);
67 split_page(page, order);
68 for (i = 1 << order; i > 0; i--) {
0999f119 69 mark_page_reserved(page);
238ec4ef
MS
70 page++;
71 }
72
0999f119 73 zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
238ec4ef
MS
74}
75
1da177e4
LT
76/*
77 * paging_init() sets up the page tables
78 */
1da177e4
LT
79void __init paging_init(void)
80{
39b742f9 81 unsigned long max_zone_pfns[MAX_NR_ZONES];
14045ebf 82 unsigned long pgd_type, asce_bits;
d882b172 83
3610cce8 84 init_mm.pgd = swapper_pg_dir;
14045ebf
MS
85 if (VMALLOC_END > (1UL << 42)) {
86 asce_bits = _ASCE_TYPE_REGION2 | _ASCE_TABLE_LENGTH;
87 pgd_type = _REGION2_ENTRY_EMPTY;
88 } else {
89 asce_bits = _ASCE_TYPE_REGION3 | _ASCE_TABLE_LENGTH;
90 pgd_type = _REGION3_ENTRY_EMPTY;
91 }
723cacbd
GS
92 init_mm.context.asce = (__pa(init_mm.pgd) & PAGE_MASK) | asce_bits;
93 S390_lowcore.kernel_asce = init_mm.context.asce;
3610cce8
MS
94 clear_table((unsigned long *) init_mm.pgd, pgd_type,
95 sizeof(unsigned long)*2048);
f4eb07c1 96 vmem_map_init();
1da177e4 97
1da177e4 98 /* enable virtual mapping in kernel mode */
3610cce8
MS
99 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
100 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
101 __ctl_load(S390_lowcore.kernel_asce, 13, 13);
204ee2c5 102 __arch_local_irq_stosm(0x04);
1da177e4 103
17f34580
HC
104 sparse_memory_present_with_active_regions(MAX_NUMNODES);
105 sparse_init();
39b742f9
HC
106 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
107 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
108 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
109 free_area_init_nodes(max_zone_pfns);
1da177e4 110}
1da177e4 111
91d37211
HC
112void mark_rodata_ro(void)
113{
d07a980c
HC
114 unsigned long size = __end_ro_after_init - __start_ro_after_init;
115
116 set_memory_ro((unsigned long)__start_ro_after_init, size >> PAGE_SHIFT);
117 pr_info("Write protected read-only-after-init data: %luk\n", size >> 10);
91d37211
HC
118}
119
1da177e4
LT
120void __init mem_init(void)
121{
64f31d58 122 cpumask_set_cpu(0, &init_mm.context.cpu_attach_mask);
1b948d6c 123 cpumask_set_cpu(0, mm_cpumask(&init_mm));
1b948d6c 124
3a368f74 125 set_max_mapnr(max_low_pfn);
1da177e4
LT
126 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
127
45e576b1
MS
128 /* Setup guest page hinting */
129 cmma_init();
130
1da177e4 131 /* this will put all low memory onto the freelists */
0c988534 132 free_all_bootmem();
0999f119 133 setup_zero_pages(); /* Setup zeroed pages. */
1da177e4 134
a18d0e2d 135 mem_init_print_info(NULL);
1da177e4
LT
136}
137
d96221ab
HC
138void free_initmem(void)
139{
dbe67df4 140 free_initmem_default(POISON_FREE_INITMEM);
1da177e4
LT
141}
142
143#ifdef CONFIG_BLK_DEV_INITRD
5e249d6e 144void __init free_initrd_mem(unsigned long start, unsigned long end)
1da177e4 145{
11199692
JL
146 free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
147 "initrd");
1da177e4
LT
148}
149#endif
421c175c
HC
150
151#ifdef CONFIG_MEMORY_HOTPLUG
033fbae9 152int arch_add_memory(int nid, u64 start, u64 size, bool for_device)
421c175c 153{
4a654294 154 unsigned long zone_start_pfn, zone_end_pfn, nr_pages;
892365ab
GS
155 unsigned long start_pfn = PFN_DOWN(start);
156 unsigned long size_pages = PFN_DOWN(size);
4a654294
GS
157 pg_data_t *pgdat = NODE_DATA(nid);
158 struct zone *zone;
159 int rc, i;
421c175c 160
421c175c
HC
161 rc = vmem_add_mapping(start, size);
162 if (rc)
163 return rc;
199071f1 164
4a654294
GS
165 for (i = 0; i < MAX_NR_ZONES; i++) {
166 zone = pgdat->node_zones + i;
167 if (zone_idx(zone) != ZONE_MOVABLE) {
168 /* Add range within existing zone limits, if possible */
169 zone_start_pfn = zone->zone_start_pfn;
170 zone_end_pfn = zone->zone_start_pfn +
171 zone->spanned_pages;
892365ab 172 } else {
4a654294
GS
173 /* Add remaining range to ZONE_MOVABLE */
174 zone_start_pfn = start_pfn;
175 zone_end_pfn = start_pfn + size_pages;
892365ab 176 }
4a654294
GS
177 if (start_pfn < zone_start_pfn || start_pfn >= zone_end_pfn)
178 continue;
179 nr_pages = (start_pfn + size_pages > zone_end_pfn) ?
180 zone_end_pfn - start_pfn : size_pages;
181 rc = __add_pages(nid, zone, start_pfn, nr_pages);
892365ab
GS
182 if (rc)
183 break;
184 start_pfn += nr_pages;
185 size_pages -= nr_pages;
4a654294
GS
186 if (!size_pages)
187 break;
892365ab 188 }
421c175c
HC
189 if (rc)
190 vmem_remove_mapping(start, size);
191 return rc;
192}
24d335ca 193
e5d709bb
HC
194unsigned long memory_block_size_bytes(void)
195{
196 /*
197 * Make sure the memory block size is always greater
198 * or equal than the memory increment size.
199 */
37c5f6c8 200 return max_t(unsigned long, MIN_MEMORY_BLOCK_SIZE, sclp.rzm);
e5d709bb
HC
201}
202
24d335ca
WC
203#ifdef CONFIG_MEMORY_HOTREMOVE
204int arch_remove_memory(u64 start, u64 size)
205{
206 /*
207 * There is no hardware or firmware interface which could trigger a
208 * hot memory remove on s390. So there is nothing that needs to be
209 * implemented.
210 */
211 return -EBUSY;
212}
213#endif
421c175c 214#endif /* CONFIG_MEMORY_HOTPLUG */