Merge branch 'upstream-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/linvil...
[linux-2.6] / arch / s390 / kernel / setup.c
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/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>
38 #include <linux/device.h>
39 #include <linux/notifier.h>
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>
48 #include <asm/page.h>
49 #include <asm/ptrace.h>
50 #include <asm/sections.h>
51
52 /*
53  * Machine setup..
54  */
55 unsigned int console_mode = 0;
56 unsigned int console_devno = -1;
57 unsigned int console_irq = -1;
58 unsigned long memory_size = 0;
59 unsigned long machine_flags = 0;
60 struct {
61         unsigned long addr, size, type;
62 } memory_chunk[MEMORY_CHUNKS] = { { 0 } };
63 #define CHUNK_READ_WRITE 0
64 #define CHUNK_READ_ONLY 1
65 volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
66 unsigned long __initdata zholes_size[MAX_NR_ZONES];
67 static unsigned long __initdata memory_end;
68
69 /*
70  * 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
77 static struct resource code_resource = {
78         .name  = "Kernel code",
79         .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
80 };
81
82 static 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  */
90 void __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  */
116 char vmhalt_cmd[128] = "";
117 char vmpoff_cmd[128] = "";
118 char vmpanic_cmd[128] = "";
119
120 static inline void strncpy_skip_quote(char *dst, char *src, int n)
121 {
122         int sx, dx;
123
124         dx = 0;
125         for (sx = 0; src[sx] != 0; sx++) {
126                 if (src[sx] == '"') continue;
127                 dst[dx++] = src[sx];
128                 if (dx >= n) break;
129         }
130 }
131
132 static int __init vmhalt_setup(char *str)
133 {
134         strncpy_skip_quote(vmhalt_cmd, str, 127);
135         vmhalt_cmd[127] = 0;
136         return 1;
137 }
138
139 __setup("vmhalt=", vmhalt_setup);
140
141 static int __init vmpoff_setup(char *str)
142 {
143         strncpy_skip_quote(vmpoff_cmd, str, 127);
144         vmpoff_cmd[127] = 0;
145         return 1;
146 }
147
148 __setup("vmpoff=", vmpoff_setup);
149
150 static int vmpanic_notify(struct notifier_block *self, unsigned long event,
151                           void *data)
152 {
153         if (MACHINE_IS_VM && strlen(vmpanic_cmd) > 0)
154                 cpcmd(vmpanic_cmd, NULL, 0, NULL);
155
156         return NOTIFY_OK;
157 }
158
159 #define PANIC_PRI_VMPANIC       0
160
161 static struct notifier_block vmpanic_nb = {
162         .notifier_call = vmpanic_notify,
163         .priority = PANIC_PRI_VMPANIC
164 };
165
166 static int __init vmpanic_setup(char *str)
167 {
168         static int register_done __initdata = 0;
169
170         strncpy_skip_quote(vmpanic_cmd, str, 127);
171         vmpanic_cmd[127] = 0;
172         if (!register_done) {
173                 register_done = 1;
174                 atomic_notifier_chain_register(&panic_notifier_list,
175                                                &vmpanic_nb);
176         }
177         return 1;
178 }
179
180 __setup("vmpanic=", vmpanic_setup);
181
182 /*
183  * condev= and conmode= setup parameter.
184  */
185
186 static int __init condev_setup(char *str)
187 {
188         int vdev;
189
190         vdev = simple_strtoul(str, &str, 0);
191         if (vdev >= 0 && vdev < 65536) {
192                 console_devno = vdev;
193                 console_irq = -1;
194         }
195         return 1;
196 }
197
198 __setup("condev=", condev_setup);
199
200 static int __init conmode_setup(char *str)
201 {
202 #if defined(CONFIG_SCLP_CONSOLE)
203         if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
204                 SET_CONSOLE_SCLP;
205 #endif
206 #if defined(CONFIG_TN3215_CONSOLE)
207         if (strncmp(str, "3215", 5) == 0)
208                 SET_CONSOLE_3215;
209 #endif
210 #if defined(CONFIG_TN3270_CONSOLE)
211         if (strncmp(str, "3270", 5) == 0)
212                 SET_CONSOLE_3270;
213 #endif
214         return 1;
215 }
216
217 __setup("conmode=", conmode_setup);
218
219 static void __init conmode_default(void)
220 {
221         char query_buffer[1024];
222         char *ptr;
223
224         if (MACHINE_IS_VM) {
225                 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
226                 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
227                 ptr = strstr(query_buffer, "SUBCHANNEL =");
228                 console_irq = simple_strtoul(ptr + 13, NULL, 16);
229                 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
230                 ptr = strstr(query_buffer, "CONMODE");
231                 /*
232                  * Set the conmode to 3215 so that the device recognition 
233                  * will set the cu_type of the console to 3215. If the
234                  * conmode is 3270 and we don't set it back then both
235                  * 3215 and the 3270 driver will try to access the console
236                  * device (3215 as console and 3270 as normal tty).
237                  */
238                 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
239                 if (ptr == NULL) {
240 #if defined(CONFIG_SCLP_CONSOLE)
241                         SET_CONSOLE_SCLP;
242 #endif
243                         return;
244                 }
245                 if (strncmp(ptr + 8, "3270", 4) == 0) {
246 #if defined(CONFIG_TN3270_CONSOLE)
247                         SET_CONSOLE_3270;
248 #elif defined(CONFIG_TN3215_CONSOLE)
249                         SET_CONSOLE_3215;
250 #elif defined(CONFIG_SCLP_CONSOLE)
251                         SET_CONSOLE_SCLP;
252 #endif
253                 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
254 #if defined(CONFIG_TN3215_CONSOLE)
255                         SET_CONSOLE_3215;
256 #elif defined(CONFIG_TN3270_CONSOLE)
257                         SET_CONSOLE_3270;
258 #elif defined(CONFIG_SCLP_CONSOLE)
259                         SET_CONSOLE_SCLP;
260 #endif
261                 }
262         } else if (MACHINE_IS_P390) {
263 #if defined(CONFIG_TN3215_CONSOLE)
264                 SET_CONSOLE_3215;
265 #elif defined(CONFIG_TN3270_CONSOLE)
266                 SET_CONSOLE_3270;
267 #endif
268         } else {
269 #if defined(CONFIG_SCLP_CONSOLE)
270                 SET_CONSOLE_SCLP;
271 #endif
272         }
273 }
274
275 #ifdef CONFIG_SMP
276 extern void machine_restart_smp(char *);
277 extern void machine_halt_smp(void);
278 extern void machine_power_off_smp(void);
279
280 void (*_machine_restart)(char *command) = machine_restart_smp;
281 void (*_machine_halt)(void) = machine_halt_smp;
282 void (*_machine_power_off)(void) = machine_power_off_smp;
283 #else
284 /*
285  * Reboot, halt and power_off routines for non SMP.
286  */
287 extern void reipl(unsigned long devno);
288 extern void reipl_diag(void);
289 static void do_machine_restart_nonsmp(char * __unused)
290 {
291         reipl_diag();
292
293         if (MACHINE_IS_VM)
294                 cpcmd ("IPL", NULL, 0, NULL);
295         else
296                 reipl (0x10000 | S390_lowcore.ipl_device);
297 }
298
299 static void do_machine_halt_nonsmp(void)
300 {
301         if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
302                 cpcmd(vmhalt_cmd, NULL, 0, NULL);
303         signal_processor(smp_processor_id(), sigp_stop_and_store_status);
304 }
305
306 static void do_machine_power_off_nonsmp(void)
307 {
308         if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
309                 cpcmd(vmpoff_cmd, NULL, 0, NULL);
310         signal_processor(smp_processor_id(), sigp_stop_and_store_status);
311 }
312
313 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
314 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
315 void (*_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
323 void machine_restart(char *command)
324 {
325         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();
331         _machine_restart(command);
332 }
333
334 void machine_halt(void)
335 {
336         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();
342         _machine_halt();
343 }
344
345 void machine_power_off(void)
346 {
347         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();
353         _machine_power_off();
354 }
355
356 /*
357  * Dummy power off function.
358  */
359 void (*pm_power_off)(void) = machine_power_off;
360
361 static void __init
362 add_memory_hole(unsigned long start, unsigned long end)
363 {
364         unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
365
366         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 }
375
376 static int __init early_parse_mem(char *p)
377 {
378         memory_end = memparse(p, &p);
379         return 0;
380 }
381 early_param("mem", early_parse_mem);
382
383 /*
384  * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
385  */
386 static int __init early_parse_ipldelay(char *p)
387 {
388         unsigned long delay = 0;
389
390         delay = simple_strtoul(p, &p, 0);
391
392         switch (*p) {
393         case 's':
394         case 'S':
395                 delay *= 1000000;
396                 break;
397         case 'm':
398         case 'M':
399                 delay *= 60 * 1000000;
400         }
401
402         /* now wait for the requested amount of time */
403         udelay(delay);
404
405         return 0;
406 }
407 early_param("ipldelay", early_parse_ipldelay);
408
409 static void __init
410 setup_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);
422         lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
423         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;
433         lc->mcck_new_psw.mask =
434                 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
435         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;
444         lc->panic_stack = (unsigned long)
445                 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
446         lc->current_task = (unsigned long) init_thread_union.thread_info.task;
447         lc->thread_info = (unsigned long) &init_thread_union;
448 #ifndef CONFIG_64BIT
449         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
456         set_prefix((u32)(unsigned long) lc);
457 }
458
459 static void __init
460 setup_resources(void)
461 {
462         struct resource *res;
463         int i;
464
465         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
470         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
492 static void __init
493 setup_memory(void)
494 {
495         unsigned long bootmap_size;
496         unsigned long start_pfn, end_pfn, init_pfn;
497         unsigned long last_rw_end;
498         int i;
499
500         /*
501          * partially used pages are not usable - thus
502          * we are rounding upwards:
503          */
504         start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
505         end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
506
507         /* 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
511         /*
512          * Initialize the boot-time allocator (with low memory only):
513          */
514         bootmap_size = init_bootmem(start_pfn, end_pfn);
515
516         /*
517          * Register RAM areas with the bootmem allocator.
518          */
519         last_rw_end = start_pfn;
520
521         for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
522                 unsigned long start_chunk, end_chunk;
523
524                 if (memory_chunk[i].type != CHUNK_READ_WRITE)
525                         continue;
526                 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
527                 start_chunk >>= PAGE_SHIFT;
528                 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
529                 end_chunk >>= PAGE_SHIFT;
530                 if (start_chunk < start_pfn)
531                         start_chunk = start_pfn;
532                 if (end_chunk > end_pfn)
533                         end_chunk = end_pfn;
534                 if (start_chunk < end_chunk) {
535                         /* Initialize storage key for RAM pages */
536                         for (init_pfn = start_chunk ; init_pfn < end_chunk;
537                              init_pfn++)
538                                 page_set_storage_key(init_pfn << PAGE_SHIFT,
539                                                      PAGE_DEFAULT_KEY);
540                         free_bootmem(start_chunk << PAGE_SHIFT,
541                                      (end_chunk - start_chunk) << PAGE_SHIFT);
542                         if (last_rw_end < start_chunk)
543                                 add_memory_hole(last_rw_end, start_chunk - 1);
544                         last_rw_end = end_chunk;
545                 }
546         }
547
548         psw_set_key(PAGE_DEFAULT_KEY);
549
550         if (last_rw_end < end_pfn - 1)
551                 add_memory_hole(last_rw_end, end_pfn - 1);
552
553         /*
554          * Reserve the bootmem bitmap itself as well. We do this in two
555          * steps (first step was init_bootmem()) because this catches
556          * the (very unlikely) case of us accidentally initializing the
557          * bootmem allocator with an invalid RAM area.
558          */
559         reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
560
561 #ifdef CONFIG_BLK_DEV_INITRD
562         if (INITRD_START) {
563                 if (INITRD_START + INITRD_SIZE <= memory_end) {
564                         reserve_bootmem(INITRD_START, INITRD_SIZE);
565                         initrd_start = INITRD_START;
566                         initrd_end = initrd_start + INITRD_SIZE;
567                 } else {
568                         printk("initrd extends beyond end of memory "
569                                "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
570                                initrd_start + INITRD_SIZE, memory_end);
571                         initrd_start = initrd_end = 0;
572                 }
573         }
574 #endif
575 }
576
577 /*
578  * Setup function called from init/main.c just after the banner
579  * was printed.
580  */
581
582 void __init
583 setup_arch(char **cmdline_p)
584 {
585         /*
586          * print what head.S has found out about the machine
587          */
588 #ifndef CONFIG_64BIT
589         printk((MACHINE_IS_VM) ?
590                "We are running under VM (31 bit mode)\n" :
591                "We are running native (31 bit mode)\n");
592         printk((MACHINE_HAS_IEEE) ?
593                "This machine has an IEEE fpu\n" :
594                "This machine has no IEEE fpu\n");
595 #else /* CONFIG_64BIT */
596         printk((MACHINE_IS_VM) ?
597                "We are running under VM (64 bit mode)\n" :
598                "We are running native (64 bit mode)\n");
599 #endif /* CONFIG_64BIT */
600
601         /* Save unparsed command line copy for /proc/cmdline */
602         strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
603
604         *cmdline_p = COMMAND_LINE;
605         *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
606
607         ROOT_DEV = Root_RAM0;
608
609         init_mm.start_code = PAGE_OFFSET;
610         init_mm.end_code = (unsigned long) &_etext;
611         init_mm.end_data = (unsigned long) &_edata;
612         init_mm.brk = (unsigned long) &_end;
613
614         memory_end = memory_size;
615
616         parse_early_param();
617
618 #ifndef CONFIG_64BIT
619         memory_end &= ~0x400000UL;
620
621         /*
622          * We need some free virtual space to be able to do vmalloc.
623          * On a machine with 2GB memory we make sure that we have at
624          * least 128 MB free space for vmalloc.
625          */
626         if (memory_end > 1920*1024*1024)
627                 memory_end = 1920*1024*1024;
628 #else /* CONFIG_64BIT */
629         memory_end &= ~0x200000UL;
630 #endif /* CONFIG_64BIT */
631
632         setup_memory();
633         setup_resources();
634         setup_lowcore();
635
636         cpu_init();
637         __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
638         smp_setup_cpu_possible_map();
639
640         /*
641          * Create kernel page tables and switch to virtual addressing.
642          */
643         paging_init();
644
645         /* Setup default console */
646         conmode_default();
647 }
648
649 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
650 {
651    printk("cpu %d "
652 #ifdef CONFIG_SMP
653            "phys_idx=%d "
654 #endif
655            "vers=%02X ident=%06X machine=%04X unused=%04X\n",
656            cpuinfo->cpu_nr,
657 #ifdef CONFIG_SMP
658            cpuinfo->cpu_addr,
659 #endif
660            cpuinfo->cpu_id.version,
661            cpuinfo->cpu_id.ident,
662            cpuinfo->cpu_id.machine,
663            cpuinfo->cpu_id.unused);
664 }
665
666 /*
667  * show_cpuinfo - Get information on one CPU for use by procfs.
668  */
669
670 static int show_cpuinfo(struct seq_file *m, void *v)
671 {
672         struct cpuinfo_S390 *cpuinfo;
673         unsigned long n = (unsigned long) v - 1;
674
675         preempt_disable();
676         if (!n) {
677                 seq_printf(m, "vendor_id       : IBM/S390\n"
678                                "# processors    : %i\n"
679                                "bogomips per cpu: %lu.%02lu\n",
680                                num_online_cpus(), loops_per_jiffy/(500000/HZ),
681                                (loops_per_jiffy/(5000/HZ))%100);
682         }
683         if (cpu_online(n)) {
684 #ifdef CONFIG_SMP
685                 if (smp_processor_id() == n)
686                         cpuinfo = &S390_lowcore.cpu_data;
687                 else
688                         cpuinfo = &lowcore_ptr[n]->cpu_data;
689 #else
690                 cpuinfo = &S390_lowcore.cpu_data;
691 #endif
692                 seq_printf(m, "processor %li: "
693                                "version = %02X,  "
694                                "identification = %06X,  "
695                                "machine = %04X\n",
696                                n, cpuinfo->cpu_id.version,
697                                cpuinfo->cpu_id.ident,
698                                cpuinfo->cpu_id.machine);
699         }
700         preempt_enable();
701         return 0;
702 }
703
704 static void *c_start(struct seq_file *m, loff_t *pos)
705 {
706         return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
707 }
708 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
709 {
710         ++*pos;
711         return c_start(m, pos);
712 }
713 static void c_stop(struct seq_file *m, void *v)
714 {
715 }
716 struct seq_operations cpuinfo_op = {
717         .start  = c_start,
718         .next   = c_next,
719         .stop   = c_stop,
720         .show   = show_cpuinfo,
721 };
722
723 #define DEFINE_IPL_ATTR(_name, _format, _value)                 \
724 static ssize_t ipl_##_name##_show(struct subsystem *subsys,     \
725                 char *page)                                     \
726 {                                                               \
727         return sprintf(page, _format, _value);                  \
728 }                                                               \
729 static struct subsys_attribute ipl_##_name##_attr =             \
730         __ATTR(_name, S_IRUGO, ipl_##_name##_show, NULL);
731
732 DEFINE_IPL_ATTR(wwpn, "0x%016llx\n", (unsigned long long)
733                 IPL_PARMBLOCK_START->fcp.wwpn);
734 DEFINE_IPL_ATTR(lun, "0x%016llx\n", (unsigned long long)
735                 IPL_PARMBLOCK_START->fcp.lun);
736 DEFINE_IPL_ATTR(bootprog, "%lld\n", (unsigned long long)
737                 IPL_PARMBLOCK_START->fcp.bootprog);
738 DEFINE_IPL_ATTR(br_lba, "%lld\n", (unsigned long long)
739                 IPL_PARMBLOCK_START->fcp.br_lba);
740
741 enum ipl_type_type {
742         ipl_type_unknown,
743         ipl_type_ccw,
744         ipl_type_fcp,
745 };
746
747 static enum ipl_type_type
748 get_ipl_type(void)
749 {
750         struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
751
752         if (!IPL_DEVNO_VALID)
753                 return ipl_type_unknown;
754         if (!IPL_PARMBLOCK_VALID)
755                 return ipl_type_ccw;
756         if (ipl->hdr.header.version > IPL_MAX_SUPPORTED_VERSION)
757                 return ipl_type_unknown;
758         if (ipl->fcp.pbt != IPL_TYPE_FCP)
759                 return ipl_type_unknown;
760         return ipl_type_fcp;
761 }
762
763 static ssize_t
764 ipl_type_show(struct subsystem *subsys, char *page)
765 {
766         switch (get_ipl_type()) {
767         case ipl_type_ccw:
768                 return sprintf(page, "ccw\n");
769         case ipl_type_fcp:
770                 return sprintf(page, "fcp\n");
771         default:
772                 return sprintf(page, "unknown\n");
773         }
774 }
775
776 static struct subsys_attribute ipl_type_attr = __ATTR_RO(ipl_type);
777
778 static ssize_t
779 ipl_device_show(struct subsystem *subsys, char *page)
780 {
781         struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
782
783         switch (get_ipl_type()) {
784         case ipl_type_ccw:
785                 return sprintf(page, "0.0.%04x\n", ipl_devno);
786         case ipl_type_fcp:
787                 return sprintf(page, "0.0.%04x\n", ipl->fcp.devno);
788         default:
789                 return 0;
790         }
791 }
792
793 static struct subsys_attribute ipl_device_attr =
794         __ATTR(device, S_IRUGO, ipl_device_show, NULL);
795
796 static struct attribute *ipl_fcp_attrs[] = {
797         &ipl_type_attr.attr,
798         &ipl_device_attr.attr,
799         &ipl_wwpn_attr.attr,
800         &ipl_lun_attr.attr,
801         &ipl_bootprog_attr.attr,
802         &ipl_br_lba_attr.attr,
803         NULL,
804 };
805
806 static struct attribute_group ipl_fcp_attr_group = {
807         .attrs = ipl_fcp_attrs,
808 };
809
810 static struct attribute *ipl_ccw_attrs[] = {
811         &ipl_type_attr.attr,
812         &ipl_device_attr.attr,
813         NULL,
814 };
815
816 static struct attribute_group ipl_ccw_attr_group = {
817         .attrs = ipl_ccw_attrs,
818 };
819
820 static struct attribute *ipl_unknown_attrs[] = {
821         &ipl_type_attr.attr,
822         NULL,
823 };
824
825 static struct attribute_group ipl_unknown_attr_group = {
826         .attrs = ipl_unknown_attrs,
827 };
828
829 static ssize_t
830 ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
831 {
832         unsigned int size = IPL_PARMBLOCK_SIZE;
833
834         if (off > size)
835                 return 0;
836         if (off + count > size)
837                 count = size - off;
838
839         memcpy(buf, (void *) IPL_PARMBLOCK_START + off, count);
840         return count;
841 }
842
843 static struct bin_attribute ipl_parameter_attr = {
844         .attr = {
845                 .name = "binary_parameter",
846                 .mode = S_IRUGO,
847                 .owner = THIS_MODULE,
848         },
849         .size = PAGE_SIZE,
850         .read = &ipl_parameter_read,
851 };
852
853 static ssize_t
854 ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
855 {
856         unsigned int size =  IPL_PARMBLOCK_START->fcp.scp_data_len;
857         void *scp_data = &IPL_PARMBLOCK_START->fcp.scp_data;
858
859         if (off > size)
860                 return 0;
861         if (off + count > size)
862                 count = size - off;
863
864         memcpy(buf, scp_data + off, count);
865         return count;
866 }
867
868 static struct bin_attribute ipl_scp_data_attr = {
869         .attr = {
870                 .name = "scp_data",
871                 .mode = S_IRUGO,
872                 .owner = THIS_MODULE,
873         },
874         .size = PAGE_SIZE,
875         .read = &ipl_scp_data_read,
876 };
877
878 static decl_subsys(ipl, NULL, NULL);
879
880 static int ipl_register_fcp_files(void)
881 {
882         int rc;
883
884         rc = sysfs_create_group(&ipl_subsys.kset.kobj,
885                                 &ipl_fcp_attr_group);
886         if (rc)
887                 goto out;
888         rc = sysfs_create_bin_file(&ipl_subsys.kset.kobj,
889                                    &ipl_parameter_attr);
890         if (rc)
891                 goto out_ipl_parm;
892         rc = sysfs_create_bin_file(&ipl_subsys.kset.kobj,
893                                    &ipl_scp_data_attr);
894         if (!rc)
895                 goto out;
896
897         sysfs_remove_bin_file(&ipl_subsys.kset.kobj, &ipl_parameter_attr);
898
899 out_ipl_parm:
900         sysfs_remove_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
901 out:
902         return rc;
903 }
904
905 static int __init
906 ipl_device_sysfs_register(void) {
907         int rc;
908
909         rc = firmware_register(&ipl_subsys);
910         if (rc)
911                 goto out;
912
913         switch (get_ipl_type()) {
914         case ipl_type_ccw:
915                 rc = sysfs_create_group(&ipl_subsys.kset.kobj,
916                                         &ipl_ccw_attr_group);
917                 break;
918         case ipl_type_fcp:
919                 rc = ipl_register_fcp_files();
920                 break;
921         default:
922                 rc = sysfs_create_group(&ipl_subsys.kset.kobj,
923                                         &ipl_unknown_attr_group);
924                 break;
925         }
926
927         if (rc)
928                 firmware_unregister(&ipl_subsys);
929 out:
930         return rc;
931 }
932
933 __initcall(ipl_device_sysfs_register);