1 // SPDX-License-Identifier: GPL-2.0
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005, 2012
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/export.h>
13 #include <linux/init.h>
14 #include <linux/device.h>
15 #include <linux/delay.h>
16 #include <linux/reboot.h>
17 #include <linux/ctype.h>
19 #include <linux/gfp.h>
20 #include <linux/crash_dump.h>
21 #include <linux/debug_locks.h>
25 #include <asm/setup.h>
26 #include <asm/cpcmd.h>
27 #include <asm/ebcdic.h>
29 #include <asm/checksum.h>
30 #include <asm/debug.h>
31 #include <asm/os_info.h>
34 #define IPL_PARM_BLOCK_VERSION 0
36 #define IPL_UNKNOWN_STR "unknown"
37 #define IPL_CCW_STR "ccw"
38 #define IPL_FCP_STR "fcp"
39 #define IPL_FCP_DUMP_STR "fcp_dump"
40 #define IPL_NSS_STR "nss"
42 #define DUMP_CCW_STR "ccw"
43 #define DUMP_FCP_STR "fcp"
44 #define DUMP_NONE_STR "none"
47 * Four shutdown trigger types are supported:
54 #define ON_PANIC_STR "on_panic"
55 #define ON_HALT_STR "on_halt"
56 #define ON_POFF_STR "on_poff"
57 #define ON_REIPL_STR "on_reboot"
58 #define ON_RESTART_STR "on_restart"
60 struct shutdown_action
;
61 struct shutdown_trigger
{
63 struct shutdown_action
*action
;
67 * The following shutdown action types are supported:
69 #define SHUTDOWN_ACTION_IPL_STR "ipl"
70 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
71 #define SHUTDOWN_ACTION_DUMP_STR "dump"
72 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
73 #define SHUTDOWN_ACTION_STOP_STR "stop"
74 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
76 struct shutdown_action
{
78 void (*fn
) (struct shutdown_trigger
*trigger
);
83 static char *ipl_type_str(enum ipl_type type
)
90 case IPL_TYPE_FCP_DUMP
:
91 return IPL_FCP_DUMP_STR
;
94 case IPL_TYPE_UNKNOWN
:
96 return IPL_UNKNOWN_STR
;
106 static char *dump_type_str(enum dump_type type
)
110 return DUMP_NONE_STR
;
120 static int ipl_block_valid
;
121 static struct ipl_parameter_block ipl_block
;
123 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
125 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
126 static struct ipl_parameter_block
*reipl_block_fcp
;
127 static struct ipl_parameter_block
*reipl_block_ccw
;
128 static struct ipl_parameter_block
*reipl_block_nss
;
129 static struct ipl_parameter_block
*reipl_block_actual
;
131 static int dump_capabilities
= DUMP_TYPE_NONE
;
132 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
133 static struct ipl_parameter_block
*dump_block_fcp
;
134 static struct ipl_parameter_block
*dump_block_ccw
;
136 static struct sclp_ipl_info sclp_ipl_info
;
138 static inline int __diag308(unsigned long subcode
, void *addr
)
140 register unsigned long _addr
asm("0") = (unsigned long) addr
;
141 register unsigned long _rc
asm("1") = 0;
144 " diag %0,%2,0x308\n"
147 : "+d" (_addr
), "+d" (_rc
)
148 : "d" (subcode
) : "cc", "memory");
152 int diag308(unsigned long subcode
, void *addr
)
154 diag_stat_inc(DIAG_STAT_X308
);
155 return __diag308(subcode
, addr
);
157 EXPORT_SYMBOL_GPL(diag308
);
161 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
162 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
163 struct kobj_attribute *attr, \
166 return snprintf(page, PAGE_SIZE, _format, ##args); \
169 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
170 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
171 struct kobj_attribute *attr, \
172 const char *buf, size_t len) \
174 unsigned long long ssid, devno; \
176 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
179 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
182 _ipl_blk.ssid = ssid; \
183 _ipl_blk.devno = devno; \
187 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
188 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
189 _ipl_blk.ssid, _ipl_blk.devno); \
190 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
191 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
192 __ATTR(_name, (S_IRUGO | S_IWUSR), \
193 sys_##_prefix##_##_name##_show, \
194 sys_##_prefix##_##_name##_store) \
196 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
197 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
198 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
199 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
201 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
202 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (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 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
220 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
221 struct kobj_attribute *attr, \
222 const char *buf, size_t len) \
224 strncpy(_value, buf, sizeof(_value) - 1); \
228 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
229 __ATTR(_name,(S_IRUGO | S_IWUSR), \
230 sys_##_prefix##_##_name##_show, \
231 sys_##_prefix##_##_name##_store)
237 static __init
enum ipl_type
get_ipl_type(void)
239 if (!ipl_block_valid
)
240 return IPL_TYPE_UNKNOWN
;
242 switch (ipl_block
.hdr
.pbt
) {
243 case DIAG308_IPL_TYPE_CCW
:
245 case DIAG308_IPL_TYPE_FCP
:
246 if (ipl_block
.ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
247 return IPL_TYPE_FCP_DUMP
;
251 return IPL_TYPE_UNKNOWN
;
254 struct ipl_info ipl_info
;
255 EXPORT_SYMBOL_GPL(ipl_info
);
257 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
260 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
263 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
265 /* VM IPL PARM routines */
266 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
267 const struct ipl_parameter_block
*ipb
)
271 char has_lowercase
= 0;
274 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
275 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
277 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
278 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
279 /* If at least one character is lowercase, we assume mixed
280 * case; otherwise we convert everything to lowercase.
282 for (i
= 0; i
< len
; i
++)
283 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
284 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
285 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
290 EBC_TOLOWER(dest
, len
);
298 size_t append_ipl_vmparm(char *dest
, size_t size
)
303 if (ipl_block_valid
&& ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
)
304 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
310 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
311 struct kobj_attribute
*attr
, char *page
)
313 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
315 append_ipl_vmparm(parm
, sizeof(parm
));
316 return sprintf(page
, "%s\n", parm
);
319 static size_t scpdata_length(const char* buf
, size_t count
)
322 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
329 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
330 const struct ipl_parameter_block
*ipb
)
336 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
337 ipb
->ipl_info
.fcp
.scp_data_len
));
342 for (i
= 0; i
< count
; i
++) {
343 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
347 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
352 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
354 for (i
= 0; i
< count
; i
++)
355 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
361 size_t append_ipl_scpdata(char *dest
, size_t len
)
366 if (ipl_block_valid
&& ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
367 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
374 static struct kobj_attribute sys_ipl_vm_parm_attr
=
375 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
377 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
378 struct kobj_attribute
*attr
, char *page
)
380 switch (ipl_info
.type
) {
382 return sprintf(page
, "0.%x.%04x\n", ipl_block
.ipl_info
.ccw
.ssid
,
383 ipl_block
.ipl_info
.ccw
.devno
);
385 case IPL_TYPE_FCP_DUMP
:
386 return sprintf(page
, "0.0.%04x\n",
387 ipl_block
.ipl_info
.fcp
.devno
);
393 static struct kobj_attribute sys_ipl_device_attr
=
394 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
396 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
397 struct bin_attribute
*attr
, char *buf
,
398 loff_t off
, size_t count
)
400 return memory_read_from_buffer(buf
, count
, &off
, &ipl_block
,
403 static struct bin_attribute ipl_parameter_attr
=
404 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
407 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
408 struct bin_attribute
*attr
, char *buf
,
409 loff_t off
, size_t count
)
411 unsigned int size
= ipl_block
.ipl_info
.fcp
.scp_data_len
;
412 void *scp_data
= &ipl_block
.ipl_info
.fcp
.scp_data
;
414 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
416 static struct bin_attribute ipl_scp_data_attr
=
417 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
419 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
425 /* FCP ipl device attributes */
427 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n",
428 (unsigned long long)ipl_block
.ipl_info
.fcp
.wwpn
);
429 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n",
430 (unsigned long long)ipl_block
.ipl_info
.fcp
.lun
);
431 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n",
432 (unsigned long long)ipl_block
.ipl_info
.fcp
.bootprog
);
433 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n",
434 (unsigned long long)ipl_block
.ipl_info
.fcp
.br_lba
);
436 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
437 struct kobj_attribute
*attr
, char *page
)
439 char loadparm
[LOADPARM_LEN
+ 1] = {};
441 if (!sclp_ipl_info
.is_valid
)
442 return sprintf(page
, "#unknown#\n");
443 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
444 EBCASC(loadparm
, LOADPARM_LEN
);
446 return sprintf(page
, "%s\n", loadparm
);
449 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
450 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
452 static struct attribute
*ipl_fcp_attrs
[] = {
453 &sys_ipl_type_attr
.attr
,
454 &sys_ipl_device_attr
.attr
,
455 &sys_ipl_fcp_wwpn_attr
.attr
,
456 &sys_ipl_fcp_lun_attr
.attr
,
457 &sys_ipl_fcp_bootprog_attr
.attr
,
458 &sys_ipl_fcp_br_lba_attr
.attr
,
459 &sys_ipl_ccw_loadparm_attr
.attr
,
463 static struct attribute_group ipl_fcp_attr_group
= {
464 .attrs
= ipl_fcp_attrs
,
465 .bin_attrs
= ipl_fcp_bin_attrs
,
468 /* CCW ipl device attributes */
470 static struct attribute
*ipl_ccw_attrs_vm
[] = {
471 &sys_ipl_type_attr
.attr
,
472 &sys_ipl_device_attr
.attr
,
473 &sys_ipl_ccw_loadparm_attr
.attr
,
474 &sys_ipl_vm_parm_attr
.attr
,
478 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
479 &sys_ipl_type_attr
.attr
,
480 &sys_ipl_device_attr
.attr
,
481 &sys_ipl_ccw_loadparm_attr
.attr
,
485 static struct attribute_group ipl_ccw_attr_group_vm
= {
486 .attrs
= ipl_ccw_attrs_vm
,
489 static struct attribute_group ipl_ccw_attr_group_lpar
= {
490 .attrs
= ipl_ccw_attrs_lpar
493 /* UNKNOWN ipl device attributes */
495 static struct attribute
*ipl_unknown_attrs
[] = {
496 &sys_ipl_type_attr
.attr
,
500 static struct attribute_group ipl_unknown_attr_group
= {
501 .attrs
= ipl_unknown_attrs
,
504 static struct kset
*ipl_kset
;
506 static void __ipl_run(void *unused
)
509 diag308(DIAG308_LOAD_CLEAR
, NULL
);
512 static void ipl_run(struct shutdown_trigger
*trigger
)
514 smp_call_ipl_cpu(__ipl_run
, NULL
);
517 static int __init
ipl_init(void)
521 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
526 switch (ipl_info
.type
) {
529 rc
= sysfs_create_group(&ipl_kset
->kobj
,
530 &ipl_ccw_attr_group_vm
);
532 rc
= sysfs_create_group(&ipl_kset
->kobj
,
533 &ipl_ccw_attr_group_lpar
);
536 case IPL_TYPE_FCP_DUMP
:
537 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
540 rc
= sysfs_create_group(&ipl_kset
->kobj
,
541 &ipl_unknown_attr_group
);
546 panic("ipl_init failed: rc = %i\n", rc
);
551 static struct shutdown_action __refdata ipl_action
= {
552 .name
= SHUTDOWN_ACTION_IPL_STR
,
558 * reipl shutdown action: Reboot Linux on shutdown.
561 /* VM IPL PARM attributes */
562 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
565 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
567 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
568 return sprintf(page
, "%s\n", vmparm
);
571 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
573 const char *buf
, size_t len
)
577 /* ignore trailing newline */
579 if ((len
> 0) && (buf
[len
- 1] == '\n'))
582 if (ip_len
> vmparm_max
)
585 /* parm is used to store kernel options, check for common chars */
586 for (i
= 0; i
< ip_len
; i
++)
587 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
590 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
591 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
593 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
594 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
595 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
597 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
604 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
605 struct kobj_attribute
*attr
, char *page
)
607 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
610 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
611 struct kobj_attribute
*attr
,
612 const char *buf
, size_t len
)
614 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
618 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
619 struct kobj_attribute
*attr
, char *page
)
621 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
624 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
625 struct kobj_attribute
*attr
,
626 const char *buf
, size_t len
)
628 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
631 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
632 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
633 reipl_nss_vmparm_store
);
634 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
635 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
636 reipl_ccw_vmparm_store
);
638 /* FCP reipl device attributes */
640 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
641 struct bin_attribute
*attr
,
642 char *buf
, loff_t off
, size_t count
)
644 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
645 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
647 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
650 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
651 struct bin_attribute
*attr
,
652 char *buf
, loff_t off
, size_t count
)
654 size_t scpdata_len
= count
;
661 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
, count
);
662 if (scpdata_len
% 8) {
663 padding
= 8 - (scpdata_len
% 8);
664 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
666 scpdata_len
+= padding
;
669 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
670 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
671 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
675 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
676 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
677 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
679 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
680 &sys_reipl_fcp_scp_data_attr
,
684 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
685 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
686 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
687 reipl_block_fcp
->ipl_info
.fcp
.lun
);
688 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
689 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
690 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
691 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
692 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
693 reipl_block_fcp
->ipl_info
.fcp
.devno
);
695 static void reipl_get_ascii_loadparm(char *loadparm
,
696 struct ipl_parameter_block
*ibp
)
698 memcpy(loadparm
, ibp
->hdr
.loadparm
, LOADPARM_LEN
);
699 EBCASC(loadparm
, LOADPARM_LEN
);
700 loadparm
[LOADPARM_LEN
] = 0;
704 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
707 char buf
[LOADPARM_LEN
+ 1];
709 reipl_get_ascii_loadparm(buf
, ipb
);
710 return sprintf(page
, "%s\n", buf
);
713 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
714 const char *buf
, size_t len
)
718 /* ignore trailing newline */
720 if ((len
> 0) && (buf
[len
- 1] == '\n'))
722 /* loadparm can have max 8 characters and must not start with a blank */
723 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
725 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
726 for (i
= 0; i
< lp_len
; i
++) {
727 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
732 /* initialize loadparm with blanks */
733 memset(ipb
->hdr
.loadparm
, ' ', LOADPARM_LEN
);
734 /* copy and convert to ebcdic */
735 memcpy(ipb
->hdr
.loadparm
, buf
, lp_len
);
736 ASCEBC(ipb
->hdr
.loadparm
, LOADPARM_LEN
);
737 ipb
->hdr
.flags
|= DIAG308_FLAGS_LP_VALID
;
742 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
743 struct kobj_attribute
*attr
, char *page
)
745 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
748 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
749 struct kobj_attribute
*attr
,
750 const char *buf
, size_t len
)
752 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
755 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
756 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
757 reipl_fcp_loadparm_store
);
759 static struct attribute
*reipl_fcp_attrs
[] = {
760 &sys_reipl_fcp_device_attr
.attr
,
761 &sys_reipl_fcp_wwpn_attr
.attr
,
762 &sys_reipl_fcp_lun_attr
.attr
,
763 &sys_reipl_fcp_bootprog_attr
.attr
,
764 &sys_reipl_fcp_br_lba_attr
.attr
,
765 &sys_reipl_fcp_loadparm_attr
.attr
,
769 static struct attribute_group reipl_fcp_attr_group
= {
770 .attrs
= reipl_fcp_attrs
,
771 .bin_attrs
= reipl_fcp_bin_attrs
,
774 /* CCW reipl device attributes */
775 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ipl_info
.ccw
);
778 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
779 struct kobj_attribute
*attr
, char *page
)
781 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
784 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
785 struct kobj_attribute
*attr
,
786 const char *buf
, size_t len
)
788 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
792 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
793 struct kobj_attribute
*attr
, char *page
)
795 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
798 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
799 struct kobj_attribute
*attr
,
800 const char *buf
, size_t len
)
802 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
805 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
806 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
807 reipl_ccw_loadparm_store
);
809 static struct attribute
*reipl_ccw_attrs_vm
[] = {
810 &sys_reipl_ccw_device_attr
.attr
,
811 &sys_reipl_ccw_loadparm_attr
.attr
,
812 &sys_reipl_ccw_vmparm_attr
.attr
,
816 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
817 &sys_reipl_ccw_device_attr
.attr
,
818 &sys_reipl_ccw_loadparm_attr
.attr
,
822 static struct attribute_group reipl_ccw_attr_group_vm
= {
824 .attrs
= reipl_ccw_attrs_vm
,
827 static struct attribute_group reipl_ccw_attr_group_lpar
= {
829 .attrs
= reipl_ccw_attrs_lpar
,
833 /* NSS reipl device attributes */
834 static void reipl_get_ascii_nss_name(char *dst
,
835 struct ipl_parameter_block
*ipb
)
837 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
838 EBCASC(dst
, NSS_NAME_SIZE
);
839 dst
[NSS_NAME_SIZE
] = 0;
842 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
843 struct kobj_attribute
*attr
, char *page
)
845 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
847 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
848 return sprintf(page
, "%s\n", nss_name
);
851 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
852 struct kobj_attribute
*attr
,
853 const char *buf
, size_t len
)
857 /* ignore trailing newline */
859 if ((len
> 0) && (buf
[len
- 1] == '\n'))
862 if (nss_len
> NSS_NAME_SIZE
)
865 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
867 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
868 DIAG308_VM_FLAGS_NSS_VALID
;
869 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
870 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
871 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
873 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
874 ~DIAG308_VM_FLAGS_NSS_VALID
;
880 static struct kobj_attribute sys_reipl_nss_name_attr
=
881 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
882 reipl_nss_name_store
);
884 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
885 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
886 reipl_nss_loadparm_store
);
888 static struct attribute
*reipl_nss_attrs
[] = {
889 &sys_reipl_nss_name_attr
.attr
,
890 &sys_reipl_nss_loadparm_attr
.attr
,
891 &sys_reipl_nss_vmparm_attr
.attr
,
895 static struct attribute_group reipl_nss_attr_group
= {
897 .attrs
= reipl_nss_attrs
,
900 void set_os_info_reipl_block(void)
902 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
903 reipl_block_actual
->hdr
.len
);
908 static int reipl_set_type(enum ipl_type type
)
910 if (!(reipl_capabilities
& type
))
915 reipl_block_actual
= reipl_block_ccw
;
918 reipl_block_actual
= reipl_block_fcp
;
921 reipl_block_actual
= reipl_block_nss
;
930 static ssize_t
reipl_type_show(struct kobject
*kobj
,
931 struct kobj_attribute
*attr
, char *page
)
933 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
936 static ssize_t
reipl_type_store(struct kobject
*kobj
,
937 struct kobj_attribute
*attr
,
938 const char *buf
, size_t len
)
942 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
943 rc
= reipl_set_type(IPL_TYPE_CCW
);
944 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
945 rc
= reipl_set_type(IPL_TYPE_FCP
);
946 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
947 rc
= reipl_set_type(IPL_TYPE_NSS
);
948 return (rc
!= 0) ? rc
: len
;
951 static struct kobj_attribute reipl_type_attr
=
952 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
954 static struct kset
*reipl_kset
;
955 static struct kset
*reipl_fcp_kset
;
957 static void __reipl_run(void *unused
)
959 switch (reipl_type
) {
961 diag308(DIAG308_SET
, reipl_block_ccw
);
962 diag308(DIAG308_LOAD_CLEAR
, NULL
);
965 diag308(DIAG308_SET
, reipl_block_fcp
);
966 diag308(DIAG308_LOAD_CLEAR
, NULL
);
969 diag308(DIAG308_SET
, reipl_block_nss
);
970 diag308(DIAG308_LOAD_CLEAR
, NULL
);
972 case IPL_TYPE_UNKNOWN
:
973 diag308(DIAG308_LOAD_CLEAR
, NULL
);
975 case IPL_TYPE_FCP_DUMP
:
978 disabled_wait((unsigned long) __builtin_return_address(0));
981 static void reipl_run(struct shutdown_trigger
*trigger
)
983 smp_call_ipl_cpu(__reipl_run
, NULL
);
986 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
988 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
989 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
990 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
991 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
994 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
997 /* check if read scp info worked and set loadparm */
998 if (sclp_ipl_info
.is_valid
)
999 memcpy(ipb
->hdr
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1001 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1002 memset(ipb
->hdr
.loadparm
, 0x40, LOADPARM_LEN
);
1003 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1006 if (MACHINE_IS_VM
&& ipl_block_valid
&&
1007 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1009 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1010 ipb
->ipl_info
.ccw
.vm_parm_len
=
1011 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1012 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1013 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1017 static int __init
reipl_nss_init(void)
1024 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1025 if (!reipl_block_nss
)
1028 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1032 reipl_block_ccw_init(reipl_block_nss
);
1033 reipl_capabilities
|= IPL_TYPE_NSS
;
1037 static int __init
reipl_ccw_init(void)
1041 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1042 if (!reipl_block_ccw
)
1045 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1046 MACHINE_IS_VM
? &reipl_ccw_attr_group_vm
1047 : &reipl_ccw_attr_group_lpar
);
1051 reipl_block_ccw_init(reipl_block_ccw
);
1052 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1053 reipl_block_ccw
->ipl_info
.ccw
.ssid
= ipl_block
.ipl_info
.ccw
.ssid
;
1054 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_block
.ipl_info
.ccw
.devno
;
1055 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1058 reipl_capabilities
|= IPL_TYPE_CCW
;
1062 static int __init
reipl_fcp_init(void)
1066 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1067 if (!reipl_block_fcp
)
1070 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1071 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1073 if (!reipl_fcp_kset
) {
1074 free_page((unsigned long) reipl_block_fcp
);
1078 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1080 kset_unregister(reipl_fcp_kset
);
1081 free_page((unsigned long) reipl_block_fcp
);
1085 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1086 memcpy(reipl_block_fcp
, &ipl_block
, sizeof(ipl_block
));
1088 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1089 * is invalid in the SCSI IPL parameter block, so take it
1090 * always from sclp_ipl_info.
1092 memcpy(reipl_block_fcp
->hdr
.loadparm
, sclp_ipl_info
.loadparm
,
1095 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1096 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1097 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1098 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1099 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1101 reipl_capabilities
|= IPL_TYPE_FCP
;
1105 static int __init
reipl_type_init(void)
1107 enum ipl_type reipl_type
= ipl_info
.type
;
1108 struct ipl_parameter_block
*reipl_block
;
1111 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1115 * If we have an OS info reipl block, this will be used
1117 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1118 memcpy(reipl_block_fcp
, reipl_block
, size
);
1119 reipl_type
= IPL_TYPE_FCP
;
1120 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1121 memcpy(reipl_block_ccw
, reipl_block
, size
);
1122 reipl_type
= IPL_TYPE_CCW
;
1125 return reipl_set_type(reipl_type
);
1128 static int __init
reipl_init(void)
1132 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1135 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1137 kset_unregister(reipl_kset
);
1140 rc
= reipl_ccw_init();
1143 rc
= reipl_fcp_init();
1146 rc
= reipl_nss_init();
1149 return reipl_type_init();
1152 static struct shutdown_action __refdata reipl_action
= {
1153 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1159 * dump shutdown action: Dump Linux on shutdown.
1162 /* FCP dump device attributes */
1164 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1165 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1166 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1167 dump_block_fcp
->ipl_info
.fcp
.lun
);
1168 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1169 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1170 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1171 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1172 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1173 dump_block_fcp
->ipl_info
.fcp
.devno
);
1175 static struct attribute
*dump_fcp_attrs
[] = {
1176 &sys_dump_fcp_device_attr
.attr
,
1177 &sys_dump_fcp_wwpn_attr
.attr
,
1178 &sys_dump_fcp_lun_attr
.attr
,
1179 &sys_dump_fcp_bootprog_attr
.attr
,
1180 &sys_dump_fcp_br_lba_attr
.attr
,
1184 static struct attribute_group dump_fcp_attr_group
= {
1185 .name
= IPL_FCP_STR
,
1186 .attrs
= dump_fcp_attrs
,
1189 /* CCW dump device attributes */
1190 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ipl_info
.ccw
);
1192 static struct attribute
*dump_ccw_attrs
[] = {
1193 &sys_dump_ccw_device_attr
.attr
,
1197 static struct attribute_group dump_ccw_attr_group
= {
1198 .name
= IPL_CCW_STR
,
1199 .attrs
= dump_ccw_attrs
,
1204 static int dump_set_type(enum dump_type type
)
1206 if (!(dump_capabilities
& type
))
1212 static ssize_t
dump_type_show(struct kobject
*kobj
,
1213 struct kobj_attribute
*attr
, char *page
)
1215 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1218 static ssize_t
dump_type_store(struct kobject
*kobj
,
1219 struct kobj_attribute
*attr
,
1220 const char *buf
, size_t len
)
1224 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1225 rc
= dump_set_type(DUMP_TYPE_NONE
);
1226 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1227 rc
= dump_set_type(DUMP_TYPE_CCW
);
1228 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1229 rc
= dump_set_type(DUMP_TYPE_FCP
);
1230 return (rc
!= 0) ? rc
: len
;
1233 static struct kobj_attribute dump_type_attr
=
1234 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1236 static struct kset
*dump_kset
;
1238 static void diag308_dump(void *dump_block
)
1240 diag308(DIAG308_SET
, dump_block
);
1242 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1244 udelay_simple(USEC_PER_SEC
);
1248 static void __dump_run(void *unused
)
1250 switch (dump_type
) {
1252 diag308_dump(dump_block_ccw
);
1255 diag308_dump(dump_block_fcp
);
1262 static void dump_run(struct shutdown_trigger
*trigger
)
1264 if (dump_type
== DUMP_TYPE_NONE
)
1267 smp_call_ipl_cpu(__dump_run
, NULL
);
1270 static int __init
dump_ccw_init(void)
1274 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1275 if (!dump_block_ccw
)
1277 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1279 free_page((unsigned long)dump_block_ccw
);
1282 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1283 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1284 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1285 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1286 dump_capabilities
|= DUMP_TYPE_CCW
;
1290 static int __init
dump_fcp_init(void)
1294 if (!sclp_ipl_info
.has_dump
)
1295 return 0; /* LDIPL DUMP is not installed */
1296 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1297 if (!dump_block_fcp
)
1299 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1301 free_page((unsigned long)dump_block_fcp
);
1304 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1305 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1306 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1307 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1308 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1309 dump_capabilities
|= DUMP_TYPE_FCP
;
1313 static int __init
dump_init(void)
1317 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1320 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1322 kset_unregister(dump_kset
);
1325 rc
= dump_ccw_init();
1328 rc
= dump_fcp_init();
1331 dump_set_type(DUMP_TYPE_NONE
);
1335 static struct shutdown_action __refdata dump_action
= {
1336 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1341 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1343 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1346 csum
= (__force
unsigned int)
1347 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1348 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1349 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1353 static struct shutdown_action __refdata dump_reipl_action
= {
1354 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1355 .fn
= dump_reipl_run
,
1359 * vmcmd shutdown action: Trigger vm command on shutdown.
1362 static char vmcmd_on_reboot
[128];
1363 static char vmcmd_on_panic
[128];
1364 static char vmcmd_on_halt
[128];
1365 static char vmcmd_on_poff
[128];
1366 static char vmcmd_on_restart
[128];
1368 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1369 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1370 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1371 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1372 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1374 static struct attribute
*vmcmd_attrs
[] = {
1375 &sys_vmcmd_on_reboot_attr
.attr
,
1376 &sys_vmcmd_on_panic_attr
.attr
,
1377 &sys_vmcmd_on_halt_attr
.attr
,
1378 &sys_vmcmd_on_poff_attr
.attr
,
1379 &sys_vmcmd_on_restart_attr
.attr
,
1383 static struct attribute_group vmcmd_attr_group
= {
1384 .attrs
= vmcmd_attrs
,
1387 static struct kset
*vmcmd_kset
;
1389 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1393 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1394 cmd
= vmcmd_on_reboot
;
1395 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1396 cmd
= vmcmd_on_panic
;
1397 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1398 cmd
= vmcmd_on_halt
;
1399 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1400 cmd
= vmcmd_on_poff
;
1401 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1402 cmd
= vmcmd_on_restart
;
1406 if (strlen(cmd
) == 0)
1408 __cpcmd(cmd
, NULL
, 0, NULL
);
1411 static int vmcmd_init(void)
1415 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1418 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1421 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1422 vmcmd_run
, vmcmd_init
};
1425 * stop shutdown action: Stop Linux on shutdown.
1428 static void stop_run(struct shutdown_trigger
*trigger
)
1430 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1431 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1432 disabled_wait((unsigned long) __builtin_return_address(0));
1436 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1441 static struct shutdown_action
*shutdown_actions_list
[] = {
1442 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1443 &vmcmd_action
, &stop_action
};
1444 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1450 static struct kset
*shutdown_actions_kset
;
1452 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1457 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1458 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1459 if (shutdown_actions_list
[i
]->init_rc
) {
1460 return shutdown_actions_list
[i
]->init_rc
;
1462 trigger
->action
= shutdown_actions_list
[i
];
1472 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1475 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1476 struct kobj_attribute
*attr
, char *page
)
1478 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1481 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1482 struct kobj_attribute
*attr
,
1483 const char *buf
, size_t len
)
1485 return set_trigger(buf
, &on_reboot_trigger
, len
);
1487 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1489 static void do_machine_restart(char *__unused
)
1492 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1495 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1499 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1501 static ssize_t
on_panic_show(struct kobject
*kobj
,
1502 struct kobj_attribute
*attr
, char *page
)
1504 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1507 static ssize_t
on_panic_store(struct kobject
*kobj
,
1508 struct kobj_attribute
*attr
,
1509 const char *buf
, size_t len
)
1511 return set_trigger(buf
, &on_panic_trigger
, len
);
1513 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1515 static void do_panic(void)
1518 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1519 stop_run(&on_panic_trigger
);
1524 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1527 static ssize_t
on_restart_show(struct kobject
*kobj
,
1528 struct kobj_attribute
*attr
, char *page
)
1530 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1533 static ssize_t
on_restart_store(struct kobject
*kobj
,
1534 struct kobj_attribute
*attr
,
1535 const char *buf
, size_t len
)
1537 return set_trigger(buf
, &on_restart_trigger
, len
);
1539 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1541 static void __do_restart(void *ignore
)
1543 __arch_local_irq_stosm(0x04); /* enable DAT */
1545 #ifdef CONFIG_CRASH_DUMP
1548 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1549 stop_run(&on_restart_trigger
);
1552 void do_restart(void)
1557 smp_call_online_cpu(__do_restart
, NULL
);
1562 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1564 static ssize_t
on_halt_show(struct kobject
*kobj
,
1565 struct kobj_attribute
*attr
, char *page
)
1567 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1570 static ssize_t
on_halt_store(struct kobject
*kobj
,
1571 struct kobj_attribute
*attr
,
1572 const char *buf
, size_t len
)
1574 return set_trigger(buf
, &on_halt_trigger
, len
);
1576 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1578 static void do_machine_halt(void)
1581 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1582 stop_run(&on_halt_trigger
);
1584 void (*_machine_halt
)(void) = do_machine_halt
;
1588 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1590 static ssize_t
on_poff_show(struct kobject
*kobj
,
1591 struct kobj_attribute
*attr
, char *page
)
1593 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1596 static ssize_t
on_poff_store(struct kobject
*kobj
,
1597 struct kobj_attribute
*attr
,
1598 const char *buf
, size_t len
)
1600 return set_trigger(buf
, &on_poff_trigger
, len
);
1602 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1604 static void do_machine_power_off(void)
1607 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1608 stop_run(&on_poff_trigger
);
1610 void (*_machine_power_off
)(void) = do_machine_power_off
;
1612 static struct attribute
*shutdown_action_attrs
[] = {
1613 &on_restart_attr
.attr
,
1614 &on_reboot_attr
.attr
,
1615 &on_panic_attr
.attr
,
1621 static struct attribute_group shutdown_action_attr_group
= {
1622 .attrs
= shutdown_action_attrs
,
1625 static void __init
shutdown_triggers_init(void)
1627 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1629 if (!shutdown_actions_kset
)
1631 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1632 &shutdown_action_attr_group
))
1636 panic("shutdown_triggers_init failed\n");
1639 static void __init
shutdown_actions_init(void)
1643 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1644 if (!shutdown_actions_list
[i
]->init
)
1646 shutdown_actions_list
[i
]->init_rc
=
1647 shutdown_actions_list
[i
]->init();
1651 static int __init
s390_ipl_init(void)
1653 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1655 sclp_early_get_ipl_info(&sclp_ipl_info
);
1657 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1658 * returned by read SCP info is invalid (contains EBCDIC blanks)
1659 * when the system has been booted via diag308. In that case we use
1660 * the value from diag308, if available.
1662 * There are also systems where diag308 store does not work in
1663 * case the system is booted from HMC. Fortunately in this case
1664 * READ SCP info provides the correct value.
1666 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 && ipl_block_valid
)
1667 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.hdr
.loadparm
, LOADPARM_LEN
);
1668 shutdown_actions_init();
1669 shutdown_triggers_init();
1673 __initcall(s390_ipl_init
);
1675 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1680 for (sx
= 0; src
[sx
] != 0; sx
++) {
1683 dst
[dx
++] = src
[sx
];
1689 static int __init
vmcmd_on_reboot_setup(char *str
)
1693 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1694 vmcmd_on_reboot
[127] = 0;
1695 on_reboot_trigger
.action
= &vmcmd_action
;
1698 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1700 static int __init
vmcmd_on_panic_setup(char *str
)
1704 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1705 vmcmd_on_panic
[127] = 0;
1706 on_panic_trigger
.action
= &vmcmd_action
;
1709 __setup("vmpanic=", vmcmd_on_panic_setup
);
1711 static int __init
vmcmd_on_halt_setup(char *str
)
1715 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1716 vmcmd_on_halt
[127] = 0;
1717 on_halt_trigger
.action
= &vmcmd_action
;
1720 __setup("vmhalt=", vmcmd_on_halt_setup
);
1722 static int __init
vmcmd_on_poff_setup(char *str
)
1726 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1727 vmcmd_on_poff
[127] = 0;
1728 on_poff_trigger
.action
= &vmcmd_action
;
1731 __setup("vmpoff=", vmcmd_on_poff_setup
);
1733 static int on_panic_notify(struct notifier_block
*self
,
1734 unsigned long event
, void *data
)
1740 static struct notifier_block on_panic_nb
= {
1741 .notifier_call
= on_panic_notify
,
1742 .priority
= INT_MIN
,
1745 void __init
setup_ipl(void)
1747 BUILD_BUG_ON(sizeof(struct ipl_parameter_block
) != PAGE_SIZE
);
1749 ipl_info
.type
= get_ipl_type();
1750 switch (ipl_info
.type
) {
1752 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_block
.ipl_info
.ccw
.ssid
;
1753 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_block
.ipl_info
.ccw
.devno
;
1756 case IPL_TYPE_FCP_DUMP
:
1757 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1758 ipl_info
.data
.fcp
.dev_id
.devno
= ipl_block
.ipl_info
.fcp
.devno
;
1759 ipl_info
.data
.fcp
.wwpn
= ipl_block
.ipl_info
.fcp
.wwpn
;
1760 ipl_info
.data
.fcp
.lun
= ipl_block
.ipl_info
.fcp
.lun
;
1763 case IPL_TYPE_UNKNOWN
:
1764 /* We have no info to copy */
1767 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1770 void __init
ipl_store_parameters(void)
1774 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1775 if (rc
== DIAG308_RC_OK
&& ipl_block
.hdr
.version
<= IPL_MAX_SUPPORTED_VERSION
)
1776 ipl_block_valid
= 1;
1779 void s390_reset_system(void)
1781 /* Disable prefixing */
1784 /* Disable lowcore protection */
1785 __ctl_clear_bit(0, 28);