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 static void reipl_get_ascii_vmparm(char *dest
,
276 const struct ipl_parameter_block
*ipb
)
280 char has_lowercase
= 0;
282 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
283 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
285 len
= ipb
->ipl_info
.ccw
.vm_parm_len
;
286 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
287 /* If at least one character is lowercase, we assume mixed
288 * case; otherwise we convert everything to lowercase.
290 for (i
= 0; i
< len
; i
++)
291 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
292 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
293 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
298 EBC_TOLOWER(dest
, len
);
304 void get_ipl_vmparm(char *dest
)
306 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
307 reipl_get_ascii_vmparm(dest
, &ipl_block
);
312 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
313 struct kobj_attribute
*attr
, char *page
)
315 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
317 get_ipl_vmparm(parm
);
318 return sprintf(page
, "%s\n", parm
);
321 static struct kobj_attribute sys_ipl_vm_parm_attr
=
322 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
324 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
325 struct kobj_attribute
*attr
, char *page
)
327 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
329 switch (ipl_info
.type
) {
331 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
333 case IPL_TYPE_FCP_DUMP
:
334 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
340 static struct kobj_attribute sys_ipl_device_attr
=
341 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
343 static ssize_t
ipl_parameter_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
344 char *buf
, loff_t off
, size_t count
)
346 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
350 static struct bin_attribute ipl_parameter_attr
= {
352 .name
= "binary_parameter",
356 .read
= &ipl_parameter_read
,
359 static ssize_t
ipl_scp_data_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
360 char *buf
, loff_t off
, size_t count
)
362 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
363 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
365 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
368 static struct bin_attribute ipl_scp_data_attr
= {
374 .read
= ipl_scp_data_read
,
377 /* FCP ipl device attributes */
379 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
380 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
381 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
382 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
383 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
384 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
385 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
386 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
388 static struct attribute
*ipl_fcp_attrs
[] = {
389 &sys_ipl_type_attr
.attr
,
390 &sys_ipl_device_attr
.attr
,
391 &sys_ipl_fcp_wwpn_attr
.attr
,
392 &sys_ipl_fcp_lun_attr
.attr
,
393 &sys_ipl_fcp_bootprog_attr
.attr
,
394 &sys_ipl_fcp_br_lba_attr
.attr
,
398 static struct attribute_group ipl_fcp_attr_group
= {
399 .attrs
= ipl_fcp_attrs
,
402 /* CCW ipl device attributes */
404 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
405 struct kobj_attribute
*attr
, char *page
)
407 char loadparm
[LOADPARM_LEN
+ 1] = {};
409 if (!sclp_ipl_info
.is_valid
)
410 return sprintf(page
, "#unknown#\n");
411 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
412 EBCASC(loadparm
, LOADPARM_LEN
);
414 return sprintf(page
, "%s\n", loadparm
);
417 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
418 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
420 static struct attribute
*ipl_ccw_attrs_vm
[] = {
421 &sys_ipl_type_attr
.attr
,
422 &sys_ipl_device_attr
.attr
,
423 &sys_ipl_ccw_loadparm_attr
.attr
,
424 &sys_ipl_vm_parm_attr
.attr
,
428 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
429 &sys_ipl_type_attr
.attr
,
430 &sys_ipl_device_attr
.attr
,
431 &sys_ipl_ccw_loadparm_attr
.attr
,
435 static struct attribute_group ipl_ccw_attr_group_vm
= {
436 .attrs
= ipl_ccw_attrs_vm
,
439 static struct attribute_group ipl_ccw_attr_group_lpar
= {
440 .attrs
= ipl_ccw_attrs_lpar
443 /* NSS ipl device attributes */
445 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
447 static struct attribute
*ipl_nss_attrs
[] = {
448 &sys_ipl_type_attr
.attr
,
449 &sys_ipl_nss_name_attr
.attr
,
450 &sys_ipl_ccw_loadparm_attr
.attr
,
451 &sys_ipl_vm_parm_attr
.attr
,
455 static struct attribute_group ipl_nss_attr_group
= {
456 .attrs
= ipl_nss_attrs
,
459 /* UNKNOWN ipl device attributes */
461 static struct attribute
*ipl_unknown_attrs
[] = {
462 &sys_ipl_type_attr
.attr
,
466 static struct attribute_group ipl_unknown_attr_group
= {
467 .attrs
= ipl_unknown_attrs
,
470 static struct kset
*ipl_kset
;
472 static int __init
ipl_register_fcp_files(void)
476 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
479 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
482 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
486 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
489 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
494 static void ipl_run(struct shutdown_trigger
*trigger
)
496 diag308(DIAG308_IPL
, NULL
);
498 __cpcmd("IPL", NULL
, 0, NULL
);
499 else if (ipl_info
.type
== IPL_TYPE_CCW
)
500 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
503 static int __init
ipl_init(void)
507 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
512 switch (ipl_info
.type
) {
515 rc
= sysfs_create_group(&ipl_kset
->kobj
,
516 &ipl_ccw_attr_group_vm
);
518 rc
= sysfs_create_group(&ipl_kset
->kobj
,
519 &ipl_ccw_attr_group_lpar
);
522 case IPL_TYPE_FCP_DUMP
:
523 rc
= ipl_register_fcp_files();
526 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
529 rc
= sysfs_create_group(&ipl_kset
->kobj
,
530 &ipl_unknown_attr_group
);
535 panic("ipl_init failed: rc = %i\n", rc
);
540 static struct shutdown_action __refdata ipl_action
= {
541 .name
= SHUTDOWN_ACTION_IPL_STR
,
547 * reipl shutdown action: Reboot Linux on shutdown.
550 /* VM IPL PARM attributes */
551 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
554 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
556 reipl_get_ascii_vmparm(vmparm
, ipb
);
557 return sprintf(page
, "%s\n", vmparm
);
560 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
562 const char *buf
, size_t len
)
566 /* ignore trailing newline */
568 if ((len
> 0) && (buf
[len
- 1] == '\n'))
571 if (ip_len
> vmparm_max
)
574 /* parm is used to store kernel options, check for common chars */
575 for (i
= 0; i
< ip_len
; i
++)
576 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
579 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
580 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
582 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
583 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
584 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
586 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
593 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
594 struct kobj_attribute
*attr
, char *page
)
596 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
599 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
600 struct kobj_attribute
*attr
,
601 const char *buf
, size_t len
)
603 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
607 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
608 struct kobj_attribute
*attr
, char *page
)
610 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
613 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
614 struct kobj_attribute
*attr
,
615 const char *buf
, size_t len
)
617 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
620 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
621 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
622 reipl_nss_vmparm_store
);
623 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
624 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
625 reipl_ccw_vmparm_store
);
627 /* FCP reipl device attributes */
629 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
630 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
631 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
632 reipl_block_fcp
->ipl_info
.fcp
.lun
);
633 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
634 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
635 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
636 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
637 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
638 reipl_block_fcp
->ipl_info
.fcp
.devno
);
640 static struct attribute
*reipl_fcp_attrs
[] = {
641 &sys_reipl_fcp_device_attr
.attr
,
642 &sys_reipl_fcp_wwpn_attr
.attr
,
643 &sys_reipl_fcp_lun_attr
.attr
,
644 &sys_reipl_fcp_bootprog_attr
.attr
,
645 &sys_reipl_fcp_br_lba_attr
.attr
,
649 static struct attribute_group reipl_fcp_attr_group
= {
651 .attrs
= reipl_fcp_attrs
,
654 /* CCW reipl device attributes */
656 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
657 reipl_block_ccw
->ipl_info
.ccw
.devno
);
659 static void reipl_get_ascii_loadparm(char *loadparm
,
660 struct ipl_parameter_block
*ibp
)
662 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
663 EBCASC(loadparm
, LOADPARM_LEN
);
664 loadparm
[LOADPARM_LEN
] = 0;
668 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
671 char buf
[LOADPARM_LEN
+ 1];
673 reipl_get_ascii_loadparm(buf
, ipb
);
674 return sprintf(page
, "%s\n", buf
);
677 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
678 const char *buf
, size_t len
)
682 /* ignore trailing newline */
684 if ((len
> 0) && (buf
[len
- 1] == '\n'))
686 /* loadparm can have max 8 characters and must not start with a blank */
687 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
689 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
690 for (i
= 0; i
< lp_len
; i
++) {
691 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
696 /* initialize loadparm with blanks */
697 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
698 /* copy and convert to ebcdic */
699 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
700 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
705 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
706 struct kobj_attribute
*attr
, char *page
)
708 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
711 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
712 struct kobj_attribute
*attr
,
713 const char *buf
, size_t len
)
715 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
719 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
720 struct kobj_attribute
*attr
, char *page
)
722 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
725 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
726 struct kobj_attribute
*attr
,
727 const char *buf
, size_t len
)
729 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
732 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
733 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
734 reipl_ccw_loadparm_store
);
736 static struct attribute
*reipl_ccw_attrs_vm
[] = {
737 &sys_reipl_ccw_device_attr
.attr
,
738 &sys_reipl_ccw_loadparm_attr
.attr
,
739 &sys_reipl_ccw_vmparm_attr
.attr
,
743 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
744 &sys_reipl_ccw_device_attr
.attr
,
745 &sys_reipl_ccw_loadparm_attr
.attr
,
749 static struct attribute_group reipl_ccw_attr_group_vm
= {
751 .attrs
= reipl_ccw_attrs_vm
,
754 static struct attribute_group reipl_ccw_attr_group_lpar
= {
756 .attrs
= reipl_ccw_attrs_lpar
,
760 /* NSS reipl device attributes */
761 static void reipl_get_ascii_nss_name(char *dst
,
762 struct ipl_parameter_block
*ipb
)
764 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
765 EBCASC(dst
, NSS_NAME_SIZE
);
766 dst
[NSS_NAME_SIZE
] = 0;
769 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
770 struct kobj_attribute
*attr
, char *page
)
772 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
774 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
775 return sprintf(page
, "%s\n", nss_name
);
778 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
779 struct kobj_attribute
*attr
,
780 const char *buf
, size_t len
)
784 /* ignore trailing newline */
786 if ((len
> 0) && (buf
[len
- 1] == '\n'))
789 if (nss_len
> NSS_NAME_SIZE
)
792 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
794 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
795 DIAG308_VM_FLAGS_NSS_VALID
;
796 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
797 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
798 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
800 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
801 ~DIAG308_VM_FLAGS_NSS_VALID
;
807 static struct kobj_attribute sys_reipl_nss_name_attr
=
808 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
809 reipl_nss_name_store
);
811 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
812 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
813 reipl_nss_loadparm_store
);
815 static struct attribute
*reipl_nss_attrs
[] = {
816 &sys_reipl_nss_name_attr
.attr
,
817 &sys_reipl_nss_loadparm_attr
.attr
,
818 &sys_reipl_nss_vmparm_attr
.attr
,
822 static struct attribute_group reipl_nss_attr_group
= {
824 .attrs
= reipl_nss_attrs
,
829 static int reipl_set_type(enum ipl_type type
)
831 if (!(reipl_capabilities
& type
))
836 if (diag308_set_works
)
837 reipl_method
= REIPL_METHOD_CCW_DIAG
;
838 else if (MACHINE_IS_VM
)
839 reipl_method
= REIPL_METHOD_CCW_VM
;
841 reipl_method
= REIPL_METHOD_CCW_CIO
;
842 reipl_block_actual
= reipl_block_ccw
;
845 if (diag308_set_works
)
846 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
847 else if (MACHINE_IS_VM
)
848 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
850 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
851 reipl_block_actual
= reipl_block_fcp
;
853 case IPL_TYPE_FCP_DUMP
:
854 reipl_method
= REIPL_METHOD_FCP_DUMP
;
857 if (diag308_set_works
)
858 reipl_method
= REIPL_METHOD_NSS_DIAG
;
860 reipl_method
= REIPL_METHOD_NSS
;
861 reipl_block_actual
= reipl_block_nss
;
863 case IPL_TYPE_UNKNOWN
:
864 reipl_method
= REIPL_METHOD_DEFAULT
;
873 static ssize_t
reipl_type_show(struct kobject
*kobj
,
874 struct kobj_attribute
*attr
, char *page
)
876 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
879 static ssize_t
reipl_type_store(struct kobject
*kobj
,
880 struct kobj_attribute
*attr
,
881 const char *buf
, size_t len
)
885 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
886 rc
= reipl_set_type(IPL_TYPE_CCW
);
887 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
888 rc
= reipl_set_type(IPL_TYPE_FCP
);
889 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
890 rc
= reipl_set_type(IPL_TYPE_NSS
);
891 return (rc
!= 0) ? rc
: len
;
894 static struct kobj_attribute reipl_type_attr
=
895 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
897 static struct kset
*reipl_kset
;
899 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
900 const enum ipl_method m
)
902 char loadparm
[LOADPARM_LEN
+ 1] = {};
903 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
904 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
907 reipl_get_ascii_loadparm(loadparm
, ipb
);
908 reipl_get_ascii_nss_name(nss_name
, ipb
);
909 reipl_get_ascii_vmparm(vmparm
, ipb
);
912 case REIPL_METHOD_CCW_VM
:
913 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
915 case REIPL_METHOD_NSS
:
916 pos
= sprintf(dst
, "IPL %s", nss_name
);
921 if (strlen(loadparm
) > 0)
922 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
923 if (strlen(vmparm
) > 0)
924 sprintf(dst
+ pos
, " PARM %s", vmparm
);
927 static void reipl_run(struct shutdown_trigger
*trigger
)
929 struct ccw_dev_id devid
;
930 static char buf
[128];
932 switch (reipl_method
) {
933 case REIPL_METHOD_CCW_CIO
:
934 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
936 reipl_ccw_dev(&devid
);
938 case REIPL_METHOD_CCW_VM
:
939 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
940 __cpcmd(buf
, NULL
, 0, NULL
);
942 case REIPL_METHOD_CCW_DIAG
:
943 diag308(DIAG308_SET
, reipl_block_ccw
);
944 diag308(DIAG308_IPL
, NULL
);
946 case REIPL_METHOD_FCP_RW_DIAG
:
947 diag308(DIAG308_SET
, reipl_block_fcp
);
948 diag308(DIAG308_IPL
, NULL
);
950 case REIPL_METHOD_FCP_RO_DIAG
:
951 diag308(DIAG308_IPL
, NULL
);
953 case REIPL_METHOD_FCP_RO_VM
:
954 __cpcmd("IPL", NULL
, 0, NULL
);
956 case REIPL_METHOD_NSS_DIAG
:
957 diag308(DIAG308_SET
, reipl_block_nss
);
958 diag308(DIAG308_IPL
, NULL
);
960 case REIPL_METHOD_NSS
:
961 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
962 __cpcmd(buf
, NULL
, 0, NULL
);
964 case REIPL_METHOD_DEFAULT
:
966 __cpcmd("IPL", NULL
, 0, NULL
);
967 diag308(DIAG308_IPL
, NULL
);
969 case REIPL_METHOD_FCP_DUMP
:
972 disabled_wait((unsigned long) __builtin_return_address(0));
975 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
977 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
978 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
979 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
980 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
983 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
986 /* check if read scp info worked and set loadparm */
987 if (sclp_ipl_info
.is_valid
)
988 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
989 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
991 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
992 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
993 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
996 if (MACHINE_IS_VM
&& diag308_set_works
&&
997 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
999 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
1000 ipb
->ipl_info
.ccw
.vm_parm_len
=
1001 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
1002 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
1003 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1007 static int __init
reipl_nss_init(void)
1014 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1015 if (!reipl_block_nss
)
1018 if (!diag308_set_works
)
1019 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1021 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1025 reipl_block_ccw_init(reipl_block_nss
);
1026 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1027 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1028 ' ', NSS_NAME_SIZE
);
1029 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1030 kernel_nss_name
, strlen(kernel_nss_name
));
1031 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1032 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1033 DIAG308_VM_FLAGS_NSS_VALID
;
1035 reipl_block_ccw_fill_parms(reipl_block_nss
);
1038 reipl_capabilities
|= IPL_TYPE_NSS
;
1042 static int __init
reipl_ccw_init(void)
1046 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1047 if (!reipl_block_ccw
)
1050 if (MACHINE_IS_VM
) {
1051 if (!diag308_set_works
)
1052 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1053 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1054 &reipl_ccw_attr_group_vm
);
1056 if(!diag308_set_works
)
1057 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1058 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1059 &reipl_ccw_attr_group_lpar
);
1064 reipl_block_ccw_init(reipl_block_ccw
);
1065 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1066 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1067 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1070 reipl_capabilities
|= IPL_TYPE_CCW
;
1074 static int __init
reipl_fcp_init(void)
1078 if (!diag308_set_works
) {
1079 if (ipl_info
.type
== IPL_TYPE_FCP
)
1080 make_attrs_ro(reipl_fcp_attrs
);
1085 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1086 if (!reipl_block_fcp
)
1088 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_fcp_attr_group
);
1090 free_page((unsigned long)reipl_block_fcp
);
1093 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1094 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1096 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1097 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1098 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1099 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1100 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1102 reipl_capabilities
|= IPL_TYPE_FCP
;
1106 static int __init
reipl_init(void)
1110 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1113 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1115 kset_unregister(reipl_kset
);
1118 rc
= reipl_ccw_init();
1121 rc
= reipl_fcp_init();
1124 rc
= reipl_nss_init();
1127 rc
= reipl_set_type(ipl_info
.type
);
1133 static struct shutdown_action __refdata reipl_action
= {
1134 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1140 * dump shutdown action: Dump Linux on shutdown.
1143 /* FCP dump device attributes */
1145 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1146 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1147 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1148 dump_block_fcp
->ipl_info
.fcp
.lun
);
1149 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1150 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1151 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1152 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1153 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1154 dump_block_fcp
->ipl_info
.fcp
.devno
);
1156 static struct attribute
*dump_fcp_attrs
[] = {
1157 &sys_dump_fcp_device_attr
.attr
,
1158 &sys_dump_fcp_wwpn_attr
.attr
,
1159 &sys_dump_fcp_lun_attr
.attr
,
1160 &sys_dump_fcp_bootprog_attr
.attr
,
1161 &sys_dump_fcp_br_lba_attr
.attr
,
1165 static struct attribute_group dump_fcp_attr_group
= {
1166 .name
= IPL_FCP_STR
,
1167 .attrs
= dump_fcp_attrs
,
1170 /* CCW dump device attributes */
1172 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1173 dump_block_ccw
->ipl_info
.ccw
.devno
);
1175 static struct attribute
*dump_ccw_attrs
[] = {
1176 &sys_dump_ccw_device_attr
.attr
,
1180 static struct attribute_group dump_ccw_attr_group
= {
1181 .name
= IPL_CCW_STR
,
1182 .attrs
= dump_ccw_attrs
,
1187 static int dump_set_type(enum dump_type type
)
1189 if (!(dump_capabilities
& type
))
1193 if (diag308_set_works
)
1194 dump_method
= DUMP_METHOD_CCW_DIAG
;
1195 else if (MACHINE_IS_VM
)
1196 dump_method
= DUMP_METHOD_CCW_VM
;
1198 dump_method
= DUMP_METHOD_CCW_CIO
;
1201 dump_method
= DUMP_METHOD_FCP_DIAG
;
1204 dump_method
= DUMP_METHOD_NONE
;
1210 static ssize_t
dump_type_show(struct kobject
*kobj
,
1211 struct kobj_attribute
*attr
, char *page
)
1213 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1216 static ssize_t
dump_type_store(struct kobject
*kobj
,
1217 struct kobj_attribute
*attr
,
1218 const char *buf
, size_t len
)
1222 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1223 rc
= dump_set_type(DUMP_TYPE_NONE
);
1224 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1225 rc
= dump_set_type(DUMP_TYPE_CCW
);
1226 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1227 rc
= dump_set_type(DUMP_TYPE_FCP
);
1228 return (rc
!= 0) ? rc
: len
;
1231 static struct kobj_attribute dump_type_attr
=
1232 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1234 static struct kset
*dump_kset
;
1236 static void dump_run(struct shutdown_trigger
*trigger
)
1238 struct ccw_dev_id devid
;
1239 static char buf
[100];
1241 switch (dump_method
) {
1242 case DUMP_METHOD_CCW_CIO
:
1244 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1246 reipl_ccw_dev(&devid
);
1248 case DUMP_METHOD_CCW_VM
:
1250 sprintf(buf
, "STORE STATUS");
1251 __cpcmd(buf
, NULL
, 0, NULL
);
1252 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1253 __cpcmd(buf
, NULL
, 0, NULL
);
1255 case DUMP_METHOD_CCW_DIAG
:
1256 diag308(DIAG308_SET
, dump_block_ccw
);
1257 diag308(DIAG308_DUMP
, NULL
);
1259 case DUMP_METHOD_FCP_DIAG
:
1260 diag308(DIAG308_SET
, dump_block_fcp
);
1261 diag308(DIAG308_DUMP
, NULL
);
1263 case DUMP_METHOD_NONE
:
1266 printk(KERN_EMERG
"Dump failed!\n");
1269 static int __init
dump_ccw_init(void)
1273 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1274 if (!dump_block_ccw
)
1276 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1278 free_page((unsigned long)dump_block_ccw
);
1281 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1282 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1283 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1284 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1285 dump_capabilities
|= DUMP_TYPE_CCW
;
1289 static int __init
dump_fcp_init(void)
1293 if (!sclp_ipl_info
.has_dump
)
1294 return 0; /* LDIPL DUMP is not installed */
1295 if (!diag308_set_works
)
1297 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1298 if (!dump_block_fcp
)
1300 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1302 free_page((unsigned long)dump_block_fcp
);
1305 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1306 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1307 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1308 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1309 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1310 dump_capabilities
|= DUMP_TYPE_FCP
;
1314 static int __init
dump_init(void)
1318 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1321 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1323 kset_unregister(dump_kset
);
1326 rc
= dump_ccw_init();
1329 rc
= dump_fcp_init();
1332 dump_set_type(DUMP_TYPE_NONE
);
1336 static struct shutdown_action __refdata dump_action
= {
1337 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1342 static void dump_reipl_run(struct shutdown_trigger
*trigger
)
1346 * Bypass dynamic address translation (DAT) when storing IPL parameter
1347 * information block address and checksum into the prefix area
1348 * (corresponding to absolute addresses 0-8191).
1349 * When enhanced DAT applies and the STE format control in one,
1350 * the absolute address is formed without prefixing. In this case a
1351 * normal store (stg/st) into the prefix area would no more match to
1352 * absolute addresses 0-8191.
1355 asm volatile("sturg %0,%1"
1356 :: "a" ((unsigned long) reipl_block_actual
),
1357 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1359 asm volatile("stura %0,%1"
1360 :: "a" ((unsigned long) reipl_block_actual
),
1361 "a" (&lowcore_ptr
[smp_processor_id()]->ipib
));
1363 asm volatile("stura %0,%1"
1364 :: "a" (csum_partial(reipl_block_actual
,
1365 reipl_block_actual
->hdr
.len
, 0)),
1366 "a" (&lowcore_ptr
[smp_processor_id()]->ipib_checksum
));
1371 static int __init
dump_reipl_init(void)
1373 if (!diag308_set_works
)
1379 static struct shutdown_action __refdata dump_reipl_action
= {
1380 .name
= SHUTDOWN_ACTION_DUMP_REIPL_STR
,
1381 .fn
= dump_reipl_run
,
1382 .init
= dump_reipl_init
,
1386 * vmcmd shutdown action: Trigger vm command on shutdown.
1389 static char vmcmd_on_reboot
[128];
1390 static char vmcmd_on_panic
[128];
1391 static char vmcmd_on_halt
[128];
1392 static char vmcmd_on_poff
[128];
1394 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1395 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1396 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1397 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1399 static struct attribute
*vmcmd_attrs
[] = {
1400 &sys_vmcmd_on_reboot_attr
.attr
,
1401 &sys_vmcmd_on_panic_attr
.attr
,
1402 &sys_vmcmd_on_halt_attr
.attr
,
1403 &sys_vmcmd_on_poff_attr
.attr
,
1407 static struct attribute_group vmcmd_attr_group
= {
1408 .attrs
= vmcmd_attrs
,
1411 static struct kset
*vmcmd_kset
;
1413 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1415 char *cmd
, *next_cmd
;
1417 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1418 cmd
= vmcmd_on_reboot
;
1419 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1420 cmd
= vmcmd_on_panic
;
1421 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1422 cmd
= vmcmd_on_halt
;
1423 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1424 cmd
= vmcmd_on_poff
;
1428 if (strlen(cmd
) == 0)
1431 next_cmd
= strchr(cmd
, '\n');
1436 __cpcmd(cmd
, NULL
, 0, NULL
);
1438 } while (cmd
!= NULL
);
1441 static int vmcmd_init(void)
1445 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1448 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1451 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1452 vmcmd_run
, vmcmd_init
};
1455 * stop shutdown action: Stop Linux on shutdown.
1458 static void stop_run(struct shutdown_trigger
*trigger
)
1460 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1461 disabled_wait((unsigned long) __builtin_return_address(0));
1463 signal_processor(smp_processor_id(), sigp_stop
);
1468 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1473 static struct shutdown_action
*shutdown_actions_list
[] = {
1474 &ipl_action
, &reipl_action
, &dump_reipl_action
, &dump_action
,
1475 &vmcmd_action
, &stop_action
};
1476 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1482 static struct kset
*shutdown_actions_kset
;
1484 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1489 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1490 if (sysfs_streq(buf
, shutdown_actions_list
[i
]->name
)) {
1491 if (shutdown_actions_list
[i
]->init_rc
) {
1492 return shutdown_actions_list
[i
]->init_rc
;
1494 trigger
->action
= shutdown_actions_list
[i
];
1504 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1507 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1508 struct kobj_attribute
*attr
, char *page
)
1510 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1513 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1514 struct kobj_attribute
*attr
,
1515 const char *buf
, size_t len
)
1517 return set_trigger(buf
, &on_reboot_trigger
, len
);
1520 static struct kobj_attribute on_reboot_attr
=
1521 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1523 static void do_machine_restart(char *__unused
)
1526 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1529 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1533 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1535 static ssize_t
on_panic_show(struct kobject
*kobj
,
1536 struct kobj_attribute
*attr
, char *page
)
1538 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1541 static ssize_t
on_panic_store(struct kobject
*kobj
,
1542 struct kobj_attribute
*attr
,
1543 const char *buf
, size_t len
)
1545 return set_trigger(buf
, &on_panic_trigger
, len
);
1548 static struct kobj_attribute on_panic_attr
=
1549 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1551 static void do_panic(void)
1553 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1554 stop_run(&on_panic_trigger
);
1559 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1561 static ssize_t
on_halt_show(struct kobject
*kobj
,
1562 struct kobj_attribute
*attr
, char *page
)
1564 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1567 static ssize_t
on_halt_store(struct kobject
*kobj
,
1568 struct kobj_attribute
*attr
,
1569 const char *buf
, size_t len
)
1571 return set_trigger(buf
, &on_halt_trigger
, len
);
1574 static struct kobj_attribute on_halt_attr
=
1575 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1578 static void do_machine_halt(void)
1581 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1582 stop_run(&on_halt_trigger
);
1584 void (*_machine_halt
)(void) = do_machine_halt
;
1588 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1590 static ssize_t
on_poff_show(struct kobject
*kobj
,
1591 struct kobj_attribute
*attr
, char *page
)
1593 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1596 static ssize_t
on_poff_store(struct kobject
*kobj
,
1597 struct kobj_attribute
*attr
,
1598 const char *buf
, size_t len
)
1600 return set_trigger(buf
, &on_poff_trigger
, len
);
1603 static struct kobj_attribute on_poff_attr
=
1604 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1607 static void do_machine_power_off(void)
1610 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1611 stop_run(&on_poff_trigger
);
1613 void (*_machine_power_off
)(void) = do_machine_power_off
;
1615 static void __init
shutdown_triggers_init(void)
1617 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1619 if (!shutdown_actions_kset
)
1621 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1622 &on_reboot_attr
.attr
))
1624 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1625 &on_panic_attr
.attr
))
1627 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1628 &on_halt_attr
.attr
))
1630 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1631 &on_poff_attr
.attr
))
1636 panic("shutdown_triggers_init failed\n");
1639 static void __init
shutdown_actions_init(void)
1643 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1644 if (!shutdown_actions_list
[i
]->init
)
1646 shutdown_actions_list
[i
]->init_rc
=
1647 shutdown_actions_list
[i
]->init();
1651 static int __init
s390_ipl_init(void)
1653 sclp_get_ipl_info(&sclp_ipl_info
);
1654 shutdown_actions_init();
1655 shutdown_triggers_init();
1659 __initcall(s390_ipl_init
);
1661 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1666 for (sx
= 0; src
[sx
] != 0; sx
++) {
1669 dst
[dx
++] = src
[sx
];
1675 static int __init
vmcmd_on_reboot_setup(char *str
)
1679 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1680 vmcmd_on_reboot
[127] = 0;
1681 on_reboot_trigger
.action
= &vmcmd_action
;
1684 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1686 static int __init
vmcmd_on_panic_setup(char *str
)
1690 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1691 vmcmd_on_panic
[127] = 0;
1692 on_panic_trigger
.action
= &vmcmd_action
;
1695 __setup("vmpanic=", vmcmd_on_panic_setup
);
1697 static int __init
vmcmd_on_halt_setup(char *str
)
1701 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1702 vmcmd_on_halt
[127] = 0;
1703 on_halt_trigger
.action
= &vmcmd_action
;
1706 __setup("vmhalt=", vmcmd_on_halt_setup
);
1708 static int __init
vmcmd_on_poff_setup(char *str
)
1712 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1713 vmcmd_on_poff
[127] = 0;
1714 on_poff_trigger
.action
= &vmcmd_action
;
1717 __setup("vmpoff=", vmcmd_on_poff_setup
);
1719 static int on_panic_notify(struct notifier_block
*self
,
1720 unsigned long event
, void *data
)
1726 static struct notifier_block on_panic_nb
= {
1727 .notifier_call
= on_panic_notify
,
1728 .priority
= INT_MIN
,
1731 void __init
setup_ipl(void)
1733 ipl_info
.type
= get_ipl_type();
1734 switch (ipl_info
.type
) {
1736 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1737 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1740 case IPL_TYPE_FCP_DUMP
:
1741 ipl_info
.data
.fcp
.dev_id
.devno
=
1742 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1743 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1744 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1745 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1748 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1749 sizeof(ipl_info
.data
.nss
.name
));
1751 case IPL_TYPE_UNKNOWN
:
1752 /* We have no info to copy */
1755 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1758 void __init
ipl_update_parameters(void)
1762 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1763 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1764 diag308_set_works
= 1;
1767 void __init
ipl_save_parameters(void)
1769 struct cio_iplinfo iplinfo
;
1770 unsigned int *ipl_ptr
;
1773 if (cio_get_iplinfo(&iplinfo
))
1776 ipl_devno
= iplinfo
.devno
;
1777 ipl_flags
|= IPL_DEVNO_VALID
;
1778 if (!iplinfo
.is_qdio
)
1780 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1781 ipl_ptr
= (unsigned int *)__LC_IPL_PARMBLOCK_PTR
;
1782 src
= (void *)(unsigned long)*ipl_ptr
;
1783 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1784 memmove(dst
, src
, PAGE_SIZE
);
1785 *ipl_ptr
= IPL_PARMBLOCK_ORIGIN
;
1788 static LIST_HEAD(rcall
);
1789 static DEFINE_MUTEX(rcall_mutex
);
1791 void register_reset_call(struct reset_call
*reset
)
1793 mutex_lock(&rcall_mutex
);
1794 list_add(&reset
->list
, &rcall
);
1795 mutex_unlock(&rcall_mutex
);
1797 EXPORT_SYMBOL_GPL(register_reset_call
);
1799 void unregister_reset_call(struct reset_call
*reset
)
1801 mutex_lock(&rcall_mutex
);
1802 list_del(&reset
->list
);
1803 mutex_unlock(&rcall_mutex
);
1805 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1807 static void do_reset_calls(void)
1809 struct reset_call
*reset
;
1811 list_for_each_entry(reset
, &rcall
, list
)
1815 u32 dump_prefix_page
;
1817 void s390_reset_system(void)
1819 struct _lowcore
*lc
;
1821 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
1823 /* Stack for interrupt/machine check handler */
1824 lc
->panic_stack
= S390_lowcore
.panic_stack
;
1826 /* Save prefix page address for dump case */
1827 dump_prefix_page
= (u32
)(unsigned long) lc
;
1829 /* Disable prefixing */
1832 /* Disable lowcore protection */
1833 __ctl_clear_bit(0,28);
1835 /* Set new machine check handler */
1836 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1837 S390_lowcore
.mcck_new_psw
.addr
=
1838 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
1840 /* Set new program check handler */
1841 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1842 S390_lowcore
.program_new_psw
.addr
=
1843 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;