1 /* 2 * bootloader support 3 * 4 * Copyright IBM, Corp. 2012 5 * 6 * Authors: 7 * Christian Borntraeger <borntraeger@de.ibm.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or (at your 10 * option) any later version. See the COPYING file in the top-level directory. 11 * 12 */ 13 14 #include "qemu/osdep.h" 15 #include "qemu-common.h" 16 #include "qapi/error.h" 17 #include "sysemu/reset.h" 18 #include "sysemu/sysemu.h" 19 #include "sysemu/tcg.h" 20 #include "cpu.h" 21 #include "elf.h" 22 #include "hw/loader.h" 23 #include "hw/qdev-properties.h" 24 #include "hw/boards.h" 25 #include "hw/s390x/virtio-ccw.h" 26 #include "hw/s390x/vfio-ccw.h" 27 #include "hw/s390x/css.h" 28 #include "hw/s390x/ebcdic.h" 29 #include "ipl.h" 30 #include "qemu/error-report.h" 31 #include "qemu/config-file.h" 32 #include "qemu/cutils.h" 33 #include "qemu/option.h" 34 #include "exec/exec-all.h" 35 36 #define KERN_IMAGE_START 0x010000UL 37 #define LINUX_MAGIC_ADDR 0x010008UL 38 #define KERN_PARM_AREA 0x010480UL 39 #define INITRD_START 0x800000UL 40 #define INITRD_PARM_START 0x010408UL 41 #define PARMFILE_START 0x001000UL 42 #define ZIPL_IMAGE_START 0x009000UL 43 #define IPL_PSW_MASK (PSW_MASK_32 | PSW_MASK_64) 44 45 static bool iplb_extended_needed(void *opaque) 46 { 47 S390IPLState *ipl = S390_IPL(object_resolve_path(TYPE_S390_IPL, NULL)); 48 49 return ipl->iplbext_migration; 50 } 51 52 static const VMStateDescription vmstate_iplb_extended = { 53 .name = "ipl/iplb_extended", 54 .version_id = 0, 55 .minimum_version_id = 0, 56 .needed = iplb_extended_needed, 57 .fields = (VMStateField[]) { 58 VMSTATE_UINT8_ARRAY(reserved_ext, IplParameterBlock, 4096 - 200), 59 VMSTATE_END_OF_LIST() 60 } 61 }; 62 63 static const VMStateDescription vmstate_iplb = { 64 .name = "ipl/iplb", 65 .version_id = 0, 66 .minimum_version_id = 0, 67 .fields = (VMStateField[]) { 68 VMSTATE_UINT8_ARRAY(reserved1, IplParameterBlock, 110), 69 VMSTATE_UINT16(devno, IplParameterBlock), 70 VMSTATE_UINT8_ARRAY(reserved2, IplParameterBlock, 88), 71 VMSTATE_END_OF_LIST() 72 }, 73 .subsections = (const VMStateDescription*[]) { 74 &vmstate_iplb_extended, 75 NULL 76 } 77 }; 78 79 static const VMStateDescription vmstate_ipl = { 80 .name = "ipl", 81 .version_id = 0, 82 .minimum_version_id = 0, 83 .fields = (VMStateField[]) { 84 VMSTATE_UINT64(compat_start_addr, S390IPLState), 85 VMSTATE_UINT64(compat_bios_start_addr, S390IPLState), 86 VMSTATE_STRUCT(iplb, S390IPLState, 0, vmstate_iplb, IplParameterBlock), 87 VMSTATE_BOOL(iplb_valid, S390IPLState), 88 VMSTATE_UINT8(cssid, S390IPLState), 89 VMSTATE_UINT8(ssid, S390IPLState), 90 VMSTATE_UINT16(devno, S390IPLState), 91 VMSTATE_END_OF_LIST() 92 } 93 }; 94 95 static S390IPLState *get_ipl_device(void) 96 { 97 return S390_IPL(object_resolve_path_type("", TYPE_S390_IPL, NULL)); 98 } 99 100 static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr) 101 { 102 uint64_t dstaddr = *(uint64_t *) opaque; 103 /* 104 * Assuming that our s390-ccw.img was linked for starting at address 0, 105 * we can simply add the destination address for the final location 106 */ 107 return srcaddr + dstaddr; 108 } 109 110 static void s390_ipl_realize(DeviceState *dev, Error **errp) 111 { 112 S390IPLState *ipl = S390_IPL(dev); 113 uint32_t *ipl_psw; 114 uint64_t pentry; 115 char *magic; 116 int kernel_size; 117 Error *err = NULL; 118 119 int bios_size; 120 char *bios_filename; 121 122 /* 123 * Always load the bios if it was enforced, 124 * even if an external kernel has been defined. 125 */ 126 if (!ipl->kernel || ipl->enforce_bios) { 127 uint64_t fwbase = (MIN(ram_size, 0x80000000U) - 0x200000) & ~0xffffUL; 128 129 if (bios_name == NULL) { 130 bios_name = ipl->firmware; 131 } 132 133 bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 134 if (bios_filename == NULL) { 135 error_setg(&err, "could not find stage1 bootloader"); 136 goto error; 137 } 138 139 bios_size = load_elf(bios_filename, NULL, 140 bios_translate_addr, &fwbase, 141 &ipl->bios_start_addr, NULL, NULL, 1, 142 EM_S390, 0, 0); 143 if (bios_size > 0) { 144 /* Adjust ELF start address to final location */ 145 ipl->bios_start_addr += fwbase; 146 } else { 147 /* Try to load non-ELF file */ 148 bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START, 149 4096); 150 ipl->bios_start_addr = ZIPL_IMAGE_START; 151 } 152 g_free(bios_filename); 153 154 if (bios_size == -1) { 155 error_setg(&err, "could not load bootloader '%s'", bios_name); 156 goto error; 157 } 158 159 /* default boot target is the bios */ 160 ipl->start_addr = ipl->bios_start_addr; 161 } 162 163 if (ipl->kernel) { 164 kernel_size = load_elf(ipl->kernel, NULL, NULL, NULL, 165 &pentry, NULL, 166 NULL, 1, EM_S390, 0, 0); 167 if (kernel_size < 0) { 168 kernel_size = load_image_targphys(ipl->kernel, 0, ram_size); 169 if (kernel_size < 0) { 170 error_setg(&err, "could not load kernel '%s'", ipl->kernel); 171 goto error; 172 } 173 /* if this is Linux use KERN_IMAGE_START */ 174 magic = rom_ptr(LINUX_MAGIC_ADDR, 6); 175 if (magic && !memcmp(magic, "S390EP", 6)) { 176 pentry = KERN_IMAGE_START; 177 } else { 178 /* if not Linux load the address of the (short) IPL PSW */ 179 ipl_psw = rom_ptr(4, 4); 180 if (ipl_psw) { 181 pentry = be32_to_cpu(*ipl_psw) & 0x7fffffffUL; 182 } else { 183 error_setg(&err, "Could not get IPL PSW"); 184 goto error; 185 } 186 } 187 } 188 /* 189 * Is it a Linux kernel (starting at 0x10000)? If yes, we fill in the 190 * kernel parameters here as well. Note: For old kernels (up to 3.2) 191 * we can not rely on the ELF entry point - it was 0x800 (the SALIPL 192 * loader) and it won't work. For this case we force it to 0x10000, too. 193 */ 194 if (pentry == KERN_IMAGE_START || pentry == 0x800) { 195 char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1); 196 ipl->start_addr = KERN_IMAGE_START; 197 /* Overwrite parameters in the kernel image, which are "rom" */ 198 if (parm_area) { 199 strcpy(parm_area, ipl->cmdline); 200 } 201 } else { 202 ipl->start_addr = pentry; 203 } 204 205 if (ipl->initrd) { 206 ram_addr_t initrd_offset; 207 int initrd_size; 208 uint64_t *romptr; 209 210 initrd_offset = INITRD_START; 211 while (kernel_size + 0x100000 > initrd_offset) { 212 initrd_offset += 0x100000; 213 } 214 initrd_size = load_image_targphys(ipl->initrd, initrd_offset, 215 ram_size - initrd_offset); 216 if (initrd_size == -1) { 217 error_setg(&err, "could not load initrd '%s'", ipl->initrd); 218 goto error; 219 } 220 221 /* 222 * we have to overwrite values in the kernel image, 223 * which are "rom" 224 */ 225 romptr = rom_ptr(INITRD_PARM_START, 16); 226 if (romptr) { 227 stq_p(romptr, initrd_offset); 228 stq_p(romptr + 1, initrd_size); 229 } 230 } 231 } 232 /* 233 * Don't ever use the migrated values, they could come from a different 234 * BIOS and therefore don't work. But still migrate the values, so 235 * QEMUs relying on it don't break. 236 */ 237 ipl->compat_start_addr = ipl->start_addr; 238 ipl->compat_bios_start_addr = ipl->bios_start_addr; 239 qemu_register_reset(qdev_reset_all_fn, dev); 240 error: 241 error_propagate(errp, err); 242 } 243 244 static Property s390_ipl_properties[] = { 245 DEFINE_PROP_STRING("kernel", S390IPLState, kernel), 246 DEFINE_PROP_STRING("initrd", S390IPLState, initrd), 247 DEFINE_PROP_STRING("cmdline", S390IPLState, cmdline), 248 DEFINE_PROP_STRING("firmware", S390IPLState, firmware), 249 DEFINE_PROP_STRING("netboot_fw", S390IPLState, netboot_fw), 250 DEFINE_PROP_BOOL("enforce_bios", S390IPLState, enforce_bios, false), 251 DEFINE_PROP_BOOL("iplbext_migration", S390IPLState, iplbext_migration, 252 true), 253 DEFINE_PROP_END_OF_LIST(), 254 }; 255 256 static void s390_ipl_set_boot_menu(S390IPLState *ipl) 257 { 258 QemuOptsList *plist = qemu_find_opts("boot-opts"); 259 QemuOpts *opts = QTAILQ_FIRST(&plist->head); 260 const char *tmp; 261 unsigned long splash_time = 0; 262 263 if (!get_boot_device(0)) { 264 if (boot_menu) { 265 error_report("boot menu requires a bootindex to be specified for " 266 "the IPL device"); 267 } 268 return; 269 } 270 271 switch (ipl->iplb.pbt) { 272 case S390_IPL_TYPE_CCW: 273 /* In the absence of -boot menu, use zipl parameters */ 274 if (!qemu_opt_get(opts, "menu")) { 275 ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_ZIPL; 276 return; 277 } 278 break; 279 case S390_IPL_TYPE_QEMU_SCSI: 280 break; 281 default: 282 if (boot_menu) { 283 error_report("boot menu is not supported for this device type"); 284 } 285 return; 286 } 287 288 if (!boot_menu) { 289 return; 290 } 291 292 ipl->qipl.qipl_flags |= QIPL_FLAG_BM_OPTS_CMD; 293 294 tmp = qemu_opt_get(opts, "splash-time"); 295 296 if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) { 297 error_report("splash-time is invalid, forcing it to 0"); 298 ipl->qipl.boot_menu_timeout = 0; 299 return; 300 } 301 302 if (splash_time > 0xffffffff) { 303 error_report("splash-time is too large, forcing it to max value"); 304 ipl->qipl.boot_menu_timeout = 0xffffffff; 305 return; 306 } 307 308 ipl->qipl.boot_menu_timeout = cpu_to_be32(splash_time); 309 } 310 311 #define CCW_DEVTYPE_NONE 0x00 312 #define CCW_DEVTYPE_VIRTIO 0x01 313 #define CCW_DEVTYPE_VIRTIO_NET 0x02 314 #define CCW_DEVTYPE_SCSI 0x03 315 #define CCW_DEVTYPE_VFIO 0x04 316 317 static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype) 318 { 319 CcwDevice *ccw_dev = NULL; 320 int tmp_dt = CCW_DEVTYPE_NONE; 321 322 if (dev_st) { 323 VirtIONet *virtio_net_dev = (VirtIONet *) 324 object_dynamic_cast(OBJECT(dev_st), TYPE_VIRTIO_NET); 325 VirtioCcwDevice *virtio_ccw_dev = (VirtioCcwDevice *) 326 object_dynamic_cast(OBJECT(qdev_get_parent_bus(dev_st)->parent), 327 TYPE_VIRTIO_CCW_DEVICE); 328 VFIOCCWDevice *vfio_ccw_dev = (VFIOCCWDevice *) 329 object_dynamic_cast(OBJECT(dev_st), TYPE_VFIO_CCW); 330 331 if (virtio_ccw_dev) { 332 ccw_dev = CCW_DEVICE(virtio_ccw_dev); 333 if (virtio_net_dev) { 334 tmp_dt = CCW_DEVTYPE_VIRTIO_NET; 335 } else { 336 tmp_dt = CCW_DEVTYPE_VIRTIO; 337 } 338 } else if (vfio_ccw_dev) { 339 ccw_dev = CCW_DEVICE(vfio_ccw_dev); 340 tmp_dt = CCW_DEVTYPE_VFIO; 341 } else { 342 SCSIDevice *sd = (SCSIDevice *) 343 object_dynamic_cast(OBJECT(dev_st), 344 TYPE_SCSI_DEVICE); 345 if (sd) { 346 SCSIBus *bus = scsi_bus_from_device(sd); 347 VirtIOSCSI *vdev = container_of(bus, VirtIOSCSI, bus); 348 VirtIOSCSICcw *scsi_ccw = container_of(vdev, VirtIOSCSICcw, 349 vdev); 350 351 ccw_dev = (CcwDevice *)object_dynamic_cast(OBJECT(scsi_ccw), 352 TYPE_CCW_DEVICE); 353 tmp_dt = CCW_DEVTYPE_SCSI; 354 } 355 } 356 } 357 if (devtype) { 358 *devtype = tmp_dt; 359 } 360 return ccw_dev; 361 } 362 363 static bool s390_gen_initial_iplb(S390IPLState *ipl) 364 { 365 DeviceState *dev_st; 366 CcwDevice *ccw_dev = NULL; 367 SCSIDevice *sd; 368 int devtype; 369 370 dev_st = get_boot_device(0); 371 if (dev_st) { 372 ccw_dev = s390_get_ccw_device(dev_st, &devtype); 373 } 374 375 /* 376 * Currently allow IPL only from CCW devices. 377 */ 378 if (ccw_dev) { 379 switch (devtype) { 380 case CCW_DEVTYPE_SCSI: 381 sd = SCSI_DEVICE(dev_st); 382 ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN); 383 ipl->iplb.blk0_len = 384 cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER_LEN); 385 ipl->iplb.pbt = S390_IPL_TYPE_QEMU_SCSI; 386 ipl->iplb.scsi.lun = cpu_to_be32(sd->lun); 387 ipl->iplb.scsi.target = cpu_to_be16(sd->id); 388 ipl->iplb.scsi.channel = cpu_to_be16(sd->channel); 389 ipl->iplb.scsi.devno = cpu_to_be16(ccw_dev->sch->devno); 390 ipl->iplb.scsi.ssid = ccw_dev->sch->ssid & 3; 391 break; 392 case CCW_DEVTYPE_VFIO: 393 ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN); 394 ipl->iplb.pbt = S390_IPL_TYPE_CCW; 395 ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno); 396 ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3; 397 break; 398 case CCW_DEVTYPE_VIRTIO_NET: 399 ipl->netboot = true; 400 /* Fall through to CCW_DEVTYPE_VIRTIO case */ 401 case CCW_DEVTYPE_VIRTIO: 402 ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN); 403 ipl->iplb.blk0_len = 404 cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN); 405 ipl->iplb.pbt = S390_IPL_TYPE_CCW; 406 ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno); 407 ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3; 408 break; 409 } 410 411 if (!s390_ipl_set_loadparm(ipl->iplb.loadparm)) { 412 ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID; 413 } 414 415 return true; 416 } 417 418 return false; 419 } 420 421 int s390_ipl_set_loadparm(uint8_t *loadparm) 422 { 423 MachineState *machine = MACHINE(qdev_get_machine()); 424 char *lp = object_property_get_str(OBJECT(machine), "loadparm", NULL); 425 426 if (lp) { 427 int i; 428 429 /* lp is an uppercase string without leading/embedded spaces */ 430 for (i = 0; i < 8 && lp[i]; i++) { 431 loadparm[i] = ascii2ebcdic[(uint8_t) lp[i]]; 432 } 433 434 if (i < 8) { 435 memset(loadparm + i, 0x40, 8 - i); /* fill with EBCDIC spaces */ 436 } 437 438 g_free(lp); 439 return 0; 440 } 441 442 return -1; 443 } 444 445 static int load_netboot_image(Error **errp) 446 { 447 S390IPLState *ipl = get_ipl_device(); 448 char *netboot_filename; 449 MemoryRegion *sysmem = get_system_memory(); 450 MemoryRegion *mr = NULL; 451 void *ram_ptr = NULL; 452 int img_size = -1; 453 454 mr = memory_region_find(sysmem, 0, 1).mr; 455 if (!mr) { 456 error_setg(errp, "Failed to find memory region at address 0"); 457 return -1; 458 } 459 460 ram_ptr = memory_region_get_ram_ptr(mr); 461 if (!ram_ptr) { 462 error_setg(errp, "No RAM found"); 463 goto unref_mr; 464 } 465 466 netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->netboot_fw); 467 if (netboot_filename == NULL) { 468 error_setg(errp, "Could not find network bootloader '%s'", 469 ipl->netboot_fw); 470 goto unref_mr; 471 } 472 473 img_size = load_elf_ram(netboot_filename, NULL, NULL, NULL, 474 &ipl->start_addr, 475 NULL, NULL, 1, EM_S390, 0, 0, NULL, false); 476 477 if (img_size < 0) { 478 img_size = load_image_size(netboot_filename, ram_ptr, ram_size); 479 ipl->start_addr = KERN_IMAGE_START; 480 } 481 482 if (img_size < 0) { 483 error_setg(errp, "Failed to load network bootloader"); 484 } 485 486 g_free(netboot_filename); 487 488 unref_mr: 489 memory_region_unref(mr); 490 return img_size; 491 } 492 493 static bool is_virtio_ccw_device_of_type(IplParameterBlock *iplb, 494 int virtio_id) 495 { 496 uint8_t cssid; 497 uint8_t ssid; 498 uint16_t devno; 499 uint16_t schid; 500 SubchDev *sch = NULL; 501 502 if (iplb->pbt != S390_IPL_TYPE_CCW) { 503 return false; 504 } 505 506 devno = be16_to_cpu(iplb->ccw.devno); 507 ssid = iplb->ccw.ssid & 3; 508 509 for (schid = 0; schid < MAX_SCHID; schid++) { 510 for (cssid = 0; cssid < MAX_CSSID; cssid++) { 511 sch = css_find_subch(1, cssid, ssid, schid); 512 513 if (sch && sch->devno == devno) { 514 return sch->id.cu_model == virtio_id; 515 } 516 } 517 } 518 return false; 519 } 520 521 static bool is_virtio_net_device(IplParameterBlock *iplb) 522 { 523 return is_virtio_ccw_device_of_type(iplb, VIRTIO_ID_NET); 524 } 525 526 static bool is_virtio_scsi_device(IplParameterBlock *iplb) 527 { 528 return is_virtio_ccw_device_of_type(iplb, VIRTIO_ID_SCSI); 529 } 530 531 void s390_ipl_update_diag308(IplParameterBlock *iplb) 532 { 533 S390IPLState *ipl = get_ipl_device(); 534 535 ipl->iplb = *iplb; 536 ipl->iplb_valid = true; 537 ipl->netboot = is_virtio_net_device(iplb); 538 } 539 540 IplParameterBlock *s390_ipl_get_iplb(void) 541 { 542 S390IPLState *ipl = get_ipl_device(); 543 544 if (!ipl->iplb_valid) { 545 return NULL; 546 } 547 return &ipl->iplb; 548 } 549 550 void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type) 551 { 552 S390IPLState *ipl = get_ipl_device(); 553 554 if (reset_type == S390_RESET_EXTERNAL || reset_type == S390_RESET_REIPL) { 555 /* use CPU 0 for full resets */ 556 ipl->reset_cpu_index = 0; 557 } else { 558 ipl->reset_cpu_index = cs->cpu_index; 559 } 560 ipl->reset_type = reset_type; 561 562 if (reset_type == S390_RESET_REIPL && 563 ipl->iplb_valid && 564 !ipl->netboot && 565 ipl->iplb.pbt == S390_IPL_TYPE_CCW && 566 is_virtio_scsi_device(&ipl->iplb)) { 567 CcwDevice *ccw_dev = s390_get_ccw_device(get_boot_device(0), NULL); 568 569 if (ccw_dev && 570 cpu_to_be16(ccw_dev->sch->devno) == ipl->iplb.ccw.devno && 571 (ccw_dev->sch->ssid & 3) == ipl->iplb.ccw.ssid) { 572 /* 573 * this is the original boot device's SCSI 574 * so restore IPL parameter info from it 575 */ 576 ipl->iplb_valid = s390_gen_initial_iplb(ipl); 577 } 578 } 579 if (reset_type == S390_RESET_MODIFIED_CLEAR || 580 reset_type == S390_RESET_LOAD_NORMAL) { 581 /* ignore -no-reboot, send no event */ 582 qemu_system_reset_request(SHUTDOWN_CAUSE_SUBSYSTEM_RESET); 583 } else { 584 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); 585 } 586 /* as this is triggered by a CPU, make sure to exit the loop */ 587 if (tcg_enabled()) { 588 cpu_loop_exit(cs); 589 } 590 } 591 592 void s390_ipl_get_reset_request(CPUState **cs, enum s390_reset *reset_type) 593 { 594 S390IPLState *ipl = get_ipl_device(); 595 596 *cs = qemu_get_cpu(ipl->reset_cpu_index); 597 if (!*cs) { 598 /* use any CPU */ 599 *cs = first_cpu; 600 } 601 *reset_type = ipl->reset_type; 602 } 603 604 void s390_ipl_clear_reset_request(void) 605 { 606 S390IPLState *ipl = get_ipl_device(); 607 608 ipl->reset_type = S390_RESET_EXTERNAL; 609 /* use CPU 0 for full resets */ 610 ipl->reset_cpu_index = 0; 611 } 612 613 static void s390_ipl_prepare_qipl(S390CPU *cpu) 614 { 615 S390IPLState *ipl = get_ipl_device(); 616 uint8_t *addr; 617 uint64_t len = 4096; 618 619 addr = cpu_physical_memory_map(cpu->env.psa, &len, 1); 620 if (!addr || len < QIPL_ADDRESS + sizeof(QemuIplParameters)) { 621 error_report("Cannot set QEMU IPL parameters"); 622 return; 623 } 624 memcpy(addr + QIPL_ADDRESS, &ipl->qipl, sizeof(QemuIplParameters)); 625 cpu_physical_memory_unmap(addr, len, 1, len); 626 } 627 628 void s390_ipl_prepare_cpu(S390CPU *cpu) 629 { 630 S390IPLState *ipl = get_ipl_device(); 631 Error *err = NULL; 632 633 cpu->env.psw.addr = ipl->start_addr; 634 cpu->env.psw.mask = IPL_PSW_MASK; 635 636 if (!ipl->kernel || ipl->iplb_valid) { 637 cpu->env.psw.addr = ipl->bios_start_addr; 638 if (!ipl->iplb_valid) { 639 ipl->iplb_valid = s390_gen_initial_iplb(ipl); 640 } 641 } 642 if (ipl->netboot) { 643 if (load_netboot_image(&err) < 0) { 644 error_report_err(err); 645 exit(1); 646 } 647 ipl->qipl.netboot_start_addr = cpu_to_be64(ipl->start_addr); 648 } 649 s390_ipl_set_boot_menu(ipl); 650 s390_ipl_prepare_qipl(cpu); 651 } 652 653 static void s390_ipl_reset(DeviceState *dev) 654 { 655 S390IPLState *ipl = S390_IPL(dev); 656 657 if (ipl->reset_type != S390_RESET_REIPL) { 658 ipl->iplb_valid = false; 659 memset(&ipl->iplb, 0, sizeof(IplParameterBlock)); 660 } 661 } 662 663 static void s390_ipl_class_init(ObjectClass *klass, void *data) 664 { 665 DeviceClass *dc = DEVICE_CLASS(klass); 666 667 dc->realize = s390_ipl_realize; 668 dc->props = s390_ipl_properties; 669 dc->reset = s390_ipl_reset; 670 dc->vmsd = &vmstate_ipl; 671 set_bit(DEVICE_CATEGORY_MISC, dc->categories); 672 /* Reason: Loads the ROMs and thus can only be used one time - internally */ 673 dc->user_creatable = false; 674 } 675 676 static const TypeInfo s390_ipl_info = { 677 .class_init = s390_ipl_class_init, 678 .parent = TYPE_DEVICE, 679 .name = TYPE_S390_IPL, 680 .instance_size = sizeof(S390IPLState), 681 }; 682 683 static void s390_ipl_register_types(void) 684 { 685 type_register_static(&s390_ipl_info); 686 } 687 688 type_init(s390_ipl_register_types) 689