x86, efi: Set runtime_version to the EFI spec revision
[linux/fpc-iii.git] / arch / s390 / kernel / ipl.c
blob6ffcd3203215a2bcacb50bc35ae12229113b0ff4
1 /*
2 * ipl/reipl/dump support for Linux on s390.
4 * Copyright IBM Corp. 2005, 2012
5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
6 * Heiko Carstens <heiko.carstens@de.ibm.com>
7 * Volker Sameske <sameske@de.ibm.com>
8 */
10 #include <linux/types.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/delay.h>
14 #include <linux/reboot.h>
15 #include <linux/ctype.h>
16 #include <linux/fs.h>
17 #include <linux/gfp.h>
18 #include <linux/crash_dump.h>
19 #include <linux/debug_locks.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/checksum.h>
29 #include <asm/debug.h>
30 #include <asm/os_info.h>
31 #include "entry.h"
33 #define IPL_PARM_BLOCK_VERSION 0
35 #define IPL_UNKNOWN_STR "unknown"
36 #define IPL_CCW_STR "ccw"
37 #define IPL_FCP_STR "fcp"
38 #define IPL_FCP_DUMP_STR "fcp_dump"
39 #define IPL_NSS_STR "nss"
41 #define DUMP_CCW_STR "ccw"
42 #define DUMP_FCP_STR "fcp"
43 #define DUMP_NONE_STR "none"
46 * Four shutdown trigger types are supported:
47 * - panic
48 * - halt
49 * - power off
50 * - reipl
51 * - restart
53 #define ON_PANIC_STR "on_panic"
54 #define ON_HALT_STR "on_halt"
55 #define ON_POFF_STR "on_poff"
56 #define ON_REIPL_STR "on_reboot"
57 #define ON_RESTART_STR "on_restart"
59 struct shutdown_action;
60 struct shutdown_trigger {
61 char *name;
62 struct shutdown_action *action;
66 * The following shutdown action types are supported:
68 #define SHUTDOWN_ACTION_IPL_STR "ipl"
69 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
70 #define SHUTDOWN_ACTION_DUMP_STR "dump"
71 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
72 #define SHUTDOWN_ACTION_STOP_STR "stop"
73 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
75 struct shutdown_action {
76 char *name;
77 void (*fn) (struct shutdown_trigger *trigger);
78 int (*init) (void);
79 int init_rc;
82 static char *ipl_type_str(enum ipl_type type)
84 switch (type) {
85 case IPL_TYPE_CCW:
86 return IPL_CCW_STR;
87 case IPL_TYPE_FCP:
88 return IPL_FCP_STR;
89 case IPL_TYPE_FCP_DUMP:
90 return IPL_FCP_DUMP_STR;
91 case IPL_TYPE_NSS:
92 return IPL_NSS_STR;
93 case IPL_TYPE_UNKNOWN:
94 default:
95 return IPL_UNKNOWN_STR;
99 enum dump_type {
100 DUMP_TYPE_NONE = 1,
101 DUMP_TYPE_CCW = 2,
102 DUMP_TYPE_FCP = 4,
105 static char *dump_type_str(enum dump_type type)
107 switch (type) {
108 case DUMP_TYPE_NONE:
109 return DUMP_NONE_STR;
110 case DUMP_TYPE_CCW:
111 return DUMP_CCW_STR;
112 case DUMP_TYPE_FCP:
113 return DUMP_FCP_STR;
114 default:
115 return NULL;
120 * Must be in data section since the bss section
121 * is not cleared when these are accessed.
123 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
124 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
126 enum ipl_method {
127 REIPL_METHOD_CCW_CIO,
128 REIPL_METHOD_CCW_DIAG,
129 REIPL_METHOD_CCW_VM,
130 REIPL_METHOD_FCP_RO_DIAG,
131 REIPL_METHOD_FCP_RW_DIAG,
132 REIPL_METHOD_FCP_RO_VM,
133 REIPL_METHOD_FCP_DUMP,
134 REIPL_METHOD_NSS,
135 REIPL_METHOD_NSS_DIAG,
136 REIPL_METHOD_DEFAULT,
139 enum dump_method {
140 DUMP_METHOD_NONE,
141 DUMP_METHOD_CCW_CIO,
142 DUMP_METHOD_CCW_DIAG,
143 DUMP_METHOD_CCW_VM,
144 DUMP_METHOD_FCP_DIAG,
147 static int diag308_set_works = 0;
149 static struct ipl_parameter_block ipl_block;
151 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
153 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
154 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
155 static struct ipl_parameter_block *reipl_block_fcp;
156 static struct ipl_parameter_block *reipl_block_ccw;
157 static struct ipl_parameter_block *reipl_block_nss;
158 static struct ipl_parameter_block *reipl_block_actual;
160 static int dump_capabilities = DUMP_TYPE_NONE;
161 static enum dump_type dump_type = DUMP_TYPE_NONE;
162 static enum dump_method dump_method = DUMP_METHOD_NONE;
163 static struct ipl_parameter_block *dump_block_fcp;
164 static struct ipl_parameter_block *dump_block_ccw;
166 static struct sclp_ipl_info sclp_ipl_info;
168 int diag308(unsigned long subcode, void *addr)
170 register unsigned long _addr asm("0") = (unsigned long) addr;
171 register unsigned long _rc asm("1") = 0;
173 asm volatile(
174 " diag %0,%2,0x308\n"
175 "0:\n"
176 EX_TABLE(0b,0b)
177 : "+d" (_addr), "+d" (_rc)
178 : "d" (subcode) : "cc", "memory");
179 return _rc;
181 EXPORT_SYMBOL_GPL(diag308);
183 /* SYSFS */
185 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
186 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
187 struct kobj_attribute *attr, \
188 char *page) \
190 return sprintf(page, _format, _value); \
192 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
193 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
195 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
196 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
197 struct kobj_attribute *attr, \
198 char *page) \
200 return sprintf(page, _fmt_out, \
201 (unsigned long long) _value); \
203 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
204 struct kobj_attribute *attr, \
205 const char *buf, size_t len) \
207 unsigned long long value; \
208 if (sscanf(buf, _fmt_in, &value) != 1) \
209 return -EINVAL; \
210 _value = value; \
211 return len; \
213 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
214 __ATTR(_name,(S_IRUGO | S_IWUSR), \
215 sys_##_prefix##_##_name##_show, \
216 sys_##_prefix##_##_name##_store);
218 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
219 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
221 char *page) \
223 return sprintf(page, _fmt_out, _value); \
225 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
226 struct kobj_attribute *attr, \
227 const char *buf, size_t len) \
229 strncpy(_value, buf, sizeof(_value) - 1); \
230 strim(_value); \
231 return len; \
233 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
234 __ATTR(_name,(S_IRUGO | S_IWUSR), \
235 sys_##_prefix##_##_name##_show, \
236 sys_##_prefix##_##_name##_store);
238 static void make_attrs_ro(struct attribute **attrs)
240 while (*attrs) {
241 (*attrs)->mode = S_IRUGO;
242 attrs++;
247 * ipl section
250 static __init enum ipl_type get_ipl_type(void)
252 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
254 if (ipl_flags & IPL_NSS_VALID)
255 return IPL_TYPE_NSS;
256 if (!(ipl_flags & IPL_DEVNO_VALID))
257 return IPL_TYPE_UNKNOWN;
258 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
259 return IPL_TYPE_CCW;
260 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
261 return IPL_TYPE_UNKNOWN;
262 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
263 return IPL_TYPE_UNKNOWN;
264 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
265 return IPL_TYPE_FCP_DUMP;
266 return IPL_TYPE_FCP;
269 struct ipl_info ipl_info;
270 EXPORT_SYMBOL_GPL(ipl_info);
272 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
273 char *page)
275 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
278 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
280 /* VM IPL PARM routines */
281 static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
282 const struct ipl_parameter_block *ipb)
284 int i;
285 size_t len;
286 char has_lowercase = 0;
288 len = 0;
289 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
290 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
292 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
293 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
294 /* If at least one character is lowercase, we assume mixed
295 * case; otherwise we convert everything to lowercase.
297 for (i = 0; i < len; i++)
298 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
299 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
300 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
301 has_lowercase = 1;
302 break;
304 if (!has_lowercase)
305 EBC_TOLOWER(dest, len);
306 EBCASC(dest, len);
308 dest[len] = 0;
310 return len;
313 size_t append_ipl_vmparm(char *dest, size_t size)
315 size_t rc;
317 rc = 0;
318 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
319 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
320 else
321 dest[0] = 0;
322 return rc;
325 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
326 struct kobj_attribute *attr, char *page)
328 char parm[DIAG308_VMPARM_SIZE + 1] = {};
330 append_ipl_vmparm(parm, sizeof(parm));
331 return sprintf(page, "%s\n", parm);
334 static size_t scpdata_length(const char* buf, size_t count)
336 while (count) {
337 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
338 break;
339 count--;
341 return count;
344 static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
345 const struct ipl_parameter_block *ipb)
347 size_t count;
348 size_t i;
349 int has_lowercase;
351 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
352 ipb->ipl_info.fcp.scp_data_len));
353 if (!count)
354 goto out;
356 has_lowercase = 0;
357 for (i = 0; i < count; i++) {
358 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
359 count = 0;
360 goto out;
362 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
363 has_lowercase = 1;
366 if (has_lowercase)
367 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
368 else
369 for (i = 0; i < count; i++)
370 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
371 out:
372 dest[count] = '\0';
373 return count;
376 size_t append_ipl_scpdata(char *dest, size_t len)
378 size_t rc;
380 rc = 0;
381 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
382 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
383 else
384 dest[0] = 0;
385 return rc;
389 static struct kobj_attribute sys_ipl_vm_parm_attr =
390 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
392 static ssize_t sys_ipl_device_show(struct kobject *kobj,
393 struct kobj_attribute *attr, char *page)
395 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
397 switch (ipl_info.type) {
398 case IPL_TYPE_CCW:
399 return sprintf(page, "0.0.%04x\n", ipl_devno);
400 case IPL_TYPE_FCP:
401 case IPL_TYPE_FCP_DUMP:
402 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
403 default:
404 return 0;
408 static struct kobj_attribute sys_ipl_device_attr =
409 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
411 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
412 struct bin_attribute *attr, char *buf,
413 loff_t off, size_t count)
415 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
416 IPL_PARMBLOCK_SIZE);
419 static struct bin_attribute ipl_parameter_attr = {
420 .attr = {
421 .name = "binary_parameter",
422 .mode = S_IRUGO,
424 .size = PAGE_SIZE,
425 .read = &ipl_parameter_read,
428 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
429 struct bin_attribute *attr, char *buf,
430 loff_t off, size_t count)
432 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
433 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
435 return memory_read_from_buffer(buf, count, &off, scp_data, size);
438 static struct bin_attribute ipl_scp_data_attr = {
439 .attr = {
440 .name = "scp_data",
441 .mode = S_IRUGO,
443 .size = PAGE_SIZE,
444 .read = ipl_scp_data_read,
447 /* FCP ipl device attributes */
449 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
450 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
451 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
452 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
453 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
454 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
455 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
456 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
458 static struct attribute *ipl_fcp_attrs[] = {
459 &sys_ipl_type_attr.attr,
460 &sys_ipl_device_attr.attr,
461 &sys_ipl_fcp_wwpn_attr.attr,
462 &sys_ipl_fcp_lun_attr.attr,
463 &sys_ipl_fcp_bootprog_attr.attr,
464 &sys_ipl_fcp_br_lba_attr.attr,
465 NULL,
468 static struct attribute_group ipl_fcp_attr_group = {
469 .attrs = ipl_fcp_attrs,
472 /* CCW ipl device attributes */
474 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
475 struct kobj_attribute *attr, char *page)
477 char loadparm[LOADPARM_LEN + 1] = {};
479 if (!sclp_ipl_info.is_valid)
480 return sprintf(page, "#unknown#\n");
481 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
482 EBCASC(loadparm, LOADPARM_LEN);
483 strim(loadparm);
484 return sprintf(page, "%s\n", loadparm);
487 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
488 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
490 static struct attribute *ipl_ccw_attrs_vm[] = {
491 &sys_ipl_type_attr.attr,
492 &sys_ipl_device_attr.attr,
493 &sys_ipl_ccw_loadparm_attr.attr,
494 &sys_ipl_vm_parm_attr.attr,
495 NULL,
498 static struct attribute *ipl_ccw_attrs_lpar[] = {
499 &sys_ipl_type_attr.attr,
500 &sys_ipl_device_attr.attr,
501 &sys_ipl_ccw_loadparm_attr.attr,
502 NULL,
505 static struct attribute_group ipl_ccw_attr_group_vm = {
506 .attrs = ipl_ccw_attrs_vm,
509 static struct attribute_group ipl_ccw_attr_group_lpar = {
510 .attrs = ipl_ccw_attrs_lpar
513 /* NSS ipl device attributes */
515 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
517 static struct attribute *ipl_nss_attrs[] = {
518 &sys_ipl_type_attr.attr,
519 &sys_ipl_nss_name_attr.attr,
520 &sys_ipl_ccw_loadparm_attr.attr,
521 &sys_ipl_vm_parm_attr.attr,
522 NULL,
525 static struct attribute_group ipl_nss_attr_group = {
526 .attrs = ipl_nss_attrs,
529 /* UNKNOWN ipl device attributes */
531 static struct attribute *ipl_unknown_attrs[] = {
532 &sys_ipl_type_attr.attr,
533 NULL,
536 static struct attribute_group ipl_unknown_attr_group = {
537 .attrs = ipl_unknown_attrs,
540 static struct kset *ipl_kset;
542 static int __init ipl_register_fcp_files(void)
544 int rc;
546 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
547 if (rc)
548 goto out;
549 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
550 if (rc)
551 goto out_ipl_parm;
552 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
553 if (!rc)
554 goto out;
556 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
558 out_ipl_parm:
559 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
560 out:
561 return rc;
564 static void __ipl_run(void *unused)
566 diag308(DIAG308_IPL, NULL);
567 if (MACHINE_IS_VM)
568 __cpcmd("IPL", NULL, 0, NULL);
569 else if (ipl_info.type == IPL_TYPE_CCW)
570 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
573 static void ipl_run(struct shutdown_trigger *trigger)
575 smp_call_ipl_cpu(__ipl_run, NULL);
578 static int __init ipl_init(void)
580 int rc;
582 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
583 if (!ipl_kset) {
584 rc = -ENOMEM;
585 goto out;
587 switch (ipl_info.type) {
588 case IPL_TYPE_CCW:
589 if (MACHINE_IS_VM)
590 rc = sysfs_create_group(&ipl_kset->kobj,
591 &ipl_ccw_attr_group_vm);
592 else
593 rc = sysfs_create_group(&ipl_kset->kobj,
594 &ipl_ccw_attr_group_lpar);
595 break;
596 case IPL_TYPE_FCP:
597 case IPL_TYPE_FCP_DUMP:
598 rc = ipl_register_fcp_files();
599 break;
600 case IPL_TYPE_NSS:
601 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
602 break;
603 default:
604 rc = sysfs_create_group(&ipl_kset->kobj,
605 &ipl_unknown_attr_group);
606 break;
608 out:
609 if (rc)
610 panic("ipl_init failed: rc = %i\n", rc);
612 return 0;
615 static struct shutdown_action __refdata ipl_action = {
616 .name = SHUTDOWN_ACTION_IPL_STR,
617 .fn = ipl_run,
618 .init = ipl_init,
622 * reipl shutdown action: Reboot Linux on shutdown.
625 /* VM IPL PARM attributes */
626 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
627 char *page)
629 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
631 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
632 return sprintf(page, "%s\n", vmparm);
635 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
636 size_t vmparm_max,
637 const char *buf, size_t len)
639 int i, ip_len;
641 /* ignore trailing newline */
642 ip_len = len;
643 if ((len > 0) && (buf[len - 1] == '\n'))
644 ip_len--;
646 if (ip_len > vmparm_max)
647 return -EINVAL;
649 /* parm is used to store kernel options, check for common chars */
650 for (i = 0; i < ip_len; i++)
651 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
652 return -EINVAL;
654 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
655 ipb->ipl_info.ccw.vm_parm_len = ip_len;
656 if (ip_len > 0) {
657 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
658 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
659 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
660 } else {
661 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
664 return len;
667 /* NSS wrapper */
668 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
669 struct kobj_attribute *attr, char *page)
671 return reipl_generic_vmparm_show(reipl_block_nss, page);
674 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
675 struct kobj_attribute *attr,
676 const char *buf, size_t len)
678 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
681 /* CCW wrapper */
682 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
683 struct kobj_attribute *attr, char *page)
685 return reipl_generic_vmparm_show(reipl_block_ccw, page);
688 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
689 struct kobj_attribute *attr,
690 const char *buf, size_t len)
692 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
695 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
696 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
697 reipl_nss_vmparm_store);
698 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
699 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
700 reipl_ccw_vmparm_store);
702 /* FCP reipl device attributes */
704 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
705 struct bin_attribute *attr,
706 char *buf, loff_t off, size_t count)
708 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
709 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
711 return memory_read_from_buffer(buf, count, &off, scp_data, size);
714 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
715 struct bin_attribute *attr,
716 char *buf, loff_t off, size_t count)
718 size_t padding;
719 size_t scpdata_len;
721 if (off < 0)
722 return -EINVAL;
724 if (off >= DIAG308_SCPDATA_SIZE)
725 return -ENOSPC;
727 if (count > DIAG308_SCPDATA_SIZE - off)
728 count = DIAG308_SCPDATA_SIZE - off;
730 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count);
731 scpdata_len = off + count;
733 if (scpdata_len % 8) {
734 padding = 8 - (scpdata_len % 8);
735 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
736 0, padding);
737 scpdata_len += padding;
740 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
741 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
742 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
744 return count;
747 static struct bin_attribute sys_reipl_fcp_scp_data_attr = {
748 .attr = {
749 .name = "scp_data",
750 .mode = S_IRUGO | S_IWUSR,
752 .size = PAGE_SIZE,
753 .read = reipl_fcp_scpdata_read,
754 .write = reipl_fcp_scpdata_write,
757 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
758 reipl_block_fcp->ipl_info.fcp.wwpn);
759 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
760 reipl_block_fcp->ipl_info.fcp.lun);
761 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
762 reipl_block_fcp->ipl_info.fcp.bootprog);
763 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
764 reipl_block_fcp->ipl_info.fcp.br_lba);
765 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
766 reipl_block_fcp->ipl_info.fcp.devno);
768 static struct attribute *reipl_fcp_attrs[] = {
769 &sys_reipl_fcp_device_attr.attr,
770 &sys_reipl_fcp_wwpn_attr.attr,
771 &sys_reipl_fcp_lun_attr.attr,
772 &sys_reipl_fcp_bootprog_attr.attr,
773 &sys_reipl_fcp_br_lba_attr.attr,
774 NULL,
777 static struct attribute_group reipl_fcp_attr_group = {
778 .attrs = reipl_fcp_attrs,
781 /* CCW reipl device attributes */
783 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
784 reipl_block_ccw->ipl_info.ccw.devno);
786 static void reipl_get_ascii_loadparm(char *loadparm,
787 struct ipl_parameter_block *ibp)
789 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
790 EBCASC(loadparm, LOADPARM_LEN);
791 loadparm[LOADPARM_LEN] = 0;
792 strim(loadparm);
795 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
796 char *page)
798 char buf[LOADPARM_LEN + 1];
800 reipl_get_ascii_loadparm(buf, ipb);
801 return sprintf(page, "%s\n", buf);
804 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
805 const char *buf, size_t len)
807 int i, lp_len;
809 /* ignore trailing newline */
810 lp_len = len;
811 if ((len > 0) && (buf[len - 1] == '\n'))
812 lp_len--;
813 /* loadparm can have max 8 characters and must not start with a blank */
814 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
815 return -EINVAL;
816 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
817 for (i = 0; i < lp_len; i++) {
818 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
819 (buf[i] == '.'))
820 continue;
821 return -EINVAL;
823 /* initialize loadparm with blanks */
824 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
825 /* copy and convert to ebcdic */
826 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
827 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
828 return len;
831 /* NSS wrapper */
832 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
833 struct kobj_attribute *attr, char *page)
835 return reipl_generic_loadparm_show(reipl_block_nss, page);
838 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
839 struct kobj_attribute *attr,
840 const char *buf, size_t len)
842 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
845 /* CCW wrapper */
846 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
847 struct kobj_attribute *attr, char *page)
849 return reipl_generic_loadparm_show(reipl_block_ccw, page);
852 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
853 struct kobj_attribute *attr,
854 const char *buf, size_t len)
856 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
859 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
860 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
861 reipl_ccw_loadparm_store);
863 static struct attribute *reipl_ccw_attrs_vm[] = {
864 &sys_reipl_ccw_device_attr.attr,
865 &sys_reipl_ccw_loadparm_attr.attr,
866 &sys_reipl_ccw_vmparm_attr.attr,
867 NULL,
870 static struct attribute *reipl_ccw_attrs_lpar[] = {
871 &sys_reipl_ccw_device_attr.attr,
872 &sys_reipl_ccw_loadparm_attr.attr,
873 NULL,
876 static struct attribute_group reipl_ccw_attr_group_vm = {
877 .name = IPL_CCW_STR,
878 .attrs = reipl_ccw_attrs_vm,
881 static struct attribute_group reipl_ccw_attr_group_lpar = {
882 .name = IPL_CCW_STR,
883 .attrs = reipl_ccw_attrs_lpar,
887 /* NSS reipl device attributes */
888 static void reipl_get_ascii_nss_name(char *dst,
889 struct ipl_parameter_block *ipb)
891 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
892 EBCASC(dst, NSS_NAME_SIZE);
893 dst[NSS_NAME_SIZE] = 0;
896 static ssize_t reipl_nss_name_show(struct kobject *kobj,
897 struct kobj_attribute *attr, char *page)
899 char nss_name[NSS_NAME_SIZE + 1] = {};
901 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
902 return sprintf(page, "%s\n", nss_name);
905 static ssize_t reipl_nss_name_store(struct kobject *kobj,
906 struct kobj_attribute *attr,
907 const char *buf, size_t len)
909 int nss_len;
911 /* ignore trailing newline */
912 nss_len = len;
913 if ((len > 0) && (buf[len - 1] == '\n'))
914 nss_len--;
916 if (nss_len > NSS_NAME_SIZE)
917 return -EINVAL;
919 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
920 if (nss_len > 0) {
921 reipl_block_nss->ipl_info.ccw.vm_flags |=
922 DIAG308_VM_FLAGS_NSS_VALID;
923 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
924 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
925 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
926 } else {
927 reipl_block_nss->ipl_info.ccw.vm_flags &=
928 ~DIAG308_VM_FLAGS_NSS_VALID;
931 return len;
934 static struct kobj_attribute sys_reipl_nss_name_attr =
935 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
936 reipl_nss_name_store);
938 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
939 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
940 reipl_nss_loadparm_store);
942 static struct attribute *reipl_nss_attrs[] = {
943 &sys_reipl_nss_name_attr.attr,
944 &sys_reipl_nss_loadparm_attr.attr,
945 &sys_reipl_nss_vmparm_attr.attr,
946 NULL,
949 static struct attribute_group reipl_nss_attr_group = {
950 .name = IPL_NSS_STR,
951 .attrs = reipl_nss_attrs,
954 static void set_reipl_block_actual(struct ipl_parameter_block *reipl_block)
956 reipl_block_actual = reipl_block;
957 os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
958 reipl_block->hdr.len);
961 /* reipl type */
963 static int reipl_set_type(enum ipl_type type)
965 if (!(reipl_capabilities & type))
966 return -EINVAL;
968 switch(type) {
969 case IPL_TYPE_CCW:
970 if (diag308_set_works)
971 reipl_method = REIPL_METHOD_CCW_DIAG;
972 else if (MACHINE_IS_VM)
973 reipl_method = REIPL_METHOD_CCW_VM;
974 else
975 reipl_method = REIPL_METHOD_CCW_CIO;
976 set_reipl_block_actual(reipl_block_ccw);
977 break;
978 case IPL_TYPE_FCP:
979 if (diag308_set_works)
980 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
981 else if (MACHINE_IS_VM)
982 reipl_method = REIPL_METHOD_FCP_RO_VM;
983 else
984 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
985 set_reipl_block_actual(reipl_block_fcp);
986 break;
987 case IPL_TYPE_FCP_DUMP:
988 reipl_method = REIPL_METHOD_FCP_DUMP;
989 break;
990 case IPL_TYPE_NSS:
991 if (diag308_set_works)
992 reipl_method = REIPL_METHOD_NSS_DIAG;
993 else
994 reipl_method = REIPL_METHOD_NSS;
995 set_reipl_block_actual(reipl_block_nss);
996 break;
997 case IPL_TYPE_UNKNOWN:
998 reipl_method = REIPL_METHOD_DEFAULT;
999 break;
1000 default:
1001 BUG();
1003 reipl_type = type;
1004 return 0;
1007 static ssize_t reipl_type_show(struct kobject *kobj,
1008 struct kobj_attribute *attr, char *page)
1010 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1013 static ssize_t reipl_type_store(struct kobject *kobj,
1014 struct kobj_attribute *attr,
1015 const char *buf, size_t len)
1017 int rc = -EINVAL;
1019 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1020 rc = reipl_set_type(IPL_TYPE_CCW);
1021 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1022 rc = reipl_set_type(IPL_TYPE_FCP);
1023 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1024 rc = reipl_set_type(IPL_TYPE_NSS);
1025 return (rc != 0) ? rc : len;
1028 static struct kobj_attribute reipl_type_attr =
1029 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1031 static struct kset *reipl_kset;
1032 static struct kset *reipl_fcp_kset;
1034 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1035 const enum ipl_method m)
1037 char loadparm[LOADPARM_LEN + 1] = {};
1038 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1039 char nss_name[NSS_NAME_SIZE + 1] = {};
1040 size_t pos = 0;
1042 reipl_get_ascii_loadparm(loadparm, ipb);
1043 reipl_get_ascii_nss_name(nss_name, ipb);
1044 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
1046 switch (m) {
1047 case REIPL_METHOD_CCW_VM:
1048 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1049 break;
1050 case REIPL_METHOD_NSS:
1051 pos = sprintf(dst, "IPL %s", nss_name);
1052 break;
1053 default:
1054 break;
1056 if (strlen(loadparm) > 0)
1057 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1058 if (strlen(vmparm) > 0)
1059 sprintf(dst + pos, " PARM %s", vmparm);
1062 static void __reipl_run(void *unused)
1064 struct ccw_dev_id devid;
1065 static char buf[128];
1067 switch (reipl_method) {
1068 case REIPL_METHOD_CCW_CIO:
1069 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1070 devid.ssid = 0;
1071 reipl_ccw_dev(&devid);
1072 break;
1073 case REIPL_METHOD_CCW_VM:
1074 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
1075 __cpcmd(buf, NULL, 0, NULL);
1076 break;
1077 case REIPL_METHOD_CCW_DIAG:
1078 diag308(DIAG308_SET, reipl_block_ccw);
1079 diag308(DIAG308_IPL, NULL);
1080 break;
1081 case REIPL_METHOD_FCP_RW_DIAG:
1082 diag308(DIAG308_SET, reipl_block_fcp);
1083 diag308(DIAG308_IPL, NULL);
1084 break;
1085 case REIPL_METHOD_FCP_RO_DIAG:
1086 diag308(DIAG308_IPL, NULL);
1087 break;
1088 case REIPL_METHOD_FCP_RO_VM:
1089 __cpcmd("IPL", NULL, 0, NULL);
1090 break;
1091 case REIPL_METHOD_NSS_DIAG:
1092 diag308(DIAG308_SET, reipl_block_nss);
1093 diag308(DIAG308_IPL, NULL);
1094 break;
1095 case REIPL_METHOD_NSS:
1096 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
1097 __cpcmd(buf, NULL, 0, NULL);
1098 break;
1099 case REIPL_METHOD_DEFAULT:
1100 if (MACHINE_IS_VM)
1101 __cpcmd("IPL", NULL, 0, NULL);
1102 diag308(DIAG308_IPL, NULL);
1103 break;
1104 case REIPL_METHOD_FCP_DUMP:
1105 break;
1107 disabled_wait((unsigned long) __builtin_return_address(0));
1110 static void reipl_run(struct shutdown_trigger *trigger)
1112 smp_call_ipl_cpu(__reipl_run, NULL);
1115 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1117 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1118 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1119 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1120 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1123 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1125 /* LOADPARM */
1126 /* check if read scp info worked and set loadparm */
1127 if (sclp_ipl_info.is_valid)
1128 memcpy(ipb->ipl_info.ccw.load_parm,
1129 &sclp_ipl_info.loadparm, LOADPARM_LEN);
1130 else
1131 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1132 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
1133 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1135 /* VM PARM */
1136 if (MACHINE_IS_VM && diag308_set_works &&
1137 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1139 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1140 ipb->ipl_info.ccw.vm_parm_len =
1141 ipl_block.ipl_info.ccw.vm_parm_len;
1142 memcpy(ipb->ipl_info.ccw.vm_parm,
1143 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1147 static int __init reipl_nss_init(void)
1149 int rc;
1151 if (!MACHINE_IS_VM)
1152 return 0;
1154 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1155 if (!reipl_block_nss)
1156 return -ENOMEM;
1158 if (!diag308_set_works)
1159 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1161 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1162 if (rc)
1163 return rc;
1165 reipl_block_ccw_init(reipl_block_nss);
1166 if (ipl_info.type == IPL_TYPE_NSS) {
1167 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1168 ' ', NSS_NAME_SIZE);
1169 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1170 kernel_nss_name, strlen(kernel_nss_name));
1171 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1172 reipl_block_nss->ipl_info.ccw.vm_flags |=
1173 DIAG308_VM_FLAGS_NSS_VALID;
1175 reipl_block_ccw_fill_parms(reipl_block_nss);
1178 reipl_capabilities |= IPL_TYPE_NSS;
1179 return 0;
1182 static int __init reipl_ccw_init(void)
1184 int rc;
1186 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1187 if (!reipl_block_ccw)
1188 return -ENOMEM;
1190 if (MACHINE_IS_VM) {
1191 if (!diag308_set_works)
1192 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1193 rc = sysfs_create_group(&reipl_kset->kobj,
1194 &reipl_ccw_attr_group_vm);
1195 } else {
1196 if(!diag308_set_works)
1197 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1198 rc = sysfs_create_group(&reipl_kset->kobj,
1199 &reipl_ccw_attr_group_lpar);
1201 if (rc)
1202 return rc;
1204 reipl_block_ccw_init(reipl_block_ccw);
1205 if (ipl_info.type == IPL_TYPE_CCW) {
1206 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1207 reipl_block_ccw_fill_parms(reipl_block_ccw);
1210 reipl_capabilities |= IPL_TYPE_CCW;
1211 return 0;
1214 static int __init reipl_fcp_init(void)
1216 int rc;
1218 if (!diag308_set_works) {
1219 if (ipl_info.type == IPL_TYPE_FCP) {
1220 make_attrs_ro(reipl_fcp_attrs);
1221 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1222 } else
1223 return 0;
1226 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1227 if (!reipl_block_fcp)
1228 return -ENOMEM;
1230 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1231 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1232 &reipl_kset->kobj);
1233 if (!reipl_fcp_kset) {
1234 free_page((unsigned long) reipl_block_fcp);
1235 return -ENOMEM;
1238 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1239 if (rc) {
1240 kset_unregister(reipl_fcp_kset);
1241 free_page((unsigned long) reipl_block_fcp);
1242 return rc;
1245 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj,
1246 &sys_reipl_fcp_scp_data_attr);
1247 if (rc) {
1248 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1249 kset_unregister(reipl_fcp_kset);
1250 free_page((unsigned long) reipl_block_fcp);
1251 return rc;
1254 if (ipl_info.type == IPL_TYPE_FCP)
1255 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1256 else {
1257 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1258 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1259 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1260 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1261 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1263 reipl_capabilities |= IPL_TYPE_FCP;
1264 return 0;
1267 static int __init reipl_type_init(void)
1269 enum ipl_type reipl_type = ipl_info.type;
1270 struct ipl_parameter_block *reipl_block;
1271 unsigned long size;
1273 reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1274 if (!reipl_block)
1275 goto out;
1277 * If we have an OS info reipl block, this will be used
1279 if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_FCP) {
1280 memcpy(reipl_block_fcp, reipl_block, size);
1281 reipl_type = IPL_TYPE_FCP;
1282 } else if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_CCW) {
1283 memcpy(reipl_block_ccw, reipl_block, size);
1284 reipl_type = IPL_TYPE_CCW;
1286 out:
1287 return reipl_set_type(reipl_type);
1290 static int __init reipl_init(void)
1292 int rc;
1294 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1295 if (!reipl_kset)
1296 return -ENOMEM;
1297 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1298 if (rc) {
1299 kset_unregister(reipl_kset);
1300 return rc;
1302 rc = reipl_ccw_init();
1303 if (rc)
1304 return rc;
1305 rc = reipl_fcp_init();
1306 if (rc)
1307 return rc;
1308 rc = reipl_nss_init();
1309 if (rc)
1310 return rc;
1311 return reipl_type_init();
1314 static struct shutdown_action __refdata reipl_action = {
1315 .name = SHUTDOWN_ACTION_REIPL_STR,
1316 .fn = reipl_run,
1317 .init = reipl_init,
1321 * dump shutdown action: Dump Linux on shutdown.
1324 /* FCP dump device attributes */
1326 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1327 dump_block_fcp->ipl_info.fcp.wwpn);
1328 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1329 dump_block_fcp->ipl_info.fcp.lun);
1330 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1331 dump_block_fcp->ipl_info.fcp.bootprog);
1332 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1333 dump_block_fcp->ipl_info.fcp.br_lba);
1334 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1335 dump_block_fcp->ipl_info.fcp.devno);
1337 static struct attribute *dump_fcp_attrs[] = {
1338 &sys_dump_fcp_device_attr.attr,
1339 &sys_dump_fcp_wwpn_attr.attr,
1340 &sys_dump_fcp_lun_attr.attr,
1341 &sys_dump_fcp_bootprog_attr.attr,
1342 &sys_dump_fcp_br_lba_attr.attr,
1343 NULL,
1346 static struct attribute_group dump_fcp_attr_group = {
1347 .name = IPL_FCP_STR,
1348 .attrs = dump_fcp_attrs,
1351 /* CCW dump device attributes */
1353 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1354 dump_block_ccw->ipl_info.ccw.devno);
1356 static struct attribute *dump_ccw_attrs[] = {
1357 &sys_dump_ccw_device_attr.attr,
1358 NULL,
1361 static struct attribute_group dump_ccw_attr_group = {
1362 .name = IPL_CCW_STR,
1363 .attrs = dump_ccw_attrs,
1366 /* dump type */
1368 static int dump_set_type(enum dump_type type)
1370 if (!(dump_capabilities & type))
1371 return -EINVAL;
1372 switch (type) {
1373 case DUMP_TYPE_CCW:
1374 if (diag308_set_works)
1375 dump_method = DUMP_METHOD_CCW_DIAG;
1376 else if (MACHINE_IS_VM)
1377 dump_method = DUMP_METHOD_CCW_VM;
1378 else
1379 dump_method = DUMP_METHOD_CCW_CIO;
1380 break;
1381 case DUMP_TYPE_FCP:
1382 dump_method = DUMP_METHOD_FCP_DIAG;
1383 break;
1384 default:
1385 dump_method = DUMP_METHOD_NONE;
1387 dump_type = type;
1388 return 0;
1391 static ssize_t dump_type_show(struct kobject *kobj,
1392 struct kobj_attribute *attr, char *page)
1394 return sprintf(page, "%s\n", dump_type_str(dump_type));
1397 static ssize_t dump_type_store(struct kobject *kobj,
1398 struct kobj_attribute *attr,
1399 const char *buf, size_t len)
1401 int rc = -EINVAL;
1403 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1404 rc = dump_set_type(DUMP_TYPE_NONE);
1405 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1406 rc = dump_set_type(DUMP_TYPE_CCW);
1407 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1408 rc = dump_set_type(DUMP_TYPE_FCP);
1409 return (rc != 0) ? rc : len;
1412 static struct kobj_attribute dump_type_attr =
1413 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1415 static struct kset *dump_kset;
1417 static void __dump_run(void *unused)
1419 struct ccw_dev_id devid;
1420 static char buf[100];
1422 switch (dump_method) {
1423 case DUMP_METHOD_CCW_CIO:
1424 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1425 devid.ssid = 0;
1426 reipl_ccw_dev(&devid);
1427 break;
1428 case DUMP_METHOD_CCW_VM:
1429 sprintf(buf, "STORE STATUS");
1430 __cpcmd(buf, NULL, 0, NULL);
1431 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1432 __cpcmd(buf, NULL, 0, NULL);
1433 break;
1434 case DUMP_METHOD_CCW_DIAG:
1435 diag308(DIAG308_SET, dump_block_ccw);
1436 diag308(DIAG308_DUMP, NULL);
1437 break;
1438 case DUMP_METHOD_FCP_DIAG:
1439 diag308(DIAG308_SET, dump_block_fcp);
1440 diag308(DIAG308_DUMP, NULL);
1441 break;
1442 default:
1443 break;
1447 static void dump_run(struct shutdown_trigger *trigger)
1449 if (dump_method == DUMP_METHOD_NONE)
1450 return;
1451 smp_send_stop();
1452 smp_call_ipl_cpu(__dump_run, NULL);
1455 static int __init dump_ccw_init(void)
1457 int rc;
1459 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1460 if (!dump_block_ccw)
1461 return -ENOMEM;
1462 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1463 if (rc) {
1464 free_page((unsigned long)dump_block_ccw);
1465 return rc;
1467 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1468 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1469 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1470 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1471 dump_capabilities |= DUMP_TYPE_CCW;
1472 return 0;
1475 static int __init dump_fcp_init(void)
1477 int rc;
1479 if (!sclp_ipl_info.has_dump)
1480 return 0; /* LDIPL DUMP is not installed */
1481 if (!diag308_set_works)
1482 return 0;
1483 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1484 if (!dump_block_fcp)
1485 return -ENOMEM;
1486 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1487 if (rc) {
1488 free_page((unsigned long)dump_block_fcp);
1489 return rc;
1491 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1492 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1493 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1494 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1495 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1496 dump_capabilities |= DUMP_TYPE_FCP;
1497 return 0;
1500 static int __init dump_init(void)
1502 int rc;
1504 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1505 if (!dump_kset)
1506 return -ENOMEM;
1507 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1508 if (rc) {
1509 kset_unregister(dump_kset);
1510 return rc;
1512 rc = dump_ccw_init();
1513 if (rc)
1514 return rc;
1515 rc = dump_fcp_init();
1516 if (rc)
1517 return rc;
1518 dump_set_type(DUMP_TYPE_NONE);
1519 return 0;
1522 static struct shutdown_action __refdata dump_action = {
1523 .name = SHUTDOWN_ACTION_DUMP_STR,
1524 .fn = dump_run,
1525 .init = dump_init,
1528 static void dump_reipl_run(struct shutdown_trigger *trigger)
1530 unsigned long ipib = (unsigned long) reipl_block_actual;
1531 unsigned int csum;
1533 csum = csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1534 mem_assign_absolute(S390_lowcore.ipib, ipib);
1535 mem_assign_absolute(S390_lowcore.ipib_checksum, csum);
1536 dump_run(trigger);
1539 static int __init dump_reipl_init(void)
1541 if (!diag308_set_works)
1542 return -EOPNOTSUPP;
1543 else
1544 return 0;
1547 static struct shutdown_action __refdata dump_reipl_action = {
1548 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1549 .fn = dump_reipl_run,
1550 .init = dump_reipl_init,
1554 * vmcmd shutdown action: Trigger vm command on shutdown.
1557 static char vmcmd_on_reboot[128];
1558 static char vmcmd_on_panic[128];
1559 static char vmcmd_on_halt[128];
1560 static char vmcmd_on_poff[128];
1561 static char vmcmd_on_restart[128];
1563 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1564 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1565 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1566 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1567 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1569 static struct attribute *vmcmd_attrs[] = {
1570 &sys_vmcmd_on_reboot_attr.attr,
1571 &sys_vmcmd_on_panic_attr.attr,
1572 &sys_vmcmd_on_halt_attr.attr,
1573 &sys_vmcmd_on_poff_attr.attr,
1574 &sys_vmcmd_on_restart_attr.attr,
1575 NULL,
1578 static struct attribute_group vmcmd_attr_group = {
1579 .attrs = vmcmd_attrs,
1582 static struct kset *vmcmd_kset;
1584 static void vmcmd_run(struct shutdown_trigger *trigger)
1586 char *cmd;
1588 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1589 cmd = vmcmd_on_reboot;
1590 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1591 cmd = vmcmd_on_panic;
1592 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1593 cmd = vmcmd_on_halt;
1594 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1595 cmd = vmcmd_on_poff;
1596 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1597 cmd = vmcmd_on_restart;
1598 else
1599 return;
1601 if (strlen(cmd) == 0)
1602 return;
1603 __cpcmd(cmd, NULL, 0, NULL);
1606 static int vmcmd_init(void)
1608 if (!MACHINE_IS_VM)
1609 return -EOPNOTSUPP;
1610 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1611 if (!vmcmd_kset)
1612 return -ENOMEM;
1613 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1616 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1617 vmcmd_run, vmcmd_init};
1620 * stop shutdown action: Stop Linux on shutdown.
1623 static void stop_run(struct shutdown_trigger *trigger)
1625 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1626 strcmp(trigger->name, ON_RESTART_STR) == 0)
1627 disabled_wait((unsigned long) __builtin_return_address(0));
1628 smp_stop_cpu();
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 lgr_info_log();
1717 on_panic_trigger.action->fn(&on_panic_trigger);
1718 stop_run(&on_panic_trigger);
1721 /* on restart */
1723 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
1724 &stop_action};
1726 static ssize_t on_restart_show(struct kobject *kobj,
1727 struct kobj_attribute *attr, char *page)
1729 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1732 static ssize_t on_restart_store(struct kobject *kobj,
1733 struct kobj_attribute *attr,
1734 const char *buf, size_t len)
1736 return set_trigger(buf, &on_restart_trigger, len);
1739 static struct kobj_attribute on_restart_attr =
1740 __ATTR(on_restart, 0644, on_restart_show, on_restart_store);
1742 static void __do_restart(void *ignore)
1744 __arch_local_irq_stosm(0x04); /* enable DAT */
1745 smp_send_stop();
1746 #ifdef CONFIG_CRASH_DUMP
1747 crash_kexec(NULL);
1748 #endif
1749 on_restart_trigger.action->fn(&on_restart_trigger);
1750 stop_run(&on_restart_trigger);
1753 void do_restart(void)
1755 tracing_off();
1756 debug_locks_off();
1757 lgr_info_log();
1758 smp_call_online_cpu(__do_restart, NULL);
1761 /* on halt */
1763 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1765 static ssize_t on_halt_show(struct kobject *kobj,
1766 struct kobj_attribute *attr, char *page)
1768 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1771 static ssize_t on_halt_store(struct kobject *kobj,
1772 struct kobj_attribute *attr,
1773 const char *buf, size_t len)
1775 return set_trigger(buf, &on_halt_trigger, len);
1778 static struct kobj_attribute on_halt_attr =
1779 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1782 static void do_machine_halt(void)
1784 smp_send_stop();
1785 on_halt_trigger.action->fn(&on_halt_trigger);
1786 stop_run(&on_halt_trigger);
1788 void (*_machine_halt)(void) = do_machine_halt;
1790 /* on power off */
1792 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1794 static ssize_t on_poff_show(struct kobject *kobj,
1795 struct kobj_attribute *attr, char *page)
1797 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1800 static ssize_t on_poff_store(struct kobject *kobj,
1801 struct kobj_attribute *attr,
1802 const char *buf, size_t len)
1804 return set_trigger(buf, &on_poff_trigger, len);
1807 static struct kobj_attribute on_poff_attr =
1808 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1811 static void do_machine_power_off(void)
1813 smp_send_stop();
1814 on_poff_trigger.action->fn(&on_poff_trigger);
1815 stop_run(&on_poff_trigger);
1817 void (*_machine_power_off)(void) = do_machine_power_off;
1819 static void __init shutdown_triggers_init(void)
1821 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1822 firmware_kobj);
1823 if (!shutdown_actions_kset)
1824 goto fail;
1825 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1826 &on_reboot_attr.attr))
1827 goto fail;
1828 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1829 &on_panic_attr.attr))
1830 goto fail;
1831 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1832 &on_halt_attr.attr))
1833 goto fail;
1834 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1835 &on_poff_attr.attr))
1836 goto fail;
1837 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1838 &on_restart_attr.attr))
1839 goto fail;
1840 return;
1841 fail:
1842 panic("shutdown_triggers_init failed\n");
1845 static void __init shutdown_actions_init(void)
1847 int i;
1849 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1850 if (!shutdown_actions_list[i]->init)
1851 continue;
1852 shutdown_actions_list[i]->init_rc =
1853 shutdown_actions_list[i]->init();
1857 static int __init s390_ipl_init(void)
1859 sclp_get_ipl_info(&sclp_ipl_info);
1860 shutdown_actions_init();
1861 shutdown_triggers_init();
1862 return 0;
1865 __initcall(s390_ipl_init);
1867 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1869 int sx, dx;
1871 dx = 0;
1872 for (sx = 0; src[sx] != 0; sx++) {
1873 if (src[sx] == '"')
1874 continue;
1875 dst[dx++] = src[sx];
1876 if (dx >= n)
1877 break;
1881 static int __init vmcmd_on_reboot_setup(char *str)
1883 if (!MACHINE_IS_VM)
1884 return 1;
1885 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1886 vmcmd_on_reboot[127] = 0;
1887 on_reboot_trigger.action = &vmcmd_action;
1888 return 1;
1890 __setup("vmreboot=", vmcmd_on_reboot_setup);
1892 static int __init vmcmd_on_panic_setup(char *str)
1894 if (!MACHINE_IS_VM)
1895 return 1;
1896 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1897 vmcmd_on_panic[127] = 0;
1898 on_panic_trigger.action = &vmcmd_action;
1899 return 1;
1901 __setup("vmpanic=", vmcmd_on_panic_setup);
1903 static int __init vmcmd_on_halt_setup(char *str)
1905 if (!MACHINE_IS_VM)
1906 return 1;
1907 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1908 vmcmd_on_halt[127] = 0;
1909 on_halt_trigger.action = &vmcmd_action;
1910 return 1;
1912 __setup("vmhalt=", vmcmd_on_halt_setup);
1914 static int __init vmcmd_on_poff_setup(char *str)
1916 if (!MACHINE_IS_VM)
1917 return 1;
1918 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1919 vmcmd_on_poff[127] = 0;
1920 on_poff_trigger.action = &vmcmd_action;
1921 return 1;
1923 __setup("vmpoff=", vmcmd_on_poff_setup);
1925 static int on_panic_notify(struct notifier_block *self,
1926 unsigned long event, void *data)
1928 do_panic();
1929 return NOTIFY_OK;
1932 static struct notifier_block on_panic_nb = {
1933 .notifier_call = on_panic_notify,
1934 .priority = INT_MIN,
1937 void __init setup_ipl(void)
1939 ipl_info.type = get_ipl_type();
1940 switch (ipl_info.type) {
1941 case IPL_TYPE_CCW:
1942 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1943 ipl_info.data.ccw.dev_id.ssid = 0;
1944 break;
1945 case IPL_TYPE_FCP:
1946 case IPL_TYPE_FCP_DUMP:
1947 ipl_info.data.fcp.dev_id.devno =
1948 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1949 ipl_info.data.fcp.dev_id.ssid = 0;
1950 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1951 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1952 break;
1953 case IPL_TYPE_NSS:
1954 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1955 sizeof(ipl_info.data.nss.name));
1956 break;
1957 case IPL_TYPE_UNKNOWN:
1958 /* We have no info to copy */
1959 break;
1961 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1964 void __init ipl_update_parameters(void)
1966 int rc;
1968 rc = diag308(DIAG308_STORE, &ipl_block);
1969 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1970 diag308_set_works = 1;
1973 void __init ipl_save_parameters(void)
1975 struct cio_iplinfo iplinfo;
1976 void *src, *dst;
1978 if (cio_get_iplinfo(&iplinfo))
1979 return;
1981 ipl_devno = iplinfo.devno;
1982 ipl_flags |= IPL_DEVNO_VALID;
1983 if (!iplinfo.is_qdio)
1984 return;
1985 ipl_flags |= IPL_PARMBLOCK_VALID;
1986 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr;
1987 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1988 memmove(dst, src, PAGE_SIZE);
1989 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN;
1992 static LIST_HEAD(rcall);
1993 static DEFINE_MUTEX(rcall_mutex);
1995 void register_reset_call(struct reset_call *reset)
1997 mutex_lock(&rcall_mutex);
1998 list_add(&reset->list, &rcall);
1999 mutex_unlock(&rcall_mutex);
2001 EXPORT_SYMBOL_GPL(register_reset_call);
2003 void unregister_reset_call(struct reset_call *reset)
2005 mutex_lock(&rcall_mutex);
2006 list_del(&reset->list);
2007 mutex_unlock(&rcall_mutex);
2009 EXPORT_SYMBOL_GPL(unregister_reset_call);
2011 static void do_reset_calls(void)
2013 struct reset_call *reset;
2015 #ifdef CONFIG_64BIT
2016 if (diag308_set_works) {
2017 diag308_reset();
2018 return;
2020 #endif
2021 list_for_each_entry(reset, &rcall, list)
2022 reset->fn();
2025 u32 dump_prefix_page;
2027 void s390_reset_system(void (*func)(void *), void *data)
2029 struct _lowcore *lc;
2031 lc = (struct _lowcore *)(unsigned long) store_prefix();
2033 /* Stack for interrupt/machine check handler */
2034 lc->panic_stack = S390_lowcore.panic_stack;
2036 /* Save prefix page address for dump case */
2037 dump_prefix_page = (u32)(unsigned long) lc;
2039 /* Disable prefixing */
2040 set_prefix(0);
2042 /* Disable lowcore protection */
2043 __ctl_clear_bit(0,28);
2045 /* Set new machine check handler */
2046 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
2047 S390_lowcore.mcck_new_psw.addr =
2048 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
2050 /* Set new program check handler */
2051 S390_lowcore.program_new_psw.mask = psw_kernel_bits | PSW_MASK_DAT;
2052 S390_lowcore.program_new_psw.addr =
2053 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
2055 /* Store status at absolute zero */
2056 store_status();
2058 do_reset_calls();
2059 if (func)
2060 func(data);