2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
19 #include <asm/setup.h>
20 #include <asm/cpcmd.h>
22 #include <asm/ebcdic.h>
23 #include <asm/reset.h>
26 #define IPL_PARM_BLOCK_VERSION 0
28 #define IPL_UNKNOWN_STR "unknown"
29 #define IPL_CCW_STR "ccw"
30 #define IPL_FCP_STR "fcp"
31 #define IPL_FCP_DUMP_STR "fcp_dump"
32 #define IPL_NSS_STR "nss"
34 #define DUMP_CCW_STR "ccw"
35 #define DUMP_FCP_STR "fcp"
36 #define DUMP_NONE_STR "none"
39 * Four shutdown trigger types are supported:
45 #define ON_PANIC_STR "on_panic"
46 #define ON_HALT_STR "on_halt"
47 #define ON_POFF_STR "on_poff"
48 #define ON_REIPL_STR "on_reboot"
50 struct shutdown_action;
51 struct shutdown_trigger {
53 struct shutdown_action *action;
57 * Five shutdown action types are supported:
59 #define SHUTDOWN_ACTION_IPL_STR "ipl"
60 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
61 #define SHUTDOWN_ACTION_DUMP_STR "dump"
62 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
63 #define SHUTDOWN_ACTION_STOP_STR "stop"
65 struct shutdown_action {
67 void (*fn) (struct shutdown_trigger *trigger);
71 static char *ipl_type_str(enum ipl_type type)
78 case IPL_TYPE_FCP_DUMP:
79 return IPL_FCP_DUMP_STR;
82 case IPL_TYPE_UNKNOWN:
84 return IPL_UNKNOWN_STR;
94 static char *dump_type_str(enum dump_type type)
109 * Must be in data section since the bss section
110 * is not cleared when these are accessed.
112 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
113 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
116 REIPL_METHOD_CCW_CIO,
117 REIPL_METHOD_CCW_DIAG,
119 REIPL_METHOD_FCP_RO_DIAG,
120 REIPL_METHOD_FCP_RW_DIAG,
121 REIPL_METHOD_FCP_RO_VM,
122 REIPL_METHOD_FCP_DUMP,
124 REIPL_METHOD_DEFAULT,
130 DUMP_METHOD_CCW_DIAG,
132 DUMP_METHOD_FCP_DIAG,
135 static int diag308_set_works = 0;
137 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
139 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
140 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
141 static struct ipl_parameter_block *reipl_block_fcp;
142 static struct ipl_parameter_block *reipl_block_ccw;
144 static char reipl_nss_name[NSS_NAME_SIZE + 1];
146 static int dump_capabilities = DUMP_TYPE_NONE;
147 static enum dump_type dump_type = DUMP_TYPE_NONE;
148 static enum dump_method dump_method = DUMP_METHOD_NONE;
149 static struct ipl_parameter_block *dump_block_fcp;
150 static struct ipl_parameter_block *dump_block_ccw;
152 static struct sclp_ipl_info sclp_ipl_info;
154 int diag308(unsigned long subcode, void *addr)
156 register unsigned long _addr asm("0") = (unsigned long) addr;
157 register unsigned long _rc asm("1") = 0;
160 " diag %0,%2,0x308\n"
163 : "+d" (_addr), "+d" (_rc)
164 : "d" (subcode) : "cc", "memory");
167 EXPORT_SYMBOL_GPL(diag308);
171 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
172 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
173 struct kobj_attribute *attr, \
176 return sprintf(page, _format, _value); \
178 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
179 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
181 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
182 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
183 struct kobj_attribute *attr, \
186 return sprintf(page, _fmt_out, \
187 (unsigned long long) _value); \
189 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
190 struct kobj_attribute *attr, \
191 const char *buf, size_t len) \
193 unsigned long long value; \
194 if (sscanf(buf, _fmt_in, &value) != 1) \
199 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
200 __ATTR(_name,(S_IRUGO | S_IWUSR), \
201 sys_##_prefix##_##_name##_show, \
202 sys_##_prefix##_##_name##_store);
204 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
205 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
206 struct kobj_attribute *attr, \
209 return sprintf(page, _fmt_out, _value); \
211 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
212 struct kobj_attribute *attr, \
213 const char *buf, size_t len) \
215 strncpy(_value, buf, sizeof(_value) - 1); \
219 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
220 __ATTR(_name,(S_IRUGO | S_IWUSR), \
221 sys_##_prefix##_##_name##_show, \
222 sys_##_prefix##_##_name##_store);
224 static void make_attrs_ro(struct attribute **attrs)
227 (*attrs)->mode = S_IRUGO;
236 static __init enum ipl_type get_ipl_type(void)
238 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
240 if (ipl_flags & IPL_NSS_VALID)
242 if (!(ipl_flags & IPL_DEVNO_VALID))
243 return IPL_TYPE_UNKNOWN;
244 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
246 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
247 return IPL_TYPE_UNKNOWN;
248 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
249 return IPL_TYPE_UNKNOWN;
250 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
251 return IPL_TYPE_FCP_DUMP;
255 struct ipl_info ipl_info;
256 EXPORT_SYMBOL_GPL(ipl_info);
258 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
261 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
264 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
266 static ssize_t sys_ipl_device_show(struct kobject *kobj,
267 struct kobj_attribute *attr, char *page)
269 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
271 switch (ipl_info.type) {
273 return sprintf(page, "0.0.%04x\n", ipl_devno);
275 case IPL_TYPE_FCP_DUMP:
276 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
282 static struct kobj_attribute sys_ipl_device_attr =
283 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
285 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
286 char *buf, loff_t off, size_t count)
288 unsigned int size = IPL_PARMBLOCK_SIZE;
292 if (off + count > size)
294 memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
298 static struct bin_attribute ipl_parameter_attr = {
300 .name = "binary_parameter",
304 .read = &ipl_parameter_read,
307 static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
308 char *buf, loff_t off, size_t count)
310 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
311 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
315 if (off + count > size)
317 memcpy(buf, scp_data + off, count);
321 static struct bin_attribute ipl_scp_data_attr = {
327 .read = ipl_scp_data_read,
330 /* FCP ipl device attributes */
332 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
333 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
334 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
335 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
336 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
337 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
338 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
339 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
341 static struct attribute *ipl_fcp_attrs[] = {
342 &sys_ipl_type_attr.attr,
343 &sys_ipl_device_attr.attr,
344 &sys_ipl_fcp_wwpn_attr.attr,
345 &sys_ipl_fcp_lun_attr.attr,
346 &sys_ipl_fcp_bootprog_attr.attr,
347 &sys_ipl_fcp_br_lba_attr.attr,
351 static struct attribute_group ipl_fcp_attr_group = {
352 .attrs = ipl_fcp_attrs,
355 /* CCW ipl device attributes */
357 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
358 struct kobj_attribute *attr, char *page)
360 char loadparm[LOADPARM_LEN + 1] = {};
362 if (!sclp_ipl_info.is_valid)
363 return sprintf(page, "#unknown#\n");
364 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
365 EBCASC(loadparm, LOADPARM_LEN);
367 return sprintf(page, "%s\n", loadparm);
370 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
371 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
373 static struct attribute *ipl_ccw_attrs[] = {
374 &sys_ipl_type_attr.attr,
375 &sys_ipl_device_attr.attr,
376 &sys_ipl_ccw_loadparm_attr.attr,
380 static struct attribute_group ipl_ccw_attr_group = {
381 .attrs = ipl_ccw_attrs,
384 /* NSS ipl device attributes */
386 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
388 static struct attribute *ipl_nss_attrs[] = {
389 &sys_ipl_type_attr.attr,
390 &sys_ipl_nss_name_attr.attr,
394 static struct attribute_group ipl_nss_attr_group = {
395 .attrs = ipl_nss_attrs,
398 /* UNKNOWN ipl device attributes */
400 static struct attribute *ipl_unknown_attrs[] = {
401 &sys_ipl_type_attr.attr,
405 static struct attribute_group ipl_unknown_attr_group = {
406 .attrs = ipl_unknown_attrs,
409 static struct kset *ipl_kset;
411 static int __init ipl_register_fcp_files(void)
415 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
418 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
421 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
425 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
428 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
433 static void ipl_run(struct shutdown_trigger *trigger)
435 diag308(DIAG308_IPL, NULL);
437 __cpcmd("IPL", NULL, 0, NULL);
438 else if (ipl_info.type == IPL_TYPE_CCW)
439 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
442 static int __init ipl_init(void)
446 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
451 switch (ipl_info.type) {
453 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_ccw_attr_group);
456 case IPL_TYPE_FCP_DUMP:
457 rc = ipl_register_fcp_files();
460 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
463 rc = sysfs_create_group(&ipl_kset->kobj,
464 &ipl_unknown_attr_group);
469 panic("ipl_init failed: rc = %i\n", rc);
474 static struct shutdown_action __refdata ipl_action = {
475 .name = SHUTDOWN_ACTION_IPL_STR,
481 * reipl shutdown action: Reboot Linux on shutdown.
484 /* FCP reipl device attributes */
486 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
487 reipl_block_fcp->ipl_info.fcp.wwpn);
488 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
489 reipl_block_fcp->ipl_info.fcp.lun);
490 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
491 reipl_block_fcp->ipl_info.fcp.bootprog);
492 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
493 reipl_block_fcp->ipl_info.fcp.br_lba);
494 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
495 reipl_block_fcp->ipl_info.fcp.devno);
497 static struct attribute *reipl_fcp_attrs[] = {
498 &sys_reipl_fcp_device_attr.attr,
499 &sys_reipl_fcp_wwpn_attr.attr,
500 &sys_reipl_fcp_lun_attr.attr,
501 &sys_reipl_fcp_bootprog_attr.attr,
502 &sys_reipl_fcp_br_lba_attr.attr,
506 static struct attribute_group reipl_fcp_attr_group = {
508 .attrs = reipl_fcp_attrs,
511 /* CCW reipl device attributes */
513 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
514 reipl_block_ccw->ipl_info.ccw.devno);
516 static void reipl_get_ascii_loadparm(char *loadparm)
518 memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
520 EBCASC(loadparm, LOADPARM_LEN);
521 loadparm[LOADPARM_LEN] = 0;
525 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
526 struct kobj_attribute *attr, char *page)
528 char buf[LOADPARM_LEN + 1];
530 reipl_get_ascii_loadparm(buf);
531 return sprintf(page, "%s\n", buf);
534 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
535 struct kobj_attribute *attr,
536 const char *buf, size_t len)
540 /* ignore trailing newline */
542 if ((len > 0) && (buf[len - 1] == '\n'))
544 /* loadparm can have max 8 characters and must not start with a blank */
545 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
547 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
548 for (i = 0; i < lp_len; i++) {
549 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
554 /* initialize loadparm with blanks */
555 memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
556 /* copy and convert to ebcdic */
557 memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
558 ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
562 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
563 __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
564 reipl_ccw_loadparm_store);
566 static struct attribute *reipl_ccw_attrs[] = {
567 &sys_reipl_ccw_device_attr.attr,
568 &sys_reipl_ccw_loadparm_attr.attr,
572 static struct attribute_group reipl_ccw_attr_group = {
574 .attrs = reipl_ccw_attrs,
578 /* NSS reipl device attributes */
580 DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);
582 static struct attribute *reipl_nss_attrs[] = {
583 &sys_reipl_nss_name_attr.attr,
587 static struct attribute_group reipl_nss_attr_group = {
589 .attrs = reipl_nss_attrs,
594 static int reipl_set_type(enum ipl_type type)
596 if (!(reipl_capabilities & type))
601 if (diag308_set_works)
602 reipl_method = REIPL_METHOD_CCW_DIAG;
603 else if (MACHINE_IS_VM)
604 reipl_method = REIPL_METHOD_CCW_VM;
606 reipl_method = REIPL_METHOD_CCW_CIO;
609 if (diag308_set_works)
610 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
611 else if (MACHINE_IS_VM)
612 reipl_method = REIPL_METHOD_FCP_RO_VM;
614 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
616 case IPL_TYPE_FCP_DUMP:
617 reipl_method = REIPL_METHOD_FCP_DUMP;
620 reipl_method = REIPL_METHOD_NSS;
622 case IPL_TYPE_UNKNOWN:
623 reipl_method = REIPL_METHOD_DEFAULT;
632 static ssize_t reipl_type_show(struct kobject *kobj,
633 struct kobj_attribute *attr, char *page)
635 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
638 static ssize_t reipl_type_store(struct kobject *kobj,
639 struct kobj_attribute *attr,
640 const char *buf, size_t len)
644 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
645 rc = reipl_set_type(IPL_TYPE_CCW);
646 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
647 rc = reipl_set_type(IPL_TYPE_FCP);
648 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
649 rc = reipl_set_type(IPL_TYPE_NSS);
650 return (rc != 0) ? rc : len;
653 static struct kobj_attribute reipl_type_attr =
654 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
656 static struct kset *reipl_kset;
658 void reipl_run(struct shutdown_trigger *trigger)
660 struct ccw_dev_id devid;
661 static char buf[100];
662 char loadparm[LOADPARM_LEN + 1];
664 switch (reipl_method) {
665 case REIPL_METHOD_CCW_CIO:
666 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
668 reipl_ccw_dev(&devid);
670 case REIPL_METHOD_CCW_VM:
671 reipl_get_ascii_loadparm(loadparm);
672 if (strlen(loadparm) == 0)
673 sprintf(buf, "IPL %X CLEAR",
674 reipl_block_ccw->ipl_info.ccw.devno);
676 sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
677 reipl_block_ccw->ipl_info.ccw.devno, loadparm);
678 __cpcmd(buf, NULL, 0, NULL);
680 case REIPL_METHOD_CCW_DIAG:
681 diag308(DIAG308_SET, reipl_block_ccw);
682 diag308(DIAG308_IPL, NULL);
684 case REIPL_METHOD_FCP_RW_DIAG:
685 diag308(DIAG308_SET, reipl_block_fcp);
686 diag308(DIAG308_IPL, NULL);
688 case REIPL_METHOD_FCP_RO_DIAG:
689 diag308(DIAG308_IPL, NULL);
691 case REIPL_METHOD_FCP_RO_VM:
692 __cpcmd("IPL", NULL, 0, NULL);
694 case REIPL_METHOD_NSS:
695 sprintf(buf, "IPL %s", reipl_nss_name);
696 __cpcmd(buf, NULL, 0, NULL);
698 case REIPL_METHOD_DEFAULT:
700 __cpcmd("IPL", NULL, 0, NULL);
701 diag308(DIAG308_IPL, NULL);
703 case REIPL_METHOD_FCP_DUMP:
707 disabled_wait((unsigned long) __builtin_return_address(0));
710 static void __init reipl_probe(void)
714 buffer = (void *) get_zeroed_page(GFP_KERNEL);
717 if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
718 diag308_set_works = 1;
719 free_page((unsigned long)buffer);
722 static int __init reipl_nss_init(void)
728 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
731 strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
732 reipl_capabilities |= IPL_TYPE_NSS;
736 static int __init reipl_ccw_init(void)
740 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
741 if (!reipl_block_ccw)
743 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
745 free_page((unsigned long)reipl_block_ccw);
748 reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
749 reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
750 reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
751 reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
752 reipl_block_ccw->hdr.flags = DIAG308_FLAGS_LP_VALID;
753 /* check if read scp info worked and set loadparm */
754 if (sclp_ipl_info.is_valid)
755 memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
756 &sclp_ipl_info.loadparm, LOADPARM_LEN);
758 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
759 memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
761 if (!MACHINE_IS_VM && !diag308_set_works)
762 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
763 if (ipl_info.type == IPL_TYPE_CCW)
764 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
765 reipl_capabilities |= IPL_TYPE_CCW;
769 static int __init reipl_fcp_init(void)
773 if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
775 if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
776 make_attrs_ro(reipl_fcp_attrs);
778 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
779 if (!reipl_block_fcp)
781 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
783 free_page((unsigned long)reipl_block_fcp);
786 if (ipl_info.type == IPL_TYPE_FCP) {
787 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
789 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
790 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
791 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
792 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
793 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
795 reipl_capabilities |= IPL_TYPE_FCP;
799 static int __init reipl_init(void)
803 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
806 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
808 kset_unregister(reipl_kset);
811 rc = reipl_ccw_init();
814 rc = reipl_fcp_init();
817 rc = reipl_nss_init();
820 rc = reipl_set_type(ipl_info.type);
826 static struct shutdown_action __refdata reipl_action = {
827 .name = SHUTDOWN_ACTION_REIPL_STR,
833 * dump shutdown action: Dump Linux on shutdown.
836 /* FCP dump device attributes */
838 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
839 dump_block_fcp->ipl_info.fcp.wwpn);
840 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
841 dump_block_fcp->ipl_info.fcp.lun);
842 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
843 dump_block_fcp->ipl_info.fcp.bootprog);
844 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
845 dump_block_fcp->ipl_info.fcp.br_lba);
846 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
847 dump_block_fcp->ipl_info.fcp.devno);
849 static struct attribute *dump_fcp_attrs[] = {
850 &sys_dump_fcp_device_attr.attr,
851 &sys_dump_fcp_wwpn_attr.attr,
852 &sys_dump_fcp_lun_attr.attr,
853 &sys_dump_fcp_bootprog_attr.attr,
854 &sys_dump_fcp_br_lba_attr.attr,
858 static struct attribute_group dump_fcp_attr_group = {
860 .attrs = dump_fcp_attrs,
863 /* CCW dump device attributes */
865 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
866 dump_block_ccw->ipl_info.ccw.devno);
868 static struct attribute *dump_ccw_attrs[] = {
869 &sys_dump_ccw_device_attr.attr,
873 static struct attribute_group dump_ccw_attr_group = {
875 .attrs = dump_ccw_attrs,
880 static int dump_set_type(enum dump_type type)
882 if (!(dump_capabilities & type))
886 if (diag308_set_works)
887 dump_method = DUMP_METHOD_CCW_DIAG;
888 else if (MACHINE_IS_VM)
889 dump_method = DUMP_METHOD_CCW_VM;
891 dump_method = DUMP_METHOD_CCW_CIO;
894 dump_method = DUMP_METHOD_FCP_DIAG;
897 dump_method = DUMP_METHOD_NONE;
903 static ssize_t dump_type_show(struct kobject *kobj,
904 struct kobj_attribute *attr, char *page)
906 return sprintf(page, "%s\n", dump_type_str(dump_type));
909 static ssize_t dump_type_store(struct kobject *kobj,
910 struct kobj_attribute *attr,
911 const char *buf, size_t len)
915 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
916 rc = dump_set_type(DUMP_TYPE_NONE);
917 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
918 rc = dump_set_type(DUMP_TYPE_CCW);
919 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
920 rc = dump_set_type(DUMP_TYPE_FCP);
921 return (rc != 0) ? rc : len;
924 static struct kobj_attribute dump_type_attr =
925 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
927 static struct kset *dump_kset;
929 static void dump_run(struct shutdown_trigger *trigger)
931 struct ccw_dev_id devid;
932 static char buf[100];
934 switch (dump_method) {
935 case DUMP_METHOD_CCW_CIO:
937 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
939 reipl_ccw_dev(&devid);
941 case DUMP_METHOD_CCW_VM:
943 sprintf(buf, "STORE STATUS");
944 __cpcmd(buf, NULL, 0, NULL);
945 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
946 __cpcmd(buf, NULL, 0, NULL);
948 case DUMP_METHOD_CCW_DIAG:
949 diag308(DIAG308_SET, dump_block_ccw);
950 diag308(DIAG308_DUMP, NULL);
952 case DUMP_METHOD_FCP_DIAG:
953 diag308(DIAG308_SET, dump_block_fcp);
954 diag308(DIAG308_DUMP, NULL);
956 case DUMP_METHOD_NONE:
960 printk(KERN_EMERG "Dump failed!\n");
963 static int __init dump_ccw_init(void)
967 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
970 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
972 free_page((unsigned long)dump_block_ccw);
975 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
976 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
977 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
978 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
979 dump_capabilities |= DUMP_TYPE_CCW;
983 static int __init dump_fcp_init(void)
987 if (!sclp_ipl_info.has_dump)
988 return 0; /* LDIPL DUMP is not installed */
989 if (!diag308_set_works)
991 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
994 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
996 free_page((unsigned long)dump_block_fcp);
999 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1000 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1001 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1002 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1003 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1004 dump_capabilities |= DUMP_TYPE_FCP;
1008 static int __init dump_init(void)
1012 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1015 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1017 kset_unregister(dump_kset);
1020 rc = dump_ccw_init();
1023 rc = dump_fcp_init();
1026 dump_set_type(DUMP_TYPE_NONE);
1030 static struct shutdown_action __refdata dump_action = {
1031 .name = SHUTDOWN_ACTION_DUMP_STR,
1037 * vmcmd shutdown action: Trigger vm command on shutdown.
1040 static char vmcmd_on_reboot[128];
1041 static char vmcmd_on_panic[128];
1042 static char vmcmd_on_halt[128];
1043 static char vmcmd_on_poff[128];
1045 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1046 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1047 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1048 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1050 static struct attribute *vmcmd_attrs[] = {
1051 &sys_vmcmd_on_reboot_attr.attr,
1052 &sys_vmcmd_on_panic_attr.attr,
1053 &sys_vmcmd_on_halt_attr.attr,
1054 &sys_vmcmd_on_poff_attr.attr,
1058 static struct attribute_group vmcmd_attr_group = {
1059 .attrs = vmcmd_attrs,
1062 static struct kset *vmcmd_kset;
1064 static void vmcmd_run(struct shutdown_trigger *trigger)
1066 char *cmd, *next_cmd;
1068 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1069 cmd = vmcmd_on_reboot;
1070 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1071 cmd = vmcmd_on_panic;
1072 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1073 cmd = vmcmd_on_halt;
1074 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1075 cmd = vmcmd_on_poff;
1079 if (strlen(cmd) == 0)
1082 next_cmd = strchr(cmd, '\n');
1087 __cpcmd(cmd, NULL, 0, NULL);
1089 } while (cmd != NULL);
1092 static int vmcmd_init(void)
1096 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1099 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1102 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1103 vmcmd_run, vmcmd_init};
1106 * stop shutdown action: Stop Linux on shutdown.
1109 static void stop_run(struct shutdown_trigger *trigger)
1111 if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1112 disabled_wait((unsigned long) __builtin_return_address(0));
1114 signal_processor(smp_processor_id(), sigp_stop);
1119 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1124 static struct shutdown_action *shutdown_actions_list[] = {
1125 &ipl_action, &reipl_action, &dump_action, &vmcmd_action, &stop_action};
1126 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1132 static struct kset *shutdown_actions_kset;
1134 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1138 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1139 if (!shutdown_actions_list[i])
1141 if (strncmp(buf, shutdown_actions_list[i]->name,
1142 strlen(shutdown_actions_list[i]->name)) == 0) {
1143 trigger->action = shutdown_actions_list[i];
1152 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1155 static ssize_t on_reboot_show(struct kobject *kobj,
1156 struct kobj_attribute *attr, char *page)
1158 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1161 static ssize_t on_reboot_store(struct kobject *kobj,
1162 struct kobj_attribute *attr,
1163 const char *buf, size_t len)
1165 return set_trigger(buf, &on_reboot_trigger, len);
1168 static struct kobj_attribute on_reboot_attr =
1169 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1171 static void do_machine_restart(char *__unused)
1174 on_reboot_trigger.action->fn(&on_reboot_trigger);
1177 void (*_machine_restart)(char *command) = do_machine_restart;
1181 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1183 static ssize_t on_panic_show(struct kobject *kobj,
1184 struct kobj_attribute *attr, char *page)
1186 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1189 static ssize_t on_panic_store(struct kobject *kobj,
1190 struct kobj_attribute *attr,
1191 const char *buf, size_t len)
1193 return set_trigger(buf, &on_panic_trigger, len);
1196 static struct kobj_attribute on_panic_attr =
1197 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1199 static void do_panic(void)
1201 on_panic_trigger.action->fn(&on_panic_trigger);
1202 stop_run(&on_panic_trigger);
1207 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1209 static ssize_t on_halt_show(struct kobject *kobj,
1210 struct kobj_attribute *attr, char *page)
1212 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1215 static ssize_t on_halt_store(struct kobject *kobj,
1216 struct kobj_attribute *attr,
1217 const char *buf, size_t len)
1219 return set_trigger(buf, &on_halt_trigger, len);
1222 static struct kobj_attribute on_halt_attr =
1223 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1226 static void do_machine_halt(void)
1229 on_halt_trigger.action->fn(&on_halt_trigger);
1230 stop_run(&on_halt_trigger);
1232 void (*_machine_halt)(void) = do_machine_halt;
1236 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1238 static ssize_t on_poff_show(struct kobject *kobj,
1239 struct kobj_attribute *attr, char *page)
1241 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1244 static ssize_t on_poff_store(struct kobject *kobj,
1245 struct kobj_attribute *attr,
1246 const char *buf, size_t len)
1248 return set_trigger(buf, &on_poff_trigger, len);
1251 static struct kobj_attribute on_poff_attr =
1252 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1255 static void do_machine_power_off(void)
1258 on_poff_trigger.action->fn(&on_poff_trigger);
1259 stop_run(&on_poff_trigger);
1261 void (*_machine_power_off)(void) = do_machine_power_off;
1263 static void __init shutdown_triggers_init(void)
1265 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1267 if (!shutdown_actions_kset)
1269 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1270 &on_reboot_attr.attr))
1272 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1273 &on_panic_attr.attr))
1275 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1276 &on_halt_attr.attr))
1278 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1279 &on_poff_attr.attr))
1284 panic("shutdown_triggers_init failed\n");
1287 static void __init shutdown_actions_init(void)
1291 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1292 if (!shutdown_actions_list[i]->init)
1294 if (shutdown_actions_list[i]->init())
1295 shutdown_actions_list[i] = NULL;
1299 static int __init s390_ipl_init(void)
1302 sclp_get_ipl_info(&sclp_ipl_info);
1303 shutdown_actions_init();
1304 shutdown_triggers_init();
1308 __initcall(s390_ipl_init);
1310 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1315 for (sx = 0; src[sx] != 0; sx++) {
1318 dst[dx++] = src[sx];
1324 static int __init vmcmd_on_reboot_setup(char *str)
1328 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1329 vmcmd_on_reboot[127] = 0;
1330 on_reboot_trigger.action = &vmcmd_action;
1333 __setup("vmreboot=", vmcmd_on_reboot_setup);
1335 static int __init vmcmd_on_panic_setup(char *str)
1339 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1340 vmcmd_on_panic[127] = 0;
1341 on_panic_trigger.action = &vmcmd_action;
1344 __setup("vmpanic=", vmcmd_on_panic_setup);
1346 static int __init vmcmd_on_halt_setup(char *str)
1350 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1351 vmcmd_on_halt[127] = 0;
1352 on_halt_trigger.action = &vmcmd_action;
1355 __setup("vmhalt=", vmcmd_on_halt_setup);
1357 static int __init vmcmd_on_poff_setup(char *str)
1361 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1362 vmcmd_on_poff[127] = 0;
1363 on_poff_trigger.action = &vmcmd_action;
1366 __setup("vmpoff=", vmcmd_on_poff_setup);
1368 static int on_panic_notify(struct notifier_block *self,
1369 unsigned long event, void *data)
1375 static struct notifier_block on_panic_nb = {
1376 .notifier_call = on_panic_notify,
1380 void __init setup_ipl(void)
1382 ipl_info.type = get_ipl_type();
1383 switch (ipl_info.type) {
1385 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1386 ipl_info.data.ccw.dev_id.ssid = 0;
1389 case IPL_TYPE_FCP_DUMP:
1390 ipl_info.data.fcp.dev_id.devno =
1391 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1392 ipl_info.data.fcp.dev_id.ssid = 0;
1393 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1394 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1397 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1398 sizeof(ipl_info.data.nss.name));
1400 case IPL_TYPE_UNKNOWN:
1402 /* We have no info to copy */
1405 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1408 void __init ipl_save_parameters(void)
1410 struct cio_iplinfo iplinfo;
1411 unsigned int *ipl_ptr;
1414 if (cio_get_iplinfo(&iplinfo))
1417 ipl_devno = iplinfo.devno;
1418 ipl_flags |= IPL_DEVNO_VALID;
1419 if (!iplinfo.is_qdio)
1421 ipl_flags |= IPL_PARMBLOCK_VALID;
1422 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1423 src = (void *)(unsigned long)*ipl_ptr;
1424 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1425 memmove(dst, src, PAGE_SIZE);
1426 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1429 static LIST_HEAD(rcall);
1430 static DEFINE_MUTEX(rcall_mutex);
1432 void register_reset_call(struct reset_call *reset)
1434 mutex_lock(&rcall_mutex);
1435 list_add(&reset->list, &rcall);
1436 mutex_unlock(&rcall_mutex);
1438 EXPORT_SYMBOL_GPL(register_reset_call);
1440 void unregister_reset_call(struct reset_call *reset)
1442 mutex_lock(&rcall_mutex);
1443 list_del(&reset->list);
1444 mutex_unlock(&rcall_mutex);
1446 EXPORT_SYMBOL_GPL(unregister_reset_call);
1448 static void do_reset_calls(void)
1450 struct reset_call *reset;
1452 list_for_each_entry(reset, &rcall, list)
1456 u32 dump_prefix_page;
1458 void s390_reset_system(void)
1460 struct _lowcore *lc;
1462 lc = (struct _lowcore *)(unsigned long) store_prefix();
1464 /* Stack for interrupt/machine check handler */
1465 lc->panic_stack = S390_lowcore.panic_stack;
1467 /* Save prefix page address for dump case */
1468 dump_prefix_page = (u32)(unsigned long) lc;
1470 /* Disable prefixing */
1473 /* Disable lowcore protection */
1474 __ctl_clear_bit(0,28);
1476 /* Set new machine check handler */
1477 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1478 S390_lowcore.mcck_new_psw.addr =
1479 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
1481 /* Set new program check handler */
1482 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1483 S390_lowcore.program_new_psw.addr =
1484 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;