2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2012
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
18 #include <linux/gfp.h>
19 #include <linux/crash_dump.h>
20 #include <linux/debug_locks.h>
23 #include <asm/setup.h>
24 #include <asm/cpcmd.h>
26 #include <asm/ebcdic.h>
27 #include <asm/reset.h>
29 #include <asm/checksum.h>
30 #include <asm/debug.h>
31 #include <asm/os_info.h>
34 #define IPL_PARM_BLOCK_VERSION 0
36 #define IPL_UNKNOWN_STR "unknown"
37 #define IPL_CCW_STR "ccw"
38 #define IPL_FCP_STR "fcp"
39 #define IPL_FCP_DUMP_STR "fcp_dump"
40 #define IPL_NSS_STR "nss"
42 #define DUMP_CCW_STR "ccw"
43 #define DUMP_FCP_STR "fcp"
44 #define DUMP_NONE_STR "none"
47 * Four shutdown trigger types are supported:
54 #define ON_PANIC_STR "on_panic"
55 #define ON_HALT_STR "on_halt"
56 #define ON_POFF_STR "on_poff"
57 #define ON_REIPL_STR "on_reboot"
58 #define ON_RESTART_STR "on_restart"
60 struct shutdown_action;
61 struct shutdown_trigger {
63 struct shutdown_action *action;
67 * The following shutdown action types are supported:
69 #define SHUTDOWN_ACTION_IPL_STR "ipl"
70 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
71 #define SHUTDOWN_ACTION_DUMP_STR "dump"
72 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
73 #define SHUTDOWN_ACTION_STOP_STR "stop"
74 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
76 struct shutdown_action {
78 void (*fn) (struct shutdown_trigger *trigger);
83 static char *ipl_type_str(enum ipl_type type)
90 case IPL_TYPE_FCP_DUMP:
91 return IPL_FCP_DUMP_STR;
94 case IPL_TYPE_UNKNOWN:
96 return IPL_UNKNOWN_STR;
106 static char *dump_type_str(enum dump_type type)
110 return DUMP_NONE_STR;
121 * Must be in data section since the bss section
122 * is not cleared when these are accessed.
124 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
125 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
128 REIPL_METHOD_CCW_CIO,
129 REIPL_METHOD_CCW_DIAG,
131 REIPL_METHOD_FCP_RO_DIAG,
132 REIPL_METHOD_FCP_RW_DIAG,
133 REIPL_METHOD_FCP_RO_VM,
134 REIPL_METHOD_FCP_DUMP,
136 REIPL_METHOD_NSS_DIAG,
137 REIPL_METHOD_DEFAULT,
143 DUMP_METHOD_CCW_DIAG,
145 DUMP_METHOD_FCP_DIAG,
148 static int diag308_set_works = 0;
150 static struct ipl_parameter_block ipl_block;
152 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
154 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
155 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
156 static struct ipl_parameter_block *reipl_block_fcp;
157 static struct ipl_parameter_block *reipl_block_ccw;
158 static struct ipl_parameter_block *reipl_block_nss;
159 static struct ipl_parameter_block *reipl_block_actual;
161 static int dump_capabilities = DUMP_TYPE_NONE;
162 static enum dump_type dump_type = DUMP_TYPE_NONE;
163 static enum dump_method dump_method = DUMP_METHOD_NONE;
164 static struct ipl_parameter_block *dump_block_fcp;
165 static struct ipl_parameter_block *dump_block_ccw;
167 static struct sclp_ipl_info sclp_ipl_info;
169 int diag308(unsigned long subcode, void *addr)
171 register unsigned long _addr asm("0") = (unsigned long) addr;
172 register unsigned long _rc asm("1") = 0;
175 " diag %0,%2,0x308\n"
178 : "+d" (_addr), "+d" (_rc)
179 : "d" (subcode) : "cc", "memory");
182 EXPORT_SYMBOL_GPL(diag308);
186 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
187 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
188 struct kobj_attribute *attr, \
191 return sprintf(page, _format, _value); \
193 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
194 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
196 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
197 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
198 struct kobj_attribute *attr, \
201 return sprintf(page, _fmt_out, \
202 (unsigned long long) _value); \
204 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
205 struct kobj_attribute *attr, \
206 const char *buf, size_t len) \
208 unsigned long long value; \
209 if (sscanf(buf, _fmt_in, &value) != 1) \
214 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
215 __ATTR(_name,(S_IRUGO | S_IWUSR), \
216 sys_##_prefix##_##_name##_show, \
217 sys_##_prefix##_##_name##_store);
219 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
220 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
221 struct kobj_attribute *attr, \
224 return sprintf(page, _fmt_out, _value); \
226 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
227 struct kobj_attribute *attr, \
228 const char *buf, size_t len) \
230 strncpy(_value, buf, sizeof(_value) - 1); \
234 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
235 __ATTR(_name,(S_IRUGO | S_IWUSR), \
236 sys_##_prefix##_##_name##_show, \
237 sys_##_prefix##_##_name##_store);
239 static void make_attrs_ro(struct attribute **attrs)
242 (*attrs)->mode = S_IRUGO;
251 static __init enum ipl_type get_ipl_type(void)
253 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
255 if (ipl_flags & IPL_NSS_VALID)
257 if (!(ipl_flags & IPL_DEVNO_VALID))
258 return IPL_TYPE_UNKNOWN;
259 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
261 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
262 return IPL_TYPE_UNKNOWN;
263 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
264 return IPL_TYPE_UNKNOWN;
265 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
266 return IPL_TYPE_FCP_DUMP;
270 struct ipl_info ipl_info;
271 EXPORT_SYMBOL_GPL(ipl_info);
273 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
276 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
279 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
281 /* VM IPL PARM routines */
282 static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
283 const struct ipl_parameter_block *ipb)
287 char has_lowercase = 0;
290 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
291 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
293 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
294 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
295 /* If at least one character is lowercase, we assume mixed
296 * case; otherwise we convert everything to lowercase.
298 for (i = 0; i < len; i++)
299 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
300 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
301 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
306 EBC_TOLOWER(dest, len);
314 size_t append_ipl_vmparm(char *dest, size_t size)
319 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
320 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
326 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
327 struct kobj_attribute *attr, char *page)
329 char parm[DIAG308_VMPARM_SIZE + 1] = {};
331 append_ipl_vmparm(parm, sizeof(parm));
332 return sprintf(page, "%s\n", parm);
335 static size_t scpdata_length(const char* buf, size_t count)
338 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
345 static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
346 const struct ipl_parameter_block *ipb)
352 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
353 ipb->ipl_info.fcp.scp_data_len));
358 for (i = 0; i < count; i++) {
359 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
363 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
368 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
370 for (i = 0; i < count; i++)
371 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
377 size_t append_ipl_scpdata(char *dest, size_t len)
382 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
383 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
390 static struct kobj_attribute sys_ipl_vm_parm_attr =
391 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
393 static ssize_t sys_ipl_device_show(struct kobject *kobj,
394 struct kobj_attribute *attr, char *page)
396 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
398 switch (ipl_info.type) {
400 return sprintf(page, "0.0.%04x\n", ipl_devno);
402 case IPL_TYPE_FCP_DUMP:
403 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
409 static struct kobj_attribute sys_ipl_device_attr =
410 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
412 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
413 struct bin_attribute *attr, char *buf,
414 loff_t off, size_t count)
416 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
420 static struct bin_attribute ipl_parameter_attr = {
422 .name = "binary_parameter",
426 .read = &ipl_parameter_read,
429 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
430 struct bin_attribute *attr, char *buf,
431 loff_t off, size_t count)
433 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
434 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
436 return memory_read_from_buffer(buf, count, &off, scp_data, size);
439 static struct bin_attribute ipl_scp_data_attr = {
445 .read = ipl_scp_data_read,
448 /* FCP ipl device attributes */
450 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
451 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
452 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
453 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
454 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
455 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
456 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
457 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
459 static struct attribute *ipl_fcp_attrs[] = {
460 &sys_ipl_type_attr.attr,
461 &sys_ipl_device_attr.attr,
462 &sys_ipl_fcp_wwpn_attr.attr,
463 &sys_ipl_fcp_lun_attr.attr,
464 &sys_ipl_fcp_bootprog_attr.attr,
465 &sys_ipl_fcp_br_lba_attr.attr,
469 static struct attribute_group ipl_fcp_attr_group = {
470 .attrs = ipl_fcp_attrs,
473 /* CCW ipl device attributes */
475 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
476 struct kobj_attribute *attr, char *page)
478 char loadparm[LOADPARM_LEN + 1] = {};
480 if (!sclp_ipl_info.is_valid)
481 return sprintf(page, "#unknown#\n");
482 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
483 EBCASC(loadparm, LOADPARM_LEN);
485 return sprintf(page, "%s\n", loadparm);
488 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
489 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
491 static struct attribute *ipl_ccw_attrs_vm[] = {
492 &sys_ipl_type_attr.attr,
493 &sys_ipl_device_attr.attr,
494 &sys_ipl_ccw_loadparm_attr.attr,
495 &sys_ipl_vm_parm_attr.attr,
499 static struct attribute *ipl_ccw_attrs_lpar[] = {
500 &sys_ipl_type_attr.attr,
501 &sys_ipl_device_attr.attr,
502 &sys_ipl_ccw_loadparm_attr.attr,
506 static struct attribute_group ipl_ccw_attr_group_vm = {
507 .attrs = ipl_ccw_attrs_vm,
510 static struct attribute_group ipl_ccw_attr_group_lpar = {
511 .attrs = ipl_ccw_attrs_lpar
514 /* NSS ipl device attributes */
516 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
518 static struct attribute *ipl_nss_attrs[] = {
519 &sys_ipl_type_attr.attr,
520 &sys_ipl_nss_name_attr.attr,
521 &sys_ipl_ccw_loadparm_attr.attr,
522 &sys_ipl_vm_parm_attr.attr,
526 static struct attribute_group ipl_nss_attr_group = {
527 .attrs = ipl_nss_attrs,
530 /* UNKNOWN ipl device attributes */
532 static struct attribute *ipl_unknown_attrs[] = {
533 &sys_ipl_type_attr.attr,
537 static struct attribute_group ipl_unknown_attr_group = {
538 .attrs = ipl_unknown_attrs,
541 static struct kset *ipl_kset;
543 static int __init ipl_register_fcp_files(void)
547 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
550 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
553 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
557 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
560 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
565 static void __ipl_run(void *unused)
567 diag308(DIAG308_IPL, NULL);
569 __cpcmd("IPL", NULL, 0, NULL);
570 else if (ipl_info.type == IPL_TYPE_CCW)
571 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
574 static void ipl_run(struct shutdown_trigger *trigger)
576 smp_call_ipl_cpu(__ipl_run, NULL);
579 static int __init ipl_init(void)
583 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
588 switch (ipl_info.type) {
591 rc = sysfs_create_group(&ipl_kset->kobj,
592 &ipl_ccw_attr_group_vm);
594 rc = sysfs_create_group(&ipl_kset->kobj,
595 &ipl_ccw_attr_group_lpar);
598 case IPL_TYPE_FCP_DUMP:
599 rc = ipl_register_fcp_files();
602 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
605 rc = sysfs_create_group(&ipl_kset->kobj,
606 &ipl_unknown_attr_group);
611 panic("ipl_init failed: rc = %i\n", rc);
616 static struct shutdown_action __refdata ipl_action = {
617 .name = SHUTDOWN_ACTION_IPL_STR,
623 * reipl shutdown action: Reboot Linux on shutdown.
626 /* VM IPL PARM attributes */
627 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
630 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
632 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
633 return sprintf(page, "%s\n", vmparm);
636 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
638 const char *buf, size_t len)
642 /* ignore trailing newline */
644 if ((len > 0) && (buf[len - 1] == '\n'))
647 if (ip_len > vmparm_max)
650 /* parm is used to store kernel options, check for common chars */
651 for (i = 0; i < ip_len; i++)
652 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
655 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
656 ipb->ipl_info.ccw.vm_parm_len = ip_len;
658 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
659 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
660 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
662 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
669 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
670 struct kobj_attribute *attr, char *page)
672 return reipl_generic_vmparm_show(reipl_block_nss, page);
675 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
676 struct kobj_attribute *attr,
677 const char *buf, size_t len)
679 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
683 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
684 struct kobj_attribute *attr, char *page)
686 return reipl_generic_vmparm_show(reipl_block_ccw, page);
689 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
690 struct kobj_attribute *attr,
691 const char *buf, size_t len)
693 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
696 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
697 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
698 reipl_nss_vmparm_store);
699 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
700 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
701 reipl_ccw_vmparm_store);
703 /* FCP reipl device attributes */
705 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
706 struct bin_attribute *attr,
707 char *buf, loff_t off, size_t count)
709 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
710 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
712 return memory_read_from_buffer(buf, count, &off, scp_data, size);
715 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
716 struct bin_attribute *attr,
717 char *buf, loff_t off, size_t count)
725 if (off >= DIAG308_SCPDATA_SIZE)
728 if (count > DIAG308_SCPDATA_SIZE - off)
729 count = DIAG308_SCPDATA_SIZE - off;
731 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count);
732 scpdata_len = off + count;
734 if (scpdata_len % 8) {
735 padding = 8 - (scpdata_len % 8);
736 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
738 scpdata_len += padding;
741 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
742 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
743 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
748 static struct bin_attribute sys_reipl_fcp_scp_data_attr = {
751 .mode = S_IRUGO | S_IWUSR,
754 .read = reipl_fcp_scpdata_read,
755 .write = reipl_fcp_scpdata_write,
758 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
759 reipl_block_fcp->ipl_info.fcp.wwpn);
760 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
761 reipl_block_fcp->ipl_info.fcp.lun);
762 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
763 reipl_block_fcp->ipl_info.fcp.bootprog);
764 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
765 reipl_block_fcp->ipl_info.fcp.br_lba);
766 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
767 reipl_block_fcp->ipl_info.fcp.devno);
769 static struct attribute *reipl_fcp_attrs[] = {
770 &sys_reipl_fcp_device_attr.attr,
771 &sys_reipl_fcp_wwpn_attr.attr,
772 &sys_reipl_fcp_lun_attr.attr,
773 &sys_reipl_fcp_bootprog_attr.attr,
774 &sys_reipl_fcp_br_lba_attr.attr,
778 static struct attribute_group reipl_fcp_attr_group = {
779 .attrs = reipl_fcp_attrs,
782 /* CCW reipl device attributes */
784 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
785 reipl_block_ccw->ipl_info.ccw.devno);
787 static void reipl_get_ascii_loadparm(char *loadparm,
788 struct ipl_parameter_block *ibp)
790 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
791 EBCASC(loadparm, LOADPARM_LEN);
792 loadparm[LOADPARM_LEN] = 0;
796 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
799 char buf[LOADPARM_LEN + 1];
801 reipl_get_ascii_loadparm(buf, ipb);
802 return sprintf(page, "%s\n", buf);
805 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
806 const char *buf, size_t len)
810 /* ignore trailing newline */
812 if ((len > 0) && (buf[len - 1] == '\n'))
814 /* loadparm can have max 8 characters and must not start with a blank */
815 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
817 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
818 for (i = 0; i < lp_len; i++) {
819 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
824 /* initialize loadparm with blanks */
825 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
826 /* copy and convert to ebcdic */
827 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
828 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
833 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
834 struct kobj_attribute *attr, char *page)
836 return reipl_generic_loadparm_show(reipl_block_nss, page);
839 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
840 struct kobj_attribute *attr,
841 const char *buf, size_t len)
843 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
847 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
848 struct kobj_attribute *attr, char *page)
850 return reipl_generic_loadparm_show(reipl_block_ccw, page);
853 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
854 struct kobj_attribute *attr,
855 const char *buf, size_t len)
857 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
860 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
861 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
862 reipl_ccw_loadparm_store);
864 static struct attribute *reipl_ccw_attrs_vm[] = {
865 &sys_reipl_ccw_device_attr.attr,
866 &sys_reipl_ccw_loadparm_attr.attr,
867 &sys_reipl_ccw_vmparm_attr.attr,
871 static struct attribute *reipl_ccw_attrs_lpar[] = {
872 &sys_reipl_ccw_device_attr.attr,
873 &sys_reipl_ccw_loadparm_attr.attr,
877 static struct attribute_group reipl_ccw_attr_group_vm = {
879 .attrs = reipl_ccw_attrs_vm,
882 static struct attribute_group reipl_ccw_attr_group_lpar = {
884 .attrs = reipl_ccw_attrs_lpar,
888 /* NSS reipl device attributes */
889 static void reipl_get_ascii_nss_name(char *dst,
890 struct ipl_parameter_block *ipb)
892 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
893 EBCASC(dst, NSS_NAME_SIZE);
894 dst[NSS_NAME_SIZE] = 0;
897 static ssize_t reipl_nss_name_show(struct kobject *kobj,
898 struct kobj_attribute *attr, char *page)
900 char nss_name[NSS_NAME_SIZE + 1] = {};
902 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
903 return sprintf(page, "%s\n", nss_name);
906 static ssize_t reipl_nss_name_store(struct kobject *kobj,
907 struct kobj_attribute *attr,
908 const char *buf, size_t len)
912 /* ignore trailing newline */
914 if ((len > 0) && (buf[len - 1] == '\n'))
917 if (nss_len > NSS_NAME_SIZE)
920 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
922 reipl_block_nss->ipl_info.ccw.vm_flags |=
923 DIAG308_VM_FLAGS_NSS_VALID;
924 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
925 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
926 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
928 reipl_block_nss->ipl_info.ccw.vm_flags &=
929 ~DIAG308_VM_FLAGS_NSS_VALID;
935 static struct kobj_attribute sys_reipl_nss_name_attr =
936 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
937 reipl_nss_name_store);
939 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
940 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
941 reipl_nss_loadparm_store);
943 static struct attribute *reipl_nss_attrs[] = {
944 &sys_reipl_nss_name_attr.attr,
945 &sys_reipl_nss_loadparm_attr.attr,
946 &sys_reipl_nss_vmparm_attr.attr,
950 static struct attribute_group reipl_nss_attr_group = {
952 .attrs = reipl_nss_attrs,
955 static void set_reipl_block_actual(struct ipl_parameter_block *reipl_block)
957 reipl_block_actual = reipl_block;
958 os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
959 reipl_block->hdr.len);
964 static int reipl_set_type(enum ipl_type type)
966 if (!(reipl_capabilities & type))
971 if (diag308_set_works)
972 reipl_method = REIPL_METHOD_CCW_DIAG;
973 else if (MACHINE_IS_VM)
974 reipl_method = REIPL_METHOD_CCW_VM;
976 reipl_method = REIPL_METHOD_CCW_CIO;
977 set_reipl_block_actual(reipl_block_ccw);
980 if (diag308_set_works)
981 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
982 else if (MACHINE_IS_VM)
983 reipl_method = REIPL_METHOD_FCP_RO_VM;
985 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
986 set_reipl_block_actual(reipl_block_fcp);
988 case IPL_TYPE_FCP_DUMP:
989 reipl_method = REIPL_METHOD_FCP_DUMP;
992 if (diag308_set_works)
993 reipl_method = REIPL_METHOD_NSS_DIAG;
995 reipl_method = REIPL_METHOD_NSS;
996 set_reipl_block_actual(reipl_block_nss);
998 case IPL_TYPE_UNKNOWN:
999 reipl_method = REIPL_METHOD_DEFAULT;
1008 static ssize_t reipl_type_show(struct kobject *kobj,
1009 struct kobj_attribute *attr, char *page)
1011 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1014 static ssize_t reipl_type_store(struct kobject *kobj,
1015 struct kobj_attribute *attr,
1016 const char *buf, size_t len)
1020 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1021 rc = reipl_set_type(IPL_TYPE_CCW);
1022 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1023 rc = reipl_set_type(IPL_TYPE_FCP);
1024 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1025 rc = reipl_set_type(IPL_TYPE_NSS);
1026 return (rc != 0) ? rc : len;
1029 static struct kobj_attribute reipl_type_attr =
1030 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1032 static struct kset *reipl_kset;
1033 static struct kset *reipl_fcp_kset;
1035 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1036 const enum ipl_method m)
1038 char loadparm[LOADPARM_LEN + 1] = {};
1039 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1040 char nss_name[NSS_NAME_SIZE + 1] = {};
1043 reipl_get_ascii_loadparm(loadparm, ipb);
1044 reipl_get_ascii_nss_name(nss_name, ipb);
1045 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
1048 case REIPL_METHOD_CCW_VM:
1049 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1051 case REIPL_METHOD_NSS:
1052 pos = sprintf(dst, "IPL %s", nss_name);
1057 if (strlen(loadparm) > 0)
1058 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1059 if (strlen(vmparm) > 0)
1060 sprintf(dst + pos, " PARM %s", vmparm);
1063 static void __reipl_run(void *unused)
1065 struct ccw_dev_id devid;
1066 static char buf[128];
1068 switch (reipl_method) {
1069 case REIPL_METHOD_CCW_CIO:
1070 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1072 reipl_ccw_dev(&devid);
1074 case REIPL_METHOD_CCW_VM:
1075 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
1076 __cpcmd(buf, NULL, 0, NULL);
1078 case REIPL_METHOD_CCW_DIAG:
1079 diag308(DIAG308_SET, reipl_block_ccw);
1080 diag308(DIAG308_IPL, NULL);
1082 case REIPL_METHOD_FCP_RW_DIAG:
1083 diag308(DIAG308_SET, reipl_block_fcp);
1084 diag308(DIAG308_IPL, NULL);
1086 case REIPL_METHOD_FCP_RO_DIAG:
1087 diag308(DIAG308_IPL, NULL);
1089 case REIPL_METHOD_FCP_RO_VM:
1090 __cpcmd("IPL", NULL, 0, NULL);
1092 case REIPL_METHOD_NSS_DIAG:
1093 diag308(DIAG308_SET, reipl_block_nss);
1094 diag308(DIAG308_IPL, NULL);
1096 case REIPL_METHOD_NSS:
1097 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
1098 __cpcmd(buf, NULL, 0, NULL);
1100 case REIPL_METHOD_DEFAULT:
1102 __cpcmd("IPL", NULL, 0, NULL);
1103 diag308(DIAG308_IPL, NULL);
1105 case REIPL_METHOD_FCP_DUMP:
1108 disabled_wait((unsigned long) __builtin_return_address(0));
1111 static void reipl_run(struct shutdown_trigger *trigger)
1113 smp_call_ipl_cpu(__reipl_run, NULL);
1116 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1118 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1119 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1120 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1121 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1124 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1127 /* check if read scp info worked and set loadparm */
1128 if (sclp_ipl_info.is_valid)
1129 memcpy(ipb->ipl_info.ccw.load_parm,
1130 &sclp_ipl_info.loadparm, LOADPARM_LEN);
1132 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1133 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
1134 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1137 if (MACHINE_IS_VM && diag308_set_works &&
1138 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1140 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1141 ipb->ipl_info.ccw.vm_parm_len =
1142 ipl_block.ipl_info.ccw.vm_parm_len;
1143 memcpy(ipb->ipl_info.ccw.vm_parm,
1144 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1148 static int __init reipl_nss_init(void)
1155 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1156 if (!reipl_block_nss)
1159 if (!diag308_set_works)
1160 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1162 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1166 reipl_block_ccw_init(reipl_block_nss);
1167 if (ipl_info.type == IPL_TYPE_NSS) {
1168 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1169 ' ', NSS_NAME_SIZE);
1170 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1171 kernel_nss_name, strlen(kernel_nss_name));
1172 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1173 reipl_block_nss->ipl_info.ccw.vm_flags |=
1174 DIAG308_VM_FLAGS_NSS_VALID;
1176 reipl_block_ccw_fill_parms(reipl_block_nss);
1179 reipl_capabilities |= IPL_TYPE_NSS;
1183 static int __init reipl_ccw_init(void)
1187 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1188 if (!reipl_block_ccw)
1191 if (MACHINE_IS_VM) {
1192 if (!diag308_set_works)
1193 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1194 rc = sysfs_create_group(&reipl_kset->kobj,
1195 &reipl_ccw_attr_group_vm);
1197 if(!diag308_set_works)
1198 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1199 rc = sysfs_create_group(&reipl_kset->kobj,
1200 &reipl_ccw_attr_group_lpar);
1205 reipl_block_ccw_init(reipl_block_ccw);
1206 if (ipl_info.type == IPL_TYPE_CCW) {
1207 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1208 reipl_block_ccw_fill_parms(reipl_block_ccw);
1211 reipl_capabilities |= IPL_TYPE_CCW;
1215 static int __init reipl_fcp_init(void)
1219 if (!diag308_set_works) {
1220 if (ipl_info.type == IPL_TYPE_FCP) {
1221 make_attrs_ro(reipl_fcp_attrs);
1222 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1227 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1228 if (!reipl_block_fcp)
1231 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1232 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1234 if (!reipl_fcp_kset) {
1235 free_page((unsigned long) reipl_block_fcp);
1239 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1241 kset_unregister(reipl_fcp_kset);
1242 free_page((unsigned long) reipl_block_fcp);
1246 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj,
1247 &sys_reipl_fcp_scp_data_attr);
1249 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1250 kset_unregister(reipl_fcp_kset);
1251 free_page((unsigned long) reipl_block_fcp);
1255 if (ipl_info.type == IPL_TYPE_FCP)
1256 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1258 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1259 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1260 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1261 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1262 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1264 reipl_capabilities |= IPL_TYPE_FCP;
1268 static int __init reipl_type_init(void)
1270 enum ipl_type reipl_type = ipl_info.type;
1271 struct ipl_parameter_block *reipl_block;
1274 reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1278 * If we have an OS info reipl block, this will be used
1280 if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_FCP) {
1281 memcpy(reipl_block_fcp, reipl_block, size);
1282 reipl_type = IPL_TYPE_FCP;
1283 } else if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_CCW) {
1284 memcpy(reipl_block_ccw, reipl_block, size);
1285 reipl_type = IPL_TYPE_CCW;
1288 return reipl_set_type(reipl_type);
1291 static int __init reipl_init(void)
1295 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1298 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1300 kset_unregister(reipl_kset);
1303 rc = reipl_ccw_init();
1306 rc = reipl_fcp_init();
1309 rc = reipl_nss_init();
1312 return reipl_type_init();
1315 static struct shutdown_action __refdata reipl_action = {
1316 .name = SHUTDOWN_ACTION_REIPL_STR,
1322 * dump shutdown action: Dump Linux on shutdown.
1325 /* FCP dump device attributes */
1327 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1328 dump_block_fcp->ipl_info.fcp.wwpn);
1329 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1330 dump_block_fcp->ipl_info.fcp.lun);
1331 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1332 dump_block_fcp->ipl_info.fcp.bootprog);
1333 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1334 dump_block_fcp->ipl_info.fcp.br_lba);
1335 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1336 dump_block_fcp->ipl_info.fcp.devno);
1338 static struct attribute *dump_fcp_attrs[] = {
1339 &sys_dump_fcp_device_attr.attr,
1340 &sys_dump_fcp_wwpn_attr.attr,
1341 &sys_dump_fcp_lun_attr.attr,
1342 &sys_dump_fcp_bootprog_attr.attr,
1343 &sys_dump_fcp_br_lba_attr.attr,
1347 static struct attribute_group dump_fcp_attr_group = {
1348 .name = IPL_FCP_STR,
1349 .attrs = dump_fcp_attrs,
1352 /* CCW dump device attributes */
1354 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1355 dump_block_ccw->ipl_info.ccw.devno);
1357 static struct attribute *dump_ccw_attrs[] = {
1358 &sys_dump_ccw_device_attr.attr,
1362 static struct attribute_group dump_ccw_attr_group = {
1363 .name = IPL_CCW_STR,
1364 .attrs = dump_ccw_attrs,
1369 static int dump_set_type(enum dump_type type)
1371 if (!(dump_capabilities & type))
1375 if (diag308_set_works)
1376 dump_method = DUMP_METHOD_CCW_DIAG;
1377 else if (MACHINE_IS_VM)
1378 dump_method = DUMP_METHOD_CCW_VM;
1380 dump_method = DUMP_METHOD_CCW_CIO;
1383 dump_method = DUMP_METHOD_FCP_DIAG;
1386 dump_method = DUMP_METHOD_NONE;
1392 static ssize_t dump_type_show(struct kobject *kobj,
1393 struct kobj_attribute *attr, char *page)
1395 return sprintf(page, "%s\n", dump_type_str(dump_type));
1398 static ssize_t dump_type_store(struct kobject *kobj,
1399 struct kobj_attribute *attr,
1400 const char *buf, size_t len)
1404 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1405 rc = dump_set_type(DUMP_TYPE_NONE);
1406 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1407 rc = dump_set_type(DUMP_TYPE_CCW);
1408 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1409 rc = dump_set_type(DUMP_TYPE_FCP);
1410 return (rc != 0) ? rc : len;
1413 static struct kobj_attribute dump_type_attr =
1414 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1416 static struct kset *dump_kset;
1418 static void __dump_run(void *unused)
1420 struct ccw_dev_id devid;
1421 static char buf[100];
1423 switch (dump_method) {
1424 case DUMP_METHOD_CCW_CIO:
1425 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1427 reipl_ccw_dev(&devid);
1429 case DUMP_METHOD_CCW_VM:
1430 sprintf(buf, "STORE STATUS");
1431 __cpcmd(buf, NULL, 0, NULL);
1432 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1433 __cpcmd(buf, NULL, 0, NULL);
1435 case DUMP_METHOD_CCW_DIAG:
1436 diag308(DIAG308_SET, dump_block_ccw);
1437 diag308(DIAG308_DUMP, NULL);
1439 case DUMP_METHOD_FCP_DIAG:
1440 diag308(DIAG308_SET, dump_block_fcp);
1441 diag308(DIAG308_DUMP, NULL);
1448 static void dump_run(struct shutdown_trigger *trigger)
1450 if (dump_method == DUMP_METHOD_NONE)
1453 smp_call_ipl_cpu(__dump_run, NULL);
1456 static int __init dump_ccw_init(void)
1460 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1461 if (!dump_block_ccw)
1463 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1465 free_page((unsigned long)dump_block_ccw);
1468 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1469 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1470 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1471 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1472 dump_capabilities |= DUMP_TYPE_CCW;
1476 static int __init dump_fcp_init(void)
1480 if (!sclp_ipl_info.has_dump)
1481 return 0; /* LDIPL DUMP is not installed */
1482 if (!diag308_set_works)
1484 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1485 if (!dump_block_fcp)
1487 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1489 free_page((unsigned long)dump_block_fcp);
1492 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1493 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1494 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1495 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1496 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1497 dump_capabilities |= DUMP_TYPE_FCP;
1501 static int __init dump_init(void)
1505 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1508 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1510 kset_unregister(dump_kset);
1513 rc = dump_ccw_init();
1516 rc = dump_fcp_init();
1519 dump_set_type(DUMP_TYPE_NONE);
1523 static struct shutdown_action __refdata dump_action = {
1524 .name = SHUTDOWN_ACTION_DUMP_STR,
1529 static void dump_reipl_run(struct shutdown_trigger *trigger)
1533 csum = csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1534 copy_to_absolute_zero(&S390_lowcore.ipib_checksum, &csum, sizeof(csum));
1535 copy_to_absolute_zero(&S390_lowcore.ipib, &reipl_block_actual,
1536 sizeof(reipl_block_actual));
1540 static int __init dump_reipl_init(void)
1542 if (!diag308_set_works)
1548 static struct shutdown_action __refdata dump_reipl_action = {
1549 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1550 .fn = dump_reipl_run,
1551 .init = dump_reipl_init,
1555 * vmcmd shutdown action: Trigger vm command on shutdown.
1558 static char vmcmd_on_reboot[128];
1559 static char vmcmd_on_panic[128];
1560 static char vmcmd_on_halt[128];
1561 static char vmcmd_on_poff[128];
1562 static char vmcmd_on_restart[128];
1564 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1565 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1566 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1567 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1568 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1570 static struct attribute *vmcmd_attrs[] = {
1571 &sys_vmcmd_on_reboot_attr.attr,
1572 &sys_vmcmd_on_panic_attr.attr,
1573 &sys_vmcmd_on_halt_attr.attr,
1574 &sys_vmcmd_on_poff_attr.attr,
1575 &sys_vmcmd_on_restart_attr.attr,
1579 static struct attribute_group vmcmd_attr_group = {
1580 .attrs = vmcmd_attrs,
1583 static struct kset *vmcmd_kset;
1585 static void vmcmd_run(struct shutdown_trigger *trigger)
1587 char *cmd, *next_cmd;
1589 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1590 cmd = vmcmd_on_reboot;
1591 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1592 cmd = vmcmd_on_panic;
1593 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1594 cmd = vmcmd_on_halt;
1595 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1596 cmd = vmcmd_on_poff;
1597 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1598 cmd = vmcmd_on_restart;
1602 if (strlen(cmd) == 0)
1605 next_cmd = strchr(cmd, '\n');
1610 __cpcmd(cmd, NULL, 0, NULL);
1612 } while (cmd != NULL);
1615 static int vmcmd_init(void)
1619 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1622 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1625 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1626 vmcmd_run, vmcmd_init};
1629 * stop shutdown action: Stop Linux on shutdown.
1632 static void stop_run(struct shutdown_trigger *trigger)
1634 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1635 strcmp(trigger->name, ON_RESTART_STR) == 0)
1636 disabled_wait((unsigned long) __builtin_return_address(0));
1640 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1645 static struct shutdown_action *shutdown_actions_list[] = {
1646 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1647 &vmcmd_action, &stop_action};
1648 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1654 static struct kset *shutdown_actions_kset;
1656 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1661 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1662 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1663 if (shutdown_actions_list[i]->init_rc) {
1664 return shutdown_actions_list[i]->init_rc;
1666 trigger->action = shutdown_actions_list[i];
1676 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1679 static ssize_t on_reboot_show(struct kobject *kobj,
1680 struct kobj_attribute *attr, char *page)
1682 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1685 static ssize_t on_reboot_store(struct kobject *kobj,
1686 struct kobj_attribute *attr,
1687 const char *buf, size_t len)
1689 return set_trigger(buf, &on_reboot_trigger, len);
1692 static struct kobj_attribute on_reboot_attr =
1693 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1695 static void do_machine_restart(char *__unused)
1698 on_reboot_trigger.action->fn(&on_reboot_trigger);
1701 void (*_machine_restart)(char *command) = do_machine_restart;
1705 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1707 static ssize_t on_panic_show(struct kobject *kobj,
1708 struct kobj_attribute *attr, char *page)
1710 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1713 static ssize_t on_panic_store(struct kobject *kobj,
1714 struct kobj_attribute *attr,
1715 const char *buf, size_t len)
1717 return set_trigger(buf, &on_panic_trigger, len);
1720 static struct kobj_attribute on_panic_attr =
1721 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1723 static void do_panic(void)
1726 on_panic_trigger.action->fn(&on_panic_trigger);
1727 stop_run(&on_panic_trigger);
1732 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
1735 static ssize_t on_restart_show(struct kobject *kobj,
1736 struct kobj_attribute *attr, char *page)
1738 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1741 static ssize_t on_restart_store(struct kobject *kobj,
1742 struct kobj_attribute *attr,
1743 const char *buf, size_t len)
1745 return set_trigger(buf, &on_restart_trigger, len);
1748 static struct kobj_attribute on_restart_attr =
1749 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1751 static void __do_restart(void *ignore)
1754 #ifdef CONFIG_CRASH_DUMP
1757 on_restart_trigger.action->fn(&on_restart_trigger);
1758 stop_run(&on_restart_trigger);
1761 void do_restart(void)
1766 smp_call_online_cpu(__do_restart, NULL);
1771 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1773 static ssize_t on_halt_show(struct kobject *kobj,
1774 struct kobj_attribute *attr, char *page)
1776 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1779 static ssize_t on_halt_store(struct kobject *kobj,
1780 struct kobj_attribute *attr,
1781 const char *buf, size_t len)
1783 return set_trigger(buf, &on_halt_trigger, len);
1786 static struct kobj_attribute on_halt_attr =
1787 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1790 static void do_machine_halt(void)
1793 on_halt_trigger.action->fn(&on_halt_trigger);
1794 stop_run(&on_halt_trigger);
1796 void (*_machine_halt)(void) = do_machine_halt;
1800 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1802 static ssize_t on_poff_show(struct kobject *kobj,
1803 struct kobj_attribute *attr, char *page)
1805 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1808 static ssize_t on_poff_store(struct kobject *kobj,
1809 struct kobj_attribute *attr,
1810 const char *buf, size_t len)
1812 return set_trigger(buf, &on_poff_trigger, len);
1815 static struct kobj_attribute on_poff_attr =
1816 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1819 static void do_machine_power_off(void)
1822 on_poff_trigger.action->fn(&on_poff_trigger);
1823 stop_run(&on_poff_trigger);
1825 void (*_machine_power_off)(void) = do_machine_power_off;
1827 static void __init shutdown_triggers_init(void)
1829 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1831 if (!shutdown_actions_kset)
1833 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1834 &on_reboot_attr.attr))
1836 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1837 &on_panic_attr.attr))
1839 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1840 &on_halt_attr.attr))
1842 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1843 &on_poff_attr.attr))
1845 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1846 &on_restart_attr.attr))
1850 panic("shutdown_triggers_init failed\n");
1853 static void __init shutdown_actions_init(void)
1857 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1858 if (!shutdown_actions_list[i]->init)
1860 shutdown_actions_list[i]->init_rc =
1861 shutdown_actions_list[i]->init();
1865 static int __init s390_ipl_init(void)
1867 sclp_get_ipl_info(&sclp_ipl_info);
1868 shutdown_actions_init();
1869 shutdown_triggers_init();
1873 __initcall(s390_ipl_init);
1875 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1880 for (sx = 0; src[sx] != 0; sx++) {
1883 dst[dx++] = src[sx];
1889 static int __init vmcmd_on_reboot_setup(char *str)
1893 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1894 vmcmd_on_reboot[127] = 0;
1895 on_reboot_trigger.action = &vmcmd_action;
1898 __setup("vmreboot=", vmcmd_on_reboot_setup);
1900 static int __init vmcmd_on_panic_setup(char *str)
1904 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1905 vmcmd_on_panic[127] = 0;
1906 on_panic_trigger.action = &vmcmd_action;
1909 __setup("vmpanic=", vmcmd_on_panic_setup);
1911 static int __init vmcmd_on_halt_setup(char *str)
1915 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1916 vmcmd_on_halt[127] = 0;
1917 on_halt_trigger.action = &vmcmd_action;
1920 __setup("vmhalt=", vmcmd_on_halt_setup);
1922 static int __init vmcmd_on_poff_setup(char *str)
1926 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1927 vmcmd_on_poff[127] = 0;
1928 on_poff_trigger.action = &vmcmd_action;
1931 __setup("vmpoff=", vmcmd_on_poff_setup);
1933 static int on_panic_notify(struct notifier_block *self,
1934 unsigned long event, void *data)
1940 static struct notifier_block on_panic_nb = {
1941 .notifier_call = on_panic_notify,
1942 .priority = INT_MIN,
1945 void __init setup_ipl(void)
1947 ipl_info.type = get_ipl_type();
1948 switch (ipl_info.type) {
1950 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1951 ipl_info.data.ccw.dev_id.ssid = 0;
1954 case IPL_TYPE_FCP_DUMP:
1955 ipl_info.data.fcp.dev_id.devno =
1956 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1957 ipl_info.data.fcp.dev_id.ssid = 0;
1958 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1959 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1962 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1963 sizeof(ipl_info.data.nss.name));
1965 case IPL_TYPE_UNKNOWN:
1966 /* We have no info to copy */
1969 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1972 void __init ipl_update_parameters(void)
1976 rc = diag308(DIAG308_STORE, &ipl_block);
1977 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1978 diag308_set_works = 1;
1981 void __init ipl_save_parameters(void)
1983 struct cio_iplinfo iplinfo;
1986 if (cio_get_iplinfo(&iplinfo))
1989 ipl_devno = iplinfo.devno;
1990 ipl_flags |= IPL_DEVNO_VALID;
1991 if (!iplinfo.is_qdio)
1993 ipl_flags |= IPL_PARMBLOCK_VALID;
1994 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
1995 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1996 memmove(dst, src, PAGE_SIZE);
1997 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
2000 static LIST_HEAD(rcall);
2001 static DEFINE_MUTEX(rcall_mutex);
2003 void register_reset_call(struct reset_call *reset)
2005 mutex_lock(&rcall_mutex);
2006 list_add(&reset->list, &rcall);
2007 mutex_unlock(&rcall_mutex);
2009 EXPORT_SYMBOL_GPL(register_reset_call);
2011 void unregister_reset_call(struct reset_call *reset)
2013 mutex_lock(&rcall_mutex);
2014 list_del(&reset->list);
2015 mutex_unlock(&rcall_mutex);
2017 EXPORT_SYMBOL_GPL(unregister_reset_call);
2019 static void do_reset_calls(void)
2021 struct reset_call *reset;
2024 if (diag308_set_works) {
2029 list_for_each_entry(reset, &rcall, list)
2033 u32 dump_prefix_page;
2035 void s390_reset_system(void (*func)(void *), void *data)
2037 struct _lowcore *lc;
2039 lc = (struct _lowcore *)(unsigned long) store_prefix();
2041 /* Stack for interrupt/machine check handler */
2042 lc->panic_stack = S390_lowcore.panic_stack;
2044 /* Save prefix page address for dump case */
2045 dump_prefix_page = (u32)(unsigned long) lc;
2047 /* Disable prefixing */
2050 /* Disable lowcore protection */
2051 __ctl_clear_bit(0,28);
2053 /* Set new machine check handler */
2054 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
2055 S390_lowcore.mcck_new_psw.addr =
2056 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
2058 /* Set new program check handler */
2059 S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
2060 S390_lowcore.program_new_psw.addr =
2061 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
2063 /* Store status at absolute zero */