blob: 49f2b68e32b13565259f7aa7a329b4b6e8a1e575 [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;
65unsigned long memory_size = 0;
66unsigned long machine_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067struct {
68 unsigned long addr, size, type;
69} memory_chunk[MEMORY_CHUNKS] = { { 0 } };
70#define CHUNK_READ_WRITE 0
71#define CHUNK_READ_ONLY 1
72volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070073static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 * This is set up by the setup-routine at boot-time
77 * for S390 need to find out, what we have to setup
78 * using address 0x10400 ...
79 */
80
81#include <asm/setup.h>
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static struct resource code_resource = {
84 .name = "Kernel code",
85 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
86};
87
88static struct resource data_resource = {
89 .name = "Kernel data",
90 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
91};
92
93/*
94 * cpu_init() initializes state that is per-CPU.
95 */
96void __devinit cpu_init (void)
97{
98 int addr = hard_smp_processor_id();
99
100 /*
101 * Store processor id in lowcore (used e.g. in timer_interrupt)
102 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200103 asm volatile("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 S390_lowcore.cpu_data.cpu_addr = addr;
105
106 /*
107 * Force FPU initialization:
108 */
109 clear_thread_flag(TIF_USEDFPU);
110 clear_used_math();
111
112 atomic_inc(&init_mm.mm_count);
113 current->active_mm = &init_mm;
114 if (current->mm)
115 BUG();
116 enter_lazy_tlb(&init_mm, current);
117}
118
119/*
120 * VM halt and poweroff setup routines
121 */
122char vmhalt_cmd[128] = "";
123char vmpoff_cmd[128] = "";
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200124char vmpanic_cmd[128] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126static inline void strncpy_skip_quote(char *dst, char *src, int n)
127{
128 int sx, dx;
129
130 dx = 0;
131 for (sx = 0; src[sx] != 0; sx++) {
132 if (src[sx] == '"') continue;
133 dst[dx++] = src[sx];
134 if (dx >= n) break;
135 }
136}
137
138static int __init vmhalt_setup(char *str)
139{
140 strncpy_skip_quote(vmhalt_cmd, str, 127);
141 vmhalt_cmd[127] = 0;
142 return 1;
143}
144
145__setup("vmhalt=", vmhalt_setup);
146
147static int __init vmpoff_setup(char *str)
148{
149 strncpy_skip_quote(vmpoff_cmd, str, 127);
150 vmpoff_cmd[127] = 0;
151 return 1;
152}
153
154__setup("vmpoff=", vmpoff_setup);
155
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200156static int vmpanic_notify(struct notifier_block *self, unsigned long event,
157 void *data)
158{
159 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
160 cpcmd(vmpanic_cmd, NULL, 0, NULL);
161
162 return NOTIFY_OK;
163}
164
165#define PANIC_PRI_VMPANIC 0
166
167static struct notifier_block vmpanic_nb = {
168 .notifier_call = vmpanic_notify,
169 .priority = PANIC_PRI_VMPANIC
170};
171
172static int __init vmpanic_setup(char *str)
173{
174 static int register_done __initdata = 0;
175
176 strncpy_skip_quote(vmpanic_cmd, str, 127);
177 vmpanic_cmd[127] = 0;
178 if (!register_done) {
179 register_done = 1;
180 atomic_notifier_chain_register(&panic_notifier_list,
181 &vmpanic_nb);
182 }
183 return 1;
184}
185
186__setup("vmpanic=", vmpanic_setup);
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/*
189 * condev= and conmode= setup parameter.
190 */
191
192static int __init condev_setup(char *str)
193{
194 int vdev;
195
196 vdev = simple_strtoul(str, &str, 0);
197 if (vdev >= 0 && vdev < 65536) {
198 console_devno = vdev;
199 console_irq = -1;
200 }
201 return 1;
202}
203
204__setup("condev=", condev_setup);
205
206static int __init conmode_setup(char *str)
207{
208#if defined(CONFIG_SCLP_CONSOLE)
209 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
210 SET_CONSOLE_SCLP;
211#endif
212#if defined(CONFIG_TN3215_CONSOLE)
213 if (strncmp(str, "3215", 5) == 0)
214 SET_CONSOLE_3215;
215#endif
216#if defined(CONFIG_TN3270_CONSOLE)
217 if (strncmp(str, "3270", 5) == 0)
218 SET_CONSOLE_3270;
219#endif
220 return 1;
221}
222
223__setup("conmode=", conmode_setup);
224
225static void __init conmode_default(void)
226{
227 char query_buffer[1024];
228 char *ptr;
229
230 if (MACHINE_IS_VM) {
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700231 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
233 ptr = strstr(query_buffer, "SUBCHANNEL =");
234 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700235 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 ptr = strstr(query_buffer, "CONMODE");
237 /*
238 * Set the conmode to 3215 so that the device recognition
239 * will set the cu_type of the console to 3215. If the
240 * conmode is 3270 and we don't set it back then both
241 * 3215 and the 3270 driver will try to access the console
242 * device (3215 as console and 3270 as normal tty).
243 */
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700244 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (ptr == NULL) {
246#if defined(CONFIG_SCLP_CONSOLE)
247 SET_CONSOLE_SCLP;
248#endif
249 return;
250 }
251 if (strncmp(ptr + 8, "3270", 4) == 0) {
252#if defined(CONFIG_TN3270_CONSOLE)
253 SET_CONSOLE_3270;
254#elif defined(CONFIG_TN3215_CONSOLE)
255 SET_CONSOLE_3215;
256#elif defined(CONFIG_SCLP_CONSOLE)
257 SET_CONSOLE_SCLP;
258#endif
259 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
260#if defined(CONFIG_TN3215_CONSOLE)
261 SET_CONSOLE_3215;
262#elif defined(CONFIG_TN3270_CONSOLE)
263 SET_CONSOLE_3270;
264#elif defined(CONFIG_SCLP_CONSOLE)
265 SET_CONSOLE_SCLP;
266#endif
267 }
268 } else if (MACHINE_IS_P390) {
269#if defined(CONFIG_TN3215_CONSOLE)
270 SET_CONSOLE_3215;
271#elif defined(CONFIG_TN3270_CONSOLE)
272 SET_CONSOLE_3270;
273#endif
274 } else {
275#if defined(CONFIG_SCLP_CONSOLE)
276 SET_CONSOLE_SCLP;
277#endif
278 }
279}
280
281#ifdef CONFIG_SMP
282extern void machine_restart_smp(char *);
283extern void machine_halt_smp(void);
284extern void machine_power_off_smp(void);
285
286void (*_machine_restart)(char *command) = machine_restart_smp;
287void (*_machine_halt)(void) = machine_halt_smp;
288void (*_machine_power_off)(void) = machine_power_off_smp;
289#else
290/*
291 * Reboot, halt and power_off routines for non SMP.
292 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293static void do_machine_restart_nonsmp(char * __unused)
294{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200295 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
298static void do_machine_halt_nonsmp(void)
299{
300 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800301 cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
303}
304
305static void do_machine_power_off_nonsmp(void)
306{
307 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800308 cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
310}
311
312void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
313void (*_machine_halt)(void) = do_machine_halt_nonsmp;
314void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
315#endif
316
317 /*
318 * Reboot, halt and power_off stubs. They just call _machine_restart,
319 * _machine_halt or _machine_power_off.
320 */
321
322void machine_restart(char *command)
323{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200324 if (!in_interrupt() || oops_in_progress)
325 /*
326 * Only unblank the console if we are called in enabled
327 * context or a bust_spinlocks cleared the way for us.
328 */
329 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 _machine_restart(command);
331}
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333void machine_halt(void)
334{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200335 if (!in_interrupt() || oops_in_progress)
336 /*
337 * Only unblank the console if we are called in enabled
338 * context or a bust_spinlocks cleared the way for us.
339 */
340 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 _machine_halt();
342}
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344void machine_power_off(void)
345{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200346 if (!in_interrupt() || oops_in_progress)
347 /*
348 * Only unblank the console if we are called in enabled
349 * context or a bust_spinlocks cleared the way for us.
350 */
351 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 _machine_power_off();
353}
354
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800355/*
356 * Dummy power off function.
357 */
358void (*pm_power_off)(void) = machine_power_off;
359
Heiko Carstens59685292006-03-24 03:15:15 -0800360static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700361{
Heiko Carstens59685292006-03-24 03:15:15 -0800362 memory_end = memparse(p, &p);
363 return 0;
364}
365early_param("mem", early_parse_mem);
366
367/*
368 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
369 */
370static int __init early_parse_ipldelay(char *p)
371{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700372 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Heiko Carstens59685292006-03-24 03:15:15 -0800374 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Heiko Carstens59685292006-03-24 03:15:15 -0800376 switch (*p) {
377 case 's':
378 case 'S':
379 delay *= 1000000;
380 break;
381 case 'm':
382 case 'M':
383 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
Heiko Carstens59685292006-03-24 03:15:15 -0800385
386 /* now wait for the requested amount of time */
387 udelay(delay);
388
389 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700390}
Heiko Carstens59685292006-03-24 03:15:15 -0800391early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Heiko Carstensc9e37352005-05-01 08:58:57 -0700393static void __init
394setup_lowcore(void)
395{
396 struct _lowcore *lc;
397 int lc_pages;
398
399 /*
400 * Setup lowcore for boot cpu
401 */
402 lc_pages = sizeof(void *) == 8 ? 2 : 1;
403 lc = (struct _lowcore *)
404 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
405 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700406 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 lc->restart_psw.addr =
408 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
409 lc->external_new_psw.mask = PSW_KERNEL_BITS;
410 lc->external_new_psw.addr =
411 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
412 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
413 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
414 lc->program_new_psw.mask = PSW_KERNEL_BITS;
415 lc->program_new_psw.addr =
416 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700417 lc->mcck_new_psw.mask =
418 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 lc->mcck_new_psw.addr =
420 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
421 lc->io_new_psw.mask = PSW_KERNEL_BITS;
422 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
423 lc->ipl_device = S390_lowcore.ipl_device;
424 lc->jiffy_timer = -1LL;
425 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
426 lc->async_stack = (unsigned long)
427 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 lc->panic_stack = (unsigned long)
429 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
431 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800432#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700433 if (MACHINE_HAS_IEEE) {
434 lc->extended_save_area_addr = (__u32)
435 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
436 /* enable extended save area */
437 ctl_set_bit(14, 29);
438 }
439#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700441}
442
443static void __init
444setup_resources(void)
445{
446 struct resource *res;
447 int i;
448
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700449 code_resource.start = (unsigned long) &_text;
450 code_resource.end = (unsigned long) &_etext - 1;
451 data_resource.start = (unsigned long) &_etext;
452 data_resource.end = (unsigned long) &_edata - 1;
453
Heiko Carstensc9e37352005-05-01 08:58:57 -0700454 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
455 res = alloc_bootmem_low(sizeof(struct resource));
456 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
457 switch (memory_chunk[i].type) {
458 case CHUNK_READ_WRITE:
459 res->name = "System RAM";
460 break;
461 case CHUNK_READ_ONLY:
462 res->name = "System ROM";
463 res->flags |= IORESOURCE_READONLY;
464 break;
465 default:
466 res->name = "reserved";
467 }
468 res->start = memory_chunk[i].addr;
469 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
470 request_resource(&iomem_resource, res);
471 request_resource(res, &code_resource);
472 request_resource(res, &data_resource);
473 }
474}
475
476static void __init
477setup_memory(void)
478{
479 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700480 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700481 int i;
482
483 /*
484 * partially used pages are not usable - thus
485 * we are rounding upwards:
486 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200487 start_pfn = PFN_UP(__pa(&_end));
488 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700489
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700490 /* Initialize storage key for kernel pages */
491 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
492 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
493
Heiko Carstens65912a82006-09-20 15:58:41 +0200494#ifdef CONFIG_BLK_DEV_INITRD
495 /*
496 * Move the initrd in case the bitmap of the bootmem allocater
497 * would overwrite it.
498 */
499
500 if (INITRD_START && INITRD_SIZE) {
501 unsigned long bmap_size;
502 unsigned long start;
503
504 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
505 bmap_size = PFN_PHYS(bmap_size);
506
507 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
508 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
509
510 if (start + INITRD_SIZE > memory_end) {
511 printk("initrd extends beyond end of memory "
512 "(0x%08lx > 0x%08lx)\n"
513 "disabling initrd\n",
514 start + INITRD_SIZE, memory_end);
515 INITRD_START = INITRD_SIZE = 0;
516 } else {
517 printk("Moving initrd (0x%08lx -> 0x%08lx, "
518 "size: %ld)\n",
519 INITRD_START, start, INITRD_SIZE);
520 memmove((void *) start, (void *) INITRD_START,
521 INITRD_SIZE);
522 INITRD_START = start;
523 }
524 }
525 }
526#endif
527
Heiko Carstensc9e37352005-05-01 08:58:57 -0700528 /*
Heiko Carstens7676bef2006-10-04 20:02:19 +0200529 * Initialize the boot-time allocator
Heiko Carstensc9e37352005-05-01 08:58:57 -0700530 */
531 bootmap_size = init_bootmem(start_pfn, end_pfn);
532
533 /*
534 * Register RAM areas with the bootmem allocator.
535 */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700536
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700537 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstens7676bef2006-10-04 20:02:19 +0200538 unsigned long start_chunk, end_chunk, pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700539
540 if (memory_chunk[i].type != CHUNK_READ_WRITE)
541 continue;
Heiko Carstens7676bef2006-10-04 20:02:19 +0200542 start_chunk = PFN_DOWN(memory_chunk[i].addr);
543 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
544 end_chunk = min(end_chunk, end_pfn);
545 if (start_chunk >= end_chunk)
546 continue;
547 add_active_range(0, start_chunk, end_chunk);
548 pfn = max(start_chunk, start_pfn);
549 for (; pfn <= end_chunk; pfn++)
550 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700551 }
552
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700553 psw_set_key(PAGE_DEFAULT_KEY);
554
Heiko Carstens7676bef2006-10-04 20:02:19 +0200555 free_bootmem_with_active_regions(0, max_pfn);
556 reserve_bootmem(0, PFN_PHYS(start_pfn));
Heiko Carstensc9e37352005-05-01 08:58:57 -0700557
558 /*
559 * Reserve the bootmem bitmap itself as well. We do this in two
560 * steps (first step was init_bootmem()) because this catches
561 * the (very unlikely) case of us accidentally initializing the
562 * bootmem allocator with an invalid RAM area.
563 */
564 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
565
566#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200567 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700568 if (INITRD_START + INITRD_SIZE <= memory_end) {
569 reserve_bootmem(INITRD_START, INITRD_SIZE);
570 initrd_start = INITRD_START;
571 initrd_end = initrd_start + INITRD_SIZE;
572 } else {
573 printk("initrd extends beyond end of memory "
574 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
575 initrd_start + INITRD_SIZE, memory_end);
576 initrd_start = initrd_end = 0;
577 }
578 }
579#endif
580}
581
582/*
583 * Setup function called from init/main.c just after the banner
584 * was printed.
585 */
586
587void __init
588setup_arch(char **cmdline_p)
589{
590 /*
591 * print what head.S has found out about the machine
592 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800593#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700594 printk((MACHINE_IS_VM) ?
595 "We are running under VM (31 bit mode)\n" :
596 "We are running native (31 bit mode)\n");
597 printk((MACHINE_HAS_IEEE) ?
598 "This machine has an IEEE fpu\n" :
599 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800600#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700601 printk((MACHINE_IS_VM) ?
602 "We are running under VM (64 bit mode)\n" :
603 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800604#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700605
Heiko Carstens59685292006-03-24 03:15:15 -0800606 /* Save unparsed command line copy for /proc/cmdline */
607 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
608
609 *cmdline_p = COMMAND_LINE;
610 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
611
Heiko Carstensc9e37352005-05-01 08:58:57 -0700612 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800613
614 init_mm.start_code = PAGE_OFFSET;
615 init_mm.end_code = (unsigned long) &_etext;
616 init_mm.end_data = (unsigned long) &_edata;
617 init_mm.brk = (unsigned long) &_end;
618
619 memory_end = memory_size;
620
Gerald Schaefer6c2a9e62006-09-20 15:59:44 +0200621 if (MACHINE_HAS_MVCOS)
622 memcpy(&uaccess, &uaccess_mvcos, sizeof(uaccess));
623 else
624 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
625
Heiko Carstens59685292006-03-24 03:15:15 -0800626 parse_early_param();
627
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800628#ifndef CONFIG_64BIT
Heiko Carstens59685292006-03-24 03:15:15 -0800629 memory_end &= ~0x400000UL;
630
Heiko Carstensc9e37352005-05-01 08:58:57 -0700631 /*
632 * We need some free virtual space to be able to do vmalloc.
633 * On a machine with 2GB memory we make sure that we have at
634 * least 128 MB free space for vmalloc.
635 */
636 if (memory_end > 1920*1024*1024)
637 memory_end = 1920*1024*1024;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800638#else /* CONFIG_64BIT */
Heiko Carstens59685292006-03-24 03:15:15 -0800639 memory_end &= ~0x200000UL;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800640#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700641
Heiko Carstensc9e37352005-05-01 08:58:57 -0700642 setup_memory();
643 setup_resources();
644 setup_lowcore();
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 cpu_init();
647 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800648 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 /*
651 * Create kernel page tables and switch to virtual addressing.
652 */
653 paging_init();
654
655 /* Setup default console */
656 conmode_default();
657}
658
659void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
660{
661 printk("cpu %d "
662#ifdef CONFIG_SMP
663 "phys_idx=%d "
664#endif
665 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
666 cpuinfo->cpu_nr,
667#ifdef CONFIG_SMP
668 cpuinfo->cpu_addr,
669#endif
670 cpuinfo->cpu_id.version,
671 cpuinfo->cpu_id.ident,
672 cpuinfo->cpu_id.machine,
673 cpuinfo->cpu_id.unused);
674}
675
676/*
677 * show_cpuinfo - Get information on one CPU for use by procfs.
678 */
679
680static int show_cpuinfo(struct seq_file *m, void *v)
681{
682 struct cpuinfo_S390 *cpuinfo;
683 unsigned long n = (unsigned long) v - 1;
684
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700685 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (!n) {
687 seq_printf(m, "vendor_id : IBM/S390\n"
688 "# processors : %i\n"
689 "bogomips per cpu: %lu.%02lu\n",
690 num_online_cpus(), loops_per_jiffy/(500000/HZ),
691 (loops_per_jiffy/(5000/HZ))%100);
692 }
693 if (cpu_online(n)) {
694#ifdef CONFIG_SMP
695 if (smp_processor_id() == n)
696 cpuinfo = &S390_lowcore.cpu_data;
697 else
698 cpuinfo = &lowcore_ptr[n]->cpu_data;
699#else
700 cpuinfo = &S390_lowcore.cpu_data;
701#endif
702 seq_printf(m, "processor %li: "
703 "version = %02X, "
704 "identification = %06X, "
705 "machine = %04X\n",
706 n, cpuinfo->cpu_id.version,
707 cpuinfo->cpu_id.ident,
708 cpuinfo->cpu_id.machine);
709 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700710 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 return 0;
712}
713
714static void *c_start(struct seq_file *m, loff_t *pos)
715{
716 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
717}
718static void *c_next(struct seq_file *m, void *v, loff_t *pos)
719{
720 ++*pos;
721 return c_start(m, pos);
722}
723static void c_stop(struct seq_file *m, void *v)
724{
725}
726struct seq_operations cpuinfo_op = {
727 .start = c_start,
728 .next = c_next,
729 .stop = c_stop,
730 .show = show_cpuinfo,
731};
732