blob: f2a9165ca4f8688df3fbec1bbeb3291b1cddb8d6 [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/*
54 * Machine setup..
55 */
56unsigned int console_mode = 0;
57unsigned int console_devno = -1;
58unsigned int console_irq = -1;
59unsigned long memory_size = 0;
60unsigned long machine_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061struct {
62 unsigned long addr, size, type;
63} memory_chunk[MEMORY_CHUNKS] = { { 0 } };
64#define CHUNK_READ_WRITE 0
65#define CHUNK_READ_ONLY 1
66volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070067unsigned long __initdata zholes_size[MAX_NR_ZONES];
68static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * This is set up by the setup-routine at boot-time
72 * for S390 need to find out, what we have to setup
73 * using address 0x10400 ...
74 */
75
76#include <asm/setup.h>
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static struct resource code_resource = {
79 .name = "Kernel code",
80 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
81};
82
83static struct resource data_resource = {
84 .name = "Kernel data",
85 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
86};
87
88/*
89 * cpu_init() initializes state that is per-CPU.
90 */
91void __devinit cpu_init (void)
92{
93 int addr = hard_smp_processor_id();
94
95 /*
96 * Store processor id in lowcore (used e.g. in timer_interrupt)
97 */
98 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
99 S390_lowcore.cpu_data.cpu_addr = addr;
100
101 /*
102 * Force FPU initialization:
103 */
104 clear_thread_flag(TIF_USEDFPU);
105 clear_used_math();
106
107 atomic_inc(&init_mm.mm_count);
108 current->active_mm = &init_mm;
109 if (current->mm)
110 BUG();
111 enter_lazy_tlb(&init_mm, current);
112}
113
114/*
115 * VM halt and poweroff setup routines
116 */
117char vmhalt_cmd[128] = "";
118char vmpoff_cmd[128] = "";
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200119char vmpanic_cmd[128] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121static inline void strncpy_skip_quote(char *dst, char *src, int n)
122{
123 int sx, dx;
124
125 dx = 0;
126 for (sx = 0; src[sx] != 0; sx++) {
127 if (src[sx] == '"') continue;
128 dst[dx++] = src[sx];
129 if (dx >= n) break;
130 }
131}
132
133static int __init vmhalt_setup(char *str)
134{
135 strncpy_skip_quote(vmhalt_cmd, str, 127);
136 vmhalt_cmd[127] = 0;
137 return 1;
138}
139
140__setup("vmhalt=", vmhalt_setup);
141
142static int __init vmpoff_setup(char *str)
143{
144 strncpy_skip_quote(vmpoff_cmd, str, 127);
145 vmpoff_cmd[127] = 0;
146 return 1;
147}
148
149__setup("vmpoff=", vmpoff_setup);
150
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200151static int vmpanic_notify(struct notifier_block *self, unsigned long event,
152 void *data)
153{
154 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
155 cpcmd(vmpanic_cmd, NULL, 0, NULL);
156
157 return NOTIFY_OK;
158}
159
160#define PANIC_PRI_VMPANIC 0
161
162static struct notifier_block vmpanic_nb = {
163 .notifier_call = vmpanic_notify,
164 .priority = PANIC_PRI_VMPANIC
165};
166
167static int __init vmpanic_setup(char *str)
168{
169 static int register_done __initdata = 0;
170
171 strncpy_skip_quote(vmpanic_cmd, str, 127);
172 vmpanic_cmd[127] = 0;
173 if (!register_done) {
174 register_done = 1;
175 atomic_notifier_chain_register(&panic_notifier_list,
176 &vmpanic_nb);
177 }
178 return 1;
179}
180
181__setup("vmpanic=", vmpanic_setup);
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/*
184 * condev= and conmode= setup parameter.
185 */
186
187static int __init condev_setup(char *str)
188{
189 int vdev;
190
191 vdev = simple_strtoul(str, &str, 0);
192 if (vdev >= 0 && vdev < 65536) {
193 console_devno = vdev;
194 console_irq = -1;
195 }
196 return 1;
197}
198
199__setup("condev=", condev_setup);
200
201static int __init conmode_setup(char *str)
202{
203#if defined(CONFIG_SCLP_CONSOLE)
204 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
205 SET_CONSOLE_SCLP;
206#endif
207#if defined(CONFIG_TN3215_CONSOLE)
208 if (strncmp(str, "3215", 5) == 0)
209 SET_CONSOLE_3215;
210#endif
211#if defined(CONFIG_TN3270_CONSOLE)
212 if (strncmp(str, "3270", 5) == 0)
213 SET_CONSOLE_3270;
214#endif
215 return 1;
216}
217
218__setup("conmode=", conmode_setup);
219
220static void __init conmode_default(void)
221{
222 char query_buffer[1024];
223 char *ptr;
224
225 if (MACHINE_IS_VM) {
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700226 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
228 ptr = strstr(query_buffer, "SUBCHANNEL =");
229 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700230 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 ptr = strstr(query_buffer, "CONMODE");
232 /*
233 * Set the conmode to 3215 so that the device recognition
234 * will set the cu_type of the console to 3215. If the
235 * conmode is 3270 and we don't set it back then both
236 * 3215 and the 3270 driver will try to access the console
237 * device (3215 as console and 3270 as normal tty).
238 */
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700239 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (ptr == NULL) {
241#if defined(CONFIG_SCLP_CONSOLE)
242 SET_CONSOLE_SCLP;
243#endif
244 return;
245 }
246 if (strncmp(ptr + 8, "3270", 4) == 0) {
247#if defined(CONFIG_TN3270_CONSOLE)
248 SET_CONSOLE_3270;
249#elif defined(CONFIG_TN3215_CONSOLE)
250 SET_CONSOLE_3215;
251#elif defined(CONFIG_SCLP_CONSOLE)
252 SET_CONSOLE_SCLP;
253#endif
254 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
255#if defined(CONFIG_TN3215_CONSOLE)
256 SET_CONSOLE_3215;
257#elif defined(CONFIG_TN3270_CONSOLE)
258 SET_CONSOLE_3270;
259#elif defined(CONFIG_SCLP_CONSOLE)
260 SET_CONSOLE_SCLP;
261#endif
262 }
263 } else if (MACHINE_IS_P390) {
264#if defined(CONFIG_TN3215_CONSOLE)
265 SET_CONSOLE_3215;
266#elif defined(CONFIG_TN3270_CONSOLE)
267 SET_CONSOLE_3270;
268#endif
269 } else {
270#if defined(CONFIG_SCLP_CONSOLE)
271 SET_CONSOLE_SCLP;
272#endif
273 }
274}
275
276#ifdef CONFIG_SMP
277extern void machine_restart_smp(char *);
278extern void machine_halt_smp(void);
279extern void machine_power_off_smp(void);
280
281void (*_machine_restart)(char *command) = machine_restart_smp;
282void (*_machine_halt)(void) = machine_halt_smp;
283void (*_machine_power_off)(void) = machine_power_off_smp;
284#else
285/*
286 * Reboot, halt and power_off routines for non SMP.
287 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288static void do_machine_restart_nonsmp(char * __unused)
289{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200290 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
293static void do_machine_halt_nonsmp(void)
294{
295 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800296 cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
298}
299
300static void do_machine_power_off_nonsmp(void)
301{
302 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800303 cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
305}
306
307void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
308void (*_machine_halt)(void) = do_machine_halt_nonsmp;
309void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
310#endif
311
312 /*
313 * Reboot, halt and power_off stubs. They just call _machine_restart,
314 * _machine_halt or _machine_power_off.
315 */
316
317void machine_restart(char *command)
318{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200319 if (!in_interrupt() || oops_in_progress)
320 /*
321 * Only unblank the console if we are called in enabled
322 * context or a bust_spinlocks cleared the way for us.
323 */
324 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 _machine_restart(command);
326}
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328void machine_halt(void)
329{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200330 if (!in_interrupt() || oops_in_progress)
331 /*
332 * Only unblank the console if we are called in enabled
333 * context or a bust_spinlocks cleared the way for us.
334 */
335 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 _machine_halt();
337}
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339void machine_power_off(void)
340{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200341 if (!in_interrupt() || oops_in_progress)
342 /*
343 * Only unblank the console if we are called in enabled
344 * context or a bust_spinlocks cleared the way for us.
345 */
346 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 _machine_power_off();
348}
349
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800350/*
351 * Dummy power off function.
352 */
353void (*pm_power_off)(void) = machine_power_off;
354
Heiko Carstensc9e37352005-05-01 08:58:57 -0700355static void __init
356add_memory_hole(unsigned long start, unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700358 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Heiko Carstensc9e37352005-05-01 08:58:57 -0700360 if (end <= dma_pfn)
361 zholes_size[ZONE_DMA] += end - start + 1;
362 else if (start > dma_pfn)
363 zholes_size[ZONE_NORMAL] += end - start + 1;
364 else {
365 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
366 zholes_size[ZONE_NORMAL] += end - dma_pfn;
367 }
368}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Heiko Carstens59685292006-03-24 03:15:15 -0800370static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700371{
Heiko Carstens59685292006-03-24 03:15:15 -0800372 memory_end = memparse(p, &p);
373 return 0;
374}
375early_param("mem", early_parse_mem);
376
377/*
378 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
379 */
380static int __init early_parse_ipldelay(char *p)
381{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700382 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Heiko Carstens59685292006-03-24 03:15:15 -0800384 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Heiko Carstens59685292006-03-24 03:15:15 -0800386 switch (*p) {
387 case 's':
388 case 'S':
389 delay *= 1000000;
390 break;
391 case 'm':
392 case 'M':
393 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
Heiko Carstens59685292006-03-24 03:15:15 -0800395
396 /* now wait for the requested amount of time */
397 udelay(delay);
398
399 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700400}
Heiko Carstens59685292006-03-24 03:15:15 -0800401early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Heiko Carstensc9e37352005-05-01 08:58:57 -0700403static void __init
404setup_lowcore(void)
405{
406 struct _lowcore *lc;
407 int lc_pages;
408
409 /*
410 * Setup lowcore for boot cpu
411 */
412 lc_pages = sizeof(void *) == 8 ? 2 : 1;
413 lc = (struct _lowcore *)
414 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
415 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700416 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 lc->restart_psw.addr =
418 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
419 lc->external_new_psw.mask = PSW_KERNEL_BITS;
420 lc->external_new_psw.addr =
421 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
422 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
423 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
424 lc->program_new_psw.mask = PSW_KERNEL_BITS;
425 lc->program_new_psw.addr =
426 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700427 lc->mcck_new_psw.mask =
428 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 lc->mcck_new_psw.addr =
430 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
431 lc->io_new_psw.mask = PSW_KERNEL_BITS;
432 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
433 lc->ipl_device = S390_lowcore.ipl_device;
434 lc->jiffy_timer = -1LL;
435 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
436 lc->async_stack = (unsigned long)
437 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 lc->panic_stack = (unsigned long)
439 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
441 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800442#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700443 if (MACHINE_HAS_IEEE) {
444 lc->extended_save_area_addr = (__u32)
445 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
446 /* enable extended save area */
447 ctl_set_bit(14, 29);
448 }
449#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700451}
452
453static void __init
454setup_resources(void)
455{
456 struct resource *res;
457 int i;
458
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700459 code_resource.start = (unsigned long) &_text;
460 code_resource.end = (unsigned long) &_etext - 1;
461 data_resource.start = (unsigned long) &_etext;
462 data_resource.end = (unsigned long) &_edata - 1;
463
Heiko Carstensc9e37352005-05-01 08:58:57 -0700464 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
465 res = alloc_bootmem_low(sizeof(struct resource));
466 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
467 switch (memory_chunk[i].type) {
468 case CHUNK_READ_WRITE:
469 res->name = "System RAM";
470 break;
471 case CHUNK_READ_ONLY:
472 res->name = "System ROM";
473 res->flags |= IORESOURCE_READONLY;
474 break;
475 default:
476 res->name = "reserved";
477 }
478 res->start = memory_chunk[i].addr;
479 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
480 request_resource(&iomem_resource, res);
481 request_resource(res, &code_resource);
482 request_resource(res, &data_resource);
483 }
484}
485
486static void __init
487setup_memory(void)
488{
489 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700490 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700491 unsigned long last_rw_end;
492 int i;
493
494 /*
495 * partially used pages are not usable - thus
496 * we are rounding upwards:
497 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200498 start_pfn = PFN_UP(__pa(&_end));
499 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700500
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700501 /* Initialize storage key for kernel pages */
502 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
503 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
504
Heiko Carstens65912a82006-09-20 15:58:41 +0200505#ifdef CONFIG_BLK_DEV_INITRD
506 /*
507 * Move the initrd in case the bitmap of the bootmem allocater
508 * would overwrite it.
509 */
510
511 if (INITRD_START && INITRD_SIZE) {
512 unsigned long bmap_size;
513 unsigned long start;
514
515 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
516 bmap_size = PFN_PHYS(bmap_size);
517
518 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
519 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
520
521 if (start + INITRD_SIZE > memory_end) {
522 printk("initrd extends beyond end of memory "
523 "(0x%08lx > 0x%08lx)\n"
524 "disabling initrd\n",
525 start + INITRD_SIZE, memory_end);
526 INITRD_START = INITRD_SIZE = 0;
527 } else {
528 printk("Moving initrd (0x%08lx -> 0x%08lx, "
529 "size: %ld)\n",
530 INITRD_START, start, INITRD_SIZE);
531 memmove((void *) start, (void *) INITRD_START,
532 INITRD_SIZE);
533 INITRD_START = start;
534 }
535 }
536 }
537#endif
538
Heiko Carstensc9e37352005-05-01 08:58:57 -0700539 /*
540 * Initialize the boot-time allocator (with low memory only):
541 */
542 bootmap_size = init_bootmem(start_pfn, end_pfn);
543
544 /*
545 * Register RAM areas with the bootmem allocator.
546 */
547 last_rw_end = start_pfn;
548
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700549 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700550 unsigned long start_chunk, end_chunk;
551
552 if (memory_chunk[i].type != CHUNK_READ_WRITE)
553 continue;
554 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
555 start_chunk >>= PAGE_SHIFT;
556 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
557 end_chunk >>= PAGE_SHIFT;
558 if (start_chunk < start_pfn)
559 start_chunk = start_pfn;
560 if (end_chunk > end_pfn)
561 end_chunk = end_pfn;
562 if (start_chunk < end_chunk) {
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700563 /* Initialize storage key for RAM pages */
564 for (init_pfn = start_chunk ; init_pfn < end_chunk;
565 init_pfn++)
566 page_set_storage_key(init_pfn << PAGE_SHIFT,
567 PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700568 free_bootmem(start_chunk << PAGE_SHIFT,
569 (end_chunk - start_chunk) << PAGE_SHIFT);
570 if (last_rw_end < start_chunk)
571 add_memory_hole(last_rw_end, start_chunk - 1);
572 last_rw_end = end_chunk;
573 }
574 }
575
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700576 psw_set_key(PAGE_DEFAULT_KEY);
577
Heiko Carstensc9e37352005-05-01 08:58:57 -0700578 if (last_rw_end < end_pfn - 1)
579 add_memory_hole(last_rw_end, end_pfn - 1);
580
581 /*
582 * Reserve the bootmem bitmap itself as well. We do this in two
583 * steps (first step was init_bootmem()) because this catches
584 * the (very unlikely) case of us accidentally initializing the
585 * bootmem allocator with an invalid RAM area.
586 */
587 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
588
589#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200590 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700591 if (INITRD_START + INITRD_SIZE <= memory_end) {
592 reserve_bootmem(INITRD_START, INITRD_SIZE);
593 initrd_start = INITRD_START;
594 initrd_end = initrd_start + INITRD_SIZE;
595 } else {
596 printk("initrd extends beyond end of memory "
597 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
598 initrd_start + INITRD_SIZE, memory_end);
599 initrd_start = initrd_end = 0;
600 }
601 }
602#endif
603}
604
605/*
606 * Setup function called from init/main.c just after the banner
607 * was printed.
608 */
609
610void __init
611setup_arch(char **cmdline_p)
612{
613 /*
614 * print what head.S has found out about the machine
615 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800616#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700617 printk((MACHINE_IS_VM) ?
618 "We are running under VM (31 bit mode)\n" :
619 "We are running native (31 bit mode)\n");
620 printk((MACHINE_HAS_IEEE) ?
621 "This machine has an IEEE fpu\n" :
622 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800623#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700624 printk((MACHINE_IS_VM) ?
625 "We are running under VM (64 bit mode)\n" :
626 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800627#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700628
Heiko Carstens59685292006-03-24 03:15:15 -0800629 /* Save unparsed command line copy for /proc/cmdline */
630 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
631
632 *cmdline_p = COMMAND_LINE;
633 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
634
Heiko Carstensc9e37352005-05-01 08:58:57 -0700635 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800636
637 init_mm.start_code = PAGE_OFFSET;
638 init_mm.end_code = (unsigned long) &_etext;
639 init_mm.end_data = (unsigned long) &_edata;
640 init_mm.brk = (unsigned long) &_end;
641
642 memory_end = memory_size;
643
644 parse_early_param();
645
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800646#ifndef CONFIG_64BIT
Heiko Carstens59685292006-03-24 03:15:15 -0800647 memory_end &= ~0x400000UL;
648
Heiko Carstensc9e37352005-05-01 08:58:57 -0700649 /*
650 * We need some free virtual space to be able to do vmalloc.
651 * On a machine with 2GB memory we make sure that we have at
652 * least 128 MB free space for vmalloc.
653 */
654 if (memory_end > 1920*1024*1024)
655 memory_end = 1920*1024*1024;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800656#else /* CONFIG_64BIT */
Heiko Carstens59685292006-03-24 03:15:15 -0800657 memory_end &= ~0x200000UL;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800658#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700659
Heiko Carstensc9e37352005-05-01 08:58:57 -0700660 setup_memory();
661 setup_resources();
662 setup_lowcore();
663
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 cpu_init();
665 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800666 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
668 /*
669 * Create kernel page tables and switch to virtual addressing.
670 */
671 paging_init();
672
673 /* Setup default console */
674 conmode_default();
675}
676
677void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
678{
679 printk("cpu %d "
680#ifdef CONFIG_SMP
681 "phys_idx=%d "
682#endif
683 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
684 cpuinfo->cpu_nr,
685#ifdef CONFIG_SMP
686 cpuinfo->cpu_addr,
687#endif
688 cpuinfo->cpu_id.version,
689 cpuinfo->cpu_id.ident,
690 cpuinfo->cpu_id.machine,
691 cpuinfo->cpu_id.unused);
692}
693
694/*
695 * show_cpuinfo - Get information on one CPU for use by procfs.
696 */
697
698static int show_cpuinfo(struct seq_file *m, void *v)
699{
700 struct cpuinfo_S390 *cpuinfo;
701 unsigned long n = (unsigned long) v - 1;
702
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700703 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (!n) {
705 seq_printf(m, "vendor_id : IBM/S390\n"
706 "# processors : %i\n"
707 "bogomips per cpu: %lu.%02lu\n",
708 num_online_cpus(), loops_per_jiffy/(500000/HZ),
709 (loops_per_jiffy/(5000/HZ))%100);
710 }
711 if (cpu_online(n)) {
712#ifdef CONFIG_SMP
713 if (smp_processor_id() == n)
714 cpuinfo = &S390_lowcore.cpu_data;
715 else
716 cpuinfo = &lowcore_ptr[n]->cpu_data;
717#else
718 cpuinfo = &S390_lowcore.cpu_data;
719#endif
720 seq_printf(m, "processor %li: "
721 "version = %02X, "
722 "identification = %06X, "
723 "machine = %04X\n",
724 n, cpuinfo->cpu_id.version,
725 cpuinfo->cpu_id.ident,
726 cpuinfo->cpu_id.machine);
727 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700728 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return 0;
730}
731
732static void *c_start(struct seq_file *m, loff_t *pos)
733{
734 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
735}
736static void *c_next(struct seq_file *m, void *v, loff_t *pos)
737{
738 ++*pos;
739 return c_start(m, pos);
740}
741static void c_stop(struct seq_file *m, void *v)
742{
743}
744struct seq_operations cpuinfo_op = {
745 .start = c_start,
746 .next = c_next,
747 .stop = c_stop,
748 .show = show_cpuinfo,
749};
750