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>
26 #include <asm/setup.h>
28 #define IPL_PARM_BLOCK_VERSION 0
30 #define IPL_UNKNOWN_STR "unknown"
31 #define IPL_CCW_STR "ccw"
32 #define IPL_FCP_STR "fcp"
33 #define IPL_FCP_DUMP_STR "fcp_dump"
34 #define IPL_NSS_STR "nss"
36 #define DUMP_CCW_STR "ccw"
37 #define DUMP_FCP_STR "fcp"
38 #define DUMP_NONE_STR "none"
41 * Four shutdown trigger types are supported:
47 #define ON_PANIC_STR "on_panic"
48 #define ON_HALT_STR "on_halt"
49 #define ON_POFF_STR "on_poff"
50 #define ON_REIPL_STR "on_reboot"
52 struct shutdown_action
;
53 struct shutdown_trigger
{
55 struct shutdown_action
*action
;
59 * Five shutdown action types are supported:
61 #define SHUTDOWN_ACTION_IPL_STR "ipl"
62 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
63 #define SHUTDOWN_ACTION_DUMP_STR "dump"
64 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
65 #define SHUTDOWN_ACTION_STOP_STR "stop"
67 struct shutdown_action
{
69 void (*fn
) (struct shutdown_trigger
*trigger
);
73 static char *ipl_type_str(enum ipl_type type
)
80 case IPL_TYPE_FCP_DUMP
:
81 return IPL_FCP_DUMP_STR
;
84 case IPL_TYPE_UNKNOWN
:
86 return IPL_UNKNOWN_STR
;
96 static char *dump_type_str(enum dump_type type
)
100 return DUMP_NONE_STR
;
111 * Must be in data section since the bss section
112 * is not cleared when these are accessed.
114 static u16 ipl_devno
__attribute__((__section__(".data"))) = 0;
115 u32 ipl_flags
__attribute__((__section__(".data"))) = 0;
118 REIPL_METHOD_CCW_CIO
,
119 REIPL_METHOD_CCW_DIAG
,
121 REIPL_METHOD_FCP_RO_DIAG
,
122 REIPL_METHOD_FCP_RW_DIAG
,
123 REIPL_METHOD_FCP_RO_VM
,
124 REIPL_METHOD_FCP_DUMP
,
126 REIPL_METHOD_NSS_DIAG
,
127 REIPL_METHOD_DEFAULT
,
133 DUMP_METHOD_CCW_DIAG
,
135 DUMP_METHOD_FCP_DIAG
,
138 static int diag308_set_works
= 0;
140 static struct ipl_parameter_block ipl_block
;
142 static int reipl_capabilities
= IPL_TYPE_UNKNOWN
;
144 static enum ipl_type reipl_type
= IPL_TYPE_UNKNOWN
;
145 static enum ipl_method reipl_method
= REIPL_METHOD_DEFAULT
;
146 static struct ipl_parameter_block
*reipl_block_fcp
;
147 static struct ipl_parameter_block
*reipl_block_ccw
;
148 static struct ipl_parameter_block
*reipl_block_nss
;
150 static int dump_capabilities
= DUMP_TYPE_NONE
;
151 static enum dump_type dump_type
= DUMP_TYPE_NONE
;
152 static enum dump_method dump_method
= DUMP_METHOD_NONE
;
153 static struct ipl_parameter_block
*dump_block_fcp
;
154 static struct ipl_parameter_block
*dump_block_ccw
;
156 static struct sclp_ipl_info sclp_ipl_info
;
158 int diag308(unsigned long subcode
, void *addr
)
160 register unsigned long _addr
asm("0") = (unsigned long) addr
;
161 register unsigned long _rc
asm("1") = 0;
164 " diag %0,%2,0x308\n"
167 : "+d" (_addr
), "+d" (_rc
)
168 : "d" (subcode
) : "cc", "memory");
171 EXPORT_SYMBOL_GPL(diag308
);
175 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
176 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
177 struct kobj_attribute *attr, \
180 return sprintf(page, _format, _value); \
182 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
183 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
185 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
186 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
190 return sprintf(page, _fmt_out, \
191 (unsigned long long) _value); \
193 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
194 struct kobj_attribute *attr, \
195 const char *buf, size_t len) \
197 unsigned long long value; \
198 if (sscanf(buf, _fmt_in, &value) != 1) \
203 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
204 __ATTR(_name,(S_IRUGO | S_IWUSR), \
205 sys_##_prefix##_##_name##_show, \
206 sys_##_prefix##_##_name##_store);
208 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
209 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
210 struct kobj_attribute *attr, \
213 return sprintf(page, _fmt_out, _value); \
215 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
216 struct kobj_attribute *attr, \
217 const char *buf, size_t len) \
219 strncpy(_value, buf, sizeof(_value) - 1); \
223 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
224 __ATTR(_name,(S_IRUGO | S_IWUSR), \
225 sys_##_prefix##_##_name##_show, \
226 sys_##_prefix##_##_name##_store);
228 static void make_attrs_ro(struct attribute
**attrs
)
231 (*attrs
)->mode
= S_IRUGO
;
240 static __init
enum ipl_type
get_ipl_type(void)
242 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
244 if (ipl_flags
& IPL_NSS_VALID
)
246 if (!(ipl_flags
& IPL_DEVNO_VALID
))
247 return IPL_TYPE_UNKNOWN
;
248 if (!(ipl_flags
& IPL_PARMBLOCK_VALID
))
250 if (ipl
->hdr
.version
> IPL_MAX_SUPPORTED_VERSION
)
251 return IPL_TYPE_UNKNOWN
;
252 if (ipl
->hdr
.pbt
!= DIAG308_IPL_TYPE_FCP
)
253 return IPL_TYPE_UNKNOWN
;
254 if (ipl
->ipl_info
.fcp
.opt
== DIAG308_IPL_OPT_DUMP
)
255 return IPL_TYPE_FCP_DUMP
;
259 struct ipl_info ipl_info
;
260 EXPORT_SYMBOL_GPL(ipl_info
);
262 static ssize_t
ipl_type_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
265 return sprintf(page
, "%s\n", ipl_type_str(ipl_info
.type
));
268 static struct kobj_attribute sys_ipl_type_attr
= __ATTR_RO(ipl_type
);
270 /* VM IPL PARM routines */
271 static void reipl_get_ascii_vmparm(char *dest
,
272 const struct ipl_parameter_block
*ipb
)
276 char has_lowercase
= 0;
278 if ((ipb
->ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
) &&
279 (ipb
->ipl_info
.ccw
.vm_parm_len
> 0)) {
281 len
= ipb
->ipl_info
.ccw
.vm_parm_len
;
282 memcpy(dest
, ipb
->ipl_info
.ccw
.vm_parm
, len
);
283 /* If at least one character is lowercase, we assume mixed
284 * case; otherwise we convert everything to lowercase.
286 for (i
= 0; i
< len
; i
++)
287 if ((dest
[i
] > 0x80 && dest
[i
] < 0x8a) || /* a-i */
288 (dest
[i
] > 0x90 && dest
[i
] < 0x9a) || /* j-r */
289 (dest
[i
] > 0xa1 && dest
[i
] < 0xaa)) { /* s-z */
294 EBC_TOLOWER(dest
, len
);
300 void get_ipl_vmparm(char *dest
)
302 if (diag308_set_works
&& (ipl_block
.hdr
.pbt
== DIAG308_IPL_TYPE_CCW
))
303 reipl_get_ascii_vmparm(dest
, &ipl_block
);
308 static ssize_t
ipl_vm_parm_show(struct kobject
*kobj
,
309 struct kobj_attribute
*attr
, char *page
)
311 char parm
[DIAG308_VMPARM_SIZE
+ 1] = {};
313 get_ipl_vmparm(parm
);
314 return sprintf(page
, "%s\n", parm
);
317 static struct kobj_attribute sys_ipl_vm_parm_attr
=
318 __ATTR(parm
, S_IRUGO
, ipl_vm_parm_show
, NULL
);
320 static ssize_t
sys_ipl_device_show(struct kobject
*kobj
,
321 struct kobj_attribute
*attr
, char *page
)
323 struct ipl_parameter_block
*ipl
= IPL_PARMBLOCK_START
;
325 switch (ipl_info
.type
) {
327 return sprintf(page
, "0.0.%04x\n", ipl_devno
);
329 case IPL_TYPE_FCP_DUMP
:
330 return sprintf(page
, "0.0.%04x\n", ipl
->ipl_info
.fcp
.devno
);
336 static struct kobj_attribute sys_ipl_device_attr
=
337 __ATTR(device
, S_IRUGO
, sys_ipl_device_show
, NULL
);
339 static ssize_t
ipl_parameter_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
340 char *buf
, loff_t off
, size_t count
)
342 return memory_read_from_buffer(buf
, count
, &off
, IPL_PARMBLOCK_START
,
346 static struct bin_attribute ipl_parameter_attr
= {
348 .name
= "binary_parameter",
352 .read
= &ipl_parameter_read
,
355 static ssize_t
ipl_scp_data_read(struct kobject
*kobj
, struct bin_attribute
*attr
,
356 char *buf
, loff_t off
, size_t count
)
358 unsigned int size
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data_len
;
359 void *scp_data
= &IPL_PARMBLOCK_START
->ipl_info
.fcp
.scp_data
;
361 return memory_read_from_buffer(buf
, count
, &off
, scp_data
, size
);
364 static struct bin_attribute ipl_scp_data_attr
= {
370 .read
= ipl_scp_data_read
,
373 /* FCP ipl device attributes */
375 DEFINE_IPL_ATTR_RO(ipl_fcp
, wwpn
, "0x%016llx\n", (unsigned long long)
376 IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
);
377 DEFINE_IPL_ATTR_RO(ipl_fcp
, lun
, "0x%016llx\n", (unsigned long long)
378 IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
);
379 DEFINE_IPL_ATTR_RO(ipl_fcp
, bootprog
, "%lld\n", (unsigned long long)
380 IPL_PARMBLOCK_START
->ipl_info
.fcp
.bootprog
);
381 DEFINE_IPL_ATTR_RO(ipl_fcp
, br_lba
, "%lld\n", (unsigned long long)
382 IPL_PARMBLOCK_START
->ipl_info
.fcp
.br_lba
);
384 static struct attribute
*ipl_fcp_attrs
[] = {
385 &sys_ipl_type_attr
.attr
,
386 &sys_ipl_device_attr
.attr
,
387 &sys_ipl_fcp_wwpn_attr
.attr
,
388 &sys_ipl_fcp_lun_attr
.attr
,
389 &sys_ipl_fcp_bootprog_attr
.attr
,
390 &sys_ipl_fcp_br_lba_attr
.attr
,
394 static struct attribute_group ipl_fcp_attr_group
= {
395 .attrs
= ipl_fcp_attrs
,
398 /* CCW ipl device attributes */
400 static ssize_t
ipl_ccw_loadparm_show(struct kobject
*kobj
,
401 struct kobj_attribute
*attr
, char *page
)
403 char loadparm
[LOADPARM_LEN
+ 1] = {};
405 if (!sclp_ipl_info
.is_valid
)
406 return sprintf(page
, "#unknown#\n");
407 memcpy(loadparm
, &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
408 EBCASC(loadparm
, LOADPARM_LEN
);
410 return sprintf(page
, "%s\n", loadparm
);
413 static struct kobj_attribute sys_ipl_ccw_loadparm_attr
=
414 __ATTR(loadparm
, 0444, ipl_ccw_loadparm_show
, NULL
);
416 static struct attribute
*ipl_ccw_attrs_vm
[] = {
417 &sys_ipl_type_attr
.attr
,
418 &sys_ipl_device_attr
.attr
,
419 &sys_ipl_ccw_loadparm_attr
.attr
,
420 &sys_ipl_vm_parm_attr
.attr
,
424 static struct attribute
*ipl_ccw_attrs_lpar
[] = {
425 &sys_ipl_type_attr
.attr
,
426 &sys_ipl_device_attr
.attr
,
427 &sys_ipl_ccw_loadparm_attr
.attr
,
431 static struct attribute_group ipl_ccw_attr_group_vm
= {
432 .attrs
= ipl_ccw_attrs_vm
,
435 static struct attribute_group ipl_ccw_attr_group_lpar
= {
436 .attrs
= ipl_ccw_attrs_lpar
439 /* NSS ipl device attributes */
441 DEFINE_IPL_ATTR_RO(ipl_nss
, name
, "%s\n", kernel_nss_name
);
443 static struct attribute
*ipl_nss_attrs
[] = {
444 &sys_ipl_type_attr
.attr
,
445 &sys_ipl_nss_name_attr
.attr
,
446 &sys_ipl_ccw_loadparm_attr
.attr
,
447 &sys_ipl_vm_parm_attr
.attr
,
451 static struct attribute_group ipl_nss_attr_group
= {
452 .attrs
= ipl_nss_attrs
,
455 /* UNKNOWN ipl device attributes */
457 static struct attribute
*ipl_unknown_attrs
[] = {
458 &sys_ipl_type_attr
.attr
,
462 static struct attribute_group ipl_unknown_attr_group
= {
463 .attrs
= ipl_unknown_attrs
,
466 static struct kset
*ipl_kset
;
468 static int __init
ipl_register_fcp_files(void)
472 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
475 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
478 rc
= sysfs_create_bin_file(&ipl_kset
->kobj
, &ipl_scp_data_attr
);
482 sysfs_remove_bin_file(&ipl_kset
->kobj
, &ipl_parameter_attr
);
485 sysfs_remove_group(&ipl_kset
->kobj
, &ipl_fcp_attr_group
);
490 static void ipl_run(struct shutdown_trigger
*trigger
)
492 diag308(DIAG308_IPL
, NULL
);
494 __cpcmd("IPL", NULL
, 0, NULL
);
495 else if (ipl_info
.type
== IPL_TYPE_CCW
)
496 reipl_ccw_dev(&ipl_info
.data
.ccw
.dev_id
);
499 static int __init
ipl_init(void)
503 ipl_kset
= kset_create_and_add("ipl", NULL
, firmware_kobj
);
508 switch (ipl_info
.type
) {
511 rc
= sysfs_create_group(&ipl_kset
->kobj
,
512 &ipl_ccw_attr_group_vm
);
514 rc
= sysfs_create_group(&ipl_kset
->kobj
,
515 &ipl_ccw_attr_group_lpar
);
518 case IPL_TYPE_FCP_DUMP
:
519 rc
= ipl_register_fcp_files();
522 rc
= sysfs_create_group(&ipl_kset
->kobj
, &ipl_nss_attr_group
);
525 rc
= sysfs_create_group(&ipl_kset
->kobj
,
526 &ipl_unknown_attr_group
);
531 panic("ipl_init failed: rc = %i\n", rc
);
536 static struct shutdown_action __refdata ipl_action
= {
537 .name
= SHUTDOWN_ACTION_IPL_STR
,
543 * reipl shutdown action: Reboot Linux on shutdown.
546 /* VM IPL PARM attributes */
547 static ssize_t
reipl_generic_vmparm_show(struct ipl_parameter_block
*ipb
,
550 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
552 reipl_get_ascii_vmparm(vmparm
, ipb
);
553 return sprintf(page
, "%s\n", vmparm
);
556 static ssize_t
reipl_generic_vmparm_store(struct ipl_parameter_block
*ipb
,
558 const char *buf
, size_t len
)
562 /* ignore trailing newline */
564 if ((len
> 0) && (buf
[len
- 1] == '\n'))
567 if (ip_len
> vmparm_max
)
570 /* parm is used to store kernel options, check for common chars */
571 for (i
= 0; i
< ip_len
; i
++)
572 if (!(isalnum(buf
[i
]) || isascii(buf
[i
]) || isprint(buf
[i
])))
575 memset(ipb
->ipl_info
.ccw
.vm_parm
, 0, DIAG308_VMPARM_SIZE
);
576 ipb
->ipl_info
.ccw
.vm_parm_len
= ip_len
;
578 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
579 memcpy(ipb
->ipl_info
.ccw
.vm_parm
, buf
, ip_len
);
580 ASCEBC(ipb
->ipl_info
.ccw
.vm_parm
, ip_len
);
582 ipb
->ipl_info
.ccw
.vm_flags
&= ~DIAG308_VM_FLAGS_VP_VALID
;
589 static ssize_t
reipl_nss_vmparm_show(struct kobject
*kobj
,
590 struct kobj_attribute
*attr
, char *page
)
592 return reipl_generic_vmparm_show(reipl_block_nss
, page
);
595 static ssize_t
reipl_nss_vmparm_store(struct kobject
*kobj
,
596 struct kobj_attribute
*attr
,
597 const char *buf
, size_t len
)
599 return reipl_generic_vmparm_store(reipl_block_nss
, 56, buf
, len
);
603 static ssize_t
reipl_ccw_vmparm_show(struct kobject
*kobj
,
604 struct kobj_attribute
*attr
, char *page
)
606 return reipl_generic_vmparm_show(reipl_block_ccw
, page
);
609 static ssize_t
reipl_ccw_vmparm_store(struct kobject
*kobj
,
610 struct kobj_attribute
*attr
,
611 const char *buf
, size_t len
)
613 return reipl_generic_vmparm_store(reipl_block_ccw
, 64, buf
, len
);
616 static struct kobj_attribute sys_reipl_nss_vmparm_attr
=
617 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_nss_vmparm_show
,
618 reipl_nss_vmparm_store
);
619 static struct kobj_attribute sys_reipl_ccw_vmparm_attr
=
620 __ATTR(parm
, S_IRUGO
| S_IWUSR
, reipl_ccw_vmparm_show
,
621 reipl_ccw_vmparm_store
);
623 /* FCP reipl device attributes */
625 DEFINE_IPL_ATTR_RW(reipl_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
626 reipl_block_fcp
->ipl_info
.fcp
.wwpn
);
627 DEFINE_IPL_ATTR_RW(reipl_fcp
, lun
, "0x%016llx\n", "%016llx\n",
628 reipl_block_fcp
->ipl_info
.fcp
.lun
);
629 DEFINE_IPL_ATTR_RW(reipl_fcp
, bootprog
, "%lld\n", "%lld\n",
630 reipl_block_fcp
->ipl_info
.fcp
.bootprog
);
631 DEFINE_IPL_ATTR_RW(reipl_fcp
, br_lba
, "%lld\n", "%lld\n",
632 reipl_block_fcp
->ipl_info
.fcp
.br_lba
);
633 DEFINE_IPL_ATTR_RW(reipl_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
634 reipl_block_fcp
->ipl_info
.fcp
.devno
);
636 static struct attribute
*reipl_fcp_attrs
[] = {
637 &sys_reipl_fcp_device_attr
.attr
,
638 &sys_reipl_fcp_wwpn_attr
.attr
,
639 &sys_reipl_fcp_lun_attr
.attr
,
640 &sys_reipl_fcp_bootprog_attr
.attr
,
641 &sys_reipl_fcp_br_lba_attr
.attr
,
645 static struct attribute_group reipl_fcp_attr_group
= {
647 .attrs
= reipl_fcp_attrs
,
650 /* CCW reipl device attributes */
652 DEFINE_IPL_ATTR_RW(reipl_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
653 reipl_block_ccw
->ipl_info
.ccw
.devno
);
655 static void reipl_get_ascii_loadparm(char *loadparm
,
656 struct ipl_parameter_block
*ibp
)
658 memcpy(loadparm
, ibp
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
659 EBCASC(loadparm
, LOADPARM_LEN
);
660 loadparm
[LOADPARM_LEN
] = 0;
664 static ssize_t
reipl_generic_loadparm_show(struct ipl_parameter_block
*ipb
,
667 char buf
[LOADPARM_LEN
+ 1];
669 reipl_get_ascii_loadparm(buf
, ipb
);
670 return sprintf(page
, "%s\n", buf
);
673 static ssize_t
reipl_generic_loadparm_store(struct ipl_parameter_block
*ipb
,
674 const char *buf
, size_t len
)
678 /* ignore trailing newline */
680 if ((len
> 0) && (buf
[len
- 1] == '\n'))
682 /* loadparm can have max 8 characters and must not start with a blank */
683 if ((lp_len
> LOADPARM_LEN
) || ((lp_len
> 0) && (buf
[0] == ' ')))
685 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
686 for (i
= 0; i
< lp_len
; i
++) {
687 if (isalpha(buf
[i
]) || isdigit(buf
[i
]) || (buf
[i
] == ' ') ||
692 /* initialize loadparm with blanks */
693 memset(ipb
->ipl_info
.ccw
.load_parm
, ' ', LOADPARM_LEN
);
694 /* copy and convert to ebcdic */
695 memcpy(ipb
->ipl_info
.ccw
.load_parm
, buf
, lp_len
);
696 ASCEBC(ipb
->ipl_info
.ccw
.load_parm
, LOADPARM_LEN
);
701 static ssize_t
reipl_nss_loadparm_show(struct kobject
*kobj
,
702 struct kobj_attribute
*attr
, char *page
)
704 return reipl_generic_loadparm_show(reipl_block_nss
, page
);
707 static ssize_t
reipl_nss_loadparm_store(struct kobject
*kobj
,
708 struct kobj_attribute
*attr
,
709 const char *buf
, size_t len
)
711 return reipl_generic_loadparm_store(reipl_block_nss
, buf
, len
);
715 static ssize_t
reipl_ccw_loadparm_show(struct kobject
*kobj
,
716 struct kobj_attribute
*attr
, char *page
)
718 return reipl_generic_loadparm_show(reipl_block_ccw
, page
);
721 static ssize_t
reipl_ccw_loadparm_store(struct kobject
*kobj
,
722 struct kobj_attribute
*attr
,
723 const char *buf
, size_t len
)
725 return reipl_generic_loadparm_store(reipl_block_ccw
, buf
, len
);
728 static struct kobj_attribute sys_reipl_ccw_loadparm_attr
=
729 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_ccw_loadparm_show
,
730 reipl_ccw_loadparm_store
);
732 static struct attribute
*reipl_ccw_attrs_vm
[] = {
733 &sys_reipl_ccw_device_attr
.attr
,
734 &sys_reipl_ccw_loadparm_attr
.attr
,
735 &sys_reipl_ccw_vmparm_attr
.attr
,
739 static struct attribute
*reipl_ccw_attrs_lpar
[] = {
740 &sys_reipl_ccw_device_attr
.attr
,
741 &sys_reipl_ccw_loadparm_attr
.attr
,
745 static struct attribute_group reipl_ccw_attr_group_vm
= {
747 .attrs
= reipl_ccw_attrs_vm
,
750 static struct attribute_group reipl_ccw_attr_group_lpar
= {
752 .attrs
= reipl_ccw_attrs_lpar
,
756 /* NSS reipl device attributes */
757 static void reipl_get_ascii_nss_name(char *dst
,
758 struct ipl_parameter_block
*ipb
)
760 memcpy(dst
, ipb
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
761 EBCASC(dst
, NSS_NAME_SIZE
);
762 dst
[NSS_NAME_SIZE
] = 0;
765 static ssize_t
reipl_nss_name_show(struct kobject
*kobj
,
766 struct kobj_attribute
*attr
, char *page
)
768 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
770 reipl_get_ascii_nss_name(nss_name
, reipl_block_nss
);
771 return sprintf(page
, "%s\n", nss_name
);
774 static ssize_t
reipl_nss_name_store(struct kobject
*kobj
,
775 struct kobj_attribute
*attr
,
776 const char *buf
, size_t len
)
780 /* ignore trailing newline */
782 if ((len
> 0) && (buf
[len
- 1] == '\n'))
785 if (nss_len
> NSS_NAME_SIZE
)
788 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
, 0x40, NSS_NAME_SIZE
);
790 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
791 DIAG308_VM_FLAGS_NSS_VALID
;
792 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
, buf
, nss_len
);
793 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
794 EBC_TOUPPER(reipl_block_nss
->ipl_info
.ccw
.nss_name
, nss_len
);
796 reipl_block_nss
->ipl_info
.ccw
.vm_flags
&=
797 ~DIAG308_VM_FLAGS_NSS_VALID
;
803 static struct kobj_attribute sys_reipl_nss_name_attr
=
804 __ATTR(name
, S_IRUGO
| S_IWUSR
, reipl_nss_name_show
,
805 reipl_nss_name_store
);
807 static struct kobj_attribute sys_reipl_nss_loadparm_attr
=
808 __ATTR(loadparm
, S_IRUGO
| S_IWUSR
, reipl_nss_loadparm_show
,
809 reipl_nss_loadparm_store
);
811 static struct attribute
*reipl_nss_attrs
[] = {
812 &sys_reipl_nss_name_attr
.attr
,
813 &sys_reipl_nss_loadparm_attr
.attr
,
814 &sys_reipl_nss_vmparm_attr
.attr
,
818 static struct attribute_group reipl_nss_attr_group
= {
820 .attrs
= reipl_nss_attrs
,
825 static int reipl_set_type(enum ipl_type type
)
827 if (!(reipl_capabilities
& type
))
832 if (diag308_set_works
)
833 reipl_method
= REIPL_METHOD_CCW_DIAG
;
834 else if (MACHINE_IS_VM
)
835 reipl_method
= REIPL_METHOD_CCW_VM
;
837 reipl_method
= REIPL_METHOD_CCW_CIO
;
840 if (diag308_set_works
)
841 reipl_method
= REIPL_METHOD_FCP_RW_DIAG
;
842 else if (MACHINE_IS_VM
)
843 reipl_method
= REIPL_METHOD_FCP_RO_VM
;
845 reipl_method
= REIPL_METHOD_FCP_RO_DIAG
;
847 case IPL_TYPE_FCP_DUMP
:
848 reipl_method
= REIPL_METHOD_FCP_DUMP
;
851 if (diag308_set_works
)
852 reipl_method
= REIPL_METHOD_NSS_DIAG
;
854 reipl_method
= REIPL_METHOD_NSS
;
856 case IPL_TYPE_UNKNOWN
:
857 reipl_method
= REIPL_METHOD_DEFAULT
;
866 static ssize_t
reipl_type_show(struct kobject
*kobj
,
867 struct kobj_attribute
*attr
, char *page
)
869 return sprintf(page
, "%s\n", ipl_type_str(reipl_type
));
872 static ssize_t
reipl_type_store(struct kobject
*kobj
,
873 struct kobj_attribute
*attr
,
874 const char *buf
, size_t len
)
878 if (strncmp(buf
, IPL_CCW_STR
, strlen(IPL_CCW_STR
)) == 0)
879 rc
= reipl_set_type(IPL_TYPE_CCW
);
880 else if (strncmp(buf
, IPL_FCP_STR
, strlen(IPL_FCP_STR
)) == 0)
881 rc
= reipl_set_type(IPL_TYPE_FCP
);
882 else if (strncmp(buf
, IPL_NSS_STR
, strlen(IPL_NSS_STR
)) == 0)
883 rc
= reipl_set_type(IPL_TYPE_NSS
);
884 return (rc
!= 0) ? rc
: len
;
887 static struct kobj_attribute reipl_type_attr
=
888 __ATTR(reipl_type
, 0644, reipl_type_show
, reipl_type_store
);
890 static struct kset
*reipl_kset
;
892 static void get_ipl_string(char *dst
, struct ipl_parameter_block
*ipb
,
893 const enum ipl_method m
)
895 char loadparm
[LOADPARM_LEN
+ 1] = {};
896 char vmparm
[DIAG308_VMPARM_SIZE
+ 1] = {};
897 char nss_name
[NSS_NAME_SIZE
+ 1] = {};
900 reipl_get_ascii_loadparm(loadparm
, ipb
);
901 reipl_get_ascii_nss_name(nss_name
, ipb
);
902 reipl_get_ascii_vmparm(vmparm
, ipb
);
905 case REIPL_METHOD_CCW_VM
:
906 pos
= sprintf(dst
, "IPL %X CLEAR", ipb
->ipl_info
.ccw
.devno
);
908 case REIPL_METHOD_NSS
:
909 pos
= sprintf(dst
, "IPL %s", nss_name
);
914 if (strlen(loadparm
) > 0)
915 pos
+= sprintf(dst
+ pos
, " LOADPARM '%s'", loadparm
);
916 if (strlen(vmparm
) > 0)
917 sprintf(dst
+ pos
, " PARM %s", vmparm
);
920 static void reipl_run(struct shutdown_trigger
*trigger
)
922 struct ccw_dev_id devid
;
923 static char buf
[128];
925 switch (reipl_method
) {
926 case REIPL_METHOD_CCW_CIO
:
927 devid
.devno
= reipl_block_ccw
->ipl_info
.ccw
.devno
;
929 reipl_ccw_dev(&devid
);
931 case REIPL_METHOD_CCW_VM
:
932 get_ipl_string(buf
, reipl_block_ccw
, REIPL_METHOD_CCW_VM
);
933 __cpcmd(buf
, NULL
, 0, NULL
);
935 case REIPL_METHOD_CCW_DIAG
:
936 diag308(DIAG308_SET
, reipl_block_ccw
);
937 diag308(DIAG308_IPL
, NULL
);
939 case REIPL_METHOD_FCP_RW_DIAG
:
940 diag308(DIAG308_SET
, reipl_block_fcp
);
941 diag308(DIAG308_IPL
, NULL
);
943 case REIPL_METHOD_FCP_RO_DIAG
:
944 diag308(DIAG308_IPL
, NULL
);
946 case REIPL_METHOD_FCP_RO_VM
:
947 __cpcmd("IPL", NULL
, 0, NULL
);
949 case REIPL_METHOD_NSS_DIAG
:
950 diag308(DIAG308_SET
, reipl_block_nss
);
951 diag308(DIAG308_IPL
, NULL
);
953 case REIPL_METHOD_NSS
:
954 get_ipl_string(buf
, reipl_block_nss
, REIPL_METHOD_NSS
);
955 __cpcmd(buf
, NULL
, 0, NULL
);
957 case REIPL_METHOD_DEFAULT
:
959 __cpcmd("IPL", NULL
, 0, NULL
);
960 diag308(DIAG308_IPL
, NULL
);
962 case REIPL_METHOD_FCP_DUMP
:
966 disabled_wait((unsigned long) __builtin_return_address(0));
969 static void reipl_block_ccw_init(struct ipl_parameter_block
*ipb
)
971 ipb
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
972 ipb
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
973 ipb
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
974 ipb
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
977 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block
*ipb
)
980 /* check if read scp info worked and set loadparm */
981 if (sclp_ipl_info
.is_valid
)
982 memcpy(ipb
->ipl_info
.ccw
.load_parm
,
983 &sclp_ipl_info
.loadparm
, LOADPARM_LEN
);
985 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
986 memset(ipb
->ipl_info
.ccw
.load_parm
, 0x40, LOADPARM_LEN
);
987 ipb
->hdr
.flags
= DIAG308_FLAGS_LP_VALID
;
990 if (MACHINE_IS_VM
&& diag308_set_works
&&
991 (ipl_block
.ipl_info
.ccw
.vm_flags
& DIAG308_VM_FLAGS_VP_VALID
)) {
993 ipb
->ipl_info
.ccw
.vm_flags
|= DIAG308_VM_FLAGS_VP_VALID
;
994 ipb
->ipl_info
.ccw
.vm_parm_len
=
995 ipl_block
.ipl_info
.ccw
.vm_parm_len
;
996 memcpy(ipb
->ipl_info
.ccw
.vm_parm
,
997 ipl_block
.ipl_info
.ccw
.vm_parm
, DIAG308_VMPARM_SIZE
);
1001 static int __init
reipl_nss_init(void)
1008 reipl_block_nss
= (void *) get_zeroed_page(GFP_KERNEL
);
1009 if (!reipl_block_nss
)
1012 if (!diag308_set_works
)
1013 sys_reipl_nss_vmparm_attr
.attr
.mode
= S_IRUGO
;
1015 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_nss_attr_group
);
1019 reipl_block_ccw_init(reipl_block_nss
);
1020 if (ipl_info
.type
== IPL_TYPE_NSS
) {
1021 memset(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1022 ' ', NSS_NAME_SIZE
);
1023 memcpy(reipl_block_nss
->ipl_info
.ccw
.nss_name
,
1024 kernel_nss_name
, strlen(kernel_nss_name
));
1025 ASCEBC(reipl_block_nss
->ipl_info
.ccw
.nss_name
, NSS_NAME_SIZE
);
1026 reipl_block_nss
->ipl_info
.ccw
.vm_flags
|=
1027 DIAG308_VM_FLAGS_NSS_VALID
;
1029 reipl_block_ccw_fill_parms(reipl_block_nss
);
1032 reipl_capabilities
|= IPL_TYPE_NSS
;
1036 static int __init
reipl_ccw_init(void)
1040 reipl_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1041 if (!reipl_block_ccw
)
1044 if (MACHINE_IS_VM
) {
1045 if (!diag308_set_works
)
1046 sys_reipl_ccw_vmparm_attr
.attr
.mode
= S_IRUGO
;
1047 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1048 &reipl_ccw_attr_group_vm
);
1050 if(!diag308_set_works
)
1051 sys_reipl_ccw_loadparm_attr
.attr
.mode
= S_IRUGO
;
1052 rc
= sysfs_create_group(&reipl_kset
->kobj
,
1053 &reipl_ccw_attr_group_lpar
);
1058 reipl_block_ccw_init(reipl_block_ccw
);
1059 if (ipl_info
.type
== IPL_TYPE_CCW
) {
1060 reipl_block_ccw
->ipl_info
.ccw
.devno
= ipl_devno
;
1061 reipl_block_ccw_fill_parms(reipl_block_ccw
);
1064 reipl_capabilities
|= IPL_TYPE_CCW
;
1068 static int __init
reipl_fcp_init(void)
1072 if ((!diag308_set_works
) && (ipl_info
.type
!= IPL_TYPE_FCP
))
1074 if ((!diag308_set_works
) && (ipl_info
.type
== IPL_TYPE_FCP
))
1075 make_attrs_ro(reipl_fcp_attrs
);
1077 reipl_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1078 if (!reipl_block_fcp
)
1080 rc
= sysfs_create_group(&reipl_kset
->kobj
, &reipl_fcp_attr_group
);
1082 free_page((unsigned long)reipl_block_fcp
);
1085 if (ipl_info
.type
== IPL_TYPE_FCP
) {
1086 memcpy(reipl_block_fcp
, IPL_PARMBLOCK_START
, PAGE_SIZE
);
1088 reipl_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1089 reipl_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1090 reipl_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1091 reipl_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1092 reipl_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_IPL
;
1094 reipl_capabilities
|= IPL_TYPE_FCP
;
1098 static int __init
reipl_init(void)
1102 reipl_kset
= kset_create_and_add("reipl", NULL
, firmware_kobj
);
1105 rc
= sysfs_create_file(&reipl_kset
->kobj
, &reipl_type_attr
.attr
);
1107 kset_unregister(reipl_kset
);
1110 rc
= reipl_ccw_init();
1113 rc
= reipl_fcp_init();
1116 rc
= reipl_nss_init();
1119 rc
= reipl_set_type(ipl_info
.type
);
1125 static struct shutdown_action __refdata reipl_action
= {
1126 .name
= SHUTDOWN_ACTION_REIPL_STR
,
1132 * dump shutdown action: Dump Linux on shutdown.
1135 /* FCP dump device attributes */
1137 DEFINE_IPL_ATTR_RW(dump_fcp
, wwpn
, "0x%016llx\n", "%016llx\n",
1138 dump_block_fcp
->ipl_info
.fcp
.wwpn
);
1139 DEFINE_IPL_ATTR_RW(dump_fcp
, lun
, "0x%016llx\n", "%016llx\n",
1140 dump_block_fcp
->ipl_info
.fcp
.lun
);
1141 DEFINE_IPL_ATTR_RW(dump_fcp
, bootprog
, "%lld\n", "%lld\n",
1142 dump_block_fcp
->ipl_info
.fcp
.bootprog
);
1143 DEFINE_IPL_ATTR_RW(dump_fcp
, br_lba
, "%lld\n", "%lld\n",
1144 dump_block_fcp
->ipl_info
.fcp
.br_lba
);
1145 DEFINE_IPL_ATTR_RW(dump_fcp
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1146 dump_block_fcp
->ipl_info
.fcp
.devno
);
1148 static struct attribute
*dump_fcp_attrs
[] = {
1149 &sys_dump_fcp_device_attr
.attr
,
1150 &sys_dump_fcp_wwpn_attr
.attr
,
1151 &sys_dump_fcp_lun_attr
.attr
,
1152 &sys_dump_fcp_bootprog_attr
.attr
,
1153 &sys_dump_fcp_br_lba_attr
.attr
,
1157 static struct attribute_group dump_fcp_attr_group
= {
1158 .name
= IPL_FCP_STR
,
1159 .attrs
= dump_fcp_attrs
,
1162 /* CCW dump device attributes */
1164 DEFINE_IPL_ATTR_RW(dump_ccw
, device
, "0.0.%04llx\n", "0.0.%llx\n",
1165 dump_block_ccw
->ipl_info
.ccw
.devno
);
1167 static struct attribute
*dump_ccw_attrs
[] = {
1168 &sys_dump_ccw_device_attr
.attr
,
1172 static struct attribute_group dump_ccw_attr_group
= {
1173 .name
= IPL_CCW_STR
,
1174 .attrs
= dump_ccw_attrs
,
1179 static int dump_set_type(enum dump_type type
)
1181 if (!(dump_capabilities
& type
))
1185 if (diag308_set_works
)
1186 dump_method
= DUMP_METHOD_CCW_DIAG
;
1187 else if (MACHINE_IS_VM
)
1188 dump_method
= DUMP_METHOD_CCW_VM
;
1190 dump_method
= DUMP_METHOD_CCW_CIO
;
1193 dump_method
= DUMP_METHOD_FCP_DIAG
;
1196 dump_method
= DUMP_METHOD_NONE
;
1202 static ssize_t
dump_type_show(struct kobject
*kobj
,
1203 struct kobj_attribute
*attr
, char *page
)
1205 return sprintf(page
, "%s\n", dump_type_str(dump_type
));
1208 static ssize_t
dump_type_store(struct kobject
*kobj
,
1209 struct kobj_attribute
*attr
,
1210 const char *buf
, size_t len
)
1214 if (strncmp(buf
, DUMP_NONE_STR
, strlen(DUMP_NONE_STR
)) == 0)
1215 rc
= dump_set_type(DUMP_TYPE_NONE
);
1216 else if (strncmp(buf
, DUMP_CCW_STR
, strlen(DUMP_CCW_STR
)) == 0)
1217 rc
= dump_set_type(DUMP_TYPE_CCW
);
1218 else if (strncmp(buf
, DUMP_FCP_STR
, strlen(DUMP_FCP_STR
)) == 0)
1219 rc
= dump_set_type(DUMP_TYPE_FCP
);
1220 return (rc
!= 0) ? rc
: len
;
1223 static struct kobj_attribute dump_type_attr
=
1224 __ATTR(dump_type
, 0644, dump_type_show
, dump_type_store
);
1226 static struct kset
*dump_kset
;
1228 static void dump_run(struct shutdown_trigger
*trigger
)
1230 struct ccw_dev_id devid
;
1231 static char buf
[100];
1233 switch (dump_method
) {
1234 case DUMP_METHOD_CCW_CIO
:
1236 devid
.devno
= dump_block_ccw
->ipl_info
.ccw
.devno
;
1238 reipl_ccw_dev(&devid
);
1240 case DUMP_METHOD_CCW_VM
:
1242 sprintf(buf
, "STORE STATUS");
1243 __cpcmd(buf
, NULL
, 0, NULL
);
1244 sprintf(buf
, "IPL %X", dump_block_ccw
->ipl_info
.ccw
.devno
);
1245 __cpcmd(buf
, NULL
, 0, NULL
);
1247 case DUMP_METHOD_CCW_DIAG
:
1248 diag308(DIAG308_SET
, dump_block_ccw
);
1249 diag308(DIAG308_DUMP
, NULL
);
1251 case DUMP_METHOD_FCP_DIAG
:
1252 diag308(DIAG308_SET
, dump_block_fcp
);
1253 diag308(DIAG308_DUMP
, NULL
);
1255 case DUMP_METHOD_NONE
:
1259 printk(KERN_EMERG
"Dump failed!\n");
1262 static int __init
dump_ccw_init(void)
1266 dump_block_ccw
= (void *) get_zeroed_page(GFP_KERNEL
);
1267 if (!dump_block_ccw
)
1269 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_ccw_attr_group
);
1271 free_page((unsigned long)dump_block_ccw
);
1274 dump_block_ccw
->hdr
.len
= IPL_PARM_BLK_CCW_LEN
;
1275 dump_block_ccw
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1276 dump_block_ccw
->hdr
.blk0_len
= IPL_PARM_BLK0_CCW_LEN
;
1277 dump_block_ccw
->hdr
.pbt
= DIAG308_IPL_TYPE_CCW
;
1278 dump_capabilities
|= DUMP_TYPE_CCW
;
1282 static int __init
dump_fcp_init(void)
1286 if (!sclp_ipl_info
.has_dump
)
1287 return 0; /* LDIPL DUMP is not installed */
1288 if (!diag308_set_works
)
1290 dump_block_fcp
= (void *) get_zeroed_page(GFP_KERNEL
);
1291 if (!dump_block_fcp
)
1293 rc
= sysfs_create_group(&dump_kset
->kobj
, &dump_fcp_attr_group
);
1295 free_page((unsigned long)dump_block_fcp
);
1298 dump_block_fcp
->hdr
.len
= IPL_PARM_BLK_FCP_LEN
;
1299 dump_block_fcp
->hdr
.version
= IPL_PARM_BLOCK_VERSION
;
1300 dump_block_fcp
->hdr
.blk0_len
= IPL_PARM_BLK0_FCP_LEN
;
1301 dump_block_fcp
->hdr
.pbt
= DIAG308_IPL_TYPE_FCP
;
1302 dump_block_fcp
->ipl_info
.fcp
.opt
= DIAG308_IPL_OPT_DUMP
;
1303 dump_capabilities
|= DUMP_TYPE_FCP
;
1307 static int __init
dump_init(void)
1311 dump_kset
= kset_create_and_add("dump", NULL
, firmware_kobj
);
1314 rc
= sysfs_create_file(&dump_kset
->kobj
, &dump_type_attr
.attr
);
1316 kset_unregister(dump_kset
);
1319 rc
= dump_ccw_init();
1322 rc
= dump_fcp_init();
1325 dump_set_type(DUMP_TYPE_NONE
);
1329 static struct shutdown_action __refdata dump_action
= {
1330 .name
= SHUTDOWN_ACTION_DUMP_STR
,
1336 * vmcmd shutdown action: Trigger vm command on shutdown.
1339 static char vmcmd_on_reboot
[128];
1340 static char vmcmd_on_panic
[128];
1341 static char vmcmd_on_halt
[128];
1342 static char vmcmd_on_poff
[128];
1344 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_reboot
, "%s\n", "%s\n", vmcmd_on_reboot
);
1345 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_panic
, "%s\n", "%s\n", vmcmd_on_panic
);
1346 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_halt
, "%s\n", "%s\n", vmcmd_on_halt
);
1347 DEFINE_IPL_ATTR_STR_RW(vmcmd
, on_poff
, "%s\n", "%s\n", vmcmd_on_poff
);
1349 static struct attribute
*vmcmd_attrs
[] = {
1350 &sys_vmcmd_on_reboot_attr
.attr
,
1351 &sys_vmcmd_on_panic_attr
.attr
,
1352 &sys_vmcmd_on_halt_attr
.attr
,
1353 &sys_vmcmd_on_poff_attr
.attr
,
1357 static struct attribute_group vmcmd_attr_group
= {
1358 .attrs
= vmcmd_attrs
,
1361 static struct kset
*vmcmd_kset
;
1363 static void vmcmd_run(struct shutdown_trigger
*trigger
)
1365 char *cmd
, *next_cmd
;
1367 if (strcmp(trigger
->name
, ON_REIPL_STR
) == 0)
1368 cmd
= vmcmd_on_reboot
;
1369 else if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1370 cmd
= vmcmd_on_panic
;
1371 else if (strcmp(trigger
->name
, ON_HALT_STR
) == 0)
1372 cmd
= vmcmd_on_halt
;
1373 else if (strcmp(trigger
->name
, ON_POFF_STR
) == 0)
1374 cmd
= vmcmd_on_poff
;
1378 if (strlen(cmd
) == 0)
1381 next_cmd
= strchr(cmd
, '\n');
1386 __cpcmd(cmd
, NULL
, 0, NULL
);
1388 } while (cmd
!= NULL
);
1391 static int vmcmd_init(void)
1395 vmcmd_kset
= kset_create_and_add("vmcmd", NULL
, firmware_kobj
);
1398 return sysfs_create_group(&vmcmd_kset
->kobj
, &vmcmd_attr_group
);
1401 static struct shutdown_action vmcmd_action
= {SHUTDOWN_ACTION_VMCMD_STR
,
1402 vmcmd_run
, vmcmd_init
};
1405 * stop shutdown action: Stop Linux on shutdown.
1408 static void stop_run(struct shutdown_trigger
*trigger
)
1410 if (strcmp(trigger
->name
, ON_PANIC_STR
) == 0)
1411 disabled_wait((unsigned long) __builtin_return_address(0));
1413 signal_processor(smp_processor_id(), sigp_stop
);
1418 static struct shutdown_action stop_action
= {SHUTDOWN_ACTION_STOP_STR
,
1423 static struct shutdown_action
*shutdown_actions_list
[] = {
1424 &ipl_action
, &reipl_action
, &dump_action
, &vmcmd_action
, &stop_action
};
1425 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1431 static struct kset
*shutdown_actions_kset
;
1433 static int set_trigger(const char *buf
, struct shutdown_trigger
*trigger
,
1437 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1438 if (!shutdown_actions_list
[i
])
1440 if (strncmp(buf
, shutdown_actions_list
[i
]->name
,
1441 strlen(shutdown_actions_list
[i
]->name
)) == 0) {
1442 trigger
->action
= shutdown_actions_list
[i
];
1451 static struct shutdown_trigger on_reboot_trigger
= {ON_REIPL_STR
,
1454 static ssize_t
on_reboot_show(struct kobject
*kobj
,
1455 struct kobj_attribute
*attr
, char *page
)
1457 return sprintf(page
, "%s\n", on_reboot_trigger
.action
->name
);
1460 static ssize_t
on_reboot_store(struct kobject
*kobj
,
1461 struct kobj_attribute
*attr
,
1462 const char *buf
, size_t len
)
1464 return set_trigger(buf
, &on_reboot_trigger
, len
);
1467 static struct kobj_attribute on_reboot_attr
=
1468 __ATTR(on_reboot
, 0644, on_reboot_show
, on_reboot_store
);
1470 static void do_machine_restart(char *__unused
)
1473 on_reboot_trigger
.action
->fn(&on_reboot_trigger
);
1476 void (*_machine_restart
)(char *command
) = do_machine_restart
;
1480 static struct shutdown_trigger on_panic_trigger
= {ON_PANIC_STR
, &stop_action
};
1482 static ssize_t
on_panic_show(struct kobject
*kobj
,
1483 struct kobj_attribute
*attr
, char *page
)
1485 return sprintf(page
, "%s\n", on_panic_trigger
.action
->name
);
1488 static ssize_t
on_panic_store(struct kobject
*kobj
,
1489 struct kobj_attribute
*attr
,
1490 const char *buf
, size_t len
)
1492 return set_trigger(buf
, &on_panic_trigger
, len
);
1495 static struct kobj_attribute on_panic_attr
=
1496 __ATTR(on_panic
, 0644, on_panic_show
, on_panic_store
);
1498 static void do_panic(void)
1500 on_panic_trigger
.action
->fn(&on_panic_trigger
);
1501 stop_run(&on_panic_trigger
);
1506 static struct shutdown_trigger on_halt_trigger
= {ON_HALT_STR
, &stop_action
};
1508 static ssize_t
on_halt_show(struct kobject
*kobj
,
1509 struct kobj_attribute
*attr
, char *page
)
1511 return sprintf(page
, "%s\n", on_halt_trigger
.action
->name
);
1514 static ssize_t
on_halt_store(struct kobject
*kobj
,
1515 struct kobj_attribute
*attr
,
1516 const char *buf
, size_t len
)
1518 return set_trigger(buf
, &on_halt_trigger
, len
);
1521 static struct kobj_attribute on_halt_attr
=
1522 __ATTR(on_halt
, 0644, on_halt_show
, on_halt_store
);
1525 static void do_machine_halt(void)
1528 on_halt_trigger
.action
->fn(&on_halt_trigger
);
1529 stop_run(&on_halt_trigger
);
1531 void (*_machine_halt
)(void) = do_machine_halt
;
1535 static struct shutdown_trigger on_poff_trigger
= {ON_POFF_STR
, &stop_action
};
1537 static ssize_t
on_poff_show(struct kobject
*kobj
,
1538 struct kobj_attribute
*attr
, char *page
)
1540 return sprintf(page
, "%s\n", on_poff_trigger
.action
->name
);
1543 static ssize_t
on_poff_store(struct kobject
*kobj
,
1544 struct kobj_attribute
*attr
,
1545 const char *buf
, size_t len
)
1547 return set_trigger(buf
, &on_poff_trigger
, len
);
1550 static struct kobj_attribute on_poff_attr
=
1551 __ATTR(on_poff
, 0644, on_poff_show
, on_poff_store
);
1554 static void do_machine_power_off(void)
1557 on_poff_trigger
.action
->fn(&on_poff_trigger
);
1558 stop_run(&on_poff_trigger
);
1560 void (*_machine_power_off
)(void) = do_machine_power_off
;
1562 static void __init
shutdown_triggers_init(void)
1564 shutdown_actions_kset
= kset_create_and_add("shutdown_actions", NULL
,
1566 if (!shutdown_actions_kset
)
1568 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1569 &on_reboot_attr
.attr
))
1571 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1572 &on_panic_attr
.attr
))
1574 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1575 &on_halt_attr
.attr
))
1577 if (sysfs_create_file(&shutdown_actions_kset
->kobj
,
1578 &on_poff_attr
.attr
))
1583 panic("shutdown_triggers_init failed\n");
1586 static void __init
shutdown_actions_init(void)
1590 for (i
= 0; i
< SHUTDOWN_ACTIONS_COUNT
; i
++) {
1591 if (!shutdown_actions_list
[i
]->init
)
1593 if (shutdown_actions_list
[i
]->init())
1594 shutdown_actions_list
[i
] = NULL
;
1598 static int __init
s390_ipl_init(void)
1600 sclp_get_ipl_info(&sclp_ipl_info
);
1601 shutdown_actions_init();
1602 shutdown_triggers_init();
1606 __initcall(s390_ipl_init
);
1608 static void __init
strncpy_skip_quote(char *dst
, char *src
, int n
)
1613 for (sx
= 0; src
[sx
] != 0; sx
++) {
1616 dst
[dx
++] = src
[sx
];
1622 static int __init
vmcmd_on_reboot_setup(char *str
)
1626 strncpy_skip_quote(vmcmd_on_reboot
, str
, 127);
1627 vmcmd_on_reboot
[127] = 0;
1628 on_reboot_trigger
.action
= &vmcmd_action
;
1631 __setup("vmreboot=", vmcmd_on_reboot_setup
);
1633 static int __init
vmcmd_on_panic_setup(char *str
)
1637 strncpy_skip_quote(vmcmd_on_panic
, str
, 127);
1638 vmcmd_on_panic
[127] = 0;
1639 on_panic_trigger
.action
= &vmcmd_action
;
1642 __setup("vmpanic=", vmcmd_on_panic_setup
);
1644 static int __init
vmcmd_on_halt_setup(char *str
)
1648 strncpy_skip_quote(vmcmd_on_halt
, str
, 127);
1649 vmcmd_on_halt
[127] = 0;
1650 on_halt_trigger
.action
= &vmcmd_action
;
1653 __setup("vmhalt=", vmcmd_on_halt_setup
);
1655 static int __init
vmcmd_on_poff_setup(char *str
)
1659 strncpy_skip_quote(vmcmd_on_poff
, str
, 127);
1660 vmcmd_on_poff
[127] = 0;
1661 on_poff_trigger
.action
= &vmcmd_action
;
1664 __setup("vmpoff=", vmcmd_on_poff_setup
);
1666 static int on_panic_notify(struct notifier_block
*self
,
1667 unsigned long event
, void *data
)
1673 static struct notifier_block on_panic_nb
= {
1674 .notifier_call
= on_panic_notify
,
1678 void __init
setup_ipl(void)
1680 ipl_info
.type
= get_ipl_type();
1681 switch (ipl_info
.type
) {
1683 ipl_info
.data
.ccw
.dev_id
.devno
= ipl_devno
;
1684 ipl_info
.data
.ccw
.dev_id
.ssid
= 0;
1687 case IPL_TYPE_FCP_DUMP
:
1688 ipl_info
.data
.fcp
.dev_id
.devno
=
1689 IPL_PARMBLOCK_START
->ipl_info
.fcp
.devno
;
1690 ipl_info
.data
.fcp
.dev_id
.ssid
= 0;
1691 ipl_info
.data
.fcp
.wwpn
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.wwpn
;
1692 ipl_info
.data
.fcp
.lun
= IPL_PARMBLOCK_START
->ipl_info
.fcp
.lun
;
1695 strncpy(ipl_info
.data
.nss
.name
, kernel_nss_name
,
1696 sizeof(ipl_info
.data
.nss
.name
));
1698 case IPL_TYPE_UNKNOWN
:
1700 /* We have no info to copy */
1703 atomic_notifier_chain_register(&panic_notifier_list
, &on_panic_nb
);
1706 void __init
ipl_update_parameters(void)
1710 rc
= diag308(DIAG308_STORE
, &ipl_block
);
1711 if ((rc
== DIAG308_RC_OK
) || (rc
== DIAG308_RC_NOCONFIG
))
1712 diag308_set_works
= 1;
1715 void __init
ipl_save_parameters(void)
1717 struct cio_iplinfo iplinfo
;
1718 unsigned int *ipl_ptr
;
1721 if (cio_get_iplinfo(&iplinfo
))
1724 ipl_devno
= iplinfo
.devno
;
1725 ipl_flags
|= IPL_DEVNO_VALID
;
1726 if (!iplinfo
.is_qdio
)
1728 ipl_flags
|= IPL_PARMBLOCK_VALID
;
1729 ipl_ptr
= (unsigned int *)__LC_IPL_PARMBLOCK_PTR
;
1730 src
= (void *)(unsigned long)*ipl_ptr
;
1731 dst
= (void *)IPL_PARMBLOCK_ORIGIN
;
1732 memmove(dst
, src
, PAGE_SIZE
);
1733 *ipl_ptr
= IPL_PARMBLOCK_ORIGIN
;
1736 static LIST_HEAD(rcall
);
1737 static DEFINE_MUTEX(rcall_mutex
);
1739 void register_reset_call(struct reset_call
*reset
)
1741 mutex_lock(&rcall_mutex
);
1742 list_add(&reset
->list
, &rcall
);
1743 mutex_unlock(&rcall_mutex
);
1745 EXPORT_SYMBOL_GPL(register_reset_call
);
1747 void unregister_reset_call(struct reset_call
*reset
)
1749 mutex_lock(&rcall_mutex
);
1750 list_del(&reset
->list
);
1751 mutex_unlock(&rcall_mutex
);
1753 EXPORT_SYMBOL_GPL(unregister_reset_call
);
1755 static void do_reset_calls(void)
1757 struct reset_call
*reset
;
1759 list_for_each_entry(reset
, &rcall
, list
)
1763 u32 dump_prefix_page
;
1765 void s390_reset_system(void)
1767 struct _lowcore
*lc
;
1769 lc
= (struct _lowcore
*)(unsigned long) store_prefix();
1771 /* Stack for interrupt/machine check handler */
1772 lc
->panic_stack
= S390_lowcore
.panic_stack
;
1774 /* Save prefix page address for dump case */
1775 dump_prefix_page
= (u32
)(unsigned long) lc
;
1777 /* Disable prefixing */
1780 /* Disable lowcore protection */
1781 __ctl_clear_bit(0,28);
1783 /* Set new machine check handler */
1784 S390_lowcore
.mcck_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1785 S390_lowcore
.mcck_new_psw
.addr
=
1786 PSW_ADDR_AMODE
| (unsigned long) s390_base_mcck_handler
;
1788 /* Set new program check handler */
1789 S390_lowcore
.program_new_psw
.mask
= psw_kernel_bits
& ~PSW_MASK_MCHECK
;
1790 S390_lowcore
.program_new_psw
.addr
=
1791 PSW_ADDR_AMODE
| (unsigned long) s390_base_pgm_handler
;