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>
32 #include <asm/sections.h>
33 #include <asm/boot_data.h>
36 #define IPL_PARM_BLOCK_VERSION 0
38 #define IPL_UNKNOWN_STR "unknown"
39 #define IPL_CCW_STR "ccw"
40 #define IPL_FCP_STR "fcp"
41 #define IPL_FCP_DUMP_STR "fcp_dump"
42 #define IPL_NSS_STR "nss"
44 #define DUMP_CCW_STR "ccw"
45 #define DUMP_FCP_STR "fcp"
46 #define DUMP_NONE_STR "none"
49 * Four shutdown trigger types are supported:
56 #define ON_PANIC_STR "on_panic"
57 #define ON_HALT_STR "on_halt"
58 #define ON_POFF_STR "on_poff"
59 #define ON_REIPL_STR "on_reboot"
60 #define ON_RESTART_STR "on_restart"
62 struct shutdown_action
;
63 struct shutdown_trigger
{
65 struct shutdown_action
*action
;
69 * The following shutdown action types are supported:
71 #define SHUTDOWN_ACTION_IPL_STR "ipl"
72 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
73 #define SHUTDOWN_ACTION_DUMP_STR "dump"
74 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
75 #define SHUTDOWN_ACTION_STOP_STR "stop"
76 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
78 struct shutdown_action
{
80 void (*fn
) (struct shutdown_trigger
*trigger
);
85 static char *ipl_type_str(enum ipl_type type
)
92 case IPL_TYPE_FCP_DUMP
:
93 return IPL_FCP_DUMP_STR
;
96 case IPL_TYPE_UNKNOWN
:
98 return IPL_UNKNOWN_STR
;
108 static char *dump_type_str(enum dump_type type
)
112 return DUMP_NONE_STR
;
122 int __bootdata_preserved(ipl_block_valid
);
123 struct ipl_parameter_block
__bootdata_preserved(ipl_block
);
124 int __bootdata_preserved(ipl_secure_flag
);
126 unsigned long __bootdata_preserved(ipl_cert_list_addr
);
127 unsigned long __bootdata_preserved(ipl_cert_list_size
);
129 unsigned long __bootdata(early_ipl_comp_list_addr
);
130 unsigned long __bootdata(early_ipl_comp_list_size
);
132 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
134 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
135 static struct ipl_parameter_block
*reipl_block_fcp
;
136 static struct ipl_parameter_block
*reipl_block_ccw
;
137 static struct ipl_parameter_block
*reipl_block_nss
;
138 static struct ipl_parameter_block
*reipl_block_actual
;
140 static int dump_capabilities
= DUMP_TYPE_NONE
;
141 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
142 static struct ipl_parameter_block
*dump_block_fcp
;
143 static struct ipl_parameter_block
*dump_block_ccw
;
145 static struct sclp_ipl_info sclp_ipl_info
;
147 static inline int __diag308(unsigned long subcode
, void *addr
)
149 register unsigned long _addr
asm("0") = (unsigned long) addr
;
150 register unsigned long _rc
asm("1") = 0;
153 " diag %0,%2,0x308\n"
156 : "+d" (_addr
), "+d" (_rc
)
157 : "d" (subcode
) : "cc", "memory");
161 int diag308(unsigned long subcode
, void *addr
)
163 if (IS_ENABLED(CONFIG_KASAN
))
164 __arch_local_irq_stosm(0x04); /* enable DAT */
165 diag_stat_inc(DIAG_STAT_X308
);
166 return __diag308(subcode
, addr
);
168 EXPORT_SYMBOL_GPL(diag308
);
172 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
173 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
174 struct kobj_attribute *attr, \
177 return snprintf(page, PAGE_SIZE, _format, ##args); \
180 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
181 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
182 struct kobj_attribute *attr, \
183 const char *buf, size_t len) \
185 unsigned long long ssid, devno; \
187 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
190 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
193 _ipl_blk.ssid = ssid; \
194 _ipl_blk.devno = devno; \
198 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
199 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
200 _ipl_blk.ssid, _ipl_blk.devno); \
201 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
202 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
203 __ATTR(_name, (S_IRUGO | S_IWUSR), \
204 sys_##_prefix##_##_name##_show, \
205 sys_##_prefix##_##_name##_store) \
207 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
208 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
209 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
210 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
212 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
213 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
214 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
215 struct kobj_attribute *attr, \
216 const char *buf, size_t len) \
218 unsigned long long value; \
219 if (sscanf(buf, _fmt_in, &value) != 1) \
224 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
225 __ATTR(_name,(S_IRUGO | S_IWUSR), \
226 sys_##_prefix##_##_name##_show, \
227 sys_##_prefix##_##_name##_store)
229 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
230 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
231 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
232 struct kobj_attribute *attr, \
233 const char *buf, size_t len) \
235 strncpy(_value, buf, sizeof(_value) - 1); \
239 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
240 __ATTR(_name,(S_IRUGO | S_IWUSR), \
241 sys_##_prefix##_##_name##_show, \
242 sys_##_prefix##_##_name##_store)
248 static __init
enum ipl_type
get_ipl_type(void)
250 if (!ipl_block_valid
)
251 return IPL_TYPE_UNKNOWN
;
253 switch (ipl_block
.pb0_hdr
.pbt
) {
257 if (ipl_block
.fcp
.opt
== IPL_PB0_FCP_OPT_DUMP
)
258 return IPL_TYPE_FCP_DUMP
;
262 return IPL_TYPE_UNKNOWN
;
265 struct ipl_info ipl_info
;
266 EXPORT_SYMBOL_GPL(ipl_info
);
268 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
271 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
274 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
276 static ssize_t
ipl_secure_show(struct kobject
*kobj
,
277 struct kobj_attribute
*attr
, char *page
)
279 return sprintf(page
, "%i\n", !!ipl_secure_flag
);
282 static struct kobj_attribute sys_ipl_secure_attr
=
283 __ATTR(secure
, 0444, ipl_secure_show
, NULL
);
285 static ssize_t
ipl_has_secure_show(struct kobject
*kobj
,
286 struct kobj_attribute
*attr
, char *page
)
288 return sprintf(page
, "%i\n", !!sclp
.has_sipl
);
291 static struct kobj_attribute sys_ipl_has_secure_attr
=
292 __ATTR(has_secure
, 0444, ipl_has_secure_show
, NULL
);
294 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
295 struct kobj_attribute
*attr
, char *page
)
297 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
299 if (ipl_block_valid
&& (ipl_block
.pb0_hdr
.pbt
== IPL_PBT_CCW
))
300 ipl_block_get_ascii_vmparm(parm
, sizeof(parm
), &ipl_block
);
301 return sprintf(page
, "%s\n", parm
);
304 static struct kobj_attribute sys_ipl_vm_parm_attr
=
305 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
307 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
308 struct kobj_attribute
*attr
, char *page
)
310 switch (ipl_info
.type
) {
312 return sprintf(page
, "0.%x.%04x\n", ipl_block
.ccw
.ssid
,
313 ipl_block
.ccw
.devno
);
315 case IPL_TYPE_FCP_DUMP
:
316 return sprintf(page
, "0.0.%04x\n", ipl_block
.fcp
.devno
);
322 static struct kobj_attribute sys_ipl_device_attr
=
323 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
325 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
326 struct bin_attribute
*attr
, char *buf
,
327 loff_t off
, size_t count
)
329 return memory_read_from_buffer(buf
, count
, &off
, &ipl_block
,
332 static struct bin_attribute ipl_parameter_attr
=
333 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
336 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
337 struct bin_attribute
*attr
, char *buf
,
338 loff_t off
, size_t count
)
340 unsigned int size
= ipl_block
.fcp
.scp_data_len
;
341 void *scp_data
= &ipl_block
.fcp
.scp_data
;
343 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
345 static struct bin_attribute ipl_scp_data_attr
=
346 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
348 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
354 /* FCP ipl device attributes */
356 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n",
357 (unsigned long long)ipl_block
.fcp
.wwpn
);
358 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n",
359 (unsigned long long)ipl_block
.fcp
.lun
);
360 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n",
361 (unsigned long long)ipl_block
.fcp
.bootprog
);
362 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n",
363 (unsigned long long)ipl_block
.fcp
.br_lba
);
365 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
366 struct kobj_attribute
*attr
, char *page
)
368 char loadparm
[LOADPARM_LEN
+ 1] = {};
370 if (!sclp_ipl_info
.is_valid
)
371 return sprintf(page
, "#unknown#\n");
372 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
373 EBCASC(loadparm
, LOADPARM_LEN
);
375 return sprintf(page
, "%s\n", loadparm
);
378 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
379 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
381 static struct attribute
*ipl_fcp_attrs
[] = {
382 &sys_ipl_type_attr
.attr
,
383 &sys_ipl_device_attr
.attr
,
384 &sys_ipl_fcp_wwpn_attr
.attr
,
385 &sys_ipl_fcp_lun_attr
.attr
,
386 &sys_ipl_fcp_bootprog_attr
.attr
,
387 &sys_ipl_fcp_br_lba_attr
.attr
,
388 &sys_ipl_ccw_loadparm_attr
.attr
,
389 &sys_ipl_secure_attr
.attr
,
390 &sys_ipl_has_secure_attr
.attr
,
394 static struct attribute_group ipl_fcp_attr_group
= {
395 .attrs
= ipl_fcp_attrs
,
396 .bin_attrs
= ipl_fcp_bin_attrs
,
399 /* CCW ipl device attributes */
401 static struct attribute
*ipl_ccw_attrs_vm
[] = {
402 &sys_ipl_type_attr
.attr
,
403 &sys_ipl_device_attr
.attr
,
404 &sys_ipl_ccw_loadparm_attr
.attr
,
405 &sys_ipl_vm_parm_attr
.attr
,
406 &sys_ipl_secure_attr
.attr
,
407 &sys_ipl_has_secure_attr
.attr
,
411 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
412 &sys_ipl_type_attr
.attr
,
413 &sys_ipl_device_attr
.attr
,
414 &sys_ipl_ccw_loadparm_attr
.attr
,
415 &sys_ipl_secure_attr
.attr
,
416 &sys_ipl_has_secure_attr
.attr
,
420 static struct attribute_group ipl_ccw_attr_group_vm
= {
421 .attrs
= ipl_ccw_attrs_vm
,
424 static struct attribute_group ipl_ccw_attr_group_lpar
= {
425 .attrs
= ipl_ccw_attrs_lpar
428 /* UNKNOWN ipl device attributes */
430 static struct attribute
*ipl_unknown_attrs
[] = {
431 &sys_ipl_type_attr
.attr
,
435 static struct attribute_group ipl_unknown_attr_group
= {
436 .attrs
= ipl_unknown_attrs
,
439 static struct kset
*ipl_kset
;
441 static void __ipl_run(void *unused
)
444 diag308(DIAG308_LOAD_CLEAR
, NULL
);
447 static void ipl_run(struct shutdown_trigger
*trigger
)
449 smp_call_ipl_cpu(__ipl_run
, NULL
);
452 static int __init
ipl_init(void)
456 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
461 switch (ipl_info
.type
) {
464 rc
= sysfs_create_group(&ipl_kset
->kobj
,
465 &ipl_ccw_attr_group_vm
);
467 rc
= sysfs_create_group(&ipl_kset
->kobj
,
468 &ipl_ccw_attr_group_lpar
);
471 case IPL_TYPE_FCP_DUMP
:
472 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
475 rc
= sysfs_create_group(&ipl_kset
->kobj
,
476 &ipl_unknown_attr_group
);
481 panic("ipl_init failed: rc = %i\n", rc
);
486 static struct shutdown_action __refdata ipl_action
= {
487 .name
= SHUTDOWN_ACTION_IPL_STR
,
493 * reipl shutdown action: Reboot Linux on shutdown.
496 /* VM IPL PARM attributes */
497 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
500 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
502 ipl_block_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
503 return sprintf(page
, "%s\n", vmparm
);
506 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
508 const char *buf
, size_t len
)
512 /* ignore trailing newline */
514 if ((len
> 0) && (buf
[len
- 1] == '\n'))
517 if (ip_len
> vmparm_max
)
520 /* parm is used to store kernel options, check for common chars */
521 for (i
= 0; i
< ip_len
; i
++)
522 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
525 memset(ipb
->ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
526 ipb
->ccw
.vm_parm_len
= ip_len
;
528 ipb
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_VP
;
529 memcpy(ipb
->ccw
.vm_parm
, buf
, ip_len
);
530 ASCEBC(ipb
->ccw
.vm_parm
, ip_len
);
532 ipb
->ccw
.vm_flags
&= ~IPL_PB0_CCW_VM_FLAG_VP
;
539 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
540 struct kobj_attribute
*attr
, char *page
)
542 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
545 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
546 struct kobj_attribute
*attr
,
547 const char *buf
, size_t len
)
549 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
553 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
554 struct kobj_attribute
*attr
, char *page
)
556 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
559 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
560 struct kobj_attribute
*attr
,
561 const char *buf
, size_t len
)
563 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
566 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
567 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
568 reipl_nss_vmparm_store
);
569 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
570 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
571 reipl_ccw_vmparm_store
);
573 /* FCP reipl device attributes */
575 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
576 struct bin_attribute
*attr
,
577 char *buf
, loff_t off
, size_t count
)
579 size_t size
= reipl_block_fcp
->fcp
.scp_data_len
;
580 void *scp_data
= reipl_block_fcp
->fcp
.scp_data
;
582 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
585 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
586 struct bin_attribute
*attr
,
587 char *buf
, loff_t off
, size_t count
)
589 size_t scpdata_len
= count
;
596 memcpy(reipl_block_fcp
->fcp
.scp_data
, buf
, count
);
597 if (scpdata_len
% 8) {
598 padding
= 8 - (scpdata_len
% 8);
599 memset(reipl_block_fcp
->fcp
.scp_data
+ scpdata_len
,
601 scpdata_len
+= padding
;
604 reipl_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
+ scpdata_len
;
605 reipl_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
+ scpdata_len
;
606 reipl_block_fcp
->fcp
.scp_data_len
= scpdata_len
;
610 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
611 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
612 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
614 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
615 &sys_reipl_fcp_scp_data_attr
,
619 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
620 reipl_block_fcp
->fcp
.wwpn
);
621 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
622 reipl_block_fcp
->fcp
.lun
);
623 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
624 reipl_block_fcp
->fcp
.bootprog
);
625 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
626 reipl_block_fcp
->fcp
.br_lba
);
627 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
628 reipl_block_fcp
->fcp
.devno
);
630 static void reipl_get_ascii_loadparm(char *loadparm
,
631 struct ipl_parameter_block
*ibp
)
633 memcpy(loadparm
, ibp
->common
.loadparm
, LOADPARM_LEN
);
634 EBCASC(loadparm
, LOADPARM_LEN
);
635 loadparm
[LOADPARM_LEN
] = 0;
639 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
642 char buf
[LOADPARM_LEN
+ 1];
644 reipl_get_ascii_loadparm(buf
, ipb
);
645 return sprintf(page
, "%s\n", buf
);
648 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
649 const char *buf
, size_t len
)
653 /* ignore trailing newline */
655 if ((len
> 0) && (buf
[len
- 1] == '\n'))
657 /* loadparm can have max 8 characters and must not start with a blank */
658 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
660 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
661 for (i
= 0; i
< lp_len
; i
++) {
662 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
667 /* initialize loadparm with blanks */
668 memset(ipb
->common
.loadparm
, ' ', LOADPARM_LEN
);
669 /* copy and convert to ebcdic */
670 memcpy(ipb
->common
.loadparm
, buf
, lp_len
);
671 ASCEBC(ipb
->common
.loadparm
, LOADPARM_LEN
);
672 ipb
->common
.flags
|= IPL_PB0_FLAG_LOADPARM
;
677 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
678 struct kobj_attribute
*attr
, char *page
)
680 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
683 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
684 struct kobj_attribute
*attr
,
685 const char *buf
, size_t len
)
687 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
690 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
691 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
692 reipl_fcp_loadparm_store
);
694 static struct attribute
*reipl_fcp_attrs
[] = {
695 &sys_reipl_fcp_device_attr
.attr
,
696 &sys_reipl_fcp_wwpn_attr
.attr
,
697 &sys_reipl_fcp_lun_attr
.attr
,
698 &sys_reipl_fcp_bootprog_attr
.attr
,
699 &sys_reipl_fcp_br_lba_attr
.attr
,
700 &sys_reipl_fcp_loadparm_attr
.attr
,
704 static struct attribute_group reipl_fcp_attr_group
= {
705 .attrs
= reipl_fcp_attrs
,
706 .bin_attrs
= reipl_fcp_bin_attrs
,
709 /* CCW reipl device attributes */
710 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ccw
);
713 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
714 struct kobj_attribute
*attr
, char *page
)
716 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
719 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
720 struct kobj_attribute
*attr
,
721 const char *buf
, size_t len
)
723 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
727 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
728 struct kobj_attribute
*attr
, char *page
)
730 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
733 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
734 struct kobj_attribute
*attr
,
735 const char *buf
, size_t len
)
737 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
740 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
741 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
742 reipl_ccw_loadparm_store
);
744 static struct attribute
*reipl_ccw_attrs_vm
[] = {
745 &sys_reipl_ccw_device_attr
.attr
,
746 &sys_reipl_ccw_loadparm_attr
.attr
,
747 &sys_reipl_ccw_vmparm_attr
.attr
,
751 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
752 &sys_reipl_ccw_device_attr
.attr
,
753 &sys_reipl_ccw_loadparm_attr
.attr
,
757 static struct attribute_group reipl_ccw_attr_group_vm
= {
759 .attrs
= reipl_ccw_attrs_vm
,
762 static struct attribute_group reipl_ccw_attr_group_lpar
= {
764 .attrs
= reipl_ccw_attrs_lpar
,
768 /* NSS reipl device attributes */
769 static void reipl_get_ascii_nss_name(char *dst
,
770 struct ipl_parameter_block
*ipb
)
772 memcpy(dst
, ipb
->ccw
.nss_name
, NSS_NAME_SIZE
);
773 EBCASC(dst
, NSS_NAME_SIZE
);
774 dst
[NSS_NAME_SIZE
] = 0;
777 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
778 struct kobj_attribute
*attr
, char *page
)
780 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
782 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
783 return sprintf(page
, "%s\n", nss_name
);
786 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
787 struct kobj_attribute
*attr
,
788 const char *buf
, size_t len
)
792 /* ignore trailing newline */
794 if ((len
> 0) && (buf
[len
- 1] == '\n'))
797 if (nss_len
> NSS_NAME_SIZE
)
800 memset(reipl_block_nss
->ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
802 reipl_block_nss
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_NSS
;
803 memcpy(reipl_block_nss
->ccw
.nss_name
, buf
, nss_len
);
804 ASCEBC(reipl_block_nss
->ccw
.nss_name
, nss_len
);
805 EBC_TOUPPER(reipl_block_nss
->ccw
.nss_name
, nss_len
);
807 reipl_block_nss
->ccw
.vm_flags
&= ~IPL_PB0_CCW_VM_FLAG_NSS
;
813 static struct kobj_attribute sys_reipl_nss_name_attr
=
814 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
815 reipl_nss_name_store
);
817 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
818 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
819 reipl_nss_loadparm_store
);
821 static struct attribute
*reipl_nss_attrs
[] = {
822 &sys_reipl_nss_name_attr
.attr
,
823 &sys_reipl_nss_loadparm_attr
.attr
,
824 &sys_reipl_nss_vmparm_attr
.attr
,
828 static struct attribute_group reipl_nss_attr_group
= {
830 .attrs
= reipl_nss_attrs
,
833 void set_os_info_reipl_block(void)
835 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
836 reipl_block_actual
->hdr
.len
);
841 static int reipl_set_type(enum ipl_type type
)
843 if (!(reipl_capabilities
& type
))
848 reipl_block_actual
= reipl_block_ccw
;
851 reipl_block_actual
= reipl_block_fcp
;
854 reipl_block_actual
= reipl_block_nss
;
863 static ssize_t
reipl_type_show(struct kobject
*kobj
,
864 struct kobj_attribute
*attr
, char *page
)
866 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
869 static ssize_t
reipl_type_store(struct kobject
*kobj
,
870 struct kobj_attribute
*attr
,
871 const char *buf
, size_t len
)
875 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
876 rc
= reipl_set_type(IPL_TYPE_CCW
);
877 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
878 rc
= reipl_set_type(IPL_TYPE_FCP
);
879 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
880 rc
= reipl_set_type(IPL_TYPE_NSS
);
881 return (rc
!= 0) ? rc
: len
;
884 static struct kobj_attribute reipl_type_attr
=
885 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
887 static struct kset
*reipl_kset
;
888 static struct kset
*reipl_fcp_kset
;
890 static void __reipl_run(void *unused
)
892 switch (reipl_type
) {
894 diag308(DIAG308_SET
, reipl_block_ccw
);
895 diag308(DIAG308_LOAD_CLEAR
, NULL
);
898 diag308(DIAG308_SET
, reipl_block_fcp
);
899 diag308(DIAG308_LOAD_CLEAR
, NULL
);
902 diag308(DIAG308_SET
, reipl_block_nss
);
903 diag308(DIAG308_LOAD_CLEAR
, NULL
);
905 case IPL_TYPE_UNKNOWN
:
906 diag308(DIAG308_LOAD_CLEAR
, NULL
);
908 case IPL_TYPE_FCP_DUMP
:
914 static void reipl_run(struct shutdown_trigger
*trigger
)
916 smp_call_ipl_cpu(__reipl_run
, NULL
);
919 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
921 ipb
->hdr
.len
= IPL_BP_CCW_LEN
;
922 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
923 ipb
->pb0_hdr
.len
= IPL_BP0_CCW_LEN
;
924 ipb
->pb0_hdr
.pbt
= IPL_PBT_CCW
;
927 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
930 /* check if read scp info worked and set loadparm */
931 if (sclp_ipl_info
.is_valid
)
932 memcpy(ipb
->ccw
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
934 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
935 memset(ipb
->ccw
.loadparm
, 0x40, LOADPARM_LEN
);
936 ipb
->ccw
.flags
= IPL_PB0_FLAG_LOADPARM
;
939 if (MACHINE_IS_VM
&& ipl_block_valid
&&
940 (ipl_block
.ccw
.vm_flags
& IPL_PB0_CCW_VM_FLAG_VP
)) {
942 ipb
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_VP
;
943 ipb
->ccw
.vm_parm_len
= ipl_block
.ccw
.vm_parm_len
;
944 memcpy(ipb
->ccw
.vm_parm
,
945 ipl_block
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
949 static int __init
reipl_nss_init(void)
956 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
957 if (!reipl_block_nss
)
960 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
964 reipl_block_ccw_init(reipl_block_nss
);
965 reipl_capabilities
|= IPL_TYPE_NSS
;
969 static int __init
reipl_ccw_init(void)
973 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
974 if (!reipl_block_ccw
)
977 rc
= sysfs_create_group(&reipl_kset
->kobj
,
978 MACHINE_IS_VM
? &reipl_ccw_attr_group_vm
979 : &reipl_ccw_attr_group_lpar
);
983 reipl_block_ccw_init(reipl_block_ccw
);
984 if (ipl_info
.type
== IPL_TYPE_CCW
) {
985 reipl_block_ccw
->ccw
.ssid
= ipl_block
.ccw
.ssid
;
986 reipl_block_ccw
->ccw
.devno
= ipl_block
.ccw
.devno
;
987 reipl_block_ccw_fill_parms(reipl_block_ccw
);
990 reipl_capabilities
|= IPL_TYPE_CCW
;
994 static int __init
reipl_fcp_init(void)
998 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
999 if (!reipl_block_fcp
)
1002 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1003 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1005 if (!reipl_fcp_kset
) {
1006 free_page((unsigned long) reipl_block_fcp
);
1010 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1012 kset_unregister(reipl_fcp_kset
);
1013 free_page((unsigned long) reipl_block_fcp
);
1017 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1018 memcpy(reipl_block_fcp
, &ipl_block
, sizeof(ipl_block
));
1020 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1021 * is invalid in the SCSI IPL parameter block, so take it
1022 * always from sclp_ipl_info.
1024 memcpy(reipl_block_fcp
->fcp
.loadparm
, sclp_ipl_info
.loadparm
,
1027 reipl_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
;
1028 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1029 reipl_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
;
1030 reipl_block_fcp
->fcp
.pbt
= IPL_PBT_FCP
;
1031 reipl_block_fcp
->fcp
.opt
= IPL_PB0_FCP_OPT_IPL
;
1033 reipl_capabilities
|= IPL_TYPE_FCP
;
1037 static int __init
reipl_type_init(void)
1039 enum ipl_type reipl_type
= ipl_info
.type
;
1040 struct ipl_parameter_block
*reipl_block
;
1043 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1047 * If we have an OS info reipl block, this will be used
1049 if (reipl_block
->pb0_hdr
.pbt
== IPL_PBT_FCP
) {
1050 memcpy(reipl_block_fcp
, reipl_block
, size
);
1051 reipl_type
= IPL_TYPE_FCP
;
1052 } else if (reipl_block
->pb0_hdr
.pbt
== IPL_PBT_CCW
) {
1053 memcpy(reipl_block_ccw
, reipl_block
, size
);
1054 reipl_type
= IPL_TYPE_CCW
;
1057 return reipl_set_type(reipl_type
);
1060 static int __init
reipl_init(void)
1064 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1067 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1069 kset_unregister(reipl_kset
);
1072 rc
= reipl_ccw_init();
1075 rc
= reipl_fcp_init();
1078 rc
= reipl_nss_init();
1081 return reipl_type_init();
1084 static struct shutdown_action __refdata reipl_action
= {
1085 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1091 * dump shutdown action: Dump Linux on shutdown.
1094 /* FCP dump device attributes */
1096 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1097 dump_block_fcp
->fcp
.wwpn
);
1098 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1099 dump_block_fcp
->fcp
.lun
);
1100 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1101 dump_block_fcp
->fcp
.bootprog
);
1102 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1103 dump_block_fcp
->fcp
.br_lba
);
1104 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1105 dump_block_fcp
->fcp
.devno
);
1107 static struct attribute
*dump_fcp_attrs
[] = {
1108 &sys_dump_fcp_device_attr
.attr
,
1109 &sys_dump_fcp_wwpn_attr
.attr
,
1110 &sys_dump_fcp_lun_attr
.attr
,
1111 &sys_dump_fcp_bootprog_attr
.attr
,
1112 &sys_dump_fcp_br_lba_attr
.attr
,
1116 static struct attribute_group dump_fcp_attr_group
= {
1117 .name
= IPL_FCP_STR
,
1118 .attrs
= dump_fcp_attrs
,
1121 /* CCW dump device attributes */
1122 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ccw
);
1124 static struct attribute
*dump_ccw_attrs
[] = {
1125 &sys_dump_ccw_device_attr
.attr
,
1129 static struct attribute_group dump_ccw_attr_group
= {
1130 .name
= IPL_CCW_STR
,
1131 .attrs
= dump_ccw_attrs
,
1136 static int dump_set_type(enum dump_type type
)
1138 if (!(dump_capabilities
& type
))
1144 static ssize_t
dump_type_show(struct kobject
*kobj
,
1145 struct kobj_attribute
*attr
, char *page
)
1147 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1150 static ssize_t
dump_type_store(struct kobject
*kobj
,
1151 struct kobj_attribute
*attr
,
1152 const char *buf
, size_t len
)
1156 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1157 rc
= dump_set_type(DUMP_TYPE_NONE
);
1158 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1159 rc
= dump_set_type(DUMP_TYPE_CCW
);
1160 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1161 rc
= dump_set_type(DUMP_TYPE_FCP
);
1162 return (rc
!= 0) ? rc
: len
;
1165 static struct kobj_attribute dump_type_attr
=
1166 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1168 static struct kset
*dump_kset
;
1170 static void diag308_dump(void *dump_block
)
1172 diag308(DIAG308_SET
, dump_block
);
1174 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1176 udelay_simple(USEC_PER_SEC
);
1180 static void __dump_run(void *unused
)
1182 switch (dump_type
) {
1184 diag308_dump(dump_block_ccw
);
1187 diag308_dump(dump_block_fcp
);
1194 static void dump_run(struct shutdown_trigger
*trigger
)
1196 if (dump_type
== DUMP_TYPE_NONE
)
1199 smp_call_ipl_cpu(__dump_run
, NULL
);
1202 static int __init
dump_ccw_init(void)
1206 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1207 if (!dump_block_ccw
)
1209 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1211 free_page((unsigned long)dump_block_ccw
);
1214 dump_block_ccw
->hdr
.len
= IPL_BP_CCW_LEN
;
1215 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1216 dump_block_ccw
->ccw
.len
= IPL_BP0_CCW_LEN
;
1217 dump_block_ccw
->ccw
.pbt
= IPL_PBT_CCW
;
1218 dump_capabilities
|= DUMP_TYPE_CCW
;
1222 static int __init
dump_fcp_init(void)
1226 if (!sclp_ipl_info
.has_dump
)
1227 return 0; /* LDIPL DUMP is not installed */
1228 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1229 if (!dump_block_fcp
)
1231 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1233 free_page((unsigned long)dump_block_fcp
);
1236 dump_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
;
1237 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1238 dump_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
;
1239 dump_block_fcp
->fcp
.pbt
= IPL_PBT_FCP
;
1240 dump_block_fcp
->fcp
.opt
= IPL_PB0_FCP_OPT_DUMP
;
1241 dump_capabilities
|= DUMP_TYPE_FCP
;
1245 static int __init
dump_init(void)
1249 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1252 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1254 kset_unregister(dump_kset
);
1257 rc
= dump_ccw_init();
1260 rc
= dump_fcp_init();
1263 dump_set_type(DUMP_TYPE_NONE
);
1267 static struct shutdown_action __refdata dump_action
= {
1268 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1273 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1275 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1278 csum
= (__force
unsigned int)
1279 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1280 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1281 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1285 static struct shutdown_action __refdata dump_reipl_action
= {
1286 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1287 .fn
= dump_reipl_run
,
1291 * vmcmd shutdown action: Trigger vm command on shutdown.
1294 static char vmcmd_on_reboot
[128];
1295 static char vmcmd_on_panic
[128];
1296 static char vmcmd_on_halt
[128];
1297 static char vmcmd_on_poff
[128];
1298 static char vmcmd_on_restart
[128];
1300 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1301 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1302 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1303 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1304 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1306 static struct attribute
*vmcmd_attrs
[] = {
1307 &sys_vmcmd_on_reboot_attr
.attr
,
1308 &sys_vmcmd_on_panic_attr
.attr
,
1309 &sys_vmcmd_on_halt_attr
.attr
,
1310 &sys_vmcmd_on_poff_attr
.attr
,
1311 &sys_vmcmd_on_restart_attr
.attr
,
1315 static struct attribute_group vmcmd_attr_group
= {
1316 .attrs
= vmcmd_attrs
,
1319 static struct kset
*vmcmd_kset
;
1321 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1325 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1326 cmd
= vmcmd_on_reboot
;
1327 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1328 cmd
= vmcmd_on_panic
;
1329 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1330 cmd
= vmcmd_on_halt
;
1331 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1332 cmd
= vmcmd_on_poff
;
1333 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1334 cmd
= vmcmd_on_restart
;
1338 if (strlen(cmd
) == 0)
1340 __cpcmd(cmd
, NULL
, 0, NULL
);
1343 static int vmcmd_init(void)
1347 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1350 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1353 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1354 vmcmd_run
, vmcmd_init
};
1357 * stop shutdown action: Stop Linux on shutdown.
1360 static void stop_run(struct shutdown_trigger
*trigger
)
1362 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1363 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1368 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1373 static struct shutdown_action
*shutdown_actions_list
[] = {
1374 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1375 &vmcmd_action
, &stop_action
};
1376 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1382 static struct kset
*shutdown_actions_kset
;
1384 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1389 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1390 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1391 if (shutdown_actions_list
[i
]->init_rc
) {
1392 return shutdown_actions_list
[i
]->init_rc
;
1394 trigger
->action
= shutdown_actions_list
[i
];
1404 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1407 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1408 struct kobj_attribute
*attr
, char *page
)
1410 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1413 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1414 struct kobj_attribute
*attr
,
1415 const char *buf
, size_t len
)
1417 return set_trigger(buf
, &on_reboot_trigger
, len
);
1419 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1421 static void do_machine_restart(char *__unused
)
1424 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1427 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1431 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1433 static ssize_t
on_panic_show(struct kobject
*kobj
,
1434 struct kobj_attribute
*attr
, char *page
)
1436 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1439 static ssize_t
on_panic_store(struct kobject
*kobj
,
1440 struct kobj_attribute
*attr
,
1441 const char *buf
, size_t len
)
1443 return set_trigger(buf
, &on_panic_trigger
, len
);
1445 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1447 static void do_panic(void)
1450 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1451 stop_run(&on_panic_trigger
);
1456 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1459 static ssize_t
on_restart_show(struct kobject
*kobj
,
1460 struct kobj_attribute
*attr
, char *page
)
1462 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1465 static ssize_t
on_restart_store(struct kobject
*kobj
,
1466 struct kobj_attribute
*attr
,
1467 const char *buf
, size_t len
)
1469 return set_trigger(buf
, &on_restart_trigger
, len
);
1471 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1473 static void __do_restart(void *ignore
)
1475 __arch_local_irq_stosm(0x04); /* enable DAT */
1477 #ifdef CONFIG_CRASH_DUMP
1480 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1481 stop_run(&on_restart_trigger
);
1484 void do_restart(void)
1489 smp_call_online_cpu(__do_restart
, NULL
);
1494 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1496 static ssize_t
on_halt_show(struct kobject
*kobj
,
1497 struct kobj_attribute
*attr
, char *page
)
1499 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1502 static ssize_t
on_halt_store(struct kobject
*kobj
,
1503 struct kobj_attribute
*attr
,
1504 const char *buf
, size_t len
)
1506 return set_trigger(buf
, &on_halt_trigger
, len
);
1508 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1510 static void do_machine_halt(void)
1513 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1514 stop_run(&on_halt_trigger
);
1516 void (*_machine_halt
)(void) = do_machine_halt
;
1520 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1522 static ssize_t
on_poff_show(struct kobject
*kobj
,
1523 struct kobj_attribute
*attr
, char *page
)
1525 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1528 static ssize_t
on_poff_store(struct kobject
*kobj
,
1529 struct kobj_attribute
*attr
,
1530 const char *buf
, size_t len
)
1532 return set_trigger(buf
, &on_poff_trigger
, len
);
1534 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1536 static void do_machine_power_off(void)
1539 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1540 stop_run(&on_poff_trigger
);
1542 void (*_machine_power_off
)(void) = do_machine_power_off
;
1544 static struct attribute
*shutdown_action_attrs
[] = {
1545 &on_restart_attr
.attr
,
1546 &on_reboot_attr
.attr
,
1547 &on_panic_attr
.attr
,
1553 static struct attribute_group shutdown_action_attr_group
= {
1554 .attrs
= shutdown_action_attrs
,
1557 static void __init
shutdown_triggers_init(void)
1559 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1561 if (!shutdown_actions_kset
)
1563 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1564 &shutdown_action_attr_group
))
1568 panic("shutdown_triggers_init failed\n");
1571 static void __init
shutdown_actions_init(void)
1575 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1576 if (!shutdown_actions_list
[i
]->init
)
1578 shutdown_actions_list
[i
]->init_rc
=
1579 shutdown_actions_list
[i
]->init();
1583 static int __init
s390_ipl_init(void)
1585 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1587 sclp_early_get_ipl_info(&sclp_ipl_info
);
1589 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1590 * returned by read SCP info is invalid (contains EBCDIC blanks)
1591 * when the system has been booted via diag308. In that case we use
1592 * the value from diag308, if available.
1594 * There are also systems where diag308 store does not work in
1595 * case the system is booted from HMC. Fortunately in this case
1596 * READ SCP info provides the correct value.
1598 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 && ipl_block_valid
)
1599 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.ccw
.loadparm
, LOADPARM_LEN
);
1600 shutdown_actions_init();
1601 shutdown_triggers_init();
1605 __initcall(s390_ipl_init
);
1607 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1612 for (sx
= 0; src
[sx
] != 0; sx
++) {
1615 dst
[dx
++] = src
[sx
];
1621 static int __init
vmcmd_on_reboot_setup(char *str
)
1625 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1626 vmcmd_on_reboot
[127] = 0;
1627 on_reboot_trigger
.action
= &vmcmd_action
;
1630 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1632 static int __init
vmcmd_on_panic_setup(char *str
)
1636 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1637 vmcmd_on_panic
[127] = 0;
1638 on_panic_trigger
.action
= &vmcmd_action
;
1641 __setup("vmpanic=", vmcmd_on_panic_setup
);
1643 static int __init
vmcmd_on_halt_setup(char *str
)
1647 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1648 vmcmd_on_halt
[127] = 0;
1649 on_halt_trigger
.action
= &vmcmd_action
;
1652 __setup("vmhalt=", vmcmd_on_halt_setup
);
1654 static int __init
vmcmd_on_poff_setup(char *str
)
1658 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1659 vmcmd_on_poff
[127] = 0;
1660 on_poff_trigger
.action
= &vmcmd_action
;
1663 __setup("vmpoff=", vmcmd_on_poff_setup
);
1665 static int on_panic_notify(struct notifier_block
*self
,
1666 unsigned long event
, void *data
)
1672 static struct notifier_block on_panic_nb
= {
1673 .notifier_call
= on_panic_notify
,
1674 .priority
= INT_MIN
,
1677 void __init
setup_ipl(void)
1679 BUILD_BUG_ON(sizeof(struct ipl_parameter_block
) != PAGE_SIZE
);
1681 ipl_info
.type
= get_ipl_type();
1682 switch (ipl_info
.type
) {
1684 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_block
.ccw
.ssid
;
1685 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_block
.ccw
.devno
;
1688 case IPL_TYPE_FCP_DUMP
:
1689 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1690 ipl_info
.data
.fcp
.dev_id
.devno
= ipl_block
.fcp
.devno
;
1691 ipl_info
.data
.fcp
.wwpn
= ipl_block
.fcp
.wwpn
;
1692 ipl_info
.data
.fcp
.lun
= ipl_block
.fcp
.lun
;
1695 case IPL_TYPE_UNKNOWN
:
1696 /* We have no info to copy */
1699 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1702 void s390_reset_system(void)
1704 /* Disable prefixing */
1707 /* Disable lowcore protection */
1708 __ctl_clear_bit(0, 28);
1709 diag_dma_ops
.diag308_reset();
1712 #ifdef CONFIG_KEXEC_FILE
1714 int ipl_report_add_component(struct ipl_report
*report
, struct kexec_buf
*kbuf
,
1715 unsigned char flags
, unsigned short cert
)
1717 struct ipl_report_component
*comp
;
1719 comp
= vzalloc(sizeof(*comp
));
1722 list_add_tail(&comp
->list
, &report
->components
);
1724 comp
->entry
.addr
= kbuf
->mem
;
1725 comp
->entry
.len
= kbuf
->memsz
;
1726 comp
->entry
.flags
= flags
;
1727 comp
->entry
.certificate_index
= cert
;
1729 report
->size
+= sizeof(comp
->entry
);
1734 int ipl_report_add_certificate(struct ipl_report
*report
, void *key
,
1735 unsigned long addr
, unsigned long len
)
1737 struct ipl_report_certificate
*cert
;
1739 cert
= vzalloc(sizeof(*cert
));
1742 list_add_tail(&cert
->list
, &report
->certificates
);
1744 cert
->entry
.addr
= addr
;
1745 cert
->entry
.len
= len
;
1748 report
->size
+= sizeof(cert
->entry
);
1749 report
->size
+= cert
->entry
.len
;
1754 struct ipl_report
*ipl_report_init(struct ipl_parameter_block
*ipib
)
1756 struct ipl_report
*report
;
1758 report
= vzalloc(sizeof(*report
));
1760 return ERR_PTR(-ENOMEM
);
1762 report
->ipib
= ipib
;
1763 INIT_LIST_HEAD(&report
->components
);
1764 INIT_LIST_HEAD(&report
->certificates
);
1766 report
->size
= ALIGN(ipib
->hdr
.len
, 8);
1767 report
->size
+= sizeof(struct ipl_rl_hdr
);
1768 report
->size
+= sizeof(struct ipl_rb_components
);
1769 report
->size
+= sizeof(struct ipl_rb_certificates
);
1774 void *ipl_report_finish(struct ipl_report
*report
)
1776 struct ipl_report_certificate
*cert
;
1777 struct ipl_report_component
*comp
;
1778 struct ipl_rb_certificates
*certs
;
1779 struct ipl_parameter_block
*ipib
;
1780 struct ipl_rb_components
*comps
;
1781 struct ipl_rl_hdr
*rl_hdr
;
1784 buf
= vzalloc(report
->size
);
1786 return ERR_PTR(-ENOMEM
);
1789 memcpy(ptr
, report
->ipib
, report
->ipib
->hdr
.len
);
1791 if (ipl_secure_flag
)
1792 ipib
->hdr
.flags
|= IPL_PL_FLAG_SIPL
;
1793 ipib
->hdr
.flags
|= IPL_PL_FLAG_IPLSR
;
1794 ptr
+= report
->ipib
->hdr
.len
;
1795 ptr
= PTR_ALIGN(ptr
, 8);
1798 ptr
+= sizeof(*rl_hdr
);
1801 comps
->rbt
= IPL_RBT_COMPONENTS
;
1802 ptr
+= sizeof(*comps
);
1803 list_for_each_entry(comp
, &report
->components
, list
) {
1804 memcpy(ptr
, &comp
->entry
, sizeof(comp
->entry
));
1805 ptr
+= sizeof(comp
->entry
);
1807 comps
->len
= ptr
- (void *)comps
;
1810 certs
->rbt
= IPL_RBT_CERTIFICATES
;
1811 ptr
+= sizeof(*certs
);
1812 list_for_each_entry(cert
, &report
->certificates
, list
) {
1813 memcpy(ptr
, &cert
->entry
, sizeof(cert
->entry
));
1814 ptr
+= sizeof(cert
->entry
);
1816 certs
->len
= ptr
- (void *)certs
;
1817 rl_hdr
->len
= ptr
- (void *)rl_hdr
;
1819 list_for_each_entry(cert
, &report
->certificates
, list
) {
1820 memcpy(ptr
, cert
->key
, cert
->entry
.len
);
1821 ptr
+= cert
->entry
.len
;
1824 BUG_ON(ptr
> buf
+ report
->size
);
1828 int ipl_report_free(struct ipl_report
*report
)
1830 struct ipl_report_component
*comp
, *ncomp
;
1831 struct ipl_report_certificate
*cert
, *ncert
;
1833 list_for_each_entry_safe(comp
, ncomp
, &report
->components
, list
)
1836 list_for_each_entry_safe(cert
, ncert
, &report
->certificates
, list
)