2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2007
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/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
18 #include <linux/gfp.h>
19 #include <linux/crash_dump.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
25 #include <asm/ebcdic.h>
26 #include <asm/reset.h>
29 #include <asm/checksum.h>
32 #define IPL_PARM_BLOCK_VERSION 0
34 #define IPL_UNKNOWN_STR "unknown"
35 #define IPL_CCW_STR "ccw"
36 #define IPL_FCP_STR "fcp"
37 #define IPL_FCP_DUMP_STR "fcp_dump"
38 #define IPL_NSS_STR "nss"
40 #define DUMP_CCW_STR "ccw"
41 #define DUMP_FCP_STR "fcp"
42 #define DUMP_NONE_STR "none"
45 * Four shutdown trigger types are supported:
52 #define ON_PANIC_STR "on_panic"
53 #define ON_HALT_STR "on_halt"
54 #define ON_POFF_STR "on_poff"
55 #define ON_REIPL_STR "on_reboot"
56 #define ON_RESTART_STR "on_restart"
58 struct shutdown_action
;
59 struct shutdown_trigger
{
61 struct shutdown_action
*action
;
65 * The following shutdown action types are supported:
67 #define SHUTDOWN_ACTION_IPL_STR "ipl"
68 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
69 #define SHUTDOWN_ACTION_DUMP_STR "dump"
70 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
71 #define SHUTDOWN_ACTION_STOP_STR "stop"
72 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
74 struct shutdown_action
{
76 void (*fn
) (struct shutdown_trigger
*trigger
);
81 static char *ipl_type_str(enum ipl_type type
)
88 case IPL_TYPE_FCP_DUMP
:
89 return IPL_FCP_DUMP_STR
;
92 case IPL_TYPE_UNKNOWN
:
94 return IPL_UNKNOWN_STR
;
104 static char *dump_type_str(enum dump_type type
)
108 return DUMP_NONE_STR
;
119 * Must be in data section since the bss section
120 * is not cleared when these are accessed.
122 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
123 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
126 REIPL_METHOD_CCW_CIO
,
127 REIPL_METHOD_CCW_DIAG
,
129 REIPL_METHOD_FCP_RO_DIAG
,
130 REIPL_METHOD_FCP_RW_DIAG
,
131 REIPL_METHOD_FCP_RO_VM
,
132 REIPL_METHOD_FCP_DUMP
,
134 REIPL_METHOD_NSS_DIAG
,
135 REIPL_METHOD_DEFAULT
,
141 DUMP_METHOD_CCW_DIAG
,
143 DUMP_METHOD_FCP_DIAG
,
146 static int diag308_set_works
= 0;
148 static struct ipl_parameter_block ipl_block
;
150 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
152 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
153 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
154 static struct ipl_parameter_block
*reipl_block_fcp
;
155 static struct ipl_parameter_block
*reipl_block_ccw
;
156 static struct ipl_parameter_block
*reipl_block_nss
;
157 static struct ipl_parameter_block
*reipl_block_actual
;
159 static int dump_capabilities
= DUMP_TYPE_NONE
;
160 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
161 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
162 static struct ipl_parameter_block
*dump_block_fcp
;
163 static struct ipl_parameter_block
*dump_block_ccw
;
165 static struct sclp_ipl_info sclp_ipl_info
;
167 int diag308(unsigned long subcode
, void *addr
)
169 register unsigned long _addr
asm("0") = (unsigned long) addr
;
170 register unsigned long _rc
asm("1") = 0;
173 " diag %0,%2,0x308\n"
176 : "+d" (_addr
), "+d" (_rc
)
177 : "d" (subcode
) : "cc", "memory");
180 EXPORT_SYMBOL_GPL(diag308
);
184 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
185 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
186 struct kobj_attribute *attr, \
189 return sprintf(page, _format, _value); \
191 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
192 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
194 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
195 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
196 struct kobj_attribute *attr, \
199 return sprintf(page, _fmt_out, \
200 (unsigned long long) _value); \
202 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
203 struct kobj_attribute *attr, \
204 const char *buf, size_t len) \
206 unsigned long long value; \
207 if (sscanf(buf, _fmt_in, &value) != 1) \
212 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
213 __ATTR(_name,(S_IRUGO | S_IWUSR), \
214 sys_##_prefix##_##_name##_show, \
215 sys_##_prefix##_##_name##_store);
217 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
218 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
219 struct kobj_attribute *attr, \
222 return sprintf(page, _fmt_out, _value); \
224 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
225 struct kobj_attribute *attr, \
226 const char *buf, size_t len) \
228 strncpy(_value, buf, sizeof(_value) - 1); \
232 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
233 __ATTR(_name,(S_IRUGO | S_IWUSR), \
234 sys_##_prefix##_##_name##_show, \
235 sys_##_prefix##_##_name##_store);
237 static void make_attrs_ro(struct attribute
**attrs
)
240 (*attrs
)->mode
= S_IRUGO
;
249 static __init
enum ipl_type
get_ipl_type(void)
251 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
253 if (ipl_flags
& IPL_NSS_VALID
)
255 if (!(ipl_flags
& IPL_DEVNO_VALID
))
256 return IPL_TYPE_UNKNOWN
;
257 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
259 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
260 return IPL_TYPE_UNKNOWN
;
261 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
262 return IPL_TYPE_UNKNOWN
;
263 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
264 return IPL_TYPE_FCP_DUMP
;
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 /* VM IPL PARM routines */
280 static size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
281 const struct ipl_parameter_block
*ipb
)
285 char has_lowercase
= 0;
288 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
289 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
291 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
292 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
293 /* If at least one character is lowercase, we assume mixed
294 * case; otherwise we convert everything to lowercase.
296 for (i
= 0; i
< len
; i
++)
297 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
298 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
299 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
304 EBC_TOLOWER(dest
, len
);
312 size_t append_ipl_vmparm(char *dest
, size_t size
)
317 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
318 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
324 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
325 struct kobj_attribute
*attr
, char *page
)
327 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
329 append_ipl_vmparm(parm
, sizeof(parm
));
330 return sprintf(page
, "%s\n", parm
);
333 static size_t scpdata_length(const char* buf
, size_t count
)
336 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
343 static size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
344 const struct ipl_parameter_block
*ipb
)
350 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
351 ipb
->ipl_info
.fcp
.scp_data_len
));
356 for (i
= 0; i
< count
; i
++) {
357 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
361 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
366 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
368 for (i
= 0; i
< count
; i
++)
369 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
375 size_t append_ipl_scpdata(char *dest
, size_t len
)
380 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
381 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
388 static struct kobj_attribute sys_ipl_vm_parm_attr
=
389 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
391 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
392 struct kobj_attribute
*attr
, char *page
)
394 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
396 switch (ipl_info
.type
) {
398 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
400 case IPL_TYPE_FCP_DUMP
:
401 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
407 static struct kobj_attribute sys_ipl_device_attr
=
408 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
410 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
411 struct bin_attribute
*attr
, char *buf
,
412 loff_t off
, size_t count
)
414 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
418 static struct bin_attribute ipl_parameter_attr
= {
420 .name
= "binary_parameter",
424 .read
= &ipl_parameter_read
,
427 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
428 struct bin_attribute
*attr
, char *buf
,
429 loff_t off
, size_t count
)
431 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
432 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
434 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
437 static struct bin_attribute ipl_scp_data_attr
= {
443 .read
= ipl_scp_data_read
,
446 /* FCP ipl device attributes */
448 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
449 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
450 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
451 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
452 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
453 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
454 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
455 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
457 static struct attribute
*ipl_fcp_attrs
[] = {
458 &sys_ipl_type_attr
.attr
,
459 &sys_ipl_device_attr
.attr
,
460 &sys_ipl_fcp_wwpn_attr
.attr
,
461 &sys_ipl_fcp_lun_attr
.attr
,
462 &sys_ipl_fcp_bootprog_attr
.attr
,
463 &sys_ipl_fcp_br_lba_attr
.attr
,
467 static struct attribute_group ipl_fcp_attr_group
= {
468 .attrs
= ipl_fcp_attrs
,
471 /* CCW ipl device attributes */
473 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
474 struct kobj_attribute
*attr
, char *page
)
476 char loadparm
[LOADPARM_LEN
+ 1] = {};
478 if (!sclp_ipl_info
.is_valid
)
479 return sprintf(page
, "#unknown#\n");
480 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
481 EBCASC(loadparm
, LOADPARM_LEN
);
483 return sprintf(page
, "%s\n", loadparm
);
486 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
487 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
489 static struct attribute
*ipl_ccw_attrs_vm
[] = {
490 &sys_ipl_type_attr
.attr
,
491 &sys_ipl_device_attr
.attr
,
492 &sys_ipl_ccw_loadparm_attr
.attr
,
493 &sys_ipl_vm_parm_attr
.attr
,
497 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
498 &sys_ipl_type_attr
.attr
,
499 &sys_ipl_device_attr
.attr
,
500 &sys_ipl_ccw_loadparm_attr
.attr
,
504 static struct attribute_group ipl_ccw_attr_group_vm
= {
505 .attrs
= ipl_ccw_attrs_vm
,
508 static struct attribute_group ipl_ccw_attr_group_lpar
= {
509 .attrs
= ipl_ccw_attrs_lpar
512 /* NSS ipl device attributes */
514 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
516 static struct attribute
*ipl_nss_attrs
[] = {
517 &sys_ipl_type_attr
.attr
,
518 &sys_ipl_nss_name_attr
.attr
,
519 &sys_ipl_ccw_loadparm_attr
.attr
,
520 &sys_ipl_vm_parm_attr
.attr
,
524 static struct attribute_group ipl_nss_attr_group
= {
525 .attrs
= ipl_nss_attrs
,
528 /* UNKNOWN ipl device attributes */
530 static struct attribute
*ipl_unknown_attrs
[] = {
531 &sys_ipl_type_attr
.attr
,
535 static struct attribute_group ipl_unknown_attr_group
= {
536 .attrs
= ipl_unknown_attrs
,
539 static struct kset
*ipl_kset
;
541 static int __init
ipl_register_fcp_files(void)
545 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
548 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
551 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
555 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
558 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
563 static void __ipl_run(void *unused
)
565 diag308(DIAG308_IPL
, NULL
);
567 __cpcmd("IPL", NULL
, 0, NULL
);
568 else if (ipl_info
.type
== IPL_TYPE_CCW
)
569 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
572 static void ipl_run(struct shutdown_trigger
*trigger
)
574 smp_switch_to_ipl_cpu(__ipl_run
, NULL
);
577 static int __init
ipl_init(void)
581 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
586 switch (ipl_info
.type
) {
589 rc
= sysfs_create_group(&ipl_kset
->kobj
,
590 &ipl_ccw_attr_group_vm
);
592 rc
= sysfs_create_group(&ipl_kset
->kobj
,
593 &ipl_ccw_attr_group_lpar
);
596 case IPL_TYPE_FCP_DUMP
:
597 rc
= ipl_register_fcp_files();
600 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
603 rc
= sysfs_create_group(&ipl_kset
->kobj
,
604 &ipl_unknown_attr_group
);
609 panic("ipl_init failed: rc = %i\n", rc
);
614 static struct shutdown_action __refdata ipl_action
= {
615 .name
= SHUTDOWN_ACTION_IPL_STR
,
621 * reipl shutdown action: Reboot Linux on shutdown.
624 /* VM IPL PARM attributes */
625 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
628 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
630 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
631 return sprintf(page
, "%s\n", vmparm
);
634 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
636 const char *buf
, size_t len
)
640 /* ignore trailing newline */
642 if ((len
> 0) && (buf
[len
- 1] == '\n'))
645 if (ip_len
> vmparm_max
)
648 /* parm is used to store kernel options, check for common chars */
649 for (i
= 0; i
< ip_len
; i
++)
650 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
653 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
654 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
656 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
657 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
658 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
660 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
667 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
668 struct kobj_attribute
*attr
, char *page
)
670 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
673 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
674 struct kobj_attribute
*attr
,
675 const char *buf
, size_t len
)
677 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
681 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
682 struct kobj_attribute
*attr
, char *page
)
684 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
687 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
688 struct kobj_attribute
*attr
,
689 const char *buf
, size_t len
)
691 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
694 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
695 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
696 reipl_nss_vmparm_store
);
697 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
698 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
699 reipl_ccw_vmparm_store
);
701 /* FCP reipl device attributes */
703 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
704 struct bin_attribute
*attr
,
705 char *buf
, loff_t off
, size_t count
)
707 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
708 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
710 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
713 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
714 struct bin_attribute
*attr
,
715 char *buf
, loff_t off
, size_t count
)
723 if (off
>= DIAG308_SCPDATA_SIZE
)
726 if (count
> DIAG308_SCPDATA_SIZE
- off
)
727 count
= DIAG308_SCPDATA_SIZE
- off
;
729 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
730 scpdata_len
= off
+ count
;
732 if (scpdata_len
% 8) {
733 padding
= 8 - (scpdata_len
% 8);
734 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
736 scpdata_len
+= padding
;
739 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
740 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
741 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
746 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
749 .mode
= S_IRUGO
| S_IWUSR
,
752 .read
= reipl_fcp_scpdata_read
,
753 .write
= reipl_fcp_scpdata_write
,
756 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
757 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
758 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
759 reipl_block_fcp
->ipl_info
.fcp
.lun
);
760 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
761 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
762 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
763 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
764 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
765 reipl_block_fcp
->ipl_info
.fcp
.devno
);
767 static struct attribute
*reipl_fcp_attrs
[] = {
768 &sys_reipl_fcp_device_attr
.attr
,
769 &sys_reipl_fcp_wwpn_attr
.attr
,
770 &sys_reipl_fcp_lun_attr
.attr
,
771 &sys_reipl_fcp_bootprog_attr
.attr
,
772 &sys_reipl_fcp_br_lba_attr
.attr
,
776 static struct attribute_group reipl_fcp_attr_group
= {
777 .attrs
= reipl_fcp_attrs
,
780 /* CCW reipl device attributes */
782 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
783 reipl_block_ccw
->ipl_info
.ccw
.devno
);
785 static void reipl_get_ascii_loadparm(char *loadparm
,
786 struct ipl_parameter_block
*ibp
)
788 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
789 EBCASC(loadparm
, LOADPARM_LEN
);
790 loadparm
[LOADPARM_LEN
] = 0;
794 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
797 char buf
[LOADPARM_LEN
+ 1];
799 reipl_get_ascii_loadparm(buf
, ipb
);
800 return sprintf(page
, "%s\n", buf
);
803 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
804 const char *buf
, size_t len
)
808 /* ignore trailing newline */
810 if ((len
> 0) && (buf
[len
- 1] == '\n'))
812 /* loadparm can have max 8 characters and must not start with a blank */
813 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
815 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
816 for (i
= 0; i
< lp_len
; i
++) {
817 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
822 /* initialize loadparm with blanks */
823 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
824 /* copy and convert to ebcdic */
825 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
826 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
831 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
832 struct kobj_attribute
*attr
, char *page
)
834 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
837 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
838 struct kobj_attribute
*attr
,
839 const char *buf
, size_t len
)
841 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
845 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
846 struct kobj_attribute
*attr
, char *page
)
848 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
851 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
852 struct kobj_attribute
*attr
,
853 const char *buf
, size_t len
)
855 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
858 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
859 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
860 reipl_ccw_loadparm_store
);
862 static struct attribute
*reipl_ccw_attrs_vm
[] = {
863 &sys_reipl_ccw_device_attr
.attr
,
864 &sys_reipl_ccw_loadparm_attr
.attr
,
865 &sys_reipl_ccw_vmparm_attr
.attr
,
869 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
870 &sys_reipl_ccw_device_attr
.attr
,
871 &sys_reipl_ccw_loadparm_attr
.attr
,
875 static struct attribute_group reipl_ccw_attr_group_vm
= {
877 .attrs
= reipl_ccw_attrs_vm
,
880 static struct attribute_group reipl_ccw_attr_group_lpar
= {
882 .attrs
= reipl_ccw_attrs_lpar
,
886 /* NSS reipl device attributes */
887 static void reipl_get_ascii_nss_name(char *dst
,
888 struct ipl_parameter_block
*ipb
)
890 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
891 EBCASC(dst
, NSS_NAME_SIZE
);
892 dst
[NSS_NAME_SIZE
] = 0;
895 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
896 struct kobj_attribute
*attr
, char *page
)
898 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
900 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
901 return sprintf(page
, "%s\n", nss_name
);
904 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
905 struct kobj_attribute
*attr
,
906 const char *buf
, size_t len
)
910 /* ignore trailing newline */
912 if ((len
> 0) && (buf
[len
- 1] == '\n'))
915 if (nss_len
> NSS_NAME_SIZE
)
918 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
920 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
921 DIAG308_VM_FLAGS_NSS_VALID
;
922 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
923 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
924 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
926 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
927 ~DIAG308_VM_FLAGS_NSS_VALID
;
933 static struct kobj_attribute sys_reipl_nss_name_attr
=
934 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
935 reipl_nss_name_store
);
937 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
938 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
939 reipl_nss_loadparm_store
);
941 static struct attribute
*reipl_nss_attrs
[] = {
942 &sys_reipl_nss_name_attr
.attr
,
943 &sys_reipl_nss_loadparm_attr
.attr
,
944 &sys_reipl_nss_vmparm_attr
.attr
,
948 static struct attribute_group reipl_nss_attr_group
= {
950 .attrs
= reipl_nss_attrs
,
955 static int reipl_set_type(enum ipl_type type
)
957 if (!(reipl_capabilities
& type
))
962 if (diag308_set_works
)
963 reipl_method
= REIPL_METHOD_CCW_DIAG
;
964 else if (MACHINE_IS_VM
)
965 reipl_method
= REIPL_METHOD_CCW_VM
;
967 reipl_method
= REIPL_METHOD_CCW_CIO
;
968 reipl_block_actual
= reipl_block_ccw
;
971 if (diag308_set_works
)
972 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
973 else if (MACHINE_IS_VM
)
974 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
976 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
977 reipl_block_actual
= reipl_block_fcp
;
979 case IPL_TYPE_FCP_DUMP
:
980 reipl_method
= REIPL_METHOD_FCP_DUMP
;
983 if (diag308_set_works
)
984 reipl_method
= REIPL_METHOD_NSS_DIAG
;
986 reipl_method
= REIPL_METHOD_NSS
;
987 reipl_block_actual
= reipl_block_nss
;
989 case IPL_TYPE_UNKNOWN
:
990 reipl_method
= REIPL_METHOD_DEFAULT
;
999 static ssize_t
reipl_type_show(struct kobject
*kobj
,
1000 struct kobj_attribute
*attr
, char *page
)
1002 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1005 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1006 struct kobj_attribute
*attr
,
1007 const char *buf
, size_t len
)
1011 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1012 rc
= reipl_set_type(IPL_TYPE_CCW
);
1013 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1014 rc
= reipl_set_type(IPL_TYPE_FCP
);
1015 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1016 rc
= reipl_set_type(IPL_TYPE_NSS
);
1017 return (rc
!= 0) ? rc
: len
;
1020 static struct kobj_attribute reipl_type_attr
=
1021 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1023 static struct kset
*reipl_kset
;
1024 static struct kset
*reipl_fcp_kset
;
1026 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1027 const enum ipl_method m
)
1029 char loadparm
[LOADPARM_LEN
+ 1] = {};
1030 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1031 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1034 reipl_get_ascii_loadparm(loadparm
, ipb
);
1035 reipl_get_ascii_nss_name(nss_name
, ipb
);
1036 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1039 case REIPL_METHOD_CCW_VM
:
1040 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1042 case REIPL_METHOD_NSS
:
1043 pos
= sprintf(dst
, "IPL %s", nss_name
);
1048 if (strlen(loadparm
) > 0)
1049 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1050 if (strlen(vmparm
) > 0)
1051 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1054 static void __reipl_run(void *unused
)
1056 struct ccw_dev_id devid
;
1057 static char buf
[128];
1059 switch (reipl_method
) {
1060 case REIPL_METHOD_CCW_CIO
:
1061 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1063 reipl_ccw_dev(&devid
);
1065 case REIPL_METHOD_CCW_VM
:
1066 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1067 __cpcmd(buf
, NULL
, 0, NULL
);
1069 case REIPL_METHOD_CCW_DIAG
:
1070 diag308(DIAG308_SET
, reipl_block_ccw
);
1071 diag308(DIAG308_IPL
, NULL
);
1073 case REIPL_METHOD_FCP_RW_DIAG
:
1074 diag308(DIAG308_SET
, reipl_block_fcp
);
1075 diag308(DIAG308_IPL
, NULL
);
1077 case REIPL_METHOD_FCP_RO_DIAG
:
1078 diag308(DIAG308_IPL
, NULL
);
1080 case REIPL_METHOD_FCP_RO_VM
:
1081 __cpcmd("IPL", NULL
, 0, NULL
);
1083 case REIPL_METHOD_NSS_DIAG
:
1084 diag308(DIAG308_SET
, reipl_block_nss
);
1085 diag308(DIAG308_IPL
, NULL
);
1087 case REIPL_METHOD_NSS
:
1088 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1089 __cpcmd(buf
, NULL
, 0, NULL
);
1091 case REIPL_METHOD_DEFAULT
:
1093 __cpcmd("IPL", NULL
, 0, NULL
);
1094 diag308(DIAG308_IPL
, NULL
);
1096 case REIPL_METHOD_FCP_DUMP
:
1099 disabled_wait((unsigned long) __builtin_return_address(0));
1102 static void reipl_run(struct shutdown_trigger
*trigger
)
1104 smp_switch_to_ipl_cpu(__reipl_run
, NULL
);
1107 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1109 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1110 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1111 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1112 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1115 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1118 /* check if read scp info worked and set loadparm */
1119 if (sclp_ipl_info
.is_valid
)
1120 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
1121 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1123 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1124 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
1125 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1128 if (MACHINE_IS_VM
&& diag308_set_works
&&
1129 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1131 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1132 ipb
->ipl_info
.ccw
.vm_parm_len
=
1133 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1134 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1135 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1139 static int __init
reipl_nss_init(void)
1146 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1147 if (!reipl_block_nss
)
1150 if (!diag308_set_works
)
1151 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1153 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1157 reipl_block_ccw_init(reipl_block_nss
);
1158 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1159 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1160 ' ', NSS_NAME_SIZE
);
1161 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1162 kernel_nss_name
, strlen(kernel_nss_name
));
1163 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1164 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1165 DIAG308_VM_FLAGS_NSS_VALID
;
1167 reipl_block_ccw_fill_parms(reipl_block_nss
);
1170 reipl_capabilities
|= IPL_TYPE_NSS
;
1174 static int __init
reipl_ccw_init(void)
1178 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1179 if (!reipl_block_ccw
)
1182 if (MACHINE_IS_VM
) {
1183 if (!diag308_set_works
)
1184 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1185 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1186 &reipl_ccw_attr_group_vm
);
1188 if(!diag308_set_works
)
1189 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1190 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1191 &reipl_ccw_attr_group_lpar
);
1196 reipl_block_ccw_init(reipl_block_ccw
);
1197 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1198 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1199 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1202 reipl_capabilities
|= IPL_TYPE_CCW
;
1206 static int __init
reipl_fcp_init(void)
1210 if (!diag308_set_works
) {
1211 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1212 make_attrs_ro(reipl_fcp_attrs
);
1213 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1218 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1219 if (!reipl_block_fcp
)
1222 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1223 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1225 if (!reipl_fcp_kset
) {
1226 free_page((unsigned long) reipl_block_fcp
);
1230 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1232 kset_unregister(reipl_fcp_kset
);
1233 free_page((unsigned long) reipl_block_fcp
);
1237 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1238 &sys_reipl_fcp_scp_data_attr
);
1240 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1241 kset_unregister(reipl_fcp_kset
);
1242 free_page((unsigned long) reipl_block_fcp
);
1246 if (ipl_info
.type
== IPL_TYPE_FCP
)
1247 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1249 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1250 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1251 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1252 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1253 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1255 reipl_capabilities
|= IPL_TYPE_FCP
;
1259 static int __init
reipl_init(void)
1263 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1266 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1268 kset_unregister(reipl_kset
);
1271 rc
= reipl_ccw_init();
1274 rc
= reipl_fcp_init();
1277 rc
= reipl_nss_init();
1280 rc
= reipl_set_type(ipl_info
.type
);
1286 static struct shutdown_action __refdata reipl_action
= {
1287 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1293 * dump shutdown action: Dump Linux on shutdown.
1296 /* FCP dump device attributes */
1298 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1299 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1300 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1301 dump_block_fcp
->ipl_info
.fcp
.lun
);
1302 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1303 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1304 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1305 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1306 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1307 dump_block_fcp
->ipl_info
.fcp
.devno
);
1309 static struct attribute
*dump_fcp_attrs
[] = {
1310 &sys_dump_fcp_device_attr
.attr
,
1311 &sys_dump_fcp_wwpn_attr
.attr
,
1312 &sys_dump_fcp_lun_attr
.attr
,
1313 &sys_dump_fcp_bootprog_attr
.attr
,
1314 &sys_dump_fcp_br_lba_attr
.attr
,
1318 static struct attribute_group dump_fcp_attr_group
= {
1319 .name
= IPL_FCP_STR
,
1320 .attrs
= dump_fcp_attrs
,
1323 /* CCW dump device attributes */
1325 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1326 dump_block_ccw
->ipl_info
.ccw
.devno
);
1328 static struct attribute
*dump_ccw_attrs
[] = {
1329 &sys_dump_ccw_device_attr
.attr
,
1333 static struct attribute_group dump_ccw_attr_group
= {
1334 .name
= IPL_CCW_STR
,
1335 .attrs
= dump_ccw_attrs
,
1340 static int dump_set_type(enum dump_type type
)
1342 if (!(dump_capabilities
& type
))
1346 if (diag308_set_works
)
1347 dump_method
= DUMP_METHOD_CCW_DIAG
;
1348 else if (MACHINE_IS_VM
)
1349 dump_method
= DUMP_METHOD_CCW_VM
;
1351 dump_method
= DUMP_METHOD_CCW_CIO
;
1354 dump_method
= DUMP_METHOD_FCP_DIAG
;
1357 dump_method
= DUMP_METHOD_NONE
;
1363 static ssize_t
dump_type_show(struct kobject
*kobj
,
1364 struct kobj_attribute
*attr
, char *page
)
1366 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1369 static ssize_t
dump_type_store(struct kobject
*kobj
,
1370 struct kobj_attribute
*attr
,
1371 const char *buf
, size_t len
)
1375 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1376 rc
= dump_set_type(DUMP_TYPE_NONE
);
1377 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1378 rc
= dump_set_type(DUMP_TYPE_CCW
);
1379 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1380 rc
= dump_set_type(DUMP_TYPE_FCP
);
1381 return (rc
!= 0) ? rc
: len
;
1384 static struct kobj_attribute dump_type_attr
=
1385 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1387 static struct kset
*dump_kset
;
1389 static void __dump_run(void *unused
)
1391 struct ccw_dev_id devid
;
1392 static char buf
[100];
1394 switch (dump_method
) {
1395 case DUMP_METHOD_CCW_CIO
:
1396 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1398 reipl_ccw_dev(&devid
);
1400 case DUMP_METHOD_CCW_VM
:
1401 sprintf(buf
, "STORE STATUS");
1402 __cpcmd(buf
, NULL
, 0, NULL
);
1403 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1404 __cpcmd(buf
, NULL
, 0, NULL
);
1406 case DUMP_METHOD_CCW_DIAG
:
1407 diag308(DIAG308_SET
, dump_block_ccw
);
1408 diag308(DIAG308_DUMP
, NULL
);
1410 case DUMP_METHOD_FCP_DIAG
:
1411 diag308(DIAG308_SET
, dump_block_fcp
);
1412 diag308(DIAG308_DUMP
, NULL
);
1419 static void dump_run(struct shutdown_trigger
*trigger
)
1421 if (dump_method
== DUMP_METHOD_NONE
)
1424 smp_switch_to_ipl_cpu(__dump_run
, NULL
);
1427 static int __init
dump_ccw_init(void)
1431 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1432 if (!dump_block_ccw
)
1434 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1436 free_page((unsigned long)dump_block_ccw
);
1439 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1440 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1441 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1442 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1443 dump_capabilities
|= DUMP_TYPE_CCW
;
1447 static int __init
dump_fcp_init(void)
1451 if (!sclp_ipl_info
.has_dump
)
1452 return 0; /* LDIPL DUMP is not installed */
1453 if (!diag308_set_works
)
1455 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1456 if (!dump_block_fcp
)
1458 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1460 free_page((unsigned long)dump_block_fcp
);
1463 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1464 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1465 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1466 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1467 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1468 dump_capabilities
|= DUMP_TYPE_FCP
;
1472 static int __init
dump_init(void)
1476 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1479 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1481 kset_unregister(dump_kset
);
1484 rc
= dump_ccw_init();
1487 rc
= dump_fcp_init();
1490 dump_set_type(DUMP_TYPE_NONE
);
1494 static struct shutdown_action __refdata dump_action
= {
1495 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1500 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1504 * Bypass dynamic address translation (DAT) when storing IPL parameter
1505 * information block address and checksum into the prefix area
1506 * (corresponding to absolute addresses 0-8191).
1507 * When enhanced DAT applies and the STE format control in one,
1508 * the absolute address is formed without prefixing. In this case a
1509 * normal store (stg/st) into the prefix area would no more match to
1510 * absolute addresses 0-8191.
1513 asm volatile("sturg %0,%1"
1514 :: "a" ((unsigned long) reipl_block_actual
),
1515 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1517 asm volatile("stura %0,%1"
1518 :: "a" ((unsigned long) reipl_block_actual
),
1519 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1521 asm volatile("stura %0,%1"
1522 :: "a" (csum_partial(reipl_block_actual
,
1523 reipl_block_actual
->hdr
.len
, 0)),
1524 "a" (&lowcore_ptr
[smp_processor_id()]->ipib_checksum
));
1529 static int __init
dump_reipl_init(void)
1531 if (!diag308_set_works
)
1537 static struct shutdown_action __refdata dump_reipl_action
= {
1538 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1539 .fn
= dump_reipl_run
,
1540 .init
= dump_reipl_init
,
1544 * vmcmd shutdown action: Trigger vm command on shutdown.
1547 static char vmcmd_on_reboot
[128];
1548 static char vmcmd_on_panic
[128];
1549 static char vmcmd_on_halt
[128];
1550 static char vmcmd_on_poff
[128];
1551 static char vmcmd_on_restart
[128];
1553 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1554 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1555 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1556 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1557 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_restart
, "%s\n", "%s\n", vmcmd_on_restart
);
1559 static struct attribute
*vmcmd_attrs
[] = {
1560 &sys_vmcmd_on_reboot_attr
.attr
,
1561 &sys_vmcmd_on_panic_attr
.attr
,
1562 &sys_vmcmd_on_halt_attr
.attr
,
1563 &sys_vmcmd_on_poff_attr
.attr
,
1564 &sys_vmcmd_on_restart_attr
.attr
,
1568 static struct attribute_group vmcmd_attr_group
= {
1569 .attrs
= vmcmd_attrs
,
1572 static struct kset
*vmcmd_kset
;
1574 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1576 char *cmd
, *next_cmd
;
1578 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1579 cmd
= vmcmd_on_reboot
;
1580 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1581 cmd
= vmcmd_on_panic
;
1582 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1583 cmd
= vmcmd_on_halt
;
1584 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1585 cmd
= vmcmd_on_poff
;
1586 else if (strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1587 cmd
= vmcmd_on_restart
;
1591 if (strlen(cmd
) == 0)
1594 next_cmd
= strchr(cmd
, '\n');
1599 __cpcmd(cmd
, NULL
, 0, NULL
);
1601 } while (cmd
!= NULL
);
1604 static int vmcmd_init(void)
1608 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1611 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1614 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1615 vmcmd_run
, vmcmd_init
};
1618 * stop shutdown action: Stop Linux on shutdown.
1621 static void stop_run(struct shutdown_trigger
*trigger
)
1623 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0 ||
1624 strcmp(trigger
->name
, ON_RESTART_STR
) == 0)
1625 disabled_wait((unsigned long) __builtin_return_address(0));
1626 while (sigp(smp_processor_id(), sigp_stop
) == sigp_busy
)
1631 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1636 static struct shutdown_action
*shutdown_actions_list
[] = {
1637 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1638 &vmcmd_action
, &stop_action
};
1639 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1645 static struct kset
*shutdown_actions_kset
;
1647 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1652 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1653 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1654 if (shutdown_actions_list
[i
]->init_rc
) {
1655 return shutdown_actions_list
[i
]->init_rc
;
1657 trigger
->action
= shutdown_actions_list
[i
];
1667 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1670 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1671 struct kobj_attribute
*attr
, char *page
)
1673 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1676 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1677 struct kobj_attribute
*attr
,
1678 const char *buf
, size_t len
)
1680 return set_trigger(buf
, &on_reboot_trigger
, len
);
1683 static struct kobj_attribute on_reboot_attr
=
1684 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1686 static void do_machine_restart(char *__unused
)
1689 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1692 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1696 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1698 static ssize_t
on_panic_show(struct kobject
*kobj
,
1699 struct kobj_attribute
*attr
, char *page
)
1701 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1704 static ssize_t
on_panic_store(struct kobject
*kobj
,
1705 struct kobj_attribute
*attr
,
1706 const char *buf
, size_t len
)
1708 return set_trigger(buf
, &on_panic_trigger
, len
);
1711 static struct kobj_attribute on_panic_attr
=
1712 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1714 static void do_panic(void)
1716 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1717 stop_run(&on_panic_trigger
);
1722 static struct shutdown_trigger on_restart_trigger
= {ON_RESTART_STR
,
1725 static ssize_t
on_restart_show(struct kobject
*kobj
,
1726 struct kobj_attribute
*attr
, char *page
)
1728 return sprintf(page
, "%s\n", on_restart_trigger
.action
->name
);
1731 static ssize_t
on_restart_store(struct kobject
*kobj
,
1732 struct kobj_attribute
*attr
,
1733 const char *buf
, size_t len
)
1735 return set_trigger(buf
, &on_restart_trigger
, len
);
1738 static struct kobj_attribute on_restart_attr
=
1739 __ATTR(on_restart
, 0644, on_restart_show
, on_restart_store
);
1741 void do_restart(void)
1743 smp_restart_with_online_cpu();
1745 #ifdef CONFIG_CRASH_DUMP
1748 on_restart_trigger
.action
->fn(&on_restart_trigger
);
1749 stop_run(&on_restart_trigger
);
1754 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1756 static ssize_t
on_halt_show(struct kobject
*kobj
,
1757 struct kobj_attribute
*attr
, char *page
)
1759 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1762 static ssize_t
on_halt_store(struct kobject
*kobj
,
1763 struct kobj_attribute
*attr
,
1764 const char *buf
, size_t len
)
1766 return set_trigger(buf
, &on_halt_trigger
, len
);
1769 static struct kobj_attribute on_halt_attr
=
1770 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1773 static void do_machine_halt(void)
1776 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1777 stop_run(&on_halt_trigger
);
1779 void (*_machine_halt
)(void) = do_machine_halt
;
1783 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1785 static ssize_t
on_poff_show(struct kobject
*kobj
,
1786 struct kobj_attribute
*attr
, char *page
)
1788 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1791 static ssize_t
on_poff_store(struct kobject
*kobj
,
1792 struct kobj_attribute
*attr
,
1793 const char *buf
, size_t len
)
1795 return set_trigger(buf
, &on_poff_trigger
, len
);
1798 static struct kobj_attribute on_poff_attr
=
1799 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1802 static void do_machine_power_off(void)
1805 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1806 stop_run(&on_poff_trigger
);
1808 void (*_machine_power_off
)(void) = do_machine_power_off
;
1810 static void __init
shutdown_triggers_init(void)
1812 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1814 if (!shutdown_actions_kset
)
1816 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1817 &on_reboot_attr
.attr
))
1819 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1820 &on_panic_attr
.attr
))
1822 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1823 &on_halt_attr
.attr
))
1825 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1826 &on_poff_attr
.attr
))
1828 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1829 &on_restart_attr
.attr
))
1833 panic("shutdown_triggers_init failed\n");
1836 static void __init
shutdown_actions_init(void)
1840 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1841 if (!shutdown_actions_list
[i
]->init
)
1843 shutdown_actions_list
[i
]->init_rc
=
1844 shutdown_actions_list
[i
]->init();
1848 static int __init
s390_ipl_init(void)
1850 sclp_get_ipl_info(&sclp_ipl_info
);
1851 shutdown_actions_init();
1852 shutdown_triggers_init();
1856 __initcall(s390_ipl_init
);
1858 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1863 for (sx
= 0; src
[sx
] != 0; sx
++) {
1866 dst
[dx
++] = src
[sx
];
1872 static int __init
vmcmd_on_reboot_setup(char *str
)
1876 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1877 vmcmd_on_reboot
[127] = 0;
1878 on_reboot_trigger
.action
= &vmcmd_action
;
1881 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1883 static int __init
vmcmd_on_panic_setup(char *str
)
1887 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1888 vmcmd_on_panic
[127] = 0;
1889 on_panic_trigger
.action
= &vmcmd_action
;
1892 __setup("vmpanic=", vmcmd_on_panic_setup
);
1894 static int __init
vmcmd_on_halt_setup(char *str
)
1898 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1899 vmcmd_on_halt
[127] = 0;
1900 on_halt_trigger
.action
= &vmcmd_action
;
1903 __setup("vmhalt=", vmcmd_on_halt_setup
);
1905 static int __init
vmcmd_on_poff_setup(char *str
)
1909 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1910 vmcmd_on_poff
[127] = 0;
1911 on_poff_trigger
.action
= &vmcmd_action
;
1914 __setup("vmpoff=", vmcmd_on_poff_setup
);
1916 static int on_panic_notify(struct notifier_block
*self
,
1917 unsigned long event
, void *data
)
1923 static struct notifier_block on_panic_nb
= {
1924 .notifier_call
= on_panic_notify
,
1925 .priority
= INT_MIN
,
1928 void __init
setup_ipl(void)
1930 ipl_info
.type
= get_ipl_type();
1931 switch (ipl_info
.type
) {
1933 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1934 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1937 case IPL_TYPE_FCP_DUMP
:
1938 ipl_info
.data
.fcp
.dev_id
.devno
=
1939 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1940 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1941 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1942 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1945 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1946 sizeof(ipl_info
.data
.nss
.name
));
1948 case IPL_TYPE_UNKNOWN
:
1949 /* We have no info to copy */
1952 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1955 void __init
ipl_update_parameters(void)
1959 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1960 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1961 diag308_set_works
= 1;
1964 void __init
ipl_save_parameters(void)
1966 struct cio_iplinfo iplinfo
;
1969 if (cio_get_iplinfo(&iplinfo
))
1972 ipl_devno
= iplinfo
.devno
;
1973 ipl_flags
|= IPL_DEVNO_VALID
;
1974 if (!iplinfo
.is_qdio
)
1976 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1977 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
1978 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1979 memmove(dst
, src
, PAGE_SIZE
);
1980 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
1983 static LIST_HEAD(rcall
);
1984 static DEFINE_MUTEX(rcall_mutex
);
1986 void register_reset_call(struct reset_call
*reset
)
1988 mutex_lock(&rcall_mutex
);
1989 list_add(&reset
->list
, &rcall
);
1990 mutex_unlock(&rcall_mutex
);
1992 EXPORT_SYMBOL_GPL(register_reset_call
);
1994 void unregister_reset_call(struct reset_call
*reset
)
1996 mutex_lock(&rcall_mutex
);
1997 list_del(&reset
->list
);
1998 mutex_unlock(&rcall_mutex
);
2000 EXPORT_SYMBOL_GPL(unregister_reset_call
);
2002 static void do_reset_calls(void)
2004 struct reset_call
*reset
;
2007 if (diag308_set_works
) {
2012 list_for_each_entry(reset
, &rcall
, list
)
2016 u32 dump_prefix_page
;
2018 void s390_reset_system(void (*func
)(void *), void *data
)
2020 struct _lowcore
*lc
;
2022 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
2024 /* Stack for interrupt/machine check handler */
2025 lc
->panic_stack
= S390_lowcore
.panic_stack
;
2027 /* Save prefix page address for dump case */
2028 dump_prefix_page
= (u32
)(unsigned long) lc
;
2030 /* Disable prefixing */
2033 /* Disable lowcore protection */
2034 __ctl_clear_bit(0,28);
2036 /* Set new machine check handler */
2037 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
| PSW_MASK_DAT
;
2038 S390_lowcore
.mcck_new_psw
.addr
=
2039 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
2041 /* Set new program check handler */
2042 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
| PSW_MASK_DAT
;
2043 S390_lowcore
.program_new_psw
.addr
=
2044 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;
2046 /* Store status at absolute zero */