Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * arch/s390/kernel/ipl.c |
| 3 | * ipl/reipl/dump support for Linux on s390. |
| 4 | * |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 5 | * Copyright IBM Corp. 2005,2012 |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 6 | * Author(s): Michael Holzheu <holzheu@de.ibm.com> |
| 7 | * Heiko Carstens <heiko.carstens@de.ibm.com> |
| 8 | * Volker Sameske <sameske@de.ibm.com> |
| 9 | */ |
| 10 | |
| 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> |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 16 | #include <linux/ctype.h> |
Akinobu Mita | 0788fea | 2008-07-14 09:59:17 +0200 | [diff] [blame] | 17 | #include <linux/fs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/gfp.h> |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 19 | #include <linux/crash_dump.h> |
Michael Holzheu | 46b05d2 | 2007-02-21 10:55:21 +0100 | [diff] [blame] | 20 | #include <asm/ipl.h> |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 21 | #include <asm/smp.h> |
| 22 | #include <asm/setup.h> |
| 23 | #include <asm/cpcmd.h> |
| 24 | #include <asm/cio.h> |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 25 | #include <asm/ebcdic.h> |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 26 | #include <asm/reset.h> |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 27 | #include <asm/sclp.h> |
Frank Munzert | 159d1ff | 2009-03-26 15:24:45 +0100 | [diff] [blame] | 28 | #include <asm/checksum.h> |
Martin Schwidefsky | 638ad34 | 2011-10-30 15:17:13 +0100 | [diff] [blame] | 29 | #include "entry.h" |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 30 | |
| 31 | #define IPL_PARM_BLOCK_VERSION 0 |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 32 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 33 | #define IPL_UNKNOWN_STR "unknown" |
| 34 | #define IPL_CCW_STR "ccw" |
| 35 | #define IPL_FCP_STR "fcp" |
| 36 | #define IPL_FCP_DUMP_STR "fcp_dump" |
| 37 | #define IPL_NSS_STR "nss" |
Heiko Carstens | 615b04b | 2007-02-21 10:55:37 +0100 | [diff] [blame] | 38 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 39 | #define DUMP_CCW_STR "ccw" |
| 40 | #define DUMP_FCP_STR "fcp" |
| 41 | #define DUMP_NONE_STR "none" |
| 42 | |
| 43 | /* |
| 44 | * Four shutdown trigger types are supported: |
| 45 | * - panic |
| 46 | * - halt |
| 47 | * - power off |
| 48 | * - reipl |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 49 | * - restart |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 50 | */ |
| 51 | #define ON_PANIC_STR "on_panic" |
| 52 | #define ON_HALT_STR "on_halt" |
| 53 | #define ON_POFF_STR "on_poff" |
| 54 | #define ON_REIPL_STR "on_reboot" |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 55 | #define ON_RESTART_STR "on_restart" |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 56 | |
| 57 | struct shutdown_action; |
| 58 | struct shutdown_trigger { |
| 59 | char *name; |
| 60 | struct shutdown_action *action; |
| 61 | }; |
| 62 | |
| 63 | /* |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 64 | * The following shutdown action types are supported: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 65 | */ |
| 66 | #define SHUTDOWN_ACTION_IPL_STR "ipl" |
| 67 | #define SHUTDOWN_ACTION_REIPL_STR "reipl" |
| 68 | #define SHUTDOWN_ACTION_DUMP_STR "dump" |
| 69 | #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd" |
| 70 | #define SHUTDOWN_ACTION_STOP_STR "stop" |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 71 | #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl" |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 72 | |
| 73 | struct shutdown_action { |
| 74 | char *name; |
| 75 | void (*fn) (struct shutdown_trigger *trigger); |
| 76 | int (*init) (void); |
Frank Munzert | 8108881 | 2009-07-07 16:37:07 +0200 | [diff] [blame] | 77 | int init_rc; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 78 | }; |
| 79 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 80 | static char *ipl_type_str(enum ipl_type type) |
| 81 | { |
| 82 | switch (type) { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 83 | case IPL_TYPE_CCW: |
| 84 | return IPL_CCW_STR; |
| 85 | case IPL_TYPE_FCP: |
| 86 | return IPL_FCP_STR; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 87 | case IPL_TYPE_FCP_DUMP: |
| 88 | return IPL_FCP_DUMP_STR; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 89 | case IPL_TYPE_NSS: |
| 90 | return IPL_NSS_STR; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 91 | case IPL_TYPE_UNKNOWN: |
| 92 | default: |
| 93 | return IPL_UNKNOWN_STR; |
| 94 | } |
| 95 | } |
| 96 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 97 | enum dump_type { |
| 98 | DUMP_TYPE_NONE = 1, |
| 99 | DUMP_TYPE_CCW = 2, |
| 100 | DUMP_TYPE_FCP = 4, |
| 101 | }; |
| 102 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 103 | static char *dump_type_str(enum dump_type type) |
| 104 | { |
| 105 | switch (type) { |
| 106 | case DUMP_TYPE_NONE: |
| 107 | return DUMP_NONE_STR; |
| 108 | case DUMP_TYPE_CCW: |
| 109 | return DUMP_CCW_STR; |
| 110 | case DUMP_TYPE_FCP: |
| 111 | return DUMP_FCP_STR; |
| 112 | default: |
| 113 | return NULL; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Must be in data section since the bss section |
| 119 | * is not cleared when these are accessed. |
| 120 | */ |
| 121 | static u16 ipl_devno __attribute__((__section__(".data"))) = 0; |
| 122 | u32 ipl_flags __attribute__((__section__(".data"))) = 0; |
| 123 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 124 | enum ipl_method { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 125 | REIPL_METHOD_CCW_CIO, |
| 126 | REIPL_METHOD_CCW_DIAG, |
| 127 | REIPL_METHOD_CCW_VM, |
| 128 | REIPL_METHOD_FCP_RO_DIAG, |
| 129 | REIPL_METHOD_FCP_RW_DIAG, |
| 130 | REIPL_METHOD_FCP_RO_VM, |
| 131 | REIPL_METHOD_FCP_DUMP, |
| 132 | REIPL_METHOD_NSS, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 133 | REIPL_METHOD_NSS_DIAG, |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 134 | REIPL_METHOD_DEFAULT, |
| 135 | }; |
| 136 | |
| 137 | enum dump_method { |
| 138 | DUMP_METHOD_NONE, |
| 139 | DUMP_METHOD_CCW_CIO, |
| 140 | DUMP_METHOD_CCW_DIAG, |
| 141 | DUMP_METHOD_CCW_VM, |
| 142 | DUMP_METHOD_FCP_DIAG, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 145 | static int diag308_set_works = 0; |
| 146 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 147 | static struct ipl_parameter_block ipl_block; |
| 148 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 149 | static int reipl_capabilities = IPL_TYPE_UNKNOWN; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 150 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 151 | static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 152 | static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 153 | static struct ipl_parameter_block *reipl_block_fcp; |
| 154 | static struct ipl_parameter_block *reipl_block_ccw; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 155 | static struct ipl_parameter_block *reipl_block_nss; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 156 | static struct ipl_parameter_block *reipl_block_actual; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 157 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 158 | static int dump_capabilities = DUMP_TYPE_NONE; |
| 159 | static enum dump_type dump_type = DUMP_TYPE_NONE; |
| 160 | static enum dump_method dump_method = DUMP_METHOD_NONE; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 161 | static struct ipl_parameter_block *dump_block_fcp; |
| 162 | static struct ipl_parameter_block *dump_block_ccw; |
| 163 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 164 | static struct sclp_ipl_info sclp_ipl_info; |
| 165 | |
Michael Holzheu | 46b05d2 | 2007-02-21 10:55:21 +0100 | [diff] [blame] | 166 | int diag308(unsigned long subcode, void *addr) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 167 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 168 | register unsigned long _addr asm("0") = (unsigned long) addr; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 169 | register unsigned long _rc asm("1") = 0; |
| 170 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 171 | asm volatile( |
| 172 | " diag %0,%2,0x308\n" |
| 173 | "0:\n" |
| 174 | EX_TABLE(0b,0b) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 175 | : "+d" (_addr), "+d" (_rc) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 176 | : "d" (subcode) : "cc", "memory"); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 177 | return _rc; |
| 178 | } |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 179 | EXPORT_SYMBOL_GPL(diag308); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 180 | |
| 181 | /* SYSFS */ |
| 182 | |
| 183 | #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 184 | static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ |
| 185 | struct kobj_attribute *attr, \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 186 | char *page) \ |
| 187 | { \ |
| 188 | return sprintf(page, _format, _value); \ |
| 189 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 190 | static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 191 | __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL); |
| 192 | |
| 193 | #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 194 | static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ |
| 195 | struct kobj_attribute *attr, \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 196 | char *page) \ |
| 197 | { \ |
| 198 | return sprintf(page, _fmt_out, \ |
| 199 | (unsigned long long) _value); \ |
| 200 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 201 | static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ |
| 202 | struct kobj_attribute *attr, \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 203 | const char *buf, size_t len) \ |
| 204 | { \ |
| 205 | unsigned long long value; \ |
| 206 | if (sscanf(buf, _fmt_in, &value) != 1) \ |
| 207 | return -EINVAL; \ |
| 208 | _value = value; \ |
| 209 | return len; \ |
| 210 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 211 | static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 212 | __ATTR(_name,(S_IRUGO | S_IWUSR), \ |
| 213 | sys_##_prefix##_##_name##_show, \ |
| 214 | sys_##_prefix##_##_name##_store); |
| 215 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 216 | #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 217 | static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ |
| 218 | struct kobj_attribute *attr, \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 219 | char *page) \ |
| 220 | { \ |
| 221 | return sprintf(page, _fmt_out, _value); \ |
| 222 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 223 | static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ |
| 224 | struct kobj_attribute *attr, \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 225 | const char *buf, size_t len) \ |
| 226 | { \ |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 227 | strncpy(_value, buf, sizeof(_value) - 1); \ |
Heiko Carstens | 1d802e2 | 2009-12-18 17:43:27 +0100 | [diff] [blame] | 228 | strim(_value); \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 229 | return len; \ |
| 230 | } \ |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 231 | static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 232 | __ATTR(_name,(S_IRUGO | S_IWUSR), \ |
| 233 | sys_##_prefix##_##_name##_show, \ |
| 234 | sys_##_prefix##_##_name##_store); |
| 235 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 236 | static void make_attrs_ro(struct attribute **attrs) |
| 237 | { |
| 238 | while (*attrs) { |
| 239 | (*attrs)->mode = S_IRUGO; |
| 240 | attrs++; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * ipl section |
| 246 | */ |
| 247 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 248 | static __init enum ipl_type get_ipl_type(void) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 249 | { |
| 250 | struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; |
| 251 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 252 | if (ipl_flags & IPL_NSS_VALID) |
| 253 | return IPL_TYPE_NSS; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 254 | if (!(ipl_flags & IPL_DEVNO_VALID)) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 255 | return IPL_TYPE_UNKNOWN; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 256 | if (!(ipl_flags & IPL_PARMBLOCK_VALID)) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 257 | return IPL_TYPE_CCW; |
| 258 | if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION) |
| 259 | return IPL_TYPE_UNKNOWN; |
| 260 | if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP) |
| 261 | return IPL_TYPE_UNKNOWN; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 262 | if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP) |
| 263 | return IPL_TYPE_FCP_DUMP; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 264 | return IPL_TYPE_FCP; |
| 265 | } |
| 266 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 267 | struct ipl_info ipl_info; |
| 268 | EXPORT_SYMBOL_GPL(ipl_info); |
| 269 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 270 | static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 271 | char *page) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 272 | { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 273 | return sprintf(page, "%s\n", ipl_type_str(ipl_info.type)); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 276 | static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 277 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 278 | /* VM IPL PARM routines */ |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 279 | static size_t reipl_get_ascii_vmparm(char *dest, size_t size, |
| 280 | const struct ipl_parameter_block *ipb) |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 281 | { |
| 282 | int i; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 283 | size_t len; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 284 | char has_lowercase = 0; |
| 285 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 286 | len = 0; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 287 | if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) && |
| 288 | (ipb->ipl_info.ccw.vm_parm_len > 0)) { |
| 289 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 290 | len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 291 | memcpy(dest, ipb->ipl_info.ccw.vm_parm, len); |
| 292 | /* If at least one character is lowercase, we assume mixed |
| 293 | * case; otherwise we convert everything to lowercase. |
| 294 | */ |
| 295 | for (i = 0; i < len; i++) |
| 296 | if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */ |
| 297 | (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */ |
| 298 | (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */ |
| 299 | has_lowercase = 1; |
| 300 | break; |
| 301 | } |
| 302 | if (!has_lowercase) |
| 303 | EBC_TOLOWER(dest, len); |
| 304 | EBCASC(dest, len); |
| 305 | } |
| 306 | dest[len] = 0; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 307 | |
| 308 | return len; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 311 | size_t append_ipl_vmparm(char *dest, size_t size) |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 312 | { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 313 | size_t rc; |
| 314 | |
| 315 | rc = 0; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 316 | if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW)) |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 317 | rc = reipl_get_ascii_vmparm(dest, size, &ipl_block); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 318 | else |
| 319 | dest[0] = 0; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 320 | return rc; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static ssize_t ipl_vm_parm_show(struct kobject *kobj, |
| 324 | struct kobj_attribute *attr, char *page) |
| 325 | { |
| 326 | char parm[DIAG308_VMPARM_SIZE + 1] = {}; |
| 327 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 328 | append_ipl_vmparm(parm, sizeof(parm)); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 329 | return sprintf(page, "%s\n", parm); |
| 330 | } |
| 331 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 332 | static size_t scpdata_length(const char* buf, size_t count) |
| 333 | { |
| 334 | while (count) { |
| 335 | if (buf[count - 1] != '\0' && buf[count - 1] != ' ') |
| 336 | break; |
| 337 | count--; |
| 338 | } |
| 339 | return count; |
| 340 | } |
| 341 | |
Martin Schwidefsky | c4736d9 | 2011-10-30 15:17:11 +0100 | [diff] [blame] | 342 | static size_t reipl_append_ascii_scpdata(char *dest, size_t size, |
| 343 | const struct ipl_parameter_block *ipb) |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 344 | { |
| 345 | size_t count; |
| 346 | size_t i; |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 347 | int has_lowercase; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 348 | |
| 349 | count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data, |
| 350 | ipb->ipl_info.fcp.scp_data_len)); |
| 351 | if (!count) |
| 352 | goto out; |
| 353 | |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 354 | has_lowercase = 0; |
| 355 | for (i = 0; i < count; i++) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 356 | if (!isascii(ipb->ipl_info.fcp.scp_data[i])) { |
| 357 | count = 0; |
| 358 | goto out; |
| 359 | } |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 360 | if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i])) |
| 361 | has_lowercase = 1; |
| 362 | } |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 363 | |
Hendrik Brueckner | 18d00ac | 2009-09-11 10:28:41 +0200 | [diff] [blame] | 364 | if (has_lowercase) |
| 365 | memcpy(dest, ipb->ipl_info.fcp.scp_data, count); |
| 366 | else |
| 367 | for (i = 0; i < count; i++) |
| 368 | dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 369 | out: |
| 370 | dest[count] = '\0'; |
| 371 | return count; |
| 372 | } |
| 373 | |
| 374 | size_t append_ipl_scpdata(char *dest, size_t len) |
| 375 | { |
| 376 | size_t rc; |
| 377 | |
| 378 | rc = 0; |
| 379 | if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP) |
| 380 | rc = reipl_append_ascii_scpdata(dest, len, &ipl_block); |
| 381 | else |
| 382 | dest[0] = 0; |
| 383 | return rc; |
| 384 | } |
| 385 | |
| 386 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 387 | static struct kobj_attribute sys_ipl_vm_parm_attr = |
| 388 | __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL); |
| 389 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 390 | static ssize_t sys_ipl_device_show(struct kobject *kobj, |
| 391 | struct kobj_attribute *attr, char *page) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 392 | { |
| 393 | struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; |
| 394 | |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 395 | switch (ipl_info.type) { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 396 | case IPL_TYPE_CCW: |
| 397 | return sprintf(page, "0.0.%04x\n", ipl_devno); |
| 398 | case IPL_TYPE_FCP: |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 399 | case IPL_TYPE_FCP_DUMP: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 400 | return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno); |
| 401 | default: |
| 402 | return 0; |
| 403 | } |
| 404 | } |
| 405 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 406 | static struct kobj_attribute sys_ipl_device_attr = |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 407 | __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL); |
| 408 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 409 | static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj, |
| 410 | struct bin_attribute *attr, char *buf, |
| 411 | loff_t off, size_t count) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 412 | { |
Akinobu Mita | 0788fea | 2008-07-14 09:59:17 +0200 | [diff] [blame] | 413 | return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START, |
| 414 | IPL_PARMBLOCK_SIZE); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static struct bin_attribute ipl_parameter_attr = { |
| 418 | .attr = { |
| 419 | .name = "binary_parameter", |
| 420 | .mode = S_IRUGO, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 421 | }, |
| 422 | .size = PAGE_SIZE, |
| 423 | .read = &ipl_parameter_read, |
| 424 | }; |
| 425 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 426 | static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj, |
| 427 | struct bin_attribute *attr, char *buf, |
| 428 | loff_t off, size_t count) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 429 | { |
| 430 | unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len; |
| 431 | void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data; |
| 432 | |
Akinobu Mita | 0788fea | 2008-07-14 09:59:17 +0200 | [diff] [blame] | 433 | return memory_read_from_buffer(buf, count, &off, scp_data, size); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static struct bin_attribute ipl_scp_data_attr = { |
| 437 | .attr = { |
| 438 | .name = "scp_data", |
| 439 | .mode = S_IRUGO, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 440 | }, |
| 441 | .size = PAGE_SIZE, |
Al Viro | 05bd711 | 2007-07-15 21:01:22 +0100 | [diff] [blame] | 442 | .read = ipl_scp_data_read, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 443 | }; |
| 444 | |
| 445 | /* FCP ipl device attributes */ |
| 446 | |
| 447 | DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long) |
| 448 | IPL_PARMBLOCK_START->ipl_info.fcp.wwpn); |
| 449 | DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long) |
| 450 | IPL_PARMBLOCK_START->ipl_info.fcp.lun); |
| 451 | DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long) |
| 452 | IPL_PARMBLOCK_START->ipl_info.fcp.bootprog); |
| 453 | DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long) |
| 454 | IPL_PARMBLOCK_START->ipl_info.fcp.br_lba); |
| 455 | |
| 456 | static struct attribute *ipl_fcp_attrs[] = { |
| 457 | &sys_ipl_type_attr.attr, |
| 458 | &sys_ipl_device_attr.attr, |
| 459 | &sys_ipl_fcp_wwpn_attr.attr, |
| 460 | &sys_ipl_fcp_lun_attr.attr, |
| 461 | &sys_ipl_fcp_bootprog_attr.attr, |
| 462 | &sys_ipl_fcp_br_lba_attr.attr, |
| 463 | NULL, |
| 464 | }; |
| 465 | |
| 466 | static struct attribute_group ipl_fcp_attr_group = { |
| 467 | .attrs = ipl_fcp_attrs, |
| 468 | }; |
| 469 | |
| 470 | /* CCW ipl device attributes */ |
| 471 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 472 | static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj, |
| 473 | struct kobj_attribute *attr, char *page) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 474 | { |
| 475 | char loadparm[LOADPARM_LEN + 1] = {}; |
| 476 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 477 | if (!sclp_ipl_info.is_valid) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 478 | return sprintf(page, "#unknown#\n"); |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 479 | memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 480 | EBCASC(loadparm, LOADPARM_LEN); |
Heiko Carstens | 1d802e2 | 2009-12-18 17:43:27 +0100 | [diff] [blame] | 481 | strim(loadparm); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 482 | return sprintf(page, "%s\n", loadparm); |
| 483 | } |
| 484 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 485 | static struct kobj_attribute sys_ipl_ccw_loadparm_attr = |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 486 | __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL); |
| 487 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 488 | static struct attribute *ipl_ccw_attrs_vm[] = { |
| 489 | &sys_ipl_type_attr.attr, |
| 490 | &sys_ipl_device_attr.attr, |
| 491 | &sys_ipl_ccw_loadparm_attr.attr, |
| 492 | &sys_ipl_vm_parm_attr.attr, |
| 493 | NULL, |
| 494 | }; |
| 495 | |
| 496 | static struct attribute *ipl_ccw_attrs_lpar[] = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 497 | &sys_ipl_type_attr.attr, |
| 498 | &sys_ipl_device_attr.attr, |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 499 | &sys_ipl_ccw_loadparm_attr.attr, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 500 | NULL, |
| 501 | }; |
| 502 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 503 | static struct attribute_group ipl_ccw_attr_group_vm = { |
| 504 | .attrs = ipl_ccw_attrs_vm, |
| 505 | }; |
| 506 | |
| 507 | static struct attribute_group ipl_ccw_attr_group_lpar = { |
| 508 | .attrs = ipl_ccw_attrs_lpar |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 509 | }; |
| 510 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 511 | /* NSS ipl device attributes */ |
| 512 | |
| 513 | DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name); |
| 514 | |
| 515 | static struct attribute *ipl_nss_attrs[] = { |
| 516 | &sys_ipl_type_attr.attr, |
| 517 | &sys_ipl_nss_name_attr.attr, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 518 | &sys_ipl_ccw_loadparm_attr.attr, |
| 519 | &sys_ipl_vm_parm_attr.attr, |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 520 | NULL, |
| 521 | }; |
| 522 | |
| 523 | static struct attribute_group ipl_nss_attr_group = { |
| 524 | .attrs = ipl_nss_attrs, |
| 525 | }; |
| 526 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 527 | /* UNKNOWN ipl device attributes */ |
| 528 | |
| 529 | static struct attribute *ipl_unknown_attrs[] = { |
| 530 | &sys_ipl_type_attr.attr, |
| 531 | NULL, |
| 532 | }; |
| 533 | |
| 534 | static struct attribute_group ipl_unknown_attr_group = { |
| 535 | .attrs = ipl_unknown_attrs, |
| 536 | }; |
| 537 | |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 538 | static struct kset *ipl_kset; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 539 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 540 | static int __init ipl_register_fcp_files(void) |
| 541 | { |
| 542 | int rc; |
| 543 | |
| 544 | rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group); |
| 545 | if (rc) |
| 546 | goto out; |
| 547 | rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr); |
| 548 | if (rc) |
| 549 | goto out_ipl_parm; |
| 550 | rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr); |
| 551 | if (!rc) |
| 552 | goto out; |
| 553 | |
| 554 | sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr); |
| 555 | |
| 556 | out_ipl_parm: |
| 557 | sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group); |
| 558 | out: |
| 559 | return rc; |
| 560 | } |
| 561 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 562 | static void __ipl_run(void *unused) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 563 | { |
| 564 | diag308(DIAG308_IPL, NULL); |
| 565 | if (MACHINE_IS_VM) |
| 566 | __cpcmd("IPL", NULL, 0, NULL); |
| 567 | else if (ipl_info.type == IPL_TYPE_CCW) |
| 568 | reipl_ccw_dev(&ipl_info.data.ccw.dev_id); |
| 569 | } |
| 570 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 571 | static void ipl_run(struct shutdown_trigger *trigger) |
| 572 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 573 | smp_call_ipl_cpu(__ipl_run, NULL); |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 574 | } |
| 575 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 576 | static int __init ipl_init(void) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 577 | { |
| 578 | int rc; |
| 579 | |
| 580 | ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj); |
| 581 | if (!ipl_kset) { |
| 582 | rc = -ENOMEM; |
| 583 | goto out; |
| 584 | } |
| 585 | switch (ipl_info.type) { |
| 586 | case IPL_TYPE_CCW: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 587 | if (MACHINE_IS_VM) |
| 588 | rc = sysfs_create_group(&ipl_kset->kobj, |
| 589 | &ipl_ccw_attr_group_vm); |
| 590 | else |
| 591 | rc = sysfs_create_group(&ipl_kset->kobj, |
| 592 | &ipl_ccw_attr_group_lpar); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 593 | break; |
| 594 | case IPL_TYPE_FCP: |
| 595 | case IPL_TYPE_FCP_DUMP: |
| 596 | rc = ipl_register_fcp_files(); |
| 597 | break; |
| 598 | case IPL_TYPE_NSS: |
| 599 | rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group); |
| 600 | break; |
| 601 | default: |
| 602 | rc = sysfs_create_group(&ipl_kset->kobj, |
| 603 | &ipl_unknown_attr_group); |
| 604 | break; |
| 605 | } |
| 606 | out: |
| 607 | if (rc) |
| 608 | panic("ipl_init failed: rc = %i\n", rc); |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 613 | static struct shutdown_action __refdata ipl_action = { |
| 614 | .name = SHUTDOWN_ACTION_IPL_STR, |
| 615 | .fn = ipl_run, |
| 616 | .init = ipl_init, |
| 617 | }; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 618 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 619 | /* |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 620 | * reipl shutdown action: Reboot Linux on shutdown. |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 621 | */ |
| 622 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 623 | /* VM IPL PARM attributes */ |
| 624 | static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb, |
| 625 | char *page) |
| 626 | { |
| 627 | char vmparm[DIAG308_VMPARM_SIZE + 1] = {}; |
| 628 | |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 629 | reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 630 | return sprintf(page, "%s\n", vmparm); |
| 631 | } |
| 632 | |
| 633 | static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb, |
| 634 | size_t vmparm_max, |
| 635 | const char *buf, size_t len) |
| 636 | { |
| 637 | int i, ip_len; |
| 638 | |
| 639 | /* ignore trailing newline */ |
| 640 | ip_len = len; |
| 641 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 642 | ip_len--; |
| 643 | |
| 644 | if (ip_len > vmparm_max) |
| 645 | return -EINVAL; |
| 646 | |
| 647 | /* parm is used to store kernel options, check for common chars */ |
| 648 | for (i = 0; i < ip_len; i++) |
| 649 | if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i]))) |
| 650 | return -EINVAL; |
| 651 | |
| 652 | memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE); |
| 653 | ipb->ipl_info.ccw.vm_parm_len = ip_len; |
| 654 | if (ip_len > 0) { |
| 655 | ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID; |
| 656 | memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len); |
| 657 | ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len); |
| 658 | } else { |
| 659 | ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID; |
| 660 | } |
| 661 | |
| 662 | return len; |
| 663 | } |
| 664 | |
| 665 | /* NSS wrapper */ |
| 666 | static ssize_t reipl_nss_vmparm_show(struct kobject *kobj, |
| 667 | struct kobj_attribute *attr, char *page) |
| 668 | { |
| 669 | return reipl_generic_vmparm_show(reipl_block_nss, page); |
| 670 | } |
| 671 | |
| 672 | static ssize_t reipl_nss_vmparm_store(struct kobject *kobj, |
| 673 | struct kobj_attribute *attr, |
| 674 | const char *buf, size_t len) |
| 675 | { |
| 676 | return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len); |
| 677 | } |
| 678 | |
| 679 | /* CCW wrapper */ |
| 680 | static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj, |
| 681 | struct kobj_attribute *attr, char *page) |
| 682 | { |
| 683 | return reipl_generic_vmparm_show(reipl_block_ccw, page); |
| 684 | } |
| 685 | |
| 686 | static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj, |
| 687 | struct kobj_attribute *attr, |
| 688 | const char *buf, size_t len) |
| 689 | { |
| 690 | return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len); |
| 691 | } |
| 692 | |
| 693 | static struct kobj_attribute sys_reipl_nss_vmparm_attr = |
| 694 | __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show, |
| 695 | reipl_nss_vmparm_store); |
| 696 | static struct kobj_attribute sys_reipl_ccw_vmparm_attr = |
| 697 | __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show, |
| 698 | reipl_ccw_vmparm_store); |
| 699 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 700 | /* FCP reipl device attributes */ |
| 701 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 702 | static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj, |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 703 | struct bin_attribute *attr, |
| 704 | char *buf, loff_t off, size_t count) |
| 705 | { |
| 706 | size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len; |
| 707 | void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data; |
| 708 | |
| 709 | return memory_read_from_buffer(buf, count, &off, scp_data, size); |
| 710 | } |
| 711 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 712 | static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj, |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 713 | struct bin_attribute *attr, |
| 714 | char *buf, loff_t off, size_t count) |
| 715 | { |
| 716 | size_t padding; |
| 717 | size_t scpdata_len; |
| 718 | |
| 719 | if (off < 0) |
| 720 | return -EINVAL; |
| 721 | |
| 722 | if (off >= DIAG308_SCPDATA_SIZE) |
| 723 | return -ENOSPC; |
| 724 | |
| 725 | if (count > DIAG308_SCPDATA_SIZE - off) |
| 726 | count = DIAG308_SCPDATA_SIZE - off; |
| 727 | |
| 728 | memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count); |
| 729 | scpdata_len = off + count; |
| 730 | |
| 731 | if (scpdata_len % 8) { |
| 732 | padding = 8 - (scpdata_len % 8); |
| 733 | memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len, |
| 734 | 0, padding); |
| 735 | scpdata_len += padding; |
| 736 | } |
| 737 | |
| 738 | reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len; |
| 739 | reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len; |
| 740 | reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len; |
| 741 | |
| 742 | return count; |
| 743 | } |
| 744 | |
| 745 | static struct bin_attribute sys_reipl_fcp_scp_data_attr = { |
| 746 | .attr = { |
| 747 | .name = "scp_data", |
| 748 | .mode = S_IRUGO | S_IWUSR, |
| 749 | }, |
| 750 | .size = PAGE_SIZE, |
| 751 | .read = reipl_fcp_scpdata_read, |
| 752 | .write = reipl_fcp_scpdata_write, |
| 753 | }; |
| 754 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 755 | DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n", |
| 756 | reipl_block_fcp->ipl_info.fcp.wwpn); |
| 757 | DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n", |
| 758 | reipl_block_fcp->ipl_info.fcp.lun); |
| 759 | DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n", |
| 760 | reipl_block_fcp->ipl_info.fcp.bootprog); |
| 761 | DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n", |
| 762 | reipl_block_fcp->ipl_info.fcp.br_lba); |
| 763 | DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 764 | reipl_block_fcp->ipl_info.fcp.devno); |
| 765 | |
| 766 | static struct attribute *reipl_fcp_attrs[] = { |
| 767 | &sys_reipl_fcp_device_attr.attr, |
| 768 | &sys_reipl_fcp_wwpn_attr.attr, |
| 769 | &sys_reipl_fcp_lun_attr.attr, |
| 770 | &sys_reipl_fcp_bootprog_attr.attr, |
| 771 | &sys_reipl_fcp_br_lba_attr.attr, |
| 772 | NULL, |
| 773 | }; |
| 774 | |
| 775 | static struct attribute_group reipl_fcp_attr_group = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 776 | .attrs = reipl_fcp_attrs, |
| 777 | }; |
| 778 | |
| 779 | /* CCW reipl device attributes */ |
| 780 | |
| 781 | DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 782 | reipl_block_ccw->ipl_info.ccw.devno); |
| 783 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 784 | static void reipl_get_ascii_loadparm(char *loadparm, |
| 785 | struct ipl_parameter_block *ibp) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 786 | { |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 787 | memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 788 | EBCASC(loadparm, LOADPARM_LEN); |
| 789 | loadparm[LOADPARM_LEN] = 0; |
Heiko Carstens | 1d802e2 | 2009-12-18 17:43:27 +0100 | [diff] [blame] | 790 | strim(loadparm); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 791 | } |
| 792 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 793 | static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb, |
| 794 | char *page) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 795 | { |
| 796 | char buf[LOADPARM_LEN + 1]; |
| 797 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 798 | reipl_get_ascii_loadparm(buf, ipb); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 799 | return sprintf(page, "%s\n", buf); |
| 800 | } |
| 801 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 802 | static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb, |
| 803 | const char *buf, size_t len) |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 804 | { |
| 805 | int i, lp_len; |
| 806 | |
| 807 | /* ignore trailing newline */ |
| 808 | lp_len = len; |
| 809 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 810 | lp_len--; |
| 811 | /* loadparm can have max 8 characters and must not start with a blank */ |
| 812 | if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' '))) |
| 813 | return -EINVAL; |
| 814 | /* loadparm can only contain "a-z,A-Z,0-9,SP,." */ |
| 815 | for (i = 0; i < lp_len; i++) { |
| 816 | if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') || |
| 817 | (buf[i] == '.')) |
| 818 | continue; |
| 819 | return -EINVAL; |
| 820 | } |
| 821 | /* initialize loadparm with blanks */ |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 822 | memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 823 | /* copy and convert to ebcdic */ |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 824 | memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len); |
| 825 | ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN); |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 826 | return len; |
| 827 | } |
| 828 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 829 | /* NSS wrapper */ |
| 830 | static ssize_t reipl_nss_loadparm_show(struct kobject *kobj, |
| 831 | struct kobj_attribute *attr, char *page) |
| 832 | { |
| 833 | return reipl_generic_loadparm_show(reipl_block_nss, page); |
| 834 | } |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 835 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 836 | static ssize_t reipl_nss_loadparm_store(struct kobject *kobj, |
| 837 | struct kobj_attribute *attr, |
| 838 | const char *buf, size_t len) |
| 839 | { |
| 840 | return reipl_generic_loadparm_store(reipl_block_nss, buf, len); |
| 841 | } |
| 842 | |
| 843 | /* CCW wrapper */ |
| 844 | static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj, |
| 845 | struct kobj_attribute *attr, char *page) |
| 846 | { |
| 847 | return reipl_generic_loadparm_show(reipl_block_ccw, page); |
| 848 | } |
| 849 | |
| 850 | static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj, |
| 851 | struct kobj_attribute *attr, |
| 852 | const char *buf, size_t len) |
| 853 | { |
| 854 | return reipl_generic_loadparm_store(reipl_block_ccw, buf, len); |
| 855 | } |
| 856 | |
| 857 | static struct kobj_attribute sys_reipl_ccw_loadparm_attr = |
| 858 | __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show, |
| 859 | reipl_ccw_loadparm_store); |
| 860 | |
| 861 | static struct attribute *reipl_ccw_attrs_vm[] = { |
| 862 | &sys_reipl_ccw_device_attr.attr, |
| 863 | &sys_reipl_ccw_loadparm_attr.attr, |
| 864 | &sys_reipl_ccw_vmparm_attr.attr, |
| 865 | NULL, |
| 866 | }; |
| 867 | |
| 868 | static struct attribute *reipl_ccw_attrs_lpar[] = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 869 | &sys_reipl_ccw_device_attr.attr, |
Michael Holzheu | 03a4d20 | 2006-12-04 15:39:58 +0100 | [diff] [blame] | 870 | &sys_reipl_ccw_loadparm_attr.attr, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 871 | NULL, |
| 872 | }; |
| 873 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 874 | static struct attribute_group reipl_ccw_attr_group_vm = { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 875 | .name = IPL_CCW_STR, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 876 | .attrs = reipl_ccw_attrs_vm, |
| 877 | }; |
| 878 | |
| 879 | static struct attribute_group reipl_ccw_attr_group_lpar = { |
| 880 | .name = IPL_CCW_STR, |
| 881 | .attrs = reipl_ccw_attrs_lpar, |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 882 | }; |
| 883 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 884 | |
| 885 | /* NSS reipl device attributes */ |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 886 | static void reipl_get_ascii_nss_name(char *dst, |
| 887 | struct ipl_parameter_block *ipb) |
| 888 | { |
| 889 | memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE); |
| 890 | EBCASC(dst, NSS_NAME_SIZE); |
| 891 | dst[NSS_NAME_SIZE] = 0; |
| 892 | } |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 893 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 894 | static ssize_t reipl_nss_name_show(struct kobject *kobj, |
| 895 | struct kobj_attribute *attr, char *page) |
| 896 | { |
| 897 | char nss_name[NSS_NAME_SIZE + 1] = {}; |
| 898 | |
| 899 | reipl_get_ascii_nss_name(nss_name, reipl_block_nss); |
| 900 | return sprintf(page, "%s\n", nss_name); |
| 901 | } |
| 902 | |
| 903 | static ssize_t reipl_nss_name_store(struct kobject *kobj, |
| 904 | struct kobj_attribute *attr, |
| 905 | const char *buf, size_t len) |
| 906 | { |
| 907 | int nss_len; |
| 908 | |
| 909 | /* ignore trailing newline */ |
| 910 | nss_len = len; |
| 911 | if ((len > 0) && (buf[len - 1] == '\n')) |
| 912 | nss_len--; |
| 913 | |
| 914 | if (nss_len > NSS_NAME_SIZE) |
| 915 | return -EINVAL; |
| 916 | |
| 917 | memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE); |
| 918 | if (nss_len > 0) { |
| 919 | reipl_block_nss->ipl_info.ccw.vm_flags |= |
| 920 | DIAG308_VM_FLAGS_NSS_VALID; |
| 921 | memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len); |
| 922 | ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len); |
| 923 | EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len); |
| 924 | } else { |
| 925 | reipl_block_nss->ipl_info.ccw.vm_flags &= |
| 926 | ~DIAG308_VM_FLAGS_NSS_VALID; |
| 927 | } |
| 928 | |
| 929 | return len; |
| 930 | } |
| 931 | |
| 932 | static struct kobj_attribute sys_reipl_nss_name_attr = |
| 933 | __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show, |
| 934 | reipl_nss_name_store); |
| 935 | |
| 936 | static struct kobj_attribute sys_reipl_nss_loadparm_attr = |
| 937 | __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show, |
| 938 | reipl_nss_loadparm_store); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 939 | |
| 940 | static struct attribute *reipl_nss_attrs[] = { |
| 941 | &sys_reipl_nss_name_attr.attr, |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 942 | &sys_reipl_nss_loadparm_attr.attr, |
| 943 | &sys_reipl_nss_vmparm_attr.attr, |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 944 | NULL, |
| 945 | }; |
| 946 | |
| 947 | static struct attribute_group reipl_nss_attr_group = { |
| 948 | .name = IPL_NSS_STR, |
| 949 | .attrs = reipl_nss_attrs, |
| 950 | }; |
| 951 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 952 | /* reipl type */ |
| 953 | |
| 954 | static int reipl_set_type(enum ipl_type type) |
| 955 | { |
| 956 | if (!(reipl_capabilities & type)) |
| 957 | return -EINVAL; |
| 958 | |
| 959 | switch(type) { |
| 960 | case IPL_TYPE_CCW: |
Michael Holzheu | 48657d2 | 2008-01-26 14:11:17 +0100 | [diff] [blame] | 961 | if (diag308_set_works) |
| 962 | reipl_method = REIPL_METHOD_CCW_DIAG; |
| 963 | else if (MACHINE_IS_VM) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 964 | reipl_method = REIPL_METHOD_CCW_VM; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 965 | else |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 966 | reipl_method = REIPL_METHOD_CCW_CIO; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 967 | reipl_block_actual = reipl_block_ccw; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 968 | break; |
| 969 | case IPL_TYPE_FCP: |
| 970 | if (diag308_set_works) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 971 | reipl_method = REIPL_METHOD_FCP_RW_DIAG; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 972 | else if (MACHINE_IS_VM) |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 973 | reipl_method = REIPL_METHOD_FCP_RO_VM; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 974 | else |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 975 | reipl_method = REIPL_METHOD_FCP_RO_DIAG; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 976 | reipl_block_actual = reipl_block_fcp; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 977 | break; |
| 978 | case IPL_TYPE_FCP_DUMP: |
| 979 | reipl_method = REIPL_METHOD_FCP_DUMP; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 980 | break; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 981 | case IPL_TYPE_NSS: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 982 | if (diag308_set_works) |
| 983 | reipl_method = REIPL_METHOD_NSS_DIAG; |
| 984 | else |
| 985 | reipl_method = REIPL_METHOD_NSS; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 986 | reipl_block_actual = reipl_block_nss; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 987 | break; |
| 988 | case IPL_TYPE_UNKNOWN: |
| 989 | reipl_method = REIPL_METHOD_DEFAULT; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 990 | break; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 991 | default: |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 992 | BUG(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 993 | } |
| 994 | reipl_type = type; |
| 995 | return 0; |
| 996 | } |
| 997 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 998 | static ssize_t reipl_type_show(struct kobject *kobj, |
| 999 | struct kobj_attribute *attr, char *page) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1000 | { |
| 1001 | return sprintf(page, "%s\n", ipl_type_str(reipl_type)); |
| 1002 | } |
| 1003 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1004 | static ssize_t reipl_type_store(struct kobject *kobj, |
| 1005 | struct kobj_attribute *attr, |
| 1006 | const char *buf, size_t len) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1007 | { |
| 1008 | int rc = -EINVAL; |
| 1009 | |
| 1010 | if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0) |
| 1011 | rc = reipl_set_type(IPL_TYPE_CCW); |
| 1012 | else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0) |
| 1013 | rc = reipl_set_type(IPL_TYPE_FCP); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1014 | else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0) |
| 1015 | rc = reipl_set_type(IPL_TYPE_NSS); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1016 | return (rc != 0) ? rc : len; |
| 1017 | } |
| 1018 | |
Greg Kroah-Hartman | 9b94916 | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1019 | static struct kobj_attribute reipl_type_attr = |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1020 | __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1021 | |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1022 | static struct kset *reipl_kset; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1023 | static struct kset *reipl_fcp_kset; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1024 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1025 | static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb, |
| 1026 | const enum ipl_method m) |
| 1027 | { |
| 1028 | char loadparm[LOADPARM_LEN + 1] = {}; |
| 1029 | char vmparm[DIAG308_VMPARM_SIZE + 1] = {}; |
| 1030 | char nss_name[NSS_NAME_SIZE + 1] = {}; |
| 1031 | size_t pos = 0; |
| 1032 | |
| 1033 | reipl_get_ascii_loadparm(loadparm, ipb); |
| 1034 | reipl_get_ascii_nss_name(nss_name, ipb); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1035 | reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb); |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1036 | |
| 1037 | switch (m) { |
| 1038 | case REIPL_METHOD_CCW_VM: |
| 1039 | pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno); |
| 1040 | break; |
| 1041 | case REIPL_METHOD_NSS: |
| 1042 | pos = sprintf(dst, "IPL %s", nss_name); |
| 1043 | break; |
| 1044 | default: |
| 1045 | break; |
| 1046 | } |
| 1047 | if (strlen(loadparm) > 0) |
| 1048 | pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm); |
| 1049 | if (strlen(vmparm) > 0) |
| 1050 | sprintf(dst + pos, " PARM %s", vmparm); |
| 1051 | } |
| 1052 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1053 | static void __reipl_run(void *unused) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1054 | { |
| 1055 | struct ccw_dev_id devid; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1056 | static char buf[128]; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1057 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1058 | switch (reipl_method) { |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1059 | case REIPL_METHOD_CCW_CIO: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1060 | devid.devno = reipl_block_ccw->ipl_info.ccw.devno; |
| 1061 | devid.ssid = 0; |
| 1062 | reipl_ccw_dev(&devid); |
| 1063 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1064 | case REIPL_METHOD_CCW_VM: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1065 | get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM); |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame] | 1066 | __cpcmd(buf, NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1067 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1068 | case REIPL_METHOD_CCW_DIAG: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1069 | diag308(DIAG308_SET, reipl_block_ccw); |
| 1070 | diag308(DIAG308_IPL, NULL); |
| 1071 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1072 | case REIPL_METHOD_FCP_RW_DIAG: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1073 | diag308(DIAG308_SET, reipl_block_fcp); |
| 1074 | diag308(DIAG308_IPL, NULL); |
| 1075 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1076 | case REIPL_METHOD_FCP_RO_DIAG: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1077 | diag308(DIAG308_IPL, NULL); |
| 1078 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1079 | case REIPL_METHOD_FCP_RO_VM: |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame] | 1080 | __cpcmd("IPL", NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1081 | break; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1082 | case REIPL_METHOD_NSS_DIAG: |
| 1083 | diag308(DIAG308_SET, reipl_block_nss); |
| 1084 | diag308(DIAG308_IPL, NULL); |
| 1085 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1086 | case REIPL_METHOD_NSS: |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1087 | get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1088 | __cpcmd(buf, NULL, 0, NULL); |
| 1089 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1090 | case REIPL_METHOD_DEFAULT: |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1091 | if (MACHINE_IS_VM) |
Heiko Carstens | 740b570 | 2006-12-04 15:40:30 +0100 | [diff] [blame] | 1092 | __cpcmd("IPL", NULL, 0, NULL); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1093 | diag308(DIAG308_IPL, NULL); |
| 1094 | break; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1095 | case REIPL_METHOD_FCP_DUMP: |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1096 | break; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1097 | } |
Michael Holzheu | 208e559 | 2008-03-05 12:37:15 +0100 | [diff] [blame] | 1098 | disabled_wait((unsigned long) __builtin_return_address(0)); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1101 | static void reipl_run(struct shutdown_trigger *trigger) |
| 1102 | { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1103 | smp_call_ipl_cpu(__reipl_run, NULL); |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1106 | static void reipl_block_ccw_init(struct ipl_parameter_block *ipb) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1107 | { |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1108 | ipb->hdr.len = IPL_PARM_BLK_CCW_LEN; |
| 1109 | ipb->hdr.version = IPL_PARM_BLOCK_VERSION; |
| 1110 | ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; |
| 1111 | ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW; |
| 1112 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1113 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1114 | static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb) |
| 1115 | { |
| 1116 | /* LOADPARM */ |
| 1117 | /* check if read scp info worked and set loadparm */ |
| 1118 | if (sclp_ipl_info.is_valid) |
| 1119 | memcpy(ipb->ipl_info.ccw.load_parm, |
| 1120 | &sclp_ipl_info.loadparm, LOADPARM_LEN); |
| 1121 | else |
| 1122 | /* read scp info failed: set empty loadparm (EBCDIC blanks) */ |
| 1123 | memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN); |
| 1124 | ipb->hdr.flags = DIAG308_FLAGS_LP_VALID; |
| 1125 | |
| 1126 | /* VM PARM */ |
| 1127 | if (MACHINE_IS_VM && diag308_set_works && |
| 1128 | (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) { |
| 1129 | |
| 1130 | ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID; |
| 1131 | ipb->ipl_info.ccw.vm_parm_len = |
| 1132 | ipl_block.ipl_info.ccw.vm_parm_len; |
| 1133 | memcpy(ipb->ipl_info.ccw.vm_parm, |
| 1134 | ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE); |
| 1135 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1136 | } |
| 1137 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1138 | static int __init reipl_nss_init(void) |
| 1139 | { |
| 1140 | int rc; |
| 1141 | |
| 1142 | if (!MACHINE_IS_VM) |
| 1143 | return 0; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1144 | |
| 1145 | reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL); |
| 1146 | if (!reipl_block_nss) |
| 1147 | return -ENOMEM; |
| 1148 | |
| 1149 | if (!diag308_set_works) |
| 1150 | sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO; |
| 1151 | |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1152 | rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group); |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1153 | if (rc) |
| 1154 | return rc; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1155 | |
| 1156 | reipl_block_ccw_init(reipl_block_nss); |
| 1157 | if (ipl_info.type == IPL_TYPE_NSS) { |
| 1158 | memset(reipl_block_nss->ipl_info.ccw.nss_name, |
| 1159 | ' ', NSS_NAME_SIZE); |
| 1160 | memcpy(reipl_block_nss->ipl_info.ccw.nss_name, |
| 1161 | kernel_nss_name, strlen(kernel_nss_name)); |
| 1162 | ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE); |
| 1163 | reipl_block_nss->ipl_info.ccw.vm_flags |= |
| 1164 | DIAG308_VM_FLAGS_NSS_VALID; |
| 1165 | |
| 1166 | reipl_block_ccw_fill_parms(reipl_block_nss); |
| 1167 | } |
| 1168 | |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1169 | reipl_capabilities |= IPL_TYPE_NSS; |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1173 | static int __init reipl_ccw_init(void) |
| 1174 | { |
| 1175 | int rc; |
| 1176 | |
| 1177 | reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); |
| 1178 | if (!reipl_block_ccw) |
| 1179 | return -ENOMEM; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1180 | |
| 1181 | if (MACHINE_IS_VM) { |
| 1182 | if (!diag308_set_works) |
| 1183 | sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO; |
| 1184 | rc = sysfs_create_group(&reipl_kset->kobj, |
| 1185 | &reipl_ccw_attr_group_vm); |
| 1186 | } else { |
| 1187 | if(!diag308_set_works) |
| 1188 | sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO; |
| 1189 | rc = sysfs_create_group(&reipl_kset->kobj, |
| 1190 | &reipl_ccw_attr_group_lpar); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1191 | } |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1192 | if (rc) |
| 1193 | return rc; |
| 1194 | |
| 1195 | reipl_block_ccw_init(reipl_block_ccw); |
| 1196 | if (ipl_info.type == IPL_TYPE_CCW) { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1197 | reipl_block_ccw->ipl_info.ccw.devno = ipl_devno; |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1198 | reipl_block_ccw_fill_parms(reipl_block_ccw); |
| 1199 | } |
| 1200 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1201 | reipl_capabilities |= IPL_TYPE_CCW; |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | static int __init reipl_fcp_init(void) |
| 1206 | { |
| 1207 | int rc; |
| 1208 | |
Michael Holzheu | 008d2d1 | 2009-03-26 15:24:51 +0100 | [diff] [blame] | 1209 | if (!diag308_set_works) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1210 | if (ipl_info.type == IPL_TYPE_FCP) { |
Michael Holzheu | 008d2d1 | 2009-03-26 15:24:51 +0100 | [diff] [blame] | 1211 | make_attrs_ro(reipl_fcp_attrs); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1212 | sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO; |
| 1213 | } else |
Michael Holzheu | 008d2d1 | 2009-03-26 15:24:51 +0100 | [diff] [blame] | 1214 | return 0; |
| 1215 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1216 | |
| 1217 | reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); |
| 1218 | if (!reipl_block_fcp) |
| 1219 | return -ENOMEM; |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1220 | |
| 1221 | /* sysfs: create fcp kset for mixing attr group and bin attrs */ |
| 1222 | reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL, |
| 1223 | &reipl_kset->kobj); |
Julia Lawall | 798620f | 2011-08-24 17:15:11 +0200 | [diff] [blame] | 1224 | if (!reipl_fcp_kset) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1225 | free_page((unsigned long) reipl_block_fcp); |
| 1226 | return -ENOMEM; |
| 1227 | } |
| 1228 | |
| 1229 | rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1230 | if (rc) { |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1231 | kset_unregister(reipl_fcp_kset); |
| 1232 | free_page((unsigned long) reipl_block_fcp); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1233 | return rc; |
| 1234 | } |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1235 | |
| 1236 | rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj, |
| 1237 | &sys_reipl_fcp_scp_data_attr); |
| 1238 | if (rc) { |
| 1239 | sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group); |
| 1240 | kset_unregister(reipl_fcp_kset); |
| 1241 | free_page((unsigned long) reipl_block_fcp); |
| 1242 | return rc; |
| 1243 | } |
| 1244 | |
| 1245 | if (ipl_info.type == IPL_TYPE_FCP) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1246 | memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE); |
Hendrik Brueckner | 684d2fd | 2009-09-11 10:28:40 +0200 | [diff] [blame] | 1247 | else { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1248 | reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; |
| 1249 | reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; |
Michael Holzheu | fbb04f3 | 2007-03-19 13:19:03 +0100 | [diff] [blame] | 1250 | reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1251 | reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; |
| 1252 | reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL; |
| 1253 | } |
| 1254 | reipl_capabilities |= IPL_TYPE_FCP; |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1258 | static int __init reipl_init(void) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1259 | { |
| 1260 | int rc; |
| 1261 | |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 1262 | reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj); |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1263 | if (!reipl_kset) |
| 1264 | return -ENOMEM; |
| 1265 | rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1266 | if (rc) { |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1267 | kset_unregister(reipl_kset); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1268 | return rc; |
| 1269 | } |
| 1270 | rc = reipl_ccw_init(); |
| 1271 | if (rc) |
| 1272 | return rc; |
| 1273 | rc = reipl_fcp_init(); |
| 1274 | if (rc) |
| 1275 | return rc; |
Hongjie Yang | fe355b7 | 2007-02-05 21:18:24 +0100 | [diff] [blame] | 1276 | rc = reipl_nss_init(); |
| 1277 | if (rc) |
| 1278 | return rc; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1279 | rc = reipl_set_type(ipl_info.type); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1280 | if (rc) |
| 1281 | return rc; |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1285 | static struct shutdown_action __refdata reipl_action = { |
| 1286 | .name = SHUTDOWN_ACTION_REIPL_STR, |
| 1287 | .fn = reipl_run, |
| 1288 | .init = reipl_init, |
| 1289 | }; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1290 | |
| 1291 | /* |
| 1292 | * dump shutdown action: Dump Linux on shutdown. |
| 1293 | */ |
| 1294 | |
| 1295 | /* FCP dump device attributes */ |
| 1296 | |
| 1297 | DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n", |
| 1298 | dump_block_fcp->ipl_info.fcp.wwpn); |
| 1299 | DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n", |
| 1300 | dump_block_fcp->ipl_info.fcp.lun); |
| 1301 | DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n", |
| 1302 | dump_block_fcp->ipl_info.fcp.bootprog); |
| 1303 | DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n", |
| 1304 | dump_block_fcp->ipl_info.fcp.br_lba); |
| 1305 | DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 1306 | dump_block_fcp->ipl_info.fcp.devno); |
| 1307 | |
| 1308 | static struct attribute *dump_fcp_attrs[] = { |
| 1309 | &sys_dump_fcp_device_attr.attr, |
| 1310 | &sys_dump_fcp_wwpn_attr.attr, |
| 1311 | &sys_dump_fcp_lun_attr.attr, |
| 1312 | &sys_dump_fcp_bootprog_attr.attr, |
| 1313 | &sys_dump_fcp_br_lba_attr.attr, |
| 1314 | NULL, |
| 1315 | }; |
| 1316 | |
| 1317 | static struct attribute_group dump_fcp_attr_group = { |
| 1318 | .name = IPL_FCP_STR, |
| 1319 | .attrs = dump_fcp_attrs, |
| 1320 | }; |
| 1321 | |
| 1322 | /* CCW dump device attributes */ |
| 1323 | |
| 1324 | DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", |
| 1325 | dump_block_ccw->ipl_info.ccw.devno); |
| 1326 | |
| 1327 | static struct attribute *dump_ccw_attrs[] = { |
| 1328 | &sys_dump_ccw_device_attr.attr, |
| 1329 | NULL, |
| 1330 | }; |
| 1331 | |
| 1332 | static struct attribute_group dump_ccw_attr_group = { |
| 1333 | .name = IPL_CCW_STR, |
| 1334 | .attrs = dump_ccw_attrs, |
| 1335 | }; |
| 1336 | |
| 1337 | /* dump type */ |
| 1338 | |
| 1339 | static int dump_set_type(enum dump_type type) |
| 1340 | { |
| 1341 | if (!(dump_capabilities & type)) |
| 1342 | return -EINVAL; |
| 1343 | switch (type) { |
| 1344 | case DUMP_TYPE_CCW: |
Michael Holzheu | 48657d2 | 2008-01-26 14:11:17 +0100 | [diff] [blame] | 1345 | if (diag308_set_works) |
| 1346 | dump_method = DUMP_METHOD_CCW_DIAG; |
| 1347 | else if (MACHINE_IS_VM) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1348 | dump_method = DUMP_METHOD_CCW_VM; |
| 1349 | else |
| 1350 | dump_method = DUMP_METHOD_CCW_CIO; |
| 1351 | break; |
| 1352 | case DUMP_TYPE_FCP: |
| 1353 | dump_method = DUMP_METHOD_FCP_DIAG; |
| 1354 | break; |
| 1355 | default: |
| 1356 | dump_method = DUMP_METHOD_NONE; |
| 1357 | } |
| 1358 | dump_type = type; |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
| 1362 | static ssize_t dump_type_show(struct kobject *kobj, |
| 1363 | struct kobj_attribute *attr, char *page) |
| 1364 | { |
| 1365 | return sprintf(page, "%s\n", dump_type_str(dump_type)); |
| 1366 | } |
| 1367 | |
| 1368 | static ssize_t dump_type_store(struct kobject *kobj, |
| 1369 | struct kobj_attribute *attr, |
| 1370 | const char *buf, size_t len) |
| 1371 | { |
| 1372 | int rc = -EINVAL; |
| 1373 | |
| 1374 | if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0) |
| 1375 | rc = dump_set_type(DUMP_TYPE_NONE); |
| 1376 | else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0) |
| 1377 | rc = dump_set_type(DUMP_TYPE_CCW); |
| 1378 | else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0) |
| 1379 | rc = dump_set_type(DUMP_TYPE_FCP); |
| 1380 | return (rc != 0) ? rc : len; |
| 1381 | } |
| 1382 | |
| 1383 | static struct kobj_attribute dump_type_attr = |
| 1384 | __ATTR(dump_type, 0644, dump_type_show, dump_type_store); |
| 1385 | |
| 1386 | static struct kset *dump_kset; |
| 1387 | |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1388 | static void __dump_run(void *unused) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1389 | { |
| 1390 | struct ccw_dev_id devid; |
| 1391 | static char buf[100]; |
| 1392 | |
| 1393 | switch (dump_method) { |
| 1394 | case DUMP_METHOD_CCW_CIO: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1395 | devid.devno = dump_block_ccw->ipl_info.ccw.devno; |
| 1396 | devid.ssid = 0; |
| 1397 | reipl_ccw_dev(&devid); |
| 1398 | break; |
| 1399 | case DUMP_METHOD_CCW_VM: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1400 | sprintf(buf, "STORE STATUS"); |
| 1401 | __cpcmd(buf, NULL, 0, NULL); |
| 1402 | sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno); |
| 1403 | __cpcmd(buf, NULL, 0, NULL); |
| 1404 | break; |
| 1405 | case DUMP_METHOD_CCW_DIAG: |
| 1406 | diag308(DIAG308_SET, dump_block_ccw); |
| 1407 | diag308(DIAG308_DUMP, NULL); |
| 1408 | break; |
| 1409 | case DUMP_METHOD_FCP_DIAG: |
| 1410 | diag308(DIAG308_SET, dump_block_fcp); |
| 1411 | diag308(DIAG308_DUMP, NULL); |
| 1412 | break; |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1413 | default: |
| 1414 | break; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1415 | } |
Heiko Carstens | 2c2df11 | 2010-02-26 22:37:34 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static void dump_run(struct shutdown_trigger *trigger) |
| 1419 | { |
| 1420 | if (dump_method == DUMP_METHOD_NONE) |
| 1421 | return; |
| 1422 | smp_send_stop(); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1423 | smp_call_ipl_cpu(__dump_run, NULL); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1426 | static int __init dump_ccw_init(void) |
| 1427 | { |
| 1428 | int rc; |
| 1429 | |
| 1430 | dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); |
| 1431 | if (!dump_block_ccw) |
| 1432 | return -ENOMEM; |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1433 | rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1434 | if (rc) { |
| 1435 | free_page((unsigned long)dump_block_ccw); |
| 1436 | return rc; |
| 1437 | } |
| 1438 | dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; |
| 1439 | dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; |
Michael Holzheu | fbb04f3 | 2007-03-19 13:19:03 +0100 | [diff] [blame] | 1440 | dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1441 | dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1442 | dump_capabilities |= DUMP_TYPE_CCW; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1443 | return 0; |
| 1444 | } |
| 1445 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1446 | static int __init dump_fcp_init(void) |
| 1447 | { |
| 1448 | int rc; |
| 1449 | |
Heiko Carstens | 05dd253 | 2007-07-10 11:24:09 +0200 | [diff] [blame] | 1450 | if (!sclp_ipl_info.has_dump) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1451 | return 0; /* LDIPL DUMP is not installed */ |
| 1452 | if (!diag308_set_works) |
| 1453 | return 0; |
| 1454 | dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); |
| 1455 | if (!dump_block_fcp) |
| 1456 | return -ENOMEM; |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1457 | rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1458 | if (rc) { |
| 1459 | free_page((unsigned long)dump_block_fcp); |
| 1460 | return rc; |
| 1461 | } |
| 1462 | dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; |
| 1463 | dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; |
Michael Holzheu | fbb04f3 | 2007-03-19 13:19:03 +0100 | [diff] [blame] | 1464 | dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1465 | dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; |
| 1466 | dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1467 | dump_capabilities |= DUMP_TYPE_FCP; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1468 | return 0; |
| 1469 | } |
| 1470 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1471 | static int __init dump_init(void) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1472 | { |
| 1473 | int rc; |
| 1474 | |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 1475 | dump_kset = kset_create_and_add("dump", NULL, firmware_kobj); |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1476 | if (!dump_kset) |
| 1477 | return -ENOMEM; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1478 | rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1479 | if (rc) { |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1480 | kset_unregister(dump_kset); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1481 | return rc; |
| 1482 | } |
| 1483 | rc = dump_ccw_init(); |
| 1484 | if (rc) |
| 1485 | return rc; |
| 1486 | rc = dump_fcp_init(); |
| 1487 | if (rc) |
| 1488 | return rc; |
Michael Holzheu | 411ed32 | 2007-04-27 16:01:49 +0200 | [diff] [blame] | 1489 | dump_set_type(DUMP_TYPE_NONE); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1490 | return 0; |
| 1491 | } |
| 1492 | |
Heiko Carstens | 2bc89b5 | 2008-02-05 16:50:40 +0100 | [diff] [blame] | 1493 | static struct shutdown_action __refdata dump_action = { |
| 1494 | .name = SHUTDOWN_ACTION_DUMP_STR, |
| 1495 | .fn = dump_run, |
| 1496 | .init = dump_init, |
| 1497 | }; |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1498 | |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1499 | static void dump_reipl_run(struct shutdown_trigger *trigger) |
| 1500 | { |
Michael Holzheu | b43445ff | 2012-03-11 11:59:28 -0400 | [diff] [blame^] | 1501 | u32 csum; |
| 1502 | |
| 1503 | csum = csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0); |
| 1504 | copy_to_absolute_zero(&S390_lowcore.ipib_checksum, &csum, sizeof(csum)); |
| 1505 | copy_to_absolute_zero(&S390_lowcore.ipib, &reipl_block_actual, |
| 1506 | sizeof(reipl_block_actual)); |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1507 | dump_run(trigger); |
| 1508 | } |
| 1509 | |
| 1510 | static int __init dump_reipl_init(void) |
| 1511 | { |
| 1512 | if (!diag308_set_works) |
| 1513 | return -EOPNOTSUPP; |
| 1514 | else |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static struct shutdown_action __refdata dump_reipl_action = { |
| 1519 | .name = SHUTDOWN_ACTION_DUMP_REIPL_STR, |
| 1520 | .fn = dump_reipl_run, |
| 1521 | .init = dump_reipl_init, |
| 1522 | }; |
| 1523 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1524 | /* |
| 1525 | * vmcmd shutdown action: Trigger vm command on shutdown. |
| 1526 | */ |
| 1527 | |
| 1528 | static char vmcmd_on_reboot[128]; |
| 1529 | static char vmcmd_on_panic[128]; |
| 1530 | static char vmcmd_on_halt[128]; |
| 1531 | static char vmcmd_on_poff[128]; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1532 | static char vmcmd_on_restart[128]; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1533 | |
| 1534 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot); |
| 1535 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic); |
| 1536 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt); |
| 1537 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff); |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1538 | DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1539 | |
| 1540 | static struct attribute *vmcmd_attrs[] = { |
| 1541 | &sys_vmcmd_on_reboot_attr.attr, |
| 1542 | &sys_vmcmd_on_panic_attr.attr, |
| 1543 | &sys_vmcmd_on_halt_attr.attr, |
| 1544 | &sys_vmcmd_on_poff_attr.attr, |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1545 | &sys_vmcmd_on_restart_attr.attr, |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1546 | NULL, |
| 1547 | }; |
| 1548 | |
| 1549 | static struct attribute_group vmcmd_attr_group = { |
| 1550 | .attrs = vmcmd_attrs, |
| 1551 | }; |
| 1552 | |
| 1553 | static struct kset *vmcmd_kset; |
| 1554 | |
| 1555 | static void vmcmd_run(struct shutdown_trigger *trigger) |
| 1556 | { |
| 1557 | char *cmd, *next_cmd; |
| 1558 | |
| 1559 | if (strcmp(trigger->name, ON_REIPL_STR) == 0) |
| 1560 | cmd = vmcmd_on_reboot; |
| 1561 | else if (strcmp(trigger->name, ON_PANIC_STR) == 0) |
| 1562 | cmd = vmcmd_on_panic; |
| 1563 | else if (strcmp(trigger->name, ON_HALT_STR) == 0) |
| 1564 | cmd = vmcmd_on_halt; |
| 1565 | else if (strcmp(trigger->name, ON_POFF_STR) == 0) |
| 1566 | cmd = vmcmd_on_poff; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1567 | else if (strcmp(trigger->name, ON_RESTART_STR) == 0) |
| 1568 | cmd = vmcmd_on_restart; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1569 | else |
| 1570 | return; |
| 1571 | |
| 1572 | if (strlen(cmd) == 0) |
| 1573 | return; |
| 1574 | do { |
| 1575 | next_cmd = strchr(cmd, '\n'); |
| 1576 | if (next_cmd) { |
| 1577 | next_cmd[0] = 0; |
| 1578 | next_cmd += 1; |
| 1579 | } |
| 1580 | __cpcmd(cmd, NULL, 0, NULL); |
| 1581 | cmd = next_cmd; |
| 1582 | } while (cmd != NULL); |
| 1583 | } |
| 1584 | |
| 1585 | static int vmcmd_init(void) |
| 1586 | { |
| 1587 | if (!MACHINE_IS_VM) |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 1588 | return -EOPNOTSUPP; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1589 | vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj); |
| 1590 | if (!vmcmd_kset) |
| 1591 | return -ENOMEM; |
| 1592 | return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group); |
| 1593 | } |
| 1594 | |
| 1595 | static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR, |
| 1596 | vmcmd_run, vmcmd_init}; |
| 1597 | |
| 1598 | /* |
| 1599 | * stop shutdown action: Stop Linux on shutdown. |
| 1600 | */ |
| 1601 | |
| 1602 | static void stop_run(struct shutdown_trigger *trigger) |
| 1603 | { |
Michael Holzheu | e1202ed | 2011-08-24 17:15:12 +0200 | [diff] [blame] | 1604 | if (strcmp(trigger->name, ON_PANIC_STR) == 0 || |
| 1605 | strcmp(trigger->name, ON_RESTART_STR) == 0) |
Michael Holzheu | c654749 | 2008-01-26 14:11:12 +0100 | [diff] [blame] | 1606 | disabled_wait((unsigned long) __builtin_return_address(0)); |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1607 | smp_stop_cpu(); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR, |
| 1611 | stop_run, NULL}; |
| 1612 | |
| 1613 | /* action list */ |
| 1614 | |
| 1615 | static struct shutdown_action *shutdown_actions_list[] = { |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1616 | &ipl_action, &reipl_action, &dump_reipl_action, &dump_action, |
| 1617 | &vmcmd_action, &stop_action}; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1618 | #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *)) |
| 1619 | |
| 1620 | /* |
| 1621 | * Trigger section |
| 1622 | */ |
| 1623 | |
| 1624 | static struct kset *shutdown_actions_kset; |
| 1625 | |
| 1626 | static int set_trigger(const char *buf, struct shutdown_trigger *trigger, |
| 1627 | size_t len) |
| 1628 | { |
| 1629 | int i; |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1630 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1631 | for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { |
Frank Munzert | 099b765 | 2009-03-26 15:23:43 +0100 | [diff] [blame] | 1632 | if (sysfs_streq(buf, shutdown_actions_list[i]->name)) { |
Frank Munzert | 8108881 | 2009-07-07 16:37:07 +0200 | [diff] [blame] | 1633 | if (shutdown_actions_list[i]->init_rc) { |
| 1634 | return shutdown_actions_list[i]->init_rc; |
| 1635 | } else { |
| 1636 | trigger->action = shutdown_actions_list[i]; |
| 1637 | return len; |
| 1638 | } |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | return -EINVAL; |
| 1642 | } |
| 1643 | |
| 1644 | /* on reipl */ |
| 1645 | |
| 1646 | static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR, |
| 1647 | &reipl_action}; |
| 1648 | |
| 1649 | static ssize_t on_reboot_show(struct kobject *kobj, |
| 1650 | struct kobj_attribute *attr, char *page) |
| 1651 | { |
| 1652 | return sprintf(page, "%s\n", on_reboot_trigger.action->name); |
| 1653 | } |
| 1654 | |
| 1655 | static ssize_t on_reboot_store(struct kobject *kobj, |
| 1656 | struct kobj_attribute *attr, |
| 1657 | const char *buf, size_t len) |
| 1658 | { |
| 1659 | return set_trigger(buf, &on_reboot_trigger, len); |
| 1660 | } |
| 1661 | |
| 1662 | static struct kobj_attribute on_reboot_attr = |
| 1663 | __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store); |
| 1664 | |
| 1665 | static void do_machine_restart(char *__unused) |
| 1666 | { |
| 1667 | smp_send_stop(); |
| 1668 | on_reboot_trigger.action->fn(&on_reboot_trigger); |
| 1669 | reipl_run(NULL); |
| 1670 | } |
| 1671 | void (*_machine_restart)(char *command) = do_machine_restart; |
| 1672 | |
| 1673 | /* on panic */ |
| 1674 | |
| 1675 | static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action}; |
| 1676 | |
| 1677 | static ssize_t on_panic_show(struct kobject *kobj, |
| 1678 | struct kobj_attribute *attr, char *page) |
| 1679 | { |
| 1680 | return sprintf(page, "%s\n", on_panic_trigger.action->name); |
| 1681 | } |
| 1682 | |
| 1683 | static ssize_t on_panic_store(struct kobject *kobj, |
| 1684 | struct kobj_attribute *attr, |
| 1685 | const char *buf, size_t len) |
| 1686 | { |
| 1687 | return set_trigger(buf, &on_panic_trigger, len); |
| 1688 | } |
| 1689 | |
| 1690 | static struct kobj_attribute on_panic_attr = |
| 1691 | __ATTR(on_panic, 0644, on_panic_show, on_panic_store); |
| 1692 | |
| 1693 | static void do_panic(void) |
| 1694 | { |
| 1695 | on_panic_trigger.action->fn(&on_panic_trigger); |
| 1696 | stop_run(&on_panic_trigger); |
| 1697 | } |
| 1698 | |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1699 | /* on restart */ |
| 1700 | |
| 1701 | static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR, |
Michael Holzheu | e1202ed | 2011-08-24 17:15:12 +0200 | [diff] [blame] | 1702 | &stop_action}; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1703 | |
| 1704 | static ssize_t on_restart_show(struct kobject *kobj, |
| 1705 | struct kobj_attribute *attr, char *page) |
| 1706 | { |
| 1707 | return sprintf(page, "%s\n", on_restart_trigger.action->name); |
| 1708 | } |
| 1709 | |
| 1710 | static ssize_t on_restart_store(struct kobject *kobj, |
| 1711 | struct kobj_attribute *attr, |
| 1712 | const char *buf, size_t len) |
| 1713 | { |
| 1714 | return set_trigger(buf, &on_restart_trigger, len); |
| 1715 | } |
| 1716 | |
| 1717 | static struct kobj_attribute on_restart_attr = |
| 1718 | __ATTR(on_restart, 0644, on_restart_show, on_restart_store); |
| 1719 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1720 | static void __do_restart(void *ignore) |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1721 | { |
| 1722 | smp_send_stop(); |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 1723 | #ifdef CONFIG_CRASH_DUMP |
| 1724 | crash_kexec(NULL); |
| 1725 | #endif |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1726 | on_restart_trigger.action->fn(&on_restart_trigger); |
| 1727 | stop_run(&on_restart_trigger); |
| 1728 | } |
| 1729 | |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 1730 | void do_restart(void) |
| 1731 | { |
| 1732 | smp_call_online_cpu(__do_restart, NULL); |
| 1733 | } |
| 1734 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1735 | /* on halt */ |
| 1736 | |
| 1737 | static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action}; |
| 1738 | |
| 1739 | static ssize_t on_halt_show(struct kobject *kobj, |
| 1740 | struct kobj_attribute *attr, char *page) |
| 1741 | { |
| 1742 | return sprintf(page, "%s\n", on_halt_trigger.action->name); |
| 1743 | } |
| 1744 | |
| 1745 | static ssize_t on_halt_store(struct kobject *kobj, |
| 1746 | struct kobj_attribute *attr, |
| 1747 | const char *buf, size_t len) |
| 1748 | { |
| 1749 | return set_trigger(buf, &on_halt_trigger, len); |
| 1750 | } |
| 1751 | |
| 1752 | static struct kobj_attribute on_halt_attr = |
| 1753 | __ATTR(on_halt, 0644, on_halt_show, on_halt_store); |
| 1754 | |
| 1755 | |
| 1756 | static void do_machine_halt(void) |
| 1757 | { |
| 1758 | smp_send_stop(); |
| 1759 | on_halt_trigger.action->fn(&on_halt_trigger); |
| 1760 | stop_run(&on_halt_trigger); |
| 1761 | } |
| 1762 | void (*_machine_halt)(void) = do_machine_halt; |
| 1763 | |
| 1764 | /* on power off */ |
| 1765 | |
| 1766 | static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action}; |
| 1767 | |
| 1768 | static ssize_t on_poff_show(struct kobject *kobj, |
| 1769 | struct kobj_attribute *attr, char *page) |
| 1770 | { |
| 1771 | return sprintf(page, "%s\n", on_poff_trigger.action->name); |
| 1772 | } |
| 1773 | |
| 1774 | static ssize_t on_poff_store(struct kobject *kobj, |
| 1775 | struct kobj_attribute *attr, |
| 1776 | const char *buf, size_t len) |
| 1777 | { |
| 1778 | return set_trigger(buf, &on_poff_trigger, len); |
| 1779 | } |
| 1780 | |
| 1781 | static struct kobj_attribute on_poff_attr = |
| 1782 | __ATTR(on_poff, 0644, on_poff_show, on_poff_store); |
| 1783 | |
| 1784 | |
| 1785 | static void do_machine_power_off(void) |
| 1786 | { |
| 1787 | smp_send_stop(); |
| 1788 | on_poff_trigger.action->fn(&on_poff_trigger); |
| 1789 | stop_run(&on_poff_trigger); |
| 1790 | } |
| 1791 | void (*_machine_power_off)(void) = do_machine_power_off; |
| 1792 | |
| 1793 | static void __init shutdown_triggers_init(void) |
| 1794 | { |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1795 | shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL, |
Greg Kroah-Hartman | f62ed9e | 2007-11-05 13:16:15 -0800 | [diff] [blame] | 1796 | firmware_kobj); |
Greg Kroah-Hartman | d91885b | 2007-11-02 17:17:00 -0400 | [diff] [blame] | 1797 | if (!shutdown_actions_kset) |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1798 | goto fail; |
| 1799 | if (sysfs_create_file(&shutdown_actions_kset->kobj, |
| 1800 | &on_reboot_attr.attr)) |
| 1801 | goto fail; |
| 1802 | if (sysfs_create_file(&shutdown_actions_kset->kobj, |
| 1803 | &on_panic_attr.attr)) |
| 1804 | goto fail; |
| 1805 | if (sysfs_create_file(&shutdown_actions_kset->kobj, |
| 1806 | &on_halt_attr.attr)) |
| 1807 | goto fail; |
| 1808 | if (sysfs_create_file(&shutdown_actions_kset->kobj, |
| 1809 | &on_poff_attr.attr)) |
| 1810 | goto fail; |
Michael Holzheu | 7dd6b33 | 2011-08-03 16:44:19 +0200 | [diff] [blame] | 1811 | if (sysfs_create_file(&shutdown_actions_kset->kobj, |
| 1812 | &on_restart_attr.attr)) |
| 1813 | goto fail; |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1814 | return; |
| 1815 | fail: |
| 1816 | panic("shutdown_triggers_init failed\n"); |
| 1817 | } |
| 1818 | |
| 1819 | static void __init shutdown_actions_init(void) |
| 1820 | { |
| 1821 | int i; |
| 1822 | |
| 1823 | for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { |
| 1824 | if (!shutdown_actions_list[i]->init) |
| 1825 | continue; |
Frank Munzert | 8108881 | 2009-07-07 16:37:07 +0200 | [diff] [blame] | 1826 | shutdown_actions_list[i]->init_rc = |
| 1827 | shutdown_actions_list[i]->init(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1828 | } |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | static int __init s390_ipl_init(void) |
| 1832 | { |
Michael Holzheu | d09293a | 2008-01-26 14:11:15 +0100 | [diff] [blame] | 1833 | sclp_get_ipl_info(&sclp_ipl_info); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1834 | shutdown_actions_init(); |
| 1835 | shutdown_triggers_init(); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1836 | return 0; |
| 1837 | } |
| 1838 | |
| 1839 | __initcall(s390_ipl_init); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1840 | |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1841 | static void __init strncpy_skip_quote(char *dst, char *src, int n) |
| 1842 | { |
| 1843 | int sx, dx; |
| 1844 | |
| 1845 | dx = 0; |
| 1846 | for (sx = 0; src[sx] != 0; sx++) { |
| 1847 | if (src[sx] == '"') |
| 1848 | continue; |
| 1849 | dst[dx++] = src[sx]; |
| 1850 | if (dx >= n) |
| 1851 | break; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | static int __init vmcmd_on_reboot_setup(char *str) |
| 1856 | { |
| 1857 | if (!MACHINE_IS_VM) |
| 1858 | return 1; |
| 1859 | strncpy_skip_quote(vmcmd_on_reboot, str, 127); |
| 1860 | vmcmd_on_reboot[127] = 0; |
| 1861 | on_reboot_trigger.action = &vmcmd_action; |
| 1862 | return 1; |
| 1863 | } |
| 1864 | __setup("vmreboot=", vmcmd_on_reboot_setup); |
| 1865 | |
| 1866 | static int __init vmcmd_on_panic_setup(char *str) |
| 1867 | { |
| 1868 | if (!MACHINE_IS_VM) |
| 1869 | return 1; |
| 1870 | strncpy_skip_quote(vmcmd_on_panic, str, 127); |
| 1871 | vmcmd_on_panic[127] = 0; |
| 1872 | on_panic_trigger.action = &vmcmd_action; |
| 1873 | return 1; |
| 1874 | } |
| 1875 | __setup("vmpanic=", vmcmd_on_panic_setup); |
| 1876 | |
| 1877 | static int __init vmcmd_on_halt_setup(char *str) |
| 1878 | { |
| 1879 | if (!MACHINE_IS_VM) |
| 1880 | return 1; |
| 1881 | strncpy_skip_quote(vmcmd_on_halt, str, 127); |
| 1882 | vmcmd_on_halt[127] = 0; |
| 1883 | on_halt_trigger.action = &vmcmd_action; |
| 1884 | return 1; |
| 1885 | } |
| 1886 | __setup("vmhalt=", vmcmd_on_halt_setup); |
| 1887 | |
| 1888 | static int __init vmcmd_on_poff_setup(char *str) |
| 1889 | { |
| 1890 | if (!MACHINE_IS_VM) |
| 1891 | return 1; |
| 1892 | strncpy_skip_quote(vmcmd_on_poff, str, 127); |
| 1893 | vmcmd_on_poff[127] = 0; |
| 1894 | on_poff_trigger.action = &vmcmd_action; |
| 1895 | return 1; |
| 1896 | } |
| 1897 | __setup("vmpoff=", vmcmd_on_poff_setup); |
| 1898 | |
| 1899 | static int on_panic_notify(struct notifier_block *self, |
| 1900 | unsigned long event, void *data) |
| 1901 | { |
| 1902 | do_panic(); |
| 1903 | return NOTIFY_OK; |
| 1904 | } |
| 1905 | |
| 1906 | static struct notifier_block on_panic_nb = { |
| 1907 | .notifier_call = on_panic_notify, |
Michael Holzheu | 7e9b580 | 2009-03-26 15:24:55 +0100 | [diff] [blame] | 1908 | .priority = INT_MIN, |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1909 | }; |
| 1910 | |
| 1911 | void __init setup_ipl(void) |
| 1912 | { |
| 1913 | ipl_info.type = get_ipl_type(); |
| 1914 | switch (ipl_info.type) { |
| 1915 | case IPL_TYPE_CCW: |
| 1916 | ipl_info.data.ccw.dev_id.devno = ipl_devno; |
| 1917 | ipl_info.data.ccw.dev_id.ssid = 0; |
| 1918 | break; |
| 1919 | case IPL_TYPE_FCP: |
| 1920 | case IPL_TYPE_FCP_DUMP: |
| 1921 | ipl_info.data.fcp.dev_id.devno = |
| 1922 | IPL_PARMBLOCK_START->ipl_info.fcp.devno; |
| 1923 | ipl_info.data.fcp.dev_id.ssid = 0; |
| 1924 | ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn; |
| 1925 | ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun; |
| 1926 | break; |
| 1927 | case IPL_TYPE_NSS: |
| 1928 | strncpy(ipl_info.data.nss.name, kernel_nss_name, |
| 1929 | sizeof(ipl_info.data.nss.name)); |
| 1930 | break; |
| 1931 | case IPL_TYPE_UNKNOWN: |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 1932 | /* We have no info to copy */ |
| 1933 | break; |
| 1934 | } |
| 1935 | atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb); |
| 1936 | } |
| 1937 | |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1938 | void __init ipl_update_parameters(void) |
| 1939 | { |
Michael Holzheu | 3a95e8e | 2008-08-01 16:39:10 +0200 | [diff] [blame] | 1940 | int rc; |
| 1941 | |
| 1942 | rc = diag308(DIAG308_STORE, &ipl_block); |
| 1943 | if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG)) |
Hendrik Brueckner | a0443fb | 2008-07-14 09:59:09 +0200 | [diff] [blame] | 1944 | diag308_set_works = 1; |
| 1945 | } |
| 1946 | |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1947 | void __init ipl_save_parameters(void) |
| 1948 | { |
| 1949 | struct cio_iplinfo iplinfo; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1950 | void *src, *dst; |
| 1951 | |
| 1952 | if (cio_get_iplinfo(&iplinfo)) |
| 1953 | return; |
| 1954 | |
| 1955 | ipl_devno = iplinfo.devno; |
| 1956 | ipl_flags |= IPL_DEVNO_VALID; |
| 1957 | if (!iplinfo.is_qdio) |
| 1958 | return; |
| 1959 | ipl_flags |= IPL_PARMBLOCK_VALID; |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 1960 | src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1961 | dst = (void *)IPL_PARMBLOCK_ORIGIN; |
| 1962 | memmove(dst, src, PAGE_SIZE); |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 1963 | S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1964 | } |
| 1965 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1966 | static LIST_HEAD(rcall); |
| 1967 | static DEFINE_MUTEX(rcall_mutex); |
| 1968 | |
| 1969 | void register_reset_call(struct reset_call *reset) |
| 1970 | { |
| 1971 | mutex_lock(&rcall_mutex); |
| 1972 | list_add(&reset->list, &rcall); |
| 1973 | mutex_unlock(&rcall_mutex); |
| 1974 | } |
| 1975 | EXPORT_SYMBOL_GPL(register_reset_call); |
| 1976 | |
| 1977 | void unregister_reset_call(struct reset_call *reset) |
| 1978 | { |
| 1979 | mutex_lock(&rcall_mutex); |
| 1980 | list_del(&reset->list); |
| 1981 | mutex_unlock(&rcall_mutex); |
| 1982 | } |
| 1983 | EXPORT_SYMBOL_GPL(unregister_reset_call); |
| 1984 | |
| 1985 | static void do_reset_calls(void) |
| 1986 | { |
| 1987 | struct reset_call *reset; |
| 1988 | |
Michael Holzheu | 9dc7356 | 2011-08-03 16:44:22 +0200 | [diff] [blame] | 1989 | #ifdef CONFIG_64BIT |
| 1990 | if (diag308_set_works) { |
| 1991 | diag308_reset(); |
| 1992 | return; |
| 1993 | } |
| 1994 | #endif |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1995 | list_for_each_entry(reset, &rcall, list) |
| 1996 | reset->fn(); |
| 1997 | } |
| 1998 | |
Heiko Carstens | c5dd858 | 2007-03-05 23:35:43 +0100 | [diff] [blame] | 1999 | u32 dump_prefix_page; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2000 | |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 2001 | void s390_reset_system(void (*func)(void *), void *data) |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2002 | { |
| 2003 | struct _lowcore *lc; |
| 2004 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2005 | lc = (struct _lowcore *)(unsigned long) store_prefix(); |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2006 | |
| 2007 | /* Stack for interrupt/machine check handler */ |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2008 | lc->panic_stack = S390_lowcore.panic_stack; |
| 2009 | |
Michael Holzheu | da1cf23 | 2006-12-15 17:18:27 +0100 | [diff] [blame] | 2010 | /* Save prefix page address for dump case */ |
Heiko Carstens | c5dd858 | 2007-03-05 23:35:43 +0100 | [diff] [blame] | 2011 | dump_prefix_page = (u32)(unsigned long) lc; |
Michael Holzheu | da1cf23 | 2006-12-15 17:18:27 +0100 | [diff] [blame] | 2012 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2013 | /* Disable prefixing */ |
| 2014 | set_prefix(0); |
| 2015 | |
| 2016 | /* Disable lowcore protection */ |
| 2017 | __ctl_clear_bit(0,28); |
| 2018 | |
| 2019 | /* Set new machine check handler */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 2020 | S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 2021 | S390_lowcore.mcck_new_psw.addr = |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 2022 | PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler; |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2023 | |
| 2024 | /* Set new program check handler */ |
Martin Schwidefsky | b50511e | 2011-10-30 15:16:50 +0100 | [diff] [blame] | 2025 | S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT; |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2026 | S390_lowcore.program_new_psw.addr = |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 2027 | PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler; |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 2028 | |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 2029 | /* Store status at absolute zero */ |
| 2030 | store_status(); |
Michael Holzheu | 99ca4e5 | 2008-01-26 14:11:11 +0100 | [diff] [blame] | 2031 | |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 2032 | do_reset_calls(); |
| 2033 | if (func) |
| 2034 | func(data); |
| 2035 | } |