2 * arch/s390/kernel/setup.c
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Hartmut Penner (hp@de.ibm.com),
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Derived from "arch/i386/kernel/setup.c"
10 * Copyright (C) 1995, Linus Torvalds
14 * This file handles the architecture-dependent parts of initialization
17 #include <linux/errno.h>
18 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/slab.h>
26 #include <linux/user.h>
27 #include <linux/a.out.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/seq_file.h>
37 #include <linux/kernel_stat.h>
38 #include <linux/device.h>
39 #include <linux/notifier.h>
40 #include <linux/pfn.h>
42 #include <asm/uaccess.h>
43 #include <asm/system.h>
45 #include <asm/mmu_context.h>
46 #include <asm/cpcmd.h>
47 #include <asm/lowcore.h>
50 #include <asm/ptrace.h>
51 #include <asm/sections.h>
54 * User copy operations.
56 struct uaccess_ops uaccess;
57 EXPORT_SYMBOL_GPL(uaccess);
62 unsigned int console_mode = 0;
63 unsigned int console_devno = -1;
64 unsigned int console_irq = -1;
65 unsigned long machine_flags = 0;
67 struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
68 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
69 static unsigned long __initdata memory_end;
72 * This is set up by the setup-routine at boot-time
73 * for S390 need to find out, what we have to setup
74 * using address 0x10400 ...
77 #include <asm/setup.h>
79 static struct resource code_resource = {
80 .name = "Kernel code",
81 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
84 static struct resource data_resource = {
85 .name = "Kernel data",
86 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
90 * cpu_init() initializes state that is per-CPU.
92 void __devinit cpu_init (void)
94 int addr = hard_smp_processor_id();
97 * Store processor id in lowcore (used e.g. in timer_interrupt)
99 asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
100 S390_lowcore.cpu_data.cpu_addr = addr;
103 * Force FPU initialization:
105 clear_thread_flag(TIF_USEDFPU);
108 atomic_inc(&init_mm.mm_count);
109 current->active_mm = &init_mm;
112 enter_lazy_tlb(&init_mm, current);
116 * VM halt and poweroff setup routines
118 char vmhalt_cmd[128] = "";
119 char vmpoff_cmd[128] = "";
120 char vmpanic_cmd[128] = "";
122 static inline void strncpy_skip_quote(char *dst, char *src, int n)
127 for (sx = 0; src[sx] != 0; sx++) {
128 if (src[sx] == '"') continue;
134 static int __init vmhalt_setup(char *str)
136 strncpy_skip_quote(vmhalt_cmd, str, 127);
141 __setup("vmhalt=", vmhalt_setup);
143 static int __init vmpoff_setup(char *str)
145 strncpy_skip_quote(vmpoff_cmd, str, 127);
150 __setup("vmpoff=", vmpoff_setup);
152 static int vmpanic_notify(struct notifier_block *self, unsigned long event,
155 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
156 cpcmd(vmpanic_cmd, NULL, 0, NULL);
161 #define PANIC_PRI_VMPANIC 0
163 static struct notifier_block vmpanic_nb = {
164 .notifier_call = vmpanic_notify,
165 .priority = PANIC_PRI_VMPANIC
168 static int __init vmpanic_setup(char *str)
170 static int register_done __initdata = 0;
172 strncpy_skip_quote(vmpanic_cmd, str, 127);
173 vmpanic_cmd[127] = 0;
174 if (!register_done) {
176 atomic_notifier_chain_register(&panic_notifier_list,
182 __setup("vmpanic=", vmpanic_setup);
185 * condev= and conmode= setup parameter.
188 static int __init condev_setup(char *str)
192 vdev = simple_strtoul(str, &str, 0);
193 if (vdev >= 0 && vdev < 65536) {
194 console_devno = vdev;
200 __setup("condev=", condev_setup);
202 static int __init conmode_setup(char *str)
204 #if defined(CONFIG_SCLP_CONSOLE)
205 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
208 #if defined(CONFIG_TN3215_CONSOLE)
209 if (strncmp(str, "3215", 5) == 0)
212 #if defined(CONFIG_TN3270_CONSOLE)
213 if (strncmp(str, "3270", 5) == 0)
219 __setup("conmode=", conmode_setup);
221 static void __init conmode_default(void)
223 char query_buffer[1024];
227 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
228 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
229 ptr = strstr(query_buffer, "SUBCHANNEL =");
230 console_irq = simple_strtoul(ptr + 13, NULL, 16);
231 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
232 ptr = strstr(query_buffer, "CONMODE");
234 * Set the conmode to 3215 so that the device recognition
235 * will set the cu_type of the console to 3215. If the
236 * conmode is 3270 and we don't set it back then both
237 * 3215 and the 3270 driver will try to access the console
238 * device (3215 as console and 3270 as normal tty).
240 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
242 #if defined(CONFIG_SCLP_CONSOLE)
247 if (strncmp(ptr + 8, "3270", 4) == 0) {
248 #if defined(CONFIG_TN3270_CONSOLE)
250 #elif defined(CONFIG_TN3215_CONSOLE)
252 #elif defined(CONFIG_SCLP_CONSOLE)
255 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
256 #if defined(CONFIG_TN3215_CONSOLE)
258 #elif defined(CONFIG_TN3270_CONSOLE)
260 #elif defined(CONFIG_SCLP_CONSOLE)
264 } else if (MACHINE_IS_P390) {
265 #if defined(CONFIG_TN3215_CONSOLE)
267 #elif defined(CONFIG_TN3270_CONSOLE)
271 #if defined(CONFIG_SCLP_CONSOLE)
278 extern void machine_restart_smp(char *);
279 extern void machine_halt_smp(void);
280 extern void machine_power_off_smp(void);
282 void (*_machine_restart)(char *command) = machine_restart_smp;
283 void (*_machine_halt)(void) = machine_halt_smp;
284 void (*_machine_power_off)(void) = machine_power_off_smp;
287 * Reboot, halt and power_off routines for non SMP.
289 static void do_machine_restart_nonsmp(char * __unused)
294 static void do_machine_halt_nonsmp(void)
296 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
297 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
298 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
301 static void do_machine_power_off_nonsmp(void)
303 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
304 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
305 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
308 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
309 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
310 void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
314 * Reboot, halt and power_off stubs. They just call _machine_restart,
315 * _machine_halt or _machine_power_off.
318 void machine_restart(char *command)
320 if (!in_interrupt() || oops_in_progress)
322 * Only unblank the console if we are called in enabled
323 * context or a bust_spinlocks cleared the way for us.
326 _machine_restart(command);
329 void machine_halt(void)
331 if (!in_interrupt() || oops_in_progress)
333 * Only unblank the console if we are called in enabled
334 * context or a bust_spinlocks cleared the way for us.
340 void machine_power_off(void)
342 if (!in_interrupt() || oops_in_progress)
344 * Only unblank the console if we are called in enabled
345 * context or a bust_spinlocks cleared the way for us.
348 _machine_power_off();
352 * Dummy power off function.
354 void (*pm_power_off)(void) = machine_power_off;
356 static int __init early_parse_mem(char *p)
358 memory_end = memparse(p, &p);
361 early_param("mem", early_parse_mem);
364 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
366 static int __init early_parse_ipldelay(char *p)
368 unsigned long delay = 0;
370 delay = simple_strtoul(p, &p, 0);
379 delay *= 60 * 1000000;
382 /* now wait for the requested amount of time */
387 early_param("ipldelay", early_parse_ipldelay);
396 * Setup lowcore for boot cpu
398 lc_pages = sizeof(void *) == 8 ? 2 : 1;
399 lc = (struct _lowcore *)
400 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
401 memset(lc, 0, lc_pages * PAGE_SIZE);
402 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
403 lc->restart_psw.addr =
404 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
405 lc->external_new_psw.mask = PSW_KERNEL_BITS;
406 lc->external_new_psw.addr =
407 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
408 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
409 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
410 lc->program_new_psw.mask = PSW_KERNEL_BITS;
411 lc->program_new_psw.addr =
412 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
413 lc->mcck_new_psw.mask =
414 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
415 lc->mcck_new_psw.addr =
416 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
417 lc->io_new_psw.mask = PSW_KERNEL_BITS;
418 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
419 lc->ipl_device = S390_lowcore.ipl_device;
420 lc->jiffy_timer = -1LL;
421 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
422 lc->async_stack = (unsigned long)
423 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
424 lc->panic_stack = (unsigned long)
425 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
426 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
427 lc->thread_info = (unsigned long) &init_thread_union;
429 if (MACHINE_HAS_IEEE) {
430 lc->extended_save_area_addr = (__u32)
431 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
432 /* enable extended save area */
433 __ctl_set_bit(14, 29);
436 set_prefix((u32)(unsigned long) lc);
440 setup_resources(void)
442 struct resource *res;
445 code_resource.start = (unsigned long) &_text;
446 code_resource.end = (unsigned long) &_etext - 1;
447 data_resource.start = (unsigned long) &_etext;
448 data_resource.end = (unsigned long) &_edata - 1;
450 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
451 res = alloc_bootmem_low(sizeof(struct resource));
452 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
453 switch (memory_chunk[i].type) {
454 case CHUNK_READ_WRITE:
455 res->name = "System RAM";
457 case CHUNK_READ_ONLY:
458 res->name = "System ROM";
459 res->flags |= IORESOURCE_READONLY;
462 res->name = "reserved";
464 res->start = memory_chunk[i].addr;
465 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
466 request_resource(&iomem_resource, res);
467 request_resource(res, &code_resource);
468 request_resource(res, &data_resource);
472 static void __init setup_memory_end(void)
474 unsigned long real_size, memory_size;
475 unsigned long max_mem, max_phys;
478 memory_size = real_size = 0;
479 max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
480 memory_end &= PAGE_MASK;
482 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
484 for (i = 0; i < MEMORY_CHUNKS; i++) {
485 struct mem_chunk *chunk = &memory_chunk[i];
487 real_size = max(real_size, chunk->addr + chunk->size);
488 if (chunk->addr >= max_mem) {
489 memset(chunk, 0, sizeof(*chunk));
492 if (chunk->addr + chunk->size > max_mem)
493 chunk->size = max_mem - chunk->addr;
494 memory_size = max(memory_size, chunk->addr + chunk->size);
497 memory_end = memory_size;
498 if (real_size > memory_end)
499 printk("More memory detected than supported. Unused: %luk\n",
500 (real_size - memory_end) >> 10);
506 unsigned long bootmap_size;
507 unsigned long start_pfn, end_pfn, init_pfn;
511 * partially used pages are not usable - thus
512 * we are rounding upwards:
514 start_pfn = PFN_UP(__pa(&_end));
515 end_pfn = max_pfn = PFN_DOWN(memory_end);
517 /* Initialize storage key for kernel pages */
518 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
519 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
521 #ifdef CONFIG_BLK_DEV_INITRD
523 * Move the initrd in case the bitmap of the bootmem allocater
524 * would overwrite it.
527 if (INITRD_START && INITRD_SIZE) {
528 unsigned long bmap_size;
531 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
532 bmap_size = PFN_PHYS(bmap_size);
534 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
535 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
537 if (start + INITRD_SIZE > memory_end) {
538 printk("initrd extends beyond end of memory "
539 "(0x%08lx > 0x%08lx)\n"
540 "disabling initrd\n",
541 start + INITRD_SIZE, memory_end);
542 INITRD_START = INITRD_SIZE = 0;
544 printk("Moving initrd (0x%08lx -> 0x%08lx, "
546 INITRD_START, start, INITRD_SIZE);
547 memmove((void *) start, (void *) INITRD_START,
549 INITRD_START = start;
556 * Initialize the boot-time allocator
558 bootmap_size = init_bootmem(start_pfn, end_pfn);
561 * Register RAM areas with the bootmem allocator.
564 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
565 unsigned long start_chunk, end_chunk, pfn;
567 if (memory_chunk[i].type != CHUNK_READ_WRITE)
569 start_chunk = PFN_DOWN(memory_chunk[i].addr);
570 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
571 end_chunk = min(end_chunk, end_pfn);
572 if (start_chunk >= end_chunk)
574 add_active_range(0, start_chunk, end_chunk);
575 pfn = max(start_chunk, start_pfn);
576 for (; pfn <= end_chunk; pfn++)
577 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
580 psw_set_key(PAGE_DEFAULT_KEY);
582 free_bootmem_with_active_regions(0, max_pfn);
583 reserve_bootmem(0, PFN_PHYS(start_pfn));
586 * Reserve the bootmem bitmap itself as well. We do this in two
587 * steps (first step was init_bootmem()) because this catches
588 * the (very unlikely) case of us accidentally initializing the
589 * bootmem allocator with an invalid RAM area.
591 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
593 #ifdef CONFIG_BLK_DEV_INITRD
594 if (INITRD_START && INITRD_SIZE) {
595 if (INITRD_START + INITRD_SIZE <= memory_end) {
596 reserve_bootmem(INITRD_START, INITRD_SIZE);
597 initrd_start = INITRD_START;
598 initrd_end = initrd_start + INITRD_SIZE;
600 printk("initrd extends beyond end of memory "
601 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
602 initrd_start + INITRD_SIZE, memory_end);
603 initrd_start = initrd_end = 0;
610 * Setup function called from init/main.c just after the banner
615 setup_arch(char **cmdline_p)
618 * print what head.S has found out about the machine
621 printk((MACHINE_IS_VM) ?
622 "We are running under VM (31 bit mode)\n" :
623 "We are running native (31 bit mode)\n");
624 printk((MACHINE_HAS_IEEE) ?
625 "This machine has an IEEE fpu\n" :
626 "This machine has no IEEE fpu\n");
627 #else /* CONFIG_64BIT */
628 printk((MACHINE_IS_VM) ?
629 "We are running under VM (64 bit mode)\n" :
630 "We are running native (64 bit mode)\n");
631 #endif /* CONFIG_64BIT */
633 /* Save unparsed command line copy for /proc/cmdline */
634 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
636 *cmdline_p = COMMAND_LINE;
637 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
639 ROOT_DEV = Root_RAM0;
641 init_mm.start_code = PAGE_OFFSET;
642 init_mm.end_code = (unsigned long) &_etext;
643 init_mm.end_data = (unsigned long) &_edata;
644 init_mm.brk = (unsigned long) &_end;
646 if (MACHINE_HAS_MVCOS)
647 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
649 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
659 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
660 smp_setup_cpu_possible_map();
663 * Create kernel page tables and switch to virtual addressing.
667 /* Setup default console */
671 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
677 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
682 cpuinfo->cpu_id.version,
683 cpuinfo->cpu_id.ident,
684 cpuinfo->cpu_id.machine,
685 cpuinfo->cpu_id.unused);
689 * show_cpuinfo - Get information on one CPU for use by procfs.
692 static int show_cpuinfo(struct seq_file *m, void *v)
694 struct cpuinfo_S390 *cpuinfo;
695 unsigned long n = (unsigned long) v - 1;
699 seq_printf(m, "vendor_id : IBM/S390\n"
700 "# processors : %i\n"
701 "bogomips per cpu: %lu.%02lu\n",
702 num_online_cpus(), loops_per_jiffy/(500000/HZ),
703 (loops_per_jiffy/(5000/HZ))%100);
707 if (smp_processor_id() == n)
708 cpuinfo = &S390_lowcore.cpu_data;
710 cpuinfo = &lowcore_ptr[n]->cpu_data;
712 cpuinfo = &S390_lowcore.cpu_data;
714 seq_printf(m, "processor %li: "
716 "identification = %06X, "
718 n, cpuinfo->cpu_id.version,
719 cpuinfo->cpu_id.ident,
720 cpuinfo->cpu_id.machine);
726 static void *c_start(struct seq_file *m, loff_t *pos)
728 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
730 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
733 return c_start(m, pos);
735 static void c_stop(struct seq_file *m, void *v)
738 struct seq_operations cpuinfo_op = {
742 .show = show_cpuinfo,