10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
14 #include <linux/reboot.h>
15 #include <linux/ctype.h>
22 #include <asm/setup.h>
28 #include <asm/checksum.h>
29 #include <asm/debug.h>
33 #define IPL_PARM_BLOCK_VERSION 0
35 #define IPL_UNKNOWN_STR "unknown"
36 #define IPL_CCW_STR "ccw"
37 #define IPL_FCP_STR "fcp"
38 #define IPL_FCP_DUMP_STR "fcp_dump"
39 #define IPL_NSS_STR "nss"
41 #define DUMP_CCW_STR "ccw"
42 #define DUMP_FCP_STR "fcp"
43 #define DUMP_NONE_STR "none"
53 #define ON_PANIC_STR "on_panic"
54 #define ON_HALT_STR "on_halt"
55 #define ON_POFF_STR "on_poff"
56 #define ON_REIPL_STR "on_reboot"
57 #define ON_RESTART_STR "on_restart"
68 #define SHUTDOWN_ACTION_IPL_STR "ipl"
69 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
70 #define SHUTDOWN_ACTION_DUMP_STR "dump"
71 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
72 #define SHUTDOWN_ACTION_STOP_STR "stop"
73 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
147 static int diag308_set_works = 0;
170 register unsigned long _addr
asm(
"0") = (
unsigned long)
addr;
171 register unsigned long _rc
asm(
"1") = 0;
174 " diag %0,%2,0x308\n"
177 :
"+d" (_addr),
"+d" (_rc)
178 :
"d" (subcode) :
"cc",
"memory");
185 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
186 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
190 return sprintf(page, _format, _value); \
192 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
193 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
195 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
196 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
197 struct kobj_attribute *attr, \
200 return sprintf(page, _fmt_out, \
201 (unsigned long long) _value); \
203 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
204 struct kobj_attribute *attr, \
205 const char *buf, size_t len) \
207 unsigned long long value; \
208 if (sscanf(buf, _fmt_in, &value) != 1) \
213 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
214 __ATTR(_name,(S_IRUGO | S_IWUSR), \
215 sys_##_prefix##_##_name##_show, \
216 sys_##_prefix##_##_name##_store);
218 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
219 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
223 return sprintf(page, _fmt_out, _value); \
225 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
226 struct kobj_attribute *attr, \
227 const char *buf, size_t len) \
229 strncpy(_value, buf, sizeof(_value) - 1); \
233 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
234 __ATTR(_name,(S_IRUGO | S_IWUSR), \
235 sys_##_prefix##_##_name##_show, \
236 sys_##_prefix##_##_name##_store);
238 static void make_attrs_ro(
struct attribute **attrs)
281 static size_t reipl_get_ascii_vmparm(
char *
dest,
size_t size,
286 char has_lowercase = 0;
297 for (i = 0; i < len; i++)
298 if ((dest[i] > 0x80 && dest[i] < 0x8a) ||
299 (dest[i] > 0x90 && dest[i] < 0x9a) ||
300 (dest[i] > 0xa1 && dest[i] < 0xaa)) {
319 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
331 return sprintf(page,
"%s\n", parm);
334 static size_t scpdata_length(
const char*
buf,
size_t count)
337 if (buf[count - 1] !=
'\0' && buf[count - 1] !=
' ')
344 static size_t reipl_append_ascii_scpdata(
char *dest,
size_t size,
357 for (i = 0; i <
count; i++) {
369 for (i = 0; i <
count; i++)
382 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
399 return sprintf(page,
"0.0.%04x\n", ipl_devno);
413 loff_t off,
size_t count)
421 .name =
"binary_parameter",
425 .read = &ipl_parameter_read,
430 loff_t off,
size_t count)
444 .read = ipl_scp_data_read,
458 static struct attribute *ipl_fcp_attrs[] = {
459 &sys_ipl_type_attr.
attr,
460 &sys_ipl_device_attr.
attr,
461 &sys_ipl_fcp_wwpn_attr.attr,
462 &sys_ipl_fcp_lun_attr.attr,
463 &sys_ipl_fcp_bootprog_attr.attr,
464 &sys_ipl_fcp_br_lba_attr.attr,
469 .attrs = ipl_fcp_attrs,
480 return sprintf(page,
"#unknown#\n");
484 return sprintf(page,
"%s\n", loadparm);
488 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show,
NULL);
490 static struct attribute *ipl_ccw_attrs_vm[] = {
491 &sys_ipl_type_attr.
attr,
492 &sys_ipl_device_attr.
attr,
493 &sys_ipl_ccw_loadparm_attr.
attr,
494 &sys_ipl_vm_parm_attr.
attr,
498 static struct attribute *ipl_ccw_attrs_lpar[] = {
499 &sys_ipl_type_attr.
attr,
500 &sys_ipl_device_attr.
attr,
501 &sys_ipl_ccw_loadparm_attr.
attr,
506 .attrs = ipl_ccw_attrs_vm,
510 .attrs = ipl_ccw_attrs_lpar
517 static struct attribute *ipl_nss_attrs[] = {
518 &sys_ipl_type_attr.
attr,
519 &sys_ipl_nss_name_attr.attr,
520 &sys_ipl_ccw_loadparm_attr.
attr,
521 &sys_ipl_vm_parm_attr.
attr,
526 .attrs = ipl_nss_attrs,
531 static struct attribute *ipl_unknown_attrs[] = {
532 &sys_ipl_type_attr.
attr,
537 .attrs = ipl_unknown_attrs,
540 static struct kset *ipl_kset;
542 static int __init ipl_register_fcp_files(
void)
564 static void __ipl_run(
void *
unused)
578 static int __init ipl_init(
void)
591 &ipl_ccw_attr_group_vm);
594 &ipl_ccw_attr_group_lpar);
598 rc = ipl_register_fcp_files();
605 &ipl_unknown_attr_group);
610 panic(
"ipl_init failed: rc = %i\n", rc);
631 reipl_get_ascii_vmparm(vmparm,
sizeof(vmparm), ipb);
632 return sprintf(page,
"%s\n", vmparm);
637 const char *buf,
size_t len)
643 if ((len > 0) && (buf[len - 1] ==
'\n'))
646 if (ip_len > vmparm_max)
650 for (i = 0; i < ip_len; i++)
671 return reipl_generic_vmparm_show(reipl_block_nss, page);
676 const char *buf,
size_t len)
678 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
685 return reipl_generic_vmparm_show(reipl_block_ccw, page);
690 const char *buf,
size_t len)
692 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
697 reipl_nss_vmparm_store);
700 reipl_ccw_vmparm_store);
706 char *buf, loff_t off,
size_t count)
708 size_t size = reipl_block_fcp->
ipl_info.
fcp.scp_data_len;
716 char *buf, loff_t off,
size_t count)
731 scpdata_len = off +
count;
733 if (scpdata_len % 8) {
734 padding = 8 - (scpdata_len % 8);
740 reipl_block_fcp->
ipl_info.
fcp.scp_data_len = scpdata_len;
753 .read = reipl_fcp_scpdata_read,
754 .write = reipl_fcp_scpdata_write,
768 static struct attribute *reipl_fcp_attrs[] = {
769 &sys_reipl_fcp_device_attr.attr,
770 &sys_reipl_fcp_wwpn_attr.attr,
771 &sys_reipl_fcp_lun_attr.attr,
772 &sys_reipl_fcp_bootprog_attr.attr,
773 &sys_reipl_fcp_br_lba_attr.attr,
778 .attrs = reipl_fcp_attrs,
786 static void reipl_get_ascii_loadparm(
char *loadparm,
800 reipl_get_ascii_loadparm(buf, ipb);
801 return sprintf(page,
"%s\n", buf);
805 const char *buf,
size_t len)
811 if ((len > 0) && (buf[len - 1] ==
'\n'))
814 if ((lp_len >
LOADPARM_LEN) || ((lp_len > 0) && (buf[0] ==
' ')))
817 for (i = 0; i < lp_len; i++) {
835 return reipl_generic_loadparm_show(reipl_block_nss, page);
840 const char *buf,
size_t len)
842 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
849 return reipl_generic_loadparm_show(reipl_block_ccw, page);
854 const char *buf,
size_t len)
856 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
861 reipl_ccw_loadparm_store);
863 static struct attribute *reipl_ccw_attrs_vm[] = {
864 &sys_reipl_ccw_device_attr.attr,
865 &sys_reipl_ccw_loadparm_attr.
attr,
866 &sys_reipl_ccw_vmparm_attr.
attr,
870 static struct attribute *reipl_ccw_attrs_lpar[] = {
871 &sys_reipl_ccw_device_attr.attr,
872 &sys_reipl_ccw_loadparm_attr.
attr,
878 .attrs = reipl_ccw_attrs_vm,
883 .attrs = reipl_ccw_attrs_lpar,
888 static void reipl_get_ascii_nss_name(
char *
dst,
901 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
902 return sprintf(page,
"%s\n", nss_name);
907 const char *buf,
size_t len)
913 if ((len > 0) && (buf[len - 1] ==
'\n'))
936 reipl_nss_name_store);
940 reipl_nss_loadparm_store);
942 static struct attribute *reipl_nss_attrs[] = {
943 &sys_reipl_nss_name_attr.
attr,
944 &sys_reipl_nss_loadparm_attr.
attr,
945 &sys_reipl_nss_vmparm_attr.
attr,
951 .attrs = reipl_nss_attrs,
956 reipl_block_actual = reipl_block;
958 reipl_block->
hdr.len);
965 if (!(reipl_capabilities & type))
970 if (diag308_set_works)
976 set_reipl_block_actual(reipl_block_ccw);
979 if (diag308_set_works)
985 set_reipl_block_actual(reipl_block_fcp);
991 if (diag308_set_works)
995 set_reipl_block_actual(reipl_block_nss);
1010 return sprintf(page,
"%s\n", ipl_type_str(reipl_type));
1015 const char *buf,
size_t len)
1025 return (rc != 0) ? rc : len;
1029 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1031 static struct kset *reipl_kset;
1032 static struct kset *reipl_fcp_kset;
1042 reipl_get_ascii_loadparm(loadparm, ipb);
1043 reipl_get_ascii_nss_name(nss_name, ipb);
1044 reipl_get_ascii_vmparm(vmparm,
sizeof(vmparm), ipb);
1051 pos =
sprintf(dst,
"IPL %s", nss_name);
1056 if (
strlen(loadparm) > 0)
1057 pos +=
sprintf(dst + pos,
" LOADPARM '%s'", loadparm);
1059 sprintf(dst + pos,
" PARM %s", vmparm);
1062 static void __reipl_run(
void *unused)
1065 static char buf[128];
1067 switch (reipl_method) {
1107 disabled_wait((
unsigned long) __builtin_return_address(0));
1141 ipl_block.ipl_info.ccw.vm_parm_len;
1147 static int __init reipl_nss_init(
void)
1155 if (!reipl_block_nss)
1158 if (!diag308_set_works)
1165 reipl_block_ccw_init(reipl_block_nss);
1175 reipl_block_ccw_fill_parms(reipl_block_nss);
1182 static int __init reipl_ccw_init(
void)
1187 if (!reipl_block_ccw)
1191 if (!diag308_set_works)
1194 &reipl_ccw_attr_group_vm);
1196 if(!diag308_set_works)
1199 &reipl_ccw_attr_group_lpar);
1204 reipl_block_ccw_init(reipl_block_ccw);
1207 reipl_block_ccw_fill_parms(reipl_block_ccw);
1214 static int __init reipl_fcp_init(
void)
1218 if (!diag308_set_works) {
1220 make_attrs_ro(reipl_fcp_attrs);
1227 if (!reipl_block_fcp)
1233 if (!reipl_fcp_kset) {
1234 free_page((
unsigned long) reipl_block_fcp);
1241 free_page((
unsigned long) reipl_block_fcp);
1246 &sys_reipl_fcp_scp_data_attr);
1250 free_page((
unsigned long) reipl_block_fcp);
1267 static int __init reipl_type_init(
void)
1280 memcpy(reipl_block_fcp, reipl_block, size);
1283 memcpy(reipl_block_ccw, reipl_block, size);
1287 return reipl_set_type(reipl_type);
1290 static int __init reipl_init(
void)
1302 rc = reipl_ccw_init();
1305 rc = reipl_fcp_init();
1308 rc = reipl_nss_init();
1311 return reipl_type_init();
1337 static struct attribute *dump_fcp_attrs[] = {
1338 &sys_dump_fcp_device_attr.attr,
1339 &sys_dump_fcp_wwpn_attr.attr,
1340 &sys_dump_fcp_lun_attr.attr,
1341 &sys_dump_fcp_bootprog_attr.attr,
1342 &sys_dump_fcp_br_lba_attr.attr,
1348 .attrs = dump_fcp_attrs,
1356 static struct attribute *dump_ccw_attrs[] = {
1357 &sys_dump_ccw_device_attr.attr,
1363 .attrs = dump_ccw_attrs,
1368 static int dump_set_type(
enum dump_type type)
1370 if (!(dump_capabilities & type))
1374 if (diag308_set_works)
1394 return sprintf(page,
"%s\n", dump_type_str(dump_type));
1399 const char *buf,
size_t len)
1409 return (rc != 0) ? rc : len;
1413 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1415 static struct kset *dump_kset;
1417 static void __dump_run(
void *unused)
1420 static char buf[100];
1422 switch (dump_method) {
1455 static int __init dump_ccw_init(
void)
1460 if (!dump_block_ccw)
1464 free_page((
unsigned long)dump_block_ccw);
1475 static int __init dump_fcp_init(
void)
1481 if (!diag308_set_works)
1484 if (!dump_block_fcp)
1488 free_page((
unsigned long)dump_block_fcp);
1500 static int __init dump_init(
void)
1512 rc = dump_ccw_init();
1515 rc = dump_fcp_init();
1530 unsigned long ipib = (
unsigned long) reipl_block_actual;
1533 csum =
csum_partial(reipl_block_actual, reipl_block_actual->
hdr.len, 0);
1539 static int __init dump_reipl_init(
void)
1541 if (!diag308_set_works)
1549 .fn = dump_reipl_run,
1550 .init = dump_reipl_init,
1557 static char vmcmd_on_reboot[128];
1558 static char vmcmd_on_panic[128];
1559 static char vmcmd_on_halt[128];
1560 static char vmcmd_on_poff[128];
1561 static char vmcmd_on_restart[128];
1569 static struct attribute *vmcmd_attrs[] = {
1570 &sys_vmcmd_on_reboot_attr.attr,
1571 &sys_vmcmd_on_panic_attr.attr,
1572 &sys_vmcmd_on_halt_attr.attr,
1573 &sys_vmcmd_on_poff_attr.attr,
1574 &sys_vmcmd_on_restart_attr.attr,
1579 .attrs = vmcmd_attrs,
1582 static struct kset *vmcmd_kset;
1589 cmd = vmcmd_on_reboot;
1591 cmd = vmcmd_on_panic;
1593 cmd = vmcmd_on_halt;
1595 cmd = vmcmd_on_poff;
1597 cmd = vmcmd_on_restart;
1606 static int vmcmd_init(
void)
1617 vmcmd_run, vmcmd_init};
1627 disabled_wait((
unsigned long) __builtin_return_address(0));
1637 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1638 &vmcmd_action, &stop_action};
1639 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1645 static struct kset *shutdown_actions_kset;
1654 if (shutdown_actions_list[i]->init_rc) {
1655 return shutdown_actions_list[
i]->
init_rc;
1657 trigger->
action = shutdown_actions_list[
i];
1673 return sprintf(page,
"%s\n", on_reboot_trigger.
action->name);
1678 const char *buf,
size_t len)
1680 return set_trigger(buf, &on_reboot_trigger, len);
1684 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1686 static void do_machine_restart(
char *
__unused)
1689 on_reboot_trigger.
action->fn(&on_reboot_trigger);
1701 return sprintf(page,
"%s\n", on_panic_trigger.
action->name);
1706 const char *buf,
size_t len)
1708 return set_trigger(buf, &on_panic_trigger, len);
1712 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1714 static void do_panic(
void)
1717 on_panic_trigger.
action->fn(&on_panic_trigger);
1718 stop_run(&on_panic_trigger);
1729 return sprintf(page,
"%s\n", on_restart_trigger.
action->name);
1734 const char *buf,
size_t len)
1736 return set_trigger(buf, &on_restart_trigger, len);
1740 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1742 static void __do_restart(
void *ignore)
1746 #ifdef CONFIG_CRASH_DUMP
1749 on_restart_trigger.
action->fn(&on_restart_trigger);
1750 stop_run(&on_restart_trigger);
1773 const char *buf,
size_t len)
1775 return set_trigger(buf, &on_halt_trigger, len);
1779 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1782 static void do_machine_halt(
void)
1785 on_halt_trigger.
action->fn(&on_halt_trigger);
1786 stop_run(&on_halt_trigger);
1802 const char *buf,
size_t len)
1804 return set_trigger(buf, &on_poff_trigger, len);
1808 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1811 static void do_machine_power_off(
void)
1814 on_poff_trigger.
action->fn(&on_poff_trigger);
1815 stop_run(&on_poff_trigger);
1819 static void __init shutdown_triggers_init(
void)
1823 if (!shutdown_actions_kset)
1826 &on_reboot_attr.
attr))
1829 &on_panic_attr.
attr))
1832 &on_halt_attr.
attr))
1835 &on_poff_attr.
attr))
1838 &on_restart_attr.
attr))
1842 panic(
"shutdown_triggers_init failed\n");
1845 static void __init shutdown_actions_init(
void)
1850 if (!shutdown_actions_list[i]->
init)
1852 shutdown_actions_list[
i]->
init_rc =
1853 shutdown_actions_list[
i]->
init();
1857 static int __init s390_ipl_init(
void)
1860 shutdown_actions_init();
1861 shutdown_triggers_init();
1867 static void __init strncpy_skip_quote(
char *dst,
char *
src,
int n)
1872 for (sx = 0; src[
sx] != 0; sx++) {
1875 dst[dx++] = src[
sx];
1881 static int __init vmcmd_on_reboot_setup(
char *
str)
1885 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1886 vmcmd_on_reboot[127] = 0;
1887 on_reboot_trigger.
action = &vmcmd_action;
1890 __setup(
"vmreboot=", vmcmd_on_reboot_setup);
1892 static int __init vmcmd_on_panic_setup(
char *str)
1896 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1897 vmcmd_on_panic[127] = 0;
1898 on_panic_trigger.
action = &vmcmd_action;
1901 __setup(
"vmpanic=", vmcmd_on_panic_setup);
1903 static int __init vmcmd_on_halt_setup(
char *str)
1907 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1908 vmcmd_on_halt[127] = 0;
1909 on_halt_trigger.
action = &vmcmd_action;
1912 __setup(
"vmhalt=", vmcmd_on_halt_setup);
1914 static int __init vmcmd_on_poff_setup(
char *str)
1918 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1919 vmcmd_on_poff[127] = 0;
1920 on_poff_trigger.
action = &vmcmd_action;
1923 __setup(
"vmpoff=", vmcmd_on_poff_setup);
1933 .notifier_call = on_panic_notify,
1970 diag308_set_works = 1;
1981 ipl_devno = iplinfo.
devno;
1986 src = (
void *)(
unsigned long)
S390_lowcore.ipl_parmblock_ptr;
1998 list_add(&reset->
list, &rcall);
2011 static void do_reset_calls(
void)
2016 if (diag308_set_works) {
2031 lc = (
struct _lowcore *)(
unsigned long) store_prefix();
2037 dump_prefix_page = (
u32)(
unsigned long)
lc;