blob: 1cbf956cb6b3f526e8d0df264c573b72662e9428 [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>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010041#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <asm/uaccess.h>
44#include <asm/system.h>
45#include <asm/smp.h>
46#include <asm/mmu_context.h>
47#include <asm/cpcmd.h>
48#include <asm/lowcore.h>
49#include <asm/irq.h>
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070050#include <asm/page.h>
51#include <asm/ptrace.h>
Heiko Carstenscc13ad62006-06-25 05:49:30 -070052#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*
Gerald Schaeferd02765d2006-09-20 15:59:42 +020055 * User copy operations.
56 */
57struct uaccess_ops uaccess;
58EXPORT_SYMBOL_GPL(uaccess);
59
60/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 * Machine setup..
62 */
63unsigned int console_mode = 0;
64unsigned int console_devno = -1;
65unsigned int console_irq = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066unsigned long machine_flags = 0;
Heiko Carstens36a2bd42006-12-04 15:40:38 +010067
Heiko Carstensf4eb07c2006-12-08 15:56:07 +010068struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070069volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070070static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 * 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 ...
76 */
77
78#include <asm/setup.h>
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static struct resource code_resource = {
81 .name = "Kernel code",
82 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
83};
84
85static struct resource data_resource = {
86 .name = "Kernel data",
87 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
88};
89
90/*
91 * cpu_init() initializes state that is per-CPU.
92 */
93void __devinit cpu_init (void)
94{
95 int addr = hard_smp_processor_id();
96
97 /*
98 * Store processor id in lowcore (used e.g. in timer_interrupt)
99 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200100 asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 S390_lowcore.cpu_data.cpu_addr = addr;
102
103 /*
104 * Force FPU initialization:
105 */
106 clear_thread_flag(TIF_USEDFPU);
107 clear_used_math();
108
109 atomic_inc(&init_mm.mm_count);
110 current->active_mm = &init_mm;
111 if (current->mm)
112 BUG();
113 enter_lazy_tlb(&init_mm, current);
114}
115
116/*
117 * VM halt and poweroff setup routines
118 */
119char vmhalt_cmd[128] = "";
120char vmpoff_cmd[128] = "";
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100121static char vmpanic_cmd[128] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123static inline void strncpy_skip_quote(char *dst, char *src, int n)
124{
125 int sx, dx;
126
127 dx = 0;
128 for (sx = 0; src[sx] != 0; sx++) {
129 if (src[sx] == '"') continue;
130 dst[dx++] = src[sx];
131 if (dx >= n) break;
132 }
133}
134
135static int __init vmhalt_setup(char *str)
136{
137 strncpy_skip_quote(vmhalt_cmd, str, 127);
138 vmhalt_cmd[127] = 0;
139 return 1;
140}
141
142__setup("vmhalt=", vmhalt_setup);
143
144static int __init vmpoff_setup(char *str)
145{
146 strncpy_skip_quote(vmpoff_cmd, str, 127);
147 vmpoff_cmd[127] = 0;
148 return 1;
149}
150
151__setup("vmpoff=", vmpoff_setup);
152
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200153static int vmpanic_notify(struct notifier_block *self, unsigned long event,
154 void *data)
155{
156 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
157 cpcmd(vmpanic_cmd, NULL, 0, NULL);
158
159 return NOTIFY_OK;
160}
161
162#define PANIC_PRI_VMPANIC 0
163
164static struct notifier_block vmpanic_nb = {
165 .notifier_call = vmpanic_notify,
166 .priority = PANIC_PRI_VMPANIC
167};
168
169static int __init vmpanic_setup(char *str)
170{
171 static int register_done __initdata = 0;
172
173 strncpy_skip_quote(vmpanic_cmd, str, 127);
174 vmpanic_cmd[127] = 0;
175 if (!register_done) {
176 register_done = 1;
177 atomic_notifier_chain_register(&panic_notifier_list,
178 &vmpanic_nb);
179 }
180 return 1;
181}
182
183__setup("vmpanic=", vmpanic_setup);
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/*
186 * condev= and conmode= setup parameter.
187 */
188
189static int __init condev_setup(char *str)
190{
191 int vdev;
192
193 vdev = simple_strtoul(str, &str, 0);
194 if (vdev >= 0 && vdev < 65536) {
195 console_devno = vdev;
196 console_irq = -1;
197 }
198 return 1;
199}
200
201__setup("condev=", condev_setup);
202
203static int __init conmode_setup(char *str)
204{
205#if defined(CONFIG_SCLP_CONSOLE)
206 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
207 SET_CONSOLE_SCLP;
208#endif
209#if defined(CONFIG_TN3215_CONSOLE)
210 if (strncmp(str, "3215", 5) == 0)
211 SET_CONSOLE_3215;
212#endif
213#if defined(CONFIG_TN3270_CONSOLE)
214 if (strncmp(str, "3270", 5) == 0)
215 SET_CONSOLE_3270;
216#endif
217 return 1;
218}
219
220__setup("conmode=", conmode_setup);
221
222static void __init conmode_default(void)
223{
224 char query_buffer[1024];
225 char *ptr;
226
227 if (MACHINE_IS_VM) {
Heiko Carstens740b5702006-12-04 15:40:30 +0100228 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
230 ptr = strstr(query_buffer, "SUBCHANNEL =");
231 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Heiko Carstens740b5702006-12-04 15:40:30 +0100232 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 ptr = strstr(query_buffer, "CONMODE");
234 /*
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).
240 */
Heiko Carstens740b5702006-12-04 15:40:30 +0100241 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (ptr == NULL) {
243#if defined(CONFIG_SCLP_CONSOLE)
244 SET_CONSOLE_SCLP;
245#endif
246 return;
247 }
248 if (strncmp(ptr + 8, "3270", 4) == 0) {
249#if defined(CONFIG_TN3270_CONSOLE)
250 SET_CONSOLE_3270;
251#elif defined(CONFIG_TN3215_CONSOLE)
252 SET_CONSOLE_3215;
253#elif defined(CONFIG_SCLP_CONSOLE)
254 SET_CONSOLE_SCLP;
255#endif
256 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
257#if defined(CONFIG_TN3215_CONSOLE)
258 SET_CONSOLE_3215;
259#elif defined(CONFIG_TN3270_CONSOLE)
260 SET_CONSOLE_3270;
261#elif defined(CONFIG_SCLP_CONSOLE)
262 SET_CONSOLE_SCLP;
263#endif
264 }
265 } else if (MACHINE_IS_P390) {
266#if defined(CONFIG_TN3215_CONSOLE)
267 SET_CONSOLE_3215;
268#elif defined(CONFIG_TN3270_CONSOLE)
269 SET_CONSOLE_3270;
270#endif
271 } else {
272#if defined(CONFIG_SCLP_CONSOLE)
273 SET_CONSOLE_SCLP;
274#endif
275 }
276}
277
278#ifdef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279void (*_machine_restart)(char *command) = machine_restart_smp;
280void (*_machine_halt)(void) = machine_halt_smp;
281void (*_machine_power_off)(void) = machine_power_off_smp;
282#else
283/*
284 * Reboot, halt and power_off routines for non SMP.
285 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286static void do_machine_restart_nonsmp(char * __unused)
287{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200288 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289}
290
291static void do_machine_halt_nonsmp(void)
292{
293 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100294 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
296}
297
298static void do_machine_power_off_nonsmp(void)
299{
300 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100301 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
303}
304
305void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
306void (*_machine_halt)(void) = do_machine_halt_nonsmp;
307void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
308#endif
309
310 /*
311 * Reboot, halt and power_off stubs. They just call _machine_restart,
312 * _machine_halt or _machine_power_off.
313 */
314
315void machine_restart(char *command)
316{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200317 if (!in_interrupt() || oops_in_progress)
318 /*
319 * Only unblank the console if we are called in enabled
320 * context or a bust_spinlocks cleared the way for us.
321 */
322 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 _machine_restart(command);
324}
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326void machine_halt(void)
327{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200328 if (!in_interrupt() || oops_in_progress)
329 /*
330 * Only unblank the console if we are called in enabled
331 * context or a bust_spinlocks cleared the way for us.
332 */
333 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 _machine_halt();
335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337void machine_power_off(void)
338{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200339 if (!in_interrupt() || oops_in_progress)
340 /*
341 * Only unblank the console if we are called in enabled
342 * context or a bust_spinlocks cleared the way for us.
343 */
344 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 _machine_power_off();
346}
347
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800348/*
349 * Dummy power off function.
350 */
351void (*pm_power_off)(void) = machine_power_off;
352
Heiko Carstens59685292006-03-24 03:15:15 -0800353static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700354{
Heiko Carstens59685292006-03-24 03:15:15 -0800355 memory_end = memparse(p, &p);
356 return 0;
357}
358early_param("mem", early_parse_mem);
359
360/*
361 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
362 */
363static int __init early_parse_ipldelay(char *p)
364{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700365 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Heiko Carstens59685292006-03-24 03:15:15 -0800367 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Heiko Carstens59685292006-03-24 03:15:15 -0800369 switch (*p) {
370 case 's':
371 case 'S':
372 delay *= 1000000;
373 break;
374 case 'm':
375 case 'M':
376 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
Heiko Carstens59685292006-03-24 03:15:15 -0800378
379 /* now wait for the requested amount of time */
380 udelay(delay);
381
382 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700383}
Heiko Carstens59685292006-03-24 03:15:15 -0800384early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Heiko Carstensc9e37352005-05-01 08:58:57 -0700386static void __init
387setup_lowcore(void)
388{
389 struct _lowcore *lc;
390 int lc_pages;
391
392 /*
393 * Setup lowcore for boot cpu
394 */
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);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700399 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 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;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700410 lc->mcck_new_psw.mask =
411 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 lc->panic_stack = (unsigned long)
422 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
424 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800425#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700426 if (MACHINE_HAS_IEEE) {
427 lc->extended_save_area_addr = (__u32)
428 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
429 /* enable extended save area */
Heiko Carstensc4972f32006-11-06 10:49:02 +0100430 __ctl_set_bit(14, 29);
Heiko Carstens77fa2242005-06-25 14:55:30 -0700431 }
432#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700434}
435
436static void __init
437setup_resources(void)
438{
439 struct resource *res;
440 int i;
441
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700442 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;
446
Heiko Carstensc9e37352005-05-01 08:58:57 -0700447 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";
453 break;
454 case CHUNK_READ_ONLY:
455 res->name = "System ROM";
456 res->flags |= IORESOURCE_READONLY;
457 break;
458 default:
459 res->name = "reserved";
460 }
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);
466 }
467}
468
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100469static void __init setup_memory_end(void)
470{
471 unsigned long real_size, memory_size;
472 unsigned long max_mem, max_phys;
473 int i;
474
475 memory_size = real_size = 0;
Heiko Carstensde338a32007-01-09 10:18:47 +0100476 max_phys = VMALLOC_END_INIT - VMALLOC_MIN_SIZE;
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100477 memory_end &= PAGE_MASK;
478
479 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
480
481 for (i = 0; i < MEMORY_CHUNKS; i++) {
482 struct mem_chunk *chunk = &memory_chunk[i];
483
484 real_size = max(real_size, chunk->addr + chunk->size);
485 if (chunk->addr >= max_mem) {
486 memset(chunk, 0, sizeof(*chunk));
487 continue;
488 }
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);
492 }
493 if (!memory_end)
494 memory_end = memory_size;
495 if (real_size > memory_end)
496 printk("More memory detected than supported. Unused: %luk\n",
497 (real_size - memory_end) >> 10);
498}
499
Heiko Carstensc9e37352005-05-01 08:58:57 -0700500static void __init
501setup_memory(void)
502{
503 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700504 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700505 int i;
506
507 /*
508 * partially used pages are not usable - thus
509 * we are rounding upwards:
510 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200511 start_pfn = PFN_UP(__pa(&_end));
512 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700513
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700514 /* Initialize storage key for kernel pages */
515 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
516 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
517
Heiko Carstens65912a82006-09-20 15:58:41 +0200518#ifdef CONFIG_BLK_DEV_INITRD
519 /*
520 * Move the initrd in case the bitmap of the bootmem allocater
521 * would overwrite it.
522 */
523
524 if (INITRD_START && INITRD_SIZE) {
525 unsigned long bmap_size;
526 unsigned long start;
527
528 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
529 bmap_size = PFN_PHYS(bmap_size);
530
531 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
532 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
533
534 if (start + INITRD_SIZE > memory_end) {
535 printk("initrd extends beyond end of memory "
536 "(0x%08lx > 0x%08lx)\n"
537 "disabling initrd\n",
538 start + INITRD_SIZE, memory_end);
539 INITRD_START = INITRD_SIZE = 0;
540 } else {
541 printk("Moving initrd (0x%08lx -> 0x%08lx, "
542 "size: %ld)\n",
543 INITRD_START, start, INITRD_SIZE);
544 memmove((void *) start, (void *) INITRD_START,
545 INITRD_SIZE);
546 INITRD_START = start;
547 }
548 }
549 }
550#endif
551
Heiko Carstensc9e37352005-05-01 08:58:57 -0700552 /*
Heiko Carstens7676bef2006-10-04 20:02:19 +0200553 * Initialize the boot-time allocator
Heiko Carstensc9e37352005-05-01 08:58:57 -0700554 */
555 bootmap_size = init_bootmem(start_pfn, end_pfn);
556
557 /*
558 * Register RAM areas with the bootmem allocator.
559 */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700560
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700561 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstens39b742f2006-12-08 15:56:10 +0100562 unsigned long start_chunk, end_chunk, pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700563
564 if (memory_chunk[i].type != CHUNK_READ_WRITE)
565 continue;
Heiko Carstens39b742f2006-12-08 15:56:10 +0100566 start_chunk = PFN_DOWN(memory_chunk[i].addr);
567 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
568 end_chunk = min(end_chunk, end_pfn);
569 if (start_chunk >= end_chunk)
570 continue;
571 add_active_range(0, start_chunk, end_chunk);
572 pfn = max(start_chunk, start_pfn);
573 for (; pfn <= end_chunk; pfn++)
574 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700575 }
576
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700577 psw_set_key(PAGE_DEFAULT_KEY);
578
Heiko Carstens39b742f2006-12-08 15:56:10 +0100579 free_bootmem_with_active_regions(0, max_pfn);
580 reserve_bootmem(0, PFN_PHYS(start_pfn));
Heiko Carstensc9e37352005-05-01 08:58:57 -0700581
582 /*
583 * Reserve the bootmem bitmap itself as well. We do this in two
584 * steps (first step was init_bootmem()) because this catches
585 * the (very unlikely) case of us accidentally initializing the
586 * bootmem allocator with an invalid RAM area.
587 */
588 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
589
590#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200591 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700592 if (INITRD_START + INITRD_SIZE <= memory_end) {
593 reserve_bootmem(INITRD_START, INITRD_SIZE);
594 initrd_start = INITRD_START;
595 initrd_end = initrd_start + INITRD_SIZE;
596 } else {
597 printk("initrd extends beyond end of memory "
598 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
599 initrd_start + INITRD_SIZE, memory_end);
600 initrd_start = initrd_end = 0;
601 }
602 }
603#endif
604}
605
606/*
607 * Setup function called from init/main.c just after the banner
608 * was printed.
609 */
610
611void __init
612setup_arch(char **cmdline_p)
613{
614 /*
615 * print what head.S has found out about the machine
616 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800617#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700618 printk((MACHINE_IS_VM) ?
619 "We are running under VM (31 bit mode)\n" :
620 "We are running native (31 bit mode)\n");
621 printk((MACHINE_HAS_IEEE) ?
622 "This machine has an IEEE fpu\n" :
623 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800624#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700625 printk((MACHINE_IS_VM) ?
626 "We are running under VM (64 bit mode)\n" :
627 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800628#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700629
Heiko Carstens59685292006-03-24 03:15:15 -0800630 /* Save unparsed command line copy for /proc/cmdline */
631 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
632
633 *cmdline_p = COMMAND_LINE;
634 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
635
Heiko Carstensc9e37352005-05-01 08:58:57 -0700636 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800637
638 init_mm.start_code = PAGE_OFFSET;
639 init_mm.end_code = (unsigned long) &_etext;
640 init_mm.end_data = (unsigned long) &_edata;
641 init_mm.brk = (unsigned long) &_end;
642
Gerald Schaefer6c2a9e62006-09-20 15:59:44 +0200643 if (MACHINE_HAS_MVCOS)
644 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
645 else
646 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
647
Heiko Carstens59685292006-03-24 03:15:15 -0800648 parse_early_param();
649
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100650 setup_memory_end();
Heiko Carstensc9e37352005-05-01 08:58:57 -0700651 setup_memory();
652 setup_resources();
653 setup_lowcore();
654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 cpu_init();
656 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800657 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /*
660 * Create kernel page tables and switch to virtual addressing.
661 */
662 paging_init();
663
664 /* Setup default console */
665 conmode_default();
666}
667
668void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
669{
670 printk("cpu %d "
671#ifdef CONFIG_SMP
672 "phys_idx=%d "
673#endif
674 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
675 cpuinfo->cpu_nr,
676#ifdef CONFIG_SMP
677 cpuinfo->cpu_addr,
678#endif
679 cpuinfo->cpu_id.version,
680 cpuinfo->cpu_id.ident,
681 cpuinfo->cpu_id.machine,
682 cpuinfo->cpu_id.unused);
683}
684
685/*
686 * show_cpuinfo - Get information on one CPU for use by procfs.
687 */
688
689static int show_cpuinfo(struct seq_file *m, void *v)
690{
691 struct cpuinfo_S390 *cpuinfo;
692 unsigned long n = (unsigned long) v - 1;
693
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700694 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (!n) {
696 seq_printf(m, "vendor_id : IBM/S390\n"
697 "# processors : %i\n"
698 "bogomips per cpu: %lu.%02lu\n",
699 num_online_cpus(), loops_per_jiffy/(500000/HZ),
700 (loops_per_jiffy/(5000/HZ))%100);
701 }
702 if (cpu_online(n)) {
703#ifdef CONFIG_SMP
704 if (smp_processor_id() == n)
705 cpuinfo = &S390_lowcore.cpu_data;
706 else
707 cpuinfo = &lowcore_ptr[n]->cpu_data;
708#else
709 cpuinfo = &S390_lowcore.cpu_data;
710#endif
711 seq_printf(m, "processor %li: "
712 "version = %02X, "
713 "identification = %06X, "
714 "machine = %04X\n",
715 n, cpuinfo->cpu_id.version,
716 cpuinfo->cpu_id.ident,
717 cpuinfo->cpu_id.machine);
718 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700719 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 return 0;
721}
722
723static void *c_start(struct seq_file *m, loff_t *pos)
724{
725 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
726}
727static void *c_next(struct seq_file *m, void *v, loff_t *pos)
728{
729 ++*pos;
730 return c_start(m, pos);
731}
732static void c_stop(struct seq_file *m, void *v)
733{
734}
735struct seq_operations cpuinfo_op = {
736 .start = c_start,
737 .next = c_next,
738 .stop = c_stop,
739 .show = show_cpuinfo,
740};
741