2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
18 #include <linux/gfp.h>
21 #include <asm/setup.h>
22 #include <asm/cpcmd.h>
24 #include <asm/ebcdic.h>
25 #include <asm/reset.h>
28 #include <asm/checksum.h>
30 #define IPL_PARM_BLOCK_VERSION 0
32 #define IPL_UNKNOWN_STR "unknown"
33 #define IPL_CCW_STR "ccw"
34 #define IPL_FCP_STR "fcp"
35 #define IPL_FCP_DUMP_STR "fcp_dump"
36 #define IPL_NSS_STR "nss"
38 #define DUMP_CCW_STR "ccw"
39 #define DUMP_FCP_STR "fcp"
40 #define DUMP_NONE_STR "none"
43 * Four shutdown trigger types are supported:
49 #define ON_PANIC_STR "on_panic"
50 #define ON_HALT_STR "on_halt"
51 #define ON_POFF_STR "on_poff"
52 #define ON_REIPL_STR "on_reboot"
54 struct shutdown_action
;
55 struct shutdown_trigger
{
57 struct shutdown_action
*action
;
61 * The following shutdown action types are supported:
63 #define SHUTDOWN_ACTION_IPL_STR "ipl"
64 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
65 #define SHUTDOWN_ACTION_DUMP_STR "dump"
66 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
67 #define SHUTDOWN_ACTION_STOP_STR "stop"
68 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
70 struct shutdown_action
{
72 void (*fn
) (struct shutdown_trigger
*trigger
);
77 static char *ipl_type_str(enum ipl_type type
)
84 case IPL_TYPE_FCP_DUMP
:
85 return IPL_FCP_DUMP_STR
;
88 case IPL_TYPE_UNKNOWN
:
90 return IPL_UNKNOWN_STR
;
100 static char *dump_type_str(enum dump_type type
)
104 return DUMP_NONE_STR
;
115 * Must be in data section since the bss section
116 * is not cleared when these are accessed.
118 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
119 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
122 REIPL_METHOD_CCW_CIO
,
123 REIPL_METHOD_CCW_DIAG
,
125 REIPL_METHOD_FCP_RO_DIAG
,
126 REIPL_METHOD_FCP_RW_DIAG
,
127 REIPL_METHOD_FCP_RO_VM
,
128 REIPL_METHOD_FCP_DUMP
,
130 REIPL_METHOD_NSS_DIAG
,
131 REIPL_METHOD_DEFAULT
,
137 DUMP_METHOD_CCW_DIAG
,
139 DUMP_METHOD_FCP_DIAG
,
142 static int diag308_set_works
= 0;
144 static struct ipl_parameter_block ipl_block
;
146 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
148 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
149 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
150 static struct ipl_parameter_block
*reipl_block_fcp
;
151 static struct ipl_parameter_block
*reipl_block_ccw
;
152 static struct ipl_parameter_block
*reipl_block_nss
;
153 static struct ipl_parameter_block
*reipl_block_actual
;
155 static int dump_capabilities
= DUMP_TYPE_NONE
;
156 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
157 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
158 static struct ipl_parameter_block
*dump_block_fcp
;
159 static struct ipl_parameter_block
*dump_block_ccw
;
161 static struct sclp_ipl_info sclp_ipl_info
;
163 int diag308(unsigned long subcode
, void *addr
)
165 register unsigned long _addr
asm("0") = (unsigned long) addr
;
166 register unsigned long _rc
asm("1") = 0;
169 " diag %0,%2,0x308\n"
172 : "+d" (_addr
), "+d" (_rc
)
173 : "d" (subcode
) : "cc", "memory");
176 EXPORT_SYMBOL_GPL(diag308
);
180 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
181 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
182 struct kobj_attribute *attr, \
185 return sprintf(page, _format, _value); \
187 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
188 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
190 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
191 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
192 struct kobj_attribute *attr, \
195 return sprintf(page, _fmt_out, \
196 (unsigned long long) _value); \
198 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
199 struct kobj_attribute *attr, \
200 const char *buf, size_t len) \
202 unsigned long long value; \
203 if (sscanf(buf, _fmt_in, &value) != 1) \
208 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
209 __ATTR(_name,(S_IRUGO | S_IWUSR), \
210 sys_##_prefix##_##_name##_show, \
211 sys_##_prefix##_##_name##_store);
213 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
214 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
215 struct kobj_attribute *attr, \
218 return sprintf(page, _fmt_out, _value); \
220 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
221 struct kobj_attribute *attr, \
222 const char *buf, size_t len) \
224 strncpy(_value, buf, sizeof(_value) - 1); \
228 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
229 __ATTR(_name,(S_IRUGO | S_IWUSR), \
230 sys_##_prefix##_##_name##_show, \
231 sys_##_prefix##_##_name##_store);
233 static void make_attrs_ro(struct attribute
**attrs
)
236 (*attrs
)->mode
= S_IRUGO
;
245 static __init
enum ipl_type
get_ipl_type(void)
247 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
249 if (ipl_flags
& IPL_NSS_VALID
)
251 if (!(ipl_flags
& IPL_DEVNO_VALID
))
252 return IPL_TYPE_UNKNOWN
;
253 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
255 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
256 return IPL_TYPE_UNKNOWN
;
257 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
258 return IPL_TYPE_UNKNOWN
;
259 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
260 return IPL_TYPE_FCP_DUMP
;
264 struct ipl_info ipl_info
;
265 EXPORT_SYMBOL_GPL(ipl_info
);
267 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
270 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
273 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
275 /* VM IPL PARM routines */
276 size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
277 const struct ipl_parameter_block
*ipb
)
281 char has_lowercase
= 0;
284 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
285 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
287 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
288 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
289 /* If at least one character is lowercase, we assume mixed
290 * case; otherwise we convert everything to lowercase.
292 for (i
= 0; i
< len
; i
++)
293 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
294 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
295 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
300 EBC_TOLOWER(dest
, len
);
308 size_t append_ipl_vmparm(char *dest
, size_t size
)
313 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
314 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
320 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
321 struct kobj_attribute
*attr
, char *page
)
323 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
325 append_ipl_vmparm(parm
, sizeof(parm
));
326 return sprintf(page
, "%s\n", parm
);
329 static size_t scpdata_length(const char* buf
, size_t count
)
332 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
339 size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
340 const struct ipl_parameter_block
*ipb
)
346 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
347 ipb
->ipl_info
.fcp
.scp_data_len
));
352 for (i
= 0; i
< count
; i
++) {
353 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
357 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
362 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
364 for (i
= 0; i
< count
; i
++)
365 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
371 size_t append_ipl_scpdata(char *dest
, size_t len
)
376 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
377 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
384 static struct kobj_attribute sys_ipl_vm_parm_attr
=
385 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
387 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
388 struct kobj_attribute
*attr
, char *page
)
390 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
392 switch (ipl_info
.type
) {
394 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
396 case IPL_TYPE_FCP_DUMP
:
397 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
403 static struct kobj_attribute sys_ipl_device_attr
=
404 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
406 static ssize_t
ipl_parameter_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
407 char *buf
, loff_t off
, size_t count
)
409 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
413 static struct bin_attribute ipl_parameter_attr
= {
415 .name
= "binary_parameter",
419 .read
= &ipl_parameter_read
,
422 static ssize_t
ipl_scp_data_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
423 char *buf
, loff_t off
, size_t count
)
425 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
426 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
428 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
431 static struct bin_attribute ipl_scp_data_attr
= {
437 .read
= ipl_scp_data_read
,
440 /* FCP ipl device attributes */
442 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
443 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
444 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
445 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
446 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
447 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
448 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
449 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
451 static struct attribute
*ipl_fcp_attrs
[] = {
452 &sys_ipl_type_attr
.attr
,
453 &sys_ipl_device_attr
.attr
,
454 &sys_ipl_fcp_wwpn_attr
.attr
,
455 &sys_ipl_fcp_lun_attr
.attr
,
456 &sys_ipl_fcp_bootprog_attr
.attr
,
457 &sys_ipl_fcp_br_lba_attr
.attr
,
461 static struct attribute_group ipl_fcp_attr_group
= {
462 .attrs
= ipl_fcp_attrs
,
465 /* CCW ipl device attributes */
467 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
468 struct kobj_attribute
*attr
, char *page
)
470 char loadparm
[LOADPARM_LEN
+ 1] = {};
472 if (!sclp_ipl_info
.is_valid
)
473 return sprintf(page
, "#unknown#\n");
474 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
475 EBCASC(loadparm
, LOADPARM_LEN
);
477 return sprintf(page
, "%s\n", loadparm
);
480 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
481 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
483 static struct attribute
*ipl_ccw_attrs_vm
[] = {
484 &sys_ipl_type_attr
.attr
,
485 &sys_ipl_device_attr
.attr
,
486 &sys_ipl_ccw_loadparm_attr
.attr
,
487 &sys_ipl_vm_parm_attr
.attr
,
491 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
492 &sys_ipl_type_attr
.attr
,
493 &sys_ipl_device_attr
.attr
,
494 &sys_ipl_ccw_loadparm_attr
.attr
,
498 static struct attribute_group ipl_ccw_attr_group_vm
= {
499 .attrs
= ipl_ccw_attrs_vm
,
502 static struct attribute_group ipl_ccw_attr_group_lpar
= {
503 .attrs
= ipl_ccw_attrs_lpar
506 /* NSS ipl device attributes */
508 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
510 static struct attribute
*ipl_nss_attrs
[] = {
511 &sys_ipl_type_attr
.attr
,
512 &sys_ipl_nss_name_attr
.attr
,
513 &sys_ipl_ccw_loadparm_attr
.attr
,
514 &sys_ipl_vm_parm_attr
.attr
,
518 static struct attribute_group ipl_nss_attr_group
= {
519 .attrs
= ipl_nss_attrs
,
522 /* UNKNOWN ipl device attributes */
524 static struct attribute
*ipl_unknown_attrs
[] = {
525 &sys_ipl_type_attr
.attr
,
529 static struct attribute_group ipl_unknown_attr_group
= {
530 .attrs
= ipl_unknown_attrs
,
533 static struct kset
*ipl_kset
;
535 static int __init
ipl_register_fcp_files(void)
539 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
542 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
545 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
549 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
552 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
557 static void __ipl_run(void *unused
)
559 diag308(DIAG308_IPL
, NULL
);
561 __cpcmd("IPL", NULL
, 0, NULL
);
562 else if (ipl_info
.type
== IPL_TYPE_CCW
)
563 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
566 static void ipl_run(struct shutdown_trigger
*trigger
)
568 smp_switch_to_ipl_cpu(__ipl_run
, NULL
);
571 static int __init
ipl_init(void)
575 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
580 switch (ipl_info
.type
) {
583 rc
= sysfs_create_group(&ipl_kset
->kobj
,
584 &ipl_ccw_attr_group_vm
);
586 rc
= sysfs_create_group(&ipl_kset
->kobj
,
587 &ipl_ccw_attr_group_lpar
);
590 case IPL_TYPE_FCP_DUMP
:
591 rc
= ipl_register_fcp_files();
594 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
597 rc
= sysfs_create_group(&ipl_kset
->kobj
,
598 &ipl_unknown_attr_group
);
603 panic("ipl_init failed: rc = %i\n", rc
);
608 static struct shutdown_action __refdata ipl_action
= {
609 .name
= SHUTDOWN_ACTION_IPL_STR
,
615 * reipl shutdown action: Reboot Linux on shutdown.
618 /* VM IPL PARM attributes */
619 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
622 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
624 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
625 return sprintf(page
, "%s\n", vmparm
);
628 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
630 const char *buf
, size_t len
)
634 /* ignore trailing newline */
636 if ((len
> 0) && (buf
[len
- 1] == '\n'))
639 if (ip_len
> vmparm_max
)
642 /* parm is used to store kernel options, check for common chars */
643 for (i
= 0; i
< ip_len
; i
++)
644 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
647 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
648 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
650 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
651 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
652 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
654 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
661 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
662 struct kobj_attribute
*attr
, char *page
)
664 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
667 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
668 struct kobj_attribute
*attr
,
669 const char *buf
, size_t len
)
671 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
675 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
676 struct kobj_attribute
*attr
, char *page
)
678 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
681 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
682 struct kobj_attribute
*attr
,
683 const char *buf
, size_t len
)
685 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
688 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
689 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
690 reipl_nss_vmparm_store
);
691 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
692 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
693 reipl_ccw_vmparm_store
);
695 /* FCP reipl device attributes */
697 static ssize_t
reipl_fcp_scpdata_read(struct kobject
*kobj
,
698 struct bin_attribute
*attr
,
699 char *buf
, loff_t off
, size_t count
)
701 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
702 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
704 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
707 static ssize_t
reipl_fcp_scpdata_write(struct kobject
*kobj
,
708 struct bin_attribute
*attr
,
709 char *buf
, loff_t off
, size_t count
)
717 if (off
>= DIAG308_SCPDATA_SIZE
)
720 if (count
> DIAG308_SCPDATA_SIZE
- off
)
721 count
= DIAG308_SCPDATA_SIZE
- off
;
723 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
724 scpdata_len
= off
+ count
;
726 if (scpdata_len
% 8) {
727 padding
= 8 - (scpdata_len
% 8);
728 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
730 scpdata_len
+= padding
;
733 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
734 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
735 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
740 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
743 .mode
= S_IRUGO
| S_IWUSR
,
746 .read
= reipl_fcp_scpdata_read
,
747 .write
= reipl_fcp_scpdata_write
,
750 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
751 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
752 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
753 reipl_block_fcp
->ipl_info
.fcp
.lun
);
754 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
755 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
756 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
757 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
758 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
759 reipl_block_fcp
->ipl_info
.fcp
.devno
);
761 static struct attribute
*reipl_fcp_attrs
[] = {
762 &sys_reipl_fcp_device_attr
.attr
,
763 &sys_reipl_fcp_wwpn_attr
.attr
,
764 &sys_reipl_fcp_lun_attr
.attr
,
765 &sys_reipl_fcp_bootprog_attr
.attr
,
766 &sys_reipl_fcp_br_lba_attr
.attr
,
770 static struct attribute_group reipl_fcp_attr_group
= {
771 .attrs
= reipl_fcp_attrs
,
774 /* CCW reipl device attributes */
776 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
777 reipl_block_ccw
->ipl_info
.ccw
.devno
);
779 static void reipl_get_ascii_loadparm(char *loadparm
,
780 struct ipl_parameter_block
*ibp
)
782 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
783 EBCASC(loadparm
, LOADPARM_LEN
);
784 loadparm
[LOADPARM_LEN
] = 0;
788 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
791 char buf
[LOADPARM_LEN
+ 1];
793 reipl_get_ascii_loadparm(buf
, ipb
);
794 return sprintf(page
, "%s\n", buf
);
797 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
798 const char *buf
, size_t len
)
802 /* ignore trailing newline */
804 if ((len
> 0) && (buf
[len
- 1] == '\n'))
806 /* loadparm can have max 8 characters and must not start with a blank */
807 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
809 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
810 for (i
= 0; i
< lp_len
; i
++) {
811 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
816 /* initialize loadparm with blanks */
817 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
818 /* copy and convert to ebcdic */
819 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
820 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
825 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
826 struct kobj_attribute
*attr
, char *page
)
828 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
831 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
832 struct kobj_attribute
*attr
,
833 const char *buf
, size_t len
)
835 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
839 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
840 struct kobj_attribute
*attr
, char *page
)
842 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
845 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
846 struct kobj_attribute
*attr
,
847 const char *buf
, size_t len
)
849 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
852 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
853 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
854 reipl_ccw_loadparm_store
);
856 static struct attribute
*reipl_ccw_attrs_vm
[] = {
857 &sys_reipl_ccw_device_attr
.attr
,
858 &sys_reipl_ccw_loadparm_attr
.attr
,
859 &sys_reipl_ccw_vmparm_attr
.attr
,
863 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
864 &sys_reipl_ccw_device_attr
.attr
,
865 &sys_reipl_ccw_loadparm_attr
.attr
,
869 static struct attribute_group reipl_ccw_attr_group_vm
= {
871 .attrs
= reipl_ccw_attrs_vm
,
874 static struct attribute_group reipl_ccw_attr_group_lpar
= {
876 .attrs
= reipl_ccw_attrs_lpar
,
880 /* NSS reipl device attributes */
881 static void reipl_get_ascii_nss_name(char *dst
,
882 struct ipl_parameter_block
*ipb
)
884 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
885 EBCASC(dst
, NSS_NAME_SIZE
);
886 dst
[NSS_NAME_SIZE
] = 0;
889 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
890 struct kobj_attribute
*attr
, char *page
)
892 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
894 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
895 return sprintf(page
, "%s\n", nss_name
);
898 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
899 struct kobj_attribute
*attr
,
900 const char *buf
, size_t len
)
904 /* ignore trailing newline */
906 if ((len
> 0) && (buf
[len
- 1] == '\n'))
909 if (nss_len
> NSS_NAME_SIZE
)
912 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
914 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
915 DIAG308_VM_FLAGS_NSS_VALID
;
916 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
917 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
918 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
920 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
921 ~DIAG308_VM_FLAGS_NSS_VALID
;
927 static struct kobj_attribute sys_reipl_nss_name_attr
=
928 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
929 reipl_nss_name_store
);
931 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
932 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
933 reipl_nss_loadparm_store
);
935 static struct attribute
*reipl_nss_attrs
[] = {
936 &sys_reipl_nss_name_attr
.attr
,
937 &sys_reipl_nss_loadparm_attr
.attr
,
938 &sys_reipl_nss_vmparm_attr
.attr
,
942 static struct attribute_group reipl_nss_attr_group
= {
944 .attrs
= reipl_nss_attrs
,
949 static int reipl_set_type(enum ipl_type type
)
951 if (!(reipl_capabilities
& type
))
956 if (diag308_set_works
)
957 reipl_method
= REIPL_METHOD_CCW_DIAG
;
958 else if (MACHINE_IS_VM
)
959 reipl_method
= REIPL_METHOD_CCW_VM
;
961 reipl_method
= REIPL_METHOD_CCW_CIO
;
962 reipl_block_actual
= reipl_block_ccw
;
965 if (diag308_set_works
)
966 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
967 else if (MACHINE_IS_VM
)
968 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
970 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
971 reipl_block_actual
= reipl_block_fcp
;
973 case IPL_TYPE_FCP_DUMP
:
974 reipl_method
= REIPL_METHOD_FCP_DUMP
;
977 if (diag308_set_works
)
978 reipl_method
= REIPL_METHOD_NSS_DIAG
;
980 reipl_method
= REIPL_METHOD_NSS
;
981 reipl_block_actual
= reipl_block_nss
;
983 case IPL_TYPE_UNKNOWN
:
984 reipl_method
= REIPL_METHOD_DEFAULT
;
993 static ssize_t
reipl_type_show(struct kobject
*kobj
,
994 struct kobj_attribute
*attr
, char *page
)
996 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
999 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1000 struct kobj_attribute
*attr
,
1001 const char *buf
, size_t len
)
1005 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1006 rc
= reipl_set_type(IPL_TYPE_CCW
);
1007 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1008 rc
= reipl_set_type(IPL_TYPE_FCP
);
1009 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1010 rc
= reipl_set_type(IPL_TYPE_NSS
);
1011 return (rc
!= 0) ? rc
: len
;
1014 static struct kobj_attribute reipl_type_attr
=
1015 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1017 static struct kset
*reipl_kset
;
1018 static struct kset
*reipl_fcp_kset
;
1020 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1021 const enum ipl_method m
)
1023 char loadparm
[LOADPARM_LEN
+ 1] = {};
1024 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1025 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1028 reipl_get_ascii_loadparm(loadparm
, ipb
);
1029 reipl_get_ascii_nss_name(nss_name
, ipb
);
1030 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1033 case REIPL_METHOD_CCW_VM
:
1034 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1036 case REIPL_METHOD_NSS
:
1037 pos
= sprintf(dst
, "IPL %s", nss_name
);
1042 if (strlen(loadparm
) > 0)
1043 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1044 if (strlen(vmparm
) > 0)
1045 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1048 static void __reipl_run(void *unused
)
1050 struct ccw_dev_id devid
;
1051 static char buf
[128];
1053 switch (reipl_method
) {
1054 case REIPL_METHOD_CCW_CIO
:
1055 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1057 reipl_ccw_dev(&devid
);
1059 case REIPL_METHOD_CCW_VM
:
1060 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1061 __cpcmd(buf
, NULL
, 0, NULL
);
1063 case REIPL_METHOD_CCW_DIAG
:
1064 diag308(DIAG308_SET
, reipl_block_ccw
);
1065 diag308(DIAG308_IPL
, NULL
);
1067 case REIPL_METHOD_FCP_RW_DIAG
:
1068 diag308(DIAG308_SET
, reipl_block_fcp
);
1069 diag308(DIAG308_IPL
, NULL
);
1071 case REIPL_METHOD_FCP_RO_DIAG
:
1072 diag308(DIAG308_IPL
, NULL
);
1074 case REIPL_METHOD_FCP_RO_VM
:
1075 __cpcmd("IPL", NULL
, 0, NULL
);
1077 case REIPL_METHOD_NSS_DIAG
:
1078 diag308(DIAG308_SET
, reipl_block_nss
);
1079 diag308(DIAG308_IPL
, NULL
);
1081 case REIPL_METHOD_NSS
:
1082 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1083 __cpcmd(buf
, NULL
, 0, NULL
);
1085 case REIPL_METHOD_DEFAULT
:
1087 __cpcmd("IPL", NULL
, 0, NULL
);
1088 diag308(DIAG308_IPL
, NULL
);
1090 case REIPL_METHOD_FCP_DUMP
:
1093 disabled_wait((unsigned long) __builtin_return_address(0));
1096 static void reipl_run(struct shutdown_trigger
*trigger
)
1098 smp_switch_to_ipl_cpu(__reipl_run
, NULL
);
1101 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1103 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1104 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1105 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1106 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1109 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1112 /* check if read scp info worked and set loadparm */
1113 if (sclp_ipl_info
.is_valid
)
1114 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
1115 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1117 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1118 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
1119 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1122 if (MACHINE_IS_VM
&& diag308_set_works
&&
1123 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1125 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1126 ipb
->ipl_info
.ccw
.vm_parm_len
=
1127 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1128 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1129 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1133 static int __init
reipl_nss_init(void)
1140 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1141 if (!reipl_block_nss
)
1144 if (!diag308_set_works
)
1145 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1147 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1151 reipl_block_ccw_init(reipl_block_nss
);
1152 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1153 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1154 ' ', NSS_NAME_SIZE
);
1155 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1156 kernel_nss_name
, strlen(kernel_nss_name
));
1157 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1158 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1159 DIAG308_VM_FLAGS_NSS_VALID
;
1161 reipl_block_ccw_fill_parms(reipl_block_nss
);
1164 reipl_capabilities
|= IPL_TYPE_NSS
;
1168 static int __init
reipl_ccw_init(void)
1172 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1173 if (!reipl_block_ccw
)
1176 if (MACHINE_IS_VM
) {
1177 if (!diag308_set_works
)
1178 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1179 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1180 &reipl_ccw_attr_group_vm
);
1182 if(!diag308_set_works
)
1183 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1184 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1185 &reipl_ccw_attr_group_lpar
);
1190 reipl_block_ccw_init(reipl_block_ccw
);
1191 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1192 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1193 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1196 reipl_capabilities
|= IPL_TYPE_CCW
;
1200 static int __init
reipl_fcp_init(void)
1204 if (!diag308_set_works
) {
1205 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1206 make_attrs_ro(reipl_fcp_attrs
);
1207 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1212 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1213 if (!reipl_block_fcp
)
1216 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1217 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1220 free_page((unsigned long) reipl_block_fcp
);
1224 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1226 kset_unregister(reipl_fcp_kset
);
1227 free_page((unsigned long) reipl_block_fcp
);
1231 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1232 &sys_reipl_fcp_scp_data_attr
);
1234 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1235 kset_unregister(reipl_fcp_kset
);
1236 free_page((unsigned long) reipl_block_fcp
);
1240 if (ipl_info
.type
== IPL_TYPE_FCP
)
1241 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1243 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1244 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1245 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1246 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1247 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1249 reipl_capabilities
|= IPL_TYPE_FCP
;
1253 static int __init
reipl_init(void)
1257 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1260 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1262 kset_unregister(reipl_kset
);
1265 rc
= reipl_ccw_init();
1268 rc
= reipl_fcp_init();
1271 rc
= reipl_nss_init();
1274 rc
= reipl_set_type(ipl_info
.type
);
1280 static struct shutdown_action __refdata reipl_action
= {
1281 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1287 * dump shutdown action: Dump Linux on shutdown.
1290 /* FCP dump device attributes */
1292 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1293 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1294 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1295 dump_block_fcp
->ipl_info
.fcp
.lun
);
1296 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1297 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1298 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1299 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1300 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1301 dump_block_fcp
->ipl_info
.fcp
.devno
);
1303 static struct attribute
*dump_fcp_attrs
[] = {
1304 &sys_dump_fcp_device_attr
.attr
,
1305 &sys_dump_fcp_wwpn_attr
.attr
,
1306 &sys_dump_fcp_lun_attr
.attr
,
1307 &sys_dump_fcp_bootprog_attr
.attr
,
1308 &sys_dump_fcp_br_lba_attr
.attr
,
1312 static struct attribute_group dump_fcp_attr_group
= {
1313 .name
= IPL_FCP_STR
,
1314 .attrs
= dump_fcp_attrs
,
1317 /* CCW dump device attributes */
1319 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1320 dump_block_ccw
->ipl_info
.ccw
.devno
);
1322 static struct attribute
*dump_ccw_attrs
[] = {
1323 &sys_dump_ccw_device_attr
.attr
,
1327 static struct attribute_group dump_ccw_attr_group
= {
1328 .name
= IPL_CCW_STR
,
1329 .attrs
= dump_ccw_attrs
,
1334 static int dump_set_type(enum dump_type type
)
1336 if (!(dump_capabilities
& type
))
1340 if (diag308_set_works
)
1341 dump_method
= DUMP_METHOD_CCW_DIAG
;
1342 else if (MACHINE_IS_VM
)
1343 dump_method
= DUMP_METHOD_CCW_VM
;
1345 dump_method
= DUMP_METHOD_CCW_CIO
;
1348 dump_method
= DUMP_METHOD_FCP_DIAG
;
1351 dump_method
= DUMP_METHOD_NONE
;
1357 static ssize_t
dump_type_show(struct kobject
*kobj
,
1358 struct kobj_attribute
*attr
, char *page
)
1360 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1363 static ssize_t
dump_type_store(struct kobject
*kobj
,
1364 struct kobj_attribute
*attr
,
1365 const char *buf
, size_t len
)
1369 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1370 rc
= dump_set_type(DUMP_TYPE_NONE
);
1371 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1372 rc
= dump_set_type(DUMP_TYPE_CCW
);
1373 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1374 rc
= dump_set_type(DUMP_TYPE_FCP
);
1375 return (rc
!= 0) ? rc
: len
;
1378 static struct kobj_attribute dump_type_attr
=
1379 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1381 static struct kset
*dump_kset
;
1383 static void __dump_run(void *unused
)
1385 struct ccw_dev_id devid
;
1386 static char buf
[100];
1388 switch (dump_method
) {
1389 case DUMP_METHOD_CCW_CIO
:
1390 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1392 reipl_ccw_dev(&devid
);
1394 case DUMP_METHOD_CCW_VM
:
1395 sprintf(buf
, "STORE STATUS");
1396 __cpcmd(buf
, NULL
, 0, NULL
);
1397 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1398 __cpcmd(buf
, NULL
, 0, NULL
);
1400 case DUMP_METHOD_CCW_DIAG
:
1401 diag308(DIAG308_SET
, dump_block_ccw
);
1402 diag308(DIAG308_DUMP
, NULL
);
1404 case DUMP_METHOD_FCP_DIAG
:
1405 diag308(DIAG308_SET
, dump_block_fcp
);
1406 diag308(DIAG308_DUMP
, NULL
);
1413 static void dump_run(struct shutdown_trigger
*trigger
)
1415 if (dump_method
== DUMP_METHOD_NONE
)
1418 smp_switch_to_ipl_cpu(__dump_run
, NULL
);
1421 static int __init
dump_ccw_init(void)
1425 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1426 if (!dump_block_ccw
)
1428 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1430 free_page((unsigned long)dump_block_ccw
);
1433 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1434 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1435 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1436 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1437 dump_capabilities
|= DUMP_TYPE_CCW
;
1441 static int __init
dump_fcp_init(void)
1445 if (!sclp_ipl_info
.has_dump
)
1446 return 0; /* LDIPL DUMP is not installed */
1447 if (!diag308_set_works
)
1449 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1450 if (!dump_block_fcp
)
1452 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1454 free_page((unsigned long)dump_block_fcp
);
1457 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1458 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1459 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1460 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1461 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1462 dump_capabilities
|= DUMP_TYPE_FCP
;
1466 static int __init
dump_init(void)
1470 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1473 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1475 kset_unregister(dump_kset
);
1478 rc
= dump_ccw_init();
1481 rc
= dump_fcp_init();
1484 dump_set_type(DUMP_TYPE_NONE
);
1488 static struct shutdown_action __refdata dump_action
= {
1489 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1494 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1498 * Bypass dynamic address translation (DAT) when storing IPL parameter
1499 * information block address and checksum into the prefix area
1500 * (corresponding to absolute addresses 0-8191).
1501 * When enhanced DAT applies and the STE format control in one,
1502 * the absolute address is formed without prefixing. In this case a
1503 * normal store (stg/st) into the prefix area would no more match to
1504 * absolute addresses 0-8191.
1507 asm volatile("sturg %0,%1"
1508 :: "a" ((unsigned long) reipl_block_actual
),
1509 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1511 asm volatile("stura %0,%1"
1512 :: "a" ((unsigned long) reipl_block_actual
),
1513 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1515 asm volatile("stura %0,%1"
1516 :: "a" (csum_partial(reipl_block_actual
,
1517 reipl_block_actual
->hdr
.len
, 0)),
1518 "a" (&lowcore_ptr
[smp_processor_id()]->ipib_checksum
));
1523 static int __init
dump_reipl_init(void)
1525 if (!diag308_set_works
)
1531 static struct shutdown_action __refdata dump_reipl_action
= {
1532 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1533 .fn
= dump_reipl_run
,
1534 .init
= dump_reipl_init
,
1538 * vmcmd shutdown action: Trigger vm command on shutdown.
1541 static char vmcmd_on_reboot
[128];
1542 static char vmcmd_on_panic
[128];
1543 static char vmcmd_on_halt
[128];
1544 static char vmcmd_on_poff
[128];
1546 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1547 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1548 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1549 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1551 static struct attribute
*vmcmd_attrs
[] = {
1552 &sys_vmcmd_on_reboot_attr
.attr
,
1553 &sys_vmcmd_on_panic_attr
.attr
,
1554 &sys_vmcmd_on_halt_attr
.attr
,
1555 &sys_vmcmd_on_poff_attr
.attr
,
1559 static struct attribute_group vmcmd_attr_group
= {
1560 .attrs
= vmcmd_attrs
,
1563 static struct kset
*vmcmd_kset
;
1565 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1567 char *cmd
, *next_cmd
;
1569 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1570 cmd
= vmcmd_on_reboot
;
1571 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1572 cmd
= vmcmd_on_panic
;
1573 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1574 cmd
= vmcmd_on_halt
;
1575 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1576 cmd
= vmcmd_on_poff
;
1580 if (strlen(cmd
) == 0)
1583 next_cmd
= strchr(cmd
, '\n');
1588 __cpcmd(cmd
, NULL
, 0, NULL
);
1590 } while (cmd
!= NULL
);
1593 static int vmcmd_init(void)
1597 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1600 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1603 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1604 vmcmd_run
, vmcmd_init
};
1607 * stop shutdown action: Stop Linux on shutdown.
1610 static void stop_run(struct shutdown_trigger
*trigger
)
1612 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1613 disabled_wait((unsigned long) __builtin_return_address(0));
1614 while (sigp(smp_processor_id(), sigp_stop
) == sigp_busy
)
1619 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1624 static struct shutdown_action
*shutdown_actions_list
[] = {
1625 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1626 &vmcmd_action
, &stop_action
};
1627 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1633 static struct kset
*shutdown_actions_kset
;
1635 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1640 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1641 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1642 if (shutdown_actions_list
[i
]->init_rc
) {
1643 return shutdown_actions_list
[i
]->init_rc
;
1645 trigger
->action
= shutdown_actions_list
[i
];
1655 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1658 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1659 struct kobj_attribute
*attr
, char *page
)
1661 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1664 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1665 struct kobj_attribute
*attr
,
1666 const char *buf
, size_t len
)
1668 return set_trigger(buf
, &on_reboot_trigger
, len
);
1671 static struct kobj_attribute on_reboot_attr
=
1672 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1674 static void do_machine_restart(char *__unused
)
1677 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1680 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1684 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1686 static ssize_t
on_panic_show(struct kobject
*kobj
,
1687 struct kobj_attribute
*attr
, char *page
)
1689 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1692 static ssize_t
on_panic_store(struct kobject
*kobj
,
1693 struct kobj_attribute
*attr
,
1694 const char *buf
, size_t len
)
1696 return set_trigger(buf
, &on_panic_trigger
, len
);
1699 static struct kobj_attribute on_panic_attr
=
1700 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1702 static void do_panic(void)
1704 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1705 stop_run(&on_panic_trigger
);
1710 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1712 static ssize_t
on_halt_show(struct kobject
*kobj
,
1713 struct kobj_attribute
*attr
, char *page
)
1715 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1718 static ssize_t
on_halt_store(struct kobject
*kobj
,
1719 struct kobj_attribute
*attr
,
1720 const char *buf
, size_t len
)
1722 return set_trigger(buf
, &on_halt_trigger
, len
);
1725 static struct kobj_attribute on_halt_attr
=
1726 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1729 static void do_machine_halt(void)
1732 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1733 stop_run(&on_halt_trigger
);
1735 void (*_machine_halt
)(void) = do_machine_halt
;
1739 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1741 static ssize_t
on_poff_show(struct kobject
*kobj
,
1742 struct kobj_attribute
*attr
, char *page
)
1744 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1747 static ssize_t
on_poff_store(struct kobject
*kobj
,
1748 struct kobj_attribute
*attr
,
1749 const char *buf
, size_t len
)
1751 return set_trigger(buf
, &on_poff_trigger
, len
);
1754 static struct kobj_attribute on_poff_attr
=
1755 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1758 static void do_machine_power_off(void)
1761 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1762 stop_run(&on_poff_trigger
);
1764 void (*_machine_power_off
)(void) = do_machine_power_off
;
1766 static void __init
shutdown_triggers_init(void)
1768 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1770 if (!shutdown_actions_kset
)
1772 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1773 &on_reboot_attr
.attr
))
1775 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1776 &on_panic_attr
.attr
))
1778 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1779 &on_halt_attr
.attr
))
1781 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1782 &on_poff_attr
.attr
))
1787 panic("shutdown_triggers_init failed\n");
1790 static void __init
shutdown_actions_init(void)
1794 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1795 if (!shutdown_actions_list
[i
]->init
)
1797 shutdown_actions_list
[i
]->init_rc
=
1798 shutdown_actions_list
[i
]->init();
1802 static int __init
s390_ipl_init(void)
1804 sclp_get_ipl_info(&sclp_ipl_info
);
1805 shutdown_actions_init();
1806 shutdown_triggers_init();
1810 __initcall(s390_ipl_init
);
1812 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1817 for (sx
= 0; src
[sx
] != 0; sx
++) {
1820 dst
[dx
++] = src
[sx
];
1826 static int __init
vmcmd_on_reboot_setup(char *str
)
1830 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1831 vmcmd_on_reboot
[127] = 0;
1832 on_reboot_trigger
.action
= &vmcmd_action
;
1835 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1837 static int __init
vmcmd_on_panic_setup(char *str
)
1841 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1842 vmcmd_on_panic
[127] = 0;
1843 on_panic_trigger
.action
= &vmcmd_action
;
1846 __setup("vmpanic=", vmcmd_on_panic_setup
);
1848 static int __init
vmcmd_on_halt_setup(char *str
)
1852 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1853 vmcmd_on_halt
[127] = 0;
1854 on_halt_trigger
.action
= &vmcmd_action
;
1857 __setup("vmhalt=", vmcmd_on_halt_setup
);
1859 static int __init
vmcmd_on_poff_setup(char *str
)
1863 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1864 vmcmd_on_poff
[127] = 0;
1865 on_poff_trigger
.action
= &vmcmd_action
;
1868 __setup("vmpoff=", vmcmd_on_poff_setup
);
1870 static int on_panic_notify(struct notifier_block
*self
,
1871 unsigned long event
, void *data
)
1877 static struct notifier_block on_panic_nb
= {
1878 .notifier_call
= on_panic_notify
,
1879 .priority
= INT_MIN
,
1882 void __init
setup_ipl(void)
1884 ipl_info
.type
= get_ipl_type();
1885 switch (ipl_info
.type
) {
1887 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1888 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1891 case IPL_TYPE_FCP_DUMP
:
1892 ipl_info
.data
.fcp
.dev_id
.devno
=
1893 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1894 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1895 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1896 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1899 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1900 sizeof(ipl_info
.data
.nss
.name
));
1902 case IPL_TYPE_UNKNOWN
:
1903 /* We have no info to copy */
1906 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1909 void __init
ipl_update_parameters(void)
1913 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1914 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1915 diag308_set_works
= 1;
1918 void __init
ipl_save_parameters(void)
1920 struct cio_iplinfo iplinfo
;
1923 if (cio_get_iplinfo(&iplinfo
))
1926 ipl_devno
= iplinfo
.devno
;
1927 ipl_flags
|= IPL_DEVNO_VALID
;
1928 if (!iplinfo
.is_qdio
)
1930 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1931 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
1932 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1933 memmove(dst
, src
, PAGE_SIZE
);
1934 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
1937 static LIST_HEAD(rcall
);
1938 static DEFINE_MUTEX(rcall_mutex
);
1940 void register_reset_call(struct reset_call
*reset
)
1942 mutex_lock(&rcall_mutex
);
1943 list_add(&reset
->list
, &rcall
);
1944 mutex_unlock(&rcall_mutex
);
1946 EXPORT_SYMBOL_GPL(register_reset_call
);
1948 void unregister_reset_call(struct reset_call
*reset
)
1950 mutex_lock(&rcall_mutex
);
1951 list_del(&reset
->list
);
1952 mutex_unlock(&rcall_mutex
);
1954 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1956 static void do_reset_calls(void)
1958 struct reset_call
*reset
;
1960 list_for_each_entry(reset
, &rcall
, list
)
1964 u32 dump_prefix_page
;
1966 void s390_reset_system(void)
1968 struct _lowcore
*lc
;
1970 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
1972 /* Stack for interrupt/machine check handler */
1973 lc
->panic_stack
= S390_lowcore
.panic_stack
;
1975 /* Save prefix page address for dump case */
1976 dump_prefix_page
= (u32
)(unsigned long) lc
;
1978 /* Disable prefixing */
1981 /* Disable lowcore protection */
1982 __ctl_clear_bit(0,28);
1984 /* Set new machine check handler */
1985 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1986 S390_lowcore
.mcck_new_psw
.addr
=
1987 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
1989 /* Set new program check handler */
1990 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1991 S390_lowcore
.program_new_psw
.addr
=
1992 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;