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>
19 #include <asm/setup.h>
20 #include <asm/cpcmd.h>
22 #include <asm/ebcdic.h>
23 #include <asm/reset.h>
26 #define IPL_PARM_BLOCK_VERSION 0
28 #define IPL_UNKNOWN_STR "unknown"
29 #define IPL_CCW_STR "ccw"
30 #define IPL_FCP_STR "fcp"
31 #define IPL_FCP_DUMP_STR "fcp_dump"
32 #define IPL_NSS_STR "nss"
34 #define DUMP_CCW_STR "ccw"
35 #define DUMP_FCP_STR "fcp"
36 #define DUMP_NONE_STR "none"
39 * Four shutdown trigger types are supported:
45 #define ON_PANIC_STR "on_panic"
46 #define ON_HALT_STR "on_halt"
47 #define ON_POFF_STR "on_poff"
48 #define ON_REIPL_STR "on_reboot"
50 struct shutdown_action
;
51 struct shutdown_trigger
{
53 struct shutdown_action
*action
;
57 * Five shutdown action types are supported:
59 #define SHUTDOWN_ACTION_IPL_STR "ipl"
60 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
61 #define SHUTDOWN_ACTION_DUMP_STR "dump"
62 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
63 #define SHUTDOWN_ACTION_STOP_STR "stop"
65 struct shutdown_action
{
67 void (*fn
) (struct shutdown_trigger
*trigger
);
71 static char *ipl_type_str(enum ipl_type type
)
78 case IPL_TYPE_FCP_DUMP
:
79 return IPL_FCP_DUMP_STR
;
82 case IPL_TYPE_UNKNOWN
:
84 return IPL_UNKNOWN_STR
;
94 static char *dump_type_str(enum dump_type type
)
109 * Must be in data section since the bss section
110 * is not cleared when these are accessed.
112 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
113 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
116 REIPL_METHOD_CCW_CIO
,
117 REIPL_METHOD_CCW_DIAG
,
119 REIPL_METHOD_FCP_RO_DIAG
,
120 REIPL_METHOD_FCP_RW_DIAG
,
121 REIPL_METHOD_FCP_RO_VM
,
122 REIPL_METHOD_FCP_DUMP
,
124 REIPL_METHOD_DEFAULT
,
130 DUMP_METHOD_CCW_DIAG
,
132 DUMP_METHOD_FCP_DIAG
,
135 static int diag308_set_works
= 0;
137 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
139 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
140 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
141 static struct ipl_parameter_block
*reipl_block_fcp
;
142 static struct ipl_parameter_block
*reipl_block_ccw
;
144 static char reipl_nss_name
[NSS_NAME_SIZE
+ 1];
146 static int dump_capabilities
= DUMP_TYPE_NONE
;
147 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
148 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
149 static struct ipl_parameter_block
*dump_block_fcp
;
150 static struct ipl_parameter_block
*dump_block_ccw
;
152 static struct sclp_ipl_info sclp_ipl_info
;
154 int diag308(unsigned long subcode
, void *addr
)
156 register unsigned long _addr
asm("0") = (unsigned long) addr
;
157 register unsigned long _rc
asm("1") = 0;
160 " diag %0,%2,0x308\n"
163 : "+d" (_addr
), "+d" (_rc
)
164 : "d" (subcode
) : "cc", "memory");
167 EXPORT_SYMBOL_GPL(diag308
);
171 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
172 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
173 struct kobj_attribute *attr, \
176 return sprintf(page, _format, _value); \
178 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
179 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
181 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
182 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
183 struct kobj_attribute *attr, \
186 return sprintf(page, _fmt_out, \
187 (unsigned long long) _value); \
189 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
190 struct kobj_attribute *attr, \
191 const char *buf, size_t len) \
193 unsigned long long value; \
194 if (sscanf(buf, _fmt_in, &value) != 1) \
199 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
200 __ATTR(_name,(S_IRUGO | S_IWUSR), \
201 sys_##_prefix##_##_name##_show, \
202 sys_##_prefix##_##_name##_store);
204 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
205 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
206 struct kobj_attribute *attr, \
209 return sprintf(page, _fmt_out, _value); \
211 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
212 struct kobj_attribute *attr, \
213 const char *buf, size_t len) \
215 strncpy(_value, buf, sizeof(_value) - 1); \
219 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
220 __ATTR(_name,(S_IRUGO | S_IWUSR), \
221 sys_##_prefix##_##_name##_show, \
222 sys_##_prefix##_##_name##_store);
224 static void make_attrs_ro(struct attribute
**attrs
)
227 (*attrs
)->mode
= S_IRUGO
;
236 static __init
enum ipl_type
get_ipl_type(void)
238 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
240 if (ipl_flags
& IPL_NSS_VALID
)
242 if (!(ipl_flags
& IPL_DEVNO_VALID
))
243 return IPL_TYPE_UNKNOWN
;
244 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
246 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
247 return IPL_TYPE_UNKNOWN
;
248 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
249 return IPL_TYPE_UNKNOWN
;
250 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
251 return IPL_TYPE_FCP_DUMP
;
255 struct ipl_info ipl_info
;
256 EXPORT_SYMBOL_GPL(ipl_info
);
258 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
261 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
264 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
266 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
267 struct kobj_attribute
*attr
, char *page
)
269 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
271 switch (ipl_info
.type
) {
273 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
275 case IPL_TYPE_FCP_DUMP
:
276 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
282 static struct kobj_attribute sys_ipl_device_attr
=
283 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
285 static ssize_t
ipl_parameter_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
286 char *buf
, loff_t off
, size_t count
)
288 unsigned int size
= IPL_PARMBLOCK_SIZE
;
292 if (off
+ count
> size
)
294 memcpy(buf
, (void *)IPL_PARMBLOCK_START
+ off
, count
);
298 static struct bin_attribute ipl_parameter_attr
= {
300 .name
= "binary_parameter",
304 .read
= &ipl_parameter_read
,
307 static ssize_t
ipl_scp_data_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
308 char *buf
, loff_t off
, size_t count
)
310 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
311 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
315 if (off
+ count
> size
)
317 memcpy(buf
, scp_data
+ off
, count
);
321 static struct bin_attribute ipl_scp_data_attr
= {
327 .read
= ipl_scp_data_read
,
330 /* FCP ipl device attributes */
332 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
333 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
334 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
335 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
336 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
337 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
338 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
339 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
341 static struct attribute
*ipl_fcp_attrs
[] = {
342 &sys_ipl_type_attr
.attr
,
343 &sys_ipl_device_attr
.attr
,
344 &sys_ipl_fcp_wwpn_attr
.attr
,
345 &sys_ipl_fcp_lun_attr
.attr
,
346 &sys_ipl_fcp_bootprog_attr
.attr
,
347 &sys_ipl_fcp_br_lba_attr
.attr
,
351 static struct attribute_group ipl_fcp_attr_group
= {
352 .attrs
= ipl_fcp_attrs
,
355 /* CCW ipl device attributes */
357 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
358 struct kobj_attribute
*attr
, char *page
)
360 char loadparm
[LOADPARM_LEN
+ 1] = {};
362 if (!sclp_ipl_info
.is_valid
)
363 return sprintf(page
, "#unknown#\n");
364 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
365 EBCASC(loadparm
, LOADPARM_LEN
);
367 return sprintf(page
, "%s\n", loadparm
);
370 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
371 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
373 static struct attribute
*ipl_ccw_attrs
[] = {
374 &sys_ipl_type_attr
.attr
,
375 &sys_ipl_device_attr
.attr
,
376 &sys_ipl_ccw_loadparm_attr
.attr
,
380 static struct attribute_group ipl_ccw_attr_group
= {
381 .attrs
= ipl_ccw_attrs
,
384 /* NSS ipl device attributes */
386 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
388 static struct attribute
*ipl_nss_attrs
[] = {
389 &sys_ipl_type_attr
.attr
,
390 &sys_ipl_nss_name_attr
.attr
,
394 static struct attribute_group ipl_nss_attr_group
= {
395 .attrs
= ipl_nss_attrs
,
398 /* UNKNOWN ipl device attributes */
400 static struct attribute
*ipl_unknown_attrs
[] = {
401 &sys_ipl_type_attr
.attr
,
405 static struct attribute_group ipl_unknown_attr_group
= {
406 .attrs
= ipl_unknown_attrs
,
409 static struct kset
*ipl_kset
;
411 static int __init
ipl_register_fcp_files(void)
415 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
418 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
421 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
425 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
428 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
433 static void ipl_run(struct shutdown_trigger
*trigger
)
435 diag308(DIAG308_IPL
, NULL
);
437 __cpcmd("IPL", NULL
, 0, NULL
);
438 else if (ipl_info
.type
== IPL_TYPE_CCW
)
439 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
442 static int ipl_init(void)
446 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
451 switch (ipl_info
.type
) {
453 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_ccw_attr_group
);
456 case IPL_TYPE_FCP_DUMP
:
457 rc
= ipl_register_fcp_files();
460 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
463 rc
= sysfs_create_group(&ipl_kset
->kobj
,
464 &ipl_unknown_attr_group
);
469 panic("ipl_init failed: rc = %i\n", rc
);
474 static struct shutdown_action ipl_action
= {SHUTDOWN_ACTION_IPL_STR
, ipl_run
,
478 * reipl shutdown action: Reboot Linux on shutdown.
481 /* FCP reipl device attributes */
483 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
484 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
485 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
486 reipl_block_fcp
->ipl_info
.fcp
.lun
);
487 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
488 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
489 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
490 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
491 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
492 reipl_block_fcp
->ipl_info
.fcp
.devno
);
494 static struct attribute
*reipl_fcp_attrs
[] = {
495 &sys_reipl_fcp_device_attr
.attr
,
496 &sys_reipl_fcp_wwpn_attr
.attr
,
497 &sys_reipl_fcp_lun_attr
.attr
,
498 &sys_reipl_fcp_bootprog_attr
.attr
,
499 &sys_reipl_fcp_br_lba_attr
.attr
,
503 static struct attribute_group reipl_fcp_attr_group
= {
505 .attrs
= reipl_fcp_attrs
,
508 /* CCW reipl device attributes */
510 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
511 reipl_block_ccw
->ipl_info
.ccw
.devno
);
513 static void reipl_get_ascii_loadparm(char *loadparm
)
515 memcpy(loadparm
, &reipl_block_ccw
->ipl_info
.ccw
.load_param
,
517 EBCASC(loadparm
, LOADPARM_LEN
);
518 loadparm
[LOADPARM_LEN
] = 0;
522 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
523 struct kobj_attribute
*attr
, char *page
)
525 char buf
[LOADPARM_LEN
+ 1];
527 reipl_get_ascii_loadparm(buf
);
528 return sprintf(page
, "%s\n", buf
);
531 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
532 struct kobj_attribute
*attr
,
533 const char *buf
, size_t len
)
537 /* ignore trailing newline */
539 if ((len
> 0) && (buf
[len
- 1] == '\n'))
541 /* loadparm can have max 8 characters and must not start with a blank */
542 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
544 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
545 for (i
= 0; i
< lp_len
; i
++) {
546 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
551 /* initialize loadparm with blanks */
552 memset(&reipl_block_ccw
->ipl_info
.ccw
.load_param
, ' ', LOADPARM_LEN
);
553 /* copy and convert to ebcdic */
554 memcpy(&reipl_block_ccw
->ipl_info
.ccw
.load_param
, buf
, lp_len
);
555 ASCEBC(reipl_block_ccw
->ipl_info
.ccw
.load_param
, LOADPARM_LEN
);
559 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
560 __ATTR(loadparm
, 0644, reipl_ccw_loadparm_show
,
561 reipl_ccw_loadparm_store
);
563 static struct attribute
*reipl_ccw_attrs
[] = {
564 &sys_reipl_ccw_device_attr
.attr
,
565 &sys_reipl_ccw_loadparm_attr
.attr
,
569 static struct attribute_group reipl_ccw_attr_group
= {
571 .attrs
= reipl_ccw_attrs
,
575 /* NSS reipl device attributes */
577 DEFINE_IPL_ATTR_STR_RW(reipl_nss
, name
, "%s\n", "%s\n", reipl_nss_name
);
579 static struct attribute
*reipl_nss_attrs
[] = {
580 &sys_reipl_nss_name_attr
.attr
,
584 static struct attribute_group reipl_nss_attr_group
= {
586 .attrs
= reipl_nss_attrs
,
591 static int reipl_set_type(enum ipl_type type
)
593 if (!(reipl_capabilities
& type
))
599 reipl_method
= REIPL_METHOD_CCW_VM
;
601 reipl_method
= REIPL_METHOD_CCW_CIO
;
604 if (diag308_set_works
)
605 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
606 else if (MACHINE_IS_VM
)
607 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
609 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
611 case IPL_TYPE_FCP_DUMP
:
612 reipl_method
= REIPL_METHOD_FCP_DUMP
;
615 reipl_method
= REIPL_METHOD_NSS
;
617 case IPL_TYPE_UNKNOWN
:
618 reipl_method
= REIPL_METHOD_DEFAULT
;
627 static ssize_t
reipl_type_show(struct kobject
*kobj
,
628 struct kobj_attribute
*attr
, char *page
)
630 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
633 static ssize_t
reipl_type_store(struct kobject
*kobj
,
634 struct kobj_attribute
*attr
,
635 const char *buf
, size_t len
)
639 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
640 rc
= reipl_set_type(IPL_TYPE_CCW
);
641 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
642 rc
= reipl_set_type(IPL_TYPE_FCP
);
643 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
644 rc
= reipl_set_type(IPL_TYPE_NSS
);
645 return (rc
!= 0) ? rc
: len
;
648 static struct kobj_attribute reipl_type_attr
=
649 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
651 static struct kset
*reipl_kset
;
653 void reipl_run(struct shutdown_trigger
*trigger
)
655 struct ccw_dev_id devid
;
656 static char buf
[100];
657 char loadparm
[LOADPARM_LEN
+ 1];
659 switch (reipl_method
) {
660 case REIPL_METHOD_CCW_CIO
:
661 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
662 if (ipl_info
.type
== IPL_TYPE_CCW
&& devid
.devno
== ipl_devno
)
663 diag308(DIAG308_IPL
, NULL
);
665 reipl_ccw_dev(&devid
);
667 case REIPL_METHOD_CCW_VM
:
668 reipl_get_ascii_loadparm(loadparm
);
669 if (strlen(loadparm
) == 0)
670 sprintf(buf
, "IPL %X CLEAR",
671 reipl_block_ccw
->ipl_info
.ccw
.devno
);
673 sprintf(buf
, "IPL %X CLEAR LOADPARM '%s'",
674 reipl_block_ccw
->ipl_info
.ccw
.devno
, loadparm
);
675 __cpcmd(buf
, NULL
, 0, NULL
);
677 case REIPL_METHOD_CCW_DIAG
:
678 diag308(DIAG308_SET
, reipl_block_ccw
);
679 diag308(DIAG308_IPL
, NULL
);
681 case REIPL_METHOD_FCP_RW_DIAG
:
682 diag308(DIAG308_SET
, reipl_block_fcp
);
683 diag308(DIAG308_IPL
, NULL
);
685 case REIPL_METHOD_FCP_RO_DIAG
:
686 diag308(DIAG308_IPL
, NULL
);
688 case REIPL_METHOD_FCP_RO_VM
:
689 __cpcmd("IPL", NULL
, 0, NULL
);
691 case REIPL_METHOD_NSS
:
692 sprintf(buf
, "IPL %s", reipl_nss_name
);
693 __cpcmd(buf
, NULL
, 0, NULL
);
695 case REIPL_METHOD_DEFAULT
:
697 __cpcmd("IPL", NULL
, 0, NULL
);
698 diag308(DIAG308_IPL
, NULL
);
700 case REIPL_METHOD_FCP_DUMP
:
706 static void __init
reipl_probe(void)
710 buffer
= (void *) get_zeroed_page(GFP_KERNEL
);
713 if (diag308(DIAG308_STORE
, buffer
) == DIAG308_RC_OK
)
714 diag308_set_works
= 1;
715 free_page((unsigned long)buffer
);
718 static int __init
reipl_nss_init(void)
724 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
727 strncpy(reipl_nss_name
, kernel_nss_name
, NSS_NAME_SIZE
+ 1);
728 reipl_capabilities
|= IPL_TYPE_NSS
;
732 static int __init
reipl_ccw_init(void)
736 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
737 if (!reipl_block_ccw
)
739 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_ccw_attr_group
);
741 free_page((unsigned long)reipl_block_ccw
);
744 reipl_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
745 reipl_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
746 reipl_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
747 reipl_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
748 /* check if read scp info worked and set loadparm */
749 if (sclp_ipl_info
.is_valid
)
750 memcpy(reipl_block_ccw
->ipl_info
.ccw
.load_param
,
751 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
753 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
754 memset(reipl_block_ccw
->ipl_info
.ccw
.load_param
, 0x40,
756 /* FIXME: check for diag308_set_works when enabling diag ccw reipl */
758 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
759 if (ipl_info
.type
== IPL_TYPE_CCW
)
760 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
761 reipl_capabilities
|= IPL_TYPE_CCW
;
765 static int __init
reipl_fcp_init(void)
769 if ((!diag308_set_works
) && (ipl_info
.type
!= IPL_TYPE_FCP
))
771 if ((!diag308_set_works
) && (ipl_info
.type
== IPL_TYPE_FCP
))
772 make_attrs_ro(reipl_fcp_attrs
);
774 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
775 if (!reipl_block_fcp
)
777 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_fcp_attr_group
);
779 free_page((unsigned long)reipl_block_fcp
);
782 if (ipl_info
.type
== IPL_TYPE_FCP
) {
783 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
785 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
786 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
787 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
788 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
789 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
791 reipl_capabilities
|= IPL_TYPE_FCP
;
795 static int reipl_init(void)
799 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
802 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
804 kset_unregister(reipl_kset
);
807 rc
= reipl_ccw_init();
810 rc
= reipl_fcp_init();
813 rc
= reipl_nss_init();
816 rc
= reipl_set_type(ipl_info
.type
);
822 static struct shutdown_action reipl_action
= {SHUTDOWN_ACTION_REIPL_STR
,
823 reipl_run
, reipl_init
};
826 * dump shutdown action: Dump Linux on shutdown.
829 /* FCP dump device attributes */
831 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
832 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
833 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
834 dump_block_fcp
->ipl_info
.fcp
.lun
);
835 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
836 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
837 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
838 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
839 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
840 dump_block_fcp
->ipl_info
.fcp
.devno
);
842 static struct attribute
*dump_fcp_attrs
[] = {
843 &sys_dump_fcp_device_attr
.attr
,
844 &sys_dump_fcp_wwpn_attr
.attr
,
845 &sys_dump_fcp_lun_attr
.attr
,
846 &sys_dump_fcp_bootprog_attr
.attr
,
847 &sys_dump_fcp_br_lba_attr
.attr
,
851 static struct attribute_group dump_fcp_attr_group
= {
853 .attrs
= dump_fcp_attrs
,
856 /* CCW dump device attributes */
858 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
859 dump_block_ccw
->ipl_info
.ccw
.devno
);
861 static struct attribute
*dump_ccw_attrs
[] = {
862 &sys_dump_ccw_device_attr
.attr
,
866 static struct attribute_group dump_ccw_attr_group
= {
868 .attrs
= dump_ccw_attrs
,
873 static int dump_set_type(enum dump_type type
)
875 if (!(dump_capabilities
& type
))
880 dump_method
= DUMP_METHOD_CCW_VM
;
882 dump_method
= DUMP_METHOD_CCW_CIO
;
885 dump_method
= DUMP_METHOD_FCP_DIAG
;
888 dump_method
= DUMP_METHOD_NONE
;
894 static ssize_t
dump_type_show(struct kobject
*kobj
,
895 struct kobj_attribute
*attr
, char *page
)
897 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
900 static ssize_t
dump_type_store(struct kobject
*kobj
,
901 struct kobj_attribute
*attr
,
902 const char *buf
, size_t len
)
906 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
907 rc
= dump_set_type(DUMP_TYPE_NONE
);
908 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
909 rc
= dump_set_type(DUMP_TYPE_CCW
);
910 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
911 rc
= dump_set_type(DUMP_TYPE_FCP
);
912 return (rc
!= 0) ? rc
: len
;
915 static struct kobj_attribute dump_type_attr
=
916 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
918 static struct kset
*dump_kset
;
920 static void dump_run(struct shutdown_trigger
*trigger
)
922 struct ccw_dev_id devid
;
923 static char buf
[100];
925 switch (dump_method
) {
926 case DUMP_METHOD_CCW_CIO
:
928 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
930 reipl_ccw_dev(&devid
);
932 case DUMP_METHOD_CCW_VM
:
934 sprintf(buf
, "STORE STATUS");
935 __cpcmd(buf
, NULL
, 0, NULL
);
936 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
937 __cpcmd(buf
, NULL
, 0, NULL
);
939 case DUMP_METHOD_CCW_DIAG
:
940 diag308(DIAG308_SET
, dump_block_ccw
);
941 diag308(DIAG308_DUMP
, NULL
);
943 case DUMP_METHOD_FCP_DIAG
:
944 diag308(DIAG308_SET
, dump_block_fcp
);
945 diag308(DIAG308_DUMP
, NULL
);
947 case DUMP_METHOD_NONE
:
951 printk(KERN_EMERG
"Dump failed!\n");
954 static int __init
dump_ccw_init(void)
958 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
961 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
963 free_page((unsigned long)dump_block_ccw
);
966 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
967 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
968 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
969 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
970 dump_capabilities
|= DUMP_TYPE_CCW
;
974 static int __init
dump_fcp_init(void)
978 if (!sclp_ipl_info
.has_dump
)
979 return 0; /* LDIPL DUMP is not installed */
980 if (!diag308_set_works
)
982 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
985 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
987 free_page((unsigned long)dump_block_fcp
);
990 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
991 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
992 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
993 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
994 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
995 dump_capabilities
|= DUMP_TYPE_FCP
;
999 static int dump_init(void)
1003 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1006 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1008 kset_unregister(dump_kset
);
1011 rc
= dump_ccw_init();
1014 rc
= dump_fcp_init();
1017 dump_set_type(DUMP_TYPE_NONE
);
1021 static struct shutdown_action dump_action
= {SHUTDOWN_ACTION_DUMP_STR
,
1022 dump_run
, dump_init
};
1025 * vmcmd shutdown action: Trigger vm command on shutdown.
1028 static char vmcmd_on_reboot
[128];
1029 static char vmcmd_on_panic
[128];
1030 static char vmcmd_on_halt
[128];
1031 static char vmcmd_on_poff
[128];
1033 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1034 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1035 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1036 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1038 static struct attribute
*vmcmd_attrs
[] = {
1039 &sys_vmcmd_on_reboot_attr
.attr
,
1040 &sys_vmcmd_on_panic_attr
.attr
,
1041 &sys_vmcmd_on_halt_attr
.attr
,
1042 &sys_vmcmd_on_poff_attr
.attr
,
1046 static struct attribute_group vmcmd_attr_group
= {
1047 .attrs
= vmcmd_attrs
,
1050 static struct kset
*vmcmd_kset
;
1052 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1054 char *cmd
, *next_cmd
;
1056 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1057 cmd
= vmcmd_on_reboot
;
1058 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1059 cmd
= vmcmd_on_panic
;
1060 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1061 cmd
= vmcmd_on_halt
;
1062 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1063 cmd
= vmcmd_on_poff
;
1067 if (strlen(cmd
) == 0)
1070 next_cmd
= strchr(cmd
, '\n');
1075 __cpcmd(cmd
, NULL
, 0, NULL
);
1077 } while (cmd
!= NULL
);
1080 static int vmcmd_init(void)
1084 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1087 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1090 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1091 vmcmd_run
, vmcmd_init
};
1094 * stop shutdown action: Stop Linux on shutdown.
1097 static void stop_run(struct shutdown_trigger
*trigger
)
1099 signal_processor(smp_processor_id(), sigp_stop_and_store_status
);
1103 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1108 static struct shutdown_action
*shutdown_actions_list
[] = {
1109 &ipl_action
, &reipl_action
, &dump_action
, &vmcmd_action
, &stop_action
};
1110 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1116 static struct kset
*shutdown_actions_kset
;
1118 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1122 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1123 if (!shutdown_actions_list
[i
])
1125 if (strncmp(buf
, shutdown_actions_list
[i
]->name
,
1126 strlen(shutdown_actions_list
[i
]->name
)) == 0) {
1127 trigger
->action
= shutdown_actions_list
[i
];
1136 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1139 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1140 struct kobj_attribute
*attr
, char *page
)
1142 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1145 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1146 struct kobj_attribute
*attr
,
1147 const char *buf
, size_t len
)
1149 return set_trigger(buf
, &on_reboot_trigger
, len
);
1152 static struct kobj_attribute on_reboot_attr
=
1153 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1155 static void do_machine_restart(char *__unused
)
1158 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1161 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1165 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1167 static ssize_t
on_panic_show(struct kobject
*kobj
,
1168 struct kobj_attribute
*attr
, char *page
)
1170 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1173 static ssize_t
on_panic_store(struct kobject
*kobj
,
1174 struct kobj_attribute
*attr
,
1175 const char *buf
, size_t len
)
1177 return set_trigger(buf
, &on_panic_trigger
, len
);
1180 static struct kobj_attribute on_panic_attr
=
1181 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1183 static void do_panic(void)
1185 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1186 stop_run(&on_panic_trigger
);
1191 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1193 static ssize_t
on_halt_show(struct kobject
*kobj
,
1194 struct kobj_attribute
*attr
, char *page
)
1196 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1199 static ssize_t
on_halt_store(struct kobject
*kobj
,
1200 struct kobj_attribute
*attr
,
1201 const char *buf
, size_t len
)
1203 return set_trigger(buf
, &on_halt_trigger
, len
);
1206 static struct kobj_attribute on_halt_attr
=
1207 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1210 static void do_machine_halt(void)
1213 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1214 stop_run(&on_halt_trigger
);
1216 void (*_machine_halt
)(void) = do_machine_halt
;
1220 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1222 static ssize_t
on_poff_show(struct kobject
*kobj
,
1223 struct kobj_attribute
*attr
, char *page
)
1225 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1228 static ssize_t
on_poff_store(struct kobject
*kobj
,
1229 struct kobj_attribute
*attr
,
1230 const char *buf
, size_t len
)
1232 return set_trigger(buf
, &on_poff_trigger
, len
);
1235 static struct kobj_attribute on_poff_attr
=
1236 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1239 static void do_machine_power_off(void)
1242 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1243 stop_run(&on_poff_trigger
);
1245 void (*_machine_power_off
)(void) = do_machine_power_off
;
1247 static void __init
shutdown_triggers_init(void)
1249 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1251 if (!shutdown_actions_kset
)
1253 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1254 &on_reboot_attr
.attr
))
1256 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1257 &on_panic_attr
.attr
))
1259 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1260 &on_halt_attr
.attr
))
1262 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1263 &on_poff_attr
.attr
))
1268 panic("shutdown_triggers_init failed\n");
1271 static void __init
shutdown_actions_init(void)
1275 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1276 if (!shutdown_actions_list
[i
]->init
)
1278 if (shutdown_actions_list
[i
]->init())
1279 shutdown_actions_list
[i
] = NULL
;
1283 static int __init
s390_ipl_init(void)
1286 shutdown_actions_init();
1287 shutdown_triggers_init();
1291 __initcall(s390_ipl_init
);
1293 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1298 for (sx
= 0; src
[sx
] != 0; sx
++) {
1301 dst
[dx
++] = src
[sx
];
1307 static int __init
vmcmd_on_reboot_setup(char *str
)
1311 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1312 vmcmd_on_reboot
[127] = 0;
1313 on_reboot_trigger
.action
= &vmcmd_action
;
1316 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1318 static int __init
vmcmd_on_panic_setup(char *str
)
1322 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1323 vmcmd_on_panic
[127] = 0;
1324 on_panic_trigger
.action
= &vmcmd_action
;
1327 __setup("vmpanic=", vmcmd_on_panic_setup
);
1329 static int __init
vmcmd_on_halt_setup(char *str
)
1333 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1334 vmcmd_on_halt
[127] = 0;
1335 on_halt_trigger
.action
= &vmcmd_action
;
1338 __setup("vmhalt=", vmcmd_on_halt_setup
);
1340 static int __init
vmcmd_on_poff_setup(char *str
)
1344 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1345 vmcmd_on_poff
[127] = 0;
1346 on_poff_trigger
.action
= &vmcmd_action
;
1349 __setup("vmpoff=", vmcmd_on_poff_setup
);
1351 static int on_panic_notify(struct notifier_block
*self
,
1352 unsigned long event
, void *data
)
1358 static struct notifier_block on_panic_nb
= {
1359 .notifier_call
= on_panic_notify
,
1363 void __init
setup_ipl(void)
1365 ipl_info
.type
= get_ipl_type();
1366 switch (ipl_info
.type
) {
1368 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1369 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1372 case IPL_TYPE_FCP_DUMP
:
1373 ipl_info
.data
.fcp
.dev_id
.devno
=
1374 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1375 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1376 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1377 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1380 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1381 sizeof(ipl_info
.data
.nss
.name
));
1383 case IPL_TYPE_UNKNOWN
:
1385 /* We have no info to copy */
1388 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1391 void __init
ipl_save_parameters(void)
1393 struct cio_iplinfo iplinfo
;
1394 unsigned int *ipl_ptr
;
1397 if (cio_get_iplinfo(&iplinfo
))
1400 ipl_devno
= iplinfo
.devno
;
1401 ipl_flags
|= IPL_DEVNO_VALID
;
1402 if (!iplinfo
.is_qdio
)
1404 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1405 ipl_ptr
= (unsigned int *)__LC_IPL_PARMBLOCK_PTR
;
1406 src
= (void *)(unsigned long)*ipl_ptr
;
1407 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1408 memmove(dst
, src
, PAGE_SIZE
);
1409 *ipl_ptr
= IPL_PARMBLOCK_ORIGIN
;
1412 static LIST_HEAD(rcall
);
1413 static DEFINE_MUTEX(rcall_mutex
);
1415 void register_reset_call(struct reset_call
*reset
)
1417 mutex_lock(&rcall_mutex
);
1418 list_add(&reset
->list
, &rcall
);
1419 mutex_unlock(&rcall_mutex
);
1421 EXPORT_SYMBOL_GPL(register_reset_call
);
1423 void unregister_reset_call(struct reset_call
*reset
)
1425 mutex_lock(&rcall_mutex
);
1426 list_del(&reset
->list
);
1427 mutex_unlock(&rcall_mutex
);
1429 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1431 static void do_reset_calls(void)
1433 struct reset_call
*reset
;
1435 list_for_each_entry(reset
, &rcall
, list
)
1439 u32 dump_prefix_page
;
1441 void s390_reset_system(void)
1443 struct _lowcore
*lc
;
1445 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
1447 /* Stack for interrupt/machine check handler */
1448 lc
->panic_stack
= S390_lowcore
.panic_stack
;
1450 /* Save prefix page address for dump case */
1451 dump_prefix_page
= (u32
)(unsigned long) lc
;
1453 /* Disable prefixing */
1456 /* Disable lowcore protection */
1457 __ctl_clear_bit(0,28);
1459 /* Set new machine check handler */
1460 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1461 S390_lowcore
.mcck_new_psw
.addr
=
1462 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
1464 /* Set new program check handler */
1465 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1466 S390_lowcore
.program_new_psw
.addr
=
1467 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;