x86/amd-iommu: Add function to complete a tlb flush
[linux/fpc-iii.git] / arch / s390 / kernel / ipl.c
blob4890ac6d7faa6da171b096e2e870cc291ffe4c93
1 /*
2 * arch/s390/kernel/ipl.c
3 * ipl/reipl/dump support for Linux on s390.
5 * Copyright IBM Corp. 2005,2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
8 * Volker Sameske <sameske@de.ibm.com>
9 */
11 #include <linux/types.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/reboot.h>
16 #include <linux/ctype.h>
17 #include <linux/fs.h>
18 #include <asm/ipl.h>
19 #include <asm/smp.h>
20 #include <asm/setup.h>
21 #include <asm/cpcmd.h>
22 #include <asm/cio.h>
23 #include <asm/ebcdic.h>
24 #include <asm/reset.h>
25 #include <asm/sclp.h>
26 #include <asm/sigp.h>
27 #include <asm/checksum.h>
29 #define IPL_PARM_BLOCK_VERSION 0
31 #define IPL_UNKNOWN_STR "unknown"
32 #define IPL_CCW_STR "ccw"
33 #define IPL_FCP_STR "fcp"
34 #define IPL_FCP_DUMP_STR "fcp_dump"
35 #define IPL_NSS_STR "nss"
37 #define DUMP_CCW_STR "ccw"
38 #define DUMP_FCP_STR "fcp"
39 #define DUMP_NONE_STR "none"
42 * Four shutdown trigger types are supported:
43 * - panic
44 * - halt
45 * - power off
46 * - reipl
48 #define ON_PANIC_STR "on_panic"
49 #define ON_HALT_STR "on_halt"
50 #define ON_POFF_STR "on_poff"
51 #define ON_REIPL_STR "on_reboot"
53 struct shutdown_action;
54 struct shutdown_trigger {
55 char *name;
56 struct shutdown_action *action;
60 * The following shutdown action types are supported:
62 #define SHUTDOWN_ACTION_IPL_STR "ipl"
63 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
64 #define SHUTDOWN_ACTION_DUMP_STR "dump"
65 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
66 #define SHUTDOWN_ACTION_STOP_STR "stop"
67 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
69 struct shutdown_action {
70 char *name;
71 void (*fn) (struct shutdown_trigger *trigger);
72 int (*init) (void);
73 int init_rc;
76 static char *ipl_type_str(enum ipl_type type)
78 switch (type) {
79 case IPL_TYPE_CCW:
80 return IPL_CCW_STR;
81 case IPL_TYPE_FCP:
82 return IPL_FCP_STR;
83 case IPL_TYPE_FCP_DUMP:
84 return IPL_FCP_DUMP_STR;
85 case IPL_TYPE_NSS:
86 return IPL_NSS_STR;
87 case IPL_TYPE_UNKNOWN:
88 default:
89 return IPL_UNKNOWN_STR;
93 enum dump_type {
94 DUMP_TYPE_NONE = 1,
95 DUMP_TYPE_CCW = 2,
96 DUMP_TYPE_FCP = 4,
99 static char *dump_type_str(enum dump_type type)
101 switch (type) {
102 case DUMP_TYPE_NONE:
103 return DUMP_NONE_STR;
104 case DUMP_TYPE_CCW:
105 return DUMP_CCW_STR;
106 case DUMP_TYPE_FCP:
107 return DUMP_FCP_STR;
108 default:
109 return NULL;
114 * Must be in data section since the bss section
115 * is not cleared when these are accessed.
117 static u16 ipl_devno __attribute__((__section__(".data"))) = 0;
118 u32 ipl_flags __attribute__((__section__(".data"))) = 0;
120 enum ipl_method {
121 REIPL_METHOD_CCW_CIO,
122 REIPL_METHOD_CCW_DIAG,
123 REIPL_METHOD_CCW_VM,
124 REIPL_METHOD_FCP_RO_DIAG,
125 REIPL_METHOD_FCP_RW_DIAG,
126 REIPL_METHOD_FCP_RO_VM,
127 REIPL_METHOD_FCP_DUMP,
128 REIPL_METHOD_NSS,
129 REIPL_METHOD_NSS_DIAG,
130 REIPL_METHOD_DEFAULT,
133 enum dump_method {
134 DUMP_METHOD_NONE,
135 DUMP_METHOD_CCW_CIO,
136 DUMP_METHOD_CCW_DIAG,
137 DUMP_METHOD_CCW_VM,
138 DUMP_METHOD_FCP_DIAG,
141 static int diag308_set_works = 0;
143 static struct ipl_parameter_block ipl_block;
145 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
147 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
148 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT;
149 static struct ipl_parameter_block *reipl_block_fcp;
150 static struct ipl_parameter_block *reipl_block_ccw;
151 static struct ipl_parameter_block *reipl_block_nss;
152 static struct ipl_parameter_block *reipl_block_actual;
154 static int dump_capabilities = DUMP_TYPE_NONE;
155 static enum dump_type dump_type = DUMP_TYPE_NONE;
156 static enum dump_method dump_method = DUMP_METHOD_NONE;
157 static struct ipl_parameter_block *dump_block_fcp;
158 static struct ipl_parameter_block *dump_block_ccw;
160 static struct sclp_ipl_info sclp_ipl_info;
162 int diag308(unsigned long subcode, void *addr)
164 register unsigned long _addr asm("0") = (unsigned long) addr;
165 register unsigned long _rc asm("1") = 0;
167 asm volatile(
168 " diag %0,%2,0x308\n"
169 "0:\n"
170 EX_TABLE(0b,0b)
171 : "+d" (_addr), "+d" (_rc)
172 : "d" (subcode) : "cc", "memory");
173 return _rc;
175 EXPORT_SYMBOL_GPL(diag308);
177 /* SYSFS */
179 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
180 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
181 struct kobj_attribute *attr, \
182 char *page) \
184 return sprintf(page, _format, _value); \
186 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
187 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);
189 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
190 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
191 struct kobj_attribute *attr, \
192 char *page) \
194 return sprintf(page, _fmt_out, \
195 (unsigned long long) _value); \
197 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
198 struct kobj_attribute *attr, \
199 const char *buf, size_t len) \
201 unsigned long long value; \
202 if (sscanf(buf, _fmt_in, &value) != 1) \
203 return -EINVAL; \
204 _value = value; \
205 return len; \
207 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
208 __ATTR(_name,(S_IRUGO | S_IWUSR), \
209 sys_##_prefix##_##_name##_show, \
210 sys_##_prefix##_##_name##_store);
212 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
213 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
214 struct kobj_attribute *attr, \
215 char *page) \
217 return sprintf(page, _fmt_out, _value); \
219 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
220 struct kobj_attribute *attr, \
221 const char *buf, size_t len) \
223 strncpy(_value, buf, sizeof(_value) - 1); \
224 strstrip(_value); \
225 return len; \
227 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
228 __ATTR(_name,(S_IRUGO | S_IWUSR), \
229 sys_##_prefix##_##_name##_show, \
230 sys_##_prefix##_##_name##_store);
232 static void make_attrs_ro(struct attribute **attrs)
234 while (*attrs) {
235 (*attrs)->mode = S_IRUGO;
236 attrs++;
241 * ipl section
244 static __init enum ipl_type get_ipl_type(void)
246 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
248 if (ipl_flags & IPL_NSS_VALID)
249 return IPL_TYPE_NSS;
250 if (!(ipl_flags & IPL_DEVNO_VALID))
251 return IPL_TYPE_UNKNOWN;
252 if (!(ipl_flags & IPL_PARMBLOCK_VALID))
253 return IPL_TYPE_CCW;
254 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION)
255 return IPL_TYPE_UNKNOWN;
256 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP)
257 return IPL_TYPE_UNKNOWN;
258 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP)
259 return IPL_TYPE_FCP_DUMP;
260 return IPL_TYPE_FCP;
263 struct ipl_info ipl_info;
264 EXPORT_SYMBOL_GPL(ipl_info);
266 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
267 char *page)
269 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
272 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
274 /* VM IPL PARM routines */
275 size_t reipl_get_ascii_vmparm(char *dest, size_t size,
276 const struct ipl_parameter_block *ipb)
278 int i;
279 size_t len;
280 char has_lowercase = 0;
282 len = 0;
283 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) &&
284 (ipb->ipl_info.ccw.vm_parm_len > 0)) {
286 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len);
287 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len);
288 /* If at least one character is lowercase, we assume mixed
289 * case; otherwise we convert everything to lowercase.
291 for (i = 0; i < len; i++)
292 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */
293 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */
294 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */
295 has_lowercase = 1;
296 break;
298 if (!has_lowercase)
299 EBC_TOLOWER(dest, len);
300 EBCASC(dest, len);
302 dest[len] = 0;
304 return len;
307 size_t append_ipl_vmparm(char *dest, size_t size)
309 size_t rc;
311 rc = 0;
312 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW))
313 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block);
314 else
315 dest[0] = 0;
316 return rc;
319 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
320 struct kobj_attribute *attr, char *page)
322 char parm[DIAG308_VMPARM_SIZE + 1] = {};
324 append_ipl_vmparm(parm, sizeof(parm));
325 return sprintf(page, "%s\n", parm);
328 static size_t scpdata_length(const char* buf, size_t count)
330 while (count) {
331 if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
332 break;
333 count--;
335 return count;
338 size_t reipl_append_ascii_scpdata(char *dest, size_t size,
339 const struct ipl_parameter_block *ipb)
341 size_t count;
342 size_t i;
343 int has_lowercase;
345 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data,
346 ipb->ipl_info.fcp.scp_data_len));
347 if (!count)
348 goto out;
350 has_lowercase = 0;
351 for (i = 0; i < count; i++) {
352 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) {
353 count = 0;
354 goto out;
356 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i]))
357 has_lowercase = 1;
360 if (has_lowercase)
361 memcpy(dest, ipb->ipl_info.fcp.scp_data, count);
362 else
363 for (i = 0; i < count; i++)
364 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]);
365 out:
366 dest[count] = '\0';
367 return count;
370 size_t append_ipl_scpdata(char *dest, size_t len)
372 size_t rc;
374 rc = 0;
375 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP)
376 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block);
377 else
378 dest[0] = 0;
379 return rc;
383 static struct kobj_attribute sys_ipl_vm_parm_attr =
384 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
386 static ssize_t sys_ipl_device_show(struct kobject *kobj,
387 struct kobj_attribute *attr, char *page)
389 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;
391 switch (ipl_info.type) {
392 case IPL_TYPE_CCW:
393 return sprintf(page, "0.0.%04x\n", ipl_devno);
394 case IPL_TYPE_FCP:
395 case IPL_TYPE_FCP_DUMP:
396 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno);
397 default:
398 return 0;
402 static struct kobj_attribute sys_ipl_device_attr =
403 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
405 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
406 char *buf, loff_t off, size_t count)
408 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
409 IPL_PARMBLOCK_SIZE);
412 static struct bin_attribute ipl_parameter_attr = {
413 .attr = {
414 .name = "binary_parameter",
415 .mode = S_IRUGO,
417 .size = PAGE_SIZE,
418 .read = &ipl_parameter_read,
421 static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
422 char *buf, loff_t off, size_t count)
424 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
425 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
427 return memory_read_from_buffer(buf, count, &off, scp_data, size);
430 static struct bin_attribute ipl_scp_data_attr = {
431 .attr = {
432 .name = "scp_data",
433 .mode = S_IRUGO,
435 .size = PAGE_SIZE,
436 .read = ipl_scp_data_read,
439 /* FCP ipl device attributes */
441 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long)
442 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn);
443 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long)
444 IPL_PARMBLOCK_START->ipl_info.fcp.lun);
445 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long)
446 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog);
447 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long)
448 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba);
450 static struct attribute *ipl_fcp_attrs[] = {
451 &sys_ipl_type_attr.attr,
452 &sys_ipl_device_attr.attr,
453 &sys_ipl_fcp_wwpn_attr.attr,
454 &sys_ipl_fcp_lun_attr.attr,
455 &sys_ipl_fcp_bootprog_attr.attr,
456 &sys_ipl_fcp_br_lba_attr.attr,
457 NULL,
460 static struct attribute_group ipl_fcp_attr_group = {
461 .attrs = ipl_fcp_attrs,
464 /* CCW ipl device attributes */
466 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
467 struct kobj_attribute *attr, char *page)
469 char loadparm[LOADPARM_LEN + 1] = {};
471 if (!sclp_ipl_info.is_valid)
472 return sprintf(page, "#unknown#\n");
473 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
474 EBCASC(loadparm, LOADPARM_LEN);
475 strstrip(loadparm);
476 return sprintf(page, "%s\n", loadparm);
479 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
480 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
482 static struct attribute *ipl_ccw_attrs_vm[] = {
483 &sys_ipl_type_attr.attr,
484 &sys_ipl_device_attr.attr,
485 &sys_ipl_ccw_loadparm_attr.attr,
486 &sys_ipl_vm_parm_attr.attr,
487 NULL,
490 static struct attribute *ipl_ccw_attrs_lpar[] = {
491 &sys_ipl_type_attr.attr,
492 &sys_ipl_device_attr.attr,
493 &sys_ipl_ccw_loadparm_attr.attr,
494 NULL,
497 static struct attribute_group ipl_ccw_attr_group_vm = {
498 .attrs = ipl_ccw_attrs_vm,
501 static struct attribute_group ipl_ccw_attr_group_lpar = {
502 .attrs = ipl_ccw_attrs_lpar
505 /* NSS ipl device attributes */
507 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name);
509 static struct attribute *ipl_nss_attrs[] = {
510 &sys_ipl_type_attr.attr,
511 &sys_ipl_nss_name_attr.attr,
512 &sys_ipl_ccw_loadparm_attr.attr,
513 &sys_ipl_vm_parm_attr.attr,
514 NULL,
517 static struct attribute_group ipl_nss_attr_group = {
518 .attrs = ipl_nss_attrs,
521 /* UNKNOWN ipl device attributes */
523 static struct attribute *ipl_unknown_attrs[] = {
524 &sys_ipl_type_attr.attr,
525 NULL,
528 static struct attribute_group ipl_unknown_attr_group = {
529 .attrs = ipl_unknown_attrs,
532 static struct kset *ipl_kset;
534 static int __init ipl_register_fcp_files(void)
536 int rc;
538 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
539 if (rc)
540 goto out;
541 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
542 if (rc)
543 goto out_ipl_parm;
544 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr);
545 if (!rc)
546 goto out;
548 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);
550 out_ipl_parm:
551 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
552 out:
553 return rc;
556 static void ipl_run(struct shutdown_trigger *trigger)
558 diag308(DIAG308_IPL, NULL);
559 if (MACHINE_IS_VM)
560 __cpcmd("IPL", NULL, 0, NULL);
561 else if (ipl_info.type == IPL_TYPE_CCW)
562 reipl_ccw_dev(&ipl_info.data.ccw.dev_id);
565 static int __init ipl_init(void)
567 int rc;
569 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
570 if (!ipl_kset) {
571 rc = -ENOMEM;
572 goto out;
574 switch (ipl_info.type) {
575 case IPL_TYPE_CCW:
576 if (MACHINE_IS_VM)
577 rc = sysfs_create_group(&ipl_kset->kobj,
578 &ipl_ccw_attr_group_vm);
579 else
580 rc = sysfs_create_group(&ipl_kset->kobj,
581 &ipl_ccw_attr_group_lpar);
582 break;
583 case IPL_TYPE_FCP:
584 case IPL_TYPE_FCP_DUMP:
585 rc = ipl_register_fcp_files();
586 break;
587 case IPL_TYPE_NSS:
588 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group);
589 break;
590 default:
591 rc = sysfs_create_group(&ipl_kset->kobj,
592 &ipl_unknown_attr_group);
593 break;
595 out:
596 if (rc)
597 panic("ipl_init failed: rc = %i\n", rc);
599 return 0;
602 static struct shutdown_action __refdata ipl_action = {
603 .name = SHUTDOWN_ACTION_IPL_STR,
604 .fn = ipl_run,
605 .init = ipl_init,
609 * reipl shutdown action: Reboot Linux on shutdown.
612 /* VM IPL PARM attributes */
613 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
614 char *page)
616 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
618 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
619 return sprintf(page, "%s\n", vmparm);
622 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
623 size_t vmparm_max,
624 const char *buf, size_t len)
626 int i, ip_len;
628 /* ignore trailing newline */
629 ip_len = len;
630 if ((len > 0) && (buf[len - 1] == '\n'))
631 ip_len--;
633 if (ip_len > vmparm_max)
634 return -EINVAL;
636 /* parm is used to store kernel options, check for common chars */
637 for (i = 0; i < ip_len; i++)
638 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
639 return -EINVAL;
641 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
642 ipb->ipl_info.ccw.vm_parm_len = ip_len;
643 if (ip_len > 0) {
644 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
645 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len);
646 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len);
647 } else {
648 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID;
651 return len;
654 /* NSS wrapper */
655 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
656 struct kobj_attribute *attr, char *page)
658 return reipl_generic_vmparm_show(reipl_block_nss, page);
661 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
662 struct kobj_attribute *attr,
663 const char *buf, size_t len)
665 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
668 /* CCW wrapper */
669 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
670 struct kobj_attribute *attr, char *page)
672 return reipl_generic_vmparm_show(reipl_block_ccw, page);
675 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
676 struct kobj_attribute *attr,
677 const char *buf, size_t len)
679 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
682 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
683 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
684 reipl_nss_vmparm_store);
685 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
686 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
687 reipl_ccw_vmparm_store);
689 /* FCP reipl device attributes */
691 static ssize_t reipl_fcp_scpdata_read(struct kobject *kobj,
692 struct bin_attribute *attr,
693 char *buf, loff_t off, size_t count)
695 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len;
696 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data;
698 return memory_read_from_buffer(buf, count, &off, scp_data, size);
701 static ssize_t reipl_fcp_scpdata_write(struct kobject *kobj,
702 struct bin_attribute *attr,
703 char *buf, loff_t off, size_t count)
705 size_t padding;
706 size_t scpdata_len;
708 if (off < 0)
709 return -EINVAL;
711 if (off >= DIAG308_SCPDATA_SIZE)
712 return -ENOSPC;
714 if (count > DIAG308_SCPDATA_SIZE - off)
715 count = DIAG308_SCPDATA_SIZE - off;
717 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count);
718 scpdata_len = off + count;
720 if (scpdata_len % 8) {
721 padding = 8 - (scpdata_len % 8);
722 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len,
723 0, padding);
724 scpdata_len += padding;
727 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len;
728 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len;
729 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len;
731 return count;
734 static struct bin_attribute sys_reipl_fcp_scp_data_attr = {
735 .attr = {
736 .name = "scp_data",
737 .mode = S_IRUGO | S_IWUSR,
739 .size = PAGE_SIZE,
740 .read = reipl_fcp_scpdata_read,
741 .write = reipl_fcp_scpdata_write,
744 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n",
745 reipl_block_fcp->ipl_info.fcp.wwpn);
746 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n",
747 reipl_block_fcp->ipl_info.fcp.lun);
748 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
749 reipl_block_fcp->ipl_info.fcp.bootprog);
750 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
751 reipl_block_fcp->ipl_info.fcp.br_lba);
752 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
753 reipl_block_fcp->ipl_info.fcp.devno);
755 static struct attribute *reipl_fcp_attrs[] = {
756 &sys_reipl_fcp_device_attr.attr,
757 &sys_reipl_fcp_wwpn_attr.attr,
758 &sys_reipl_fcp_lun_attr.attr,
759 &sys_reipl_fcp_bootprog_attr.attr,
760 &sys_reipl_fcp_br_lba_attr.attr,
761 NULL,
764 static struct attribute_group reipl_fcp_attr_group = {
765 .attrs = reipl_fcp_attrs,
768 /* CCW reipl device attributes */
770 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
771 reipl_block_ccw->ipl_info.ccw.devno);
773 static void reipl_get_ascii_loadparm(char *loadparm,
774 struct ipl_parameter_block *ibp)
776 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN);
777 EBCASC(loadparm, LOADPARM_LEN);
778 loadparm[LOADPARM_LEN] = 0;
779 strstrip(loadparm);
782 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
783 char *page)
785 char buf[LOADPARM_LEN + 1];
787 reipl_get_ascii_loadparm(buf, ipb);
788 return sprintf(page, "%s\n", buf);
791 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
792 const char *buf, size_t len)
794 int i, lp_len;
796 /* ignore trailing newline */
797 lp_len = len;
798 if ((len > 0) && (buf[len - 1] == '\n'))
799 lp_len--;
800 /* loadparm can have max 8 characters and must not start with a blank */
801 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
802 return -EINVAL;
803 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
804 for (i = 0; i < lp_len; i++) {
805 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
806 (buf[i] == '.'))
807 continue;
808 return -EINVAL;
810 /* initialize loadparm with blanks */
811 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN);
812 /* copy and convert to ebcdic */
813 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len);
814 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN);
815 return len;
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 /* reipl type */
943 static int reipl_set_type(enum ipl_type type)
945 if (!(reipl_capabilities & type))
946 return -EINVAL;
948 switch(type) {
949 case IPL_TYPE_CCW:
950 if (diag308_set_works)
951 reipl_method = REIPL_METHOD_CCW_DIAG;
952 else if (MACHINE_IS_VM)
953 reipl_method = REIPL_METHOD_CCW_VM;
954 else
955 reipl_method = REIPL_METHOD_CCW_CIO;
956 reipl_block_actual = reipl_block_ccw;
957 break;
958 case IPL_TYPE_FCP:
959 if (diag308_set_works)
960 reipl_method = REIPL_METHOD_FCP_RW_DIAG;
961 else if (MACHINE_IS_VM)
962 reipl_method = REIPL_METHOD_FCP_RO_VM;
963 else
964 reipl_method = REIPL_METHOD_FCP_RO_DIAG;
965 reipl_block_actual = reipl_block_fcp;
966 break;
967 case IPL_TYPE_FCP_DUMP:
968 reipl_method = REIPL_METHOD_FCP_DUMP;
969 break;
970 case IPL_TYPE_NSS:
971 if (diag308_set_works)
972 reipl_method = REIPL_METHOD_NSS_DIAG;
973 else
974 reipl_method = REIPL_METHOD_NSS;
975 reipl_block_actual = reipl_block_nss;
976 break;
977 case IPL_TYPE_UNKNOWN:
978 reipl_method = REIPL_METHOD_DEFAULT;
979 break;
980 default:
981 BUG();
983 reipl_type = type;
984 return 0;
987 static ssize_t reipl_type_show(struct kobject *kobj,
988 struct kobj_attribute *attr, char *page)
990 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
993 static ssize_t reipl_type_store(struct kobject *kobj,
994 struct kobj_attribute *attr,
995 const char *buf, size_t len)
997 int rc = -EINVAL;
999 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1000 rc = reipl_set_type(IPL_TYPE_CCW);
1001 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1002 rc = reipl_set_type(IPL_TYPE_FCP);
1003 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1004 rc = reipl_set_type(IPL_TYPE_NSS);
1005 return (rc != 0) ? rc : len;
1008 static struct kobj_attribute reipl_type_attr =
1009 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1011 static struct kset *reipl_kset;
1012 static struct kset *reipl_fcp_kset;
1014 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb,
1015 const enum ipl_method m)
1017 char loadparm[LOADPARM_LEN + 1] = {};
1018 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
1019 char nss_name[NSS_NAME_SIZE + 1] = {};
1020 size_t pos = 0;
1022 reipl_get_ascii_loadparm(loadparm, ipb);
1023 reipl_get_ascii_nss_name(nss_name, ipb);
1024 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
1026 switch (m) {
1027 case REIPL_METHOD_CCW_VM:
1028 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno);
1029 break;
1030 case REIPL_METHOD_NSS:
1031 pos = sprintf(dst, "IPL %s", nss_name);
1032 break;
1033 default:
1034 break;
1036 if (strlen(loadparm) > 0)
1037 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm);
1038 if (strlen(vmparm) > 0)
1039 sprintf(dst + pos, " PARM %s", vmparm);
1042 static void reipl_run(struct shutdown_trigger *trigger)
1044 struct ccw_dev_id devid;
1045 static char buf[128];
1047 switch (reipl_method) {
1048 case REIPL_METHOD_CCW_CIO:
1049 devid.devno = reipl_block_ccw->ipl_info.ccw.devno;
1050 devid.ssid = 0;
1051 reipl_ccw_dev(&devid);
1052 break;
1053 case REIPL_METHOD_CCW_VM:
1054 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM);
1055 __cpcmd(buf, NULL, 0, NULL);
1056 break;
1057 case REIPL_METHOD_CCW_DIAG:
1058 diag308(DIAG308_SET, reipl_block_ccw);
1059 diag308(DIAG308_IPL, NULL);
1060 break;
1061 case REIPL_METHOD_FCP_RW_DIAG:
1062 diag308(DIAG308_SET, reipl_block_fcp);
1063 diag308(DIAG308_IPL, NULL);
1064 break;
1065 case REIPL_METHOD_FCP_RO_DIAG:
1066 diag308(DIAG308_IPL, NULL);
1067 break;
1068 case REIPL_METHOD_FCP_RO_VM:
1069 __cpcmd("IPL", NULL, 0, NULL);
1070 break;
1071 case REIPL_METHOD_NSS_DIAG:
1072 diag308(DIAG308_SET, reipl_block_nss);
1073 diag308(DIAG308_IPL, NULL);
1074 break;
1075 case REIPL_METHOD_NSS:
1076 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS);
1077 __cpcmd(buf, NULL, 0, NULL);
1078 break;
1079 case REIPL_METHOD_DEFAULT:
1080 if (MACHINE_IS_VM)
1081 __cpcmd("IPL", NULL, 0, NULL);
1082 diag308(DIAG308_IPL, NULL);
1083 break;
1084 case REIPL_METHOD_FCP_DUMP:
1085 break;
1087 disabled_wait((unsigned long) __builtin_return_address(0));
1090 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1092 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN;
1093 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1094 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1095 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1098 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1100 /* LOADPARM */
1101 /* check if read scp info worked and set loadparm */
1102 if (sclp_ipl_info.is_valid)
1103 memcpy(ipb->ipl_info.ccw.load_parm,
1104 &sclp_ipl_info.loadparm, LOADPARM_LEN);
1105 else
1106 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1107 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN);
1108 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID;
1110 /* VM PARM */
1111 if (MACHINE_IS_VM && diag308_set_works &&
1112 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) {
1114 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID;
1115 ipb->ipl_info.ccw.vm_parm_len =
1116 ipl_block.ipl_info.ccw.vm_parm_len;
1117 memcpy(ipb->ipl_info.ccw.vm_parm,
1118 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1122 static int __init reipl_nss_init(void)
1124 int rc;
1126 if (!MACHINE_IS_VM)
1127 return 0;
1129 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1130 if (!reipl_block_nss)
1131 return -ENOMEM;
1133 if (!diag308_set_works)
1134 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO;
1136 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1137 if (rc)
1138 return rc;
1140 reipl_block_ccw_init(reipl_block_nss);
1141 if (ipl_info.type == IPL_TYPE_NSS) {
1142 memset(reipl_block_nss->ipl_info.ccw.nss_name,
1143 ' ', NSS_NAME_SIZE);
1144 memcpy(reipl_block_nss->ipl_info.ccw.nss_name,
1145 kernel_nss_name, strlen(kernel_nss_name));
1146 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE);
1147 reipl_block_nss->ipl_info.ccw.vm_flags |=
1148 DIAG308_VM_FLAGS_NSS_VALID;
1150 reipl_block_ccw_fill_parms(reipl_block_nss);
1153 reipl_capabilities |= IPL_TYPE_NSS;
1154 return 0;
1157 static int __init reipl_ccw_init(void)
1159 int rc;
1161 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1162 if (!reipl_block_ccw)
1163 return -ENOMEM;
1165 if (MACHINE_IS_VM) {
1166 if (!diag308_set_works)
1167 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO;
1168 rc = sysfs_create_group(&reipl_kset->kobj,
1169 &reipl_ccw_attr_group_vm);
1170 } else {
1171 if(!diag308_set_works)
1172 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO;
1173 rc = sysfs_create_group(&reipl_kset->kobj,
1174 &reipl_ccw_attr_group_lpar);
1176 if (rc)
1177 return rc;
1179 reipl_block_ccw_init(reipl_block_ccw);
1180 if (ipl_info.type == IPL_TYPE_CCW) {
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_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 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj,
1221 &sys_reipl_fcp_scp_data_attr);
1222 if (rc) {
1223 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1224 kset_unregister(reipl_fcp_kset);
1225 free_page((unsigned long) reipl_block_fcp);
1226 return rc;
1229 if (ipl_info.type == IPL_TYPE_FCP)
1230 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE);
1231 else {
1232 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1233 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1234 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1235 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1236 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL;
1238 reipl_capabilities |= IPL_TYPE_FCP;
1239 return 0;
1242 static int __init reipl_init(void)
1244 int rc;
1246 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1247 if (!reipl_kset)
1248 return -ENOMEM;
1249 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1250 if (rc) {
1251 kset_unregister(reipl_kset);
1252 return rc;
1254 rc = reipl_ccw_init();
1255 if (rc)
1256 return rc;
1257 rc = reipl_fcp_init();
1258 if (rc)
1259 return rc;
1260 rc = reipl_nss_init();
1261 if (rc)
1262 return rc;
1263 rc = reipl_set_type(ipl_info.type);
1264 if (rc)
1265 return rc;
1266 return 0;
1269 static struct shutdown_action __refdata reipl_action = {
1270 .name = SHUTDOWN_ACTION_REIPL_STR,
1271 .fn = reipl_run,
1272 .init = reipl_init,
1276 * dump shutdown action: Dump Linux on shutdown.
1279 /* FCP dump device attributes */
1281 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n",
1282 dump_block_fcp->ipl_info.fcp.wwpn);
1283 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n",
1284 dump_block_fcp->ipl_info.fcp.lun);
1285 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1286 dump_block_fcp->ipl_info.fcp.bootprog);
1287 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1288 dump_block_fcp->ipl_info.fcp.br_lba);
1289 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1290 dump_block_fcp->ipl_info.fcp.devno);
1292 static struct attribute *dump_fcp_attrs[] = {
1293 &sys_dump_fcp_device_attr.attr,
1294 &sys_dump_fcp_wwpn_attr.attr,
1295 &sys_dump_fcp_lun_attr.attr,
1296 &sys_dump_fcp_bootprog_attr.attr,
1297 &sys_dump_fcp_br_lba_attr.attr,
1298 NULL,
1301 static struct attribute_group dump_fcp_attr_group = {
1302 .name = IPL_FCP_STR,
1303 .attrs = dump_fcp_attrs,
1306 /* CCW dump device attributes */
1308 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n",
1309 dump_block_ccw->ipl_info.ccw.devno);
1311 static struct attribute *dump_ccw_attrs[] = {
1312 &sys_dump_ccw_device_attr.attr,
1313 NULL,
1316 static struct attribute_group dump_ccw_attr_group = {
1317 .name = IPL_CCW_STR,
1318 .attrs = dump_ccw_attrs,
1321 /* dump type */
1323 static int dump_set_type(enum dump_type type)
1325 if (!(dump_capabilities & type))
1326 return -EINVAL;
1327 switch (type) {
1328 case DUMP_TYPE_CCW:
1329 if (diag308_set_works)
1330 dump_method = DUMP_METHOD_CCW_DIAG;
1331 else if (MACHINE_IS_VM)
1332 dump_method = DUMP_METHOD_CCW_VM;
1333 else
1334 dump_method = DUMP_METHOD_CCW_CIO;
1335 break;
1336 case DUMP_TYPE_FCP:
1337 dump_method = DUMP_METHOD_FCP_DIAG;
1338 break;
1339 default:
1340 dump_method = DUMP_METHOD_NONE;
1342 dump_type = type;
1343 return 0;
1346 static ssize_t dump_type_show(struct kobject *kobj,
1347 struct kobj_attribute *attr, char *page)
1349 return sprintf(page, "%s\n", dump_type_str(dump_type));
1352 static ssize_t dump_type_store(struct kobject *kobj,
1353 struct kobj_attribute *attr,
1354 const char *buf, size_t len)
1356 int rc = -EINVAL;
1358 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1359 rc = dump_set_type(DUMP_TYPE_NONE);
1360 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1361 rc = dump_set_type(DUMP_TYPE_CCW);
1362 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1363 rc = dump_set_type(DUMP_TYPE_FCP);
1364 return (rc != 0) ? rc : len;
1367 static struct kobj_attribute dump_type_attr =
1368 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1370 static struct kset *dump_kset;
1372 static void dump_run(struct shutdown_trigger *trigger)
1374 struct ccw_dev_id devid;
1375 static char buf[100];
1377 switch (dump_method) {
1378 case DUMP_METHOD_CCW_CIO:
1379 smp_send_stop();
1380 devid.devno = dump_block_ccw->ipl_info.ccw.devno;
1381 devid.ssid = 0;
1382 reipl_ccw_dev(&devid);
1383 break;
1384 case DUMP_METHOD_CCW_VM:
1385 smp_send_stop();
1386 sprintf(buf, "STORE STATUS");
1387 __cpcmd(buf, NULL, 0, NULL);
1388 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno);
1389 __cpcmd(buf, NULL, 0, NULL);
1390 break;
1391 case DUMP_METHOD_CCW_DIAG:
1392 diag308(DIAG308_SET, dump_block_ccw);
1393 diag308(DIAG308_DUMP, NULL);
1394 break;
1395 case DUMP_METHOD_FCP_DIAG:
1396 diag308(DIAG308_SET, dump_block_fcp);
1397 diag308(DIAG308_DUMP, NULL);
1398 break;
1399 case DUMP_METHOD_NONE:
1400 return;
1402 printk(KERN_EMERG "Dump failed!\n");
1405 static int __init dump_ccw_init(void)
1407 int rc;
1409 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1410 if (!dump_block_ccw)
1411 return -ENOMEM;
1412 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1413 if (rc) {
1414 free_page((unsigned long)dump_block_ccw);
1415 return rc;
1417 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN;
1418 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1419 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN;
1420 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW;
1421 dump_capabilities |= DUMP_TYPE_CCW;
1422 return 0;
1425 static int __init dump_fcp_init(void)
1427 int rc;
1429 if (!sclp_ipl_info.has_dump)
1430 return 0; /* LDIPL DUMP is not installed */
1431 if (!diag308_set_works)
1432 return 0;
1433 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1434 if (!dump_block_fcp)
1435 return -ENOMEM;
1436 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1437 if (rc) {
1438 free_page((unsigned long)dump_block_fcp);
1439 return rc;
1441 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN;
1442 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1443 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN;
1444 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP;
1445 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP;
1446 dump_capabilities |= DUMP_TYPE_FCP;
1447 return 0;
1450 static int __init dump_init(void)
1452 int rc;
1454 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1455 if (!dump_kset)
1456 return -ENOMEM;
1457 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1458 if (rc) {
1459 kset_unregister(dump_kset);
1460 return rc;
1462 rc = dump_ccw_init();
1463 if (rc)
1464 return rc;
1465 rc = dump_fcp_init();
1466 if (rc)
1467 return rc;
1468 dump_set_type(DUMP_TYPE_NONE);
1469 return 0;
1472 static struct shutdown_action __refdata dump_action = {
1473 .name = SHUTDOWN_ACTION_DUMP_STR,
1474 .fn = dump_run,
1475 .init = dump_init,
1478 static void dump_reipl_run(struct shutdown_trigger *trigger)
1480 preempt_disable();
1482 * Bypass dynamic address translation (DAT) when storing IPL parameter
1483 * information block address and checksum into the prefix area
1484 * (corresponding to absolute addresses 0-8191).
1485 * When enhanced DAT applies and the STE format control in one,
1486 * the absolute address is formed without prefixing. In this case a
1487 * normal store (stg/st) into the prefix area would no more match to
1488 * absolute addresses 0-8191.
1490 #ifdef CONFIG_64BIT
1491 asm volatile("sturg %0,%1"
1492 :: "a" ((unsigned long) reipl_block_actual),
1493 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1494 #else
1495 asm volatile("stura %0,%1"
1496 :: "a" ((unsigned long) reipl_block_actual),
1497 "a" (&lowcore_ptr[smp_processor_id()]->ipib));
1498 #endif
1499 asm volatile("stura %0,%1"
1500 :: "a" (csum_partial(reipl_block_actual,
1501 reipl_block_actual->hdr.len, 0)),
1502 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum));
1503 preempt_enable();
1504 dump_run(trigger);
1507 static int __init dump_reipl_init(void)
1509 if (!diag308_set_works)
1510 return -EOPNOTSUPP;
1511 else
1512 return 0;
1515 static struct shutdown_action __refdata dump_reipl_action = {
1516 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1517 .fn = dump_reipl_run,
1518 .init = dump_reipl_init,
1522 * vmcmd shutdown action: Trigger vm command on shutdown.
1525 static char vmcmd_on_reboot[128];
1526 static char vmcmd_on_panic[128];
1527 static char vmcmd_on_halt[128];
1528 static char vmcmd_on_poff[128];
1530 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1531 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1532 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1533 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1535 static struct attribute *vmcmd_attrs[] = {
1536 &sys_vmcmd_on_reboot_attr.attr,
1537 &sys_vmcmd_on_panic_attr.attr,
1538 &sys_vmcmd_on_halt_attr.attr,
1539 &sys_vmcmd_on_poff_attr.attr,
1540 NULL,
1543 static struct attribute_group vmcmd_attr_group = {
1544 .attrs = vmcmd_attrs,
1547 static struct kset *vmcmd_kset;
1549 static void vmcmd_run(struct shutdown_trigger *trigger)
1551 char *cmd, *next_cmd;
1553 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1554 cmd = vmcmd_on_reboot;
1555 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1556 cmd = vmcmd_on_panic;
1557 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1558 cmd = vmcmd_on_halt;
1559 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1560 cmd = vmcmd_on_poff;
1561 else
1562 return;
1564 if (strlen(cmd) == 0)
1565 return;
1566 do {
1567 next_cmd = strchr(cmd, '\n');
1568 if (next_cmd) {
1569 next_cmd[0] = 0;
1570 next_cmd += 1;
1572 __cpcmd(cmd, NULL, 0, NULL);
1573 cmd = next_cmd;
1574 } while (cmd != NULL);
1577 static int vmcmd_init(void)
1579 if (!MACHINE_IS_VM)
1580 return -ENOTSUPP;
1581 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1582 if (!vmcmd_kset)
1583 return -ENOMEM;
1584 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1587 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1588 vmcmd_run, vmcmd_init};
1591 * stop shutdown action: Stop Linux on shutdown.
1594 static void stop_run(struct shutdown_trigger *trigger)
1596 if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1597 disabled_wait((unsigned long) __builtin_return_address(0));
1598 while (signal_processor(smp_processor_id(), sigp_stop) == sigp_busy)
1599 cpu_relax();
1600 for (;;);
1603 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1604 stop_run, NULL};
1606 /* action list */
1608 static struct shutdown_action *shutdown_actions_list[] = {
1609 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1610 &vmcmd_action, &stop_action};
1611 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1614 * Trigger section
1617 static struct kset *shutdown_actions_kset;
1619 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1620 size_t len)
1622 int i;
1624 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1625 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1626 if (shutdown_actions_list[i]->init_rc) {
1627 return shutdown_actions_list[i]->init_rc;
1628 } else {
1629 trigger->action = shutdown_actions_list[i];
1630 return len;
1634 return -EINVAL;
1637 /* on reipl */
1639 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1640 &reipl_action};
1642 static ssize_t on_reboot_show(struct kobject *kobj,
1643 struct kobj_attribute *attr, char *page)
1645 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1648 static ssize_t on_reboot_store(struct kobject *kobj,
1649 struct kobj_attribute *attr,
1650 const char *buf, size_t len)
1652 return set_trigger(buf, &on_reboot_trigger, len);
1655 static struct kobj_attribute on_reboot_attr =
1656 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store);
1658 static void do_machine_restart(char *__unused)
1660 smp_send_stop();
1661 on_reboot_trigger.action->fn(&on_reboot_trigger);
1662 reipl_run(NULL);
1664 void (*_machine_restart)(char *command) = do_machine_restart;
1666 /* on panic */
1668 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1670 static ssize_t on_panic_show(struct kobject *kobj,
1671 struct kobj_attribute *attr, char *page)
1673 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1676 static ssize_t on_panic_store(struct kobject *kobj,
1677 struct kobj_attribute *attr,
1678 const char *buf, size_t len)
1680 return set_trigger(buf, &on_panic_trigger, len);
1683 static struct kobj_attribute on_panic_attr =
1684 __ATTR(on_panic, 0644, on_panic_show, on_panic_store);
1686 static void do_panic(void)
1688 on_panic_trigger.action->fn(&on_panic_trigger);
1689 stop_run(&on_panic_trigger);
1692 /* on halt */
1694 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1696 static ssize_t on_halt_show(struct kobject *kobj,
1697 struct kobj_attribute *attr, char *page)
1699 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1702 static ssize_t on_halt_store(struct kobject *kobj,
1703 struct kobj_attribute *attr,
1704 const char *buf, size_t len)
1706 return set_trigger(buf, &on_halt_trigger, len);
1709 static struct kobj_attribute on_halt_attr =
1710 __ATTR(on_halt, 0644, on_halt_show, on_halt_store);
1713 static void do_machine_halt(void)
1715 smp_send_stop();
1716 on_halt_trigger.action->fn(&on_halt_trigger);
1717 stop_run(&on_halt_trigger);
1719 void (*_machine_halt)(void) = do_machine_halt;
1721 /* on power off */
1723 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1725 static ssize_t on_poff_show(struct kobject *kobj,
1726 struct kobj_attribute *attr, char *page)
1728 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1731 static ssize_t on_poff_store(struct kobject *kobj,
1732 struct kobj_attribute *attr,
1733 const char *buf, size_t len)
1735 return set_trigger(buf, &on_poff_trigger, len);
1738 static struct kobj_attribute on_poff_attr =
1739 __ATTR(on_poff, 0644, on_poff_show, on_poff_store);
1742 static void do_machine_power_off(void)
1744 smp_send_stop();
1745 on_poff_trigger.action->fn(&on_poff_trigger);
1746 stop_run(&on_poff_trigger);
1748 void (*_machine_power_off)(void) = do_machine_power_off;
1750 static void __init shutdown_triggers_init(void)
1752 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1753 firmware_kobj);
1754 if (!shutdown_actions_kset)
1755 goto fail;
1756 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1757 &on_reboot_attr.attr))
1758 goto fail;
1759 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1760 &on_panic_attr.attr))
1761 goto fail;
1762 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1763 &on_halt_attr.attr))
1764 goto fail;
1765 if (sysfs_create_file(&shutdown_actions_kset->kobj,
1766 &on_poff_attr.attr))
1767 goto fail;
1769 return;
1770 fail:
1771 panic("shutdown_triggers_init failed\n");
1774 static void __init shutdown_actions_init(void)
1776 int i;
1778 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1779 if (!shutdown_actions_list[i]->init)
1780 continue;
1781 shutdown_actions_list[i]->init_rc =
1782 shutdown_actions_list[i]->init();
1786 static int __init s390_ipl_init(void)
1788 sclp_get_ipl_info(&sclp_ipl_info);
1789 shutdown_actions_init();
1790 shutdown_triggers_init();
1791 return 0;
1794 __initcall(s390_ipl_init);
1796 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1798 int sx, dx;
1800 dx = 0;
1801 for (sx = 0; src[sx] != 0; sx++) {
1802 if (src[sx] == '"')
1803 continue;
1804 dst[dx++] = src[sx];
1805 if (dx >= n)
1806 break;
1810 static int __init vmcmd_on_reboot_setup(char *str)
1812 if (!MACHINE_IS_VM)
1813 return 1;
1814 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1815 vmcmd_on_reboot[127] = 0;
1816 on_reboot_trigger.action = &vmcmd_action;
1817 return 1;
1819 __setup("vmreboot=", vmcmd_on_reboot_setup);
1821 static int __init vmcmd_on_panic_setup(char *str)
1823 if (!MACHINE_IS_VM)
1824 return 1;
1825 strncpy_skip_quote(vmcmd_on_panic, str, 127);
1826 vmcmd_on_panic[127] = 0;
1827 on_panic_trigger.action = &vmcmd_action;
1828 return 1;
1830 __setup("vmpanic=", vmcmd_on_panic_setup);
1832 static int __init vmcmd_on_halt_setup(char *str)
1834 if (!MACHINE_IS_VM)
1835 return 1;
1836 strncpy_skip_quote(vmcmd_on_halt, str, 127);
1837 vmcmd_on_halt[127] = 0;
1838 on_halt_trigger.action = &vmcmd_action;
1839 return 1;
1841 __setup("vmhalt=", vmcmd_on_halt_setup);
1843 static int __init vmcmd_on_poff_setup(char *str)
1845 if (!MACHINE_IS_VM)
1846 return 1;
1847 strncpy_skip_quote(vmcmd_on_poff, str, 127);
1848 vmcmd_on_poff[127] = 0;
1849 on_poff_trigger.action = &vmcmd_action;
1850 return 1;
1852 __setup("vmpoff=", vmcmd_on_poff_setup);
1854 static int on_panic_notify(struct notifier_block *self,
1855 unsigned long event, void *data)
1857 do_panic();
1858 return NOTIFY_OK;
1861 static struct notifier_block on_panic_nb = {
1862 .notifier_call = on_panic_notify,
1863 .priority = INT_MIN,
1866 void __init setup_ipl(void)
1868 ipl_info.type = get_ipl_type();
1869 switch (ipl_info.type) {
1870 case IPL_TYPE_CCW:
1871 ipl_info.data.ccw.dev_id.devno = ipl_devno;
1872 ipl_info.data.ccw.dev_id.ssid = 0;
1873 break;
1874 case IPL_TYPE_FCP:
1875 case IPL_TYPE_FCP_DUMP:
1876 ipl_info.data.fcp.dev_id.devno =
1877 IPL_PARMBLOCK_START->ipl_info.fcp.devno;
1878 ipl_info.data.fcp.dev_id.ssid = 0;
1879 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn;
1880 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun;
1881 break;
1882 case IPL_TYPE_NSS:
1883 strncpy(ipl_info.data.nss.name, kernel_nss_name,
1884 sizeof(ipl_info.data.nss.name));
1885 break;
1886 case IPL_TYPE_UNKNOWN:
1887 /* We have no info to copy */
1888 break;
1890 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
1893 void __init ipl_update_parameters(void)
1895 int rc;
1897 rc = diag308(DIAG308_STORE, &ipl_block);
1898 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG))
1899 diag308_set_works = 1;
1902 void __init ipl_save_parameters(void)
1904 struct cio_iplinfo iplinfo;
1905 unsigned int *ipl_ptr;
1906 void *src, *dst;
1908 if (cio_get_iplinfo(&iplinfo))
1909 return;
1911 ipl_devno = iplinfo.devno;
1912 ipl_flags |= IPL_DEVNO_VALID;
1913 if (!iplinfo.is_qdio)
1914 return;
1915 ipl_flags |= IPL_PARMBLOCK_VALID;
1916 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
1917 src = (void *)(unsigned long)*ipl_ptr;
1918 dst = (void *)IPL_PARMBLOCK_ORIGIN;
1919 memmove(dst, src, PAGE_SIZE);
1920 *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
1923 static LIST_HEAD(rcall);
1924 static DEFINE_MUTEX(rcall_mutex);
1926 void register_reset_call(struct reset_call *reset)
1928 mutex_lock(&rcall_mutex);
1929 list_add(&reset->list, &rcall);
1930 mutex_unlock(&rcall_mutex);
1932 EXPORT_SYMBOL_GPL(register_reset_call);
1934 void unregister_reset_call(struct reset_call *reset)
1936 mutex_lock(&rcall_mutex);
1937 list_del(&reset->list);
1938 mutex_unlock(&rcall_mutex);
1940 EXPORT_SYMBOL_GPL(unregister_reset_call);
1942 static void do_reset_calls(void)
1944 struct reset_call *reset;
1946 list_for_each_entry(reset, &rcall, list)
1947 reset->fn();
1950 u32 dump_prefix_page;
1952 void s390_reset_system(void)
1954 struct _lowcore *lc;
1956 lc = (struct _lowcore *)(unsigned long) store_prefix();
1958 /* Stack for interrupt/machine check handler */
1959 lc->panic_stack = S390_lowcore.panic_stack;
1961 /* Save prefix page address for dump case */
1962 dump_prefix_page = (u32)(unsigned long) lc;
1964 /* Disable prefixing */
1965 set_prefix(0);
1967 /* Disable lowcore protection */
1968 __ctl_clear_bit(0,28);
1970 /* Set new machine check handler */
1971 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1972 S390_lowcore.mcck_new_psw.addr =
1973 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler;
1975 /* Set new program check handler */
1976 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
1977 S390_lowcore.program_new_psw.addr =
1978 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler;
1980 do_reset_calls();