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>
18 #include <linux/gfp.h>
21 #include <asm/setup.h>
22 #include <asm/cpcmd.h>
24 #include <asm/ebcdic.h>
25 #include <asm/reset.h>
28 #include <asm/checksum.h>
30 #define IPL_PARM_BLOCK_VERSION 0
32 #define IPL_UNKNOWN_STR "unknown"
33 #define IPL_CCW_STR "ccw"
34 #define IPL_FCP_STR "fcp"
35 #define IPL_FCP_DUMP_STR "fcp_dump"
36 #define IPL_NSS_STR "nss"
38 #define DUMP_CCW_STR "ccw"
39 #define DUMP_FCP_STR "fcp"
40 #define DUMP_NONE_STR "none"
43 * Four shutdown trigger types are supported:
50 #define ON_PANIC_STR "on_panic"
51 #define ON_HALT_STR "on_halt"
52 #define ON_POFF_STR "on_poff"
53 #define ON_REIPL_STR "on_reboot"
54 #define ON_RESTART_STR "on_restart"
56 struct shutdown_action;
57 struct shutdown_trigger {
59 struct shutdown_action *action;
63 * The following shutdown action types are supported:
65 #define SHUTDOWN_ACTION_IPL_STR "ipl"
66 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
67 #define SHUTDOWN_ACTION_DUMP_STR "dump"
68 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
69 #define SHUTDOWN_ACTION_STOP_STR "stop"
70 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
72 struct shutdown_action {
74 void (*fn) (struct shutdown_trigger *trigger);
79 static char *ipl_type_str(enum ipl_type type)
86 case IPL_TYPE_FCP_DUMP:
87 return IPL_FCP_DUMP_STR;
90 case IPL_TYPE_UNKNOWN:
92 return IPL_UNKNOWN_STR;
102 static char *dump_type_str(enum dump_type type)
106 return DUMP_NONE_STR;
117 * Must be in data section since the bss section
118 * is not cleared when these are accessed.
120 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
121 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
124 REIPL_METHOD_CCW_CIO,
125 REIPL_METHOD_CCW_DIAG,
127 REIPL_METHOD_FCP_RO_DIAG,
128 REIPL_METHOD_FCP_RW_DIAG,
129 REIPL_METHOD_FCP_RO_VM,
130 REIPL_METHOD_FCP_DUMP,
132 REIPL_METHOD_NSS_DIAG,
133 REIPL_METHOD_DEFAULT,
139 DUMP_METHOD_CCW_DIAG,
141 DUMP_METHOD_FCP_DIAG,
144 static int diag308_set_works = 0;
146 static struct ipl_parameter_block ipl_block;
148 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
150 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
151 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
152 static struct ipl_parameter_block *reipl_block_fcp;
153 static struct ipl_parameter_block *reipl_block_ccw;
154 static struct ipl_parameter_block *reipl_block_nss;
155 static struct ipl_parameter_block *reipl_block_actual;
157 static int dump_capabilities = DUMP_TYPE_NONE;
158 static enum dump_type dump_type = DUMP_TYPE_NONE;
159 static enum dump_method dump_method = DUMP_METHOD_NONE;
160 static struct ipl_parameter_block *dump_block_fcp;
161 static struct ipl_parameter_block *dump_block_ccw;
163 static struct sclp_ipl_info sclp_ipl_info;
165 int diag308(unsigned long subcode, void *addr)
167 register unsigned long _addr asm("0") = (unsigned long) addr;
168 register unsigned long _rc asm("1") = 0;
171 " diag %0,%2,0x308\n"
174 : "+d" (_addr), "+d" (_rc)
175 : "d" (subcode) : "cc", "memory");
178 EXPORT_SYMBOL_GPL(diag308);
182 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
183 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
184 struct kobj_attribute *attr, \
187 return sprintf(page, _format, _value); \
189 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
190 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
192 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
193 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
194 struct kobj_attribute *attr, \
197 return sprintf(page, _fmt_out, \
198 (unsigned long long) _value); \
200 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
201 struct kobj_attribute *attr, \
202 const char *buf, size_t len) \
204 unsigned long long value; \
205 if (sscanf(buf, _fmt_in, &value) != 1) \
210 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
211 __ATTR(_name,(S_IRUGO | S_IWUSR), \
212 sys_##_prefix##_##_name##_show, \
213 sys_##_prefix##_##_name##_store);
215 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
216 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
217 struct kobj_attribute *attr, \
220 return sprintf(page, _fmt_out, _value); \
222 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
223 struct kobj_attribute *attr, \
224 const char *buf, size_t len) \
226 strncpy(_value, buf, sizeof(_value) - 1); \
230 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
231 __ATTR(_name,(S_IRUGO | S_IWUSR), \
232 sys_##_prefix##_##_name##_show, \
233 sys_##_prefix##_##_name##_store);
235 static void make_attrs_ro(struct attribute **attrs)
238 (*attrs)->mode = S_IRUGO;
247 static __init enum ipl_type get_ipl_type(void)
249 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
251 if (ipl_flags & IPL_NSS_VALID)
253 if (!(ipl_flags & IPL_DEVNO_VALID))
254 return IPL_TYPE_UNKNOWN;
255 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
257 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
258 return IPL_TYPE_UNKNOWN;
259 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
260 return IPL_TYPE_UNKNOWN;
261 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
262 return IPL_TYPE_FCP_DUMP;
266 struct ipl_info ipl_info;
267 EXPORT_SYMBOL_GPL(ipl_info);
269 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
272 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
275 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
277 /* VM IPL PARM routines */
278 size_t reipl_get_ascii_vmparm(char *dest, size_t size,
279 const struct ipl_parameter_block *ipb)
283 char has_lowercase = 0;
286 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
287 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
289 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
290 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
291 /* If at least one character is lowercase, we assume mixed
292 * case; otherwise we convert everything to lowercase.
294 for (i = 0; i < len; i++)
295 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
296 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
297 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
302 EBC_TOLOWER(dest, len);
310 size_t append_ipl_vmparm(char *dest, size_t size)
315 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
316 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
322 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
323 struct kobj_attribute *attr, char *page)
325 char parm[DIAG308_VMPARM_SIZE + 1] = {};
327 append_ipl_vmparm(parm, sizeof(parm));
328 return sprintf(page, "%s\n", parm);
331 static size_t scpdata_length(const char* buf, size_t count)
334 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
341 size_t reipl_append_ascii_scpdata(char *dest, size_t size,
342 const struct ipl_parameter_block *ipb)
348 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
349 ipb->ipl_info.fcp.scp_data_len));
354 for (i = 0; i < count; i++) {
355 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
359 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
364 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
366 for (i = 0; i < count; i++)
367 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
373 size_t append_ipl_scpdata(char *dest, size_t len)
378 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
379 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
386 static struct kobj_attribute sys_ipl_vm_parm_attr =
387 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
389 static ssize_t sys_ipl_device_show(struct kobject *kobj,
390 struct kobj_attribute *attr, char *page)
392 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
394 switch (ipl_info.type) {
396 return sprintf(page, "0.0.%04x\n", ipl_devno);
398 case IPL_TYPE_FCP_DUMP:
399 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
405 static struct kobj_attribute sys_ipl_device_attr =
406 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
408 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
409 struct bin_attribute *attr, char *buf,
410 loff_t off, size_t count)
412 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
416 static struct bin_attribute ipl_parameter_attr = {
418 .name = "binary_parameter",
422 .read = &ipl_parameter_read,
425 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
426 struct bin_attribute *attr, char *buf,
427 loff_t off, size_t count)
429 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
430 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
432 return memory_read_from_buffer(buf, count, &off, scp_data, size);
435 static struct bin_attribute ipl_scp_data_attr = {
441 .read = ipl_scp_data_read,
444 /* FCP ipl device attributes */
446 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
447 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
448 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
449 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
450 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
451 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
452 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
453 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
455 static struct attribute *ipl_fcp_attrs[] = {
456 &sys_ipl_type_attr.attr,
457 &sys_ipl_device_attr.attr,
458 &sys_ipl_fcp_wwpn_attr.attr,
459 &sys_ipl_fcp_lun_attr.attr,
460 &sys_ipl_fcp_bootprog_attr.attr,
461 &sys_ipl_fcp_br_lba_attr.attr,
465 static struct attribute_group ipl_fcp_attr_group = {
466 .attrs = ipl_fcp_attrs,
469 /* CCW ipl device attributes */
471 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
472 struct kobj_attribute *attr, char *page)
474 char loadparm[LOADPARM_LEN + 1] = {};
476 if (!sclp_ipl_info.is_valid)
477 return sprintf(page, "#unknown#\n");
478 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
479 EBCASC(loadparm, LOADPARM_LEN);
481 return sprintf(page, "%s\n", loadparm);
484 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
485 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
487 static struct attribute *ipl_ccw_attrs_vm[] = {
488 &sys_ipl_type_attr.attr,
489 &sys_ipl_device_attr.attr,
490 &sys_ipl_ccw_loadparm_attr.attr,
491 &sys_ipl_vm_parm_attr.attr,
495 static struct attribute *ipl_ccw_attrs_lpar[] = {
496 &sys_ipl_type_attr.attr,
497 &sys_ipl_device_attr.attr,
498 &sys_ipl_ccw_loadparm_attr.attr,
502 static struct attribute_group ipl_ccw_attr_group_vm = {
503 .attrs = ipl_ccw_attrs_vm,
506 static struct attribute_group ipl_ccw_attr_group_lpar = {
507 .attrs = ipl_ccw_attrs_lpar
510 /* NSS ipl device attributes */
512 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
514 static struct attribute *ipl_nss_attrs[] = {
515 &sys_ipl_type_attr.attr,
516 &sys_ipl_nss_name_attr.attr,
517 &sys_ipl_ccw_loadparm_attr.attr,
518 &sys_ipl_vm_parm_attr.attr,
522 static struct attribute_group ipl_nss_attr_group = {
523 .attrs = ipl_nss_attrs,
526 /* UNKNOWN ipl device attributes */
528 static struct attribute *ipl_unknown_attrs[] = {
529 &sys_ipl_type_attr.attr,
533 static struct attribute_group ipl_unknown_attr_group = {
534 .attrs = ipl_unknown_attrs,
537 static struct kset *ipl_kset;
539 static int __init ipl_register_fcp_files(void)
543 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
546 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
549 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
553 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
556 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
561 static void __ipl_run(void *unused)
563 diag308(DIAG308_IPL, NULL);
565 __cpcmd("IPL", NULL, 0, NULL);
566 else if (ipl_info.type == IPL_TYPE_CCW)
567 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
570 static void ipl_run(struct shutdown_trigger *trigger)
572 smp_switch_to_ipl_cpu(__ipl_run, NULL);
575 static int __init ipl_init(void)
579 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
584 switch (ipl_info.type) {
587 rc = sysfs_create_group(&ipl_kset->kobj,
588 &ipl_ccw_attr_group_vm);
590 rc = sysfs_create_group(&ipl_kset->kobj,
591 &ipl_ccw_attr_group_lpar);
594 case IPL_TYPE_FCP_DUMP:
595 rc = ipl_register_fcp_files();
598 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
601 rc = sysfs_create_group(&ipl_kset->kobj,
602 &ipl_unknown_attr_group);
607 panic("ipl_init failed: rc = %i\n", rc);
612 static struct shutdown_action __refdata ipl_action = {
613 .name = SHUTDOWN_ACTION_IPL_STR,
619 * reipl shutdown action: Reboot Linux on shutdown.
622 /* VM IPL PARM attributes */
623 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
626 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
628 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
629 return sprintf(page, "%s\n", vmparm);
632 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
634 const char *buf, size_t len)
638 /* ignore trailing newline */
640 if ((len > 0) && (buf[len - 1] == '\n'))
643 if (ip_len > vmparm_max)
646 /* parm is used to store kernel options, check for common chars */
647 for (i = 0; i < ip_len; i++)
648 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
651 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
652 ipb->ipl_info.ccw.vm_parm_len = ip_len;
654 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
655 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
656 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
658 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
665 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
666 struct kobj_attribute *attr, char *page)
668 return reipl_generic_vmparm_show(reipl_block_nss, page);
671 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
672 struct kobj_attribute *attr,
673 const char *buf, size_t len)
675 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
679 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
680 struct kobj_attribute *attr, char *page)
682 return reipl_generic_vmparm_show(reipl_block_ccw, page);
685 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
686 struct kobj_attribute *attr,
687 const char *buf, size_t len)
689 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
692 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
693 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
694 reipl_nss_vmparm_store);
695 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
696 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
697 reipl_ccw_vmparm_store);
699 /* FCP reipl device attributes */
701 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
702 struct bin_attribute *attr,
703 char *buf, loff_t off, size_t count)
705 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
706 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
708 return memory_read_from_buffer(buf, count, &off, scp_data, size);
711 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
712 struct bin_attribute *attr,
713 char *buf, loff_t off, size_t count)
721 if (off >= DIAG308_SCPDATA_SIZE)
724 if (count > DIAG308_SCPDATA_SIZE - off)
725 count = DIAG308_SCPDATA_SIZE - off;
727 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count);
728 scpdata_len = off + count;
730 if (scpdata_len % 8) {
731 padding = 8 - (scpdata_len % 8);
732 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
734 scpdata_len += padding;
737 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
738 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
739 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
744 static struct bin_attribute sys_reipl_fcp_scp_data_attr = {
747 .mode = S_IRUGO | S_IWUSR,
750 .read = reipl_fcp_scpdata_read,
751 .write = reipl_fcp_scpdata_write,
754 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
755 reipl_block_fcp->ipl_info.fcp.wwpn);
756 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
757 reipl_block_fcp->ipl_info.fcp.lun);
758 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
759 reipl_block_fcp->ipl_info.fcp.bootprog);
760 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
761 reipl_block_fcp->ipl_info.fcp.br_lba);
762 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
763 reipl_block_fcp->ipl_info.fcp.devno);
765 static struct attribute *reipl_fcp_attrs[] = {
766 &sys_reipl_fcp_device_attr.attr,
767 &sys_reipl_fcp_wwpn_attr.attr,
768 &sys_reipl_fcp_lun_attr.attr,
769 &sys_reipl_fcp_bootprog_attr.attr,
770 &sys_reipl_fcp_br_lba_attr.attr,
774 static struct attribute_group reipl_fcp_attr_group = {
775 .attrs = reipl_fcp_attrs,
778 /* CCW reipl device attributes */
780 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
781 reipl_block_ccw->ipl_info.ccw.devno);
783 static void reipl_get_ascii_loadparm(char *loadparm,
784 struct ipl_parameter_block *ibp)
786 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
787 EBCASC(loadparm, LOADPARM_LEN);
788 loadparm[LOADPARM_LEN] = 0;
792 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
795 char buf[LOADPARM_LEN + 1];
797 reipl_get_ascii_loadparm(buf, ipb);
798 return sprintf(page, "%s\n", buf);
801 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
802 const char *buf, size_t len)
806 /* ignore trailing newline */
808 if ((len > 0) && (buf[len - 1] == '\n'))
810 /* loadparm can have max 8 characters and must not start with a blank */
811 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
813 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
814 for (i = 0; i < lp_len; i++) {
815 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
820 /* initialize loadparm with blanks */
821 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
822 /* copy and convert to ebcdic */
823 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
824 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
829 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
830 struct kobj_attribute *attr, char *page)
832 return reipl_generic_loadparm_show(reipl_block_nss, page);
835 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
836 struct kobj_attribute *attr,
837 const char *buf, size_t len)
839 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
843 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
844 struct kobj_attribute *attr, char *page)
846 return reipl_generic_loadparm_show(reipl_block_ccw, page);
849 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
850 struct kobj_attribute *attr,
851 const char *buf, size_t len)
853 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
856 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
857 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
858 reipl_ccw_loadparm_store);
860 static struct attribute *reipl_ccw_attrs_vm[] = {
861 &sys_reipl_ccw_device_attr.attr,
862 &sys_reipl_ccw_loadparm_attr.attr,
863 &sys_reipl_ccw_vmparm_attr.attr,
867 static struct attribute *reipl_ccw_attrs_lpar[] = {
868 &sys_reipl_ccw_device_attr.attr,
869 &sys_reipl_ccw_loadparm_attr.attr,
873 static struct attribute_group reipl_ccw_attr_group_vm = {
875 .attrs = reipl_ccw_attrs_vm,
878 static struct attribute_group reipl_ccw_attr_group_lpar = {
880 .attrs = reipl_ccw_attrs_lpar,
884 /* NSS reipl device attributes */
885 static void reipl_get_ascii_nss_name(char *dst,
886 struct ipl_parameter_block *ipb)
888 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
889 EBCASC(dst, NSS_NAME_SIZE);
890 dst[NSS_NAME_SIZE] = 0;
893 static ssize_t reipl_nss_name_show(struct kobject *kobj,
894 struct kobj_attribute *attr, char *page)
896 char nss_name[NSS_NAME_SIZE + 1] = {};
898 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
899 return sprintf(page, "%s\n", nss_name);
902 static ssize_t reipl_nss_name_store(struct kobject *kobj,
903 struct kobj_attribute *attr,
904 const char *buf, size_t len)
908 /* ignore trailing newline */
910 if ((len > 0) && (buf[len - 1] == '\n'))
913 if (nss_len > NSS_NAME_SIZE)
916 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
918 reipl_block_nss->ipl_info.ccw.vm_flags |=
919 DIAG308_VM_FLAGS_NSS_VALID;
920 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
921 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
922 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
924 reipl_block_nss->ipl_info.ccw.vm_flags &=
925 ~DIAG308_VM_FLAGS_NSS_VALID;
931 static struct kobj_attribute sys_reipl_nss_name_attr =
932 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
933 reipl_nss_name_store);
935 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
936 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
937 reipl_nss_loadparm_store);
939 static struct attribute *reipl_nss_attrs[] = {
940 &sys_reipl_nss_name_attr.attr,
941 &sys_reipl_nss_loadparm_attr.attr,
942 &sys_reipl_nss_vmparm_attr.attr,
946 static struct attribute_group reipl_nss_attr_group = {
948 .attrs = reipl_nss_attrs,
953 static int reipl_set_type(enum ipl_type type)
955 if (!(reipl_capabilities & type))
960 if (diag308_set_works)
961 reipl_method = REIPL_METHOD_CCW_DIAG;
962 else if (MACHINE_IS_VM)
963 reipl_method = REIPL_METHOD_CCW_VM;
965 reipl_method = REIPL_METHOD_CCW_CIO;
966 reipl_block_actual = reipl_block_ccw;
969 if (diag308_set_works)
970 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
971 else if (MACHINE_IS_VM)
972 reipl_method = REIPL_METHOD_FCP_RO_VM;
974 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
975 reipl_block_actual = reipl_block_fcp;
977 case IPL_TYPE_FCP_DUMP:
978 reipl_method = REIPL_METHOD_FCP_DUMP;
981 if (diag308_set_works)
982 reipl_method = REIPL_METHOD_NSS_DIAG;
984 reipl_method = REIPL_METHOD_NSS;
985 reipl_block_actual = reipl_block_nss;
987 case IPL_TYPE_UNKNOWN:
988 reipl_method = REIPL_METHOD_DEFAULT;
997 static ssize_t reipl_type_show(struct kobject *kobj,
998 struct kobj_attribute *attr, char *page)
1000 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1003 static ssize_t reipl_type_store(struct kobject *kobj,
1004 struct kobj_attribute *attr,
1005 const char *buf, size_t len)
1009 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1010 rc = reipl_set_type(IPL_TYPE_CCW);
1011 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1012 rc = reipl_set_type(IPL_TYPE_FCP);
1013 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1014 rc = reipl_set_type(IPL_TYPE_NSS);
1015 return (rc != 0) ? rc : len;
1018 static struct kobj_attribute reipl_type_attr =
1019 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1021 static struct kset *reipl_kset;
1022 static struct kset *reipl_fcp_kset;
1024 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1025 const enum ipl_method m)
1027 char loadparm[LOADPARM_LEN + 1] = {};
1028 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1029 char nss_name[NSS_NAME_SIZE + 1] = {};
1032 reipl_get_ascii_loadparm(loadparm, ipb);
1033 reipl_get_ascii_nss_name(nss_name, ipb);
1034 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
1037 case REIPL_METHOD_CCW_VM:
1038 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1040 case REIPL_METHOD_NSS:
1041 pos = sprintf(dst, "IPL %s", nss_name);
1046 if (strlen(loadparm) > 0)
1047 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1048 if (strlen(vmparm) > 0)
1049 sprintf(dst + pos, " PARM %s", vmparm);
1052 static void __reipl_run(void *unused)
1054 struct ccw_dev_id devid;
1055 static char buf[128];
1057 switch (reipl_method) {
1058 case REIPL_METHOD_CCW_CIO:
1059 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1061 reipl_ccw_dev(&devid);
1063 case REIPL_METHOD_CCW_VM:
1064 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
1065 __cpcmd(buf, NULL, 0, NULL);
1067 case REIPL_METHOD_CCW_DIAG:
1068 diag308(DIAG308_SET, reipl_block_ccw);
1069 diag308(DIAG308_IPL, NULL);
1071 case REIPL_METHOD_FCP_RW_DIAG:
1072 diag308(DIAG308_SET, reipl_block_fcp);
1073 diag308(DIAG308_IPL, NULL);
1075 case REIPL_METHOD_FCP_RO_DIAG:
1076 diag308(DIAG308_IPL, NULL);
1078 case REIPL_METHOD_FCP_RO_VM:
1079 __cpcmd("IPL", NULL, 0, NULL);
1081 case REIPL_METHOD_NSS_DIAG:
1082 diag308(DIAG308_SET, reipl_block_nss);
1083 diag308(DIAG308_IPL, NULL);
1085 case REIPL_METHOD_NSS:
1086 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
1087 __cpcmd(buf, NULL, 0, NULL);
1089 case REIPL_METHOD_DEFAULT:
1091 __cpcmd("IPL", NULL, 0, NULL);
1092 diag308(DIAG308_IPL, NULL);
1094 case REIPL_METHOD_FCP_DUMP:
1097 disabled_wait((unsigned long) __builtin_return_address(0));
1100 static void reipl_run(struct shutdown_trigger *trigger)
1102 smp_switch_to_ipl_cpu(__reipl_run, NULL);
1105 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1107 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1108 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1109 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1110 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1113 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1116 /* check if read scp info worked and set loadparm */
1117 if (sclp_ipl_info.is_valid)
1118 memcpy(ipb->ipl_info.ccw.load_parm,
1119 &sclp_ipl_info.loadparm, LOADPARM_LEN);
1121 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1122 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
1123 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1126 if (MACHINE_IS_VM && diag308_set_works &&
1127 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1129 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1130 ipb->ipl_info.ccw.vm_parm_len =
1131 ipl_block.ipl_info.ccw.vm_parm_len;
1132 memcpy(ipb->ipl_info.ccw.vm_parm,
1133 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1137 static int __init reipl_nss_init(void)
1144 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1145 if (!reipl_block_nss)
1148 if (!diag308_set_works)
1149 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1151 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1155 reipl_block_ccw_init(reipl_block_nss);
1156 if (ipl_info.type == IPL_TYPE_NSS) {
1157 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1158 ' ', NSS_NAME_SIZE);
1159 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1160 kernel_nss_name, strlen(kernel_nss_name));
1161 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1162 reipl_block_nss->ipl_info.ccw.vm_flags |=
1163 DIAG308_VM_FLAGS_NSS_VALID;
1165 reipl_block_ccw_fill_parms(reipl_block_nss);
1168 reipl_capabilities |= IPL_TYPE_NSS;
1172 static int __init reipl_ccw_init(void)
1176 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1177 if (!reipl_block_ccw)
1180 if (MACHINE_IS_VM) {
1181 if (!diag308_set_works)
1182 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1183 rc = sysfs_create_group(&reipl_kset->kobj,
1184 &reipl_ccw_attr_group_vm);
1186 if(!diag308_set_works)
1187 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1188 rc = sysfs_create_group(&reipl_kset->kobj,
1189 &reipl_ccw_attr_group_lpar);
1194 reipl_block_ccw_init(reipl_block_ccw);
1195 if (ipl_info.type == IPL_TYPE_CCW) {
1196 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1197 reipl_block_ccw_fill_parms(reipl_block_ccw);
1200 reipl_capabilities |= IPL_TYPE_CCW;
1204 static int __init reipl_fcp_init(void)
1208 if (!diag308_set_works) {
1209 if (ipl_info.type == IPL_TYPE_FCP) {
1210 make_attrs_ro(reipl_fcp_attrs);
1211 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1216 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1217 if (!reipl_block_fcp)
1220 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1221 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1223 if (!reipl_fcp_kset) {
1224 free_page((unsigned long) reipl_block_fcp);
1228 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1230 kset_unregister(reipl_fcp_kset);
1231 free_page((unsigned long) reipl_block_fcp);
1235 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj,
1236 &sys_reipl_fcp_scp_data_attr);
1238 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1239 kset_unregister(reipl_fcp_kset);
1240 free_page((unsigned long) reipl_block_fcp);
1244 if (ipl_info.type == IPL_TYPE_FCP)
1245 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1247 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1248 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1249 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1250 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1251 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1253 reipl_capabilities |= IPL_TYPE_FCP;
1257 static int __init reipl_init(void)
1261 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1264 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1266 kset_unregister(reipl_kset);
1269 rc = reipl_ccw_init();
1272 rc = reipl_fcp_init();
1275 rc = reipl_nss_init();
1278 rc = reipl_set_type(ipl_info.type);
1284 static struct shutdown_action __refdata reipl_action = {
1285 .name = SHUTDOWN_ACTION_REIPL_STR,
1291 * dump shutdown action: Dump Linux on shutdown.
1294 /* FCP dump device attributes */
1296 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1297 dump_block_fcp->ipl_info.fcp.wwpn);
1298 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1299 dump_block_fcp->ipl_info.fcp.lun);
1300 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1301 dump_block_fcp->ipl_info.fcp.bootprog);
1302 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1303 dump_block_fcp->ipl_info.fcp.br_lba);
1304 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1305 dump_block_fcp->ipl_info.fcp.devno);
1307 static struct attribute *dump_fcp_attrs[] = {
1308 &sys_dump_fcp_device_attr.attr,
1309 &sys_dump_fcp_wwpn_attr.attr,
1310 &sys_dump_fcp_lun_attr.attr,
1311 &sys_dump_fcp_bootprog_attr.attr,
1312 &sys_dump_fcp_br_lba_attr.attr,
1316 static struct attribute_group dump_fcp_attr_group = {
1317 .name = IPL_FCP_STR,
1318 .attrs = dump_fcp_attrs,
1321 /* CCW dump device attributes */
1323 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1324 dump_block_ccw->ipl_info.ccw.devno);
1326 static struct attribute *dump_ccw_attrs[] = {
1327 &sys_dump_ccw_device_attr.attr,
1331 static struct attribute_group dump_ccw_attr_group = {
1332 .name = IPL_CCW_STR,
1333 .attrs = dump_ccw_attrs,
1338 static int dump_set_type(enum dump_type type)
1340 if (!(dump_capabilities & type))
1344 if (diag308_set_works)
1345 dump_method = DUMP_METHOD_CCW_DIAG;
1346 else if (MACHINE_IS_VM)
1347 dump_method = DUMP_METHOD_CCW_VM;
1349 dump_method = DUMP_METHOD_CCW_CIO;
1352 dump_method = DUMP_METHOD_FCP_DIAG;
1355 dump_method = DUMP_METHOD_NONE;
1361 static ssize_t dump_type_show(struct kobject *kobj,
1362 struct kobj_attribute *attr, char *page)
1364 return sprintf(page, "%s\n", dump_type_str(dump_type));
1367 static ssize_t dump_type_store(struct kobject *kobj,
1368 struct kobj_attribute *attr,
1369 const char *buf, size_t len)
1373 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1374 rc = dump_set_type(DUMP_TYPE_NONE);
1375 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1376 rc = dump_set_type(DUMP_TYPE_CCW);
1377 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1378 rc = dump_set_type(DUMP_TYPE_FCP);
1379 return (rc != 0) ? rc : len;
1382 static struct kobj_attribute dump_type_attr =
1383 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1385 static struct kset *dump_kset;
1387 static void __dump_run(void *unused)
1389 struct ccw_dev_id devid;
1390 static char buf[100];
1392 switch (dump_method) {
1393 case DUMP_METHOD_CCW_CIO:
1394 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1396 reipl_ccw_dev(&devid);
1398 case DUMP_METHOD_CCW_VM:
1399 sprintf(buf, "STORE STATUS");
1400 __cpcmd(buf, NULL, 0, NULL);
1401 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1402 __cpcmd(buf, NULL, 0, NULL);
1404 case DUMP_METHOD_CCW_DIAG:
1405 diag308(DIAG308_SET, dump_block_ccw);
1406 diag308(DIAG308_DUMP, NULL);
1408 case DUMP_METHOD_FCP_DIAG:
1409 diag308(DIAG308_SET, dump_block_fcp);
1410 diag308(DIAG308_DUMP, NULL);
1417 static void dump_run(struct shutdown_trigger *trigger)
1419 if (dump_method == DUMP_METHOD_NONE)
1422 smp_switch_to_ipl_cpu(__dump_run, NULL);
1425 static int __init dump_ccw_init(void)
1429 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1430 if (!dump_block_ccw)
1432 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1434 free_page((unsigned long)dump_block_ccw);
1437 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1438 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1439 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1440 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1441 dump_capabilities |= DUMP_TYPE_CCW;
1445 static int __init dump_fcp_init(void)
1449 if (!sclp_ipl_info.has_dump)
1450 return 0; /* LDIPL DUMP is not installed */
1451 if (!diag308_set_works)
1453 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1454 if (!dump_block_fcp)
1456 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1458 free_page((unsigned long)dump_block_fcp);
1461 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1462 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1463 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1464 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1465 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1466 dump_capabilities |= DUMP_TYPE_FCP;
1470 static int __init dump_init(void)
1474 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1477 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1479 kset_unregister(dump_kset);
1482 rc = dump_ccw_init();
1485 rc = dump_fcp_init();
1488 dump_set_type(DUMP_TYPE_NONE);
1492 static struct shutdown_action __refdata dump_action = {
1493 .name = SHUTDOWN_ACTION_DUMP_STR,
1498 static void dump_reipl_run(struct shutdown_trigger *trigger)
1502 * Bypass dynamic address translation (DAT) when storing IPL parameter
1503 * information block address and checksum into the prefix area
1504 * (corresponding to absolute addresses 0-8191).
1505 * When enhanced DAT applies and the STE format control in one,
1506 * the absolute address is formed without prefixing. In this case a
1507 * normal store (stg/st) into the prefix area would no more match to
1508 * absolute addresses 0-8191.
1511 asm volatile("sturg %0,%1"
1512 :: "a" ((unsigned long) reipl_block_actual),
1513 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1515 asm volatile("stura %0,%1"
1516 :: "a" ((unsigned long) reipl_block_actual),
1517 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1519 asm volatile("stura %0,%1"
1520 :: "a" (csum_partial(reipl_block_actual,
1521 reipl_block_actual->hdr.len, 0)),
1522 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1527 static int __init dump_reipl_init(void)
1529 if (!diag308_set_works)
1535 static struct shutdown_action __refdata dump_reipl_action = {
1536 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1537 .fn = dump_reipl_run,
1538 .init = dump_reipl_init,
1542 * vmcmd shutdown action: Trigger vm command on shutdown.
1545 static char vmcmd_on_reboot[128];
1546 static char vmcmd_on_panic[128];
1547 static char vmcmd_on_halt[128];
1548 static char vmcmd_on_poff[128];
1549 static char vmcmd_on_restart[128];
1551 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1552 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1553 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1554 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1555 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1557 static struct attribute *vmcmd_attrs[] = {
1558 &sys_vmcmd_on_reboot_attr.attr,
1559 &sys_vmcmd_on_panic_attr.attr,
1560 &sys_vmcmd_on_halt_attr.attr,
1561 &sys_vmcmd_on_poff_attr.attr,
1562 &sys_vmcmd_on_restart_attr.attr,
1566 static struct attribute_group vmcmd_attr_group = {
1567 .attrs = vmcmd_attrs,
1570 static struct kset *vmcmd_kset;
1572 static void vmcmd_run(struct shutdown_trigger *trigger)
1574 char *cmd, *next_cmd;
1576 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1577 cmd = vmcmd_on_reboot;
1578 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1579 cmd = vmcmd_on_panic;
1580 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1581 cmd = vmcmd_on_halt;
1582 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1583 cmd = vmcmd_on_poff;
1584 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1585 cmd = vmcmd_on_restart;
1589 if (strlen(cmd) == 0)
1592 next_cmd = strchr(cmd, '\n');
1597 __cpcmd(cmd, NULL, 0, NULL);
1599 } while (cmd != NULL);
1602 static int vmcmd_init(void)
1606 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1609 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1612 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1613 vmcmd_run, vmcmd_init};
1616 * stop shutdown action: Stop Linux on shutdown.
1619 static void stop_run(struct shutdown_trigger *trigger)
1621 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1622 strcmp(trigger->name, ON_RESTART_STR) == 0)
1623 disabled_wait((unsigned long) __builtin_return_address(0));
1624 while (sigp(smp_processor_id(), sigp_stop) == sigp_busy)
1629 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1634 static struct shutdown_action *shutdown_actions_list[] = {
1635 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1636 &vmcmd_action, &stop_action};
1637 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1643 static struct kset *shutdown_actions_kset;
1645 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1650 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1651 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1652 if (shutdown_actions_list[i]->init_rc) {
1653 return shutdown_actions_list[i]->init_rc;
1655 trigger->action = shutdown_actions_list[i];
1665 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1668 static ssize_t on_reboot_show(struct kobject *kobj,
1669 struct kobj_attribute *attr, char *page)
1671 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1674 static ssize_t on_reboot_store(struct kobject *kobj,
1675 struct kobj_attribute *attr,
1676 const char *buf, size_t len)
1678 return set_trigger(buf, &on_reboot_trigger, len);
1681 static struct kobj_attribute on_reboot_attr =
1682 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1684 static void do_machine_restart(char *__unused)
1687 on_reboot_trigger.action->fn(&on_reboot_trigger);
1690 void (*_machine_restart)(char *command) = do_machine_restart;
1694 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1696 static ssize_t on_panic_show(struct kobject *kobj,
1697 struct kobj_attribute *attr, char *page)
1699 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1702 static ssize_t on_panic_store(struct kobject *kobj,
1703 struct kobj_attribute *attr,
1704 const char *buf, size_t len)
1706 return set_trigger(buf, &on_panic_trigger, len);
1709 static struct kobj_attribute on_panic_attr =
1710 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1712 static void do_panic(void)
1714 on_panic_trigger.action->fn(&on_panic_trigger);
1715 stop_run(&on_panic_trigger);
1720 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
1723 static ssize_t on_restart_show(struct kobject *kobj,
1724 struct kobj_attribute *attr, char *page)
1726 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1729 static ssize_t on_restart_store(struct kobject *kobj,
1730 struct kobj_attribute *attr,
1731 const char *buf, size_t len)
1733 return set_trigger(buf, &on_restart_trigger, len);
1736 static struct kobj_attribute on_restart_attr =
1737 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1739 void do_restart(void)
1741 smp_restart_with_online_cpu();
1743 on_restart_trigger.action->fn(&on_restart_trigger);
1744 stop_run(&on_restart_trigger);
1749 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1751 static ssize_t on_halt_show(struct kobject *kobj,
1752 struct kobj_attribute *attr, char *page)
1754 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1757 static ssize_t on_halt_store(struct kobject *kobj,
1758 struct kobj_attribute *attr,
1759 const char *buf, size_t len)
1761 return set_trigger(buf, &on_halt_trigger, len);
1764 static struct kobj_attribute on_halt_attr =
1765 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1768 static void do_machine_halt(void)
1771 on_halt_trigger.action->fn(&on_halt_trigger);
1772 stop_run(&on_halt_trigger);
1774 void (*_machine_halt)(void) = do_machine_halt;
1778 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1780 static ssize_t on_poff_show(struct kobject *kobj,
1781 struct kobj_attribute *attr, char *page)
1783 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1786 static ssize_t on_poff_store(struct kobject *kobj,
1787 struct kobj_attribute *attr,
1788 const char *buf, size_t len)
1790 return set_trigger(buf, &on_poff_trigger, len);
1793 static struct kobj_attribute on_poff_attr =
1794 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1797 static void do_machine_power_off(void)
1800 on_poff_trigger.action->fn(&on_poff_trigger);
1801 stop_run(&on_poff_trigger);
1803 void (*_machine_power_off)(void) = do_machine_power_off;
1805 static void __init shutdown_triggers_init(void)
1807 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1809 if (!shutdown_actions_kset)
1811 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1812 &on_reboot_attr.attr))
1814 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1815 &on_panic_attr.attr))
1817 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1818 &on_halt_attr.attr))
1820 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1821 &on_poff_attr.attr))
1823 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1824 &on_restart_attr.attr))
1828 panic("shutdown_triggers_init failed\n");
1831 static void __init shutdown_actions_init(void)
1835 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1836 if (!shutdown_actions_list[i]->init)
1838 shutdown_actions_list[i]->init_rc =
1839 shutdown_actions_list[i]->init();
1843 static int __init s390_ipl_init(void)
1845 sclp_get_ipl_info(&sclp_ipl_info);
1846 shutdown_actions_init();
1847 shutdown_triggers_init();
1851 __initcall(s390_ipl_init);
1853 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1858 for (sx = 0; src[sx] != 0; sx++) {
1861 dst[dx++] = src[sx];
1867 static int __init vmcmd_on_reboot_setup(char *str)
1871 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1872 vmcmd_on_reboot[127] = 0;
1873 on_reboot_trigger.action = &vmcmd_action;
1876 __setup("vmreboot=", vmcmd_on_reboot_setup);
1878 static int __init vmcmd_on_panic_setup(char *str)
1882 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1883 vmcmd_on_panic[127] = 0;
1884 on_panic_trigger.action = &vmcmd_action;
1887 __setup("vmpanic=", vmcmd_on_panic_setup);
1889 static int __init vmcmd_on_halt_setup(char *str)
1893 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1894 vmcmd_on_halt[127] = 0;
1895 on_halt_trigger.action = &vmcmd_action;
1898 __setup("vmhalt=", vmcmd_on_halt_setup);
1900 static int __init vmcmd_on_poff_setup(char *str)
1904 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1905 vmcmd_on_poff[127] = 0;
1906 on_poff_trigger.action = &vmcmd_action;
1909 __setup("vmpoff=", vmcmd_on_poff_setup);
1911 static int on_panic_notify(struct notifier_block *self,
1912 unsigned long event, void *data)
1918 static struct notifier_block on_panic_nb = {
1919 .notifier_call = on_panic_notify,
1920 .priority = INT_MIN,
1923 void __init setup_ipl(void)
1925 ipl_info.type = get_ipl_type();
1926 switch (ipl_info.type) {
1928 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1929 ipl_info.data.ccw.dev_id.ssid = 0;
1932 case IPL_TYPE_FCP_DUMP:
1933 ipl_info.data.fcp.dev_id.devno =
1934 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1935 ipl_info.data.fcp.dev_id.ssid = 0;
1936 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1937 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1940 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1941 sizeof(ipl_info.data.nss.name));
1943 case IPL_TYPE_UNKNOWN:
1944 /* We have no info to copy */
1947 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1950 void __init ipl_update_parameters(void)
1954 rc = diag308(DIAG308_STORE, &ipl_block);
1955 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1956 diag308_set_works = 1;
1959 void __init ipl_save_parameters(void)
1961 struct cio_iplinfo iplinfo;
1964 if (cio_get_iplinfo(&iplinfo))
1967 ipl_devno = iplinfo.devno;
1968 ipl_flags |= IPL_DEVNO_VALID;
1969 if (!iplinfo.is_qdio)
1971 ipl_flags |= IPL_PARMBLOCK_VALID;
1972 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
1973 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1974 memmove(dst, src, PAGE_SIZE);
1975 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
1978 static LIST_HEAD(rcall);
1979 static DEFINE_MUTEX(rcall_mutex);
1981 void register_reset_call(struct reset_call *reset)
1983 mutex_lock(&rcall_mutex);
1984 list_add(&reset->list, &rcall);
1985 mutex_unlock(&rcall_mutex);
1987 EXPORT_SYMBOL_GPL(register_reset_call);
1989 void unregister_reset_call(struct reset_call *reset)
1991 mutex_lock(&rcall_mutex);
1992 list_del(&reset->list);
1993 mutex_unlock(&rcall_mutex);
1995 EXPORT_SYMBOL_GPL(unregister_reset_call);
1997 static void do_reset_calls(void)
1999 struct reset_call *reset;
2002 if (diag308_set_works) {
2007 list_for_each_entry(reset, &rcall, list)
2011 u32 dump_prefix_page;
2013 void s390_reset_system(void)
2015 struct _lowcore *lc;
2017 lc = (struct _lowcore *)(unsigned long) store_prefix();
2019 /* Stack for interrupt/machine check handler */
2020 lc->panic_stack = S390_lowcore.panic_stack;
2022 /* Save prefix page address for dump case */
2023 dump_prefix_page = (u32)(unsigned long) lc;
2025 /* Disable prefixing */
2028 /* Disable lowcore protection */
2029 __ctl_clear_bit(0,28);
2031 /* Set new machine check handler */
2032 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
2033 S390_lowcore.mcck_new_psw.addr =
2034 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
2036 /* Set new program check handler */
2037 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
2038 S390_lowcore.program_new_psw.addr =
2039 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;