blob: 49ef206ec8806c6a6dc4ed0b0d9e211979065cf1 [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
Heiko Carstensf4eb07c2006-12-08 15:56:07 +010067struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070069static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 * This is set up by the setup-routine at boot-time
73 * for S390 need to find out, what we have to setup
74 * using address 0x10400 ...
75 */
76
77#include <asm/setup.h>
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static struct resource code_resource = {
80 .name = "Kernel code",
81 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
82};
83
84static struct resource data_resource = {
85 .name = "Kernel data",
86 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
87};
88
89/*
90 * cpu_init() initializes state that is per-CPU.
91 */
92void __devinit cpu_init (void)
93{
94 int addr = hard_smp_processor_id();
95
96 /*
97 * Store processor id in lowcore (used e.g. in timer_interrupt)
98 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020099 asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 S390_lowcore.cpu_data.cpu_addr = addr;
101
102 /*
103 * Force FPU initialization:
104 */
105 clear_thread_flag(TIF_USEDFPU);
106 clear_used_math();
107
108 atomic_inc(&init_mm.mm_count);
109 current->active_mm = &init_mm;
110 if (current->mm)
111 BUG();
112 enter_lazy_tlb(&init_mm, current);
113}
114
115/*
116 * VM halt and poweroff setup routines
117 */
118char vmhalt_cmd[128] = "";
119char vmpoff_cmd[128] = "";
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200120char vmpanic_cmd[128] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122static inline void strncpy_skip_quote(char *dst, char *src, int n)
123{
124 int sx, dx;
125
126 dx = 0;
127 for (sx = 0; src[sx] != 0; sx++) {
128 if (src[sx] == '"') continue;
129 dst[dx++] = src[sx];
130 if (dx >= n) break;
131 }
132}
133
134static int __init vmhalt_setup(char *str)
135{
136 strncpy_skip_quote(vmhalt_cmd, str, 127);
137 vmhalt_cmd[127] = 0;
138 return 1;
139}
140
141__setup("vmhalt=", vmhalt_setup);
142
143static int __init vmpoff_setup(char *str)
144{
145 strncpy_skip_quote(vmpoff_cmd, str, 127);
146 vmpoff_cmd[127] = 0;
147 return 1;
148}
149
150__setup("vmpoff=", vmpoff_setup);
151
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200152static int vmpanic_notify(struct notifier_block *self, unsigned long event,
153 void *data)
154{
155 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
156 cpcmd(vmpanic_cmd, NULL, 0, NULL);
157
158 return NOTIFY_OK;
159}
160
161#define PANIC_PRI_VMPANIC 0
162
163static struct notifier_block vmpanic_nb = {
164 .notifier_call = vmpanic_notify,
165 .priority = PANIC_PRI_VMPANIC
166};
167
168static int __init vmpanic_setup(char *str)
169{
170 static int register_done __initdata = 0;
171
172 strncpy_skip_quote(vmpanic_cmd, str, 127);
173 vmpanic_cmd[127] = 0;
174 if (!register_done) {
175 register_done = 1;
176 atomic_notifier_chain_register(&panic_notifier_list,
177 &vmpanic_nb);
178 }
179 return 1;
180}
181
182__setup("vmpanic=", vmpanic_setup);
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/*
185 * condev= and conmode= setup parameter.
186 */
187
188static int __init condev_setup(char *str)
189{
190 int vdev;
191
192 vdev = simple_strtoul(str, &str, 0);
193 if (vdev >= 0 && vdev < 65536) {
194 console_devno = vdev;
195 console_irq = -1;
196 }
197 return 1;
198}
199
200__setup("condev=", condev_setup);
201
202static int __init conmode_setup(char *str)
203{
204#if defined(CONFIG_SCLP_CONSOLE)
205 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
206 SET_CONSOLE_SCLP;
207#endif
208#if defined(CONFIG_TN3215_CONSOLE)
209 if (strncmp(str, "3215", 5) == 0)
210 SET_CONSOLE_3215;
211#endif
212#if defined(CONFIG_TN3270_CONSOLE)
213 if (strncmp(str, "3270", 5) == 0)
214 SET_CONSOLE_3270;
215#endif
216 return 1;
217}
218
219__setup("conmode=", conmode_setup);
220
221static void __init conmode_default(void)
222{
223 char query_buffer[1024];
224 char *ptr;
225
226 if (MACHINE_IS_VM) {
Heiko Carstens740b5702006-12-04 15:40:30 +0100227 cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
229 ptr = strstr(query_buffer, "SUBCHANNEL =");
230 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Heiko Carstens740b5702006-12-04 15:40:30 +0100231 cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 ptr = strstr(query_buffer, "CONMODE");
233 /*
234 * Set the conmode to 3215 so that the device recognition
235 * will set the cu_type of the console to 3215. If the
236 * conmode is 3270 and we don't set it back then both
237 * 3215 and the 3270 driver will try to access the console
238 * device (3215 as console and 3270 as normal tty).
239 */
Heiko Carstens740b5702006-12-04 15:40:30 +0100240 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (ptr == NULL) {
242#if defined(CONFIG_SCLP_CONSOLE)
243 SET_CONSOLE_SCLP;
244#endif
245 return;
246 }
247 if (strncmp(ptr + 8, "3270", 4) == 0) {
248#if defined(CONFIG_TN3270_CONSOLE)
249 SET_CONSOLE_3270;
250#elif defined(CONFIG_TN3215_CONSOLE)
251 SET_CONSOLE_3215;
252#elif defined(CONFIG_SCLP_CONSOLE)
253 SET_CONSOLE_SCLP;
254#endif
255 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
256#if defined(CONFIG_TN3215_CONSOLE)
257 SET_CONSOLE_3215;
258#elif defined(CONFIG_TN3270_CONSOLE)
259 SET_CONSOLE_3270;
260#elif defined(CONFIG_SCLP_CONSOLE)
261 SET_CONSOLE_SCLP;
262#endif
263 }
264 } else if (MACHINE_IS_P390) {
265#if defined(CONFIG_TN3215_CONSOLE)
266 SET_CONSOLE_3215;
267#elif defined(CONFIG_TN3270_CONSOLE)
268 SET_CONSOLE_3270;
269#endif
270 } else {
271#if defined(CONFIG_SCLP_CONSOLE)
272 SET_CONSOLE_SCLP;
273#endif
274 }
275}
276
277#ifdef CONFIG_SMP
278extern void machine_restart_smp(char *);
279extern void machine_halt_smp(void);
280extern void machine_power_off_smp(void);
281
282void (*_machine_restart)(char *command) = machine_restart_smp;
283void (*_machine_halt)(void) = machine_halt_smp;
284void (*_machine_power_off)(void) = machine_power_off_smp;
285#else
286/*
287 * Reboot, halt and power_off routines for non SMP.
288 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289static void do_machine_restart_nonsmp(char * __unused)
290{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200291 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
294static void do_machine_halt_nonsmp(void)
295{
296 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100297 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
299}
300
301static void do_machine_power_off_nonsmp(void)
302{
303 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Heiko Carstens740b5702006-12-04 15:40:30 +0100304 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
306}
307
308void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
309void (*_machine_halt)(void) = do_machine_halt_nonsmp;
310void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
311#endif
312
313 /*
314 * Reboot, halt and power_off stubs. They just call _machine_restart,
315 * _machine_halt or _machine_power_off.
316 */
317
318void machine_restart(char *command)
319{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200320 if (!in_interrupt() || oops_in_progress)
321 /*
322 * Only unblank the console if we are called in enabled
323 * context or a bust_spinlocks cleared the way for us.
324 */
325 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 _machine_restart(command);
327}
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329void machine_halt(void)
330{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200331 if (!in_interrupt() || oops_in_progress)
332 /*
333 * Only unblank the console if we are called in enabled
334 * context or a bust_spinlocks cleared the way for us.
335 */
336 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 _machine_halt();
338}
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340void machine_power_off(void)
341{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200342 if (!in_interrupt() || oops_in_progress)
343 /*
344 * Only unblank the console if we are called in enabled
345 * context or a bust_spinlocks cleared the way for us.
346 */
347 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 _machine_power_off();
349}
350
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800351/*
352 * Dummy power off function.
353 */
354void (*pm_power_off)(void) = machine_power_off;
355
Heiko Carstens59685292006-03-24 03:15:15 -0800356static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700357{
Heiko Carstens59685292006-03-24 03:15:15 -0800358 memory_end = memparse(p, &p);
359 return 0;
360}
361early_param("mem", early_parse_mem);
362
363/*
364 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
365 */
366static int __init early_parse_ipldelay(char *p)
367{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700368 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Heiko Carstens59685292006-03-24 03:15:15 -0800370 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Heiko Carstens59685292006-03-24 03:15:15 -0800372 switch (*p) {
373 case 's':
374 case 'S':
375 delay *= 1000000;
376 break;
377 case 'm':
378 case 'M':
379 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
Heiko Carstens59685292006-03-24 03:15:15 -0800381
382 /* now wait for the requested amount of time */
383 udelay(delay);
384
385 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700386}
Heiko Carstens59685292006-03-24 03:15:15 -0800387early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Heiko Carstensc9e37352005-05-01 08:58:57 -0700389static void __init
390setup_lowcore(void)
391{
392 struct _lowcore *lc;
393 int lc_pages;
394
395 /*
396 * Setup lowcore for boot cpu
397 */
398 lc_pages = sizeof(void *) == 8 ? 2 : 1;
399 lc = (struct _lowcore *)
400 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
401 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700402 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 lc->restart_psw.addr =
404 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
405 lc->external_new_psw.mask = PSW_KERNEL_BITS;
406 lc->external_new_psw.addr =
407 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
408 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
409 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
410 lc->program_new_psw.mask = PSW_KERNEL_BITS;
411 lc->program_new_psw.addr =
412 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700413 lc->mcck_new_psw.mask =
414 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 lc->mcck_new_psw.addr =
416 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
417 lc->io_new_psw.mask = PSW_KERNEL_BITS;
418 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
419 lc->ipl_device = S390_lowcore.ipl_device;
420 lc->jiffy_timer = -1LL;
421 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
422 lc->async_stack = (unsigned long)
423 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 lc->panic_stack = (unsigned long)
425 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
427 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800428#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700429 if (MACHINE_HAS_IEEE) {
430 lc->extended_save_area_addr = (__u32)
431 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
432 /* enable extended save area */
Heiko Carstensc4972f32006-11-06 10:49:02 +0100433 __ctl_set_bit(14, 29);
Heiko Carstens77fa2242005-06-25 14:55:30 -0700434 }
435#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700437}
438
439static void __init
440setup_resources(void)
441{
442 struct resource *res;
443 int i;
444
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700445 code_resource.start = (unsigned long) &_text;
446 code_resource.end = (unsigned long) &_etext - 1;
447 data_resource.start = (unsigned long) &_etext;
448 data_resource.end = (unsigned long) &_edata - 1;
449
Heiko Carstensc9e37352005-05-01 08:58:57 -0700450 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
451 res = alloc_bootmem_low(sizeof(struct resource));
452 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
453 switch (memory_chunk[i].type) {
454 case CHUNK_READ_WRITE:
455 res->name = "System RAM";
456 break;
457 case CHUNK_READ_ONLY:
458 res->name = "System ROM";
459 res->flags |= IORESOURCE_READONLY;
460 break;
461 default:
462 res->name = "reserved";
463 }
464 res->start = memory_chunk[i].addr;
465 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
466 request_resource(&iomem_resource, res);
467 request_resource(res, &code_resource);
468 request_resource(res, &data_resource);
469 }
470}
471
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100472static void __init setup_memory_end(void)
473{
474 unsigned long real_size, memory_size;
475 unsigned long max_mem, max_phys;
476 int i;
477
478 memory_size = real_size = 0;
479 max_phys = VMALLOC_END - VMALLOC_MIN_SIZE;
480 memory_end &= PAGE_MASK;
481
482 max_mem = memory_end ? min(max_phys, memory_end) : max_phys;
483
484 for (i = 0; i < MEMORY_CHUNKS; i++) {
485 struct mem_chunk *chunk = &memory_chunk[i];
486
487 real_size = max(real_size, chunk->addr + chunk->size);
488 if (chunk->addr >= max_mem) {
489 memset(chunk, 0, sizeof(*chunk));
490 continue;
491 }
492 if (chunk->addr + chunk->size > max_mem)
493 chunk->size = max_mem - chunk->addr;
494 memory_size = max(memory_size, chunk->addr + chunk->size);
495 }
496 if (!memory_end)
497 memory_end = memory_size;
498 if (real_size > memory_end)
499 printk("More memory detected than supported. Unused: %luk\n",
500 (real_size - memory_end) >> 10);
501}
502
Heiko Carstensc9e37352005-05-01 08:58:57 -0700503static void __init
504setup_memory(void)
505{
506 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700507 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700508 int i;
509
510 /*
511 * partially used pages are not usable - thus
512 * we are rounding upwards:
513 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200514 start_pfn = PFN_UP(__pa(&_end));
515 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700516
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700517 /* Initialize storage key for kernel pages */
518 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
519 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
520
Heiko Carstens65912a82006-09-20 15:58:41 +0200521#ifdef CONFIG_BLK_DEV_INITRD
522 /*
523 * Move the initrd in case the bitmap of the bootmem allocater
524 * would overwrite it.
525 */
526
527 if (INITRD_START && INITRD_SIZE) {
528 unsigned long bmap_size;
529 unsigned long start;
530
531 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
532 bmap_size = PFN_PHYS(bmap_size);
533
534 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
535 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
536
537 if (start + INITRD_SIZE > memory_end) {
538 printk("initrd extends beyond end of memory "
539 "(0x%08lx > 0x%08lx)\n"
540 "disabling initrd\n",
541 start + INITRD_SIZE, memory_end);
542 INITRD_START = INITRD_SIZE = 0;
543 } else {
544 printk("Moving initrd (0x%08lx -> 0x%08lx, "
545 "size: %ld)\n",
546 INITRD_START, start, INITRD_SIZE);
547 memmove((void *) start, (void *) INITRD_START,
548 INITRD_SIZE);
549 INITRD_START = start;
550 }
551 }
552 }
553#endif
554
Heiko Carstensc9e37352005-05-01 08:58:57 -0700555 /*
Heiko Carstens7676bef2006-10-04 20:02:19 +0200556 * Initialize the boot-time allocator
Heiko Carstensc9e37352005-05-01 08:58:57 -0700557 */
558 bootmap_size = init_bootmem(start_pfn, end_pfn);
559
560 /*
561 * Register RAM areas with the bootmem allocator.
562 */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700563
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700564 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstens39b742f2006-12-08 15:56:10 +0100565 unsigned long start_chunk, end_chunk, pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700566
567 if (memory_chunk[i].type != CHUNK_READ_WRITE)
568 continue;
Heiko Carstens39b742f2006-12-08 15:56:10 +0100569 start_chunk = PFN_DOWN(memory_chunk[i].addr);
570 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
571 end_chunk = min(end_chunk, end_pfn);
572 if (start_chunk >= end_chunk)
573 continue;
574 add_active_range(0, start_chunk, end_chunk);
575 pfn = max(start_chunk, start_pfn);
576 for (; pfn <= end_chunk; pfn++)
577 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700578 }
579
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700580 psw_set_key(PAGE_DEFAULT_KEY);
581
Heiko Carstens39b742f2006-12-08 15:56:10 +0100582 free_bootmem_with_active_regions(0, max_pfn);
583 reserve_bootmem(0, PFN_PHYS(start_pfn));
Heiko Carstensc9e37352005-05-01 08:58:57 -0700584
585 /*
586 * Reserve the bootmem bitmap itself as well. We do this in two
587 * steps (first step was init_bootmem()) because this catches
588 * the (very unlikely) case of us accidentally initializing the
589 * bootmem allocator with an invalid RAM area.
590 */
591 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
592
593#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200594 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700595 if (INITRD_START + INITRD_SIZE <= memory_end) {
596 reserve_bootmem(INITRD_START, INITRD_SIZE);
597 initrd_start = INITRD_START;
598 initrd_end = initrd_start + INITRD_SIZE;
599 } else {
600 printk("initrd extends beyond end of memory "
601 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
602 initrd_start + INITRD_SIZE, memory_end);
603 initrd_start = initrd_end = 0;
604 }
605 }
606#endif
607}
608
609/*
610 * Setup function called from init/main.c just after the banner
611 * was printed.
612 */
613
614void __init
615setup_arch(char **cmdline_p)
616{
617 /*
618 * print what head.S has found out about the machine
619 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800620#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700621 printk((MACHINE_IS_VM) ?
622 "We are running under VM (31 bit mode)\n" :
623 "We are running native (31 bit mode)\n");
624 printk((MACHINE_HAS_IEEE) ?
625 "This machine has an IEEE fpu\n" :
626 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800627#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700628 printk((MACHINE_IS_VM) ?
629 "We are running under VM (64 bit mode)\n" :
630 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800631#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700632
Heiko Carstens59685292006-03-24 03:15:15 -0800633 /* Save unparsed command line copy for /proc/cmdline */
634 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
635
636 *cmdline_p = COMMAND_LINE;
637 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
638
Heiko Carstensc9e37352005-05-01 08:58:57 -0700639 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800640
641 init_mm.start_code = PAGE_OFFSET;
642 init_mm.end_code = (unsigned long) &_etext;
643 init_mm.end_data = (unsigned long) &_edata;
644 init_mm.brk = (unsigned long) &_end;
645
Gerald Schaefer6c2a9e62006-09-20 15:59:44 +0200646 if (MACHINE_HAS_MVCOS)
647 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
648 else
649 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
650
Heiko Carstens59685292006-03-24 03:15:15 -0800651 parse_early_param();
652
Heiko Carstens8b62bc92006-12-04 15:40:56 +0100653 setup_memory_end();
Heiko Carstensc9e37352005-05-01 08:58:57 -0700654 setup_memory();
655 setup_resources();
656 setup_lowcore();
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 cpu_init();
659 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800660 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 /*
663 * Create kernel page tables and switch to virtual addressing.
664 */
665 paging_init();
666
667 /* Setup default console */
668 conmode_default();
669}
670
671void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
672{
673 printk("cpu %d "
674#ifdef CONFIG_SMP
675 "phys_idx=%d "
676#endif
677 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
678 cpuinfo->cpu_nr,
679#ifdef CONFIG_SMP
680 cpuinfo->cpu_addr,
681#endif
682 cpuinfo->cpu_id.version,
683 cpuinfo->cpu_id.ident,
684 cpuinfo->cpu_id.machine,
685 cpuinfo->cpu_id.unused);
686}
687
688/*
689 * show_cpuinfo - Get information on one CPU for use by procfs.
690 */
691
692static int show_cpuinfo(struct seq_file *m, void *v)
693{
694 struct cpuinfo_S390 *cpuinfo;
695 unsigned long n = (unsigned long) v - 1;
696
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700697 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (!n) {
699 seq_printf(m, "vendor_id : IBM/S390\n"
700 "# processors : %i\n"
701 "bogomips per cpu: %lu.%02lu\n",
702 num_online_cpus(), loops_per_jiffy/(500000/HZ),
703 (loops_per_jiffy/(5000/HZ))%100);
704 }
705 if (cpu_online(n)) {
706#ifdef CONFIG_SMP
707 if (smp_processor_id() == n)
708 cpuinfo = &S390_lowcore.cpu_data;
709 else
710 cpuinfo = &lowcore_ptr[n]->cpu_data;
711#else
712 cpuinfo = &S390_lowcore.cpu_data;
713#endif
714 seq_printf(m, "processor %li: "
715 "version = %02X, "
716 "identification = %06X, "
717 "machine = %04X\n",
718 n, cpuinfo->cpu_id.version,
719 cpuinfo->cpu_id.ident,
720 cpuinfo->cpu_id.machine);
721 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700722 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 return 0;
724}
725
726static void *c_start(struct seq_file *m, loff_t *pos)
727{
728 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
729}
730static void *c_next(struct seq_file *m, void *v, loff_t *pos)
731{
732 ++*pos;
733 return c_start(m, pos);
734}
735static void c_stop(struct seq_file *m, void *v)
736{
737}
738struct seq_operations cpuinfo_op = {
739 .start = c_start,
740 .next = c_next,
741 .stop = c_stop,
742 .show = show_cpuinfo,
743};
744