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 <asm/ipl.h> 18 #include <asm/smp.h> 19 #include <asm/setup.h> 20 #include <asm/cpcmd.h> 21 #include <asm/cio.h> 22 #include <asm/ebcdic.h> 23 #include <asm/reset.h> 24 #include <asm/sclp.h> 25 26 #define IPL_PARM_BLOCK_VERSION 0 27 28 #define IPL_UNKNOWN_STR "unknown" 29 #define IPL_CCW_STR "ccw" 30 #define IPL_FCP_STR "fcp" 31 #define IPL_FCP_DUMP_STR "fcp_dump" 32 #define IPL_NSS_STR "nss" 33 34 #define DUMP_CCW_STR "ccw" 35 #define DUMP_FCP_STR "fcp" 36 #define DUMP_NONE_STR "none" 37 38 /* 39 * Four shutdown trigger types are supported: 40 * - panic 41 * - halt 42 * - power off 43 * - reipl 44 */ 45 #define ON_PANIC_STR "on_panic" 46 #define ON_HALT_STR "on_halt" 47 #define ON_POFF_STR "on_poff" 48 #define ON_REIPL_STR "on_reboot" 49 50 struct shutdown_action; 51 struct shutdown_trigger { 52 char *name; 53 struct shutdown_action *action; 54 }; 55 56 /* 57 * Five shutdown action types are supported: 58 */ 59 #define SHUTDOWN_ACTION_IPL_STR "ipl" 60 #define SHUTDOWN_ACTION_REIPL_STR "reipl" 61 #define SHUTDOWN_ACTION_DUMP_STR "dump" 62 #define SHUTDOWN_ACTION_VMCMD_STR "vmcmd" 63 #define SHUTDOWN_ACTION_STOP_STR "stop" 64 65 struct shutdown_action { 66 char *name; 67 void (*fn) (struct shutdown_trigger *trigger); 68 int (*init) (void); 69 }; 70 71 static char *ipl_type_str(enum ipl_type type) 72 { 73 switch (type) { 74 case IPL_TYPE_CCW: 75 return IPL_CCW_STR; 76 case IPL_TYPE_FCP: 77 return IPL_FCP_STR; 78 case IPL_TYPE_FCP_DUMP: 79 return IPL_FCP_DUMP_STR; 80 case IPL_TYPE_NSS: 81 return IPL_NSS_STR; 82 case IPL_TYPE_UNKNOWN: 83 default: 84 return IPL_UNKNOWN_STR; 85 } 86 } 87 88 enum dump_type { 89 DUMP_TYPE_NONE = 1, 90 DUMP_TYPE_CCW = 2, 91 DUMP_TYPE_FCP = 4, 92 }; 93 94 static char *dump_type_str(enum dump_type type) 95 { 96 switch (type) { 97 case DUMP_TYPE_NONE: 98 return DUMP_NONE_STR; 99 case DUMP_TYPE_CCW: 100 return DUMP_CCW_STR; 101 case DUMP_TYPE_FCP: 102 return DUMP_FCP_STR; 103 default: 104 return NULL; 105 } 106 } 107 108 /* 109 * Must be in data section since the bss section 110 * is not cleared when these are accessed. 111 */ 112 static u16 ipl_devno __attribute__((__section__(".data"))) = 0; 113 u32 ipl_flags __attribute__((__section__(".data"))) = 0; 114 115 enum ipl_method { 116 REIPL_METHOD_CCW_CIO, 117 REIPL_METHOD_CCW_DIAG, 118 REIPL_METHOD_CCW_VM, 119 REIPL_METHOD_FCP_RO_DIAG, 120 REIPL_METHOD_FCP_RW_DIAG, 121 REIPL_METHOD_FCP_RO_VM, 122 REIPL_METHOD_FCP_DUMP, 123 REIPL_METHOD_NSS, 124 REIPL_METHOD_DEFAULT, 125 }; 126 127 enum dump_method { 128 DUMP_METHOD_NONE, 129 DUMP_METHOD_CCW_CIO, 130 DUMP_METHOD_CCW_DIAG, 131 DUMP_METHOD_CCW_VM, 132 DUMP_METHOD_FCP_DIAG, 133 }; 134 135 static int diag308_set_works = 0; 136 137 static int reipl_capabilities = IPL_TYPE_UNKNOWN; 138 139 static enum ipl_type reipl_type = IPL_TYPE_UNKNOWN; 140 static enum ipl_method reipl_method = REIPL_METHOD_DEFAULT; 141 static struct ipl_parameter_block *reipl_block_fcp; 142 static struct ipl_parameter_block *reipl_block_ccw; 143 144 static char reipl_nss_name[NSS_NAME_SIZE + 1]; 145 146 static int dump_capabilities = DUMP_TYPE_NONE; 147 static enum dump_type dump_type = DUMP_TYPE_NONE; 148 static enum dump_method dump_method = DUMP_METHOD_NONE; 149 static struct ipl_parameter_block *dump_block_fcp; 150 static struct ipl_parameter_block *dump_block_ccw; 151 152 static struct sclp_ipl_info sclp_ipl_info; 153 154 int diag308(unsigned long subcode, void *addr) 155 { 156 register unsigned long _addr asm("0") = (unsigned long) addr; 157 register unsigned long _rc asm("1") = 0; 158 159 asm volatile( 160 " diag %0,%2,0x308\n" 161 "0:\n" 162 EX_TABLE(0b,0b) 163 : "+d" (_addr), "+d" (_rc) 164 : "d" (subcode) : "cc", "memory"); 165 return _rc; 166 } 167 EXPORT_SYMBOL_GPL(diag308); 168 169 /* SYSFS */ 170 171 #define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \ 172 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ 173 struct kobj_attribute *attr, \ 174 char *page) \ 175 { \ 176 return sprintf(page, _format, _value); \ 177 } \ 178 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ 179 __ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL); 180 181 #define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \ 182 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ 183 struct kobj_attribute *attr, \ 184 char *page) \ 185 { \ 186 return sprintf(page, _fmt_out, \ 187 (unsigned long long) _value); \ 188 } \ 189 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ 190 struct kobj_attribute *attr, \ 191 const char *buf, size_t len) \ 192 { \ 193 unsigned long long value; \ 194 if (sscanf(buf, _fmt_in, &value) != 1) \ 195 return -EINVAL; \ 196 _value = value; \ 197 return len; \ 198 } \ 199 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ 200 __ATTR(_name,(S_IRUGO | S_IWUSR), \ 201 sys_##_prefix##_##_name##_show, \ 202 sys_##_prefix##_##_name##_store); 203 204 #define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\ 205 static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \ 206 struct kobj_attribute *attr, \ 207 char *page) \ 208 { \ 209 return sprintf(page, _fmt_out, _value); \ 210 } \ 211 static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ 212 struct kobj_attribute *attr, \ 213 const char *buf, size_t len) \ 214 { \ 215 strncpy(_value, buf, sizeof(_value) - 1); \ 216 strstrip(_value); \ 217 return len; \ 218 } \ 219 static struct kobj_attribute sys_##_prefix##_##_name##_attr = \ 220 __ATTR(_name,(S_IRUGO | S_IWUSR), \ 221 sys_##_prefix##_##_name##_show, \ 222 sys_##_prefix##_##_name##_store); 223 224 static void make_attrs_ro(struct attribute **attrs) 225 { 226 while (*attrs) { 227 (*attrs)->mode = S_IRUGO; 228 attrs++; 229 } 230 } 231 232 /* 233 * ipl section 234 */ 235 236 static __init enum ipl_type get_ipl_type(void) 237 { 238 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; 239 240 if (ipl_flags & IPL_NSS_VALID) 241 return IPL_TYPE_NSS; 242 if (!(ipl_flags & IPL_DEVNO_VALID)) 243 return IPL_TYPE_UNKNOWN; 244 if (!(ipl_flags & IPL_PARMBLOCK_VALID)) 245 return IPL_TYPE_CCW; 246 if (ipl->hdr.version > IPL_MAX_SUPPORTED_VERSION) 247 return IPL_TYPE_UNKNOWN; 248 if (ipl->hdr.pbt != DIAG308_IPL_TYPE_FCP) 249 return IPL_TYPE_UNKNOWN; 250 if (ipl->ipl_info.fcp.opt == DIAG308_IPL_OPT_DUMP) 251 return IPL_TYPE_FCP_DUMP; 252 return IPL_TYPE_FCP; 253 } 254 255 struct ipl_info ipl_info; 256 EXPORT_SYMBOL_GPL(ipl_info); 257 258 static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr, 259 char *page) 260 { 261 return sprintf(page, "%s\n", ipl_type_str(ipl_info.type)); 262 } 263 264 static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type); 265 266 static ssize_t sys_ipl_device_show(struct kobject *kobj, 267 struct kobj_attribute *attr, char *page) 268 { 269 struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START; 270 271 switch (ipl_info.type) { 272 case IPL_TYPE_CCW: 273 return sprintf(page, "0.0.%04x\n", ipl_devno); 274 case IPL_TYPE_FCP: 275 case IPL_TYPE_FCP_DUMP: 276 return sprintf(page, "0.0.%04x\n", ipl->ipl_info.fcp.devno); 277 default: 278 return 0; 279 } 280 } 281 282 static struct kobj_attribute sys_ipl_device_attr = 283 __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL); 284 285 static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr, 286 char *buf, loff_t off, size_t count) 287 { 288 unsigned int size = IPL_PARMBLOCK_SIZE; 289 290 if (off > size) 291 return 0; 292 if (off + count > size) 293 count = size - off; 294 memcpy(buf, (void *)IPL_PARMBLOCK_START + off, count); 295 return count; 296 } 297 298 static struct bin_attribute ipl_parameter_attr = { 299 .attr = { 300 .name = "binary_parameter", 301 .mode = S_IRUGO, 302 }, 303 .size = PAGE_SIZE, 304 .read = &ipl_parameter_read, 305 }; 306 307 static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr, 308 char *buf, loff_t off, size_t count) 309 { 310 unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len; 311 void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data; 312 313 if (off > size) 314 return 0; 315 if (off + count > size) 316 count = size - off; 317 memcpy(buf, scp_data + off, count); 318 return count; 319 } 320 321 static struct bin_attribute ipl_scp_data_attr = { 322 .attr = { 323 .name = "scp_data", 324 .mode = S_IRUGO, 325 }, 326 .size = PAGE_SIZE, 327 .read = ipl_scp_data_read, 328 }; 329 330 /* FCP ipl device attributes */ 331 332 DEFINE_IPL_ATTR_RO(ipl_fcp, wwpn, "0x%016llx\n", (unsigned long long) 333 IPL_PARMBLOCK_START->ipl_info.fcp.wwpn); 334 DEFINE_IPL_ATTR_RO(ipl_fcp, lun, "0x%016llx\n", (unsigned long long) 335 IPL_PARMBLOCK_START->ipl_info.fcp.lun); 336 DEFINE_IPL_ATTR_RO(ipl_fcp, bootprog, "%lld\n", (unsigned long long) 337 IPL_PARMBLOCK_START->ipl_info.fcp.bootprog); 338 DEFINE_IPL_ATTR_RO(ipl_fcp, br_lba, "%lld\n", (unsigned long long) 339 IPL_PARMBLOCK_START->ipl_info.fcp.br_lba); 340 341 static struct attribute *ipl_fcp_attrs[] = { 342 &sys_ipl_type_attr.attr, 343 &sys_ipl_device_attr.attr, 344 &sys_ipl_fcp_wwpn_attr.attr, 345 &sys_ipl_fcp_lun_attr.attr, 346 &sys_ipl_fcp_bootprog_attr.attr, 347 &sys_ipl_fcp_br_lba_attr.attr, 348 NULL, 349 }; 350 351 static struct attribute_group ipl_fcp_attr_group = { 352 .attrs = ipl_fcp_attrs, 353 }; 354 355 /* CCW ipl device attributes */ 356 357 static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj, 358 struct kobj_attribute *attr, char *page) 359 { 360 char loadparm[LOADPARM_LEN + 1] = {}; 361 362 if (!sclp_ipl_info.is_valid) 363 return sprintf(page, "#unknown#\n"); 364 memcpy(loadparm, &sclp_ipl_info.loadparm, LOADPARM_LEN); 365 EBCASC(loadparm, LOADPARM_LEN); 366 strstrip(loadparm); 367 return sprintf(page, "%s\n", loadparm); 368 } 369 370 static struct kobj_attribute sys_ipl_ccw_loadparm_attr = 371 __ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL); 372 373 static struct attribute *ipl_ccw_attrs[] = { 374 &sys_ipl_type_attr.attr, 375 &sys_ipl_device_attr.attr, 376 &sys_ipl_ccw_loadparm_attr.attr, 377 NULL, 378 }; 379 380 static struct attribute_group ipl_ccw_attr_group = { 381 .attrs = ipl_ccw_attrs, 382 }; 383 384 /* NSS ipl device attributes */ 385 386 DEFINE_IPL_ATTR_RO(ipl_nss, name, "%s\n", kernel_nss_name); 387 388 static struct attribute *ipl_nss_attrs[] = { 389 &sys_ipl_type_attr.attr, 390 &sys_ipl_nss_name_attr.attr, 391 NULL, 392 }; 393 394 static struct attribute_group ipl_nss_attr_group = { 395 .attrs = ipl_nss_attrs, 396 }; 397 398 /* UNKNOWN ipl device attributes */ 399 400 static struct attribute *ipl_unknown_attrs[] = { 401 &sys_ipl_type_attr.attr, 402 NULL, 403 }; 404 405 static struct attribute_group ipl_unknown_attr_group = { 406 .attrs = ipl_unknown_attrs, 407 }; 408 409 static struct kset *ipl_kset; 410 411 static int __init ipl_register_fcp_files(void) 412 { 413 int rc; 414 415 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_fcp_attr_group); 416 if (rc) 417 goto out; 418 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_parameter_attr); 419 if (rc) 420 goto out_ipl_parm; 421 rc = sysfs_create_bin_file(&ipl_kset->kobj, &ipl_scp_data_attr); 422 if (!rc) 423 goto out; 424 425 sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr); 426 427 out_ipl_parm: 428 sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group); 429 out: 430 return rc; 431 } 432 433 static void ipl_run(struct shutdown_trigger *trigger) 434 { 435 diag308(DIAG308_IPL, NULL); 436 if (MACHINE_IS_VM) 437 __cpcmd("IPL", NULL, 0, NULL); 438 else if (ipl_info.type == IPL_TYPE_CCW) 439 reipl_ccw_dev(&ipl_info.data.ccw.dev_id); 440 } 441 442 static int ipl_init(void) 443 { 444 int rc; 445 446 ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj); 447 if (!ipl_kset) { 448 rc = -ENOMEM; 449 goto out; 450 } 451 switch (ipl_info.type) { 452 case IPL_TYPE_CCW: 453 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_ccw_attr_group); 454 break; 455 case IPL_TYPE_FCP: 456 case IPL_TYPE_FCP_DUMP: 457 rc = ipl_register_fcp_files(); 458 break; 459 case IPL_TYPE_NSS: 460 rc = sysfs_create_group(&ipl_kset->kobj, &ipl_nss_attr_group); 461 break; 462 default: 463 rc = sysfs_create_group(&ipl_kset->kobj, 464 &ipl_unknown_attr_group); 465 break; 466 } 467 out: 468 if (rc) 469 panic("ipl_init failed: rc = %i\n", rc); 470 471 return 0; 472 } 473 474 static struct shutdown_action ipl_action = {SHUTDOWN_ACTION_IPL_STR, ipl_run, 475 ipl_init}; 476 477 /* 478 * reipl shutdown action: Reboot Linux on shutdown. 479 */ 480 481 /* FCP reipl device attributes */ 482 483 DEFINE_IPL_ATTR_RW(reipl_fcp, wwpn, "0x%016llx\n", "%016llx\n", 484 reipl_block_fcp->ipl_info.fcp.wwpn); 485 DEFINE_IPL_ATTR_RW(reipl_fcp, lun, "0x%016llx\n", "%016llx\n", 486 reipl_block_fcp->ipl_info.fcp.lun); 487 DEFINE_IPL_ATTR_RW(reipl_fcp, bootprog, "%lld\n", "%lld\n", 488 reipl_block_fcp->ipl_info.fcp.bootprog); 489 DEFINE_IPL_ATTR_RW(reipl_fcp, br_lba, "%lld\n", "%lld\n", 490 reipl_block_fcp->ipl_info.fcp.br_lba); 491 DEFINE_IPL_ATTR_RW(reipl_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", 492 reipl_block_fcp->ipl_info.fcp.devno); 493 494 static struct attribute *reipl_fcp_attrs[] = { 495 &sys_reipl_fcp_device_attr.attr, 496 &sys_reipl_fcp_wwpn_attr.attr, 497 &sys_reipl_fcp_lun_attr.attr, 498 &sys_reipl_fcp_bootprog_attr.attr, 499 &sys_reipl_fcp_br_lba_attr.attr, 500 NULL, 501 }; 502 503 static struct attribute_group reipl_fcp_attr_group = { 504 .name = IPL_FCP_STR, 505 .attrs = reipl_fcp_attrs, 506 }; 507 508 /* CCW reipl device attributes */ 509 510 DEFINE_IPL_ATTR_RW(reipl_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", 511 reipl_block_ccw->ipl_info.ccw.devno); 512 513 static void reipl_get_ascii_loadparm(char *loadparm) 514 { 515 memcpy(loadparm, &reipl_block_ccw->ipl_info.ccw.load_param, 516 LOADPARM_LEN); 517 EBCASC(loadparm, LOADPARM_LEN); 518 loadparm[LOADPARM_LEN] = 0; 519 strstrip(loadparm); 520 } 521 522 static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj, 523 struct kobj_attribute *attr, char *page) 524 { 525 char buf[LOADPARM_LEN + 1]; 526 527 reipl_get_ascii_loadparm(buf); 528 return sprintf(page, "%s\n", buf); 529 } 530 531 static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj, 532 struct kobj_attribute *attr, 533 const char *buf, size_t len) 534 { 535 int i, lp_len; 536 537 /* ignore trailing newline */ 538 lp_len = len; 539 if ((len > 0) && (buf[len - 1] == '\n')) 540 lp_len--; 541 /* loadparm can have max 8 characters and must not start with a blank */ 542 if ((lp_len > LOADPARM_LEN) || ((lp_len > 0) && (buf[0] == ' '))) 543 return -EINVAL; 544 /* loadparm can only contain "a-z,A-Z,0-9,SP,." */ 545 for (i = 0; i < lp_len; i++) { 546 if (isalpha(buf[i]) || isdigit(buf[i]) || (buf[i] == ' ') || 547 (buf[i] == '.')) 548 continue; 549 return -EINVAL; 550 } 551 /* initialize loadparm with blanks */ 552 memset(&reipl_block_ccw->ipl_info.ccw.load_param, ' ', LOADPARM_LEN); 553 /* copy and convert to ebcdic */ 554 memcpy(&reipl_block_ccw->ipl_info.ccw.load_param, buf, lp_len); 555 ASCEBC(reipl_block_ccw->ipl_info.ccw.load_param, LOADPARM_LEN); 556 return len; 557 } 558 559 static struct kobj_attribute sys_reipl_ccw_loadparm_attr = 560 __ATTR(loadparm, 0644, reipl_ccw_loadparm_show, 561 reipl_ccw_loadparm_store); 562 563 static struct attribute *reipl_ccw_attrs[] = { 564 &sys_reipl_ccw_device_attr.attr, 565 &sys_reipl_ccw_loadparm_attr.attr, 566 NULL, 567 }; 568 569 static struct attribute_group reipl_ccw_attr_group = { 570 .name = IPL_CCW_STR, 571 .attrs = reipl_ccw_attrs, 572 }; 573 574 575 /* NSS reipl device attributes */ 576 577 DEFINE_IPL_ATTR_STR_RW(reipl_nss, name, "%s\n", "%s\n", reipl_nss_name); 578 579 static struct attribute *reipl_nss_attrs[] = { 580 &sys_reipl_nss_name_attr.attr, 581 NULL, 582 }; 583 584 static struct attribute_group reipl_nss_attr_group = { 585 .name = IPL_NSS_STR, 586 .attrs = reipl_nss_attrs, 587 }; 588 589 /* reipl type */ 590 591 static int reipl_set_type(enum ipl_type type) 592 { 593 if (!(reipl_capabilities & type)) 594 return -EINVAL; 595 596 switch(type) { 597 case IPL_TYPE_CCW: 598 if (diag308_set_works) 599 reipl_method = REIPL_METHOD_CCW_DIAG; 600 else if (MACHINE_IS_VM) 601 reipl_method = REIPL_METHOD_CCW_VM; 602 else 603 reipl_method = REIPL_METHOD_CCW_CIO; 604 break; 605 case IPL_TYPE_FCP: 606 if (diag308_set_works) 607 reipl_method = REIPL_METHOD_FCP_RW_DIAG; 608 else if (MACHINE_IS_VM) 609 reipl_method = REIPL_METHOD_FCP_RO_VM; 610 else 611 reipl_method = REIPL_METHOD_FCP_RO_DIAG; 612 break; 613 case IPL_TYPE_FCP_DUMP: 614 reipl_method = REIPL_METHOD_FCP_DUMP; 615 break; 616 case IPL_TYPE_NSS: 617 reipl_method = REIPL_METHOD_NSS; 618 break; 619 case IPL_TYPE_UNKNOWN: 620 reipl_method = REIPL_METHOD_DEFAULT; 621 break; 622 default: 623 BUG(); 624 } 625 reipl_type = type; 626 return 0; 627 } 628 629 static ssize_t reipl_type_show(struct kobject *kobj, 630 struct kobj_attribute *attr, char *page) 631 { 632 return sprintf(page, "%s\n", ipl_type_str(reipl_type)); 633 } 634 635 static ssize_t reipl_type_store(struct kobject *kobj, 636 struct kobj_attribute *attr, 637 const char *buf, size_t len) 638 { 639 int rc = -EINVAL; 640 641 if (strncmp(buf, IPL_CCW_STR, strlen(IPL_CCW_STR)) == 0) 642 rc = reipl_set_type(IPL_TYPE_CCW); 643 else if (strncmp(buf, IPL_FCP_STR, strlen(IPL_FCP_STR)) == 0) 644 rc = reipl_set_type(IPL_TYPE_FCP); 645 else if (strncmp(buf, IPL_NSS_STR, strlen(IPL_NSS_STR)) == 0) 646 rc = reipl_set_type(IPL_TYPE_NSS); 647 return (rc != 0) ? rc : len; 648 } 649 650 static struct kobj_attribute reipl_type_attr = 651 __ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store); 652 653 static struct kset *reipl_kset; 654 655 void reipl_run(struct shutdown_trigger *trigger) 656 { 657 struct ccw_dev_id devid; 658 static char buf[100]; 659 char loadparm[LOADPARM_LEN + 1]; 660 661 switch (reipl_method) { 662 case REIPL_METHOD_CCW_CIO: 663 devid.devno = reipl_block_ccw->ipl_info.ccw.devno; 664 devid.ssid = 0; 665 reipl_ccw_dev(&devid); 666 break; 667 case REIPL_METHOD_CCW_VM: 668 reipl_get_ascii_loadparm(loadparm); 669 if (strlen(loadparm) == 0) 670 sprintf(buf, "IPL %X CLEAR", 671 reipl_block_ccw->ipl_info.ccw.devno); 672 else 673 sprintf(buf, "IPL %X CLEAR LOADPARM '%s'", 674 reipl_block_ccw->ipl_info.ccw.devno, loadparm); 675 __cpcmd(buf, NULL, 0, NULL); 676 break; 677 case REIPL_METHOD_CCW_DIAG: 678 diag308(DIAG308_SET, reipl_block_ccw); 679 diag308(DIAG308_IPL, NULL); 680 break; 681 case REIPL_METHOD_FCP_RW_DIAG: 682 diag308(DIAG308_SET, reipl_block_fcp); 683 diag308(DIAG308_IPL, NULL); 684 break; 685 case REIPL_METHOD_FCP_RO_DIAG: 686 diag308(DIAG308_IPL, NULL); 687 break; 688 case REIPL_METHOD_FCP_RO_VM: 689 __cpcmd("IPL", NULL, 0, NULL); 690 break; 691 case REIPL_METHOD_NSS: 692 sprintf(buf, "IPL %s", reipl_nss_name); 693 __cpcmd(buf, NULL, 0, NULL); 694 break; 695 case REIPL_METHOD_DEFAULT: 696 if (MACHINE_IS_VM) 697 __cpcmd("IPL", NULL, 0, NULL); 698 diag308(DIAG308_IPL, NULL); 699 break; 700 case REIPL_METHOD_FCP_DUMP: 701 default: 702 break; 703 } 704 } 705 706 static void __init reipl_probe(void) 707 { 708 void *buffer; 709 710 buffer = (void *) get_zeroed_page(GFP_KERNEL); 711 if (!buffer) 712 return; 713 if (diag308(DIAG308_STORE, buffer) == DIAG308_RC_OK) 714 diag308_set_works = 1; 715 free_page((unsigned long)buffer); 716 } 717 718 static int __init reipl_nss_init(void) 719 { 720 int rc; 721 722 if (!MACHINE_IS_VM) 723 return 0; 724 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group); 725 if (rc) 726 return rc; 727 strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1); 728 reipl_capabilities |= IPL_TYPE_NSS; 729 return 0; 730 } 731 732 static int __init reipl_ccw_init(void) 733 { 734 int rc; 735 736 reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); 737 if (!reipl_block_ccw) 738 return -ENOMEM; 739 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group); 740 if (rc) { 741 free_page((unsigned long)reipl_block_ccw); 742 return rc; 743 } 744 reipl_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; 745 reipl_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; 746 reipl_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; 747 reipl_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; 748 reipl_block_ccw->hdr.flags = DIAG308_FLAGS_LP_VALID; 749 /* check if read scp info worked and set loadparm */ 750 if (sclp_ipl_info.is_valid) 751 memcpy(reipl_block_ccw->ipl_info.ccw.load_param, 752 &sclp_ipl_info.loadparm, LOADPARM_LEN); 753 else 754 /* read scp info failed: set empty loadparm (EBCDIC blanks) */ 755 memset(reipl_block_ccw->ipl_info.ccw.load_param, 0x40, 756 LOADPARM_LEN); 757 if (!MACHINE_IS_VM && !diag308_set_works) 758 sys_reipl_ccw_loadparm_attr.attr.mode = S_IRUGO; 759 if (ipl_info.type == IPL_TYPE_CCW) 760 reipl_block_ccw->ipl_info.ccw.devno = ipl_devno; 761 reipl_capabilities |= IPL_TYPE_CCW; 762 return 0; 763 } 764 765 static int __init reipl_fcp_init(void) 766 { 767 int rc; 768 769 if ((!diag308_set_works) && (ipl_info.type != IPL_TYPE_FCP)) 770 return 0; 771 if ((!diag308_set_works) && (ipl_info.type == IPL_TYPE_FCP)) 772 make_attrs_ro(reipl_fcp_attrs); 773 774 reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); 775 if (!reipl_block_fcp) 776 return -ENOMEM; 777 rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group); 778 if (rc) { 779 free_page((unsigned long)reipl_block_fcp); 780 return rc; 781 } 782 if (ipl_info.type == IPL_TYPE_FCP) { 783 memcpy(reipl_block_fcp, IPL_PARMBLOCK_START, PAGE_SIZE); 784 } else { 785 reipl_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; 786 reipl_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; 787 reipl_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; 788 reipl_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; 789 reipl_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_IPL; 790 } 791 reipl_capabilities |= IPL_TYPE_FCP; 792 return 0; 793 } 794 795 static int reipl_init(void) 796 { 797 int rc; 798 799 reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj); 800 if (!reipl_kset) 801 return -ENOMEM; 802 rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr); 803 if (rc) { 804 kset_unregister(reipl_kset); 805 return rc; 806 } 807 rc = reipl_ccw_init(); 808 if (rc) 809 return rc; 810 rc = reipl_fcp_init(); 811 if (rc) 812 return rc; 813 rc = reipl_nss_init(); 814 if (rc) 815 return rc; 816 rc = reipl_set_type(ipl_info.type); 817 if (rc) 818 return rc; 819 return 0; 820 } 821 822 static struct shutdown_action reipl_action = {SHUTDOWN_ACTION_REIPL_STR, 823 reipl_run, reipl_init}; 824 825 /* 826 * dump shutdown action: Dump Linux on shutdown. 827 */ 828 829 /* FCP dump device attributes */ 830 831 DEFINE_IPL_ATTR_RW(dump_fcp, wwpn, "0x%016llx\n", "%016llx\n", 832 dump_block_fcp->ipl_info.fcp.wwpn); 833 DEFINE_IPL_ATTR_RW(dump_fcp, lun, "0x%016llx\n", "%016llx\n", 834 dump_block_fcp->ipl_info.fcp.lun); 835 DEFINE_IPL_ATTR_RW(dump_fcp, bootprog, "%lld\n", "%lld\n", 836 dump_block_fcp->ipl_info.fcp.bootprog); 837 DEFINE_IPL_ATTR_RW(dump_fcp, br_lba, "%lld\n", "%lld\n", 838 dump_block_fcp->ipl_info.fcp.br_lba); 839 DEFINE_IPL_ATTR_RW(dump_fcp, device, "0.0.%04llx\n", "0.0.%llx\n", 840 dump_block_fcp->ipl_info.fcp.devno); 841 842 static struct attribute *dump_fcp_attrs[] = { 843 &sys_dump_fcp_device_attr.attr, 844 &sys_dump_fcp_wwpn_attr.attr, 845 &sys_dump_fcp_lun_attr.attr, 846 &sys_dump_fcp_bootprog_attr.attr, 847 &sys_dump_fcp_br_lba_attr.attr, 848 NULL, 849 }; 850 851 static struct attribute_group dump_fcp_attr_group = { 852 .name = IPL_FCP_STR, 853 .attrs = dump_fcp_attrs, 854 }; 855 856 /* CCW dump device attributes */ 857 858 DEFINE_IPL_ATTR_RW(dump_ccw, device, "0.0.%04llx\n", "0.0.%llx\n", 859 dump_block_ccw->ipl_info.ccw.devno); 860 861 static struct attribute *dump_ccw_attrs[] = { 862 &sys_dump_ccw_device_attr.attr, 863 NULL, 864 }; 865 866 static struct attribute_group dump_ccw_attr_group = { 867 .name = IPL_CCW_STR, 868 .attrs = dump_ccw_attrs, 869 }; 870 871 /* dump type */ 872 873 static int dump_set_type(enum dump_type type) 874 { 875 if (!(dump_capabilities & type)) 876 return -EINVAL; 877 switch (type) { 878 case DUMP_TYPE_CCW: 879 if (diag308_set_works) 880 dump_method = DUMP_METHOD_CCW_DIAG; 881 else if (MACHINE_IS_VM) 882 dump_method = DUMP_METHOD_CCW_VM; 883 else 884 dump_method = DUMP_METHOD_CCW_CIO; 885 break; 886 case DUMP_TYPE_FCP: 887 dump_method = DUMP_METHOD_FCP_DIAG; 888 break; 889 default: 890 dump_method = DUMP_METHOD_NONE; 891 } 892 dump_type = type; 893 return 0; 894 } 895 896 static ssize_t dump_type_show(struct kobject *kobj, 897 struct kobj_attribute *attr, char *page) 898 { 899 return sprintf(page, "%s\n", dump_type_str(dump_type)); 900 } 901 902 static ssize_t dump_type_store(struct kobject *kobj, 903 struct kobj_attribute *attr, 904 const char *buf, size_t len) 905 { 906 int rc = -EINVAL; 907 908 if (strncmp(buf, DUMP_NONE_STR, strlen(DUMP_NONE_STR)) == 0) 909 rc = dump_set_type(DUMP_TYPE_NONE); 910 else if (strncmp(buf, DUMP_CCW_STR, strlen(DUMP_CCW_STR)) == 0) 911 rc = dump_set_type(DUMP_TYPE_CCW); 912 else if (strncmp(buf, DUMP_FCP_STR, strlen(DUMP_FCP_STR)) == 0) 913 rc = dump_set_type(DUMP_TYPE_FCP); 914 return (rc != 0) ? rc : len; 915 } 916 917 static struct kobj_attribute dump_type_attr = 918 __ATTR(dump_type, 0644, dump_type_show, dump_type_store); 919 920 static struct kset *dump_kset; 921 922 static void dump_run(struct shutdown_trigger *trigger) 923 { 924 struct ccw_dev_id devid; 925 static char buf[100]; 926 927 switch (dump_method) { 928 case DUMP_METHOD_CCW_CIO: 929 smp_send_stop(); 930 devid.devno = dump_block_ccw->ipl_info.ccw.devno; 931 devid.ssid = 0; 932 reipl_ccw_dev(&devid); 933 break; 934 case DUMP_METHOD_CCW_VM: 935 smp_send_stop(); 936 sprintf(buf, "STORE STATUS"); 937 __cpcmd(buf, NULL, 0, NULL); 938 sprintf(buf, "IPL %X", dump_block_ccw->ipl_info.ccw.devno); 939 __cpcmd(buf, NULL, 0, NULL); 940 break; 941 case DUMP_METHOD_CCW_DIAG: 942 diag308(DIAG308_SET, dump_block_ccw); 943 diag308(DIAG308_DUMP, NULL); 944 break; 945 case DUMP_METHOD_FCP_DIAG: 946 diag308(DIAG308_SET, dump_block_fcp); 947 diag308(DIAG308_DUMP, NULL); 948 break; 949 case DUMP_METHOD_NONE: 950 default: 951 return; 952 } 953 printk(KERN_EMERG "Dump failed!\n"); 954 } 955 956 static int __init dump_ccw_init(void) 957 { 958 int rc; 959 960 dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL); 961 if (!dump_block_ccw) 962 return -ENOMEM; 963 rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group); 964 if (rc) { 965 free_page((unsigned long)dump_block_ccw); 966 return rc; 967 } 968 dump_block_ccw->hdr.len = IPL_PARM_BLK_CCW_LEN; 969 dump_block_ccw->hdr.version = IPL_PARM_BLOCK_VERSION; 970 dump_block_ccw->hdr.blk0_len = IPL_PARM_BLK0_CCW_LEN; 971 dump_block_ccw->hdr.pbt = DIAG308_IPL_TYPE_CCW; 972 dump_capabilities |= DUMP_TYPE_CCW; 973 return 0; 974 } 975 976 static int __init dump_fcp_init(void) 977 { 978 int rc; 979 980 if (!sclp_ipl_info.has_dump) 981 return 0; /* LDIPL DUMP is not installed */ 982 if (!diag308_set_works) 983 return 0; 984 dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL); 985 if (!dump_block_fcp) 986 return -ENOMEM; 987 rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group); 988 if (rc) { 989 free_page((unsigned long)dump_block_fcp); 990 return rc; 991 } 992 dump_block_fcp->hdr.len = IPL_PARM_BLK_FCP_LEN; 993 dump_block_fcp->hdr.version = IPL_PARM_BLOCK_VERSION; 994 dump_block_fcp->hdr.blk0_len = IPL_PARM_BLK0_FCP_LEN; 995 dump_block_fcp->hdr.pbt = DIAG308_IPL_TYPE_FCP; 996 dump_block_fcp->ipl_info.fcp.opt = DIAG308_IPL_OPT_DUMP; 997 dump_capabilities |= DUMP_TYPE_FCP; 998 return 0; 999 } 1000 1001 static int dump_init(void) 1002 { 1003 int rc; 1004 1005 dump_kset = kset_create_and_add("dump", NULL, firmware_kobj); 1006 if (!dump_kset) 1007 return -ENOMEM; 1008 rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr.attr); 1009 if (rc) { 1010 kset_unregister(dump_kset); 1011 return rc; 1012 } 1013 rc = dump_ccw_init(); 1014 if (rc) 1015 return rc; 1016 rc = dump_fcp_init(); 1017 if (rc) 1018 return rc; 1019 dump_set_type(DUMP_TYPE_NONE); 1020 return 0; 1021 } 1022 1023 static struct shutdown_action dump_action = {SHUTDOWN_ACTION_DUMP_STR, 1024 dump_run, dump_init}; 1025 1026 /* 1027 * vmcmd shutdown action: Trigger vm command on shutdown. 1028 */ 1029 1030 static char vmcmd_on_reboot[128]; 1031 static char vmcmd_on_panic[128]; 1032 static char vmcmd_on_halt[128]; 1033 static char vmcmd_on_poff[128]; 1034 1035 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_reboot, "%s\n", "%s\n", vmcmd_on_reboot); 1036 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_panic, "%s\n", "%s\n", vmcmd_on_panic); 1037 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_halt, "%s\n", "%s\n", vmcmd_on_halt); 1038 DEFINE_IPL_ATTR_STR_RW(vmcmd, on_poff, "%s\n", "%s\n", vmcmd_on_poff); 1039 1040 static struct attribute *vmcmd_attrs[] = { 1041 &sys_vmcmd_on_reboot_attr.attr, 1042 &sys_vmcmd_on_panic_attr.attr, 1043 &sys_vmcmd_on_halt_attr.attr, 1044 &sys_vmcmd_on_poff_attr.attr, 1045 NULL, 1046 }; 1047 1048 static struct attribute_group vmcmd_attr_group = { 1049 .attrs = vmcmd_attrs, 1050 }; 1051 1052 static struct kset *vmcmd_kset; 1053 1054 static void vmcmd_run(struct shutdown_trigger *trigger) 1055 { 1056 char *cmd, *next_cmd; 1057 1058 if (strcmp(trigger->name, ON_REIPL_STR) == 0) 1059 cmd = vmcmd_on_reboot; 1060 else if (strcmp(trigger->name, ON_PANIC_STR) == 0) 1061 cmd = vmcmd_on_panic; 1062 else if (strcmp(trigger->name, ON_HALT_STR) == 0) 1063 cmd = vmcmd_on_halt; 1064 else if (strcmp(trigger->name, ON_POFF_STR) == 0) 1065 cmd = vmcmd_on_poff; 1066 else 1067 return; 1068 1069 if (strlen(cmd) == 0) 1070 return; 1071 do { 1072 next_cmd = strchr(cmd, '\n'); 1073 if (next_cmd) { 1074 next_cmd[0] = 0; 1075 next_cmd += 1; 1076 } 1077 __cpcmd(cmd, NULL, 0, NULL); 1078 cmd = next_cmd; 1079 } while (cmd != NULL); 1080 } 1081 1082 static int vmcmd_init(void) 1083 { 1084 if (!MACHINE_IS_VM) 1085 return -ENOTSUPP; 1086 vmcmd_kset = kset_create_and_add("vmcmd", NULL, firmware_kobj); 1087 if (!vmcmd_kset) 1088 return -ENOMEM; 1089 return sysfs_create_group(&vmcmd_kset->kobj, &vmcmd_attr_group); 1090 } 1091 1092 static struct shutdown_action vmcmd_action = {SHUTDOWN_ACTION_VMCMD_STR, 1093 vmcmd_run, vmcmd_init}; 1094 1095 /* 1096 * stop shutdown action: Stop Linux on shutdown. 1097 */ 1098 1099 static void stop_run(struct shutdown_trigger *trigger) 1100 { 1101 if (strcmp(trigger->name, ON_PANIC_STR) == 0) 1102 disabled_wait((unsigned long) __builtin_return_address(0)); 1103 else { 1104 signal_processor(smp_processor_id(), sigp_stop); 1105 for (;;); 1106 } 1107 } 1108 1109 static struct shutdown_action stop_action = {SHUTDOWN_ACTION_STOP_STR, 1110 stop_run, NULL}; 1111 1112 /* action list */ 1113 1114 static struct shutdown_action *shutdown_actions_list[] = { 1115 &ipl_action, &reipl_action, &dump_action, &vmcmd_action, &stop_action}; 1116 #define SHUTDOWN_ACTIONS_COUNT (sizeof(shutdown_actions_list) / sizeof(void *)) 1117 1118 /* 1119 * Trigger section 1120 */ 1121 1122 static struct kset *shutdown_actions_kset; 1123 1124 static int set_trigger(const char *buf, struct shutdown_trigger *trigger, 1125 size_t len) 1126 { 1127 int i; 1128 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { 1129 if (!shutdown_actions_list[i]) 1130 continue; 1131 if (strncmp(buf, shutdown_actions_list[i]->name, 1132 strlen(shutdown_actions_list[i]->name)) == 0) { 1133 trigger->action = shutdown_actions_list[i]; 1134 return len; 1135 } 1136 } 1137 return -EINVAL; 1138 } 1139 1140 /* on reipl */ 1141 1142 static struct shutdown_trigger on_reboot_trigger = {ON_REIPL_STR, 1143 &reipl_action}; 1144 1145 static ssize_t on_reboot_show(struct kobject *kobj, 1146 struct kobj_attribute *attr, char *page) 1147 { 1148 return sprintf(page, "%s\n", on_reboot_trigger.action->name); 1149 } 1150 1151 static ssize_t on_reboot_store(struct kobject *kobj, 1152 struct kobj_attribute *attr, 1153 const char *buf, size_t len) 1154 { 1155 return set_trigger(buf, &on_reboot_trigger, len); 1156 } 1157 1158 static struct kobj_attribute on_reboot_attr = 1159 __ATTR(on_reboot, 0644, on_reboot_show, on_reboot_store); 1160 1161 static void do_machine_restart(char *__unused) 1162 { 1163 smp_send_stop(); 1164 on_reboot_trigger.action->fn(&on_reboot_trigger); 1165 reipl_run(NULL); 1166 } 1167 void (*_machine_restart)(char *command) = do_machine_restart; 1168 1169 /* on panic */ 1170 1171 static struct shutdown_trigger on_panic_trigger = {ON_PANIC_STR, &stop_action}; 1172 1173 static ssize_t on_panic_show(struct kobject *kobj, 1174 struct kobj_attribute *attr, char *page) 1175 { 1176 return sprintf(page, "%s\n", on_panic_trigger.action->name); 1177 } 1178 1179 static ssize_t on_panic_store(struct kobject *kobj, 1180 struct kobj_attribute *attr, 1181 const char *buf, size_t len) 1182 { 1183 return set_trigger(buf, &on_panic_trigger, len); 1184 } 1185 1186 static struct kobj_attribute on_panic_attr = 1187 __ATTR(on_panic, 0644, on_panic_show, on_panic_store); 1188 1189 static void do_panic(void) 1190 { 1191 on_panic_trigger.action->fn(&on_panic_trigger); 1192 stop_run(&on_panic_trigger); 1193 } 1194 1195 /* on halt */ 1196 1197 static struct shutdown_trigger on_halt_trigger = {ON_HALT_STR, &stop_action}; 1198 1199 static ssize_t on_halt_show(struct kobject *kobj, 1200 struct kobj_attribute *attr, char *page) 1201 { 1202 return sprintf(page, "%s\n", on_halt_trigger.action->name); 1203 } 1204 1205 static ssize_t on_halt_store(struct kobject *kobj, 1206 struct kobj_attribute *attr, 1207 const char *buf, size_t len) 1208 { 1209 return set_trigger(buf, &on_halt_trigger, len); 1210 } 1211 1212 static struct kobj_attribute on_halt_attr = 1213 __ATTR(on_halt, 0644, on_halt_show, on_halt_store); 1214 1215 1216 static void do_machine_halt(void) 1217 { 1218 smp_send_stop(); 1219 on_halt_trigger.action->fn(&on_halt_trigger); 1220 stop_run(&on_halt_trigger); 1221 } 1222 void (*_machine_halt)(void) = do_machine_halt; 1223 1224 /* on power off */ 1225 1226 static struct shutdown_trigger on_poff_trigger = {ON_POFF_STR, &stop_action}; 1227 1228 static ssize_t on_poff_show(struct kobject *kobj, 1229 struct kobj_attribute *attr, char *page) 1230 { 1231 return sprintf(page, "%s\n", on_poff_trigger.action->name); 1232 } 1233 1234 static ssize_t on_poff_store(struct kobject *kobj, 1235 struct kobj_attribute *attr, 1236 const char *buf, size_t len) 1237 { 1238 return set_trigger(buf, &on_poff_trigger, len); 1239 } 1240 1241 static struct kobj_attribute on_poff_attr = 1242 __ATTR(on_poff, 0644, on_poff_show, on_poff_store); 1243 1244 1245 static void do_machine_power_off(void) 1246 { 1247 smp_send_stop(); 1248 on_poff_trigger.action->fn(&on_poff_trigger); 1249 stop_run(&on_poff_trigger); 1250 } 1251 void (*_machine_power_off)(void) = do_machine_power_off; 1252 1253 static void __init shutdown_triggers_init(void) 1254 { 1255 shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL, 1256 firmware_kobj); 1257 if (!shutdown_actions_kset) 1258 goto fail; 1259 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1260 &on_reboot_attr.attr)) 1261 goto fail; 1262 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1263 &on_panic_attr.attr)) 1264 goto fail; 1265 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1266 &on_halt_attr.attr)) 1267 goto fail; 1268 if (sysfs_create_file(&shutdown_actions_kset->kobj, 1269 &on_poff_attr.attr)) 1270 goto fail; 1271 1272 return; 1273 fail: 1274 panic("shutdown_triggers_init failed\n"); 1275 } 1276 1277 static void __init shutdown_actions_init(void) 1278 { 1279 int i; 1280 1281 for (i = 0; i < SHUTDOWN_ACTIONS_COUNT; i++) { 1282 if (!shutdown_actions_list[i]->init) 1283 continue; 1284 if (shutdown_actions_list[i]->init()) 1285 shutdown_actions_list[i] = NULL; 1286 } 1287 } 1288 1289 static int __init s390_ipl_init(void) 1290 { 1291 reipl_probe(); 1292 sclp_get_ipl_info(&sclp_ipl_info); 1293 shutdown_actions_init(); 1294 shutdown_triggers_init(); 1295 return 0; 1296 } 1297 1298 __initcall(s390_ipl_init); 1299 1300 static void __init strncpy_skip_quote(char *dst, char *src, int n) 1301 { 1302 int sx, dx; 1303 1304 dx = 0; 1305 for (sx = 0; src[sx] != 0; sx++) { 1306 if (src[sx] == '"') 1307 continue; 1308 dst[dx++] = src[sx]; 1309 if (dx >= n) 1310 break; 1311 } 1312 } 1313 1314 static int __init vmcmd_on_reboot_setup(char *str) 1315 { 1316 if (!MACHINE_IS_VM) 1317 return 1; 1318 strncpy_skip_quote(vmcmd_on_reboot, str, 127); 1319 vmcmd_on_reboot[127] = 0; 1320 on_reboot_trigger.action = &vmcmd_action; 1321 return 1; 1322 } 1323 __setup("vmreboot=", vmcmd_on_reboot_setup); 1324 1325 static int __init vmcmd_on_panic_setup(char *str) 1326 { 1327 if (!MACHINE_IS_VM) 1328 return 1; 1329 strncpy_skip_quote(vmcmd_on_panic, str, 127); 1330 vmcmd_on_panic[127] = 0; 1331 on_panic_trigger.action = &vmcmd_action; 1332 return 1; 1333 } 1334 __setup("vmpanic=", vmcmd_on_panic_setup); 1335 1336 static int __init vmcmd_on_halt_setup(char *str) 1337 { 1338 if (!MACHINE_IS_VM) 1339 return 1; 1340 strncpy_skip_quote(vmcmd_on_halt, str, 127); 1341 vmcmd_on_halt[127] = 0; 1342 on_halt_trigger.action = &vmcmd_action; 1343 return 1; 1344 } 1345 __setup("vmhalt=", vmcmd_on_halt_setup); 1346 1347 static int __init vmcmd_on_poff_setup(char *str) 1348 { 1349 if (!MACHINE_IS_VM) 1350 return 1; 1351 strncpy_skip_quote(vmcmd_on_poff, str, 127); 1352 vmcmd_on_poff[127] = 0; 1353 on_poff_trigger.action = &vmcmd_action; 1354 return 1; 1355 } 1356 __setup("vmpoff=", vmcmd_on_poff_setup); 1357 1358 static int on_panic_notify(struct notifier_block *self, 1359 unsigned long event, void *data) 1360 { 1361 do_panic(); 1362 return NOTIFY_OK; 1363 } 1364 1365 static struct notifier_block on_panic_nb = { 1366 .notifier_call = on_panic_notify, 1367 .priority = 0, 1368 }; 1369 1370 void __init setup_ipl(void) 1371 { 1372 ipl_info.type = get_ipl_type(); 1373 switch (ipl_info.type) { 1374 case IPL_TYPE_CCW: 1375 ipl_info.data.ccw.dev_id.devno = ipl_devno; 1376 ipl_info.data.ccw.dev_id.ssid = 0; 1377 break; 1378 case IPL_TYPE_FCP: 1379 case IPL_TYPE_FCP_DUMP: 1380 ipl_info.data.fcp.dev_id.devno = 1381 IPL_PARMBLOCK_START->ipl_info.fcp.devno; 1382 ipl_info.data.fcp.dev_id.ssid = 0; 1383 ipl_info.data.fcp.wwpn = IPL_PARMBLOCK_START->ipl_info.fcp.wwpn; 1384 ipl_info.data.fcp.lun = IPL_PARMBLOCK_START->ipl_info.fcp.lun; 1385 break; 1386 case IPL_TYPE_NSS: 1387 strncpy(ipl_info.data.nss.name, kernel_nss_name, 1388 sizeof(ipl_info.data.nss.name)); 1389 break; 1390 case IPL_TYPE_UNKNOWN: 1391 default: 1392 /* We have no info to copy */ 1393 break; 1394 } 1395 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb); 1396 } 1397 1398 void __init ipl_save_parameters(void) 1399 { 1400 struct cio_iplinfo iplinfo; 1401 unsigned int *ipl_ptr; 1402 void *src, *dst; 1403 1404 if (cio_get_iplinfo(&iplinfo)) 1405 return; 1406 1407 ipl_devno = iplinfo.devno; 1408 ipl_flags |= IPL_DEVNO_VALID; 1409 if (!iplinfo.is_qdio) 1410 return; 1411 ipl_flags |= IPL_PARMBLOCK_VALID; 1412 ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR; 1413 src = (void *)(unsigned long)*ipl_ptr; 1414 dst = (void *)IPL_PARMBLOCK_ORIGIN; 1415 memmove(dst, src, PAGE_SIZE); 1416 *ipl_ptr = IPL_PARMBLOCK_ORIGIN; 1417 } 1418 1419 static LIST_HEAD(rcall); 1420 static DEFINE_MUTEX(rcall_mutex); 1421 1422 void register_reset_call(struct reset_call *reset) 1423 { 1424 mutex_lock(&rcall_mutex); 1425 list_add(&reset->list, &rcall); 1426 mutex_unlock(&rcall_mutex); 1427 } 1428 EXPORT_SYMBOL_GPL(register_reset_call); 1429 1430 void unregister_reset_call(struct reset_call *reset) 1431 { 1432 mutex_lock(&rcall_mutex); 1433 list_del(&reset->list); 1434 mutex_unlock(&rcall_mutex); 1435 } 1436 EXPORT_SYMBOL_GPL(unregister_reset_call); 1437 1438 static void do_reset_calls(void) 1439 { 1440 struct reset_call *reset; 1441 1442 list_for_each_entry(reset, &rcall, list) 1443 reset->fn(); 1444 } 1445 1446 u32 dump_prefix_page; 1447 1448 void s390_reset_system(void) 1449 { 1450 struct _lowcore *lc; 1451 1452 lc = (struct _lowcore *)(unsigned long) store_prefix(); 1453 1454 /* Stack for interrupt/machine check handler */ 1455 lc->panic_stack = S390_lowcore.panic_stack; 1456 1457 /* Save prefix page address for dump case */ 1458 dump_prefix_page = (u32)(unsigned long) lc; 1459 1460 /* Disable prefixing */ 1461 set_prefix(0); 1462 1463 /* Disable lowcore protection */ 1464 __ctl_clear_bit(0,28); 1465 1466 /* Set new machine check handler */ 1467 S390_lowcore.mcck_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK; 1468 S390_lowcore.mcck_new_psw.addr = 1469 PSW_ADDR_AMODE | (unsigned long) s390_base_mcck_handler; 1470 1471 /* Set new program check handler */ 1472 S390_lowcore.program_new_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK; 1473 S390_lowcore.program_new_psw.addr = 1474 PSW_ADDR_AMODE | (unsigned long) s390_base_pgm_handler; 1475 1476 do_reset_calls(); 1477 } 1478 1479