blob: c08325187a46b42df01732e2648b3dc376b33d9d [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>
31#include <linux/config.h>
32#include <linux/init.h>
33#include <linux/initrd.h>
34#include <linux/bootmem.h>
35#include <linux/root_dev.h>
36#include <linux/console.h>
37#include <linux/seq_file.h>
38#include <linux/kernel_stat.h>
Heiko Carstens1e8e3382005-10-30 15:00:11 -080039#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include <asm/uaccess.h>
42#include <asm/system.h>
43#include <asm/smp.h>
44#include <asm/mmu_context.h>
45#include <asm/cpcmd.h>
46#include <asm/lowcore.h>
47#include <asm/irq.h>
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -070048#include <asm/page.h>
49#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*
52 * Machine setup..
53 */
54unsigned int console_mode = 0;
55unsigned int console_devno = -1;
56unsigned int console_irq = -1;
57unsigned long memory_size = 0;
58unsigned long machine_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059struct {
60 unsigned long addr, size, type;
61} memory_chunk[MEMORY_CHUNKS] = { { 0 } };
62#define CHUNK_READ_WRITE 0
63#define CHUNK_READ_ONLY 1
64volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070065unsigned long __initdata zholes_size[MAX_NR_ZONES];
66static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/*
69 * Setup options
70 */
71extern int _text,_etext, _edata, _end;
72
73/*
74 * This is set up by the setup-routine at boot-time
75 * for S390 need to find out, what we have to setup
76 * using address 0x10400 ...
77 */
78
79#include <asm/setup.h>
80
81static char command_line[COMMAND_LINE_SIZE] = { 0, };
82
83static struct resource code_resource = {
84 .name = "Kernel code",
Heiko Carstensc9e37352005-05-01 08:58:57 -070085 .start = (unsigned long) &_text,
86 .end = (unsigned long) &_etext - 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
88};
89
90static struct resource data_resource = {
91 .name = "Kernel data",
Heiko Carstensc9e37352005-05-01 08:58:57 -070092 .start = (unsigned long) &_etext,
93 .end = (unsigned long) &_edata - 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
95};
96
97/*
98 * cpu_init() initializes state that is per-CPU.
99 */
100void __devinit cpu_init (void)
101{
102 int addr = hard_smp_processor_id();
103
104 /*
105 * Store processor id in lowcore (used e.g. in timer_interrupt)
106 */
107 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
108 S390_lowcore.cpu_data.cpu_addr = addr;
109
110 /*
111 * Force FPU initialization:
112 */
113 clear_thread_flag(TIF_USEDFPU);
114 clear_used_math();
115
116 atomic_inc(&init_mm.mm_count);
117 current->active_mm = &init_mm;
118 if (current->mm)
119 BUG();
120 enter_lazy_tlb(&init_mm, current);
121}
122
123/*
124 * VM halt and poweroff setup routines
125 */
126char vmhalt_cmd[128] = "";
127char vmpoff_cmd[128] = "";
128
129static inline void strncpy_skip_quote(char *dst, char *src, int n)
130{
131 int sx, dx;
132
133 dx = 0;
134 for (sx = 0; src[sx] != 0; sx++) {
135 if (src[sx] == '"') continue;
136 dst[dx++] = src[sx];
137 if (dx >= n) break;
138 }
139}
140
141static int __init vmhalt_setup(char *str)
142{
143 strncpy_skip_quote(vmhalt_cmd, str, 127);
144 vmhalt_cmd[127] = 0;
145 return 1;
146}
147
148__setup("vmhalt=", vmhalt_setup);
149
150static int __init vmpoff_setup(char *str)
151{
152 strncpy_skip_quote(vmpoff_cmd, str, 127);
153 vmpoff_cmd[127] = 0;
154 return 1;
155}
156
157__setup("vmpoff=", vmpoff_setup);
158
159/*
160 * condev= and conmode= setup parameter.
161 */
162
163static int __init condev_setup(char *str)
164{
165 int vdev;
166
167 vdev = simple_strtoul(str, &str, 0);
168 if (vdev >= 0 && vdev < 65536) {
169 console_devno = vdev;
170 console_irq = -1;
171 }
172 return 1;
173}
174
175__setup("condev=", condev_setup);
176
177static int __init conmode_setup(char *str)
178{
179#if defined(CONFIG_SCLP_CONSOLE)
180 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
181 SET_CONSOLE_SCLP;
182#endif
183#if defined(CONFIG_TN3215_CONSOLE)
184 if (strncmp(str, "3215", 5) == 0)
185 SET_CONSOLE_3215;
186#endif
187#if defined(CONFIG_TN3270_CONSOLE)
188 if (strncmp(str, "3270", 5) == 0)
189 SET_CONSOLE_3270;
190#endif
191 return 1;
192}
193
194__setup("conmode=", conmode_setup);
195
196static void __init conmode_default(void)
197{
198 char query_buffer[1024];
199 char *ptr;
200
201 if (MACHINE_IS_VM) {
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700202 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
204 ptr = strstr(query_buffer, "SUBCHANNEL =");
205 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700206 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 ptr = strstr(query_buffer, "CONMODE");
208 /*
209 * Set the conmode to 3215 so that the device recognition
210 * will set the cu_type of the console to 3215. If the
211 * conmode is 3270 and we don't set it back then both
212 * 3215 and the 3270 driver will try to access the console
213 * device (3215 as console and 3270 as normal tty).
214 */
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700215 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 if (ptr == NULL) {
217#if defined(CONFIG_SCLP_CONSOLE)
218 SET_CONSOLE_SCLP;
219#endif
220 return;
221 }
222 if (strncmp(ptr + 8, "3270", 4) == 0) {
223#if defined(CONFIG_TN3270_CONSOLE)
224 SET_CONSOLE_3270;
225#elif defined(CONFIG_TN3215_CONSOLE)
226 SET_CONSOLE_3215;
227#elif defined(CONFIG_SCLP_CONSOLE)
228 SET_CONSOLE_SCLP;
229#endif
230 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
231#if defined(CONFIG_TN3215_CONSOLE)
232 SET_CONSOLE_3215;
233#elif defined(CONFIG_TN3270_CONSOLE)
234 SET_CONSOLE_3270;
235#elif defined(CONFIG_SCLP_CONSOLE)
236 SET_CONSOLE_SCLP;
237#endif
238 }
239 } else if (MACHINE_IS_P390) {
240#if defined(CONFIG_TN3215_CONSOLE)
241 SET_CONSOLE_3215;
242#elif defined(CONFIG_TN3270_CONSOLE)
243 SET_CONSOLE_3270;
244#endif
245 } else {
246#if defined(CONFIG_SCLP_CONSOLE)
247 SET_CONSOLE_SCLP;
248#endif
249 }
250}
251
252#ifdef CONFIG_SMP
253extern void machine_restart_smp(char *);
254extern void machine_halt_smp(void);
255extern void machine_power_off_smp(void);
256
257void (*_machine_restart)(char *command) = machine_restart_smp;
258void (*_machine_halt)(void) = machine_halt_smp;
259void (*_machine_power_off)(void) = machine_power_off_smp;
260#else
261/*
262 * Reboot, halt and power_off routines for non SMP.
263 */
264extern void reipl(unsigned long devno);
Volker Sameskec7822682005-09-16 19:27:35 -0700265extern void reipl_diag(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266static void do_machine_restart_nonsmp(char * __unused)
267{
Volker Sameskec7822682005-09-16 19:27:35 -0700268 reipl_diag();
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (MACHINE_IS_VM)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800271 cpcmd ("IPL", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 else
273 reipl (0x10000 | S390_lowcore.ipl_device);
274}
275
276static void do_machine_halt_nonsmp(void)
277{
278 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800279 cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
281}
282
283static void do_machine_power_off_nonsmp(void)
284{
285 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800286 cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
288}
289
290void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
291void (*_machine_halt)(void) = do_machine_halt_nonsmp;
292void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
293#endif
294
295 /*
296 * Reboot, halt and power_off stubs. They just call _machine_restart,
297 * _machine_halt or _machine_power_off.
298 */
299
300void machine_restart(char *command)
301{
302 console_unblank();
303 _machine_restart(command);
304}
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306void machine_halt(void)
307{
308 console_unblank();
309 _machine_halt();
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312void machine_power_off(void)
313{
314 console_unblank();
315 _machine_power_off();
316}
317
Heiko Carstensc9e37352005-05-01 08:58:57 -0700318static void __init
319add_memory_hole(unsigned long start, unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700321 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Heiko Carstensc9e37352005-05-01 08:58:57 -0700323 if (end <= dma_pfn)
324 zholes_size[ZONE_DMA] += end - start + 1;
325 else if (start > dma_pfn)
326 zholes_size[ZONE_NORMAL] += end - start + 1;
327 else {
328 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
329 zholes_size[ZONE_NORMAL] += end - dma_pfn;
330 }
331}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Heiko Carstensc9e37352005-05-01 08:58:57 -0700333static void __init
334parse_cmdline_early(char **cmdline_p)
335{
336 char c = ' ', cn, *to = command_line, *from = COMMAND_LINE;
337 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Heiko Carstensc9e37352005-05-01 08:58:57 -0700339 /* Save unparsed command line copy for /proc/cmdline */
340 memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
341 saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Heiko Carstensc9e37352005-05-01 08:58:57 -0700343 for (;;) {
344 /*
345 * "mem=XXX[kKmM]" sets memsize
346 */
347 if (c == ' ' && strncmp(from, "mem=", 4) == 0) {
348 memory_end = simple_strtoul(from+4, &from, 0);
349 if ( *from == 'K' || *from == 'k' ) {
350 memory_end = memory_end << 10;
351 from++;
352 } else if ( *from == 'M' || *from == 'm' ) {
353 memory_end = memory_end << 20;
354 from++;
355 }
356 }
357 /*
358 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
359 */
360 if (c == ' ' && strncmp(from, "ipldelay=", 9) == 0) {
361 delay = simple_strtoul(from+9, &from, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 if (*from == 's' || *from == 'S') {
363 delay = delay*1000000;
364 from++;
365 } else if (*from == 'm' || *from == 'M') {
366 delay = delay*60*1000000;
367 from++;
368 }
369 /* now wait for the requested amount of time */
370 udelay(delay);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700371 }
372 cn = *(from++);
373 if (!cn)
374 break;
375 if (cn == '\n')
376 cn = ' '; /* replace newlines with space */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (cn == 0x0d)
378 cn = ' '; /* replace 0x0d with space */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700379 if (cn == ' ' && c == ' ')
380 continue; /* remove additional spaces */
381 c = cn;
382 if (to - command_line >= COMMAND_LINE_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 break;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700384 *(to++) = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 }
Heiko Carstensc9e37352005-05-01 08:58:57 -0700386 if (c == ' ' && to > command_line) to--;
387 *to = '\0';
388 *cmdline_p = command_line;
389}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Heiko Carstensc9e37352005-05-01 08:58:57 -0700391static void __init
392setup_lowcore(void)
393{
394 struct _lowcore *lc;
395 int lc_pages;
396
397 /*
398 * Setup lowcore for boot cpu
399 */
400 lc_pages = sizeof(void *) == 8 ? 2 : 1;
401 lc = (struct _lowcore *)
402 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
403 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700404 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 lc->restart_psw.addr =
406 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
407 lc->external_new_psw.mask = PSW_KERNEL_BITS;
408 lc->external_new_psw.addr =
409 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
410 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
411 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
412 lc->program_new_psw.mask = PSW_KERNEL_BITS;
413 lc->program_new_psw.addr =
414 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700415 lc->mcck_new_psw.mask =
416 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 lc->mcck_new_psw.addr =
418 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
419 lc->io_new_psw.mask = PSW_KERNEL_BITS;
420 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
421 lc->ipl_device = S390_lowcore.ipl_device;
422 lc->jiffy_timer = -1LL;
423 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
424 lc->async_stack = (unsigned long)
425 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 lc->panic_stack = (unsigned long)
427 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
429 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800430#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700431 if (MACHINE_HAS_IEEE) {
432 lc->extended_save_area_addr = (__u32)
433 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
434 /* enable extended save area */
435 ctl_set_bit(14, 29);
436 }
437#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700439}
440
441static void __init
442setup_resources(void)
443{
444 struct resource *res;
445 int i;
446
447 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
448 res = alloc_bootmem_low(sizeof(struct resource));
449 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
450 switch (memory_chunk[i].type) {
451 case CHUNK_READ_WRITE:
452 res->name = "System RAM";
453 break;
454 case CHUNK_READ_ONLY:
455 res->name = "System ROM";
456 res->flags |= IORESOURCE_READONLY;
457 break;
458 default:
459 res->name = "reserved";
460 }
461 res->start = memory_chunk[i].addr;
462 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
463 request_resource(&iomem_resource, res);
464 request_resource(res, &code_resource);
465 request_resource(res, &data_resource);
466 }
467}
468
469static void __init
470setup_memory(void)
471{
472 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700473 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700474 unsigned long last_rw_end;
475 int i;
476
477 /*
478 * partially used pages are not usable - thus
479 * we are rounding upwards:
480 */
481 start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
482 end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
483
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700484 /* Initialize storage key for kernel pages */
485 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
486 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
487
Heiko Carstensc9e37352005-05-01 08:58:57 -0700488 /*
489 * Initialize the boot-time allocator (with low memory only):
490 */
491 bootmap_size = init_bootmem(start_pfn, end_pfn);
492
493 /*
494 * Register RAM areas with the bootmem allocator.
495 */
496 last_rw_end = start_pfn;
497
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700498 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700499 unsigned long start_chunk, end_chunk;
500
501 if (memory_chunk[i].type != CHUNK_READ_WRITE)
502 continue;
503 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
504 start_chunk >>= PAGE_SHIFT;
505 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
506 end_chunk >>= PAGE_SHIFT;
507 if (start_chunk < start_pfn)
508 start_chunk = start_pfn;
509 if (end_chunk > end_pfn)
510 end_chunk = end_pfn;
511 if (start_chunk < end_chunk) {
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700512 /* Initialize storage key for RAM pages */
513 for (init_pfn = start_chunk ; init_pfn < end_chunk;
514 init_pfn++)
515 page_set_storage_key(init_pfn << PAGE_SHIFT,
516 PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700517 free_bootmem(start_chunk << PAGE_SHIFT,
518 (end_chunk - start_chunk) << PAGE_SHIFT);
519 if (last_rw_end < start_chunk)
520 add_memory_hole(last_rw_end, start_chunk - 1);
521 last_rw_end = end_chunk;
522 }
523 }
524
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700525 psw_set_key(PAGE_DEFAULT_KEY);
526
Heiko Carstensc9e37352005-05-01 08:58:57 -0700527 if (last_rw_end < end_pfn - 1)
528 add_memory_hole(last_rw_end, end_pfn - 1);
529
530 /*
531 * Reserve the bootmem bitmap itself as well. We do this in two
532 * steps (first step was init_bootmem()) because this catches
533 * the (very unlikely) case of us accidentally initializing the
534 * bootmem allocator with an invalid RAM area.
535 */
536 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
537
538#ifdef CONFIG_BLK_DEV_INITRD
539 if (INITRD_START) {
540 if (INITRD_START + INITRD_SIZE <= memory_end) {
541 reserve_bootmem(INITRD_START, INITRD_SIZE);
542 initrd_start = INITRD_START;
543 initrd_end = initrd_start + INITRD_SIZE;
544 } else {
545 printk("initrd extends beyond end of memory "
546 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
547 initrd_start + INITRD_SIZE, memory_end);
548 initrd_start = initrd_end = 0;
549 }
550 }
551#endif
552}
553
554/*
555 * Setup function called from init/main.c just after the banner
556 * was printed.
557 */
558
559void __init
560setup_arch(char **cmdline_p)
561{
562 /*
563 * print what head.S has found out about the machine
564 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800565#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700566 printk((MACHINE_IS_VM) ?
567 "We are running under VM (31 bit mode)\n" :
568 "We are running native (31 bit mode)\n");
569 printk((MACHINE_HAS_IEEE) ?
570 "This machine has an IEEE fpu\n" :
571 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800572#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700573 printk((MACHINE_IS_VM) ?
574 "We are running under VM (64 bit mode)\n" :
575 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800576#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700577
578 ROOT_DEV = Root_RAM0;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800579#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700580 memory_end = memory_size & ~0x400000UL; /* align memory end to 4MB */
581 /*
582 * We need some free virtual space to be able to do vmalloc.
583 * On a machine with 2GB memory we make sure that we have at
584 * least 128 MB free space for vmalloc.
585 */
586 if (memory_end > 1920*1024*1024)
587 memory_end = 1920*1024*1024;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800588#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700589 memory_end = memory_size & ~0x200000UL; /* detected in head.s */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800590#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700591
592 init_mm.start_code = PAGE_OFFSET;
593 init_mm.end_code = (unsigned long) &_etext;
594 init_mm.end_data = (unsigned long) &_edata;
595 init_mm.brk = (unsigned long) &_end;
596
597 parse_cmdline_early(cmdline_p);
598
599 setup_memory();
600 setup_resources();
601 setup_lowcore();
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 cpu_init();
604 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
605
606 /*
607 * Create kernel page tables and switch to virtual addressing.
608 */
609 paging_init();
610
611 /* Setup default console */
612 conmode_default();
613}
614
615void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
616{
617 printk("cpu %d "
618#ifdef CONFIG_SMP
619 "phys_idx=%d "
620#endif
621 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
622 cpuinfo->cpu_nr,
623#ifdef CONFIG_SMP
624 cpuinfo->cpu_addr,
625#endif
626 cpuinfo->cpu_id.version,
627 cpuinfo->cpu_id.ident,
628 cpuinfo->cpu_id.machine,
629 cpuinfo->cpu_id.unused);
630}
631
632/*
633 * show_cpuinfo - Get information on one CPU for use by procfs.
634 */
635
636static int show_cpuinfo(struct seq_file *m, void *v)
637{
638 struct cpuinfo_S390 *cpuinfo;
639 unsigned long n = (unsigned long) v - 1;
640
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700641 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (!n) {
643 seq_printf(m, "vendor_id : IBM/S390\n"
644 "# processors : %i\n"
645 "bogomips per cpu: %lu.%02lu\n",
646 num_online_cpus(), loops_per_jiffy/(500000/HZ),
647 (loops_per_jiffy/(5000/HZ))%100);
648 }
649 if (cpu_online(n)) {
650#ifdef CONFIG_SMP
651 if (smp_processor_id() == n)
652 cpuinfo = &S390_lowcore.cpu_data;
653 else
654 cpuinfo = &lowcore_ptr[n]->cpu_data;
655#else
656 cpuinfo = &S390_lowcore.cpu_data;
657#endif
658 seq_printf(m, "processor %li: "
659 "version = %02X, "
660 "identification = %06X, "
661 "machine = %04X\n",
662 n, cpuinfo->cpu_id.version,
663 cpuinfo->cpu_id.ident,
664 cpuinfo->cpu_id.machine);
665 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700666 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return 0;
668}
669
670static void *c_start(struct seq_file *m, loff_t *pos)
671{
672 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
673}
674static void *c_next(struct seq_file *m, void *v, loff_t *pos)
675{
676 ++*pos;
677 return c_start(m, pos);
678}
679static void c_stop(struct seq_file *m, void *v)
680{
681}
682struct seq_operations cpuinfo_op = {
683 .start = c_start,
684 .next = c_next,
685 .stop = c_stop,
686 .show = show_cpuinfo,
687};
688
Heiko Carstens1e8e3382005-10-30 15:00:11 -0800689#define DEFINE_IPL_ATTR(_name, _format, _value) \
690static ssize_t ipl_##_name##_show(struct subsystem *subsys, \
691 char *page) \
692{ \
693 return sprintf(page, _format, _value); \
694} \
695static struct subsys_attribute ipl_##_name##_attr = \
696 __ATTR(_name, S_IRUGO, ipl_##_name##_show, NULL);
697
698DEFINE_IPL_ATTR(wwpn, "0x%016llx\n", (unsigned long long)
699 IPL_PARMBLOCK_START->fcp.wwpn);
700DEFINE_IPL_ATTR(lun, "0x%016llx\n", (unsigned long long)
701 IPL_PARMBLOCK_START->fcp.lun);
702DEFINE_IPL_ATTR(bootprog, "%lld\n", (unsigned long long)
703 IPL_PARMBLOCK_START->fcp.bootprog);
704DEFINE_IPL_ATTR(br_lba, "%lld\n", (unsigned long long)
705 IPL_PARMBLOCK_START->fcp.br_lba);
706
707enum ipl_type_type {
708 ipl_type_unknown,
709 ipl_type_ccw,
710 ipl_type_fcp,
711};
712
713static enum ipl_type_type
714get_ipl_type(void)
715{
716 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
717
718 if (!IPL_DEVNO_VALID)
719 return ipl_type_unknown;
720 if (!IPL_PARMBLOCK_VALID)
721 return ipl_type_ccw;
722 if (ipl->hdr.header.version > IPL_MAX_SUPPORTED_VERSION)
723 return ipl_type_unknown;
724 if (ipl->fcp.pbt != IPL_TYPE_FCP)
725 return ipl_type_unknown;
726 return ipl_type_fcp;
727}
728
729static ssize_t
730ipl_type_show(struct subsystem *subsys, char *page)
731{
732 switch (get_ipl_type()) {
733 case ipl_type_ccw:
734 return sprintf(page, "ccw\n");
735 case ipl_type_fcp:
736 return sprintf(page, "fcp\n");
737 default:
738 return sprintf(page, "unknown\n");
739 }
740}
741
742static struct subsys_attribute ipl_type_attr = __ATTR_RO(ipl_type);
743
744static ssize_t
745ipl_device_show(struct subsystem *subsys, char *page)
746{
747 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
748
749 switch (get_ipl_type()) {
750 case ipl_type_ccw:
751 return sprintf(page, "0.0.%04x\n", ipl_devno);
752 case ipl_type_fcp:
753 return sprintf(page, "0.0.%04x\n", ipl->fcp.devno);
754 default:
755 return 0;
756 }
757}
758
759static struct subsys_attribute ipl_device_attr =
760 __ATTR(device, S_IRUGO, ipl_device_show, NULL);
761
762static struct attribute *ipl_fcp_attrs[] = {
763 &ipl_type_attr.attr,
764 &ipl_device_attr.attr,
765 &ipl_wwpn_attr.attr,
766 &ipl_lun_attr.attr,
767 &ipl_bootprog_attr.attr,
768 &ipl_br_lba_attr.attr,
769 NULL,
770};
771
772static struct attribute_group ipl_fcp_attr_group = {
773 .attrs = ipl_fcp_attrs,
774};
775
776static struct attribute *ipl_ccw_attrs[] = {
777 &ipl_type_attr.attr,
778 &ipl_device_attr.attr,
779 NULL,
780};
781
782static struct attribute_group ipl_ccw_attr_group = {
783 .attrs = ipl_ccw_attrs,
784};
785
786static struct attribute *ipl_unknown_attrs[] = {
787 &ipl_type_attr.attr,
788 NULL,
789};
790
791static struct attribute_group ipl_unknown_attr_group = {
792 .attrs = ipl_unknown_attrs,
793};
794
795static ssize_t
796ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
797{
798 unsigned int size = IPL_PARMBLOCK_SIZE;
799
800 if (off > size)
801 return 0;
802 if (off + count > size)
803 count = size - off;
804
805 memcpy(buf, (void *) IPL_PARMBLOCK_START + off, count);
806 return count;
807}
808
809static struct bin_attribute ipl_parameter_attr = {
810 .attr = {
811 .name = "binary_parameter",
812 .mode = S_IRUGO,
813 .owner = THIS_MODULE,
814 },
815 .size = PAGE_SIZE,
816 .read = &ipl_parameter_read,
817};
818
819static ssize_t
820ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
821{
822 unsigned int size = IPL_PARMBLOCK_START->fcp.scp_data_len;
823 void *scp_data = &IPL_PARMBLOCK_START->fcp.scp_data;
824
825 if (off > size)
826 return 0;
827 if (off + count > size)
828 count = size - off;
829
830 memcpy(buf, scp_data + off, count);
831 return count;
832}
833
834static struct bin_attribute ipl_scp_data_attr = {
835 .attr = {
836 .name = "scp_data",
837 .mode = S_IRUGO,
838 .owner = THIS_MODULE,
839 },
840 .size = PAGE_SIZE,
841 .read = &ipl_scp_data_read,
842};
843
844static decl_subsys(ipl, NULL, NULL);
845
846static int __init
847ipl_device_sysfs_register(void) {
848 int rc;
849
850 rc = firmware_register(&ipl_subsys);
851 if (rc)
852 return rc;
853
854 switch (get_ipl_type()) {
855 case ipl_type_ccw:
856 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_ccw_attr_group);
857 break;
858 case ipl_type_fcp:
859 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
860 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
861 &ipl_parameter_attr);
862 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
863 &ipl_scp_data_attr);
864 break;
865 default:
866 sysfs_create_group(&ipl_subsys.kset.kobj,
867 &ipl_unknown_attr_group);
868 break;
869 }
870 return 0;
871}
872
873__initcall(ipl_device_sysfs_register);