blob: e5a72a2b0c560d0cafac5967b81ba3927d9ac356 [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{
1501 preempt_disable();
1502 /*
1503 * Bypass dynamic address translation (DAT) when storing IPL parameter
1504 * information block address and checksum into the prefix area
1505 * (corresponding to absolute addresses 0-8191).
1506 * When enhanced DAT applies and the STE format control in one,
1507 * the absolute address is formed without prefixing. In this case a
1508 * normal store (stg/st) into the prefix area would no more match to
1509 * absolute addresses 0-8191.
1510 */
1511#ifdef CONFIG_64BIT
1512 asm volatile("sturg %0,%1"
1513 :: "a" ((unsigned long) reipl_block_actual),
1514 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1515#else
1516 asm volatile("stura %0,%1"
1517 :: "a" ((unsigned long) reipl_block_actual),
1518 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1519#endif
1520 asm volatile("stura %0,%1"
Frank Munzert159d1ff2009-03-26 15:24:45 +01001521 :: "a" (csum_partial(reipl_block_actual,
1522 reipl_block_actual->hdr.len, 0)),
Frank Munzert099b7652009-03-26 15:23:43 +01001523 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1524 preempt_enable();
1525 dump_run(trigger);
1526}
1527
1528static int __init dump_reipl_init(void)
1529{
1530 if (!diag308_set_works)
1531 return -EOPNOTSUPP;
1532 else
1533 return 0;
1534}
1535
1536static struct shutdown_action __refdata dump_reipl_action = {
1537 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1538 .fn = dump_reipl_run,
1539 .init = dump_reipl_init,
1540};
1541
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001542/*
1543 * vmcmd shutdown action: Trigger vm command on shutdown.
1544 */
1545
1546static char vmcmd_on_reboot[128];
1547static char vmcmd_on_panic[128];
1548static char vmcmd_on_halt[128];
1549static char vmcmd_on_poff[128];
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001550static char vmcmd_on_restart[128];
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001551
1552DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1553DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1554DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1555DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001556DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001557
1558static struct attribute *vmcmd_attrs[] = {
1559 &sys_vmcmd_on_reboot_attr.attr,
1560 &sys_vmcmd_on_panic_attr.attr,
1561 &sys_vmcmd_on_halt_attr.attr,
1562 &sys_vmcmd_on_poff_attr.attr,
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001563 &sys_vmcmd_on_restart_attr.attr,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001564 NULL,
1565};
1566
1567static struct attribute_group vmcmd_attr_group = {
1568 .attrs = vmcmd_attrs,
1569};
1570
1571static struct kset *vmcmd_kset;
1572
1573static void vmcmd_run(struct shutdown_trigger *trigger)
1574{
1575 char *cmd, *next_cmd;
1576
1577 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1578 cmd = vmcmd_on_reboot;
1579 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1580 cmd = vmcmd_on_panic;
1581 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1582 cmd = vmcmd_on_halt;
1583 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1584 cmd = vmcmd_on_poff;
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001585 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1586 cmd = vmcmd_on_restart;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001587 else
1588 return;
1589
1590 if (strlen(cmd) == 0)
1591 return;
1592 do {
1593 next_cmd = strchr(cmd, '\n');
1594 if (next_cmd) {
1595 next_cmd[0] = 0;
1596 next_cmd += 1;
1597 }
1598 __cpcmd(cmd, NULL, 0, NULL);
1599 cmd = next_cmd;
1600 } while (cmd != NULL);
1601}
1602
1603static int vmcmd_init(void)
1604{
1605 if (!MACHINE_IS_VM)
Heiko Carstensb8e660b2010-02-26 22:37:41 +01001606 return -EOPNOTSUPP;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001607 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1608 if (!vmcmd_kset)
1609 return -ENOMEM;
1610 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1611}
1612
1613static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1614 vmcmd_run, vmcmd_init};
1615
1616/*
1617 * stop shutdown action: Stop Linux on shutdown.
1618 */
1619
1620static void stop_run(struct shutdown_trigger *trigger)
1621{
Michael Holzheue1202ed2011-08-24 17:15:12 +02001622 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1623 strcmp(trigger->name, ON_RESTART_STR) == 0)
Michael Holzheuc6547492008-01-26 14:11:12 +01001624 disabled_wait((unsigned long) __builtin_return_address(0));
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001625 smp_stop_cpu();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001626}
1627
1628static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1629 stop_run, NULL};
1630
1631/* action list */
1632
1633static struct shutdown_action *shutdown_actions_list[] = {
Frank Munzert099b7652009-03-26 15:23:43 +01001634 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1635 &vmcmd_action, &stop_action};
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001636#define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1637
1638/*
1639 * Trigger section
1640 */
1641
1642static struct kset *shutdown_actions_kset;
1643
1644static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1645 size_t len)
1646{
1647 int i;
Frank Munzert099b7652009-03-26 15:23:43 +01001648
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001649 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
Frank Munzert099b7652009-03-26 15:23:43 +01001650 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
Frank Munzert81088812009-07-07 16:37:07 +02001651 if (shutdown_actions_list[i]->init_rc) {
1652 return shutdown_actions_list[i]->init_rc;
1653 } else {
1654 trigger->action = shutdown_actions_list[i];
1655 return len;
1656 }
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001657 }
1658 }
1659 return -EINVAL;
1660}
1661
1662/* on reipl */
1663
1664static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1665 &reipl_action};
1666
1667static ssize_t on_reboot_show(struct kobject *kobj,
1668 struct kobj_attribute *attr, char *page)
1669{
1670 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1671}
1672
1673static ssize_t on_reboot_store(struct kobject *kobj,
1674 struct kobj_attribute *attr,
1675 const char *buf, size_t len)
1676{
1677 return set_trigger(buf, &on_reboot_trigger, len);
1678}
1679
1680static struct kobj_attribute on_reboot_attr =
1681 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1682
1683static void do_machine_restart(char *__unused)
1684{
1685 smp_send_stop();
1686 on_reboot_trigger.action->fn(&on_reboot_trigger);
1687 reipl_run(NULL);
1688}
1689void (*_machine_restart)(char *command) = do_machine_restart;
1690
1691/* on panic */
1692
1693static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1694
1695static ssize_t on_panic_show(struct kobject *kobj,
1696 struct kobj_attribute *attr, char *page)
1697{
1698 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1699}
1700
1701static ssize_t on_panic_store(struct kobject *kobj,
1702 struct kobj_attribute *attr,
1703 const char *buf, size_t len)
1704{
1705 return set_trigger(buf, &on_panic_trigger, len);
1706}
1707
1708static struct kobj_attribute on_panic_attr =
1709 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1710
1711static void do_panic(void)
1712{
1713 on_panic_trigger.action->fn(&on_panic_trigger);
1714 stop_run(&on_panic_trigger);
1715}
1716
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001717/* on restart */
1718
1719static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
Michael Holzheue1202ed2011-08-24 17:15:12 +02001720 &stop_action};
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001721
1722static ssize_t on_restart_show(struct kobject *kobj,
1723 struct kobj_attribute *attr, char *page)
1724{
1725 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1726}
1727
1728static ssize_t on_restart_store(struct kobject *kobj,
1729 struct kobj_attribute *attr,
1730 const char *buf, size_t len)
1731{
1732 return set_trigger(buf, &on_restart_trigger, len);
1733}
1734
1735static struct kobj_attribute on_restart_attr =
1736 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1737
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001738static void __do_restart(void *ignore)
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001739{
1740 smp_send_stop();
Michael Holzheu60a0c682011-10-30 15:16:40 +01001741#ifdef CONFIG_CRASH_DUMP
1742 crash_kexec(NULL);
1743#endif
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001744 on_restart_trigger.action->fn(&on_restart_trigger);
1745 stop_run(&on_restart_trigger);
1746}
1747
Martin Schwidefsky8b646bd2012-03-11 11:59:26 -04001748void do_restart(void)
1749{
1750 smp_call_online_cpu(__do_restart, NULL);
1751}
1752
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001753/* on halt */
1754
1755static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1756
1757static ssize_t on_halt_show(struct kobject *kobj,
1758 struct kobj_attribute *attr, char *page)
1759{
1760 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1761}
1762
1763static ssize_t on_halt_store(struct kobject *kobj,
1764 struct kobj_attribute *attr,
1765 const char *buf, size_t len)
1766{
1767 return set_trigger(buf, &on_halt_trigger, len);
1768}
1769
1770static struct kobj_attribute on_halt_attr =
1771 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1772
1773
1774static void do_machine_halt(void)
1775{
1776 smp_send_stop();
1777 on_halt_trigger.action->fn(&on_halt_trigger);
1778 stop_run(&on_halt_trigger);
1779}
1780void (*_machine_halt)(void) = do_machine_halt;
1781
1782/* on power off */
1783
1784static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1785
1786static ssize_t on_poff_show(struct kobject *kobj,
1787 struct kobj_attribute *attr, char *page)
1788{
1789 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1790}
1791
1792static ssize_t on_poff_store(struct kobject *kobj,
1793 struct kobj_attribute *attr,
1794 const char *buf, size_t len)
1795{
1796 return set_trigger(buf, &on_poff_trigger, len);
1797}
1798
1799static struct kobj_attribute on_poff_attr =
1800 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1801
1802
1803static void do_machine_power_off(void)
1804{
1805 smp_send_stop();
1806 on_poff_trigger.action->fn(&on_poff_trigger);
1807 stop_run(&on_poff_trigger);
1808}
1809void (*_machine_power_off)(void) = do_machine_power_off;
1810
1811static void __init shutdown_triggers_init(void)
1812{
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001813 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
Greg Kroah-Hartmanf62ed9e2007-11-05 13:16:15 -08001814 firmware_kobj);
Greg Kroah-Hartmand91885b2007-11-02 17:17:00 -04001815 if (!shutdown_actions_kset)
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001816 goto fail;
1817 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1818 &on_reboot_attr.attr))
1819 goto fail;
1820 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1821 &on_panic_attr.attr))
1822 goto fail;
1823 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1824 &on_halt_attr.attr))
1825 goto fail;
1826 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1827 &on_poff_attr.attr))
1828 goto fail;
Michael Holzheu7dd6b332011-08-03 16:44:19 +02001829 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1830 &on_restart_attr.attr))
1831 goto fail;
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001832 return;
1833fail:
1834 panic("shutdown_triggers_init failed\n");
1835}
1836
1837static void __init shutdown_actions_init(void)
1838{
1839 int i;
1840
1841 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1842 if (!shutdown_actions_list[i]->init)
1843 continue;
Frank Munzert81088812009-07-07 16:37:07 +02001844 shutdown_actions_list[i]->init_rc =
1845 shutdown_actions_list[i]->init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001846 }
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001847}
1848
1849static int __init s390_ipl_init(void)
1850{
Michael Holzheud09293a2008-01-26 14:11:15 +01001851 sclp_get_ipl_info(&sclp_ipl_info);
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001852 shutdown_actions_init();
1853 shutdown_triggers_init();
Michael Holzheuff6b8ea2006-09-20 15:58:49 +02001854 return 0;
1855}
1856
1857__initcall(s390_ipl_init);
Heiko Carstens15e9b582006-12-04 15:40:26 +01001858
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001859static void __init strncpy_skip_quote(char *dst, char *src, int n)
1860{
1861 int sx, dx;
1862
1863 dx = 0;
1864 for (sx = 0; src[sx] != 0; sx++) {
1865 if (src[sx] == '"')
1866 continue;
1867 dst[dx++] = src[sx];
1868 if (dx >= n)
1869 break;
1870 }
1871}
1872
1873static int __init vmcmd_on_reboot_setup(char *str)
1874{
1875 if (!MACHINE_IS_VM)
1876 return 1;
1877 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1878 vmcmd_on_reboot[127] = 0;
1879 on_reboot_trigger.action = &vmcmd_action;
1880 return 1;
1881}
1882__setup("vmreboot=", vmcmd_on_reboot_setup);
1883
1884static int __init vmcmd_on_panic_setup(char *str)
1885{
1886 if (!MACHINE_IS_VM)
1887 return 1;
1888 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1889 vmcmd_on_panic[127] = 0;
1890 on_panic_trigger.action = &vmcmd_action;
1891 return 1;
1892}
1893__setup("vmpanic=", vmcmd_on_panic_setup);
1894
1895static int __init vmcmd_on_halt_setup(char *str)
1896{
1897 if (!MACHINE_IS_VM)
1898 return 1;
1899 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1900 vmcmd_on_halt[127] = 0;
1901 on_halt_trigger.action = &vmcmd_action;
1902 return 1;
1903}
1904__setup("vmhalt=", vmcmd_on_halt_setup);
1905
1906static int __init vmcmd_on_poff_setup(char *str)
1907{
1908 if (!MACHINE_IS_VM)
1909 return 1;
1910 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1911 vmcmd_on_poff[127] = 0;
1912 on_poff_trigger.action = &vmcmd_action;
1913 return 1;
1914}
1915__setup("vmpoff=", vmcmd_on_poff_setup);
1916
1917static int on_panic_notify(struct notifier_block *self,
1918 unsigned long event, void *data)
1919{
1920 do_panic();
1921 return NOTIFY_OK;
1922}
1923
1924static struct notifier_block on_panic_nb = {
1925 .notifier_call = on_panic_notify,
Michael Holzheu7e9b5802009-03-26 15:24:55 +01001926 .priority = INT_MIN,
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001927};
1928
1929void __init setup_ipl(void)
1930{
1931 ipl_info.type = get_ipl_type();
1932 switch (ipl_info.type) {
1933 case IPL_TYPE_CCW:
1934 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1935 ipl_info.data.ccw.dev_id.ssid = 0;
1936 break;
1937 case IPL_TYPE_FCP:
1938 case IPL_TYPE_FCP_DUMP:
1939 ipl_info.data.fcp.dev_id.devno =
1940 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1941 ipl_info.data.fcp.dev_id.ssid = 0;
1942 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1943 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1944 break;
1945 case IPL_TYPE_NSS:
1946 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1947 sizeof(ipl_info.data.nss.name));
1948 break;
1949 case IPL_TYPE_UNKNOWN:
Michael Holzheu99ca4e52008-01-26 14:11:11 +01001950 /* We have no info to copy */
1951 break;
1952 }
1953 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1954}
1955
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001956void __init ipl_update_parameters(void)
1957{
Michael Holzheu3a95e8e2008-08-01 16:39:10 +02001958 int rc;
1959
1960 rc = diag308(DIAG308_STORE, &ipl_block);
1961 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
Hendrik Bruecknera0443fb2008-07-14 09:59:09 +02001962 diag308_set_works = 1;
1963}
1964
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001965void __init ipl_save_parameters(void)
1966{
1967 struct cio_iplinfo iplinfo;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001968 void *src, *dst;
1969
1970 if (cio_get_iplinfo(&iplinfo))
1971 return;
1972
1973 ipl_devno = iplinfo.devno;
1974 ipl_flags |= IPL_DEVNO_VALID;
1975 if (!iplinfo.is_qdio)
1976 return;
1977 ipl_flags |= IPL_PARMBLOCK_VALID;
Heiko Carstenscbb870c2010-02-26 22:37:43 +01001978 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001979 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1980 memmove(dst, src, PAGE_SIZE);
Heiko Carstenscbb870c2010-02-26 22:37:43 +01001981 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
Heiko Carstens6fc321f2007-04-27 16:01:25 +02001982}
1983
Heiko Carstens15e9b582006-12-04 15:40:26 +01001984static LIST_HEAD(rcall);
1985static DEFINE_MUTEX(rcall_mutex);
1986
1987void register_reset_call(struct reset_call *reset)
1988{
1989 mutex_lock(&rcall_mutex);
1990 list_add(&reset->list, &rcall);
1991 mutex_unlock(&rcall_mutex);
1992}
1993EXPORT_SYMBOL_GPL(register_reset_call);
1994
1995void unregister_reset_call(struct reset_call *reset)
1996{
1997 mutex_lock(&rcall_mutex);
1998 list_del(&reset->list);
1999 mutex_unlock(&rcall_mutex);
2000}
2001EXPORT_SYMBOL_GPL(unregister_reset_call);
2002
2003static void do_reset_calls(void)
2004{
2005 struct reset_call *reset;
2006
Michael Holzheu9dc73562011-08-03 16:44:22 +02002007#ifdef CONFIG_64BIT
2008 if (diag308_set_works) {
2009 diag308_reset();
2010 return;
2011 }
2012#endif
Heiko Carstens15e9b582006-12-04 15:40:26 +01002013 list_for_each_entry(reset, &rcall, list)
2014 reset->fn();
2015}
2016
Heiko Carstensc5dd8582007-03-05 23:35:43 +01002017u32 dump_prefix_page;
Heiko Carstens15e9b582006-12-04 15:40:26 +01002018
Michael Holzheu60a0c682011-10-30 15:16:40 +01002019void s390_reset_system(void (*func)(void *), void *data)
Heiko Carstens15e9b582006-12-04 15:40:26 +01002020{
2021 struct _lowcore *lc;
2022
Heiko Carstens15e9b582006-12-04 15:40:26 +01002023 lc = (struct _lowcore *)(unsigned long) store_prefix();
Michael Holzheua45e1412006-12-15 17:18:22 +01002024
2025 /* Stack for interrupt/machine check handler */
Heiko Carstens15e9b582006-12-04 15:40:26 +01002026 lc->panic_stack = S390_lowcore.panic_stack;
2027
Michael Holzheuda1cf232006-12-15 17:18:27 +01002028 /* Save prefix page address for dump case */
Heiko Carstensc5dd8582007-03-05 23:35:43 +01002029 dump_prefix_page = (u32)(unsigned long) lc;
Michael Holzheuda1cf232006-12-15 17:18:27 +01002030
Heiko Carstens15e9b582006-12-04 15:40:26 +01002031 /* Disable prefixing */
2032 set_prefix(0);
2033
2034 /* Disable lowcore protection */
2035 __ctl_clear_bit(0,28);
2036
2037 /* Set new machine check handler */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +01002038 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
Heiko Carstens15e9b582006-12-04 15:40:26 +01002039 S390_lowcore.mcck_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01002040 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01002041
2042 /* Set new program check handler */
Martin Schwidefskyb50511e2011-10-30 15:16:50 +01002043 S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
Michael Holzheua45e1412006-12-15 17:18:22 +01002044 S390_lowcore.program_new_psw.addr =
Heiko Carstensab14de62007-02-05 21:18:37 +01002045 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
Michael Holzheua45e1412006-12-15 17:18:22 +01002046
Michael Holzheu60a0c682011-10-30 15:16:40 +01002047 /* Store status at absolute zero */
2048 store_status();
Michael Holzheu99ca4e52008-01-26 14:11:11 +01002049
Michael Holzheu60a0c682011-10-30 15:16:40 +01002050 do_reset_calls();
2051 if (func)
2052 func(data);
2053}