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>
21 #include <asm/setup.h>
22 #include <asm/cpcmd.h>
24 #include <asm/ebcdic.h>
25 #include <asm/reset.h>
28 #include <asm/checksum.h>
30 #define IPL_PARM_BLOCK_VERSION 0
32 #define IPL_UNKNOWN_STR "unknown"
33 #define IPL_CCW_STR "ccw"
34 #define IPL_FCP_STR "fcp"
35 #define IPL_FCP_DUMP_STR "fcp_dump"
36 #define IPL_NSS_STR "nss"
38 #define DUMP_CCW_STR "ccw"
39 #define DUMP_FCP_STR "fcp"
40 #define DUMP_NONE_STR "none"
43 * Four shutdown trigger types are supported:
49 #define ON_PANIC_STR "on_panic"
50 #define ON_HALT_STR "on_halt"
51 #define ON_POFF_STR "on_poff"
52 #define ON_REIPL_STR "on_reboot"
54 struct shutdown_action
;
55 struct shutdown_trigger
{
57 struct shutdown_action
*action
;
61 * The following shutdown action types are supported:
63 #define SHUTDOWN_ACTION_IPL_STR "ipl"
64 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
65 #define SHUTDOWN_ACTION_DUMP_STR "dump"
66 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
67 #define SHUTDOWN_ACTION_STOP_STR "stop"
68 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
70 struct shutdown_action
{
72 void (*fn
) (struct shutdown_trigger
*trigger
);
77 static char *ipl_type_str(enum ipl_type type
)
84 case IPL_TYPE_FCP_DUMP
:
85 return IPL_FCP_DUMP_STR
;
88 case IPL_TYPE_UNKNOWN
:
90 return IPL_UNKNOWN_STR
;
100 static char *dump_type_str(enum dump_type type
)
104 return DUMP_NONE_STR
;
115 * Must be in data section since the bss section
116 * is not cleared when these are accessed.
118 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
119 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
122 REIPL_METHOD_CCW_CIO
,
123 REIPL_METHOD_CCW_DIAG
,
125 REIPL_METHOD_FCP_RO_DIAG
,
126 REIPL_METHOD_FCP_RW_DIAG
,
127 REIPL_METHOD_FCP_RO_VM
,
128 REIPL_METHOD_FCP_DUMP
,
130 REIPL_METHOD_NSS_DIAG
,
131 REIPL_METHOD_DEFAULT
,
137 DUMP_METHOD_CCW_DIAG
,
139 DUMP_METHOD_FCP_DIAG
,
142 static int diag308_set_works
= 0;
144 static struct ipl_parameter_block ipl_block
;
146 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
148 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
149 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
150 static struct ipl_parameter_block
*reipl_block_fcp
;
151 static struct ipl_parameter_block
*reipl_block_ccw
;
152 static struct ipl_parameter_block
*reipl_block_nss
;
153 static struct ipl_parameter_block
*reipl_block_actual
;
155 static int dump_capabilities
= DUMP_TYPE_NONE
;
156 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
157 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
158 static struct ipl_parameter_block
*dump_block_fcp
;
159 static struct ipl_parameter_block
*dump_block_ccw
;
161 static struct sclp_ipl_info sclp_ipl_info
;
163 int diag308(unsigned long subcode
, void *addr
)
165 register unsigned long _addr
asm("0") = (unsigned long) addr
;
166 register unsigned long _rc
asm("1") = 0;
169 " diag %0,%2,0x308\n"
172 : "+d" (_addr
), "+d" (_rc
)
173 : "d" (subcode
) : "cc", "memory");
176 EXPORT_SYMBOL_GPL(diag308
);
180 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
181 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
182 struct kobj_attribute *attr, \
185 return sprintf(page, _format, _value); \
187 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
188 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
190 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
191 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
192 struct kobj_attribute *attr, \
195 return sprintf(page, _fmt_out, \
196 (unsigned long long) _value); \
198 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
199 struct kobj_attribute *attr, \
200 const char *buf, size_t len) \
202 unsigned long long value; \
203 if (sscanf(buf, _fmt_in, &value) != 1) \
208 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
209 __ATTR(_name,(S_IRUGO | S_IWUSR), \
210 sys_##_prefix##_##_name##_show, \
211 sys_##_prefix##_##_name##_store);
213 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
214 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
215 struct kobj_attribute *attr, \
218 return sprintf(page, _fmt_out, _value); \
220 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
221 struct kobj_attribute *attr, \
222 const char *buf, size_t len) \
224 strncpy(_value, buf, sizeof(_value) - 1); \
228 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
229 __ATTR(_name,(S_IRUGO | S_IWUSR), \
230 sys_##_prefix##_##_name##_show, \
231 sys_##_prefix##_##_name##_store);
233 static void make_attrs_ro(struct attribute
**attrs
)
236 (*attrs
)->mode
= S_IRUGO
;
245 static __init
enum ipl_type
get_ipl_type(void)
247 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
249 if (ipl_flags
& IPL_NSS_VALID
)
251 if (!(ipl_flags
& IPL_DEVNO_VALID
))
252 return IPL_TYPE_UNKNOWN
;
253 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
255 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
256 return IPL_TYPE_UNKNOWN
;
257 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
258 return IPL_TYPE_UNKNOWN
;
259 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
260 return IPL_TYPE_FCP_DUMP
;
264 struct ipl_info ipl_info
;
265 EXPORT_SYMBOL_GPL(ipl_info
);
267 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
270 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
273 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
275 /* VM IPL PARM routines */
276 size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
277 const struct ipl_parameter_block
*ipb
)
281 char has_lowercase
= 0;
284 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
285 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
287 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
288 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
289 /* If at least one character is lowercase, we assume mixed
290 * case; otherwise we convert everything to lowercase.
292 for (i
= 0; i
< len
; i
++)
293 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
294 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
295 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
300 EBC_TOLOWER(dest
, len
);
308 size_t append_ipl_vmparm(char *dest
, size_t size
)
313 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
314 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
320 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
321 struct kobj_attribute
*attr
, char *page
)
323 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
325 append_ipl_vmparm(parm
, sizeof(parm
));
326 return sprintf(page
, "%s\n", parm
);
329 static size_t scpdata_length(const char* buf
, size_t count
)
332 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
339 size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
340 const struct ipl_parameter_block
*ipb
)
346 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
347 ipb
->ipl_info
.fcp
.scp_data_len
));
352 for (i
= 0; i
< count
; i
++) {
353 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
357 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
362 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
364 for (i
= 0; i
< count
; i
++)
365 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
371 size_t append_ipl_scpdata(char *dest
, size_t len
)
376 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
377 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
384 static struct kobj_attribute sys_ipl_vm_parm_attr
=
385 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
387 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
388 struct kobj_attribute
*attr
, char *page
)
390 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
392 switch (ipl_info
.type
) {
394 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
396 case IPL_TYPE_FCP_DUMP
:
397 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
403 static struct kobj_attribute sys_ipl_device_attr
=
404 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
406 static ssize_t
ipl_parameter_read(struct file
*filp
, struct kobject
*kobj
,
407 struct bin_attribute
*attr
, char *buf
,
408 loff_t off
, size_t count
)
410 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
414 static struct bin_attribute ipl_parameter_attr
= {
416 .name
= "binary_parameter",
420 .read
= &ipl_parameter_read
,
423 static ssize_t
ipl_scp_data_read(struct file
*filp
, struct kobject
*kobj
,
424 struct bin_attribute
*attr
, char *buf
,
425 loff_t off
, size_t count
)
427 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
428 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
430 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
433 static struct bin_attribute ipl_scp_data_attr
= {
439 .read
= ipl_scp_data_read
,
442 /* FCP ipl device attributes */
444 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
445 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
446 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
447 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
448 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
449 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
450 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
451 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
453 static struct attribute
*ipl_fcp_attrs
[] = {
454 &sys_ipl_type_attr
.attr
,
455 &sys_ipl_device_attr
.attr
,
456 &sys_ipl_fcp_wwpn_attr
.attr
,
457 &sys_ipl_fcp_lun_attr
.attr
,
458 &sys_ipl_fcp_bootprog_attr
.attr
,
459 &sys_ipl_fcp_br_lba_attr
.attr
,
463 static struct attribute_group ipl_fcp_attr_group
= {
464 .attrs
= ipl_fcp_attrs
,
467 /* CCW ipl device attributes */
469 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
470 struct kobj_attribute
*attr
, char *page
)
472 char loadparm
[LOADPARM_LEN
+ 1] = {};
474 if (!sclp_ipl_info
.is_valid
)
475 return sprintf(page
, "#unknown#\n");
476 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
477 EBCASC(loadparm
, LOADPARM_LEN
);
479 return sprintf(page
, "%s\n", loadparm
);
482 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
483 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
485 static struct attribute
*ipl_ccw_attrs_vm
[] = {
486 &sys_ipl_type_attr
.attr
,
487 &sys_ipl_device_attr
.attr
,
488 &sys_ipl_ccw_loadparm_attr
.attr
,
489 &sys_ipl_vm_parm_attr
.attr
,
493 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
494 &sys_ipl_type_attr
.attr
,
495 &sys_ipl_device_attr
.attr
,
496 &sys_ipl_ccw_loadparm_attr
.attr
,
500 static struct attribute_group ipl_ccw_attr_group_vm
= {
501 .attrs
= ipl_ccw_attrs_vm
,
504 static struct attribute_group ipl_ccw_attr_group_lpar
= {
505 .attrs
= ipl_ccw_attrs_lpar
508 /* NSS ipl device attributes */
510 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
512 static struct attribute
*ipl_nss_attrs
[] = {
513 &sys_ipl_type_attr
.attr
,
514 &sys_ipl_nss_name_attr
.attr
,
515 &sys_ipl_ccw_loadparm_attr
.attr
,
516 &sys_ipl_vm_parm_attr
.attr
,
520 static struct attribute_group ipl_nss_attr_group
= {
521 .attrs
= ipl_nss_attrs
,
524 /* UNKNOWN ipl device attributes */
526 static struct attribute
*ipl_unknown_attrs
[] = {
527 &sys_ipl_type_attr
.attr
,
531 static struct attribute_group ipl_unknown_attr_group
= {
532 .attrs
= ipl_unknown_attrs
,
535 static struct kset
*ipl_kset
;
537 static int __init
ipl_register_fcp_files(void)
541 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
544 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
547 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
551 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
554 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
559 static void __ipl_run(void *unused
)
561 diag308(DIAG308_IPL
, NULL
);
563 __cpcmd("IPL", NULL
, 0, NULL
);
564 else if (ipl_info
.type
== IPL_TYPE_CCW
)
565 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
568 static void ipl_run(struct shutdown_trigger
*trigger
)
570 smp_switch_to_ipl_cpu(__ipl_run
, NULL
);
573 static int __init
ipl_init(void)
577 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
582 switch (ipl_info
.type
) {
585 rc
= sysfs_create_group(&ipl_kset
->kobj
,
586 &ipl_ccw_attr_group_vm
);
588 rc
= sysfs_create_group(&ipl_kset
->kobj
,
589 &ipl_ccw_attr_group_lpar
);
592 case IPL_TYPE_FCP_DUMP
:
593 rc
= ipl_register_fcp_files();
596 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
599 rc
= sysfs_create_group(&ipl_kset
->kobj
,
600 &ipl_unknown_attr_group
);
605 panic("ipl_init failed: rc = %i\n", rc
);
610 static struct shutdown_action __refdata ipl_action
= {
611 .name
= SHUTDOWN_ACTION_IPL_STR
,
617 * reipl shutdown action: Reboot Linux on shutdown.
620 /* VM IPL PARM attributes */
621 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
624 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
626 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
627 return sprintf(page
, "%s\n", vmparm
);
630 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
632 const char *buf
, size_t len
)
636 /* ignore trailing newline */
638 if ((len
> 0) && (buf
[len
- 1] == '\n'))
641 if (ip_len
> vmparm_max
)
644 /* parm is used to store kernel options, check for common chars */
645 for (i
= 0; i
< ip_len
; i
++)
646 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
649 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
650 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
652 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
653 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
654 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
656 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
663 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
664 struct kobj_attribute
*attr
, char *page
)
666 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
669 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
670 struct kobj_attribute
*attr
,
671 const char *buf
, size_t len
)
673 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
677 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
678 struct kobj_attribute
*attr
, char *page
)
680 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
683 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
684 struct kobj_attribute
*attr
,
685 const char *buf
, size_t len
)
687 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
690 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
691 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
692 reipl_nss_vmparm_store
);
693 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
694 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
695 reipl_ccw_vmparm_store
);
697 /* FCP reipl device attributes */
699 static ssize_t
reipl_fcp_scpdata_read(struct file
*filp
, struct kobject
*kobj
,
700 struct bin_attribute
*attr
,
701 char *buf
, loff_t off
, size_t count
)
703 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
704 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
706 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
709 static ssize_t
reipl_fcp_scpdata_write(struct file
*filp
, struct kobject
*kobj
,
710 struct bin_attribute
*attr
,
711 char *buf
, loff_t off
, size_t count
)
719 if (off
>= DIAG308_SCPDATA_SIZE
)
722 if (count
> DIAG308_SCPDATA_SIZE
- off
)
723 count
= DIAG308_SCPDATA_SIZE
- off
;
725 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
726 scpdata_len
= off
+ count
;
728 if (scpdata_len
% 8) {
729 padding
= 8 - (scpdata_len
% 8);
730 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
732 scpdata_len
+= padding
;
735 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
736 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
737 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
742 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
745 .mode
= S_IRUGO
| S_IWUSR
,
748 .read
= reipl_fcp_scpdata_read
,
749 .write
= reipl_fcp_scpdata_write
,
752 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
753 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
754 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
755 reipl_block_fcp
->ipl_info
.fcp
.lun
);
756 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
757 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
758 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
759 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
760 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
761 reipl_block_fcp
->ipl_info
.fcp
.devno
);
763 static struct attribute
*reipl_fcp_attrs
[] = {
764 &sys_reipl_fcp_device_attr
.attr
,
765 &sys_reipl_fcp_wwpn_attr
.attr
,
766 &sys_reipl_fcp_lun_attr
.attr
,
767 &sys_reipl_fcp_bootprog_attr
.attr
,
768 &sys_reipl_fcp_br_lba_attr
.attr
,
772 static struct attribute_group reipl_fcp_attr_group
= {
773 .attrs
= reipl_fcp_attrs
,
776 /* CCW reipl device attributes */
778 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
779 reipl_block_ccw
->ipl_info
.ccw
.devno
);
781 static void reipl_get_ascii_loadparm(char *loadparm
,
782 struct ipl_parameter_block
*ibp
)
784 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
785 EBCASC(loadparm
, LOADPARM_LEN
);
786 loadparm
[LOADPARM_LEN
] = 0;
790 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
793 char buf
[LOADPARM_LEN
+ 1];
795 reipl_get_ascii_loadparm(buf
, ipb
);
796 return sprintf(page
, "%s\n", buf
);
799 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
800 const char *buf
, size_t len
)
804 /* ignore trailing newline */
806 if ((len
> 0) && (buf
[len
- 1] == '\n'))
808 /* loadparm can have max 8 characters and must not start with a blank */
809 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
811 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
812 for (i
= 0; i
< lp_len
; i
++) {
813 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
818 /* initialize loadparm with blanks */
819 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
820 /* copy and convert to ebcdic */
821 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
822 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
827 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
828 struct kobj_attribute
*attr
, char *page
)
830 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
833 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
834 struct kobj_attribute
*attr
,
835 const char *buf
, size_t len
)
837 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
841 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
842 struct kobj_attribute
*attr
, char *page
)
844 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
847 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
848 struct kobj_attribute
*attr
,
849 const char *buf
, size_t len
)
851 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
854 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
855 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
856 reipl_ccw_loadparm_store
);
858 static struct attribute
*reipl_ccw_attrs_vm
[] = {
859 &sys_reipl_ccw_device_attr
.attr
,
860 &sys_reipl_ccw_loadparm_attr
.attr
,
861 &sys_reipl_ccw_vmparm_attr
.attr
,
865 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
866 &sys_reipl_ccw_device_attr
.attr
,
867 &sys_reipl_ccw_loadparm_attr
.attr
,
871 static struct attribute_group reipl_ccw_attr_group_vm
= {
873 .attrs
= reipl_ccw_attrs_vm
,
876 static struct attribute_group reipl_ccw_attr_group_lpar
= {
878 .attrs
= reipl_ccw_attrs_lpar
,
882 /* NSS reipl device attributes */
883 static void reipl_get_ascii_nss_name(char *dst
,
884 struct ipl_parameter_block
*ipb
)
886 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
887 EBCASC(dst
, NSS_NAME_SIZE
);
888 dst
[NSS_NAME_SIZE
] = 0;
891 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
892 struct kobj_attribute
*attr
, char *page
)
894 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
896 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
897 return sprintf(page
, "%s\n", nss_name
);
900 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
901 struct kobj_attribute
*attr
,
902 const char *buf
, size_t len
)
906 /* ignore trailing newline */
908 if ((len
> 0) && (buf
[len
- 1] == '\n'))
911 if (nss_len
> NSS_NAME_SIZE
)
914 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
916 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
917 DIAG308_VM_FLAGS_NSS_VALID
;
918 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
919 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
920 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
922 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
923 ~DIAG308_VM_FLAGS_NSS_VALID
;
929 static struct kobj_attribute sys_reipl_nss_name_attr
=
930 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
931 reipl_nss_name_store
);
933 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
934 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
935 reipl_nss_loadparm_store
);
937 static struct attribute
*reipl_nss_attrs
[] = {
938 &sys_reipl_nss_name_attr
.attr
,
939 &sys_reipl_nss_loadparm_attr
.attr
,
940 &sys_reipl_nss_vmparm_attr
.attr
,
944 static struct attribute_group reipl_nss_attr_group
= {
946 .attrs
= reipl_nss_attrs
,
951 static int reipl_set_type(enum ipl_type type
)
953 if (!(reipl_capabilities
& type
))
958 if (diag308_set_works
)
959 reipl_method
= REIPL_METHOD_CCW_DIAG
;
960 else if (MACHINE_IS_VM
)
961 reipl_method
= REIPL_METHOD_CCW_VM
;
963 reipl_method
= REIPL_METHOD_CCW_CIO
;
964 reipl_block_actual
= reipl_block_ccw
;
967 if (diag308_set_works
)
968 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
969 else if (MACHINE_IS_VM
)
970 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
972 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
973 reipl_block_actual
= reipl_block_fcp
;
975 case IPL_TYPE_FCP_DUMP
:
976 reipl_method
= REIPL_METHOD_FCP_DUMP
;
979 if (diag308_set_works
)
980 reipl_method
= REIPL_METHOD_NSS_DIAG
;
982 reipl_method
= REIPL_METHOD_NSS
;
983 reipl_block_actual
= reipl_block_nss
;
985 case IPL_TYPE_UNKNOWN
:
986 reipl_method
= REIPL_METHOD_DEFAULT
;
995 static ssize_t
reipl_type_show(struct kobject
*kobj
,
996 struct kobj_attribute
*attr
, char *page
)
998 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
1001 static ssize_t
reipl_type_store(struct kobject
*kobj
,
1002 struct kobj_attribute
*attr
,
1003 const char *buf
, size_t len
)
1007 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1008 rc
= reipl_set_type(IPL_TYPE_CCW
);
1009 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1010 rc
= reipl_set_type(IPL_TYPE_FCP
);
1011 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1012 rc
= reipl_set_type(IPL_TYPE_NSS
);
1013 return (rc
!= 0) ? rc
: len
;
1016 static struct kobj_attribute reipl_type_attr
=
1017 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1019 static struct kset
*reipl_kset
;
1020 static struct kset
*reipl_fcp_kset
;
1022 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1023 const enum ipl_method m
)
1025 char loadparm
[LOADPARM_LEN
+ 1] = {};
1026 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1027 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1030 reipl_get_ascii_loadparm(loadparm
, ipb
);
1031 reipl_get_ascii_nss_name(nss_name
, ipb
);
1032 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1035 case REIPL_METHOD_CCW_VM
:
1036 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1038 case REIPL_METHOD_NSS
:
1039 pos
= sprintf(dst
, "IPL %s", nss_name
);
1044 if (strlen(loadparm
) > 0)
1045 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1046 if (strlen(vmparm
) > 0)
1047 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1050 static void __reipl_run(void *unused
)
1052 struct ccw_dev_id devid
;
1053 static char buf
[128];
1055 switch (reipl_method
) {
1056 case REIPL_METHOD_CCW_CIO
:
1057 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1059 reipl_ccw_dev(&devid
);
1061 case REIPL_METHOD_CCW_VM
:
1062 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1063 __cpcmd(buf
, NULL
, 0, NULL
);
1065 case REIPL_METHOD_CCW_DIAG
:
1066 diag308(DIAG308_SET
, reipl_block_ccw
);
1067 diag308(DIAG308_IPL
, NULL
);
1069 case REIPL_METHOD_FCP_RW_DIAG
:
1070 diag308(DIAG308_SET
, reipl_block_fcp
);
1071 diag308(DIAG308_IPL
, NULL
);
1073 case REIPL_METHOD_FCP_RO_DIAG
:
1074 diag308(DIAG308_IPL
, NULL
);
1076 case REIPL_METHOD_FCP_RO_VM
:
1077 __cpcmd("IPL", NULL
, 0, NULL
);
1079 case REIPL_METHOD_NSS_DIAG
:
1080 diag308(DIAG308_SET
, reipl_block_nss
);
1081 diag308(DIAG308_IPL
, NULL
);
1083 case REIPL_METHOD_NSS
:
1084 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1085 __cpcmd(buf
, NULL
, 0, NULL
);
1087 case REIPL_METHOD_DEFAULT
:
1089 __cpcmd("IPL", NULL
, 0, NULL
);
1090 diag308(DIAG308_IPL
, NULL
);
1092 case REIPL_METHOD_FCP_DUMP
:
1095 disabled_wait((unsigned long) __builtin_return_address(0));
1098 static void reipl_run(struct shutdown_trigger
*trigger
)
1100 smp_switch_to_ipl_cpu(__reipl_run
, NULL
);
1103 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1105 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1106 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1107 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1108 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1111 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1114 /* check if read scp info worked and set loadparm */
1115 if (sclp_ipl_info
.is_valid
)
1116 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
1117 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1119 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1120 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
1121 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1124 if (MACHINE_IS_VM
&& diag308_set_works
&&
1125 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1127 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1128 ipb
->ipl_info
.ccw
.vm_parm_len
=
1129 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1130 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1131 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1135 static int __init
reipl_nss_init(void)
1142 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1143 if (!reipl_block_nss
)
1146 if (!diag308_set_works
)
1147 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1149 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1153 reipl_block_ccw_init(reipl_block_nss
);
1154 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1155 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1156 ' ', NSS_NAME_SIZE
);
1157 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1158 kernel_nss_name
, strlen(kernel_nss_name
));
1159 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1160 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1161 DIAG308_VM_FLAGS_NSS_VALID
;
1163 reipl_block_ccw_fill_parms(reipl_block_nss
);
1166 reipl_capabilities
|= IPL_TYPE_NSS
;
1170 static int __init
reipl_ccw_init(void)
1174 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1175 if (!reipl_block_ccw
)
1178 if (MACHINE_IS_VM
) {
1179 if (!diag308_set_works
)
1180 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1181 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1182 &reipl_ccw_attr_group_vm
);
1184 if(!diag308_set_works
)
1185 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1186 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1187 &reipl_ccw_attr_group_lpar
);
1192 reipl_block_ccw_init(reipl_block_ccw
);
1193 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1194 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1195 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1198 reipl_capabilities
|= IPL_TYPE_CCW
;
1202 static int __init
reipl_fcp_init(void)
1206 if (!diag308_set_works
) {
1207 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1208 make_attrs_ro(reipl_fcp_attrs
);
1209 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1214 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1215 if (!reipl_block_fcp
)
1218 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1219 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1222 free_page((unsigned long) reipl_block_fcp
);
1226 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1228 kset_unregister(reipl_fcp_kset
);
1229 free_page((unsigned long) reipl_block_fcp
);
1233 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1234 &sys_reipl_fcp_scp_data_attr
);
1236 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1237 kset_unregister(reipl_fcp_kset
);
1238 free_page((unsigned long) reipl_block_fcp
);
1242 if (ipl_info
.type
== IPL_TYPE_FCP
)
1243 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1245 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1246 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1247 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1248 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1249 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1251 reipl_capabilities
|= IPL_TYPE_FCP
;
1255 static int __init
reipl_init(void)
1259 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1262 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1264 kset_unregister(reipl_kset
);
1267 rc
= reipl_ccw_init();
1270 rc
= reipl_fcp_init();
1273 rc
= reipl_nss_init();
1276 rc
= reipl_set_type(ipl_info
.type
);
1282 static struct shutdown_action __refdata reipl_action
= {
1283 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1289 * dump shutdown action: Dump Linux on shutdown.
1292 /* FCP dump device attributes */
1294 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1295 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1296 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1297 dump_block_fcp
->ipl_info
.fcp
.lun
);
1298 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1299 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1300 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1301 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1302 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1303 dump_block_fcp
->ipl_info
.fcp
.devno
);
1305 static struct attribute
*dump_fcp_attrs
[] = {
1306 &sys_dump_fcp_device_attr
.attr
,
1307 &sys_dump_fcp_wwpn_attr
.attr
,
1308 &sys_dump_fcp_lun_attr
.attr
,
1309 &sys_dump_fcp_bootprog_attr
.attr
,
1310 &sys_dump_fcp_br_lba_attr
.attr
,
1314 static struct attribute_group dump_fcp_attr_group
= {
1315 .name
= IPL_FCP_STR
,
1316 .attrs
= dump_fcp_attrs
,
1319 /* CCW dump device attributes */
1321 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1322 dump_block_ccw
->ipl_info
.ccw
.devno
);
1324 static struct attribute
*dump_ccw_attrs
[] = {
1325 &sys_dump_ccw_device_attr
.attr
,
1329 static struct attribute_group dump_ccw_attr_group
= {
1330 .name
= IPL_CCW_STR
,
1331 .attrs
= dump_ccw_attrs
,
1336 static int dump_set_type(enum dump_type type
)
1338 if (!(dump_capabilities
& type
))
1342 if (diag308_set_works
)
1343 dump_method
= DUMP_METHOD_CCW_DIAG
;
1344 else if (MACHINE_IS_VM
)
1345 dump_method
= DUMP_METHOD_CCW_VM
;
1347 dump_method
= DUMP_METHOD_CCW_CIO
;
1350 dump_method
= DUMP_METHOD_FCP_DIAG
;
1353 dump_method
= DUMP_METHOD_NONE
;
1359 static ssize_t
dump_type_show(struct kobject
*kobj
,
1360 struct kobj_attribute
*attr
, char *page
)
1362 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1365 static ssize_t
dump_type_store(struct kobject
*kobj
,
1366 struct kobj_attribute
*attr
,
1367 const char *buf
, size_t len
)
1371 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1372 rc
= dump_set_type(DUMP_TYPE_NONE
);
1373 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1374 rc
= dump_set_type(DUMP_TYPE_CCW
);
1375 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1376 rc
= dump_set_type(DUMP_TYPE_FCP
);
1377 return (rc
!= 0) ? rc
: len
;
1380 static struct kobj_attribute dump_type_attr
=
1381 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1383 static struct kset
*dump_kset
;
1385 static void __dump_run(void *unused
)
1387 struct ccw_dev_id devid
;
1388 static char buf
[100];
1390 switch (dump_method
) {
1391 case DUMP_METHOD_CCW_CIO
:
1392 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1394 reipl_ccw_dev(&devid
);
1396 case DUMP_METHOD_CCW_VM
:
1397 sprintf(buf
, "STORE STATUS");
1398 __cpcmd(buf
, NULL
, 0, NULL
);
1399 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1400 __cpcmd(buf
, NULL
, 0, NULL
);
1402 case DUMP_METHOD_CCW_DIAG
:
1403 diag308(DIAG308_SET
, dump_block_ccw
);
1404 diag308(DIAG308_DUMP
, NULL
);
1406 case DUMP_METHOD_FCP_DIAG
:
1407 diag308(DIAG308_SET
, dump_block_fcp
);
1408 diag308(DIAG308_DUMP
, NULL
);
1415 static void dump_run(struct shutdown_trigger
*trigger
)
1417 if (dump_method
== DUMP_METHOD_NONE
)
1420 smp_switch_to_ipl_cpu(__dump_run
, NULL
);
1423 static int __init
dump_ccw_init(void)
1427 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1428 if (!dump_block_ccw
)
1430 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1432 free_page((unsigned long)dump_block_ccw
);
1435 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1436 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1437 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1438 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1439 dump_capabilities
|= DUMP_TYPE_CCW
;
1443 static int __init
dump_fcp_init(void)
1447 if (!sclp_ipl_info
.has_dump
)
1448 return 0; /* LDIPL DUMP is not installed */
1449 if (!diag308_set_works
)
1451 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1452 if (!dump_block_fcp
)
1454 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1456 free_page((unsigned long)dump_block_fcp
);
1459 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1460 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1461 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1462 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1463 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1464 dump_capabilities
|= DUMP_TYPE_FCP
;
1468 static int __init
dump_init(void)
1472 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1475 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1477 kset_unregister(dump_kset
);
1480 rc
= dump_ccw_init();
1483 rc
= dump_fcp_init();
1486 dump_set_type(DUMP_TYPE_NONE
);
1490 static struct shutdown_action __refdata dump_action
= {
1491 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1496 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1500 * Bypass dynamic address translation (DAT) when storing IPL parameter
1501 * information block address and checksum into the prefix area
1502 * (corresponding to absolute addresses 0-8191).
1503 * When enhanced DAT applies and the STE format control in one,
1504 * the absolute address is formed without prefixing. In this case a
1505 * normal store (stg/st) into the prefix area would no more match to
1506 * absolute addresses 0-8191.
1509 asm volatile("sturg %0,%1"
1510 :: "a" ((unsigned long) reipl_block_actual
),
1511 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1513 asm volatile("stura %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" (csum_partial(reipl_block_actual
,
1519 reipl_block_actual
->hdr
.len
, 0)),
1520 "a" (&lowcore_ptr
[smp_processor_id()]->ipib_checksum
));
1525 static int __init
dump_reipl_init(void)
1527 if (!diag308_set_works
)
1533 static struct shutdown_action __refdata dump_reipl_action
= {
1534 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1535 .fn
= dump_reipl_run
,
1536 .init
= dump_reipl_init
,
1540 * vmcmd shutdown action: Trigger vm command on shutdown.
1543 static char vmcmd_on_reboot
[128];
1544 static char vmcmd_on_panic
[128];
1545 static char vmcmd_on_halt
[128];
1546 static char vmcmd_on_poff
[128];
1548 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1549 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1550 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1551 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1553 static struct attribute
*vmcmd_attrs
[] = {
1554 &sys_vmcmd_on_reboot_attr
.attr
,
1555 &sys_vmcmd_on_panic_attr
.attr
,
1556 &sys_vmcmd_on_halt_attr
.attr
,
1557 &sys_vmcmd_on_poff_attr
.attr
,
1561 static struct attribute_group vmcmd_attr_group
= {
1562 .attrs
= vmcmd_attrs
,
1565 static struct kset
*vmcmd_kset
;
1567 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1569 char *cmd
, *next_cmd
;
1571 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1572 cmd
= vmcmd_on_reboot
;
1573 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1574 cmd
= vmcmd_on_panic
;
1575 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1576 cmd
= vmcmd_on_halt
;
1577 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1578 cmd
= vmcmd_on_poff
;
1582 if (strlen(cmd
) == 0)
1585 next_cmd
= strchr(cmd
, '\n');
1590 __cpcmd(cmd
, NULL
, 0, NULL
);
1592 } while (cmd
!= NULL
);
1595 static int vmcmd_init(void)
1599 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1602 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1605 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1606 vmcmd_run
, vmcmd_init
};
1609 * stop shutdown action: Stop Linux on shutdown.
1612 static void stop_run(struct shutdown_trigger
*trigger
)
1614 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1615 disabled_wait((unsigned long) __builtin_return_address(0));
1616 while (sigp(smp_processor_id(), sigp_stop
) == sigp_busy
)
1621 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1626 static struct shutdown_action
*shutdown_actions_list
[] = {
1627 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1628 &vmcmd_action
, &stop_action
};
1629 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1635 static struct kset
*shutdown_actions_kset
;
1637 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1642 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1643 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1644 if (shutdown_actions_list
[i
]->init_rc
) {
1645 return shutdown_actions_list
[i
]->init_rc
;
1647 trigger
->action
= shutdown_actions_list
[i
];
1657 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1660 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1661 struct kobj_attribute
*attr
, char *page
)
1663 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1666 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1667 struct kobj_attribute
*attr
,
1668 const char *buf
, size_t len
)
1670 return set_trigger(buf
, &on_reboot_trigger
, len
);
1673 static struct kobj_attribute on_reboot_attr
=
1674 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1676 static void do_machine_restart(char *__unused
)
1679 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1682 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1686 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1688 static ssize_t
on_panic_show(struct kobject
*kobj
,
1689 struct kobj_attribute
*attr
, char *page
)
1691 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1694 static ssize_t
on_panic_store(struct kobject
*kobj
,
1695 struct kobj_attribute
*attr
,
1696 const char *buf
, size_t len
)
1698 return set_trigger(buf
, &on_panic_trigger
, len
);
1701 static struct kobj_attribute on_panic_attr
=
1702 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1704 static void do_panic(void)
1706 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1707 stop_run(&on_panic_trigger
);
1712 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1714 static ssize_t
on_halt_show(struct kobject
*kobj
,
1715 struct kobj_attribute
*attr
, char *page
)
1717 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1720 static ssize_t
on_halt_store(struct kobject
*kobj
,
1721 struct kobj_attribute
*attr
,
1722 const char *buf
, size_t len
)
1724 return set_trigger(buf
, &on_halt_trigger
, len
);
1727 static struct kobj_attribute on_halt_attr
=
1728 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1731 static void do_machine_halt(void)
1734 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1735 stop_run(&on_halt_trigger
);
1737 void (*_machine_halt
)(void) = do_machine_halt
;
1741 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1743 static ssize_t
on_poff_show(struct kobject
*kobj
,
1744 struct kobj_attribute
*attr
, char *page
)
1746 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1749 static ssize_t
on_poff_store(struct kobject
*kobj
,
1750 struct kobj_attribute
*attr
,
1751 const char *buf
, size_t len
)
1753 return set_trigger(buf
, &on_poff_trigger
, len
);
1756 static struct kobj_attribute on_poff_attr
=
1757 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1760 static void do_machine_power_off(void)
1763 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1764 stop_run(&on_poff_trigger
);
1766 void (*_machine_power_off
)(void) = do_machine_power_off
;
1768 static void __init
shutdown_triggers_init(void)
1770 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1772 if (!shutdown_actions_kset
)
1774 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1775 &on_reboot_attr
.attr
))
1777 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1778 &on_panic_attr
.attr
))
1780 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1781 &on_halt_attr
.attr
))
1783 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1784 &on_poff_attr
.attr
))
1789 panic("shutdown_triggers_init failed\n");
1792 static void __init
shutdown_actions_init(void)
1796 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1797 if (!shutdown_actions_list
[i
]->init
)
1799 shutdown_actions_list
[i
]->init_rc
=
1800 shutdown_actions_list
[i
]->init();
1804 static int __init
s390_ipl_init(void)
1806 sclp_get_ipl_info(&sclp_ipl_info
);
1807 shutdown_actions_init();
1808 shutdown_triggers_init();
1812 __initcall(s390_ipl_init
);
1814 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1819 for (sx
= 0; src
[sx
] != 0; sx
++) {
1822 dst
[dx
++] = src
[sx
];
1828 static int __init
vmcmd_on_reboot_setup(char *str
)
1832 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1833 vmcmd_on_reboot
[127] = 0;
1834 on_reboot_trigger
.action
= &vmcmd_action
;
1837 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1839 static int __init
vmcmd_on_panic_setup(char *str
)
1843 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1844 vmcmd_on_panic
[127] = 0;
1845 on_panic_trigger
.action
= &vmcmd_action
;
1848 __setup("vmpanic=", vmcmd_on_panic_setup
);
1850 static int __init
vmcmd_on_halt_setup(char *str
)
1854 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1855 vmcmd_on_halt
[127] = 0;
1856 on_halt_trigger
.action
= &vmcmd_action
;
1859 __setup("vmhalt=", vmcmd_on_halt_setup
);
1861 static int __init
vmcmd_on_poff_setup(char *str
)
1865 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1866 vmcmd_on_poff
[127] = 0;
1867 on_poff_trigger
.action
= &vmcmd_action
;
1870 __setup("vmpoff=", vmcmd_on_poff_setup
);
1872 static int on_panic_notify(struct notifier_block
*self
,
1873 unsigned long event
, void *data
)
1879 static struct notifier_block on_panic_nb
= {
1880 .notifier_call
= on_panic_notify
,
1881 .priority
= INT_MIN
,
1884 void __init
setup_ipl(void)
1886 ipl_info
.type
= get_ipl_type();
1887 switch (ipl_info
.type
) {
1889 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1890 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1893 case IPL_TYPE_FCP_DUMP
:
1894 ipl_info
.data
.fcp
.dev_id
.devno
=
1895 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1896 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1897 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1898 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1901 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1902 sizeof(ipl_info
.data
.nss
.name
));
1904 case IPL_TYPE_UNKNOWN
:
1905 /* We have no info to copy */
1908 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1911 void __init
ipl_update_parameters(void)
1915 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1916 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1917 diag308_set_works
= 1;
1920 void __init
ipl_save_parameters(void)
1922 struct cio_iplinfo iplinfo
;
1925 if (cio_get_iplinfo(&iplinfo
))
1928 ipl_devno
= iplinfo
.devno
;
1929 ipl_flags
|= IPL_DEVNO_VALID
;
1930 if (!iplinfo
.is_qdio
)
1932 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1933 src
= (void *)(unsigned long)S390_lowcore
.ipl_parmblock_ptr
;
1934 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1935 memmove(dst
, src
, PAGE_SIZE
);
1936 S390_lowcore
.ipl_parmblock_ptr
= IPL_PARMBLOCK_ORIGIN
;
1939 static LIST_HEAD(rcall
);
1940 static DEFINE_MUTEX(rcall_mutex
);
1942 void register_reset_call(struct reset_call
*reset
)
1944 mutex_lock(&rcall_mutex
);
1945 list_add(&reset
->list
, &rcall
);
1946 mutex_unlock(&rcall_mutex
);
1948 EXPORT_SYMBOL_GPL(register_reset_call
);
1950 void unregister_reset_call(struct reset_call
*reset
)
1952 mutex_lock(&rcall_mutex
);
1953 list_del(&reset
->list
);
1954 mutex_unlock(&rcall_mutex
);
1956 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1958 static void do_reset_calls(void)
1960 struct reset_call
*reset
;
1962 list_for_each_entry(reset
, &rcall
, list
)
1966 u32 dump_prefix_page
;
1968 void s390_reset_system(void)
1970 struct _lowcore
*lc
;
1972 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
1974 /* Stack for interrupt/machine check handler */
1975 lc
->panic_stack
= S390_lowcore
.panic_stack
;
1977 /* Save prefix page address for dump case */
1978 dump_prefix_page
= (u32
)(unsigned long) lc
;
1980 /* Disable prefixing */
1983 /* Disable lowcore protection */
1984 __ctl_clear_bit(0,28);
1986 /* Set new machine check handler */
1987 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1988 S390_lowcore
.mcck_new_psw
.addr
=
1989 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
1991 /* Set new program check handler */
1992 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1993 S390_lowcore
.program_new_psw
.addr
=
1994 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;