Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / s390 / kernel / ipl.c
blob34477c1aee6dfdeb957275129b995a2ea5fcacfb
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005, 2012
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/export.h>
13 #include <linux/init.h>
14 #include <linux/device.h>
15 #include <linux/delay.h>
16 #include <linux/reboot.h>
17 #include <linux/ctype.h>
18 #include <linux/fs.h>
19 #include <linux/gfp.h>
20 #include <linux/crash_dump.h>
21 #include <linux/debug_locks.h>
22 #include <asm/diag.h>
23 #include <asm/ipl.h>
24 #include <asm/smp.h>
25 #include <asm/setup.h>
26 #include <asm/cpcmd.h>
27 #include <asm/cio.h>
28 #include <asm/ebcdic.h>
29 #include <asm/reset.h>
30 #include <asm/sclp.h>
31 #include <asm/checksum.h>
32 #include <asm/debug.h>
33 #include <asm/os_info.h>
34 #include "entry.h"
36 #define IPL_PARM_BLOCK_VERSION 0
38 #define IPL_UNKNOWN_STR "unknown"
39 #define IPL_CCW_STR "ccw"
40 #define IPL_FCP_STR "fcp"
41 #define IPL_FCP_DUMP_STR "fcp_dump"
42 #define IPL_NSS_STR "nss"
44 #define DUMP_CCW_STR "ccw"
45 #define DUMP_FCP_STR "fcp"
46 #define DUMP_NONE_STR "none"
49 * Four shutdown trigger types are supported:
50 * - panic
51 * - halt
52 * - power off
53 * - reipl
54 * - restart
56 #define ON_PANIC_STR "on_panic"
57 #define ON_HALT_STR "on_halt"
58 #define ON_POFF_STR "on_poff"
59 #define ON_REIPL_STR "on_reboot"
60 #define ON_RESTART_STR "on_restart"
62 struct shutdown_action;
63 struct shutdown_trigger {
64 char *name;
65 struct shutdown_action *action;
69 * The following shutdown action types are supported:
71 #define SHUTDOWN_ACTION_IPL_STR "ipl"
72 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
73 #define SHUTDOWN_ACTION_DUMP_STR "dump"
74 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
75 #define SHUTDOWN_ACTION_STOP_STR "stop"
76 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
78 struct shutdown_action {
79 char *name;
80 void (*fn) (struct shutdown_trigger *trigger);
81 int (*init) (void);
82 int init_rc;
85 static char *ipl_type_str(enum ipl_type type)
87 switch (type) {
88 case IPL_TYPE_CCW:
89 return IPL_CCW_STR;
90 case IPL_TYPE_FCP:
91 return IPL_FCP_STR;
92 case IPL_TYPE_FCP_DUMP:
93 return IPL_FCP_DUMP_STR;
94 case IPL_TYPE_NSS:
95 return IPL_NSS_STR;
96 case IPL_TYPE_UNKNOWN:
97 default:
98 return IPL_UNKNOWN_STR;
102 enum dump_type {
103 DUMP_TYPE_NONE = 1,
104 DUMP_TYPE_CCW = 2,
105 DUMP_TYPE_FCP = 4,
108 static char *dump_type_str(enum dump_type type)
110 switch (type) {
111 case DUMP_TYPE_NONE:
112 return DUMP_NONE_STR;
113 case DUMP_TYPE_CCW:
114 return DUMP_CCW_STR;
115 case DUMP_TYPE_FCP:
116 return DUMP_FCP_STR;
117 default:
118 return NULL;
122 static u8 ipl_ssid;
123 static u16 ipl_devno;
124 u32 ipl_flags;
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;
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 static inline 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: nopr %%r7\n"
176 EX_TABLE(0b,0b)
177 : "+d" (_addr), "+d" (_rc)
178 : "d" (subcode) : "cc", "memory");
179 return _rc;
182 int diag308(unsigned long subcode, void *addr)
184 diag_stat_inc(DIAG_STAT_X308);
185 return __diag308(subcode, addr);
187 EXPORT_SYMBOL_GPL(diag308);
189 /* SYSFS */
191 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
192 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
193 struct kobj_attribute *attr, \
194 char *page) \
196 return snprintf(page, PAGE_SIZE, _format, ##args); \
199 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
200 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
201 struct kobj_attribute *attr, \
202 const char *buf, size_t len) \
204 unsigned long long ssid, devno; \
206 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
207 return -EINVAL; \
209 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
210 return -EINVAL; \
212 _ipl_blk.ssid = ssid; \
213 _ipl_blk.devno = devno; \
214 return len; \
217 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
218 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
219 _ipl_blk.ssid, _ipl_blk.devno); \
220 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
221 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
222 __ATTR(_name, (S_IRUGO | S_IWUSR), \
223 sys_##_prefix##_##_name##_show, \
224 sys_##_prefix##_##_name##_store) \
226 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
227 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
228 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
229 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
231 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
232 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
233 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
234 struct kobj_attribute *attr, \
235 const char *buf, size_t len) \
237 unsigned long long value; \
238 if (sscanf(buf, _fmt_in, &value) != 1) \
239 return -EINVAL; \
240 _value = value; \
241 return len; \
243 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
244 __ATTR(_name,(S_IRUGO | S_IWUSR), \
245 sys_##_prefix##_##_name##_show, \
246 sys_##_prefix##_##_name##_store)
248 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
249 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
250 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
251 struct kobj_attribute *attr, \
252 const char *buf, size_t len) \
254 strncpy(_value, buf, sizeof(_value) - 1); \
255 strim(_value); \
256 return len; \
258 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
259 __ATTR(_name,(S_IRUGO | S_IWUSR), \
260 sys_##_prefix##_##_name##_show, \
261 sys_##_prefix##_##_name##_store)
263 static void make_attrs_ro(struct attribute **attrs)
265 while (*attrs) {
266 (*attrs)->mode = S_IRUGO;
267 attrs++;
272 * ipl section
275 static __init enum ipl_type get_ipl_type(void)
277 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
279 if (!(ipl_flags & IPL_DEVNO_VALID))
280 return IPL_TYPE_UNKNOWN;
281 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
282 return IPL_TYPE_CCW;
283 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
284 return IPL_TYPE_UNKNOWN;
285 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
286 return IPL_TYPE_UNKNOWN;
287 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
288 return IPL_TYPE_FCP_DUMP;
289 return IPL_TYPE_FCP;
292 struct ipl_info ipl_info;
293 EXPORT_SYMBOL_GPL(ipl_info);
295 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
296 char *page)
298 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
301 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
303 /* VM IPL PARM routines */
304 static size_t reipl_get_ascii_vmparm(char *dest, size_t size,
305 const struct ipl_parameter_block *ipb)
307 int i;
308 size_t len;
309 char has_lowercase = 0;
311 len = 0;
312 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
313 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
315 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
316 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
317 /* If at least one character is lowercase, we assume mixed
318 * case; otherwise we convert everything to lowercase.
320 for (i = 0; i < len; i++)
321 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
322 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
323 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
324 has_lowercase = 1;
325 break;
327 if (!has_lowercase)
328 EBC_TOLOWER(dest, len);
329 EBCASC(dest, len);
331 dest[len] = 0;
333 return len;
336 size_t append_ipl_vmparm(char *dest, size_t size)
338 size_t rc;
340 rc = 0;
341 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
342 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
343 else
344 dest[0] = 0;
345 return rc;
348 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
349 struct kobj_attribute *attr, char *page)
351 char parm[DIAG308_VMPARM_SIZE + 1] = {};
353 append_ipl_vmparm(parm, sizeof(parm));
354 return sprintf(page, "%s\n", parm);
357 static size_t scpdata_length(const char* buf, size_t count)
359 while (count) {
360 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
361 break;
362 count--;
364 return count;
367 static size_t reipl_append_ascii_scpdata(char *dest, size_t size,
368 const struct ipl_parameter_block *ipb)
370 size_t count;
371 size_t i;
372 int has_lowercase;
374 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
375 ipb->ipl_info.fcp.scp_data_len));
376 if (!count)
377 goto out;
379 has_lowercase = 0;
380 for (i = 0; i < count; i++) {
381 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
382 count = 0;
383 goto out;
385 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
386 has_lowercase = 1;
389 if (has_lowercase)
390 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
391 else
392 for (i = 0; i < count; i++)
393 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
394 out:
395 dest[count] = '\0';
396 return count;
399 size_t append_ipl_scpdata(char *dest, size_t len)
401 size_t rc;
403 rc = 0;
404 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
405 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
406 else
407 dest[0] = 0;
408 return rc;
412 static struct kobj_attribute sys_ipl_vm_parm_attr =
413 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
415 static ssize_t sys_ipl_device_show(struct kobject *kobj,
416 struct kobj_attribute *attr, char *page)
418 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
420 switch (ipl_info.type) {
421 case IPL_TYPE_CCW:
422 return sprintf(page, "0.%x.%04x\n", ipl_ssid, ipl_devno);
423 case IPL_TYPE_FCP:
424 case IPL_TYPE_FCP_DUMP:
425 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
426 default:
427 return 0;
431 static struct kobj_attribute sys_ipl_device_attr =
432 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
434 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
435 struct bin_attribute *attr, char *buf,
436 loff_t off, size_t count)
438 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
439 IPL_PARMBLOCK_SIZE);
441 static struct bin_attribute ipl_parameter_attr =
442 __BIN_ATTR(binary_parameter, S_IRUGO, ipl_parameter_read, NULL,
443 PAGE_SIZE);
445 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
446 struct bin_attribute *attr, char *buf,
447 loff_t off, size_t count)
449 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
450 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
452 return memory_read_from_buffer(buf, count, &off, scp_data, size);
454 static struct bin_attribute ipl_scp_data_attr =
455 __BIN_ATTR(scp_data, S_IRUGO, ipl_scp_data_read, NULL, PAGE_SIZE);
457 static struct bin_attribute *ipl_fcp_bin_attrs[] = {
458 &ipl_parameter_attr,
459 &ipl_scp_data_attr,
460 NULL,
463 /* FCP ipl device attributes */
465 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
466 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
467 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
468 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
469 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
470 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
471 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
472 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
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_fcp_attrs[] = {
491 &sys_ipl_type_attr.attr,
492 &sys_ipl_device_attr.attr,
493 &sys_ipl_fcp_wwpn_attr.attr,
494 &sys_ipl_fcp_lun_attr.attr,
495 &sys_ipl_fcp_bootprog_attr.attr,
496 &sys_ipl_fcp_br_lba_attr.attr,
497 &sys_ipl_ccw_loadparm_attr.attr,
498 NULL,
501 static struct attribute_group ipl_fcp_attr_group = {
502 .attrs = ipl_fcp_attrs,
503 .bin_attrs = ipl_fcp_bin_attrs,
506 /* CCW ipl device attributes */
508 static struct attribute *ipl_ccw_attrs_vm[] = {
509 &sys_ipl_type_attr.attr,
510 &sys_ipl_device_attr.attr,
511 &sys_ipl_ccw_loadparm_attr.attr,
512 &sys_ipl_vm_parm_attr.attr,
513 NULL,
516 static struct attribute *ipl_ccw_attrs_lpar[] = {
517 &sys_ipl_type_attr.attr,
518 &sys_ipl_device_attr.attr,
519 &sys_ipl_ccw_loadparm_attr.attr,
520 NULL,
523 static struct attribute_group ipl_ccw_attr_group_vm = {
524 .attrs = ipl_ccw_attrs_vm,
527 static struct attribute_group ipl_ccw_attr_group_lpar = {
528 .attrs = ipl_ccw_attrs_lpar
531 /* UNKNOWN ipl device attributes */
533 static struct attribute *ipl_unknown_attrs[] = {
534 &sys_ipl_type_attr.attr,
535 NULL,
538 static struct attribute_group ipl_unknown_attr_group = {
539 .attrs = ipl_unknown_attrs,
542 static struct kset *ipl_kset;
544 static void __ipl_run(void *unused)
546 __bpon();
547 diag308(DIAG308_LOAD_CLEAR, NULL);
548 if (MACHINE_IS_VM)
549 __cpcmd("IPL", NULL, 0, NULL);
550 else if (ipl_info.type == IPL_TYPE_CCW)
551 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
554 static void ipl_run(struct shutdown_trigger *trigger)
556 smp_call_ipl_cpu(__ipl_run, NULL);
559 static int __init ipl_init(void)
561 int rc;
563 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
564 if (!ipl_kset) {
565 rc = -ENOMEM;
566 goto out;
568 switch (ipl_info.type) {
569 case IPL_TYPE_CCW:
570 if (MACHINE_IS_VM)
571 rc = sysfs_create_group(&ipl_kset->kobj,
572 &ipl_ccw_attr_group_vm);
573 else
574 rc = sysfs_create_group(&ipl_kset->kobj,
575 &ipl_ccw_attr_group_lpar);
576 break;
577 case IPL_TYPE_FCP:
578 case IPL_TYPE_FCP_DUMP:
579 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
580 break;
581 default:
582 rc = sysfs_create_group(&ipl_kset->kobj,
583 &ipl_unknown_attr_group);
584 break;
586 out:
587 if (rc)
588 panic("ipl_init failed: rc = %i\n", rc);
590 return 0;
593 static struct shutdown_action __refdata ipl_action = {
594 .name = SHUTDOWN_ACTION_IPL_STR,
595 .fn = ipl_run,
596 .init = ipl_init,
600 * reipl shutdown action: Reboot Linux on shutdown.
603 /* VM IPL PARM attributes */
604 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
605 char *page)
607 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
609 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
610 return sprintf(page, "%s\n", vmparm);
613 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
614 size_t vmparm_max,
615 const char *buf, size_t len)
617 int i, ip_len;
619 /* ignore trailing newline */
620 ip_len = len;
621 if ((len > 0) && (buf[len - 1] == '\n'))
622 ip_len--;
624 if (ip_len > vmparm_max)
625 return -EINVAL;
627 /* parm is used to store kernel options, check for common chars */
628 for (i = 0; i < ip_len; i++)
629 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
630 return -EINVAL;
632 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
633 ipb->ipl_info.ccw.vm_parm_len = ip_len;
634 if (ip_len > 0) {
635 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
636 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
637 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
638 } else {
639 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
642 return len;
645 /* NSS wrapper */
646 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
647 struct kobj_attribute *attr, char *page)
649 return reipl_generic_vmparm_show(reipl_block_nss, page);
652 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
653 struct kobj_attribute *attr,
654 const char *buf, size_t len)
656 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
659 /* CCW wrapper */
660 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
661 struct kobj_attribute *attr, char *page)
663 return reipl_generic_vmparm_show(reipl_block_ccw, page);
666 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
667 struct kobj_attribute *attr,
668 const char *buf, size_t len)
670 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
673 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
674 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
675 reipl_nss_vmparm_store);
676 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
677 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
678 reipl_ccw_vmparm_store);
680 /* FCP reipl device attributes */
682 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
683 struct bin_attribute *attr,
684 char *buf, loff_t off, size_t count)
686 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
687 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
689 return memory_read_from_buffer(buf, count, &off, scp_data, size);
692 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
693 struct bin_attribute *attr,
694 char *buf, loff_t off, size_t count)
696 size_t scpdata_len = count;
697 size_t padding;
700 if (off)
701 return -EINVAL;
703 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf, count);
704 if (scpdata_len % 8) {
705 padding = 8 - (scpdata_len % 8);
706 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
707 0, padding);
708 scpdata_len += padding;
711 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
712 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
713 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
715 return count;
717 static struct bin_attribute sys_reipl_fcp_scp_data_attr =
718 __BIN_ATTR(scp_data, (S_IRUGO | S_IWUSR), reipl_fcp_scpdata_read,
719 reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
721 static struct bin_attribute *reipl_fcp_bin_attrs[] = {
722 &sys_reipl_fcp_scp_data_attr,
723 NULL,
726 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
727 reipl_block_fcp->ipl_info.fcp.wwpn);
728 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
729 reipl_block_fcp->ipl_info.fcp.lun);
730 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
731 reipl_block_fcp->ipl_info.fcp.bootprog);
732 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
733 reipl_block_fcp->ipl_info.fcp.br_lba);
734 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
735 reipl_block_fcp->ipl_info.fcp.devno);
737 static void reipl_get_ascii_loadparm(char *loadparm,
738 struct ipl_parameter_block *ibp)
740 memcpy(loadparm, ibp->hdr.loadparm, LOADPARM_LEN);
741 EBCASC(loadparm, LOADPARM_LEN);
742 loadparm[LOADPARM_LEN] = 0;
743 strim(loadparm);
746 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
747 char *page)
749 char buf[LOADPARM_LEN + 1];
751 reipl_get_ascii_loadparm(buf, ipb);
752 return sprintf(page, "%s\n", buf);
755 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
756 const char *buf, size_t len)
758 int i, lp_len;
760 /* ignore trailing newline */
761 lp_len = len;
762 if ((len > 0) && (buf[len - 1] == '\n'))
763 lp_len--;
764 /* loadparm can have max 8 characters and must not start with a blank */
765 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
766 return -EINVAL;
767 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
768 for (i = 0; i < lp_len; i++) {
769 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
770 (buf[i] == '.'))
771 continue;
772 return -EINVAL;
774 /* initialize loadparm with blanks */
775 memset(ipb->hdr.loadparm, ' ', LOADPARM_LEN);
776 /* copy and convert to ebcdic */
777 memcpy(ipb->hdr.loadparm, buf, lp_len);
778 ASCEBC(ipb->hdr.loadparm, LOADPARM_LEN);
779 return len;
782 /* FCP wrapper */
783 static ssize_t reipl_fcp_loadparm_show(struct kobject *kobj,
784 struct kobj_attribute *attr, char *page)
786 return reipl_generic_loadparm_show(reipl_block_fcp, page);
789 static ssize_t reipl_fcp_loadparm_store(struct kobject *kobj,
790 struct kobj_attribute *attr,
791 const char *buf, size_t len)
793 return reipl_generic_loadparm_store(reipl_block_fcp, buf, len);
796 static struct kobj_attribute sys_reipl_fcp_loadparm_attr =
797 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_fcp_loadparm_show,
798 reipl_fcp_loadparm_store);
800 static struct attribute *reipl_fcp_attrs[] = {
801 &sys_reipl_fcp_device_attr.attr,
802 &sys_reipl_fcp_wwpn_attr.attr,
803 &sys_reipl_fcp_lun_attr.attr,
804 &sys_reipl_fcp_bootprog_attr.attr,
805 &sys_reipl_fcp_br_lba_attr.attr,
806 &sys_reipl_fcp_loadparm_attr.attr,
807 NULL,
810 static struct attribute_group reipl_fcp_attr_group = {
811 .attrs = reipl_fcp_attrs,
812 .bin_attrs = reipl_fcp_bin_attrs,
815 /* CCW reipl device attributes */
816 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ipl_info.ccw);
818 /* NSS wrapper */
819 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
820 struct kobj_attribute *attr, char *page)
822 return reipl_generic_loadparm_show(reipl_block_nss, page);
825 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
826 struct kobj_attribute *attr,
827 const char *buf, size_t len)
829 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
832 /* CCW wrapper */
833 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
834 struct kobj_attribute *attr, char *page)
836 return reipl_generic_loadparm_show(reipl_block_ccw, page);
839 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
840 struct kobj_attribute *attr,
841 const char *buf, size_t len)
843 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
846 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
847 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
848 reipl_ccw_loadparm_store);
850 static struct attribute *reipl_ccw_attrs_vm[] = {
851 &sys_reipl_ccw_device_attr.attr,
852 &sys_reipl_ccw_loadparm_attr.attr,
853 &sys_reipl_ccw_vmparm_attr.attr,
854 NULL,
857 static struct attribute *reipl_ccw_attrs_lpar[] = {
858 &sys_reipl_ccw_device_attr.attr,
859 &sys_reipl_ccw_loadparm_attr.attr,
860 NULL,
863 static struct attribute_group reipl_ccw_attr_group_vm = {
864 .name = IPL_CCW_STR,
865 .attrs = reipl_ccw_attrs_vm,
868 static struct attribute_group reipl_ccw_attr_group_lpar = {
869 .name = IPL_CCW_STR,
870 .attrs = reipl_ccw_attrs_lpar,
874 /* NSS reipl device attributes */
875 static void reipl_get_ascii_nss_name(char *dst,
876 struct ipl_parameter_block *ipb)
878 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
879 EBCASC(dst, NSS_NAME_SIZE);
880 dst[NSS_NAME_SIZE] = 0;
883 static ssize_t reipl_nss_name_show(struct kobject *kobj,
884 struct kobj_attribute *attr, char *page)
886 char nss_name[NSS_NAME_SIZE + 1] = {};
888 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
889 return sprintf(page, "%s\n", nss_name);
892 static ssize_t reipl_nss_name_store(struct kobject *kobj,
893 struct kobj_attribute *attr,
894 const char *buf, size_t len)
896 int nss_len;
898 /* ignore trailing newline */
899 nss_len = len;
900 if ((len > 0) && (buf[len - 1] == '\n'))
901 nss_len--;
903 if (nss_len > NSS_NAME_SIZE)
904 return -EINVAL;
906 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE);
907 if (nss_len > 0) {
908 reipl_block_nss->ipl_info.ccw.vm_flags |=
909 DIAG308_VM_FLAGS_NSS_VALID;
910 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len);
911 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
912 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len);
913 } else {
914 reipl_block_nss->ipl_info.ccw.vm_flags &=
915 ~DIAG308_VM_FLAGS_NSS_VALID;
918 return len;
921 static struct kobj_attribute sys_reipl_nss_name_attr =
922 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
923 reipl_nss_name_store);
925 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
926 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
927 reipl_nss_loadparm_store);
929 static struct attribute *reipl_nss_attrs[] = {
930 &sys_reipl_nss_name_attr.attr,
931 &sys_reipl_nss_loadparm_attr.attr,
932 &sys_reipl_nss_vmparm_attr.attr,
933 NULL,
936 static struct attribute_group reipl_nss_attr_group = {
937 .name = IPL_NSS_STR,
938 .attrs = reipl_nss_attrs,
941 static void set_reipl_block_actual(struct ipl_parameter_block *reipl_block)
943 reipl_block_actual = reipl_block;
944 os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
945 reipl_block->hdr.len);
948 /* reipl type */
950 static int reipl_set_type(enum ipl_type type)
952 if (!(reipl_capabilities & type))
953 return -EINVAL;
955 switch(type) {
956 case IPL_TYPE_CCW:
957 if (diag308_set_works)
958 reipl_method = REIPL_METHOD_CCW_DIAG;
959 else if (MACHINE_IS_VM)
960 reipl_method = REIPL_METHOD_CCW_VM;
961 else
962 reipl_method = REIPL_METHOD_CCW_CIO;
963 set_reipl_block_actual(reipl_block_ccw);
964 break;
965 case IPL_TYPE_FCP:
966 if (diag308_set_works)
967 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
968 else if (MACHINE_IS_VM)
969 reipl_method = REIPL_METHOD_FCP_RO_VM;
970 else
971 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
972 set_reipl_block_actual(reipl_block_fcp);
973 break;
974 case IPL_TYPE_FCP_DUMP:
975 reipl_method = REIPL_METHOD_FCP_DUMP;
976 break;
977 case IPL_TYPE_NSS:
978 if (diag308_set_works)
979 reipl_method = REIPL_METHOD_NSS_DIAG;
980 else
981 reipl_method = REIPL_METHOD_NSS;
982 set_reipl_block_actual(reipl_block_nss);
983 break;
984 case IPL_TYPE_UNKNOWN:
985 reipl_method = REIPL_METHOD_DEFAULT;
986 break;
987 default:
988 BUG();
990 reipl_type = type;
991 return 0;
994 static ssize_t reipl_type_show(struct kobject *kobj,
995 struct kobj_attribute *attr, char *page)
997 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1000 static ssize_t reipl_type_store(struct kobject *kobj,
1001 struct kobj_attribute *attr,
1002 const char *buf, size_t len)
1004 int rc = -EINVAL;
1006 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1007 rc = reipl_set_type(IPL_TYPE_CCW);
1008 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1009 rc = reipl_set_type(IPL_TYPE_FCP);
1010 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1011 rc = reipl_set_type(IPL_TYPE_NSS);
1012 return (rc != 0) ? rc : len;
1015 static struct kobj_attribute reipl_type_attr =
1016 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1018 static struct kset *reipl_kset;
1019 static struct kset *reipl_fcp_kset;
1021 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1022 const enum ipl_method m)
1024 char loadparm[LOADPARM_LEN + 1] = {};
1025 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1026 char nss_name[NSS_NAME_SIZE + 1] = {};
1027 size_t pos = 0;
1029 reipl_get_ascii_loadparm(loadparm, ipb);
1030 reipl_get_ascii_nss_name(nss_name, ipb);
1031 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
1033 switch (m) {
1034 case REIPL_METHOD_CCW_VM:
1035 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1036 break;
1037 case REIPL_METHOD_NSS:
1038 pos = sprintf(dst, "IPL %s", nss_name);
1039 break;
1040 default:
1041 break;
1043 if (strlen(loadparm) > 0)
1044 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1045 if (strlen(vmparm) > 0)
1046 sprintf(dst + pos, " PARM %s", vmparm);
1049 static void __reipl_run(void *unused)
1051 struct ccw_dev_id devid;
1052 static char buf[128];
1054 switch (reipl_method) {
1055 case REIPL_METHOD_CCW_CIO:
1056 devid.ssid = reipl_block_ccw->ipl_info.ccw.ssid;
1057 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1058 reipl_ccw_dev(&devid);
1059 break;
1060 case REIPL_METHOD_CCW_VM:
1061 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
1062 __cpcmd(buf, NULL, 0, NULL);
1063 break;
1064 case REIPL_METHOD_CCW_DIAG:
1065 diag308(DIAG308_SET, reipl_block_ccw);
1066 diag308(DIAG308_LOAD_CLEAR, NULL);
1067 break;
1068 case REIPL_METHOD_FCP_RW_DIAG:
1069 diag308(DIAG308_SET, reipl_block_fcp);
1070 diag308(DIAG308_LOAD_CLEAR, NULL);
1071 break;
1072 case REIPL_METHOD_FCP_RO_DIAG:
1073 diag308(DIAG308_LOAD_CLEAR, NULL);
1074 break;
1075 case REIPL_METHOD_FCP_RO_VM:
1076 __cpcmd("IPL", NULL, 0, NULL);
1077 break;
1078 case REIPL_METHOD_NSS_DIAG:
1079 diag308(DIAG308_SET, reipl_block_nss);
1080 diag308(DIAG308_LOAD_CLEAR, NULL);
1081 break;
1082 case REIPL_METHOD_NSS:
1083 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
1084 __cpcmd(buf, NULL, 0, NULL);
1085 break;
1086 case REIPL_METHOD_DEFAULT:
1087 if (MACHINE_IS_VM)
1088 __cpcmd("IPL", NULL, 0, NULL);
1089 diag308(DIAG308_LOAD_CLEAR, NULL);
1090 break;
1091 case REIPL_METHOD_FCP_DUMP:
1092 break;
1094 disabled_wait((unsigned long) __builtin_return_address(0));
1097 static void reipl_run(struct shutdown_trigger *trigger)
1099 smp_call_ipl_cpu(__reipl_run, NULL);
1102 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1104 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1105 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1106 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1107 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1110 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1112 /* LOADPARM */
1113 /* check if read scp info worked and set loadparm */
1114 if (sclp_ipl_info.is_valid)
1115 memcpy(ipb->hdr.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
1116 else
1117 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1118 memset(ipb->hdr.loadparm, 0x40, LOADPARM_LEN);
1119 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1121 /* VM PARM */
1122 if (MACHINE_IS_VM && diag308_set_works &&
1123 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1125 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1126 ipb->ipl_info.ccw.vm_parm_len =
1127 ipl_block.ipl_info.ccw.vm_parm_len;
1128 memcpy(ipb->ipl_info.ccw.vm_parm,
1129 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1133 static int __init reipl_nss_init(void)
1135 int rc;
1137 if (!MACHINE_IS_VM)
1138 return 0;
1140 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1141 if (!reipl_block_nss)
1142 return -ENOMEM;
1144 if (!diag308_set_works)
1145 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1147 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1148 if (rc)
1149 return rc;
1151 reipl_block_ccw_init(reipl_block_nss);
1152 reipl_capabilities |= IPL_TYPE_NSS;
1153 return 0;
1156 static int __init reipl_ccw_init(void)
1158 int rc;
1160 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1161 if (!reipl_block_ccw)
1162 return -ENOMEM;
1164 if (MACHINE_IS_VM) {
1165 if (!diag308_set_works)
1166 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1167 rc = sysfs_create_group(&reipl_kset->kobj,
1168 &reipl_ccw_attr_group_vm);
1169 } else {
1170 if(!diag308_set_works)
1171 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1172 rc = sysfs_create_group(&reipl_kset->kobj,
1173 &reipl_ccw_attr_group_lpar);
1175 if (rc)
1176 return rc;
1178 reipl_block_ccw_init(reipl_block_ccw);
1179 if (ipl_info.type == IPL_TYPE_CCW) {
1180 reipl_block_ccw->ipl_info.ccw.ssid = ipl_ssid;
1181 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno;
1182 reipl_block_ccw_fill_parms(reipl_block_ccw);
1185 reipl_capabilities |= IPL_TYPE_CCW;
1186 return 0;
1189 static int __init reipl_fcp_init(void)
1191 int rc;
1193 if (!diag308_set_works) {
1194 if (ipl_info.type == IPL_TYPE_FCP) {
1195 make_attrs_ro(reipl_fcp_attrs);
1196 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO;
1197 } else
1198 return 0;
1201 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1202 if (!reipl_block_fcp)
1203 return -ENOMEM;
1205 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1206 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1207 &reipl_kset->kobj);
1208 if (!reipl_fcp_kset) {
1209 free_page((unsigned long) reipl_block_fcp);
1210 return -ENOMEM;
1213 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1214 if (rc) {
1215 kset_unregister(reipl_fcp_kset);
1216 free_page((unsigned long) reipl_block_fcp);
1217 return rc;
1220 if (ipl_info.type == IPL_TYPE_FCP) {
1221 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1223 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1224 * is invalid in the SCSI IPL parameter block, so take it
1225 * always from sclp_ipl_info.
1227 memcpy(reipl_block_fcp->hdr.loadparm, sclp_ipl_info.loadparm,
1228 LOADPARM_LEN);
1229 } else {
1230 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1231 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1232 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1233 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1234 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1236 reipl_capabilities |= IPL_TYPE_FCP;
1237 return 0;
1240 static int __init reipl_type_init(void)
1242 enum ipl_type reipl_type = ipl_info.type;
1243 struct ipl_parameter_block *reipl_block;
1244 unsigned long size;
1246 reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1247 if (!reipl_block)
1248 goto out;
1250 * If we have an OS info reipl block, this will be used
1252 if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_FCP) {
1253 memcpy(reipl_block_fcp, reipl_block, size);
1254 reipl_type = IPL_TYPE_FCP;
1255 } else if (reipl_block->hdr.pbt == DIAG308_IPL_TYPE_CCW) {
1256 memcpy(reipl_block_ccw, reipl_block, size);
1257 reipl_type = IPL_TYPE_CCW;
1259 out:
1260 return reipl_set_type(reipl_type);
1263 static int __init reipl_init(void)
1265 int rc;
1267 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1268 if (!reipl_kset)
1269 return -ENOMEM;
1270 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1271 if (rc) {
1272 kset_unregister(reipl_kset);
1273 return rc;
1275 rc = reipl_ccw_init();
1276 if (rc)
1277 return rc;
1278 rc = reipl_fcp_init();
1279 if (rc)
1280 return rc;
1281 rc = reipl_nss_init();
1282 if (rc)
1283 return rc;
1284 return reipl_type_init();
1287 static struct shutdown_action __refdata reipl_action = {
1288 .name = SHUTDOWN_ACTION_REIPL_STR,
1289 .fn = reipl_run,
1290 .init = reipl_init,
1294 * dump shutdown action: Dump Linux on shutdown.
1297 /* FCP dump device attributes */
1299 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
1300 dump_block_fcp->ipl_info.fcp.wwpn);
1301 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
1302 dump_block_fcp->ipl_info.fcp.lun);
1303 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1304 dump_block_fcp->ipl_info.fcp.bootprog);
1305 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1306 dump_block_fcp->ipl_info.fcp.br_lba);
1307 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1308 dump_block_fcp->ipl_info.fcp.devno);
1310 static struct attribute *dump_fcp_attrs[] = {
1311 &sys_dump_fcp_device_attr.attr,
1312 &sys_dump_fcp_wwpn_attr.attr,
1313 &sys_dump_fcp_lun_attr.attr,
1314 &sys_dump_fcp_bootprog_attr.attr,
1315 &sys_dump_fcp_br_lba_attr.attr,
1316 NULL,
1319 static struct attribute_group dump_fcp_attr_group = {
1320 .name = IPL_FCP_STR,
1321 .attrs = dump_fcp_attrs,
1324 /* CCW dump device attributes */
1325 DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ipl_info.ccw);
1327 static struct attribute *dump_ccw_attrs[] = {
1328 &sys_dump_ccw_device_attr.attr,
1329 NULL,
1332 static struct attribute_group dump_ccw_attr_group = {
1333 .name = IPL_CCW_STR,
1334 .attrs = dump_ccw_attrs,
1337 /* dump type */
1339 static int dump_set_type(enum dump_type type)
1341 if (!(dump_capabilities & type))
1342 return -EINVAL;
1343 switch (type) {
1344 case DUMP_TYPE_CCW:
1345 if (diag308_set_works)
1346 dump_method = DUMP_METHOD_CCW_DIAG;
1347 else if (MACHINE_IS_VM)
1348 dump_method = DUMP_METHOD_CCW_VM;
1349 else
1350 dump_method = DUMP_METHOD_CCW_CIO;
1351 break;
1352 case DUMP_TYPE_FCP:
1353 dump_method = DUMP_METHOD_FCP_DIAG;
1354 break;
1355 default:
1356 dump_method = DUMP_METHOD_NONE;
1358 dump_type = type;
1359 return 0;
1362 static ssize_t dump_type_show(struct kobject *kobj,
1363 struct kobj_attribute *attr, char *page)
1365 return sprintf(page, "%s\n", dump_type_str(dump_type));
1368 static ssize_t dump_type_store(struct kobject *kobj,
1369 struct kobj_attribute *attr,
1370 const char *buf, size_t len)
1372 int rc = -EINVAL;
1374 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1375 rc = dump_set_type(DUMP_TYPE_NONE);
1376 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1377 rc = dump_set_type(DUMP_TYPE_CCW);
1378 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1379 rc = dump_set_type(DUMP_TYPE_FCP);
1380 return (rc != 0) ? rc : len;
1383 static struct kobj_attribute dump_type_attr =
1384 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1386 static struct kset *dump_kset;
1388 static void diag308_dump(void *dump_block)
1390 diag308(DIAG308_SET, dump_block);
1391 while (1) {
1392 if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
1393 break;
1394 udelay_simple(USEC_PER_SEC);
1398 static void __dump_run(void *unused)
1400 struct ccw_dev_id devid;
1401 static char buf[100];
1403 switch (dump_method) {
1404 case DUMP_METHOD_CCW_CIO:
1405 devid.ssid = dump_block_ccw->ipl_info.ccw.ssid;
1406 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1407 reipl_ccw_dev(&devid);
1408 break;
1409 case DUMP_METHOD_CCW_VM:
1410 sprintf(buf, "STORE STATUS");
1411 __cpcmd(buf, NULL, 0, NULL);
1412 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1413 __cpcmd(buf, NULL, 0, NULL);
1414 break;
1415 case DUMP_METHOD_CCW_DIAG:
1416 diag308_dump(dump_block_ccw);
1417 break;
1418 case DUMP_METHOD_FCP_DIAG:
1419 diag308_dump(dump_block_fcp);
1420 break;
1421 default:
1422 break;
1426 static void dump_run(struct shutdown_trigger *trigger)
1428 if (dump_method == DUMP_METHOD_NONE)
1429 return;
1430 smp_send_stop();
1431 smp_call_ipl_cpu(__dump_run, NULL);
1434 static int __init dump_ccw_init(void)
1436 int rc;
1438 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1439 if (!dump_block_ccw)
1440 return -ENOMEM;
1441 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1442 if (rc) {
1443 free_page((unsigned long)dump_block_ccw);
1444 return rc;
1446 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1447 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1448 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1449 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1450 dump_capabilities |= DUMP_TYPE_CCW;
1451 return 0;
1454 static int __init dump_fcp_init(void)
1456 int rc;
1458 if (!sclp_ipl_info.has_dump)
1459 return 0; /* LDIPL DUMP is not installed */
1460 if (!diag308_set_works)
1461 return 0;
1462 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1463 if (!dump_block_fcp)
1464 return -ENOMEM;
1465 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1466 if (rc) {
1467 free_page((unsigned long)dump_block_fcp);
1468 return rc;
1470 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1471 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1472 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1473 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1474 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1475 dump_capabilities |= DUMP_TYPE_FCP;
1476 return 0;
1479 static int __init dump_init(void)
1481 int rc;
1483 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1484 if (!dump_kset)
1485 return -ENOMEM;
1486 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1487 if (rc) {
1488 kset_unregister(dump_kset);
1489 return rc;
1491 rc = dump_ccw_init();
1492 if (rc)
1493 return rc;
1494 rc = dump_fcp_init();
1495 if (rc)
1496 return rc;
1497 dump_set_type(DUMP_TYPE_NONE);
1498 return 0;
1501 static struct shutdown_action __refdata dump_action = {
1502 .name = SHUTDOWN_ACTION_DUMP_STR,
1503 .fn = dump_run,
1504 .init = dump_init,
1507 static void dump_reipl_run(struct shutdown_trigger *trigger)
1509 unsigned long ipib = (unsigned long) reipl_block_actual;
1510 unsigned int csum;
1512 csum = (__force unsigned int)
1513 csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1514 mem_assign_absolute(S390_lowcore.ipib, ipib);
1515 mem_assign_absolute(S390_lowcore.ipib_checksum, csum);
1516 dump_run(trigger);
1519 static int __init dump_reipl_init(void)
1521 if (!diag308_set_works)
1522 return -EOPNOTSUPP;
1523 else
1524 return 0;
1527 static struct shutdown_action __refdata dump_reipl_action = {
1528 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1529 .fn = dump_reipl_run,
1530 .init = dump_reipl_init,
1534 * vmcmd shutdown action: Trigger vm command on shutdown.
1537 static char vmcmd_on_reboot[128];
1538 static char vmcmd_on_panic[128];
1539 static char vmcmd_on_halt[128];
1540 static char vmcmd_on_poff[128];
1541 static char vmcmd_on_restart[128];
1543 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1544 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1545 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1546 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1547 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1549 static struct attribute *vmcmd_attrs[] = {
1550 &sys_vmcmd_on_reboot_attr.attr,
1551 &sys_vmcmd_on_panic_attr.attr,
1552 &sys_vmcmd_on_halt_attr.attr,
1553 &sys_vmcmd_on_poff_attr.attr,
1554 &sys_vmcmd_on_restart_attr.attr,
1555 NULL,
1558 static struct attribute_group vmcmd_attr_group = {
1559 .attrs = vmcmd_attrs,
1562 static struct kset *vmcmd_kset;
1564 static void vmcmd_run(struct shutdown_trigger *trigger)
1566 char *cmd;
1568 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1569 cmd = vmcmd_on_reboot;
1570 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1571 cmd = vmcmd_on_panic;
1572 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1573 cmd = vmcmd_on_halt;
1574 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1575 cmd = vmcmd_on_poff;
1576 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1577 cmd = vmcmd_on_restart;
1578 else
1579 return;
1581 if (strlen(cmd) == 0)
1582 return;
1583 __cpcmd(cmd, NULL, 0, NULL);
1586 static int vmcmd_init(void)
1588 if (!MACHINE_IS_VM)
1589 return -EOPNOTSUPP;
1590 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1591 if (!vmcmd_kset)
1592 return -ENOMEM;
1593 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1596 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1597 vmcmd_run, vmcmd_init};
1600 * stop shutdown action: Stop Linux on shutdown.
1603 static void stop_run(struct shutdown_trigger *trigger)
1605 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1606 strcmp(trigger->name, ON_RESTART_STR) == 0)
1607 disabled_wait((unsigned long) __builtin_return_address(0));
1608 smp_stop_cpu();
1611 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1612 stop_run, NULL};
1614 /* action list */
1616 static struct shutdown_action *shutdown_actions_list[] = {
1617 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1618 &vmcmd_action, &stop_action};
1619 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1622 * Trigger section
1625 static struct kset *shutdown_actions_kset;
1627 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1628 size_t len)
1630 int i;
1632 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1633 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1634 if (shutdown_actions_list[i]->init_rc) {
1635 return shutdown_actions_list[i]->init_rc;
1636 } else {
1637 trigger->action = shutdown_actions_list[i];
1638 return len;
1642 return -EINVAL;
1645 /* on reipl */
1647 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1648 &reipl_action};
1650 static ssize_t on_reboot_show(struct kobject *kobj,
1651 struct kobj_attribute *attr, char *page)
1653 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1656 static ssize_t on_reboot_store(struct kobject *kobj,
1657 struct kobj_attribute *attr,
1658 const char *buf, size_t len)
1660 return set_trigger(buf, &on_reboot_trigger, len);
1662 static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
1664 static void do_machine_restart(char *__unused)
1666 smp_send_stop();
1667 on_reboot_trigger.action->fn(&on_reboot_trigger);
1668 reipl_run(NULL);
1670 void (*_machine_restart)(char *command) = do_machine_restart;
1672 /* on panic */
1674 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1676 static ssize_t on_panic_show(struct kobject *kobj,
1677 struct kobj_attribute *attr, char *page)
1679 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1682 static ssize_t on_panic_store(struct kobject *kobj,
1683 struct kobj_attribute *attr,
1684 const char *buf, size_t len)
1686 return set_trigger(buf, &on_panic_trigger, len);
1688 static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
1690 static void do_panic(void)
1692 lgr_info_log();
1693 on_panic_trigger.action->fn(&on_panic_trigger);
1694 stop_run(&on_panic_trigger);
1697 /* on restart */
1699 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
1700 &stop_action};
1702 static ssize_t on_restart_show(struct kobject *kobj,
1703 struct kobj_attribute *attr, char *page)
1705 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1708 static ssize_t on_restart_store(struct kobject *kobj,
1709 struct kobj_attribute *attr,
1710 const char *buf, size_t len)
1712 return set_trigger(buf, &on_restart_trigger, len);
1714 static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
1716 static void __do_restart(void *ignore)
1718 __arch_local_irq_stosm(0x04); /* enable DAT */
1719 smp_send_stop();
1720 #ifdef CONFIG_CRASH_DUMP
1721 crash_kexec(NULL);
1722 #endif
1723 on_restart_trigger.action->fn(&on_restart_trigger);
1724 stop_run(&on_restart_trigger);
1727 void do_restart(void)
1729 tracing_off();
1730 debug_locks_off();
1731 lgr_info_log();
1732 smp_call_online_cpu(__do_restart, NULL);
1735 /* on halt */
1737 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1739 static ssize_t on_halt_show(struct kobject *kobj,
1740 struct kobj_attribute *attr, char *page)
1742 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1745 static ssize_t on_halt_store(struct kobject *kobj,
1746 struct kobj_attribute *attr,
1747 const char *buf, size_t len)
1749 return set_trigger(buf, &on_halt_trigger, len);
1751 static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
1753 static void do_machine_halt(void)
1755 smp_send_stop();
1756 on_halt_trigger.action->fn(&on_halt_trigger);
1757 stop_run(&on_halt_trigger);
1759 void (*_machine_halt)(void) = do_machine_halt;
1761 /* on power off */
1763 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1765 static ssize_t on_poff_show(struct kobject *kobj,
1766 struct kobj_attribute *attr, char *page)
1768 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1771 static ssize_t on_poff_store(struct kobject *kobj,
1772 struct kobj_attribute *attr,
1773 const char *buf, size_t len)
1775 return set_trigger(buf, &on_poff_trigger, len);
1777 static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
1779 static void do_machine_power_off(void)
1781 smp_send_stop();
1782 on_poff_trigger.action->fn(&on_poff_trigger);
1783 stop_run(&on_poff_trigger);
1785 void (*_machine_power_off)(void) = do_machine_power_off;
1787 static struct attribute *shutdown_action_attrs[] = {
1788 &on_restart_attr.attr,
1789 &on_reboot_attr.attr,
1790 &on_panic_attr.attr,
1791 &on_halt_attr.attr,
1792 &on_poff_attr.attr,
1793 NULL,
1796 static struct attribute_group shutdown_action_attr_group = {
1797 .attrs = shutdown_action_attrs,
1800 static void __init shutdown_triggers_init(void)
1802 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1803 firmware_kobj);
1804 if (!shutdown_actions_kset)
1805 goto fail;
1806 if (sysfs_create_group(&shutdown_actions_kset->kobj,
1807 &shutdown_action_attr_group))
1808 goto fail;
1809 return;
1810 fail:
1811 panic("shutdown_triggers_init failed\n");
1814 static void __init shutdown_actions_init(void)
1816 int i;
1818 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1819 if (!shutdown_actions_list[i]->init)
1820 continue;
1821 shutdown_actions_list[i]->init_rc =
1822 shutdown_actions_list[i]->init();
1826 static int __init s390_ipl_init(void)
1828 char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1830 sclp_early_get_ipl_info(&sclp_ipl_info);
1832 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1833 * returned by read SCP info is invalid (contains EBCDIC blanks)
1834 * when the system has been booted via diag308. In that case we use
1835 * the value from diag308, if available.
1837 * There are also systems where diag308 store does not work in
1838 * case the system is booted from HMC. Fortunately in this case
1839 * READ SCP info provides the correct value.
1841 if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 &&
1842 diag308_set_works)
1843 memcpy(sclp_ipl_info.loadparm, ipl_block.hdr.loadparm,
1844 LOADPARM_LEN);
1845 shutdown_actions_init();
1846 shutdown_triggers_init();
1847 return 0;
1850 __initcall(s390_ipl_init);
1852 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1854 int sx, dx;
1856 dx = 0;
1857 for (sx = 0; src[sx] != 0; sx++) {
1858 if (src[sx] == '"')
1859 continue;
1860 dst[dx++] = src[sx];
1861 if (dx >= n)
1862 break;
1866 static int __init vmcmd_on_reboot_setup(char *str)
1868 if (!MACHINE_IS_VM)
1869 return 1;
1870 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1871 vmcmd_on_reboot[127] = 0;
1872 on_reboot_trigger.action = &vmcmd_action;
1873 return 1;
1875 __setup("vmreboot=", vmcmd_on_reboot_setup);
1877 static int __init vmcmd_on_panic_setup(char *str)
1879 if (!MACHINE_IS_VM)
1880 return 1;
1881 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1882 vmcmd_on_panic[127] = 0;
1883 on_panic_trigger.action = &vmcmd_action;
1884 return 1;
1886 __setup("vmpanic=", vmcmd_on_panic_setup);
1888 static int __init vmcmd_on_halt_setup(char *str)
1890 if (!MACHINE_IS_VM)
1891 return 1;
1892 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1893 vmcmd_on_halt[127] = 0;
1894 on_halt_trigger.action = &vmcmd_action;
1895 return 1;
1897 __setup("vmhalt=", vmcmd_on_halt_setup);
1899 static int __init vmcmd_on_poff_setup(char *str)
1901 if (!MACHINE_IS_VM)
1902 return 1;
1903 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1904 vmcmd_on_poff[127] = 0;
1905 on_poff_trigger.action = &vmcmd_action;
1906 return 1;
1908 __setup("vmpoff=", vmcmd_on_poff_setup);
1910 static int on_panic_notify(struct notifier_block *self,
1911 unsigned long event, void *data)
1913 do_panic();
1914 return NOTIFY_OK;
1917 static struct notifier_block on_panic_nb = {
1918 .notifier_call = on_panic_notify,
1919 .priority = INT_MIN,
1922 void __init setup_ipl(void)
1924 ipl_info.type = get_ipl_type();
1925 switch (ipl_info.type) {
1926 case IPL_TYPE_CCW:
1927 ipl_info.data.ccw.dev_id.ssid = ipl_ssid;
1928 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1929 break;
1930 case IPL_TYPE_FCP:
1931 case IPL_TYPE_FCP_DUMP:
1932 ipl_info.data.fcp.dev_id.ssid = 0;
1933 ipl_info.data.fcp.dev_id.devno =
1934 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1935 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1936 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1937 break;
1938 case IPL_TYPE_NSS:
1939 case IPL_TYPE_UNKNOWN:
1940 /* We have no info to copy */
1941 break;
1943 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1946 void __init ipl_update_parameters(void)
1948 int rc;
1950 rc = diag308(DIAG308_STORE, &ipl_block);
1951 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1952 diag308_set_works = 1;
1955 void __init ipl_verify_parameters(void)
1957 struct cio_iplinfo iplinfo;
1959 if (cio_get_iplinfo(&iplinfo))
1960 return;
1962 ipl_ssid = iplinfo.ssid;
1963 ipl_devno = iplinfo.devno;
1964 ipl_flags |= IPL_DEVNO_VALID;
1965 if (!iplinfo.is_qdio)
1966 return;
1967 ipl_flags |= IPL_PARMBLOCK_VALID;
1970 static LIST_HEAD(rcall);
1971 static DEFINE_MUTEX(rcall_mutex);
1973 void register_reset_call(struct reset_call *reset)
1975 mutex_lock(&rcall_mutex);
1976 list_add(&reset->list, &rcall);
1977 mutex_unlock(&rcall_mutex);
1979 EXPORT_SYMBOL_GPL(register_reset_call);
1981 void unregister_reset_call(struct reset_call *reset)
1983 mutex_lock(&rcall_mutex);
1984 list_del(&reset->list);
1985 mutex_unlock(&rcall_mutex);
1987 EXPORT_SYMBOL_GPL(unregister_reset_call);
1989 static void do_reset_calls(void)
1991 struct reset_call *reset;
1993 if (diag308_set_works) {
1994 diag308_reset();
1995 return;
1997 list_for_each_entry(reset, &rcall, list)
1998 reset->fn();
2001 void s390_reset_system(void)
2003 struct lowcore *lc;
2005 lc = (struct lowcore *)(unsigned long) store_prefix();
2007 /* Stack for interrupt/machine check handler */
2008 lc->panic_stack = S390_lowcore.panic_stack;
2010 /* Disable prefixing */
2011 set_prefix(0);
2013 /* Disable lowcore protection */
2014 __ctl_clear_bit(0,28);
2016 /* Set new machine check handler */
2017 S390_lowcore.mcck_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT;
2018 S390_lowcore.mcck_new_psw.addr =
2019 (unsigned long) s390_base_mcck_handler;
2021 /* Set new program check handler */
2022 S390_lowcore.program_new_psw.mask = PSW_KERNEL_BITS | PSW_MASK_DAT;
2023 S390_lowcore.program_new_psw.addr =
2024 (unsigned long) s390_base_pgm_handler;
2026 do_reset_calls();