[S390] boot from NSS support
[linux-2.6/verdex.git] / arch / s390 / kernel / setup.c
blob2569aafcc5438a8a21989a24a537e2682f327f66
1 /*
2 * arch/s390/kernel/setup.c
4 * S390 version
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>
21 #include <linux/mm.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/ctype.h>
42 #include <linux/reboot.h>
44 #include <asm/uaccess.h>
45 #include <asm/system.h>
46 #include <asm/smp.h>
47 #include <asm/mmu_context.h>
48 #include <asm/cpcmd.h>
49 #include <asm/lowcore.h>
50 #include <asm/irq.h>
51 #include <asm/page.h>
52 #include <asm/ptrace.h>
53 #include <asm/sections.h>
54 #include <asm/ebcdic.h>
55 #include <asm/compat.h>
57 long psw_kernel_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_PRIMARY |
58 PSW_MASK_MCHECK | PSW_DEFAULT_KEY);
59 long psw_user_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
60 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
61 PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
64 * User copy operations.
66 struct uaccess_ops uaccess;
67 EXPORT_SYMBOL_GPL(uaccess);
70 * Machine setup..
72 unsigned int console_mode = 0;
73 unsigned int console_devno = -1;
74 unsigned int console_irq = -1;
75 unsigned long machine_flags = 0;
77 struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
78 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
79 static unsigned long __initdata memory_end;
82 * This is set up by the setup-routine at boot-time
83 * for S390 need to find out, what we have to setup
84 * using address 0x10400 ...
87 #include <asm/setup.h>
89 static struct resource code_resource = {
90 .name = "Kernel code",
91 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
94 static struct resource data_resource = {
95 .name = "Kernel data",
96 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
100 * cpu_init() initializes state that is per-CPU.
102 void __devinit cpu_init (void)
104 int addr = hard_smp_processor_id();
107 * Store processor id in lowcore (used e.g. in timer_interrupt)
109 asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
110 S390_lowcore.cpu_data.cpu_addr = addr;
113 * Force FPU initialization:
115 clear_thread_flag(TIF_USEDFPU);
116 clear_used_math();
118 atomic_inc(&init_mm.mm_count);
119 current->active_mm = &init_mm;
120 if (current->mm)
121 BUG();
122 enter_lazy_tlb(&init_mm, current);
126 * VM halt and poweroff setup routines
128 char vmhalt_cmd[128] = "";
129 char vmpoff_cmd[128] = "";
130 static char vmpanic_cmd[128] = "";
132 static inline void strncpy_skip_quote(char *dst, char *src, int n)
134 int sx, dx;
136 dx = 0;
137 for (sx = 0; src[sx] != 0; sx++) {
138 if (src[sx] == '"') continue;
139 dst[dx++] = src[sx];
140 if (dx >= n) break;
144 static int __init vmhalt_setup(char *str)
146 strncpy_skip_quote(vmhalt_cmd, str, 127);
147 vmhalt_cmd[127] = 0;
148 return 1;
151 __setup("vmhalt=", vmhalt_setup);
153 static int __init vmpoff_setup(char *str)
155 strncpy_skip_quote(vmpoff_cmd, str, 127);
156 vmpoff_cmd[127] = 0;
157 return 1;
160 __setup("vmpoff=", vmpoff_setup);
162 static int vmpanic_notify(struct notifier_block *self, unsigned long event,
163 void *data)
165 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
166 cpcmd(vmpanic_cmd, NULL, 0, NULL);
168 return NOTIFY_OK;
171 #define PANIC_PRI_VMPANIC 0
173 static struct notifier_block vmpanic_nb = {
174 .notifier_call = vmpanic_notify,
175 .priority = PANIC_PRI_VMPANIC
178 static int __init vmpanic_setup(char *str)
180 static int register_done __initdata = 0;
182 strncpy_skip_quote(vmpanic_cmd, str, 127);
183 vmpanic_cmd[127] = 0;
184 if (!register_done) {
185 register_done = 1;
186 atomic_notifier_chain_register(&panic_notifier_list,
187 &vmpanic_nb);
189 return 1;
192 __setup("vmpanic=", vmpanic_setup);
195 * condev= and conmode= setup parameter.
198 static int __init condev_setup(char *str)
200 int vdev;
202 vdev = simple_strtoul(str, &str, 0);
203 if (vdev >= 0 && vdev < 65536) {
204 console_devno = vdev;
205 console_irq = -1;
207 return 1;
210 __setup("condev=", condev_setup);
212 static int __init conmode_setup(char *str)
214 #if defined(CONFIG_SCLP_CONSOLE)
215 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
216 SET_CONSOLE_SCLP;
217 #endif
218 #if defined(CONFIG_TN3215_CONSOLE)
219 if (strncmp(str, "3215", 5) == 0)
220 SET_CONSOLE_3215;
221 #endif
222 #if defined(CONFIG_TN3270_CONSOLE)
223 if (strncmp(str, "3270", 5) == 0)
224 SET_CONSOLE_3270;
225 #endif
226 return 1;
229 __setup("conmode=", conmode_setup);
231 static void __init conmode_default(void)
233 char query_buffer[1024];
234 char *ptr;
236 if (MACHINE_IS_VM) {
237 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
238 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
239 ptr = strstr(query_buffer, "SUBCHANNEL =");
240 console_irq = simple_strtoul(ptr + 13, NULL, 16);
241 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
242 ptr = strstr(query_buffer, "CONMODE");
244 * Set the conmode to 3215 so that the device recognition
245 * will set the cu_type of the console to 3215. If the
246 * conmode is 3270 and we don't set it back then both
247 * 3215 and the 3270 driver will try to access the console
248 * device (3215 as console and 3270 as normal tty).
250 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
251 if (ptr == NULL) {
252 #if defined(CONFIG_SCLP_CONSOLE)
253 SET_CONSOLE_SCLP;
254 #endif
255 return;
257 if (strncmp(ptr + 8, "3270", 4) == 0) {
258 #if defined(CONFIG_TN3270_CONSOLE)
259 SET_CONSOLE_3270;
260 #elif defined(CONFIG_TN3215_CONSOLE)
261 SET_CONSOLE_3215;
262 #elif defined(CONFIG_SCLP_CONSOLE)
263 SET_CONSOLE_SCLP;
264 #endif
265 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
266 #if defined(CONFIG_TN3215_CONSOLE)
267 SET_CONSOLE_3215;
268 #elif defined(CONFIG_TN3270_CONSOLE)
269 SET_CONSOLE_3270;
270 #elif defined(CONFIG_SCLP_CONSOLE)
271 SET_CONSOLE_SCLP;
272 #endif
274 } else if (MACHINE_IS_P390) {
275 #if defined(CONFIG_TN3215_CONSOLE)
276 SET_CONSOLE_3215;
277 #elif defined(CONFIG_TN3270_CONSOLE)
278 SET_CONSOLE_3270;
279 #endif
280 } else {
281 #if defined(CONFIG_SCLP_CONSOLE)
282 SET_CONSOLE_SCLP;
283 #endif
288 * Create a Kernel NSS if the SAVESYS= parameter is defined
290 #define DEFSYS_CMD_SIZE 96
291 #define SAVESYS_CMD_SIZE 32
293 extern int _eshared;
294 char kernel_nss_name[NSS_NAME_SIZE + 1];
296 #ifdef CONFIG_SHARED_KERNEL
297 static __init void create_kernel_nss(void)
299 unsigned int i, stext_pfn, eshared_pfn, end_pfn, min_size;
300 #ifdef CONFIG_BLK_DEV_INITRD
301 unsigned int sinitrd_pfn, einitrd_pfn;
302 #endif
303 int response;
304 char *savesys_ptr;
305 char upper_command_line[COMMAND_LINE_SIZE];
306 char defsys_cmd[DEFSYS_CMD_SIZE];
307 char savesys_cmd[SAVESYS_CMD_SIZE];
309 /* Do nothing if we are not running under VM */
310 if (!MACHINE_IS_VM)
311 return;
313 /* Convert COMMAND_LINE to upper case */
314 for (i = 0; i < strlen(COMMAND_LINE); i++)
315 upper_command_line[i] = toupper(COMMAND_LINE[i]);
317 savesys_ptr = strstr(upper_command_line, "SAVESYS=");
319 if (!savesys_ptr)
320 return;
322 savesys_ptr += 8; /* Point to the beginning of the NSS name */
323 for (i = 0; i < NSS_NAME_SIZE; i++) {
324 if (savesys_ptr[i] == ' ' || savesys_ptr[i] == '\0')
325 break;
326 kernel_nss_name[i] = savesys_ptr[i];
329 stext_pfn = PFN_DOWN(__pa(&_stext));
330 eshared_pfn = PFN_DOWN(__pa(&_eshared));
331 end_pfn = PFN_UP(__pa(&_end));
332 min_size = end_pfn << 2;
334 sprintf(defsys_cmd, "DEFSYS %s 00000-%.5X EW %.5X-%.5X SR %.5X-%.5X",
335 kernel_nss_name, stext_pfn - 1, stext_pfn, eshared_pfn - 1,
336 eshared_pfn, end_pfn);
338 #ifdef CONFIG_BLK_DEV_INITRD
339 if (INITRD_START && INITRD_SIZE) {
340 sinitrd_pfn = PFN_DOWN(__pa(INITRD_START));
341 einitrd_pfn = PFN_UP(__pa(INITRD_START + INITRD_SIZE));
342 min_size = einitrd_pfn << 2;
343 sprintf(defsys_cmd, "%s EW %.5X-%.5X", defsys_cmd,
344 sinitrd_pfn, einitrd_pfn);
346 #endif
348 sprintf(defsys_cmd, "%s EW MINSIZE=%.7iK", defsys_cmd, min_size);
349 sprintf(savesys_cmd, "SAVESYS %s \n IPL %s",
350 kernel_nss_name, kernel_nss_name);
352 __cpcmd(defsys_cmd, NULL, 0, &response);
354 if (response != 0)
355 return;
357 __cpcmd(savesys_cmd, NULL, 0, &response);
359 if (response != strlen(savesys_cmd))
360 return;
362 ipl_flags = IPL_NSS_VALID;
365 #else /* CONFIG_SHARED_KERNEL */
367 static inline void create_kernel_nss(void) { }
369 #endif /* CONFIG_SHARED_KERNEL */
372 * Clear bss memory
374 static __init void clear_bss_section(void)
376 memset(__bss_start, 0, _end - __bss_start);
380 * Initialize storage key for kernel pages
382 static __init void init_kernel_storage_key(void)
384 unsigned long end_pfn, init_pfn;
386 end_pfn = PFN_UP(__pa(&_end));
388 for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
389 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
392 static __init void detect_machine_type(void)
394 struct cpuinfo_S390 *cpuinfo = &S390_lowcore.cpu_data;
396 asm volatile("stidp %0" : "=m" (S390_lowcore.cpu_data.cpu_id));
398 /* Running under z/VM ? */
399 if (cpuinfo->cpu_id.version == 0xff)
400 machine_flags |= 1;
402 /* Running on a P/390 ? */
403 if (cpuinfo->cpu_id.machine == 0x7490)
404 machine_flags |= 4;
408 * Save ipl parameters, clear bss memory, initialize storage keys
409 * and create a kernel NSS at startup if the SAVESYS= parm is defined
411 void __init startup_init(void)
413 ipl_save_parameters();
414 clear_bss_section();
415 init_kernel_storage_key();
416 lockdep_init();
417 detect_machine_type();
418 create_kernel_nss();
421 #ifdef CONFIG_SMP
422 void (*_machine_restart)(char *command) = machine_restart_smp;
423 void (*_machine_halt)(void) = machine_halt_smp;
424 void (*_machine_power_off)(void) = machine_power_off_smp;
425 #else
427 * Reboot, halt and power_off routines for non SMP.
429 static void do_machine_restart_nonsmp(char * __unused)
431 do_reipl();
434 static void do_machine_halt_nonsmp(void)
436 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
437 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
438 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
441 static void do_machine_power_off_nonsmp(void)
443 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
444 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
445 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
448 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
449 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
450 void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
451 #endif
454 * Reboot, halt and power_off stubs. They just call _machine_restart,
455 * _machine_halt or _machine_power_off.
458 void machine_restart(char *command)
460 if (!in_interrupt() || oops_in_progress)
462 * Only unblank the console if we are called in enabled
463 * context or a bust_spinlocks cleared the way for us.
465 console_unblank();
466 _machine_restart(command);
469 void machine_halt(void)
471 if (!in_interrupt() || oops_in_progress)
473 * Only unblank the console if we are called in enabled
474 * context or a bust_spinlocks cleared the way for us.
476 console_unblank();
477 _machine_halt();
480 void machine_power_off(void)
482 if (!in_interrupt() || oops_in_progress)
484 * Only unblank the console if we are called in enabled
485 * context or a bust_spinlocks cleared the way for us.
487 console_unblank();
488 _machine_power_off();
492 * Dummy power off function.
494 void (*pm_power_off)(void) = machine_power_off;
496 static int __init early_parse_mem(char *p)
498 memory_end = memparse(p, &p);
499 return 0;
501 early_param("mem", early_parse_mem);
504 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
506 static int __init early_parse_ipldelay(char *p)
508 unsigned long delay = 0;
510 delay = simple_strtoul(p, &p, 0);
512 switch (*p) {
513 case 's':
514 case 'S':
515 delay *= 1000000;
516 break;
517 case 'm':
518 case 'M':
519 delay *= 60 * 1000000;
522 /* now wait for the requested amount of time */
523 udelay(delay);
525 return 0;
527 early_param("ipldelay", early_parse_ipldelay);
529 #ifdef CONFIG_S390_SWITCH_AMODE
530 unsigned int switch_amode = 0;
531 EXPORT_SYMBOL_GPL(switch_amode);
533 static inline void set_amode_and_uaccess(unsigned long user_amode,
534 unsigned long user32_amode)
536 psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode |
537 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
538 PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
539 #ifdef CONFIG_COMPAT
540 psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode |
541 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
542 PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
543 psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode |
544 PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
545 PSW32_MASK_PSTATE;
546 #endif
547 psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
548 PSW_MASK_MCHECK | PSW_DEFAULT_KEY;
550 if (MACHINE_HAS_MVCOS) {
551 printk("mvcos available.\n");
552 memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
553 } else {
554 printk("mvcos not available.\n");
555 memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
560 * Switch kernel/user addressing modes?
562 static int __init early_parse_switch_amode(char *p)
564 switch_amode = 1;
565 return 0;
567 early_param("switch_amode", early_parse_switch_amode);
569 #else /* CONFIG_S390_SWITCH_AMODE */
570 static inline void set_amode_and_uaccess(unsigned long user_amode,
571 unsigned long user32_amode)
574 #endif /* CONFIG_S390_SWITCH_AMODE */
576 #ifdef CONFIG_S390_EXEC_PROTECT
577 unsigned int s390_noexec = 0;
578 EXPORT_SYMBOL_GPL(s390_noexec);
581 * Enable execute protection?
583 static int __init early_parse_noexec(char *p)
585 if (!strncmp(p, "off", 3))
586 return 0;
587 switch_amode = 1;
588 s390_noexec = 1;
589 return 0;
591 early_param("noexec", early_parse_noexec);
592 #endif /* CONFIG_S390_EXEC_PROTECT */
594 static void setup_addressing_mode(void)
596 if (s390_noexec) {
597 printk("S390 execute protection active, ");
598 set_amode_and_uaccess(PSW_ASC_SECONDARY, PSW32_ASC_SECONDARY);
599 return;
601 if (switch_amode) {
602 printk("S390 address spaces switched, ");
603 set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY);
607 static void __init
608 setup_lowcore(void)
610 struct _lowcore *lc;
611 int lc_pages;
614 * Setup lowcore for boot cpu
616 lc_pages = sizeof(void *) == 8 ? 2 : 1;
617 lc = (struct _lowcore *)
618 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
619 memset(lc, 0, lc_pages * PAGE_SIZE);
620 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
621 lc->restart_psw.addr =
622 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
623 if (switch_amode)
624 lc->restart_psw.mask |= PSW_ASC_HOME;
625 lc->external_new_psw.mask = psw_kernel_bits;
626 lc->external_new_psw.addr =
627 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
628 lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
629 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
630 lc->program_new_psw.mask = psw_kernel_bits;
631 lc->program_new_psw.addr =
632 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
633 lc->mcck_new_psw.mask =
634 psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
635 lc->mcck_new_psw.addr =
636 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
637 lc->io_new_psw.mask = psw_kernel_bits;
638 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
639 lc->ipl_device = S390_lowcore.ipl_device;
640 lc->jiffy_timer = -1LL;
641 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
642 lc->async_stack = (unsigned long)
643 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
644 lc->panic_stack = (unsigned long)
645 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
646 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
647 lc->thread_info = (unsigned long) &init_thread_union;
648 #ifndef CONFIG_64BIT
649 if (MACHINE_HAS_IEEE) {
650 lc->extended_save_area_addr = (__u32)
651 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
652 /* enable extended save area */
653 __ctl_set_bit(14, 29);
655 #endif
656 set_prefix((u32)(unsigned long) lc);
659 static void __init
660 setup_resources(void)
662 struct resource *res, *sub_res;
663 int i;
665 code_resource.start = (unsigned long) &_text;
666 code_resource.end = (unsigned long) &_etext - 1;
667 data_resource.start = (unsigned long) &_etext;
668 data_resource.end = (unsigned long) &_edata - 1;
670 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
671 res = alloc_bootmem_low(sizeof(struct resource));
672 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
673 switch (memory_chunk[i].type) {
674 case CHUNK_READ_WRITE:
675 res->name = "System RAM";
676 break;
677 case CHUNK_READ_ONLY:
678 res->name = "System ROM";
679 res->flags |= IORESOURCE_READONLY;
680 break;
681 default:
682 res->name = "reserved";
684 res->start = memory_chunk[i].addr;
685 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
686 request_resource(&iomem_resource, res);
688 if (code_resource.start >= res->start &&
689 code_resource.start <= res->end &&
690 code_resource.end > res->end) {
691 sub_res = alloc_bootmem_low(sizeof(struct resource));
692 memcpy(sub_res, &code_resource,
693 sizeof(struct resource));
694 sub_res->end = res->end;
695 code_resource.start = res->end + 1;
696 request_resource(res, sub_res);
699 if (code_resource.start >= res->start &&
700 code_resource.start <= res->end &&
701 code_resource.end <= res->end)
702 request_resource(res, &code_resource);
704 if (data_resource.start >= res->start &&
705 data_resource.start <= res->end &&
706 data_resource.end > res->end) {
707 sub_res = alloc_bootmem_low(sizeof(struct resource));
708 memcpy(sub_res, &data_resource,
709 sizeof(struct resource));
710 sub_res->end = res->end;
711 data_resource.start = res->end + 1;
712 request_resource(res, sub_res);
715 if (data_resource.start >= res->start &&
716 data_resource.start <= res->end &&
717 data_resource.end <= res->end)
718 request_resource(res, &data_resource);
722 static void __init setup_memory_end(void)
724 unsigned long real_size, memory_size;
725 unsigned long max_mem, max_phys;
726 int i;
728 memory_size = real_size = 0;
729 max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
730 memory_end &= PAGE_MASK;
732 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
734 for (i = 0; i < MEMORY_CHUNKS; i++) {
735 struct mem_chunk *chunk = &memory_chunk[i];
737 real_size = max(real_size, chunk->addr + chunk->size);
738 if (chunk->addr >= max_mem) {
739 memset(chunk, 0, sizeof(*chunk));
740 continue;
742 if (chunk->addr + chunk->size > max_mem)
743 chunk->size = max_mem - chunk->addr;
744 memory_size = max(memory_size, chunk->addr + chunk->size);
746 if (!memory_end)
747 memory_end = memory_size;
750 static void __init
751 setup_memory(void)
753 unsigned long bootmap_size;
754 unsigned long start_pfn, end_pfn;
755 int i;
758 * partially used pages are not usable - thus
759 * we are rounding upwards:
761 start_pfn = PFN_UP(__pa(&_end));
762 end_pfn = max_pfn = PFN_DOWN(memory_end);
764 #ifdef CONFIG_BLK_DEV_INITRD
766 * Move the initrd in case the bitmap of the bootmem allocater
767 * would overwrite it.
770 if (INITRD_START && INITRD_SIZE) {
771 unsigned long bmap_size;
772 unsigned long start;
774 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
775 bmap_size = PFN_PHYS(bmap_size);
777 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
778 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
780 if (start + INITRD_SIZE > memory_end) {
781 printk("initrd extends beyond end of memory "
782 "(0x%08lx > 0x%08lx)\n"
783 "disabling initrd\n",
784 start + INITRD_SIZE, memory_end);
785 INITRD_START = INITRD_SIZE = 0;
786 } else {
787 printk("Moving initrd (0x%08lx -> 0x%08lx, "
788 "size: %ld)\n",
789 INITRD_START, start, INITRD_SIZE);
790 memmove((void *) start, (void *) INITRD_START,
791 INITRD_SIZE);
792 INITRD_START = start;
796 #endif
799 * Initialize the boot-time allocator
801 bootmap_size = init_bootmem(start_pfn, end_pfn);
804 * Register RAM areas with the bootmem allocator.
807 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
808 unsigned long start_chunk, end_chunk, pfn;
810 if (memory_chunk[i].type != CHUNK_READ_WRITE)
811 continue;
812 start_chunk = PFN_DOWN(memory_chunk[i].addr);
813 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
814 end_chunk = min(end_chunk, end_pfn);
815 if (start_chunk >= end_chunk)
816 continue;
817 add_active_range(0, start_chunk, end_chunk);
818 pfn = max(start_chunk, start_pfn);
819 for (; pfn <= end_chunk; pfn++)
820 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
823 psw_set_key(PAGE_DEFAULT_KEY);
825 free_bootmem_with_active_regions(0, max_pfn);
826 reserve_bootmem(0, PFN_PHYS(start_pfn));
829 * Reserve the bootmem bitmap itself as well. We do this in two
830 * steps (first step was init_bootmem()) because this catches
831 * the (very unlikely) case of us accidentally initializing the
832 * bootmem allocator with an invalid RAM area.
834 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
836 #ifdef CONFIG_BLK_DEV_INITRD
837 if (INITRD_START && INITRD_SIZE) {
838 if (INITRD_START + INITRD_SIZE <= memory_end) {
839 reserve_bootmem(INITRD_START, INITRD_SIZE);
840 initrd_start = INITRD_START;
841 initrd_end = initrd_start + INITRD_SIZE;
842 } else {
843 printk("initrd extends beyond end of memory "
844 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
845 initrd_start + INITRD_SIZE, memory_end);
846 initrd_start = initrd_end = 0;
849 #endif
853 * Setup function called from init/main.c just after the banner
854 * was printed.
857 void __init
858 setup_arch(char **cmdline_p)
861 * print what head.S has found out about the machine
863 #ifndef CONFIG_64BIT
864 printk((MACHINE_IS_VM) ?
865 "We are running under VM (31 bit mode)\n" :
866 "We are running native (31 bit mode)\n");
867 printk((MACHINE_HAS_IEEE) ?
868 "This machine has an IEEE fpu\n" :
869 "This machine has no IEEE fpu\n");
870 #else /* CONFIG_64BIT */
871 printk((MACHINE_IS_VM) ?
872 "We are running under VM (64 bit mode)\n" :
873 "We are running native (64 bit mode)\n");
874 #endif /* CONFIG_64BIT */
876 /* Save unparsed command line copy for /proc/cmdline */
877 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
879 *cmdline_p = COMMAND_LINE;
880 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
882 ROOT_DEV = Root_RAM0;
884 init_mm.start_code = PAGE_OFFSET;
885 init_mm.end_code = (unsigned long) &_etext;
886 init_mm.end_data = (unsigned long) &_edata;
887 init_mm.brk = (unsigned long) &_end;
889 if (MACHINE_HAS_MVCOS)
890 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
891 else
892 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
894 parse_early_param();
896 setup_memory_end();
897 setup_addressing_mode();
898 setup_memory();
899 setup_resources();
900 setup_lowcore();
902 cpu_init();
903 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
904 smp_setup_cpu_possible_map();
907 * Create kernel page tables and switch to virtual addressing.
909 paging_init();
911 /* Setup default console */
912 conmode_default();
915 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
917 printk("cpu %d "
918 #ifdef CONFIG_SMP
919 "phys_idx=%d "
920 #endif
921 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
922 cpuinfo->cpu_nr,
923 #ifdef CONFIG_SMP
924 cpuinfo->cpu_addr,
925 #endif
926 cpuinfo->cpu_id.version,
927 cpuinfo->cpu_id.ident,
928 cpuinfo->cpu_id.machine,
929 cpuinfo->cpu_id.unused);
933 * show_cpuinfo - Get information on one CPU for use by procfs.
936 static int show_cpuinfo(struct seq_file *m, void *v)
938 struct cpuinfo_S390 *cpuinfo;
939 unsigned long n = (unsigned long) v - 1;
941 preempt_disable();
942 if (!n) {
943 seq_printf(m, "vendor_id : IBM/S390\n"
944 "# processors : %i\n"
945 "bogomips per cpu: %lu.%02lu\n",
946 num_online_cpus(), loops_per_jiffy/(500000/HZ),
947 (loops_per_jiffy/(5000/HZ))%100);
949 if (cpu_online(n)) {
950 #ifdef CONFIG_SMP
951 if (smp_processor_id() == n)
952 cpuinfo = &S390_lowcore.cpu_data;
953 else
954 cpuinfo = &lowcore_ptr[n]->cpu_data;
955 #else
956 cpuinfo = &S390_lowcore.cpu_data;
957 #endif
958 seq_printf(m, "processor %li: "
959 "version = %02X, "
960 "identification = %06X, "
961 "machine = %04X\n",
962 n, cpuinfo->cpu_id.version,
963 cpuinfo->cpu_id.ident,
964 cpuinfo->cpu_id.machine);
966 preempt_enable();
967 return 0;
970 static void *c_start(struct seq_file *m, loff_t *pos)
972 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
974 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
976 ++*pos;
977 return c_start(m, pos);
979 static void c_stop(struct seq_file *m, void *v)
982 struct seq_operations cpuinfo_op = {
983 .start = c_start,
984 .next = c_next,
985 .stop = c_stop,
986 .show = show_cpuinfo,