2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
20 #include <asm/setup.h>
21 #include <asm/cpcmd.h>
23 #include <asm/ebcdic.h>
24 #include <asm/reset.h>
26 #include <asm/checksum.h>
28 #define IPL_PARM_BLOCK_VERSION 0
30 #define IPL_UNKNOWN_STR "unknown"
31 #define IPL_CCW_STR "ccw"
32 #define IPL_FCP_STR "fcp"
33 #define IPL_FCP_DUMP_STR "fcp_dump"
34 #define IPL_NSS_STR "nss"
36 #define DUMP_CCW_STR "ccw"
37 #define DUMP_FCP_STR "fcp"
38 #define DUMP_NONE_STR "none"
41 * Four shutdown trigger types are supported:
47 #define ON_PANIC_STR "on_panic"
48 #define ON_HALT_STR "on_halt"
49 #define ON_POFF_STR "on_poff"
50 #define ON_REIPL_STR "on_reboot"
52 struct shutdown_action;
53 struct shutdown_trigger {
55 struct shutdown_action *action;
59 * The following shutdown action types are supported:
61 #define SHUTDOWN_ACTION_IPL_STR "ipl"
62 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
63 #define SHUTDOWN_ACTION_DUMP_STR "dump"
64 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
65 #define SHUTDOWN_ACTION_STOP_STR "stop"
66 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
68 struct shutdown_action {
70 void (*fn) (struct shutdown_trigger *trigger);
74 static char *ipl_type_str(enum ipl_type type)
81 case IPL_TYPE_FCP_DUMP:
82 return IPL_FCP_DUMP_STR;
85 case IPL_TYPE_UNKNOWN:
87 return IPL_UNKNOWN_STR;
97 static char *dump_type_str(enum dump_type type)
101 return DUMP_NONE_STR;
112 * Must be in data section since the bss section
113 * is not cleared when these are accessed.
115 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
116 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
119 REIPL_METHOD_CCW_CIO,
120 REIPL_METHOD_CCW_DIAG,
122 REIPL_METHOD_FCP_RO_DIAG,
123 REIPL_METHOD_FCP_RW_DIAG,
124 REIPL_METHOD_FCP_RO_VM,
125 REIPL_METHOD_FCP_DUMP,
127 REIPL_METHOD_NSS_DIAG,
128 REIPL_METHOD_DEFAULT,
134 DUMP_METHOD_CCW_DIAG,
136 DUMP_METHOD_FCP_DIAG,
139 static int diag308_set_works = 0;
141 static struct ipl_parameter_block ipl_block;
143 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
145 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
146 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
147 static struct ipl_parameter_block *reipl_block_fcp;
148 static struct ipl_parameter_block *reipl_block_ccw;
149 static struct ipl_parameter_block *reipl_block_nss;
150 static struct ipl_parameter_block *reipl_block_actual;
152 static int dump_capabilities = DUMP_TYPE_NONE;
153 static enum dump_type dump_type = DUMP_TYPE_NONE;
154 static enum dump_method dump_method = DUMP_METHOD_NONE;
155 static struct ipl_parameter_block *dump_block_fcp;
156 static struct ipl_parameter_block *dump_block_ccw;
158 static struct sclp_ipl_info sclp_ipl_info;
160 int diag308(unsigned long subcode, void *addr)
162 register unsigned long _addr asm("0") = (unsigned long) addr;
163 register unsigned long _rc asm("1") = 0;
166 " diag %0,%2,0x308\n"
169 : "+d" (_addr), "+d" (_rc)
170 : "d" (subcode) : "cc", "memory");
173 EXPORT_SYMBOL_GPL(diag308);
177 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
178 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
179 struct kobj_attribute *attr, \
182 return sprintf(page, _format, _value); \
184 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
185 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
187 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
188 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
189 struct kobj_attribute *attr, \
192 return sprintf(page, _fmt_out, \
193 (unsigned long long) _value); \
195 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
196 struct kobj_attribute *attr, \
197 const char *buf, size_t len) \
199 unsigned long long value; \
200 if (sscanf(buf, _fmt_in, &value) != 1) \
205 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
206 __ATTR(_name,(S_IRUGO | S_IWUSR), \
207 sys_##_prefix##_##_name##_show, \
208 sys_##_prefix##_##_name##_store);
210 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
211 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
212 struct kobj_attribute *attr, \
215 return sprintf(page, _fmt_out, _value); \
217 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
218 struct kobj_attribute *attr, \
219 const char *buf, size_t len) \
221 strncpy(_value, buf, sizeof(_value) - 1); \
225 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
226 __ATTR(_name,(S_IRUGO | S_IWUSR), \
227 sys_##_prefix##_##_name##_show, \
228 sys_##_prefix##_##_name##_store);
230 static void make_attrs_ro(struct attribute **attrs)
233 (*attrs)->mode = S_IRUGO;
242 static __init enum ipl_type get_ipl_type(void)
244 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
246 if (ipl_flags & IPL_NSS_VALID)
248 if (!(ipl_flags & IPL_DEVNO_VALID))
249 return IPL_TYPE_UNKNOWN;
250 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
252 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
253 return IPL_TYPE_UNKNOWN;
254 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
255 return IPL_TYPE_UNKNOWN;
256 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
257 return IPL_TYPE_FCP_DUMP;
261 struct ipl_info ipl_info;
262 EXPORT_SYMBOL_GPL(ipl_info);
264 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
267 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
270 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
272 /* VM IPL PARM routines */
273 static void reipl_get_ascii_vmparm(char *dest,
274 const struct ipl_parameter_block *ipb)
278 char has_lowercase = 0;
280 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
281 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
283 len = ipb->ipl_info.ccw.vm_parm_len;
284 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
285 /* If at least one character is lowercase, we assume mixed
286 * case; otherwise we convert everything to lowercase.
288 for (i = 0; i < len; i++)
289 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
290 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
291 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
296 EBC_TOLOWER(dest, len);
302 void get_ipl_vmparm(char *dest)
304 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
305 reipl_get_ascii_vmparm(dest, &ipl_block);
310 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
311 struct kobj_attribute *attr, char *page)
313 char parm[DIAG308_VMPARM_SIZE + 1] = {};
315 get_ipl_vmparm(parm);
316 return sprintf(page, "%s\n", parm);
319 static struct kobj_attribute sys_ipl_vm_parm_attr =
320 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
322 static ssize_t sys_ipl_device_show(struct kobject *kobj,
323 struct kobj_attribute *attr, char *page)
325 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
327 switch (ipl_info.type) {
329 return sprintf(page, "0.0.%04x\n", ipl_devno);
331 case IPL_TYPE_FCP_DUMP:
332 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
338 static struct kobj_attribute sys_ipl_device_attr =
339 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
341 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
342 char *buf, loff_t off, size_t count)
344 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
348 static struct bin_attribute ipl_parameter_attr = {
350 .name = "binary_parameter",
354 .read = &ipl_parameter_read,
357 static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
358 char *buf, loff_t off, size_t count)
360 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
361 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
363 return memory_read_from_buffer(buf, count, &off, scp_data, size);
366 static struct bin_attribute ipl_scp_data_attr = {
372 .read = ipl_scp_data_read,
375 /* FCP ipl device attributes */
377 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
378 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
379 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
380 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
381 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
382 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
383 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
384 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
386 static struct attribute *ipl_fcp_attrs[] = {
387 &sys_ipl_type_attr.attr,
388 &sys_ipl_device_attr.attr,
389 &sys_ipl_fcp_wwpn_attr.attr,
390 &sys_ipl_fcp_lun_attr.attr,
391 &sys_ipl_fcp_bootprog_attr.attr,
392 &sys_ipl_fcp_br_lba_attr.attr,
396 static struct attribute_group ipl_fcp_attr_group = {
397 .attrs = ipl_fcp_attrs,
400 /* CCW ipl device attributes */
402 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
403 struct kobj_attribute *attr, char *page)
405 char loadparm[LOADPARM_LEN + 1] = {};
407 if (!sclp_ipl_info.is_valid)
408 return sprintf(page, "#unknown#\n");
409 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
410 EBCASC(loadparm, LOADPARM_LEN);
412 return sprintf(page, "%s\n", loadparm);
415 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
416 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
418 static struct attribute *ipl_ccw_attrs_vm[] = {
419 &sys_ipl_type_attr.attr,
420 &sys_ipl_device_attr.attr,
421 &sys_ipl_ccw_loadparm_attr.attr,
422 &sys_ipl_vm_parm_attr.attr,
426 static struct attribute *ipl_ccw_attrs_lpar[] = {
427 &sys_ipl_type_attr.attr,
428 &sys_ipl_device_attr.attr,
429 &sys_ipl_ccw_loadparm_attr.attr,
433 static struct attribute_group ipl_ccw_attr_group_vm = {
434 .attrs = ipl_ccw_attrs_vm,
437 static struct attribute_group ipl_ccw_attr_group_lpar = {
438 .attrs = ipl_ccw_attrs_lpar
441 /* NSS ipl device attributes */
443 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
445 static struct attribute *ipl_nss_attrs[] = {
446 &sys_ipl_type_attr.attr,
447 &sys_ipl_nss_name_attr.attr,
448 &sys_ipl_ccw_loadparm_attr.attr,
449 &sys_ipl_vm_parm_attr.attr,
453 static struct attribute_group ipl_nss_attr_group = {
454 .attrs = ipl_nss_attrs,
457 /* UNKNOWN ipl device attributes */
459 static struct attribute *ipl_unknown_attrs[] = {
460 &sys_ipl_type_attr.attr,
464 static struct attribute_group ipl_unknown_attr_group = {
465 .attrs = ipl_unknown_attrs,
468 static struct kset *ipl_kset;
470 static int __init ipl_register_fcp_files(void)
474 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
477 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
480 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
484 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
487 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
492 static void ipl_run(struct shutdown_trigger *trigger)
494 diag308(DIAG308_IPL, NULL);
496 __cpcmd("IPL", NULL, 0, NULL);
497 else if (ipl_info.type == IPL_TYPE_CCW)
498 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
501 static int __init ipl_init(void)
505 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
510 switch (ipl_info.type) {
513 rc = sysfs_create_group(&ipl_kset->kobj,
514 &ipl_ccw_attr_group_vm);
516 rc = sysfs_create_group(&ipl_kset->kobj,
517 &ipl_ccw_attr_group_lpar);
520 case IPL_TYPE_FCP_DUMP:
521 rc = ipl_register_fcp_files();
524 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
527 rc = sysfs_create_group(&ipl_kset->kobj,
528 &ipl_unknown_attr_group);
533 panic("ipl_init failed: rc = %i\n", rc);
538 static struct shutdown_action __refdata ipl_action = {
539 .name = SHUTDOWN_ACTION_IPL_STR,
545 * reipl shutdown action: Reboot Linux on shutdown.
548 /* VM IPL PARM attributes */
549 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
552 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
554 reipl_get_ascii_vmparm(vmparm, ipb);
555 return sprintf(page, "%s\n", vmparm);
558 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
560 const char *buf, size_t len)
564 /* ignore trailing newline */
566 if ((len > 0) && (buf[len - 1] == '\n'))
569 if (ip_len > vmparm_max)
572 /* parm is used to store kernel options, check for common chars */
573 for (i = 0; i < ip_len; i++)
574 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
577 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
578 ipb->ipl_info.ccw.vm_parm_len = ip_len;
580 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
581 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
582 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
584 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
591 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
592 struct kobj_attribute *attr, char *page)
594 return reipl_generic_vmparm_show(reipl_block_nss, page);
597 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
598 struct kobj_attribute *attr,
599 const char *buf, size_t len)
601 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
605 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
606 struct kobj_attribute *attr, char *page)
608 return reipl_generic_vmparm_show(reipl_block_ccw, page);
611 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
612 struct kobj_attribute *attr,
613 const char *buf, size_t len)
615 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
618 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
619 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
620 reipl_nss_vmparm_store);
621 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
622 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
623 reipl_ccw_vmparm_store);
625 /* FCP reipl device attributes */
627 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
628 reipl_block_fcp->ipl_info.fcp.wwpn);
629 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
630 reipl_block_fcp->ipl_info.fcp.lun);
631 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
632 reipl_block_fcp->ipl_info.fcp.bootprog);
633 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
634 reipl_block_fcp->ipl_info.fcp.br_lba);
635 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
636 reipl_block_fcp->ipl_info.fcp.devno);
638 static struct attribute *reipl_fcp_attrs[] = {
639 &sys_reipl_fcp_device_attr.attr,
640 &sys_reipl_fcp_wwpn_attr.attr,
641 &sys_reipl_fcp_lun_attr.attr,
642 &sys_reipl_fcp_bootprog_attr.attr,
643 &sys_reipl_fcp_br_lba_attr.attr,
647 static struct attribute_group reipl_fcp_attr_group = {
649 .attrs = reipl_fcp_attrs,
652 /* CCW reipl device attributes */
654 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
655 reipl_block_ccw->ipl_info.ccw.devno);
657 static void reipl_get_ascii_loadparm(char *loadparm,
658 struct ipl_parameter_block *ibp)
660 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
661 EBCASC(loadparm, LOADPARM_LEN);
662 loadparm[LOADPARM_LEN] = 0;
666 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
669 char buf[LOADPARM_LEN + 1];
671 reipl_get_ascii_loadparm(buf, ipb);
672 return sprintf(page, "%s\n", buf);
675 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
676 const char *buf, size_t len)
680 /* ignore trailing newline */
682 if ((len > 0) && (buf[len - 1] == '\n'))
684 /* loadparm can have max 8 characters and must not start with a blank */
685 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
687 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
688 for (i = 0; i < lp_len; i++) {
689 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
694 /* initialize loadparm with blanks */
695 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
696 /* copy and convert to ebcdic */
697 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
698 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
703 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
704 struct kobj_attribute *attr, char *page)
706 return reipl_generic_loadparm_show(reipl_block_nss, page);
709 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
710 struct kobj_attribute *attr,
711 const char *buf, size_t len)
713 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
717 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
718 struct kobj_attribute *attr, char *page)
720 return reipl_generic_loadparm_show(reipl_block_ccw, page);
723 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
724 struct kobj_attribute *attr,
725 const char *buf, size_t len)
727 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
730 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
731 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
732 reipl_ccw_loadparm_store);
734 static struct attribute *reipl_ccw_attrs_vm[] = {
735 &sys_reipl_ccw_device_attr.attr,
736 &sys_reipl_ccw_loadparm_attr.attr,
737 &sys_reipl_ccw_vmparm_attr.attr,
741 static struct attribute *reipl_ccw_attrs_lpar[] = {
742 &sys_reipl_ccw_device_attr.attr,
743 &sys_reipl_ccw_loadparm_attr.attr,
747 static struct attribute_group reipl_ccw_attr_group_vm = {
749 .attrs = reipl_ccw_attrs_vm,
752 static struct attribute_group reipl_ccw_attr_group_lpar = {
754 .attrs = reipl_ccw_attrs_lpar,
758 /* NSS reipl device attributes */
759 static void reipl_get_ascii_nss_name(char *dst,
760 struct ipl_parameter_block *ipb)
762 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
763 EBCASC(dst, NSS_NAME_SIZE);
764 dst[NSS_NAME_SIZE] = 0;
767 static ssize_t reipl_nss_name_show(struct kobject *kobj,
768 struct kobj_attribute *attr, char *page)
770 char nss_name[NSS_NAME_SIZE + 1] = {};
772 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
773 return sprintf(page, "%s\n", nss_name);
776 static ssize_t reipl_nss_name_store(struct kobject *kobj,
777 struct kobj_attribute *attr,
778 const char *buf, size_t len)
782 /* ignore trailing newline */
784 if ((len > 0) && (buf[len - 1] == '\n'))
787 if (nss_len > NSS_NAME_SIZE)
790 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
792 reipl_block_nss->ipl_info.ccw.vm_flags |=
793 DIAG308_VM_FLAGS_NSS_VALID;
794 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
795 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
796 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
798 reipl_block_nss->ipl_info.ccw.vm_flags &=
799 ~DIAG308_VM_FLAGS_NSS_VALID;
805 static struct kobj_attribute sys_reipl_nss_name_attr =
806 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
807 reipl_nss_name_store);
809 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
810 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
811 reipl_nss_loadparm_store);
813 static struct attribute *reipl_nss_attrs[] = {
814 &sys_reipl_nss_name_attr.attr,
815 &sys_reipl_nss_loadparm_attr.attr,
816 &sys_reipl_nss_vmparm_attr.attr,
820 static struct attribute_group reipl_nss_attr_group = {
822 .attrs = reipl_nss_attrs,
827 static int reipl_set_type(enum ipl_type type)
829 if (!(reipl_capabilities & type))
834 if (diag308_set_works)
835 reipl_method = REIPL_METHOD_CCW_DIAG;
836 else if (MACHINE_IS_VM)
837 reipl_method = REIPL_METHOD_CCW_VM;
839 reipl_method = REIPL_METHOD_CCW_CIO;
840 reipl_block_actual = reipl_block_ccw;
843 if (diag308_set_works)
844 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
845 else if (MACHINE_IS_VM)
846 reipl_method = REIPL_METHOD_FCP_RO_VM;
848 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
849 reipl_block_actual = reipl_block_fcp;
851 case IPL_TYPE_FCP_DUMP:
852 reipl_method = REIPL_METHOD_FCP_DUMP;
855 if (diag308_set_works)
856 reipl_method = REIPL_METHOD_NSS_DIAG;
858 reipl_method = REIPL_METHOD_NSS;
859 reipl_block_actual = reipl_block_nss;
861 case IPL_TYPE_UNKNOWN:
862 reipl_method = REIPL_METHOD_DEFAULT;
871 static ssize_t reipl_type_show(struct kobject *kobj,
872 struct kobj_attribute *attr, char *page)
874 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
877 static ssize_t reipl_type_store(struct kobject *kobj,
878 struct kobj_attribute *attr,
879 const char *buf, size_t len)
883 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
884 rc = reipl_set_type(IPL_TYPE_CCW);
885 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
886 rc = reipl_set_type(IPL_TYPE_FCP);
887 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
888 rc = reipl_set_type(IPL_TYPE_NSS);
889 return (rc != 0) ? rc : len;
892 static struct kobj_attribute reipl_type_attr =
893 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
895 static struct kset *reipl_kset;
897 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
898 const enum ipl_method m)
900 char loadparm[LOADPARM_LEN + 1] = {};
901 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
902 char nss_name[NSS_NAME_SIZE + 1] = {};
905 reipl_get_ascii_loadparm(loadparm, ipb);
906 reipl_get_ascii_nss_name(nss_name, ipb);
907 reipl_get_ascii_vmparm(vmparm, ipb);
910 case REIPL_METHOD_CCW_VM:
911 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
913 case REIPL_METHOD_NSS:
914 pos = sprintf(dst, "IPL %s", nss_name);
919 if (strlen(loadparm) > 0)
920 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
921 if (strlen(vmparm) > 0)
922 sprintf(dst + pos, " PARM %s", vmparm);
925 static void reipl_run(struct shutdown_trigger *trigger)
927 struct ccw_dev_id devid;
928 static char buf[128];
930 switch (reipl_method) {
931 case REIPL_METHOD_CCW_CIO:
932 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
934 reipl_ccw_dev(&devid);
936 case REIPL_METHOD_CCW_VM:
937 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
938 __cpcmd(buf, NULL, 0, NULL);
940 case REIPL_METHOD_CCW_DIAG:
941 diag308(DIAG308_SET, reipl_block_ccw);
942 diag308(DIAG308_IPL, NULL);
944 case REIPL_METHOD_FCP_RW_DIAG:
945 diag308(DIAG308_SET, reipl_block_fcp);
946 diag308(DIAG308_IPL, NULL);
948 case REIPL_METHOD_FCP_RO_DIAG:
949 diag308(DIAG308_IPL, NULL);
951 case REIPL_METHOD_FCP_RO_VM:
952 __cpcmd("IPL", NULL, 0, NULL);
954 case REIPL_METHOD_NSS_DIAG:
955 diag308(DIAG308_SET, reipl_block_nss);
956 diag308(DIAG308_IPL, NULL);
958 case REIPL_METHOD_NSS:
959 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
960 __cpcmd(buf, NULL, 0, NULL);
962 case REIPL_METHOD_DEFAULT:
964 __cpcmd("IPL", NULL, 0, NULL);
965 diag308(DIAG308_IPL, NULL);
967 case REIPL_METHOD_FCP_DUMP:
970 disabled_wait((unsigned long) __builtin_return_address(0));
973 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
975 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
976 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
977 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
978 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
981 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
984 /* check if read scp info worked and set loadparm */
985 if (sclp_ipl_info.is_valid)
986 memcpy(ipb->ipl_info.ccw.load_parm,
987 &sclp_ipl_info.loadparm, LOADPARM_LEN);
989 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
990 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
991 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
994 if (MACHINE_IS_VM && diag308_set_works &&
995 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
997 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
998 ipb->ipl_info.ccw.vm_parm_len =
999 ipl_block.ipl_info.ccw.vm_parm_len;
1000 memcpy(ipb->ipl_info.ccw.vm_parm,
1001 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1005 static int __init reipl_nss_init(void)
1012 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1013 if (!reipl_block_nss)
1016 if (!diag308_set_works)
1017 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1019 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1023 reipl_block_ccw_init(reipl_block_nss);
1024 if (ipl_info.type == IPL_TYPE_NSS) {
1025 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1026 ' ', NSS_NAME_SIZE);
1027 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1028 kernel_nss_name, strlen(kernel_nss_name));
1029 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1030 reipl_block_nss->ipl_info.ccw.vm_flags |=
1031 DIAG308_VM_FLAGS_NSS_VALID;
1033 reipl_block_ccw_fill_parms(reipl_block_nss);
1036 reipl_capabilities |= IPL_TYPE_NSS;
1040 static int __init reipl_ccw_init(void)
1044 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1045 if (!reipl_block_ccw)
1048 if (MACHINE_IS_VM) {
1049 if (!diag308_set_works)
1050 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1051 rc = sysfs_create_group(&reipl_kset->kobj,
1052 &reipl_ccw_attr_group_vm);
1054 if(!diag308_set_works)
1055 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1056 rc = sysfs_create_group(&reipl_kset->kobj,
1057 &reipl_ccw_attr_group_lpar);
1062 reipl_block_ccw_init(reipl_block_ccw);
1063 if (ipl_info.type == IPL_TYPE_CCW) {
1064 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1065 reipl_block_ccw_fill_parms(reipl_block_ccw);
1068 reipl_capabilities |= IPL_TYPE_CCW;
1072 static int __init reipl_fcp_init(void)
1076 if (!diag308_set_works) {
1077 if (ipl_info.type == IPL_TYPE_FCP)
1078 make_attrs_ro(reipl_fcp_attrs);
1083 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1084 if (!reipl_block_fcp)
1086 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
1088 free_page((unsigned long)reipl_block_fcp);
1091 if (ipl_info.type == IPL_TYPE_FCP) {
1092 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1094 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1095 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1096 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1097 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1098 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1100 reipl_capabilities |= IPL_TYPE_FCP;
1104 static int __init reipl_init(void)
1108 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1111 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1113 kset_unregister(reipl_kset);
1116 rc = reipl_ccw_init();
1119 rc = reipl_fcp_init();
1122 rc = reipl_nss_init();
1125 rc = reipl_set_type(ipl_info.type);
1131 static struct shutdown_action __refdata reipl_action = {
1132 .name = SHUTDOWN_ACTION_REIPL_STR,
1138 * dump shutdown action: Dump Linux on shutdown.
1141 /* FCP dump device attributes */
1143 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1144 dump_block_fcp->ipl_info.fcp.wwpn);
1145 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1146 dump_block_fcp->ipl_info.fcp.lun);
1147 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1148 dump_block_fcp->ipl_info.fcp.bootprog);
1149 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1150 dump_block_fcp->ipl_info.fcp.br_lba);
1151 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1152 dump_block_fcp->ipl_info.fcp.devno);
1154 static struct attribute *dump_fcp_attrs[] = {
1155 &sys_dump_fcp_device_attr.attr,
1156 &sys_dump_fcp_wwpn_attr.attr,
1157 &sys_dump_fcp_lun_attr.attr,
1158 &sys_dump_fcp_bootprog_attr.attr,
1159 &sys_dump_fcp_br_lba_attr.attr,
1163 static struct attribute_group dump_fcp_attr_group = {
1164 .name = IPL_FCP_STR,
1165 .attrs = dump_fcp_attrs,
1168 /* CCW dump device attributes */
1170 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1171 dump_block_ccw->ipl_info.ccw.devno);
1173 static struct attribute *dump_ccw_attrs[] = {
1174 &sys_dump_ccw_device_attr.attr,
1178 static struct attribute_group dump_ccw_attr_group = {
1179 .name = IPL_CCW_STR,
1180 .attrs = dump_ccw_attrs,
1185 static int dump_set_type(enum dump_type type)
1187 if (!(dump_capabilities & type))
1191 if (diag308_set_works)
1192 dump_method = DUMP_METHOD_CCW_DIAG;
1193 else if (MACHINE_IS_VM)
1194 dump_method = DUMP_METHOD_CCW_VM;
1196 dump_method = DUMP_METHOD_CCW_CIO;
1199 dump_method = DUMP_METHOD_FCP_DIAG;
1202 dump_method = DUMP_METHOD_NONE;
1208 static ssize_t dump_type_show(struct kobject *kobj,
1209 struct kobj_attribute *attr, char *page)
1211 return sprintf(page, "%s\n", dump_type_str(dump_type));
1214 static ssize_t dump_type_store(struct kobject *kobj,
1215 struct kobj_attribute *attr,
1216 const char *buf, size_t len)
1220 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1221 rc = dump_set_type(DUMP_TYPE_NONE);
1222 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1223 rc = dump_set_type(DUMP_TYPE_CCW);
1224 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1225 rc = dump_set_type(DUMP_TYPE_FCP);
1226 return (rc != 0) ? rc : len;
1229 static struct kobj_attribute dump_type_attr =
1230 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1232 static struct kset *dump_kset;
1234 static void dump_run(struct shutdown_trigger *trigger)
1236 struct ccw_dev_id devid;
1237 static char buf[100];
1239 switch (dump_method) {
1240 case DUMP_METHOD_CCW_CIO:
1242 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1244 reipl_ccw_dev(&devid);
1246 case DUMP_METHOD_CCW_VM:
1248 sprintf(buf, "STORE STATUS");
1249 __cpcmd(buf, NULL, 0, NULL);
1250 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1251 __cpcmd(buf, NULL, 0, NULL);
1253 case DUMP_METHOD_CCW_DIAG:
1254 diag308(DIAG308_SET, dump_block_ccw);
1255 diag308(DIAG308_DUMP, NULL);
1257 case DUMP_METHOD_FCP_DIAG:
1258 diag308(DIAG308_SET, dump_block_fcp);
1259 diag308(DIAG308_DUMP, NULL);
1261 case DUMP_METHOD_NONE:
1264 printk(KERN_EMERG "Dump failed!\n");
1267 static int __init dump_ccw_init(void)
1271 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1272 if (!dump_block_ccw)
1274 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1276 free_page((unsigned long)dump_block_ccw);
1279 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1280 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1281 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1282 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1283 dump_capabilities |= DUMP_TYPE_CCW;
1287 static int __init dump_fcp_init(void)
1291 if (!sclp_ipl_info.has_dump)
1292 return 0; /* LDIPL DUMP is not installed */
1293 if (!diag308_set_works)
1295 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1296 if (!dump_block_fcp)
1298 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1300 free_page((unsigned long)dump_block_fcp);
1303 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1304 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1305 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1306 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1307 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1308 dump_capabilities |= DUMP_TYPE_FCP;
1312 static int __init dump_init(void)
1316 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1319 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1321 kset_unregister(dump_kset);
1324 rc = dump_ccw_init();
1327 rc = dump_fcp_init();
1330 dump_set_type(DUMP_TYPE_NONE);
1334 static struct shutdown_action __refdata dump_action = {
1335 .name = SHUTDOWN_ACTION_DUMP_STR,
1340 static void dump_reipl_run(struct shutdown_trigger *trigger)
1344 * Bypass dynamic address translation (DAT) when storing IPL parameter
1345 * information block address and checksum into the prefix area
1346 * (corresponding to absolute addresses 0-8191).
1347 * When enhanced DAT applies and the STE format control in one,
1348 * the absolute address is formed without prefixing. In this case a
1349 * normal store (stg/st) into the prefix area would no more match to
1350 * absolute addresses 0-8191.
1353 asm volatile("sturg %0,%1"
1354 :: "a" ((unsigned long) reipl_block_actual),
1355 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1357 asm volatile("stura %0,%1"
1358 :: "a" ((unsigned long) reipl_block_actual),
1359 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1361 asm volatile("stura %0,%1"
1362 :: "a" (csum_partial(reipl_block_actual,
1363 reipl_block_actual->hdr.len, 0)),
1364 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1369 static int __init dump_reipl_init(void)
1371 if (!diag308_set_works)
1377 static struct shutdown_action __refdata dump_reipl_action = {
1378 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1379 .fn = dump_reipl_run,
1380 .init = dump_reipl_init,
1384 * vmcmd shutdown action: Trigger vm command on shutdown.
1387 static char vmcmd_on_reboot[128];
1388 static char vmcmd_on_panic[128];
1389 static char vmcmd_on_halt[128];
1390 static char vmcmd_on_poff[128];
1392 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1393 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1394 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1395 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1397 static struct attribute *vmcmd_attrs[] = {
1398 &sys_vmcmd_on_reboot_attr.attr,
1399 &sys_vmcmd_on_panic_attr.attr,
1400 &sys_vmcmd_on_halt_attr.attr,
1401 &sys_vmcmd_on_poff_attr.attr,
1405 static struct attribute_group vmcmd_attr_group = {
1406 .attrs = vmcmd_attrs,
1409 static struct kset *vmcmd_kset;
1411 static void vmcmd_run(struct shutdown_trigger *trigger)
1413 char *cmd, *next_cmd;
1415 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1416 cmd = vmcmd_on_reboot;
1417 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1418 cmd = vmcmd_on_panic;
1419 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1420 cmd = vmcmd_on_halt;
1421 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1422 cmd = vmcmd_on_poff;
1426 if (strlen(cmd) == 0)
1429 next_cmd = strchr(cmd, '\n');
1434 __cpcmd(cmd, NULL, 0, NULL);
1436 } while (cmd != NULL);
1439 static int vmcmd_init(void)
1443 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1446 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1449 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1450 vmcmd_run, vmcmd_init};
1453 * stop shutdown action: Stop Linux on shutdown.
1456 static void stop_run(struct shutdown_trigger *trigger)
1458 if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1459 disabled_wait((unsigned long) __builtin_return_address(0));
1461 signal_processor(smp_processor_id(), sigp_stop);
1466 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1471 static struct shutdown_action *shutdown_actions_list[] = {
1472 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1473 &vmcmd_action, &stop_action};
1474 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1480 static struct kset *shutdown_actions_kset;
1482 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1487 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1488 if (!shutdown_actions_list[i])
1490 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1491 trigger->action = shutdown_actions_list[i];
1500 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1503 static ssize_t on_reboot_show(struct kobject *kobj,
1504 struct kobj_attribute *attr, char *page)
1506 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1509 static ssize_t on_reboot_store(struct kobject *kobj,
1510 struct kobj_attribute *attr,
1511 const char *buf, size_t len)
1513 return set_trigger(buf, &on_reboot_trigger, len);
1516 static struct kobj_attribute on_reboot_attr =
1517 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1519 static void do_machine_restart(char *__unused)
1522 on_reboot_trigger.action->fn(&on_reboot_trigger);
1525 void (*_machine_restart)(char *command) = do_machine_restart;
1529 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1531 static ssize_t on_panic_show(struct kobject *kobj,
1532 struct kobj_attribute *attr, char *page)
1534 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1537 static ssize_t on_panic_store(struct kobject *kobj,
1538 struct kobj_attribute *attr,
1539 const char *buf, size_t len)
1541 return set_trigger(buf, &on_panic_trigger, len);
1544 static struct kobj_attribute on_panic_attr =
1545 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1547 static void do_panic(void)
1549 on_panic_trigger.action->fn(&on_panic_trigger);
1550 stop_run(&on_panic_trigger);
1555 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1557 static ssize_t on_halt_show(struct kobject *kobj,
1558 struct kobj_attribute *attr, char *page)
1560 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1563 static ssize_t on_halt_store(struct kobject *kobj,
1564 struct kobj_attribute *attr,
1565 const char *buf, size_t len)
1567 return set_trigger(buf, &on_halt_trigger, len);
1570 static struct kobj_attribute on_halt_attr =
1571 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1574 static void do_machine_halt(void)
1577 on_halt_trigger.action->fn(&on_halt_trigger);
1578 stop_run(&on_halt_trigger);
1580 void (*_machine_halt)(void) = do_machine_halt;
1584 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1586 static ssize_t on_poff_show(struct kobject *kobj,
1587 struct kobj_attribute *attr, char *page)
1589 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1592 static ssize_t on_poff_store(struct kobject *kobj,
1593 struct kobj_attribute *attr,
1594 const char *buf, size_t len)
1596 return set_trigger(buf, &on_poff_trigger, len);
1599 static struct kobj_attribute on_poff_attr =
1600 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1603 static void do_machine_power_off(void)
1606 on_poff_trigger.action->fn(&on_poff_trigger);
1607 stop_run(&on_poff_trigger);
1609 void (*_machine_power_off)(void) = do_machine_power_off;
1611 static void __init shutdown_triggers_init(void)
1613 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1615 if (!shutdown_actions_kset)
1617 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1618 &on_reboot_attr.attr))
1620 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1621 &on_panic_attr.attr))
1623 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1624 &on_halt_attr.attr))
1626 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1627 &on_poff_attr.attr))
1632 panic("shutdown_triggers_init failed\n");
1635 static void __init shutdown_actions_init(void)
1639 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1640 if (!shutdown_actions_list[i]->init)
1642 if (shutdown_actions_list[i]->init())
1643 shutdown_actions_list[i] = NULL;
1647 static int __init s390_ipl_init(void)
1649 sclp_get_ipl_info(&sclp_ipl_info);
1650 shutdown_actions_init();
1651 shutdown_triggers_init();
1655 __initcall(s390_ipl_init);
1657 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1662 for (sx = 0; src[sx] != 0; sx++) {
1665 dst[dx++] = src[sx];
1671 static int __init vmcmd_on_reboot_setup(char *str)
1675 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1676 vmcmd_on_reboot[127] = 0;
1677 on_reboot_trigger.action = &vmcmd_action;
1680 __setup("vmreboot=", vmcmd_on_reboot_setup);
1682 static int __init vmcmd_on_panic_setup(char *str)
1686 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1687 vmcmd_on_panic[127] = 0;
1688 on_panic_trigger.action = &vmcmd_action;
1691 __setup("vmpanic=", vmcmd_on_panic_setup);
1693 static int __init vmcmd_on_halt_setup(char *str)
1697 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1698 vmcmd_on_halt[127] = 0;
1699 on_halt_trigger.action = &vmcmd_action;
1702 __setup("vmhalt=", vmcmd_on_halt_setup);
1704 static int __init vmcmd_on_poff_setup(char *str)
1708 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1709 vmcmd_on_poff[127] = 0;
1710 on_poff_trigger.action = &vmcmd_action;
1713 __setup("vmpoff=", vmcmd_on_poff_setup);
1715 static int on_panic_notify(struct notifier_block *self,
1716 unsigned long event, void *data)
1722 static struct notifier_block on_panic_nb = {
1723 .notifier_call = on_panic_notify,
1724 .priority = INT_MIN,
1727 void __init setup_ipl(void)
1729 ipl_info.type = get_ipl_type();
1730 switch (ipl_info.type) {
1732 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1733 ipl_info.data.ccw.dev_id.ssid = 0;
1736 case IPL_TYPE_FCP_DUMP:
1737 ipl_info.data.fcp.dev_id.devno =
1738 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1739 ipl_info.data.fcp.dev_id.ssid = 0;
1740 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1741 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1744 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1745 sizeof(ipl_info.data.nss.name));
1747 case IPL_TYPE_UNKNOWN:
1748 /* We have no info to copy */
1751 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1754 void __init ipl_update_parameters(void)
1758 rc = diag308(DIAG308_STORE, &ipl_block);
1759 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1760 diag308_set_works = 1;
1763 void __init ipl_save_parameters(void)
1765 struct cio_iplinfo iplinfo;
1766 unsigned int *ipl_ptr;
1769 if (cio_get_iplinfo(&iplinfo))
1772 ipl_devno = iplinfo.devno;
1773 ipl_flags |= IPL_DEVNO_VALID;
1774 if (!iplinfo.is_qdio)
1776 ipl_flags |= IPL_PARMBLOCK_VALID;
1777 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1778 src = (void *)(unsigned long)*ipl_ptr;
1779 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1780 memmove(dst, src, PAGE_SIZE);
1781 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1784 static LIST_HEAD(rcall);
1785 static DEFINE_MUTEX(rcall_mutex);
1787 void register_reset_call(struct reset_call *reset)
1789 mutex_lock(&rcall_mutex);
1790 list_add(&reset->list, &rcall);
1791 mutex_unlock(&rcall_mutex);
1793 EXPORT_SYMBOL_GPL(register_reset_call);
1795 void unregister_reset_call(struct reset_call *reset)
1797 mutex_lock(&rcall_mutex);
1798 list_del(&reset->list);
1799 mutex_unlock(&rcall_mutex);
1801 EXPORT_SYMBOL_GPL(unregister_reset_call);
1803 static void do_reset_calls(void)
1805 struct reset_call *reset;
1807 list_for_each_entry(reset, &rcall, list)
1811 u32 dump_prefix_page;
1813 void s390_reset_system(void)
1815 struct _lowcore *lc;
1817 lc = (struct _lowcore *)(unsigned long) store_prefix();
1819 /* Stack for interrupt/machine check handler */
1820 lc->panic_stack = S390_lowcore.panic_stack;
1822 /* Save prefix page address for dump case */
1823 dump_prefix_page = (u32)(unsigned long) lc;
1825 /* Disable prefixing */
1828 /* Disable lowcore protection */
1829 __ctl_clear_bit(0,28);
1831 /* Set new machine check handler */
1832 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1833 S390_lowcore.mcck_new_psw.addr =
1834 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
1836 /* Set new program check handler */
1837 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1838 S390_lowcore.program_new_psw.addr =
1839 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;