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>
41 #include <linux/reboot.h>
43 #include <asm/uaccess.h>
44 #include <asm/system.h>
46 #include <asm/mmu_context.h>
47 #include <asm/cpcmd.h>
48 #include <asm/lowcore.h>
51 #include <asm/ptrace.h>
52 #include <asm/sections.h>
55 * User copy operations.
57 struct uaccess_ops uaccess;
58 EXPORT_SYMBOL_GPL(uaccess);
63 unsigned int console_mode = 0;
64 unsigned int console_devno = -1;
65 unsigned int console_irq = -1;
66 unsigned long machine_flags = 0;
68 struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
69 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
70 static unsigned long __initdata memory_end;
73 * This is set up by the setup-routine at boot-time
74 * for S390 need to find out, what we have to setup
75 * using address 0x10400 ...
78 #include <asm/setup.h>
80 static struct resource code_resource = {
81 .name = "Kernel code",
82 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
85 static struct resource data_resource = {
86 .name = "Kernel data",
87 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
91 * cpu_init() initializes state that is per-CPU.
93 void __devinit cpu_init (void)
95 int addr = hard_smp_processor_id();
98 * Store processor id in lowcore (used e.g. in timer_interrupt)
100 asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
101 S390_lowcore.cpu_data.cpu_addr = addr;
104 * Force FPU initialization:
106 clear_thread_flag(TIF_USEDFPU);
109 atomic_inc(&init_mm.mm_count);
110 current->active_mm = &init_mm;
113 enter_lazy_tlb(&init_mm, current);
117 * VM halt and poweroff setup routines
119 char vmhalt_cmd[128] = "";
120 char vmpoff_cmd[128] = "";
121 static char vmpanic_cmd[128] = "";
123 static inline void strncpy_skip_quote(char *dst, char *src, int n)
128 for (sx = 0; src[sx] != 0; sx++) {
129 if (src[sx] == '"') continue;
135 static int __init vmhalt_setup(char *str)
137 strncpy_skip_quote(vmhalt_cmd, str, 127);
142 __setup("vmhalt=", vmhalt_setup);
144 static int __init vmpoff_setup(char *str)
146 strncpy_skip_quote(vmpoff_cmd, str, 127);
151 __setup("vmpoff=", vmpoff_setup);
153 static int vmpanic_notify(struct notifier_block *self, unsigned long event,
156 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
157 cpcmd(vmpanic_cmd, NULL, 0, NULL);
162 #define PANIC_PRI_VMPANIC 0
164 static struct notifier_block vmpanic_nb = {
165 .notifier_call = vmpanic_notify,
166 .priority = PANIC_PRI_VMPANIC
169 static int __init vmpanic_setup(char *str)
171 static int register_done __initdata = 0;
173 strncpy_skip_quote(vmpanic_cmd, str, 127);
174 vmpanic_cmd[127] = 0;
175 if (!register_done) {
177 atomic_notifier_chain_register(&panic_notifier_list,
183 __setup("vmpanic=", vmpanic_setup);
186 * condev= and conmode= setup parameter.
189 static int __init condev_setup(char *str)
193 vdev = simple_strtoul(str, &str, 0);
194 if (vdev >= 0 && vdev < 65536) {
195 console_devno = vdev;
201 __setup("condev=", condev_setup);
203 static int __init conmode_setup(char *str)
205 #if defined(CONFIG_SCLP_CONSOLE)
206 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
209 #if defined(CONFIG_TN3215_CONSOLE)
210 if (strncmp(str, "3215", 5) == 0)
213 #if defined(CONFIG_TN3270_CONSOLE)
214 if (strncmp(str, "3270", 5) == 0)
220 __setup("conmode=", conmode_setup);
222 static void __init conmode_default(void)
224 char query_buffer[1024];
228 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
229 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
230 ptr = strstr(query_buffer, "SUBCHANNEL =");
231 console_irq = simple_strtoul(ptr + 13, NULL, 16);
232 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
233 ptr = strstr(query_buffer, "CONMODE");
235 * Set the conmode to 3215 so that the device recognition
236 * will set the cu_type of the console to 3215. If the
237 * conmode is 3270 and we don't set it back then both
238 * 3215 and the 3270 driver will try to access the console
239 * device (3215 as console and 3270 as normal tty).
241 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
243 #if defined(CONFIG_SCLP_CONSOLE)
248 if (strncmp(ptr + 8, "3270", 4) == 0) {
249 #if defined(CONFIG_TN3270_CONSOLE)
251 #elif defined(CONFIG_TN3215_CONSOLE)
253 #elif defined(CONFIG_SCLP_CONSOLE)
256 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
257 #if defined(CONFIG_TN3215_CONSOLE)
259 #elif defined(CONFIG_TN3270_CONSOLE)
261 #elif defined(CONFIG_SCLP_CONSOLE)
265 } else if (MACHINE_IS_P390) {
266 #if defined(CONFIG_TN3215_CONSOLE)
268 #elif defined(CONFIG_TN3270_CONSOLE)
272 #if defined(CONFIG_SCLP_CONSOLE)
279 void (*_machine_restart)(char *command) = machine_restart_smp;
280 void (*_machine_halt)(void) = machine_halt_smp;
281 void (*_machine_power_off)(void) = machine_power_off_smp;
284 * Reboot, halt and power_off routines for non SMP.
286 static void do_machine_restart_nonsmp(char * __unused)
291 static void do_machine_halt_nonsmp(void)
293 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
294 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
295 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
298 static void do_machine_power_off_nonsmp(void)
300 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
301 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
302 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
305 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
306 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
307 void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
311 * Reboot, halt and power_off stubs. They just call _machine_restart,
312 * _machine_halt or _machine_power_off.
315 void machine_restart(char *command)
317 if (!in_interrupt() || oops_in_progress)
319 * Only unblank the console if we are called in enabled
320 * context or a bust_spinlocks cleared the way for us.
323 _machine_restart(command);
326 void machine_halt(void)
328 if (!in_interrupt() || oops_in_progress)
330 * Only unblank the console if we are called in enabled
331 * context or a bust_spinlocks cleared the way for us.
337 void machine_power_off(void)
339 if (!in_interrupt() || oops_in_progress)
341 * Only unblank the console if we are called in enabled
342 * context or a bust_spinlocks cleared the way for us.
345 _machine_power_off();
349 * Dummy power off function.
351 void (*pm_power_off)(void) = machine_power_off;
353 static int __init early_parse_mem(char *p)
355 memory_end = memparse(p, &p);
358 early_param("mem", early_parse_mem);
361 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
363 static int __init early_parse_ipldelay(char *p)
365 unsigned long delay = 0;
367 delay = simple_strtoul(p, &p, 0);
376 delay *= 60 * 1000000;
379 /* now wait for the requested amount of time */
384 early_param("ipldelay", early_parse_ipldelay);
393 * Setup lowcore for boot cpu
395 lc_pages = sizeof(void *) == 8 ? 2 : 1;
396 lc = (struct _lowcore *)
397 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
398 memset(lc, 0, lc_pages * PAGE_SIZE);
399 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
400 lc->restart_psw.addr =
401 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
402 lc->external_new_psw.mask = PSW_KERNEL_BITS;
403 lc->external_new_psw.addr =
404 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
405 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
406 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
407 lc->program_new_psw.mask = PSW_KERNEL_BITS;
408 lc->program_new_psw.addr =
409 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
410 lc->mcck_new_psw.mask =
411 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
412 lc->mcck_new_psw.addr =
413 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
414 lc->io_new_psw.mask = PSW_KERNEL_BITS;
415 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
416 lc->ipl_device = S390_lowcore.ipl_device;
417 lc->jiffy_timer = -1LL;
418 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
419 lc->async_stack = (unsigned long)
420 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
421 lc->panic_stack = (unsigned long)
422 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
423 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
424 lc->thread_info = (unsigned long) &init_thread_union;
426 if (MACHINE_HAS_IEEE) {
427 lc->extended_save_area_addr = (__u32)
428 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
429 /* enable extended save area */
430 __ctl_set_bit(14, 29);
433 set_prefix((u32)(unsigned long) lc);
437 setup_resources(void)
439 struct resource *res;
442 code_resource.start = (unsigned long) &_text;
443 code_resource.end = (unsigned long) &_etext - 1;
444 data_resource.start = (unsigned long) &_etext;
445 data_resource.end = (unsigned long) &_edata - 1;
447 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
448 res = alloc_bootmem_low(sizeof(struct resource));
449 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
450 switch (memory_chunk[i].type) {
451 case CHUNK_READ_WRITE:
452 res->name = "System RAM";
454 case CHUNK_READ_ONLY:
455 res->name = "System ROM";
456 res->flags |= IORESOURCE_READONLY;
459 res->name = "reserved";
461 res->start = memory_chunk[i].addr;
462 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
463 request_resource(&iomem_resource, res);
464 request_resource(res, &code_resource);
465 request_resource(res, &data_resource);
469 static void __init setup_memory_end(void)
471 unsigned long real_size, memory_size;
472 unsigned long max_mem, max_phys;
475 memory_size = real_size = 0;
476 max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
477 memory_end &= PAGE_MASK;
479 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
481 for (i = 0; i < MEMORY_CHUNKS; i++) {
482 struct mem_chunk *chunk = &memory_chunk[i];
484 real_size = max(real_size, chunk->addr + chunk->size);
485 if (chunk->addr >= max_mem) {
486 memset(chunk, 0, sizeof(*chunk));
489 if (chunk->addr + chunk->size > max_mem)
490 chunk->size = max_mem - chunk->addr;
491 memory_size = max(memory_size, chunk->addr + chunk->size);
494 memory_end = memory_size;
500 unsigned long bootmap_size;
501 unsigned long start_pfn, end_pfn, init_pfn;
505 * partially used pages are not usable - thus
506 * we are rounding upwards:
508 start_pfn = PFN_UP(__pa(&_end));
509 end_pfn = max_pfn = PFN_DOWN(memory_end);
511 /* Initialize storage key for kernel pages */
512 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
513 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
515 #ifdef CONFIG_BLK_DEV_INITRD
517 * Move the initrd in case the bitmap of the bootmem allocater
518 * would overwrite it.
521 if (INITRD_START && INITRD_SIZE) {
522 unsigned long bmap_size;
525 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
526 bmap_size = PFN_PHYS(bmap_size);
528 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
529 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
531 if (start + INITRD_SIZE > memory_end) {
532 printk("initrd extends beyond end of memory "
533 "(0x%08lx > 0x%08lx)\n"
534 "disabling initrd\n",
535 start + INITRD_SIZE, memory_end);
536 INITRD_START = INITRD_SIZE = 0;
538 printk("Moving initrd (0x%08lx -> 0x%08lx, "
540 INITRD_START, start, INITRD_SIZE);
541 memmove((void *) start, (void *) INITRD_START,
543 INITRD_START = start;
550 * Initialize the boot-time allocator
552 bootmap_size = init_bootmem(start_pfn, end_pfn);
555 * Register RAM areas with the bootmem allocator.
558 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
559 unsigned long start_chunk, end_chunk, pfn;
561 if (memory_chunk[i].type != CHUNK_READ_WRITE)
563 start_chunk = PFN_DOWN(memory_chunk[i].addr);
564 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
565 end_chunk = min(end_chunk, end_pfn);
566 if (start_chunk >= end_chunk)
568 add_active_range(0, start_chunk, end_chunk);
569 pfn = max(start_chunk, start_pfn);
570 for (; pfn <= end_chunk; pfn++)
571 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
574 psw_set_key(PAGE_DEFAULT_KEY);
576 free_bootmem_with_active_regions(0, max_pfn);
577 reserve_bootmem(0, PFN_PHYS(start_pfn));
580 * Reserve the bootmem bitmap itself as well. We do this in two
581 * steps (first step was init_bootmem()) because this catches
582 * the (very unlikely) case of us accidentally initializing the
583 * bootmem allocator with an invalid RAM area.
585 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
587 #ifdef CONFIG_BLK_DEV_INITRD
588 if (INITRD_START && INITRD_SIZE) {
589 if (INITRD_START + INITRD_SIZE <= memory_end) {
590 reserve_bootmem(INITRD_START, INITRD_SIZE);
591 initrd_start = INITRD_START;
592 initrd_end = initrd_start + INITRD_SIZE;
594 printk("initrd extends beyond end of memory "
595 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
596 initrd_start + INITRD_SIZE, memory_end);
597 initrd_start = initrd_end = 0;
604 * Setup function called from init/main.c just after the banner
609 setup_arch(char **cmdline_p)
612 * print what head.S has found out about the machine
615 printk((MACHINE_IS_VM) ?
616 "We are running under VM (31 bit mode)\n" :
617 "We are running native (31 bit mode)\n");
618 printk((MACHINE_HAS_IEEE) ?
619 "This machine has an IEEE fpu\n" :
620 "This machine has no IEEE fpu\n");
621 #else /* CONFIG_64BIT */
622 printk((MACHINE_IS_VM) ?
623 "We are running under VM (64 bit mode)\n" :
624 "We are running native (64 bit mode)\n");
625 #endif /* CONFIG_64BIT */
627 /* Save unparsed command line copy for /proc/cmdline */
628 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
630 *cmdline_p = COMMAND_LINE;
631 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
633 ROOT_DEV = Root_RAM0;
635 init_mm.start_code = PAGE_OFFSET;
636 init_mm.end_code = (unsigned long) &_etext;
637 init_mm.end_data = (unsigned long) &_edata;
638 init_mm.brk = (unsigned long) &_end;
640 if (MACHINE_HAS_MVCOS)
641 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
643 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
653 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
654 smp_setup_cpu_possible_map();
657 * Create kernel page tables and switch to virtual addressing.
661 /* Setup default console */
665 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
671 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
676 cpuinfo->cpu_id.version,
677 cpuinfo->cpu_id.ident,
678 cpuinfo->cpu_id.machine,
679 cpuinfo->cpu_id.unused);
683 * show_cpuinfo - Get information on one CPU for use by procfs.
686 static int show_cpuinfo(struct seq_file *m, void *v)
688 struct cpuinfo_S390 *cpuinfo;
689 unsigned long n = (unsigned long) v - 1;
693 seq_printf(m, "vendor_id : IBM/S390\n"
694 "# processors : %i\n"
695 "bogomips per cpu: %lu.%02lu\n",
696 num_online_cpus(), loops_per_jiffy/(500000/HZ),
697 (loops_per_jiffy/(5000/HZ))%100);
701 if (smp_processor_id() == n)
702 cpuinfo = &S390_lowcore.cpu_data;
704 cpuinfo = &lowcore_ptr[n]->cpu_data;
706 cpuinfo = &S390_lowcore.cpu_data;
708 seq_printf(m, "processor %li: "
710 "identification = %06X, "
712 n, cpuinfo->cpu_id.version,
713 cpuinfo->cpu_id.ident,
714 cpuinfo->cpu_id.machine);
720 static void *c_start(struct seq_file *m, loff_t *pos)
722 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
724 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
727 return c_start(m, pos);
729 static void c_stop(struct seq_file *m, void *v)
732 struct seq_operations cpuinfo_op = {
736 .show = show_cpuinfo,