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 struct ipl_parameter_block
__bootdata(early_ipl_block
);
123 int __bootdata(early_ipl_block_valid
);
125 static int ipl_block_valid
;
126 static struct ipl_parameter_block ipl_block
;
128 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
130 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
131 static struct ipl_parameter_block
*reipl_block_fcp
;
132 static struct ipl_parameter_block
*reipl_block_ccw
;
133 static struct ipl_parameter_block
*reipl_block_nss
;
134 static struct ipl_parameter_block
*reipl_block_actual
;
136 static int dump_capabilities
= DUMP_TYPE_NONE
;
137 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
138 static struct ipl_parameter_block
*dump_block_fcp
;
139 static struct ipl_parameter_block
*dump_block_ccw
;
141 static struct sclp_ipl_info sclp_ipl_info
;
143 static inline int __diag308(unsigned long subcode
, void *addr
)
145 register unsigned long _addr
asm("0") = (unsigned long) addr
;
146 register unsigned long _rc
asm("1") = 0;
149 " diag %0,%2,0x308\n"
152 : "+d" (_addr
), "+d" (_rc
)
153 : "d" (subcode
) : "cc", "memory");
157 int diag308(unsigned long subcode
, void *addr
)
159 if (IS_ENABLED(CONFIG_KASAN
))
160 __arch_local_irq_stosm(0x04); /* enable DAT */
161 diag_stat_inc(DIAG_STAT_X308
);
162 return __diag308(subcode
, addr
);
164 EXPORT_SYMBOL_GPL(diag308
);
168 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
169 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
170 struct kobj_attribute *attr, \
173 return snprintf(page, PAGE_SIZE, _format, ##args); \
176 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
177 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
178 struct kobj_attribute *attr, \
179 const char *buf, size_t len) \
181 unsigned long long ssid, devno; \
183 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
186 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
189 _ipl_blk.ssid = ssid; \
190 _ipl_blk.devno = devno; \
194 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
195 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
196 _ipl_blk.ssid, _ipl_blk.devno); \
197 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
198 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
199 __ATTR(_name, (S_IRUGO | S_IWUSR), \
200 sys_##_prefix##_##_name##_show, \
201 sys_##_prefix##_##_name##_store) \
203 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
204 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
205 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
206 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
208 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
209 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
210 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
211 struct kobj_attribute *attr, \
212 const char *buf, size_t len) \
214 unsigned long long value; \
215 if (sscanf(buf, _fmt_in, &value) != 1) \
220 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
221 __ATTR(_name,(S_IRUGO | S_IWUSR), \
222 sys_##_prefix##_##_name##_show, \
223 sys_##_prefix##_##_name##_store)
225 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
226 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
227 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
228 struct kobj_attribute *attr, \
229 const char *buf, size_t len) \
231 strncpy(_value, buf, sizeof(_value) - 1); \
235 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
236 __ATTR(_name,(S_IRUGO | S_IWUSR), \
237 sys_##_prefix##_##_name##_show, \
238 sys_##_prefix##_##_name##_store)
244 static __init
enum ipl_type
get_ipl_type(void)
246 if (!ipl_block_valid
)
247 return IPL_TYPE_UNKNOWN
;
249 switch (ipl_block
.hdr
.pbt
) {
250 case DIAG308_IPL_TYPE_CCW
:
252 case DIAG308_IPL_TYPE_FCP
:
253 if (ipl_block
.ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
254 return IPL_TYPE_FCP_DUMP
;
258 return IPL_TYPE_UNKNOWN
;
261 struct ipl_info ipl_info
;
262 EXPORT_SYMBOL_GPL(ipl_info
);
264 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
267 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
270 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
272 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
273 struct kobj_attribute
*attr
, char *page
)
275 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
277 if (ipl_block_valid
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
278 ipl_block_get_ascii_vmparm(parm
, sizeof(parm
), &ipl_block
);
279 return sprintf(page
, "%s\n", parm
);
282 static struct kobj_attribute sys_ipl_vm_parm_attr
=
283 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
285 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
286 struct kobj_attribute
*attr
, char *page
)
288 switch (ipl_info
.type
) {
290 return sprintf(page
, "0.%x.%04x\n", ipl_block
.ipl_info
.ccw
.ssid
,
291 ipl_block
.ipl_info
.ccw
.devno
);
293 case IPL_TYPE_FCP_DUMP
:
294 return sprintf(page
, "0.0.%04x\n",
295 ipl_block
.ipl_info
.fcp
.devno
);
301 static struct kobj_attribute sys_ipl_device_attr
=
302 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
304 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
305 struct bin_attribute
*attr
, char *buf
,
306 loff_t off
, size_t count
)
308 return memory_read_from_buffer(buf
, count
, &off
, &ipl_block
,
311 static struct bin_attribute ipl_parameter_attr
=
312 __BIN_ATTR(binary_parameter
, S_IRUGO
, ipl_parameter_read
, NULL
,
315 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
316 struct bin_attribute
*attr
, char *buf
,
317 loff_t off
, size_t count
)
319 unsigned int size
= ipl_block
.ipl_info
.fcp
.scp_data_len
;
320 void *scp_data
= &ipl_block
.ipl_info
.fcp
.scp_data
;
322 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
324 static struct bin_attribute ipl_scp_data_attr
=
325 __BIN_ATTR(scp_data
, S_IRUGO
, ipl_scp_data_read
, NULL
, PAGE_SIZE
);
327 static struct bin_attribute
*ipl_fcp_bin_attrs
[] = {
333 /* FCP ipl device attributes */
335 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n",
336 (unsigned long long)ipl_block
.ipl_info
.fcp
.wwpn
);
337 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n",
338 (unsigned long long)ipl_block
.ipl_info
.fcp
.lun
);
339 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n",
340 (unsigned long long)ipl_block
.ipl_info
.fcp
.bootprog
);
341 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n",
342 (unsigned long long)ipl_block
.ipl_info
.fcp
.br_lba
);
344 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
345 struct kobj_attribute
*attr
, char *page
)
347 char loadparm
[LOADPARM_LEN
+ 1] = {};
349 if (!sclp_ipl_info
.is_valid
)
350 return sprintf(page
, "#unknown#\n");
351 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
352 EBCASC(loadparm
, LOADPARM_LEN
);
354 return sprintf(page
, "%s\n", loadparm
);
357 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
358 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
360 static struct attribute
*ipl_fcp_attrs
[] = {
361 &sys_ipl_type_attr
.attr
,
362 &sys_ipl_device_attr
.attr
,
363 &sys_ipl_fcp_wwpn_attr
.attr
,
364 &sys_ipl_fcp_lun_attr
.attr
,
365 &sys_ipl_fcp_bootprog_attr
.attr
,
366 &sys_ipl_fcp_br_lba_attr
.attr
,
367 &sys_ipl_ccw_loadparm_attr
.attr
,
371 static struct attribute_group ipl_fcp_attr_group
= {
372 .attrs
= ipl_fcp_attrs
,
373 .bin_attrs
= ipl_fcp_bin_attrs
,
376 /* CCW ipl device attributes */
378 static struct attribute
*ipl_ccw_attrs_vm
[] = {
379 &sys_ipl_type_attr
.attr
,
380 &sys_ipl_device_attr
.attr
,
381 &sys_ipl_ccw_loadparm_attr
.attr
,
382 &sys_ipl_vm_parm_attr
.attr
,
386 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
387 &sys_ipl_type_attr
.attr
,
388 &sys_ipl_device_attr
.attr
,
389 &sys_ipl_ccw_loadparm_attr
.attr
,
393 static struct attribute_group ipl_ccw_attr_group_vm
= {
394 .attrs
= ipl_ccw_attrs_vm
,
397 static struct attribute_group ipl_ccw_attr_group_lpar
= {
398 .attrs
= ipl_ccw_attrs_lpar
401 /* UNKNOWN ipl device attributes */
403 static struct attribute
*ipl_unknown_attrs
[] = {
404 &sys_ipl_type_attr
.attr
,
408 static struct attribute_group ipl_unknown_attr_group
= {
409 .attrs
= ipl_unknown_attrs
,
412 static struct kset
*ipl_kset
;
414 static void __ipl_run(void *unused
)
417 diag308(DIAG308_LOAD_CLEAR
, NULL
);
420 static void ipl_run(struct shutdown_trigger
*trigger
)
422 smp_call_ipl_cpu(__ipl_run
, NULL
);
425 static int __init
ipl_init(void)
429 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
434 switch (ipl_info
.type
) {
437 rc
= sysfs_create_group(&ipl_kset
->kobj
,
438 &ipl_ccw_attr_group_vm
);
440 rc
= sysfs_create_group(&ipl_kset
->kobj
,
441 &ipl_ccw_attr_group_lpar
);
444 case IPL_TYPE_FCP_DUMP
:
445 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
448 rc
= sysfs_create_group(&ipl_kset
->kobj
,
449 &ipl_unknown_attr_group
);
454 panic("ipl_init failed: rc = %i\n", rc
);
459 static struct shutdown_action __refdata ipl_action
= {
460 .name
= SHUTDOWN_ACTION_IPL_STR
,
466 * reipl shutdown action: Reboot Linux on shutdown.
469 /* VM IPL PARM attributes */
470 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
473 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
475 ipl_block_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
476 return sprintf(page
, "%s\n", vmparm
);
479 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
481 const char *buf
, size_t len
)
485 /* ignore trailing newline */
487 if ((len
> 0) && (buf
[len
- 1] == '\n'))
490 if (ip_len
> vmparm_max
)
493 /* parm is used to store kernel options, check for common chars */
494 for (i
= 0; i
< ip_len
; i
++)
495 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
498 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
499 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
501 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
502 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
503 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
505 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
512 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
513 struct kobj_attribute
*attr
, char *page
)
515 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
518 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
519 struct kobj_attribute
*attr
,
520 const char *buf
, size_t len
)
522 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
526 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
527 struct kobj_attribute
*attr
, char *page
)
529 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
532 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
533 struct kobj_attribute
*attr
,
534 const char *buf
, size_t len
)
536 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
539 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
540 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
541 reipl_nss_vmparm_store
);
542 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
543 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
544 reipl_ccw_vmparm_store
);
546 /* FCP reipl device attributes */
548 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
549 struct bin_attribute
*attr
,
550 char *buf
, loff_t off
, size_t count
)
552 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
553 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
555 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
558 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
559 struct bin_attribute
*attr
,
560 char *buf
, loff_t off
, size_t count
)
562 size_t scpdata_len
= count
;
569 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
, count
);
570 if (scpdata_len
% 8) {
571 padding
= 8 - (scpdata_len
% 8);
572 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
574 scpdata_len
+= padding
;
577 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
578 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
579 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
583 static struct bin_attribute sys_reipl_fcp_scp_data_attr
=
584 __BIN_ATTR(scp_data
, (S_IRUGO
| S_IWUSR
), reipl_fcp_scpdata_read
,
585 reipl_fcp_scpdata_write
, DIAG308_SCPDATA_SIZE
);
587 static struct bin_attribute
*reipl_fcp_bin_attrs
[] = {
588 &sys_reipl_fcp_scp_data_attr
,
592 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
593 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
594 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%llx\n",
595 reipl_block_fcp
->ipl_info
.fcp
.lun
);
596 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
597 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
598 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
599 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
600 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
601 reipl_block_fcp
->ipl_info
.fcp
.devno
);
603 static void reipl_get_ascii_loadparm(char *loadparm
,
604 struct ipl_parameter_block
*ibp
)
606 memcpy(loadparm
, ibp
->hdr
.loadparm
, LOADPARM_LEN
);
607 EBCASC(loadparm
, LOADPARM_LEN
);
608 loadparm
[LOADPARM_LEN
] = 0;
612 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
615 char buf
[LOADPARM_LEN
+ 1];
617 reipl_get_ascii_loadparm(buf
, ipb
);
618 return sprintf(page
, "%s\n", buf
);
621 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
622 const char *buf
, size_t len
)
626 /* ignore trailing newline */
628 if ((len
> 0) && (buf
[len
- 1] == '\n'))
630 /* loadparm can have max 8 characters and must not start with a blank */
631 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
633 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
634 for (i
= 0; i
< lp_len
; i
++) {
635 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
640 /* initialize loadparm with blanks */
641 memset(ipb
->hdr
.loadparm
, ' ', LOADPARM_LEN
);
642 /* copy and convert to ebcdic */
643 memcpy(ipb
->hdr
.loadparm
, buf
, lp_len
);
644 ASCEBC(ipb
->hdr
.loadparm
, LOADPARM_LEN
);
645 ipb
->hdr
.flags
|= DIAG308_FLAGS_LP_VALID
;
650 static ssize_t
reipl_fcp_loadparm_show(struct kobject
*kobj
,
651 struct kobj_attribute
*attr
, char *page
)
653 return reipl_generic_loadparm_show(reipl_block_fcp
, page
);
656 static ssize_t
reipl_fcp_loadparm_store(struct kobject
*kobj
,
657 struct kobj_attribute
*attr
,
658 const char *buf
, size_t len
)
660 return reipl_generic_loadparm_store(reipl_block_fcp
, buf
, len
);
663 static struct kobj_attribute sys_reipl_fcp_loadparm_attr
=
664 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_fcp_loadparm_show
,
665 reipl_fcp_loadparm_store
);
667 static struct attribute
*reipl_fcp_attrs
[] = {
668 &sys_reipl_fcp_device_attr
.attr
,
669 &sys_reipl_fcp_wwpn_attr
.attr
,
670 &sys_reipl_fcp_lun_attr
.attr
,
671 &sys_reipl_fcp_bootprog_attr
.attr
,
672 &sys_reipl_fcp_br_lba_attr
.attr
,
673 &sys_reipl_fcp_loadparm_attr
.attr
,
677 static struct attribute_group reipl_fcp_attr_group
= {
678 .attrs
= reipl_fcp_attrs
,
679 .bin_attrs
= reipl_fcp_bin_attrs
,
682 /* CCW reipl device attributes */
683 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw
, device
, reipl_block_ccw
->ipl_info
.ccw
);
686 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
687 struct kobj_attribute
*attr
, char *page
)
689 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
692 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
693 struct kobj_attribute
*attr
,
694 const char *buf
, size_t len
)
696 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
700 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
701 struct kobj_attribute
*attr
, char *page
)
703 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
706 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
707 struct kobj_attribute
*attr
,
708 const char *buf
, size_t len
)
710 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
713 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
714 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
715 reipl_ccw_loadparm_store
);
717 static struct attribute
*reipl_ccw_attrs_vm
[] = {
718 &sys_reipl_ccw_device_attr
.attr
,
719 &sys_reipl_ccw_loadparm_attr
.attr
,
720 &sys_reipl_ccw_vmparm_attr
.attr
,
724 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
725 &sys_reipl_ccw_device_attr
.attr
,
726 &sys_reipl_ccw_loadparm_attr
.attr
,
730 static struct attribute_group reipl_ccw_attr_group_vm
= {
732 .attrs
= reipl_ccw_attrs_vm
,
735 static struct attribute_group reipl_ccw_attr_group_lpar
= {
737 .attrs
= reipl_ccw_attrs_lpar
,
741 /* NSS reipl device attributes */
742 static void reipl_get_ascii_nss_name(char *dst
,
743 struct ipl_parameter_block
*ipb
)
745 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
746 EBCASC(dst
, NSS_NAME_SIZE
);
747 dst
[NSS_NAME_SIZE
] = 0;
750 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
751 struct kobj_attribute
*attr
, char *page
)
753 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
755 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
756 return sprintf(page
, "%s\n", nss_name
);
759 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
760 struct kobj_attribute
*attr
,
761 const char *buf
, size_t len
)
765 /* ignore trailing newline */
767 if ((len
> 0) && (buf
[len
- 1] == '\n'))
770 if (nss_len
> NSS_NAME_SIZE
)
773 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
775 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
776 DIAG308_VM_FLAGS_NSS_VALID
;
777 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
778 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
779 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
781 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
782 ~DIAG308_VM_FLAGS_NSS_VALID
;
788 static struct kobj_attribute sys_reipl_nss_name_attr
=
789 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
790 reipl_nss_name_store
);
792 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
793 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
794 reipl_nss_loadparm_store
);
796 static struct attribute
*reipl_nss_attrs
[] = {
797 &sys_reipl_nss_name_attr
.attr
,
798 &sys_reipl_nss_loadparm_attr
.attr
,
799 &sys_reipl_nss_vmparm_attr
.attr
,
803 static struct attribute_group reipl_nss_attr_group
= {
805 .attrs
= reipl_nss_attrs
,
808 void set_os_info_reipl_block(void)
810 os_info_entry_add(OS_INFO_REIPL_BLOCK
, reipl_block_actual
,
811 reipl_block_actual
->hdr
.len
);
816 static int reipl_set_type(enum ipl_type type
)
818 if (!(reipl_capabilities
& type
))
823 reipl_block_actual
= reipl_block_ccw
;
826 reipl_block_actual
= reipl_block_fcp
;
829 reipl_block_actual
= reipl_block_nss
;
838 static ssize_t
reipl_type_show(struct kobject
*kobj
,
839 struct kobj_attribute
*attr
, char *page
)
841 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
844 static ssize_t
reipl_type_store(struct kobject
*kobj
,
845 struct kobj_attribute
*attr
,
846 const char *buf
, size_t len
)
850 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
851 rc
= reipl_set_type(IPL_TYPE_CCW
);
852 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
853 rc
= reipl_set_type(IPL_TYPE_FCP
);
854 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
855 rc
= reipl_set_type(IPL_TYPE_NSS
);
856 return (rc
!= 0) ? rc
: len
;
859 static struct kobj_attribute reipl_type_attr
=
860 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
862 static struct kset
*reipl_kset
;
863 static struct kset
*reipl_fcp_kset
;
865 static void __reipl_run(void *unused
)
867 switch (reipl_type
) {
869 diag308(DIAG308_SET
, reipl_block_ccw
);
870 diag308(DIAG308_LOAD_CLEAR
, NULL
);
873 diag308(DIAG308_SET
, reipl_block_fcp
);
874 diag308(DIAG308_LOAD_CLEAR
, NULL
);
877 diag308(DIAG308_SET
, reipl_block_nss
);
878 diag308(DIAG308_LOAD_CLEAR
, NULL
);
880 case IPL_TYPE_UNKNOWN
:
881 diag308(DIAG308_LOAD_CLEAR
, NULL
);
883 case IPL_TYPE_FCP_DUMP
:
886 disabled_wait((unsigned long) __builtin_return_address(0));
889 static void reipl_run(struct shutdown_trigger
*trigger
)
891 smp_call_ipl_cpu(__reipl_run
, NULL
);
894 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
896 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
897 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
898 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
899 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
902 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
905 /* check if read scp info worked and set loadparm */
906 if (sclp_ipl_info
.is_valid
)
907 memcpy(ipb
->hdr
.loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
909 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
910 memset(ipb
->hdr
.loadparm
, 0x40, LOADPARM_LEN
);
911 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
914 if (MACHINE_IS_VM
&& ipl_block_valid
&&
915 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
917 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
918 ipb
->ipl_info
.ccw
.vm_parm_len
=
919 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
920 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
921 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
925 static int __init
reipl_nss_init(void)
932 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
933 if (!reipl_block_nss
)
936 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
940 reipl_block_ccw_init(reipl_block_nss
);
941 reipl_capabilities
|= IPL_TYPE_NSS
;
945 static int __init
reipl_ccw_init(void)
949 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
950 if (!reipl_block_ccw
)
953 rc
= sysfs_create_group(&reipl_kset
->kobj
,
954 MACHINE_IS_VM
? &reipl_ccw_attr_group_vm
955 : &reipl_ccw_attr_group_lpar
);
959 reipl_block_ccw_init(reipl_block_ccw
);
960 if (ipl_info
.type
== IPL_TYPE_CCW
) {
961 reipl_block_ccw
->ipl_info
.ccw
.ssid
= ipl_block
.ipl_info
.ccw
.ssid
;
962 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_block
.ipl_info
.ccw
.devno
;
963 reipl_block_ccw_fill_parms(reipl_block_ccw
);
966 reipl_capabilities
|= IPL_TYPE_CCW
;
970 static int __init
reipl_fcp_init(void)
974 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
975 if (!reipl_block_fcp
)
978 /* sysfs: create fcp kset for mixing attr group and bin attrs */
979 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
981 if (!reipl_fcp_kset
) {
982 free_page((unsigned long) reipl_block_fcp
);
986 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
988 kset_unregister(reipl_fcp_kset
);
989 free_page((unsigned long) reipl_block_fcp
);
993 if (ipl_info
.type
== IPL_TYPE_FCP
) {
994 memcpy(reipl_block_fcp
, &ipl_block
, sizeof(ipl_block
));
996 * Fix loadparm: There are systems where the (SCSI) LOADPARM
997 * is invalid in the SCSI IPL parameter block, so take it
998 * always from sclp_ipl_info.
1000 memcpy(reipl_block_fcp
->hdr
.loadparm
, sclp_ipl_info
.loadparm
,
1003 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1004 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1005 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1006 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1007 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1009 reipl_capabilities
|= IPL_TYPE_FCP
;
1013 static int __init
reipl_type_init(void)
1015 enum ipl_type reipl_type
= ipl_info
.type
;
1016 struct ipl_parameter_block
*reipl_block
;
1019 reipl_block
= os_info_old_entry(OS_INFO_REIPL_BLOCK
, &size
);
1023 * If we have an OS info reipl block, this will be used
1025 if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_FCP
) {
1026 memcpy(reipl_block_fcp
, reipl_block
, size
);
1027 reipl_type
= IPL_TYPE_FCP
;
1028 } else if (reipl_block
->hdr
.pbt
== DIAG308_IPL_TYPE_CCW
) {
1029 memcpy(reipl_block_ccw
, reipl_block
, size
);
1030 reipl_type
= IPL_TYPE_CCW
;
1033 return reipl_set_type(reipl_type
);
1036 static int __init
reipl_init(void)
1040 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1043 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1045 kset_unregister(reipl_kset
);
1048 rc
= reipl_ccw_init();
1051 rc
= reipl_fcp_init();
1054 rc
= reipl_nss_init();
1057 return reipl_type_init();
1060 static struct shutdown_action __refdata reipl_action
= {
1061 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1067 * dump shutdown action: Dump Linux on shutdown.
1070 /* FCP dump device attributes */
1072 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%llx\n",
1073 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1074 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%llx\n",
1075 dump_block_fcp
->ipl_info
.fcp
.lun
);
1076 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1077 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1078 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1079 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1080 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1081 dump_block_fcp
->ipl_info
.fcp
.devno
);
1083 static struct attribute
*dump_fcp_attrs
[] = {
1084 &sys_dump_fcp_device_attr
.attr
,
1085 &sys_dump_fcp_wwpn_attr
.attr
,
1086 &sys_dump_fcp_lun_attr
.attr
,
1087 &sys_dump_fcp_bootprog_attr
.attr
,
1088 &sys_dump_fcp_br_lba_attr
.attr
,
1092 static struct attribute_group dump_fcp_attr_group
= {
1093 .name
= IPL_FCP_STR
,
1094 .attrs
= dump_fcp_attrs
,
1097 /* CCW dump device attributes */
1098 DEFINE_IPL_CCW_ATTR_RW(dump_ccw
, device
, dump_block_ccw
->ipl_info
.ccw
);
1100 static struct attribute
*dump_ccw_attrs
[] = {
1101 &sys_dump_ccw_device_attr
.attr
,
1105 static struct attribute_group dump_ccw_attr_group
= {
1106 .name
= IPL_CCW_STR
,
1107 .attrs
= dump_ccw_attrs
,
1112 static int dump_set_type(enum dump_type type
)
1114 if (!(dump_capabilities
& type
))
1120 static ssize_t
dump_type_show(struct kobject
*kobj
,
1121 struct kobj_attribute
*attr
, char *page
)
1123 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1126 static ssize_t
dump_type_store(struct kobject
*kobj
,
1127 struct kobj_attribute
*attr
,
1128 const char *buf
, size_t len
)
1132 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1133 rc
= dump_set_type(DUMP_TYPE_NONE
);
1134 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1135 rc
= dump_set_type(DUMP_TYPE_CCW
);
1136 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1137 rc
= dump_set_type(DUMP_TYPE_FCP
);
1138 return (rc
!= 0) ? rc
: len
;
1141 static struct kobj_attribute dump_type_attr
=
1142 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1144 static struct kset
*dump_kset
;
1146 static void diag308_dump(void *dump_block
)
1148 diag308(DIAG308_SET
, dump_block
);
1150 if (diag308(DIAG308_LOAD_NORMAL_DUMP
, NULL
) != 0x302)
1152 udelay_simple(USEC_PER_SEC
);
1156 static void __dump_run(void *unused
)
1158 switch (dump_type
) {
1160 diag308_dump(dump_block_ccw
);
1163 diag308_dump(dump_block_fcp
);
1170 static void dump_run(struct shutdown_trigger
*trigger
)
1172 if (dump_type
== DUMP_TYPE_NONE
)
1175 smp_call_ipl_cpu(__dump_run
, NULL
);
1178 static int __init
dump_ccw_init(void)
1182 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1183 if (!dump_block_ccw
)
1185 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1187 free_page((unsigned long)dump_block_ccw
);
1190 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1191 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1192 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1193 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1194 dump_capabilities
|= DUMP_TYPE_CCW
;
1198 static int __init
dump_fcp_init(void)
1202 if (!sclp_ipl_info
.has_dump
)
1203 return 0; /* LDIPL DUMP is not installed */
1204 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1205 if (!dump_block_fcp
)
1207 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1209 free_page((unsigned long)dump_block_fcp
);
1212 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1213 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1214 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1215 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1216 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1217 dump_capabilities
|= DUMP_TYPE_FCP
;
1221 static int __init
dump_init(void)
1225 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1228 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1230 kset_unregister(dump_kset
);
1233 rc
= dump_ccw_init();
1236 rc
= dump_fcp_init();
1239 dump_set_type(DUMP_TYPE_NONE
);
1243 static struct shutdown_action __refdata dump_action
= {
1244 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1249 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1251 unsigned long ipib
= (unsigned long) reipl_block_actual
;
1254 csum
= (__force
unsigned int)
1255 csum_partial(reipl_block_actual
, reipl_block_actual
->hdr
.len
, 0);
1256 mem_assign_absolute(S390_lowcore
.ipib
, ipib
);
1257 mem_assign_absolute(S390_lowcore
.ipib_checksum
, csum
);
1261 static struct shutdown_action __refdata dump_reipl_action
= {
1262 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1263 .fn
= dump_reipl_run
,
1267 * vmcmd shutdown action: Trigger vm command on shutdown.
1270 static char vmcmd_on_reboot
[128];
1271 static char vmcmd_on_panic
[128];
1272 static char vmcmd_on_halt
[128];
1273 static char vmcmd_on_poff
[128];
1274 static char vmcmd_on_restart
[128];
1276 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1277 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1278 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1279 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1280 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1282 static struct attribute
*vmcmd_attrs
[] = {
1283 &sys_vmcmd_on_reboot_attr
.attr
,
1284 &sys_vmcmd_on_panic_attr
.attr
,
1285 &sys_vmcmd_on_halt_attr
.attr
,
1286 &sys_vmcmd_on_poff_attr
.attr
,
1287 &sys_vmcmd_on_restart_attr
.attr
,
1291 static struct attribute_group vmcmd_attr_group
= {
1292 .attrs
= vmcmd_attrs
,
1295 static struct kset
*vmcmd_kset
;
1297 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1301 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1302 cmd
= vmcmd_on_reboot
;
1303 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1304 cmd
= vmcmd_on_panic
;
1305 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1306 cmd
= vmcmd_on_halt
;
1307 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1308 cmd
= vmcmd_on_poff
;
1309 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1310 cmd
= vmcmd_on_restart
;
1314 if (strlen(cmd
) == 0)
1316 __cpcmd(cmd
, NULL
, 0, NULL
);
1319 static int vmcmd_init(void)
1323 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1326 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1329 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1330 vmcmd_run
, vmcmd_init
};
1333 * stop shutdown action: Stop Linux on shutdown.
1336 static void stop_run(struct shutdown_trigger
*trigger
)
1338 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1339 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1340 disabled_wait((unsigned long) __builtin_return_address(0));
1344 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1349 static struct shutdown_action
*shutdown_actions_list
[] = {
1350 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1351 &vmcmd_action
, &stop_action
};
1352 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1358 static struct kset
*shutdown_actions_kset
;
1360 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1365 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1366 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1367 if (shutdown_actions_list
[i
]->init_rc
) {
1368 return shutdown_actions_list
[i
]->init_rc
;
1370 trigger
->action
= shutdown_actions_list
[i
];
1380 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1383 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1384 struct kobj_attribute
*attr
, char *page
)
1386 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1389 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1390 struct kobj_attribute
*attr
,
1391 const char *buf
, size_t len
)
1393 return set_trigger(buf
, &on_reboot_trigger
, len
);
1395 static struct kobj_attribute on_reboot_attr
= __ATTR_RW(on_reboot
);
1397 static void do_machine_restart(char *__unused
)
1400 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1403 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1407 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1409 static ssize_t
on_panic_show(struct kobject
*kobj
,
1410 struct kobj_attribute
*attr
, char *page
)
1412 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1415 static ssize_t
on_panic_store(struct kobject
*kobj
,
1416 struct kobj_attribute
*attr
,
1417 const char *buf
, size_t len
)
1419 return set_trigger(buf
, &on_panic_trigger
, len
);
1421 static struct kobj_attribute on_panic_attr
= __ATTR_RW(on_panic
);
1423 static void do_panic(void)
1426 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1427 stop_run(&on_panic_trigger
);
1432 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1435 static ssize_t
on_restart_show(struct kobject
*kobj
,
1436 struct kobj_attribute
*attr
, char *page
)
1438 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1441 static ssize_t
on_restart_store(struct kobject
*kobj
,
1442 struct kobj_attribute
*attr
,
1443 const char *buf
, size_t len
)
1445 return set_trigger(buf
, &on_restart_trigger
, len
);
1447 static struct kobj_attribute on_restart_attr
= __ATTR_RW(on_restart
);
1449 static void __do_restart(void *ignore
)
1451 __arch_local_irq_stosm(0x04); /* enable DAT */
1453 #ifdef CONFIG_CRASH_DUMP
1456 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1457 stop_run(&on_restart_trigger
);
1460 void do_restart(void)
1465 smp_call_online_cpu(__do_restart
, NULL
);
1470 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1472 static ssize_t
on_halt_show(struct kobject
*kobj
,
1473 struct kobj_attribute
*attr
, char *page
)
1475 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1478 static ssize_t
on_halt_store(struct kobject
*kobj
,
1479 struct kobj_attribute
*attr
,
1480 const char *buf
, size_t len
)
1482 return set_trigger(buf
, &on_halt_trigger
, len
);
1484 static struct kobj_attribute on_halt_attr
= __ATTR_RW(on_halt
);
1486 static void do_machine_halt(void)
1489 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1490 stop_run(&on_halt_trigger
);
1492 void (*_machine_halt
)(void) = do_machine_halt
;
1496 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1498 static ssize_t
on_poff_show(struct kobject
*kobj
,
1499 struct kobj_attribute
*attr
, char *page
)
1501 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1504 static ssize_t
on_poff_store(struct kobject
*kobj
,
1505 struct kobj_attribute
*attr
,
1506 const char *buf
, size_t len
)
1508 return set_trigger(buf
, &on_poff_trigger
, len
);
1510 static struct kobj_attribute on_poff_attr
= __ATTR_RW(on_poff
);
1512 static void do_machine_power_off(void)
1515 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1516 stop_run(&on_poff_trigger
);
1518 void (*_machine_power_off
)(void) = do_machine_power_off
;
1520 static struct attribute
*shutdown_action_attrs
[] = {
1521 &on_restart_attr
.attr
,
1522 &on_reboot_attr
.attr
,
1523 &on_panic_attr
.attr
,
1529 static struct attribute_group shutdown_action_attr_group
= {
1530 .attrs
= shutdown_action_attrs
,
1533 static void __init
shutdown_triggers_init(void)
1535 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1537 if (!shutdown_actions_kset
)
1539 if (sysfs_create_group(&shutdown_actions_kset
->kobj
,
1540 &shutdown_action_attr_group
))
1544 panic("shutdown_triggers_init failed\n");
1547 static void __init
shutdown_actions_init(void)
1551 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1552 if (!shutdown_actions_list
[i
]->init
)
1554 shutdown_actions_list
[i
]->init_rc
=
1555 shutdown_actions_list
[i
]->init();
1559 static int __init
s390_ipl_init(void)
1561 char str
[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1563 sclp_early_get_ipl_info(&sclp_ipl_info
);
1565 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1566 * returned by read SCP info is invalid (contains EBCDIC blanks)
1567 * when the system has been booted via diag308. In that case we use
1568 * the value from diag308, if available.
1570 * There are also systems where diag308 store does not work in
1571 * case the system is booted from HMC. Fortunately in this case
1572 * READ SCP info provides the correct value.
1574 if (memcmp(sclp_ipl_info
.loadparm
, str
, sizeof(str
)) == 0 && ipl_block_valid
)
1575 memcpy(sclp_ipl_info
.loadparm
, ipl_block
.hdr
.loadparm
, LOADPARM_LEN
);
1576 shutdown_actions_init();
1577 shutdown_triggers_init();
1581 __initcall(s390_ipl_init
);
1583 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1588 for (sx
= 0; src
[sx
] != 0; sx
++) {
1591 dst
[dx
++] = src
[sx
];
1597 static int __init
vmcmd_on_reboot_setup(char *str
)
1601 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1602 vmcmd_on_reboot
[127] = 0;
1603 on_reboot_trigger
.action
= &vmcmd_action
;
1606 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1608 static int __init
vmcmd_on_panic_setup(char *str
)
1612 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1613 vmcmd_on_panic
[127] = 0;
1614 on_panic_trigger
.action
= &vmcmd_action
;
1617 __setup("vmpanic=", vmcmd_on_panic_setup
);
1619 static int __init
vmcmd_on_halt_setup(char *str
)
1623 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1624 vmcmd_on_halt
[127] = 0;
1625 on_halt_trigger
.action
= &vmcmd_action
;
1628 __setup("vmhalt=", vmcmd_on_halt_setup
);
1630 static int __init
vmcmd_on_poff_setup(char *str
)
1634 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1635 vmcmd_on_poff
[127] = 0;
1636 on_poff_trigger
.action
= &vmcmd_action
;
1639 __setup("vmpoff=", vmcmd_on_poff_setup
);
1641 static int on_panic_notify(struct notifier_block
*self
,
1642 unsigned long event
, void *data
)
1648 static struct notifier_block on_panic_nb
= {
1649 .notifier_call
= on_panic_notify
,
1650 .priority
= INT_MIN
,
1653 void __init
setup_ipl(void)
1655 BUILD_BUG_ON(sizeof(struct ipl_parameter_block
) != PAGE_SIZE
);
1657 ipl_info
.type
= get_ipl_type();
1658 switch (ipl_info
.type
) {
1660 ipl_info
.data
.ccw
.dev_id
.ssid
= ipl_block
.ipl_info
.ccw
.ssid
;
1661 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_block
.ipl_info
.ccw
.devno
;
1664 case IPL_TYPE_FCP_DUMP
:
1665 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1666 ipl_info
.data
.fcp
.dev_id
.devno
= ipl_block
.ipl_info
.fcp
.devno
;
1667 ipl_info
.data
.fcp
.wwpn
= ipl_block
.ipl_info
.fcp
.wwpn
;
1668 ipl_info
.data
.fcp
.lun
= ipl_block
.ipl_info
.fcp
.lun
;
1671 case IPL_TYPE_UNKNOWN
:
1672 /* We have no info to copy */
1675 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1678 void __init
ipl_store_parameters(void)
1680 if (early_ipl_block_valid
) {
1681 memcpy(&ipl_block
, &early_ipl_block
, sizeof(ipl_block
));
1682 ipl_block_valid
= 1;
1686 void s390_reset_system(void)
1688 /* Disable prefixing */
1691 /* Disable lowcore protection */
1692 __ctl_clear_bit(0, 28);