[PATCH] au1xxx: oss sound support for au1200
[linux-block.git] / arch / s390 / kernel / setup.c
CommitLineData
1da177e4
LT
1/*
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>
1e8e3383 39#include <linux/device.h>
1da177e4
LT
40
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>
0b642ede
PO
48#include <asm/page.h>
49#include <asm/ptrace.h>
1da177e4
LT
50
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;
1da177e4
LT
59struct {
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 */
c9e37353
HC
65unsigned long __initdata zholes_size[MAX_NR_ZONES];
66static unsigned long __initdata memory_end;
1da177e4
LT
67
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
1da177e4
LT
81static struct resource code_resource = {
82 .name = "Kernel code",
c9e37353
HC
83 .start = (unsigned long) &_text,
84 .end = (unsigned long) &_etext - 1,
1da177e4
LT
85 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
86};
87
88static struct resource data_resource = {
89 .name = "Kernel data",
c9e37353
HC
90 .start = (unsigned long) &_etext,
91 .end = (unsigned long) &_edata - 1,
1da177e4
LT
92 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
93};
94
95/*
96 * cpu_init() initializes state that is per-CPU.
97 */
98void __devinit cpu_init (void)
99{
100 int addr = hard_smp_processor_id();
101
102 /*
103 * Store processor id in lowcore (used e.g. in timer_interrupt)
104 */
105 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
106 S390_lowcore.cpu_data.cpu_addr = addr;
107
108 /*
109 * Force FPU initialization:
110 */
111 clear_thread_flag(TIF_USEDFPU);
112 clear_used_math();
113
114 atomic_inc(&init_mm.mm_count);
115 current->active_mm = &init_mm;
116 if (current->mm)
117 BUG();
118 enter_lazy_tlb(&init_mm, current);
119}
120
121/*
122 * VM halt and poweroff setup routines
123 */
124char vmhalt_cmd[128] = "";
125char vmpoff_cmd[128] = "";
126
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
157/*
158 * condev= and conmode= setup parameter.
159 */
160
161static int __init condev_setup(char *str)
162{
163 int vdev;
164
165 vdev = simple_strtoul(str, &str, 0);
166 if (vdev >= 0 && vdev < 65536) {
167 console_devno = vdev;
168 console_irq = -1;
169 }
170 return 1;
171}
172
173__setup("condev=", condev_setup);
174
175static int __init conmode_setup(char *str)
176{
177#if defined(CONFIG_SCLP_CONSOLE)
178 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
179 SET_CONSOLE_SCLP;
180#endif
181#if defined(CONFIG_TN3215_CONSOLE)
182 if (strncmp(str, "3215", 5) == 0)
183 SET_CONSOLE_3215;
184#endif
185#if defined(CONFIG_TN3270_CONSOLE)
186 if (strncmp(str, "3270", 5) == 0)
187 SET_CONSOLE_3270;
188#endif
189 return 1;
190}
191
192__setup("conmode=", conmode_setup);
193
194static void __init conmode_default(void)
195{
196 char query_buffer[1024];
197 char *ptr;
198
199 if (MACHINE_IS_VM) {
6b979de3 200 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
1da177e4
LT
201 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
202 ptr = strstr(query_buffer, "SUBCHANNEL =");
203 console_irq = simple_strtoul(ptr + 13, NULL, 16);
6b979de3 204 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
1da177e4
LT
205 ptr = strstr(query_buffer, "CONMODE");
206 /*
207 * Set the conmode to 3215 so that the device recognition
208 * will set the cu_type of the console to 3215. If the
209 * conmode is 3270 and we don't set it back then both
210 * 3215 and the 3270 driver will try to access the console
211 * device (3215 as console and 3270 as normal tty).
212 */
6b979de3 213 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
1da177e4
LT
214 if (ptr == NULL) {
215#if defined(CONFIG_SCLP_CONSOLE)
216 SET_CONSOLE_SCLP;
217#endif
218 return;
219 }
220 if (strncmp(ptr + 8, "3270", 4) == 0) {
221#if defined(CONFIG_TN3270_CONSOLE)
222 SET_CONSOLE_3270;
223#elif defined(CONFIG_TN3215_CONSOLE)
224 SET_CONSOLE_3215;
225#elif defined(CONFIG_SCLP_CONSOLE)
226 SET_CONSOLE_SCLP;
227#endif
228 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
229#if defined(CONFIG_TN3215_CONSOLE)
230 SET_CONSOLE_3215;
231#elif defined(CONFIG_TN3270_CONSOLE)
232 SET_CONSOLE_3270;
233#elif defined(CONFIG_SCLP_CONSOLE)
234 SET_CONSOLE_SCLP;
235#endif
236 }
237 } else if (MACHINE_IS_P390) {
238#if defined(CONFIG_TN3215_CONSOLE)
239 SET_CONSOLE_3215;
240#elif defined(CONFIG_TN3270_CONSOLE)
241 SET_CONSOLE_3270;
242#endif
243 } else {
244#if defined(CONFIG_SCLP_CONSOLE)
245 SET_CONSOLE_SCLP;
246#endif
247 }
248}
249
250#ifdef CONFIG_SMP
251extern void machine_restart_smp(char *);
252extern void machine_halt_smp(void);
253extern void machine_power_off_smp(void);
254
255void (*_machine_restart)(char *command) = machine_restart_smp;
256void (*_machine_halt)(void) = machine_halt_smp;
257void (*_machine_power_off)(void) = machine_power_off_smp;
258#else
259/*
260 * Reboot, halt and power_off routines for non SMP.
261 */
262extern void reipl(unsigned long devno);
c782268b 263extern void reipl_diag(void);
1da177e4
LT
264static void do_machine_restart_nonsmp(char * __unused)
265{
c782268b
VS
266 reipl_diag();
267
1da177e4 268 if (MACHINE_IS_VM)
68c11917 269 cpcmd ("IPL", NULL, 0, NULL);
1da177e4
LT
270 else
271 reipl (0x10000 | S390_lowcore.ipl_device);
272}
273
274static void do_machine_halt_nonsmp(void)
275{
276 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
68c11917 277 cpcmd(vmhalt_cmd, NULL, 0, NULL);
1da177e4
LT
278 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
279}
280
281static void do_machine_power_off_nonsmp(void)
282{
283 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
68c11917 284 cpcmd(vmpoff_cmd, NULL, 0, NULL);
1da177e4
LT
285 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
286}
287
288void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
289void (*_machine_halt)(void) = do_machine_halt_nonsmp;
290void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
291#endif
292
293 /*
294 * Reboot, halt and power_off stubs. They just call _machine_restart,
295 * _machine_halt or _machine_power_off.
296 */
297
298void machine_restart(char *command)
299{
300 console_unblank();
301 _machine_restart(command);
302}
303
1da177e4
LT
304void machine_halt(void)
305{
306 console_unblank();
307 _machine_halt();
308}
309
1da177e4
LT
310void machine_power_off(void)
311{
312 console_unblank();
313 _machine_power_off();
314}
315
53df751c
MS
316/*
317 * Dummy power off function.
318 */
319void (*pm_power_off)(void) = machine_power_off;
320
c9e37353
HC
321static void __init
322add_memory_hole(unsigned long start, unsigned long end)
1da177e4 323{
c9e37353
HC
324 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
325
326 if (end <= dma_pfn)
327 zholes_size[ZONE_DMA] += end - start + 1;
328 else if (start > dma_pfn)
329 zholes_size[ZONE_NORMAL] += end - start + 1;
330 else {
331 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
332 zholes_size[ZONE_NORMAL] += end - dma_pfn;
333 }
334}
1da177e4 335
59685296
HC
336static int __init early_parse_mem(char *p)
337{
338 memory_end = memparse(p, &p);
339 return 0;
340}
341early_param("mem", early_parse_mem);
342
343/*
344 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
345 */
346static int __init early_parse_ipldelay(char *p)
c9e37353 347{
c9e37353 348 unsigned long delay = 0;
1da177e4 349
59685296 350 delay = simple_strtoul(p, &p, 0);
1da177e4 351
59685296
HC
352 switch (*p) {
353 case 's':
354 case 'S':
355 delay *= 1000000;
356 break;
357 case 'm':
358 case 'M':
359 delay *= 60 * 1000000;
c9e37353 360 }
59685296
HC
361
362 /* now wait for the requested amount of time */
363 udelay(delay);
364
365 return 0;
c9e37353 366}
59685296 367early_param("ipldelay", early_parse_ipldelay);
c9e37353
HC
368
369static void __init
370setup_lowcore(void)
371{
372 struct _lowcore *lc;
373 int lc_pages;
374
375 /*
376 * Setup lowcore for boot cpu
377 */
378 lc_pages = sizeof(void *) == 8 ? 2 : 1;
379 lc = (struct _lowcore *)
380 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
381 memset(lc, 0, lc_pages * PAGE_SIZE);
0b642ede 382 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
c9e37353
HC
383 lc->restart_psw.addr =
384 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
385 lc->external_new_psw.mask = PSW_KERNEL_BITS;
386 lc->external_new_psw.addr =
387 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
388 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
389 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
390 lc->program_new_psw.mask = PSW_KERNEL_BITS;
391 lc->program_new_psw.addr =
392 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
77fa2245
HC
393 lc->mcck_new_psw.mask =
394 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
c9e37353
HC
395 lc->mcck_new_psw.addr =
396 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
397 lc->io_new_psw.mask = PSW_KERNEL_BITS;
398 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
399 lc->ipl_device = S390_lowcore.ipl_device;
400 lc->jiffy_timer = -1LL;
401 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
402 lc->async_stack = (unsigned long)
403 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
c9e37353
HC
404 lc->panic_stack = (unsigned long)
405 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
c9e37353
HC
406 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
407 lc->thread_info = (unsigned long) &init_thread_union;
347a8dc3 408#ifndef CONFIG_64BIT
77fa2245
HC
409 if (MACHINE_HAS_IEEE) {
410 lc->extended_save_area_addr = (__u32)
411 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
412 /* enable extended save area */
413 ctl_set_bit(14, 29);
414 }
415#endif
c9e37353
HC
416 set_prefix((u32)(unsigned long) lc);
417}
418
419static void __init
420setup_resources(void)
421{
422 struct resource *res;
423 int i;
424
425 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
426 res = alloc_bootmem_low(sizeof(struct resource));
427 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
428 switch (memory_chunk[i].type) {
429 case CHUNK_READ_WRITE:
430 res->name = "System RAM";
431 break;
432 case CHUNK_READ_ONLY:
433 res->name = "System ROM";
434 res->flags |= IORESOURCE_READONLY;
435 break;
436 default:
437 res->name = "reserved";
438 }
439 res->start = memory_chunk[i].addr;
440 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
441 request_resource(&iomem_resource, res);
442 request_resource(res, &code_resource);
443 request_resource(res, &data_resource);
444 }
445}
446
447static void __init
448setup_memory(void)
449{
450 unsigned long bootmap_size;
0b642ede 451 unsigned long start_pfn, end_pfn, init_pfn;
c9e37353
HC
452 unsigned long last_rw_end;
453 int i;
1da177e4
LT
454
455 /*
456 * partially used pages are not usable - thus
457 * we are rounding upwards:
458 */
459 start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
460 end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
461
0b642ede
PO
462 /* Initialize storage key for kernel pages */
463 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
464 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
465
1da177e4
LT
466 /*
467 * Initialize the boot-time allocator (with low memory only):
468 */
469 bootmap_size = init_bootmem(start_pfn, end_pfn);
470
471 /*
472 * Register RAM areas with the bootmem allocator.
473 */
c9e37353
HC
474 last_rw_end = start_pfn;
475
0b642ede 476 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
1da177e4
LT
477 unsigned long start_chunk, end_chunk;
478
479 if (memory_chunk[i].type != CHUNK_READ_WRITE)
480 continue;
481 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
482 start_chunk >>= PAGE_SHIFT;
483 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
484 end_chunk >>= PAGE_SHIFT;
485 if (start_chunk < start_pfn)
486 start_chunk = start_pfn;
487 if (end_chunk > end_pfn)
488 end_chunk = end_pfn;
c9e37353 489 if (start_chunk < end_chunk) {
0b642ede
PO
490 /* Initialize storage key for RAM pages */
491 for (init_pfn = start_chunk ; init_pfn < end_chunk;
492 init_pfn++)
493 page_set_storage_key(init_pfn << PAGE_SHIFT,
494 PAGE_DEFAULT_KEY);
1da177e4
LT
495 free_bootmem(start_chunk << PAGE_SHIFT,
496 (end_chunk - start_chunk) << PAGE_SHIFT);
c9e37353
HC
497 if (last_rw_end < start_chunk)
498 add_memory_hole(last_rw_end, start_chunk - 1);
499 last_rw_end = end_chunk;
500 }
1da177e4
LT
501 }
502
0b642ede
PO
503 psw_set_key(PAGE_DEFAULT_KEY);
504
c9e37353
HC
505 if (last_rw_end < end_pfn - 1)
506 add_memory_hole(last_rw_end, end_pfn - 1);
507
508 /*
509 * Reserve the bootmem bitmap itself as well. We do this in two
510 * steps (first step was init_bootmem()) because this catches
511 * the (very unlikely) case of us accidentally initializing the
512 * bootmem allocator with an invalid RAM area.
513 */
514 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
1da177e4
LT
515
516#ifdef CONFIG_BLK_DEV_INITRD
c9e37353 517 if (INITRD_START) {
1da177e4
LT
518 if (INITRD_START + INITRD_SIZE <= memory_end) {
519 reserve_bootmem(INITRD_START, INITRD_SIZE);
520 initrd_start = INITRD_START;
521 initrd_end = initrd_start + INITRD_SIZE;
522 } else {
c9e37353
HC
523 printk("initrd extends beyond end of memory "
524 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
525 initrd_start + INITRD_SIZE, memory_end);
526 initrd_start = initrd_end = 0;
1da177e4 527 }
c9e37353 528 }
1da177e4 529#endif
c9e37353 530}
1da177e4 531
c9e37353
HC
532/*
533 * Setup function called from init/main.c just after the banner
534 * was printed.
535 */
1da177e4 536
c9e37353
HC
537void __init
538setup_arch(char **cmdline_p)
539{
1da177e4 540 /*
c9e37353 541 * print what head.S has found out about the machine
1da177e4 542 */
347a8dc3 543#ifndef CONFIG_64BIT
c9e37353
HC
544 printk((MACHINE_IS_VM) ?
545 "We are running under VM (31 bit mode)\n" :
546 "We are running native (31 bit mode)\n");
547 printk((MACHINE_HAS_IEEE) ?
548 "This machine has an IEEE fpu\n" :
549 "This machine has no IEEE fpu\n");
347a8dc3 550#else /* CONFIG_64BIT */
c9e37353
HC
551 printk((MACHINE_IS_VM) ?
552 "We are running under VM (64 bit mode)\n" :
553 "We are running native (64 bit mode)\n");
347a8dc3 554#endif /* CONFIG_64BIT */
c9e37353 555
59685296
HC
556 /* Save unparsed command line copy for /proc/cmdline */
557 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
558
559 *cmdline_p = COMMAND_LINE;
560 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
561
c9e37353 562 ROOT_DEV = Root_RAM0;
59685296
HC
563
564 init_mm.start_code = PAGE_OFFSET;
565 init_mm.end_code = (unsigned long) &_etext;
566 init_mm.end_data = (unsigned long) &_edata;
567 init_mm.brk = (unsigned long) &_end;
568
569 memory_end = memory_size;
570
571 parse_early_param();
572
347a8dc3 573#ifndef CONFIG_64BIT
59685296
HC
574 memory_end &= ~0x400000UL;
575
c9e37353
HC
576 /*
577 * We need some free virtual space to be able to do vmalloc.
578 * On a machine with 2GB memory we make sure that we have at
579 * least 128 MB free space for vmalloc.
580 */
581 if (memory_end > 1920*1024*1024)
582 memory_end = 1920*1024*1024;
347a8dc3 583#else /* CONFIG_64BIT */
59685296 584 memory_end &= ~0x200000UL;
347a8dc3 585#endif /* CONFIG_64BIT */
c9e37353 586
c9e37353
HC
587 setup_memory();
588 setup_resources();
589 setup_lowcore();
590
1da177e4
LT
591 cpu_init();
592 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
255acee7 593 smp_setup_cpu_possible_map();
1da177e4
LT
594
595 /*
596 * Create kernel page tables and switch to virtual addressing.
597 */
598 paging_init();
599
600 /* Setup default console */
601 conmode_default();
602}
603
604void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
605{
606 printk("cpu %d "
607#ifdef CONFIG_SMP
608 "phys_idx=%d "
609#endif
610 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
611 cpuinfo->cpu_nr,
612#ifdef CONFIG_SMP
613 cpuinfo->cpu_addr,
614#endif
615 cpuinfo->cpu_id.version,
616 cpuinfo->cpu_id.ident,
617 cpuinfo->cpu_id.machine,
618 cpuinfo->cpu_id.unused);
619}
620
621/*
622 * show_cpuinfo - Get information on one CPU for use by procfs.
623 */
624
625static int show_cpuinfo(struct seq_file *m, void *v)
626{
627 struct cpuinfo_S390 *cpuinfo;
628 unsigned long n = (unsigned long) v - 1;
629
b7ae9dd8 630 preempt_disable();
1da177e4
LT
631 if (!n) {
632 seq_printf(m, "vendor_id : IBM/S390\n"
633 "# processors : %i\n"
634 "bogomips per cpu: %lu.%02lu\n",
635 num_online_cpus(), loops_per_jiffy/(500000/HZ),
636 (loops_per_jiffy/(5000/HZ))%100);
637 }
638 if (cpu_online(n)) {
639#ifdef CONFIG_SMP
640 if (smp_processor_id() == n)
641 cpuinfo = &S390_lowcore.cpu_data;
642 else
643 cpuinfo = &lowcore_ptr[n]->cpu_data;
644#else
645 cpuinfo = &S390_lowcore.cpu_data;
646#endif
647 seq_printf(m, "processor %li: "
648 "version = %02X, "
649 "identification = %06X, "
650 "machine = %04X\n",
651 n, cpuinfo->cpu_id.version,
652 cpuinfo->cpu_id.ident,
653 cpuinfo->cpu_id.machine);
654 }
b7ae9dd8 655 preempt_enable();
1da177e4
LT
656 return 0;
657}
658
659static void *c_start(struct seq_file *m, loff_t *pos)
660{
661 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
662}
663static void *c_next(struct seq_file *m, void *v, loff_t *pos)
664{
665 ++*pos;
666 return c_start(m, pos);
667}
668static void c_stop(struct seq_file *m, void *v)
669{
670}
671struct seq_operations cpuinfo_op = {
672 .start = c_start,
673 .next = c_next,
674 .stop = c_stop,
675 .show = show_cpuinfo,
676};
677
1e8e3383
HC
678#define DEFINE_IPL_ATTR(_name, _format, _value) \
679static ssize_t ipl_##_name##_show(struct subsystem *subsys, \
680 char *page) \
681{ \
682 return sprintf(page, _format, _value); \
683} \
684static struct subsys_attribute ipl_##_name##_attr = \
685 __ATTR(_name, S_IRUGO, ipl_##_name##_show, NULL);
686
687DEFINE_IPL_ATTR(wwpn, "0x%016llx\n", (unsigned long long)
688 IPL_PARMBLOCK_START->fcp.wwpn);
689DEFINE_IPL_ATTR(lun, "0x%016llx\n", (unsigned long long)
690 IPL_PARMBLOCK_START->fcp.lun);
691DEFINE_IPL_ATTR(bootprog, "%lld\n", (unsigned long long)
692 IPL_PARMBLOCK_START->fcp.bootprog);
693DEFINE_IPL_ATTR(br_lba, "%lld\n", (unsigned long long)
694 IPL_PARMBLOCK_START->fcp.br_lba);
695
696enum ipl_type_type {
697 ipl_type_unknown,
698 ipl_type_ccw,
699 ipl_type_fcp,
700};
701
702static enum ipl_type_type
703get_ipl_type(void)
704{
705 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
706
707 if (!IPL_DEVNO_VALID)
708 return ipl_type_unknown;
709 if (!IPL_PARMBLOCK_VALID)
710 return ipl_type_ccw;
711 if (ipl->hdr.header.version > IPL_MAX_SUPPORTED_VERSION)
712 return ipl_type_unknown;
713 if (ipl->fcp.pbt != IPL_TYPE_FCP)
714 return ipl_type_unknown;
715 return ipl_type_fcp;
716}
717
718static ssize_t
719ipl_type_show(struct subsystem *subsys, char *page)
720{
721 switch (get_ipl_type()) {
722 case ipl_type_ccw:
723 return sprintf(page, "ccw\n");
724 case ipl_type_fcp:
725 return sprintf(page, "fcp\n");
726 default:
727 return sprintf(page, "unknown\n");
728 }
729}
730
731static struct subsys_attribute ipl_type_attr = __ATTR_RO(ipl_type);
732
733static ssize_t
734ipl_device_show(struct subsystem *subsys, char *page)
735{
736 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
737
738 switch (get_ipl_type()) {
739 case ipl_type_ccw:
740 return sprintf(page, "0.0.%04x\n", ipl_devno);
741 case ipl_type_fcp:
742 return sprintf(page, "0.0.%04x\n", ipl->fcp.devno);
743 default:
744 return 0;
745 }
746}
747
748static struct subsys_attribute ipl_device_attr =
749 __ATTR(device, S_IRUGO, ipl_device_show, NULL);
750
751static struct attribute *ipl_fcp_attrs[] = {
752 &ipl_type_attr.attr,
753 &ipl_device_attr.attr,
754 &ipl_wwpn_attr.attr,
755 &ipl_lun_attr.attr,
756 &ipl_bootprog_attr.attr,
757 &ipl_br_lba_attr.attr,
758 NULL,
759};
760
761static struct attribute_group ipl_fcp_attr_group = {
762 .attrs = ipl_fcp_attrs,
763};
764
765static struct attribute *ipl_ccw_attrs[] = {
766 &ipl_type_attr.attr,
767 &ipl_device_attr.attr,
768 NULL,
769};
770
771static struct attribute_group ipl_ccw_attr_group = {
772 .attrs = ipl_ccw_attrs,
773};
774
775static struct attribute *ipl_unknown_attrs[] = {
776 &ipl_type_attr.attr,
777 NULL,
778};
779
780static struct attribute_group ipl_unknown_attr_group = {
781 .attrs = ipl_unknown_attrs,
782};
783
784static ssize_t
785ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
786{
787 unsigned int size = IPL_PARMBLOCK_SIZE;
788
789 if (off > size)
790 return 0;
791 if (off + count > size)
792 count = size - off;
793
794 memcpy(buf, (void *) IPL_PARMBLOCK_START + off, count);
795 return count;
796}
797
798static struct bin_attribute ipl_parameter_attr = {
799 .attr = {
800 .name = "binary_parameter",
801 .mode = S_IRUGO,
802 .owner = THIS_MODULE,
803 },
804 .size = PAGE_SIZE,
805 .read = &ipl_parameter_read,
806};
807
808static ssize_t
809ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
810{
811 unsigned int size = IPL_PARMBLOCK_START->fcp.scp_data_len;
812 void *scp_data = &IPL_PARMBLOCK_START->fcp.scp_data;
813
814 if (off > size)
815 return 0;
816 if (off + count > size)
817 count = size - off;
818
819 memcpy(buf, scp_data + off, count);
820 return count;
821}
822
823static struct bin_attribute ipl_scp_data_attr = {
824 .attr = {
825 .name = "scp_data",
826 .mode = S_IRUGO,
827 .owner = THIS_MODULE,
828 },
829 .size = PAGE_SIZE,
830 .read = &ipl_scp_data_read,
831};
832
833static decl_subsys(ipl, NULL, NULL);
834
835static int __init
836ipl_device_sysfs_register(void) {
837 int rc;
838
839 rc = firmware_register(&ipl_subsys);
840 if (rc)
841 return rc;
842
843 switch (get_ipl_type()) {
844 case ipl_type_ccw:
845 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_ccw_attr_group);
846 break;
847 case ipl_type_fcp:
848 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
849 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
850 &ipl_parameter_attr);
851 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
852 &ipl_scp_data_attr);
853 break;
854 default:
855 sysfs_create_group(&ipl_subsys.kset.kobj,
856 &ipl_unknown_attr_group);
857 break;
858 }
859 return 0;
860}
861
862__initcall(ipl_device_sysfs_register);