[S390] Fix couple of section mismatches.
[deliverable/linux.git] / arch / s390 / kernel / ipl.c
1 /*
2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
4 *
5 * Copyright IBM Corp. 2005,2007
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>
16 #include <linux/ctype.h>
17 #include <asm/ipl.h>
18 #include <asm/smp.h>
19 #include <asm/setup.h>
20 #include <asm/cpcmd.h>
21 #include <asm/cio.h>
22 #include <asm/ebcdic.h>
23 #include <asm/reset.h>
24 #include <asm/sclp.h>
25
26 #define IPL_PARM_BLOCK_VERSION 0
27
28 #define IPL_UNKNOWN_STR "unknown"
29 #define IPL_CCW_STR "ccw"
30 #define IPL_FCP_STR "fcp"
31 #define IPL_FCP_DUMP_STR "fcp_dump"
32 #define IPL_NSS_STR "nss"
33
34 #define DUMP_CCW_STR "ccw"
35 #define DUMP_FCP_STR "fcp"
36 #define DUMP_NONE_STR "none"
37
38 /*
39 * Four shutdown trigger types are supported:
40 * - panic
41 * - halt
42 * - power off
43 * - reipl
44 */
45 #define ON_PANIC_STR "on_panic"
46 #define ON_HALT_STR "on_halt"
47 #define ON_POFF_STR "on_poff"
48 #define ON_REIPL_STR "on_reboot"
49
50 struct shutdown_action;
51 struct shutdown_trigger {
52 char *name;
53 struct shutdown_action *action;
54 };
55
56 /*
57 * Five shutdown action types are supported:
58 */
59 #define SHUTDOWN_ACTION_IPL_STR "ipl"
60 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
61 #define SHUTDOWN_ACTION_DUMP_STR "dump"
62 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
63 #define SHUTDOWN_ACTION_STOP_STR "stop"
64
65 struct shutdown_action {
66 char *name;
67 void (*fn) (struct shutdown_trigger *trigger);
68 int (*init) (void);
69 };
70
71 static char *ipl_type_str(enum ipl_type type)
72 {
73 switch (type) {
74 case IPL_TYPE_CCW:
75 return IPL_CCW_STR;
76 case IPL_TYPE_FCP:
77 return IPL_FCP_STR;
78 case IPL_TYPE_FCP_DUMP:
79 return IPL_FCP_DUMP_STR;
80 case IPL_TYPE_NSS:
81 return IPL_NSS_STR;
82 case IPL_TYPE_UNKNOWN:
83 default:
84 return IPL_UNKNOWN_STR;
85 }
86 }
87
88 enum dump_type {
89 DUMP_TYPE_NONE = 1,
90 DUMP_TYPE_CCW = 2,
91 DUMP_TYPE_FCP = 4,
92 };
93
94 static char *dump_type_str(enum dump_type type)
95 {
96 switch (type) {
97 case DUMP_TYPE_NONE:
98 return DUMP_NONE_STR;
99 case DUMP_TYPE_CCW:
100 return DUMP_CCW_STR;
101 case DUMP_TYPE_FCP:
102 return DUMP_FCP_STR;
103 default:
104 return NULL;
105 }
106 }
107
108 /*
109 * Must be in data section since the bss section
110 * is not cleared when these are accessed.
111 */
112 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
113 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
114
115 enum ipl_method {
116 REIPL_METHOD_CCW_CIO,
117 REIPL_METHOD_CCW_DIAG,
118 REIPL_METHOD_CCW_VM,
119 REIPL_METHOD_FCP_RO_DIAG,
120 REIPL_METHOD_FCP_RW_DIAG,
121 REIPL_METHOD_FCP_RO_VM,
122 REIPL_METHOD_FCP_DUMP,
123 REIPL_METHOD_NSS,
124 REIPL_METHOD_DEFAULT,
125 };
126
127 enum dump_method {
128 DUMP_METHOD_NONE,
129 DUMP_METHOD_CCW_CIO,
130 DUMP_METHOD_CCW_DIAG,
131 DUMP_METHOD_CCW_VM,
132 DUMP_METHOD_FCP_DIAG,
133 };
134
135 static int diag308_set_works = 0;
136
137 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
138
139 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
140 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
141 static struct ipl_parameter_block *reipl_block_fcp;
142 static struct ipl_parameter_block *reipl_block_ccw;
143
144 static char reipl_nss_name[NSS_NAME_SIZE + 1];
145
146 static int dump_capabilities = DUMP_TYPE_NONE;
147 static enum dump_type dump_type = DUMP_TYPE_NONE;
148 static enum dump_method dump_method = DUMP_METHOD_NONE;
149 static struct ipl_parameter_block *dump_block_fcp;
150 static struct ipl_parameter_block *dump_block_ccw;
151
152 static struct sclp_ipl_info sclp_ipl_info;
153
154 int diag308(unsigned long subcode, void *addr)
155 {
156 register unsigned long _addr asm("0") = (unsigned long) addr;
157 register unsigned long _rc asm("1") = 0;
158
159 asm volatile(
160 " diag %0,%2,0x308\n"
161 "0:\n"
162 EX_TABLE(0b,0b)
163 : "+d" (_addr), "+d" (_rc)
164 : "d" (subcode) : "cc", "memory");
165 return _rc;
166 }
167 EXPORT_SYMBOL_GPL(diag308);
168
169 /* SYSFS */
170
171 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
172 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
173 struct kobj_attribute *attr, \
174 char *page) \
175 { \
176 return sprintf(page, _format, _value); \
177 } \
178 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
179 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
180
181 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
182 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
183 struct kobj_attribute *attr, \
184 char *page) \
185 { \
186 return sprintf(page, _fmt_out, \
187 (unsigned long long) _value); \
188 } \
189 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
190 struct kobj_attribute *attr, \
191 const char *buf, size_t len) \
192 { \
193 unsigned long long value; \
194 if (sscanf(buf, _fmt_in, &value) != 1) \
195 return -EINVAL; \
196 _value = value; \
197 return len; \
198 } \
199 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
200 __ATTR(_name,(S_IRUGO | S_IWUSR), \
201 sys_##_prefix##_##_name##_show, \
202 sys_##_prefix##_##_name##_store);
203
204 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
205 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
206 struct kobj_attribute *attr, \
207 char *page) \
208 { \
209 return sprintf(page, _fmt_out, _value); \
210 } \
211 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
212 struct kobj_attribute *attr, \
213 const char *buf, size_t len) \
214 { \
215 strncpy(_value, buf, sizeof(_value) - 1); \
216 strstrip(_value); \
217 return len; \
218 } \
219 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
220 __ATTR(_name,(S_IRUGO | S_IWUSR), \
221 sys_##_prefix##_##_name##_show, \
222 sys_##_prefix##_##_name##_store);
223
224 static void make_attrs_ro(struct attribute **attrs)
225 {
226 while (*attrs) {
227 (*attrs)->mode = S_IRUGO;
228 attrs++;
229 }
230 }
231
232 /*
233 * ipl section
234 */
235
236 static __init enum ipl_type get_ipl_type(void)
237 {
238 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
239
240 if (ipl_flags & IPL_NSS_VALID)
241 return IPL_TYPE_NSS;
242 if (!(ipl_flags & IPL_DEVNO_VALID))
243 return IPL_TYPE_UNKNOWN;
244 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
245 return IPL_TYPE_CCW;
246 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
247 return IPL_TYPE_UNKNOWN;
248 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
249 return IPL_TYPE_UNKNOWN;
250 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
251 return IPL_TYPE_FCP_DUMP;
252 return IPL_TYPE_FCP;
253 }
254
255 struct ipl_info ipl_info;
256 EXPORT_SYMBOL_GPL(ipl_info);
257
258 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
259 char *page)
260 {
261 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
262 }
263
264 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
265
266 static ssize_t sys_ipl_device_show(struct kobject *kobj,
267 struct kobj_attribute *attr, char *page)
268 {
269 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
270
271 switch (ipl_info.type) {
272 case IPL_TYPE_CCW:
273 return sprintf(page, "0.0.%04x\n", ipl_devno);
274 case IPL_TYPE_FCP:
275 case IPL_TYPE_FCP_DUMP:
276 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
277 default:
278 return 0;
279 }
280 }
281
282 static struct kobj_attribute sys_ipl_device_attr =
283 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
284
285 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
286 char *buf, loff_t off, size_t count)
287 {
288 unsigned int size = IPL_PARMBLOCK_SIZE;
289
290 if (off > size)
291 return 0;
292 if (off + count > size)
293 count = size - off;
294 memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count);
295 return count;
296 }
297
298 static struct bin_attribute ipl_parameter_attr = {
299 .attr = {
300 .name = "binary_parameter",
301 .mode = S_IRUGO,
302 },
303 .size = PAGE_SIZE,
304 .read = &ipl_parameter_read,
305 };
306
307 static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
308 char *buf, loff_t off, size_t count)
309 {
310 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
311 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
312
313 if (off > size)
314 return 0;
315 if (off + count > size)
316 count = size - off;
317 memcpy(buf, scp_data + off, count);
318 return count;
319 }
320
321 static struct bin_attribute ipl_scp_data_attr = {
322 .attr = {
323 .name = "scp_data",
324 .mode = S_IRUGO,
325 },
326 .size = PAGE_SIZE,
327 .read = ipl_scp_data_read,
328 };
329
330 /* FCP ipl device attributes */
331
332 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
333 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
334 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
335 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
336 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
337 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
338 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
339 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
340
341 static struct attribute *ipl_fcp_attrs[] = {
342 &sys_ipl_type_attr.attr,
343 &sys_ipl_device_attr.attr,
344 &sys_ipl_fcp_wwpn_attr.attr,
345 &sys_ipl_fcp_lun_attr.attr,
346 &sys_ipl_fcp_bootprog_attr.attr,
347 &sys_ipl_fcp_br_lba_attr.attr,
348 NULL,
349 };
350
351 static struct attribute_group ipl_fcp_attr_group = {
352 .attrs = ipl_fcp_attrs,
353 };
354
355 /* CCW ipl device attributes */
356
357 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
358 struct kobj_attribute *attr, char *page)
359 {
360 char loadparm[LOADPARM_LEN + 1] = {};
361
362 if (!sclp_ipl_info.is_valid)
363 return sprintf(page, "#unknown#\n");
364 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
365 EBCASC(loadparm, LOADPARM_LEN);
366 strstrip(loadparm);
367 return sprintf(page, "%s\n", loadparm);
368 }
369
370 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
371 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
372
373 static struct attribute *ipl_ccw_attrs[] = {
374 &sys_ipl_type_attr.attr,
375 &sys_ipl_device_attr.attr,
376 &sys_ipl_ccw_loadparm_attr.attr,
377 NULL,
378 };
379
380 static struct attribute_group ipl_ccw_attr_group = {
381 .attrs = ipl_ccw_attrs,
382 };
383
384 /* NSS ipl device attributes */
385
386 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
387
388 static struct attribute *ipl_nss_attrs[] = {
389 &sys_ipl_type_attr.attr,
390 &sys_ipl_nss_name_attr.attr,
391 NULL,
392 };
393
394 static struct attribute_group ipl_nss_attr_group = {
395 .attrs = ipl_nss_attrs,
396 };
397
398 /* UNKNOWN ipl device attributes */
399
400 static struct attribute *ipl_unknown_attrs[] = {
401 &sys_ipl_type_attr.attr,
402 NULL,
403 };
404
405 static struct attribute_group ipl_unknown_attr_group = {
406 .attrs = ipl_unknown_attrs,
407 };
408
409 static struct kset *ipl_kset;
410
411 static int __init ipl_register_fcp_files(void)
412 {
413 int rc;
414
415 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
416 if (rc)
417 goto out;
418 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
419 if (rc)
420 goto out_ipl_parm;
421 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
422 if (!rc)
423 goto out;
424
425 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
426
427 out_ipl_parm:
428 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
429 out:
430 return rc;
431 }
432
433 static void ipl_run(struct shutdown_trigger *trigger)
434 {
435 diag308(DIAG308_IPL, NULL);
436 if (MACHINE_IS_VM)
437 __cpcmd("IPL", NULL, 0, NULL);
438 else if (ipl_info.type == IPL_TYPE_CCW)
439 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
440 }
441
442 static int __init ipl_init(void)
443 {
444 int rc;
445
446 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
447 if (!ipl_kset) {
448 rc = -ENOMEM;
449 goto out;
450 }
451 switch (ipl_info.type) {
452 case IPL_TYPE_CCW:
453 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_ccw_attr_group);
454 break;
455 case IPL_TYPE_FCP:
456 case IPL_TYPE_FCP_DUMP:
457 rc = ipl_register_fcp_files();
458 break;
459 case IPL_TYPE_NSS:
460 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
461 break;
462 default:
463 rc = sysfs_create_group(&ipl_kset->kobj,
464 &ipl_unknown_attr_group);
465 break;
466 }
467 out:
468 if (rc)
469 panic("ipl_init failed: rc = %i\n", rc);
470
471 return 0;
472 }
473
474 static struct shutdown_action __refdata ipl_action = {
475 .name = SHUTDOWN_ACTION_IPL_STR,
476 .fn = ipl_run,
477 .init = ipl_init,
478 };
479
480 /*
481 * reipl shutdown action: Reboot Linux on shutdown.
482 */
483
484 /* FCP reipl device attributes */
485
486 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
487 reipl_block_fcp->ipl_info.fcp.wwpn);
488 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
489 reipl_block_fcp->ipl_info.fcp.lun);
490 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
491 reipl_block_fcp->ipl_info.fcp.bootprog);
492 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
493 reipl_block_fcp->ipl_info.fcp.br_lba);
494 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
495 reipl_block_fcp->ipl_info.fcp.devno);
496
497 static struct attribute *reipl_fcp_attrs[] = {
498 &sys_reipl_fcp_device_attr.attr,
499 &sys_reipl_fcp_wwpn_attr.attr,
500 &sys_reipl_fcp_lun_attr.attr,
501 &sys_reipl_fcp_bootprog_attr.attr,
502 &sys_reipl_fcp_br_lba_attr.attr,
503 NULL,
504 };
505
506 static struct attribute_group reipl_fcp_attr_group = {
507 .name = IPL_FCP_STR,
508 .attrs = reipl_fcp_attrs,
509 };
510
511 /* CCW reipl device attributes */
512
513 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
514 reipl_block_ccw->ipl_info.ccw.devno);
515
516 static void reipl_get_ascii_loadparm(char *loadparm)
517 {
518 memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param,
519 LOADPARM_LEN);
520 EBCASC(loadparm, LOADPARM_LEN);
521 loadparm[LOADPARM_LEN] = 0;
522 strstrip(loadparm);
523 }
524
525 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
526 struct kobj_attribute *attr, char *page)
527 {
528 char buf[LOADPARM_LEN + 1];
529
530 reipl_get_ascii_loadparm(buf);
531 return sprintf(page, "%s\n", buf);
532 }
533
534 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
535 struct kobj_attribute *attr,
536 const char *buf, size_t len)
537 {
538 int i, lp_len;
539
540 /* ignore trailing newline */
541 lp_len = len;
542 if ((len > 0) && (buf[len - 1] == '\n'))
543 lp_len--;
544 /* loadparm can have max 8 characters and must not start with a blank */
545 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
546 return -EINVAL;
547 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
548 for (i = 0; i < lp_len; i++) {
549 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
550 (buf[i] == '.'))
551 continue;
552 return -EINVAL;
553 }
554 /* initialize loadparm with blanks */
555 memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN);
556 /* copy and convert to ebcdic */
557 memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len);
558 ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN);
559 return len;
560 }
561
562 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
563 __ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
564 reipl_ccw_loadparm_store);
565
566 static struct attribute *reipl_ccw_attrs[] = {
567 &sys_reipl_ccw_device_attr.attr,
568 &sys_reipl_ccw_loadparm_attr.attr,
569 NULL,
570 };
571
572 static struct attribute_group reipl_ccw_attr_group = {
573 .name = IPL_CCW_STR,
574 .attrs = reipl_ccw_attrs,
575 };
576
577
578 /* NSS reipl device attributes */
579
580 DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name);
581
582 static struct attribute *reipl_nss_attrs[] = {
583 &sys_reipl_nss_name_attr.attr,
584 NULL,
585 };
586
587 static struct attribute_group reipl_nss_attr_group = {
588 .name = IPL_NSS_STR,
589 .attrs = reipl_nss_attrs,
590 };
591
592 /* reipl type */
593
594 static int reipl_set_type(enum ipl_type type)
595 {
596 if (!(reipl_capabilities & type))
597 return -EINVAL;
598
599 switch(type) {
600 case IPL_TYPE_CCW:
601 if (diag308_set_works)
602 reipl_method = REIPL_METHOD_CCW_DIAG;
603 else if (MACHINE_IS_VM)
604 reipl_method = REIPL_METHOD_CCW_VM;
605 else
606 reipl_method = REIPL_METHOD_CCW_CIO;
607 break;
608 case IPL_TYPE_FCP:
609 if (diag308_set_works)
610 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
611 else if (MACHINE_IS_VM)
612 reipl_method = REIPL_METHOD_FCP_RO_VM;
613 else
614 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
615 break;
616 case IPL_TYPE_FCP_DUMP:
617 reipl_method = REIPL_METHOD_FCP_DUMP;
618 break;
619 case IPL_TYPE_NSS:
620 reipl_method = REIPL_METHOD_NSS;
621 break;
622 case IPL_TYPE_UNKNOWN:
623 reipl_method = REIPL_METHOD_DEFAULT;
624 break;
625 default:
626 BUG();
627 }
628 reipl_type = type;
629 return 0;
630 }
631
632 static ssize_t reipl_type_show(struct kobject *kobj,
633 struct kobj_attribute *attr, char *page)
634 {
635 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
636 }
637
638 static ssize_t reipl_type_store(struct kobject *kobj,
639 struct kobj_attribute *attr,
640 const char *buf, size_t len)
641 {
642 int rc = -EINVAL;
643
644 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
645 rc = reipl_set_type(IPL_TYPE_CCW);
646 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
647 rc = reipl_set_type(IPL_TYPE_FCP);
648 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
649 rc = reipl_set_type(IPL_TYPE_NSS);
650 return (rc != 0) ? rc : len;
651 }
652
653 static struct kobj_attribute reipl_type_attr =
654 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
655
656 static struct kset *reipl_kset;
657
658 void reipl_run(struct shutdown_trigger *trigger)
659 {
660 struct ccw_dev_id devid;
661 static char buf[100];
662 char loadparm[LOADPARM_LEN + 1];
663
664 switch (reipl_method) {
665 case REIPL_METHOD_CCW_CIO:
666 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
667 devid.ssid = 0;
668 reipl_ccw_dev(&devid);
669 break;
670 case REIPL_METHOD_CCW_VM:
671 reipl_get_ascii_loadparm(loadparm);
672 if (strlen(loadparm) == 0)
673 sprintf(buf, "IPL %X CLEAR",
674 reipl_block_ccw->ipl_info.ccw.devno);
675 else
676 sprintf(buf, "IPL %X CLEAR LOADPARM '%s'",
677 reipl_block_ccw->ipl_info.ccw.devno, loadparm);
678 __cpcmd(buf, NULL, 0, NULL);
679 break;
680 case REIPL_METHOD_CCW_DIAG:
681 diag308(DIAG308_SET, reipl_block_ccw);
682 diag308(DIAG308_IPL, NULL);
683 break;
684 case REIPL_METHOD_FCP_RW_DIAG:
685 diag308(DIAG308_SET, reipl_block_fcp);
686 diag308(DIAG308_IPL, NULL);
687 break;
688 case REIPL_METHOD_FCP_RO_DIAG:
689 diag308(DIAG308_IPL, NULL);
690 break;
691 case REIPL_METHOD_FCP_RO_VM:
692 __cpcmd("IPL", NULL, 0, NULL);
693 break;
694 case REIPL_METHOD_NSS:
695 sprintf(buf, "IPL %s", reipl_nss_name);
696 __cpcmd(buf, NULL, 0, NULL);
697 break;
698 case REIPL_METHOD_DEFAULT:
699 if (MACHINE_IS_VM)
700 __cpcmd("IPL", NULL, 0, NULL);
701 diag308(DIAG308_IPL, NULL);
702 break;
703 case REIPL_METHOD_FCP_DUMP:
704 default:
705 break;
706 }
707 }
708
709 static void __init reipl_probe(void)
710 {
711 void *buffer;
712
713 buffer = (void *) get_zeroed_page(GFP_KERNEL);
714 if (!buffer)
715 return;
716 if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK)
717 diag308_set_works = 1;
718 free_page((unsigned long)buffer);
719 }
720
721 static int __init reipl_nss_init(void)
722 {
723 int rc;
724
725 if (!MACHINE_IS_VM)
726 return 0;
727 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
728 if (rc)
729 return rc;
730 strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
731 reipl_capabilities |= IPL_TYPE_NSS;
732 return 0;
733 }
734
735 static int __init reipl_ccw_init(void)
736 {
737 int rc;
738
739 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
740 if (!reipl_block_ccw)
741 return -ENOMEM;
742 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
743 if (rc) {
744 free_page((unsigned long)reipl_block_ccw);
745 return rc;
746 }
747 reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
748 reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
749 reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
750 reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
751 reipl_block_ccw->hdr.flags = DIAG308_FLAGS_LP_VALID;
752 /* check if read scp info worked and set loadparm */
753 if (sclp_ipl_info.is_valid)
754 memcpy(reipl_block_ccw->ipl_info.ccw.load_param,
755 &sclp_ipl_info.loadparm, LOADPARM_LEN);
756 else
757 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
758 memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40,
759 LOADPARM_LEN);
760 if (!MACHINE_IS_VM && !diag308_set_works)
761 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
762 if (ipl_info.type == IPL_TYPE_CCW)
763 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
764 reipl_capabilities |= IPL_TYPE_CCW;
765 return 0;
766 }
767
768 static int __init reipl_fcp_init(void)
769 {
770 int rc;
771
772 if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP))
773 return 0;
774 if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP))
775 make_attrs_ro(reipl_fcp_attrs);
776
777 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
778 if (!reipl_block_fcp)
779 return -ENOMEM;
780 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
781 if (rc) {
782 free_page((unsigned long)reipl_block_fcp);
783 return rc;
784 }
785 if (ipl_info.type == IPL_TYPE_FCP) {
786 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
787 } else {
788 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
789 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
790 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
791 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
792 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
793 }
794 reipl_capabilities |= IPL_TYPE_FCP;
795 return 0;
796 }
797
798 static int __init reipl_init(void)
799 {
800 int rc;
801
802 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
803 if (!reipl_kset)
804 return -ENOMEM;
805 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
806 if (rc) {
807 kset_unregister(reipl_kset);
808 return rc;
809 }
810 rc = reipl_ccw_init();
811 if (rc)
812 return rc;
813 rc = reipl_fcp_init();
814 if (rc)
815 return rc;
816 rc = reipl_nss_init();
817 if (rc)
818 return rc;
819 rc = reipl_set_type(ipl_info.type);
820 if (rc)
821 return rc;
822 return 0;
823 }
824
825 static struct shutdown_action __refdata reipl_action = {
826 .name = SHUTDOWN_ACTION_REIPL_STR,
827 .fn = reipl_run,
828 .init = reipl_init,
829 };
830
831 /*
832 * dump shutdown action: Dump Linux on shutdown.
833 */
834
835 /* FCP dump device attributes */
836
837 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
838 dump_block_fcp->ipl_info.fcp.wwpn);
839 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
840 dump_block_fcp->ipl_info.fcp.lun);
841 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
842 dump_block_fcp->ipl_info.fcp.bootprog);
843 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
844 dump_block_fcp->ipl_info.fcp.br_lba);
845 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
846 dump_block_fcp->ipl_info.fcp.devno);
847
848 static struct attribute *dump_fcp_attrs[] = {
849 &sys_dump_fcp_device_attr.attr,
850 &sys_dump_fcp_wwpn_attr.attr,
851 &sys_dump_fcp_lun_attr.attr,
852 &sys_dump_fcp_bootprog_attr.attr,
853 &sys_dump_fcp_br_lba_attr.attr,
854 NULL,
855 };
856
857 static struct attribute_group dump_fcp_attr_group = {
858 .name = IPL_FCP_STR,
859 .attrs = dump_fcp_attrs,
860 };
861
862 /* CCW dump device attributes */
863
864 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
865 dump_block_ccw->ipl_info.ccw.devno);
866
867 static struct attribute *dump_ccw_attrs[] = {
868 &sys_dump_ccw_device_attr.attr,
869 NULL,
870 };
871
872 static struct attribute_group dump_ccw_attr_group = {
873 .name = IPL_CCW_STR,
874 .attrs = dump_ccw_attrs,
875 };
876
877 /* dump type */
878
879 static int dump_set_type(enum dump_type type)
880 {
881 if (!(dump_capabilities & type))
882 return -EINVAL;
883 switch (type) {
884 case DUMP_TYPE_CCW:
885 if (diag308_set_works)
886 dump_method = DUMP_METHOD_CCW_DIAG;
887 else if (MACHINE_IS_VM)
888 dump_method = DUMP_METHOD_CCW_VM;
889 else
890 dump_method = DUMP_METHOD_CCW_CIO;
891 break;
892 case DUMP_TYPE_FCP:
893 dump_method = DUMP_METHOD_FCP_DIAG;
894 break;
895 default:
896 dump_method = DUMP_METHOD_NONE;
897 }
898 dump_type = type;
899 return 0;
900 }
901
902 static ssize_t dump_type_show(struct kobject *kobj,
903 struct kobj_attribute *attr, char *page)
904 {
905 return sprintf(page, "%s\n", dump_type_str(dump_type));
906 }
907
908 static ssize_t dump_type_store(struct kobject *kobj,
909 struct kobj_attribute *attr,
910 const char *buf, size_t len)
911 {
912 int rc = -EINVAL;
913
914 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
915 rc = dump_set_type(DUMP_TYPE_NONE);
916 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
917 rc = dump_set_type(DUMP_TYPE_CCW);
918 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
919 rc = dump_set_type(DUMP_TYPE_FCP);
920 return (rc != 0) ? rc : len;
921 }
922
923 static struct kobj_attribute dump_type_attr =
924 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
925
926 static struct kset *dump_kset;
927
928 static void dump_run(struct shutdown_trigger *trigger)
929 {
930 struct ccw_dev_id devid;
931 static char buf[100];
932
933 switch (dump_method) {
934 case DUMP_METHOD_CCW_CIO:
935 smp_send_stop();
936 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
937 devid.ssid = 0;
938 reipl_ccw_dev(&devid);
939 break;
940 case DUMP_METHOD_CCW_VM:
941 smp_send_stop();
942 sprintf(buf, "STORE STATUS");
943 __cpcmd(buf, NULL, 0, NULL);
944 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
945 __cpcmd(buf, NULL, 0, NULL);
946 break;
947 case DUMP_METHOD_CCW_DIAG:
948 diag308(DIAG308_SET, dump_block_ccw);
949 diag308(DIAG308_DUMP, NULL);
950 break;
951 case DUMP_METHOD_FCP_DIAG:
952 diag308(DIAG308_SET, dump_block_fcp);
953 diag308(DIAG308_DUMP, NULL);
954 break;
955 case DUMP_METHOD_NONE:
956 default:
957 return;
958 }
959 printk(KERN_EMERG "Dump failed!\n");
960 }
961
962 static int __init dump_ccw_init(void)
963 {
964 int rc;
965
966 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
967 if (!dump_block_ccw)
968 return -ENOMEM;
969 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
970 if (rc) {
971 free_page((unsigned long)dump_block_ccw);
972 return rc;
973 }
974 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
975 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
976 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
977 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
978 dump_capabilities |= DUMP_TYPE_CCW;
979 return 0;
980 }
981
982 static int __init dump_fcp_init(void)
983 {
984 int rc;
985
986 if (!sclp_ipl_info.has_dump)
987 return 0; /* LDIPL DUMP is not installed */
988 if (!diag308_set_works)
989 return 0;
990 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
991 if (!dump_block_fcp)
992 return -ENOMEM;
993 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
994 if (rc) {
995 free_page((unsigned long)dump_block_fcp);
996 return rc;
997 }
998 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
999 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1000 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1001 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1002 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1003 dump_capabilities |= DUMP_TYPE_FCP;
1004 return 0;
1005 }
1006
1007 static int __init dump_init(void)
1008 {
1009 int rc;
1010
1011 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1012 if (!dump_kset)
1013 return -ENOMEM;
1014 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1015 if (rc) {
1016 kset_unregister(dump_kset);
1017 return rc;
1018 }
1019 rc = dump_ccw_init();
1020 if (rc)
1021 return rc;
1022 rc = dump_fcp_init();
1023 if (rc)
1024 return rc;
1025 dump_set_type(DUMP_TYPE_NONE);
1026 return 0;
1027 }
1028
1029 static struct shutdown_action __refdata dump_action = {
1030 .name = SHUTDOWN_ACTION_DUMP_STR,
1031 .fn = dump_run,
1032 .init = dump_init,
1033 };
1034
1035 /*
1036 * vmcmd shutdown action: Trigger vm command on shutdown.
1037 */
1038
1039 static char vmcmd_on_reboot[128];
1040 static char vmcmd_on_panic[128];
1041 static char vmcmd_on_halt[128];
1042 static char vmcmd_on_poff[128];
1043
1044 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1045 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1046 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1047 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1048
1049 static struct attribute *vmcmd_attrs[] = {
1050 &sys_vmcmd_on_reboot_attr.attr,
1051 &sys_vmcmd_on_panic_attr.attr,
1052 &sys_vmcmd_on_halt_attr.attr,
1053 &sys_vmcmd_on_poff_attr.attr,
1054 NULL,
1055 };
1056
1057 static struct attribute_group vmcmd_attr_group = {
1058 .attrs = vmcmd_attrs,
1059 };
1060
1061 static struct kset *vmcmd_kset;
1062
1063 static void vmcmd_run(struct shutdown_trigger *trigger)
1064 {
1065 char *cmd, *next_cmd;
1066
1067 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1068 cmd = vmcmd_on_reboot;
1069 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1070 cmd = vmcmd_on_panic;
1071 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1072 cmd = vmcmd_on_halt;
1073 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1074 cmd = vmcmd_on_poff;
1075 else
1076 return;
1077
1078 if (strlen(cmd) == 0)
1079 return;
1080 do {
1081 next_cmd = strchr(cmd, '\n');
1082 if (next_cmd) {
1083 next_cmd[0] = 0;
1084 next_cmd += 1;
1085 }
1086 __cpcmd(cmd, NULL, 0, NULL);
1087 cmd = next_cmd;
1088 } while (cmd != NULL);
1089 }
1090
1091 static int vmcmd_init(void)
1092 {
1093 if (!MACHINE_IS_VM)
1094 return -ENOTSUPP;
1095 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1096 if (!vmcmd_kset)
1097 return -ENOMEM;
1098 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1099 }
1100
1101 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1102 vmcmd_run, vmcmd_init};
1103
1104 /*
1105 * stop shutdown action: Stop Linux on shutdown.
1106 */
1107
1108 static void stop_run(struct shutdown_trigger *trigger)
1109 {
1110 if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1111 disabled_wait((unsigned long) __builtin_return_address(0));
1112 else {
1113 signal_processor(smp_processor_id(), sigp_stop);
1114 for (;;);
1115 }
1116 }
1117
1118 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1119 stop_run, NULL};
1120
1121 /* action list */
1122
1123 static struct shutdown_action *shutdown_actions_list[] = {
1124 &ipl_action, &reipl_action, &dump_action, &vmcmd_action, &stop_action};
1125 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1126
1127 /*
1128 * Trigger section
1129 */
1130
1131 static struct kset *shutdown_actions_kset;
1132
1133 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1134 size_t len)
1135 {
1136 int i;
1137 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1138 if (!shutdown_actions_list[i])
1139 continue;
1140 if (strncmp(buf, shutdown_actions_list[i]->name,
1141 strlen(shutdown_actions_list[i]->name)) == 0) {
1142 trigger->action = shutdown_actions_list[i];
1143 return len;
1144 }
1145 }
1146 return -EINVAL;
1147 }
1148
1149 /* on reipl */
1150
1151 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1152 &reipl_action};
1153
1154 static ssize_t on_reboot_show(struct kobject *kobj,
1155 struct kobj_attribute *attr, char *page)
1156 {
1157 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1158 }
1159
1160 static ssize_t on_reboot_store(struct kobject *kobj,
1161 struct kobj_attribute *attr,
1162 const char *buf, size_t len)
1163 {
1164 return set_trigger(buf, &on_reboot_trigger, len);
1165 }
1166
1167 static struct kobj_attribute on_reboot_attr =
1168 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1169
1170 static void do_machine_restart(char *__unused)
1171 {
1172 smp_send_stop();
1173 on_reboot_trigger.action->fn(&on_reboot_trigger);
1174 reipl_run(NULL);
1175 }
1176 void (*_machine_restart)(char *command) = do_machine_restart;
1177
1178 /* on panic */
1179
1180 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1181
1182 static ssize_t on_panic_show(struct kobject *kobj,
1183 struct kobj_attribute *attr, char *page)
1184 {
1185 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1186 }
1187
1188 static ssize_t on_panic_store(struct kobject *kobj,
1189 struct kobj_attribute *attr,
1190 const char *buf, size_t len)
1191 {
1192 return set_trigger(buf, &on_panic_trigger, len);
1193 }
1194
1195 static struct kobj_attribute on_panic_attr =
1196 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1197
1198 static void do_panic(void)
1199 {
1200 on_panic_trigger.action->fn(&on_panic_trigger);
1201 stop_run(&on_panic_trigger);
1202 }
1203
1204 /* on halt */
1205
1206 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1207
1208 static ssize_t on_halt_show(struct kobject *kobj,
1209 struct kobj_attribute *attr, char *page)
1210 {
1211 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1212 }
1213
1214 static ssize_t on_halt_store(struct kobject *kobj,
1215 struct kobj_attribute *attr,
1216 const char *buf, size_t len)
1217 {
1218 return set_trigger(buf, &on_halt_trigger, len);
1219 }
1220
1221 static struct kobj_attribute on_halt_attr =
1222 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1223
1224
1225 static void do_machine_halt(void)
1226 {
1227 smp_send_stop();
1228 on_halt_trigger.action->fn(&on_halt_trigger);
1229 stop_run(&on_halt_trigger);
1230 }
1231 void (*_machine_halt)(void) = do_machine_halt;
1232
1233 /* on power off */
1234
1235 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1236
1237 static ssize_t on_poff_show(struct kobject *kobj,
1238 struct kobj_attribute *attr, char *page)
1239 {
1240 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1241 }
1242
1243 static ssize_t on_poff_store(struct kobject *kobj,
1244 struct kobj_attribute *attr,
1245 const char *buf, size_t len)
1246 {
1247 return set_trigger(buf, &on_poff_trigger, len);
1248 }
1249
1250 static struct kobj_attribute on_poff_attr =
1251 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1252
1253
1254 static void do_machine_power_off(void)
1255 {
1256 smp_send_stop();
1257 on_poff_trigger.action->fn(&on_poff_trigger);
1258 stop_run(&on_poff_trigger);
1259 }
1260 void (*_machine_power_off)(void) = do_machine_power_off;
1261
1262 static void __init shutdown_triggers_init(void)
1263 {
1264 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1265 firmware_kobj);
1266 if (!shutdown_actions_kset)
1267 goto fail;
1268 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1269 &on_reboot_attr.attr))
1270 goto fail;
1271 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1272 &on_panic_attr.attr))
1273 goto fail;
1274 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1275 &on_halt_attr.attr))
1276 goto fail;
1277 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1278 &on_poff_attr.attr))
1279 goto fail;
1280
1281 return;
1282 fail:
1283 panic("shutdown_triggers_init failed\n");
1284 }
1285
1286 static void __init shutdown_actions_init(void)
1287 {
1288 int i;
1289
1290 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1291 if (!shutdown_actions_list[i]->init)
1292 continue;
1293 if (shutdown_actions_list[i]->init())
1294 shutdown_actions_list[i] = NULL;
1295 }
1296 }
1297
1298 static int __init s390_ipl_init(void)
1299 {
1300 reipl_probe();
1301 sclp_get_ipl_info(&sclp_ipl_info);
1302 shutdown_actions_init();
1303 shutdown_triggers_init();
1304 return 0;
1305 }
1306
1307 __initcall(s390_ipl_init);
1308
1309 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1310 {
1311 int sx, dx;
1312
1313 dx = 0;
1314 for (sx = 0; src[sx] != 0; sx++) {
1315 if (src[sx] == '"')
1316 continue;
1317 dst[dx++] = src[sx];
1318 if (dx >= n)
1319 break;
1320 }
1321 }
1322
1323 static int __init vmcmd_on_reboot_setup(char *str)
1324 {
1325 if (!MACHINE_IS_VM)
1326 return 1;
1327 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1328 vmcmd_on_reboot[127] = 0;
1329 on_reboot_trigger.action = &vmcmd_action;
1330 return 1;
1331 }
1332 __setup("vmreboot=", vmcmd_on_reboot_setup);
1333
1334 static int __init vmcmd_on_panic_setup(char *str)
1335 {
1336 if (!MACHINE_IS_VM)
1337 return 1;
1338 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1339 vmcmd_on_panic[127] = 0;
1340 on_panic_trigger.action = &vmcmd_action;
1341 return 1;
1342 }
1343 __setup("vmpanic=", vmcmd_on_panic_setup);
1344
1345 static int __init vmcmd_on_halt_setup(char *str)
1346 {
1347 if (!MACHINE_IS_VM)
1348 return 1;
1349 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1350 vmcmd_on_halt[127] = 0;
1351 on_halt_trigger.action = &vmcmd_action;
1352 return 1;
1353 }
1354 __setup("vmhalt=", vmcmd_on_halt_setup);
1355
1356 static int __init vmcmd_on_poff_setup(char *str)
1357 {
1358 if (!MACHINE_IS_VM)
1359 return 1;
1360 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1361 vmcmd_on_poff[127] = 0;
1362 on_poff_trigger.action = &vmcmd_action;
1363 return 1;
1364 }
1365 __setup("vmpoff=", vmcmd_on_poff_setup);
1366
1367 static int on_panic_notify(struct notifier_block *self,
1368 unsigned long event, void *data)
1369 {
1370 do_panic();
1371 return NOTIFY_OK;
1372 }
1373
1374 static struct notifier_block on_panic_nb = {
1375 .notifier_call = on_panic_notify,
1376 .priority = 0,
1377 };
1378
1379 void __init setup_ipl(void)
1380 {
1381 ipl_info.type = get_ipl_type();
1382 switch (ipl_info.type) {
1383 case IPL_TYPE_CCW:
1384 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1385 ipl_info.data.ccw.dev_id.ssid = 0;
1386 break;
1387 case IPL_TYPE_FCP:
1388 case IPL_TYPE_FCP_DUMP:
1389 ipl_info.data.fcp.dev_id.devno =
1390 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1391 ipl_info.data.fcp.dev_id.ssid = 0;
1392 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1393 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1394 break;
1395 case IPL_TYPE_NSS:
1396 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1397 sizeof(ipl_info.data.nss.name));
1398 break;
1399 case IPL_TYPE_UNKNOWN:
1400 default:
1401 /* We have no info to copy */
1402 break;
1403 }
1404 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1405 }
1406
1407 void __init ipl_save_parameters(void)
1408 {
1409 struct cio_iplinfo iplinfo;
1410 unsigned int *ipl_ptr;
1411 void *src, *dst;
1412
1413 if (cio_get_iplinfo(&iplinfo))
1414 return;
1415
1416 ipl_devno = iplinfo.devno;
1417 ipl_flags |= IPL_DEVNO_VALID;
1418 if (!iplinfo.is_qdio)
1419 return;
1420 ipl_flags |= IPL_PARMBLOCK_VALID;
1421 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1422 src = (void *)(unsigned long)*ipl_ptr;
1423 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1424 memmove(dst, src, PAGE_SIZE);
1425 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1426 }
1427
1428 static LIST_HEAD(rcall);
1429 static DEFINE_MUTEX(rcall_mutex);
1430
1431 void register_reset_call(struct reset_call *reset)
1432 {
1433 mutex_lock(&rcall_mutex);
1434 list_add(&reset->list, &rcall);
1435 mutex_unlock(&rcall_mutex);
1436 }
1437 EXPORT_SYMBOL_GPL(register_reset_call);
1438
1439 void unregister_reset_call(struct reset_call *reset)
1440 {
1441 mutex_lock(&rcall_mutex);
1442 list_del(&reset->list);
1443 mutex_unlock(&rcall_mutex);
1444 }
1445 EXPORT_SYMBOL_GPL(unregister_reset_call);
1446
1447 static void do_reset_calls(void)
1448 {
1449 struct reset_call *reset;
1450
1451 list_for_each_entry(reset, &rcall, list)
1452 reset->fn();
1453 }
1454
1455 u32 dump_prefix_page;
1456
1457 void s390_reset_system(void)
1458 {
1459 struct _lowcore *lc;
1460
1461 lc = (struct _lowcore *)(unsigned long) store_prefix();
1462
1463 /* Stack for interrupt/machine check handler */
1464 lc->panic_stack = S390_lowcore.panic_stack;
1465
1466 /* Save prefix page address for dump case */
1467 dump_prefix_page = (u32)(unsigned long) lc;
1468
1469 /* Disable prefixing */
1470 set_prefix(0);
1471
1472 /* Disable lowcore protection */
1473 __ctl_clear_bit(0,28);
1474
1475 /* Set new machine check handler */
1476 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1477 S390_lowcore.mcck_new_psw.addr =
1478 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
1479
1480 /* Set new program check handler */
1481 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1482 S390_lowcore.program_new_psw.addr =
1483 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
1484
1485 do_reset_calls();
1486 }
1487
This page took 0.111035 seconds and 5 git commands to generate.