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>
37 #define IPL_PARM_BLOCK_VERSION 0
39 #define IPL_UNKNOWN_STR "unknown"
40 #define IPL_CCW_STR "ccw"
41 #define IPL_FCP_STR "fcp"
42 #define IPL_FCP_DUMP_STR "fcp_dump"
43 #define IPL_NSS_STR "nss"
45 #define DUMP_CCW_STR "ccw"
46 #define DUMP_FCP_STR "fcp"
47 #define DUMP_NONE_STR "none"
50 * Four shutdown trigger types are supported:
57 #define ON_PANIC_STR "on_panic"
58 #define ON_HALT_STR "on_halt"
59 #define ON_POFF_STR "on_poff"
60 #define ON_REIPL_STR "on_reboot"
61 #define ON_RESTART_STR "on_restart"
63 struct shutdown_action
;
64 struct shutdown_trigger
{
66 struct shutdown_action
*action
;
70 * The following shutdown action types are supported:
72 #define SHUTDOWN_ACTION_IPL_STR "ipl"
73 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
74 #define SHUTDOWN_ACTION_DUMP_STR "dump"
75 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
76 #define SHUTDOWN_ACTION_STOP_STR "stop"
77 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
79 struct shutdown_action
{
81 void (*fn
) (struct shutdown_trigger
*trigger
);
86 static char *ipl_type_str(enum ipl_type type
)
93 case IPL_TYPE_FCP_DUMP
:
94 return IPL_FCP_DUMP_STR
;
97 case IPL_TYPE_UNKNOWN
:
99 return IPL_UNKNOWN_STR
;
109 static char *dump_type_str(enum dump_type type
)
113 return DUMP_NONE_STR
;
123 int __bootdata_preserved(ipl_block_valid
);
124 struct ipl_parameter_block
__bootdata_preserved(ipl_block
);
125 int __bootdata_preserved(ipl_secure_flag
);
127 unsigned long __bootdata_preserved(ipl_cert_list_addr
);
128 unsigned long __bootdata_preserved(ipl_cert_list_size
);
130 unsigned long __bootdata(early_ipl_comp_list_addr
);
131 unsigned long __bootdata(early_ipl_comp_list_size
);
133 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
135 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
136 static struct ipl_parameter_block
*reipl_block_fcp
;
137 static struct ipl_parameter_block
*reipl_block_ccw
;
138 static struct ipl_parameter_block
*reipl_block_nss
;
139 static struct ipl_parameter_block
*reipl_block_actual
;
141 static int dump_capabilities
= DUMP_TYPE_NONE
;
142 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
143 static struct ipl_parameter_block
*dump_block_fcp
;
144 static struct ipl_parameter_block
*dump_block_ccw
;
146 static struct sclp_ipl_info sclp_ipl_info
;
148 static inline int __diag308(unsigned long subcode
, void *addr
)
150 register unsigned long _addr
asm("0") = (unsigned long) addr
;
151 register unsigned long _rc
asm("1") = 0;
154 " diag %0,%2,0x308\n"
157 : "+d" (_addr
), "+d" (_rc
)
158 : "d" (subcode
) : "cc", "memory");
162 int diag308(unsigned long subcode
, void *addr
)
164 if (IS_ENABLED(CONFIG_KASAN
))
165 __arch_local_irq_stosm(0x04); /* enable DAT */
166 diag_stat_inc(DIAG_STAT_X308
);
167 return __diag308(subcode
, addr
);
169 EXPORT_SYMBOL_GPL(diag308
);
173 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
174 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
175 struct kobj_attribute *attr, \
178 return snprintf(page, PAGE_SIZE, _format, ##args); \
181 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
182 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
183 struct kobj_attribute *attr, \
184 const char *buf, size_t len) \
186 unsigned long long ssid, devno; \
188 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
191 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
194 _ipl_blk.ssid = ssid; \
195 _ipl_blk.devno = devno; \
199 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
200 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
201 _ipl_blk.ssid, _ipl_blk.devno); \
202 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
203 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
204 __ATTR(_name, (S_IRUGO | S_IWUSR), \
205 sys_##_prefix##_##_name##_show, \
206 sys_##_prefix##_##_name##_store) \
208 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
209 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
210 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
211 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
213 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
214 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
215 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
216 struct kobj_attribute *attr, \
217 const char *buf, size_t len) \
219 unsigned long long value; \
220 if (sscanf(buf, _fmt_in, &value) != 1) \
225 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
226 __ATTR(_name,(S_IRUGO | S_IWUSR), \
227 sys_##_prefix##_##_name##_show, \
228 sys_##_prefix##_##_name##_store)
230 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
231 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
232 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
233 struct kobj_attribute *attr, \
234 const char *buf, size_t len) \
236 strncpy(_value, buf, sizeof(_value) - 1); \
240 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
241 __ATTR(_name,(S_IRUGO | S_IWUSR), \
242 sys_##_prefix##_##_name##_show, \
243 sys_##_prefix##_##_name##_store)
249 static __init
enum ipl_type
get_ipl_type(void)
251 if (!ipl_block_valid
)
252 return IPL_TYPE_UNKNOWN
;
254 switch (ipl_block
.pb0_hdr
.pbt
) {
258 if (ipl_block
.fcp
.opt
== IPL_PB0_FCP_OPT_DUMP
)
259 return IPL_TYPE_FCP_DUMP
;
263 return IPL_TYPE_UNKNOWN
;
266 struct ipl_info ipl_info
;
267 EXPORT_SYMBOL_GPL(ipl_info
);
269 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
272 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
275 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
277 static ssize_t
ipl_secure_show(struct kobject
*kobj
,
278 struct kobj_attribute
*attr
, char *page
)
280 return sprintf(page
, "%i\n", !!ipl_secure_flag
);
283 static struct kobj_attribute sys_ipl_secure_attr
=
284 __ATTR(secure
, 0444, ipl_secure_show
, NULL
);
286 static ssize_t
ipl_has_secure_show(struct kobject
*kobj
,
287 struct kobj_attribute
*attr
, char *page
)
289 return sprintf(page
, "%i\n", !!sclp
.has_sipl
);
292 static struct kobj_attribute sys_ipl_has_secure_attr
=
293 __ATTR(has_secure
, 0444, ipl_has_secure_show
, NULL
);
295 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
296 struct kobj_attribute
*attr
, char *page
)
298 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
300 if (ipl_block_valid
&& (ipl_block
.pb0_hdr
.pbt
== IPL_PBT_CCW
))
301 ipl_block_get_ascii_vmparm(parm
, sizeof(parm
), &ipl_block
);
302 return sprintf(page
, "%s\n", parm
);
305 static struct kobj_attribute sys_ipl_vm_parm_attr
=
306 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
308 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
309 struct kobj_attribute
*attr
, char *page
)
311 switch (ipl_info
.type
) {
313 return sprintf(page
, "0.%x.%04x\n", ipl_block
.ccw
.ssid
,
314 ipl_block
.ccw
.devno
);
316 case IPL_TYPE_FCP_DUMP
:
317 return sprintf(page
, "0.0.%04x\n", ipl_block
.fcp
.devno
);
323 static struct kobj_attribute sys_ipl_device_attr
=
324 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
326 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
327 struct bin_attribute
*attr
, char *buf
,
328 loff_t off
, size_t count
)
330 return memory_read_from_buffer(buf
, count
, &off
, &ipl_block
,
333 static struct bin_attribute ipl_parameter_attr
=
334 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
337 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
338 struct bin_attribute
*attr
, char *buf
,
339 loff_t off
, size_t count
)
341 unsigned int size
= ipl_block
.fcp
.scp_data_len
;
342 void *scp_data
= &ipl_block
.fcp
.scp_data
;
344 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
346 static struct bin_attribute ipl_scp_data_attr
=
347 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
349 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
355 /* FCP ipl device attributes */
357 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n",
358 (unsigned long long)ipl_block
.fcp
.wwpn
);
359 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n",
360 (unsigned long long)ipl_block
.fcp
.lun
);
361 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n",
362 (unsigned long long)ipl_block
.fcp
.bootprog
);
363 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n",
364 (unsigned long long)ipl_block
.fcp
.br_lba
);
366 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
367 struct kobj_attribute
*attr
, char *page
)
369 char loadparm
[LOADPARM_LEN
+ 1] = {};
371 if (!sclp_ipl_info
.is_valid
)
372 return sprintf(page
, "#unknown#\n");
373 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
374 EBCASC(loadparm
, LOADPARM_LEN
);
376 return sprintf(page
, "%s\n", loadparm
);
379 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
380 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
382 static struct attribute
*ipl_fcp_attrs
[] = {
383 &sys_ipl_type_attr
.attr
,
384 &sys_ipl_device_attr
.attr
,
385 &sys_ipl_fcp_wwpn_attr
.attr
,
386 &sys_ipl_fcp_lun_attr
.attr
,
387 &sys_ipl_fcp_bootprog_attr
.attr
,
388 &sys_ipl_fcp_br_lba_attr
.attr
,
389 &sys_ipl_ccw_loadparm_attr
.attr
,
390 &sys_ipl_secure_attr
.attr
,
391 &sys_ipl_has_secure_attr
.attr
,
395 static struct attribute_group ipl_fcp_attr_group
= {
396 .attrs
= ipl_fcp_attrs
,
397 .bin_attrs
= ipl_fcp_bin_attrs
,
400 /* CCW ipl device attributes */
402 static struct attribute
*ipl_ccw_attrs_vm
[] = {
403 &sys_ipl_type_attr
.attr
,
404 &sys_ipl_device_attr
.attr
,
405 &sys_ipl_ccw_loadparm_attr
.attr
,
406 &sys_ipl_vm_parm_attr
.attr
,
407 &sys_ipl_secure_attr
.attr
,
408 &sys_ipl_has_secure_attr
.attr
,
412 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
413 &sys_ipl_type_attr
.attr
,
414 &sys_ipl_device_attr
.attr
,
415 &sys_ipl_ccw_loadparm_attr
.attr
,
416 &sys_ipl_secure_attr
.attr
,
417 &sys_ipl_has_secure_attr
.attr
,
421 static struct attribute_group ipl_ccw_attr_group_vm
= {
422 .attrs
= ipl_ccw_attrs_vm
,
425 static struct attribute_group ipl_ccw_attr_group_lpar
= {
426 .attrs
= ipl_ccw_attrs_lpar
429 /* UNKNOWN ipl device attributes */
431 static struct attribute
*ipl_unknown_attrs
[] = {
432 &sys_ipl_type_attr
.attr
,
436 static struct attribute_group ipl_unknown_attr_group
= {
437 .attrs
= ipl_unknown_attrs
,
440 static struct kset
*ipl_kset
;
442 static void __ipl_run(void *unused
)
445 diag308(DIAG308_LOAD_CLEAR
, NULL
);
448 static void ipl_run(struct shutdown_trigger
*trigger
)
450 smp_call_ipl_cpu(__ipl_run
, NULL
);
453 static int __init
ipl_init(void)
457 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
462 switch (ipl_info
.type
) {
465 rc
= sysfs_create_group(&ipl_kset
->kobj
,
466 &ipl_ccw_attr_group_vm
);
468 rc
= sysfs_create_group(&ipl_kset
->kobj
,
469 &ipl_ccw_attr_group_lpar
);
472 case IPL_TYPE_FCP_DUMP
:
473 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
476 rc
= sysfs_create_group(&ipl_kset
->kobj
,
477 &ipl_unknown_attr_group
);
482 panic("ipl_init failed: rc = %i\n", rc
);
487 static struct shutdown_action __refdata ipl_action
= {
488 .name
= SHUTDOWN_ACTION_IPL_STR
,
494 * reipl shutdown action: Reboot Linux on shutdown.
497 /* VM IPL PARM attributes */
498 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
501 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
503 ipl_block_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
504 return sprintf(page
, "%s\n", vmparm
);
507 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
509 const char *buf
, size_t len
)
513 /* ignore trailing newline */
515 if ((len
> 0) && (buf
[len
- 1] == '\n'))
518 if (ip_len
> vmparm_max
)
521 /* parm is used to store kernel options, check for common chars */
522 for (i
= 0; i
< ip_len
; i
++)
523 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
526 memset(ipb
->ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
527 ipb
->ccw
.vm_parm_len
= ip_len
;
529 ipb
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_VP
;
530 memcpy(ipb
->ccw
.vm_parm
, buf
, ip_len
);
531 ASCEBC(ipb
->ccw
.vm_parm
, ip_len
);
533 ipb
->ccw
.vm_flags
&= ~IPL_PB0_CCW_VM_FLAG_VP
;
540 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
541 struct kobj_attribute
*attr
, char *page
)
543 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
546 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
547 struct kobj_attribute
*attr
,
548 const char *buf
, size_t len
)
550 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
554 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
555 struct kobj_attribute
*attr
, char *page
)
557 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
560 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
561 struct kobj_attribute
*attr
,
562 const char *buf
, size_t len
)
564 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
567 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
568 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
569 reipl_nss_vmparm_store
);
570 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
571 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
572 reipl_ccw_vmparm_store
);
574 /* FCP reipl device attributes */
576 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
577 struct bin_attribute
*attr
,
578 char *buf
, loff_t off
, size_t count
)
580 size_t size
= reipl_block_fcp
->fcp
.scp_data_len
;
581 void *scp_data
= reipl_block_fcp
->fcp
.scp_data
;
583 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
586 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
587 struct bin_attribute
*attr
,
588 char *buf
, loff_t off
, size_t count
)
590 size_t scpdata_len
= count
;
597 memcpy(reipl_block_fcp
->fcp
.scp_data
, buf
, count
);
598 if (scpdata_len
% 8) {
599 padding
= 8 - (scpdata_len
% 8);
600 memset(reipl_block_fcp
->fcp
.scp_data
+ scpdata_len
,
602 scpdata_len
+= padding
;
605 reipl_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
+ scpdata_len
;
606 reipl_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
+ scpdata_len
;
607 reipl_block_fcp
->fcp
.scp_data_len
= scpdata_len
;
611 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
612 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
613 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
615 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
616 &sys_reipl_fcp_scp_data_attr
,
620 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
621 reipl_block_fcp
->fcp
.wwpn
);
622 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
623 reipl_block_fcp
->fcp
.lun
);
624 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
625 reipl_block_fcp
->fcp
.bootprog
);
626 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
627 reipl_block_fcp
->fcp
.br_lba
);
628 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
629 reipl_block_fcp
->fcp
.devno
);
631 static void reipl_get_ascii_loadparm(char *loadparm
,
632 struct ipl_parameter_block
*ibp
)
634 memcpy(loadparm
, ibp
->common
.loadparm
, LOADPARM_LEN
);
635 EBCASC(loadparm
, LOADPARM_LEN
);
636 loadparm
[LOADPARM_LEN
] = 0;
640 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
643 char buf
[LOADPARM_LEN
+ 1];
645 reipl_get_ascii_loadparm(buf
, ipb
);
646 return sprintf(page
, "%s\n", buf
);
649 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
650 const char *buf
, size_t len
)
654 /* ignore trailing newline */
656 if ((len
> 0) && (buf
[len
- 1] == '\n'))
658 /* loadparm can have max 8 characters and must not start with a blank */
659 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
661 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
662 for (i
= 0; i
< lp_len
; i
++) {
663 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
668 /* initialize loadparm with blanks */
669 memset(ipb
->common
.loadparm
, ' ', LOADPARM_LEN
);
670 /* copy and convert to ebcdic */
671 memcpy(ipb
->common
.loadparm
, buf
, lp_len
);
672 ASCEBC(ipb
->common
.loadparm
, LOADPARM_LEN
);
673 ipb
->common
.flags
|= IPL_PB0_FLAG_LOADPARM
;
678 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
679 struct kobj_attribute
*attr
, char *page
)
681 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
684 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
685 struct kobj_attribute
*attr
,
686 const char *buf
, size_t len
)
688 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
691 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
692 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
693 reipl_fcp_loadparm_store
);
695 static struct attribute
*reipl_fcp_attrs
[] = {
696 &sys_reipl_fcp_device_attr
.attr
,
697 &sys_reipl_fcp_wwpn_attr
.attr
,
698 &sys_reipl_fcp_lun_attr
.attr
,
699 &sys_reipl_fcp_bootprog_attr
.attr
,
700 &sys_reipl_fcp_br_lba_attr
.attr
,
701 &sys_reipl_fcp_loadparm_attr
.attr
,
705 static struct attribute_group reipl_fcp_attr_group
= {
706 .attrs
= reipl_fcp_attrs
,
707 .bin_attrs
= reipl_fcp_bin_attrs
,
710 /* CCW reipl device attributes */
711 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ccw
);
714 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
715 struct kobj_attribute
*attr
, char *page
)
717 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
720 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
721 struct kobj_attribute
*attr
,
722 const char *buf
, size_t len
)
724 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
728 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
729 struct kobj_attribute
*attr
, char *page
)
731 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
734 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
735 struct kobj_attribute
*attr
,
736 const char *buf
, size_t len
)
738 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
741 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
742 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
743 reipl_ccw_loadparm_store
);
745 static struct attribute
*reipl_ccw_attrs_vm
[] = {
746 &sys_reipl_ccw_device_attr
.attr
,
747 &sys_reipl_ccw_loadparm_attr
.attr
,
748 &sys_reipl_ccw_vmparm_attr
.attr
,
752 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
753 &sys_reipl_ccw_device_attr
.attr
,
754 &sys_reipl_ccw_loadparm_attr
.attr
,
758 static struct attribute_group reipl_ccw_attr_group_vm
= {
760 .attrs
= reipl_ccw_attrs_vm
,
763 static struct attribute_group reipl_ccw_attr_group_lpar
= {
765 .attrs
= reipl_ccw_attrs_lpar
,
769 /* NSS reipl device attributes */
770 static void reipl_get_ascii_nss_name(char *dst
,
771 struct ipl_parameter_block
*ipb
)
773 memcpy(dst
, ipb
->ccw
.nss_name
, NSS_NAME_SIZE
);
774 EBCASC(dst
, NSS_NAME_SIZE
);
775 dst
[NSS_NAME_SIZE
] = 0;
778 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
779 struct kobj_attribute
*attr
, char *page
)
781 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
783 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
784 return sprintf(page
, "%s\n", nss_name
);
787 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
788 struct kobj_attribute
*attr
,
789 const char *buf
, size_t len
)
793 /* ignore trailing newline */
795 if ((len
> 0) && (buf
[len
- 1] == '\n'))
798 if (nss_len
> NSS_NAME_SIZE
)
801 memset(reipl_block_nss
->ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
803 reipl_block_nss
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_NSS
;
804 memcpy(reipl_block_nss
->ccw
.nss_name
, buf
, nss_len
);
805 ASCEBC(reipl_block_nss
->ccw
.nss_name
, nss_len
);
806 EBC_TOUPPER(reipl_block_nss
->ccw
.nss_name
, nss_len
);
808 reipl_block_nss
->ccw
.vm_flags
&= ~IPL_PB0_CCW_VM_FLAG_NSS
;
814 static struct kobj_attribute sys_reipl_nss_name_attr
=
815 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
816 reipl_nss_name_store
);
818 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
819 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
820 reipl_nss_loadparm_store
);
822 static struct attribute
*reipl_nss_attrs
[] = {
823 &sys_reipl_nss_name_attr
.attr
,
824 &sys_reipl_nss_loadparm_attr
.attr
,
825 &sys_reipl_nss_vmparm_attr
.attr
,
829 static struct attribute_group reipl_nss_attr_group
= {
831 .attrs
= reipl_nss_attrs
,
834 void set_os_info_reipl_block(void)
836 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
837 reipl_block_actual
->hdr
.len
);
842 static int reipl_set_type(enum ipl_type type
)
844 if (!(reipl_capabilities
& type
))
849 reipl_block_actual
= reipl_block_ccw
;
852 reipl_block_actual
= reipl_block_fcp
;
855 reipl_block_actual
= reipl_block_nss
;
864 static ssize_t
reipl_type_show(struct kobject
*kobj
,
865 struct kobj_attribute
*attr
, char *page
)
867 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
870 static ssize_t
reipl_type_store(struct kobject
*kobj
,
871 struct kobj_attribute
*attr
,
872 const char *buf
, size_t len
)
876 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
877 rc
= reipl_set_type(IPL_TYPE_CCW
);
878 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
879 rc
= reipl_set_type(IPL_TYPE_FCP
);
880 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
881 rc
= reipl_set_type(IPL_TYPE_NSS
);
882 return (rc
!= 0) ? rc
: len
;
885 static struct kobj_attribute reipl_type_attr
=
886 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
888 static struct kset
*reipl_kset
;
889 static struct kset
*reipl_fcp_kset
;
891 static void __reipl_run(void *unused
)
893 switch (reipl_type
) {
895 uv_set_shared(__pa(reipl_block_ccw
));
896 diag308(DIAG308_SET
, reipl_block_ccw
);
897 uv_remove_shared(__pa(reipl_block_ccw
));
898 diag308(DIAG308_LOAD_CLEAR
, NULL
);
901 uv_set_shared(__pa(reipl_block_fcp
));
902 diag308(DIAG308_SET
, reipl_block_fcp
);
903 uv_remove_shared(__pa(reipl_block_fcp
));
904 diag308(DIAG308_LOAD_CLEAR
, NULL
);
907 uv_set_shared(__pa(reipl_block_nss
));
908 diag308(DIAG308_SET
, reipl_block_nss
);
909 uv_remove_shared(__pa(reipl_block_nss
));
910 diag308(DIAG308_LOAD_CLEAR
, NULL
);
912 case IPL_TYPE_UNKNOWN
:
913 diag308(DIAG308_LOAD_CLEAR
, NULL
);
915 case IPL_TYPE_FCP_DUMP
:
921 static void reipl_run(struct shutdown_trigger
*trigger
)
923 smp_call_ipl_cpu(__reipl_run
, NULL
);
926 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
928 ipb
->hdr
.len
= IPL_BP_CCW_LEN
;
929 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
930 ipb
->pb0_hdr
.len
= IPL_BP0_CCW_LEN
;
931 ipb
->pb0_hdr
.pbt
= IPL_PBT_CCW
;
934 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
937 /* check if read scp info worked and set loadparm */
938 if (sclp_ipl_info
.is_valid
)
939 memcpy(ipb
->ccw
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
941 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
942 memset(ipb
->ccw
.loadparm
, 0x40, LOADPARM_LEN
);
943 ipb
->ccw
.flags
= IPL_PB0_FLAG_LOADPARM
;
946 if (MACHINE_IS_VM
&& ipl_block_valid
&&
947 (ipl_block
.ccw
.vm_flags
& IPL_PB0_CCW_VM_FLAG_VP
)) {
949 ipb
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_VP
;
950 ipb
->ccw
.vm_parm_len
= ipl_block
.ccw
.vm_parm_len
;
951 memcpy(ipb
->ccw
.vm_parm
,
952 ipl_block
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
956 static int __init
reipl_nss_init(void)
963 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
964 if (!reipl_block_nss
)
967 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
971 reipl_block_ccw_init(reipl_block_nss
);
972 reipl_capabilities
|= IPL_TYPE_NSS
;
976 static int __init
reipl_ccw_init(void)
980 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
981 if (!reipl_block_ccw
)
984 rc
= sysfs_create_group(&reipl_kset
->kobj
,
985 MACHINE_IS_VM
? &reipl_ccw_attr_group_vm
986 : &reipl_ccw_attr_group_lpar
);
990 reipl_block_ccw_init(reipl_block_ccw
);
991 if (ipl_info
.type
== IPL_TYPE_CCW
) {
992 reipl_block_ccw
->ccw
.ssid
= ipl_block
.ccw
.ssid
;
993 reipl_block_ccw
->ccw
.devno
= ipl_block
.ccw
.devno
;
994 reipl_block_ccw_fill_parms(reipl_block_ccw
);
997 reipl_capabilities
|= IPL_TYPE_CCW
;
1001 static int __init
reipl_fcp_init(void)
1005 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1006 if (!reipl_block_fcp
)
1009 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1010 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1012 if (!reipl_fcp_kset
) {
1013 free_page((unsigned long) reipl_block_fcp
);
1017 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1019 kset_unregister(reipl_fcp_kset
);
1020 free_page((unsigned long) reipl_block_fcp
);
1024 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1025 memcpy(reipl_block_fcp
, &ipl_block
, sizeof(ipl_block
));
1027 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1028 * is invalid in the SCSI IPL parameter block, so take it
1029 * always from sclp_ipl_info.
1031 memcpy(reipl_block_fcp
->fcp
.loadparm
, sclp_ipl_info
.loadparm
,
1034 reipl_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
;
1035 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1036 reipl_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
;
1037 reipl_block_fcp
->fcp
.pbt
= IPL_PBT_FCP
;
1038 reipl_block_fcp
->fcp
.opt
= IPL_PB0_FCP_OPT_IPL
;
1040 reipl_capabilities
|= IPL_TYPE_FCP
;
1044 static int __init
reipl_type_init(void)
1046 enum ipl_type reipl_type
= ipl_info
.type
;
1047 struct ipl_parameter_block
*reipl_block
;
1050 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1054 * If we have an OS info reipl block, this will be used
1056 if (reipl_block
->pb0_hdr
.pbt
== IPL_PBT_FCP
) {
1057 memcpy(reipl_block_fcp
, reipl_block
, size
);
1058 reipl_type
= IPL_TYPE_FCP
;
1059 } else if (reipl_block
->pb0_hdr
.pbt
== IPL_PBT_CCW
) {
1060 memcpy(reipl_block_ccw
, reipl_block
, size
);
1061 reipl_type
= IPL_TYPE_CCW
;
1064 return reipl_set_type(reipl_type
);
1067 static int __init
reipl_init(void)
1071 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1074 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1076 kset_unregister(reipl_kset
);
1079 rc
= reipl_ccw_init();
1082 rc
= reipl_fcp_init();
1085 rc
= reipl_nss_init();
1088 return reipl_type_init();
1091 static struct shutdown_action __refdata reipl_action
= {
1092 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1098 * dump shutdown action: Dump Linux on shutdown.
1101 /* FCP dump device attributes */
1103 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1104 dump_block_fcp
->fcp
.wwpn
);
1105 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1106 dump_block_fcp
->fcp
.lun
);
1107 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1108 dump_block_fcp
->fcp
.bootprog
);
1109 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1110 dump_block_fcp
->fcp
.br_lba
);
1111 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1112 dump_block_fcp
->fcp
.devno
);
1114 static struct attribute
*dump_fcp_attrs
[] = {
1115 &sys_dump_fcp_device_attr
.attr
,
1116 &sys_dump_fcp_wwpn_attr
.attr
,
1117 &sys_dump_fcp_lun_attr
.attr
,
1118 &sys_dump_fcp_bootprog_attr
.attr
,
1119 &sys_dump_fcp_br_lba_attr
.attr
,
1123 static struct attribute_group dump_fcp_attr_group
= {
1124 .name
= IPL_FCP_STR
,
1125 .attrs
= dump_fcp_attrs
,
1128 /* CCW dump device attributes */
1129 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ccw
);
1131 static struct attribute
*dump_ccw_attrs
[] = {
1132 &sys_dump_ccw_device_attr
.attr
,
1136 static struct attribute_group dump_ccw_attr_group
= {
1137 .name
= IPL_CCW_STR
,
1138 .attrs
= dump_ccw_attrs
,
1143 static int dump_set_type(enum dump_type type
)
1145 if (!(dump_capabilities
& type
))
1151 static ssize_t
dump_type_show(struct kobject
*kobj
,
1152 struct kobj_attribute
*attr
, char *page
)
1154 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1157 static ssize_t
dump_type_store(struct kobject
*kobj
,
1158 struct kobj_attribute
*attr
,
1159 const char *buf
, size_t len
)
1163 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1164 rc
= dump_set_type(DUMP_TYPE_NONE
);
1165 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1166 rc
= dump_set_type(DUMP_TYPE_CCW
);
1167 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1168 rc
= dump_set_type(DUMP_TYPE_FCP
);
1169 return (rc
!= 0) ? rc
: len
;
1172 static struct kobj_attribute dump_type_attr
=
1173 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1175 static struct kset
*dump_kset
;
1177 static void diag308_dump(void *dump_block
)
1179 uv_set_shared(__pa(dump_block
));
1180 diag308(DIAG308_SET
, dump_block
);
1181 uv_remove_shared(__pa(dump_block
));
1183 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1185 udelay_simple(USEC_PER_SEC
);
1189 static void __dump_run(void *unused
)
1191 switch (dump_type
) {
1193 diag308_dump(dump_block_ccw
);
1196 diag308_dump(dump_block_fcp
);
1203 static void dump_run(struct shutdown_trigger
*trigger
)
1205 if (dump_type
== DUMP_TYPE_NONE
)
1208 smp_call_ipl_cpu(__dump_run
, NULL
);
1211 static int __init
dump_ccw_init(void)
1215 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1216 if (!dump_block_ccw
)
1218 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1220 free_page((unsigned long)dump_block_ccw
);
1223 dump_block_ccw
->hdr
.len
= IPL_BP_CCW_LEN
;
1224 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1225 dump_block_ccw
->ccw
.len
= IPL_BP0_CCW_LEN
;
1226 dump_block_ccw
->ccw
.pbt
= IPL_PBT_CCW
;
1227 dump_capabilities
|= DUMP_TYPE_CCW
;
1231 static int __init
dump_fcp_init(void)
1235 if (!sclp_ipl_info
.has_dump
)
1236 return 0; /* LDIPL DUMP is not installed */
1237 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1238 if (!dump_block_fcp
)
1240 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1242 free_page((unsigned long)dump_block_fcp
);
1245 dump_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
;
1246 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1247 dump_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
;
1248 dump_block_fcp
->fcp
.pbt
= IPL_PBT_FCP
;
1249 dump_block_fcp
->fcp
.opt
= IPL_PB0_FCP_OPT_DUMP
;
1250 dump_capabilities
|= DUMP_TYPE_FCP
;
1254 static int __init
dump_init(void)
1258 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1261 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1263 kset_unregister(dump_kset
);
1266 rc
= dump_ccw_init();
1269 rc
= dump_fcp_init();
1272 dump_set_type(DUMP_TYPE_NONE
);
1276 static struct shutdown_action __refdata dump_action
= {
1277 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1282 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1284 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1287 csum
= (__force
unsigned int)
1288 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1289 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1290 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1294 static struct shutdown_action __refdata dump_reipl_action
= {
1295 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1296 .fn
= dump_reipl_run
,
1300 * vmcmd shutdown action: Trigger vm command on shutdown.
1303 static char vmcmd_on_reboot
[128];
1304 static char vmcmd_on_panic
[128];
1305 static char vmcmd_on_halt
[128];
1306 static char vmcmd_on_poff
[128];
1307 static char vmcmd_on_restart
[128];
1309 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1310 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1311 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1312 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1313 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1315 static struct attribute
*vmcmd_attrs
[] = {
1316 &sys_vmcmd_on_reboot_attr
.attr
,
1317 &sys_vmcmd_on_panic_attr
.attr
,
1318 &sys_vmcmd_on_halt_attr
.attr
,
1319 &sys_vmcmd_on_poff_attr
.attr
,
1320 &sys_vmcmd_on_restart_attr
.attr
,
1324 static struct attribute_group vmcmd_attr_group
= {
1325 .attrs
= vmcmd_attrs
,
1328 static struct kset
*vmcmd_kset
;
1330 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1334 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1335 cmd
= vmcmd_on_reboot
;
1336 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1337 cmd
= vmcmd_on_panic
;
1338 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1339 cmd
= vmcmd_on_halt
;
1340 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1341 cmd
= vmcmd_on_poff
;
1342 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1343 cmd
= vmcmd_on_restart
;
1347 if (strlen(cmd
) == 0)
1349 __cpcmd(cmd
, NULL
, 0, NULL
);
1352 static int vmcmd_init(void)
1356 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1359 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1362 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1363 vmcmd_run
, vmcmd_init
};
1366 * stop shutdown action: Stop Linux on shutdown.
1369 static void stop_run(struct shutdown_trigger
*trigger
)
1371 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1372 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1377 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1382 static struct shutdown_action
*shutdown_actions_list
[] = {
1383 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1384 &vmcmd_action
, &stop_action
};
1385 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1391 static struct kset
*shutdown_actions_kset
;
1393 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1398 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1399 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1400 if (shutdown_actions_list
[i
]->init_rc
) {
1401 return shutdown_actions_list
[i
]->init_rc
;
1403 trigger
->action
= shutdown_actions_list
[i
];
1413 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1416 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1417 struct kobj_attribute
*attr
, char *page
)
1419 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1422 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1423 struct kobj_attribute
*attr
,
1424 const char *buf
, size_t len
)
1426 return set_trigger(buf
, &on_reboot_trigger
, len
);
1428 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1430 static void do_machine_restart(char *__unused
)
1433 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1436 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1440 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1442 static ssize_t
on_panic_show(struct kobject
*kobj
,
1443 struct kobj_attribute
*attr
, char *page
)
1445 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1448 static ssize_t
on_panic_store(struct kobject
*kobj
,
1449 struct kobj_attribute
*attr
,
1450 const char *buf
, size_t len
)
1452 return set_trigger(buf
, &on_panic_trigger
, len
);
1454 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1456 static void do_panic(void)
1459 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1460 stop_run(&on_panic_trigger
);
1465 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1468 static ssize_t
on_restart_show(struct kobject
*kobj
,
1469 struct kobj_attribute
*attr
, char *page
)
1471 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1474 static ssize_t
on_restart_store(struct kobject
*kobj
,
1475 struct kobj_attribute
*attr
,
1476 const char *buf
, size_t len
)
1478 return set_trigger(buf
, &on_restart_trigger
, len
);
1480 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1482 static void __do_restart(void *ignore
)
1484 __arch_local_irq_stosm(0x04); /* enable DAT */
1486 #ifdef CONFIG_CRASH_DUMP
1489 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1490 stop_run(&on_restart_trigger
);
1493 void do_restart(void)
1498 smp_call_online_cpu(__do_restart
, NULL
);
1503 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1505 static ssize_t
on_halt_show(struct kobject
*kobj
,
1506 struct kobj_attribute
*attr
, char *page
)
1508 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1511 static ssize_t
on_halt_store(struct kobject
*kobj
,
1512 struct kobj_attribute
*attr
,
1513 const char *buf
, size_t len
)
1515 return set_trigger(buf
, &on_halt_trigger
, len
);
1517 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1519 static void do_machine_halt(void)
1522 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1523 stop_run(&on_halt_trigger
);
1525 void (*_machine_halt
)(void) = do_machine_halt
;
1529 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1531 static ssize_t
on_poff_show(struct kobject
*kobj
,
1532 struct kobj_attribute
*attr
, char *page
)
1534 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1537 static ssize_t
on_poff_store(struct kobject
*kobj
,
1538 struct kobj_attribute
*attr
,
1539 const char *buf
, size_t len
)
1541 return set_trigger(buf
, &on_poff_trigger
, len
);
1543 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1545 static void do_machine_power_off(void)
1548 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1549 stop_run(&on_poff_trigger
);
1551 void (*_machine_power_off
)(void) = do_machine_power_off
;
1553 static struct attribute
*shutdown_action_attrs
[] = {
1554 &on_restart_attr
.attr
,
1555 &on_reboot_attr
.attr
,
1556 &on_panic_attr
.attr
,
1562 static struct attribute_group shutdown_action_attr_group
= {
1563 .attrs
= shutdown_action_attrs
,
1566 static void __init
shutdown_triggers_init(void)
1568 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1570 if (!shutdown_actions_kset
)
1572 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1573 &shutdown_action_attr_group
))
1577 panic("shutdown_triggers_init failed\n");
1580 static void __init
shutdown_actions_init(void)
1584 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1585 if (!shutdown_actions_list
[i
]->init
)
1587 shutdown_actions_list
[i
]->init_rc
=
1588 shutdown_actions_list
[i
]->init();
1592 static int __init
s390_ipl_init(void)
1594 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1596 sclp_early_get_ipl_info(&sclp_ipl_info
);
1598 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1599 * returned by read SCP info is invalid (contains EBCDIC blanks)
1600 * when the system has been booted via diag308. In that case we use
1601 * the value from diag308, if available.
1603 * There are also systems where diag308 store does not work in
1604 * case the system is booted from HMC. Fortunately in this case
1605 * READ SCP info provides the correct value.
1607 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 && ipl_block_valid
)
1608 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.ccw
.loadparm
, LOADPARM_LEN
);
1609 shutdown_actions_init();
1610 shutdown_triggers_init();
1614 __initcall(s390_ipl_init
);
1616 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1621 for (sx
= 0; src
[sx
] != 0; sx
++) {
1624 dst
[dx
++] = src
[sx
];
1630 static int __init
vmcmd_on_reboot_setup(char *str
)
1634 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1635 vmcmd_on_reboot
[127] = 0;
1636 on_reboot_trigger
.action
= &vmcmd_action
;
1639 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1641 static int __init
vmcmd_on_panic_setup(char *str
)
1645 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1646 vmcmd_on_panic
[127] = 0;
1647 on_panic_trigger
.action
= &vmcmd_action
;
1650 __setup("vmpanic=", vmcmd_on_panic_setup
);
1652 static int __init
vmcmd_on_halt_setup(char *str
)
1656 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1657 vmcmd_on_halt
[127] = 0;
1658 on_halt_trigger
.action
= &vmcmd_action
;
1661 __setup("vmhalt=", vmcmd_on_halt_setup
);
1663 static int __init
vmcmd_on_poff_setup(char *str
)
1667 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1668 vmcmd_on_poff
[127] = 0;
1669 on_poff_trigger
.action
= &vmcmd_action
;
1672 __setup("vmpoff=", vmcmd_on_poff_setup
);
1674 static int on_panic_notify(struct notifier_block
*self
,
1675 unsigned long event
, void *data
)
1681 static struct notifier_block on_panic_nb
= {
1682 .notifier_call
= on_panic_notify
,
1683 .priority
= INT_MIN
,
1686 void __init
setup_ipl(void)
1688 BUILD_BUG_ON(sizeof(struct ipl_parameter_block
) != PAGE_SIZE
);
1690 ipl_info
.type
= get_ipl_type();
1691 switch (ipl_info
.type
) {
1693 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_block
.ccw
.ssid
;
1694 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_block
.ccw
.devno
;
1697 case IPL_TYPE_FCP_DUMP
:
1698 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1699 ipl_info
.data
.fcp
.dev_id
.devno
= ipl_block
.fcp
.devno
;
1700 ipl_info
.data
.fcp
.wwpn
= ipl_block
.fcp
.wwpn
;
1701 ipl_info
.data
.fcp
.lun
= ipl_block
.fcp
.lun
;
1704 case IPL_TYPE_UNKNOWN
:
1705 /* We have no info to copy */
1708 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1711 void s390_reset_system(void)
1713 /* Disable prefixing */
1716 /* Disable lowcore protection */
1717 __ctl_clear_bit(0, 28);
1718 diag_dma_ops
.diag308_reset();
1721 #ifdef CONFIG_KEXEC_FILE
1723 int ipl_report_add_component(struct ipl_report
*report
, struct kexec_buf
*kbuf
,
1724 unsigned char flags
, unsigned short cert
)
1726 struct ipl_report_component
*comp
;
1728 comp
= vzalloc(sizeof(*comp
));
1731 list_add_tail(&comp
->list
, &report
->components
);
1733 comp
->entry
.addr
= kbuf
->mem
;
1734 comp
->entry
.len
= kbuf
->memsz
;
1735 comp
->entry
.flags
= flags
;
1736 comp
->entry
.certificate_index
= cert
;
1738 report
->size
+= sizeof(comp
->entry
);
1743 int ipl_report_add_certificate(struct ipl_report
*report
, void *key
,
1744 unsigned long addr
, unsigned long len
)
1746 struct ipl_report_certificate
*cert
;
1748 cert
= vzalloc(sizeof(*cert
));
1751 list_add_tail(&cert
->list
, &report
->certificates
);
1753 cert
->entry
.addr
= addr
;
1754 cert
->entry
.len
= len
;
1757 report
->size
+= sizeof(cert
->entry
);
1758 report
->size
+= cert
->entry
.len
;
1763 struct ipl_report
*ipl_report_init(struct ipl_parameter_block
*ipib
)
1765 struct ipl_report
*report
;
1767 report
= vzalloc(sizeof(*report
));
1769 return ERR_PTR(-ENOMEM
);
1771 report
->ipib
= ipib
;
1772 INIT_LIST_HEAD(&report
->components
);
1773 INIT_LIST_HEAD(&report
->certificates
);
1775 report
->size
= ALIGN(ipib
->hdr
.len
, 8);
1776 report
->size
+= sizeof(struct ipl_rl_hdr
);
1777 report
->size
+= sizeof(struct ipl_rb_components
);
1778 report
->size
+= sizeof(struct ipl_rb_certificates
);
1783 void *ipl_report_finish(struct ipl_report
*report
)
1785 struct ipl_report_certificate
*cert
;
1786 struct ipl_report_component
*comp
;
1787 struct ipl_rb_certificates
*certs
;
1788 struct ipl_parameter_block
*ipib
;
1789 struct ipl_rb_components
*comps
;
1790 struct ipl_rl_hdr
*rl_hdr
;
1793 buf
= vzalloc(report
->size
);
1795 return ERR_PTR(-ENOMEM
);
1798 memcpy(ptr
, report
->ipib
, report
->ipib
->hdr
.len
);
1800 if (ipl_secure_flag
)
1801 ipib
->hdr
.flags
|= IPL_PL_FLAG_SIPL
;
1802 ipib
->hdr
.flags
|= IPL_PL_FLAG_IPLSR
;
1803 ptr
+= report
->ipib
->hdr
.len
;
1804 ptr
= PTR_ALIGN(ptr
, 8);
1807 ptr
+= sizeof(*rl_hdr
);
1810 comps
->rbt
= IPL_RBT_COMPONENTS
;
1811 ptr
+= sizeof(*comps
);
1812 list_for_each_entry(comp
, &report
->components
, list
) {
1813 memcpy(ptr
, &comp
->entry
, sizeof(comp
->entry
));
1814 ptr
+= sizeof(comp
->entry
);
1816 comps
->len
= ptr
- (void *)comps
;
1819 certs
->rbt
= IPL_RBT_CERTIFICATES
;
1820 ptr
+= sizeof(*certs
);
1821 list_for_each_entry(cert
, &report
->certificates
, list
) {
1822 memcpy(ptr
, &cert
->entry
, sizeof(cert
->entry
));
1823 ptr
+= sizeof(cert
->entry
);
1825 certs
->len
= ptr
- (void *)certs
;
1826 rl_hdr
->len
= ptr
- (void *)rl_hdr
;
1828 list_for_each_entry(cert
, &report
->certificates
, list
) {
1829 memcpy(ptr
, cert
->key
, cert
->entry
.len
);
1830 ptr
+= cert
->entry
.len
;
1833 BUG_ON(ptr
> buf
+ report
->size
);
1837 int ipl_report_free(struct ipl_report
*report
)
1839 struct ipl_report_component
*comp
, *ncomp
;
1840 struct ipl_report_certificate
*cert
, *ncert
;
1842 list_for_each_entry_safe(comp
, ncomp
, &report
->components
, list
)
1845 list_for_each_entry_safe(cert
, ncert
, &report
->certificates
, list
)