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