1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#define KMSG_COMPONENT "setup"
16#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
17
18#include <linux/errno.h>
19#include <linux/export.h>
20#include <linux/sched.h>
21#include <linux/kernel.h>
22#include <linux/memblock.h>
23#include <linux/mm.h>
24#include <linux/stddef.h>
25#include <linux/unistd.h>
26#include <linux/ptrace.h>
27#include <linux/user.h>
28#include <linux/tty.h>
29#include <linux/ioport.h>
30#include <linux/delay.h>
31#include <linux/init.h>
32#include <linux/initrd.h>
33#include <linux/bootmem.h>
34#include <linux/root_dev.h>
35#include <linux/console.h>
36#include <linux/kernel_stat.h>
37#include <linux/device.h>
38#include <linux/notifier.h>
39#include <linux/pfn.h>
40#include <linux/ctype.h>
41#include <linux/reboot.h>
42#include <linux/topology.h>
43#include <linux/ftrace.h>
44#include <linux/kexec.h>
45#include <linux/crash_dump.h>
46#include <linux/memory.h>
47#include <linux/compat.h>
48
49#include <asm/ipl.h>
50#include <asm/facility.h>
51#include <asm/smp.h>
52#include <asm/mmu_context.h>
53#include <asm/cpcmd.h>
54#include <asm/lowcore.h>
55#include <asm/irq.h>
56#include <asm/page.h>
57#include <asm/ptrace.h>
58#include <asm/sections.h>
59#include <asm/ebcdic.h>
60#include <asm/kvm_virtio.h>
61#include <asm/diag.h>
62#include <asm/os_info.h>
63#include <asm/sclp.h>
64#include "entry.h"
65
66
67
68
69unsigned int console_mode = 0;
70EXPORT_SYMBOL(console_mode);
71
72unsigned int console_devno = -1;
73EXPORT_SYMBOL(console_devno);
74
75unsigned int console_irq = -1;
76EXPORT_SYMBOL(console_irq);
77
78unsigned long elf_hwcap = 0;
79char elf_platform[ELF_PLATFORM_SIZE];
80
81unsigned long int_hwcap = 0;
82struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
83
84int __initdata memory_end_set;
85unsigned long __initdata memory_end;
86
87unsigned long VMALLOC_START;
88EXPORT_SYMBOL(VMALLOC_START);
89
90unsigned long VMALLOC_END;
91EXPORT_SYMBOL(VMALLOC_END);
92
93struct page *vmemmap;
94EXPORT_SYMBOL(vmemmap);
95
96#ifdef CONFIG_64BIT
97unsigned long MODULES_VADDR;
98unsigned long MODULES_END;
99#endif
100
101
102struct _lowcore *lowcore_ptr[NR_CPUS];
103EXPORT_SYMBOL(lowcore_ptr);
104
105
106
107
108
109
110
111#include <asm/setup.h>
112
113
114
115
116
117static int __init condev_setup(char *str)
118{
119 int vdev;
120
121 vdev = simple_strtoul(str, &str, 0);
122 if (vdev >= 0 && vdev < 65536) {
123 console_devno = vdev;
124 console_irq = -1;
125 }
126 return 1;
127}
128
129__setup("condev=", condev_setup);
130
131static void __init set_preferred_console(void)
132{
133 if (MACHINE_IS_KVM) {
134 if (sclp_has_vt220())
135 add_preferred_console("ttyS", 1, NULL);
136 else if (sclp_has_linemode())
137 add_preferred_console("ttyS", 0, NULL);
138 else
139 add_preferred_console("hvc", 0, NULL);
140 } else if (CONSOLE_IS_3215 || CONSOLE_IS_SCLP)
141 add_preferred_console("ttyS", 0, NULL);
142 else if (CONSOLE_IS_3270)
143 add_preferred_console("tty3270", 0, NULL);
144}
145
146static int __init conmode_setup(char *str)
147{
148#if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
149 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
150 SET_CONSOLE_SCLP;
151#endif
152#if defined(CONFIG_TN3215_CONSOLE)
153 if (strncmp(str, "3215", 5) == 0)
154 SET_CONSOLE_3215;
155#endif
156#if defined(CONFIG_TN3270_CONSOLE)
157 if (strncmp(str, "3270", 5) == 0)
158 SET_CONSOLE_3270;
159#endif
160 set_preferred_console();
161 return 1;
162}
163
164__setup("conmode=", conmode_setup);
165
166static void __init conmode_default(void)
167{
168 char query_buffer[1024];
169 char *ptr;
170
171 if (MACHINE_IS_VM) {
172 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
173 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
174 ptr = strstr(query_buffer, "SUBCHANNEL =");
175 console_irq = simple_strtoul(ptr + 13, NULL, 16);
176 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
177 ptr = strstr(query_buffer, "CONMODE");
178
179
180
181
182
183
184
185 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
186 if (ptr == NULL) {
187#if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
188 SET_CONSOLE_SCLP;
189#endif
190 return;
191 }
192 if (strncmp(ptr + 8, "3270", 4) == 0) {
193#if defined(CONFIG_TN3270_CONSOLE)
194 SET_CONSOLE_3270;
195#elif defined(CONFIG_TN3215_CONSOLE)
196 SET_CONSOLE_3215;
197#elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
198 SET_CONSOLE_SCLP;
199#endif
200 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
201#if defined(CONFIG_TN3215_CONSOLE)
202 SET_CONSOLE_3215;
203#elif defined(CONFIG_TN3270_CONSOLE)
204 SET_CONSOLE_3270;
205#elif defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
206 SET_CONSOLE_SCLP;
207#endif
208 }
209 } else {
210#if defined(CONFIG_SCLP_CONSOLE) || defined(CONFIG_SCLP_VT220_CONSOLE)
211 SET_CONSOLE_SCLP;
212#endif
213 }
214}
215
216#ifdef CONFIG_ZFCPDUMP
217static void __init setup_zfcpdump(void)
218{
219 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
220 return;
221 if (OLDMEM_BASE)
222 return;
223 strcat(boot_command_line, " cio_ignore=all,!ipldev,!condev");
224 console_loglevel = 2;
225}
226#else
227static inline void setup_zfcpdump(void) {}
228#endif
229
230
231
232
233
234
235void machine_restart(char *command)
236{
237 if ((!in_interrupt() && !in_atomic()) || oops_in_progress)
238
239
240
241
242 console_unblank();
243 _machine_restart(command);
244}
245
246void machine_halt(void)
247{
248 if (!in_interrupt() || oops_in_progress)
249
250
251
252
253 console_unblank();
254 _machine_halt();
255}
256
257void machine_power_off(void)
258{
259 if (!in_interrupt() || oops_in_progress)
260
261
262
263
264 console_unblank();
265 _machine_power_off();
266}
267
268
269
270
271void (*pm_power_off)(void) = machine_power_off;
272EXPORT_SYMBOL_GPL(pm_power_off);
273
274static int __init early_parse_mem(char *p)
275{
276 memory_end = memparse(p, &p);
277 memory_end_set = 1;
278 return 0;
279}
280early_param("mem", early_parse_mem);
281
282static int __init parse_vmalloc(char *arg)
283{
284 if (!arg)
285 return -EINVAL;
286 VMALLOC_END = (memparse(arg, &arg) + PAGE_SIZE - 1) & PAGE_MASK;
287 return 0;
288}
289early_param("vmalloc", parse_vmalloc);
290
291void *restart_stack __attribute__((__section__(".data")));
292
293static void __init setup_lowcore(void)
294{
295 struct _lowcore *lc;
296
297
298
299
300 BUILD_BUG_ON(sizeof(struct _lowcore) != LC_PAGES * 4096);
301 lc = __alloc_bootmem_low(LC_PAGES * PAGE_SIZE, LC_PAGES * PAGE_SIZE, 0);
302 lc->restart_psw.mask = PSW_KERNEL_BITS;
303 lc->restart_psw.addr =
304 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
305 lc->external_new_psw.mask = PSW_KERNEL_BITS |
306 PSW_MASK_DAT | PSW_MASK_MCHECK;
307 lc->external_new_psw.addr =
308 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
309 lc->svc_new_psw.mask = PSW_KERNEL_BITS |
310 PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK;
311 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
312 lc->program_new_psw.mask = PSW_KERNEL_BITS |
313 PSW_MASK_DAT | PSW_MASK_MCHECK;
314 lc->program_new_psw.addr =
315 PSW_ADDR_AMODE | (unsigned long) pgm_check_handler;
316 lc->mcck_new_psw.mask = PSW_KERNEL_BITS;
317 lc->mcck_new_psw.addr =
318 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
319 lc->io_new_psw.mask = PSW_KERNEL_BITS |
320 PSW_MASK_DAT | PSW_MASK_MCHECK;
321 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
322 lc->clock_comparator = -1ULL;
323 lc->kernel_stack = ((unsigned long) &init_thread_union)
324 + THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
325 lc->async_stack = (unsigned long)
326 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0)
327 + ASYNC_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
328 lc->panic_stack = (unsigned long)
329 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0)
330 + PAGE_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
331 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
332 lc->thread_info = (unsigned long) &init_thread_union;
333#ifdef CONFIG_64BIT
334 lc->lpp = LPP_MAGIC;
335#endif
336 lc->machine_flags = S390_lowcore.machine_flags;
337 lc->stfl_fac_list = S390_lowcore.stfl_fac_list;
338 memcpy(lc->stfle_fac_list, S390_lowcore.stfle_fac_list,
339 MAX_FACILITY_BIT/8);
340#ifndef CONFIG_64BIT
341 if (MACHINE_HAS_IEEE) {
342 lc->extended_save_area_addr = (__u32)
343 __alloc_bootmem_low(PAGE_SIZE, PAGE_SIZE, 0);
344
345 __ctl_set_bit(14, 29);
346 }
347#else
348 if (MACHINE_HAS_VX)
349 lc->vector_save_area_addr =
350 (unsigned long) &lc->vector_save_area;
351 lc->vdso_per_cpu_data = (unsigned long) &lc->paste[0];
352#endif
353 lc->sync_enter_timer = S390_lowcore.sync_enter_timer;
354 lc->async_enter_timer = S390_lowcore.async_enter_timer;
355 lc->exit_timer = S390_lowcore.exit_timer;
356 lc->user_timer = S390_lowcore.user_timer;
357 lc->system_timer = S390_lowcore.system_timer;
358 lc->steal_timer = S390_lowcore.steal_timer;
359 lc->last_update_timer = S390_lowcore.last_update_timer;
360 lc->last_update_clock = S390_lowcore.last_update_clock;
361 lc->ftrace_func = S390_lowcore.ftrace_func;
362
363 restart_stack = __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0);
364 restart_stack += ASYNC_SIZE;
365
366
367
368
369
370
371 lc->restart_stack = (unsigned long) restart_stack;
372 lc->restart_fn = (unsigned long) do_restart;
373 lc->restart_data = 0;
374 lc->restart_source = -1UL;
375
376
377 mem_assign_absolute(S390_lowcore.restart_stack, lc->restart_stack);
378 mem_assign_absolute(S390_lowcore.restart_fn, lc->restart_fn);
379 mem_assign_absolute(S390_lowcore.restart_data, lc->restart_data);
380 mem_assign_absolute(S390_lowcore.restart_source, lc->restart_source);
381 mem_assign_absolute(S390_lowcore.restart_psw, lc->restart_psw);
382
383#ifdef CONFIG_SMP
384 lc->spinlock_lockval = arch_spin_lockval(0);
385#endif
386
387 set_prefix((u32)(unsigned long) lc);
388 lowcore_ptr[0] = lc;
389}
390
391static struct resource code_resource = {
392 .name = "Kernel code",
393 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
394};
395
396static struct resource data_resource = {
397 .name = "Kernel data",
398 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
399};
400
401static struct resource bss_resource = {
402 .name = "Kernel bss",
403 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
404};
405
406static struct resource __initdata *standard_resources[] = {
407 &code_resource,
408 &data_resource,
409 &bss_resource,
410};
411
412static void __init setup_resources(void)
413{
414 struct resource *res, *std_res, *sub_res;
415 int i, j;
416
417 code_resource.start = (unsigned long) &_text;
418 code_resource.end = (unsigned long) &_etext - 1;
419 data_resource.start = (unsigned long) &_etext;
420 data_resource.end = (unsigned long) &_edata - 1;
421 bss_resource.start = (unsigned long) &__bss_start;
422 bss_resource.end = (unsigned long) &__bss_stop - 1;
423
424 for (i = 0; i < MEMORY_CHUNKS; i++) {
425 if (!memory_chunk[i].size)
426 continue;
427 res = alloc_bootmem_low(sizeof(*res));
428 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
429 switch (memory_chunk[i].type) {
430 case CHUNK_READ_WRITE:
431 res->name = "System RAM";
432 break;
433 case CHUNK_READ_ONLY:
434 res->name = "System ROM";
435 res->flags |= IORESOURCE_READONLY;
436 break;
437 default:
438 res->name = "reserved";
439 }
440 res->start = memory_chunk[i].addr;
441 res->end = res->start + memory_chunk[i].size - 1;
442 request_resource(&iomem_resource, res);
443
444 for (j = 0; j < ARRAY_SIZE(standard_resources); j++) {
445 std_res = standard_resources[j];
446 if (std_res->start < res->start ||
447 std_res->start > res->end)
448 continue;
449 if (std_res->end > res->end) {
450 sub_res = alloc_bootmem_low(sizeof(*sub_res));
451 *sub_res = *std_res;
452 sub_res->end = res->end;
453 std_res->start = res->end + 1;
454 request_resource(res, sub_res);
455 } else {
456 request_resource(res, std_res);
457 }
458 }
459 }
460}
461
462static void __init setup_memory_end(void)
463{
464 unsigned long vmax, vmalloc_size, tmp;
465 unsigned long real_memory_size = 0;
466 int i;
467
468
469#ifdef CONFIG_ZFCPDUMP
470 if (ipl_info.type == IPL_TYPE_FCP_DUMP &&
471 !OLDMEM_BASE && sclp_get_hsa_size()) {
472 memory_end = sclp_get_hsa_size();
473 memory_end_set = 1;
474 }
475#endif
476 memory_end &= PAGE_MASK;
477
478
479
480
481
482 for (i = 0; i < MEMORY_CHUNKS; i++) {
483 unsigned long start, end;
484 struct mem_chunk *chunk;
485 unsigned long align;
486
487 chunk = &memory_chunk[i];
488 if (!chunk->size)
489 continue;
490 align = 1UL << (MAX_ORDER + PAGE_SHIFT - 1);
491 start = (chunk->addr + align - 1) & ~(align - 1);
492 end = (chunk->addr + chunk->size) & ~(align - 1);
493 if (start >= end)
494 memset(chunk, 0, sizeof(*chunk));
495 else {
496 chunk->addr = start;
497 chunk->size = end - start;
498 }
499 real_memory_size = max(real_memory_size,
500 chunk->addr + chunk->size);
501 }
502
503
504#ifdef CONFIG_64BIT
505 vmalloc_size = VMALLOC_END ?: (128UL << 30) - MODULES_LEN;
506 tmp = (memory_end ?: real_memory_size) / PAGE_SIZE;
507 tmp = tmp * (sizeof(struct page) + PAGE_SIZE) + vmalloc_size;
508 if (tmp <= (1UL << 42))
509 vmax = 1UL << 42;
510 else
511 vmax = 1UL << 53;
512
513 MODULES_END = vmax;
514 MODULES_VADDR = MODULES_END - MODULES_LEN;
515 VMALLOC_END = MODULES_VADDR;
516#else
517 vmalloc_size = VMALLOC_END ?: 96UL << 20;
518 vmax = 1UL << 31;
519
520 VMALLOC_END = vmax;
521#endif
522 VMALLOC_START = vmax - vmalloc_size;
523
524
525 tmp = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
526
527 tmp = SECTION_ALIGN_UP(tmp);
528 tmp = VMALLOC_START - tmp * sizeof(struct page);
529 tmp &= ~((vmax >> 11) - 1);
530 tmp = min(tmp, 1UL << MAX_PHYSMEM_BITS);
531 vmemmap = (struct page *) tmp;
532
533
534 memory_end = min(memory_end ?: real_memory_size, tmp);
535
536
537 for (i = 0; i < MEMORY_CHUNKS; i++) {
538 struct mem_chunk *chunk = &memory_chunk[i];
539
540 if (!chunk->size)
541 continue;
542 if (chunk->addr >= memory_end) {
543 memset(chunk, 0, sizeof(*chunk));
544 continue;
545 }
546 if (chunk->addr + chunk->size > memory_end)
547 chunk->size = memory_end - chunk->addr;
548 }
549}
550
551static void __init setup_vmcoreinfo(void)
552{
553 mem_assign_absolute(S390_lowcore.vmcore_info, paddr_vmcoreinfo_note());
554}
555
556#ifdef CONFIG_CRASH_DUMP
557
558
559
560
561static unsigned long __init find_crash_base(unsigned long crash_size,
562 char **msg)
563{
564 unsigned long crash_base;
565 struct mem_chunk *chunk;
566 int i;
567
568 if (memory_chunk[0].size < crash_size) {
569 *msg = "first memory chunk must be at least crashkernel size";
570 return 0;
571 }
572 if (OLDMEM_BASE && crash_size == OLDMEM_SIZE)
573 return OLDMEM_BASE;
574
575 for (i = MEMORY_CHUNKS - 1; i >= 0; i--) {
576 chunk = &memory_chunk[i];
577 if (chunk->size == 0)
578 continue;
579 if (chunk->type != CHUNK_READ_WRITE)
580 continue;
581 if (chunk->size < crash_size)
582 continue;
583 crash_base = (chunk->addr + chunk->size) - crash_size;
584 if (crash_base < crash_size)
585 continue;
586 if (crash_base < sclp_get_hsa_size())
587 continue;
588 if (crash_base < (unsigned long) INITRD_START + INITRD_SIZE)
589 continue;
590 return crash_base;
591 }
592 *msg = "no suitable area found";
593 return 0;
594}
595
596
597
598
599static int __init verify_crash_base(unsigned long crash_base,
600 unsigned long crash_size,
601 char **msg)
602{
603 struct mem_chunk *chunk;
604 int i;
605
606
607
608
609
610 if (crash_size > crash_base) {
611 *msg = "crashkernel offset must be greater than size";
612 return -EINVAL;
613 }
614
615
616 if (memory_chunk[0].size < crash_size) {
617 *msg = "first memory chunk must be at least crashkernel size";
618 return -EINVAL;
619 }
620
621 for (i = 0; i < MEMORY_CHUNKS; i++) {
622 chunk = &memory_chunk[i];
623 if (chunk->size == 0)
624 continue;
625 if (crash_base < chunk->addr)
626 continue;
627 if (crash_base >= chunk->addr + chunk->size)
628 continue;
629
630 if (crash_base + crash_size > chunk->addr + chunk->size) {
631 *msg = "selected memory chunk is too small for "
632 "crashkernel memory";
633 return -EINVAL;
634 }
635 return 0;
636 }
637 *msg = "invalid memory range specified";
638 return -EINVAL;
639}
640
641
642
643
644
645
646static int kdump_mem_notifier(struct notifier_block *nb,
647 unsigned long action, void *data)
648{
649 struct memory_notify *arg = data;
650
651 if (arg->start_pfn < PFN_DOWN(resource_size(&crashk_res)))
652 return NOTIFY_BAD;
653 if (arg->start_pfn > PFN_DOWN(crashk_res.end))
654 return NOTIFY_OK;
655 if (arg->start_pfn + arg->nr_pages - 1 < PFN_DOWN(crashk_res.start))
656 return NOTIFY_OK;
657 return NOTIFY_BAD;
658}
659
660static struct notifier_block kdump_mem_nb = {
661 .notifier_call = kdump_mem_notifier,
662};
663
664#endif
665
666
667
668
669static void reserve_oldmem(void)
670{
671#ifdef CONFIG_CRASH_DUMP
672 unsigned long real_size = 0;
673 int i;
674
675 if (!OLDMEM_BASE)
676 return;
677 for (i = 0; i < MEMORY_CHUNKS; i++) {
678 struct mem_chunk *chunk = &memory_chunk[i];
679
680 real_size = max(real_size, chunk->addr + chunk->size);
681 }
682 create_mem_hole(memory_chunk, OLDMEM_BASE, OLDMEM_SIZE);
683 create_mem_hole(memory_chunk, OLDMEM_SIZE, real_size - OLDMEM_SIZE);
684 if (OLDMEM_BASE + OLDMEM_SIZE == real_size)
685 saved_max_pfn = PFN_DOWN(OLDMEM_BASE) - 1;
686 else
687 saved_max_pfn = PFN_DOWN(real_size) - 1;
688#endif
689}
690
691
692
693
694static void __init reserve_crashkernel(void)
695{
696#ifdef CONFIG_CRASH_DUMP
697 unsigned long long crash_base, crash_size;
698 char *msg = NULL;
699 int rc;
700
701 rc = parse_crashkernel(boot_command_line, memory_end, &crash_size,
702 &crash_base);
703 if (rc || crash_size == 0)
704 return;
705 crash_base = ALIGN(crash_base, KEXEC_CRASH_MEM_ALIGN);
706 crash_size = ALIGN(crash_size, KEXEC_CRASH_MEM_ALIGN);
707 if (register_memory_notifier(&kdump_mem_nb))
708 return;
709 if (!crash_base)
710 crash_base = find_crash_base(crash_size, &msg);
711 if (!crash_base) {
712 pr_info("crashkernel reservation failed: %s\n", msg);
713 unregister_memory_notifier(&kdump_mem_nb);
714 return;
715 }
716 if (verify_crash_base(crash_base, crash_size, &msg)) {
717 pr_info("crashkernel reservation failed: %s\n", msg);
718 unregister_memory_notifier(&kdump_mem_nb);
719 return;
720 }
721 if (!OLDMEM_BASE && MACHINE_IS_VM)
722 diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size));
723 crashk_res.start = crash_base;
724 crashk_res.end = crash_base + crash_size - 1;
725 insert_resource(&iomem_resource, &crashk_res);
726 create_mem_hole(memory_chunk, crash_base, crash_size);
727 pr_info("Reserving %lluMB of memory at %lluMB "
728 "for crashkernel (System RAM: %luMB)\n",
729 crash_size >> 20, crash_base >> 20, memory_end >> 20);
730 os_info_crashkernel_add(crash_base, crash_size);
731#endif
732}
733
734static void __init setup_memory(void)
735{
736 unsigned long bootmap_size;
737 unsigned long start_pfn, end_pfn;
738 int i;
739
740
741
742
743
744 start_pfn = PFN_UP(__pa(&_end));
745 end_pfn = max_pfn = PFN_DOWN(memory_end);
746
747#ifdef CONFIG_BLK_DEV_INITRD
748
749
750
751
752
753 if (INITRD_START && INITRD_SIZE) {
754 unsigned long bmap_size;
755 unsigned long start;
756
757 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
758 bmap_size = PFN_PHYS(bmap_size);
759
760 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
761 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
762
763#ifdef CONFIG_CRASH_DUMP
764 if (OLDMEM_BASE) {
765
766 if (start + INITRD_SIZE > OLDMEM_BASE &&
767 start < OLDMEM_BASE + OLDMEM_SIZE)
768 start = OLDMEM_BASE + OLDMEM_SIZE;
769 }
770#endif
771 if (start + INITRD_SIZE > memory_end) {
772 pr_err("initrd extends beyond end of "
773 "memory (0x%08lx > 0x%08lx) "
774 "disabling initrd\n",
775 start + INITRD_SIZE, memory_end);
776 INITRD_START = INITRD_SIZE = 0;
777 } else {
778 pr_info("Moving initrd (0x%08lx -> "
779 "0x%08lx, size: %ld)\n",
780 INITRD_START, start, INITRD_SIZE);
781 memmove((void *) start, (void *) INITRD_START,
782 INITRD_SIZE);
783 INITRD_START = start;
784 }
785 }
786 }
787#endif
788
789
790
791
792 bootmap_size = init_bootmem(start_pfn, end_pfn);
793
794
795
796
797
798 for (i = 0; i < MEMORY_CHUNKS; i++) {
799 unsigned long start_chunk, end_chunk, pfn;
800
801 if (!memory_chunk[i].size)
802 continue;
803 start_chunk = PFN_DOWN(memory_chunk[i].addr);
804 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size);
805 end_chunk = min(end_chunk, end_pfn);
806 if (start_chunk >= end_chunk)
807 continue;
808 memblock_add_node(PFN_PHYS(start_chunk),
809 PFN_PHYS(end_chunk - start_chunk), 0);
810 pfn = max(start_chunk, start_pfn);
811 storage_key_init_range(PFN_PHYS(pfn), PFN_PHYS(end_chunk));
812 }
813
814 psw_set_key(PAGE_DEFAULT_KEY);
815
816 free_bootmem_with_active_regions(0, max_pfn);
817
818
819
820
821 reserve_bootmem(0, (unsigned long)_ehead, BOOTMEM_DEFAULT);
822 reserve_bootmem((unsigned long)_stext,
823 PFN_PHYS(start_pfn) - (unsigned long)_stext,
824 BOOTMEM_DEFAULT);
825
826
827
828
829
830
831 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size,
832 BOOTMEM_DEFAULT);
833
834#ifdef CONFIG_CRASH_DUMP
835 if (crashk_res.start)
836 reserve_bootmem(crashk_res.start,
837 crashk_res.end - crashk_res.start + 1,
838 BOOTMEM_DEFAULT);
839 if (is_kdump_kernel())
840 reserve_bootmem(elfcorehdr_addr - OLDMEM_BASE,
841 PAGE_ALIGN(elfcorehdr_size), BOOTMEM_DEFAULT);
842#endif
843#ifdef CONFIG_BLK_DEV_INITRD
844 if (INITRD_START && INITRD_SIZE) {
845 if (INITRD_START + INITRD_SIZE <= memory_end) {
846 reserve_bootmem(INITRD_START, INITRD_SIZE,
847 BOOTMEM_DEFAULT);
848 initrd_start = INITRD_START;
849 initrd_end = initrd_start + INITRD_SIZE;
850 } else {
851 pr_err("initrd extends beyond end of "
852 "memory (0x%08lx > 0x%08lx) "
853 "disabling initrd\n",
854 initrd_start + INITRD_SIZE, memory_end);
855 initrd_start = initrd_end = 0;
856 }
857 }
858#endif
859}
860
861
862
863
864static void __init setup_hwcaps(void)
865{
866 static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
867 struct cpuid cpu_id;
868 int i;
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888 for (i = 0; i < 6; i++)
889 if (test_facility(stfl_bits[i]))
890 elf_hwcap |= 1UL << i;
891
892 if (test_facility(22) && test_facility(30))
893 elf_hwcap |= HWCAP_S390_ETF3EH;
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908 if ((elf_hwcap & (1UL << 2)) && test_facility(42) && test_facility(44))
909 elf_hwcap |= HWCAP_S390_DFP;
910
911
912
913
914 if (MACHINE_HAS_HPAGE)
915 elf_hwcap |= HWCAP_S390_HPAGE;
916
917#if defined(CONFIG_64BIT)
918
919
920
921
922 elf_hwcap |= HWCAP_S390_HIGH_GPRS;
923
924
925
926
927 if (test_facility(50) && test_facility(73))
928 elf_hwcap |= HWCAP_S390_TE;
929
930
931
932
933 if (test_facility(129))
934 elf_hwcap |= HWCAP_S390_VXRS;
935#endif
936
937 get_cpu_id(&cpu_id);
938 switch (cpu_id.machine) {
939 case 0x9672:
940#if !defined(CONFIG_64BIT)
941 default:
942#endif
943 strcpy(elf_platform, "g5");
944 break;
945 case 0x2064:
946 case 0x2066:
947#if defined(CONFIG_64BIT)
948 default:
949#endif
950 strcpy(elf_platform, "z900");
951 break;
952 case 0x2084:
953 case 0x2086:
954 strcpy(elf_platform, "z990");
955 break;
956 case 0x2094:
957 case 0x2096:
958 strcpy(elf_platform, "z9-109");
959 break;
960 case 0x2097:
961 case 0x2098:
962 strcpy(elf_platform, "z10");
963 break;
964 case 0x2817:
965 case 0x2818:
966 strcpy(elf_platform, "z196");
967 break;
968 case 0x2827:
969 case 0x2828:
970 strcpy(elf_platform, "zEC12");
971 break;
972 case 0x2964:
973 strcpy(elf_platform, "z13");
974 break;
975 }
976
977
978
979
980 if (sclp_has_sief2())
981 int_hwcap |= HWCAP_INT_SIE;
982}
983
984
985
986
987
988
989void __init setup_arch(char **cmdline_p)
990{
991
992
993
994#ifndef CONFIG_64BIT
995 if (MACHINE_IS_VM)
996 pr_info("Linux is running as a z/VM "
997 "guest operating system in 31-bit mode\n");
998 else if (MACHINE_IS_LPAR)
999 pr_info("Linux is running natively in 31-bit mode\n");
1000 if (MACHINE_HAS_IEEE)
1001 pr_info("The hardware system has IEEE compatible "
1002 "floating point units\n");
1003 else
1004 pr_info("The hardware system has no IEEE compatible "
1005 "floating point units\n");
1006#else
1007 if (MACHINE_IS_VM)
1008 pr_info("Linux is running as a z/VM "
1009 "guest operating system in 64-bit mode\n");
1010 else if (MACHINE_IS_KVM)
1011 pr_info("Linux is running under KVM in 64-bit mode\n");
1012 else if (MACHINE_IS_LPAR)
1013 pr_info("Linux is running natively in 64-bit mode\n");
1014#endif
1015
1016
1017
1018 *cmdline_p = boot_command_line;
1019
1020 ROOT_DEV = Root_RAM0;
1021
1022 init_mm.start_code = PAGE_OFFSET;
1023 init_mm.end_code = (unsigned long) &_etext;
1024 init_mm.end_data = (unsigned long) &_edata;
1025 init_mm.brk = (unsigned long) &_end;
1026
1027 parse_early_param();
1028 detect_memory_layout(memory_chunk, memory_end);
1029 os_info_init();
1030 setup_ipl();
1031 reserve_oldmem();
1032 setup_memory_end();
1033 reserve_crashkernel();
1034 setup_memory();
1035 setup_resources();
1036 setup_vmcoreinfo();
1037 setup_lowcore();
1038
1039 smp_fill_possible_mask();
1040 cpu_init();
1041 s390_init_cpu_topology();
1042
1043
1044
1045
1046 setup_hwcaps();
1047
1048
1049
1050
1051 paging_init();
1052
1053
1054 conmode_default();
1055 set_preferred_console();
1056
1057
1058 setup_zfcpdump();
1059}
1060