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 bool reipl_fcp_clear
;
148 static bool reipl_ccw_clear
;
150 static inline int __diag308(unsigned long subcode
, void *addr
)
152 register unsigned long _addr
asm("0") = (unsigned long) addr
;
153 register unsigned long _rc
asm("1") = 0;
156 " diag %0,%2,0x308\n"
159 : "+d" (_addr
), "+d" (_rc
)
160 : "d" (subcode
) : "cc", "memory");
164 int diag308(unsigned long subcode
, void *addr
)
166 if (IS_ENABLED(CONFIG_KASAN
))
167 __arch_local_irq_stosm(0x04); /* enable DAT */
168 diag_stat_inc(DIAG_STAT_X308
);
169 return __diag308(subcode
, addr
);
171 EXPORT_SYMBOL_GPL(diag308
);
175 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
176 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
177 struct kobj_attribute *attr, \
180 return snprintf(page, PAGE_SIZE, _format, ##args); \
183 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
184 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
185 struct kobj_attribute *attr, \
186 const char *buf, size_t len) \
188 unsigned long long ssid, devno; \
190 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
193 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
196 _ipl_blk.ssid = ssid; \
197 _ipl_blk.devno = devno; \
201 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
202 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
203 _ipl_blk.ssid, _ipl_blk.devno); \
204 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
205 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
206 __ATTR(_name, (S_IRUGO | S_IWUSR), \
207 sys_##_prefix##_##_name##_show, \
208 sys_##_prefix##_##_name##_store) \
210 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
211 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
212 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
213 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
215 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
216 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
217 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
218 struct kobj_attribute *attr, \
219 const char *buf, size_t len) \
221 unsigned long long value; \
222 if (sscanf(buf, _fmt_in, &value) != 1) \
227 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
228 __ATTR(_name,(S_IRUGO | S_IWUSR), \
229 sys_##_prefix##_##_name##_show, \
230 sys_##_prefix##_##_name##_store)
232 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
233 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
234 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
235 struct kobj_attribute *attr, \
236 const char *buf, size_t len) \
238 strncpy(_value, buf, sizeof(_value) - 1); \
242 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
243 __ATTR(_name,(S_IRUGO | S_IWUSR), \
244 sys_##_prefix##_##_name##_show, \
245 sys_##_prefix##_##_name##_store)
251 static __init
enum ipl_type
get_ipl_type(void)
253 if (!ipl_block_valid
)
254 return IPL_TYPE_UNKNOWN
;
256 switch (ipl_block
.pb0_hdr
.pbt
) {
260 if (ipl_block
.fcp
.opt
== IPL_PB0_FCP_OPT_DUMP
)
261 return IPL_TYPE_FCP_DUMP
;
265 return IPL_TYPE_UNKNOWN
;
268 struct ipl_info ipl_info
;
269 EXPORT_SYMBOL_GPL(ipl_info
);
271 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
274 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
277 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
279 static ssize_t
ipl_secure_show(struct kobject
*kobj
,
280 struct kobj_attribute
*attr
, char *page
)
282 return sprintf(page
, "%i\n", !!ipl_secure_flag
);
285 static struct kobj_attribute sys_ipl_secure_attr
=
286 __ATTR(secure
, 0444, ipl_secure_show
, NULL
);
288 static ssize_t
ipl_has_secure_show(struct kobject
*kobj
,
289 struct kobj_attribute
*attr
, char *page
)
291 return sprintf(page
, "%i\n", !!sclp
.has_sipl
);
294 static struct kobj_attribute sys_ipl_has_secure_attr
=
295 __ATTR(has_secure
, 0444, ipl_has_secure_show
, NULL
);
297 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
298 struct kobj_attribute
*attr
, char *page
)
300 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
302 if (ipl_block_valid
&& (ipl_block
.pb0_hdr
.pbt
== IPL_PBT_CCW
))
303 ipl_block_get_ascii_vmparm(parm
, sizeof(parm
), &ipl_block
);
304 return sprintf(page
, "%s\n", parm
);
307 static struct kobj_attribute sys_ipl_vm_parm_attr
=
308 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
310 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
311 struct kobj_attribute
*attr
, char *page
)
313 switch (ipl_info
.type
) {
315 return sprintf(page
, "0.%x.%04x\n", ipl_block
.ccw
.ssid
,
316 ipl_block
.ccw
.devno
);
318 case IPL_TYPE_FCP_DUMP
:
319 return sprintf(page
, "0.0.%04x\n", ipl_block
.fcp
.devno
);
325 static struct kobj_attribute sys_ipl_device_attr
=
326 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
328 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
329 struct bin_attribute
*attr
, char *buf
,
330 loff_t off
, size_t count
)
332 return memory_read_from_buffer(buf
, count
, &off
, &ipl_block
,
335 static struct bin_attribute ipl_parameter_attr
=
336 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
339 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
340 struct bin_attribute
*attr
, char *buf
,
341 loff_t off
, size_t count
)
343 unsigned int size
= ipl_block
.fcp
.scp_data_len
;
344 void *scp_data
= &ipl_block
.fcp
.scp_data
;
346 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
348 static struct bin_attribute ipl_scp_data_attr
=
349 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
351 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
357 /* FCP ipl device attributes */
359 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n",
360 (unsigned long long)ipl_block
.fcp
.wwpn
);
361 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n",
362 (unsigned long long)ipl_block
.fcp
.lun
);
363 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n",
364 (unsigned long long)ipl_block
.fcp
.bootprog
);
365 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n",
366 (unsigned long long)ipl_block
.fcp
.br_lba
);
368 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
369 struct kobj_attribute
*attr
, char *page
)
371 char loadparm
[LOADPARM_LEN
+ 1] = {};
373 if (!sclp_ipl_info
.is_valid
)
374 return sprintf(page
, "#unknown#\n");
375 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
376 EBCASC(loadparm
, LOADPARM_LEN
);
378 return sprintf(page
, "%s\n", loadparm
);
381 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
382 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
384 static struct attribute
*ipl_fcp_attrs
[] = {
385 &sys_ipl_type_attr
.attr
,
386 &sys_ipl_device_attr
.attr
,
387 &sys_ipl_fcp_wwpn_attr
.attr
,
388 &sys_ipl_fcp_lun_attr
.attr
,
389 &sys_ipl_fcp_bootprog_attr
.attr
,
390 &sys_ipl_fcp_br_lba_attr
.attr
,
391 &sys_ipl_ccw_loadparm_attr
.attr
,
392 &sys_ipl_secure_attr
.attr
,
393 &sys_ipl_has_secure_attr
.attr
,
397 static struct attribute_group ipl_fcp_attr_group
= {
398 .attrs
= ipl_fcp_attrs
,
399 .bin_attrs
= ipl_fcp_bin_attrs
,
402 /* CCW ipl device attributes */
404 static struct attribute
*ipl_ccw_attrs_vm
[] = {
405 &sys_ipl_type_attr
.attr
,
406 &sys_ipl_device_attr
.attr
,
407 &sys_ipl_ccw_loadparm_attr
.attr
,
408 &sys_ipl_vm_parm_attr
.attr
,
409 &sys_ipl_secure_attr
.attr
,
410 &sys_ipl_has_secure_attr
.attr
,
414 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
415 &sys_ipl_type_attr
.attr
,
416 &sys_ipl_device_attr
.attr
,
417 &sys_ipl_ccw_loadparm_attr
.attr
,
418 &sys_ipl_secure_attr
.attr
,
419 &sys_ipl_has_secure_attr
.attr
,
423 static struct attribute_group ipl_ccw_attr_group_vm
= {
424 .attrs
= ipl_ccw_attrs_vm
,
427 static struct attribute_group ipl_ccw_attr_group_lpar
= {
428 .attrs
= ipl_ccw_attrs_lpar
431 /* UNKNOWN ipl device attributes */
433 static struct attribute
*ipl_unknown_attrs
[] = {
434 &sys_ipl_type_attr
.attr
,
438 static struct attribute_group ipl_unknown_attr_group
= {
439 .attrs
= ipl_unknown_attrs
,
442 static struct kset
*ipl_kset
;
444 static void __ipl_run(void *unused
)
447 diag308(DIAG308_LOAD_CLEAR
, NULL
);
450 static void ipl_run(struct shutdown_trigger
*trigger
)
452 smp_call_ipl_cpu(__ipl_run
, NULL
);
455 static int __init
ipl_init(void)
459 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
464 switch (ipl_info
.type
) {
467 rc
= sysfs_create_group(&ipl_kset
->kobj
,
468 &ipl_ccw_attr_group_vm
);
470 rc
= sysfs_create_group(&ipl_kset
->kobj
,
471 &ipl_ccw_attr_group_lpar
);
474 case IPL_TYPE_FCP_DUMP
:
475 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
478 rc
= sysfs_create_group(&ipl_kset
->kobj
,
479 &ipl_unknown_attr_group
);
484 panic("ipl_init failed: rc = %i\n", rc
);
489 static struct shutdown_action __refdata ipl_action
= {
490 .name
= SHUTDOWN_ACTION_IPL_STR
,
496 * reipl shutdown action: Reboot Linux on shutdown.
499 /* VM IPL PARM attributes */
500 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
503 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
505 ipl_block_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
506 return sprintf(page
, "%s\n", vmparm
);
509 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
511 const char *buf
, size_t len
)
515 /* ignore trailing newline */
517 if ((len
> 0) && (buf
[len
- 1] == '\n'))
520 if (ip_len
> vmparm_max
)
523 /* parm is used to store kernel options, check for common chars */
524 for (i
= 0; i
< ip_len
; i
++)
525 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
528 memset(ipb
->ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
529 ipb
->ccw
.vm_parm_len
= ip_len
;
531 ipb
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_VP
;
532 memcpy(ipb
->ccw
.vm_parm
, buf
, ip_len
);
533 ASCEBC(ipb
->ccw
.vm_parm
, ip_len
);
535 ipb
->ccw
.vm_flags
&= ~IPL_PB0_CCW_VM_FLAG_VP
;
542 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
543 struct kobj_attribute
*attr
, char *page
)
545 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
548 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
549 struct kobj_attribute
*attr
,
550 const char *buf
, size_t len
)
552 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
556 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
557 struct kobj_attribute
*attr
, char *page
)
559 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
562 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
563 struct kobj_attribute
*attr
,
564 const char *buf
, size_t len
)
566 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
569 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
570 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
571 reipl_nss_vmparm_store
);
572 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
573 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
574 reipl_ccw_vmparm_store
);
576 /* FCP reipl device attributes */
578 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
579 struct bin_attribute
*attr
,
580 char *buf
, loff_t off
, size_t count
)
582 size_t size
= reipl_block_fcp
->fcp
.scp_data_len
;
583 void *scp_data
= reipl_block_fcp
->fcp
.scp_data
;
585 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
588 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
589 struct bin_attribute
*attr
,
590 char *buf
, loff_t off
, size_t count
)
592 size_t scpdata_len
= count
;
599 memcpy(reipl_block_fcp
->fcp
.scp_data
, buf
, count
);
600 if (scpdata_len
% 8) {
601 padding
= 8 - (scpdata_len
% 8);
602 memset(reipl_block_fcp
->fcp
.scp_data
+ scpdata_len
,
604 scpdata_len
+= padding
;
607 reipl_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
+ scpdata_len
;
608 reipl_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
+ scpdata_len
;
609 reipl_block_fcp
->fcp
.scp_data_len
= scpdata_len
;
613 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
614 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
615 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
617 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
618 &sys_reipl_fcp_scp_data_attr
,
622 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
623 reipl_block_fcp
->fcp
.wwpn
);
624 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
625 reipl_block_fcp
->fcp
.lun
);
626 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
627 reipl_block_fcp
->fcp
.bootprog
);
628 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
629 reipl_block_fcp
->fcp
.br_lba
);
630 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
631 reipl_block_fcp
->fcp
.devno
);
633 static void reipl_get_ascii_loadparm(char *loadparm
,
634 struct ipl_parameter_block
*ibp
)
636 memcpy(loadparm
, ibp
->common
.loadparm
, LOADPARM_LEN
);
637 EBCASC(loadparm
, LOADPARM_LEN
);
638 loadparm
[LOADPARM_LEN
] = 0;
642 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
645 char buf
[LOADPARM_LEN
+ 1];
647 reipl_get_ascii_loadparm(buf
, ipb
);
648 return sprintf(page
, "%s\n", buf
);
651 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
652 const char *buf
, size_t len
)
656 /* ignore trailing newline */
658 if ((len
> 0) && (buf
[len
- 1] == '\n'))
660 /* loadparm can have max 8 characters and must not start with a blank */
661 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
663 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
664 for (i
= 0; i
< lp_len
; i
++) {
665 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
670 /* initialize loadparm with blanks */
671 memset(ipb
->common
.loadparm
, ' ', LOADPARM_LEN
);
672 /* copy and convert to ebcdic */
673 memcpy(ipb
->common
.loadparm
, buf
, lp_len
);
674 ASCEBC(ipb
->common
.loadparm
, LOADPARM_LEN
);
675 ipb
->common
.flags
|= IPL_PB0_FLAG_LOADPARM
;
680 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
681 struct kobj_attribute
*attr
, char *page
)
683 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
686 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
687 struct kobj_attribute
*attr
,
688 const char *buf
, size_t len
)
690 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
693 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
694 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
695 reipl_fcp_loadparm_store
);
697 static ssize_t
reipl_fcp_clear_show(struct kobject
*kobj
,
698 struct kobj_attribute
*attr
, char *page
)
700 return sprintf(page
, "%u\n", reipl_fcp_clear
);
703 static ssize_t
reipl_fcp_clear_store(struct kobject
*kobj
,
704 struct kobj_attribute
*attr
,
705 const char *buf
, size_t len
)
707 if (strtobool(buf
, &reipl_fcp_clear
) < 0)
712 static struct attribute
*reipl_fcp_attrs
[] = {
713 &sys_reipl_fcp_device_attr
.attr
,
714 &sys_reipl_fcp_wwpn_attr
.attr
,
715 &sys_reipl_fcp_lun_attr
.attr
,
716 &sys_reipl_fcp_bootprog_attr
.attr
,
717 &sys_reipl_fcp_br_lba_attr
.attr
,
718 &sys_reipl_fcp_loadparm_attr
.attr
,
722 static struct attribute_group reipl_fcp_attr_group
= {
723 .attrs
= reipl_fcp_attrs
,
724 .bin_attrs
= reipl_fcp_bin_attrs
,
727 static struct kobj_attribute sys_reipl_fcp_clear_attr
=
728 __ATTR(clear
, 0644, reipl_fcp_clear_show
, reipl_fcp_clear_store
);
730 /* CCW reipl device attributes */
731 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ccw
);
734 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
735 struct kobj_attribute
*attr
, char *page
)
737 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
740 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
741 struct kobj_attribute
*attr
,
742 const char *buf
, size_t len
)
744 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
748 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
749 struct kobj_attribute
*attr
, char *page
)
751 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
754 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
755 struct kobj_attribute
*attr
,
756 const char *buf
, size_t len
)
758 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
761 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
762 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
763 reipl_ccw_loadparm_store
);
765 static ssize_t
reipl_ccw_clear_show(struct kobject
*kobj
,
766 struct kobj_attribute
*attr
, char *page
)
768 return sprintf(page
, "%u\n", reipl_ccw_clear
);
771 static ssize_t
reipl_ccw_clear_store(struct kobject
*kobj
,
772 struct kobj_attribute
*attr
,
773 const char *buf
, size_t len
)
775 if (strtobool(buf
, &reipl_ccw_clear
) < 0)
780 static struct kobj_attribute sys_reipl_ccw_clear_attr
=
781 __ATTR(clear
, 0644, reipl_ccw_clear_show
, reipl_ccw_clear_store
);
783 static struct attribute
*reipl_ccw_attrs_vm
[] = {
784 &sys_reipl_ccw_device_attr
.attr
,
785 &sys_reipl_ccw_loadparm_attr
.attr
,
786 &sys_reipl_ccw_vmparm_attr
.attr
,
787 &sys_reipl_ccw_clear_attr
.attr
,
791 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
792 &sys_reipl_ccw_device_attr
.attr
,
793 &sys_reipl_ccw_loadparm_attr
.attr
,
794 &sys_reipl_ccw_clear_attr
.attr
,
798 static struct attribute_group reipl_ccw_attr_group_vm
= {
800 .attrs
= reipl_ccw_attrs_vm
,
803 static struct attribute_group reipl_ccw_attr_group_lpar
= {
805 .attrs
= reipl_ccw_attrs_lpar
,
809 /* NSS reipl device attributes */
810 static void reipl_get_ascii_nss_name(char *dst
,
811 struct ipl_parameter_block
*ipb
)
813 memcpy(dst
, ipb
->ccw
.nss_name
, NSS_NAME_SIZE
);
814 EBCASC(dst
, NSS_NAME_SIZE
);
815 dst
[NSS_NAME_SIZE
] = 0;
818 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
819 struct kobj_attribute
*attr
, char *page
)
821 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
823 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
824 return sprintf(page
, "%s\n", nss_name
);
827 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
828 struct kobj_attribute
*attr
,
829 const char *buf
, size_t len
)
833 /* ignore trailing newline */
835 if ((len
> 0) && (buf
[len
- 1] == '\n'))
838 if (nss_len
> NSS_NAME_SIZE
)
841 memset(reipl_block_nss
->ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
843 reipl_block_nss
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_NSS
;
844 memcpy(reipl_block_nss
->ccw
.nss_name
, buf
, nss_len
);
845 ASCEBC(reipl_block_nss
->ccw
.nss_name
, nss_len
);
846 EBC_TOUPPER(reipl_block_nss
->ccw
.nss_name
, nss_len
);
848 reipl_block_nss
->ccw
.vm_flags
&= ~IPL_PB0_CCW_VM_FLAG_NSS
;
854 static struct kobj_attribute sys_reipl_nss_name_attr
=
855 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
856 reipl_nss_name_store
);
858 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
859 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
860 reipl_nss_loadparm_store
);
862 static struct attribute
*reipl_nss_attrs
[] = {
863 &sys_reipl_nss_name_attr
.attr
,
864 &sys_reipl_nss_loadparm_attr
.attr
,
865 &sys_reipl_nss_vmparm_attr
.attr
,
869 static struct attribute_group reipl_nss_attr_group
= {
871 .attrs
= reipl_nss_attrs
,
874 void set_os_info_reipl_block(void)
876 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
877 reipl_block_actual
->hdr
.len
);
882 static int reipl_set_type(enum ipl_type type
)
884 if (!(reipl_capabilities
& type
))
889 reipl_block_actual
= reipl_block_ccw
;
892 reipl_block_actual
= reipl_block_fcp
;
895 reipl_block_actual
= reipl_block_nss
;
904 static ssize_t
reipl_type_show(struct kobject
*kobj
,
905 struct kobj_attribute
*attr
, char *page
)
907 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
910 static ssize_t
reipl_type_store(struct kobject
*kobj
,
911 struct kobj_attribute
*attr
,
912 const char *buf
, size_t len
)
916 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
917 rc
= reipl_set_type(IPL_TYPE_CCW
);
918 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
919 rc
= reipl_set_type(IPL_TYPE_FCP
);
920 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
921 rc
= reipl_set_type(IPL_TYPE_NSS
);
922 return (rc
!= 0) ? rc
: len
;
925 static struct kobj_attribute reipl_type_attr
=
926 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
928 static struct kset
*reipl_kset
;
929 static struct kset
*reipl_fcp_kset
;
931 static void __reipl_run(void *unused
)
933 switch (reipl_type
) {
935 diag308(DIAG308_SET
, reipl_block_ccw
);
937 diag308(DIAG308_LOAD_CLEAR
, NULL
);
939 diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
);
942 diag308(DIAG308_SET
, reipl_block_fcp
);
944 diag308(DIAG308_LOAD_CLEAR
, NULL
);
946 diag308(DIAG308_LOAD_NORMAL
, NULL
);
949 diag308(DIAG308_SET
, reipl_block_nss
);
950 diag308(DIAG308_LOAD_CLEAR
, NULL
);
952 case IPL_TYPE_UNKNOWN
:
953 diag308(DIAG308_LOAD_CLEAR
, NULL
);
955 case IPL_TYPE_FCP_DUMP
:
961 static void reipl_run(struct shutdown_trigger
*trigger
)
963 smp_call_ipl_cpu(__reipl_run
, NULL
);
966 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
968 ipb
->hdr
.len
= IPL_BP_CCW_LEN
;
969 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
970 ipb
->pb0_hdr
.len
= IPL_BP0_CCW_LEN
;
971 ipb
->pb0_hdr
.pbt
= IPL_PBT_CCW
;
974 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
977 /* check if read scp info worked and set loadparm */
978 if (sclp_ipl_info
.is_valid
)
979 memcpy(ipb
->ccw
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
981 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
982 memset(ipb
->ccw
.loadparm
, 0x40, LOADPARM_LEN
);
983 ipb
->ccw
.flags
= IPL_PB0_FLAG_LOADPARM
;
986 if (MACHINE_IS_VM
&& ipl_block_valid
&&
987 (ipl_block
.ccw
.vm_flags
& IPL_PB0_CCW_VM_FLAG_VP
)) {
989 ipb
->ccw
.vm_flags
|= IPL_PB0_CCW_VM_FLAG_VP
;
990 ipb
->ccw
.vm_parm_len
= ipl_block
.ccw
.vm_parm_len
;
991 memcpy(ipb
->ccw
.vm_parm
,
992 ipl_block
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
996 static int __init
reipl_nss_init(void)
1003 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1004 if (!reipl_block_nss
)
1007 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1011 reipl_block_ccw_init(reipl_block_nss
);
1012 reipl_capabilities
|= IPL_TYPE_NSS
;
1016 static int __init
reipl_ccw_init(void)
1020 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1021 if (!reipl_block_ccw
)
1024 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1025 MACHINE_IS_VM
? &reipl_ccw_attr_group_vm
1026 : &reipl_ccw_attr_group_lpar
);
1030 reipl_block_ccw_init(reipl_block_ccw
);
1031 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1032 reipl_block_ccw
->ccw
.ssid
= ipl_block
.ccw
.ssid
;
1033 reipl_block_ccw
->ccw
.devno
= ipl_block
.ccw
.devno
;
1034 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1037 reipl_capabilities
|= IPL_TYPE_CCW
;
1041 static int __init
reipl_fcp_init(void)
1045 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1046 if (!reipl_block_fcp
)
1049 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1050 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1052 if (!reipl_fcp_kset
) {
1053 free_page((unsigned long) reipl_block_fcp
);
1057 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1061 if (test_facility(141)) {
1062 rc
= sysfs_create_file(&reipl_fcp_kset
->kobj
,
1063 &sys_reipl_fcp_clear_attr
.attr
);
1067 reipl_fcp_clear
= true;
1069 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1070 memcpy(reipl_block_fcp
, &ipl_block
, sizeof(ipl_block
));
1072 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1073 * is invalid in the SCSI IPL parameter block, so take it
1074 * always from sclp_ipl_info.
1076 memcpy(reipl_block_fcp
->fcp
.loadparm
, sclp_ipl_info
.loadparm
,
1079 reipl_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
;
1080 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1081 reipl_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
;
1082 reipl_block_fcp
->fcp
.pbt
= IPL_PBT_FCP
;
1083 reipl_block_fcp
->fcp
.opt
= IPL_PB0_FCP_OPT_IPL
;
1085 reipl_capabilities
|= IPL_TYPE_FCP
;
1089 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1091 kset_unregister(reipl_fcp_kset
);
1092 free_page((unsigned long) reipl_block_fcp
);
1096 static int __init
reipl_type_init(void)
1098 enum ipl_type reipl_type
= ipl_info
.type
;
1099 struct ipl_parameter_block
*reipl_block
;
1102 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1106 * If we have an OS info reipl block, this will be used
1108 if (reipl_block
->pb0_hdr
.pbt
== IPL_PBT_FCP
) {
1109 memcpy(reipl_block_fcp
, reipl_block
, size
);
1110 reipl_type
= IPL_TYPE_FCP
;
1111 } else if (reipl_block
->pb0_hdr
.pbt
== IPL_PBT_CCW
) {
1112 memcpy(reipl_block_ccw
, reipl_block
, size
);
1113 reipl_type
= IPL_TYPE_CCW
;
1116 return reipl_set_type(reipl_type
);
1119 static int __init
reipl_init(void)
1123 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1126 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1128 kset_unregister(reipl_kset
);
1131 rc
= reipl_ccw_init();
1134 rc
= reipl_fcp_init();
1137 rc
= reipl_nss_init();
1140 return reipl_type_init();
1143 static struct shutdown_action __refdata reipl_action
= {
1144 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1150 * dump shutdown action: Dump Linux on shutdown.
1153 /* FCP dump device attributes */
1155 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1156 dump_block_fcp
->fcp
.wwpn
);
1157 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1158 dump_block_fcp
->fcp
.lun
);
1159 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1160 dump_block_fcp
->fcp
.bootprog
);
1161 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1162 dump_block_fcp
->fcp
.br_lba
);
1163 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1164 dump_block_fcp
->fcp
.devno
);
1166 static struct attribute
*dump_fcp_attrs
[] = {
1167 &sys_dump_fcp_device_attr
.attr
,
1168 &sys_dump_fcp_wwpn_attr
.attr
,
1169 &sys_dump_fcp_lun_attr
.attr
,
1170 &sys_dump_fcp_bootprog_attr
.attr
,
1171 &sys_dump_fcp_br_lba_attr
.attr
,
1175 static struct attribute_group dump_fcp_attr_group
= {
1176 .name
= IPL_FCP_STR
,
1177 .attrs
= dump_fcp_attrs
,
1180 /* CCW dump device attributes */
1181 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ccw
);
1183 static struct attribute
*dump_ccw_attrs
[] = {
1184 &sys_dump_ccw_device_attr
.attr
,
1188 static struct attribute_group dump_ccw_attr_group
= {
1189 .name
= IPL_CCW_STR
,
1190 .attrs
= dump_ccw_attrs
,
1195 static int dump_set_type(enum dump_type type
)
1197 if (!(dump_capabilities
& type
))
1203 static ssize_t
dump_type_show(struct kobject
*kobj
,
1204 struct kobj_attribute
*attr
, char *page
)
1206 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1209 static ssize_t
dump_type_store(struct kobject
*kobj
,
1210 struct kobj_attribute
*attr
,
1211 const char *buf
, size_t len
)
1215 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1216 rc
= dump_set_type(DUMP_TYPE_NONE
);
1217 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1218 rc
= dump_set_type(DUMP_TYPE_CCW
);
1219 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1220 rc
= dump_set_type(DUMP_TYPE_FCP
);
1221 return (rc
!= 0) ? rc
: len
;
1224 static struct kobj_attribute dump_type_attr
=
1225 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1227 static struct kset
*dump_kset
;
1229 static void diag308_dump(void *dump_block
)
1231 diag308(DIAG308_SET
, dump_block
);
1233 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1235 udelay_simple(USEC_PER_SEC
);
1239 static void __dump_run(void *unused
)
1241 switch (dump_type
) {
1243 diag308_dump(dump_block_ccw
);
1246 diag308_dump(dump_block_fcp
);
1253 static void dump_run(struct shutdown_trigger
*trigger
)
1255 if (dump_type
== DUMP_TYPE_NONE
)
1258 smp_call_ipl_cpu(__dump_run
, NULL
);
1261 static int __init
dump_ccw_init(void)
1265 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1266 if (!dump_block_ccw
)
1268 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1270 free_page((unsigned long)dump_block_ccw
);
1273 dump_block_ccw
->hdr
.len
= IPL_BP_CCW_LEN
;
1274 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1275 dump_block_ccw
->ccw
.len
= IPL_BP0_CCW_LEN
;
1276 dump_block_ccw
->ccw
.pbt
= IPL_PBT_CCW
;
1277 dump_capabilities
|= DUMP_TYPE_CCW
;
1281 static int __init
dump_fcp_init(void)
1285 if (!sclp_ipl_info
.has_dump
)
1286 return 0; /* LDIPL DUMP is not installed */
1287 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1288 if (!dump_block_fcp
)
1290 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1292 free_page((unsigned long)dump_block_fcp
);
1295 dump_block_fcp
->hdr
.len
= IPL_BP_FCP_LEN
;
1296 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1297 dump_block_fcp
->fcp
.len
= IPL_BP0_FCP_LEN
;
1298 dump_block_fcp
->fcp
.pbt
= IPL_PBT_FCP
;
1299 dump_block_fcp
->fcp
.opt
= IPL_PB0_FCP_OPT_DUMP
;
1300 dump_capabilities
|= DUMP_TYPE_FCP
;
1304 static int __init
dump_init(void)
1308 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1311 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1313 kset_unregister(dump_kset
);
1316 rc
= dump_ccw_init();
1319 rc
= dump_fcp_init();
1322 dump_set_type(DUMP_TYPE_NONE
);
1326 static struct shutdown_action __refdata dump_action
= {
1327 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1332 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1334 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1337 csum
= (__force
unsigned int)
1338 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1339 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1340 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1344 static struct shutdown_action __refdata dump_reipl_action
= {
1345 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1346 .fn
= dump_reipl_run
,
1350 * vmcmd shutdown action: Trigger vm command on shutdown.
1353 static char vmcmd_on_reboot
[128];
1354 static char vmcmd_on_panic
[128];
1355 static char vmcmd_on_halt
[128];
1356 static char vmcmd_on_poff
[128];
1357 static char vmcmd_on_restart
[128];
1359 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1360 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1361 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1362 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1363 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1365 static struct attribute
*vmcmd_attrs
[] = {
1366 &sys_vmcmd_on_reboot_attr
.attr
,
1367 &sys_vmcmd_on_panic_attr
.attr
,
1368 &sys_vmcmd_on_halt_attr
.attr
,
1369 &sys_vmcmd_on_poff_attr
.attr
,
1370 &sys_vmcmd_on_restart_attr
.attr
,
1374 static struct attribute_group vmcmd_attr_group
= {
1375 .attrs
= vmcmd_attrs
,
1378 static struct kset
*vmcmd_kset
;
1380 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1384 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1385 cmd
= vmcmd_on_reboot
;
1386 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1387 cmd
= vmcmd_on_panic
;
1388 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1389 cmd
= vmcmd_on_halt
;
1390 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1391 cmd
= vmcmd_on_poff
;
1392 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1393 cmd
= vmcmd_on_restart
;
1397 if (strlen(cmd
) == 0)
1399 __cpcmd(cmd
, NULL
, 0, NULL
);
1402 static int vmcmd_init(void)
1406 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1409 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1412 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1413 vmcmd_run
, vmcmd_init
};
1416 * stop shutdown action: Stop Linux on shutdown.
1419 static void stop_run(struct shutdown_trigger
*trigger
)
1421 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1422 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1427 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1432 static struct shutdown_action
*shutdown_actions_list
[] = {
1433 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1434 &vmcmd_action
, &stop_action
};
1435 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1441 static struct kset
*shutdown_actions_kset
;
1443 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1448 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1449 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1450 if (shutdown_actions_list
[i
]->init_rc
) {
1451 return shutdown_actions_list
[i
]->init_rc
;
1453 trigger
->action
= shutdown_actions_list
[i
];
1463 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1466 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1467 struct kobj_attribute
*attr
, char *page
)
1469 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1472 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1473 struct kobj_attribute
*attr
,
1474 const char *buf
, size_t len
)
1476 return set_trigger(buf
, &on_reboot_trigger
, len
);
1478 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1480 static void do_machine_restart(char *__unused
)
1483 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1486 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1490 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1492 static ssize_t
on_panic_show(struct kobject
*kobj
,
1493 struct kobj_attribute
*attr
, char *page
)
1495 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1498 static ssize_t
on_panic_store(struct kobject
*kobj
,
1499 struct kobj_attribute
*attr
,
1500 const char *buf
, size_t len
)
1502 return set_trigger(buf
, &on_panic_trigger
, len
);
1504 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1506 static void do_panic(void)
1509 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1510 stop_run(&on_panic_trigger
);
1515 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1518 static ssize_t
on_restart_show(struct kobject
*kobj
,
1519 struct kobj_attribute
*attr
, char *page
)
1521 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1524 static ssize_t
on_restart_store(struct kobject
*kobj
,
1525 struct kobj_attribute
*attr
,
1526 const char *buf
, size_t len
)
1528 return set_trigger(buf
, &on_restart_trigger
, len
);
1530 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1532 static void __do_restart(void *ignore
)
1534 __arch_local_irq_stosm(0x04); /* enable DAT */
1536 #ifdef CONFIG_CRASH_DUMP
1539 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1540 stop_run(&on_restart_trigger
);
1543 void do_restart(void)
1548 smp_call_online_cpu(__do_restart
, NULL
);
1553 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1555 static ssize_t
on_halt_show(struct kobject
*kobj
,
1556 struct kobj_attribute
*attr
, char *page
)
1558 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1561 static ssize_t
on_halt_store(struct kobject
*kobj
,
1562 struct kobj_attribute
*attr
,
1563 const char *buf
, size_t len
)
1565 return set_trigger(buf
, &on_halt_trigger
, len
);
1567 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1569 static void do_machine_halt(void)
1572 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1573 stop_run(&on_halt_trigger
);
1575 void (*_machine_halt
)(void) = do_machine_halt
;
1579 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1581 static ssize_t
on_poff_show(struct kobject
*kobj
,
1582 struct kobj_attribute
*attr
, char *page
)
1584 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1587 static ssize_t
on_poff_store(struct kobject
*kobj
,
1588 struct kobj_attribute
*attr
,
1589 const char *buf
, size_t len
)
1591 return set_trigger(buf
, &on_poff_trigger
, len
);
1593 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1595 static void do_machine_power_off(void)
1598 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1599 stop_run(&on_poff_trigger
);
1601 void (*_machine_power_off
)(void) = do_machine_power_off
;
1603 static struct attribute
*shutdown_action_attrs
[] = {
1604 &on_restart_attr
.attr
,
1605 &on_reboot_attr
.attr
,
1606 &on_panic_attr
.attr
,
1612 static struct attribute_group shutdown_action_attr_group
= {
1613 .attrs
= shutdown_action_attrs
,
1616 static void __init
shutdown_triggers_init(void)
1618 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1620 if (!shutdown_actions_kset
)
1622 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1623 &shutdown_action_attr_group
))
1627 panic("shutdown_triggers_init failed\n");
1630 static void __init
shutdown_actions_init(void)
1634 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1635 if (!shutdown_actions_list
[i
]->init
)
1637 shutdown_actions_list
[i
]->init_rc
=
1638 shutdown_actions_list
[i
]->init();
1642 static int __init
s390_ipl_init(void)
1644 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1646 sclp_early_get_ipl_info(&sclp_ipl_info
);
1648 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1649 * returned by read SCP info is invalid (contains EBCDIC blanks)
1650 * when the system has been booted via diag308. In that case we use
1651 * the value from diag308, if available.
1653 * There are also systems where diag308 store does not work in
1654 * case the system is booted from HMC. Fortunately in this case
1655 * READ SCP info provides the correct value.
1657 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 && ipl_block_valid
)
1658 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.ccw
.loadparm
, LOADPARM_LEN
);
1659 shutdown_actions_init();
1660 shutdown_triggers_init();
1664 __initcall(s390_ipl_init
);
1666 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1671 for (sx
= 0; src
[sx
] != 0; sx
++) {
1674 dst
[dx
++] = src
[sx
];
1680 static int __init
vmcmd_on_reboot_setup(char *str
)
1684 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1685 vmcmd_on_reboot
[127] = 0;
1686 on_reboot_trigger
.action
= &vmcmd_action
;
1689 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1691 static int __init
vmcmd_on_panic_setup(char *str
)
1695 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1696 vmcmd_on_panic
[127] = 0;
1697 on_panic_trigger
.action
= &vmcmd_action
;
1700 __setup("vmpanic=", vmcmd_on_panic_setup
);
1702 static int __init
vmcmd_on_halt_setup(char *str
)
1706 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1707 vmcmd_on_halt
[127] = 0;
1708 on_halt_trigger
.action
= &vmcmd_action
;
1711 __setup("vmhalt=", vmcmd_on_halt_setup
);
1713 static int __init
vmcmd_on_poff_setup(char *str
)
1717 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1718 vmcmd_on_poff
[127] = 0;
1719 on_poff_trigger
.action
= &vmcmd_action
;
1722 __setup("vmpoff=", vmcmd_on_poff_setup
);
1724 static int on_panic_notify(struct notifier_block
*self
,
1725 unsigned long event
, void *data
)
1731 static struct notifier_block on_panic_nb
= {
1732 .notifier_call
= on_panic_notify
,
1733 .priority
= INT_MIN
,
1736 void __init
setup_ipl(void)
1738 BUILD_BUG_ON(sizeof(struct ipl_parameter_block
) != PAGE_SIZE
);
1740 ipl_info
.type
= get_ipl_type();
1741 switch (ipl_info
.type
) {
1743 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_block
.ccw
.ssid
;
1744 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_block
.ccw
.devno
;
1747 case IPL_TYPE_FCP_DUMP
:
1748 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1749 ipl_info
.data
.fcp
.dev_id
.devno
= ipl_block
.fcp
.devno
;
1750 ipl_info
.data
.fcp
.wwpn
= ipl_block
.fcp
.wwpn
;
1751 ipl_info
.data
.fcp
.lun
= ipl_block
.fcp
.lun
;
1754 case IPL_TYPE_UNKNOWN
:
1755 /* We have no info to copy */
1758 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1761 void s390_reset_system(void)
1763 /* Disable prefixing */
1766 /* Disable lowcore protection */
1767 __ctl_clear_bit(0, 28);
1768 diag_dma_ops
.diag308_reset();
1771 #ifdef CONFIG_KEXEC_FILE
1773 int ipl_report_add_component(struct ipl_report
*report
, struct kexec_buf
*kbuf
,
1774 unsigned char flags
, unsigned short cert
)
1776 struct ipl_report_component
*comp
;
1778 comp
= vzalloc(sizeof(*comp
));
1781 list_add_tail(&comp
->list
, &report
->components
);
1783 comp
->entry
.addr
= kbuf
->mem
;
1784 comp
->entry
.len
= kbuf
->memsz
;
1785 comp
->entry
.flags
= flags
;
1786 comp
->entry
.certificate_index
= cert
;
1788 report
->size
+= sizeof(comp
->entry
);
1793 int ipl_report_add_certificate(struct ipl_report
*report
, void *key
,
1794 unsigned long addr
, unsigned long len
)
1796 struct ipl_report_certificate
*cert
;
1798 cert
= vzalloc(sizeof(*cert
));
1801 list_add_tail(&cert
->list
, &report
->certificates
);
1803 cert
->entry
.addr
= addr
;
1804 cert
->entry
.len
= len
;
1807 report
->size
+= sizeof(cert
->entry
);
1808 report
->size
+= cert
->entry
.len
;
1813 struct ipl_report
*ipl_report_init(struct ipl_parameter_block
*ipib
)
1815 struct ipl_report
*report
;
1817 report
= vzalloc(sizeof(*report
));
1819 return ERR_PTR(-ENOMEM
);
1821 report
->ipib
= ipib
;
1822 INIT_LIST_HEAD(&report
->components
);
1823 INIT_LIST_HEAD(&report
->certificates
);
1825 report
->size
= ALIGN(ipib
->hdr
.len
, 8);
1826 report
->size
+= sizeof(struct ipl_rl_hdr
);
1827 report
->size
+= sizeof(struct ipl_rb_components
);
1828 report
->size
+= sizeof(struct ipl_rb_certificates
);
1833 void *ipl_report_finish(struct ipl_report
*report
)
1835 struct ipl_report_certificate
*cert
;
1836 struct ipl_report_component
*comp
;
1837 struct ipl_rb_certificates
*certs
;
1838 struct ipl_parameter_block
*ipib
;
1839 struct ipl_rb_components
*comps
;
1840 struct ipl_rl_hdr
*rl_hdr
;
1843 buf
= vzalloc(report
->size
);
1845 return ERR_PTR(-ENOMEM
);
1848 memcpy(ptr
, report
->ipib
, report
->ipib
->hdr
.len
);
1850 if (ipl_secure_flag
)
1851 ipib
->hdr
.flags
|= IPL_PL_FLAG_SIPL
;
1852 ipib
->hdr
.flags
|= IPL_PL_FLAG_IPLSR
;
1853 ptr
+= report
->ipib
->hdr
.len
;
1854 ptr
= PTR_ALIGN(ptr
, 8);
1857 ptr
+= sizeof(*rl_hdr
);
1860 comps
->rbt
= IPL_RBT_COMPONENTS
;
1861 ptr
+= sizeof(*comps
);
1862 list_for_each_entry(comp
, &report
->components
, list
) {
1863 memcpy(ptr
, &comp
->entry
, sizeof(comp
->entry
));
1864 ptr
+= sizeof(comp
->entry
);
1866 comps
->len
= ptr
- (void *)comps
;
1869 certs
->rbt
= IPL_RBT_CERTIFICATES
;
1870 ptr
+= sizeof(*certs
);
1871 list_for_each_entry(cert
, &report
->certificates
, list
) {
1872 memcpy(ptr
, &cert
->entry
, sizeof(cert
->entry
));
1873 ptr
+= sizeof(cert
->entry
);
1875 certs
->len
= ptr
- (void *)certs
;
1876 rl_hdr
->len
= ptr
- (void *)rl_hdr
;
1878 list_for_each_entry(cert
, &report
->certificates
, list
) {
1879 memcpy(ptr
, cert
->key
, cert
->entry
.len
);
1880 ptr
+= cert
->entry
.len
;
1883 BUG_ON(ptr
> buf
+ report
->size
);
1887 int ipl_report_free(struct ipl_report
*report
)
1889 struct ipl_report_component
*comp
, *ncomp
;
1890 struct ipl_report_certificate
*cert
, *ncert
;
1892 list_for_each_entry_safe(comp
, ncomp
, &report
->components
, list
)
1895 list_for_each_entry_safe(cert
, ncert
, &report
->certificates
, list
)