blob: 813444aac7d7690429d48dba024398395d5d457a [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>
Heiko Carstenscc13ad62006-06-25 05:49:30 -070050#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/*
53 * Machine setup..
54 */
55unsigned int console_mode = 0;
56unsigned int console_devno = -1;
57unsigned int console_irq = -1;
58unsigned long memory_size = 0;
59unsigned long machine_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060struct {
61 unsigned long addr, size, type;
62} memory_chunk[MEMORY_CHUNKS] = { { 0 } };
63#define CHUNK_READ_WRITE 0
64#define CHUNK_READ_ONLY 1
65volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
Heiko Carstensc9e37352005-05-01 08:58:57 -070066unsigned long __initdata zholes_size[MAX_NR_ZONES];
67static unsigned long __initdata memory_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * This is set up by the setup-routine at boot-time
71 * for S390 need to find out, what we have to setup
72 * using address 0x10400 ...
73 */
74
75#include <asm/setup.h>
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static struct resource code_resource = {
78 .name = "Kernel code",
79 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
80};
81
82static struct resource data_resource = {
83 .name = "Kernel data",
84 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
85};
86
87/*
88 * cpu_init() initializes state that is per-CPU.
89 */
90void __devinit cpu_init (void)
91{
92 int addr = hard_smp_processor_id();
93
94 /*
95 * Store processor id in lowcore (used e.g. in timer_interrupt)
96 */
97 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
98 S390_lowcore.cpu_data.cpu_addr = addr;
99
100 /*
101 * Force FPU initialization:
102 */
103 clear_thread_flag(TIF_USEDFPU);
104 clear_used_math();
105
106 atomic_inc(&init_mm.mm_count);
107 current->active_mm = &init_mm;
108 if (current->mm)
109 BUG();
110 enter_lazy_tlb(&init_mm, current);
111}
112
113/*
114 * VM halt and poweroff setup routines
115 */
116char vmhalt_cmd[128] = "";
117char vmpoff_cmd[128] = "";
118
119static inline void strncpy_skip_quote(char *dst, char *src, int n)
120{
121 int sx, dx;
122
123 dx = 0;
124 for (sx = 0; src[sx] != 0; sx++) {
125 if (src[sx] == '"') continue;
126 dst[dx++] = src[sx];
127 if (dx >= n) break;
128 }
129}
130
131static int __init vmhalt_setup(char *str)
132{
133 strncpy_skip_quote(vmhalt_cmd, str, 127);
134 vmhalt_cmd[127] = 0;
135 return 1;
136}
137
138__setup("vmhalt=", vmhalt_setup);
139
140static int __init vmpoff_setup(char *str)
141{
142 strncpy_skip_quote(vmpoff_cmd, str, 127);
143 vmpoff_cmd[127] = 0;
144 return 1;
145}
146
147__setup("vmpoff=", vmpoff_setup);
148
149/*
150 * condev= and conmode= setup parameter.
151 */
152
153static int __init condev_setup(char *str)
154{
155 int vdev;
156
157 vdev = simple_strtoul(str, &str, 0);
158 if (vdev >= 0 && vdev < 65536) {
159 console_devno = vdev;
160 console_irq = -1;
161 }
162 return 1;
163}
164
165__setup("condev=", condev_setup);
166
167static int __init conmode_setup(char *str)
168{
169#if defined(CONFIG_SCLP_CONSOLE)
170 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
171 SET_CONSOLE_SCLP;
172#endif
173#if defined(CONFIG_TN3215_CONSOLE)
174 if (strncmp(str, "3215", 5) == 0)
175 SET_CONSOLE_3215;
176#endif
177#if defined(CONFIG_TN3270_CONSOLE)
178 if (strncmp(str, "3270", 5) == 0)
179 SET_CONSOLE_3270;
180#endif
181 return 1;
182}
183
184__setup("conmode=", conmode_setup);
185
186static void __init conmode_default(void)
187{
188 char query_buffer[1024];
189 char *ptr;
190
191 if (MACHINE_IS_VM) {
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700192 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
194 ptr = strstr(query_buffer, "SUBCHANNEL =");
195 console_irq = simple_strtoul(ptr + 13, NULL, 16);
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700196 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 ptr = strstr(query_buffer, "CONMODE");
198 /*
199 * Set the conmode to 3215 so that the device recognition
200 * will set the cu_type of the console to 3215. If the
201 * conmode is 3270 and we don't set it back then both
202 * 3215 and the 3270 driver will try to access the console
203 * device (3215 as console and 3270 as normal tty).
204 */
Christian Borntraeger6b979de2005-06-25 14:55:32 -0700205 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 if (ptr == NULL) {
207#if defined(CONFIG_SCLP_CONSOLE)
208 SET_CONSOLE_SCLP;
209#endif
210 return;
211 }
212 if (strncmp(ptr + 8, "3270", 4) == 0) {
213#if defined(CONFIG_TN3270_CONSOLE)
214 SET_CONSOLE_3270;
215#elif defined(CONFIG_TN3215_CONSOLE)
216 SET_CONSOLE_3215;
217#elif defined(CONFIG_SCLP_CONSOLE)
218 SET_CONSOLE_SCLP;
219#endif
220 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
221#if defined(CONFIG_TN3215_CONSOLE)
222 SET_CONSOLE_3215;
223#elif defined(CONFIG_TN3270_CONSOLE)
224 SET_CONSOLE_3270;
225#elif defined(CONFIG_SCLP_CONSOLE)
226 SET_CONSOLE_SCLP;
227#endif
228 }
229 } else if (MACHINE_IS_P390) {
230#if defined(CONFIG_TN3215_CONSOLE)
231 SET_CONSOLE_3215;
232#elif defined(CONFIG_TN3270_CONSOLE)
233 SET_CONSOLE_3270;
234#endif
235 } else {
236#if defined(CONFIG_SCLP_CONSOLE)
237 SET_CONSOLE_SCLP;
238#endif
239 }
240}
241
242#ifdef CONFIG_SMP
243extern void machine_restart_smp(char *);
244extern void machine_halt_smp(void);
245extern void machine_power_off_smp(void);
246
247void (*_machine_restart)(char *command) = machine_restart_smp;
248void (*_machine_halt)(void) = machine_halt_smp;
249void (*_machine_power_off)(void) = machine_power_off_smp;
250#else
251/*
252 * Reboot, halt and power_off routines for non SMP.
253 */
254extern void reipl(unsigned long devno);
Volker Sameskec7822682005-09-16 19:27:35 -0700255extern void reipl_diag(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256static void do_machine_restart_nonsmp(char * __unused)
257{
Volker Sameskec7822682005-09-16 19:27:35 -0700258 reipl_diag();
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (MACHINE_IS_VM)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800261 cpcmd ("IPL", NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 else
263 reipl (0x10000 | S390_lowcore.ipl_device);
264}
265
266static void do_machine_halt_nonsmp(void)
267{
268 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800269 cpcmd(vmhalt_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
271}
272
273static void do_machine_power_off_nonsmp(void)
274{
275 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
Alexey Dobriyan68c11912006-01-14 13:20:58 -0800276 cpcmd(vmpoff_cmd, NULL, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
278}
279
280void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
281void (*_machine_halt)(void) = do_machine_halt_nonsmp;
282void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
283#endif
284
285 /*
286 * Reboot, halt and power_off stubs. They just call _machine_restart,
287 * _machine_halt or _machine_power_off.
288 */
289
290void machine_restart(char *command)
291{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200292 if (!in_interrupt() || oops_in_progress)
293 /*
294 * Only unblank the console if we are called in enabled
295 * context or a bust_spinlocks cleared the way for us.
296 */
297 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 _machine_restart(command);
299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301void machine_halt(void)
302{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200303 if (!in_interrupt() || oops_in_progress)
304 /*
305 * Only unblank the console if we are called in enabled
306 * context or a bust_spinlocks cleared the way for us.
307 */
308 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 _machine_halt();
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312void machine_power_off(void)
313{
Martin Schwidefsky06fa46a2006-06-29 14:57:32 +0200314 if (!in_interrupt() || oops_in_progress)
315 /*
316 * Only unblank the console if we are called in enabled
317 * context or a bust_spinlocks cleared the way for us.
318 */
319 console_unblank();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 _machine_power_off();
321}
322
Martin Schwidefsky53df7512006-01-14 13:21:01 -0800323/*
324 * Dummy power off function.
325 */
326void (*pm_power_off)(void) = machine_power_off;
327
Heiko Carstensc9e37352005-05-01 08:58:57 -0700328static void __init
329add_memory_hole(unsigned long start, unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700331 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Heiko Carstensc9e37352005-05-01 08:58:57 -0700333 if (end <= dma_pfn)
334 zholes_size[ZONE_DMA] += end - start + 1;
335 else if (start > dma_pfn)
336 zholes_size[ZONE_NORMAL] += end - start + 1;
337 else {
338 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
339 zholes_size[ZONE_NORMAL] += end - dma_pfn;
340 }
341}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Heiko Carstens59685292006-03-24 03:15:15 -0800343static int __init early_parse_mem(char *p)
Heiko Carstensc9e37352005-05-01 08:58:57 -0700344{
Heiko Carstens59685292006-03-24 03:15:15 -0800345 memory_end = memparse(p, &p);
346 return 0;
347}
348early_param("mem", early_parse_mem);
349
350/*
351 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
352 */
353static int __init early_parse_ipldelay(char *p)
354{
Heiko Carstensc9e37352005-05-01 08:58:57 -0700355 unsigned long delay = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Heiko Carstens59685292006-03-24 03:15:15 -0800357 delay = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Heiko Carstens59685292006-03-24 03:15:15 -0800359 switch (*p) {
360 case 's':
361 case 'S':
362 delay *= 1000000;
363 break;
364 case 'm':
365 case 'M':
366 delay *= 60 * 1000000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
Heiko Carstens59685292006-03-24 03:15:15 -0800368
369 /* now wait for the requested amount of time */
370 udelay(delay);
371
372 return 0;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700373}
Heiko Carstens59685292006-03-24 03:15:15 -0800374early_param("ipldelay", early_parse_ipldelay);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Heiko Carstensc9e37352005-05-01 08:58:57 -0700376static void __init
377setup_lowcore(void)
378{
379 struct _lowcore *lc;
380 int lc_pages;
381
382 /*
383 * Setup lowcore for boot cpu
384 */
385 lc_pages = sizeof(void *) == 8 ? 2 : 1;
386 lc = (struct _lowcore *)
387 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
388 memset(lc, 0, lc_pages * PAGE_SIZE);
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700389 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 lc->restart_psw.addr =
391 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
392 lc->external_new_psw.mask = PSW_KERNEL_BITS;
393 lc->external_new_psw.addr =
394 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
395 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
396 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
397 lc->program_new_psw.mask = PSW_KERNEL_BITS;
398 lc->program_new_psw.addr =
399 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
Heiko Carstens77fa2242005-06-25 14:55:30 -0700400 lc->mcck_new_psw.mask =
401 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 lc->mcck_new_psw.addr =
403 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
404 lc->io_new_psw.mask = PSW_KERNEL_BITS;
405 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
406 lc->ipl_device = S390_lowcore.ipl_device;
407 lc->jiffy_timer = -1LL;
408 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
409 lc->async_stack = (unsigned long)
410 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 lc->panic_stack = (unsigned long)
412 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
414 lc->thread_info = (unsigned long) &init_thread_union;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800415#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700416 if (MACHINE_HAS_IEEE) {
417 lc->extended_save_area_addr = (__u32)
418 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
419 /* enable extended save area */
420 ctl_set_bit(14, 29);
421 }
422#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 set_prefix((u32)(unsigned long) lc);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700424}
425
426static void __init
427setup_resources(void)
428{
429 struct resource *res;
430 int i;
431
Heiko Carstenscc13ad62006-06-25 05:49:30 -0700432 code_resource.start = (unsigned long) &_text;
433 code_resource.end = (unsigned long) &_etext - 1;
434 data_resource.start = (unsigned long) &_etext;
435 data_resource.end = (unsigned long) &_edata - 1;
436
Heiko Carstensc9e37352005-05-01 08:58:57 -0700437 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
438 res = alloc_bootmem_low(sizeof(struct resource));
439 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
440 switch (memory_chunk[i].type) {
441 case CHUNK_READ_WRITE:
442 res->name = "System RAM";
443 break;
444 case CHUNK_READ_ONLY:
445 res->name = "System ROM";
446 res->flags |= IORESOURCE_READONLY;
447 break;
448 default:
449 res->name = "reserved";
450 }
451 res->start = memory_chunk[i].addr;
452 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
453 request_resource(&iomem_resource, res);
454 request_resource(res, &code_resource);
455 request_resource(res, &data_resource);
456 }
457}
458
459static void __init
460setup_memory(void)
461{
462 unsigned long bootmap_size;
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700463 unsigned long start_pfn, end_pfn, init_pfn;
Heiko Carstensc9e37352005-05-01 08:58:57 -0700464 unsigned long last_rw_end;
465 int i;
466
467 /*
468 * partially used pages are not usable - thus
469 * we are rounding upwards:
470 */
471 start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
472 end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
473
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700474 /* Initialize storage key for kernel pages */
475 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
476 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
477
Heiko Carstensc9e37352005-05-01 08:58:57 -0700478 /*
479 * Initialize the boot-time allocator (with low memory only):
480 */
481 bootmap_size = init_bootmem(start_pfn, end_pfn);
482
483 /*
484 * Register RAM areas with the bootmem allocator.
485 */
486 last_rw_end = start_pfn;
487
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700488 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
Heiko Carstensc9e37352005-05-01 08:58:57 -0700489 unsigned long start_chunk, end_chunk;
490
491 if (memory_chunk[i].type != CHUNK_READ_WRITE)
492 continue;
493 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
494 start_chunk >>= PAGE_SHIFT;
495 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
496 end_chunk >>= PAGE_SHIFT;
497 if (start_chunk < start_pfn)
498 start_chunk = start_pfn;
499 if (end_chunk > end_pfn)
500 end_chunk = end_pfn;
501 if (start_chunk < end_chunk) {
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700502 /* Initialize storage key for RAM pages */
503 for (init_pfn = start_chunk ; init_pfn < end_chunk;
504 init_pfn++)
505 page_set_storage_key(init_pfn << PAGE_SHIFT,
506 PAGE_DEFAULT_KEY);
Heiko Carstensc9e37352005-05-01 08:58:57 -0700507 free_bootmem(start_chunk << PAGE_SHIFT,
508 (end_chunk - start_chunk) << PAGE_SHIFT);
509 if (last_rw_end < start_chunk)
510 add_memory_hole(last_rw_end, start_chunk - 1);
511 last_rw_end = end_chunk;
512 }
513 }
514
Peter Oberparleiter0b642ed2005-05-01 08:58:58 -0700515 psw_set_key(PAGE_DEFAULT_KEY);
516
Heiko Carstensc9e37352005-05-01 08:58:57 -0700517 if (last_rw_end < end_pfn - 1)
518 add_memory_hole(last_rw_end, end_pfn - 1);
519
520 /*
521 * Reserve the bootmem bitmap itself as well. We do this in two
522 * steps (first step was init_bootmem()) because this catches
523 * the (very unlikely) case of us accidentally initializing the
524 * bootmem allocator with an invalid RAM area.
525 */
526 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
527
528#ifdef CONFIG_BLK_DEV_INITRD
529 if (INITRD_START) {
530 if (INITRD_START + INITRD_SIZE <= memory_end) {
531 reserve_bootmem(INITRD_START, INITRD_SIZE);
532 initrd_start = INITRD_START;
533 initrd_end = initrd_start + INITRD_SIZE;
534 } else {
535 printk("initrd extends beyond end of memory "
536 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
537 initrd_start + INITRD_SIZE, memory_end);
538 initrd_start = initrd_end = 0;
539 }
540 }
541#endif
542}
543
544/*
545 * Setup function called from init/main.c just after the banner
546 * was printed.
547 */
548
549void __init
550setup_arch(char **cmdline_p)
551{
552 /*
553 * print what head.S has found out about the machine
554 */
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800555#ifndef CONFIG_64BIT
Heiko Carstensc9e37352005-05-01 08:58:57 -0700556 printk((MACHINE_IS_VM) ?
557 "We are running under VM (31 bit mode)\n" :
558 "We are running native (31 bit mode)\n");
559 printk((MACHINE_HAS_IEEE) ?
560 "This machine has an IEEE fpu\n" :
561 "This machine has no IEEE fpu\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800562#else /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700563 printk((MACHINE_IS_VM) ?
564 "We are running under VM (64 bit mode)\n" :
565 "We are running native (64 bit mode)\n");
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800566#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700567
Heiko Carstens59685292006-03-24 03:15:15 -0800568 /* Save unparsed command line copy for /proc/cmdline */
569 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
570
571 *cmdline_p = COMMAND_LINE;
572 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
573
Heiko Carstensc9e37352005-05-01 08:58:57 -0700574 ROOT_DEV = Root_RAM0;
Heiko Carstens59685292006-03-24 03:15:15 -0800575
576 init_mm.start_code = PAGE_OFFSET;
577 init_mm.end_code = (unsigned long) &_etext;
578 init_mm.end_data = (unsigned long) &_edata;
579 init_mm.brk = (unsigned long) &_end;
580
581 memory_end = memory_size;
582
583 parse_early_param();
584
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800585#ifndef CONFIG_64BIT
Heiko Carstens59685292006-03-24 03:15:15 -0800586 memory_end &= ~0x400000UL;
587
Heiko Carstensc9e37352005-05-01 08:58:57 -0700588 /*
589 * We need some free virtual space to be able to do vmalloc.
590 * On a machine with 2GB memory we make sure that we have at
591 * least 128 MB free space for vmalloc.
592 */
593 if (memory_end > 1920*1024*1024)
594 memory_end = 1920*1024*1024;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800595#else /* CONFIG_64BIT */
Heiko Carstens59685292006-03-24 03:15:15 -0800596 memory_end &= ~0x200000UL;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800597#endif /* CONFIG_64BIT */
Heiko Carstensc9e37352005-05-01 08:58:57 -0700598
Heiko Carstensc9e37352005-05-01 08:58:57 -0700599 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;
Heiko Carstens255acee2006-02-17 13:52:46 -0800605 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 /*
608 * Create kernel page tables and switch to virtual addressing.
609 */
610 paging_init();
611
612 /* Setup default console */
613 conmode_default();
614}
615
616void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
617{
618 printk("cpu %d "
619#ifdef CONFIG_SMP
620 "phys_idx=%d "
621#endif
622 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
623 cpuinfo->cpu_nr,
624#ifdef CONFIG_SMP
625 cpuinfo->cpu_addr,
626#endif
627 cpuinfo->cpu_id.version,
628 cpuinfo->cpu_id.ident,
629 cpuinfo->cpu_id.machine,
630 cpuinfo->cpu_id.unused);
631}
632
633/*
634 * show_cpuinfo - Get information on one CPU for use by procfs.
635 */
636
637static int show_cpuinfo(struct seq_file *m, void *v)
638{
639 struct cpuinfo_S390 *cpuinfo;
640 unsigned long n = (unsigned long) v - 1;
641
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700642 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 if (!n) {
644 seq_printf(m, "vendor_id : IBM/S390\n"
645 "# processors : %i\n"
646 "bogomips per cpu: %lu.%02lu\n",
647 num_online_cpus(), loops_per_jiffy/(500000/HZ),
648 (loops_per_jiffy/(5000/HZ))%100);
649 }
650 if (cpu_online(n)) {
651#ifdef CONFIG_SMP
652 if (smp_processor_id() == n)
653 cpuinfo = &S390_lowcore.cpu_data;
654 else
655 cpuinfo = &lowcore_ptr[n]->cpu_data;
656#else
657 cpuinfo = &S390_lowcore.cpu_data;
658#endif
659 seq_printf(m, "processor %li: "
660 "version = %02X, "
661 "identification = %06X, "
662 "machine = %04X\n",
663 n, cpuinfo->cpu_id.version,
664 cpuinfo->cpu_id.ident,
665 cpuinfo->cpu_id.machine);
666 }
Heiko Carstensb7ae9dd2005-09-16 19:27:34 -0700667 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return 0;
669}
670
671static void *c_start(struct seq_file *m, loff_t *pos)
672{
673 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
674}
675static void *c_next(struct seq_file *m, void *v, loff_t *pos)
676{
677 ++*pos;
678 return c_start(m, pos);
679}
680static void c_stop(struct seq_file *m, void *v)
681{
682}
683struct seq_operations cpuinfo_op = {
684 .start = c_start,
685 .next = c_next,
686 .stop = c_stop,
687 .show = show_cpuinfo,
688};
689
Heiko Carstens1e8e3382005-10-30 15:00:11 -0800690#define DEFINE_IPL_ATTR(_name, _format, _value) \
691static ssize_t ipl_##_name##_show(struct subsystem *subsys, \
692 char *page) \
693{ \
694 return sprintf(page, _format, _value); \
695} \
696static struct subsys_attribute ipl_##_name##_attr = \
697 __ATTR(_name, S_IRUGO, ipl_##_name##_show, NULL);
698
699DEFINE_IPL_ATTR(wwpn, "0x%016llx\n", (unsigned long long)
700 IPL_PARMBLOCK_START->fcp.wwpn);
701DEFINE_IPL_ATTR(lun, "0x%016llx\n", (unsigned long long)
702 IPL_PARMBLOCK_START->fcp.lun);
703DEFINE_IPL_ATTR(bootprog, "%lld\n", (unsigned long long)
704 IPL_PARMBLOCK_START->fcp.bootprog);
705DEFINE_IPL_ATTR(br_lba, "%lld\n", (unsigned long long)
706 IPL_PARMBLOCK_START->fcp.br_lba);
707
708enum ipl_type_type {
709 ipl_type_unknown,
710 ipl_type_ccw,
711 ipl_type_fcp,
712};
713
714static enum ipl_type_type
715get_ipl_type(void)
716{
717 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
718
719 if (!IPL_DEVNO_VALID)
720 return ipl_type_unknown;
721 if (!IPL_PARMBLOCK_VALID)
722 return ipl_type_ccw;
723 if (ipl->hdr.header.version > IPL_MAX_SUPPORTED_VERSION)
724 return ipl_type_unknown;
725 if (ipl->fcp.pbt != IPL_TYPE_FCP)
726 return ipl_type_unknown;
727 return ipl_type_fcp;
728}
729
730static ssize_t
731ipl_type_show(struct subsystem *subsys, char *page)
732{
733 switch (get_ipl_type()) {
734 case ipl_type_ccw:
735 return sprintf(page, "ccw\n");
736 case ipl_type_fcp:
737 return sprintf(page, "fcp\n");
738 default:
739 return sprintf(page, "unknown\n");
740 }
741}
742
743static struct subsys_attribute ipl_type_attr = __ATTR_RO(ipl_type);
744
745static ssize_t
746ipl_device_show(struct subsystem *subsys, char *page)
747{
748 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
749
750 switch (get_ipl_type()) {
751 case ipl_type_ccw:
752 return sprintf(page, "0.0.%04x\n", ipl_devno);
753 case ipl_type_fcp:
754 return sprintf(page, "0.0.%04x\n", ipl->fcp.devno);
755 default:
756 return 0;
757 }
758}
759
760static struct subsys_attribute ipl_device_attr =
761 __ATTR(device, S_IRUGO, ipl_device_show, NULL);
762
763static struct attribute *ipl_fcp_attrs[] = {
764 &ipl_type_attr.attr,
765 &ipl_device_attr.attr,
766 &ipl_wwpn_attr.attr,
767 &ipl_lun_attr.attr,
768 &ipl_bootprog_attr.attr,
769 &ipl_br_lba_attr.attr,
770 NULL,
771};
772
773static struct attribute_group ipl_fcp_attr_group = {
774 .attrs = ipl_fcp_attrs,
775};
776
777static struct attribute *ipl_ccw_attrs[] = {
778 &ipl_type_attr.attr,
779 &ipl_device_attr.attr,
780 NULL,
781};
782
783static struct attribute_group ipl_ccw_attr_group = {
784 .attrs = ipl_ccw_attrs,
785};
786
787static struct attribute *ipl_unknown_attrs[] = {
788 &ipl_type_attr.attr,
789 NULL,
790};
791
792static struct attribute_group ipl_unknown_attr_group = {
793 .attrs = ipl_unknown_attrs,
794};
795
796static ssize_t
797ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
798{
799 unsigned int size = IPL_PARMBLOCK_SIZE;
800
801 if (off > size)
802 return 0;
803 if (off + count > size)
804 count = size - off;
805
806 memcpy(buf, (void *) IPL_PARMBLOCK_START + off, count);
807 return count;
808}
809
810static struct bin_attribute ipl_parameter_attr = {
811 .attr = {
812 .name = "binary_parameter",
813 .mode = S_IRUGO,
814 .owner = THIS_MODULE,
815 },
816 .size = PAGE_SIZE,
817 .read = &ipl_parameter_read,
818};
819
820static ssize_t
821ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
822{
823 unsigned int size = IPL_PARMBLOCK_START->fcp.scp_data_len;
824 void *scp_data = &IPL_PARMBLOCK_START->fcp.scp_data;
825
826 if (off > size)
827 return 0;
828 if (off + count > size)
829 count = size - off;
830
831 memcpy(buf, scp_data + off, count);
832 return count;
833}
834
835static struct bin_attribute ipl_scp_data_attr = {
836 .attr = {
837 .name = "scp_data",
838 .mode = S_IRUGO,
839 .owner = THIS_MODULE,
840 },
841 .size = PAGE_SIZE,
842 .read = &ipl_scp_data_read,
843};
844
845static decl_subsys(ipl, NULL, NULL);
846
847static int __init
848ipl_device_sysfs_register(void) {
849 int rc;
850
851 rc = firmware_register(&ipl_subsys);
852 if (rc)
853 return rc;
854
855 switch (get_ipl_type()) {
856 case ipl_type_ccw:
857 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_ccw_attr_group);
858 break;
859 case ipl_type_fcp:
860 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
861 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
862 &ipl_parameter_attr);
863 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
864 &ipl_scp_data_attr);
865 break;
866 default:
867 sysfs_create_group(&ipl_subsys.kset.kobj,
868 &ipl_unknown_attr_group);
869 break;
870 }
871 return 0;
872}
873
874__initcall(ipl_device_sysfs_register);