blob: e229af59976c5aa4d3c389b59d10d78228bf7445 [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 -070073unsigned long __initdata zholes_size[MAX_NR_ZONES];
74static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 * This is set up by the setup-routine at boot-time
78 * for S390 need to find out, what we have to setup
79 * using address 0x10400 ...
80 */
81
82#include <asm/setup.h>
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static struct resource code_resource = {
85 .name = "Kernel code",
86 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
87};
88
89static struct resource data_resource = {
90 .name = "Kernel data",
91 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
92};
93
94/*
95 * cpu_init() initializes state that is per-CPU.
96 */
97void __devinit cpu_init (void)
98{
99 int addr = hard_smp_processor_id();
100
101 /*
102 * Store processor id in lowcore (used e.g. in timer_interrupt)
103 */
104 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
105 S390_lowcore.cpu_data.cpu_addr = addr;
106
107 /*
108 * Force FPU initialization:
109 */
110 clear_thread_flag(TIF_USEDFPU);
111 clear_used_math();
112
113 atomic_inc(&init_mm.mm_count);
114 current->active_mm = &init_mm;
115 if (current->mm)
116 BUG();
117 enter_lazy_tlb(&init_mm, current);
118}
119
120/*
121 * VM halt and poweroff setup routines
122 */
123char vmhalt_cmd[128] = "";
124char vmpoff_cmd[128] = "";
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200125char vmpanic_cmd[128] = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127static inline void strncpy_skip_quote(char *dst, char *src, int n)
128{
129 int sx, dx;
130
131 dx = 0;
132 for (sx = 0; src[sx] != 0; sx++) {
133 if (src[sx] == '"') continue;
134 dst[dx++] = src[sx];
135 if (dx >= n) break;
136 }
137}
138
139static int __init vmhalt_setup(char *str)
140{
141 strncpy_skip_quote(vmhalt_cmd, str, 127);
142 vmhalt_cmd[127] = 0;
143 return 1;
144}
145
146__setup("vmhalt=", vmhalt_setup);
147
148static int __init vmpoff_setup(char *str)
149{
150 strncpy_skip_quote(vmpoff_cmd, str, 127);
151 vmpoff_cmd[127] = 0;
152 return 1;
153}
154
155__setup("vmpoff=", vmpoff_setup);
156
Peter Oberparleiter585c3042006-06-29 15:08:25 +0200157static int vmpanic_notify(struct notifier_block *self, unsigned long event,
158 void *data)
159{
160 if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
161 cpcmd(vmpanic_cmd, NULL, 0, NULL);
162
163 return NOTIFY_OK;
164}
165
166#define PANIC_PRI_VMPANIC 0
167
168static struct notifier_block vmpanic_nb = {
169 .notifier_call = vmpanic_notify,
170 .priority = PANIC_PRI_VMPANIC
171};
172
173static int __init vmpanic_setup(char *str)
174{
175 static int register_done __initdata = 0;
176
177 strncpy_skip_quote(vmpanic_cmd, str, 127);
178 vmpanic_cmd[127] = 0;
179 if (!register_done) {
180 register_done = 1;
181 atomic_notifier_chain_register(&panic_notifier_list,
182 &vmpanic_nb);
183 }
184 return 1;
185}
186
187__setup("vmpanic=", vmpanic_setup);
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/*
190 * condev= and conmode= setup parameter.
191 */
192
193static int __init condev_setup(char *str)
194{
195 int vdev;
196
197 vdev = simple_strtoul(str, &str, 0);
198 if (vdev >= 0 && vdev < 65536) {
199 console_devno = vdev;
200 console_irq = -1;
201 }
202 return 1;
203}
204
205__setup("condev=", condev_setup);
206
207static int __init conmode_setup(char *str)
208{
209#if defined(CONFIG_SCLP_CONSOLE)
210 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
211 SET_CONSOLE_SCLP;
212#endif
213#if defined(CONFIG_TN3215_CONSOLE)
214 if (strncmp(str, "3215", 5) == 0)
215 SET_CONSOLE_3215;
216#endif
217#if defined(CONFIG_TN3270_CONSOLE)
218 if (strncmp(str, "3270", 5) == 0)
219 SET_CONSOLE_3270;
220#endif
221 return 1;
222}
223
224__setup("conmode=", conmode_setup);
225
226static void __init conmode_default(void)
227{
228 char query_buffer[1024];
229 char *ptr;
230
231 if (MACHINE_IS_VM) {
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700232 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
234 ptr = strstr(query_buffer, "SUBCHANNEL =");
235 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700236 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 ptr = strstr(query_buffer, "CONMODE");
238 /*
239 * Set the conmode to 3215 so that the device recognition
240 * will set the cu_type of the console to 3215. If the
241 * conmode is 3270 and we don't set it back then both
242 * 3215 and the 3270 driver will try to access the console
243 * device (3215 as console and 3270 as normal tty).
244 */
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700245 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (ptr == NULL) {
247#if defined(CONFIG_SCLP_CONSOLE)
248 SET_CONSOLE_SCLP;
249#endif
250 return;
251 }
252 if (strncmp(ptr + 8, "3270", 4) == 0) {
253#if defined(CONFIG_TN3270_CONSOLE)
254 SET_CONSOLE_3270;
255#elif defined(CONFIG_TN3215_CONSOLE)
256 SET_CONSOLE_3215;
257#elif defined(CONFIG_SCLP_CONSOLE)
258 SET_CONSOLE_SCLP;
259#endif
260 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
261#if defined(CONFIG_TN3215_CONSOLE)
262 SET_CONSOLE_3215;
263#elif defined(CONFIG_TN3270_CONSOLE)
264 SET_CONSOLE_3270;
265#elif defined(CONFIG_SCLP_CONSOLE)
266 SET_CONSOLE_SCLP;
267#endif
268 }
269 } else if (MACHINE_IS_P390) {
270#if defined(CONFIG_TN3215_CONSOLE)
271 SET_CONSOLE_3215;
272#elif defined(CONFIG_TN3270_CONSOLE)
273 SET_CONSOLE_3270;
274#endif
275 } else {
276#if defined(CONFIG_SCLP_CONSOLE)
277 SET_CONSOLE_SCLP;
278#endif
279 }
280}
281
282#ifdef CONFIG_SMP
283extern void machine_restart_smp(char *);
284extern void machine_halt_smp(void);
285extern void machine_power_off_smp(void);
286
287void (*_machine_restart)(char *command) = machine_restart_smp;
288void (*_machine_halt)(void) = machine_halt_smp;
289void (*_machine_power_off)(void) = machine_power_off_smp;
290#else
291/*
292 * Reboot, halt and power_off routines for non SMP.
293 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294static void do_machine_restart_nonsmp(char * __unused)
295{
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200296 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
299static void do_machine_halt_nonsmp(void)
300{
301 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800302 cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
304}
305
306static void do_machine_power_off_nonsmp(void)
307{
308 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800309 cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
311}
312
313void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
314void (*_machine_halt)(void) = do_machine_halt_nonsmp;
315void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
316#endif
317
318 /*
319 * Reboot, halt and power_off stubs. They just call _machine_restart,
320 * _machine_halt or _machine_power_off.
321 */
322
323void machine_restart(char *command)
324{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200325 if (!in_interrupt() || oops_in_progress)
326 /*
327 * Only unblank the console if we are called in enabled
328 * context or a bust_spinlocks cleared the way for us.
329 */
330 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 _machine_restart(command);
332}
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334void machine_halt(void)
335{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200336 if (!in_interrupt() || oops_in_progress)
337 /*
338 * Only unblank the console if we are called in enabled
339 * context or a bust_spinlocks cleared the way for us.
340 */
341 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 _machine_halt();
343}
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345void machine_power_off(void)
346{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200347 if (!in_interrupt() || oops_in_progress)
348 /*
349 * Only unblank the console if we are called in enabled
350 * context or a bust_spinlocks cleared the way for us.
351 */
352 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 _machine_power_off();
354}
355
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800356/*
357 * Dummy power off function.
358 */
359void (*pm_power_off)(void) = machine_power_off;
360
Heiko Carstensc9e37352005-05-01 08:58:57 -0700361static void __init
362add_memory_hole(unsigned long start, unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700364 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Heiko Carstensc9e37352005-05-01 08:58:57 -0700366 if (end <= dma_pfn)
367 zholes_size[ZONE_DMA] += end - start + 1;
368 else if (start > dma_pfn)
369 zholes_size[ZONE_NORMAL] += end - start + 1;
370 else {
371 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
372 zholes_size[ZONE_NORMAL] += end - dma_pfn;
373 }
374}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Heiko Carstens59685292006-03-24 03:15:15 -0800376static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700377{
Heiko Carstens59685292006-03-24 03:15:15 -0800378 memory_end = memparse(p, &p);
379 return 0;
380}
381early_param("mem", early_parse_mem);
382
383/*
384 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
385 */
386static int __init early_parse_ipldelay(char *p)
387{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700388 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Heiko Carstens59685292006-03-24 03:15:15 -0800390 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Heiko Carstens59685292006-03-24 03:15:15 -0800392 switch (*p) {
393 case 's':
394 case 'S':
395 delay *= 1000000;
396 break;
397 case 'm':
398 case 'M':
399 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
Heiko Carstens59685292006-03-24 03:15:15 -0800401
402 /* now wait for the requested amount of time */
403 udelay(delay);
404
405 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700406}
Heiko Carstens59685292006-03-24 03:15:15 -0800407early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Heiko Carstensc9e37352005-05-01 08:58:57 -0700409static void __init
410setup_lowcore(void)
411{
412 struct _lowcore *lc;
413 int lc_pages;
414
415 /*
416 * Setup lowcore for boot cpu
417 */
418 lc_pages = sizeof(void *) == 8 ? 2 : 1;
419 lc = (struct _lowcore *)
420 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
421 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700422 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 lc->restart_psw.addr =
424 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
425 lc->external_new_psw.mask = PSW_KERNEL_BITS;
426 lc->external_new_psw.addr =
427 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
428 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
429 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
430 lc->program_new_psw.mask = PSW_KERNEL_BITS;
431 lc->program_new_psw.addr =
432 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700433 lc->mcck_new_psw.mask =
434 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 lc->mcck_new_psw.addr =
436 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
437 lc->io_new_psw.mask = PSW_KERNEL_BITS;
438 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
439 lc->ipl_device = S390_lowcore.ipl_device;
440 lc->jiffy_timer = -1LL;
441 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
442 lc->async_stack = (unsigned long)
443 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 lc->panic_stack = (unsigned long)
445 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
447 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800448#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700449 if (MACHINE_HAS_IEEE) {
450 lc->extended_save_area_addr = (__u32)
451 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
452 /* enable extended save area */
453 ctl_set_bit(14, 29);
454 }
455#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700457}
458
459static void __init
460setup_resources(void)
461{
462 struct resource *res;
463 int i;
464
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700465 code_resource.start = (unsigned long) &_text;
466 code_resource.end = (unsigned long) &_etext - 1;
467 data_resource.start = (unsigned long) &_etext;
468 data_resource.end = (unsigned long) &_edata - 1;
469
Heiko Carstensc9e37352005-05-01 08:58:57 -0700470 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
471 res = alloc_bootmem_low(sizeof(struct resource));
472 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
473 switch (memory_chunk[i].type) {
474 case CHUNK_READ_WRITE:
475 res->name = "System RAM";
476 break;
477 case CHUNK_READ_ONLY:
478 res->name = "System ROM";
479 res->flags |= IORESOURCE_READONLY;
480 break;
481 default:
482 res->name = "reserved";
483 }
484 res->start = memory_chunk[i].addr;
485 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
486 request_resource(&iomem_resource, res);
487 request_resource(res, &code_resource);
488 request_resource(res, &data_resource);
489 }
490}
491
492static void __init
493setup_memory(void)
494{
495 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700496 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700497 unsigned long last_rw_end;
498 int i;
499
500 /*
501 * partially used pages are not usable - thus
502 * we are rounding upwards:
503 */
Heiko Carstens65912a82006-09-20 15:58:41 +0200504 start_pfn = PFN_UP(__pa(&_end));
505 end_pfn = max_pfn = PFN_DOWN(memory_end);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700506
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700507 /* Initialize storage key for kernel pages */
508 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
509 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
510
Heiko Carstens65912a82006-09-20 15:58:41 +0200511#ifdef CONFIG_BLK_DEV_INITRD
512 /*
513 * Move the initrd in case the bitmap of the bootmem allocater
514 * would overwrite it.
515 */
516
517 if (INITRD_START && INITRD_SIZE) {
518 unsigned long bmap_size;
519 unsigned long start;
520
521 bmap_size = bootmem_bootmap_pages(end_pfn - start_pfn + 1);
522 bmap_size = PFN_PHYS(bmap_size);
523
524 if (PFN_PHYS(start_pfn) + bmap_size > INITRD_START) {
525 start = PFN_PHYS(start_pfn) + bmap_size + PAGE_SIZE;
526
527 if (start + INITRD_SIZE > memory_end) {
528 printk("initrd extends beyond end of memory "
529 "(0x%08lx > 0x%08lx)\n"
530 "disabling initrd\n",
531 start + INITRD_SIZE, memory_end);
532 INITRD_START = INITRD_SIZE = 0;
533 } else {
534 printk("Moving initrd (0x%08lx -> 0x%08lx, "
535 "size: %ld)\n",
536 INITRD_START, start, INITRD_SIZE);
537 memmove((void *) start, (void *) INITRD_START,
538 INITRD_SIZE);
539 INITRD_START = start;
540 }
541 }
542 }
543#endif
544
Heiko Carstensc9e37352005-05-01 08:58:57 -0700545 /*
546 * Initialize the boot-time allocator (with low memory only):
547 */
548 bootmap_size = init_bootmem(start_pfn, end_pfn);
549
550 /*
551 * Register RAM areas with the bootmem allocator.
552 */
553 last_rw_end = start_pfn;
554
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700555 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700556 unsigned long start_chunk, end_chunk;
557
558 if (memory_chunk[i].type != CHUNK_READ_WRITE)
559 continue;
560 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
561 start_chunk >>= PAGE_SHIFT;
562 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
563 end_chunk >>= PAGE_SHIFT;
564 if (start_chunk < start_pfn)
565 start_chunk = start_pfn;
566 if (end_chunk > end_pfn)
567 end_chunk = end_pfn;
568 if (start_chunk < end_chunk) {
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700569 /* Initialize storage key for RAM pages */
570 for (init_pfn = start_chunk ; init_pfn < end_chunk;
571 init_pfn++)
572 page_set_storage_key(init_pfn << PAGE_SHIFT,
573 PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700574 free_bootmem(start_chunk << PAGE_SHIFT,
575 (end_chunk - start_chunk) << PAGE_SHIFT);
576 if (last_rw_end < start_chunk)
577 add_memory_hole(last_rw_end, start_chunk - 1);
578 last_rw_end = end_chunk;
579 }
580 }
581
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700582 psw_set_key(PAGE_DEFAULT_KEY);
583
Heiko Carstensc9e37352005-05-01 08:58:57 -0700584 if (last_rw_end < end_pfn - 1)
585 add_memory_hole(last_rw_end, end_pfn - 1);
586
587 /*
588 * Reserve the bootmem bitmap itself as well. We do this in two
589 * steps (first step was init_bootmem()) because this catches
590 * the (very unlikely) case of us accidentally initializing the
591 * bootmem allocator with an invalid RAM area.
592 */
593 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
594
595#ifdef CONFIG_BLK_DEV_INITRD
Heiko Carstens65912a82006-09-20 15:58:41 +0200596 if (INITRD_START && INITRD_SIZE) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700597 if (INITRD_START + INITRD_SIZE <= memory_end) {
598 reserve_bootmem(INITRD_START, INITRD_SIZE);
599 initrd_start = INITRD_START;
600 initrd_end = initrd_start + INITRD_SIZE;
601 } else {
602 printk("initrd extends beyond end of memory "
603 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
604 initrd_start + INITRD_SIZE, memory_end);
605 initrd_start = initrd_end = 0;
606 }
607 }
608#endif
609}
610
611/*
612 * Setup function called from init/main.c just after the banner
613 * was printed.
614 */
615
616void __init
617setup_arch(char **cmdline_p)
618{
619 /*
620 * print what head.S has found out about the machine
621 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800622#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700623 printk((MACHINE_IS_VM) ?
624 "We are running under VM (31 bit mode)\n" :
625 "We are running native (31 bit mode)\n");
626 printk((MACHINE_HAS_IEEE) ?
627 "This machine has an IEEE fpu\n" :
628 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800629#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700630 printk((MACHINE_IS_VM) ?
631 "We are running under VM (64 bit mode)\n" :
632 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800633#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700634
Heiko Carstens59685292006-03-24 03:15:15 -0800635 /* Save unparsed command line copy for /proc/cmdline */
636 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
637
638 *cmdline_p = COMMAND_LINE;
639 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
640
Heiko Carstensc9e37352005-05-01 08:58:57 -0700641 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800642
643 init_mm.start_code = PAGE_OFFSET;
644 init_mm.end_code = (unsigned long) &_etext;
645 init_mm.end_data = (unsigned long) &_edata;
646 init_mm.brk = (unsigned long) &_end;
647
648 memory_end = memory_size;
649
Gerald Schaeferd02765d2006-09-20 15:59:42 +0200650 memcpy(&uaccess, &uaccess_std, sizeof(uaccess));
Heiko Carstens59685292006-03-24 03:15:15 -0800651 parse_early_param();
652
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800653#ifndef CONFIG_64BIT
Heiko Carstens59685292006-03-24 03:15:15 -0800654 memory_end &= ~0x400000UL;
655
Heiko Carstensc9e37352005-05-01 08:58:57 -0700656 /*
657 * We need some free virtual space to be able to do vmalloc.
658 * On a machine with 2GB memory we make sure that we have at
659 * least 128 MB free space for vmalloc.
660 */
661 if (memory_end > 1920*1024*1024)
662 memory_end = 1920*1024*1024;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800663#else /* CONFIG_64BIT */
Heiko Carstens59685292006-03-24 03:15:15 -0800664 memory_end &= ~0x200000UL;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800665#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700666
Heiko Carstensc9e37352005-05-01 08:58:57 -0700667 setup_memory();
668 setup_resources();
669 setup_lowcore();
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 cpu_init();
672 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
Heiko Carstens255acee2006-02-17 13:52:46 -0800673 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 /*
676 * Create kernel page tables and switch to virtual addressing.
677 */
678 paging_init();
679
680 /* Setup default console */
681 conmode_default();
682}
683
684void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
685{
686 printk("cpu %d "
687#ifdef CONFIG_SMP
688 "phys_idx=%d "
689#endif
690 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
691 cpuinfo->cpu_nr,
692#ifdef CONFIG_SMP
693 cpuinfo->cpu_addr,
694#endif
695 cpuinfo->cpu_id.version,
696 cpuinfo->cpu_id.ident,
697 cpuinfo->cpu_id.machine,
698 cpuinfo->cpu_id.unused);
699}
700
701/*
702 * show_cpuinfo - Get information on one CPU for use by procfs.
703 */
704
705static int show_cpuinfo(struct seq_file *m, void *v)
706{
707 struct cpuinfo_S390 *cpuinfo;
708 unsigned long n = (unsigned long) v - 1;
709
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700710 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 if (!n) {
712 seq_printf(m, "vendor_id : IBM/S390\n"
713 "# processors : %i\n"
714 "bogomips per cpu: %lu.%02lu\n",
715 num_online_cpus(), loops_per_jiffy/(500000/HZ),
716 (loops_per_jiffy/(5000/HZ))%100);
717 }
718 if (cpu_online(n)) {
719#ifdef CONFIG_SMP
720 if (smp_processor_id() == n)
721 cpuinfo = &S390_lowcore.cpu_data;
722 else
723 cpuinfo = &lowcore_ptr[n]->cpu_data;
724#else
725 cpuinfo = &S390_lowcore.cpu_data;
726#endif
727 seq_printf(m, "processor %li: "
728 "version = %02X, "
729 "identification = %06X, "
730 "machine = %04X\n",
731 n, cpuinfo->cpu_id.version,
732 cpuinfo->cpu_id.ident,
733 cpuinfo->cpu_id.machine);
734 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700735 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 return 0;
737}
738
739static void *c_start(struct seq_file *m, loff_t *pos)
740{
741 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
742}
743static void *c_next(struct seq_file *m, void *v, loff_t *pos)
744{
745 ++*pos;
746 return c_start(m, pos);
747}
748static void c_stop(struct seq_file *m, void *v)
749{
750}
751struct seq_operations cpuinfo_op = {
752 .start = c_start,
753 .next = c_next,
754 .stop = c_stop,
755 .show = show_cpuinfo,
756};
757