2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
20 #include <asm/setup.h>
21 #include <asm/cpcmd.h>
23 #include <asm/ebcdic.h>
24 #include <asm/reset.h>
27 #include <asm/checksum.h>
29 #define IPL_PARM_BLOCK_VERSION 0
31 #define IPL_UNKNOWN_STR "unknown"
32 #define IPL_CCW_STR "ccw"
33 #define IPL_FCP_STR "fcp"
34 #define IPL_FCP_DUMP_STR "fcp_dump"
35 #define IPL_NSS_STR "nss"
37 #define DUMP_CCW_STR "ccw"
38 #define DUMP_FCP_STR "fcp"
39 #define DUMP_NONE_STR "none"
42 * Four shutdown trigger types are supported:
48 #define ON_PANIC_STR "on_panic"
49 #define ON_HALT_STR "on_halt"
50 #define ON_POFF_STR "on_poff"
51 #define ON_REIPL_STR "on_reboot"
53 struct shutdown_action;
54 struct shutdown_trigger {
56 struct shutdown_action *action;
60 * The following shutdown action types are supported:
62 #define SHUTDOWN_ACTION_IPL_STR "ipl"
63 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
64 #define SHUTDOWN_ACTION_DUMP_STR "dump"
65 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
66 #define SHUTDOWN_ACTION_STOP_STR "stop"
67 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
69 struct shutdown_action {
71 void (*fn) (struct shutdown_trigger *trigger);
75 static char *ipl_type_str(enum ipl_type type)
82 case IPL_TYPE_FCP_DUMP:
83 return IPL_FCP_DUMP_STR;
86 case IPL_TYPE_UNKNOWN:
88 return IPL_UNKNOWN_STR;
98 static char *dump_type_str(enum dump_type type)
102 return DUMP_NONE_STR;
113 * Must be in data section since the bss section
114 * is not cleared when these are accessed.
116 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
117 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
120 REIPL_METHOD_CCW_CIO,
121 REIPL_METHOD_CCW_DIAG,
123 REIPL_METHOD_FCP_RO_DIAG,
124 REIPL_METHOD_FCP_RW_DIAG,
125 REIPL_METHOD_FCP_RO_VM,
126 REIPL_METHOD_FCP_DUMP,
128 REIPL_METHOD_NSS_DIAG,
129 REIPL_METHOD_DEFAULT,
135 DUMP_METHOD_CCW_DIAG,
137 DUMP_METHOD_FCP_DIAG,
140 static int diag308_set_works = 0;
142 static struct ipl_parameter_block ipl_block;
144 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
146 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
147 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
148 static struct ipl_parameter_block *reipl_block_fcp;
149 static struct ipl_parameter_block *reipl_block_ccw;
150 static struct ipl_parameter_block *reipl_block_nss;
151 static struct ipl_parameter_block *reipl_block_actual;
153 static int dump_capabilities = DUMP_TYPE_NONE;
154 static enum dump_type dump_type = DUMP_TYPE_NONE;
155 static enum dump_method dump_method = DUMP_METHOD_NONE;
156 static struct ipl_parameter_block *dump_block_fcp;
157 static struct ipl_parameter_block *dump_block_ccw;
159 static struct sclp_ipl_info sclp_ipl_info;
161 int diag308(unsigned long subcode, void *addr)
163 register unsigned long _addr asm("0") = (unsigned long) addr;
164 register unsigned long _rc asm("1") = 0;
167 " diag %0,%2,0x308\n"
170 : "+d" (_addr), "+d" (_rc)
171 : "d" (subcode) : "cc", "memory");
174 EXPORT_SYMBOL_GPL(diag308);
178 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
179 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
180 struct kobj_attribute *attr, \
183 return sprintf(page, _format, _value); \
185 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
186 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
188 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
189 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
190 struct kobj_attribute *attr, \
193 return sprintf(page, _fmt_out, \
194 (unsigned long long) _value); \
196 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
197 struct kobj_attribute *attr, \
198 const char *buf, size_t len) \
200 unsigned long long value; \
201 if (sscanf(buf, _fmt_in, &value) != 1) \
206 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
207 __ATTR(_name,(S_IRUGO | S_IWUSR), \
208 sys_##_prefix##_##_name##_show, \
209 sys_##_prefix##_##_name##_store);
211 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
212 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
213 struct kobj_attribute *attr, \
216 return sprintf(page, _fmt_out, _value); \
218 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
219 struct kobj_attribute *attr, \
220 const char *buf, size_t len) \
222 strncpy(_value, buf, sizeof(_value) - 1); \
226 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
227 __ATTR(_name,(S_IRUGO | S_IWUSR), \
228 sys_##_prefix##_##_name##_show, \
229 sys_##_prefix##_##_name##_store);
231 static void make_attrs_ro(struct attribute **attrs)
234 (*attrs)->mode = S_IRUGO;
243 static __init enum ipl_type get_ipl_type(void)
245 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
247 if (ipl_flags & IPL_NSS_VALID)
249 if (!(ipl_flags & IPL_DEVNO_VALID))
250 return IPL_TYPE_UNKNOWN;
251 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
253 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
254 return IPL_TYPE_UNKNOWN;
255 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
256 return IPL_TYPE_UNKNOWN;
257 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
258 return IPL_TYPE_FCP_DUMP;
262 struct ipl_info ipl_info;
263 EXPORT_SYMBOL_GPL(ipl_info);
265 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
268 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
271 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
273 /* VM IPL PARM routines */
274 static void reipl_get_ascii_vmparm(char *dest,
275 const struct ipl_parameter_block *ipb)
279 char has_lowercase = 0;
281 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
282 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
284 len = ipb->ipl_info.ccw.vm_parm_len;
285 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
286 /* If at least one character is lowercase, we assume mixed
287 * case; otherwise we convert everything to lowercase.
289 for (i = 0; i < len; i++)
290 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
291 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
292 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
297 EBC_TOLOWER(dest, len);
303 void get_ipl_vmparm(char *dest)
305 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
306 reipl_get_ascii_vmparm(dest, &ipl_block);
311 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
312 struct kobj_attribute *attr, char *page)
314 char parm[DIAG308_VMPARM_SIZE + 1] = {};
316 get_ipl_vmparm(parm);
317 return sprintf(page, "%s\n", parm);
320 static struct kobj_attribute sys_ipl_vm_parm_attr =
321 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
323 static ssize_t sys_ipl_device_show(struct kobject *kobj,
324 struct kobj_attribute *attr, char *page)
326 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
328 switch (ipl_info.type) {
330 return sprintf(page, "0.0.%04x\n", ipl_devno);
332 case IPL_TYPE_FCP_DUMP:
333 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
339 static struct kobj_attribute sys_ipl_device_attr =
340 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
342 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
343 char *buf, loff_t off, size_t count)
345 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
349 static struct bin_attribute ipl_parameter_attr = {
351 .name = "binary_parameter",
355 .read = &ipl_parameter_read,
358 static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
359 char *buf, loff_t off, size_t count)
361 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
362 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
364 return memory_read_from_buffer(buf, count, &off, scp_data, size);
367 static struct bin_attribute ipl_scp_data_attr = {
373 .read = ipl_scp_data_read,
376 /* FCP ipl device attributes */
378 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
379 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
380 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
381 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
382 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
383 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
384 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
385 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
387 static struct attribute *ipl_fcp_attrs[] = {
388 &sys_ipl_type_attr.attr,
389 &sys_ipl_device_attr.attr,
390 &sys_ipl_fcp_wwpn_attr.attr,
391 &sys_ipl_fcp_lun_attr.attr,
392 &sys_ipl_fcp_bootprog_attr.attr,
393 &sys_ipl_fcp_br_lba_attr.attr,
397 static struct attribute_group ipl_fcp_attr_group = {
398 .attrs = ipl_fcp_attrs,
401 /* CCW ipl device attributes */
403 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
404 struct kobj_attribute *attr, char *page)
406 char loadparm[LOADPARM_LEN + 1] = {};
408 if (!sclp_ipl_info.is_valid)
409 return sprintf(page, "#unknown#\n");
410 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
411 EBCASC(loadparm, LOADPARM_LEN);
413 return sprintf(page, "%s\n", loadparm);
416 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
417 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
419 static struct attribute *ipl_ccw_attrs_vm[] = {
420 &sys_ipl_type_attr.attr,
421 &sys_ipl_device_attr.attr,
422 &sys_ipl_ccw_loadparm_attr.attr,
423 &sys_ipl_vm_parm_attr.attr,
427 static struct attribute *ipl_ccw_attrs_lpar[] = {
428 &sys_ipl_type_attr.attr,
429 &sys_ipl_device_attr.attr,
430 &sys_ipl_ccw_loadparm_attr.attr,
434 static struct attribute_group ipl_ccw_attr_group_vm = {
435 .attrs = ipl_ccw_attrs_vm,
438 static struct attribute_group ipl_ccw_attr_group_lpar = {
439 .attrs = ipl_ccw_attrs_lpar
442 /* NSS ipl device attributes */
444 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
446 static struct attribute *ipl_nss_attrs[] = {
447 &sys_ipl_type_attr.attr,
448 &sys_ipl_nss_name_attr.attr,
449 &sys_ipl_ccw_loadparm_attr.attr,
450 &sys_ipl_vm_parm_attr.attr,
454 static struct attribute_group ipl_nss_attr_group = {
455 .attrs = ipl_nss_attrs,
458 /* UNKNOWN ipl device attributes */
460 static struct attribute *ipl_unknown_attrs[] = {
461 &sys_ipl_type_attr.attr,
465 static struct attribute_group ipl_unknown_attr_group = {
466 .attrs = ipl_unknown_attrs,
469 static struct kset *ipl_kset;
471 static int __init ipl_register_fcp_files(void)
475 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
478 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
481 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
485 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
488 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
493 static void ipl_run(struct shutdown_trigger *trigger)
495 diag308(DIAG308_IPL, NULL);
497 __cpcmd("IPL", NULL, 0, NULL);
498 else if (ipl_info.type == IPL_TYPE_CCW)
499 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
502 static int __init ipl_init(void)
506 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
511 switch (ipl_info.type) {
514 rc = sysfs_create_group(&ipl_kset->kobj,
515 &ipl_ccw_attr_group_vm);
517 rc = sysfs_create_group(&ipl_kset->kobj,
518 &ipl_ccw_attr_group_lpar);
521 case IPL_TYPE_FCP_DUMP:
522 rc = ipl_register_fcp_files();
525 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
528 rc = sysfs_create_group(&ipl_kset->kobj,
529 &ipl_unknown_attr_group);
534 panic("ipl_init failed: rc = %i\n", rc);
539 static struct shutdown_action __refdata ipl_action = {
540 .name = SHUTDOWN_ACTION_IPL_STR,
546 * reipl shutdown action: Reboot Linux on shutdown.
549 /* VM IPL PARM attributes */
550 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
553 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
555 reipl_get_ascii_vmparm(vmparm, ipb);
556 return sprintf(page, "%s\n", vmparm);
559 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
561 const char *buf, size_t len)
565 /* ignore trailing newline */
567 if ((len > 0) && (buf[len - 1] == '\n'))
570 if (ip_len > vmparm_max)
573 /* parm is used to store kernel options, check for common chars */
574 for (i = 0; i < ip_len; i++)
575 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
578 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
579 ipb->ipl_info.ccw.vm_parm_len = ip_len;
581 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
582 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
583 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
585 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
592 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
593 struct kobj_attribute *attr, char *page)
595 return reipl_generic_vmparm_show(reipl_block_nss, page);
598 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
599 struct kobj_attribute *attr,
600 const char *buf, size_t len)
602 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
606 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
607 struct kobj_attribute *attr, char *page)
609 return reipl_generic_vmparm_show(reipl_block_ccw, page);
612 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
613 struct kobj_attribute *attr,
614 const char *buf, size_t len)
616 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
619 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
620 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
621 reipl_nss_vmparm_store);
622 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
623 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
624 reipl_ccw_vmparm_store);
626 /* FCP reipl device attributes */
628 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
629 reipl_block_fcp->ipl_info.fcp.wwpn);
630 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
631 reipl_block_fcp->ipl_info.fcp.lun);
632 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
633 reipl_block_fcp->ipl_info.fcp.bootprog);
634 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
635 reipl_block_fcp->ipl_info.fcp.br_lba);
636 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
637 reipl_block_fcp->ipl_info.fcp.devno);
639 static struct attribute *reipl_fcp_attrs[] = {
640 &sys_reipl_fcp_device_attr.attr,
641 &sys_reipl_fcp_wwpn_attr.attr,
642 &sys_reipl_fcp_lun_attr.attr,
643 &sys_reipl_fcp_bootprog_attr.attr,
644 &sys_reipl_fcp_br_lba_attr.attr,
648 static struct attribute_group reipl_fcp_attr_group = {
650 .attrs = reipl_fcp_attrs,
653 /* CCW reipl device attributes */
655 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
656 reipl_block_ccw->ipl_info.ccw.devno);
658 static void reipl_get_ascii_loadparm(char *loadparm,
659 struct ipl_parameter_block *ibp)
661 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
662 EBCASC(loadparm, LOADPARM_LEN);
663 loadparm[LOADPARM_LEN] = 0;
667 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
670 char buf[LOADPARM_LEN + 1];
672 reipl_get_ascii_loadparm(buf, ipb);
673 return sprintf(page, "%s\n", buf);
676 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
677 const char *buf, size_t len)
681 /* ignore trailing newline */
683 if ((len > 0) && (buf[len - 1] == '\n'))
685 /* loadparm can have max 8 characters and must not start with a blank */
686 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
688 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
689 for (i = 0; i < lp_len; i++) {
690 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
695 /* initialize loadparm with blanks */
696 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
697 /* copy and convert to ebcdic */
698 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
699 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
704 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
705 struct kobj_attribute *attr, char *page)
707 return reipl_generic_loadparm_show(reipl_block_nss, page);
710 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
711 struct kobj_attribute *attr,
712 const char *buf, size_t len)
714 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
718 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
719 struct kobj_attribute *attr, char *page)
721 return reipl_generic_loadparm_show(reipl_block_ccw, page);
724 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
725 struct kobj_attribute *attr,
726 const char *buf, size_t len)
728 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
731 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
732 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
733 reipl_ccw_loadparm_store);
735 static struct attribute *reipl_ccw_attrs_vm[] = {
736 &sys_reipl_ccw_device_attr.attr,
737 &sys_reipl_ccw_loadparm_attr.attr,
738 &sys_reipl_ccw_vmparm_attr.attr,
742 static struct attribute *reipl_ccw_attrs_lpar[] = {
743 &sys_reipl_ccw_device_attr.attr,
744 &sys_reipl_ccw_loadparm_attr.attr,
748 static struct attribute_group reipl_ccw_attr_group_vm = {
750 .attrs = reipl_ccw_attrs_vm,
753 static struct attribute_group reipl_ccw_attr_group_lpar = {
755 .attrs = reipl_ccw_attrs_lpar,
759 /* NSS reipl device attributes */
760 static void reipl_get_ascii_nss_name(char *dst,
761 struct ipl_parameter_block *ipb)
763 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
764 EBCASC(dst, NSS_NAME_SIZE);
765 dst[NSS_NAME_SIZE] = 0;
768 static ssize_t reipl_nss_name_show(struct kobject *kobj,
769 struct kobj_attribute *attr, char *page)
771 char nss_name[NSS_NAME_SIZE + 1] = {};
773 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
774 return sprintf(page, "%s\n", nss_name);
777 static ssize_t reipl_nss_name_store(struct kobject *kobj,
778 struct kobj_attribute *attr,
779 const char *buf, size_t len)
783 /* ignore trailing newline */
785 if ((len > 0) && (buf[len - 1] == '\n'))
788 if (nss_len > NSS_NAME_SIZE)
791 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
793 reipl_block_nss->ipl_info.ccw.vm_flags |=
794 DIAG308_VM_FLAGS_NSS_VALID;
795 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
796 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
797 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
799 reipl_block_nss->ipl_info.ccw.vm_flags &=
800 ~DIAG308_VM_FLAGS_NSS_VALID;
806 static struct kobj_attribute sys_reipl_nss_name_attr =
807 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
808 reipl_nss_name_store);
810 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
811 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
812 reipl_nss_loadparm_store);
814 static struct attribute *reipl_nss_attrs[] = {
815 &sys_reipl_nss_name_attr.attr,
816 &sys_reipl_nss_loadparm_attr.attr,
817 &sys_reipl_nss_vmparm_attr.attr,
821 static struct attribute_group reipl_nss_attr_group = {
823 .attrs = reipl_nss_attrs,
828 static int reipl_set_type(enum ipl_type type)
830 if (!(reipl_capabilities & type))
835 if (diag308_set_works)
836 reipl_method = REIPL_METHOD_CCW_DIAG;
837 else if (MACHINE_IS_VM)
838 reipl_method = REIPL_METHOD_CCW_VM;
840 reipl_method = REIPL_METHOD_CCW_CIO;
841 reipl_block_actual = reipl_block_ccw;
844 if (diag308_set_works)
845 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
846 else if (MACHINE_IS_VM)
847 reipl_method = REIPL_METHOD_FCP_RO_VM;
849 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
850 reipl_block_actual = reipl_block_fcp;
852 case IPL_TYPE_FCP_DUMP:
853 reipl_method = REIPL_METHOD_FCP_DUMP;
856 if (diag308_set_works)
857 reipl_method = REIPL_METHOD_NSS_DIAG;
859 reipl_method = REIPL_METHOD_NSS;
860 reipl_block_actual = reipl_block_nss;
862 case IPL_TYPE_UNKNOWN:
863 reipl_method = REIPL_METHOD_DEFAULT;
872 static ssize_t reipl_type_show(struct kobject *kobj,
873 struct kobj_attribute *attr, char *page)
875 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
878 static ssize_t reipl_type_store(struct kobject *kobj,
879 struct kobj_attribute *attr,
880 const char *buf, size_t len)
884 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
885 rc = reipl_set_type(IPL_TYPE_CCW);
886 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
887 rc = reipl_set_type(IPL_TYPE_FCP);
888 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
889 rc = reipl_set_type(IPL_TYPE_NSS);
890 return (rc != 0) ? rc : len;
893 static struct kobj_attribute reipl_type_attr =
894 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
896 static struct kset *reipl_kset;
898 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
899 const enum ipl_method m)
901 char loadparm[LOADPARM_LEN + 1] = {};
902 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
903 char nss_name[NSS_NAME_SIZE + 1] = {};
906 reipl_get_ascii_loadparm(loadparm, ipb);
907 reipl_get_ascii_nss_name(nss_name, ipb);
908 reipl_get_ascii_vmparm(vmparm, ipb);
911 case REIPL_METHOD_CCW_VM:
912 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
914 case REIPL_METHOD_NSS:
915 pos = sprintf(dst, "IPL %s", nss_name);
920 if (strlen(loadparm) > 0)
921 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
922 if (strlen(vmparm) > 0)
923 sprintf(dst + pos, " PARM %s", vmparm);
926 static void reipl_run(struct shutdown_trigger *trigger)
928 struct ccw_dev_id devid;
929 static char buf[128];
931 switch (reipl_method) {
932 case REIPL_METHOD_CCW_CIO:
933 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
935 reipl_ccw_dev(&devid);
937 case REIPL_METHOD_CCW_VM:
938 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
939 __cpcmd(buf, NULL, 0, NULL);
941 case REIPL_METHOD_CCW_DIAG:
942 diag308(DIAG308_SET, reipl_block_ccw);
943 diag308(DIAG308_IPL, NULL);
945 case REIPL_METHOD_FCP_RW_DIAG:
946 diag308(DIAG308_SET, reipl_block_fcp);
947 diag308(DIAG308_IPL, NULL);
949 case REIPL_METHOD_FCP_RO_DIAG:
950 diag308(DIAG308_IPL, NULL);
952 case REIPL_METHOD_FCP_RO_VM:
953 __cpcmd("IPL", NULL, 0, NULL);
955 case REIPL_METHOD_NSS_DIAG:
956 diag308(DIAG308_SET, reipl_block_nss);
957 diag308(DIAG308_IPL, NULL);
959 case REIPL_METHOD_NSS:
960 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
961 __cpcmd(buf, NULL, 0, NULL);
963 case REIPL_METHOD_DEFAULT:
965 __cpcmd("IPL", NULL, 0, NULL);
966 diag308(DIAG308_IPL, NULL);
968 case REIPL_METHOD_FCP_DUMP:
971 disabled_wait((unsigned long) __builtin_return_address(0));
974 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
976 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
977 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
978 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
979 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
982 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
985 /* check if read scp info worked and set loadparm */
986 if (sclp_ipl_info.is_valid)
987 memcpy(ipb->ipl_info.ccw.load_parm,
988 &sclp_ipl_info.loadparm, LOADPARM_LEN);
990 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
991 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
992 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
995 if (MACHINE_IS_VM && diag308_set_works &&
996 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
998 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
999 ipb->ipl_info.ccw.vm_parm_len =
1000 ipl_block.ipl_info.ccw.vm_parm_len;
1001 memcpy(ipb->ipl_info.ccw.vm_parm,
1002 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1006 static int __init reipl_nss_init(void)
1013 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1014 if (!reipl_block_nss)
1017 if (!diag308_set_works)
1018 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1020 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1024 reipl_block_ccw_init(reipl_block_nss);
1025 if (ipl_info.type == IPL_TYPE_NSS) {
1026 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1027 ' ', NSS_NAME_SIZE);
1028 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1029 kernel_nss_name, strlen(kernel_nss_name));
1030 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1031 reipl_block_nss->ipl_info.ccw.vm_flags |=
1032 DIAG308_VM_FLAGS_NSS_VALID;
1034 reipl_block_ccw_fill_parms(reipl_block_nss);
1037 reipl_capabilities |= IPL_TYPE_NSS;
1041 static int __init reipl_ccw_init(void)
1045 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1046 if (!reipl_block_ccw)
1049 if (MACHINE_IS_VM) {
1050 if (!diag308_set_works)
1051 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1052 rc = sysfs_create_group(&reipl_kset->kobj,
1053 &reipl_ccw_attr_group_vm);
1055 if(!diag308_set_works)
1056 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1057 rc = sysfs_create_group(&reipl_kset->kobj,
1058 &reipl_ccw_attr_group_lpar);
1063 reipl_block_ccw_init(reipl_block_ccw);
1064 if (ipl_info.type == IPL_TYPE_CCW) {
1065 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1066 reipl_block_ccw_fill_parms(reipl_block_ccw);
1069 reipl_capabilities |= IPL_TYPE_CCW;
1073 static int __init reipl_fcp_init(void)
1077 if (!diag308_set_works) {
1078 if (ipl_info.type == IPL_TYPE_FCP)
1079 make_attrs_ro(reipl_fcp_attrs);
1084 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1085 if (!reipl_block_fcp)
1087 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
1089 free_page((unsigned long)reipl_block_fcp);
1092 if (ipl_info.type == IPL_TYPE_FCP) {
1093 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1095 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1096 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1097 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1098 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1099 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1101 reipl_capabilities |= IPL_TYPE_FCP;
1105 static int __init reipl_init(void)
1109 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1112 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1114 kset_unregister(reipl_kset);
1117 rc = reipl_ccw_init();
1120 rc = reipl_fcp_init();
1123 rc = reipl_nss_init();
1126 rc = reipl_set_type(ipl_info.type);
1132 static struct shutdown_action __refdata reipl_action = {
1133 .name = SHUTDOWN_ACTION_REIPL_STR,
1139 * dump shutdown action: Dump Linux on shutdown.
1142 /* FCP dump device attributes */
1144 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1145 dump_block_fcp->ipl_info.fcp.wwpn);
1146 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1147 dump_block_fcp->ipl_info.fcp.lun);
1148 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1149 dump_block_fcp->ipl_info.fcp.bootprog);
1150 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1151 dump_block_fcp->ipl_info.fcp.br_lba);
1152 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1153 dump_block_fcp->ipl_info.fcp.devno);
1155 static struct attribute *dump_fcp_attrs[] = {
1156 &sys_dump_fcp_device_attr.attr,
1157 &sys_dump_fcp_wwpn_attr.attr,
1158 &sys_dump_fcp_lun_attr.attr,
1159 &sys_dump_fcp_bootprog_attr.attr,
1160 &sys_dump_fcp_br_lba_attr.attr,
1164 static struct attribute_group dump_fcp_attr_group = {
1165 .name = IPL_FCP_STR,
1166 .attrs = dump_fcp_attrs,
1169 /* CCW dump device attributes */
1171 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1172 dump_block_ccw->ipl_info.ccw.devno);
1174 static struct attribute *dump_ccw_attrs[] = {
1175 &sys_dump_ccw_device_attr.attr,
1179 static struct attribute_group dump_ccw_attr_group = {
1180 .name = IPL_CCW_STR,
1181 .attrs = dump_ccw_attrs,
1186 static int dump_set_type(enum dump_type type)
1188 if (!(dump_capabilities & type))
1192 if (diag308_set_works)
1193 dump_method = DUMP_METHOD_CCW_DIAG;
1194 else if (MACHINE_IS_VM)
1195 dump_method = DUMP_METHOD_CCW_VM;
1197 dump_method = DUMP_METHOD_CCW_CIO;
1200 dump_method = DUMP_METHOD_FCP_DIAG;
1203 dump_method = DUMP_METHOD_NONE;
1209 static ssize_t dump_type_show(struct kobject *kobj,
1210 struct kobj_attribute *attr, char *page)
1212 return sprintf(page, "%s\n", dump_type_str(dump_type));
1215 static ssize_t dump_type_store(struct kobject *kobj,
1216 struct kobj_attribute *attr,
1217 const char *buf, size_t len)
1221 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1222 rc = dump_set_type(DUMP_TYPE_NONE);
1223 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1224 rc = dump_set_type(DUMP_TYPE_CCW);
1225 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1226 rc = dump_set_type(DUMP_TYPE_FCP);
1227 return (rc != 0) ? rc : len;
1230 static struct kobj_attribute dump_type_attr =
1231 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1233 static struct kset *dump_kset;
1235 static void dump_run(struct shutdown_trigger *trigger)
1237 struct ccw_dev_id devid;
1238 static char buf[100];
1240 switch (dump_method) {
1241 case DUMP_METHOD_CCW_CIO:
1243 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1245 reipl_ccw_dev(&devid);
1247 case DUMP_METHOD_CCW_VM:
1249 sprintf(buf, "STORE STATUS");
1250 __cpcmd(buf, NULL, 0, NULL);
1251 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1252 __cpcmd(buf, NULL, 0, NULL);
1254 case DUMP_METHOD_CCW_DIAG:
1255 diag308(DIAG308_SET, dump_block_ccw);
1256 diag308(DIAG308_DUMP, NULL);
1258 case DUMP_METHOD_FCP_DIAG:
1259 diag308(DIAG308_SET, dump_block_fcp);
1260 diag308(DIAG308_DUMP, NULL);
1262 case DUMP_METHOD_NONE:
1265 printk(KERN_EMERG "Dump failed!\n");
1268 static int __init dump_ccw_init(void)
1272 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1273 if (!dump_block_ccw)
1275 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1277 free_page((unsigned long)dump_block_ccw);
1280 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1281 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1282 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1283 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1284 dump_capabilities |= DUMP_TYPE_CCW;
1288 static int __init dump_fcp_init(void)
1292 if (!sclp_ipl_info.has_dump)
1293 return 0; /* LDIPL DUMP is not installed */
1294 if (!diag308_set_works)
1296 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1297 if (!dump_block_fcp)
1299 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1301 free_page((unsigned long)dump_block_fcp);
1304 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1305 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1306 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1307 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1308 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1309 dump_capabilities |= DUMP_TYPE_FCP;
1313 static int __init dump_init(void)
1317 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1320 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1322 kset_unregister(dump_kset);
1325 rc = dump_ccw_init();
1328 rc = dump_fcp_init();
1331 dump_set_type(DUMP_TYPE_NONE);
1335 static struct shutdown_action __refdata dump_action = {
1336 .name = SHUTDOWN_ACTION_DUMP_STR,
1341 static void dump_reipl_run(struct shutdown_trigger *trigger)
1345 * Bypass dynamic address translation (DAT) when storing IPL parameter
1346 * information block address and checksum into the prefix area
1347 * (corresponding to absolute addresses 0-8191).
1348 * When enhanced DAT applies and the STE format control in one,
1349 * the absolute address is formed without prefixing. In this case a
1350 * normal store (stg/st) into the prefix area would no more match to
1351 * absolute addresses 0-8191.
1354 asm volatile("sturg %0,%1"
1355 :: "a" ((unsigned long) reipl_block_actual),
1356 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1358 asm volatile("stura %0,%1"
1359 :: "a" ((unsigned long) reipl_block_actual),
1360 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1362 asm volatile("stura %0,%1"
1363 :: "a" (csum_partial(reipl_block_actual,
1364 reipl_block_actual->hdr.len, 0)),
1365 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1370 static int __init dump_reipl_init(void)
1372 if (!diag308_set_works)
1378 static struct shutdown_action __refdata dump_reipl_action = {
1379 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1380 .fn = dump_reipl_run,
1381 .init = dump_reipl_init,
1385 * vmcmd shutdown action: Trigger vm command on shutdown.
1388 static char vmcmd_on_reboot[128];
1389 static char vmcmd_on_panic[128];
1390 static char vmcmd_on_halt[128];
1391 static char vmcmd_on_poff[128];
1393 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1394 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1395 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1396 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1398 static struct attribute *vmcmd_attrs[] = {
1399 &sys_vmcmd_on_reboot_attr.attr,
1400 &sys_vmcmd_on_panic_attr.attr,
1401 &sys_vmcmd_on_halt_attr.attr,
1402 &sys_vmcmd_on_poff_attr.attr,
1406 static struct attribute_group vmcmd_attr_group = {
1407 .attrs = vmcmd_attrs,
1410 static struct kset *vmcmd_kset;
1412 static void vmcmd_run(struct shutdown_trigger *trigger)
1414 char *cmd, *next_cmd;
1416 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1417 cmd = vmcmd_on_reboot;
1418 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1419 cmd = vmcmd_on_panic;
1420 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1421 cmd = vmcmd_on_halt;
1422 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1423 cmd = vmcmd_on_poff;
1427 if (strlen(cmd) == 0)
1430 next_cmd = strchr(cmd, '\n');
1435 __cpcmd(cmd, NULL, 0, NULL);
1437 } while (cmd != NULL);
1440 static int vmcmd_init(void)
1444 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1447 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1450 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1451 vmcmd_run, vmcmd_init};
1454 * stop shutdown action: Stop Linux on shutdown.
1457 static void stop_run(struct shutdown_trigger *trigger)
1459 if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1460 disabled_wait((unsigned long) __builtin_return_address(0));
1462 signal_processor(smp_processor_id(), sigp_stop);
1467 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1472 static struct shutdown_action *shutdown_actions_list[] = {
1473 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1474 &vmcmd_action, &stop_action};
1475 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1481 static struct kset *shutdown_actions_kset;
1483 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1488 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1489 if (!shutdown_actions_list[i])
1491 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1492 trigger->action = shutdown_actions_list[i];
1501 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1504 static ssize_t on_reboot_show(struct kobject *kobj,
1505 struct kobj_attribute *attr, char *page)
1507 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1510 static ssize_t on_reboot_store(struct kobject *kobj,
1511 struct kobj_attribute *attr,
1512 const char *buf, size_t len)
1514 return set_trigger(buf, &on_reboot_trigger, len);
1517 static struct kobj_attribute on_reboot_attr =
1518 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1520 static void do_machine_restart(char *__unused)
1523 on_reboot_trigger.action->fn(&on_reboot_trigger);
1526 void (*_machine_restart)(char *command) = do_machine_restart;
1530 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1532 static ssize_t on_panic_show(struct kobject *kobj,
1533 struct kobj_attribute *attr, char *page)
1535 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1538 static ssize_t on_panic_store(struct kobject *kobj,
1539 struct kobj_attribute *attr,
1540 const char *buf, size_t len)
1542 return set_trigger(buf, &on_panic_trigger, len);
1545 static struct kobj_attribute on_panic_attr =
1546 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1548 static void do_panic(void)
1550 on_panic_trigger.action->fn(&on_panic_trigger);
1551 stop_run(&on_panic_trigger);
1556 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1558 static ssize_t on_halt_show(struct kobject *kobj,
1559 struct kobj_attribute *attr, char *page)
1561 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1564 static ssize_t on_halt_store(struct kobject *kobj,
1565 struct kobj_attribute *attr,
1566 const char *buf, size_t len)
1568 return set_trigger(buf, &on_halt_trigger, len);
1571 static struct kobj_attribute on_halt_attr =
1572 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1575 static void do_machine_halt(void)
1578 on_halt_trigger.action->fn(&on_halt_trigger);
1579 stop_run(&on_halt_trigger);
1581 void (*_machine_halt)(void) = do_machine_halt;
1585 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1587 static ssize_t on_poff_show(struct kobject *kobj,
1588 struct kobj_attribute *attr, char *page)
1590 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1593 static ssize_t on_poff_store(struct kobject *kobj,
1594 struct kobj_attribute *attr,
1595 const char *buf, size_t len)
1597 return set_trigger(buf, &on_poff_trigger, len);
1600 static struct kobj_attribute on_poff_attr =
1601 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1604 static void do_machine_power_off(void)
1607 on_poff_trigger.action->fn(&on_poff_trigger);
1608 stop_run(&on_poff_trigger);
1610 void (*_machine_power_off)(void) = do_machine_power_off;
1612 static void __init shutdown_triggers_init(void)
1614 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1616 if (!shutdown_actions_kset)
1618 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1619 &on_reboot_attr.attr))
1621 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1622 &on_panic_attr.attr))
1624 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1625 &on_halt_attr.attr))
1627 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1628 &on_poff_attr.attr))
1633 panic("shutdown_triggers_init failed\n");
1636 static void __init shutdown_actions_init(void)
1640 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1641 if (!shutdown_actions_list[i]->init)
1643 if (shutdown_actions_list[i]->init())
1644 shutdown_actions_list[i] = NULL;
1648 static int __init s390_ipl_init(void)
1650 sclp_get_ipl_info(&sclp_ipl_info);
1651 shutdown_actions_init();
1652 shutdown_triggers_init();
1656 __initcall(s390_ipl_init);
1658 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1663 for (sx = 0; src[sx] != 0; sx++) {
1666 dst[dx++] = src[sx];
1672 static int __init vmcmd_on_reboot_setup(char *str)
1676 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1677 vmcmd_on_reboot[127] = 0;
1678 on_reboot_trigger.action = &vmcmd_action;
1681 __setup("vmreboot=", vmcmd_on_reboot_setup);
1683 static int __init vmcmd_on_panic_setup(char *str)
1687 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1688 vmcmd_on_panic[127] = 0;
1689 on_panic_trigger.action = &vmcmd_action;
1692 __setup("vmpanic=", vmcmd_on_panic_setup);
1694 static int __init vmcmd_on_halt_setup(char *str)
1698 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1699 vmcmd_on_halt[127] = 0;
1700 on_halt_trigger.action = &vmcmd_action;
1703 __setup("vmhalt=", vmcmd_on_halt_setup);
1705 static int __init vmcmd_on_poff_setup(char *str)
1709 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1710 vmcmd_on_poff[127] = 0;
1711 on_poff_trigger.action = &vmcmd_action;
1714 __setup("vmpoff=", vmcmd_on_poff_setup);
1716 static int on_panic_notify(struct notifier_block *self,
1717 unsigned long event, void *data)
1723 static struct notifier_block on_panic_nb = {
1724 .notifier_call = on_panic_notify,
1725 .priority = INT_MIN,
1728 void __init setup_ipl(void)
1730 ipl_info.type = get_ipl_type();
1731 switch (ipl_info.type) {
1733 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1734 ipl_info.data.ccw.dev_id.ssid = 0;
1737 case IPL_TYPE_FCP_DUMP:
1738 ipl_info.data.fcp.dev_id.devno =
1739 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1740 ipl_info.data.fcp.dev_id.ssid = 0;
1741 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1742 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1745 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1746 sizeof(ipl_info.data.nss.name));
1748 case IPL_TYPE_UNKNOWN:
1749 /* We have no info to copy */
1752 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1755 void __init ipl_update_parameters(void)
1759 rc = diag308(DIAG308_STORE, &ipl_block);
1760 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1761 diag308_set_works = 1;
1764 void __init ipl_save_parameters(void)
1766 struct cio_iplinfo iplinfo;
1767 unsigned int *ipl_ptr;
1770 if (cio_get_iplinfo(&iplinfo))
1773 ipl_devno = iplinfo.devno;
1774 ipl_flags |= IPL_DEVNO_VALID;
1775 if (!iplinfo.is_qdio)
1777 ipl_flags |= IPL_PARMBLOCK_VALID;
1778 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1779 src = (void *)(unsigned long)*ipl_ptr;
1780 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1781 memmove(dst, src, PAGE_SIZE);
1782 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1785 static LIST_HEAD(rcall);
1786 static DEFINE_MUTEX(rcall_mutex);
1788 void register_reset_call(struct reset_call *reset)
1790 mutex_lock(&rcall_mutex);
1791 list_add(&reset->list, &rcall);
1792 mutex_unlock(&rcall_mutex);
1794 EXPORT_SYMBOL_GPL(register_reset_call);
1796 void unregister_reset_call(struct reset_call *reset)
1798 mutex_lock(&rcall_mutex);
1799 list_del(&reset->list);
1800 mutex_unlock(&rcall_mutex);
1802 EXPORT_SYMBOL_GPL(unregister_reset_call);
1804 static void do_reset_calls(void)
1806 struct reset_call *reset;
1808 list_for_each_entry(reset, &rcall, list)
1812 u32 dump_prefix_page;
1814 void s390_reset_system(void)
1816 struct _lowcore *lc;
1818 lc = (struct _lowcore *)(unsigned long) store_prefix();
1820 /* Stack for interrupt/machine check handler */
1821 lc->panic_stack = S390_lowcore.panic_stack;
1823 /* Save prefix page address for dump case */
1824 dump_prefix_page = (u32)(unsigned long) lc;
1826 /* Disable prefixing */
1829 /* Disable lowcore protection */
1830 __ctl_clear_bit(0,28);
1832 /* Set new machine check handler */
1833 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1834 S390_lowcore.mcck_new_psw.addr =
1835 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
1837 /* Set new program check handler */
1838 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1839 S390_lowcore.program_new_psw.addr =
1840 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;