blob: 9e2f6f7c0e5a9729cc3623e1b140f3e5cff97374 [file] [log] [blame]
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001/*
2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
4 *
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04005 * Copyright IBM Corp. 2005,2012
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02006 * 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 Holzheu03a4d202006-12-04 15:39:58 +010016#include <linux/ctype.h>
Akinobu Mita0788fea2008-07-14 09:59:17 +020017#include <linux/fs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/gfp.h>
Michael Holzheu60a0c682011-10-30 15:16:40 +010019#include <linux/crash_dump.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010020#include <asm/ipl.h>
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020021#include <asm/smp.h>
22#include <asm/setup.h>
23#include <asm/cpcmd.h>
24#include <asm/cio.h>
Michael Holzheu03a4d202006-12-04 15:39:58 +010025#include <asm/ebcdic.h>
Heiko Carstens15e9b582006-12-04 15:40:26 +010026#include <asm/reset.h>
Heiko Carstensab14de62007-02-05 21:18:37 +010027#include <asm/sclp.h>
Frank Munzert159d1ff2009-03-26 15:24:45 +010028#include <asm/checksum.h>
Martin Schwidefsky638ad342011-10-30 15:17:13 +010029#include "entry.h"
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020030
31#define IPL_PARM_BLOCK_VERSION 0
Michael Holzheu03a4d202006-12-04 15:39:58 +010032
Michael Holzheu411ed322007-04-27 16:01:49 +020033#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 Carstens615b04b2007-02-21 10:55:37 +010038
Michael Holzheu99ca4e52008-01-26 14:11:11 +010039#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 Holzheu7dd6b332011-08-03 16:44:19 +020049 * - restart
Michael Holzheu99ca4e52008-01-26 14:11:11 +010050 */
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 Holzheu7dd6b332011-08-03 16:44:19 +020055#define ON_RESTART_STR "on_restart"
Michael Holzheu99ca4e52008-01-26 14:11:11 +010056
57struct shutdown_action;
58struct shutdown_trigger {
59 char *name;
60 struct shutdown_action *action;
61};
62
63/*
Frank Munzert099b7652009-03-26 15:23:43 +010064 * The following shutdown action types are supported:
Michael Holzheu99ca4e52008-01-26 14:11:11 +010065 */
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 Munzert099b7652009-03-26 15:23:43 +010071#define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
Michael Holzheu99ca4e52008-01-26 14:11:11 +010072
73struct shutdown_action {
74 char *name;
75 void (*fn) (struct shutdown_trigger *trigger);
76 int (*init) (void);
Frank Munzert81088812009-07-07 16:37:07 +020077 int init_rc;
Michael Holzheu99ca4e52008-01-26 14:11:11 +010078};
79
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020080static char *ipl_type_str(enum ipl_type type)
81{
82 switch (type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020083 case IPL_TYPE_CCW:
84 return IPL_CCW_STR;
85 case IPL_TYPE_FCP:
86 return IPL_FCP_STR;
Michael Holzheu411ed322007-04-27 16:01:49 +020087 case IPL_TYPE_FCP_DUMP:
88 return IPL_FCP_DUMP_STR;
Hongjie Yangfe355b72007-02-05 21:18:24 +010089 case IPL_TYPE_NSS:
90 return IPL_NSS_STR;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +020091 case IPL_TYPE_UNKNOWN:
92 default:
93 return IPL_UNKNOWN_STR;
94 }
95}
96
Michael Holzheu411ed322007-04-27 16:01:49 +020097enum dump_type {
98 DUMP_TYPE_NONE = 1,
99 DUMP_TYPE_CCW = 2,
100 DUMP_TYPE_FCP = 4,
101};
102
Michael Holzheu411ed322007-04-27 16:01:49 +0200103static 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 */
121static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
122u32 ipl_flags __attribute__((__section__(".data"))) = 0;
123
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200124enum ipl_method {
Michael Holzheu411ed322007-04-27 16:01:49 +0200125 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 Bruecknera0443fb2008-07-14 09:59:09 +0200133 REIPL_METHOD_NSS_DIAG,
Michael Holzheu411ed322007-04-27 16:01:49 +0200134 REIPL_METHOD_DEFAULT,
135};
136
137enum 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 Holzheuff6b8ea2006-09-20 15:58:49 +0200143};
144
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200145static int diag308_set_works = 0;
146
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200147static struct ipl_parameter_block ipl_block;
148
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200149static int reipl_capabilities = IPL_TYPE_UNKNOWN;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100150
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200151static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
Michael Holzheu411ed322007-04-27 16:01:49 +0200152static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200153static struct ipl_parameter_block *reipl_block_fcp;
154static struct ipl_parameter_block *reipl_block_ccw;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200155static struct ipl_parameter_block *reipl_block_nss;
Frank Munzert099b7652009-03-26 15:23:43 +0100156static struct ipl_parameter_block *reipl_block_actual;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100157
Michael Holzheu411ed322007-04-27 16:01:49 +0200158static int dump_capabilities = DUMP_TYPE_NONE;
159static enum dump_type dump_type = DUMP_TYPE_NONE;
160static enum dump_method dump_method = DUMP_METHOD_NONE;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200161static struct ipl_parameter_block *dump_block_fcp;
162static struct ipl_parameter_block *dump_block_ccw;
163
Heiko Carstens05dd2532007-07-10 11:24:09 +0200164static struct sclp_ipl_info sclp_ipl_info;
165
Michael Holzheu46b05d22007-02-21 10:55:21 +0100166int diag308(unsigned long subcode, void *addr)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200167{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200168 register unsigned long _addr asm("0") = (unsigned long) addr;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200169 register unsigned long _rc asm("1") = 0;
170
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200171 asm volatile(
172 " diag %0,%2,0x308\n"
173 "0:\n"
174 EX_TABLE(0b,0b)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200175 : "+d" (_addr), "+d" (_rc)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200176 : "d" (subcode) : "cc", "memory");
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200177 return _rc;
178}
Michael Holzheu411ed322007-04-27 16:01:49 +0200179EXPORT_SYMBOL_GPL(diag308);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200180
181/* SYSFS */
182
183#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400184static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
185 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200186 char *page) \
187{ \
188 return sprintf(page, _format, _value); \
189} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400190static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200191 __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-Hartman9b949162007-11-02 17:17:00 -0400194static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
195 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200196 char *page) \
197{ \
198 return sprintf(page, _fmt_out, \
199 (unsigned long long) _value); \
200} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400201static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
202 struct kobj_attribute *attr, \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200203 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-Hartman9b949162007-11-02 17:17:00 -0400211static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200212 __ATTR(_name,(S_IRUGO | S_IWUSR), \
213 sys_##_prefix##_##_name##_show, \
214 sys_##_prefix##_##_name##_store);
215
Hongjie Yangfe355b72007-02-05 21:18:24 +0100216#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400217static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
218 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100219 char *page) \
220{ \
221 return sprintf(page, _fmt_out, _value); \
222} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400223static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
224 struct kobj_attribute *attr, \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100225 const char *buf, size_t len) \
226{ \
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100227 strncpy(_value, buf, sizeof(_value) - 1); \
Heiko Carstens1d802e22009-12-18 17:43:27 +0100228 strim(_value); \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100229 return len; \
230} \
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400231static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
Hongjie Yangfe355b72007-02-05 21:18:24 +0100232 __ATTR(_name,(S_IRUGO | S_IWUSR), \
233 sys_##_prefix##_##_name##_show, \
234 sys_##_prefix##_##_name##_store);
235
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200236static 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 Holzheu411ed322007-04-27 16:01:49 +0200248static __init enum ipl_type get_ipl_type(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200249{
250 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
251
Hongjie Yangfe355b72007-02-05 21:18:24 +0100252 if (ipl_flags & IPL_NSS_VALID)
253 return IPL_TYPE_NSS;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200254 if (!(ipl_flags & IPL_DEVNO_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200255 return IPL_TYPE_UNKNOWN;
Heiko Carstense87bfe52006-09-20 15:59:15 +0200256 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200257 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 Holzheu411ed322007-04-27 16:01:49 +0200262 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
263 return IPL_TYPE_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200264 return IPL_TYPE_FCP;
265}
266
Michael Holzheu411ed322007-04-27 16:01:49 +0200267struct ipl_info ipl_info;
268EXPORT_SYMBOL_GPL(ipl_info);
269
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400270static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
271 char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200272{
Michael Holzheu411ed322007-04-27 16:01:49 +0200273 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200274}
275
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400276static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200277
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200278/* VM IPL PARM routines */
Martin Schwidefskyc4736d92011-10-30 15:17:11 +0100279static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
280 const struct ipl_parameter_block *ipb)
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200281{
282 int i;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200283 size_t len;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200284 char has_lowercase = 0;
285
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200286 len = 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200287 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
288 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
289
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200290 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200291 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 Brueckner684d2fd2009-09-11 10:28:40 +0200307
308 return len;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200309}
310
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200311size_t append_ipl_vmparm(char *dest, size_t size)
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200312{
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200313 size_t rc;
314
315 rc = 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200316 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200317 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200318 else
319 dest[0] = 0;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200320 return rc;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200321}
322
323static 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 Brueckner684d2fd2009-09-11 10:28:40 +0200328 append_ipl_vmparm(parm, sizeof(parm));
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200329 return sprintf(page, "%s\n", parm);
330}
331
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200332static 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 Schwidefskyc4736d92011-10-30 15:17:11 +0100342static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
343 const struct ipl_parameter_block *ipb)
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200344{
345 size_t count;
346 size_t i;
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200347 int has_lowercase;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200348
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 Brueckner18d00ac2009-09-11 10:28:41 +0200354 has_lowercase = 0;
355 for (i = 0; i < count; i++) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200356 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
357 count = 0;
358 goto out;
359 }
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200360 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
361 has_lowercase = 1;
362 }
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200363
Hendrik Brueckner18d00ac2009-09-11 10:28:41 +0200364 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 Brueckner684d2fd2009-09-11 10:28:40 +0200369out:
370 dest[count] = '\0';
371 return count;
372}
373
374size_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 Bruecknera0443fb2008-07-14 09:59:09 +0200387static struct kobj_attribute sys_ipl_vm_parm_attr =
388 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
389
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400390static ssize_t sys_ipl_device_show(struct kobject *kobj,
391 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200392{
393 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
394
Michael Holzheu411ed322007-04-27 16:01:49 +0200395 switch (ipl_info.type) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200396 case IPL_TYPE_CCW:
397 return sprintf(page, "0.0.%04x\n", ipl_devno);
398 case IPL_TYPE_FCP:
Michael Holzheu411ed322007-04-27 16:01:49 +0200399 case IPL_TYPE_FCP_DUMP:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200400 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
401 default:
402 return 0;
403 }
404}
405
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400406static struct kobj_attribute sys_ipl_device_attr =
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200407 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
408
Chris Wright2c3c8be2010-05-12 18:28:57 -0700409static 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 Holzheuff6b8ea2006-09-20 15:58:49 +0200412{
Akinobu Mita0788fea2008-07-14 09:59:17 +0200413 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
414 IPL_PARMBLOCK_SIZE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200415}
416
417static struct bin_attribute ipl_parameter_attr = {
418 .attr = {
419 .name = "binary_parameter",
420 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200421 },
422 .size = PAGE_SIZE,
423 .read = &ipl_parameter_read,
424};
425
Chris Wright2c3c8be2010-05-12 18:28:57 -0700426static 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 Holzheuff6b8ea2006-09-20 15:58:49 +0200429{
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 Mita0788fea2008-07-14 09:59:17 +0200433 return memory_read_from_buffer(buf, count, &off, scp_data, size);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200434}
435
436static struct bin_attribute ipl_scp_data_attr = {
437 .attr = {
438 .name = "scp_data",
439 .mode = S_IRUGO,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200440 },
441 .size = PAGE_SIZE,
Al Viro05bd7112007-07-15 21:01:22 +0100442 .read = ipl_scp_data_read,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200443};
444
445/* FCP ipl device attributes */
446
447DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
448 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
449DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
450 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
451DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
452 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
453DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
454 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
455
456static 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
466static struct attribute_group ipl_fcp_attr_group = {
467 .attrs = ipl_fcp_attrs,
468};
469
470/* CCW ipl device attributes */
471
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400472static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
473 struct kobj_attribute *attr, char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100474{
475 char loadparm[LOADPARM_LEN + 1] = {};
476
Heiko Carstens05dd2532007-07-10 11:24:09 +0200477 if (!sclp_ipl_info.is_valid)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100478 return sprintf(page, "#unknown#\n");
Heiko Carstens05dd2532007-07-10 11:24:09 +0200479 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100480 EBCASC(loadparm, LOADPARM_LEN);
Heiko Carstens1d802e22009-12-18 17:43:27 +0100481 strim(loadparm);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100482 return sprintf(page, "%s\n", loadparm);
483}
484
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400485static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
Michael Holzheu03a4d202006-12-04 15:39:58 +0100486 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
487
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200488static 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
496static struct attribute *ipl_ccw_attrs_lpar[] = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200497 &sys_ipl_type_attr.attr,
498 &sys_ipl_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100499 &sys_ipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200500 NULL,
501};
502
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200503static struct attribute_group ipl_ccw_attr_group_vm = {
504 .attrs = ipl_ccw_attrs_vm,
505};
506
507static struct attribute_group ipl_ccw_attr_group_lpar = {
508 .attrs = ipl_ccw_attrs_lpar
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200509};
510
Hongjie Yangfe355b72007-02-05 21:18:24 +0100511/* NSS ipl device attributes */
512
513DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
514
515static struct attribute *ipl_nss_attrs[] = {
516 &sys_ipl_type_attr.attr,
517 &sys_ipl_nss_name_attr.attr,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200518 &sys_ipl_ccw_loadparm_attr.attr,
519 &sys_ipl_vm_parm_attr.attr,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100520 NULL,
521};
522
523static struct attribute_group ipl_nss_attr_group = {
524 .attrs = ipl_nss_attrs,
525};
526
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200527/* UNKNOWN ipl device attributes */
528
529static struct attribute *ipl_unknown_attrs[] = {
530 &sys_ipl_type_attr.attr,
531 NULL,
532};
533
534static struct attribute_group ipl_unknown_attr_group = {
535 .attrs = ipl_unknown_attrs,
536};
537
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -0400538static struct kset *ipl_kset;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200539
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100540static 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
556out_ipl_parm:
557 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
558out:
559 return rc;
560}
561
Heiko Carstens2c2df112010-02-26 22:37:34 +0100562static void __ipl_run(void *unused)
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100563{
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 Carstens2c2df112010-02-26 22:37:34 +0100571static void ipl_run(struct shutdown_trigger *trigger)
572{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -0400573 smp_call_ipl_cpu(__ipl_run, NULL);
Heiko Carstens2c2df112010-02-26 22:37:34 +0100574}
575
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100576static int __init ipl_init(void)
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100577{
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 Bruecknera0443fb2008-07-14 09:59:09 +0200587 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 Holzheu99ca4e52008-01-26 14:11:11 +0100593 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 }
606out:
607 if (rc)
608 panic("ipl_init failed: rc = %i\n", rc);
609
610 return 0;
611}
612
Heiko Carstens2bc89b52008-02-05 16:50:40 +0100613static struct shutdown_action __refdata ipl_action = {
614 .name = SHUTDOWN_ACTION_IPL_STR,
615 .fn = ipl_run,
616 .init = ipl_init,
617};
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100618
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200619/*
Michael Holzheu99ca4e52008-01-26 14:11:11 +0100620 * reipl shutdown action: Reboot Linux on shutdown.
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200621 */
622
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200623/* VM IPL PARM attributes */
624static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
625 char *page)
626{
627 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
628
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200629 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200630 return sprintf(page, "%s\n", vmparm);
631}
632
633static 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 */
666static 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
672static 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 */
680static 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
686static 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
693static struct kobj_attribute sys_reipl_nss_vmparm_attr =
694 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
695 reipl_nss_vmparm_store);
696static 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 Holzheuff6b8ea2006-09-20 15:58:49 +0200700/* FCP reipl device attributes */
701
Chris Wright2c3c8be2010-05-12 18:28:57 -0700702static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200703 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 Wright2c3c8be2010-05-12 18:28:57 -0700712static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +0200713 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
745static 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 Holzheuff6b8ea2006-09-20 15:58:49 +0200755DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
756 reipl_block_fcp->ipl_info.fcp.wwpn);
757DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
758 reipl_block_fcp->ipl_info.fcp.lun);
759DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
760 reipl_block_fcp->ipl_info.fcp.bootprog);
761DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
762 reipl_block_fcp->ipl_info.fcp.br_lba);
763DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
764 reipl_block_fcp->ipl_info.fcp.devno);
765
766static 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
775static struct attribute_group reipl_fcp_attr_group = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200776 .attrs = reipl_fcp_attrs,
777};
778
779/* CCW reipl device attributes */
780
781DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
782 reipl_block_ccw->ipl_info.ccw.devno);
783
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200784static void reipl_get_ascii_loadparm(char *loadparm,
785 struct ipl_parameter_block *ibp)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100786{
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200787 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100788 EBCASC(loadparm, LOADPARM_LEN);
789 loadparm[LOADPARM_LEN] = 0;
Heiko Carstens1d802e22009-12-18 17:43:27 +0100790 strim(loadparm);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100791}
792
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200793static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
794 char *page)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100795{
796 char buf[LOADPARM_LEN + 1];
797
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200798 reipl_get_ascii_loadparm(buf, ipb);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100799 return sprintf(page, "%s\n", buf);
800}
801
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200802static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
803 const char *buf, size_t len)
Michael Holzheu03a4d202006-12-04 15:39:58 +0100804{
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 Bruecknera0443fb2008-07-14 09:59:09 +0200822 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100823 /* copy and convert to ebcdic */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200824 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
825 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
Michael Holzheu03a4d202006-12-04 15:39:58 +0100826 return len;
827}
828
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200829/* NSS wrapper */
830static 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 Holzheu03a4d202006-12-04 15:39:58 +0100835
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200836static 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 */
844static 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
850static 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
857static 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
861static 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
868static struct attribute *reipl_ccw_attrs_lpar[] = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200869 &sys_reipl_ccw_device_attr.attr,
Michael Holzheu03a4d202006-12-04 15:39:58 +0100870 &sys_reipl_ccw_loadparm_attr.attr,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200871 NULL,
872};
873
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200874static struct attribute_group reipl_ccw_attr_group_vm = {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200875 .name = IPL_CCW_STR,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200876 .attrs = reipl_ccw_attrs_vm,
877};
878
879static struct attribute_group reipl_ccw_attr_group_lpar = {
880 .name = IPL_CCW_STR,
881 .attrs = reipl_ccw_attrs_lpar,
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200882};
883
Hongjie Yangfe355b72007-02-05 21:18:24 +0100884
885/* NSS reipl device attributes */
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200886static 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 Yangfe355b72007-02-05 21:18:24 +0100893
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200894static 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
903static 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
932static 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
936static 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 Yangfe355b72007-02-05 21:18:24 +0100939
940static struct attribute *reipl_nss_attrs[] = {
941 &sys_reipl_nss_name_attr.attr,
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200942 &sys_reipl_nss_loadparm_attr.attr,
943 &sys_reipl_nss_vmparm_attr.attr,
Hongjie Yangfe355b72007-02-05 21:18:24 +0100944 NULL,
945};
946
947static struct attribute_group reipl_nss_attr_group = {
948 .name = IPL_NSS_STR,
949 .attrs = reipl_nss_attrs,
950};
951
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200952/* reipl type */
953
954static 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 Holzheu48657d22008-01-26 14:11:17 +0100961 if (diag308_set_works)
962 reipl_method = REIPL_METHOD_CCW_DIAG;
963 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200964 reipl_method = REIPL_METHOD_CCW_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200965 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200966 reipl_method = REIPL_METHOD_CCW_CIO;
Frank Munzert099b7652009-03-26 15:23:43 +0100967 reipl_block_actual = reipl_block_ccw;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200968 break;
969 case IPL_TYPE_FCP:
970 if (diag308_set_works)
Michael Holzheu411ed322007-04-27 16:01:49 +0200971 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200972 else if (MACHINE_IS_VM)
Michael Holzheu411ed322007-04-27 16:01:49 +0200973 reipl_method = REIPL_METHOD_FCP_RO_VM;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200974 else
Michael Holzheu411ed322007-04-27 16:01:49 +0200975 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
Frank Munzert099b7652009-03-26 15:23:43 +0100976 reipl_block_actual = reipl_block_fcp;
Michael Holzheu411ed322007-04-27 16:01:49 +0200977 break;
978 case IPL_TYPE_FCP_DUMP:
979 reipl_method = REIPL_METHOD_FCP_DUMP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200980 break;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100981 case IPL_TYPE_NSS:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +0200982 if (diag308_set_works)
983 reipl_method = REIPL_METHOD_NSS_DIAG;
984 else
985 reipl_method = REIPL_METHOD_NSS;
Frank Munzert099b7652009-03-26 15:23:43 +0100986 reipl_block_actual = reipl_block_nss;
Michael Holzheu411ed322007-04-27 16:01:49 +0200987 break;
988 case IPL_TYPE_UNKNOWN:
989 reipl_method = REIPL_METHOD_DEFAULT;
Hongjie Yangfe355b72007-02-05 21:18:24 +0100990 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200991 default:
Michael Holzheu411ed322007-04-27 16:01:49 +0200992 BUG();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +0200993 }
994 reipl_type = type;
995 return 0;
996}
997
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -0400998static ssize_t reipl_type_show(struct kobject *kobj,
999 struct kobj_attribute *attr, char *page)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001000{
1001 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1002}
1003
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001004static ssize_t reipl_type_store(struct kobject *kobj,
1005 struct kobj_attribute *attr,
1006 const char *buf, size_t len)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001007{
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 Yangfe355b72007-02-05 21:18:24 +01001014 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1015 rc = reipl_set_type(IPL_TYPE_NSS);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001016 return (rc != 0) ? rc : len;
1017}
1018
Greg Kroah-Hartman9b949162007-11-02 17:17:00 -04001019static struct kobj_attribute reipl_type_attr =
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001020 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001021
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001022static struct kset *reipl_kset;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001023static struct kset *reipl_fcp_kset;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001024
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001025static 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 Brueckner684d2fd2009-09-11 10:28:40 +02001035 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001036
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 Carstens2c2df112010-02-26 22:37:34 +01001053static void __reipl_run(void *unused)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001054{
1055 struct ccw_dev_id devid;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001056 static char buf[128];
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001057
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001058 switch (reipl_method) {
Michael Holzheu411ed322007-04-27 16:01:49 +02001059 case REIPL_METHOD_CCW_CIO:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001060 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1061 devid.ssid = 0;
1062 reipl_ccw_dev(&devid);
1063 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001064 case REIPL_METHOD_CCW_VM:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001065 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
Heiko Carstens740b5702006-12-04 15:40:30 +01001066 __cpcmd(buf, NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001067 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001068 case REIPL_METHOD_CCW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001069 diag308(DIAG308_SET, reipl_block_ccw);
1070 diag308(DIAG308_IPL, NULL);
1071 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001072 case REIPL_METHOD_FCP_RW_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001073 diag308(DIAG308_SET, reipl_block_fcp);
1074 diag308(DIAG308_IPL, NULL);
1075 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001076 case REIPL_METHOD_FCP_RO_DIAG:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001077 diag308(DIAG308_IPL, NULL);
1078 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001079 case REIPL_METHOD_FCP_RO_VM:
Heiko Carstens740b5702006-12-04 15:40:30 +01001080 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001081 break;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001082 case REIPL_METHOD_NSS_DIAG:
1083 diag308(DIAG308_SET, reipl_block_nss);
1084 diag308(DIAG308_IPL, NULL);
1085 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001086 case REIPL_METHOD_NSS:
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001087 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
Hongjie Yangfe355b72007-02-05 21:18:24 +01001088 __cpcmd(buf, NULL, 0, NULL);
1089 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001090 case REIPL_METHOD_DEFAULT:
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001091 if (MACHINE_IS_VM)
Heiko Carstens740b5702006-12-04 15:40:30 +01001092 __cpcmd("IPL", NULL, 0, NULL);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001093 diag308(DIAG308_IPL, NULL);
1094 break;
Michael Holzheu411ed322007-04-27 16:01:49 +02001095 case REIPL_METHOD_FCP_DUMP:
Michael Holzheu411ed322007-04-27 16:01:49 +02001096 break;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001097 }
Michael Holzheu208e5592008-03-05 12:37:15 +01001098 disabled_wait((unsigned long) __builtin_return_address(0));
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001099}
1100
Heiko Carstens2c2df112010-02-26 22:37:34 +01001101static void reipl_run(struct shutdown_trigger *trigger)
1102{
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001103 smp_call_ipl_cpu(__reipl_run, NULL);
Heiko Carstens2c2df112010-02-26 22:37:34 +01001104}
1105
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001106static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001107{
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001108 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 Holzheuff6b8ea2006-09-20 15:58:49 +02001113
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001114static 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 Holzheuff6b8ea2006-09-20 15:58:49 +02001136}
1137
Hongjie Yangfe355b72007-02-05 21:18:24 +01001138static int __init reipl_nss_init(void)
1139{
1140 int rc;
1141
1142 if (!MACHINE_IS_VM)
1143 return 0;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001144
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-Hartmand91885b2007-11-02 17:17:00 -04001152 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
Hongjie Yangfe355b72007-02-05 21:18:24 +01001153 if (rc)
1154 return rc;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001155
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 Yangfe355b72007-02-05 21:18:24 +01001169 reipl_capabilities |= IPL_TYPE_NSS;
1170 return 0;
1171}
1172
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001173static 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 Bruecknera0443fb2008-07-14 09:59:09 +02001180
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 Holzheuff6b8ea2006-09-20 15:58:49 +02001191 }
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001192 if (rc)
1193 return rc;
1194
1195 reipl_block_ccw_init(reipl_block_ccw);
1196 if (ipl_info.type == IPL_TYPE_CCW) {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001197 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001198 reipl_block_ccw_fill_parms(reipl_block_ccw);
1199 }
1200
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001201 reipl_capabilities |= IPL_TYPE_CCW;
1202 return 0;
1203}
1204
1205static int __init reipl_fcp_init(void)
1206{
1207 int rc;
1208
Michael Holzheu008d2d12009-03-26 15:24:51 +01001209 if (!diag308_set_works) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001210 if (ipl_info.type == IPL_TYPE_FCP) {
Michael Holzheu008d2d12009-03-26 15:24:51 +01001211 make_attrs_ro(reipl_fcp_attrs);
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001212 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1213 } else
Michael Holzheu008d2d12009-03-26 15:24:51 +01001214 return 0;
1215 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001216
1217 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1218 if (!reipl_block_fcp)
1219 return -ENOMEM;
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001220
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 Lawall798620f2011-08-24 17:15:11 +02001224 if (!reipl_fcp_kset) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001225 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 Holzheuff6b8ea2006-09-20 15:58:49 +02001230 if (rc) {
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001231 kset_unregister(reipl_fcp_kset);
1232 free_page((unsigned long) reipl_block_fcp);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001233 return rc;
1234 }
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001235
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 Holzheuff6b8ea2006-09-20 15:58:49 +02001246 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
Hendrik Brueckner684d2fd2009-09-11 10:28:40 +02001247 else {
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001248 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1249 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
Michael Holzheufbb04f32007-03-19 13:19:03 +01001250 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001251 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 Carstens2bc89b52008-02-05 16:50:40 +01001258static int __init reipl_init(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001259{
1260 int rc;
1261
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001262 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001263 if (!reipl_kset)
1264 return -ENOMEM;
1265 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001266 if (rc) {
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001267 kset_unregister(reipl_kset);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001268 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 Yangfe355b72007-02-05 21:18:24 +01001276 rc = reipl_nss_init();
1277 if (rc)
1278 return rc;
Michael Holzheu411ed322007-04-27 16:01:49 +02001279 rc = reipl_set_type(ipl_info.type);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001280 if (rc)
1281 return rc;
1282 return 0;
1283}
1284
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001285static struct shutdown_action __refdata reipl_action = {
1286 .name = SHUTDOWN_ACTION_REIPL_STR,
1287 .fn = reipl_run,
1288 .init = reipl_init,
1289};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001290
1291/*
1292 * dump shutdown action: Dump Linux on shutdown.
1293 */
1294
1295/* FCP dump device attributes */
1296
1297DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1298 dump_block_fcp->ipl_info.fcp.wwpn);
1299DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1300 dump_block_fcp->ipl_info.fcp.lun);
1301DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1302 dump_block_fcp->ipl_info.fcp.bootprog);
1303DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1304 dump_block_fcp->ipl_info.fcp.br_lba);
1305DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1306 dump_block_fcp->ipl_info.fcp.devno);
1307
1308static 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
1317static 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
1324DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1325 dump_block_ccw->ipl_info.ccw.devno);
1326
1327static struct attribute *dump_ccw_attrs[] = {
1328 &sys_dump_ccw_device_attr.attr,
1329 NULL,
1330};
1331
1332static struct attribute_group dump_ccw_attr_group = {
1333 .name = IPL_CCW_STR,
1334 .attrs = dump_ccw_attrs,
1335};
1336
1337/* dump type */
1338
1339static 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 Holzheu48657d22008-01-26 14:11:17 +01001345 if (diag308_set_works)
1346 dump_method = DUMP_METHOD_CCW_DIAG;
1347 else if (MACHINE_IS_VM)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001348 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
1362static 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
1368static 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
1383static struct kobj_attribute dump_type_attr =
1384 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1385
1386static struct kset *dump_kset;
1387
Heiko Carstens2c2df112010-02-26 22:37:34 +01001388static void __dump_run(void *unused)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001389{
1390 struct ccw_dev_id devid;
1391 static char buf[100];
1392
1393 switch (dump_method) {
1394 case DUMP_METHOD_CCW_CIO:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001395 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 Holzheu99ca4e52008-01-26 14:11:11 +01001400 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 Carstens2c2df112010-02-26 22:37:34 +01001413 default:
1414 break;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001415 }
Heiko Carstens2c2df112010-02-26 22:37:34 +01001416}
1417
1418static void dump_run(struct shutdown_trigger *trigger)
1419{
1420 if (dump_method == DUMP_METHOD_NONE)
1421 return;
1422 smp_send_stop();
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001423 smp_call_ipl_cpu(__dump_run, NULL);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001424}
1425
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001426static 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-Hartmand91885b2007-11-02 17:17:00 -04001433 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001434 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 Holzheufbb04f32007-03-19 13:19:03 +01001440 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001441 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
Michael Holzheu411ed322007-04-27 16:01:49 +02001442 dump_capabilities |= DUMP_TYPE_CCW;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001443 return 0;
1444}
1445
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001446static int __init dump_fcp_init(void)
1447{
1448 int rc;
1449
Heiko Carstens05dd2532007-07-10 11:24:09 +02001450 if (!sclp_ipl_info.has_dump)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001451 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-Hartmand91885b2007-11-02 17:17:00 -04001457 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001458 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 Holzheufbb04f32007-03-19 13:19:03 +01001464 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001465 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1466 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
Michael Holzheu411ed322007-04-27 16:01:49 +02001467 dump_capabilities |= DUMP_TYPE_FCP;
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001468 return 0;
1469}
1470
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001471static int __init dump_init(void)
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001472{
1473 int rc;
1474
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001475 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001476 if (!dump_kset)
1477 return -ENOMEM;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001478 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001479 if (rc) {
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001480 kset_unregister(dump_kset);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001481 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 Holzheu411ed322007-04-27 16:01:49 +02001489 dump_set_type(DUMP_TYPE_NONE);
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001490 return 0;
1491}
1492
Heiko Carstens2bc89b52008-02-05 16:50:40 +01001493static struct shutdown_action __refdata dump_action = {
1494 .name = SHUTDOWN_ACTION_DUMP_STR,
1495 .fn = dump_run,
1496 .init = dump_init,
1497};
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001498
Frank Munzert099b7652009-03-26 15:23:43 +01001499static void dump_reipl_run(struct shutdown_trigger *trigger)
1500{
Michael Holzheub43445ff2012-03-11 11:59:28 -04001501 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 Munzert099b7652009-03-26 15:23:43 +01001507 dump_run(trigger);
1508}
1509
1510static int __init dump_reipl_init(void)
1511{
1512 if (!diag308_set_works)
1513 return -EOPNOTSUPP;
1514 else
1515 return 0;
1516}
1517
1518static 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 Holzheu99ca4e52008-01-26 14:11:11 +01001524/*
1525 * vmcmd shutdown action: Trigger vm command on shutdown.
1526 */
1527
1528static char vmcmd_on_reboot[128];
1529static char vmcmd_on_panic[128];
1530static char vmcmd_on_halt[128];
1531static char vmcmd_on_poff[128];
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001532static char vmcmd_on_restart[128];
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001533
1534DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1535DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1536DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1537DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001538DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001539
1540static 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 Holzheu7dd6b332011-08-03 16:44:19 +02001545 &sys_vmcmd_on_restart_attr.attr,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001546 NULL,
1547};
1548
1549static struct attribute_group vmcmd_attr_group = {
1550 .attrs = vmcmd_attrs,
1551};
1552
1553static struct kset *vmcmd_kset;
1554
1555static 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 Holzheu7dd6b332011-08-03 16:44:19 +02001567 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1568 cmd = vmcmd_on_restart;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001569 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
1585static int vmcmd_init(void)
1586{
1587 if (!MACHINE_IS_VM)
Heiko Carstensb8e660b2010-02-26 22:37:41 +01001588 return -EOPNOTSUPP;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001589 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
1595static 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
1602static void stop_run(struct shutdown_trigger *trigger)
1603{
Michael Holzheue1202ed2011-08-24 17:15:12 +02001604 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1605 strcmp(trigger->name, ON_RESTART_STR) == 0)
Michael Holzheuc6547492008-01-26 14:11:12 +01001606 disabled_wait((unsigned long) __builtin_return_address(0));
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001607 smp_stop_cpu();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001608}
1609
1610static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1611 stop_run, NULL};
1612
1613/* action list */
1614
1615static struct shutdown_action *shutdown_actions_list[] = {
Frank Munzert099b7652009-03-26 15:23:43 +01001616 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1617 &vmcmd_action, &stop_action};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001618#define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1619
1620/*
1621 * Trigger section
1622 */
1623
1624static struct kset *shutdown_actions_kset;
1625
1626static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1627 size_t len)
1628{
1629 int i;
Frank Munzert099b7652009-03-26 15:23:43 +01001630
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001631 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
Frank Munzert099b7652009-03-26 15:23:43 +01001632 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
Frank Munzert81088812009-07-07 16:37:07 +02001633 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 Holzheu99ca4e52008-01-26 14:11:11 +01001639 }
1640 }
1641 return -EINVAL;
1642}
1643
1644/* on reipl */
1645
1646static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1647 &reipl_action};
1648
1649static 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
1655static 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
1662static struct kobj_attribute on_reboot_attr =
1663 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1664
1665static 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}
1671void (*_machine_restart)(char *command) = do_machine_restart;
1672
1673/* on panic */
1674
1675static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1676
1677static 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
1683static 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
1690static struct kobj_attribute on_panic_attr =
1691 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1692
1693static void do_panic(void)
1694{
1695 on_panic_trigger.action->fn(&on_panic_trigger);
1696 stop_run(&on_panic_trigger);
1697}
1698
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001699/* on restart */
1700
1701static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
Michael Holzheue1202ed2011-08-24 17:15:12 +02001702 &stop_action};
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001703
1704static 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
1710static 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
1717static struct kobj_attribute on_restart_attr =
1718 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1719
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001720static void __do_restart(void *ignore)
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001721{
1722 smp_send_stop();
Michael Holzheu60a0c682011-10-30 15:16:40 +01001723#ifdef CONFIG_CRASH_DUMP
1724 crash_kexec(NULL);
1725#endif
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001726 on_restart_trigger.action->fn(&on_restart_trigger);
1727 stop_run(&on_restart_trigger);
1728}
1729
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001730void do_restart(void)
1731{
1732 smp_call_online_cpu(__do_restart, NULL);
1733}
1734
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001735/* on halt */
1736
1737static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1738
1739static 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
1745static 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
1752static struct kobj_attribute on_halt_attr =
1753 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1754
1755
1756static 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}
1762void (*_machine_halt)(void) = do_machine_halt;
1763
1764/* on power off */
1765
1766static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1767
1768static 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
1774static 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
1781static struct kobj_attribute on_poff_attr =
1782 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1783
1784
1785static 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}
1791void (*_machine_power_off)(void) = do_machine_power_off;
1792
1793static void __init shutdown_triggers_init(void)
1794{
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001795 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001796 firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001797 if (!shutdown_actions_kset)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001798 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 Holzheu7dd6b332011-08-03 16:44:19 +02001811 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1812 &on_restart_attr.attr))
1813 goto fail;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001814 return;
1815fail:
1816 panic("shutdown_triggers_init failed\n");
1817}
1818
1819static 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 Munzert81088812009-07-07 16:37:07 +02001826 shutdown_actions_list[i]->init_rc =
1827 shutdown_actions_list[i]->init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001828 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001829}
1830
1831static int __init s390_ipl_init(void)
1832{
Michael Holzheud09293a2008-01-26 14:11:15 +01001833 sclp_get_ipl_info(&sclp_ipl_info);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001834 shutdown_actions_init();
1835 shutdown_triggers_init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001836 return 0;
1837}
1838
1839__initcall(s390_ipl_init);
Heiko Carstens15e9b582006-12-04 15:40:26 +01001840
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001841static 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
1855static 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
1866static 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
1877static 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
1888static 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
1899static int on_panic_notify(struct notifier_block *self,
1900 unsigned long event, void *data)
1901{
1902 do_panic();
1903 return NOTIFY_OK;
1904}
1905
1906static struct notifier_block on_panic_nb = {
1907 .notifier_call = on_panic_notify,
Michael Holzheu7e9b5802009-03-26 15:24:55 +01001908 .priority = INT_MIN,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001909};
1910
1911void __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 Holzheu99ca4e52008-01-26 14:11:11 +01001932 /* We have no info to copy */
1933 break;
1934 }
1935 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1936}
1937
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001938void __init ipl_update_parameters(void)
1939{
Michael Holzheu3a95e8e2008-08-01 16:39:10 +02001940 int rc;
1941
1942 rc = diag308(DIAG308_STORE, &ipl_block);
1943 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001944 diag308_set_works = 1;
1945}
1946
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001947void __init ipl_save_parameters(void)
1948{
1949 struct cio_iplinfo iplinfo;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001950 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 Carstenscbb870c2010-02-26 22:37:43 +01001960 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001961 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1962 memmove(dst, src, PAGE_SIZE);
Heiko Carstenscbb870c2010-02-26 22:37:43 +01001963 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001964}
1965
Heiko Carstens15e9b582006-12-04 15:40:26 +01001966static LIST_HEAD(rcall);
1967static DEFINE_MUTEX(rcall_mutex);
1968
1969void 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}
1975EXPORT_SYMBOL_GPL(register_reset_call);
1976
1977void unregister_reset_call(struct reset_call *reset)
1978{
1979 mutex_lock(&rcall_mutex);
1980 list_del(&reset->list);
1981 mutex_unlock(&rcall_mutex);
1982}
1983EXPORT_SYMBOL_GPL(unregister_reset_call);
1984
1985static void do_reset_calls(void)
1986{
1987 struct reset_call *reset;
1988
Michael Holzheu9dc73562011-08-03 16:44:22 +02001989#ifdef CONFIG_64BIT
1990 if (diag308_set_works) {
1991 diag308_reset();
1992 return;
1993 }
1994#endif
Heiko Carstens15e9b582006-12-04 15:40:26 +01001995 list_for_each_entry(reset, &rcall, list)
1996 reset->fn();
1997}
1998
Heiko Carstensc5dd8582007-03-05 23:35:43 +01001999u32 dump_prefix_page;
Heiko Carstens15e9b582006-12-04 15:40:26 +01002000
Michael Holzheu60a0c682011-10-30 15:16:40 +01002001void s390_reset_system(void (*func)(void *), void *data)
Heiko Carstens15e9b582006-12-04 15:40:26 +01002002{
2003 struct _lowcore *lc;
2004
Heiko Carstens15e9b582006-12-04 15:40:26 +01002005 lc = (struct _lowcore *)(unsigned long) store_prefix();
Michael Holzheua45e1412006-12-15 17:18:22 +01002006
2007 /* Stack for interrupt/machine check handler */
Heiko Carstens15e9b582006-12-04 15:40:26 +01002008 lc->panic_stack = S390_lowcore.panic_stack;
2009
Michael Holzheuda1cf232006-12-15 17:18:27 +01002010 /* Save prefix page address for dump case */
Heiko Carstensc5dd8582007-03-05 23:35:43 +01002011 dump_prefix_page = (u32)(unsigned long) lc;
Michael Holzheuda1cf232006-12-15 17:18:27 +01002012
Heiko Carstens15e9b582006-12-04 15:40:26 +01002013 /* 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 Schwidefskyb50511e2011-10-30 15:16:50 +01002020 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
Heiko Carstens15e9b582006-12-04 15:40:26 +01002021 S390_lowcore.mcck_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01002022 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01002023
2024 /* Set new program check handler */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +01002025 S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
Michael Holzheua45e1412006-12-15 17:18:22 +01002026 S390_lowcore.program_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01002027 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01002028
Michael Holzheu60a0c682011-10-30 15:16:40 +01002029 /* Store status at absolute zero */
2030 store_status();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01002031
Michael Holzheu60a0c682011-10-30 15:16:40 +01002032 do_reset_calls();
2033 if (func)
2034 func(data);
2035}