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>
20 #include <asm/setup.h>
21 #include <asm/cpcmd.h>
23 #include <asm/ebcdic.h>
24 #include <asm/reset.h>
27 #include <asm/checksum.h>
29 #define IPL_PARM_BLOCK_VERSION 0
31 #define IPL_UNKNOWN_STR "unknown"
32 #define IPL_CCW_STR "ccw"
33 #define IPL_FCP_STR "fcp"
34 #define IPL_FCP_DUMP_STR "fcp_dump"
35 #define IPL_NSS_STR "nss"
37 #define DUMP_CCW_STR "ccw"
38 #define DUMP_FCP_STR "fcp"
39 #define DUMP_NONE_STR "none"
42 * Four shutdown trigger types are supported:
48 #define ON_PANIC_STR "on_panic"
49 #define ON_HALT_STR "on_halt"
50 #define ON_POFF_STR "on_poff"
51 #define ON_REIPL_STR "on_reboot"
53 struct shutdown_action
;
54 struct shutdown_trigger
{
56 struct shutdown_action
*action
;
60 * The following shutdown action types are supported:
62 #define SHUTDOWN_ACTION_IPL_STR "ipl"
63 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
64 #define SHUTDOWN_ACTION_DUMP_STR "dump"
65 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
66 #define SHUTDOWN_ACTION_STOP_STR "stop"
67 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
69 struct shutdown_action
{
71 void (*fn
) (struct shutdown_trigger
*trigger
);
76 static char *ipl_type_str(enum ipl_type type
)
83 case IPL_TYPE_FCP_DUMP
:
84 return IPL_FCP_DUMP_STR
;
87 case IPL_TYPE_UNKNOWN
:
89 return IPL_UNKNOWN_STR
;
99 static char *dump_type_str(enum dump_type type
)
103 return DUMP_NONE_STR
;
114 * Must be in data section since the bss section
115 * is not cleared when these are accessed.
117 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
118 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
121 REIPL_METHOD_CCW_CIO
,
122 REIPL_METHOD_CCW_DIAG
,
124 REIPL_METHOD_FCP_RO_DIAG
,
125 REIPL_METHOD_FCP_RW_DIAG
,
126 REIPL_METHOD_FCP_RO_VM
,
127 REIPL_METHOD_FCP_DUMP
,
129 REIPL_METHOD_NSS_DIAG
,
130 REIPL_METHOD_DEFAULT
,
136 DUMP_METHOD_CCW_DIAG
,
138 DUMP_METHOD_FCP_DIAG
,
141 static int diag308_set_works
= 0;
143 static struct ipl_parameter_block ipl_block
;
145 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
147 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
148 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
149 static struct ipl_parameter_block
*reipl_block_fcp
;
150 static struct ipl_parameter_block
*reipl_block_ccw
;
151 static struct ipl_parameter_block
*reipl_block_nss
;
152 static struct ipl_parameter_block
*reipl_block_actual
;
154 static int dump_capabilities
= DUMP_TYPE_NONE
;
155 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
156 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
157 static struct ipl_parameter_block
*dump_block_fcp
;
158 static struct ipl_parameter_block
*dump_block_ccw
;
160 static struct sclp_ipl_info sclp_ipl_info
;
162 int diag308(unsigned long subcode
, void *addr
)
164 register unsigned long _addr
asm("0") = (unsigned long) addr
;
165 register unsigned long _rc
asm("1") = 0;
168 " diag %0,%2,0x308\n"
171 : "+d" (_addr
), "+d" (_rc
)
172 : "d" (subcode
) : "cc", "memory");
175 EXPORT_SYMBOL_GPL(diag308
);
179 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
180 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
181 struct kobj_attribute *attr, \
184 return sprintf(page, _format, _value); \
186 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
187 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
189 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
190 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
191 struct kobj_attribute *attr, \
194 return sprintf(page, _fmt_out, \
195 (unsigned long long) _value); \
197 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
198 struct kobj_attribute *attr, \
199 const char *buf, size_t len) \
201 unsigned long long value; \
202 if (sscanf(buf, _fmt_in, &value) != 1) \
207 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
208 __ATTR(_name,(S_IRUGO | S_IWUSR), \
209 sys_##_prefix##_##_name##_show, \
210 sys_##_prefix##_##_name##_store);
212 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
213 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
214 struct kobj_attribute *attr, \
217 return sprintf(page, _fmt_out, _value); \
219 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
221 const char *buf, size_t len) \
223 strncpy(_value, buf, sizeof(_value) - 1); \
227 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
228 __ATTR(_name,(S_IRUGO | S_IWUSR), \
229 sys_##_prefix##_##_name##_show, \
230 sys_##_prefix##_##_name##_store);
232 static void make_attrs_ro(struct attribute
**attrs
)
235 (*attrs
)->mode
= S_IRUGO
;
244 static __init
enum ipl_type
get_ipl_type(void)
246 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
248 if (ipl_flags
& IPL_NSS_VALID
)
250 if (!(ipl_flags
& IPL_DEVNO_VALID
))
251 return IPL_TYPE_UNKNOWN
;
252 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
254 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
255 return IPL_TYPE_UNKNOWN
;
256 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
257 return IPL_TYPE_UNKNOWN
;
258 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
259 return IPL_TYPE_FCP_DUMP
;
263 struct ipl_info ipl_info
;
264 EXPORT_SYMBOL_GPL(ipl_info
);
266 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
269 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
272 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
274 /* VM IPL PARM routines */
275 size_t reipl_get_ascii_vmparm(char *dest
, size_t size
,
276 const struct ipl_parameter_block
*ipb
)
280 char has_lowercase
= 0;
283 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
284 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
286 len
= min_t(size_t, size
- 1, ipb
->ipl_info
.ccw
.vm_parm_len
);
287 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
288 /* If at least one character is lowercase, we assume mixed
289 * case; otherwise we convert everything to lowercase.
291 for (i
= 0; i
< len
; i
++)
292 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
293 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
294 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
299 EBC_TOLOWER(dest
, len
);
307 size_t append_ipl_vmparm(char *dest
, size_t size
)
312 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
313 rc
= reipl_get_ascii_vmparm(dest
, size
, &ipl_block
);
319 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
320 struct kobj_attribute
*attr
, char *page
)
322 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
324 append_ipl_vmparm(parm
, sizeof(parm
));
325 return sprintf(page
, "%s\n", parm
);
328 static size_t scpdata_length(const char* buf
, size_t count
)
331 if (buf
[count
- 1] != '\0' && buf
[count
- 1] != ' ')
338 size_t reipl_append_ascii_scpdata(char *dest
, size_t size
,
339 const struct ipl_parameter_block
*ipb
)
345 count
= min(size
- 1, scpdata_length(ipb
->ipl_info
.fcp
.scp_data
,
346 ipb
->ipl_info
.fcp
.scp_data_len
));
351 for (i
= 0; i
< count
; i
++) {
352 if (!isascii(ipb
->ipl_info
.fcp
.scp_data
[i
])) {
356 if (!has_lowercase
&& islower(ipb
->ipl_info
.fcp
.scp_data
[i
]))
361 memcpy(dest
, ipb
->ipl_info
.fcp
.scp_data
, count
);
363 for (i
= 0; i
< count
; i
++)
364 dest
[i
] = tolower(ipb
->ipl_info
.fcp
.scp_data
[i
]);
370 size_t append_ipl_scpdata(char *dest
, size_t len
)
375 if (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_FCP
)
376 rc
= reipl_append_ascii_scpdata(dest
, len
, &ipl_block
);
383 static struct kobj_attribute sys_ipl_vm_parm_attr
=
384 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
386 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
387 struct kobj_attribute
*attr
, char *page
)
389 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
391 switch (ipl_info
.type
) {
393 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
395 case IPL_TYPE_FCP_DUMP
:
396 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
402 static struct kobj_attribute sys_ipl_device_attr
=
403 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
405 static ssize_t
ipl_parameter_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
406 char *buf
, loff_t off
, size_t count
)
408 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
412 static struct bin_attribute ipl_parameter_attr
= {
414 .name
= "binary_parameter",
418 .read
= &ipl_parameter_read
,
421 static ssize_t
ipl_scp_data_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
422 char *buf
, loff_t off
, size_t count
)
424 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
425 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
427 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
430 static struct bin_attribute ipl_scp_data_attr
= {
436 .read
= ipl_scp_data_read
,
439 /* FCP ipl device attributes */
441 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
442 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
443 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
444 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
445 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
446 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
447 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
448 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
450 static struct attribute
*ipl_fcp_attrs
[] = {
451 &sys_ipl_type_attr
.attr
,
452 &sys_ipl_device_attr
.attr
,
453 &sys_ipl_fcp_wwpn_attr
.attr
,
454 &sys_ipl_fcp_lun_attr
.attr
,
455 &sys_ipl_fcp_bootprog_attr
.attr
,
456 &sys_ipl_fcp_br_lba_attr
.attr
,
460 static struct attribute_group ipl_fcp_attr_group
= {
461 .attrs
= ipl_fcp_attrs
,
464 /* CCW ipl device attributes */
466 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
467 struct kobj_attribute
*attr
, char *page
)
469 char loadparm
[LOADPARM_LEN
+ 1] = {};
471 if (!sclp_ipl_info
.is_valid
)
472 return sprintf(page
, "#unknown#\n");
473 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
474 EBCASC(loadparm
, LOADPARM_LEN
);
476 return sprintf(page
, "%s\n", loadparm
);
479 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
480 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
482 static struct attribute
*ipl_ccw_attrs_vm
[] = {
483 &sys_ipl_type_attr
.attr
,
484 &sys_ipl_device_attr
.attr
,
485 &sys_ipl_ccw_loadparm_attr
.attr
,
486 &sys_ipl_vm_parm_attr
.attr
,
490 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
491 &sys_ipl_type_attr
.attr
,
492 &sys_ipl_device_attr
.attr
,
493 &sys_ipl_ccw_loadparm_attr
.attr
,
497 static struct attribute_group ipl_ccw_attr_group_vm
= {
498 .attrs
= ipl_ccw_attrs_vm
,
501 static struct attribute_group ipl_ccw_attr_group_lpar
= {
502 .attrs
= ipl_ccw_attrs_lpar
505 /* NSS ipl device attributes */
507 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
509 static struct attribute
*ipl_nss_attrs
[] = {
510 &sys_ipl_type_attr
.attr
,
511 &sys_ipl_nss_name_attr
.attr
,
512 &sys_ipl_ccw_loadparm_attr
.attr
,
513 &sys_ipl_vm_parm_attr
.attr
,
517 static struct attribute_group ipl_nss_attr_group
= {
518 .attrs
= ipl_nss_attrs
,
521 /* UNKNOWN ipl device attributes */
523 static struct attribute
*ipl_unknown_attrs
[] = {
524 &sys_ipl_type_attr
.attr
,
528 static struct attribute_group ipl_unknown_attr_group
= {
529 .attrs
= ipl_unknown_attrs
,
532 static struct kset
*ipl_kset
;
534 static int __init
ipl_register_fcp_files(void)
538 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
541 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
544 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
548 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
551 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
556 static void ipl_run(struct shutdown_trigger
*trigger
)
558 diag308(DIAG308_IPL
, NULL
);
560 __cpcmd("IPL", NULL
, 0, NULL
);
561 else if (ipl_info
.type
== IPL_TYPE_CCW
)
562 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
565 static int __init
ipl_init(void)
569 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
574 switch (ipl_info
.type
) {
577 rc
= sysfs_create_group(&ipl_kset
->kobj
,
578 &ipl_ccw_attr_group_vm
);
580 rc
= sysfs_create_group(&ipl_kset
->kobj
,
581 &ipl_ccw_attr_group_lpar
);
584 case IPL_TYPE_FCP_DUMP
:
585 rc
= ipl_register_fcp_files();
588 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
591 rc
= sysfs_create_group(&ipl_kset
->kobj
,
592 &ipl_unknown_attr_group
);
597 panic("ipl_init failed: rc = %i\n", rc
);
602 static struct shutdown_action __refdata ipl_action
= {
603 .name
= SHUTDOWN_ACTION_IPL_STR
,
609 * reipl shutdown action: Reboot Linux on shutdown.
612 /* VM IPL PARM attributes */
613 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
616 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
618 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
619 return sprintf(page
, "%s\n", vmparm
);
622 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
624 const char *buf
, size_t len
)
628 /* ignore trailing newline */
630 if ((len
> 0) && (buf
[len
- 1] == '\n'))
633 if (ip_len
> vmparm_max
)
636 /* parm is used to store kernel options, check for common chars */
637 for (i
= 0; i
< ip_len
; i
++)
638 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
641 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
642 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
644 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
645 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
646 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
648 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
655 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
656 struct kobj_attribute
*attr
, char *page
)
658 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
661 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
662 struct kobj_attribute
*attr
,
663 const char *buf
, size_t len
)
665 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
669 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
670 struct kobj_attribute
*attr
, char *page
)
672 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
675 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
676 struct kobj_attribute
*attr
,
677 const char *buf
, size_t len
)
679 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
682 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
683 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
684 reipl_nss_vmparm_store
);
685 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
686 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
687 reipl_ccw_vmparm_store
);
689 /* FCP reipl device attributes */
691 static ssize_t
reipl_fcp_scpdata_read(struct kobject
*kobj
,
692 struct bin_attribute
*attr
,
693 char *buf
, loff_t off
, size_t count
)
695 size_t size
= reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
;
696 void *scp_data
= reipl_block_fcp
->ipl_info
.fcp
.scp_data
;
698 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
701 static ssize_t
reipl_fcp_scpdata_write(struct kobject
*kobj
,
702 struct bin_attribute
*attr
,
703 char *buf
, loff_t off
, size_t count
)
711 if (off
>= DIAG308_SCPDATA_SIZE
)
714 if (count
> DIAG308_SCPDATA_SIZE
- off
)
715 count
= DIAG308_SCPDATA_SIZE
- off
;
717 memcpy(reipl_block_fcp
->ipl_info
.fcp
.scp_data
, buf
+ off
, count
);
718 scpdata_len
= off
+ count
;
720 if (scpdata_len
% 8) {
721 padding
= 8 - (scpdata_len
% 8);
722 memset(reipl_block_fcp
->ipl_info
.fcp
.scp_data
+ scpdata_len
,
724 scpdata_len
+= padding
;
727 reipl_block_fcp
->ipl_info
.fcp
.scp_data_len
= scpdata_len
;
728 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
+ scpdata_len
;
729 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
+ scpdata_len
;
734 static struct bin_attribute sys_reipl_fcp_scp_data_attr
= {
737 .mode
= S_IRUGO
| S_IWUSR
,
740 .read
= reipl_fcp_scpdata_read
,
741 .write
= reipl_fcp_scpdata_write
,
744 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
745 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
746 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
747 reipl_block_fcp
->ipl_info
.fcp
.lun
);
748 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
749 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
750 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
751 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
752 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
753 reipl_block_fcp
->ipl_info
.fcp
.devno
);
755 static struct attribute
*reipl_fcp_attrs
[] = {
756 &sys_reipl_fcp_device_attr
.attr
,
757 &sys_reipl_fcp_wwpn_attr
.attr
,
758 &sys_reipl_fcp_lun_attr
.attr
,
759 &sys_reipl_fcp_bootprog_attr
.attr
,
760 &sys_reipl_fcp_br_lba_attr
.attr
,
764 static struct attribute_group reipl_fcp_attr_group
= {
765 .attrs
= reipl_fcp_attrs
,
768 /* CCW reipl device attributes */
770 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
771 reipl_block_ccw
->ipl_info
.ccw
.devno
);
773 static void reipl_get_ascii_loadparm(char *loadparm
,
774 struct ipl_parameter_block
*ibp
)
776 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
777 EBCASC(loadparm
, LOADPARM_LEN
);
778 loadparm
[LOADPARM_LEN
] = 0;
782 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
785 char buf
[LOADPARM_LEN
+ 1];
787 reipl_get_ascii_loadparm(buf
, ipb
);
788 return sprintf(page
, "%s\n", buf
);
791 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
792 const char *buf
, size_t len
)
796 /* ignore trailing newline */
798 if ((len
> 0) && (buf
[len
- 1] == '\n'))
800 /* loadparm can have max 8 characters and must not start with a blank */
801 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
803 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
804 for (i
= 0; i
< lp_len
; i
++) {
805 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
810 /* initialize loadparm with blanks */
811 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
812 /* copy and convert to ebcdic */
813 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
814 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
819 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
820 struct kobj_attribute
*attr
, char *page
)
822 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
825 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
826 struct kobj_attribute
*attr
,
827 const char *buf
, size_t len
)
829 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
833 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
834 struct kobj_attribute
*attr
, char *page
)
836 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
839 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
840 struct kobj_attribute
*attr
,
841 const char *buf
, size_t len
)
843 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
846 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
847 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
848 reipl_ccw_loadparm_store
);
850 static struct attribute
*reipl_ccw_attrs_vm
[] = {
851 &sys_reipl_ccw_device_attr
.attr
,
852 &sys_reipl_ccw_loadparm_attr
.attr
,
853 &sys_reipl_ccw_vmparm_attr
.attr
,
857 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
858 &sys_reipl_ccw_device_attr
.attr
,
859 &sys_reipl_ccw_loadparm_attr
.attr
,
863 static struct attribute_group reipl_ccw_attr_group_vm
= {
865 .attrs
= reipl_ccw_attrs_vm
,
868 static struct attribute_group reipl_ccw_attr_group_lpar
= {
870 .attrs
= reipl_ccw_attrs_lpar
,
874 /* NSS reipl device attributes */
875 static void reipl_get_ascii_nss_name(char *dst
,
876 struct ipl_parameter_block
*ipb
)
878 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
879 EBCASC(dst
, NSS_NAME_SIZE
);
880 dst
[NSS_NAME_SIZE
] = 0;
883 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
884 struct kobj_attribute
*attr
, char *page
)
886 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
888 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
889 return sprintf(page
, "%s\n", nss_name
);
892 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
893 struct kobj_attribute
*attr
,
894 const char *buf
, size_t len
)
898 /* ignore trailing newline */
900 if ((len
> 0) && (buf
[len
- 1] == '\n'))
903 if (nss_len
> NSS_NAME_SIZE
)
906 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
908 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
909 DIAG308_VM_FLAGS_NSS_VALID
;
910 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
911 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
912 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
914 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
915 ~DIAG308_VM_FLAGS_NSS_VALID
;
921 static struct kobj_attribute sys_reipl_nss_name_attr
=
922 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
923 reipl_nss_name_store
);
925 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
926 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
927 reipl_nss_loadparm_store
);
929 static struct attribute
*reipl_nss_attrs
[] = {
930 &sys_reipl_nss_name_attr
.attr
,
931 &sys_reipl_nss_loadparm_attr
.attr
,
932 &sys_reipl_nss_vmparm_attr
.attr
,
936 static struct attribute_group reipl_nss_attr_group
= {
938 .attrs
= reipl_nss_attrs
,
943 static int reipl_set_type(enum ipl_type type
)
945 if (!(reipl_capabilities
& type
))
950 if (diag308_set_works
)
951 reipl_method
= REIPL_METHOD_CCW_DIAG
;
952 else if (MACHINE_IS_VM
)
953 reipl_method
= REIPL_METHOD_CCW_VM
;
955 reipl_method
= REIPL_METHOD_CCW_CIO
;
956 reipl_block_actual
= reipl_block_ccw
;
959 if (diag308_set_works
)
960 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
961 else if (MACHINE_IS_VM
)
962 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
964 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
965 reipl_block_actual
= reipl_block_fcp
;
967 case IPL_TYPE_FCP_DUMP
:
968 reipl_method
= REIPL_METHOD_FCP_DUMP
;
971 if (diag308_set_works
)
972 reipl_method
= REIPL_METHOD_NSS_DIAG
;
974 reipl_method
= REIPL_METHOD_NSS
;
975 reipl_block_actual
= reipl_block_nss
;
977 case IPL_TYPE_UNKNOWN
:
978 reipl_method
= REIPL_METHOD_DEFAULT
;
987 static ssize_t
reipl_type_show(struct kobject
*kobj
,
988 struct kobj_attribute
*attr
, char *page
)
990 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
993 static ssize_t
reipl_type_store(struct kobject
*kobj
,
994 struct kobj_attribute
*attr
,
995 const char *buf
, size_t len
)
999 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
1000 rc
= reipl_set_type(IPL_TYPE_CCW
);
1001 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
1002 rc
= reipl_set_type(IPL_TYPE_FCP
);
1003 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
1004 rc
= reipl_set_type(IPL_TYPE_NSS
);
1005 return (rc
!= 0) ? rc
: len
;
1008 static struct kobj_attribute reipl_type_attr
=
1009 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
1011 static struct kset
*reipl_kset
;
1012 static struct kset
*reipl_fcp_kset
;
1014 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
1015 const enum ipl_method m
)
1017 char loadparm
[LOADPARM_LEN
+ 1] = {};
1018 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
1019 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
1022 reipl_get_ascii_loadparm(loadparm
, ipb
);
1023 reipl_get_ascii_nss_name(nss_name
, ipb
);
1024 reipl_get_ascii_vmparm(vmparm
, sizeof(vmparm
), ipb
);
1027 case REIPL_METHOD_CCW_VM
:
1028 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
1030 case REIPL_METHOD_NSS
:
1031 pos
= sprintf(dst
, "IPL %s", nss_name
);
1036 if (strlen(loadparm
) > 0)
1037 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
1038 if (strlen(vmparm
) > 0)
1039 sprintf(dst
+ pos
, " PARM %s", vmparm
);
1042 static void reipl_run(struct shutdown_trigger
*trigger
)
1044 struct ccw_dev_id devid
;
1045 static char buf
[128];
1047 switch (reipl_method
) {
1048 case REIPL_METHOD_CCW_CIO
:
1049 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
1051 reipl_ccw_dev(&devid
);
1053 case REIPL_METHOD_CCW_VM
:
1054 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
1055 __cpcmd(buf
, NULL
, 0, NULL
);
1057 case REIPL_METHOD_CCW_DIAG
:
1058 diag308(DIAG308_SET
, reipl_block_ccw
);
1059 diag308(DIAG308_IPL
, NULL
);
1061 case REIPL_METHOD_FCP_RW_DIAG
:
1062 diag308(DIAG308_SET
, reipl_block_fcp
);
1063 diag308(DIAG308_IPL
, NULL
);
1065 case REIPL_METHOD_FCP_RO_DIAG
:
1066 diag308(DIAG308_IPL
, NULL
);
1068 case REIPL_METHOD_FCP_RO_VM
:
1069 __cpcmd("IPL", NULL
, 0, NULL
);
1071 case REIPL_METHOD_NSS_DIAG
:
1072 diag308(DIAG308_SET
, reipl_block_nss
);
1073 diag308(DIAG308_IPL
, NULL
);
1075 case REIPL_METHOD_NSS
:
1076 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
1077 __cpcmd(buf
, NULL
, 0, NULL
);
1079 case REIPL_METHOD_DEFAULT
:
1081 __cpcmd("IPL", NULL
, 0, NULL
);
1082 diag308(DIAG308_IPL
, NULL
);
1084 case REIPL_METHOD_FCP_DUMP
:
1087 disabled_wait((unsigned long) __builtin_return_address(0));
1090 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
1092 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1093 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1094 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1095 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1098 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
1101 /* check if read scp info worked and set loadparm */
1102 if (sclp_ipl_info
.is_valid
)
1103 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
1104 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
1106 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1107 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
1108 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
1111 if (MACHINE_IS_VM
&& diag308_set_works
&&
1112 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
1114 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1115 ipb
->ipl_info
.ccw
.vm_parm_len
=
1116 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1117 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1118 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1122 static int __init
reipl_nss_init(void)
1129 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1130 if (!reipl_block_nss
)
1133 if (!diag308_set_works
)
1134 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1136 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1140 reipl_block_ccw_init(reipl_block_nss
);
1141 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1142 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1143 ' ', NSS_NAME_SIZE
);
1144 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1145 kernel_nss_name
, strlen(kernel_nss_name
));
1146 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1147 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1148 DIAG308_VM_FLAGS_NSS_VALID
;
1150 reipl_block_ccw_fill_parms(reipl_block_nss
);
1153 reipl_capabilities
|= IPL_TYPE_NSS
;
1157 static int __init
reipl_ccw_init(void)
1161 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1162 if (!reipl_block_ccw
)
1165 if (MACHINE_IS_VM
) {
1166 if (!diag308_set_works
)
1167 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1168 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1169 &reipl_ccw_attr_group_vm
);
1171 if(!diag308_set_works
)
1172 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1173 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1174 &reipl_ccw_attr_group_lpar
);
1179 reipl_block_ccw_init(reipl_block_ccw
);
1180 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1181 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1182 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1185 reipl_capabilities
|= IPL_TYPE_CCW
;
1189 static int __init
reipl_fcp_init(void)
1193 if (!diag308_set_works
) {
1194 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1195 make_attrs_ro(reipl_fcp_attrs
);
1196 sys_reipl_fcp_scp_data_attr
.attr
.mode
= S_IRUGO
;
1201 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1202 if (!reipl_block_fcp
)
1205 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1206 reipl_fcp_kset
= kset_create_and_add(IPL_FCP_STR
, NULL
,
1209 free_page((unsigned long) reipl_block_fcp
);
1213 rc
= sysfs_create_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1215 kset_unregister(reipl_fcp_kset
);
1216 free_page((unsigned long) reipl_block_fcp
);
1220 rc
= sysfs_create_bin_file(&reipl_fcp_kset
->kobj
,
1221 &sys_reipl_fcp_scp_data_attr
);
1223 sysfs_remove_group(&reipl_fcp_kset
->kobj
, &reipl_fcp_attr_group
);
1224 kset_unregister(reipl_fcp_kset
);
1225 free_page((unsigned long) reipl_block_fcp
);
1229 if (ipl_info
.type
== IPL_TYPE_FCP
)
1230 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1232 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1233 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1234 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1235 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1236 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1238 reipl_capabilities
|= IPL_TYPE_FCP
;
1242 static int __init
reipl_init(void)
1246 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1249 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1251 kset_unregister(reipl_kset
);
1254 rc
= reipl_ccw_init();
1257 rc
= reipl_fcp_init();
1260 rc
= reipl_nss_init();
1263 rc
= reipl_set_type(ipl_info
.type
);
1269 static struct shutdown_action __refdata reipl_action
= {
1270 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1276 * dump shutdown action: Dump Linux on shutdown.
1279 /* FCP dump device attributes */
1281 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1282 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1283 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1284 dump_block_fcp
->ipl_info
.fcp
.lun
);
1285 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1286 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1287 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1288 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1289 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1290 dump_block_fcp
->ipl_info
.fcp
.devno
);
1292 static struct attribute
*dump_fcp_attrs
[] = {
1293 &sys_dump_fcp_device_attr
.attr
,
1294 &sys_dump_fcp_wwpn_attr
.attr
,
1295 &sys_dump_fcp_lun_attr
.attr
,
1296 &sys_dump_fcp_bootprog_attr
.attr
,
1297 &sys_dump_fcp_br_lba_attr
.attr
,
1301 static struct attribute_group dump_fcp_attr_group
= {
1302 .name
= IPL_FCP_STR
,
1303 .attrs
= dump_fcp_attrs
,
1306 /* CCW dump device attributes */
1308 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1309 dump_block_ccw
->ipl_info
.ccw
.devno
);
1311 static struct attribute
*dump_ccw_attrs
[] = {
1312 &sys_dump_ccw_device_attr
.attr
,
1316 static struct attribute_group dump_ccw_attr_group
= {
1317 .name
= IPL_CCW_STR
,
1318 .attrs
= dump_ccw_attrs
,
1323 static int dump_set_type(enum dump_type type
)
1325 if (!(dump_capabilities
& type
))
1329 if (diag308_set_works
)
1330 dump_method
= DUMP_METHOD_CCW_DIAG
;
1331 else if (MACHINE_IS_VM
)
1332 dump_method
= DUMP_METHOD_CCW_VM
;
1334 dump_method
= DUMP_METHOD_CCW_CIO
;
1337 dump_method
= DUMP_METHOD_FCP_DIAG
;
1340 dump_method
= DUMP_METHOD_NONE
;
1346 static ssize_t
dump_type_show(struct kobject
*kobj
,
1347 struct kobj_attribute
*attr
, char *page
)
1349 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1352 static ssize_t
dump_type_store(struct kobject
*kobj
,
1353 struct kobj_attribute
*attr
,
1354 const char *buf
, size_t len
)
1358 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1359 rc
= dump_set_type(DUMP_TYPE_NONE
);
1360 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1361 rc
= dump_set_type(DUMP_TYPE_CCW
);
1362 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1363 rc
= dump_set_type(DUMP_TYPE_FCP
);
1364 return (rc
!= 0) ? rc
: len
;
1367 static struct kobj_attribute dump_type_attr
=
1368 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1370 static struct kset
*dump_kset
;
1372 static void dump_run(struct shutdown_trigger
*trigger
)
1374 struct ccw_dev_id devid
;
1375 static char buf
[100];
1377 switch (dump_method
) {
1378 case DUMP_METHOD_CCW_CIO
:
1380 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1382 reipl_ccw_dev(&devid
);
1384 case DUMP_METHOD_CCW_VM
:
1386 sprintf(buf
, "STORE STATUS");
1387 __cpcmd(buf
, NULL
, 0, NULL
);
1388 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1389 __cpcmd(buf
, NULL
, 0, NULL
);
1391 case DUMP_METHOD_CCW_DIAG
:
1392 diag308(DIAG308_SET
, dump_block_ccw
);
1393 diag308(DIAG308_DUMP
, NULL
);
1395 case DUMP_METHOD_FCP_DIAG
:
1396 diag308(DIAG308_SET
, dump_block_fcp
);
1397 diag308(DIAG308_DUMP
, NULL
);
1399 case DUMP_METHOD_NONE
:
1402 printk(KERN_EMERG
"Dump failed!\n");
1405 static int __init
dump_ccw_init(void)
1409 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1410 if (!dump_block_ccw
)
1412 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1414 free_page((unsigned long)dump_block_ccw
);
1417 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1418 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1419 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1420 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1421 dump_capabilities
|= DUMP_TYPE_CCW
;
1425 static int __init
dump_fcp_init(void)
1429 if (!sclp_ipl_info
.has_dump
)
1430 return 0; /* LDIPL DUMP is not installed */
1431 if (!diag308_set_works
)
1433 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1434 if (!dump_block_fcp
)
1436 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1438 free_page((unsigned long)dump_block_fcp
);
1441 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1442 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1443 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1444 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1445 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1446 dump_capabilities
|= DUMP_TYPE_FCP
;
1450 static int __init
dump_init(void)
1454 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1457 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1459 kset_unregister(dump_kset
);
1462 rc
= dump_ccw_init();
1465 rc
= dump_fcp_init();
1468 dump_set_type(DUMP_TYPE_NONE
);
1472 static struct shutdown_action __refdata dump_action
= {
1473 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1478 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1482 * Bypass dynamic address translation (DAT) when storing IPL parameter
1483 * information block address and checksum into the prefix area
1484 * (corresponding to absolute addresses 0-8191).
1485 * When enhanced DAT applies and the STE format control in one,
1486 * the absolute address is formed without prefixing. In this case a
1487 * normal store (stg/st) into the prefix area would no more match to
1488 * absolute addresses 0-8191.
1491 asm volatile("sturg %0,%1"
1492 :: "a" ((unsigned long) reipl_block_actual
),
1493 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1495 asm volatile("stura %0,%1"
1496 :: "a" ((unsigned long) reipl_block_actual
),
1497 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1499 asm volatile("stura %0,%1"
1500 :: "a" (csum_partial(reipl_block_actual
,
1501 reipl_block_actual
->hdr
.len
, 0)),
1502 "a" (&lowcore_ptr
[smp_processor_id()]->ipib_checksum
));
1507 static int __init
dump_reipl_init(void)
1509 if (!diag308_set_works
)
1515 static struct shutdown_action __refdata dump_reipl_action
= {
1516 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1517 .fn
= dump_reipl_run
,
1518 .init
= dump_reipl_init
,
1522 * vmcmd shutdown action: Trigger vm command on shutdown.
1525 static char vmcmd_on_reboot
[128];
1526 static char vmcmd_on_panic
[128];
1527 static char vmcmd_on_halt
[128];
1528 static char vmcmd_on_poff
[128];
1530 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1531 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1532 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1533 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1535 static struct attribute
*vmcmd_attrs
[] = {
1536 &sys_vmcmd_on_reboot_attr
.attr
,
1537 &sys_vmcmd_on_panic_attr
.attr
,
1538 &sys_vmcmd_on_halt_attr
.attr
,
1539 &sys_vmcmd_on_poff_attr
.attr
,
1543 static struct attribute_group vmcmd_attr_group
= {
1544 .attrs
= vmcmd_attrs
,
1547 static struct kset
*vmcmd_kset
;
1549 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1551 char *cmd
, *next_cmd
;
1553 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1554 cmd
= vmcmd_on_reboot
;
1555 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1556 cmd
= vmcmd_on_panic
;
1557 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1558 cmd
= vmcmd_on_halt
;
1559 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1560 cmd
= vmcmd_on_poff
;
1564 if (strlen(cmd
) == 0)
1567 next_cmd
= strchr(cmd
, '\n');
1572 __cpcmd(cmd
, NULL
, 0, NULL
);
1574 } while (cmd
!= NULL
);
1577 static int vmcmd_init(void)
1581 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1584 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1587 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1588 vmcmd_run
, vmcmd_init
};
1591 * stop shutdown action: Stop Linux on shutdown.
1594 static void stop_run(struct shutdown_trigger
*trigger
)
1596 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1597 disabled_wait((unsigned long) __builtin_return_address(0));
1599 signal_processor(smp_processor_id(), sigp_stop
);
1604 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1609 static struct shutdown_action
*shutdown_actions_list
[] = {
1610 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1611 &vmcmd_action
, &stop_action
};
1612 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1618 static struct kset
*shutdown_actions_kset
;
1620 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1625 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1626 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1627 if (shutdown_actions_list
[i
]->init_rc
) {
1628 return shutdown_actions_list
[i
]->init_rc
;
1630 trigger
->action
= shutdown_actions_list
[i
];
1640 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1643 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1644 struct kobj_attribute
*attr
, char *page
)
1646 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1649 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1650 struct kobj_attribute
*attr
,
1651 const char *buf
, size_t len
)
1653 return set_trigger(buf
, &on_reboot_trigger
, len
);
1656 static struct kobj_attribute on_reboot_attr
=
1657 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1659 static void do_machine_restart(char *__unused
)
1662 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1665 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1669 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1671 static ssize_t
on_panic_show(struct kobject
*kobj
,
1672 struct kobj_attribute
*attr
, char *page
)
1674 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1677 static ssize_t
on_panic_store(struct kobject
*kobj
,
1678 struct kobj_attribute
*attr
,
1679 const char *buf
, size_t len
)
1681 return set_trigger(buf
, &on_panic_trigger
, len
);
1684 static struct kobj_attribute on_panic_attr
=
1685 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1687 static void do_panic(void)
1689 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1690 stop_run(&on_panic_trigger
);
1695 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1697 static ssize_t
on_halt_show(struct kobject
*kobj
,
1698 struct kobj_attribute
*attr
, char *page
)
1700 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1703 static ssize_t
on_halt_store(struct kobject
*kobj
,
1704 struct kobj_attribute
*attr
,
1705 const char *buf
, size_t len
)
1707 return set_trigger(buf
, &on_halt_trigger
, len
);
1710 static struct kobj_attribute on_halt_attr
=
1711 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1714 static void do_machine_halt(void)
1717 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1718 stop_run(&on_halt_trigger
);
1720 void (*_machine_halt
)(void) = do_machine_halt
;
1724 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1726 static ssize_t
on_poff_show(struct kobject
*kobj
,
1727 struct kobj_attribute
*attr
, char *page
)
1729 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1732 static ssize_t
on_poff_store(struct kobject
*kobj
,
1733 struct kobj_attribute
*attr
,
1734 const char *buf
, size_t len
)
1736 return set_trigger(buf
, &on_poff_trigger
, len
);
1739 static struct kobj_attribute on_poff_attr
=
1740 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1743 static void do_machine_power_off(void)
1746 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1747 stop_run(&on_poff_trigger
);
1749 void (*_machine_power_off
)(void) = do_machine_power_off
;
1751 static void __init
shutdown_triggers_init(void)
1753 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1755 if (!shutdown_actions_kset
)
1757 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1758 &on_reboot_attr
.attr
))
1760 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1761 &on_panic_attr
.attr
))
1763 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1764 &on_halt_attr
.attr
))
1766 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1767 &on_poff_attr
.attr
))
1772 panic("shutdown_triggers_init failed\n");
1775 static void __init
shutdown_actions_init(void)
1779 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1780 if (!shutdown_actions_list
[i
]->init
)
1782 shutdown_actions_list
[i
]->init_rc
=
1783 shutdown_actions_list
[i
]->init();
1787 static int __init
s390_ipl_init(void)
1789 sclp_get_ipl_info(&sclp_ipl_info
);
1790 shutdown_actions_init();
1791 shutdown_triggers_init();
1795 __initcall(s390_ipl_init
);
1797 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1802 for (sx
= 0; src
[sx
] != 0; sx
++) {
1805 dst
[dx
++] = src
[sx
];
1811 static int __init
vmcmd_on_reboot_setup(char *str
)
1815 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1816 vmcmd_on_reboot
[127] = 0;
1817 on_reboot_trigger
.action
= &vmcmd_action
;
1820 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1822 static int __init
vmcmd_on_panic_setup(char *str
)
1826 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1827 vmcmd_on_panic
[127] = 0;
1828 on_panic_trigger
.action
= &vmcmd_action
;
1831 __setup("vmpanic=", vmcmd_on_panic_setup
);
1833 static int __init
vmcmd_on_halt_setup(char *str
)
1837 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1838 vmcmd_on_halt
[127] = 0;
1839 on_halt_trigger
.action
= &vmcmd_action
;
1842 __setup("vmhalt=", vmcmd_on_halt_setup
);
1844 static int __init
vmcmd_on_poff_setup(char *str
)
1848 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1849 vmcmd_on_poff
[127] = 0;
1850 on_poff_trigger
.action
= &vmcmd_action
;
1853 __setup("vmpoff=", vmcmd_on_poff_setup
);
1855 static int on_panic_notify(struct notifier_block
*self
,
1856 unsigned long event
, void *data
)
1862 static struct notifier_block on_panic_nb
= {
1863 .notifier_call
= on_panic_notify
,
1864 .priority
= INT_MIN
,
1867 void __init
setup_ipl(void)
1869 ipl_info
.type
= get_ipl_type();
1870 switch (ipl_info
.type
) {
1872 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1873 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1876 case IPL_TYPE_FCP_DUMP
:
1877 ipl_info
.data
.fcp
.dev_id
.devno
=
1878 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1879 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1880 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1881 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1884 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1885 sizeof(ipl_info
.data
.nss
.name
));
1887 case IPL_TYPE_UNKNOWN
:
1888 /* We have no info to copy */
1891 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1894 void __init
ipl_update_parameters(void)
1898 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1899 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1900 diag308_set_works
= 1;
1903 void __init
ipl_save_parameters(void)
1905 struct cio_iplinfo iplinfo
;
1906 unsigned int *ipl_ptr
;
1909 if (cio_get_iplinfo(&iplinfo
))
1912 ipl_devno
= iplinfo
.devno
;
1913 ipl_flags
|= IPL_DEVNO_VALID
;
1914 if (!iplinfo
.is_qdio
)
1916 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1917 ipl_ptr
= (unsigned int *)__LC_IPL_PARMBLOCK_PTR
;
1918 src
= (void *)(unsigned long)*ipl_ptr
;
1919 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1920 memmove(dst
, src
, PAGE_SIZE
);
1921 *ipl_ptr
= IPL_PARMBLOCK_ORIGIN
;
1924 static LIST_HEAD(rcall
);
1925 static DEFINE_MUTEX(rcall_mutex
);
1927 void register_reset_call(struct reset_call
*reset
)
1929 mutex_lock(&rcall_mutex
);
1930 list_add(&reset
->list
, &rcall
);
1931 mutex_unlock(&rcall_mutex
);
1933 EXPORT_SYMBOL_GPL(register_reset_call
);
1935 void unregister_reset_call(struct reset_call
*reset
)
1937 mutex_lock(&rcall_mutex
);
1938 list_del(&reset
->list
);
1939 mutex_unlock(&rcall_mutex
);
1941 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1943 static void do_reset_calls(void)
1945 struct reset_call
*reset
;
1947 list_for_each_entry(reset
, &rcall
, list
)
1951 u32 dump_prefix_page
;
1953 void s390_reset_system(void)
1955 struct _lowcore
*lc
;
1957 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
1959 /* Stack for interrupt/machine check handler */
1960 lc
->panic_stack
= S390_lowcore
.panic_stack
;
1962 /* Save prefix page address for dump case */
1963 dump_prefix_page
= (u32
)(unsigned long) lc
;
1965 /* Disable prefixing */
1968 /* Disable lowcore protection */
1969 __ctl_clear_bit(0,28);
1971 /* Set new machine check handler */
1972 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1973 S390_lowcore
.mcck_new_psw
.addr
=
1974 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
1976 /* Set new program check handler */
1977 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1978 S390_lowcore
.program_new_psw
.addr
=
1979 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;