spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / arch / s390 / kernel / ipl.c
blobaffa8e68124a18f6daad5ee18b03d4f8f0ce098e
1 /*
2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
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 */
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 <linux/fs.h>
18 #include <linux/gfp.h>
19 #include <linux/crash_dump.h>
20 #include <asm/ipl.h>
21 #include <asm/smp.h>
22 #include <asm/setup.h>
23 #include <asm/cpcmd.h>
24 #include <asm/cio.h>
25 #include <asm/ebcdic.h>
26 #include <asm/reset.h>
27 #include <asm/sclp.h>
28 #include <asm/sigp.h>
29 #include <asm/checksum.h>
30 #include "entry.h"
32 #define IPL_PARM_BLOCK_VERSION 0
34 #define IPL_UNKNOWN_STR "unknown"
35 #define IPL_CCW_STR "ccw"
36 #define IPL_FCP_STR "fcp"
37 #define IPL_FCP_DUMP_STR "fcp_dump"
38 #define IPL_NSS_STR "nss"
40 #define DUMP_CCW_STR "ccw"
41 #define DUMP_FCP_STR "fcp"
42 #define DUMP_NONE_STR "none"
45 * Four shutdown trigger types are supported:
46 * - panic
47 * - halt
48 * - power off
49 * - reipl
50 * - restart
52 #define ON_PANIC_STR "on_panic"
53 #define ON_HALT_STR "on_halt"
54 #define ON_POFF_STR "on_poff"
55 #define ON_REIPL_STR "on_reboot"
56 #define ON_RESTART_STR "on_restart"
58 struct shutdown_action;
59 struct shutdown_trigger {
60 char *name;
61 struct shutdown_action *action;
65 * The following shutdown action types are supported:
67 #define SHUTDOWN_ACTION_IPL_STR "ipl"
68 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
69 #define SHUTDOWN_ACTION_DUMP_STR "dump"
70 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
71 #define SHUTDOWN_ACTION_STOP_STR "stop"
72 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
74 struct shutdown_action {
75 char *name;
76 void (*fn) (struct shutdown_trigger *trigger);
77 int (*init) (void);
78 int init_rc;
81 static char *ipl_type_str(enum ipl_type type)
83 switch (type) {
84 case IPL_TYPE_CCW:
85 return IPL_CCW_STR;
86 case IPL_TYPE_FCP:
87 return IPL_FCP_STR;
88 case IPL_TYPE_FCP_DUMP:
89 return IPL_FCP_DUMP_STR;
90 case IPL_TYPE_NSS:
91 return IPL_NSS_STR;
92 case IPL_TYPE_UNKNOWN:
93 default:
94 return IPL_UNKNOWN_STR;
98 enum dump_type {
99 DUMP_TYPE_NONE = 1,
100 DUMP_TYPE_CCW = 2,
101 DUMP_TYPE_FCP = 4,
104 static char *dump_type_str(enum dump_type type)
106 switch (type) {
107 case DUMP_TYPE_NONE:
108 return DUMP_NONE_STR;
109 case DUMP_TYPE_CCW:
110 return DUMP_CCW_STR;
111 case DUMP_TYPE_FCP:
112 return DUMP_FCP_STR;
113 default:
114 return NULL;
119 * Must be in data section since the bss section
120 * is not cleared when these are accessed.
122 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
123 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
125 enum ipl_method {
126 REIPL_METHOD_CCW_CIO,
127 REIPL_METHOD_CCW_DIAG,
128 REIPL_METHOD_CCW_VM,
129 REIPL_METHOD_FCP_RO_DIAG,
130 REIPL_METHOD_FCP_RW_DIAG,
131 REIPL_METHOD_FCP_RO_VM,
132 REIPL_METHOD_FCP_DUMP,
133 REIPL_METHOD_NSS,
134 REIPL_METHOD_NSS_DIAG,
135 REIPL_METHOD_DEFAULT,
138 enum dump_method {
139 DUMP_METHOD_NONE,
140 DUMP_METHOD_CCW_CIO,
141 DUMP_METHOD_CCW_DIAG,
142 DUMP_METHOD_CCW_VM,
143 DUMP_METHOD_FCP_DIAG,
146 static int diag308_set_works = 0;
148 static struct ipl_parameter_block ipl_block;
150 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
152 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
153 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
154 static struct ipl_parameter_block *reipl_block_fcp;
155 static struct ipl_parameter_block *reipl_block_ccw;
156 static struct ipl_parameter_block *reipl_block_nss;
157 static struct ipl_parameter_block *reipl_block_actual;
159 static int dump_capabilities = DUMP_TYPE_NONE;
160 static enum dump_type dump_type = DUMP_TYPE_NONE;
161 static enum dump_method dump_method = DUMP_METHOD_NONE;
162 static struct ipl_parameter_block *dump_block_fcp;
163 static struct ipl_parameter_block *dump_block_ccw;
165 static struct sclp_ipl_info sclp_ipl_info;
167 int diag308(unsigned long subcode, void *addr)
169 register unsigned long _addr asm("0") = (unsigned long) addr;
170 register unsigned long _rc asm("1") = 0;
172 asm volatile(
173 " diag %0,%2,0x308\n"
174 "0:\n"
175 EX_TABLE(0b,0b)
176 : "+d" (_addr), "+d" (_rc)
177 : "d" (subcode) : "cc", "memory");
178 return _rc;
180 EXPORT_SYMBOL_GPL(diag308);
182 /* SYSFS */
184 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
185 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
186 struct kobj_attribute *attr, \
187 char *page) \
189 return sprintf(page, _format, _value); \
191 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
192 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
194 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
195 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
196 struct kobj_attribute *attr, \
197 char *page) \
199 return sprintf(page, _fmt_out, \
200 (unsigned long long) _value); \
202 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
203 struct kobj_attribute *attr, \
204 const char *buf, size_t len) \
206 unsigned long long value; \
207 if (sscanf(buf, _fmt_in, &value) != 1) \
208 return -EINVAL; \
209 _value = value; \
210 return len; \
212 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
213 __ATTR(_name,(S_IRUGO | S_IWUSR), \
214 sys_##_prefix##_##_name##_show, \
215 sys_##_prefix##_##_name##_store);
217 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
218 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
219 struct kobj_attribute *attr, \
220 char *page) \
222 return sprintf(page, _fmt_out, _value); \
224 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
225 struct kobj_attribute *attr, \
226 const char *buf, size_t len) \
228 strncpy(_value, buf, sizeof(_value) - 1); \
229 strim(_value); \
230 return len; \
232 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
233 __ATTR(_name,(S_IRUGO | S_IWUSR), \
234 sys_##_prefix##_##_name##_show, \
235 sys_##_prefix##_##_name##_store);
237 static void make_attrs_ro(struct attribute **attrs)
239 while (*attrs) {
240 (*attrs)->mode = S_IRUGO;
241 attrs++;
246 * ipl section
249 static __init enum ipl_type get_ipl_type(void)
251 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
253 if (ipl_flags & IPL_NSS_VALID)
254 return IPL_TYPE_NSS;
255 if (!(ipl_flags & IPL_DEVNO_VALID))
256 return IPL_TYPE_UNKNOWN;
257 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
258 return IPL_TYPE_CCW;
259 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
260 return IPL_TYPE_UNKNOWN;
261 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
262 return IPL_TYPE_UNKNOWN;
263 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
264 return IPL_TYPE_FCP_DUMP;
265 return IPL_TYPE_FCP;
268 struct ipl_info ipl_info;
269 EXPORT_SYMBOL_GPL(ipl_info);
271 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
272 char *page)
274 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
277 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
279 /* VM IPL PARM routines */
280 static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
281 const struct ipl_parameter_block *ipb)
283 int i;
284 size_t len;
285 char has_lowercase = 0;
287 len = 0;
288 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
289 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
291 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
292 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
293 /* If at least one character is lowercase, we assume mixed
294 * case; otherwise we convert everything to lowercase.
296 for (i = 0; i < len; i++)
297 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
298 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
299 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
300 has_lowercase = 1;
301 break;
303 if (!has_lowercase)
304 EBC_TOLOWER(dest, len);
305 EBCASC(dest, len);
307 dest[len] = 0;
309 return len;
312 size_t append_ipl_vmparm(char *dest, size_t size)
314 size_t rc;
316 rc = 0;
317 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
318 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
319 else
320 dest[0] = 0;
321 return rc;
324 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
325 struct kobj_attribute *attr, char *page)
327 char parm[DIAG308_VMPARM_SIZE + 1] = {};
329 append_ipl_vmparm(parm, sizeof(parm));
330 return sprintf(page, "%s\n", parm);
333 static size_t scpdata_length(const char* buf, size_t count)
335 while (count) {
336 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
337 break;
338 count--;
340 return count;
343 static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
344 const struct ipl_parameter_block *ipb)
346 size_t count;
347 size_t i;
348 int has_lowercase;
350 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
351 ipb->ipl_info.fcp.scp_data_len));
352 if (!count)
353 goto out;
355 has_lowercase = 0;
356 for (i = 0; i < count; i++) {
357 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
358 count = 0;
359 goto out;
361 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
362 has_lowercase = 1;
365 if (has_lowercase)
366 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
367 else
368 for (i = 0; i < count; i++)
369 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
370 out:
371 dest[count] = '\0';
372 return count;
375 size_t append_ipl_scpdata(char *dest, size_t len)
377 size_t rc;
379 rc = 0;
380 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
381 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
382 else
383 dest[0] = 0;
384 return rc;
388 static struct kobj_attribute sys_ipl_vm_parm_attr =
389 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
391 static ssize_t sys_ipl_device_show(struct kobject *kobj,
392 struct kobj_attribute *attr, char *page)
394 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
396 switch (ipl_info.type) {
397 case IPL_TYPE_CCW:
398 return sprintf(page, "0.0.%04x\n", ipl_devno);
399 case IPL_TYPE_FCP:
400 case IPL_TYPE_FCP_DUMP:
401 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
402 default:
403 return 0;
407 static struct kobj_attribute sys_ipl_device_attr =
408 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
410 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
411 struct bin_attribute *attr, char *buf,
412 loff_t off, size_t count)
414 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
415 IPL_PARMBLOCK_SIZE);
418 static struct bin_attribute ipl_parameter_attr = {
419 .attr = {
420 .name = "binary_parameter",
421 .mode = S_IRUGO,
423 .size = PAGE_SIZE,
424 .read = &ipl_parameter_read,
427 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
428 struct bin_attribute *attr, char *buf,
429 loff_t off, size_t count)
431 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
432 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
434 return memory_read_from_buffer(buf, count, &off, scp_data, size);
437 static struct bin_attribute ipl_scp_data_attr = {
438 .attr = {
439 .name = "scp_data",
440 .mode = S_IRUGO,
442 .size = PAGE_SIZE,
443 .read = ipl_scp_data_read,
446 /* FCP ipl device attributes */
448 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
449 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
450 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
451 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
452 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
453 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
454 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
455 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
457 static struct attribute *ipl_fcp_attrs[] = {
458 &sys_ipl_type_attr.attr,
459 &sys_ipl_device_attr.attr,
460 &sys_ipl_fcp_wwpn_attr.attr,
461 &sys_ipl_fcp_lun_attr.attr,
462 &sys_ipl_fcp_bootprog_attr.attr,
463 &sys_ipl_fcp_br_lba_attr.attr,
464 NULL,
467 static struct attribute_group ipl_fcp_attr_group = {
468 .attrs = ipl_fcp_attrs,
471 /* CCW ipl device attributes */
473 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
474 struct kobj_attribute *attr, char *page)
476 char loadparm[LOADPARM_LEN + 1] = {};
478 if (!sclp_ipl_info.is_valid)
479 return sprintf(page, "#unknown#\n");
480 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
481 EBCASC(loadparm, LOADPARM_LEN);
482 strim(loadparm);
483 return sprintf(page, "%s\n", loadparm);
486 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
487 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
489 static struct attribute *ipl_ccw_attrs_vm[] = {
490 &sys_ipl_type_attr.attr,
491 &sys_ipl_device_attr.attr,
492 &sys_ipl_ccw_loadparm_attr.attr,
493 &sys_ipl_vm_parm_attr.attr,
494 NULL,
497 static struct attribute *ipl_ccw_attrs_lpar[] = {
498 &sys_ipl_type_attr.attr,
499 &sys_ipl_device_attr.attr,
500 &sys_ipl_ccw_loadparm_attr.attr,
501 NULL,
504 static struct attribute_group ipl_ccw_attr_group_vm = {
505 .attrs = ipl_ccw_attrs_vm,
508 static struct attribute_group ipl_ccw_attr_group_lpar = {
509 .attrs = ipl_ccw_attrs_lpar
512 /* NSS ipl device attributes */
514 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
516 static struct attribute *ipl_nss_attrs[] = {
517 &sys_ipl_type_attr.attr,
518 &sys_ipl_nss_name_attr.attr,
519 &sys_ipl_ccw_loadparm_attr.attr,
520 &sys_ipl_vm_parm_attr.attr,
521 NULL,
524 static struct attribute_group ipl_nss_attr_group = {
525 .attrs = ipl_nss_attrs,
528 /* UNKNOWN ipl device attributes */
530 static struct attribute *ipl_unknown_attrs[] = {
531 &sys_ipl_type_attr.attr,
532 NULL,
535 static struct attribute_group ipl_unknown_attr_group = {
536 .attrs = ipl_unknown_attrs,
539 static struct kset *ipl_kset;
541 static int __init ipl_register_fcp_files(void)
543 int rc;
545 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
546 if (rc)
547 goto out;
548 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
549 if (rc)
550 goto out_ipl_parm;
551 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
552 if (!rc)
553 goto out;
555 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
557 out_ipl_parm:
558 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
559 out:
560 return rc;
563 static void __ipl_run(void *unused)
565 diag308(DIAG308_IPL, NULL);
566 if (MACHINE_IS_VM)
567 __cpcmd("IPL", NULL, 0, NULL);
568 else if (ipl_info.type == IPL_TYPE_CCW)
569 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
572 static void ipl_run(struct shutdown_trigger *trigger)
574 smp_switch_to_ipl_cpu(__ipl_run, NULL);
577 static int __init ipl_init(void)
579 int rc;
581 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
582 if (!ipl_kset) {
583 rc = -ENOMEM;
584 goto out;
586 switch (ipl_info.type) {
587 case IPL_TYPE_CCW:
588 if (MACHINE_IS_VM)
589 rc = sysfs_create_group(&ipl_kset->kobj,
590 &ipl_ccw_attr_group_vm);
591 else
592 rc = sysfs_create_group(&ipl_kset->kobj,
593 &ipl_ccw_attr_group_lpar);
594 break;
595 case IPL_TYPE_FCP:
596 case IPL_TYPE_FCP_DUMP:
597 rc = ipl_register_fcp_files();
598 break;
599 case IPL_TYPE_NSS:
600 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
601 break;
602 default:
603 rc = sysfs_create_group(&ipl_kset->kobj,
604 &ipl_unknown_attr_group);
605 break;
607 out:
608 if (rc)
609 panic("ipl_init failed: rc = %i\n", rc);
611 return 0;
614 static struct shutdown_action __refdata ipl_action = {
615 .name = SHUTDOWN_ACTION_IPL_STR,
616 .fn = ipl_run,
617 .init = ipl_init,
621 * reipl shutdown action: Reboot Linux on shutdown.
624 /* VM IPL PARM attributes */
625 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
626 char *page)
628 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
630 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
631 return sprintf(page, "%s\n", vmparm);
634 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
635 size_t vmparm_max,
636 const char *buf, size_t len)
638 int i, ip_len;
640 /* ignore trailing newline */
641 ip_len = len;
642 if ((len > 0) && (buf[len - 1] == '\n'))
643 ip_len--;
645 if (ip_len > vmparm_max)
646 return -EINVAL;
648 /* parm is used to store kernel options, check for common chars */
649 for (i = 0; i < ip_len; i++)
650 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
651 return -EINVAL;
653 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
654 ipb->ipl_info.ccw.vm_parm_len = ip_len;
655 if (ip_len > 0) {
656 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
657 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
658 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
659 } else {
660 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
663 return len;
666 /* NSS wrapper */
667 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
668 struct kobj_attribute *attr, char *page)
670 return reipl_generic_vmparm_show(reipl_block_nss, page);
673 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
674 struct kobj_attribute *attr,
675 const char *buf, size_t len)
677 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
680 /* CCW wrapper */
681 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
682 struct kobj_attribute *attr, char *page)
684 return reipl_generic_vmparm_show(reipl_block_ccw, page);
687 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
688 struct kobj_attribute *attr,
689 const char *buf, size_t len)
691 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
694 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
695 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
696 reipl_nss_vmparm_store);
697 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
698 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
699 reipl_ccw_vmparm_store);
701 /* FCP reipl device attributes */
703 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
704 struct bin_attribute *attr,
705 char *buf, loff_t off, size_t count)
707 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
708 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
710 return memory_read_from_buffer(buf, count, &off, scp_data, size);
713 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
714 struct bin_attribute *attr,
715 char *buf, loff_t off, size_t count)
717 size_t padding;
718 size_t scpdata_len;
720 if (off < 0)
721 return -EINVAL;
723 if (off >= DIAG308_SCPDATA_SIZE)
724 return -ENOSPC;
726 if (count > DIAG308_SCPDATA_SIZE - off)
727 count = DIAG308_SCPDATA_SIZE - off;
729 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count);
730 scpdata_len = off + count;
732 if (scpdata_len % 8) {
733 padding = 8 - (scpdata_len % 8);
734 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
735 0, padding);
736 scpdata_len += padding;
739 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
740 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
741 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
743 return count;
746 static struct bin_attribute sys_reipl_fcp_scp_data_attr = {
747 .attr = {
748 .name = "scp_data",
749 .mode = S_IRUGO | S_IWUSR,
751 .size = PAGE_SIZE,
752 .read = reipl_fcp_scpdata_read,
753 .write = reipl_fcp_scpdata_write,
756 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
757 reipl_block_fcp->ipl_info.fcp.wwpn);
758 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
759 reipl_block_fcp->ipl_info.fcp.lun);
760 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
761 reipl_block_fcp->ipl_info.fcp.bootprog);
762 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
763 reipl_block_fcp->ipl_info.fcp.br_lba);
764 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
765 reipl_block_fcp->ipl_info.fcp.devno);
767 static struct attribute *reipl_fcp_attrs[] = {
768 &sys_reipl_fcp_device_attr.attr,
769 &sys_reipl_fcp_wwpn_attr.attr,
770 &sys_reipl_fcp_lun_attr.attr,
771 &sys_reipl_fcp_bootprog_attr.attr,
772 &sys_reipl_fcp_br_lba_attr.attr,
773 NULL,
776 static struct attribute_group reipl_fcp_attr_group = {
777 .attrs = reipl_fcp_attrs,
780 /* CCW reipl device attributes */
782 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
783 reipl_block_ccw->ipl_info.ccw.devno);
785 static void reipl_get_ascii_loadparm(char *loadparm,
786 struct ipl_parameter_block *ibp)
788 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
789 EBCASC(loadparm, LOADPARM_LEN);
790 loadparm[LOADPARM_LEN] = 0;
791 strim(loadparm);
794 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
795 char *page)
797 char buf[LOADPARM_LEN + 1];
799 reipl_get_ascii_loadparm(buf, ipb);
800 return sprintf(page, "%s\n", buf);
803 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
804 const char *buf, size_t len)
806 int i, lp_len;
808 /* ignore trailing newline */
809 lp_len = len;
810 if ((len > 0) && (buf[len - 1] == '\n'))
811 lp_len--;
812 /* loadparm can have max 8 characters and must not start with a blank */
813 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
814 return -EINVAL;
815 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
816 for (i = 0; i < lp_len; i++) {
817 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
818 (buf[i] == '.'))
819 continue;
820 return -EINVAL;
822 /* initialize loadparm with blanks */
823 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
824 /* copy and convert to ebcdic */
825 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
826 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
827 return len;
830 /* NSS wrapper */
831 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
832 struct kobj_attribute *attr, char *page)
834 return reipl_generic_loadparm_show(reipl_block_nss, page);
837 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
838 struct kobj_attribute *attr,
839 const char *buf, size_t len)
841 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
844 /* CCW wrapper */
845 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
846 struct kobj_attribute *attr, char *page)
848 return reipl_generic_loadparm_show(reipl_block_ccw, page);
851 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
852 struct kobj_attribute *attr,
853 const char *buf, size_t len)
855 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
858 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
859 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
860 reipl_ccw_loadparm_store);
862 static struct attribute *reipl_ccw_attrs_vm[] = {
863 &sys_reipl_ccw_device_attr.attr,
864 &sys_reipl_ccw_loadparm_attr.attr,
865 &sys_reipl_ccw_vmparm_attr.attr,
866 NULL,
869 static struct attribute *reipl_ccw_attrs_lpar[] = {
870 &sys_reipl_ccw_device_attr.attr,
871 &sys_reipl_ccw_loadparm_attr.attr,
872 NULL,
875 static struct attribute_group reipl_ccw_attr_group_vm = {
876 .name = IPL_CCW_STR,
877 .attrs = reipl_ccw_attrs_vm,
880 static struct attribute_group reipl_ccw_attr_group_lpar = {
881 .name = IPL_CCW_STR,
882 .attrs = reipl_ccw_attrs_lpar,
886 /* NSS reipl device attributes */
887 static void reipl_get_ascii_nss_name(char *dst,
888 struct ipl_parameter_block *ipb)
890 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
891 EBCASC(dst, NSS_NAME_SIZE);
892 dst[NSS_NAME_SIZE] = 0;
895 static ssize_t reipl_nss_name_show(struct kobject *kobj,
896 struct kobj_attribute *attr, char *page)
898 char nss_name[NSS_NAME_SIZE + 1] = {};
900 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
901 return sprintf(page, "%s\n", nss_name);
904 static ssize_t reipl_nss_name_store(struct kobject *kobj,
905 struct kobj_attribute *attr,
906 const char *buf, size_t len)
908 int nss_len;
910 /* ignore trailing newline */
911 nss_len = len;
912 if ((len > 0) && (buf[len - 1] == '\n'))
913 nss_len--;
915 if (nss_len > NSS_NAME_SIZE)
916 return -EINVAL;
918 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
919 if (nss_len > 0) {
920 reipl_block_nss->ipl_info.ccw.vm_flags |=
921 DIAG308_VM_FLAGS_NSS_VALID;
922 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
923 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
924 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
925 } else {
926 reipl_block_nss->ipl_info.ccw.vm_flags &=
927 ~DIAG308_VM_FLAGS_NSS_VALID;
930 return len;
933 static struct kobj_attribute sys_reipl_nss_name_attr =
934 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
935 reipl_nss_name_store);
937 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
938 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
939 reipl_nss_loadparm_store);
941 static struct attribute *reipl_nss_attrs[] = {
942 &sys_reipl_nss_name_attr.attr,
943 &sys_reipl_nss_loadparm_attr.attr,
944 &sys_reipl_nss_vmparm_attr.attr,
945 NULL,
948 static struct attribute_group reipl_nss_attr_group = {
949 .name = IPL_NSS_STR,
950 .attrs = reipl_nss_attrs,
953 /* reipl type */
955 static int reipl_set_type(enum ipl_type type)
957 if (!(reipl_capabilities & type))
958 return -EINVAL;
960 switch(type) {
961 case IPL_TYPE_CCW:
962 if (diag308_set_works)
963 reipl_method = REIPL_METHOD_CCW_DIAG;
964 else if (MACHINE_IS_VM)
965 reipl_method = REIPL_METHOD_CCW_VM;
966 else
967 reipl_method = REIPL_METHOD_CCW_CIO;
968 reipl_block_actual = reipl_block_ccw;
969 break;
970 case IPL_TYPE_FCP:
971 if (diag308_set_works)
972 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
973 else if (MACHINE_IS_VM)
974 reipl_method = REIPL_METHOD_FCP_RO_VM;
975 else
976 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
977 reipl_block_actual = reipl_block_fcp;
978 break;
979 case IPL_TYPE_FCP_DUMP:
980 reipl_method = REIPL_METHOD_FCP_DUMP;
981 break;
982 case IPL_TYPE_NSS:
983 if (diag308_set_works)
984 reipl_method = REIPL_METHOD_NSS_DIAG;
985 else
986 reipl_method = REIPL_METHOD_NSS;
987 reipl_block_actual = reipl_block_nss;
988 break;
989 case IPL_TYPE_UNKNOWN:
990 reipl_method = REIPL_METHOD_DEFAULT;
991 break;
992 default:
993 BUG();
995 reipl_type = type;
996 return 0;
999 static ssize_t reipl_type_show(struct kobject *kobj,
1000 struct kobj_attribute *attr, char *page)
1002 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1005 static ssize_t reipl_type_store(struct kobject *kobj,
1006 struct kobj_attribute *attr,
1007 const char *buf, size_t len)
1009 int rc = -EINVAL;
1011 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1012 rc = reipl_set_type(IPL_TYPE_CCW);
1013 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1014 rc = reipl_set_type(IPL_TYPE_FCP);
1015 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1016 rc = reipl_set_type(IPL_TYPE_NSS);
1017 return (rc != 0) ? rc : len;
1020 static struct kobj_attribute reipl_type_attr =
1021 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1023 static struct kset *reipl_kset;
1024 static struct kset *reipl_fcp_kset;
1026 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1027 const enum ipl_method m)
1029 char loadparm[LOADPARM_LEN + 1] = {};
1030 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1031 char nss_name[NSS_NAME_SIZE + 1] = {};
1032 size_t pos = 0;
1034 reipl_get_ascii_loadparm(loadparm, ipb);
1035 reipl_get_ascii_nss_name(nss_name, ipb);
1036 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
1038 switch (m) {
1039 case REIPL_METHOD_CCW_VM:
1040 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1041 break;
1042 case REIPL_METHOD_NSS:
1043 pos = sprintf(dst, "IPL %s", nss_name);
1044 break;
1045 default:
1046 break;
1048 if (strlen(loadparm) > 0)
1049 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1050 if (strlen(vmparm) > 0)
1051 sprintf(dst + pos, " PARM %s", vmparm);
1054 static void __reipl_run(void *unused)
1056 struct ccw_dev_id devid;
1057 static char buf[128];
1059 switch (reipl_method) {
1060 case REIPL_METHOD_CCW_CIO:
1061 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1062 devid.ssid = 0;
1063 reipl_ccw_dev(&devid);
1064 break;
1065 case REIPL_METHOD_CCW_VM:
1066 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
1067 __cpcmd(buf, NULL, 0, NULL);
1068 break;
1069 case REIPL_METHOD_CCW_DIAG:
1070 diag308(DIAG308_SET, reipl_block_ccw);
1071 diag308(DIAG308_IPL, NULL);
1072 break;
1073 case REIPL_METHOD_FCP_RW_DIAG:
1074 diag308(DIAG308_SET, reipl_block_fcp);
1075 diag308(DIAG308_IPL, NULL);
1076 break;
1077 case REIPL_METHOD_FCP_RO_DIAG:
1078 diag308(DIAG308_IPL, NULL);
1079 break;
1080 case REIPL_METHOD_FCP_RO_VM:
1081 __cpcmd("IPL", NULL, 0, NULL);
1082 break;
1083 case REIPL_METHOD_NSS_DIAG:
1084 diag308(DIAG308_SET, reipl_block_nss);
1085 diag308(DIAG308_IPL, NULL);
1086 break;
1087 case REIPL_METHOD_NSS:
1088 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
1089 __cpcmd(buf, NULL, 0, NULL);
1090 break;
1091 case REIPL_METHOD_DEFAULT:
1092 if (MACHINE_IS_VM)
1093 __cpcmd("IPL", NULL, 0, NULL);
1094 diag308(DIAG308_IPL, NULL);
1095 break;
1096 case REIPL_METHOD_FCP_DUMP:
1097 break;
1099 disabled_wait((unsigned long) __builtin_return_address(0));
1102 static void reipl_run(struct shutdown_trigger *trigger)
1104 smp_switch_to_ipl_cpu(__reipl_run, NULL);
1107 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1109 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1110 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1111 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1112 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1115 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1117 /* LOADPARM */
1118 /* check if read scp info worked and set loadparm */
1119 if (sclp_ipl_info.is_valid)
1120 memcpy(ipb->ipl_info.ccw.load_parm,
1121 &sclp_ipl_info.loadparm, LOADPARM_LEN);
1122 else
1123 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1124 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
1125 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1127 /* VM PARM */
1128 if (MACHINE_IS_VM && diag308_set_works &&
1129 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1131 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1132 ipb->ipl_info.ccw.vm_parm_len =
1133 ipl_block.ipl_info.ccw.vm_parm_len;
1134 memcpy(ipb->ipl_info.ccw.vm_parm,
1135 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1139 static int __init reipl_nss_init(void)
1141 int rc;
1143 if (!MACHINE_IS_VM)
1144 return 0;
1146 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1147 if (!reipl_block_nss)
1148 return -ENOMEM;
1150 if (!diag308_set_works)
1151 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1153 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1154 if (rc)
1155 return rc;
1157 reipl_block_ccw_init(reipl_block_nss);
1158 if (ipl_info.type == IPL_TYPE_NSS) {
1159 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1160 ' ', NSS_NAME_SIZE);
1161 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1162 kernel_nss_name, strlen(kernel_nss_name));
1163 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1164 reipl_block_nss->ipl_info.ccw.vm_flags |=
1165 DIAG308_VM_FLAGS_NSS_VALID;
1167 reipl_block_ccw_fill_parms(reipl_block_nss);
1170 reipl_capabilities |= IPL_TYPE_NSS;
1171 return 0;
1174 static int __init reipl_ccw_init(void)
1176 int rc;
1178 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1179 if (!reipl_block_ccw)
1180 return -ENOMEM;
1182 if (MACHINE_IS_VM) {
1183 if (!diag308_set_works)
1184 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1185 rc = sysfs_create_group(&reipl_kset->kobj,
1186 &reipl_ccw_attr_group_vm);
1187 } else {
1188 if(!diag308_set_works)
1189 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1190 rc = sysfs_create_group(&reipl_kset->kobj,
1191 &reipl_ccw_attr_group_lpar);
1193 if (rc)
1194 return rc;
1196 reipl_block_ccw_init(reipl_block_ccw);
1197 if (ipl_info.type == IPL_TYPE_CCW) {
1198 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1199 reipl_block_ccw_fill_parms(reipl_block_ccw);
1202 reipl_capabilities |= IPL_TYPE_CCW;
1203 return 0;
1206 static int __init reipl_fcp_init(void)
1208 int rc;
1210 if (!diag308_set_works) {
1211 if (ipl_info.type == IPL_TYPE_FCP) {
1212 make_attrs_ro(reipl_fcp_attrs);
1213 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1214 } else
1215 return 0;
1218 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1219 if (!reipl_block_fcp)
1220 return -ENOMEM;
1222 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1223 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1224 &reipl_kset->kobj);
1225 if (!reipl_fcp_kset) {
1226 free_page((unsigned long) reipl_block_fcp);
1227 return -ENOMEM;
1230 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1231 if (rc) {
1232 kset_unregister(reipl_fcp_kset);
1233 free_page((unsigned long) reipl_block_fcp);
1234 return rc;
1237 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj,
1238 &sys_reipl_fcp_scp_data_attr);
1239 if (rc) {
1240 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1241 kset_unregister(reipl_fcp_kset);
1242 free_page((unsigned long) reipl_block_fcp);
1243 return rc;
1246 if (ipl_info.type == IPL_TYPE_FCP)
1247 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1248 else {
1249 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1250 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1251 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1252 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1253 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1255 reipl_capabilities |= IPL_TYPE_FCP;
1256 return 0;
1259 static int __init reipl_init(void)
1261 int rc;
1263 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1264 if (!reipl_kset)
1265 return -ENOMEM;
1266 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1267 if (rc) {
1268 kset_unregister(reipl_kset);
1269 return rc;
1271 rc = reipl_ccw_init();
1272 if (rc)
1273 return rc;
1274 rc = reipl_fcp_init();
1275 if (rc)
1276 return rc;
1277 rc = reipl_nss_init();
1278 if (rc)
1279 return rc;
1280 rc = reipl_set_type(ipl_info.type);
1281 if (rc)
1282 return rc;
1283 return 0;
1286 static struct shutdown_action __refdata reipl_action = {
1287 .name = SHUTDOWN_ACTION_REIPL_STR,
1288 .fn = reipl_run,
1289 .init = reipl_init,
1293 * dump shutdown action: Dump Linux on shutdown.
1296 /* FCP dump device attributes */
1298 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1299 dump_block_fcp->ipl_info.fcp.wwpn);
1300 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1301 dump_block_fcp->ipl_info.fcp.lun);
1302 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1303 dump_block_fcp->ipl_info.fcp.bootprog);
1304 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1305 dump_block_fcp->ipl_info.fcp.br_lba);
1306 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1307 dump_block_fcp->ipl_info.fcp.devno);
1309 static struct attribute *dump_fcp_attrs[] = {
1310 &sys_dump_fcp_device_attr.attr,
1311 &sys_dump_fcp_wwpn_attr.attr,
1312 &sys_dump_fcp_lun_attr.attr,
1313 &sys_dump_fcp_bootprog_attr.attr,
1314 &sys_dump_fcp_br_lba_attr.attr,
1315 NULL,
1318 static struct attribute_group dump_fcp_attr_group = {
1319 .name = IPL_FCP_STR,
1320 .attrs = dump_fcp_attrs,
1323 /* CCW dump device attributes */
1325 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1326 dump_block_ccw->ipl_info.ccw.devno);
1328 static struct attribute *dump_ccw_attrs[] = {
1329 &sys_dump_ccw_device_attr.attr,
1330 NULL,
1333 static struct attribute_group dump_ccw_attr_group = {
1334 .name = IPL_CCW_STR,
1335 .attrs = dump_ccw_attrs,
1338 /* dump type */
1340 static int dump_set_type(enum dump_type type)
1342 if (!(dump_capabilities & type))
1343 return -EINVAL;
1344 switch (type) {
1345 case DUMP_TYPE_CCW:
1346 if (diag308_set_works)
1347 dump_method = DUMP_METHOD_CCW_DIAG;
1348 else if (MACHINE_IS_VM)
1349 dump_method = DUMP_METHOD_CCW_VM;
1350 else
1351 dump_method = DUMP_METHOD_CCW_CIO;
1352 break;
1353 case DUMP_TYPE_FCP:
1354 dump_method = DUMP_METHOD_FCP_DIAG;
1355 break;
1356 default:
1357 dump_method = DUMP_METHOD_NONE;
1359 dump_type = type;
1360 return 0;
1363 static ssize_t dump_type_show(struct kobject *kobj,
1364 struct kobj_attribute *attr, char *page)
1366 return sprintf(page, "%s\n", dump_type_str(dump_type));
1369 static ssize_t dump_type_store(struct kobject *kobj,
1370 struct kobj_attribute *attr,
1371 const char *buf, size_t len)
1373 int rc = -EINVAL;
1375 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1376 rc = dump_set_type(DUMP_TYPE_NONE);
1377 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1378 rc = dump_set_type(DUMP_TYPE_CCW);
1379 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1380 rc = dump_set_type(DUMP_TYPE_FCP);
1381 return (rc != 0) ? rc : len;
1384 static struct kobj_attribute dump_type_attr =
1385 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1387 static struct kset *dump_kset;
1389 static void __dump_run(void *unused)
1391 struct ccw_dev_id devid;
1392 static char buf[100];
1394 switch (dump_method) {
1395 case DUMP_METHOD_CCW_CIO:
1396 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1397 devid.ssid = 0;
1398 reipl_ccw_dev(&devid);
1399 break;
1400 case DUMP_METHOD_CCW_VM:
1401 sprintf(buf, "STORE STATUS");
1402 __cpcmd(buf, NULL, 0, NULL);
1403 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1404 __cpcmd(buf, NULL, 0, NULL);
1405 break;
1406 case DUMP_METHOD_CCW_DIAG:
1407 diag308(DIAG308_SET, dump_block_ccw);
1408 diag308(DIAG308_DUMP, NULL);
1409 break;
1410 case DUMP_METHOD_FCP_DIAG:
1411 diag308(DIAG308_SET, dump_block_fcp);
1412 diag308(DIAG308_DUMP, NULL);
1413 break;
1414 default:
1415 break;
1419 static void dump_run(struct shutdown_trigger *trigger)
1421 if (dump_method == DUMP_METHOD_NONE)
1422 return;
1423 smp_send_stop();
1424 smp_switch_to_ipl_cpu(__dump_run, NULL);
1427 static int __init dump_ccw_init(void)
1429 int rc;
1431 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1432 if (!dump_block_ccw)
1433 return -ENOMEM;
1434 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1435 if (rc) {
1436 free_page((unsigned long)dump_block_ccw);
1437 return rc;
1439 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1440 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1441 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1442 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1443 dump_capabilities |= DUMP_TYPE_CCW;
1444 return 0;
1447 static int __init dump_fcp_init(void)
1449 int rc;
1451 if (!sclp_ipl_info.has_dump)
1452 return 0; /* LDIPL DUMP is not installed */
1453 if (!diag308_set_works)
1454 return 0;
1455 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1456 if (!dump_block_fcp)
1457 return -ENOMEM;
1458 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1459 if (rc) {
1460 free_page((unsigned long)dump_block_fcp);
1461 return rc;
1463 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1464 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1465 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1466 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1467 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1468 dump_capabilities |= DUMP_TYPE_FCP;
1469 return 0;
1472 static int __init dump_init(void)
1474 int rc;
1476 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1477 if (!dump_kset)
1478 return -ENOMEM;
1479 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1480 if (rc) {
1481 kset_unregister(dump_kset);
1482 return rc;
1484 rc = dump_ccw_init();
1485 if (rc)
1486 return rc;
1487 rc = dump_fcp_init();
1488 if (rc)
1489 return rc;
1490 dump_set_type(DUMP_TYPE_NONE);
1491 return 0;
1494 static struct shutdown_action __refdata dump_action = {
1495 .name = SHUTDOWN_ACTION_DUMP_STR,
1496 .fn = dump_run,
1497 .init = dump_init,
1500 static void dump_reipl_run(struct shutdown_trigger *trigger)
1502 preempt_disable();
1504 * Bypass dynamic address translation (DAT) when storing IPL parameter
1505 * information block address and checksum into the prefix area
1506 * (corresponding to absolute addresses 0-8191).
1507 * When enhanced DAT applies and the STE format control in one,
1508 * the absolute address is formed without prefixing. In this case a
1509 * normal store (stg/st) into the prefix area would no more match to
1510 * absolute addresses 0-8191.
1512 #ifdef CONFIG_64BIT
1513 asm volatile("sturg %0,%1"
1514 :: "a" ((unsigned long) reipl_block_actual),
1515 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1516 #else
1517 asm volatile("stura %0,%1"
1518 :: "a" ((unsigned long) reipl_block_actual),
1519 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1520 #endif
1521 asm volatile("stura %0,%1"
1522 :: "a" (csum_partial(reipl_block_actual,
1523 reipl_block_actual->hdr.len, 0)),
1524 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1525 preempt_enable();
1526 dump_run(trigger);
1529 static int __init dump_reipl_init(void)
1531 if (!diag308_set_works)
1532 return -EOPNOTSUPP;
1533 else
1534 return 0;
1537 static struct shutdown_action __refdata dump_reipl_action = {
1538 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1539 .fn = dump_reipl_run,
1540 .init = dump_reipl_init,
1544 * vmcmd shutdown action: Trigger vm command on shutdown.
1547 static char vmcmd_on_reboot[128];
1548 static char vmcmd_on_panic[128];
1549 static char vmcmd_on_halt[128];
1550 static char vmcmd_on_poff[128];
1551 static char vmcmd_on_restart[128];
1553 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1554 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1555 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1556 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1557 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1559 static struct attribute *vmcmd_attrs[] = {
1560 &sys_vmcmd_on_reboot_attr.attr,
1561 &sys_vmcmd_on_panic_attr.attr,
1562 &sys_vmcmd_on_halt_attr.attr,
1563 &sys_vmcmd_on_poff_attr.attr,
1564 &sys_vmcmd_on_restart_attr.attr,
1565 NULL,
1568 static struct attribute_group vmcmd_attr_group = {
1569 .attrs = vmcmd_attrs,
1572 static struct kset *vmcmd_kset;
1574 static void vmcmd_run(struct shutdown_trigger *trigger)
1576 char *cmd, *next_cmd;
1578 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1579 cmd = vmcmd_on_reboot;
1580 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1581 cmd = vmcmd_on_panic;
1582 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1583 cmd = vmcmd_on_halt;
1584 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1585 cmd = vmcmd_on_poff;
1586 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1587 cmd = vmcmd_on_restart;
1588 else
1589 return;
1591 if (strlen(cmd) == 0)
1592 return;
1593 do {
1594 next_cmd = strchr(cmd, '\n');
1595 if (next_cmd) {
1596 next_cmd[0] = 0;
1597 next_cmd += 1;
1599 __cpcmd(cmd, NULL, 0, NULL);
1600 cmd = next_cmd;
1601 } while (cmd != NULL);
1604 static int vmcmd_init(void)
1606 if (!MACHINE_IS_VM)
1607 return -EOPNOTSUPP;
1608 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1609 if (!vmcmd_kset)
1610 return -ENOMEM;
1611 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1614 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1615 vmcmd_run, vmcmd_init};
1618 * stop shutdown action: Stop Linux on shutdown.
1621 static void stop_run(struct shutdown_trigger *trigger)
1623 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1624 strcmp(trigger->name, ON_RESTART_STR) == 0)
1625 disabled_wait((unsigned long) __builtin_return_address(0));
1626 while (sigp(smp_processor_id(), sigp_stop) == sigp_busy)
1627 cpu_relax();
1628 for (;;);
1631 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1632 stop_run, NULL};
1634 /* action list */
1636 static struct shutdown_action *shutdown_actions_list[] = {
1637 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1638 &vmcmd_action, &stop_action};
1639 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1642 * Trigger section
1645 static struct kset *shutdown_actions_kset;
1647 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1648 size_t len)
1650 int i;
1652 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1653 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1654 if (shutdown_actions_list[i]->init_rc) {
1655 return shutdown_actions_list[i]->init_rc;
1656 } else {
1657 trigger->action = shutdown_actions_list[i];
1658 return len;
1662 return -EINVAL;
1665 /* on reipl */
1667 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1668 &reipl_action};
1670 static ssize_t on_reboot_show(struct kobject *kobj,
1671 struct kobj_attribute *attr, char *page)
1673 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1676 static ssize_t on_reboot_store(struct kobject *kobj,
1677 struct kobj_attribute *attr,
1678 const char *buf, size_t len)
1680 return set_trigger(buf, &on_reboot_trigger, len);
1683 static struct kobj_attribute on_reboot_attr =
1684 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1686 static void do_machine_restart(char *__unused)
1688 smp_send_stop();
1689 on_reboot_trigger.action->fn(&on_reboot_trigger);
1690 reipl_run(NULL);
1692 void (*_machine_restart)(char *command) = do_machine_restart;
1694 /* on panic */
1696 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1698 static ssize_t on_panic_show(struct kobject *kobj,
1699 struct kobj_attribute *attr, char *page)
1701 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1704 static ssize_t on_panic_store(struct kobject *kobj,
1705 struct kobj_attribute *attr,
1706 const char *buf, size_t len)
1708 return set_trigger(buf, &on_panic_trigger, len);
1711 static struct kobj_attribute on_panic_attr =
1712 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1714 static void do_panic(void)
1716 on_panic_trigger.action->fn(&on_panic_trigger);
1717 stop_run(&on_panic_trigger);
1720 /* on restart */
1722 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
1723 &stop_action};
1725 static ssize_t on_restart_show(struct kobject *kobj,
1726 struct kobj_attribute *attr, char *page)
1728 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1731 static ssize_t on_restart_store(struct kobject *kobj,
1732 struct kobj_attribute *attr,
1733 const char *buf, size_t len)
1735 return set_trigger(buf, &on_restart_trigger, len);
1738 static struct kobj_attribute on_restart_attr =
1739 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1741 void do_restart(void)
1743 smp_restart_with_online_cpu();
1744 smp_send_stop();
1745 #ifdef CONFIG_CRASH_DUMP
1746 crash_kexec(NULL);
1747 #endif
1748 on_restart_trigger.action->fn(&on_restart_trigger);
1749 stop_run(&on_restart_trigger);
1752 /* on halt */
1754 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1756 static ssize_t on_halt_show(struct kobject *kobj,
1757 struct kobj_attribute *attr, char *page)
1759 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1762 static ssize_t on_halt_store(struct kobject *kobj,
1763 struct kobj_attribute *attr,
1764 const char *buf, size_t len)
1766 return set_trigger(buf, &on_halt_trigger, len);
1769 static struct kobj_attribute on_halt_attr =
1770 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1773 static void do_machine_halt(void)
1775 smp_send_stop();
1776 on_halt_trigger.action->fn(&on_halt_trigger);
1777 stop_run(&on_halt_trigger);
1779 void (*_machine_halt)(void) = do_machine_halt;
1781 /* on power off */
1783 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1785 static ssize_t on_poff_show(struct kobject *kobj,
1786 struct kobj_attribute *attr, char *page)
1788 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1791 static ssize_t on_poff_store(struct kobject *kobj,
1792 struct kobj_attribute *attr,
1793 const char *buf, size_t len)
1795 return set_trigger(buf, &on_poff_trigger, len);
1798 static struct kobj_attribute on_poff_attr =
1799 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1802 static void do_machine_power_off(void)
1804 smp_send_stop();
1805 on_poff_trigger.action->fn(&on_poff_trigger);
1806 stop_run(&on_poff_trigger);
1808 void (*_machine_power_off)(void) = do_machine_power_off;
1810 static void __init shutdown_triggers_init(void)
1812 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1813 firmware_kobj);
1814 if (!shutdown_actions_kset)
1815 goto fail;
1816 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1817 &on_reboot_attr.attr))
1818 goto fail;
1819 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1820 &on_panic_attr.attr))
1821 goto fail;
1822 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1823 &on_halt_attr.attr))
1824 goto fail;
1825 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1826 &on_poff_attr.attr))
1827 goto fail;
1828 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1829 &on_restart_attr.attr))
1830 goto fail;
1831 return;
1832 fail:
1833 panic("shutdown_triggers_init failed\n");
1836 static void __init shutdown_actions_init(void)
1838 int i;
1840 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1841 if (!shutdown_actions_list[i]->init)
1842 continue;
1843 shutdown_actions_list[i]->init_rc =
1844 shutdown_actions_list[i]->init();
1848 static int __init s390_ipl_init(void)
1850 sclp_get_ipl_info(&sclp_ipl_info);
1851 shutdown_actions_init();
1852 shutdown_triggers_init();
1853 return 0;
1856 __initcall(s390_ipl_init);
1858 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1860 int sx, dx;
1862 dx = 0;
1863 for (sx = 0; src[sx] != 0; sx++) {
1864 if (src[sx] == '"')
1865 continue;
1866 dst[dx++] = src[sx];
1867 if (dx >= n)
1868 break;
1872 static int __init vmcmd_on_reboot_setup(char *str)
1874 if (!MACHINE_IS_VM)
1875 return 1;
1876 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1877 vmcmd_on_reboot[127] = 0;
1878 on_reboot_trigger.action = &vmcmd_action;
1879 return 1;
1881 __setup("vmreboot=", vmcmd_on_reboot_setup);
1883 static int __init vmcmd_on_panic_setup(char *str)
1885 if (!MACHINE_IS_VM)
1886 return 1;
1887 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1888 vmcmd_on_panic[127] = 0;
1889 on_panic_trigger.action = &vmcmd_action;
1890 return 1;
1892 __setup("vmpanic=", vmcmd_on_panic_setup);
1894 static int __init vmcmd_on_halt_setup(char *str)
1896 if (!MACHINE_IS_VM)
1897 return 1;
1898 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1899 vmcmd_on_halt[127] = 0;
1900 on_halt_trigger.action = &vmcmd_action;
1901 return 1;
1903 __setup("vmhalt=", vmcmd_on_halt_setup);
1905 static int __init vmcmd_on_poff_setup(char *str)
1907 if (!MACHINE_IS_VM)
1908 return 1;
1909 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1910 vmcmd_on_poff[127] = 0;
1911 on_poff_trigger.action = &vmcmd_action;
1912 return 1;
1914 __setup("vmpoff=", vmcmd_on_poff_setup);
1916 static int on_panic_notify(struct notifier_block *self,
1917 unsigned long event, void *data)
1919 do_panic();
1920 return NOTIFY_OK;
1923 static struct notifier_block on_panic_nb = {
1924 .notifier_call = on_panic_notify,
1925 .priority = INT_MIN,
1928 void __init setup_ipl(void)
1930 ipl_info.type = get_ipl_type();
1931 switch (ipl_info.type) {
1932 case IPL_TYPE_CCW:
1933 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1934 ipl_info.data.ccw.dev_id.ssid = 0;
1935 break;
1936 case IPL_TYPE_FCP:
1937 case IPL_TYPE_FCP_DUMP:
1938 ipl_info.data.fcp.dev_id.devno =
1939 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1940 ipl_info.data.fcp.dev_id.ssid = 0;
1941 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1942 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1943 break;
1944 case IPL_TYPE_NSS:
1945 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1946 sizeof(ipl_info.data.nss.name));
1947 break;
1948 case IPL_TYPE_UNKNOWN:
1949 /* We have no info to copy */
1950 break;
1952 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1955 void __init ipl_update_parameters(void)
1957 int rc;
1959 rc = diag308(DIAG308_STORE, &ipl_block);
1960 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1961 diag308_set_works = 1;
1964 void __init ipl_save_parameters(void)
1966 struct cio_iplinfo iplinfo;
1967 void *src, *dst;
1969 if (cio_get_iplinfo(&iplinfo))
1970 return;
1972 ipl_devno = iplinfo.devno;
1973 ipl_flags |= IPL_DEVNO_VALID;
1974 if (!iplinfo.is_qdio)
1975 return;
1976 ipl_flags |= IPL_PARMBLOCK_VALID;
1977 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
1978 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1979 memmove(dst, src, PAGE_SIZE);
1980 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
1983 static LIST_HEAD(rcall);
1984 static DEFINE_MUTEX(rcall_mutex);
1986 void register_reset_call(struct reset_call *reset)
1988 mutex_lock(&rcall_mutex);
1989 list_add(&reset->list, &rcall);
1990 mutex_unlock(&rcall_mutex);
1992 EXPORT_SYMBOL_GPL(register_reset_call);
1994 void unregister_reset_call(struct reset_call *reset)
1996 mutex_lock(&rcall_mutex);
1997 list_del(&reset->list);
1998 mutex_unlock(&rcall_mutex);
2000 EXPORT_SYMBOL_GPL(unregister_reset_call);
2002 static void do_reset_calls(void)
2004 struct reset_call *reset;
2006 #ifdef CONFIG_64BIT
2007 if (diag308_set_works) {
2008 diag308_reset();
2009 return;
2011 #endif
2012 list_for_each_entry(reset, &rcall, list)
2013 reset->fn();
2016 u32 dump_prefix_page;
2018 void s390_reset_system(void (*func)(void *), void *data)
2020 struct _lowcore *lc;
2022 lc = (struct _lowcore *)(unsigned long) store_prefix();
2024 /* Stack for interrupt/machine check handler */
2025 lc->panic_stack = S390_lowcore.panic_stack;
2027 /* Save prefix page address for dump case */
2028 dump_prefix_page = (u32)(unsigned long) lc;
2030 /* Disable prefixing */
2031 set_prefix(0);
2033 /* Disable lowcore protection */
2034 __ctl_clear_bit(0,28);
2036 /* Set new machine check handler */
2037 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
2038 S390_lowcore.mcck_new_psw.addr =
2039 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
2041 /* Set new program check handler */
2042 S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
2043 S390_lowcore.program_new_psw.addr =
2044 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
2046 /* Store status at absolute zero */
2047 store_status();
2049 do_reset_calls();
2050 if (func)
2051 func(data);