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