2 * ipl/reipl/dump support for Linux on s390.
4 * Copyright IBM Corp. 2005, 2012
5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 * Volker Sameske <sameske@de.ibm.com>
10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/delay.h>
14 #include <linux/reboot.h>
15 #include <linux/ctype.h>
17 #include <linux/gfp.h>
18 #include <linux/crash_dump.h>
19 #include <linux/debug_locks.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
25 #include <asm/ebcdic.h>
26 #include <asm/reset.h>
28 #include <asm/checksum.h>
29 #include <asm/debug.h>
30 #include <asm/os_info.h>
33 #define IPL_PARM_BLOCK_VERSION 0
35 #define IPL_UNKNOWN_STR "unknown"
36 #define IPL_CCW_STR "ccw"
37 #define IPL_FCP_STR "fcp"
38 #define IPL_FCP_DUMP_STR "fcp_dump"
39 #define IPL_NSS_STR "nss"
41 #define DUMP_CCW_STR "ccw"
42 #define DUMP_FCP_STR "fcp"
43 #define DUMP_NONE_STR "none"
46 * Four shutdown trigger types are supported:
53 #define ON_PANIC_STR "on_panic"
54 #define ON_HALT_STR "on_halt"
55 #define ON_POFF_STR "on_poff"
56 #define ON_REIPL_STR "on_reboot"
57 #define ON_RESTART_STR "on_restart"
59 struct shutdown_action
;
60 struct shutdown_trigger
{
62 struct shutdown_action
*action
;
66 * The following shutdown action types are supported:
68 #define SHUTDOWN_ACTION_IPL_STR "ipl"
69 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
70 #define SHUTDOWN_ACTION_DUMP_STR "dump"
71 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
72 #define SHUTDOWN_ACTION_STOP_STR "stop"
73 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
75 struct shutdown_action
{
77 void (*fn
) (struct shutdown_trigger
*trigger
);
82 static char *ipl_type_str(enum ipl_type type
)
89 case IPL_TYPE_FCP_DUMP
:
90 return IPL_FCP_DUMP_STR
;
93 case IPL_TYPE_UNKNOWN
:
95 return IPL_UNKNOWN_STR
;
105 static char *dump_type_str(enum dump_type type
)
109 return DUMP_NONE_STR
;
120 * Must be in data section since the bss section
121 * is not cleared when these are accessed.
123 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
124 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
127 REIPL_METHOD_CCW_CIO
,
128 REIPL_METHOD_CCW_DIAG
,
130 REIPL_METHOD_FCP_RO_DIAG
,
131 REIPL_METHOD_FCP_RW_DIAG
,
132 REIPL_METHOD_FCP_RO_VM
,
133 REIPL_METHOD_FCP_DUMP
,
135 REIPL_METHOD_NSS_DIAG
,
136 REIPL_METHOD_DEFAULT
,
142 DUMP_METHOD_CCW_DIAG
,
144 DUMP_METHOD_FCP_DIAG
,
147 static int diag308_set_works
= 0;
149 static struct ipl_parameter_block ipl_block
;
151 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
153 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
154 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
155 static struct ipl_parameter_block
*reipl_block_fcp
;
156 static struct ipl_parameter_block
*reipl_block_ccw
;
157 static struct ipl_parameter_block
*reipl_block_nss
;
158 static struct ipl_parameter_block
*reipl_block_actual
;
160 static int dump_capabilities
= DUMP_TYPE_NONE
;
161 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
162 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
163 static struct ipl_parameter_block
*dump_block_fcp
;
164 static struct ipl_parameter_block
*dump_block_ccw
;
166 static struct sclp_ipl_info sclp_ipl_info
;
168 int diag308(unsigned long subcode
, void *addr
)
170 register unsigned long _addr
asm("0") = (unsigned long) addr
;
171 register unsigned long _rc
asm("1") = 0;
174 " diag %0,%2,0x308\n"
177 : "+d" (_addr
), "+d" (_rc
)
178 : "d" (subcode
) : "cc", "memory");
181 EXPORT_SYMBOL_GPL(diag308
);
185 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
186 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
190 return sprintf(page, _format, _value); \
192 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
193 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
195 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
196 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
197 struct kobj_attribute *attr, \
200 return sprintf(page, _fmt_out, \
201 (unsigned long long) _value); \
203 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
204 struct kobj_attribute *attr, \
205 const char *buf, size_t len) \
207 unsigned long long value; \
208 if (sscanf(buf, _fmt_in, &value) != 1) \
213 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
214 __ATTR(_name,(S_IRUGO | S_IWUSR), \
215 sys_##_prefix##_##_name##_show, \
216 sys_##_prefix##_##_name##_store);
218 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
219 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
223 return sprintf(page, _fmt_out, _value); \
225 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
226 struct kobj_attribute *attr, \
227 const char *buf, size_t len) \
229 strncpy(_value, buf, sizeof(_value) - 1); \
233 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
234 __ATTR(_name,(S_IRUGO | S_IWUSR), \
235 sys_##_prefix##_##_name##_show, \
236 sys_##_prefix##_##_name##_store);
238 static void make_attrs_ro(struct attribute
**attrs
)
241 (*attrs
)->mode
= S_IRUGO
;
250 static __init
enum ipl_type
get_ipl_type(void)
252 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
254 if (ipl_flags
& IPL_NSS_VALID
)
256 if (!(ipl_flags
& IPL_DEVNO_VALID
))
257 return IPL_TYPE_UNKNOWN
;
258 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
260 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
261 return IPL_TYPE_UNKNOWN
;
262 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
263 return IPL_TYPE_UNKNOWN
;
264 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
265 return IPL_TYPE_FCP_DUMP
;
269 struct ipl_info ipl_info
;
270 EXPORT_SYMBOL_GPL(ipl_info
);
272 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
275 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
278 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
280 /* VM IPL PARM routines */
281 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
282 const struct ipl_parameter_block
*ipb
)
286 char has_lowercase
= 0;
289 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
290 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
292 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
293 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
294 /* If at least one character is lowercase, we assume mixed
295 * case; otherwise we convert everything to lowercase.
297 for (i
= 0; i
< len
; i
++)
298 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
299 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
300 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
305 EBC_TOLOWER(dest
, len
);
313 size_t append_ipl_vmparm(char *dest
, size_t size
)
318 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
319 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
325 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
326 struct kobj_attribute
*attr
, char *page
)
328 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
330 append_ipl_vmparm(parm
, sizeof(parm
));
331 return sprintf(page
, "%s\n", parm
);
334 static size_t scpdata_length(const char* buf
, size_t count
)
337 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
344 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
345 const struct ipl_parameter_block
*ipb
)
351 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
352 ipb
->ipl_info
.fcp
.scp_data_len
));
357 for (i
= 0; i
< count
; i
++) {
358 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
362 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
367 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
369 for (i
= 0; i
< count
; i
++)
370 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
376 size_t append_ipl_scpdata(char *dest
, size_t len
)
381 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
382 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
389 static struct kobj_attribute sys_ipl_vm_parm_attr
=
390 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
392 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
393 struct kobj_attribute
*attr
, char *page
)
395 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
397 switch (ipl_info
.type
) {
399 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
401 case IPL_TYPE_FCP_DUMP
:
402 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
408 static struct kobj_attribute sys_ipl_device_attr
=
409 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
411 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
412 struct bin_attribute
*attr
, char *buf
,
413 loff_t off
, size_t count
)
415 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
419 static struct bin_attribute ipl_parameter_attr
= {
421 .name
= "binary_parameter",
425 .read
= &ipl_parameter_read
,
428 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
429 struct bin_attribute
*attr
, char *buf
,
430 loff_t off
, size_t count
)
432 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
433 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
435 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
438 static struct bin_attribute ipl_scp_data_attr
= {
444 .read
= ipl_scp_data_read
,
447 /* FCP ipl device attributes */
449 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
450 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
451 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
452 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
453 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
454 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
455 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
456 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
458 static struct attribute
*ipl_fcp_attrs
[] = {
459 &sys_ipl_type_attr
.attr
,
460 &sys_ipl_device_attr
.attr
,
461 &sys_ipl_fcp_wwpn_attr
.attr
,
462 &sys_ipl_fcp_lun_attr
.attr
,
463 &sys_ipl_fcp_bootprog_attr
.attr
,
464 &sys_ipl_fcp_br_lba_attr
.attr
,
468 static struct attribute_group ipl_fcp_attr_group
= {
469 .attrs
= ipl_fcp_attrs
,
472 /* CCW ipl device attributes */
474 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
475 struct kobj_attribute
*attr
, char *page
)
477 char loadparm
[LOADPARM_LEN
+ 1] = {};
479 if (!sclp_ipl_info
.is_valid
)
480 return sprintf(page
, "#unknown#\n");
481 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
482 EBCASC(loadparm
, LOADPARM_LEN
);
484 return sprintf(page
, "%s\n", loadparm
);
487 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
488 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
490 static struct attribute
*ipl_ccw_attrs_vm
[] = {
491 &sys_ipl_type_attr
.attr
,
492 &sys_ipl_device_attr
.attr
,
493 &sys_ipl_ccw_loadparm_attr
.attr
,
494 &sys_ipl_vm_parm_attr
.attr
,
498 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
499 &sys_ipl_type_attr
.attr
,
500 &sys_ipl_device_attr
.attr
,
501 &sys_ipl_ccw_loadparm_attr
.attr
,
505 static struct attribute_group ipl_ccw_attr_group_vm
= {
506 .attrs
= ipl_ccw_attrs_vm
,
509 static struct attribute_group ipl_ccw_attr_group_lpar
= {
510 .attrs
= ipl_ccw_attrs_lpar
513 /* NSS ipl device attributes */
515 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
517 static struct attribute
*ipl_nss_attrs
[] = {
518 &sys_ipl_type_attr
.attr
,
519 &sys_ipl_nss_name_attr
.attr
,
520 &sys_ipl_ccw_loadparm_attr
.attr
,
521 &sys_ipl_vm_parm_attr
.attr
,
525 static struct attribute_group ipl_nss_attr_group
= {
526 .attrs
= ipl_nss_attrs
,
529 /* UNKNOWN ipl device attributes */
531 static struct attribute
*ipl_unknown_attrs
[] = {
532 &sys_ipl_type_attr
.attr
,
536 static struct attribute_group ipl_unknown_attr_group
= {
537 .attrs
= ipl_unknown_attrs
,
540 static struct kset
*ipl_kset
;
542 static int __init
ipl_register_fcp_files(void)
546 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
549 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
552 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
556 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
559 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
564 static void __ipl_run(void *unused
)
566 diag308(DIAG308_IPL
, NULL
);
568 __cpcmd("IPL", NULL
, 0, NULL
);
569 else if (ipl_info
.type
== IPL_TYPE_CCW
)
570 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
573 static void ipl_run(struct shutdown_trigger
*trigger
)
575 smp_call_ipl_cpu(__ipl_run
, NULL
);
578 static int __init
ipl_init(void)
582 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
587 switch (ipl_info
.type
) {
590 rc
= sysfs_create_group(&ipl_kset
->kobj
,
591 &ipl_ccw_attr_group_vm
);
593 rc
= sysfs_create_group(&ipl_kset
->kobj
,
594 &ipl_ccw_attr_group_lpar
);
597 case IPL_TYPE_FCP_DUMP
:
598 rc
= ipl_register_fcp_files();
601 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
604 rc
= sysfs_create_group(&ipl_kset
->kobj
,
605 &ipl_unknown_attr_group
);
610 panic("ipl_init failed: rc = %i\n", rc
);
615 static struct shutdown_action __refdata ipl_action
= {
616 .name
= SHUTDOWN_ACTION_IPL_STR
,
622 * reipl shutdown action: Reboot Linux on shutdown.
625 /* VM IPL PARM attributes */
626 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
629 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
631 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
632 return sprintf(page
, "%s\n", vmparm
);
635 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
637 const char *buf
, size_t len
)
641 /* ignore trailing newline */
643 if ((len
> 0) && (buf
[len
- 1] == '\n'))
646 if (ip_len
> vmparm_max
)
649 /* parm is used to store kernel options, check for common chars */
650 for (i
= 0; i
< ip_len
; i
++)
651 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
654 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
655 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
657 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
658 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
659 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
661 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
668 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
669 struct kobj_attribute
*attr
, char *page
)
671 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
674 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
675 struct kobj_attribute
*attr
,
676 const char *buf
, size_t len
)
678 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
682 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
683 struct kobj_attribute
*attr
, char *page
)
685 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
688 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
689 struct kobj_attribute
*attr
,
690 const char *buf
, size_t len
)
692 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
695 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
696 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
697 reipl_nss_vmparm_store
);
698 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
699 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
700 reipl_ccw_vmparm_store
);
702 /* FCP reipl device attributes */
704 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
705 struct bin_attribute
*attr
,
706 char *buf
, loff_t off
, size_t count
)
708 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
709 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
711 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
714 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
715 struct bin_attribute
*attr
,
716 char *buf
, loff_t off
, size_t count
)
724 if (off
>= DIAG308_SCPDATA_SIZE
)
727 if (count
> DIAG308_SCPDATA_SIZE
- off
)
728 count
= DIAG308_SCPDATA_SIZE
- off
;
730 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
731 scpdata_len
= off
+ count
;
733 if (scpdata_len
% 8) {
734 padding
= 8 - (scpdata_len
% 8);
735 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
737 scpdata_len
+= padding
;
740 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
741 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
742 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
747 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
750 .mode
= S_IRUGO
| S_IWUSR
,
753 .read
= reipl_fcp_scpdata_read
,
754 .write
= reipl_fcp_scpdata_write
,
757 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
758 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
759 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
760 reipl_block_fcp
->ipl_info
.fcp
.lun
);
761 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
762 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
763 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
764 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
765 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
766 reipl_block_fcp
->ipl_info
.fcp
.devno
);
768 static struct attribute
*reipl_fcp_attrs
[] = {
769 &sys_reipl_fcp_device_attr
.attr
,
770 &sys_reipl_fcp_wwpn_attr
.attr
,
771 &sys_reipl_fcp_lun_attr
.attr
,
772 &sys_reipl_fcp_bootprog_attr
.attr
,
773 &sys_reipl_fcp_br_lba_attr
.attr
,
777 static struct attribute_group reipl_fcp_attr_group
= {
778 .attrs
= reipl_fcp_attrs
,
781 /* CCW reipl device attributes */
783 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
784 reipl_block_ccw
->ipl_info
.ccw
.devno
);
786 static void reipl_get_ascii_loadparm(char *loadparm
,
787 struct ipl_parameter_block
*ibp
)
789 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
790 EBCASC(loadparm
, LOADPARM_LEN
);
791 loadparm
[LOADPARM_LEN
] = 0;
795 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
798 char buf
[LOADPARM_LEN
+ 1];
800 reipl_get_ascii_loadparm(buf
, ipb
);
801 return sprintf(page
, "%s\n", buf
);
804 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
805 const char *buf
, size_t len
)
809 /* ignore trailing newline */
811 if ((len
> 0) && (buf
[len
- 1] == '\n'))
813 /* loadparm can have max 8 characters and must not start with a blank */
814 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
816 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
817 for (i
= 0; i
< lp_len
; i
++) {
818 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
823 /* initialize loadparm with blanks */
824 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
825 /* copy and convert to ebcdic */
826 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
827 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
832 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
833 struct kobj_attribute
*attr
, char *page
)
835 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
838 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
839 struct kobj_attribute
*attr
,
840 const char *buf
, size_t len
)
842 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
846 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
847 struct kobj_attribute
*attr
, char *page
)
849 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
852 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
853 struct kobj_attribute
*attr
,
854 const char *buf
, size_t len
)
856 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
859 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
860 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
861 reipl_ccw_loadparm_store
);
863 static struct attribute
*reipl_ccw_attrs_vm
[] = {
864 &sys_reipl_ccw_device_attr
.attr
,
865 &sys_reipl_ccw_loadparm_attr
.attr
,
866 &sys_reipl_ccw_vmparm_attr
.attr
,
870 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
871 &sys_reipl_ccw_device_attr
.attr
,
872 &sys_reipl_ccw_loadparm_attr
.attr
,
876 static struct attribute_group reipl_ccw_attr_group_vm
= {
878 .attrs
= reipl_ccw_attrs_vm
,
881 static struct attribute_group reipl_ccw_attr_group_lpar
= {
883 .attrs
= reipl_ccw_attrs_lpar
,
887 /* NSS reipl device attributes */
888 static void reipl_get_ascii_nss_name(char *dst
,
889 struct ipl_parameter_block
*ipb
)
891 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
892 EBCASC(dst
, NSS_NAME_SIZE
);
893 dst
[NSS_NAME_SIZE
] = 0;
896 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
897 struct kobj_attribute
*attr
, char *page
)
899 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
901 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
902 return sprintf(page
, "%s\n", nss_name
);
905 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
906 struct kobj_attribute
*attr
,
907 const char *buf
, size_t len
)
911 /* ignore trailing newline */
913 if ((len
> 0) && (buf
[len
- 1] == '\n'))
916 if (nss_len
> NSS_NAME_SIZE
)
919 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
921 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
922 DIAG308_VM_FLAGS_NSS_VALID
;
923 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
924 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
925 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
927 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
928 ~DIAG308_VM_FLAGS_NSS_VALID
;
934 static struct kobj_attribute sys_reipl_nss_name_attr
=
935 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
936 reipl_nss_name_store
);
938 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
939 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
940 reipl_nss_loadparm_store
);
942 static struct attribute
*reipl_nss_attrs
[] = {
943 &sys_reipl_nss_name_attr
.attr
,
944 &sys_reipl_nss_loadparm_attr
.attr
,
945 &sys_reipl_nss_vmparm_attr
.attr
,
949 static struct attribute_group reipl_nss_attr_group
= {
951 .attrs
= reipl_nss_attrs
,
954 static void set_reipl_block_actual(struct ipl_parameter_block
*reipl_block
)
956 reipl_block_actual
= reipl_block
;
957 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
958 reipl_block
->hdr
.len
);
963 static int reipl_set_type(enum ipl_type type
)
965 if (!(reipl_capabilities
& type
))
970 if (diag308_set_works
)
971 reipl_method
= REIPL_METHOD_CCW_DIAG
;
972 else if (MACHINE_IS_VM
)
973 reipl_method
= REIPL_METHOD_CCW_VM
;
975 reipl_method
= REIPL_METHOD_CCW_CIO
;
976 set_reipl_block_actual(reipl_block_ccw
);
979 if (diag308_set_works
)
980 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
981 else if (MACHINE_IS_VM
)
982 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
984 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
985 set_reipl_block_actual(reipl_block_fcp
);
987 case IPL_TYPE_FCP_DUMP
:
988 reipl_method
= REIPL_METHOD_FCP_DUMP
;
991 if (diag308_set_works
)
992 reipl_method
= REIPL_METHOD_NSS_DIAG
;
994 reipl_method
= REIPL_METHOD_NSS
;
995 set_reipl_block_actual(reipl_block_nss
);
997 case IPL_TYPE_UNKNOWN
:
998 reipl_method
= REIPL_METHOD_DEFAULT
;
1007 static ssize_t
reipl_type_show(struct kobject
*kobj
,
1008 struct kobj_attribute
*attr
, char *page
)
1010 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1013 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1014 struct kobj_attribute
*attr
,
1015 const char *buf
, size_t len
)
1019 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1020 rc
= reipl_set_type(IPL_TYPE_CCW
);
1021 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1022 rc
= reipl_set_type(IPL_TYPE_FCP
);
1023 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1024 rc
= reipl_set_type(IPL_TYPE_NSS
);
1025 return (rc
!= 0) ? rc
: len
;
1028 static struct kobj_attribute reipl_type_attr
=
1029 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1031 static struct kset
*reipl_kset
;
1032 static struct kset
*reipl_fcp_kset
;
1034 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1035 const enum ipl_method m
)
1037 char loadparm
[LOADPARM_LEN
+ 1] = {};
1038 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1039 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1042 reipl_get_ascii_loadparm(loadparm
, ipb
);
1043 reipl_get_ascii_nss_name(nss_name
, ipb
);
1044 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1047 case REIPL_METHOD_CCW_VM
:
1048 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1050 case REIPL_METHOD_NSS
:
1051 pos
= sprintf(dst
, "IPL %s", nss_name
);
1056 if (strlen(loadparm
) > 0)
1057 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1058 if (strlen(vmparm
) > 0)
1059 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1062 static void __reipl_run(void *unused
)
1064 struct ccw_dev_id devid
;
1065 static char buf
[128];
1067 switch (reipl_method
) {
1068 case REIPL_METHOD_CCW_CIO
:
1069 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1071 reipl_ccw_dev(&devid
);
1073 case REIPL_METHOD_CCW_VM
:
1074 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1075 __cpcmd(buf
, NULL
, 0, NULL
);
1077 case REIPL_METHOD_CCW_DIAG
:
1078 diag308(DIAG308_SET
, reipl_block_ccw
);
1079 diag308(DIAG308_IPL
, NULL
);
1081 case REIPL_METHOD_FCP_RW_DIAG
:
1082 diag308(DIAG308_SET
, reipl_block_fcp
);
1083 diag308(DIAG308_IPL
, NULL
);
1085 case REIPL_METHOD_FCP_RO_DIAG
:
1086 diag308(DIAG308_IPL
, NULL
);
1088 case REIPL_METHOD_FCP_RO_VM
:
1089 __cpcmd("IPL", NULL
, 0, NULL
);
1091 case REIPL_METHOD_NSS_DIAG
:
1092 diag308(DIAG308_SET
, reipl_block_nss
);
1093 diag308(DIAG308_IPL
, NULL
);
1095 case REIPL_METHOD_NSS
:
1096 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1097 __cpcmd(buf
, NULL
, 0, NULL
);
1099 case REIPL_METHOD_DEFAULT
:
1101 __cpcmd("IPL", NULL
, 0, NULL
);
1102 diag308(DIAG308_IPL
, NULL
);
1104 case REIPL_METHOD_FCP_DUMP
:
1107 disabled_wait((unsigned long) __builtin_return_address(0));
1110 static void reipl_run(struct shutdown_trigger
*trigger
)
1112 smp_call_ipl_cpu(__reipl_run
, NULL
);
1115 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1117 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1118 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1119 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1120 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1123 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1126 /* check if read scp info worked and set loadparm */
1127 if (sclp_ipl_info
.is_valid
)
1128 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
1129 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1131 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1132 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
1133 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1136 if (MACHINE_IS_VM
&& diag308_set_works
&&
1137 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1139 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1140 ipb
->ipl_info
.ccw
.vm_parm_len
=
1141 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1142 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1143 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1147 static int __init
reipl_nss_init(void)
1154 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1155 if (!reipl_block_nss
)
1158 if (!diag308_set_works
)
1159 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1161 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1165 reipl_block_ccw_init(reipl_block_nss
);
1166 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1167 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1168 ' ', NSS_NAME_SIZE
);
1169 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1170 kernel_nss_name
, strlen(kernel_nss_name
));
1171 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1172 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1173 DIAG308_VM_FLAGS_NSS_VALID
;
1175 reipl_block_ccw_fill_parms(reipl_block_nss
);
1178 reipl_capabilities
|= IPL_TYPE_NSS
;
1182 static int __init
reipl_ccw_init(void)
1186 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1187 if (!reipl_block_ccw
)
1190 if (MACHINE_IS_VM
) {
1191 if (!diag308_set_works
)
1192 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1193 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1194 &reipl_ccw_attr_group_vm
);
1196 if(!diag308_set_works
)
1197 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1198 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1199 &reipl_ccw_attr_group_lpar
);
1204 reipl_block_ccw_init(reipl_block_ccw
);
1205 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1206 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1207 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1210 reipl_capabilities
|= IPL_TYPE_CCW
;
1214 static int __init
reipl_fcp_init(void)
1218 if (!diag308_set_works
) {
1219 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1220 make_attrs_ro(reipl_fcp_attrs
);
1221 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1226 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1227 if (!reipl_block_fcp
)
1230 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1231 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1233 if (!reipl_fcp_kset
) {
1234 free_page((unsigned long) reipl_block_fcp
);
1238 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1240 kset_unregister(reipl_fcp_kset
);
1241 free_page((unsigned long) reipl_block_fcp
);
1245 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1246 &sys_reipl_fcp_scp_data_attr
);
1248 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1249 kset_unregister(reipl_fcp_kset
);
1250 free_page((unsigned long) reipl_block_fcp
);
1254 if (ipl_info
.type
== IPL_TYPE_FCP
)
1255 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1257 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1258 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1259 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1260 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1261 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1263 reipl_capabilities
|= IPL_TYPE_FCP
;
1267 static int __init
reipl_type_init(void)
1269 enum ipl_type reipl_type
= ipl_info
.type
;
1270 struct ipl_parameter_block
*reipl_block
;
1273 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1277 * If we have an OS info reipl block, this will be used
1279 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1280 memcpy(reipl_block_fcp
, reipl_block
, size
);
1281 reipl_type
= IPL_TYPE_FCP
;
1282 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1283 memcpy(reipl_block_ccw
, reipl_block
, size
);
1284 reipl_type
= IPL_TYPE_CCW
;
1287 return reipl_set_type(reipl_type
);
1290 static int __init
reipl_init(void)
1294 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1297 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1299 kset_unregister(reipl_kset
);
1302 rc
= reipl_ccw_init();
1305 rc
= reipl_fcp_init();
1308 rc
= reipl_nss_init();
1311 return reipl_type_init();
1314 static struct shutdown_action __refdata reipl_action
= {
1315 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1321 * dump shutdown action: Dump Linux on shutdown.
1324 /* FCP dump device attributes */
1326 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1327 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1328 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1329 dump_block_fcp
->ipl_info
.fcp
.lun
);
1330 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1331 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1332 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1333 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1334 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1335 dump_block_fcp
->ipl_info
.fcp
.devno
);
1337 static struct attribute
*dump_fcp_attrs
[] = {
1338 &sys_dump_fcp_device_attr
.attr
,
1339 &sys_dump_fcp_wwpn_attr
.attr
,
1340 &sys_dump_fcp_lun_attr
.attr
,
1341 &sys_dump_fcp_bootprog_attr
.attr
,
1342 &sys_dump_fcp_br_lba_attr
.attr
,
1346 static struct attribute_group dump_fcp_attr_group
= {
1347 .name
= IPL_FCP_STR
,
1348 .attrs
= dump_fcp_attrs
,
1351 /* CCW dump device attributes */
1353 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1354 dump_block_ccw
->ipl_info
.ccw
.devno
);
1356 static struct attribute
*dump_ccw_attrs
[] = {
1357 &sys_dump_ccw_device_attr
.attr
,
1361 static struct attribute_group dump_ccw_attr_group
= {
1362 .name
= IPL_CCW_STR
,
1363 .attrs
= dump_ccw_attrs
,
1368 static int dump_set_type(enum dump_type type
)
1370 if (!(dump_capabilities
& type
))
1374 if (diag308_set_works
)
1375 dump_method
= DUMP_METHOD_CCW_DIAG
;
1376 else if (MACHINE_IS_VM
)
1377 dump_method
= DUMP_METHOD_CCW_VM
;
1379 dump_method
= DUMP_METHOD_CCW_CIO
;
1382 dump_method
= DUMP_METHOD_FCP_DIAG
;
1385 dump_method
= DUMP_METHOD_NONE
;
1391 static ssize_t
dump_type_show(struct kobject
*kobj
,
1392 struct kobj_attribute
*attr
, char *page
)
1394 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1397 static ssize_t
dump_type_store(struct kobject
*kobj
,
1398 struct kobj_attribute
*attr
,
1399 const char *buf
, size_t len
)
1403 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1404 rc
= dump_set_type(DUMP_TYPE_NONE
);
1405 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1406 rc
= dump_set_type(DUMP_TYPE_CCW
);
1407 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1408 rc
= dump_set_type(DUMP_TYPE_FCP
);
1409 return (rc
!= 0) ? rc
: len
;
1412 static struct kobj_attribute dump_type_attr
=
1413 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1415 static struct kset
*dump_kset
;
1417 static void __dump_run(void *unused
)
1419 struct ccw_dev_id devid
;
1420 static char buf
[100];
1422 switch (dump_method
) {
1423 case DUMP_METHOD_CCW_CIO
:
1424 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1426 reipl_ccw_dev(&devid
);
1428 case DUMP_METHOD_CCW_VM
:
1429 sprintf(buf
, "STORE STATUS");
1430 __cpcmd(buf
, NULL
, 0, NULL
);
1431 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1432 __cpcmd(buf
, NULL
, 0, NULL
);
1434 case DUMP_METHOD_CCW_DIAG
:
1435 diag308(DIAG308_SET
, dump_block_ccw
);
1436 diag308(DIAG308_DUMP
, NULL
);
1438 case DUMP_METHOD_FCP_DIAG
:
1439 diag308(DIAG308_SET
, dump_block_fcp
);
1440 diag308(DIAG308_DUMP
, NULL
);
1447 static void dump_run(struct shutdown_trigger
*trigger
)
1449 if (dump_method
== DUMP_METHOD_NONE
)
1452 smp_call_ipl_cpu(__dump_run
, NULL
);
1455 static int __init
dump_ccw_init(void)
1459 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1460 if (!dump_block_ccw
)
1462 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1464 free_page((unsigned long)dump_block_ccw
);
1467 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1468 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1469 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1470 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1471 dump_capabilities
|= DUMP_TYPE_CCW
;
1475 static int __init
dump_fcp_init(void)
1479 if (!sclp_ipl_info
.has_dump
)
1480 return 0; /* LDIPL DUMP is not installed */
1481 if (!diag308_set_works
)
1483 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1484 if (!dump_block_fcp
)
1486 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1488 free_page((unsigned long)dump_block_fcp
);
1491 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1492 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1493 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1494 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1495 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1496 dump_capabilities
|= DUMP_TYPE_FCP
;
1500 static int __init
dump_init(void)
1504 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1507 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1509 kset_unregister(dump_kset
);
1512 rc
= dump_ccw_init();
1515 rc
= dump_fcp_init();
1518 dump_set_type(DUMP_TYPE_NONE
);
1522 static struct shutdown_action __refdata dump_action
= {
1523 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1528 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1530 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1533 csum
= csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1534 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1535 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1539 static int __init
dump_reipl_init(void)
1541 if (!diag308_set_works
)
1547 static struct shutdown_action __refdata dump_reipl_action
= {
1548 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1549 .fn
= dump_reipl_run
,
1550 .init
= dump_reipl_init
,
1554 * vmcmd shutdown action: Trigger vm command on shutdown.
1557 static char vmcmd_on_reboot
[128];
1558 static char vmcmd_on_panic
[128];
1559 static char vmcmd_on_halt
[128];
1560 static char vmcmd_on_poff
[128];
1561 static char vmcmd_on_restart
[128];
1563 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1564 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1565 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1566 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1567 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1569 static struct attribute
*vmcmd_attrs
[] = {
1570 &sys_vmcmd_on_reboot_attr
.attr
,
1571 &sys_vmcmd_on_panic_attr
.attr
,
1572 &sys_vmcmd_on_halt_attr
.attr
,
1573 &sys_vmcmd_on_poff_attr
.attr
,
1574 &sys_vmcmd_on_restart_attr
.attr
,
1578 static struct attribute_group vmcmd_attr_group
= {
1579 .attrs
= vmcmd_attrs
,
1582 static struct kset
*vmcmd_kset
;
1584 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1588 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1589 cmd
= vmcmd_on_reboot
;
1590 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1591 cmd
= vmcmd_on_panic
;
1592 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1593 cmd
= vmcmd_on_halt
;
1594 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1595 cmd
= vmcmd_on_poff
;
1596 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1597 cmd
= vmcmd_on_restart
;
1601 if (strlen(cmd
) == 0)
1603 __cpcmd(cmd
, NULL
, 0, NULL
);
1606 static int vmcmd_init(void)
1610 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1613 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1616 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1617 vmcmd_run
, vmcmd_init
};
1620 * stop shutdown action: Stop Linux on shutdown.
1623 static void stop_run(struct shutdown_trigger
*trigger
)
1625 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1626 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1627 disabled_wait((unsigned long) __builtin_return_address(0));
1631 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1636 static struct shutdown_action
*shutdown_actions_list
[] = {
1637 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1638 &vmcmd_action
, &stop_action
};
1639 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1645 static struct kset
*shutdown_actions_kset
;
1647 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1652 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1653 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1654 if (shutdown_actions_list
[i
]->init_rc
) {
1655 return shutdown_actions_list
[i
]->init_rc
;
1657 trigger
->action
= shutdown_actions_list
[i
];
1667 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1670 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1671 struct kobj_attribute
*attr
, char *page
)
1673 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1676 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1677 struct kobj_attribute
*attr
,
1678 const char *buf
, size_t len
)
1680 return set_trigger(buf
, &on_reboot_trigger
, len
);
1683 static struct kobj_attribute on_reboot_attr
=
1684 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1686 static void do_machine_restart(char *__unused
)
1689 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1692 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1696 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1698 static ssize_t
on_panic_show(struct kobject
*kobj
,
1699 struct kobj_attribute
*attr
, char *page
)
1701 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1704 static ssize_t
on_panic_store(struct kobject
*kobj
,
1705 struct kobj_attribute
*attr
,
1706 const char *buf
, size_t len
)
1708 return set_trigger(buf
, &on_panic_trigger
, len
);
1711 static struct kobj_attribute on_panic_attr
=
1712 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1714 static void do_panic(void)
1717 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1718 stop_run(&on_panic_trigger
);
1723 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1726 static ssize_t
on_restart_show(struct kobject
*kobj
,
1727 struct kobj_attribute
*attr
, char *page
)
1729 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1732 static ssize_t
on_restart_store(struct kobject
*kobj
,
1733 struct kobj_attribute
*attr
,
1734 const char *buf
, size_t len
)
1736 return set_trigger(buf
, &on_restart_trigger
, len
);
1739 static struct kobj_attribute on_restart_attr
=
1740 __ATTR(on_restart
, 0644, on_restart_show
, on_restart_store
);
1742 static void __do_restart(void *ignore
)
1744 __arch_local_irq_stosm(0x04); /* enable DAT */
1746 #ifdef CONFIG_CRASH_DUMP
1749 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1750 stop_run(&on_restart_trigger
);
1753 void do_restart(void)
1758 smp_call_online_cpu(__do_restart
, NULL
);
1763 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1765 static ssize_t
on_halt_show(struct kobject
*kobj
,
1766 struct kobj_attribute
*attr
, char *page
)
1768 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1771 static ssize_t
on_halt_store(struct kobject
*kobj
,
1772 struct kobj_attribute
*attr
,
1773 const char *buf
, size_t len
)
1775 return set_trigger(buf
, &on_halt_trigger
, len
);
1778 static struct kobj_attribute on_halt_attr
=
1779 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1782 static void do_machine_halt(void)
1785 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1786 stop_run(&on_halt_trigger
);
1788 void (*_machine_halt
)(void) = do_machine_halt
;
1792 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1794 static ssize_t
on_poff_show(struct kobject
*kobj
,
1795 struct kobj_attribute
*attr
, char *page
)
1797 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1800 static ssize_t
on_poff_store(struct kobject
*kobj
,
1801 struct kobj_attribute
*attr
,
1802 const char *buf
, size_t len
)
1804 return set_trigger(buf
, &on_poff_trigger
, len
);
1807 static struct kobj_attribute on_poff_attr
=
1808 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1811 static void do_machine_power_off(void)
1814 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1815 stop_run(&on_poff_trigger
);
1817 void (*_machine_power_off
)(void) = do_machine_power_off
;
1819 static void __init
shutdown_triggers_init(void)
1821 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1823 if (!shutdown_actions_kset
)
1825 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1826 &on_reboot_attr
.attr
))
1828 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1829 &on_panic_attr
.attr
))
1831 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1832 &on_halt_attr
.attr
))
1834 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1835 &on_poff_attr
.attr
))
1837 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1838 &on_restart_attr
.attr
))
1842 panic("shutdown_triggers_init failed\n");
1845 static void __init
shutdown_actions_init(void)
1849 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1850 if (!shutdown_actions_list
[i
]->init
)
1852 shutdown_actions_list
[i
]->init_rc
=
1853 shutdown_actions_list
[i
]->init();
1857 static int __init
s390_ipl_init(void)
1859 sclp_get_ipl_info(&sclp_ipl_info
);
1860 shutdown_actions_init();
1861 shutdown_triggers_init();
1865 __initcall(s390_ipl_init
);
1867 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1872 for (sx
= 0; src
[sx
] != 0; sx
++) {
1875 dst
[dx
++] = src
[sx
];
1881 static int __init
vmcmd_on_reboot_setup(char *str
)
1885 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1886 vmcmd_on_reboot
[127] = 0;
1887 on_reboot_trigger
.action
= &vmcmd_action
;
1890 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1892 static int __init
vmcmd_on_panic_setup(char *str
)
1896 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1897 vmcmd_on_panic
[127] = 0;
1898 on_panic_trigger
.action
= &vmcmd_action
;
1901 __setup("vmpanic=", vmcmd_on_panic_setup
);
1903 static int __init
vmcmd_on_halt_setup(char *str
)
1907 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1908 vmcmd_on_halt
[127] = 0;
1909 on_halt_trigger
.action
= &vmcmd_action
;
1912 __setup("vmhalt=", vmcmd_on_halt_setup
);
1914 static int __init
vmcmd_on_poff_setup(char *str
)
1918 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1919 vmcmd_on_poff
[127] = 0;
1920 on_poff_trigger
.action
= &vmcmd_action
;
1923 __setup("vmpoff=", vmcmd_on_poff_setup
);
1925 static int on_panic_notify(struct notifier_block
*self
,
1926 unsigned long event
, void *data
)
1932 static struct notifier_block on_panic_nb
= {
1933 .notifier_call
= on_panic_notify
,
1934 .priority
= INT_MIN
,
1937 void __init
setup_ipl(void)
1939 ipl_info
.type
= get_ipl_type();
1940 switch (ipl_info
.type
) {
1942 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1943 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1946 case IPL_TYPE_FCP_DUMP
:
1947 ipl_info
.data
.fcp
.dev_id
.devno
=
1948 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1949 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1950 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1951 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1954 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1955 sizeof(ipl_info
.data
.nss
.name
));
1957 case IPL_TYPE_UNKNOWN
:
1958 /* We have no info to copy */
1961 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1964 void __init
ipl_update_parameters(void)
1968 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1969 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1970 diag308_set_works
= 1;
1973 void __init
ipl_save_parameters(void)
1975 struct cio_iplinfo iplinfo
;
1978 if (cio_get_iplinfo(&iplinfo
))
1981 ipl_devno
= iplinfo
.devno
;
1982 ipl_flags
|= IPL_DEVNO_VALID
;
1983 if (!iplinfo
.is_qdio
)
1985 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1986 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
1987 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1988 memmove(dst
, src
, PAGE_SIZE
);
1989 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
1992 static LIST_HEAD(rcall
);
1993 static DEFINE_MUTEX(rcall_mutex
);
1995 void register_reset_call(struct reset_call
*reset
)
1997 mutex_lock(&rcall_mutex
);
1998 list_add(&reset
->list
, &rcall
);
1999 mutex_unlock(&rcall_mutex
);
2001 EXPORT_SYMBOL_GPL(register_reset_call
);
2003 void unregister_reset_call(struct reset_call
*reset
)
2005 mutex_lock(&rcall_mutex
);
2006 list_del(&reset
->list
);
2007 mutex_unlock(&rcall_mutex
);
2009 EXPORT_SYMBOL_GPL(unregister_reset_call
);
2011 static void do_reset_calls(void)
2013 struct reset_call
*reset
;
2016 if (diag308_set_works
) {
2021 list_for_each_entry(reset
, &rcall
, list
)
2025 u32 dump_prefix_page
;
2027 void s390_reset_system(void (*func
)(void *), void *data
)
2029 struct _lowcore
*lc
;
2031 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
2033 /* Stack for interrupt/machine check handler */
2034 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2036 /* Save prefix page address for dump case */
2037 dump_prefix_page
= (u32
)(unsigned long) lc
;
2039 /* Disable prefixing */
2042 /* Disable lowcore protection */
2043 __ctl_clear_bit(0,28);
2045 /* Set new machine check handler */
2046 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
| PSW_MASK_DAT
;
2047 S390_lowcore
.mcck_new_psw
.addr
=
2048 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
2050 /* Set new program check handler */
2051 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
| PSW_MASK_DAT
;
2052 S390_lowcore
.program_new_psw
.addr
=
2053 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;
2055 /* Store status at absolute zero */