1 /* 2 * arch/s390/kernel/ipl.c 3 * ipl/reipl/dump support for Linux on s390. 4 * 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 */ 10 11 #include <linux/types.h> 12 #include <linux/module.h> 13 #include <linux/device.h> 14 #include <linux/delay.h> 15 #include <linux/reboot.h> 16 #include <linux/ctype.h> 17 #include <linux/fs.h> 18 #include <linux/gfp.h> 19 #include <asm/ipl.h> 20 #include <asm/smp.h> 21 #include <asm/setup.h> 22 #include <asm/cpcmd.h> 23 #include <asm/cio.h> 24 #include <asm/ebcdic.h> 25 #include <asm/reset.h> 26 #include <asm/sclp.h> 27 #include <asm/sigp.h> 28 #include <asm/checksum.h> 29 30 #define IPL_PARM_BLOCK_VERSION 0 31 32 #define IPL_UNKNOWN_STR "unknown" 33 #define IPL_CCW_STR "ccw" 34 #define IPL_FCP_STR "fcp" 35 #define IPL_FCP_DUMP_STR "fcp_dump" 36 #define IPL_NSS_STR "nss" 37 38 #define DUMP_CCW_STR "ccw" 39 #define DUMP_FCP_STR "fcp" 40 #define DUMP_NONE_STR "none" 41 42 /* 43 * Four shutdown trigger types are supported: 44 * - panic 45 * - halt 46 * - power off 47 * - reipl 48 * - restart 49 */ 50 #define ON_PANIC_STR "on_panic" 51 #define ON_HALT_STR "on_halt" 52 #define ON_POFF_STR "on_poff" 53 #define ON_REIPL_STR "on_reboot" 54 #define ON_RESTART_STR "on_restart" 55 56 struct shutdown_action; 57 struct shutdown_trigger { 58 char *name; 59 struct shutdown_action *action; 60 }; 61 62 /* 63 * The following shutdown action types are supported: 64 */ 65 #define SHUTDOWN_ACTION_IPL_STR "ipl" 66 #define SHUTDOWN_ACTION_REIPL_STR "reipl" 67 #define SHUTDOWN_ACTION_DUMP_STR "dump" 68 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd" 69 #define SHUTDOWN_ACTION_STOP_STR "stop" 70 #define SHUTDOWN_ACTION_DUMP_REIPL_STR "dump_reipl" 71 72 struct shutdown_action { 73 char *name; 74 void (*fn) (struct shutdown_trigger *trigger); 75 int (*init) (void); 76 int init_rc; 77 }; 78 79 static char *ipl_type_str(enum ipl_type type) 80 { 81 switch (type) { 82 case IPL_TYPE_CCW: 83 return IPL_CCW_STR; 84 case IPL_TYPE_FCP: 85 return IPL_FCP_STR; 86 case IPL_TYPE_FCP_DUMP: 87 return IPL_FCP_DUMP_STR; 88 case IPL_TYPE_NSS: 89 return IPL_NSS_STR; 90 case IPL_TYPE_UNKNOWN: 91 default: 92 return IPL_UNKNOWN_STR; 93 } 94 } 95 96 enum dump_type { 97 DUMP_TYPE_NONE = 1, 98 DUMP_TYPE_CCW = 2, 99 DUMP_TYPE_FCP = 4, 100 }; 101 102 static char *dump_type_str(enum dump_type type) 103 { 104 switch (type) { 105 case DUMP_TYPE_NONE: 106 return DUMP_NONE_STR; 107 case DUMP_TYPE_CCW: 108 return DUMP_CCW_STR; 109 case DUMP_TYPE_FCP: 110 return DUMP_FCP_STR; 111 default: 112 return NULL; 113 } 114 } 115 116 /* 117 * Must be in data section since the bss section 118 * is not cleared when these are accessed. 119 */ 120 static u16 ipl_devno __attribute__((__section__(".data"))) = 0; 121 u32 ipl_flags __attribute__((__section__(".data"))) = 0; 122 123 enum ipl_method { 124 REIPL_METHOD_CCW_CIO, 125 REIPL_METHOD_CCW_DIAG, 126 REIPL_METHOD_CCW_VM, 127 REIPL_METHOD_FCP_RO_DIAG, 128 REIPL_METHOD_FCP_RW_DIAG, 129 REIPL_METHOD_FCP_RO_VM, 130 REIPL_METHOD_FCP_DUMP, 131 REIPL_METHOD_NSS, 132 REIPL_METHOD_NSS_DIAG, 133 REIPL_METHOD_DEFAULT, 134 }; 135 136 enum dump_method { 137 DUMP_METHOD_NONE, 138 DUMP_METHOD_CCW_CIO, 139 DUMP_METHOD_CCW_DIAG, 140 DUMP_METHOD_CCW_VM, 141 DUMP_METHOD_FCP_DIAG, 142 }; 143 144 static int diag308_set_works = 0; 145 146 static struct ipl_parameter_block ipl_block; 147 148 static int reipl_capabilities = IPL_TYPE_UNKNOWN; 149 150 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN; 151 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT; 152 static struct ipl_parameter_block *reipl_block_fcp; 153 static struct ipl_parameter_block *reipl_block_ccw; 154 static struct ipl_parameter_block *reipl_block_nss; 155 static struct ipl_parameter_block *reipl_block_actual; 156 157 static int dump_capabilities = DUMP_TYPE_NONE; 158 static enum dump_type dump_type = DUMP_TYPE_NONE; 159 static enum dump_method dump_method = DUMP_METHOD_NONE; 160 static struct ipl_parameter_block *dump_block_fcp; 161 static struct ipl_parameter_block *dump_block_ccw; 162 163 static struct sclp_ipl_info sclp_ipl_info; 164 165 int diag308(unsigned long subcode, void *addr) 166 { 167 register unsigned long _addr asm("0") = (unsigned long) addr; 168 register unsigned long _rc asm("1") = 0; 169 170 asm volatile( 171 " diag %0,%2,0x308\n" 172 "0:\n" 173 EX_TABLE(0b,0b) 174 : "+d" (_addr), "+d" (_rc) 175 : "d" (subcode) : "cc", "memory"); 176 return _rc; 177 } 178 EXPORT_SYMBOL_GPL(diag308); 179 180 /* SYSFS */ 181 182 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \ 183 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ 184 struct kobj_attribute *attr, \ 185 char *page) \ 186 { \ 187 return sprintf(page, _format, _value); \ 188 } \ 189 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ 190 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL); 191 192 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \ 193 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ 194 struct kobj_attribute *attr, \ 195 char *page) \ 196 { \ 197 return sprintf(page, _fmt_out, \ 198 (unsigned long long) _value); \ 199 } \ 200 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ 201 struct kobj_attribute *attr, \ 202 const char *buf, size_t len) \ 203 { \ 204 unsigned long long value; \ 205 if (sscanf(buf, _fmt_in, &value) != 1) \ 206 return -EINVAL; \ 207 _value = value; \ 208 return len; \ 209 } \ 210 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ 211 __ATTR(_name,(S_IRUGO | S_IWUSR), \ 212 sys_##_prefix##_##_name##_show, \ 213 sys_##_prefix##_##_name##_store); 214 215 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\ 216 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ 217 struct kobj_attribute *attr, \ 218 char *page) \ 219 { \ 220 return sprintf(page, _fmt_out, _value); \ 221 } \ 222 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ 223 struct kobj_attribute *attr, \ 224 const char *buf, size_t len) \ 225 { \ 226 strncpy(_value, buf, sizeof(_value) - 1); \ 227 strim(_value); \ 228 return len; \ 229 } \ 230 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ 231 __ATTR(_name,(S_IRUGO | S_IWUSR), \ 232 sys_##_prefix##_##_name##_show, \ 233 sys_##_prefix##_##_name##_store); 234 235 static void make_attrs_ro(struct attribute **attrs) 236 { 237 while (*attrs) { 238 (*attrs)->mode = S_IRUGO; 239 attrs++; 240 } 241 } 242 243 /* 244 * ipl section 245 */ 246 247 static __init enum ipl_type get_ipl_type(void) 248 { 249 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; 250 251 if (ipl_flags & IPL_NSS_VALID) 252 return IPL_TYPE_NSS; 253 if (!(ipl_flags & IPL_DEVNO_VALID)) 254 return IPL_TYPE_UNKNOWN; 255 if (!(ipl_flags & IPL_PARMBLOCK_VALID)) 256 return IPL_TYPE_CCW; 257 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION) 258 return IPL_TYPE_UNKNOWN; 259 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP) 260 return IPL_TYPE_UNKNOWN; 261 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP) 262 return IPL_TYPE_FCP_DUMP; 263 return IPL_TYPE_FCP; 264 } 265 266 struct ipl_info ipl_info; 267 EXPORT_SYMBOL_GPL(ipl_info); 268 269 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr, 270 char *page) 271 { 272 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type)); 273 } 274 275 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type); 276 277 /* VM IPL PARM routines */ 278 size_t reipl_get_ascii_vmparm(char *dest, size_t size, 279 const struct ipl_parameter_block *ipb) 280 { 281 int i; 282 size_t len; 283 char has_lowercase = 0; 284 285 len = 0; 286 if ((ipb->ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID) && 287 (ipb->ipl_info.ccw.vm_parm_len > 0)) { 288 289 len = min_t(size_t, size - 1, ipb->ipl_info.ccw.vm_parm_len); 290 memcpy(dest, ipb->ipl_info.ccw.vm_parm, len); 291 /* If at least one character is lowercase, we assume mixed 292 * case; otherwise we convert everything to lowercase. 293 */ 294 for (i = 0; i < len; i++) 295 if ((dest[i] > 0x80 && dest[i] < 0x8a) || /* a-i */ 296 (dest[i] > 0x90 && dest[i] < 0x9a) || /* j-r */ 297 (dest[i] > 0xa1 && dest[i] < 0xaa)) { /* s-z */ 298 has_lowercase = 1; 299 break; 300 } 301 if (!has_lowercase) 302 EBC_TOLOWER(dest, len); 303 EBCASC(dest, len); 304 } 305 dest[len] = 0; 306 307 return len; 308 } 309 310 size_t append_ipl_vmparm(char *dest, size_t size) 311 { 312 size_t rc; 313 314 rc = 0; 315 if (diag308_set_works && (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_CCW)) 316 rc = reipl_get_ascii_vmparm(dest, size, &ipl_block); 317 else 318 dest[0] = 0; 319 return rc; 320 } 321 322 static ssize_t ipl_vm_parm_show(struct kobject *kobj, 323 struct kobj_attribute *attr, char *page) 324 { 325 char parm[DIAG308_VMPARM_SIZE + 1] = {}; 326 327 append_ipl_vmparm(parm, sizeof(parm)); 328 return sprintf(page, "%s\n", parm); 329 } 330 331 static size_t scpdata_length(const char* buf, size_t count) 332 { 333 while (count) { 334 if (buf[count - 1] != '\0' && buf[count - 1] != ' ') 335 break; 336 count--; 337 } 338 return count; 339 } 340 341 size_t reipl_append_ascii_scpdata(char *dest, size_t size, 342 const struct ipl_parameter_block *ipb) 343 { 344 size_t count; 345 size_t i; 346 int has_lowercase; 347 348 count = min(size - 1, scpdata_length(ipb->ipl_info.fcp.scp_data, 349 ipb->ipl_info.fcp.scp_data_len)); 350 if (!count) 351 goto out; 352 353 has_lowercase = 0; 354 for (i = 0; i < count; i++) { 355 if (!isascii(ipb->ipl_info.fcp.scp_data[i])) { 356 count = 0; 357 goto out; 358 } 359 if (!has_lowercase && islower(ipb->ipl_info.fcp.scp_data[i])) 360 has_lowercase = 1; 361 } 362 363 if (has_lowercase) 364 memcpy(dest, ipb->ipl_info.fcp.scp_data, count); 365 else 366 for (i = 0; i < count; i++) 367 dest[i] = tolower(ipb->ipl_info.fcp.scp_data[i]); 368 out: 369 dest[count] = '\0'; 370 return count; 371 } 372 373 size_t append_ipl_scpdata(char *dest, size_t len) 374 { 375 size_t rc; 376 377 rc = 0; 378 if (ipl_block.hdr.pbt == DIAG308_IPL_TYPE_FCP) 379 rc = reipl_append_ascii_scpdata(dest, len, &ipl_block); 380 else 381 dest[0] = 0; 382 return rc; 383 } 384 385 386 static struct kobj_attribute sys_ipl_vm_parm_attr = 387 __ATTR(parm, S_IRUGO, ipl_vm_parm_show, NULL); 388 389 static ssize_t sys_ipl_device_show(struct kobject *kobj, 390 struct kobj_attribute *attr, char *page) 391 { 392 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; 393 394 switch (ipl_info.type) { 395 case IPL_TYPE_CCW: 396 return sprintf(page, "0.0.%04x\n", ipl_devno); 397 case IPL_TYPE_FCP: 398 case IPL_TYPE_FCP_DUMP: 399 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno); 400 default: 401 return 0; 402 } 403 } 404 405 static struct kobj_attribute sys_ipl_device_attr = 406 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL); 407 408 static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj, 409 struct bin_attribute *attr, char *buf, 410 loff_t off, size_t count) 411 { 412 return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START, 413 IPL_PARMBLOCK_SIZE); 414 } 415 416 static struct bin_attribute ipl_parameter_attr = { 417 .attr = { 418 .name = "binary_parameter", 419 .mode = S_IRUGO, 420 }, 421 .size = PAGE_SIZE, 422 .read = &ipl_parameter_read, 423 }; 424 425 static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj, 426 struct bin_attribute *attr, char *buf, 427 loff_t off, size_t count) 428 { 429 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len; 430 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data; 431 432 return memory_read_from_buffer(buf, count, &off, scp_data, size); 433 } 434 435 static struct bin_attribute ipl_scp_data_attr = { 436 .attr = { 437 .name = "scp_data", 438 .mode = S_IRUGO, 439 }, 440 .size = PAGE_SIZE, 441 .read = ipl_scp_data_read, 442 }; 443 444 /* FCP ipl device attributes */ 445 446 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long) 447 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn); 448 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long) 449 IPL_PARMBLOCK_START->ipl_info.fcp.lun); 450 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long) 451 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog); 452 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long) 453 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba); 454 455 static struct attribute *ipl_fcp_attrs[] = { 456 &sys_ipl_type_attr.attr, 457 &sys_ipl_device_attr.attr, 458 &sys_ipl_fcp_wwpn_attr.attr, 459 &sys_ipl_fcp_lun_attr.attr, 460 &sys_ipl_fcp_bootprog_attr.attr, 461 &sys_ipl_fcp_br_lba_attr.attr, 462 NULL, 463 }; 464 465 static struct attribute_group ipl_fcp_attr_group = { 466 .attrs = ipl_fcp_attrs, 467 }; 468 469 /* CCW ipl device attributes */ 470 471 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj, 472 struct kobj_attribute *attr, char *page) 473 { 474 char loadparm[LOADPARM_LEN + 1] = {}; 475 476 if (!sclp_ipl_info.is_valid) 477 return sprintf(page, "#unknown#\n"); 478 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN); 479 EBCASC(loadparm, LOADPARM_LEN); 480 strim(loadparm); 481 return sprintf(page, "%s\n", loadparm); 482 } 483 484 static struct kobj_attribute sys_ipl_ccw_loadparm_attr = 485 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL); 486 487 static struct attribute *ipl_ccw_attrs_vm[] = { 488 &sys_ipl_type_attr.attr, 489 &sys_ipl_device_attr.attr, 490 &sys_ipl_ccw_loadparm_attr.attr, 491 &sys_ipl_vm_parm_attr.attr, 492 NULL, 493 }; 494 495 static struct attribute *ipl_ccw_attrs_lpar[] = { 496 &sys_ipl_type_attr.attr, 497 &sys_ipl_device_attr.attr, 498 &sys_ipl_ccw_loadparm_attr.attr, 499 NULL, 500 }; 501 502 static struct attribute_group ipl_ccw_attr_group_vm = { 503 .attrs = ipl_ccw_attrs_vm, 504 }; 505 506 static struct attribute_group ipl_ccw_attr_group_lpar = { 507 .attrs = ipl_ccw_attrs_lpar 508 }; 509 510 /* NSS ipl device attributes */ 511 512 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name); 513 514 static struct attribute *ipl_nss_attrs[] = { 515 &sys_ipl_type_attr.attr, 516 &sys_ipl_nss_name_attr.attr, 517 &sys_ipl_ccw_loadparm_attr.attr, 518 &sys_ipl_vm_parm_attr.attr, 519 NULL, 520 }; 521 522 static struct attribute_group ipl_nss_attr_group = { 523 .attrs = ipl_nss_attrs, 524 }; 525 526 /* UNKNOWN ipl device attributes */ 527 528 static struct attribute *ipl_unknown_attrs[] = { 529 &sys_ipl_type_attr.attr, 530 NULL, 531 }; 532 533 static struct attribute_group ipl_unknown_attr_group = { 534 .attrs = ipl_unknown_attrs, 535 }; 536 537 static struct kset *ipl_kset; 538 539 static int __init ipl_register_fcp_files(void) 540 { 541 int rc; 542 543 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group); 544 if (rc) 545 goto out; 546 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr); 547 if (rc) 548 goto out_ipl_parm; 549 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr); 550 if (!rc) 551 goto out; 552 553 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr); 554 555 out_ipl_parm: 556 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group); 557 out: 558 return rc; 559 } 560 561 static void __ipl_run(void *unused) 562 { 563 diag308(DIAG308_IPL, NULL); 564 if (MACHINE_IS_VM) 565 __cpcmd("IPL", NULL, 0, NULL); 566 else if (ipl_info.type == IPL_TYPE_CCW) 567 reipl_ccw_dev(&ipl_info.data.ccw.dev_id); 568 } 569 570 static void ipl_run(struct shutdown_trigger *trigger) 571 { 572 smp_switch_to_ipl_cpu(__ipl_run, NULL); 573 } 574 575 static int __init ipl_init(void) 576 { 577 int rc; 578 579 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj); 580 if (!ipl_kset) { 581 rc = -ENOMEM; 582 goto out; 583 } 584 switch (ipl_info.type) { 585 case IPL_TYPE_CCW: 586 if (MACHINE_IS_VM) 587 rc = sysfs_create_group(&ipl_kset->kobj, 588 &ipl_ccw_attr_group_vm); 589 else 590 rc = sysfs_create_group(&ipl_kset->kobj, 591 &ipl_ccw_attr_group_lpar); 592 break; 593 case IPL_TYPE_FCP: 594 case IPL_TYPE_FCP_DUMP: 595 rc = ipl_register_fcp_files(); 596 break; 597 case IPL_TYPE_NSS: 598 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group); 599 break; 600 default: 601 rc = sysfs_create_group(&ipl_kset->kobj, 602 &ipl_unknown_attr_group); 603 break; 604 } 605 out: 606 if (rc) 607 panic("ipl_init failed: rc = %i\n", rc); 608 609 return 0; 610 } 611 612 static struct shutdown_action __refdata ipl_action = { 613 .name = SHUTDOWN_ACTION_IPL_STR, 614 .fn = ipl_run, 615 .init = ipl_init, 616 }; 617 618 /* 619 * reipl shutdown action: Reboot Linux on shutdown. 620 */ 621 622 /* VM IPL PARM attributes */ 623 static ssize_t reipl_generic_vmparm_show(struct ipl_parameter_block *ipb, 624 char *page) 625 { 626 char vmparm[DIAG308_VMPARM_SIZE + 1] = {}; 627 628 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb); 629 return sprintf(page, "%s\n", vmparm); 630 } 631 632 static ssize_t reipl_generic_vmparm_store(struct ipl_parameter_block *ipb, 633 size_t vmparm_max, 634 const char *buf, size_t len) 635 { 636 int i, ip_len; 637 638 /* ignore trailing newline */ 639 ip_len = len; 640 if ((len > 0) && (buf[len - 1] == '\n')) 641 ip_len--; 642 643 if (ip_len > vmparm_max) 644 return -EINVAL; 645 646 /* parm is used to store kernel options, check for common chars */ 647 for (i = 0; i < ip_len; i++) 648 if (!(isalnum(buf[i]) || isascii(buf[i]) || isprint(buf[i]))) 649 return -EINVAL; 650 651 memset(ipb->ipl_info.ccw.vm_parm, 0, DIAG308_VMPARM_SIZE); 652 ipb->ipl_info.ccw.vm_parm_len = ip_len; 653 if (ip_len > 0) { 654 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID; 655 memcpy(ipb->ipl_info.ccw.vm_parm, buf, ip_len); 656 ASCEBC(ipb->ipl_info.ccw.vm_parm, ip_len); 657 } else { 658 ipb->ipl_info.ccw.vm_flags &= ~DIAG308_VM_FLAGS_VP_VALID; 659 } 660 661 return len; 662 } 663 664 /* NSS wrapper */ 665 static ssize_t reipl_nss_vmparm_show(struct kobject *kobj, 666 struct kobj_attribute *attr, char *page) 667 { 668 return reipl_generic_vmparm_show(reipl_block_nss, page); 669 } 670 671 static ssize_t reipl_nss_vmparm_store(struct kobject *kobj, 672 struct kobj_attribute *attr, 673 const char *buf, size_t len) 674 { 675 return reipl_generic_vmparm_store(reipl_block_nss, 56, buf, len); 676 } 677 678 /* CCW wrapper */ 679 static ssize_t reipl_ccw_vmparm_show(struct kobject *kobj, 680 struct kobj_attribute *attr, char *page) 681 { 682 return reipl_generic_vmparm_show(reipl_block_ccw, page); 683 } 684 685 static ssize_t reipl_ccw_vmparm_store(struct kobject *kobj, 686 struct kobj_attribute *attr, 687 const char *buf, size_t len) 688 { 689 return reipl_generic_vmparm_store(reipl_block_ccw, 64, buf, len); 690 } 691 692 static struct kobj_attribute sys_reipl_nss_vmparm_attr = 693 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_nss_vmparm_show, 694 reipl_nss_vmparm_store); 695 static struct kobj_attribute sys_reipl_ccw_vmparm_attr = 696 __ATTR(parm, S_IRUGO | S_IWUSR, reipl_ccw_vmparm_show, 697 reipl_ccw_vmparm_store); 698 699 /* FCP reipl device attributes */ 700 701 static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj, 702 struct bin_attribute *attr, 703 char *buf, loff_t off, size_t count) 704 { 705 size_t size = reipl_block_fcp->ipl_info.fcp.scp_data_len; 706 void *scp_data = reipl_block_fcp->ipl_info.fcp.scp_data; 707 708 return memory_read_from_buffer(buf, count, &off, scp_data, size); 709 } 710 711 static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj, 712 struct bin_attribute *attr, 713 char *buf, loff_t off, size_t count) 714 { 715 size_t padding; 716 size_t scpdata_len; 717 718 if (off < 0) 719 return -EINVAL; 720 721 if (off >= DIAG308_SCPDATA_SIZE) 722 return -ENOSPC; 723 724 if (count > DIAG308_SCPDATA_SIZE - off) 725 count = DIAG308_SCPDATA_SIZE - off; 726 727 memcpy(reipl_block_fcp->ipl_info.fcp.scp_data, buf + off, count); 728 scpdata_len = off + count; 729 730 if (scpdata_len % 8) { 731 padding = 8 - (scpdata_len % 8); 732 memset(reipl_block_fcp->ipl_info.fcp.scp_data + scpdata_len, 733 0, padding); 734 scpdata_len += padding; 735 } 736 737 reipl_block_fcp->ipl_info.fcp.scp_data_len = scpdata_len; 738 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN + scpdata_len; 739 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN + scpdata_len; 740 741 return count; 742 } 743 744 static struct bin_attribute sys_reipl_fcp_scp_data_attr = { 745 .attr = { 746 .name = "scp_data", 747 .mode = S_IRUGO | S_IWUSR, 748 }, 749 .size = PAGE_SIZE, 750 .read = reipl_fcp_scpdata_read, 751 .write = reipl_fcp_scpdata_write, 752 }; 753 754 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n", 755 reipl_block_fcp->ipl_info.fcp.wwpn); 756 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n", 757 reipl_block_fcp->ipl_info.fcp.lun); 758 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n", 759 reipl_block_fcp->ipl_info.fcp.bootprog); 760 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n", 761 reipl_block_fcp->ipl_info.fcp.br_lba); 762 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", 763 reipl_block_fcp->ipl_info.fcp.devno); 764 765 static struct attribute *reipl_fcp_attrs[] = { 766 &sys_reipl_fcp_device_attr.attr, 767 &sys_reipl_fcp_wwpn_attr.attr, 768 &sys_reipl_fcp_lun_attr.attr, 769 &sys_reipl_fcp_bootprog_attr.attr, 770 &sys_reipl_fcp_br_lba_attr.attr, 771 NULL, 772 }; 773 774 static struct attribute_group reipl_fcp_attr_group = { 775 .attrs = reipl_fcp_attrs, 776 }; 777 778 /* CCW reipl device attributes */ 779 780 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", 781 reipl_block_ccw->ipl_info.ccw.devno); 782 783 static void reipl_get_ascii_loadparm(char *loadparm, 784 struct ipl_parameter_block *ibp) 785 { 786 memcpy(loadparm, ibp->ipl_info.ccw.load_parm, LOADPARM_LEN); 787 EBCASC(loadparm, LOADPARM_LEN); 788 loadparm[LOADPARM_LEN] = 0; 789 strim(loadparm); 790 } 791 792 static ssize_t reipl_generic_loadparm_show(struct ipl_parameter_block *ipb, 793 char *page) 794 { 795 char buf[LOADPARM_LEN + 1]; 796 797 reipl_get_ascii_loadparm(buf, ipb); 798 return sprintf(page, "%s\n", buf); 799 } 800 801 static ssize_t reipl_generic_loadparm_store(struct ipl_parameter_block *ipb, 802 const char *buf, size_t len) 803 { 804 int i, lp_len; 805 806 /* ignore trailing newline */ 807 lp_len = len; 808 if ((len > 0) && (buf[len - 1] == '\n')) 809 lp_len--; 810 /* loadparm can have max 8 characters and must not start with a blank */ 811 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' '))) 812 return -EINVAL; 813 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */ 814 for (i = 0; i < lp_len; i++) { 815 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') || 816 (buf[i] == '.')) 817 continue; 818 return -EINVAL; 819 } 820 /* initialize loadparm with blanks */ 821 memset(ipb->ipl_info.ccw.load_parm, ' ', LOADPARM_LEN); 822 /* copy and convert to ebcdic */ 823 memcpy(ipb->ipl_info.ccw.load_parm, buf, lp_len); 824 ASCEBC(ipb->ipl_info.ccw.load_parm, LOADPARM_LEN); 825 return len; 826 } 827 828 /* NSS wrapper */ 829 static ssize_t reipl_nss_loadparm_show(struct kobject *kobj, 830 struct kobj_attribute *attr, char *page) 831 { 832 return reipl_generic_loadparm_show(reipl_block_nss, page); 833 } 834 835 static ssize_t reipl_nss_loadparm_store(struct kobject *kobj, 836 struct kobj_attribute *attr, 837 const char *buf, size_t len) 838 { 839 return reipl_generic_loadparm_store(reipl_block_nss, buf, len); 840 } 841 842 /* CCW wrapper */ 843 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj, 844 struct kobj_attribute *attr, char *page) 845 { 846 return reipl_generic_loadparm_show(reipl_block_ccw, page); 847 } 848 849 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj, 850 struct kobj_attribute *attr, 851 const char *buf, size_t len) 852 { 853 return reipl_generic_loadparm_store(reipl_block_ccw, buf, len); 854 } 855 856 static struct kobj_attribute sys_reipl_ccw_loadparm_attr = 857 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_ccw_loadparm_show, 858 reipl_ccw_loadparm_store); 859 860 static struct attribute *reipl_ccw_attrs_vm[] = { 861 &sys_reipl_ccw_device_attr.attr, 862 &sys_reipl_ccw_loadparm_attr.attr, 863 &sys_reipl_ccw_vmparm_attr.attr, 864 NULL, 865 }; 866 867 static struct attribute *reipl_ccw_attrs_lpar[] = { 868 &sys_reipl_ccw_device_attr.attr, 869 &sys_reipl_ccw_loadparm_attr.attr, 870 NULL, 871 }; 872 873 static struct attribute_group reipl_ccw_attr_group_vm = { 874 .name = IPL_CCW_STR, 875 .attrs = reipl_ccw_attrs_vm, 876 }; 877 878 static struct attribute_group reipl_ccw_attr_group_lpar = { 879 .name = IPL_CCW_STR, 880 .attrs = reipl_ccw_attrs_lpar, 881 }; 882 883 884 /* NSS reipl device attributes */ 885 static void reipl_get_ascii_nss_name(char *dst, 886 struct ipl_parameter_block *ipb) 887 { 888 memcpy(dst, ipb->ipl_info.ccw.nss_name, NSS_NAME_SIZE); 889 EBCASC(dst, NSS_NAME_SIZE); 890 dst[NSS_NAME_SIZE] = 0; 891 } 892 893 static ssize_t reipl_nss_name_show(struct kobject *kobj, 894 struct kobj_attribute *attr, char *page) 895 { 896 char nss_name[NSS_NAME_SIZE + 1] = {}; 897 898 reipl_get_ascii_nss_name(nss_name, reipl_block_nss); 899 return sprintf(page, "%s\n", nss_name); 900 } 901 902 static ssize_t reipl_nss_name_store(struct kobject *kobj, 903 struct kobj_attribute *attr, 904 const char *buf, size_t len) 905 { 906 int nss_len; 907 908 /* ignore trailing newline */ 909 nss_len = len; 910 if ((len > 0) && (buf[len - 1] == '\n')) 911 nss_len--; 912 913 if (nss_len > NSS_NAME_SIZE) 914 return -EINVAL; 915 916 memset(reipl_block_nss->ipl_info.ccw.nss_name, 0x40, NSS_NAME_SIZE); 917 if (nss_len > 0) { 918 reipl_block_nss->ipl_info.ccw.vm_flags |= 919 DIAG308_VM_FLAGS_NSS_VALID; 920 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, buf, nss_len); 921 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, nss_len); 922 EBC_TOUPPER(reipl_block_nss->ipl_info.ccw.nss_name, nss_len); 923 } else { 924 reipl_block_nss->ipl_info.ccw.vm_flags &= 925 ~DIAG308_VM_FLAGS_NSS_VALID; 926 } 927 928 return len; 929 } 930 931 static struct kobj_attribute sys_reipl_nss_name_attr = 932 __ATTR(name, S_IRUGO | S_IWUSR, reipl_nss_name_show, 933 reipl_nss_name_store); 934 935 static struct kobj_attribute sys_reipl_nss_loadparm_attr = 936 __ATTR(loadparm, S_IRUGO | S_IWUSR, reipl_nss_loadparm_show, 937 reipl_nss_loadparm_store); 938 939 static struct attribute *reipl_nss_attrs[] = { 940 &sys_reipl_nss_name_attr.attr, 941 &sys_reipl_nss_loadparm_attr.attr, 942 &sys_reipl_nss_vmparm_attr.attr, 943 NULL, 944 }; 945 946 static struct attribute_group reipl_nss_attr_group = { 947 .name = IPL_NSS_STR, 948 .attrs = reipl_nss_attrs, 949 }; 950 951 /* reipl type */ 952 953 static int reipl_set_type(enum ipl_type type) 954 { 955 if (!(reipl_capabilities & type)) 956 return -EINVAL; 957 958 switch(type) { 959 case IPL_TYPE_CCW: 960 if (diag308_set_works) 961 reipl_method = REIPL_METHOD_CCW_DIAG; 962 else if (MACHINE_IS_VM) 963 reipl_method = REIPL_METHOD_CCW_VM; 964 else 965 reipl_method = REIPL_METHOD_CCW_CIO; 966 reipl_block_actual = reipl_block_ccw; 967 break; 968 case IPL_TYPE_FCP: 969 if (diag308_set_works) 970 reipl_method = REIPL_METHOD_FCP_RW_DIAG; 971 else if (MACHINE_IS_VM) 972 reipl_method = REIPL_METHOD_FCP_RO_VM; 973 else 974 reipl_method = REIPL_METHOD_FCP_RO_DIAG; 975 reipl_block_actual = reipl_block_fcp; 976 break; 977 case IPL_TYPE_FCP_DUMP: 978 reipl_method = REIPL_METHOD_FCP_DUMP; 979 break; 980 case IPL_TYPE_NSS: 981 if (diag308_set_works) 982 reipl_method = REIPL_METHOD_NSS_DIAG; 983 else 984 reipl_method = REIPL_METHOD_NSS; 985 reipl_block_actual = reipl_block_nss; 986 break; 987 case IPL_TYPE_UNKNOWN: 988 reipl_method = REIPL_METHOD_DEFAULT; 989 break; 990 default: 991 BUG(); 992 } 993 reipl_type = type; 994 return 0; 995 } 996 997 static ssize_t reipl_type_show(struct kobject *kobj, 998 struct kobj_attribute *attr, char *page) 999 { 1000 return sprintf(page, "%s\n", ipl_type_str(reipl_type)); 1001 } 1002 1003 static ssize_t reipl_type_store(struct kobject *kobj, 1004 struct kobj_attribute *attr, 1005 const char *buf, size_t len) 1006 { 1007 int rc = -EINVAL; 1008 1009 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0) 1010 rc = reipl_set_type(IPL_TYPE_CCW); 1011 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0) 1012 rc = reipl_set_type(IPL_TYPE_FCP); 1013 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0) 1014 rc = reipl_set_type(IPL_TYPE_NSS); 1015 return (rc != 0) ? rc : len; 1016 } 1017 1018 static struct kobj_attribute reipl_type_attr = 1019 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store); 1020 1021 static struct kset *reipl_kset; 1022 static struct kset *reipl_fcp_kset; 1023 1024 static void get_ipl_string(char *dst, struct ipl_parameter_block *ipb, 1025 const enum ipl_method m) 1026 { 1027 char loadparm[LOADPARM_LEN + 1] = {}; 1028 char vmparm[DIAG308_VMPARM_SIZE + 1] = {}; 1029 char nss_name[NSS_NAME_SIZE + 1] = {}; 1030 size_t pos = 0; 1031 1032 reipl_get_ascii_loadparm(loadparm, ipb); 1033 reipl_get_ascii_nss_name(nss_name, ipb); 1034 reipl_get_ascii_vmparm(vmparm, sizeof(vmparm), ipb); 1035 1036 switch (m) { 1037 case REIPL_METHOD_CCW_VM: 1038 pos = sprintf(dst, "IPL %X CLEAR", ipb->ipl_info.ccw.devno); 1039 break; 1040 case REIPL_METHOD_NSS: 1041 pos = sprintf(dst, "IPL %s", nss_name); 1042 break; 1043 default: 1044 break; 1045 } 1046 if (strlen(loadparm) > 0) 1047 pos += sprintf(dst + pos, " LOADPARM '%s'", loadparm); 1048 if (strlen(vmparm) > 0) 1049 sprintf(dst + pos, " PARM %s", vmparm); 1050 } 1051 1052 static void __reipl_run(void *unused) 1053 { 1054 struct ccw_dev_id devid; 1055 static char buf[128]; 1056 1057 switch (reipl_method) { 1058 case REIPL_METHOD_CCW_CIO: 1059 devid.devno = reipl_block_ccw->ipl_info.ccw.devno; 1060 devid.ssid = 0; 1061 reipl_ccw_dev(&devid); 1062 break; 1063 case REIPL_METHOD_CCW_VM: 1064 get_ipl_string(buf, reipl_block_ccw, REIPL_METHOD_CCW_VM); 1065 __cpcmd(buf, NULL, 0, NULL); 1066 break; 1067 case REIPL_METHOD_CCW_DIAG: 1068 diag308(DIAG308_SET, reipl_block_ccw); 1069 diag308(DIAG308_IPL, NULL); 1070 break; 1071 case REIPL_METHOD_FCP_RW_DIAG: 1072 diag308(DIAG308_SET, reipl_block_fcp); 1073 diag308(DIAG308_IPL, NULL); 1074 break; 1075 case REIPL_METHOD_FCP_RO_DIAG: 1076 diag308(DIAG308_IPL, NULL); 1077 break; 1078 case REIPL_METHOD_FCP_RO_VM: 1079 __cpcmd("IPL", NULL, 0, NULL); 1080 break; 1081 case REIPL_METHOD_NSS_DIAG: 1082 diag308(DIAG308_SET, reipl_block_nss); 1083 diag308(DIAG308_IPL, NULL); 1084 break; 1085 case REIPL_METHOD_NSS: 1086 get_ipl_string(buf, reipl_block_nss, REIPL_METHOD_NSS); 1087 __cpcmd(buf, NULL, 0, NULL); 1088 break; 1089 case REIPL_METHOD_DEFAULT: 1090 if (MACHINE_IS_VM) 1091 __cpcmd("IPL", NULL, 0, NULL); 1092 diag308(DIAG308_IPL, NULL); 1093 break; 1094 case REIPL_METHOD_FCP_DUMP: 1095 break; 1096 } 1097 disabled_wait((unsigned long) __builtin_return_address(0)); 1098 } 1099 1100 static void reipl_run(struct shutdown_trigger *trigger) 1101 { 1102 smp_switch_to_ipl_cpu(__reipl_run, NULL); 1103 } 1104 1105 static void reipl_block_ccw_init(struct ipl_parameter_block *ipb) 1106 { 1107 ipb->hdr.len = IPL_PARM_BLK_CCW_LEN; 1108 ipb->hdr.version = IPL_PARM_BLOCK_VERSION; 1109 ipb->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; 1110 ipb->hdr.pbt = DIAG308_IPL_TYPE_CCW; 1111 } 1112 1113 static void reipl_block_ccw_fill_parms(struct ipl_parameter_block *ipb) 1114 { 1115 /* LOADPARM */ 1116 /* check if read scp info worked and set loadparm */ 1117 if (sclp_ipl_info.is_valid) 1118 memcpy(ipb->ipl_info.ccw.load_parm, 1119 &sclp_ipl_info.loadparm, LOADPARM_LEN); 1120 else 1121 /* read scp info failed: set empty loadparm (EBCDIC blanks) */ 1122 memset(ipb->ipl_info.ccw.load_parm, 0x40, LOADPARM_LEN); 1123 ipb->hdr.flags = DIAG308_FLAGS_LP_VALID; 1124 1125 /* VM PARM */ 1126 if (MACHINE_IS_VM && diag308_set_works && 1127 (ipl_block.ipl_info.ccw.vm_flags & DIAG308_VM_FLAGS_VP_VALID)) { 1128 1129 ipb->ipl_info.ccw.vm_flags |= DIAG308_VM_FLAGS_VP_VALID; 1130 ipb->ipl_info.ccw.vm_parm_len = 1131 ipl_block.ipl_info.ccw.vm_parm_len; 1132 memcpy(ipb->ipl_info.ccw.vm_parm, 1133 ipl_block.ipl_info.ccw.vm_parm, DIAG308_VMPARM_SIZE); 1134 } 1135 } 1136 1137 static int __init reipl_nss_init(void) 1138 { 1139 int rc; 1140 1141 if (!MACHINE_IS_VM) 1142 return 0; 1143 1144 reipl_block_nss = (void *) get_zeroed_page(GFP_KERNEL); 1145 if (!reipl_block_nss) 1146 return -ENOMEM; 1147 1148 if (!diag308_set_works) 1149 sys_reipl_nss_vmparm_attr.attr.mode = S_IRUGO; 1150 1151 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group); 1152 if (rc) 1153 return rc; 1154 1155 reipl_block_ccw_init(reipl_block_nss); 1156 if (ipl_info.type == IPL_TYPE_NSS) { 1157 memset(reipl_block_nss->ipl_info.ccw.nss_name, 1158 ' ', NSS_NAME_SIZE); 1159 memcpy(reipl_block_nss->ipl_info.ccw.nss_name, 1160 kernel_nss_name, strlen(kernel_nss_name)); 1161 ASCEBC(reipl_block_nss->ipl_info.ccw.nss_name, NSS_NAME_SIZE); 1162 reipl_block_nss->ipl_info.ccw.vm_flags |= 1163 DIAG308_VM_FLAGS_NSS_VALID; 1164 1165 reipl_block_ccw_fill_parms(reipl_block_nss); 1166 } 1167 1168 reipl_capabilities |= IPL_TYPE_NSS; 1169 return 0; 1170 } 1171 1172 static int __init reipl_ccw_init(void) 1173 { 1174 int rc; 1175 1176 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); 1177 if (!reipl_block_ccw) 1178 return -ENOMEM; 1179 1180 if (MACHINE_IS_VM) { 1181 if (!diag308_set_works) 1182 sys_reipl_ccw_vmparm_attr.attr.mode = S_IRUGO; 1183 rc = sysfs_create_group(&reipl_kset->kobj, 1184 &reipl_ccw_attr_group_vm); 1185 } else { 1186 if(!diag308_set_works) 1187 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO; 1188 rc = sysfs_create_group(&reipl_kset->kobj, 1189 &reipl_ccw_attr_group_lpar); 1190 } 1191 if (rc) 1192 return rc; 1193 1194 reipl_block_ccw_init(reipl_block_ccw); 1195 if (ipl_info.type == IPL_TYPE_CCW) { 1196 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno; 1197 reipl_block_ccw_fill_parms(reipl_block_ccw); 1198 } 1199 1200 reipl_capabilities |= IPL_TYPE_CCW; 1201 return 0; 1202 } 1203 1204 static int __init reipl_fcp_init(void) 1205 { 1206 int rc; 1207 1208 if (!diag308_set_works) { 1209 if (ipl_info.type == IPL_TYPE_FCP) { 1210 make_attrs_ro(reipl_fcp_attrs); 1211 sys_reipl_fcp_scp_data_attr.attr.mode = S_IRUGO; 1212 } else 1213 return 0; 1214 } 1215 1216 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); 1217 if (!reipl_block_fcp) 1218 return -ENOMEM; 1219 1220 /* sysfs: create fcp kset for mixing attr group and bin attrs */ 1221 reipl_fcp_kset = kset_create_and_add(IPL_FCP_STR, NULL, 1222 &reipl_kset->kobj); 1223 if (!reipl_fcp_kset) { 1224 free_page((unsigned long) reipl_block_fcp); 1225 return -ENOMEM; 1226 } 1227 1228 rc = sysfs_create_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group); 1229 if (rc) { 1230 kset_unregister(reipl_fcp_kset); 1231 free_page((unsigned long) reipl_block_fcp); 1232 return rc; 1233 } 1234 1235 rc = sysfs_create_bin_file(&reipl_fcp_kset->kobj, 1236 &sys_reipl_fcp_scp_data_attr); 1237 if (rc) { 1238 sysfs_remove_group(&reipl_fcp_kset->kobj, &reipl_fcp_attr_group); 1239 kset_unregister(reipl_fcp_kset); 1240 free_page((unsigned long) reipl_block_fcp); 1241 return rc; 1242 } 1243 1244 if (ipl_info.type == IPL_TYPE_FCP) 1245 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE); 1246 else { 1247 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; 1248 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; 1249 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; 1250 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; 1251 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL; 1252 } 1253 reipl_capabilities |= IPL_TYPE_FCP; 1254 return 0; 1255 } 1256 1257 static int __init reipl_init(void) 1258 { 1259 int rc; 1260 1261 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj); 1262 if (!reipl_kset) 1263 return -ENOMEM; 1264 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr); 1265 if (rc) { 1266 kset_unregister(reipl_kset); 1267 return rc; 1268 } 1269 rc = reipl_ccw_init(); 1270 if (rc) 1271 return rc; 1272 rc = reipl_fcp_init(); 1273 if (rc) 1274 return rc; 1275 rc = reipl_nss_init(); 1276 if (rc) 1277 return rc; 1278 rc = reipl_set_type(ipl_info.type); 1279 if (rc) 1280 return rc; 1281 return 0; 1282 } 1283 1284 static struct shutdown_action __refdata reipl_action = { 1285 .name = SHUTDOWN_ACTION_REIPL_STR, 1286 .fn = reipl_run, 1287 .init = reipl_init, 1288 }; 1289 1290 /* 1291 * dump shutdown action: Dump Linux on shutdown. 1292 */ 1293 1294 /* FCP dump device attributes */ 1295 1296 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n", 1297 dump_block_fcp->ipl_info.fcp.wwpn); 1298 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n", 1299 dump_block_fcp->ipl_info.fcp.lun); 1300 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n", 1301 dump_block_fcp->ipl_info.fcp.bootprog); 1302 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n", 1303 dump_block_fcp->ipl_info.fcp.br_lba); 1304 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", 1305 dump_block_fcp->ipl_info.fcp.devno); 1306 1307 static struct attribute *dump_fcp_attrs[] = { 1308 &sys_dump_fcp_device_attr.attr, 1309 &sys_dump_fcp_wwpn_attr.attr, 1310 &sys_dump_fcp_lun_attr.attr, 1311 &sys_dump_fcp_bootprog_attr.attr, 1312 &sys_dump_fcp_br_lba_attr.attr, 1313 NULL, 1314 }; 1315 1316 static struct attribute_group dump_fcp_attr_group = { 1317 .name = IPL_FCP_STR, 1318 .attrs = dump_fcp_attrs, 1319 }; 1320 1321 /* CCW dump device attributes */ 1322 1323 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", 1324 dump_block_ccw->ipl_info.ccw.devno); 1325 1326 static struct attribute *dump_ccw_attrs[] = { 1327 &sys_dump_ccw_device_attr.attr, 1328 NULL, 1329 }; 1330 1331 static struct attribute_group dump_ccw_attr_group = { 1332 .name = IPL_CCW_STR, 1333 .attrs = dump_ccw_attrs, 1334 }; 1335 1336 /* dump type */ 1337 1338 static int dump_set_type(enum dump_type type) 1339 { 1340 if (!(dump_capabilities & type)) 1341 return -EINVAL; 1342 switch (type) { 1343 case DUMP_TYPE_CCW: 1344 if (diag308_set_works) 1345 dump_method = DUMP_METHOD_CCW_DIAG; 1346 else if (MACHINE_IS_VM) 1347 dump_method = DUMP_METHOD_CCW_VM; 1348 else 1349 dump_method = DUMP_METHOD_CCW_CIO; 1350 break; 1351 case DUMP_TYPE_FCP: 1352 dump_method = DUMP_METHOD_FCP_DIAG; 1353 break; 1354 default: 1355 dump_method = DUMP_METHOD_NONE; 1356 } 1357 dump_type = type; 1358 return 0; 1359 } 1360 1361 static ssize_t dump_type_show(struct kobject *kobj, 1362 struct kobj_attribute *attr, char *page) 1363 { 1364 return sprintf(page, "%s\n", dump_type_str(dump_type)); 1365 } 1366 1367 static ssize_t dump_type_store(struct kobject *kobj, 1368 struct kobj_attribute *attr, 1369 const char *buf, size_t len) 1370 { 1371 int rc = -EINVAL; 1372 1373 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0) 1374 rc = dump_set_type(DUMP_TYPE_NONE); 1375 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0) 1376 rc = dump_set_type(DUMP_TYPE_CCW); 1377 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0) 1378 rc = dump_set_type(DUMP_TYPE_FCP); 1379 return (rc != 0) ? rc : len; 1380 } 1381 1382 static struct kobj_attribute dump_type_attr = 1383 __ATTR(dump_type, 0644, dump_type_show, dump_type_store); 1384 1385 static struct kset *dump_kset; 1386 1387 static void __dump_run(void *unused) 1388 { 1389 struct ccw_dev_id devid; 1390 static char buf[100]; 1391 1392 switch (dump_method) { 1393 case DUMP_METHOD_CCW_CIO: 1394 devid.devno = dump_block_ccw->ipl_info.ccw.devno; 1395 devid.ssid = 0; 1396 reipl_ccw_dev(&devid); 1397 break; 1398 case DUMP_METHOD_CCW_VM: 1399 sprintf(buf, "STORE STATUS"); 1400 __cpcmd(buf, NULL, 0, NULL); 1401 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno); 1402 __cpcmd(buf, NULL, 0, NULL); 1403 break; 1404 case DUMP_METHOD_CCW_DIAG: 1405 diag308(DIAG308_SET, dump_block_ccw); 1406 diag308(DIAG308_DUMP, NULL); 1407 break; 1408 case DUMP_METHOD_FCP_DIAG: 1409 diag308(DIAG308_SET, dump_block_fcp); 1410 diag308(DIAG308_DUMP, NULL); 1411 break; 1412 default: 1413 break; 1414 } 1415 } 1416 1417 static void dump_run(struct shutdown_trigger *trigger) 1418 { 1419 if (dump_method == DUMP_METHOD_NONE) 1420 return; 1421 smp_send_stop(); 1422 smp_switch_to_ipl_cpu(__dump_run, NULL); 1423 } 1424 1425 static int __init dump_ccw_init(void) 1426 { 1427 int rc; 1428 1429 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); 1430 if (!dump_block_ccw) 1431 return -ENOMEM; 1432 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group); 1433 if (rc) { 1434 free_page((unsigned long)dump_block_ccw); 1435 return rc; 1436 } 1437 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; 1438 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; 1439 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; 1440 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; 1441 dump_capabilities |= DUMP_TYPE_CCW; 1442 return 0; 1443 } 1444 1445 static int __init dump_fcp_init(void) 1446 { 1447 int rc; 1448 1449 if (!sclp_ipl_info.has_dump) 1450 return 0; /* LDIPL DUMP is not installed */ 1451 if (!diag308_set_works) 1452 return 0; 1453 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); 1454 if (!dump_block_fcp) 1455 return -ENOMEM; 1456 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group); 1457 if (rc) { 1458 free_page((unsigned long)dump_block_fcp); 1459 return rc; 1460 } 1461 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; 1462 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; 1463 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; 1464 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; 1465 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP; 1466 dump_capabilities |= DUMP_TYPE_FCP; 1467 return 0; 1468 } 1469 1470 static int __init dump_init(void) 1471 { 1472 int rc; 1473 1474 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj); 1475 if (!dump_kset) 1476 return -ENOMEM; 1477 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr); 1478 if (rc) { 1479 kset_unregister(dump_kset); 1480 return rc; 1481 } 1482 rc = dump_ccw_init(); 1483 if (rc) 1484 return rc; 1485 rc = dump_fcp_init(); 1486 if (rc) 1487 return rc; 1488 dump_set_type(DUMP_TYPE_NONE); 1489 return 0; 1490 } 1491 1492 static struct shutdown_action __refdata dump_action = { 1493 .name = SHUTDOWN_ACTION_DUMP_STR, 1494 .fn = dump_run, 1495 .init = dump_init, 1496 }; 1497 1498 static void dump_reipl_run(struct shutdown_trigger *trigger) 1499 { 1500 preempt_disable(); 1501 /* 1502 * Bypass dynamic address translation (DAT) when storing IPL parameter 1503 * information block address and checksum into the prefix area 1504 * (corresponding to absolute addresses 0-8191). 1505 * When enhanced DAT applies and the STE format control in one, 1506 * the absolute address is formed without prefixing. In this case a 1507 * normal store (stg/st) into the prefix area would no more match to 1508 * absolute addresses 0-8191. 1509 */ 1510 #ifdef CONFIG_64BIT 1511 asm volatile("sturg %0,%1" 1512 :: "a" ((unsigned long) reipl_block_actual), 1513 "a" (&lowcore_ptr[smp_processor_id()]->ipib)); 1514 #else 1515 asm volatile("stura %0,%1" 1516 :: "a" ((unsigned long) reipl_block_actual), 1517 "a" (&lowcore_ptr[smp_processor_id()]->ipib)); 1518 #endif 1519 asm volatile("stura %0,%1" 1520 :: "a" (csum_partial(reipl_block_actual, 1521 reipl_block_actual->hdr.len, 0)), 1522 "a" (&lowcore_ptr[smp_processor_id()]->ipib_checksum)); 1523 preempt_enable(); 1524 dump_run(trigger); 1525 } 1526 1527 static int __init dump_reipl_init(void) 1528 { 1529 if (!diag308_set_works) 1530 return -EOPNOTSUPP; 1531 else 1532 return 0; 1533 } 1534 1535 static struct shutdown_action __refdata dump_reipl_action = { 1536 .name = SHUTDOWN_ACTION_DUMP_REIPL_STR, 1537 .fn = dump_reipl_run, 1538 .init = dump_reipl_init, 1539 }; 1540 1541 /* 1542 * vmcmd shutdown action: Trigger vm command on shutdown. 1543 */ 1544 1545 static char vmcmd_on_reboot[128]; 1546 static char vmcmd_on_panic[128]; 1547 static char vmcmd_on_halt[128]; 1548 static char vmcmd_on_poff[128]; 1549 static char vmcmd_on_restart[128]; 1550 1551 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot); 1552 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic); 1553 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt); 1554 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff); 1555 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_restart, "%s\n", "%s\n", vmcmd_on_restart); 1556 1557 static struct attribute *vmcmd_attrs[] = { 1558 &sys_vmcmd_on_reboot_attr.attr, 1559 &sys_vmcmd_on_panic_attr.attr, 1560 &sys_vmcmd_on_halt_attr.attr, 1561 &sys_vmcmd_on_poff_attr.attr, 1562 &sys_vmcmd_on_restart_attr.attr, 1563 NULL, 1564 }; 1565 1566 static struct attribute_group vmcmd_attr_group = { 1567 .attrs = vmcmd_attrs, 1568 }; 1569 1570 static struct kset *vmcmd_kset; 1571 1572 static void vmcmd_run(struct shutdown_trigger *trigger) 1573 { 1574 char *cmd, *next_cmd; 1575 1576 if (strcmp(trigger->name, ON_REIPL_STR) == 0) 1577 cmd = vmcmd_on_reboot; 1578 else if (strcmp(trigger->name, ON_PANIC_STR) == 0) 1579 cmd = vmcmd_on_panic; 1580 else if (strcmp(trigger->name, ON_HALT_STR) == 0) 1581 cmd = vmcmd_on_halt; 1582 else if (strcmp(trigger->name, ON_POFF_STR) == 0) 1583 cmd = vmcmd_on_poff; 1584 else if (strcmp(trigger->name, ON_RESTART_STR) == 0) 1585 cmd = vmcmd_on_restart; 1586 else 1587 return; 1588 1589 if (strlen(cmd) == 0) 1590 return; 1591 do { 1592 next_cmd = strchr(cmd, '\n'); 1593 if (next_cmd) { 1594 next_cmd[0] = 0; 1595 next_cmd += 1; 1596 } 1597 __cpcmd(cmd, NULL, 0, NULL); 1598 cmd = next_cmd; 1599 } while (cmd != NULL); 1600 } 1601 1602 static int vmcmd_init(void) 1603 { 1604 if (!MACHINE_IS_VM) 1605 return -EOPNOTSUPP; 1606 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj); 1607 if (!vmcmd_kset) 1608 return -ENOMEM; 1609 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group); 1610 } 1611 1612 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR, 1613 vmcmd_run, vmcmd_init}; 1614 1615 /* 1616 * stop shutdown action: Stop Linux on shutdown. 1617 */ 1618 1619 static void stop_run(struct shutdown_trigger *trigger) 1620 { 1621 if (strcmp(trigger->name, ON_PANIC_STR) == 0 || 1622 strcmp(trigger->name, ON_RESTART_STR) == 0) 1623 disabled_wait((unsigned long) __builtin_return_address(0)); 1624 while (sigp(smp_processor_id(), sigp_stop) == sigp_busy) 1625 cpu_relax(); 1626 for (;;); 1627 } 1628 1629 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR, 1630 stop_run, NULL}; 1631 1632 /* action list */ 1633 1634 static struct shutdown_action *shutdown_actions_list[] = { 1635 &ipl_action, &reipl_action, &dump_reipl_action, &dump_action, 1636 &vmcmd_action, &stop_action}; 1637 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *)) 1638 1639 /* 1640 * Trigger section 1641 */ 1642 1643 static struct kset *shutdown_actions_kset; 1644 1645 static int set_trigger(const char *buf, struct shutdown_trigger *trigger, 1646 size_t len) 1647 { 1648 int i; 1649 1650 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { 1651 if (sysfs_streq(buf, shutdown_actions_list[i]->name)) { 1652 if (shutdown_actions_list[i]->init_rc) { 1653 return shutdown_actions_list[i]->init_rc; 1654 } else { 1655 trigger->action = shutdown_actions_list[i]; 1656 return len; 1657 } 1658 } 1659 } 1660 return -EINVAL; 1661 } 1662 1663 /* on reipl */ 1664 1665 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR, 1666 &reipl_action}; 1667 1668 static ssize_t on_reboot_show(struct kobject *kobj, 1669 struct kobj_attribute *attr, char *page) 1670 { 1671 return sprintf(page, "%s\n", on_reboot_trigger.action->name); 1672 } 1673 1674 static ssize_t on_reboot_store(struct kobject *kobj, 1675 struct kobj_attribute *attr, 1676 const char *buf, size_t len) 1677 { 1678 return set_trigger(buf, &on_reboot_trigger, len); 1679 } 1680 1681 static struct kobj_attribute on_reboot_attr = 1682 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store); 1683 1684 static void do_machine_restart(char *__unused) 1685 { 1686 smp_send_stop(); 1687 on_reboot_trigger.action->fn(&on_reboot_trigger); 1688 reipl_run(NULL); 1689 } 1690 void (*_machine_restart)(char *command) = do_machine_restart; 1691 1692 /* on panic */ 1693 1694 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action}; 1695 1696 static ssize_t on_panic_show(struct kobject *kobj, 1697 struct kobj_attribute *attr, char *page) 1698 { 1699 return sprintf(page, "%s\n", on_panic_trigger.action->name); 1700 } 1701 1702 static ssize_t on_panic_store(struct kobject *kobj, 1703 struct kobj_attribute *attr, 1704 const char *buf, size_t len) 1705 { 1706 return set_trigger(buf, &on_panic_trigger, len); 1707 } 1708 1709 static struct kobj_attribute on_panic_attr = 1710 __ATTR(on_panic, 0644, on_panic_show, on_panic_store); 1711 1712 static void do_panic(void) 1713 { 1714 on_panic_trigger.action->fn(&on_panic_trigger); 1715 stop_run(&on_panic_trigger); 1716 } 1717 1718 /* on restart */ 1719 1720 static struct shutdown_trigger on_restart_trigger = {ON_RESTART_STR, 1721 &stop_action}; 1722 1723 static ssize_t on_restart_show(struct kobject *kobj, 1724 struct kobj_attribute *attr, char *page) 1725 { 1726 return sprintf(page, "%s\n", on_restart_trigger.action->name); 1727 } 1728 1729 static ssize_t on_restart_store(struct kobject *kobj, 1730 struct kobj_attribute *attr, 1731 const char *buf, size_t len) 1732 { 1733 return set_trigger(buf, &on_restart_trigger, len); 1734 } 1735 1736 static struct kobj_attribute on_restart_attr = 1737 __ATTR(on_restart, 0644, on_restart_show, on_restart_store); 1738 1739 void do_restart(void) 1740 { 1741 smp_send_stop(); 1742 on_restart_trigger.action->fn(&on_restart_trigger); 1743 stop_run(&on_restart_trigger); 1744 } 1745 1746 /* on halt */ 1747 1748 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action}; 1749 1750 static ssize_t on_halt_show(struct kobject *kobj, 1751 struct kobj_attribute *attr, char *page) 1752 { 1753 return sprintf(page, "%s\n", on_halt_trigger.action->name); 1754 } 1755 1756 static ssize_t on_halt_store(struct kobject *kobj, 1757 struct kobj_attribute *attr, 1758 const char *buf, size_t len) 1759 { 1760 return set_trigger(buf, &on_halt_trigger, len); 1761 } 1762 1763 static struct kobj_attribute on_halt_attr = 1764 __ATTR(on_halt, 0644, on_halt_show, on_halt_store); 1765 1766 1767 static void do_machine_halt(void) 1768 { 1769 smp_send_stop(); 1770 on_halt_trigger.action->fn(&on_halt_trigger); 1771 stop_run(&on_halt_trigger); 1772 } 1773 void (*_machine_halt)(void) = do_machine_halt; 1774 1775 /* on power off */ 1776 1777 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action}; 1778 1779 static ssize_t on_poff_show(struct kobject *kobj, 1780 struct kobj_attribute *attr, char *page) 1781 { 1782 return sprintf(page, "%s\n", on_poff_trigger.action->name); 1783 } 1784 1785 static ssize_t on_poff_store(struct kobject *kobj, 1786 struct kobj_attribute *attr, 1787 const char *buf, size_t len) 1788 { 1789 return set_trigger(buf, &on_poff_trigger, len); 1790 } 1791 1792 static struct kobj_attribute on_poff_attr = 1793 __ATTR(on_poff, 0644, on_poff_show, on_poff_store); 1794 1795 1796 static void do_machine_power_off(void) 1797 { 1798 smp_send_stop(); 1799 on_poff_trigger.action->fn(&on_poff_trigger); 1800 stop_run(&on_poff_trigger); 1801 } 1802 void (*_machine_power_off)(void) = do_machine_power_off; 1803 1804 static void __init shutdown_triggers_init(void) 1805 { 1806 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL, 1807 firmware_kobj); 1808 if (!shutdown_actions_kset) 1809 goto fail; 1810 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1811 &on_reboot_attr.attr)) 1812 goto fail; 1813 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1814 &on_panic_attr.attr)) 1815 goto fail; 1816 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1817 &on_halt_attr.attr)) 1818 goto fail; 1819 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1820 &on_poff_attr.attr)) 1821 goto fail; 1822 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1823 &on_restart_attr.attr)) 1824 goto fail; 1825 return; 1826 fail: 1827 panic("shutdown_triggers_init failed\n"); 1828 } 1829 1830 static void __init shutdown_actions_init(void) 1831 { 1832 int i; 1833 1834 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { 1835 if (!shutdown_actions_list[i]->init) 1836 continue; 1837 shutdown_actions_list[i]->init_rc = 1838 shutdown_actions_list[i]->init(); 1839 } 1840 } 1841 1842 static int __init s390_ipl_init(void) 1843 { 1844 sclp_get_ipl_info(&sclp_ipl_info); 1845 shutdown_actions_init(); 1846 shutdown_triggers_init(); 1847 return 0; 1848 } 1849 1850 __initcall(s390_ipl_init); 1851 1852 static void __init strncpy_skip_quote(char *dst, char *src, int n) 1853 { 1854 int sx, dx; 1855 1856 dx = 0; 1857 for (sx = 0; src[sx] != 0; sx++) { 1858 if (src[sx] == '"') 1859 continue; 1860 dst[dx++] = src[sx]; 1861 if (dx >= n) 1862 break; 1863 } 1864 } 1865 1866 static int __init vmcmd_on_reboot_setup(char *str) 1867 { 1868 if (!MACHINE_IS_VM) 1869 return 1; 1870 strncpy_skip_quote(vmcmd_on_reboot, str, 127); 1871 vmcmd_on_reboot[127] = 0; 1872 on_reboot_trigger.action = &vmcmd_action; 1873 return 1; 1874 } 1875 __setup("vmreboot=", vmcmd_on_reboot_setup); 1876 1877 static int __init vmcmd_on_panic_setup(char *str) 1878 { 1879 if (!MACHINE_IS_VM) 1880 return 1; 1881 strncpy_skip_quote(vmcmd_on_panic, str, 127); 1882 vmcmd_on_panic[127] = 0; 1883 on_panic_trigger.action = &vmcmd_action; 1884 return 1; 1885 } 1886 __setup("vmpanic=", vmcmd_on_panic_setup); 1887 1888 static int __init vmcmd_on_halt_setup(char *str) 1889 { 1890 if (!MACHINE_IS_VM) 1891 return 1; 1892 strncpy_skip_quote(vmcmd_on_halt, str, 127); 1893 vmcmd_on_halt[127] = 0; 1894 on_halt_trigger.action = &vmcmd_action; 1895 return 1; 1896 } 1897 __setup("vmhalt=", vmcmd_on_halt_setup); 1898 1899 static int __init vmcmd_on_poff_setup(char *str) 1900 { 1901 if (!MACHINE_IS_VM) 1902 return 1; 1903 strncpy_skip_quote(vmcmd_on_poff, str, 127); 1904 vmcmd_on_poff[127] = 0; 1905 on_poff_trigger.action = &vmcmd_action; 1906 return 1; 1907 } 1908 __setup("vmpoff=", vmcmd_on_poff_setup); 1909 1910 static int on_panic_notify(struct notifier_block *self, 1911 unsigned long event, void *data) 1912 { 1913 do_panic(); 1914 return NOTIFY_OK; 1915 } 1916 1917 static struct notifier_block on_panic_nb = { 1918 .notifier_call = on_panic_notify, 1919 .priority = INT_MIN, 1920 }; 1921 1922 void __init setup_ipl(void) 1923 { 1924 ipl_info.type = get_ipl_type(); 1925 switch (ipl_info.type) { 1926 case IPL_TYPE_CCW: 1927 ipl_info.data.ccw.dev_id.devno = ipl_devno; 1928 ipl_info.data.ccw.dev_id.ssid = 0; 1929 break; 1930 case IPL_TYPE_FCP: 1931 case IPL_TYPE_FCP_DUMP: 1932 ipl_info.data.fcp.dev_id.devno = 1933 IPL_PARMBLOCK_START->ipl_info.fcp.devno; 1934 ipl_info.data.fcp.dev_id.ssid = 0; 1935 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn; 1936 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun; 1937 break; 1938 case IPL_TYPE_NSS: 1939 strncpy(ipl_info.data.nss.name, kernel_nss_name, 1940 sizeof(ipl_info.data.nss.name)); 1941 break; 1942 case IPL_TYPE_UNKNOWN: 1943 /* We have no info to copy */ 1944 break; 1945 } 1946 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb); 1947 } 1948 1949 void __init ipl_update_parameters(void) 1950 { 1951 int rc; 1952 1953 rc = diag308(DIAG308_STORE, &ipl_block); 1954 if ((rc == DIAG308_RC_OK) || (rc == DIAG308_RC_NOCONFIG)) 1955 diag308_set_works = 1; 1956 } 1957 1958 void __init ipl_save_parameters(void) 1959 { 1960 struct cio_iplinfo iplinfo; 1961 void *src, *dst; 1962 1963 if (cio_get_iplinfo(&iplinfo)) 1964 return; 1965 1966 ipl_devno = iplinfo.devno; 1967 ipl_flags |= IPL_DEVNO_VALID; 1968 if (!iplinfo.is_qdio) 1969 return; 1970 ipl_flags |= IPL_PARMBLOCK_VALID; 1971 src = (void *)(unsigned long)S390_lowcore.ipl_parmblock_ptr; 1972 dst = (void *)IPL_PARMBLOCK_ORIGIN; 1973 memmove(dst, src, PAGE_SIZE); 1974 S390_lowcore.ipl_parmblock_ptr = IPL_PARMBLOCK_ORIGIN; 1975 } 1976 1977 static LIST_HEAD(rcall); 1978 static DEFINE_MUTEX(rcall_mutex); 1979 1980 void register_reset_call(struct reset_call *reset) 1981 { 1982 mutex_lock(&rcall_mutex); 1983 list_add(&reset->list, &rcall); 1984 mutex_unlock(&rcall_mutex); 1985 } 1986 EXPORT_SYMBOL_GPL(register_reset_call); 1987 1988 void unregister_reset_call(struct reset_call *reset) 1989 { 1990 mutex_lock(&rcall_mutex); 1991 list_del(&reset->list); 1992 mutex_unlock(&rcall_mutex); 1993 } 1994 EXPORT_SYMBOL_GPL(unregister_reset_call); 1995 1996 static void do_reset_calls(void) 1997 { 1998 struct reset_call *reset; 1999 2000 #ifdef CONFIG_64BIT 2001 if (diag308_set_works) { 2002 diag308_reset(); 2003 return; 2004 } 2005 #endif 2006 list_for_each_entry(reset, &rcall, list) 2007 reset->fn(); 2008 } 2009 2010 u32 dump_prefix_page; 2011 2012 void s390_reset_system(void) 2013 { 2014 struct _lowcore *lc; 2015 2016 lc = (struct _lowcore *)(unsigned long) store_prefix(); 2017 2018 /* Stack for interrupt/machine check handler */ 2019 lc->panic_stack = S390_lowcore.panic_stack; 2020 2021 /* Save prefix page address for dump case */ 2022 dump_prefix_page = (u32)(unsigned long) lc; 2023 2024 /* Disable prefixing */ 2025 set_prefix(0); 2026 2027 /* Disable lowcore protection */ 2028 __ctl_clear_bit(0,28); 2029 2030 /* Set new machine check handler */ 2031 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK; 2032 S390_lowcore.mcck_new_psw.addr = 2033 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler; 2034 2035 /* Set new program check handler */ 2036 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK; 2037 S390_lowcore.program_new_psw.addr = 2038 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler; 2039 2040 do_reset_calls(); 2041 } 2042 2043