[S390] console_unblank woes.
[linux-2.6/libata-dev.git] / arch / s390 / kernel / setup.c
blob813444aac7d7690429d48dba024398395d5d457a
1 /*
2 * arch/s390/kernel/setup.c
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)
9 * Derived from "arch/i386/kernel/setup.c"
10 * Copyright (C) 1995, Linus Torvalds
14 * This file handles the architecture-dependent parts of initialization
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>
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>
53 * Machine setup..
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;
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 ...
75 #include <asm/setup.h>
77 static struct resource code_resource = {
78 .name = "Kernel code",
79 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
82 static struct resource data_resource = {
83 .name = "Kernel data",
84 .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
88 * cpu_init() initializes state that is per-CPU.
90 void __devinit cpu_init (void)
92 int addr = hard_smp_processor_id();
95 * Store processor id in lowcore (used e.g. in timer_interrupt)
97 asm volatile ("stidp %0": "=m" (S390_lowcore.cpu_data.cpu_id));
98 S390_lowcore.cpu_data.cpu_addr = addr;
101 * Force FPU initialization:
103 clear_thread_flag(TIF_USEDFPU);
104 clear_used_math();
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);
114 * VM halt and poweroff setup routines
116 char vmhalt_cmd[128] = "";
117 char vmpoff_cmd[128] = "";
119 static inline void strncpy_skip_quote(char *dst, char *src, int n)
121 int sx, dx;
123 dx = 0;
124 for (sx = 0; src[sx] != 0; sx++) {
125 if (src[sx] == '"') continue;
126 dst[dx++] = src[sx];
127 if (dx >= n) break;
131 static int __init vmhalt_setup(char *str)
133 strncpy_skip_quote(vmhalt_cmd, str, 127);
134 vmhalt_cmd[127] = 0;
135 return 1;
138 __setup("vmhalt=", vmhalt_setup);
140 static int __init vmpoff_setup(char *str)
142 strncpy_skip_quote(vmpoff_cmd, str, 127);
143 vmpoff_cmd[127] = 0;
144 return 1;
147 __setup("vmpoff=", vmpoff_setup);
150 * condev= and conmode= setup parameter.
153 static int __init condev_setup(char *str)
155 int vdev;
157 vdev = simple_strtoul(str, &str, 0);
158 if (vdev >= 0 && vdev < 65536) {
159 console_devno = vdev;
160 console_irq = -1;
162 return 1;
165 __setup("condev=", condev_setup);
167 static int __init conmode_setup(char *str)
169 #if defined(CONFIG_SCLP_CONSOLE)
170 if (strncmp(str, "hwc", 4) == 0 || strncmp(str, "sclp", 5) == 0)
171 SET_CONSOLE_SCLP;
172 #endif
173 #if defined(CONFIG_TN3215_CONSOLE)
174 if (strncmp(str, "3215", 5) == 0)
175 SET_CONSOLE_3215;
176 #endif
177 #if defined(CONFIG_TN3270_CONSOLE)
178 if (strncmp(str, "3270", 5) == 0)
179 SET_CONSOLE_3270;
180 #endif
181 return 1;
184 __setup("conmode=", conmode_setup);
186 static void __init conmode_default(void)
188 char query_buffer[1024];
189 char *ptr;
191 if (MACHINE_IS_VM) {
192 __cpcmd("QUERY CONSOLE", query_buffer, 1024, NULL);
193 console_devno = simple_strtoul(query_buffer + 5, NULL, 16);
194 ptr = strstr(query_buffer, "SUBCHANNEL =");
195 console_irq = simple_strtoul(ptr + 13, NULL, 16);
196 __cpcmd("QUERY TERM", query_buffer, 1024, NULL);
197 ptr = strstr(query_buffer, "CONMODE");
199 * Set the conmode to 3215 so that the device recognition
200 * will set the cu_type of the console to 3215. If the
201 * conmode is 3270 and we don't set it back then both
202 * 3215 and the 3270 driver will try to access the console
203 * device (3215 as console and 3270 as normal tty).
205 __cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
206 if (ptr == NULL) {
207 #if defined(CONFIG_SCLP_CONSOLE)
208 SET_CONSOLE_SCLP;
209 #endif
210 return;
212 if (strncmp(ptr + 8, "3270", 4) == 0) {
213 #if defined(CONFIG_TN3270_CONSOLE)
214 SET_CONSOLE_3270;
215 #elif defined(CONFIG_TN3215_CONSOLE)
216 SET_CONSOLE_3215;
217 #elif defined(CONFIG_SCLP_CONSOLE)
218 SET_CONSOLE_SCLP;
219 #endif
220 } else if (strncmp(ptr + 8, "3215", 4) == 0) {
221 #if defined(CONFIG_TN3215_CONSOLE)
222 SET_CONSOLE_3215;
223 #elif defined(CONFIG_TN3270_CONSOLE)
224 SET_CONSOLE_3270;
225 #elif defined(CONFIG_SCLP_CONSOLE)
226 SET_CONSOLE_SCLP;
227 #endif
229 } else if (MACHINE_IS_P390) {
230 #if defined(CONFIG_TN3215_CONSOLE)
231 SET_CONSOLE_3215;
232 #elif defined(CONFIG_TN3270_CONSOLE)
233 SET_CONSOLE_3270;
234 #endif
235 } else {
236 #if defined(CONFIG_SCLP_CONSOLE)
237 SET_CONSOLE_SCLP;
238 #endif
242 #ifdef CONFIG_SMP
243 extern void machine_restart_smp(char *);
244 extern void machine_halt_smp(void);
245 extern void machine_power_off_smp(void);
247 void (*_machine_restart)(char *command) = machine_restart_smp;
248 void (*_machine_halt)(void) = machine_halt_smp;
249 void (*_machine_power_off)(void) = machine_power_off_smp;
250 #else
252 * Reboot, halt and power_off routines for non SMP.
254 extern void reipl(unsigned long devno);
255 extern void reipl_diag(void);
256 static void do_machine_restart_nonsmp(char * __unused)
258 reipl_diag();
260 if (MACHINE_IS_VM)
261 cpcmd ("IPL", NULL, 0, NULL);
262 else
263 reipl (0x10000 | S390_lowcore.ipl_device);
266 static void do_machine_halt_nonsmp(void)
268 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
269 cpcmd(vmhalt_cmd, NULL, 0, NULL);
270 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
273 static void do_machine_power_off_nonsmp(void)
275 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
276 cpcmd(vmpoff_cmd, NULL, 0, NULL);
277 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
280 void (*_machine_restart)(char *command) = do_machine_restart_nonsmp;
281 void (*_machine_halt)(void) = do_machine_halt_nonsmp;
282 void (*_machine_power_off)(void) = do_machine_power_off_nonsmp;
283 #endif
286 * Reboot, halt and power_off stubs. They just call _machine_restart,
287 * _machine_halt or _machine_power_off.
290 void machine_restart(char *command)
292 if (!in_interrupt() || oops_in_progress)
294 * Only unblank the console if we are called in enabled
295 * context or a bust_spinlocks cleared the way for us.
297 console_unblank();
298 _machine_restart(command);
301 void machine_halt(void)
303 if (!in_interrupt() || oops_in_progress)
305 * Only unblank the console if we are called in enabled
306 * context or a bust_spinlocks cleared the way for us.
308 console_unblank();
309 _machine_halt();
312 void machine_power_off(void)
314 if (!in_interrupt() || oops_in_progress)
316 * Only unblank the console if we are called in enabled
317 * context or a bust_spinlocks cleared the way for us.
319 console_unblank();
320 _machine_power_off();
324 * Dummy power off function.
326 void (*pm_power_off)(void) = machine_power_off;
328 static void __init
329 add_memory_hole(unsigned long start, unsigned long end)
331 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
333 if (end <= dma_pfn)
334 zholes_size[ZONE_DMA] += end - start + 1;
335 else if (start > dma_pfn)
336 zholes_size[ZONE_NORMAL] += end - start + 1;
337 else {
338 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
339 zholes_size[ZONE_NORMAL] += end - dma_pfn;
343 static int __init early_parse_mem(char *p)
345 memory_end = memparse(p, &p);
346 return 0;
348 early_param("mem", early_parse_mem);
351 * "ipldelay=XXX[sm]" sets ipl delay in seconds or minutes
353 static int __init early_parse_ipldelay(char *p)
355 unsigned long delay = 0;
357 delay = simple_strtoul(p, &p, 0);
359 switch (*p) {
360 case 's':
361 case 'S':
362 delay *= 1000000;
363 break;
364 case 'm':
365 case 'M':
366 delay *= 60 * 1000000;
369 /* now wait for the requested amount of time */
370 udelay(delay);
372 return 0;
374 early_param("ipldelay", early_parse_ipldelay);
376 static void __init
377 setup_lowcore(void)
379 struct _lowcore *lc;
380 int lc_pages;
383 * Setup lowcore for boot cpu
385 lc_pages = sizeof(void *) == 8 ? 2 : 1;
386 lc = (struct _lowcore *)
387 __alloc_bootmem(lc_pages * PAGE_SIZE, lc_pages * PAGE_SIZE, 0);
388 memset(lc, 0, lc_pages * PAGE_SIZE);
389 lc->restart_psw.mask = PSW_BASE_BITS | PSW_DEFAULT_KEY;
390 lc->restart_psw.addr =
391 PSW_ADDR_AMODE | (unsigned long) restart_int_handler;
392 lc->external_new_psw.mask = PSW_KERNEL_BITS;
393 lc->external_new_psw.addr =
394 PSW_ADDR_AMODE | (unsigned long) ext_int_handler;
395 lc->svc_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_IO | PSW_MASK_EXT;
396 lc->svc_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) system_call;
397 lc->program_new_psw.mask = PSW_KERNEL_BITS;
398 lc->program_new_psw.addr =
399 PSW_ADDR_AMODE | (unsigned long)pgm_check_handler;
400 lc->mcck_new_psw.mask =
401 PSW_KERNEL_BITS & ~PSW_MASK_MCHECK & ~PSW_MASK_DAT;
402 lc->mcck_new_psw.addr =
403 PSW_ADDR_AMODE | (unsigned long) mcck_int_handler;
404 lc->io_new_psw.mask = PSW_KERNEL_BITS;
405 lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
406 lc->ipl_device = S390_lowcore.ipl_device;
407 lc->jiffy_timer = -1LL;
408 lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
409 lc->async_stack = (unsigned long)
410 __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
411 lc->panic_stack = (unsigned long)
412 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0) + PAGE_SIZE;
413 lc->current_task = (unsigned long) init_thread_union.thread_info.task;
414 lc->thread_info = (unsigned long) &init_thread_union;
415 #ifndef CONFIG_64BIT
416 if (MACHINE_HAS_IEEE) {
417 lc->extended_save_area_addr = (__u32)
418 __alloc_bootmem(PAGE_SIZE, PAGE_SIZE, 0);
419 /* enable extended save area */
420 ctl_set_bit(14, 29);
422 #endif
423 set_prefix((u32)(unsigned long) lc);
426 static void __init
427 setup_resources(void)
429 struct resource *res;
430 int i;
432 code_resource.start = (unsigned long) &_text;
433 code_resource.end = (unsigned long) &_etext - 1;
434 data_resource.start = (unsigned long) &_etext;
435 data_resource.end = (unsigned long) &_edata - 1;
437 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
438 res = alloc_bootmem_low(sizeof(struct resource));
439 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
440 switch (memory_chunk[i].type) {
441 case CHUNK_READ_WRITE:
442 res->name = "System RAM";
443 break;
444 case CHUNK_READ_ONLY:
445 res->name = "System ROM";
446 res->flags |= IORESOURCE_READONLY;
447 break;
448 default:
449 res->name = "reserved";
451 res->start = memory_chunk[i].addr;
452 res->end = memory_chunk[i].addr + memory_chunk[i].size - 1;
453 request_resource(&iomem_resource, res);
454 request_resource(res, &code_resource);
455 request_resource(res, &data_resource);
459 static void __init
460 setup_memory(void)
462 unsigned long bootmap_size;
463 unsigned long start_pfn, end_pfn, init_pfn;
464 unsigned long last_rw_end;
465 int i;
468 * partially used pages are not usable - thus
469 * we are rounding upwards:
471 start_pfn = (__pa(&_end) + PAGE_SIZE - 1) >> PAGE_SHIFT;
472 end_pfn = max_pfn = memory_end >> PAGE_SHIFT;
474 /* Initialize storage key for kernel pages */
475 for (init_pfn = 0 ; init_pfn < start_pfn; init_pfn++)
476 page_set_storage_key(init_pfn << PAGE_SHIFT, PAGE_DEFAULT_KEY);
479 * Initialize the boot-time allocator (with low memory only):
481 bootmap_size = init_bootmem(start_pfn, end_pfn);
484 * Register RAM areas with the bootmem allocator.
486 last_rw_end = start_pfn;
488 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
489 unsigned long start_chunk, end_chunk;
491 if (memory_chunk[i].type != CHUNK_READ_WRITE)
492 continue;
493 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1);
494 start_chunk >>= PAGE_SHIFT;
495 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size);
496 end_chunk >>= PAGE_SHIFT;
497 if (start_chunk < start_pfn)
498 start_chunk = start_pfn;
499 if (end_chunk > end_pfn)
500 end_chunk = end_pfn;
501 if (start_chunk < end_chunk) {
502 /* Initialize storage key for RAM pages */
503 for (init_pfn = start_chunk ; init_pfn < end_chunk;
504 init_pfn++)
505 page_set_storage_key(init_pfn << PAGE_SHIFT,
506 PAGE_DEFAULT_KEY);
507 free_bootmem(start_chunk << PAGE_SHIFT,
508 (end_chunk - start_chunk) << PAGE_SHIFT);
509 if (last_rw_end < start_chunk)
510 add_memory_hole(last_rw_end, start_chunk - 1);
511 last_rw_end = end_chunk;
515 psw_set_key(PAGE_DEFAULT_KEY);
517 if (last_rw_end < end_pfn - 1)
518 add_memory_hole(last_rw_end, end_pfn - 1);
521 * Reserve the bootmem bitmap itself as well. We do this in two
522 * steps (first step was init_bootmem()) because this catches
523 * the (very unlikely) case of us accidentally initializing the
524 * bootmem allocator with an invalid RAM area.
526 reserve_bootmem(start_pfn << PAGE_SHIFT, bootmap_size);
528 #ifdef CONFIG_BLK_DEV_INITRD
529 if (INITRD_START) {
530 if (INITRD_START + INITRD_SIZE <= memory_end) {
531 reserve_bootmem(INITRD_START, INITRD_SIZE);
532 initrd_start = INITRD_START;
533 initrd_end = initrd_start + INITRD_SIZE;
534 } else {
535 printk("initrd extends beyond end of memory "
536 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
537 initrd_start + INITRD_SIZE, memory_end);
538 initrd_start = initrd_end = 0;
541 #endif
545 * Setup function called from init/main.c just after the banner
546 * was printed.
549 void __init
550 setup_arch(char **cmdline_p)
553 * print what head.S has found out about the machine
555 #ifndef CONFIG_64BIT
556 printk((MACHINE_IS_VM) ?
557 "We are running under VM (31 bit mode)\n" :
558 "We are running native (31 bit mode)\n");
559 printk((MACHINE_HAS_IEEE) ?
560 "This machine has an IEEE fpu\n" :
561 "This machine has no IEEE fpu\n");
562 #else /* CONFIG_64BIT */
563 printk((MACHINE_IS_VM) ?
564 "We are running under VM (64 bit mode)\n" :
565 "We are running native (64 bit mode)\n");
566 #endif /* CONFIG_64BIT */
568 /* Save unparsed command line copy for /proc/cmdline */
569 strlcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
571 *cmdline_p = COMMAND_LINE;
572 *(*cmdline_p + COMMAND_LINE_SIZE - 1) = '\0';
574 ROOT_DEV = Root_RAM0;
576 init_mm.start_code = PAGE_OFFSET;
577 init_mm.end_code = (unsigned long) &_etext;
578 init_mm.end_data = (unsigned long) &_edata;
579 init_mm.brk = (unsigned long) &_end;
581 memory_end = memory_size;
583 parse_early_param();
585 #ifndef CONFIG_64BIT
586 memory_end &= ~0x400000UL;
589 * We need some free virtual space to be able to do vmalloc.
590 * On a machine with 2GB memory we make sure that we have at
591 * least 128 MB free space for vmalloc.
593 if (memory_end > 1920*1024*1024)
594 memory_end = 1920*1024*1024;
595 #else /* CONFIG_64BIT */
596 memory_end &= ~0x200000UL;
597 #endif /* CONFIG_64BIT */
599 setup_memory();
600 setup_resources();
601 setup_lowcore();
603 cpu_init();
604 __cpu_logical_map[0] = S390_lowcore.cpu_data.cpu_addr;
605 smp_setup_cpu_possible_map();
608 * Create kernel page tables and switch to virtual addressing.
610 paging_init();
612 /* Setup default console */
613 conmode_default();
616 void print_cpu_info(struct cpuinfo_S390 *cpuinfo)
618 printk("cpu %d "
619 #ifdef CONFIG_SMP
620 "phys_idx=%d "
621 #endif
622 "vers=%02X ident=%06X machine=%04X unused=%04X\n",
623 cpuinfo->cpu_nr,
624 #ifdef CONFIG_SMP
625 cpuinfo->cpu_addr,
626 #endif
627 cpuinfo->cpu_id.version,
628 cpuinfo->cpu_id.ident,
629 cpuinfo->cpu_id.machine,
630 cpuinfo->cpu_id.unused);
634 * show_cpuinfo - Get information on one CPU for use by procfs.
637 static int show_cpuinfo(struct seq_file *m, void *v)
639 struct cpuinfo_S390 *cpuinfo;
640 unsigned long n = (unsigned long) v - 1;
642 preempt_disable();
643 if (!n) {
644 seq_printf(m, "vendor_id : IBM/S390\n"
645 "# processors : %i\n"
646 "bogomips per cpu: %lu.%02lu\n",
647 num_online_cpus(), loops_per_jiffy/(500000/HZ),
648 (loops_per_jiffy/(5000/HZ))%100);
650 if (cpu_online(n)) {
651 #ifdef CONFIG_SMP
652 if (smp_processor_id() == n)
653 cpuinfo = &S390_lowcore.cpu_data;
654 else
655 cpuinfo = &lowcore_ptr[n]->cpu_data;
656 #else
657 cpuinfo = &S390_lowcore.cpu_data;
658 #endif
659 seq_printf(m, "processor %li: "
660 "version = %02X, "
661 "identification = %06X, "
662 "machine = %04X\n",
663 n, cpuinfo->cpu_id.version,
664 cpuinfo->cpu_id.ident,
665 cpuinfo->cpu_id.machine);
667 preempt_enable();
668 return 0;
671 static void *c_start(struct seq_file *m, loff_t *pos)
673 return *pos < NR_CPUS ? (void *)((unsigned long) *pos + 1) : NULL;
675 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
677 ++*pos;
678 return c_start(m, pos);
680 static void c_stop(struct seq_file *m, void *v)
683 struct seq_operations cpuinfo_op = {
684 .start = c_start,
685 .next = c_next,
686 .stop = c_stop,
687 .show = show_cpuinfo,
690 #define DEFINE_IPL_ATTR(_name, _format, _value) \
691 static ssize_t ipl_##_name##_show(struct subsystem *subsys, \
692 char *page) \
694 return sprintf(page, _format, _value); \
696 static struct subsys_attribute ipl_##_name##_attr = \
697 __ATTR(_name, S_IRUGO, ipl_##_name##_show, NULL);
699 DEFINE_IPL_ATTR(wwpn, "0x%016llx\n", (unsigned long long)
700 IPL_PARMBLOCK_START->fcp.wwpn);
701 DEFINE_IPL_ATTR(lun, "0x%016llx\n", (unsigned long long)
702 IPL_PARMBLOCK_START->fcp.lun);
703 DEFINE_IPL_ATTR(bootprog, "%lld\n", (unsigned long long)
704 IPL_PARMBLOCK_START->fcp.bootprog);
705 DEFINE_IPL_ATTR(br_lba, "%lld\n", (unsigned long long)
706 IPL_PARMBLOCK_START->fcp.br_lba);
708 enum ipl_type_type {
709 ipl_type_unknown,
710 ipl_type_ccw,
711 ipl_type_fcp,
714 static enum ipl_type_type
715 get_ipl_type(void)
717 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
719 if (!IPL_DEVNO_VALID)
720 return ipl_type_unknown;
721 if (!IPL_PARMBLOCK_VALID)
722 return ipl_type_ccw;
723 if (ipl->hdr.header.version > IPL_MAX_SUPPORTED_VERSION)
724 return ipl_type_unknown;
725 if (ipl->fcp.pbt != IPL_TYPE_FCP)
726 return ipl_type_unknown;
727 return ipl_type_fcp;
730 static ssize_t
731 ipl_type_show(struct subsystem *subsys, char *page)
733 switch (get_ipl_type()) {
734 case ipl_type_ccw:
735 return sprintf(page, "ccw\n");
736 case ipl_type_fcp:
737 return sprintf(page, "fcp\n");
738 default:
739 return sprintf(page, "unknown\n");
743 static struct subsys_attribute ipl_type_attr = __ATTR_RO(ipl_type);
745 static ssize_t
746 ipl_device_show(struct subsystem *subsys, char *page)
748 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
750 switch (get_ipl_type()) {
751 case ipl_type_ccw:
752 return sprintf(page, "0.0.%04x\n", ipl_devno);
753 case ipl_type_fcp:
754 return sprintf(page, "0.0.%04x\n", ipl->fcp.devno);
755 default:
756 return 0;
760 static struct subsys_attribute ipl_device_attr =
761 __ATTR(device, S_IRUGO, ipl_device_show, NULL);
763 static struct attribute *ipl_fcp_attrs[] = {
764 &ipl_type_attr.attr,
765 &ipl_device_attr.attr,
766 &ipl_wwpn_attr.attr,
767 &ipl_lun_attr.attr,
768 &ipl_bootprog_attr.attr,
769 &ipl_br_lba_attr.attr,
770 NULL,
773 static struct attribute_group ipl_fcp_attr_group = {
774 .attrs = ipl_fcp_attrs,
777 static struct attribute *ipl_ccw_attrs[] = {
778 &ipl_type_attr.attr,
779 &ipl_device_attr.attr,
780 NULL,
783 static struct attribute_group ipl_ccw_attr_group = {
784 .attrs = ipl_ccw_attrs,
787 static struct attribute *ipl_unknown_attrs[] = {
788 &ipl_type_attr.attr,
789 NULL,
792 static struct attribute_group ipl_unknown_attr_group = {
793 .attrs = ipl_unknown_attrs,
796 static ssize_t
797 ipl_parameter_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
799 unsigned int size = IPL_PARMBLOCK_SIZE;
801 if (off > size)
802 return 0;
803 if (off + count > size)
804 count = size - off;
806 memcpy(buf, (void *) IPL_PARMBLOCK_START + off, count);
807 return count;
810 static struct bin_attribute ipl_parameter_attr = {
811 .attr = {
812 .name = "binary_parameter",
813 .mode = S_IRUGO,
814 .owner = THIS_MODULE,
816 .size = PAGE_SIZE,
817 .read = &ipl_parameter_read,
820 static ssize_t
821 ipl_scp_data_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
823 unsigned int size = IPL_PARMBLOCK_START->fcp.scp_data_len;
824 void *scp_data = &IPL_PARMBLOCK_START->fcp.scp_data;
826 if (off > size)
827 return 0;
828 if (off + count > size)
829 count = size - off;
831 memcpy(buf, scp_data + off, count);
832 return count;
835 static struct bin_attribute ipl_scp_data_attr = {
836 .attr = {
837 .name = "scp_data",
838 .mode = S_IRUGO,
839 .owner = THIS_MODULE,
841 .size = PAGE_SIZE,
842 .read = &ipl_scp_data_read,
845 static decl_subsys(ipl, NULL, NULL);
847 static int __init
848 ipl_device_sysfs_register(void) {
849 int rc;
851 rc = firmware_register(&ipl_subsys);
852 if (rc)
853 return rc;
855 switch (get_ipl_type()) {
856 case ipl_type_ccw:
857 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_ccw_attr_group);
858 break;
859 case ipl_type_fcp:
860 sysfs_create_group(&ipl_subsys.kset.kobj, &ipl_fcp_attr_group);
861 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
862 &ipl_parameter_attr);
863 sysfs_create_bin_file(&ipl_subsys.kset.kobj,
864 &ipl_scp_data_attr);
865 break;
866 default:
867 sysfs_create_group(&ipl_subsys.kset.kobj,
868 &ipl_unknown_attr_group);
869 break;
871 return 0;
874 __initcall(ipl_device_sysfs_register);