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>
19 #include <linux/crash_dump.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
25 #include <asm/ebcdic.h>
26 #include <asm/reset.h>
29 #include <asm/checksum.h>
31 #define IPL_PARM_BLOCK_VERSION 0
33 #define IPL_UNKNOWN_STR "unknown"
34 #define IPL_CCW_STR "ccw"
35 #define IPL_FCP_STR "fcp"
36 #define IPL_FCP_DUMP_STR "fcp_dump"
37 #define IPL_NSS_STR "nss"
39 #define DUMP_CCW_STR "ccw"
40 #define DUMP_FCP_STR "fcp"
41 #define DUMP_NONE_STR "none"
44 * Four shutdown trigger types are supported:
51 #define ON_PANIC_STR "on_panic"
52 #define ON_HALT_STR "on_halt"
53 #define ON_POFF_STR "on_poff"
54 #define ON_REIPL_STR "on_reboot"
55 #define ON_RESTART_STR "on_restart"
57 struct shutdown_action
;
58 struct shutdown_trigger
{
60 struct shutdown_action
*action
;
64 * The following shutdown action types are supported:
66 #define SHUTDOWN_ACTION_IPL_STR "ipl"
67 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
68 #define SHUTDOWN_ACTION_DUMP_STR "dump"
69 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
70 #define SHUTDOWN_ACTION_STOP_STR "stop"
71 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
73 struct shutdown_action
{
75 void (*fn
) (struct shutdown_trigger
*trigger
);
80 static char *ipl_type_str(enum ipl_type type
)
87 case IPL_TYPE_FCP_DUMP
:
88 return IPL_FCP_DUMP_STR
;
91 case IPL_TYPE_UNKNOWN
:
93 return IPL_UNKNOWN_STR
;
103 static char *dump_type_str(enum dump_type type
)
107 return DUMP_NONE_STR
;
118 * Must be in data section since the bss section
119 * is not cleared when these are accessed.
121 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
122 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
125 REIPL_METHOD_CCW_CIO
,
126 REIPL_METHOD_CCW_DIAG
,
128 REIPL_METHOD_FCP_RO_DIAG
,
129 REIPL_METHOD_FCP_RW_DIAG
,
130 REIPL_METHOD_FCP_RO_VM
,
131 REIPL_METHOD_FCP_DUMP
,
133 REIPL_METHOD_NSS_DIAG
,
134 REIPL_METHOD_DEFAULT
,
140 DUMP_METHOD_CCW_DIAG
,
142 DUMP_METHOD_FCP_DIAG
,
145 static int diag308_set_works
= 0;
147 static struct ipl_parameter_block ipl_block
;
149 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
151 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
152 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
153 static struct ipl_parameter_block
*reipl_block_fcp
;
154 static struct ipl_parameter_block
*reipl_block_ccw
;
155 static struct ipl_parameter_block
*reipl_block_nss
;
156 static struct ipl_parameter_block
*reipl_block_actual
;
158 static int dump_capabilities
= DUMP_TYPE_NONE
;
159 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
160 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
161 static struct ipl_parameter_block
*dump_block_fcp
;
162 static struct ipl_parameter_block
*dump_block_ccw
;
164 static struct sclp_ipl_info sclp_ipl_info
;
166 int diag308(unsigned long subcode
, void *addr
)
168 register unsigned long _addr
asm("0") = (unsigned long) addr
;
169 register unsigned long _rc
asm("1") = 0;
172 " diag %0,%2,0x308\n"
175 : "+d" (_addr
), "+d" (_rc
)
176 : "d" (subcode
) : "cc", "memory");
179 EXPORT_SYMBOL_GPL(diag308
);
183 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
184 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
185 struct kobj_attribute *attr, \
188 return sprintf(page, _format, _value); \
190 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
191 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
193 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
194 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
195 struct kobj_attribute *attr, \
198 return sprintf(page, _fmt_out, \
199 (unsigned long long) _value); \
201 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
202 struct kobj_attribute *attr, \
203 const char *buf, size_t len) \
205 unsigned long long value; \
206 if (sscanf(buf, _fmt_in, &value) != 1) \
211 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
212 __ATTR(_name,(S_IRUGO | S_IWUSR), \
213 sys_##_prefix##_##_name##_show, \
214 sys_##_prefix##_##_name##_store);
216 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
217 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
218 struct kobj_attribute *attr, \
221 return sprintf(page, _fmt_out, _value); \
223 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
224 struct kobj_attribute *attr, \
225 const char *buf, size_t len) \
227 strncpy(_value, buf, sizeof(_value) - 1); \
231 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
232 __ATTR(_name,(S_IRUGO | S_IWUSR), \
233 sys_##_prefix##_##_name##_show, \
234 sys_##_prefix##_##_name##_store);
236 static void make_attrs_ro(struct attribute
**attrs
)
239 (*attrs
)->mode
= S_IRUGO
;
248 static __init
enum ipl_type
get_ipl_type(void)
250 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
252 if (ipl_flags
& IPL_NSS_VALID
)
254 if (!(ipl_flags
& IPL_DEVNO_VALID
))
255 return IPL_TYPE_UNKNOWN
;
256 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
258 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
259 return IPL_TYPE_UNKNOWN
;
260 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
261 return IPL_TYPE_UNKNOWN
;
262 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
263 return IPL_TYPE_FCP_DUMP
;
267 struct ipl_info ipl_info
;
268 EXPORT_SYMBOL_GPL(ipl_info
);
270 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
273 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
276 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
278 /* VM IPL PARM routines */
279 size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
280 const struct ipl_parameter_block
*ipb
)
284 char has_lowercase
= 0;
287 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
288 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
290 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
291 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
292 /* If at least one character is lowercase, we assume mixed
293 * case; otherwise we convert everything to lowercase.
295 for (i
= 0; i
< len
; i
++)
296 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
297 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
298 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
303 EBC_TOLOWER(dest
, len
);
311 size_t append_ipl_vmparm(char *dest
, size_t size
)
316 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
317 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
323 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
324 struct kobj_attribute
*attr
, char *page
)
326 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
328 append_ipl_vmparm(parm
, sizeof(parm
));
329 return sprintf(page
, "%s\n", parm
);
332 static size_t scpdata_length(const char* buf
, size_t count
)
335 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
342 size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
343 const struct ipl_parameter_block
*ipb
)
349 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
350 ipb
->ipl_info
.fcp
.scp_data_len
));
355 for (i
= 0; i
< count
; i
++) {
356 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
360 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
365 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
367 for (i
= 0; i
< count
; i
++)
368 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
374 size_t append_ipl_scpdata(char *dest
, size_t len
)
379 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
380 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
387 static struct kobj_attribute sys_ipl_vm_parm_attr
=
388 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
390 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
391 struct kobj_attribute
*attr
, char *page
)
393 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
395 switch (ipl_info
.type
) {
397 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
399 case IPL_TYPE_FCP_DUMP
:
400 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
406 static struct kobj_attribute sys_ipl_device_attr
=
407 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
409 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
410 struct bin_attribute
*attr
, char *buf
,
411 loff_t off
, size_t count
)
413 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
417 static struct bin_attribute ipl_parameter_attr
= {
419 .name
= "binary_parameter",
423 .read
= &ipl_parameter_read
,
426 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
427 struct bin_attribute
*attr
, char *buf
,
428 loff_t off
, size_t count
)
430 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
431 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
433 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
436 static struct bin_attribute ipl_scp_data_attr
= {
442 .read
= ipl_scp_data_read
,
445 /* FCP ipl device attributes */
447 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
448 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
449 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
450 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
451 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
452 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
453 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
454 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
456 static struct attribute
*ipl_fcp_attrs
[] = {
457 &sys_ipl_type_attr
.attr
,
458 &sys_ipl_device_attr
.attr
,
459 &sys_ipl_fcp_wwpn_attr
.attr
,
460 &sys_ipl_fcp_lun_attr
.attr
,
461 &sys_ipl_fcp_bootprog_attr
.attr
,
462 &sys_ipl_fcp_br_lba_attr
.attr
,
466 static struct attribute_group ipl_fcp_attr_group
= {
467 .attrs
= ipl_fcp_attrs
,
470 /* CCW ipl device attributes */
472 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
473 struct kobj_attribute
*attr
, char *page
)
475 char loadparm
[LOADPARM_LEN
+ 1] = {};
477 if (!sclp_ipl_info
.is_valid
)
478 return sprintf(page
, "#unknown#\n");
479 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
480 EBCASC(loadparm
, LOADPARM_LEN
);
482 return sprintf(page
, "%s\n", loadparm
);
485 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
486 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
488 static struct attribute
*ipl_ccw_attrs_vm
[] = {
489 &sys_ipl_type_attr
.attr
,
490 &sys_ipl_device_attr
.attr
,
491 &sys_ipl_ccw_loadparm_attr
.attr
,
492 &sys_ipl_vm_parm_attr
.attr
,
496 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
497 &sys_ipl_type_attr
.attr
,
498 &sys_ipl_device_attr
.attr
,
499 &sys_ipl_ccw_loadparm_attr
.attr
,
503 static struct attribute_group ipl_ccw_attr_group_vm
= {
504 .attrs
= ipl_ccw_attrs_vm
,
507 static struct attribute_group ipl_ccw_attr_group_lpar
= {
508 .attrs
= ipl_ccw_attrs_lpar
511 /* NSS ipl device attributes */
513 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
515 static struct attribute
*ipl_nss_attrs
[] = {
516 &sys_ipl_type_attr
.attr
,
517 &sys_ipl_nss_name_attr
.attr
,
518 &sys_ipl_ccw_loadparm_attr
.attr
,
519 &sys_ipl_vm_parm_attr
.attr
,
523 static struct attribute_group ipl_nss_attr_group
= {
524 .attrs
= ipl_nss_attrs
,
527 /* UNKNOWN ipl device attributes */
529 static struct attribute
*ipl_unknown_attrs
[] = {
530 &sys_ipl_type_attr
.attr
,
534 static struct attribute_group ipl_unknown_attr_group
= {
535 .attrs
= ipl_unknown_attrs
,
538 static struct kset
*ipl_kset
;
540 static int __init
ipl_register_fcp_files(void)
544 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
547 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
550 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
554 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
557 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
562 static void __ipl_run(void *unused
)
564 diag308(DIAG308_IPL
, NULL
);
566 __cpcmd("IPL", NULL
, 0, NULL
);
567 else if (ipl_info
.type
== IPL_TYPE_CCW
)
568 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
571 static void ipl_run(struct shutdown_trigger
*trigger
)
573 smp_switch_to_ipl_cpu(__ipl_run
, NULL
);
576 static int __init
ipl_init(void)
580 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
585 switch (ipl_info
.type
) {
588 rc
= sysfs_create_group(&ipl_kset
->kobj
,
589 &ipl_ccw_attr_group_vm
);
591 rc
= sysfs_create_group(&ipl_kset
->kobj
,
592 &ipl_ccw_attr_group_lpar
);
595 case IPL_TYPE_FCP_DUMP
:
596 rc
= ipl_register_fcp_files();
599 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
602 rc
= sysfs_create_group(&ipl_kset
->kobj
,
603 &ipl_unknown_attr_group
);
608 panic("ipl_init failed: rc = %i\n", rc
);
613 static struct shutdown_action __refdata ipl_action
= {
614 .name
= SHUTDOWN_ACTION_IPL_STR
,
620 * reipl shutdown action: Reboot Linux on shutdown.
623 /* VM IPL PARM attributes */
624 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
627 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
629 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
630 return sprintf(page
, "%s\n", vmparm
);
633 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
635 const char *buf
, size_t len
)
639 /* ignore trailing newline */
641 if ((len
> 0) && (buf
[len
- 1] == '\n'))
644 if (ip_len
> vmparm_max
)
647 /* parm is used to store kernel options, check for common chars */
648 for (i
= 0; i
< ip_len
; i
++)
649 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
652 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
653 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
655 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
656 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
657 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
659 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
666 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
667 struct kobj_attribute
*attr
, char *page
)
669 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
672 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
673 struct kobj_attribute
*attr
,
674 const char *buf
, size_t len
)
676 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
680 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
681 struct kobj_attribute
*attr
, char *page
)
683 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
686 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
687 struct kobj_attribute
*attr
,
688 const char *buf
, size_t len
)
690 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
693 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
694 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
695 reipl_nss_vmparm_store
);
696 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
697 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
698 reipl_ccw_vmparm_store
);
700 /* FCP reipl device attributes */
702 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
703 struct bin_attribute
*attr
,
704 char *buf
, loff_t off
, size_t count
)
706 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
707 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
709 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
712 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
713 struct bin_attribute
*attr
,
714 char *buf
, loff_t off
, size_t count
)
722 if (off
>= DIAG308_SCPDATA_SIZE
)
725 if (count
> DIAG308_SCPDATA_SIZE
- off
)
726 count
= DIAG308_SCPDATA_SIZE
- off
;
728 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
729 scpdata_len
= off
+ count
;
731 if (scpdata_len
% 8) {
732 padding
= 8 - (scpdata_len
% 8);
733 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
735 scpdata_len
+= padding
;
738 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
739 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
740 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
745 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
748 .mode
= S_IRUGO
| S_IWUSR
,
751 .read
= reipl_fcp_scpdata_read
,
752 .write
= reipl_fcp_scpdata_write
,
755 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
756 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
757 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
758 reipl_block_fcp
->ipl_info
.fcp
.lun
);
759 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
760 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
761 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
762 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
763 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
764 reipl_block_fcp
->ipl_info
.fcp
.devno
);
766 static struct attribute
*reipl_fcp_attrs
[] = {
767 &sys_reipl_fcp_device_attr
.attr
,
768 &sys_reipl_fcp_wwpn_attr
.attr
,
769 &sys_reipl_fcp_lun_attr
.attr
,
770 &sys_reipl_fcp_bootprog_attr
.attr
,
771 &sys_reipl_fcp_br_lba_attr
.attr
,
775 static struct attribute_group reipl_fcp_attr_group
= {
776 .attrs
= reipl_fcp_attrs
,
779 /* CCW reipl device attributes */
781 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
782 reipl_block_ccw
->ipl_info
.ccw
.devno
);
784 static void reipl_get_ascii_loadparm(char *loadparm
,
785 struct ipl_parameter_block
*ibp
)
787 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
788 EBCASC(loadparm
, LOADPARM_LEN
);
789 loadparm
[LOADPARM_LEN
] = 0;
793 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
796 char buf
[LOADPARM_LEN
+ 1];
798 reipl_get_ascii_loadparm(buf
, ipb
);
799 return sprintf(page
, "%s\n", buf
);
802 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
803 const char *buf
, size_t len
)
807 /* ignore trailing newline */
809 if ((len
> 0) && (buf
[len
- 1] == '\n'))
811 /* loadparm can have max 8 characters and must not start with a blank */
812 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
814 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
815 for (i
= 0; i
< lp_len
; i
++) {
816 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
821 /* initialize loadparm with blanks */
822 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
823 /* copy and convert to ebcdic */
824 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
825 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
830 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
831 struct kobj_attribute
*attr
, char *page
)
833 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
836 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
837 struct kobj_attribute
*attr
,
838 const char *buf
, size_t len
)
840 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
844 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
845 struct kobj_attribute
*attr
, char *page
)
847 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
850 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
851 struct kobj_attribute
*attr
,
852 const char *buf
, size_t len
)
854 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
857 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
858 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
859 reipl_ccw_loadparm_store
);
861 static struct attribute
*reipl_ccw_attrs_vm
[] = {
862 &sys_reipl_ccw_device_attr
.attr
,
863 &sys_reipl_ccw_loadparm_attr
.attr
,
864 &sys_reipl_ccw_vmparm_attr
.attr
,
868 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
869 &sys_reipl_ccw_device_attr
.attr
,
870 &sys_reipl_ccw_loadparm_attr
.attr
,
874 static struct attribute_group reipl_ccw_attr_group_vm
= {
876 .attrs
= reipl_ccw_attrs_vm
,
879 static struct attribute_group reipl_ccw_attr_group_lpar
= {
881 .attrs
= reipl_ccw_attrs_lpar
,
885 /* NSS reipl device attributes */
886 static void reipl_get_ascii_nss_name(char *dst
,
887 struct ipl_parameter_block
*ipb
)
889 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
890 EBCASC(dst
, NSS_NAME_SIZE
);
891 dst
[NSS_NAME_SIZE
] = 0;
894 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
895 struct kobj_attribute
*attr
, char *page
)
897 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
899 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
900 return sprintf(page
, "%s\n", nss_name
);
903 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
904 struct kobj_attribute
*attr
,
905 const char *buf
, size_t len
)
909 /* ignore trailing newline */
911 if ((len
> 0) && (buf
[len
- 1] == '\n'))
914 if (nss_len
> NSS_NAME_SIZE
)
917 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
919 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
920 DIAG308_VM_FLAGS_NSS_VALID
;
921 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
922 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
923 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
925 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
926 ~DIAG308_VM_FLAGS_NSS_VALID
;
932 static struct kobj_attribute sys_reipl_nss_name_attr
=
933 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
934 reipl_nss_name_store
);
936 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
937 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
938 reipl_nss_loadparm_store
);
940 static struct attribute
*reipl_nss_attrs
[] = {
941 &sys_reipl_nss_name_attr
.attr
,
942 &sys_reipl_nss_loadparm_attr
.attr
,
943 &sys_reipl_nss_vmparm_attr
.attr
,
947 static struct attribute_group reipl_nss_attr_group
= {
949 .attrs
= reipl_nss_attrs
,
954 static int reipl_set_type(enum ipl_type type
)
956 if (!(reipl_capabilities
& type
))
961 if (diag308_set_works
)
962 reipl_method
= REIPL_METHOD_CCW_DIAG
;
963 else if (MACHINE_IS_VM
)
964 reipl_method
= REIPL_METHOD_CCW_VM
;
966 reipl_method
= REIPL_METHOD_CCW_CIO
;
967 reipl_block_actual
= reipl_block_ccw
;
970 if (diag308_set_works
)
971 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
972 else if (MACHINE_IS_VM
)
973 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
975 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
976 reipl_block_actual
= reipl_block_fcp
;
978 case IPL_TYPE_FCP_DUMP
:
979 reipl_method
= REIPL_METHOD_FCP_DUMP
;
982 if (diag308_set_works
)
983 reipl_method
= REIPL_METHOD_NSS_DIAG
;
985 reipl_method
= REIPL_METHOD_NSS
;
986 reipl_block_actual
= reipl_block_nss
;
988 case IPL_TYPE_UNKNOWN
:
989 reipl_method
= REIPL_METHOD_DEFAULT
;
998 static ssize_t
reipl_type_show(struct kobject
*kobj
,
999 struct kobj_attribute
*attr
, char *page
)
1001 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1004 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1005 struct kobj_attribute
*attr
,
1006 const char *buf
, size_t len
)
1010 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1011 rc
= reipl_set_type(IPL_TYPE_CCW
);
1012 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1013 rc
= reipl_set_type(IPL_TYPE_FCP
);
1014 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1015 rc
= reipl_set_type(IPL_TYPE_NSS
);
1016 return (rc
!= 0) ? rc
: len
;
1019 static struct kobj_attribute reipl_type_attr
=
1020 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1022 static struct kset
*reipl_kset
;
1023 static struct kset
*reipl_fcp_kset
;
1025 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1026 const enum ipl_method m
)
1028 char loadparm
[LOADPARM_LEN
+ 1] = {};
1029 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1030 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1033 reipl_get_ascii_loadparm(loadparm
, ipb
);
1034 reipl_get_ascii_nss_name(nss_name
, ipb
);
1035 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1038 case REIPL_METHOD_CCW_VM
:
1039 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1041 case REIPL_METHOD_NSS
:
1042 pos
= sprintf(dst
, "IPL %s", nss_name
);
1047 if (strlen(loadparm
) > 0)
1048 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1049 if (strlen(vmparm
) > 0)
1050 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1053 static void __reipl_run(void *unused
)
1055 struct ccw_dev_id devid
;
1056 static char buf
[128];
1058 switch (reipl_method
) {
1059 case REIPL_METHOD_CCW_CIO
:
1060 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1062 reipl_ccw_dev(&devid
);
1064 case REIPL_METHOD_CCW_VM
:
1065 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1066 __cpcmd(buf
, NULL
, 0, NULL
);
1068 case REIPL_METHOD_CCW_DIAG
:
1069 diag308(DIAG308_SET
, reipl_block_ccw
);
1070 diag308(DIAG308_IPL
, NULL
);
1072 case REIPL_METHOD_FCP_RW_DIAG
:
1073 diag308(DIAG308_SET
, reipl_block_fcp
);
1074 diag308(DIAG308_IPL
, NULL
);
1076 case REIPL_METHOD_FCP_RO_DIAG
:
1077 diag308(DIAG308_IPL
, NULL
);
1079 case REIPL_METHOD_FCP_RO_VM
:
1080 __cpcmd("IPL", NULL
, 0, NULL
);
1082 case REIPL_METHOD_NSS_DIAG
:
1083 diag308(DIAG308_SET
, reipl_block_nss
);
1084 diag308(DIAG308_IPL
, NULL
);
1086 case REIPL_METHOD_NSS
:
1087 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1088 __cpcmd(buf
, NULL
, 0, NULL
);
1090 case REIPL_METHOD_DEFAULT
:
1092 __cpcmd("IPL", NULL
, 0, NULL
);
1093 diag308(DIAG308_IPL
, NULL
);
1095 case REIPL_METHOD_FCP_DUMP
:
1098 disabled_wait((unsigned long) __builtin_return_address(0));
1101 static void reipl_run(struct shutdown_trigger
*trigger
)
1103 smp_switch_to_ipl_cpu(__reipl_run
, NULL
);
1106 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1108 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1109 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1110 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1111 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1114 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1117 /* check if read scp info worked and set loadparm */
1118 if (sclp_ipl_info
.is_valid
)
1119 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
1120 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1122 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1123 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
1124 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1127 if (MACHINE_IS_VM
&& diag308_set_works
&&
1128 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1130 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1131 ipb
->ipl_info
.ccw
.vm_parm_len
=
1132 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1133 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1134 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1138 static int __init
reipl_nss_init(void)
1145 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1146 if (!reipl_block_nss
)
1149 if (!diag308_set_works
)
1150 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1152 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1156 reipl_block_ccw_init(reipl_block_nss
);
1157 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1158 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1159 ' ', NSS_NAME_SIZE
);
1160 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1161 kernel_nss_name
, strlen(kernel_nss_name
));
1162 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1163 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1164 DIAG308_VM_FLAGS_NSS_VALID
;
1166 reipl_block_ccw_fill_parms(reipl_block_nss
);
1169 reipl_capabilities
|= IPL_TYPE_NSS
;
1173 static int __init
reipl_ccw_init(void)
1177 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1178 if (!reipl_block_ccw
)
1181 if (MACHINE_IS_VM
) {
1182 if (!diag308_set_works
)
1183 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1184 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1185 &reipl_ccw_attr_group_vm
);
1187 if(!diag308_set_works
)
1188 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1189 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1190 &reipl_ccw_attr_group_lpar
);
1195 reipl_block_ccw_init(reipl_block_ccw
);
1196 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1197 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1198 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1201 reipl_capabilities
|= IPL_TYPE_CCW
;
1205 static int __init
reipl_fcp_init(void)
1209 if (!diag308_set_works
) {
1210 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1211 make_attrs_ro(reipl_fcp_attrs
);
1212 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1217 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1218 if (!reipl_block_fcp
)
1221 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1222 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1224 if (!reipl_fcp_kset
) {
1225 free_page((unsigned long) reipl_block_fcp
);
1229 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1231 kset_unregister(reipl_fcp_kset
);
1232 free_page((unsigned long) reipl_block_fcp
);
1236 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1237 &sys_reipl_fcp_scp_data_attr
);
1239 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1240 kset_unregister(reipl_fcp_kset
);
1241 free_page((unsigned long) reipl_block_fcp
);
1245 if (ipl_info
.type
== IPL_TYPE_FCP
)
1246 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1248 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1249 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1250 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1251 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1252 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1254 reipl_capabilities
|= IPL_TYPE_FCP
;
1258 static int __init
reipl_init(void)
1262 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1265 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1267 kset_unregister(reipl_kset
);
1270 rc
= reipl_ccw_init();
1273 rc
= reipl_fcp_init();
1276 rc
= reipl_nss_init();
1279 rc
= reipl_set_type(ipl_info
.type
);
1285 static struct shutdown_action __refdata reipl_action
= {
1286 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1292 * dump shutdown action: Dump Linux on shutdown.
1295 /* FCP dump device attributes */
1297 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1298 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1299 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1300 dump_block_fcp
->ipl_info
.fcp
.lun
);
1301 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1302 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1303 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1304 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1305 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1306 dump_block_fcp
->ipl_info
.fcp
.devno
);
1308 static struct attribute
*dump_fcp_attrs
[] = {
1309 &sys_dump_fcp_device_attr
.attr
,
1310 &sys_dump_fcp_wwpn_attr
.attr
,
1311 &sys_dump_fcp_lun_attr
.attr
,
1312 &sys_dump_fcp_bootprog_attr
.attr
,
1313 &sys_dump_fcp_br_lba_attr
.attr
,
1317 static struct attribute_group dump_fcp_attr_group
= {
1318 .name
= IPL_FCP_STR
,
1319 .attrs
= dump_fcp_attrs
,
1322 /* CCW dump device attributes */
1324 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1325 dump_block_ccw
->ipl_info
.ccw
.devno
);
1327 static struct attribute
*dump_ccw_attrs
[] = {
1328 &sys_dump_ccw_device_attr
.attr
,
1332 static struct attribute_group dump_ccw_attr_group
= {
1333 .name
= IPL_CCW_STR
,
1334 .attrs
= dump_ccw_attrs
,
1339 static int dump_set_type(enum dump_type type
)
1341 if (!(dump_capabilities
& type
))
1345 if (diag308_set_works
)
1346 dump_method
= DUMP_METHOD_CCW_DIAG
;
1347 else if (MACHINE_IS_VM
)
1348 dump_method
= DUMP_METHOD_CCW_VM
;
1350 dump_method
= DUMP_METHOD_CCW_CIO
;
1353 dump_method
= DUMP_METHOD_FCP_DIAG
;
1356 dump_method
= DUMP_METHOD_NONE
;
1362 static ssize_t
dump_type_show(struct kobject
*kobj
,
1363 struct kobj_attribute
*attr
, char *page
)
1365 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1368 static ssize_t
dump_type_store(struct kobject
*kobj
,
1369 struct kobj_attribute
*attr
,
1370 const char *buf
, size_t len
)
1374 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1375 rc
= dump_set_type(DUMP_TYPE_NONE
);
1376 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1377 rc
= dump_set_type(DUMP_TYPE_CCW
);
1378 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1379 rc
= dump_set_type(DUMP_TYPE_FCP
);
1380 return (rc
!= 0) ? rc
: len
;
1383 static struct kobj_attribute dump_type_attr
=
1384 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1386 static struct kset
*dump_kset
;
1388 static void __dump_run(void *unused
)
1390 struct ccw_dev_id devid
;
1391 static char buf
[100];
1393 switch (dump_method
) {
1394 case DUMP_METHOD_CCW_CIO
:
1395 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1397 reipl_ccw_dev(&devid
);
1399 case DUMP_METHOD_CCW_VM
:
1400 sprintf(buf
, "STORE STATUS");
1401 __cpcmd(buf
, NULL
, 0, NULL
);
1402 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1403 __cpcmd(buf
, NULL
, 0, NULL
);
1405 case DUMP_METHOD_CCW_DIAG
:
1406 diag308(DIAG308_SET
, dump_block_ccw
);
1407 diag308(DIAG308_DUMP
, NULL
);
1409 case DUMP_METHOD_FCP_DIAG
:
1410 diag308(DIAG308_SET
, dump_block_fcp
);
1411 diag308(DIAG308_DUMP
, NULL
);
1418 static void dump_run(struct shutdown_trigger
*trigger
)
1420 if (dump_method
== DUMP_METHOD_NONE
)
1423 smp_switch_to_ipl_cpu(__dump_run
, NULL
);
1426 static int __init
dump_ccw_init(void)
1430 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1431 if (!dump_block_ccw
)
1433 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1435 free_page((unsigned long)dump_block_ccw
);
1438 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1439 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1440 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1441 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1442 dump_capabilities
|= DUMP_TYPE_CCW
;
1446 static int __init
dump_fcp_init(void)
1450 if (!sclp_ipl_info
.has_dump
)
1451 return 0; /* LDIPL DUMP is not installed */
1452 if (!diag308_set_works
)
1454 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1455 if (!dump_block_fcp
)
1457 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1459 free_page((unsigned long)dump_block_fcp
);
1462 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1463 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1464 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1465 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1466 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1467 dump_capabilities
|= DUMP_TYPE_FCP
;
1471 static int __init
dump_init(void)
1475 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1478 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1480 kset_unregister(dump_kset
);
1483 rc
= dump_ccw_init();
1486 rc
= dump_fcp_init();
1489 dump_set_type(DUMP_TYPE_NONE
);
1493 static struct shutdown_action __refdata dump_action
= {
1494 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1499 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1503 * Bypass dynamic address translation (DAT) when storing IPL parameter
1504 * information block address and checksum into the prefix area
1505 * (corresponding to absolute addresses 0-8191).
1506 * When enhanced DAT applies and the STE format control in one,
1507 * the absolute address is formed without prefixing. In this case a
1508 * normal store (stg/st) into the prefix area would no more match to
1509 * absolute addresses 0-8191.
1512 asm volatile("sturg %0,%1"
1513 :: "a" ((unsigned long) reipl_block_actual
),
1514 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1516 asm volatile("stura %0,%1"
1517 :: "a" ((unsigned long) reipl_block_actual
),
1518 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1520 asm volatile("stura %0,%1"
1521 :: "a" (csum_partial(reipl_block_actual
,
1522 reipl_block_actual
->hdr
.len
, 0)),
1523 "a" (&lowcore_ptr
[smp_processor_id()]->ipib_checksum
));
1528 static int __init
dump_reipl_init(void)
1530 if (!diag308_set_works
)
1536 static struct shutdown_action __refdata dump_reipl_action
= {
1537 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1538 .fn
= dump_reipl_run
,
1539 .init
= dump_reipl_init
,
1543 * vmcmd shutdown action: Trigger vm command on shutdown.
1546 static char vmcmd_on_reboot
[128];
1547 static char vmcmd_on_panic
[128];
1548 static char vmcmd_on_halt
[128];
1549 static char vmcmd_on_poff
[128];
1550 static char vmcmd_on_restart
[128];
1552 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1553 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1554 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1555 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1556 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1558 static struct attribute
*vmcmd_attrs
[] = {
1559 &sys_vmcmd_on_reboot_attr
.attr
,
1560 &sys_vmcmd_on_panic_attr
.attr
,
1561 &sys_vmcmd_on_halt_attr
.attr
,
1562 &sys_vmcmd_on_poff_attr
.attr
,
1563 &sys_vmcmd_on_restart_attr
.attr
,
1567 static struct attribute_group vmcmd_attr_group
= {
1568 .attrs
= vmcmd_attrs
,
1571 static struct kset
*vmcmd_kset
;
1573 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1575 char *cmd
, *next_cmd
;
1577 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1578 cmd
= vmcmd_on_reboot
;
1579 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1580 cmd
= vmcmd_on_panic
;
1581 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1582 cmd
= vmcmd_on_halt
;
1583 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1584 cmd
= vmcmd_on_poff
;
1585 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1586 cmd
= vmcmd_on_restart
;
1590 if (strlen(cmd
) == 0)
1593 next_cmd
= strchr(cmd
, '\n');
1598 __cpcmd(cmd
, NULL
, 0, NULL
);
1600 } while (cmd
!= NULL
);
1603 static int vmcmd_init(void)
1607 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1610 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1613 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1614 vmcmd_run
, vmcmd_init
};
1617 * stop shutdown action: Stop Linux on shutdown.
1620 static void stop_run(struct shutdown_trigger
*trigger
)
1622 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1623 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1624 disabled_wait((unsigned long) __builtin_return_address(0));
1625 while (sigp(smp_processor_id(), sigp_stop
) == sigp_busy
)
1630 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1635 static struct shutdown_action
*shutdown_actions_list
[] = {
1636 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1637 &vmcmd_action
, &stop_action
};
1638 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1644 static struct kset
*shutdown_actions_kset
;
1646 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1651 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1652 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1653 if (shutdown_actions_list
[i
]->init_rc
) {
1654 return shutdown_actions_list
[i
]->init_rc
;
1656 trigger
->action
= shutdown_actions_list
[i
];
1666 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1669 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1670 struct kobj_attribute
*attr
, char *page
)
1672 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1675 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1676 struct kobj_attribute
*attr
,
1677 const char *buf
, size_t len
)
1679 return set_trigger(buf
, &on_reboot_trigger
, len
);
1682 static struct kobj_attribute on_reboot_attr
=
1683 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1685 static void do_machine_restart(char *__unused
)
1688 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1691 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1695 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1697 static ssize_t
on_panic_show(struct kobject
*kobj
,
1698 struct kobj_attribute
*attr
, char *page
)
1700 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1703 static ssize_t
on_panic_store(struct kobject
*kobj
,
1704 struct kobj_attribute
*attr
,
1705 const char *buf
, size_t len
)
1707 return set_trigger(buf
, &on_panic_trigger
, len
);
1710 static struct kobj_attribute on_panic_attr
=
1711 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1713 static void do_panic(void)
1715 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1716 stop_run(&on_panic_trigger
);
1721 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1724 static ssize_t
on_restart_show(struct kobject
*kobj
,
1725 struct kobj_attribute
*attr
, char *page
)
1727 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1730 static ssize_t
on_restart_store(struct kobject
*kobj
,
1731 struct kobj_attribute
*attr
,
1732 const char *buf
, size_t len
)
1734 return set_trigger(buf
, &on_restart_trigger
, len
);
1737 static struct kobj_attribute on_restart_attr
=
1738 __ATTR(on_restart
, 0644, on_restart_show
, on_restart_store
);
1740 void do_restart(void)
1742 smp_restart_with_online_cpu();
1744 #ifdef CONFIG_CRASH_DUMP
1747 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1748 stop_run(&on_restart_trigger
);
1753 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1755 static ssize_t
on_halt_show(struct kobject
*kobj
,
1756 struct kobj_attribute
*attr
, char *page
)
1758 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1761 static ssize_t
on_halt_store(struct kobject
*kobj
,
1762 struct kobj_attribute
*attr
,
1763 const char *buf
, size_t len
)
1765 return set_trigger(buf
, &on_halt_trigger
, len
);
1768 static struct kobj_attribute on_halt_attr
=
1769 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1772 static void do_machine_halt(void)
1775 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1776 stop_run(&on_halt_trigger
);
1778 void (*_machine_halt
)(void) = do_machine_halt
;
1782 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1784 static ssize_t
on_poff_show(struct kobject
*kobj
,
1785 struct kobj_attribute
*attr
, char *page
)
1787 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1790 static ssize_t
on_poff_store(struct kobject
*kobj
,
1791 struct kobj_attribute
*attr
,
1792 const char *buf
, size_t len
)
1794 return set_trigger(buf
, &on_poff_trigger
, len
);
1797 static struct kobj_attribute on_poff_attr
=
1798 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1801 static void do_machine_power_off(void)
1804 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1805 stop_run(&on_poff_trigger
);
1807 void (*_machine_power_off
)(void) = do_machine_power_off
;
1809 static void __init
shutdown_triggers_init(void)
1811 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1813 if (!shutdown_actions_kset
)
1815 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1816 &on_reboot_attr
.attr
))
1818 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1819 &on_panic_attr
.attr
))
1821 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1822 &on_halt_attr
.attr
))
1824 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1825 &on_poff_attr
.attr
))
1827 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1828 &on_restart_attr
.attr
))
1832 panic("shutdown_triggers_init failed\n");
1835 static void __init
shutdown_actions_init(void)
1839 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1840 if (!shutdown_actions_list
[i
]->init
)
1842 shutdown_actions_list
[i
]->init_rc
=
1843 shutdown_actions_list
[i
]->init();
1847 static int __init
s390_ipl_init(void)
1849 sclp_get_ipl_info(&sclp_ipl_info
);
1850 shutdown_actions_init();
1851 shutdown_triggers_init();
1855 __initcall(s390_ipl_init
);
1857 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1862 for (sx
= 0; src
[sx
] != 0; sx
++) {
1865 dst
[dx
++] = src
[sx
];
1871 static int __init
vmcmd_on_reboot_setup(char *str
)
1875 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1876 vmcmd_on_reboot
[127] = 0;
1877 on_reboot_trigger
.action
= &vmcmd_action
;
1880 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1882 static int __init
vmcmd_on_panic_setup(char *str
)
1886 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1887 vmcmd_on_panic
[127] = 0;
1888 on_panic_trigger
.action
= &vmcmd_action
;
1891 __setup("vmpanic=", vmcmd_on_panic_setup
);
1893 static int __init
vmcmd_on_halt_setup(char *str
)
1897 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1898 vmcmd_on_halt
[127] = 0;
1899 on_halt_trigger
.action
= &vmcmd_action
;
1902 __setup("vmhalt=", vmcmd_on_halt_setup
);
1904 static int __init
vmcmd_on_poff_setup(char *str
)
1908 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1909 vmcmd_on_poff
[127] = 0;
1910 on_poff_trigger
.action
= &vmcmd_action
;
1913 __setup("vmpoff=", vmcmd_on_poff_setup
);
1915 static int on_panic_notify(struct notifier_block
*self
,
1916 unsigned long event
, void *data
)
1922 static struct notifier_block on_panic_nb
= {
1923 .notifier_call
= on_panic_notify
,
1924 .priority
= INT_MIN
,
1927 void __init
setup_ipl(void)
1929 ipl_info
.type
= get_ipl_type();
1930 switch (ipl_info
.type
) {
1932 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1933 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1936 case IPL_TYPE_FCP_DUMP
:
1937 ipl_info
.data
.fcp
.dev_id
.devno
=
1938 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1939 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1940 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1941 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1944 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1945 sizeof(ipl_info
.data
.nss
.name
));
1947 case IPL_TYPE_UNKNOWN
:
1948 /* We have no info to copy */
1951 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1954 void __init
ipl_update_parameters(void)
1958 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1959 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1960 diag308_set_works
= 1;
1963 void __init
ipl_save_parameters(void)
1965 struct cio_iplinfo iplinfo
;
1968 if (cio_get_iplinfo(&iplinfo
))
1971 ipl_devno
= iplinfo
.devno
;
1972 ipl_flags
|= IPL_DEVNO_VALID
;
1973 if (!iplinfo
.is_qdio
)
1975 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1976 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
1977 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1978 memmove(dst
, src
, PAGE_SIZE
);
1979 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
1982 static LIST_HEAD(rcall
);
1983 static DEFINE_MUTEX(rcall_mutex
);
1985 void register_reset_call(struct reset_call
*reset
)
1987 mutex_lock(&rcall_mutex
);
1988 list_add(&reset
->list
, &rcall
);
1989 mutex_unlock(&rcall_mutex
);
1991 EXPORT_SYMBOL_GPL(register_reset_call
);
1993 void unregister_reset_call(struct reset_call
*reset
)
1995 mutex_lock(&rcall_mutex
);
1996 list_del(&reset
->list
);
1997 mutex_unlock(&rcall_mutex
);
1999 EXPORT_SYMBOL_GPL(unregister_reset_call
);
2001 static void do_reset_calls(void)
2003 struct reset_call
*reset
;
2006 if (diag308_set_works
) {
2011 list_for_each_entry(reset
, &rcall
, list
)
2015 u32 dump_prefix_page
;
2017 void s390_reset_system(void)
2019 struct _lowcore
*lc
;
2021 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
2023 /* Stack for interrupt/machine check handler */
2024 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2026 /* Save prefix page address for dump case */
2027 dump_prefix_page
= (u32
)(unsigned long) lc
;
2029 /* Disable prefixing */
2032 /* Disable lowcore protection */
2033 __ctl_clear_bit(0,28);
2035 /* Set new machine check handler */
2036 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
2037 S390_lowcore
.mcck_new_psw
.addr
=
2038 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
2040 /* Set new program check handler */
2041 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
2042 S390_lowcore
.program_new_psw
.addr
=
2043 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;