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/config.h>
32 #include <linux/init.h>
33 #include <linux/initrd.h>
34 #include <linux/bootmem.h>
35 #include <linux/root_dev.h>
36 #include <linux/console.h>
37 #include <linux/seq_file.h>
38 #include <linux/kernel_stat.h>
39 #include <linux/device.h>
41 #include <asm/uaccess.h>
42 #include <asm/system.h>
44 #include <asm/mmu_context.h>
45 #include <asm/cpcmd.h>
46 #include <asm/lowcore.h>
49 #include <asm/ptrace.h>
50 #include <asm/sections.h>
55 unsigned int console_mode = 0;
56 unsigned int console_devno = -1;
57 unsigned int console_irq = -1;
58 unsigned long memory_size = 0;
59 unsigned long machine_flags = 0;
61 unsigned long addr, size, type;
62 } memory_chunk[MEMORY_CHUNKS] = { { 0 } };
63 #define CHUNK_READ_WRITE 0
64 #define CHUNK_READ_ONLY 1
65 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
66 unsigned long __initdata zholes_size[MAX_NR_ZONES];
67 static unsigned long __initdata memory_end;
70 * This is set up by the setup-routine at boot-time
71 * for S390 need to find out, what we have to setup
72 * using address 0x10400 ...
75 #include <asm/setup.h>
77 static struct resource code_resource = {
78 .name = "Kernel code",
79 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
82 static struct resource data_resource = {
83 .name = "Kernel data",
84 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
88 * cpu_init() initializes state that is per-CPU.
90 void __devinit cpu_init (void)
92 int addr = hard_smp_processor_id();
95 * Store processor id in lowcore (used e.g. in timer_interrupt)
97 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
98 S390_lowcore.cpu_data.cpu_addr = addr;
101 * Force FPU initialization:
103 clear_thread_flag(TIF_USEDFPU);
106 atomic_inc(&init_mm.mm_count);
107 current->active_mm = &init_mm;
110 enter_lazy_tlb(&init_mm, current);
114 * VM halt and poweroff setup routines
116 char vmhalt_cmd[128] = "";
117 char vmpoff_cmd[128] = "";
119 static inline void strncpy_skip_quote(char *dst, char *src, int n)
124 for (sx = 0; src[sx] != 0; sx++) {
125 if (src[sx] == '"') continue;
131 static int __init vmhalt_setup(char *str)
133 strncpy_skip_quote(vmhalt_cmd, str, 127);
138 __setup("vmhalt=", vmhalt_setup);
140 static int __init vmpoff_setup(char *str)
142 strncpy_skip_quote(vmpoff_cmd, str, 127);
147 __setup("vmpoff=", vmpoff_setup);
150 * condev= and conmode= setup parameter.
153 static int __init condev_setup(char *str)
157 vdev = simple_strtoul(str, &str, 0);
158 if (vdev >= 0 && vdev < 65536) {
159 console_devno = vdev;
165 __setup("condev=", condev_setup);
167 static int __init conmode_setup(char *str)
169 #if defined(CONFIG_SCLP_CONSOLE)
170 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
173 #if defined(CONFIG_TN3215_CONSOLE)
174 if (strncmp(str, "3215", 5) == 0)
177 #if defined(CONFIG_TN3270_CONSOLE)
178 if (strncmp(str, "3270", 5) == 0)
184 __setup("conmode=", conmode_setup);
186 static void __init conmode_default(void)
188 char query_buffer[1024];
192 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
193 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
194 ptr = strstr(query_buffer, "SUBCHANNEL =");
195 console_irq = simple_strtoul(ptr + 13, NULL, 16);
196 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
197 ptr = strstr(query_buffer, "CONMODE");
199 * Set the conmode to 3215 so that the device recognition
200 * will set the cu_type of the console to 3215. If the
201 * conmode is 3270 and we don't set it back then both
202 * 3215 and the 3270 driver will try to access the console
203 * device (3215 as console and 3270 as normal tty).
205 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
207 #if defined(CONFIG_SCLP_CONSOLE)
212 if (strncmp(ptr + 8, "3270", 4) == 0) {
213 #if defined(CONFIG_TN3270_CONSOLE)
215 #elif defined(CONFIG_TN3215_CONSOLE)
217 #elif defined(CONFIG_SCLP_CONSOLE)
220 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
221 #if defined(CONFIG_TN3215_CONSOLE)
223 #elif defined(CONFIG_TN3270_CONSOLE)
225 #elif defined(CONFIG_SCLP_CONSOLE)
229 } else if (MACHINE_IS_P390) {
230 #if defined(CONFIG_TN3215_CONSOLE)
232 #elif defined(CONFIG_TN3270_CONSOLE)
236 #if defined(CONFIG_SCLP_CONSOLE)
243 extern void machine_restart_smp(char *);
244 extern void machine_halt_smp(void);
245 extern void machine_power_off_smp(void);
247 void (*_machine_restart)(char *command) = machine_restart_smp;
248 void (*_machine_halt)(void) = machine_halt_smp;
249 void (*_machine_power_off)(void) = machine_power_off_smp;
252 * Reboot, halt and power_off routines for non SMP.
254 extern void reipl(unsigned long devno);
255 extern void reipl_diag(void);
256 static void do_machine_restart_nonsmp(char * __unused)
261 cpcmd ("IPL", NULL, 0, NULL);
263 reipl (0x10000 | S390_lowcore.ipl_device);
266 static void do_machine_halt_nonsmp(void)
268 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
269 cpcmd(vmhalt_cmd, NULL, 0, NULL);
270 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
273 static void do_machine_power_off_nonsmp(void)
275 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
276 cpcmd(vmpoff_cmd, NULL, 0, NULL);
277 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
280 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
281 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
282 void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
286 * Reboot, halt and power_off stubs. They just call _machine_restart,
287 * _machine_halt or _machine_power_off.
290 void machine_restart(char *command)
293 _machine_restart(command);
296 void machine_halt(void)
302 void machine_power_off(void)
305 _machine_power_off();
309 * Dummy power off function.
311 void (*pm_power_off)(void) = machine_power_off;
314 add_memory_hole(unsigned long start, unsigned long end)
316 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
319 zholes_size[ZONE_DMA] += end - start + 1;
320 else if (start > dma_pfn)
321 zholes_size[ZONE_NORMAL] += end - start + 1;
323 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
324 zholes_size[ZONE_NORMAL] += end - dma_pfn;
328 static int __init early_parse_mem(char *p)
330 memory_end = memparse(p, &p);
333 early_param("mem", early_parse_mem);
336 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
338 static int __init early_parse_ipldelay(char *p)
340 unsigned long delay = 0;
342 delay = simple_strtoul(p, &p, 0);
351 delay *= 60 * 1000000;
354 /* now wait for the requested amount of time */
359 early_param("ipldelay", early_parse_ipldelay);
368 * Setup lowcore for boot cpu
370 lc_pages = sizeof(void *) == 8 ? 2 : 1;
371 lc = (struct _lowcore *)
372 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
373 memset(lc, 0, lc_pages * PAGE_SIZE);
374 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
375 lc->restart_psw.addr =
376 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
377 lc->external_new_psw.mask = PSW_KERNEL_BITS;
378 lc->external_new_psw.addr =
379 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
380 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
381 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
382 lc->program_new_psw.mask = PSW_KERNEL_BITS;
383 lc->program_new_psw.addr =
384 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
385 lc->mcck_new_psw.mask =
386 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
387 lc->mcck_new_psw.addr =
388 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
389 lc->io_new_psw.mask = PSW_KERNEL_BITS;
390 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
391 lc->ipl_device = S390_lowcore.ipl_device;
392 lc->jiffy_timer = -1LL;
393 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
394 lc->async_stack = (unsigned long)
395 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
396 lc->panic_stack = (unsigned long)
397 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
398 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
399 lc->thread_info = (unsigned long) &init_thread_union;
401 if (MACHINE_HAS_IEEE) {
402 lc->extended_save_area_addr = (__u32)
403 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
404 /* enable extended save area */
408 set_prefix((u32)(unsigned long) lc);
412 setup_resources(void)
414 struct resource *res;
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;
422 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
423 res = alloc_bootmem_low(sizeof(struct resource));
424 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
425 switch (memory_chunk[i].type) {
426 case CHUNK_READ_WRITE:
427 res->name = "System RAM";
429 case CHUNK_READ_ONLY:
430 res->name = "System ROM";
431 res->flags |= IORESOURCE_READONLY;
434 res->name = "reserved";
436 res->start = memory_chunk[i].addr;
437 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
438 request_resource(&iomem_resource, res);
439 request_resource(res, &code_resource);
440 request_resource(res, &data_resource);
447 unsigned long bootmap_size;
448 unsigned long start_pfn, end_pfn, init_pfn;
449 unsigned long last_rw_end;
453 * partially used pages are not usable - thus
454 * we are rounding upwards:
456 start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
457 end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
459 /* Initialize storage key for kernel pages */
460 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
461 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
464 * Initialize the boot-time allocator (with low memory only):
466 bootmap_size = init_bootmem(start_pfn, end_pfn);
469 * Register RAM areas with the bootmem allocator.
471 last_rw_end = start_pfn;
473 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
474 unsigned long start_chunk, end_chunk;
476 if (memory_chunk[i].type != CHUNK_READ_WRITE)
478 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
479 start_chunk >>= PAGE_SHIFT;
480 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
481 end_chunk >>= PAGE_SHIFT;
482 if (start_chunk < start_pfn)
483 start_chunk = start_pfn;
484 if (end_chunk > end_pfn)
486 if (start_chunk < end_chunk) {
487 /* Initialize storage key for RAM pages */
488 for (init_pfn = start_chunk ; init_pfn < end_chunk;
490 page_set_storage_key(init_pfn << PAGE_SHIFT,
492 free_bootmem(start_chunk << PAGE_SHIFT,
493 (end_chunk - start_chunk) << PAGE_SHIFT);
494 if (last_rw_end < start_chunk)
495 add_memory_hole(last_rw_end, start_chunk - 1);
496 last_rw_end = end_chunk;
500 psw_set_key(PAGE_DEFAULT_KEY);
502 if (last_rw_end < end_pfn - 1)
503 add_memory_hole(last_rw_end, end_pfn - 1);
506 * Reserve the bootmem bitmap itself as well. We do this in two
507 * steps (first step was init_bootmem()) because this catches
508 * the (very unlikely) case of us accidentally initializing the
509 * bootmem allocator with an invalid RAM area.
511 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
513 #ifdef CONFIG_BLK_DEV_INITRD
515 if (INITRD_START + INITRD_SIZE <= memory_end) {
516 reserve_bootmem(INITRD_START, INITRD_SIZE);
517 initrd_start = INITRD_START;
518 initrd_end = initrd_start + INITRD_SIZE;
520 printk("initrd extends beyond end of memory "
521 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
522 initrd_start + INITRD_SIZE, memory_end);
523 initrd_start = initrd_end = 0;
530 * Setup function called from init/main.c just after the banner
535 setup_arch(char **cmdline_p)
538 * print what head.S has found out about the machine
541 printk((MACHINE_IS_VM) ?
542 "We are running under VM (31 bit mode)\n" :
543 "We are running native (31 bit mode)\n");
544 printk((MACHINE_HAS_IEEE) ?
545 "This machine has an IEEE fpu\n" :
546 "This machine has no IEEE fpu\n");
547 #else /* CONFIG_64BIT */
548 printk((MACHINE_IS_VM) ?
549 "We are running under VM (64 bit mode)\n" :
550 "We are running native (64 bit mode)\n");
551 #endif /* CONFIG_64BIT */
553 /* Save unparsed command line copy for /proc/cmdline */
554 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
556 *cmdline_p = COMMAND_LINE;
557 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
559 ROOT_DEV = Root_RAM0;
561 init_mm.start_code = PAGE_OFFSET;
562 init_mm.end_code = (unsigned long) &_etext;
563 init_mm.end_data = (unsigned long) &_edata;
564 init_mm.brk = (unsigned long) &_end;
566 memory_end = memory_size;
571 memory_end &= ~0x400000UL;
574 * We need some free virtual space to be able to do vmalloc.
575 * On a machine with 2GB memory we make sure that we have at
576 * least 128 MB free space for vmalloc.
578 if (memory_end > 1920*1024*1024)
579 memory_end = 1920*1024*1024;
580 #else /* CONFIG_64BIT */
581 memory_end &= ~0x200000UL;
582 #endif /* CONFIG_64BIT */
589 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
590 smp_setup_cpu_possible_map();
593 * Create kernel page tables and switch to virtual addressing.
597 /* Setup default console */
601 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
607 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
612 cpuinfo->cpu_id.version,
613 cpuinfo->cpu_id.ident,
614 cpuinfo->cpu_id.machine,
615 cpuinfo->cpu_id.unused);
619 * show_cpuinfo - Get information on one CPU for use by procfs.
622 static int show_cpuinfo(struct seq_file *m, void *v)
624 struct cpuinfo_S390 *cpuinfo;
625 unsigned long n = (unsigned long) v - 1;
629 seq_printf(m, "vendor_id : IBM/S390\n"
630 "# processors : %i\n"
631 "bogomips per cpu: %lu.%02lu\n",
632 num_online_cpus(), loops_per_jiffy/(500000/HZ),
633 (loops_per_jiffy/(5000/HZ))%100);
637 if (smp_processor_id() == n)
638 cpuinfo = &S390_lowcore.cpu_data;
640 cpuinfo = &lowcore_ptr[n]->cpu_data;
642 cpuinfo = &S390_lowcore.cpu_data;
644 seq_printf(m, "processor %li: "
646 "identification = %06X, "
648 n, cpuinfo->cpu_id.version,
649 cpuinfo->cpu_id.ident,
650 cpuinfo->cpu_id.machine);
656 static void *c_start(struct seq_file *m, loff_t *pos)
658 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
660 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
663 return c_start(m, pos);
665 static void c_stop(struct seq_file *m, void *v)
668 struct seq_operations cpuinfo_op = {
672 .show = show_cpuinfo,
675 #define DEFINE_IPL_ATTR(_name, _format, _value) \
676 static ssize_t ipl_##_name##_show(struct subsystem *subsys, \
679 return sprintf(page, _format, _value); \
681 static struct subsys_attribute ipl_##_name##_attr = \
682 __ATTR(_name, S_IRUGO, ipl_##_name##_show, NULL);
684 DEFINE_IPL_ATTR(wwpn, "0x%016llx\n", (unsigned long long)
685 IPL_PARMBLOCK_START->fcp.wwpn);
686 DEFINE_IPL_ATTR(lun, "0x%016llx\n", (unsigned long long)
687 IPL_PARMBLOCK_START->fcp.lun);
688 DEFINE_IPL_ATTR(bootprog, "%lld\n", (unsigned long long)
689 IPL_PARMBLOCK_START->fcp.bootprog);
690 DEFINE_IPL_ATTR(br_lba, "%lld\n", (unsigned long long)
691 IPL_PARMBLOCK_START->fcp.br_lba);
699 static enum ipl_type_type
702 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
704 if (!IPL_DEVNO_VALID)
705 return ipl_type_unknown;
706 if (!IPL_PARMBLOCK_VALID)
708 if (ipl->hdr.header.version > IPL_MAX_SUPPORTED_VERSION)
709 return ipl_type_unknown;
710 if (ipl->fcp.pbt != IPL_TYPE_FCP)
711 return ipl_type_unknown;
716 ipl_type_show(struct subsystem *subsys, char *page)
718 switch (get_ipl_type()) {
720 return sprintf(page, "ccw\n");
722 return sprintf(page, "fcp\n");
724 return sprintf(page, "unknown\n");
728 static struct subsys_attribute ipl_type_attr = __ATTR_RO(ipl_type);
731 ipl_device_show(struct subsystem *subsys, char *page)
733 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
735 switch (get_ipl_type()) {
737 return sprintf(page, "0.0.%04x\n", ipl_devno);
739 return sprintf(page, "0.0.%04x\n", ipl->fcp.devno);
745 static struct subsys_attribute ipl_device_attr =
746 __ATTR(device, S_IRUGO, ipl_device_show, NULL);
748 static struct attribute *ipl_fcp_attrs[] = {
750 &ipl_device_attr.attr,
753 &ipl_bootprog_attr.attr,
754 &ipl_br_lba_attr.attr,
758 static struct attribute_group ipl_fcp_attr_group = {
759 .attrs = ipl_fcp_attrs,
762 static struct attribute *ipl_ccw_attrs[] = {
764 &ipl_device_attr.attr,
768 static struct attribute_group ipl_ccw_attr_group = {
769 .attrs = ipl_ccw_attrs,
772 static struct attribute *ipl_unknown_attrs[] = {
777 static struct attribute_group ipl_unknown_attr_group = {
778 .attrs = ipl_unknown_attrs,
782 ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
784 unsigned int size = IPL_PARMBLOCK_SIZE;
788 if (off + count > size)
791 memcpy(buf, (void *) IPL_PARMBLOCK_START + off, count);
795 static struct bin_attribute ipl_parameter_attr = {
797 .name = "binary_parameter",
799 .owner = THIS_MODULE,
802 .read = &ipl_parameter_read,
806 ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
808 unsigned int size = IPL_PARMBLOCK_START->fcp.scp_data_len;
809 void *scp_data = &IPL_PARMBLOCK_START->fcp.scp_data;
813 if (off + count > size)
816 memcpy(buf, scp_data + off, count);
820 static struct bin_attribute ipl_scp_data_attr = {
824 .owner = THIS_MODULE,
827 .read = &ipl_scp_data_read,
830 static decl_subsys(ipl, NULL, NULL);
833 ipl_device_sysfs_register(void) {
836 rc = firmware_register(&ipl_subsys);
840 switch (get_ipl_type()) {
842 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_ccw_attr_group);
845 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
846 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
847 &ipl_parameter_attr);
848 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
852 sysfs_create_group(&ipl_subsys.kset.kobj,
853 &ipl_unknown_attr_group);
859 __initcall(ipl_device_sysfs_register);