blob: 3dfd0985861c339f327c609804c1487627168b65 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/setup.c
3 *
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)
8 *
9 * Derived from "arch/i386/kernel/setup.c"
10 * Copyright (C) 1995, Linus Torvalds
11 */
12
13/*
14 * This file handles the architecture-dependent parts of initialization
15 */
16
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#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>
Heiko Carstens1e8e3382005-10-30 15:00:11 -080038#include <linux/device.h>
Peter Oberparleiter585c3042006-06-29 15:08:25 +020039#include <linux/notifier.h>
Heiko Carstens65912a82006-09-20 15:58:41 +020040#include <linux/pfn.h>
Hongjie Yangfe355b72007-02-05 21:18:24 +010041#include <linux/ctype.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010042#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Michael Holzheu46b05d22007-02-21 10:55:21 +010044#include <asm/ipl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/uaccess.h>
46#include <asm/system.h>
47#include <asm/smp.h>
48#include <asm/mmu_context.h>
49#include <asm/cpcmd.h>
50#include <asm/lowcore.h>
51#include <asm/irq.h>
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070052#include <asm/page.h>
53#include <asm/ptrace.h>
Heiko Carstenscc13ad62006-06-25 05:49:30 -070054#include <asm/sections.h>
Hongjie Yangfe355b72007-02-05 21:18:24 +010055#include <asm/ebcdic.h>
Gerald Schaeferc1821c22007-02-05 21:18:17 +010056#include <asm/compat.h>
57
58long psw_kernel_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_PRIMARY |
59 PSW_MASK_MCHECK | PSW_DEFAULT_KEY);
60long psw_user_bits = (PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
61 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
62 PSW_MASK_PSTATE | PSW_DEFAULT_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64/*
Gerald Schaeferd02765d2006-09-20 15:59:42 +020065 * User copy operations.
66 */
67struct uaccess_ops uaccess;
68EXPORT_SYMBOL_GPL(uaccess);
69
70/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * Machine setup..
72 */
73unsigned int console_mode = 0;
74unsigned int console_devno = -1;
75unsigned int console_irq = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076unsigned long machine_flags = 0;
Heiko Carstens36a2bd42006-12-04 15:40:38 +010077
Heiko Carstensf4eb07c2006-12-08 15:56:07 +010078struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070079volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070080static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 * This is set up by the setup-routine at boot-time
84 * for S390 need to find out, what we have to setup
85 * using address 0x10400 ...
86 */
87
88#include <asm/setup.h>
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static struct resource code_resource = {
91 .name = "Kernel code",
92 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
93};
94
95static struct resource data_resource = {
96 .name = "Kernel data",
97 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
98};
99
100/*
101 * cpu_init() initializes state that is per-CPU.
102 */
103void __devinit cpu_init (void)
104{
105 int addr = hard_smp_processor_id();
106
107 /*
108 * Store processor id in lowcore (used e.g. in timer_interrupt)
109 */
Michael Holzheu72960a02007-02-21 10:55:18 +0100110 get_cpu_id(&S390_lowcore.cpu_data.cpu_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 S390_lowcore.cpu_data.cpu_addr = addr;
112
113 /*
114 * Force FPU initialization:
115 */
116 clear_thread_flag(TIF_USEDFPU);
117 clear_used_math();
118
119 atomic_inc(&init_mm.mm_count);
120 current->active_mm = &init_mm;
121 if (current->mm)
122 BUG();
123 enter_lazy_tlb(&init_mm, current);
124}
125
126/*
127 * VM halt and poweroff setup routines
128 */
129char vmhalt_cmd[128] = "";
130char vmpoff_cmd[128] = "";
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100131static char vmpanic_cmd[128] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100133static void strncpy_skip_quote(char *dst, char *src, int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 int sx, dx;
136
137 dx = 0;
138 for (sx = 0; src[sx] != 0; sx++) {
139 if (src[sx] == '"') continue;
140 dst[dx++] = src[sx];
141 if (dx >= n) break;
142 }
143}
144
145static int __init vmhalt_setup(char *str)
146{
147 strncpy_skip_quote(vmhalt_cmd, str, 127);
148 vmhalt_cmd[127] = 0;
149 return 1;
150}
151
152__setup("vmhalt=", vmhalt_setup);
153
154static int __init vmpoff_setup(char *str)
155{
156 strncpy_skip_quote(vmpoff_cmd, str, 127);
157 vmpoff_cmd[127] = 0;
158 return 1;
159}
160
161__setup("vmpoff=", vmpoff_setup);
162
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200163static int vmpanic_notify(struct notifier_block *self, unsigned long event,
164 void *data)
165{
166 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
167 cpcmd(vmpanic_cmd, NULL, 0, NULL);
168
169 return NOTIFY_OK;
170}
171
172#define PANIC_PRI_VMPANIC 0
173
174static struct notifier_block vmpanic_nb = {
175 .notifier_call = vmpanic_notify,
176 .priority = PANIC_PRI_VMPANIC
177};
178
179static int __init vmpanic_setup(char *str)
180{
181 static int register_done __initdata = 0;
182
183 strncpy_skip_quote(vmpanic_cmd, str, 127);
184 vmpanic_cmd[127] = 0;
185 if (!register_done) {
186 register_done = 1;
187 atomic_notifier_chain_register(&panic_notifier_list,
188 &vmpanic_nb);
189 }
190 return 1;
191}
192
193__setup("vmpanic=", vmpanic_setup);
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195/*
196 * condev= and conmode= setup parameter.
197 */
198
199static int __init condev_setup(char *str)
200{
201 int vdev;
202
203 vdev = simple_strtoul(str, &str, 0);
204 if (vdev >= 0 && vdev < 65536) {
205 console_devno = vdev;
206 console_irq = -1;
207 }
208 return 1;
209}
210
211__setup("condev=", condev_setup);
212
213static int __init conmode_setup(char *str)
214{
215#if defined(CONFIG_SCLP_CONSOLE)
216 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
217 SET_CONSOLE_SCLP;
218#endif
219#if defined(CONFIG_TN3215_CONSOLE)
220 if (strncmp(str, "3215", 5) == 0)
221 SET_CONSOLE_3215;
222#endif
223#if defined(CONFIG_TN3270_CONSOLE)
224 if (strncmp(str, "3270", 5) == 0)
225 SET_CONSOLE_3270;
226#endif
227 return 1;
228}
229
230__setup("conmode=", conmode_setup);
231
232static void __init conmode_default(void)
233{
234 char query_buffer[1024];
235 char *ptr;
236
237 if (MACHINE_IS_VM) {
Heiko Carstens740b5702006-12-04 15:40:30 +0100238 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
240 ptr = strstr(query_buffer, "SUBCHANNEL =");
241 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Heiko Carstens740b5702006-12-04 15:40:30 +0100242 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 ptr = strstr(query_buffer, "CONMODE");
244 /*
245 * Set the conmode to 3215 so that the device recognition
246 * will set the cu_type of the console to 3215. If the
247 * conmode is 3270 and we don't set it back then both
248 * 3215 and the 3270 driver will try to access the console
249 * device (3215 as console and 3270 as normal tty).
250 */
Heiko Carstens740b5702006-12-04 15:40:30 +0100251 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if (ptr == NULL) {
253#if defined(CONFIG_SCLP_CONSOLE)
254 SET_CONSOLE_SCLP;
255#endif
256 return;
257 }
258 if (strncmp(ptr + 8, "3270", 4) == 0) {
259#if defined(CONFIG_TN3270_CONSOLE)
260 SET_CONSOLE_3270;
261#elif defined(CONFIG_TN3215_CONSOLE)
262 SET_CONSOLE_3215;
263#elif defined(CONFIG_SCLP_CONSOLE)
264 SET_CONSOLE_SCLP;
265#endif
266 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
267#if defined(CONFIG_TN3215_CONSOLE)
268 SET_CONSOLE_3215;
269#elif defined(CONFIG_TN3270_CONSOLE)
270 SET_CONSOLE_3270;
271#elif defined(CONFIG_SCLP_CONSOLE)
272 SET_CONSOLE_SCLP;
273#endif
274 }
275 } else if (MACHINE_IS_P390) {
276#if defined(CONFIG_TN3215_CONSOLE)
277 SET_CONSOLE_3215;
278#elif defined(CONFIG_TN3270_CONSOLE)
279 SET_CONSOLE_3270;
280#endif
281 } else {
282#if defined(CONFIG_SCLP_CONSOLE)
283 SET_CONSOLE_SCLP;
284#endif
285 }
286}
287
Michael Holzheu411ed322007-04-27 16:01:49 +0200288#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
289static void __init setup_zfcpdump(unsigned int console_devno)
290{
291 static char str[64];
292
293 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
294 return;
295 if (console_devno != -1)
296 sprintf(str, "cio_ignore=all,!0.0.%04x,!0.0.%04x",
297 ipl_info.data.fcp.dev_id.devno, console_devno);
298 else
299 sprintf(str, "cio_ignore=all,!0.0.%04x",
300 ipl_info.data.fcp.dev_id.devno);
301 strcat(COMMAND_LINE, str);
302 console_loglevel = 2;
303}
304#else
305static inline void setup_zfcpdump(unsigned int console_devno) {}
306#endif /* CONFIG_ZFCPDUMP */
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309void (*_machine_restart)(char *command) = machine_restart_smp;
310void (*_machine_halt)(void) = machine_halt_smp;
311void (*_machine_power_off)(void) = machine_power_off_smp;
312#else
313/*
314 * Reboot, halt and power_off routines for non SMP.
315 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316static void do_machine_restart_nonsmp(char * __unused)
317{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200318 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
321static void do_machine_halt_nonsmp(void)
322{
323 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100324 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
326}
327
328static void do_machine_power_off_nonsmp(void)
329{
330 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100331 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
333}
334
335void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
336void (*_machine_halt)(void) = do_machine_halt_nonsmp;
337void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
338#endif
339
340 /*
341 * Reboot, halt and power_off stubs. They just call _machine_restart,
342 * _machine_halt or _machine_power_off.
343 */
344
345void machine_restart(char *command)
346{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200347 if (!in_interrupt() || oops_in_progress)
348 /*
349 * Only unblank the console if we are called in enabled
350 * context or a bust_spinlocks cleared the way for us.
351 */
352 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 _machine_restart(command);
354}
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356void machine_halt(void)
357{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200358 if (!in_interrupt() || oops_in_progress)
359 /*
360 * Only unblank the console if we are called in enabled
361 * context or a bust_spinlocks cleared the way for us.
362 */
363 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 _machine_halt();
365}
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367void machine_power_off(void)
368{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200369 if (!in_interrupt() || oops_in_progress)
370 /*
371 * Only unblank the console if we are called in enabled
372 * context or a bust_spinlocks cleared the way for us.
373 */
374 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 _machine_power_off();
376}
377
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800378/*
379 * Dummy power off function.
380 */
381void (*pm_power_off)(void) = machine_power_off;
382
Heiko Carstens59685292006-03-24 03:15:15 -0800383static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700384{
Heiko Carstens59685292006-03-24 03:15:15 -0800385 memory_end = memparse(p, &p);
386 return 0;
387}
388early_param("mem", early_parse_mem);
389
390/*
391 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
392 */
393static int __init early_parse_ipldelay(char *p)
394{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700395 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Heiko Carstens59685292006-03-24 03:15:15 -0800397 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Heiko Carstens59685292006-03-24 03:15:15 -0800399 switch (*p) {
400 case 's':
401 case 'S':
402 delay *= 1000000;
403 break;
404 case 'm':
405 case 'M':
406 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
Heiko Carstens59685292006-03-24 03:15:15 -0800408
409 /* now wait for the requested amount of time */
410 udelay(delay);
411
412 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700413}
Heiko Carstens59685292006-03-24 03:15:15 -0800414early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100416#ifdef CONFIG_S390_SWITCH_AMODE
417unsigned int switch_amode = 0;
418EXPORT_SYMBOL_GPL(switch_amode);
419
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100420static void set_amode_and_uaccess(unsigned long user_amode,
421 unsigned long user32_amode)
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100422{
423 psw_user_bits = PSW_BASE_BITS | PSW_MASK_DAT | user_amode |
424 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
425 PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
426#ifdef CONFIG_COMPAT
427 psw_user32_bits = PSW_BASE32_BITS | PSW_MASK_DAT | user_amode |
428 PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK |
429 PSW_MASK_PSTATE | PSW_DEFAULT_KEY;
430 psw32_user_bits = PSW32_BASE_BITS | PSW32_MASK_DAT | user32_amode |
431 PSW32_MASK_IO | PSW32_MASK_EXT | PSW32_MASK_MCHECK |
432 PSW32_MASK_PSTATE;
433#endif
434 psw_kernel_bits = PSW_BASE_BITS | PSW_MASK_DAT | PSW_ASC_HOME |
435 PSW_MASK_MCHECK | PSW_DEFAULT_KEY;
436
437 if (MACHINE_HAS_MVCOS) {
438 printk("mvcos available.\n");
439 memcpy(&uaccess, &uaccess_mvcos_switch, sizeof(uaccess));
440 } else {
441 printk("mvcos not available.\n");
442 memcpy(&uaccess, &uaccess_pt, sizeof(uaccess));
443 }
444}
445
446/*
447 * Switch kernel/user addressing modes?
448 */
449static int __init early_parse_switch_amode(char *p)
450{
451 switch_amode = 1;
452 return 0;
453}
454early_param("switch_amode", early_parse_switch_amode);
455
456#else /* CONFIG_S390_SWITCH_AMODE */
457static inline void set_amode_and_uaccess(unsigned long user_amode,
458 unsigned long user32_amode)
459{
460}
461#endif /* CONFIG_S390_SWITCH_AMODE */
462
463#ifdef CONFIG_S390_EXEC_PROTECT
464unsigned int s390_noexec = 0;
465EXPORT_SYMBOL_GPL(s390_noexec);
466
467/*
468 * Enable execute protection?
469 */
470static int __init early_parse_noexec(char *p)
471{
472 if (!strncmp(p, "off", 3))
473 return 0;
474 switch_amode = 1;
475 s390_noexec = 1;
476 return 0;
477}
478early_param("noexec", early_parse_noexec);
479#endif /* CONFIG_S390_EXEC_PROTECT */
480
481static void setup_addressing_mode(void)
482{
483 if (s390_noexec) {
484 printk("S390 execute protection active, ");
485 set_amode_and_uaccess(PSW_ASC_SECONDARY, PSW32_ASC_SECONDARY);
486 return;
487 }
488 if (switch_amode) {
489 printk("S390 address spaces switched, ");
490 set_amode_and_uaccess(PSW_ASC_PRIMARY, PSW32_ASC_PRIMARY);
491 }
492}
493
Heiko Carstensc9e37352005-05-01 08:58:57 -0700494static void __init
495setup_lowcore(void)
496{
497 struct _lowcore *lc;
498 int lc_pages;
499
500 /*
501 * Setup lowcore for boot cpu
502 */
503 lc_pages = sizeof(void *) == 8 ? 2 : 1;
504 lc = (struct _lowcore *)
505 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
506 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700507 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 lc->restart_psw.addr =
509 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100510 if (switch_amode)
511 lc->restart_psw.mask |= PSW_ASC_HOME;
512 lc->external_new_psw.mask = psw_kernel_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 lc->external_new_psw.addr =
514 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100515 lc->svc_new_psw.mask = psw_kernel_bits | PSW_MASK_IO | PSW_MASK_EXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100517 lc->program_new_psw.mask = psw_kernel_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 lc->program_new_psw.addr =
519 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700520 lc->mcck_new_psw.mask =
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100521 psw_kernel_bits & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 lc->mcck_new_psw.addr =
523 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100524 lc->io_new_psw.mask = psw_kernel_bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
526 lc->ipl_device = S390_lowcore.ipl_device;
527 lc->jiffy_timer = -1LL;
528 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
529 lc->async_stack = (unsigned long)
530 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 lc->panic_stack = (unsigned long)
532 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
534 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800535#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700536 if (MACHINE_HAS_IEEE) {
537 lc->extended_save_area_addr = (__u32)
538 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
539 /* enable extended save area */
Heiko Carstensc4972f32006-11-06 10:49:02 +0100540 __ctl_set_bit(14, 29);
Heiko Carstens77fa2242005-06-25 14:55:30 -0700541 }
542#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700544}
545
546static void __init
547setup_resources(void)
548{
Hongjie Yangfe355b72007-02-05 21:18:24 +0100549 struct resource *res, *sub_res;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700550 int i;
551
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700552 code_resource.start = (unsigned long) &_text;
553 code_resource.end = (unsigned long) &_etext - 1;
554 data_resource.start = (unsigned long) &_etext;
555 data_resource.end = (unsigned long) &_edata - 1;
556
Heiko Carstensc9e37352005-05-01 08:58:57 -0700557 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
558 res = alloc_bootmem_low(sizeof(struct resource));
559 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
560 switch (memory_chunk[i].type) {
561 case CHUNK_READ_WRITE:
562 res->name = "System RAM";
563 break;
564 case CHUNK_READ_ONLY:
565 res->name = "System ROM";
566 res->flags |= IORESOURCE_READONLY;
567 break;
568 default:
569 res->name = "reserved";
570 }
571 res->start = memory_chunk[i].addr;
572 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
573 request_resource(&iomem_resource, res);
Hongjie Yangfe355b72007-02-05 21:18:24 +0100574
575 if (code_resource.start >= res->start &&
576 code_resource.start <= res->end &&
577 code_resource.end > res->end) {
578 sub_res = alloc_bootmem_low(sizeof(struct resource));
579 memcpy(sub_res, &code_resource,
580 sizeof(struct resource));
581 sub_res->end = res->end;
582 code_resource.start = res->end + 1;
583 request_resource(res, sub_res);
584 }
585
586 if (code_resource.start >= res->start &&
587 code_resource.start <= res->end &&
588 code_resource.end <= res->end)
589 request_resource(res, &code_resource);
590
591 if (data_resource.start >= res->start &&
592 data_resource.start <= res->end &&
593 data_resource.end > res->end) {
594 sub_res = alloc_bootmem_low(sizeof(struct resource));
595 memcpy(sub_res, &data_resource,
596 sizeof(struct resource));
597 sub_res->end = res->end;
598 data_resource.start = res->end + 1;
599 request_resource(res, sub_res);
600 }
601
602 if (data_resource.start >= res->start &&
603 data_resource.start <= res->end &&
604 data_resource.end <= res->end)
605 request_resource(res, &data_resource);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700606 }
607}
608
Michael Holzheu411ed322007-04-27 16:01:49 +0200609unsigned long real_memory_size;
610EXPORT_SYMBOL_GPL(real_memory_size);
611
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100612static void __init setup_memory_end(void)
613{
Michael Holzheu411ed322007-04-27 16:01:49 +0200614 unsigned long memory_size;
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100615 unsigned long max_mem, max_phys;
616 int i;
617
Michael Holzheu411ed322007-04-27 16:01:49 +0200618#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
619 if (ipl_info.type == IPL_TYPE_FCP_DUMP)
620 memory_end = ZFCPDUMP_HSA_SIZE;
621#endif
622 memory_size = 0;
Heiko Carstensde338a32007-01-09 10:18:47 +0100623 max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100624 memory_end &= PAGE_MASK;
625
626 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
627
628 for (i = 0; i < MEMORY_CHUNKS; i++) {
629 struct mem_chunk *chunk = &memory_chunk[i];
630
Michael Holzheu411ed322007-04-27 16:01:49 +0200631 real_memory_size = max(real_memory_size,
632 chunk->addr + chunk->size);
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100633 if (chunk->addr >= max_mem) {
634 memset(chunk, 0, sizeof(*chunk));
635 continue;
636 }
637 if (chunk->addr + chunk->size > max_mem)
638 chunk->size = max_mem - chunk->addr;
639 memory_size = max(memory_size, chunk->addr + chunk->size);
640 }
641 if (!memory_end)
642 memory_end = memory_size;
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100643}
644
Heiko Carstensc9e37352005-05-01 08:58:57 -0700645static void __init
646setup_memory(void)
647{
648 unsigned long bootmap_size;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100649 unsigned long start_pfn, end_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700650 int i;
651
652 /*
653 * partially used pages are not usable - thus
654 * we are rounding upwards:
655 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200656 start_pfn = PFN_UP(__pa(&_end));
657 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700658
Heiko Carstens65912a82006-09-20 15:58:41 +0200659#ifdef CONFIG_BLK_DEV_INITRD
660 /*
661 * Move the initrd in case the bitmap of the bootmem allocater
662 * would overwrite it.
663 */
664
665 if (INITRD_START && INITRD_SIZE) {
666 unsigned long bmap_size;
667 unsigned long start;
668
669 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
670 bmap_size = PFN_PHYS(bmap_size);
671
672 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
673 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
674
675 if (start + INITRD_SIZE > memory_end) {
676 printk("initrd extends beyond end of memory "
677 "(0x%08lx > 0x%08lx)\n"
678 "disabling initrd\n",
679 start + INITRD_SIZE, memory_end);
680 INITRD_START = INITRD_SIZE = 0;
681 } else {
682 printk("Moving initrd (0x%08lx -> 0x%08lx, "
683 "size: %ld)\n",
684 INITRD_START, start, INITRD_SIZE);
685 memmove((void *) start, (void *) INITRD_START,
686 INITRD_SIZE);
687 INITRD_START = start;
688 }
689 }
690 }
691#endif
692
Heiko Carstensc9e37352005-05-01 08:58:57 -0700693 /*
Heiko Carstens7676bef2006-10-04 20:02:19 +0200694 * Initialize the boot-time allocator
Heiko Carstensc9e37352005-05-01 08:58:57 -0700695 */
696 bootmap_size = init_bootmem(start_pfn, end_pfn);
697
698 /*
699 * Register RAM areas with the bootmem allocator.
700 */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700701
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700702 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstens39b742f2006-12-08 15:56:10 +0100703 unsigned long start_chunk, end_chunk, pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700704
705 if (memory_chunk[i].type != CHUNK_READ_WRITE)
706 continue;
Heiko Carstens39b742f2006-12-08 15:56:10 +0100707 start_chunk = PFN_DOWN(memory_chunk[i].addr);
708 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
709 end_chunk = min(end_chunk, end_pfn);
710 if (start_chunk >= end_chunk)
711 continue;
712 add_active_range(0, start_chunk, end_chunk);
713 pfn = max(start_chunk, start_pfn);
714 for (; pfn <= end_chunk; pfn++)
715 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700716 }
717
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700718 psw_set_key(PAGE_DEFAULT_KEY);
719
Heiko Carstens39b742f2006-12-08 15:56:10 +0100720 free_bootmem_with_active_regions(0, max_pfn);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700721
722 /*
Heiko Carstens615b04b2007-02-21 10:55:37 +0100723 * Reserve memory used for lowcore/command line/kernel image.
724 */
725 reserve_bootmem(0, (unsigned long)_ehead);
726 reserve_bootmem((unsigned long)_stext,
727 PFN_PHYS(start_pfn) - (unsigned long)_stext);
728 /*
Heiko Carstensc9e37352005-05-01 08:58:57 -0700729 * Reserve the bootmem bitmap itself as well. We do this in two
730 * steps (first step was init_bootmem()) because this catches
731 * the (very unlikely) case of us accidentally initializing the
732 * bootmem allocator with an invalid RAM area.
733 */
734 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
735
736#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200737 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700738 if (INITRD_START + INITRD_SIZE <= memory_end) {
739 reserve_bootmem(INITRD_START, INITRD_SIZE);
740 initrd_start = INITRD_START;
741 initrd_end = initrd_start + INITRD_SIZE;
742 } else {
743 printk("initrd extends beyond end of memory "
744 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
745 initrd_start + INITRD_SIZE, memory_end);
746 initrd_start = initrd_end = 0;
747 }
748 }
749#endif
750}
751
752/*
753 * Setup function called from init/main.c just after the banner
754 * was printed.
755 */
756
757void __init
758setup_arch(char **cmdline_p)
759{
760 /*
761 * print what head.S has found out about the machine
762 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800763#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700764 printk((MACHINE_IS_VM) ?
765 "We are running under VM (31 bit mode)\n" :
766 "We are running native (31 bit mode)\n");
767 printk((MACHINE_HAS_IEEE) ?
768 "This machine has an IEEE fpu\n" :
769 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800770#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700771 printk((MACHINE_IS_VM) ?
772 "We are running under VM (64 bit mode)\n" :
773 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800774#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700775
Heiko Carstens59685292006-03-24 03:15:15 -0800776 /* Save unparsed command line copy for /proc/cmdline */
Alon Bar-Leve06b1a32007-02-12 00:54:19 -0800777 strlcpy(boot_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
Heiko Carstens59685292006-03-24 03:15:15 -0800778
779 *cmdline_p = COMMAND_LINE;
780 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
781
Heiko Carstensc9e37352005-05-01 08:58:57 -0700782 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800783
784 init_mm.start_code = PAGE_OFFSET;
785 init_mm.end_code = (unsigned long) &_etext;
786 init_mm.end_data = (unsigned long) &_edata;
787 init_mm.brk = (unsigned long) &_end;
788
Gerald Schaefer6c2a9e62006-09-20 15:59:44 +0200789 if (MACHINE_HAS_MVCOS)
790 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
791 else
792 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
793
Heiko Carstens59685292006-03-24 03:15:15 -0800794 parse_early_param();
795
Michael Holzheu411ed322007-04-27 16:01:49 +0200796 setup_ipl_info();
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100797 setup_memory_end();
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100798 setup_addressing_mode();
Heiko Carstensc9e37352005-05-01 08:58:57 -0700799 setup_memory();
800 setup_resources();
801 setup_lowcore();
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 cpu_init();
804 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800805 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
807 /*
808 * Create kernel page tables and switch to virtual addressing.
809 */
810 paging_init();
811
812 /* Setup default console */
813 conmode_default();
Michael Holzheu411ed322007-04-27 16:01:49 +0200814
815 /* Setup zfcpdump support */
816 setup_zfcpdump(console_devno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817}
818
819void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
820{
821 printk("cpu %d "
822#ifdef CONFIG_SMP
823 "phys_idx=%d "
824#endif
825 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
826 cpuinfo->cpu_nr,
827#ifdef CONFIG_SMP
828 cpuinfo->cpu_addr,
829#endif
830 cpuinfo->cpu_id.version,
831 cpuinfo->cpu_id.ident,
832 cpuinfo->cpu_id.machine,
833 cpuinfo->cpu_id.unused);
834}
835
836/*
837 * show_cpuinfo - Get information on one CPU for use by procfs.
838 */
839
840static int show_cpuinfo(struct seq_file *m, void *v)
841{
842 struct cpuinfo_S390 *cpuinfo;
843 unsigned long n = (unsigned long) v - 1;
844
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +0100845 s390_adjust_jiffies();
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700846 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (!n) {
848 seq_printf(m, "vendor_id : IBM/S390\n"
849 "# processors : %i\n"
850 "bogomips per cpu: %lu.%02lu\n",
851 num_online_cpus(), loops_per_jiffy/(500000/HZ),
852 (loops_per_jiffy/(5000/HZ))%100);
853 }
854 if (cpu_online(n)) {
855#ifdef CONFIG_SMP
856 if (smp_processor_id() == n)
857 cpuinfo = &S390_lowcore.cpu_data;
858 else
859 cpuinfo = &lowcore_ptr[n]->cpu_data;
860#else
861 cpuinfo = &S390_lowcore.cpu_data;
862#endif
863 seq_printf(m, "processor %li: "
864 "version = %02X, "
865 "identification = %06X, "
866 "machine = %04X\n",
867 n, cpuinfo->cpu_id.version,
868 cpuinfo->cpu_id.ident,
869 cpuinfo->cpu_id.machine);
870 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700871 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 return 0;
873}
874
875static void *c_start(struct seq_file *m, loff_t *pos)
876{
877 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
878}
879static void *c_next(struct seq_file *m, void *v, loff_t *pos)
880{
881 ++*pos;
882 return c_start(m, pos);
883}
884static void c_stop(struct seq_file *m, void *v)
885{
886}
887struct seq_operations cpuinfo_op = {
888 .start = c_start,
889 .next = c_next,
890 .stop = c_stop,
891 .show = show_cpuinfo,
892};
893