blob: b928fecdc743e61760364be8492a1735ebef0f9c [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include <asm/uaccess.h>
43#include <asm/system.h>
44#include <asm/smp.h>
45#include <asm/mmu_context.h>
46#include <asm/cpcmd.h>
47#include <asm/lowcore.h>
48#include <asm/irq.h>
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070049#include <asm/page.h>
50#include <asm/ptrace.h>
Heiko Carstenscc13ad62006-06-25 05:49:30 -070051#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*
Gerald Schaeferd02765d2006-09-20 15:59:42 +020054 * User copy operations.
55 */
56struct uaccess_ops uaccess;
57EXPORT_SYMBOL_GPL(uaccess);
58
59/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 * Machine setup..
61 */
62unsigned int console_mode = 0;
63unsigned int console_devno = -1;
64unsigned int console_irq = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065unsigned long machine_flags = 0;
Heiko Carstens36a2bd42006-12-04 15:40:38 +010066
67struct mem_chunk memory_chunk[MEMORY_CHUNKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +010069unsigned long __initdata zholes_size[MAX_NR_ZONES];
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] = "";
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200121char 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
279extern void machine_restart_smp(char *);
280extern void machine_halt_smp(void);
281extern void machine_power_off_smp(void);
282
283void (*_machine_restart)(char *command) = machine_restart_smp;
284void (*_machine_halt)(void) = machine_halt_smp;
285void (*_machine_power_off)(void) = machine_power_off_smp;
286#else
287/*
288 * Reboot, halt and power_off routines for non SMP.
289 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290static void do_machine_restart_nonsmp(char * __unused)
291{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200292 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
295static void do_machine_halt_nonsmp(void)
296{
297 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100298 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
300}
301
302static void do_machine_power_off_nonsmp(void)
303{
304 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100305 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
307}
308
309void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
310void (*_machine_halt)(void) = do_machine_halt_nonsmp;
311void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
312#endif
313
314 /*
315 * Reboot, halt and power_off stubs. They just call _machine_restart,
316 * _machine_halt or _machine_power_off.
317 */
318
319void machine_restart(char *command)
320{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200321 if (!in_interrupt() || oops_in_progress)
322 /*
323 * Only unblank the console if we are called in enabled
324 * context or a bust_spinlocks cleared the way for us.
325 */
326 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 _machine_restart(command);
328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330void machine_halt(void)
331{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200332 if (!in_interrupt() || oops_in_progress)
333 /*
334 * Only unblank the console if we are called in enabled
335 * context or a bust_spinlocks cleared the way for us.
336 */
337 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 _machine_halt();
339}
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341void machine_power_off(void)
342{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200343 if (!in_interrupt() || oops_in_progress)
344 /*
345 * Only unblank the console if we are called in enabled
346 * context or a bust_spinlocks cleared the way for us.
347 */
348 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 _machine_power_off();
350}
351
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800352/*
353 * Dummy power off function.
354 */
355void (*pm_power_off)(void) = machine_power_off;
356
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +0100357static void __init
358add_memory_hole(unsigned long start, unsigned long end)
359{
360 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
361
362 if (end <= dma_pfn)
363 zholes_size[ZONE_DMA] += end - start + 1;
364 else if (start > dma_pfn)
365 zholes_size[ZONE_NORMAL] += end - start + 1;
366 else {
367 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
368 zholes_size[ZONE_NORMAL] += end - dma_pfn;
369 }
370}
371
Heiko Carstens59685292006-03-24 03:15:15 -0800372static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700373{
Heiko Carstens59685292006-03-24 03:15:15 -0800374 memory_end = memparse(p, &p);
375 return 0;
376}
377early_param("mem", early_parse_mem);
378
379/*
380 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
381 */
382static int __init early_parse_ipldelay(char *p)
383{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700384 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Heiko Carstens59685292006-03-24 03:15:15 -0800386 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Heiko Carstens59685292006-03-24 03:15:15 -0800388 switch (*p) {
389 case 's':
390 case 'S':
391 delay *= 1000000;
392 break;
393 case 'm':
394 case 'M':
395 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
Heiko Carstens59685292006-03-24 03:15:15 -0800397
398 /* now wait for the requested amount of time */
399 udelay(delay);
400
401 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700402}
Heiko Carstens59685292006-03-24 03:15:15 -0800403early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Heiko Carstensc9e37352005-05-01 08:58:57 -0700405static void __init
406setup_lowcore(void)
407{
408 struct _lowcore *lc;
409 int lc_pages;
410
411 /*
412 * Setup lowcore for boot cpu
413 */
414 lc_pages = sizeof(void *) == 8 ? 2 : 1;
415 lc = (struct _lowcore *)
416 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
417 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700418 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 lc->restart_psw.addr =
420 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
421 lc->external_new_psw.mask = PSW_KERNEL_BITS;
422 lc->external_new_psw.addr =
423 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
424 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
425 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
426 lc->program_new_psw.mask = PSW_KERNEL_BITS;
427 lc->program_new_psw.addr =
428 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700429 lc->mcck_new_psw.mask =
430 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 lc->mcck_new_psw.addr =
432 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
433 lc->io_new_psw.mask = PSW_KERNEL_BITS;
434 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
435 lc->ipl_device = S390_lowcore.ipl_device;
436 lc->jiffy_timer = -1LL;
437 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
438 lc->async_stack = (unsigned long)
439 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 lc->panic_stack = (unsigned long)
441 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
443 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800444#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700445 if (MACHINE_HAS_IEEE) {
446 lc->extended_save_area_addr = (__u32)
447 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
448 /* enable extended save area */
Heiko Carstensc4972f32006-11-06 10:49:02 +0100449 __ctl_set_bit(14, 29);
Heiko Carstens77fa2242005-06-25 14:55:30 -0700450 }
451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700453}
454
455static void __init
456setup_resources(void)
457{
458 struct resource *res;
459 int i;
460
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700461 code_resource.start = (unsigned long) &_text;
462 code_resource.end = (unsigned long) &_etext - 1;
463 data_resource.start = (unsigned long) &_etext;
464 data_resource.end = (unsigned long) &_edata - 1;
465
Heiko Carstensc9e37352005-05-01 08:58:57 -0700466 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
467 res = alloc_bootmem_low(sizeof(struct resource));
468 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
469 switch (memory_chunk[i].type) {
470 case CHUNK_READ_WRITE:
471 res->name = "System RAM";
472 break;
473 case CHUNK_READ_ONLY:
474 res->name = "System ROM";
475 res->flags |= IORESOURCE_READONLY;
476 break;
477 default:
478 res->name = "reserved";
479 }
480 res->start = memory_chunk[i].addr;
481 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
482 request_resource(&iomem_resource, res);
483 request_resource(res, &code_resource);
484 request_resource(res, &data_resource);
485 }
486}
487
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100488static void __init setup_memory_end(void)
489{
490 unsigned long real_size, memory_size;
491 unsigned long max_mem, max_phys;
492 int i;
493
494 memory_size = real_size = 0;
495 max_phys = VMALLOC_END - VMALLOC_MIN_SIZE;
496 memory_end &= PAGE_MASK;
497
498 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
499
500 for (i = 0; i < MEMORY_CHUNKS; i++) {
501 struct mem_chunk *chunk = &memory_chunk[i];
502
503 real_size = max(real_size, chunk->addr + chunk->size);
504 if (chunk->addr >= max_mem) {
505 memset(chunk, 0, sizeof(*chunk));
506 continue;
507 }
508 if (chunk->addr + chunk->size > max_mem)
509 chunk->size = max_mem - chunk->addr;
510 memory_size = max(memory_size, chunk->addr + chunk->size);
511 }
512 if (!memory_end)
513 memory_end = memory_size;
514 if (real_size > memory_end)
515 printk("More memory detected than supported. Unused: %luk\n",
516 (real_size - memory_end) >> 10);
517}
518
Heiko Carstensc9e37352005-05-01 08:58:57 -0700519static void __init
520setup_memory(void)
521{
522 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700523 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +0100524 unsigned long last_rw_end;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700525 int i;
526
527 /*
528 * partially used pages are not usable - thus
529 * we are rounding upwards:
530 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200531 start_pfn = PFN_UP(__pa(&_end));
532 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700533
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700534 /* Initialize storage key for kernel pages */
535 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
536 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
537
Heiko Carstens65912a82006-09-20 15:58:41 +0200538#ifdef CONFIG_BLK_DEV_INITRD
539 /*
540 * Move the initrd in case the bitmap of the bootmem allocater
541 * would overwrite it.
542 */
543
544 if (INITRD_START && INITRD_SIZE) {
545 unsigned long bmap_size;
546 unsigned long start;
547
548 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
549 bmap_size = PFN_PHYS(bmap_size);
550
551 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
552 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
553
554 if (start + INITRD_SIZE > memory_end) {
555 printk("initrd extends beyond end of memory "
556 "(0x%08lx > 0x%08lx)\n"
557 "disabling initrd\n",
558 start + INITRD_SIZE, memory_end);
559 INITRD_START = INITRD_SIZE = 0;
560 } else {
561 printk("Moving initrd (0x%08lx -> 0x%08lx, "
562 "size: %ld)\n",
563 INITRD_START, start, INITRD_SIZE);
564 memmove((void *) start, (void *) INITRD_START,
565 INITRD_SIZE);
566 INITRD_START = start;
567 }
568 }
569 }
570#endif
571
Heiko Carstensc9e37352005-05-01 08:58:57 -0700572 /*
Heiko Carstens7676bef2006-10-04 20:02:19 +0200573 * Initialize the boot-time allocator
Heiko Carstensc9e37352005-05-01 08:58:57 -0700574 */
575 bootmap_size = init_bootmem(start_pfn, end_pfn);
576
577 /*
578 * Register RAM areas with the bootmem allocator.
579 */
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +0100580 last_rw_end = start_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700581
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700582 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +0100583 unsigned long start_chunk, end_chunk;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700584
585 if (memory_chunk[i].type != CHUNK_READ_WRITE)
586 continue;
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +0100587 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
588 start_chunk >>= PAGE_SHIFT;
589 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
590 end_chunk >>= PAGE_SHIFT;
591 if (start_chunk < start_pfn)
592 start_chunk = start_pfn;
593 if (end_chunk > end_pfn)
594 end_chunk = end_pfn;
595 if (start_chunk < end_chunk) {
596 /* Initialize storage key for RAM pages */
597 for (init_pfn = start_chunk ; init_pfn < end_chunk;
598 init_pfn++)
599 page_set_storage_key(init_pfn << PAGE_SHIFT,
600 PAGE_DEFAULT_KEY);
601 free_bootmem(start_chunk << PAGE_SHIFT,
602 (end_chunk - start_chunk) << PAGE_SHIFT);
603 if (last_rw_end < start_chunk)
604 add_memory_hole(last_rw_end, start_chunk - 1);
605 last_rw_end = end_chunk;
606 }
Heiko Carstensc9e37352005-05-01 08:58:57 -0700607 }
608
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700609 psw_set_key(PAGE_DEFAULT_KEY);
610
Heiko Carstensbcc8bcb12006-11-06 10:49:00 +0100611 if (last_rw_end < end_pfn - 1)
612 add_memory_hole(last_rw_end, end_pfn - 1);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700613
614 /*
615 * Reserve the bootmem bitmap itself as well. We do this in two
616 * steps (first step was init_bootmem()) because this catches
617 * the (very unlikely) case of us accidentally initializing the
618 * bootmem allocator with an invalid RAM area.
619 */
620 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
621
622#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200623 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700624 if (INITRD_START + INITRD_SIZE <= memory_end) {
625 reserve_bootmem(INITRD_START, INITRD_SIZE);
626 initrd_start = INITRD_START;
627 initrd_end = initrd_start + INITRD_SIZE;
628 } else {
629 printk("initrd extends beyond end of memory "
630 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
631 initrd_start + INITRD_SIZE, memory_end);
632 initrd_start = initrd_end = 0;
633 }
634 }
635#endif
636}
637
638/*
639 * Setup function called from init/main.c just after the banner
640 * was printed.
641 */
642
643void __init
644setup_arch(char **cmdline_p)
645{
646 /*
647 * print what head.S has found out about the machine
648 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800649#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700650 printk((MACHINE_IS_VM) ?
651 "We are running under VM (31 bit mode)\n" :
652 "We are running native (31 bit mode)\n");
653 printk((MACHINE_HAS_IEEE) ?
654 "This machine has an IEEE fpu\n" :
655 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800656#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700657 printk((MACHINE_IS_VM) ?
658 "We are running under VM (64 bit mode)\n" :
659 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800660#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700661
Heiko Carstens59685292006-03-24 03:15:15 -0800662 /* Save unparsed command line copy for /proc/cmdline */
663 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
664
665 *cmdline_p = COMMAND_LINE;
666 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
667
Heiko Carstensc9e37352005-05-01 08:58:57 -0700668 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800669
670 init_mm.start_code = PAGE_OFFSET;
671 init_mm.end_code = (unsigned long) &_etext;
672 init_mm.end_data = (unsigned long) &_edata;
673 init_mm.brk = (unsigned long) &_end;
674
Gerald Schaefer6c2a9e62006-09-20 15:59:44 +0200675 if (MACHINE_HAS_MVCOS)
676 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
677 else
678 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
679
Heiko Carstens59685292006-03-24 03:15:15 -0800680 parse_early_param();
681
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100682 setup_memory_end();
Heiko Carstensc9e37352005-05-01 08:58:57 -0700683 setup_memory();
684 setup_resources();
685 setup_lowcore();
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 cpu_init();
688 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800689 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 /*
692 * Create kernel page tables and switch to virtual addressing.
693 */
694 paging_init();
695
696 /* Setup default console */
697 conmode_default();
698}
699
700void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
701{
702 printk("cpu %d "
703#ifdef CONFIG_SMP
704 "phys_idx=%d "
705#endif
706 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
707 cpuinfo->cpu_nr,
708#ifdef CONFIG_SMP
709 cpuinfo->cpu_addr,
710#endif
711 cpuinfo->cpu_id.version,
712 cpuinfo->cpu_id.ident,
713 cpuinfo->cpu_id.machine,
714 cpuinfo->cpu_id.unused);
715}
716
717/*
718 * show_cpuinfo - Get information on one CPU for use by procfs.
719 */
720
721static int show_cpuinfo(struct seq_file *m, void *v)
722{
723 struct cpuinfo_S390 *cpuinfo;
724 unsigned long n = (unsigned long) v - 1;
725
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700726 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 if (!n) {
728 seq_printf(m, "vendor_id : IBM/S390\n"
729 "# processors : %i\n"
730 "bogomips per cpu: %lu.%02lu\n",
731 num_online_cpus(), loops_per_jiffy/(500000/HZ),
732 (loops_per_jiffy/(5000/HZ))%100);
733 }
734 if (cpu_online(n)) {
735#ifdef CONFIG_SMP
736 if (smp_processor_id() == n)
737 cpuinfo = &S390_lowcore.cpu_data;
738 else
739 cpuinfo = &lowcore_ptr[n]->cpu_data;
740#else
741 cpuinfo = &S390_lowcore.cpu_data;
742#endif
743 seq_printf(m, "processor %li: "
744 "version = %02X, "
745 "identification = %06X, "
746 "machine = %04X\n",
747 n, cpuinfo->cpu_id.version,
748 cpuinfo->cpu_id.ident,
749 cpuinfo->cpu_id.machine);
750 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700751 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return 0;
753}
754
755static void *c_start(struct seq_file *m, loff_t *pos)
756{
757 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
758}
759static void *c_next(struct seq_file *m, void *v, loff_t *pos)
760{
761 ++*pos;
762 return c_start(m, pos);
763}
764static void c_stop(struct seq_file *m, void *v)
765{
766}
767struct seq_operations cpuinfo_op = {
768 .start = c_start,
769 .next = c_next,
770 .stop = c_stop,
771 .show = show_cpuinfo,
772};
773