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