Merge tag 'locking-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / s390 / kernel / ipl.c
blob7a21eca498aae762ee26be052078689639325b49
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/ebcdic.h>
28 #include <asm/sclp.h>
29 #include <asm/checksum.h>
30 #include <asm/debug.h>
31 #include <asm/os_info.h>
32 #include <asm/sections.h>
33 #include <asm/boot_data.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_NVME_STR "nvme"
43 #define IPL_NVME_DUMP_STR "nvme_dump"
44 #define IPL_NSS_STR "nss"
46 #define DUMP_CCW_STR "ccw"
47 #define DUMP_FCP_STR "fcp"
48 #define DUMP_NVME_STR "nvme"
49 #define DUMP_NONE_STR "none"
52 * Four shutdown trigger types are supported:
53 * - panic
54 * - halt
55 * - power off
56 * - reipl
57 * - restart
59 #define ON_PANIC_STR "on_panic"
60 #define ON_HALT_STR "on_halt"
61 #define ON_POFF_STR "on_poff"
62 #define ON_REIPL_STR "on_reboot"
63 #define ON_RESTART_STR "on_restart"
65 struct shutdown_action;
66 struct shutdown_trigger {
67 char *name;
68 struct shutdown_action *action;
72 * The following shutdown action types are supported:
74 #define SHUTDOWN_ACTION_IPL_STR "ipl"
75 #define SHUTDOWN_ACTION_REIPL_STR "reipl"
76 #define SHUTDOWN_ACTION_DUMP_STR "dump"
77 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd"
78 #define SHUTDOWN_ACTION_STOP_STR "stop"
79 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl"
81 struct shutdown_action {
82 char *name;
83 void (*fn) (struct shutdown_trigger *trigger);
84 int (*init) (void);
85 int init_rc;
88 static char *ipl_type_str(enum ipl_type type)
90 switch (type) {
91 case IPL_TYPE_CCW:
92 return IPL_CCW_STR;
93 case IPL_TYPE_FCP:
94 return IPL_FCP_STR;
95 case IPL_TYPE_FCP_DUMP:
96 return IPL_FCP_DUMP_STR;
97 case IPL_TYPE_NSS:
98 return IPL_NSS_STR;
99 case IPL_TYPE_NVME:
100 return IPL_NVME_STR;
101 case IPL_TYPE_NVME_DUMP:
102 return IPL_NVME_DUMP_STR;
103 case IPL_TYPE_UNKNOWN:
104 default:
105 return IPL_UNKNOWN_STR;
109 enum dump_type {
110 DUMP_TYPE_NONE = 1,
111 DUMP_TYPE_CCW = 2,
112 DUMP_TYPE_FCP = 4,
113 DUMP_TYPE_NVME = 8,
116 static char *dump_type_str(enum dump_type type)
118 switch (type) {
119 case DUMP_TYPE_NONE:
120 return DUMP_NONE_STR;
121 case DUMP_TYPE_CCW:
122 return DUMP_CCW_STR;
123 case DUMP_TYPE_FCP:
124 return DUMP_FCP_STR;
125 case DUMP_TYPE_NVME:
126 return DUMP_NVME_STR;
127 default:
128 return NULL;
132 int __bootdata_preserved(ipl_block_valid);
133 struct ipl_parameter_block __bootdata_preserved(ipl_block);
134 int __bootdata_preserved(ipl_secure_flag);
136 unsigned long __bootdata_preserved(ipl_cert_list_addr);
137 unsigned long __bootdata_preserved(ipl_cert_list_size);
139 unsigned long __bootdata(early_ipl_comp_list_addr);
140 unsigned long __bootdata(early_ipl_comp_list_size);
142 static int reipl_capabilities = IPL_TYPE_UNKNOWN;
144 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN;
145 static struct ipl_parameter_block *reipl_block_fcp;
146 static struct ipl_parameter_block *reipl_block_nvme;
147 static struct ipl_parameter_block *reipl_block_ccw;
148 static struct ipl_parameter_block *reipl_block_nss;
149 static struct ipl_parameter_block *reipl_block_actual;
151 static int dump_capabilities = DUMP_TYPE_NONE;
152 static enum dump_type dump_type = DUMP_TYPE_NONE;
153 static struct ipl_parameter_block *dump_block_fcp;
154 static struct ipl_parameter_block *dump_block_nvme;
155 static struct ipl_parameter_block *dump_block_ccw;
157 static struct sclp_ipl_info sclp_ipl_info;
159 static bool reipl_nvme_clear;
160 static bool reipl_fcp_clear;
161 static bool reipl_ccw_clear;
163 static inline int __diag308(unsigned long subcode, void *addr)
165 register unsigned long _addr asm("0") = (unsigned long) addr;
166 register unsigned long _rc asm("1") = 0;
168 asm volatile(
169 " diag %0,%2,0x308\n"
170 "0: nopr %%r7\n"
171 EX_TABLE(0b,0b)
172 : "+d" (_addr), "+d" (_rc)
173 : "d" (subcode) : "cc", "memory");
174 return _rc;
177 int diag308(unsigned long subcode, void *addr)
179 if (IS_ENABLED(CONFIG_KASAN))
180 __arch_local_irq_stosm(0x04); /* enable DAT */
181 diag_stat_inc(DIAG_STAT_X308);
182 return __diag308(subcode, addr);
184 EXPORT_SYMBOL_GPL(diag308);
186 /* SYSFS */
188 #define IPL_ATTR_SHOW_FN(_prefix, _name, _format, args...) \
189 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
190 struct kobj_attribute *attr, \
191 char *page) \
193 return scnprintf(page, PAGE_SIZE, _format, ##args); \
196 #define IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk) \
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 ssid, devno; \
203 if (sscanf(buf, "0.%llx.%llx\n", &ssid, &devno) != 2) \
204 return -EINVAL; \
206 if (ssid > __MAX_SSID || devno > __MAX_SUBCHANNEL) \
207 return -EINVAL; \
209 _ipl_blk.ssid = ssid; \
210 _ipl_blk.devno = devno; \
211 return len; \
214 #define DEFINE_IPL_CCW_ATTR_RW(_prefix, _name, _ipl_blk) \
215 IPL_ATTR_SHOW_FN(_prefix, _name, "0.%x.%04x\n", \
216 _ipl_blk.ssid, _ipl_blk.devno); \
217 IPL_ATTR_CCW_STORE_FN(_prefix, _name, _ipl_blk); \
218 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
219 __ATTR(_name, (S_IRUGO | S_IWUSR), \
220 sys_##_prefix##_##_name##_show, \
221 sys_##_prefix##_##_name##_store) \
223 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
224 IPL_ATTR_SHOW_FN(_prefix, _name, _format, _value) \
225 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
226 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL)
228 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
229 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, (unsigned long long) _value) \
230 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
231 struct kobj_attribute *attr, \
232 const char *buf, size_t len) \
234 unsigned long long value; \
235 if (sscanf(buf, _fmt_in, &value) != 1) \
236 return -EINVAL; \
237 _value = value; \
238 return len; \
240 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
241 __ATTR(_name,(S_IRUGO | S_IWUSR), \
242 sys_##_prefix##_##_name##_show, \
243 sys_##_prefix##_##_name##_store)
245 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
246 IPL_ATTR_SHOW_FN(_prefix, _name, _fmt_out, _value) \
247 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
248 struct kobj_attribute *attr, \
249 const char *buf, size_t len) \
251 strncpy(_value, buf, sizeof(_value) - 1); \
252 strim(_value); \
253 return len; \
255 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
256 __ATTR(_name,(S_IRUGO | S_IWUSR), \
257 sys_##_prefix##_##_name##_show, \
258 sys_##_prefix##_##_name##_store)
261 * ipl section
264 static __init enum ipl_type get_ipl_type(void)
266 if (!ipl_block_valid)
267 return IPL_TYPE_UNKNOWN;
269 switch (ipl_block.pb0_hdr.pbt) {
270 case IPL_PBT_CCW:
271 return IPL_TYPE_CCW;
272 case IPL_PBT_FCP:
273 if (ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
274 return IPL_TYPE_FCP_DUMP;
275 else
276 return IPL_TYPE_FCP;
277 case IPL_PBT_NVME:
278 if (ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
279 return IPL_TYPE_NVME_DUMP;
280 else
281 return IPL_TYPE_NVME;
283 return IPL_TYPE_UNKNOWN;
286 struct ipl_info ipl_info;
287 EXPORT_SYMBOL_GPL(ipl_info);
289 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
290 char *page)
292 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
295 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
297 static ssize_t ipl_secure_show(struct kobject *kobj,
298 struct kobj_attribute *attr, char *page)
300 return sprintf(page, "%i\n", !!ipl_secure_flag);
303 static struct kobj_attribute sys_ipl_secure_attr =
304 __ATTR(secure, 0444, ipl_secure_show, NULL);
306 static ssize_t ipl_has_secure_show(struct kobject *kobj,
307 struct kobj_attribute *attr, char *page)
309 return sprintf(page, "%i\n", !!sclp.has_sipl);
312 static struct kobj_attribute sys_ipl_has_secure_attr =
313 __ATTR(has_secure, 0444, ipl_has_secure_show, NULL);
315 static ssize_t ipl_vm_parm_show(struct kobject *kobj,
316 struct kobj_attribute *attr, char *page)
318 char parm[DIAG308_VMPARM_SIZE + 1] = {};
320 if (ipl_block_valid && (ipl_block.pb0_hdr.pbt == IPL_PBT_CCW))
321 ipl_block_get_ascii_vmparm(parm, sizeof(parm), &ipl_block);
322 return sprintf(page, "%s\n", parm);
325 static struct kobj_attribute sys_ipl_vm_parm_attr =
326 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL);
328 static ssize_t sys_ipl_device_show(struct kobject *kobj,
329 struct kobj_attribute *attr, char *page)
331 switch (ipl_info.type) {
332 case IPL_TYPE_CCW:
333 return sprintf(page, "0.%x.%04x\n", ipl_block.ccw.ssid,
334 ipl_block.ccw.devno);
335 case IPL_TYPE_FCP:
336 case IPL_TYPE_FCP_DUMP:
337 return sprintf(page, "0.0.%04x\n", ipl_block.fcp.devno);
338 case IPL_TYPE_NVME:
339 case IPL_TYPE_NVME_DUMP:
340 return sprintf(page, "%08ux\n", ipl_block.nvme.fid);
341 default:
342 return 0;
346 static struct kobj_attribute sys_ipl_device_attr =
347 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
349 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
350 struct bin_attribute *attr, char *buf,
351 loff_t off, size_t count)
353 return memory_read_from_buffer(buf, count, &off, &ipl_block,
354 ipl_block.hdr.len);
356 static struct bin_attribute ipl_parameter_attr =
357 __BIN_ATTR(binary_parameter, S_IRUGO, ipl_parameter_read, NULL,
358 PAGE_SIZE);
360 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
361 struct bin_attribute *attr, char *buf,
362 loff_t off, size_t count)
364 unsigned int size = ipl_block.fcp.scp_data_len;
365 void *scp_data = &ipl_block.fcp.scp_data;
367 return memory_read_from_buffer(buf, count, &off, scp_data, size);
370 static ssize_t ipl_nvme_scp_data_read(struct file *filp, struct kobject *kobj,
371 struct bin_attribute *attr, char *buf,
372 loff_t off, size_t count)
374 unsigned int size = ipl_block.nvme.scp_data_len;
375 void *scp_data = &ipl_block.nvme.scp_data;
377 return memory_read_from_buffer(buf, count, &off, scp_data, size);
380 static struct bin_attribute ipl_scp_data_attr =
381 __BIN_ATTR(scp_data, S_IRUGO, ipl_scp_data_read, NULL, PAGE_SIZE);
383 static struct bin_attribute ipl_nvme_scp_data_attr =
384 __BIN_ATTR(scp_data, S_IRUGO, ipl_nvme_scp_data_read, NULL, PAGE_SIZE);
386 static struct bin_attribute *ipl_fcp_bin_attrs[] = {
387 &ipl_parameter_attr,
388 &ipl_scp_data_attr,
389 NULL,
392 static struct bin_attribute *ipl_nvme_bin_attrs[] = {
393 &ipl_parameter_attr,
394 &ipl_nvme_scp_data_attr,
395 NULL,
398 /* FCP ipl device attributes */
400 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n",
401 (unsigned long long)ipl_block.fcp.wwpn);
402 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n",
403 (unsigned long long)ipl_block.fcp.lun);
404 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n",
405 (unsigned long long)ipl_block.fcp.bootprog);
406 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n",
407 (unsigned long long)ipl_block.fcp.br_lba);
409 /* NVMe ipl device attributes */
410 DEFINE_IPL_ATTR_RO(ipl_nvme, fid, "0x%08llx\n",
411 (unsigned long long)ipl_block.nvme.fid);
412 DEFINE_IPL_ATTR_RO(ipl_nvme, nsid, "0x%08llx\n",
413 (unsigned long long)ipl_block.nvme.nsid);
414 DEFINE_IPL_ATTR_RO(ipl_nvme, bootprog, "%lld\n",
415 (unsigned long long)ipl_block.nvme.bootprog);
416 DEFINE_IPL_ATTR_RO(ipl_nvme, br_lba, "%lld\n",
417 (unsigned long long)ipl_block.nvme.br_lba);
419 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
420 struct kobj_attribute *attr, char *page)
422 char loadparm[LOADPARM_LEN + 1] = {};
424 if (!sclp_ipl_info.is_valid)
425 return sprintf(page, "#unknown#\n");
426 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
427 EBCASC(loadparm, LOADPARM_LEN);
428 strim(loadparm);
429 return sprintf(page, "%s\n", loadparm);
432 static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
433 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);
435 static struct attribute *ipl_fcp_attrs[] = {
436 &sys_ipl_type_attr.attr,
437 &sys_ipl_device_attr.attr,
438 &sys_ipl_fcp_wwpn_attr.attr,
439 &sys_ipl_fcp_lun_attr.attr,
440 &sys_ipl_fcp_bootprog_attr.attr,
441 &sys_ipl_fcp_br_lba_attr.attr,
442 &sys_ipl_ccw_loadparm_attr.attr,
443 &sys_ipl_secure_attr.attr,
444 &sys_ipl_has_secure_attr.attr,
445 NULL,
448 static struct attribute_group ipl_fcp_attr_group = {
449 .attrs = ipl_fcp_attrs,
450 .bin_attrs = ipl_fcp_bin_attrs,
453 static struct attribute *ipl_nvme_attrs[] = {
454 &sys_ipl_type_attr.attr,
455 &sys_ipl_nvme_fid_attr.attr,
456 &sys_ipl_nvme_nsid_attr.attr,
457 &sys_ipl_nvme_bootprog_attr.attr,
458 &sys_ipl_nvme_br_lba_attr.attr,
459 &sys_ipl_ccw_loadparm_attr.attr,
460 &sys_ipl_secure_attr.attr,
461 &sys_ipl_has_secure_attr.attr,
462 NULL,
465 static struct attribute_group ipl_nvme_attr_group = {
466 .attrs = ipl_nvme_attrs,
467 .bin_attrs = ipl_nvme_bin_attrs,
471 /* CCW ipl device attributes */
473 static struct attribute *ipl_ccw_attrs_vm[] = {
474 &sys_ipl_type_attr.attr,
475 &sys_ipl_device_attr.attr,
476 &sys_ipl_ccw_loadparm_attr.attr,
477 &sys_ipl_vm_parm_attr.attr,
478 &sys_ipl_secure_attr.attr,
479 &sys_ipl_has_secure_attr.attr,
480 NULL,
483 static struct attribute *ipl_ccw_attrs_lpar[] = {
484 &sys_ipl_type_attr.attr,
485 &sys_ipl_device_attr.attr,
486 &sys_ipl_ccw_loadparm_attr.attr,
487 &sys_ipl_secure_attr.attr,
488 &sys_ipl_has_secure_attr.attr,
489 NULL,
492 static struct attribute_group ipl_ccw_attr_group_vm = {
493 .attrs = ipl_ccw_attrs_vm,
496 static struct attribute_group ipl_ccw_attr_group_lpar = {
497 .attrs = ipl_ccw_attrs_lpar
500 /* UNKNOWN ipl device attributes */
502 static struct attribute *ipl_unknown_attrs[] = {
503 &sys_ipl_type_attr.attr,
504 NULL,
507 static struct attribute_group ipl_unknown_attr_group = {
508 .attrs = ipl_unknown_attrs,
511 static struct kset *ipl_kset;
513 static void __ipl_run(void *unused)
515 __bpon();
516 diag308(DIAG308_LOAD_CLEAR, NULL);
519 static void ipl_run(struct shutdown_trigger *trigger)
521 smp_call_ipl_cpu(__ipl_run, NULL);
524 static int __init ipl_init(void)
526 int rc;
528 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
529 if (!ipl_kset) {
530 rc = -ENOMEM;
531 goto out;
533 switch (ipl_info.type) {
534 case IPL_TYPE_CCW:
535 if (MACHINE_IS_VM)
536 rc = sysfs_create_group(&ipl_kset->kobj,
537 &ipl_ccw_attr_group_vm);
538 else
539 rc = sysfs_create_group(&ipl_kset->kobj,
540 &ipl_ccw_attr_group_lpar);
541 break;
542 case IPL_TYPE_FCP:
543 case IPL_TYPE_FCP_DUMP:
544 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
545 break;
546 case IPL_TYPE_NVME:
547 case IPL_TYPE_NVME_DUMP:
548 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nvme_attr_group);
549 break;
550 default:
551 rc = sysfs_create_group(&ipl_kset->kobj,
552 &ipl_unknown_attr_group);
553 break;
555 out:
556 if (rc)
557 panic("ipl_init failed: rc = %i\n", rc);
559 return 0;
562 static struct shutdown_action __refdata ipl_action = {
563 .name = SHUTDOWN_ACTION_IPL_STR,
564 .fn = ipl_run,
565 .init = ipl_init,
569 * reipl shutdown action: Reboot Linux on shutdown.
572 /* VM IPL PARM attributes */
573 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb,
574 char *page)
576 char vmparm[DIAG308_VMPARM_SIZE + 1] = {};
578 ipl_block_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb);
579 return sprintf(page, "%s\n", vmparm);
582 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb,
583 size_t vmparm_max,
584 const char *buf, size_t len)
586 int i, ip_len;
588 /* ignore trailing newline */
589 ip_len = len;
590 if ((len > 0) && (buf[len - 1] == '\n'))
591 ip_len--;
593 if (ip_len > vmparm_max)
594 return -EINVAL;
596 /* parm is used to store kernel options, check for common chars */
597 for (i = 0; i < ip_len; i++)
598 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i])))
599 return -EINVAL;
601 memset(ipb->ccw.vm_parm, 0, DIAG308_VMPARM_SIZE);
602 ipb->ccw.vm_parm_len = ip_len;
603 if (ip_len > 0) {
604 ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
605 memcpy(ipb->ccw.vm_parm, buf, ip_len);
606 ASCEBC(ipb->ccw.vm_parm, ip_len);
607 } else {
608 ipb->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_VP;
611 return len;
614 /* NSS wrapper */
615 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj,
616 struct kobj_attribute *attr, char *page)
618 return reipl_generic_vmparm_show(reipl_block_nss, page);
621 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj,
622 struct kobj_attribute *attr,
623 const char *buf, size_t len)
625 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len);
628 /* CCW wrapper */
629 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj,
630 struct kobj_attribute *attr, char *page)
632 return reipl_generic_vmparm_show(reipl_block_ccw, page);
635 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj,
636 struct kobj_attribute *attr,
637 const char *buf, size_t len)
639 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len);
642 static struct kobj_attribute sys_reipl_nss_vmparm_attr =
643 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show,
644 reipl_nss_vmparm_store);
645 static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
646 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show,
647 reipl_ccw_vmparm_store);
649 /* FCP reipl device attributes */
651 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
652 struct bin_attribute *attr,
653 char *buf, loff_t off, size_t count)
655 size_t size = reipl_block_fcp->fcp.scp_data_len;
656 void *scp_data = reipl_block_fcp->fcp.scp_data;
658 return memory_read_from_buffer(buf, count, &off, scp_data, size);
661 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
662 struct bin_attribute *attr,
663 char *buf, loff_t off, size_t count)
665 size_t scpdata_len = count;
666 size_t padding;
669 if (off)
670 return -EINVAL;
672 memcpy(reipl_block_fcp->fcp.scp_data, buf, count);
673 if (scpdata_len % 8) {
674 padding = 8 - (scpdata_len % 8);
675 memset(reipl_block_fcp->fcp.scp_data + scpdata_len,
676 0, padding);
677 scpdata_len += padding;
680 reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
681 reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN + scpdata_len;
682 reipl_block_fcp->fcp.scp_data_len = scpdata_len;
684 return count;
686 static struct bin_attribute sys_reipl_fcp_scp_data_attr =
687 __BIN_ATTR(scp_data, (S_IRUGO | S_IWUSR), reipl_fcp_scpdata_read,
688 reipl_fcp_scpdata_write, DIAG308_SCPDATA_SIZE);
690 static struct bin_attribute *reipl_fcp_bin_attrs[] = {
691 &sys_reipl_fcp_scp_data_attr,
692 NULL,
695 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%llx\n",
696 reipl_block_fcp->fcp.wwpn);
697 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%llx\n",
698 reipl_block_fcp->fcp.lun);
699 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n",
700 reipl_block_fcp->fcp.bootprog);
701 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n",
702 reipl_block_fcp->fcp.br_lba);
703 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
704 reipl_block_fcp->fcp.devno);
706 static void reipl_get_ascii_loadparm(char *loadparm,
707 struct ipl_parameter_block *ibp)
709 memcpy(loadparm, ibp->common.loadparm, LOADPARM_LEN);
710 EBCASC(loadparm, LOADPARM_LEN);
711 loadparm[LOADPARM_LEN] = 0;
712 strim(loadparm);
715 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb,
716 char *page)
718 char buf[LOADPARM_LEN + 1];
720 reipl_get_ascii_loadparm(buf, ipb);
721 return sprintf(page, "%s\n", buf);
724 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb,
725 const char *buf, size_t len)
727 int i, lp_len;
729 /* ignore trailing newline */
730 lp_len = len;
731 if ((len > 0) && (buf[len - 1] == '\n'))
732 lp_len--;
733 /* loadparm can have max 8 characters and must not start with a blank */
734 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' ')))
735 return -EINVAL;
736 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */
737 for (i = 0; i < lp_len; i++) {
738 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') ||
739 (buf[i] == '.'))
740 continue;
741 return -EINVAL;
743 /* initialize loadparm with blanks */
744 memset(ipb->common.loadparm, ' ', LOADPARM_LEN);
745 /* copy and convert to ebcdic */
746 memcpy(ipb->common.loadparm, buf, lp_len);
747 ASCEBC(ipb->common.loadparm, LOADPARM_LEN);
748 ipb->common.flags |= IPL_PB0_FLAG_LOADPARM;
749 return len;
752 /* FCP wrapper */
753 static ssize_t reipl_fcp_loadparm_show(struct kobject *kobj,
754 struct kobj_attribute *attr, char *page)
756 return reipl_generic_loadparm_show(reipl_block_fcp, page);
759 static ssize_t reipl_fcp_loadparm_store(struct kobject *kobj,
760 struct kobj_attribute *attr,
761 const char *buf, size_t len)
763 return reipl_generic_loadparm_store(reipl_block_fcp, buf, len);
766 static struct kobj_attribute sys_reipl_fcp_loadparm_attr =
767 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_fcp_loadparm_show,
768 reipl_fcp_loadparm_store);
770 static ssize_t reipl_fcp_clear_show(struct kobject *kobj,
771 struct kobj_attribute *attr, char *page)
773 return sprintf(page, "%u\n", reipl_fcp_clear);
776 static ssize_t reipl_fcp_clear_store(struct kobject *kobj,
777 struct kobj_attribute *attr,
778 const char *buf, size_t len)
780 if (strtobool(buf, &reipl_fcp_clear) < 0)
781 return -EINVAL;
782 return len;
785 static struct attribute *reipl_fcp_attrs[] = {
786 &sys_reipl_fcp_device_attr.attr,
787 &sys_reipl_fcp_wwpn_attr.attr,
788 &sys_reipl_fcp_lun_attr.attr,
789 &sys_reipl_fcp_bootprog_attr.attr,
790 &sys_reipl_fcp_br_lba_attr.attr,
791 &sys_reipl_fcp_loadparm_attr.attr,
792 NULL,
795 static struct attribute_group reipl_fcp_attr_group = {
796 .attrs = reipl_fcp_attrs,
797 .bin_attrs = reipl_fcp_bin_attrs,
800 static struct kobj_attribute sys_reipl_fcp_clear_attr =
801 __ATTR(clear, 0644, reipl_fcp_clear_show, reipl_fcp_clear_store);
803 /* NVME reipl device attributes */
805 static ssize_t reipl_nvme_scpdata_read(struct file *filp, struct kobject *kobj,
806 struct bin_attribute *attr,
807 char *buf, loff_t off, size_t count)
809 size_t size = reipl_block_nvme->nvme.scp_data_len;
810 void *scp_data = reipl_block_nvme->nvme.scp_data;
812 return memory_read_from_buffer(buf, count, &off, scp_data, size);
815 static ssize_t reipl_nvme_scpdata_write(struct file *filp, struct kobject *kobj,
816 struct bin_attribute *attr,
817 char *buf, loff_t off, size_t count)
819 size_t scpdata_len = count;
820 size_t padding;
822 if (off)
823 return -EINVAL;
825 memcpy(reipl_block_nvme->nvme.scp_data, buf, count);
826 if (scpdata_len % 8) {
827 padding = 8 - (scpdata_len % 8);
828 memset(reipl_block_nvme->nvme.scp_data + scpdata_len,
829 0, padding);
830 scpdata_len += padding;
833 reipl_block_nvme->hdr.len = IPL_BP_FCP_LEN + scpdata_len;
834 reipl_block_nvme->nvme.len = IPL_BP0_FCP_LEN + scpdata_len;
835 reipl_block_nvme->nvme.scp_data_len = scpdata_len;
837 return count;
840 static struct bin_attribute sys_reipl_nvme_scp_data_attr =
841 __BIN_ATTR(scp_data, (S_IRUGO | S_IWUSR), reipl_nvme_scpdata_read,
842 reipl_nvme_scpdata_write, DIAG308_SCPDATA_SIZE);
844 static struct bin_attribute *reipl_nvme_bin_attrs[] = {
845 &sys_reipl_nvme_scp_data_attr,
846 NULL,
849 DEFINE_IPL_ATTR_RW(reipl_nvme, fid, "0x%08llx\n", "%llx\n",
850 reipl_block_nvme->nvme.fid);
851 DEFINE_IPL_ATTR_RW(reipl_nvme, nsid, "0x%08llx\n", "%llx\n",
852 reipl_block_nvme->nvme.nsid);
853 DEFINE_IPL_ATTR_RW(reipl_nvme, bootprog, "%lld\n", "%lld\n",
854 reipl_block_nvme->nvme.bootprog);
855 DEFINE_IPL_ATTR_RW(reipl_nvme, br_lba, "%lld\n", "%lld\n",
856 reipl_block_nvme->nvme.br_lba);
858 /* nvme wrapper */
859 static ssize_t reipl_nvme_loadparm_show(struct kobject *kobj,
860 struct kobj_attribute *attr, char *page)
862 return reipl_generic_loadparm_show(reipl_block_nvme, page);
865 static ssize_t reipl_nvme_loadparm_store(struct kobject *kobj,
866 struct kobj_attribute *attr,
867 const char *buf, size_t len)
869 return reipl_generic_loadparm_store(reipl_block_nvme, buf, len);
872 static struct kobj_attribute sys_reipl_nvme_loadparm_attr =
873 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nvme_loadparm_show,
874 reipl_nvme_loadparm_store);
876 static struct attribute *reipl_nvme_attrs[] = {
877 &sys_reipl_nvme_fid_attr.attr,
878 &sys_reipl_nvme_nsid_attr.attr,
879 &sys_reipl_nvme_bootprog_attr.attr,
880 &sys_reipl_nvme_br_lba_attr.attr,
881 &sys_reipl_nvme_loadparm_attr.attr,
882 NULL,
885 static struct attribute_group reipl_nvme_attr_group = {
886 .attrs = reipl_nvme_attrs,
887 .bin_attrs = reipl_nvme_bin_attrs
890 static ssize_t reipl_nvme_clear_show(struct kobject *kobj,
891 struct kobj_attribute *attr, char *page)
893 return sprintf(page, "%u\n", reipl_nvme_clear);
896 static ssize_t reipl_nvme_clear_store(struct kobject *kobj,
897 struct kobj_attribute *attr,
898 const char *buf, size_t len)
900 if (strtobool(buf, &reipl_nvme_clear) < 0)
901 return -EINVAL;
902 return len;
905 static struct kobj_attribute sys_reipl_nvme_clear_attr =
906 __ATTR(clear, 0644, reipl_nvme_clear_show, reipl_nvme_clear_store);
908 /* CCW reipl device attributes */
909 DEFINE_IPL_CCW_ATTR_RW(reipl_ccw, device, reipl_block_ccw->ccw);
911 /* NSS wrapper */
912 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj,
913 struct kobj_attribute *attr, char *page)
915 return reipl_generic_loadparm_show(reipl_block_nss, page);
918 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj,
919 struct kobj_attribute *attr,
920 const char *buf, size_t len)
922 return reipl_generic_loadparm_store(reipl_block_nss, buf, len);
925 /* CCW wrapper */
926 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
927 struct kobj_attribute *attr, char *page)
929 return reipl_generic_loadparm_show(reipl_block_ccw, page);
932 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
933 struct kobj_attribute *attr,
934 const char *buf, size_t len)
936 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len);
939 static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
940 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show,
941 reipl_ccw_loadparm_store);
943 static ssize_t reipl_ccw_clear_show(struct kobject *kobj,
944 struct kobj_attribute *attr, char *page)
946 return sprintf(page, "%u\n", reipl_ccw_clear);
949 static ssize_t reipl_ccw_clear_store(struct kobject *kobj,
950 struct kobj_attribute *attr,
951 const char *buf, size_t len)
953 if (strtobool(buf, &reipl_ccw_clear) < 0)
954 return -EINVAL;
955 return len;
958 static struct kobj_attribute sys_reipl_ccw_clear_attr =
959 __ATTR(clear, 0644, reipl_ccw_clear_show, reipl_ccw_clear_store);
961 static struct attribute *reipl_ccw_attrs_vm[] = {
962 &sys_reipl_ccw_device_attr.attr,
963 &sys_reipl_ccw_loadparm_attr.attr,
964 &sys_reipl_ccw_vmparm_attr.attr,
965 &sys_reipl_ccw_clear_attr.attr,
966 NULL,
969 static struct attribute *reipl_ccw_attrs_lpar[] = {
970 &sys_reipl_ccw_device_attr.attr,
971 &sys_reipl_ccw_loadparm_attr.attr,
972 &sys_reipl_ccw_clear_attr.attr,
973 NULL,
976 static struct attribute_group reipl_ccw_attr_group_vm = {
977 .name = IPL_CCW_STR,
978 .attrs = reipl_ccw_attrs_vm,
981 static struct attribute_group reipl_ccw_attr_group_lpar = {
982 .name = IPL_CCW_STR,
983 .attrs = reipl_ccw_attrs_lpar,
987 /* NSS reipl device attributes */
988 static void reipl_get_ascii_nss_name(char *dst,
989 struct ipl_parameter_block *ipb)
991 memcpy(dst, ipb->ccw.nss_name, NSS_NAME_SIZE);
992 EBCASC(dst, NSS_NAME_SIZE);
993 dst[NSS_NAME_SIZE] = 0;
996 static ssize_t reipl_nss_name_show(struct kobject *kobj,
997 struct kobj_attribute *attr, char *page)
999 char nss_name[NSS_NAME_SIZE + 1] = {};
1001 reipl_get_ascii_nss_name(nss_name, reipl_block_nss);
1002 return sprintf(page, "%s\n", nss_name);
1005 static ssize_t reipl_nss_name_store(struct kobject *kobj,
1006 struct kobj_attribute *attr,
1007 const char *buf, size_t len)
1009 int nss_len;
1011 /* ignore trailing newline */
1012 nss_len = len;
1013 if ((len > 0) && (buf[len - 1] == '\n'))
1014 nss_len--;
1016 if (nss_len > NSS_NAME_SIZE)
1017 return -EINVAL;
1019 memset(reipl_block_nss->ccw.nss_name, 0x40, NSS_NAME_SIZE);
1020 if (nss_len > 0) {
1021 reipl_block_nss->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_NSS;
1022 memcpy(reipl_block_nss->ccw.nss_name, buf, nss_len);
1023 ASCEBC(reipl_block_nss->ccw.nss_name, nss_len);
1024 EBC_TOUPPER(reipl_block_nss->ccw.nss_name, nss_len);
1025 } else {
1026 reipl_block_nss->ccw.vm_flags &= ~IPL_PB0_CCW_VM_FLAG_NSS;
1029 return len;
1032 static struct kobj_attribute sys_reipl_nss_name_attr =
1033 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show,
1034 reipl_nss_name_store);
1036 static struct kobj_attribute sys_reipl_nss_loadparm_attr =
1037 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show,
1038 reipl_nss_loadparm_store);
1040 static struct attribute *reipl_nss_attrs[] = {
1041 &sys_reipl_nss_name_attr.attr,
1042 &sys_reipl_nss_loadparm_attr.attr,
1043 &sys_reipl_nss_vmparm_attr.attr,
1044 NULL,
1047 static struct attribute_group reipl_nss_attr_group = {
1048 .name = IPL_NSS_STR,
1049 .attrs = reipl_nss_attrs,
1052 void set_os_info_reipl_block(void)
1054 os_info_entry_add(OS_INFO_REIPL_BLOCK, reipl_block_actual,
1055 reipl_block_actual->hdr.len);
1058 /* reipl type */
1060 static int reipl_set_type(enum ipl_type type)
1062 if (!(reipl_capabilities & type))
1063 return -EINVAL;
1065 switch(type) {
1066 case IPL_TYPE_CCW:
1067 reipl_block_actual = reipl_block_ccw;
1068 break;
1069 case IPL_TYPE_FCP:
1070 reipl_block_actual = reipl_block_fcp;
1071 break;
1072 case IPL_TYPE_NVME:
1073 reipl_block_actual = reipl_block_nvme;
1074 break;
1075 case IPL_TYPE_NSS:
1076 reipl_block_actual = reipl_block_nss;
1077 break;
1078 default:
1079 break;
1081 reipl_type = type;
1082 return 0;
1085 static ssize_t reipl_type_show(struct kobject *kobj,
1086 struct kobj_attribute *attr, char *page)
1088 return sprintf(page, "%s\n", ipl_type_str(reipl_type));
1091 static ssize_t reipl_type_store(struct kobject *kobj,
1092 struct kobj_attribute *attr,
1093 const char *buf, size_t len)
1095 int rc = -EINVAL;
1097 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0)
1098 rc = reipl_set_type(IPL_TYPE_CCW);
1099 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0)
1100 rc = reipl_set_type(IPL_TYPE_FCP);
1101 else if (strncmp(buf, IPL_NVME_STR, strlen(IPL_NVME_STR)) == 0)
1102 rc = reipl_set_type(IPL_TYPE_NVME);
1103 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0)
1104 rc = reipl_set_type(IPL_TYPE_NSS);
1105 return (rc != 0) ? rc : len;
1108 static struct kobj_attribute reipl_type_attr =
1109 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);
1111 static struct kset *reipl_kset;
1112 static struct kset *reipl_fcp_kset;
1113 static struct kset *reipl_nvme_kset;
1115 static void __reipl_run(void *unused)
1117 switch (reipl_type) {
1118 case IPL_TYPE_CCW:
1119 diag308(DIAG308_SET, reipl_block_ccw);
1120 if (reipl_ccw_clear)
1121 diag308(DIAG308_LOAD_CLEAR, NULL);
1122 else
1123 diag308(DIAG308_LOAD_NORMAL_DUMP, NULL);
1124 break;
1125 case IPL_TYPE_FCP:
1126 diag308(DIAG308_SET, reipl_block_fcp);
1127 if (reipl_fcp_clear)
1128 diag308(DIAG308_LOAD_CLEAR, NULL);
1129 else
1130 diag308(DIAG308_LOAD_NORMAL, NULL);
1131 break;
1132 case IPL_TYPE_NVME:
1133 diag308(DIAG308_SET, reipl_block_nvme);
1134 if (reipl_nvme_clear)
1135 diag308(DIAG308_LOAD_CLEAR, NULL);
1136 else
1137 diag308(DIAG308_LOAD_NORMAL, NULL);
1138 break;
1139 case IPL_TYPE_NSS:
1140 diag308(DIAG308_SET, reipl_block_nss);
1141 diag308(DIAG308_LOAD_CLEAR, NULL);
1142 break;
1143 case IPL_TYPE_UNKNOWN:
1144 diag308(DIAG308_LOAD_CLEAR, NULL);
1145 break;
1146 case IPL_TYPE_FCP_DUMP:
1147 case IPL_TYPE_NVME_DUMP:
1148 break;
1150 disabled_wait();
1153 static void reipl_run(struct shutdown_trigger *trigger)
1155 smp_call_ipl_cpu(__reipl_run, NULL);
1158 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb)
1160 ipb->hdr.len = IPL_BP_CCW_LEN;
1161 ipb->hdr.version = IPL_PARM_BLOCK_VERSION;
1162 ipb->pb0_hdr.len = IPL_BP0_CCW_LEN;
1163 ipb->pb0_hdr.pbt = IPL_PBT_CCW;
1166 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb)
1168 /* LOADPARM */
1169 /* check if read scp info worked and set loadparm */
1170 if (sclp_ipl_info.is_valid)
1171 memcpy(ipb->ccw.loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN);
1172 else
1173 /* read scp info failed: set empty loadparm (EBCDIC blanks) */
1174 memset(ipb->ccw.loadparm, 0x40, LOADPARM_LEN);
1175 ipb->ccw.flags = IPL_PB0_FLAG_LOADPARM;
1177 /* VM PARM */
1178 if (MACHINE_IS_VM && ipl_block_valid &&
1179 (ipl_block.ccw.vm_flags & IPL_PB0_CCW_VM_FLAG_VP)) {
1181 ipb->ccw.vm_flags |= IPL_PB0_CCW_VM_FLAG_VP;
1182 ipb->ccw.vm_parm_len = ipl_block.ccw.vm_parm_len;
1183 memcpy(ipb->ccw.vm_parm,
1184 ipl_block.ccw.vm_parm, DIAG308_VMPARM_SIZE);
1188 static int __init reipl_nss_init(void)
1190 int rc;
1192 if (!MACHINE_IS_VM)
1193 return 0;
1195 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL);
1196 if (!reipl_block_nss)
1197 return -ENOMEM;
1199 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
1200 if (rc)
1201 return rc;
1203 reipl_block_ccw_init(reipl_block_nss);
1204 reipl_capabilities |= IPL_TYPE_NSS;
1205 return 0;
1208 static int __init reipl_ccw_init(void)
1210 int rc;
1212 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1213 if (!reipl_block_ccw)
1214 return -ENOMEM;
1216 rc = sysfs_create_group(&reipl_kset->kobj,
1217 MACHINE_IS_VM ? &reipl_ccw_attr_group_vm
1218 : &reipl_ccw_attr_group_lpar);
1219 if (rc)
1220 return rc;
1222 reipl_block_ccw_init(reipl_block_ccw);
1223 if (ipl_info.type == IPL_TYPE_CCW) {
1224 reipl_block_ccw->ccw.ssid = ipl_block.ccw.ssid;
1225 reipl_block_ccw->ccw.devno = ipl_block.ccw.devno;
1226 reipl_block_ccw_fill_parms(reipl_block_ccw);
1229 reipl_capabilities |= IPL_TYPE_CCW;
1230 return 0;
1233 static int __init reipl_fcp_init(void)
1235 int rc;
1237 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1238 if (!reipl_block_fcp)
1239 return -ENOMEM;
1241 /* sysfs: create fcp kset for mixing attr group and bin attrs */
1242 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL,
1243 &reipl_kset->kobj);
1244 if (!reipl_fcp_kset) {
1245 free_page((unsigned long) reipl_block_fcp);
1246 return -ENOMEM;
1249 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1250 if (rc)
1251 goto out1;
1253 if (test_facility(141)) {
1254 rc = sysfs_create_file(&reipl_fcp_kset->kobj,
1255 &sys_reipl_fcp_clear_attr.attr);
1256 if (rc)
1257 goto out2;
1258 } else {
1259 reipl_fcp_clear = true;
1262 if (ipl_info.type == IPL_TYPE_FCP) {
1263 memcpy(reipl_block_fcp, &ipl_block, sizeof(ipl_block));
1265 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1266 * is invalid in the SCSI IPL parameter block, so take it
1267 * always from sclp_ipl_info.
1269 memcpy(reipl_block_fcp->fcp.loadparm, sclp_ipl_info.loadparm,
1270 LOADPARM_LEN);
1271 } else {
1272 reipl_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1273 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1274 reipl_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1275 reipl_block_fcp->fcp.pbt = IPL_PBT_FCP;
1276 reipl_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_IPL;
1278 reipl_capabilities |= IPL_TYPE_FCP;
1279 return 0;
1281 out2:
1282 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group);
1283 out1:
1284 kset_unregister(reipl_fcp_kset);
1285 free_page((unsigned long) reipl_block_fcp);
1286 return rc;
1289 static int __init reipl_nvme_init(void)
1291 int rc;
1293 reipl_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1294 if (!reipl_block_nvme)
1295 return -ENOMEM;
1297 /* sysfs: create kset for mixing attr group and bin attrs */
1298 reipl_nvme_kset = kset_create_and_add(IPL_NVME_STR, NULL,
1299 &reipl_kset->kobj);
1300 if (!reipl_nvme_kset) {
1301 free_page((unsigned long) reipl_block_nvme);
1302 return -ENOMEM;
1305 rc = sysfs_create_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1306 if (rc)
1307 goto out1;
1309 if (test_facility(141)) {
1310 rc = sysfs_create_file(&reipl_nvme_kset->kobj,
1311 &sys_reipl_nvme_clear_attr.attr);
1312 if (rc)
1313 goto out2;
1314 } else {
1315 reipl_nvme_clear = true;
1318 if (ipl_info.type == IPL_TYPE_NVME) {
1319 memcpy(reipl_block_nvme, &ipl_block, sizeof(ipl_block));
1321 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1322 * is invalid in the IPL parameter block, so take it
1323 * always from sclp_ipl_info.
1325 memcpy(reipl_block_nvme->nvme.loadparm, sclp_ipl_info.loadparm,
1326 LOADPARM_LEN);
1327 } else {
1328 reipl_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1329 reipl_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1330 reipl_block_nvme->nvme.len = IPL_BP0_NVME_LEN;
1331 reipl_block_nvme->nvme.pbt = IPL_PBT_NVME;
1332 reipl_block_nvme->nvme.opt = IPL_PB0_NVME_OPT_IPL;
1334 reipl_capabilities |= IPL_TYPE_NVME;
1335 return 0;
1337 out2:
1338 sysfs_remove_group(&reipl_nvme_kset->kobj, &reipl_nvme_attr_group);
1339 out1:
1340 kset_unregister(reipl_nvme_kset);
1341 free_page((unsigned long) reipl_block_nvme);
1342 return rc;
1345 static int __init reipl_type_init(void)
1347 enum ipl_type reipl_type = ipl_info.type;
1348 struct ipl_parameter_block *reipl_block;
1349 unsigned long size;
1351 reipl_block = os_info_old_entry(OS_INFO_REIPL_BLOCK, &size);
1352 if (!reipl_block)
1353 goto out;
1355 * If we have an OS info reipl block, this will be used
1357 if (reipl_block->pb0_hdr.pbt == IPL_PBT_FCP) {
1358 memcpy(reipl_block_fcp, reipl_block, size);
1359 reipl_type = IPL_TYPE_FCP;
1360 } else if (reipl_block->pb0_hdr.pbt == IPL_PBT_NVME) {
1361 memcpy(reipl_block_nvme, reipl_block, size);
1362 reipl_type = IPL_TYPE_NVME;
1363 } else if (reipl_block->pb0_hdr.pbt == IPL_PBT_CCW) {
1364 memcpy(reipl_block_ccw, reipl_block, size);
1365 reipl_type = IPL_TYPE_CCW;
1367 out:
1368 return reipl_set_type(reipl_type);
1371 static int __init reipl_init(void)
1373 int rc;
1375 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
1376 if (!reipl_kset)
1377 return -ENOMEM;
1378 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
1379 if (rc) {
1380 kset_unregister(reipl_kset);
1381 return rc;
1383 rc = reipl_ccw_init();
1384 if (rc)
1385 return rc;
1386 rc = reipl_fcp_init();
1387 if (rc)
1388 return rc;
1389 rc = reipl_nvme_init();
1390 if (rc)
1391 return rc;
1392 rc = reipl_nss_init();
1393 if (rc)
1394 return rc;
1395 return reipl_type_init();
1398 static struct shutdown_action __refdata reipl_action = {
1399 .name = SHUTDOWN_ACTION_REIPL_STR,
1400 .fn = reipl_run,
1401 .init = reipl_init,
1405 * dump shutdown action: Dump Linux on shutdown.
1408 /* FCP dump device attributes */
1410 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%llx\n",
1411 dump_block_fcp->fcp.wwpn);
1412 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%llx\n",
1413 dump_block_fcp->fcp.lun);
1414 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n",
1415 dump_block_fcp->fcp.bootprog);
1416 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n",
1417 dump_block_fcp->fcp.br_lba);
1418 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n",
1419 dump_block_fcp->fcp.devno);
1421 static struct attribute *dump_fcp_attrs[] = {
1422 &sys_dump_fcp_device_attr.attr,
1423 &sys_dump_fcp_wwpn_attr.attr,
1424 &sys_dump_fcp_lun_attr.attr,
1425 &sys_dump_fcp_bootprog_attr.attr,
1426 &sys_dump_fcp_br_lba_attr.attr,
1427 NULL,
1430 static struct attribute_group dump_fcp_attr_group = {
1431 .name = IPL_FCP_STR,
1432 .attrs = dump_fcp_attrs,
1435 /* NVME dump device attributes */
1436 DEFINE_IPL_ATTR_RW(dump_nvme, fid, "0x%08llx\n", "%llx\n",
1437 dump_block_nvme->nvme.fid);
1438 DEFINE_IPL_ATTR_RW(dump_nvme, nsid, "0x%08llx\n", "%llx\n",
1439 dump_block_nvme->nvme.nsid);
1440 DEFINE_IPL_ATTR_RW(dump_nvme, bootprog, "%lld\n", "%llx\n",
1441 dump_block_nvme->nvme.bootprog);
1442 DEFINE_IPL_ATTR_RW(dump_nvme, br_lba, "%lld\n", "%llx\n",
1443 dump_block_nvme->nvme.br_lba);
1445 static struct attribute *dump_nvme_attrs[] = {
1446 &sys_dump_nvme_fid_attr.attr,
1447 &sys_dump_nvme_nsid_attr.attr,
1448 &sys_dump_nvme_bootprog_attr.attr,
1449 &sys_dump_nvme_br_lba_attr.attr,
1450 NULL,
1453 static struct attribute_group dump_nvme_attr_group = {
1454 .name = IPL_NVME_STR,
1455 .attrs = dump_nvme_attrs,
1458 /* CCW dump device attributes */
1459 DEFINE_IPL_CCW_ATTR_RW(dump_ccw, device, dump_block_ccw->ccw);
1461 static struct attribute *dump_ccw_attrs[] = {
1462 &sys_dump_ccw_device_attr.attr,
1463 NULL,
1466 static struct attribute_group dump_ccw_attr_group = {
1467 .name = IPL_CCW_STR,
1468 .attrs = dump_ccw_attrs,
1471 /* dump type */
1473 static int dump_set_type(enum dump_type type)
1475 if (!(dump_capabilities & type))
1476 return -EINVAL;
1477 dump_type = type;
1478 return 0;
1481 static ssize_t dump_type_show(struct kobject *kobj,
1482 struct kobj_attribute *attr, char *page)
1484 return sprintf(page, "%s\n", dump_type_str(dump_type));
1487 static ssize_t dump_type_store(struct kobject *kobj,
1488 struct kobj_attribute *attr,
1489 const char *buf, size_t len)
1491 int rc = -EINVAL;
1493 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0)
1494 rc = dump_set_type(DUMP_TYPE_NONE);
1495 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0)
1496 rc = dump_set_type(DUMP_TYPE_CCW);
1497 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0)
1498 rc = dump_set_type(DUMP_TYPE_FCP);
1499 else if (strncmp(buf, DUMP_NVME_STR, strlen(DUMP_NVME_STR)) == 0)
1500 rc = dump_set_type(DUMP_TYPE_NVME);
1501 return (rc != 0) ? rc : len;
1504 static struct kobj_attribute dump_type_attr =
1505 __ATTR(dump_type, 0644, dump_type_show, dump_type_store);
1507 static struct kset *dump_kset;
1509 static void diag308_dump(void *dump_block)
1511 diag308(DIAG308_SET, dump_block);
1512 while (1) {
1513 if (diag308(DIAG308_LOAD_NORMAL_DUMP, NULL) != 0x302)
1514 break;
1515 udelay(USEC_PER_SEC);
1519 static void __dump_run(void *unused)
1521 switch (dump_type) {
1522 case DUMP_TYPE_CCW:
1523 diag308_dump(dump_block_ccw);
1524 break;
1525 case DUMP_TYPE_FCP:
1526 diag308_dump(dump_block_fcp);
1527 break;
1528 case DUMP_TYPE_NVME:
1529 diag308_dump(dump_block_nvme);
1530 break;
1531 default:
1532 break;
1536 static void dump_run(struct shutdown_trigger *trigger)
1538 if (dump_type == DUMP_TYPE_NONE)
1539 return;
1540 smp_send_stop();
1541 smp_call_ipl_cpu(__dump_run, NULL);
1544 static int __init dump_ccw_init(void)
1546 int rc;
1548 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
1549 if (!dump_block_ccw)
1550 return -ENOMEM;
1551 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
1552 if (rc) {
1553 free_page((unsigned long)dump_block_ccw);
1554 return rc;
1556 dump_block_ccw->hdr.len = IPL_BP_CCW_LEN;
1557 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION;
1558 dump_block_ccw->ccw.len = IPL_BP0_CCW_LEN;
1559 dump_block_ccw->ccw.pbt = IPL_PBT_CCW;
1560 dump_capabilities |= DUMP_TYPE_CCW;
1561 return 0;
1564 static int __init dump_fcp_init(void)
1566 int rc;
1568 if (!sclp_ipl_info.has_dump)
1569 return 0; /* LDIPL DUMP is not installed */
1570 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
1571 if (!dump_block_fcp)
1572 return -ENOMEM;
1573 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
1574 if (rc) {
1575 free_page((unsigned long)dump_block_fcp);
1576 return rc;
1578 dump_block_fcp->hdr.len = IPL_BP_FCP_LEN;
1579 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION;
1580 dump_block_fcp->fcp.len = IPL_BP0_FCP_LEN;
1581 dump_block_fcp->fcp.pbt = IPL_PBT_FCP;
1582 dump_block_fcp->fcp.opt = IPL_PB0_FCP_OPT_DUMP;
1583 dump_capabilities |= DUMP_TYPE_FCP;
1584 return 0;
1587 static int __init dump_nvme_init(void)
1589 int rc;
1591 if (!sclp_ipl_info.has_dump)
1592 return 0; /* LDIPL DUMP is not installed */
1593 dump_block_nvme = (void *) get_zeroed_page(GFP_KERNEL);
1594 if (!dump_block_nvme)
1595 return -ENOMEM;
1596 rc = sysfs_create_group(&dump_kset->kobj, &dump_nvme_attr_group);
1597 if (rc) {
1598 free_page((unsigned long)dump_block_nvme);
1599 return rc;
1601 dump_block_nvme->hdr.len = IPL_BP_NVME_LEN;
1602 dump_block_nvme->hdr.version = IPL_PARM_BLOCK_VERSION;
1603 dump_block_nvme->fcp.len = IPL_BP0_NVME_LEN;
1604 dump_block_nvme->fcp.pbt = IPL_PBT_NVME;
1605 dump_block_nvme->fcp.opt = IPL_PB0_NVME_OPT_DUMP;
1606 dump_capabilities |= DUMP_TYPE_NVME;
1607 return 0;
1610 static int __init dump_init(void)
1612 int rc;
1614 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
1615 if (!dump_kset)
1616 return -ENOMEM;
1617 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr);
1618 if (rc) {
1619 kset_unregister(dump_kset);
1620 return rc;
1622 rc = dump_ccw_init();
1623 if (rc)
1624 return rc;
1625 rc = dump_fcp_init();
1626 if (rc)
1627 return rc;
1628 rc = dump_nvme_init();
1629 if (rc)
1630 return rc;
1631 dump_set_type(DUMP_TYPE_NONE);
1632 return 0;
1635 static struct shutdown_action __refdata dump_action = {
1636 .name = SHUTDOWN_ACTION_DUMP_STR,
1637 .fn = dump_run,
1638 .init = dump_init,
1641 static void dump_reipl_run(struct shutdown_trigger *trigger)
1643 unsigned long ipib = (unsigned long) reipl_block_actual;
1644 unsigned int csum;
1646 csum = (__force unsigned int)
1647 csum_partial(reipl_block_actual, reipl_block_actual->hdr.len, 0);
1648 mem_assign_absolute(S390_lowcore.ipib, ipib);
1649 mem_assign_absolute(S390_lowcore.ipib_checksum, csum);
1650 dump_run(trigger);
1653 static struct shutdown_action __refdata dump_reipl_action = {
1654 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR,
1655 .fn = dump_reipl_run,
1659 * vmcmd shutdown action: Trigger vm command on shutdown.
1662 static char vmcmd_on_reboot[128];
1663 static char vmcmd_on_panic[128];
1664 static char vmcmd_on_halt[128];
1665 static char vmcmd_on_poff[128];
1666 static char vmcmd_on_restart[128];
1668 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot);
1669 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic);
1670 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt);
1671 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff);
1672 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart);
1674 static struct attribute *vmcmd_attrs[] = {
1675 &sys_vmcmd_on_reboot_attr.attr,
1676 &sys_vmcmd_on_panic_attr.attr,
1677 &sys_vmcmd_on_halt_attr.attr,
1678 &sys_vmcmd_on_poff_attr.attr,
1679 &sys_vmcmd_on_restart_attr.attr,
1680 NULL,
1683 static struct attribute_group vmcmd_attr_group = {
1684 .attrs = vmcmd_attrs,
1687 static struct kset *vmcmd_kset;
1689 static void vmcmd_run(struct shutdown_trigger *trigger)
1691 char *cmd;
1693 if (strcmp(trigger->name, ON_REIPL_STR) == 0)
1694 cmd = vmcmd_on_reboot;
1695 else if (strcmp(trigger->name, ON_PANIC_STR) == 0)
1696 cmd = vmcmd_on_panic;
1697 else if (strcmp(trigger->name, ON_HALT_STR) == 0)
1698 cmd = vmcmd_on_halt;
1699 else if (strcmp(trigger->name, ON_POFF_STR) == 0)
1700 cmd = vmcmd_on_poff;
1701 else if (strcmp(trigger->name, ON_RESTART_STR) == 0)
1702 cmd = vmcmd_on_restart;
1703 else
1704 return;
1706 if (strlen(cmd) == 0)
1707 return;
1708 __cpcmd(cmd, NULL, 0, NULL);
1711 static int vmcmd_init(void)
1713 if (!MACHINE_IS_VM)
1714 return -EOPNOTSUPP;
1715 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj);
1716 if (!vmcmd_kset)
1717 return -ENOMEM;
1718 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group);
1721 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR,
1722 vmcmd_run, vmcmd_init};
1725 * stop shutdown action: Stop Linux on shutdown.
1728 static void stop_run(struct shutdown_trigger *trigger)
1730 if (strcmp(trigger->name, ON_PANIC_STR) == 0 ||
1731 strcmp(trigger->name, ON_RESTART_STR) == 0)
1732 disabled_wait();
1733 smp_stop_cpu();
1736 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR,
1737 stop_run, NULL};
1739 /* action list */
1741 static struct shutdown_action *shutdown_actions_list[] = {
1742 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action,
1743 &vmcmd_action, &stop_action};
1744 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *))
1747 * Trigger section
1750 static struct kset *shutdown_actions_kset;
1752 static int set_trigger(const char *buf, struct shutdown_trigger *trigger,
1753 size_t len)
1755 int i;
1757 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1758 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) {
1759 if (shutdown_actions_list[i]->init_rc) {
1760 return shutdown_actions_list[i]->init_rc;
1761 } else {
1762 trigger->action = shutdown_actions_list[i];
1763 return len;
1767 return -EINVAL;
1770 /* on reipl */
1772 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR,
1773 &reipl_action};
1775 static ssize_t on_reboot_show(struct kobject *kobj,
1776 struct kobj_attribute *attr, char *page)
1778 return sprintf(page, "%s\n", on_reboot_trigger.action->name);
1781 static ssize_t on_reboot_store(struct kobject *kobj,
1782 struct kobj_attribute *attr,
1783 const char *buf, size_t len)
1785 return set_trigger(buf, &on_reboot_trigger, len);
1787 static struct kobj_attribute on_reboot_attr = __ATTR_RW(on_reboot);
1789 static void do_machine_restart(char *__unused)
1791 smp_send_stop();
1792 on_reboot_trigger.action->fn(&on_reboot_trigger);
1793 reipl_run(NULL);
1795 void (*_machine_restart)(char *command) = do_machine_restart;
1797 /* on panic */
1799 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action};
1801 static ssize_t on_panic_show(struct kobject *kobj,
1802 struct kobj_attribute *attr, char *page)
1804 return sprintf(page, "%s\n", on_panic_trigger.action->name);
1807 static ssize_t on_panic_store(struct kobject *kobj,
1808 struct kobj_attribute *attr,
1809 const char *buf, size_t len)
1811 return set_trigger(buf, &on_panic_trigger, len);
1813 static struct kobj_attribute on_panic_attr = __ATTR_RW(on_panic);
1815 static void do_panic(void)
1817 lgr_info_log();
1818 on_panic_trigger.action->fn(&on_panic_trigger);
1819 stop_run(&on_panic_trigger);
1822 /* on restart */
1824 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR,
1825 &stop_action};
1827 static ssize_t on_restart_show(struct kobject *kobj,
1828 struct kobj_attribute *attr, char *page)
1830 return sprintf(page, "%s\n", on_restart_trigger.action->name);
1833 static ssize_t on_restart_store(struct kobject *kobj,
1834 struct kobj_attribute *attr,
1835 const char *buf, size_t len)
1837 return set_trigger(buf, &on_restart_trigger, len);
1839 static struct kobj_attribute on_restart_attr = __ATTR_RW(on_restart);
1841 static void __do_restart(void *ignore)
1843 __arch_local_irq_stosm(0x04); /* enable DAT */
1844 smp_send_stop();
1845 #ifdef CONFIG_CRASH_DUMP
1846 crash_kexec(NULL);
1847 #endif
1848 on_restart_trigger.action->fn(&on_restart_trigger);
1849 stop_run(&on_restart_trigger);
1852 void do_restart(void)
1854 tracing_off();
1855 debug_locks_off();
1856 lgr_info_log();
1857 smp_call_online_cpu(__do_restart, NULL);
1860 /* on halt */
1862 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action};
1864 static ssize_t on_halt_show(struct kobject *kobj,
1865 struct kobj_attribute *attr, char *page)
1867 return sprintf(page, "%s\n", on_halt_trigger.action->name);
1870 static ssize_t on_halt_store(struct kobject *kobj,
1871 struct kobj_attribute *attr,
1872 const char *buf, size_t len)
1874 return set_trigger(buf, &on_halt_trigger, len);
1876 static struct kobj_attribute on_halt_attr = __ATTR_RW(on_halt);
1878 static void do_machine_halt(void)
1880 smp_send_stop();
1881 on_halt_trigger.action->fn(&on_halt_trigger);
1882 stop_run(&on_halt_trigger);
1884 void (*_machine_halt)(void) = do_machine_halt;
1886 /* on power off */
1888 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action};
1890 static ssize_t on_poff_show(struct kobject *kobj,
1891 struct kobj_attribute *attr, char *page)
1893 return sprintf(page, "%s\n", on_poff_trigger.action->name);
1896 static ssize_t on_poff_store(struct kobject *kobj,
1897 struct kobj_attribute *attr,
1898 const char *buf, size_t len)
1900 return set_trigger(buf, &on_poff_trigger, len);
1902 static struct kobj_attribute on_poff_attr = __ATTR_RW(on_poff);
1904 static void do_machine_power_off(void)
1906 smp_send_stop();
1907 on_poff_trigger.action->fn(&on_poff_trigger);
1908 stop_run(&on_poff_trigger);
1910 void (*_machine_power_off)(void) = do_machine_power_off;
1912 static struct attribute *shutdown_action_attrs[] = {
1913 &on_restart_attr.attr,
1914 &on_reboot_attr.attr,
1915 &on_panic_attr.attr,
1916 &on_halt_attr.attr,
1917 &on_poff_attr.attr,
1918 NULL,
1921 static struct attribute_group shutdown_action_attr_group = {
1922 .attrs = shutdown_action_attrs,
1925 static void __init shutdown_triggers_init(void)
1927 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
1928 firmware_kobj);
1929 if (!shutdown_actions_kset)
1930 goto fail;
1931 if (sysfs_create_group(&shutdown_actions_kset->kobj,
1932 &shutdown_action_attr_group))
1933 goto fail;
1934 return;
1935 fail:
1936 panic("shutdown_triggers_init failed\n");
1939 static void __init shutdown_actions_init(void)
1941 int i;
1943 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) {
1944 if (!shutdown_actions_list[i]->init)
1945 continue;
1946 shutdown_actions_list[i]->init_rc =
1947 shutdown_actions_list[i]->init();
1951 static int __init s390_ipl_init(void)
1953 char str[8] = {0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40};
1955 sclp_early_get_ipl_info(&sclp_ipl_info);
1957 * Fix loadparm: There are systems where the (SCSI) LOADPARM
1958 * returned by read SCP info is invalid (contains EBCDIC blanks)
1959 * when the system has been booted via diag308. In that case we use
1960 * the value from diag308, if available.
1962 * There are also systems where diag308 store does not work in
1963 * case the system is booted from HMC. Fortunately in this case
1964 * READ SCP info provides the correct value.
1966 if (memcmp(sclp_ipl_info.loadparm, str, sizeof(str)) == 0 && ipl_block_valid)
1967 memcpy(sclp_ipl_info.loadparm, ipl_block.ccw.loadparm, LOADPARM_LEN);
1968 shutdown_actions_init();
1969 shutdown_triggers_init();
1970 return 0;
1973 __initcall(s390_ipl_init);
1975 static void __init strncpy_skip_quote(char *dst, char *src, int n)
1977 int sx, dx;
1979 dx = 0;
1980 for (sx = 0; src[sx] != 0; sx++) {
1981 if (src[sx] == '"')
1982 continue;
1983 dst[dx++] = src[sx];
1984 if (dx >= n)
1985 break;
1989 static int __init vmcmd_on_reboot_setup(char *str)
1991 if (!MACHINE_IS_VM)
1992 return 1;
1993 strncpy_skip_quote(vmcmd_on_reboot, str, 127);
1994 vmcmd_on_reboot[127] = 0;
1995 on_reboot_trigger.action = &vmcmd_action;
1996 return 1;
1998 __setup("vmreboot=", vmcmd_on_reboot_setup);
2000 static int __init vmcmd_on_panic_setup(char *str)
2002 if (!MACHINE_IS_VM)
2003 return 1;
2004 strncpy_skip_quote(vmcmd_on_panic, str, 127);
2005 vmcmd_on_panic[127] = 0;
2006 on_panic_trigger.action = &vmcmd_action;
2007 return 1;
2009 __setup("vmpanic=", vmcmd_on_panic_setup);
2011 static int __init vmcmd_on_halt_setup(char *str)
2013 if (!MACHINE_IS_VM)
2014 return 1;
2015 strncpy_skip_quote(vmcmd_on_halt, str, 127);
2016 vmcmd_on_halt[127] = 0;
2017 on_halt_trigger.action = &vmcmd_action;
2018 return 1;
2020 __setup("vmhalt=", vmcmd_on_halt_setup);
2022 static int __init vmcmd_on_poff_setup(char *str)
2024 if (!MACHINE_IS_VM)
2025 return 1;
2026 strncpy_skip_quote(vmcmd_on_poff, str, 127);
2027 vmcmd_on_poff[127] = 0;
2028 on_poff_trigger.action = &vmcmd_action;
2029 return 1;
2031 __setup("vmpoff=", vmcmd_on_poff_setup);
2033 static int on_panic_notify(struct notifier_block *self,
2034 unsigned long event, void *data)
2036 do_panic();
2037 return NOTIFY_OK;
2040 static struct notifier_block on_panic_nb = {
2041 .notifier_call = on_panic_notify,
2042 .priority = INT_MIN,
2045 void __init setup_ipl(void)
2047 BUILD_BUG_ON(sizeof(struct ipl_parameter_block) != PAGE_SIZE);
2049 ipl_info.type = get_ipl_type();
2050 switch (ipl_info.type) {
2051 case IPL_TYPE_CCW:
2052 ipl_info.data.ccw.dev_id.ssid = ipl_block.ccw.ssid;
2053 ipl_info.data.ccw.dev_id.devno = ipl_block.ccw.devno;
2054 break;
2055 case IPL_TYPE_FCP:
2056 case IPL_TYPE_FCP_DUMP:
2057 ipl_info.data.fcp.dev_id.ssid = 0;
2058 ipl_info.data.fcp.dev_id.devno = ipl_block.fcp.devno;
2059 ipl_info.data.fcp.wwpn = ipl_block.fcp.wwpn;
2060 ipl_info.data.fcp.lun = ipl_block.fcp.lun;
2061 break;
2062 case IPL_TYPE_NVME:
2063 case IPL_TYPE_NVME_DUMP:
2064 ipl_info.data.nvme.fid = ipl_block.nvme.fid;
2065 ipl_info.data.nvme.nsid = ipl_block.nvme.nsid;
2066 break;
2067 case IPL_TYPE_NSS:
2068 case IPL_TYPE_UNKNOWN:
2069 /* We have no info to copy */
2070 break;
2072 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
2075 void s390_reset_system(void)
2077 /* Disable prefixing */
2078 set_prefix(0);
2080 /* Disable lowcore protection */
2081 __ctl_clear_bit(0, 28);
2082 diag_dma_ops.diag308_reset();
2085 #ifdef CONFIG_KEXEC_FILE
2087 int ipl_report_add_component(struct ipl_report *report, struct kexec_buf *kbuf,
2088 unsigned char flags, unsigned short cert)
2090 struct ipl_report_component *comp;
2092 comp = vzalloc(sizeof(*comp));
2093 if (!comp)
2094 return -ENOMEM;
2095 list_add_tail(&comp->list, &report->components);
2097 comp->entry.addr = kbuf->mem;
2098 comp->entry.len = kbuf->memsz;
2099 comp->entry.flags = flags;
2100 comp->entry.certificate_index = cert;
2102 report->size += sizeof(comp->entry);
2104 return 0;
2107 int ipl_report_add_certificate(struct ipl_report *report, void *key,
2108 unsigned long addr, unsigned long len)
2110 struct ipl_report_certificate *cert;
2112 cert = vzalloc(sizeof(*cert));
2113 if (!cert)
2114 return -ENOMEM;
2115 list_add_tail(&cert->list, &report->certificates);
2117 cert->entry.addr = addr;
2118 cert->entry.len = len;
2119 cert->key = key;
2121 report->size += sizeof(cert->entry);
2122 report->size += cert->entry.len;
2124 return 0;
2127 struct ipl_report *ipl_report_init(struct ipl_parameter_block *ipib)
2129 struct ipl_report *report;
2131 report = vzalloc(sizeof(*report));
2132 if (!report)
2133 return ERR_PTR(-ENOMEM);
2135 report->ipib = ipib;
2136 INIT_LIST_HEAD(&report->components);
2137 INIT_LIST_HEAD(&report->certificates);
2139 report->size = ALIGN(ipib->hdr.len, 8);
2140 report->size += sizeof(struct ipl_rl_hdr);
2141 report->size += sizeof(struct ipl_rb_components);
2142 report->size += sizeof(struct ipl_rb_certificates);
2144 return report;
2147 void *ipl_report_finish(struct ipl_report *report)
2149 struct ipl_report_certificate *cert;
2150 struct ipl_report_component *comp;
2151 struct ipl_rb_certificates *certs;
2152 struct ipl_parameter_block *ipib;
2153 struct ipl_rb_components *comps;
2154 struct ipl_rl_hdr *rl_hdr;
2155 void *buf, *ptr;
2157 buf = vzalloc(report->size);
2158 if (!buf)
2159 return ERR_PTR(-ENOMEM);
2160 ptr = buf;
2162 memcpy(ptr, report->ipib, report->ipib->hdr.len);
2163 ipib = ptr;
2164 if (ipl_secure_flag)
2165 ipib->hdr.flags |= IPL_PL_FLAG_SIPL;
2166 ipib->hdr.flags |= IPL_PL_FLAG_IPLSR;
2167 ptr += report->ipib->hdr.len;
2168 ptr = PTR_ALIGN(ptr, 8);
2170 rl_hdr = ptr;
2171 ptr += sizeof(*rl_hdr);
2173 comps = ptr;
2174 comps->rbt = IPL_RBT_COMPONENTS;
2175 ptr += sizeof(*comps);
2176 list_for_each_entry(comp, &report->components, list) {
2177 memcpy(ptr, &comp->entry, sizeof(comp->entry));
2178 ptr += sizeof(comp->entry);
2180 comps->len = ptr - (void *)comps;
2182 certs = ptr;
2183 certs->rbt = IPL_RBT_CERTIFICATES;
2184 ptr += sizeof(*certs);
2185 list_for_each_entry(cert, &report->certificates, list) {
2186 memcpy(ptr, &cert->entry, sizeof(cert->entry));
2187 ptr += sizeof(cert->entry);
2189 certs->len = ptr - (void *)certs;
2190 rl_hdr->len = ptr - (void *)rl_hdr;
2192 list_for_each_entry(cert, &report->certificates, list) {
2193 memcpy(ptr, cert->key, cert->entry.len);
2194 ptr += cert->entry.len;
2197 BUG_ON(ptr > buf + report->size);
2198 return buf;
2201 int ipl_report_free(struct ipl_report *report)
2203 struct ipl_report_component *comp, *ncomp;
2204 struct ipl_report_certificate *cert, *ncert;
2206 list_for_each_entry_safe(comp, ncomp, &report->components, list)
2207 vfree(comp);
2209 list_for_each_entry_safe(cert, ncert, &report->certificates, list)
2210 vfree(cert);
2212 vfree(report);
2214 return 0;
2217 #endif