+ if (reset_type == S390_RESET_EXTERNAL || reset_type == S390_RESET_REIPL) {
+ /* use CPU 0 for full resets */
+ ipl->reset_cpu_index = 0;
+ } else {
+ ipl->reset_cpu_index = cs->cpu_index;
+ }
+ ipl->reset_type = reset_type;
+
+ if (reset_type == S390_RESET_REIPL &&
+ ipl->iplb_valid &&
+ !ipl->netboot &&
+ ipl->iplb.pbt == S390_IPL_TYPE_CCW &&
+ is_virtio_scsi_device(&ipl->iplb)) {
+ CcwDevice *ccw_dev = s390_get_ccw_device(get_boot_device(0));
+
+ if (ccw_dev &&
+ cpu_to_be16(ccw_dev->sch->devno) == ipl->iplb.ccw.devno &&
+ (ccw_dev->sch->ssid & 3) == ipl->iplb.ccw.ssid) {
+ /*
+ * this is the original boot device's SCSI
+ * so restore IPL parameter info from it
+ */
+ ipl->iplb_valid = s390_gen_initial_iplb(ipl);
+ }
+ }
+ if (reset_type == S390_RESET_MODIFIED_CLEAR ||
+ reset_type == S390_RESET_LOAD_NORMAL) {
+ /* ignore -no-reboot, send no event */
+ qemu_system_reset_request(SHUTDOWN_CAUSE_SUBSYSTEM_RESET);
+ } else {
+ qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
+ }
+ /* as this is triggered by a CPU, make sure to exit the loop */
+ if (tcg_enabled()) {
+ cpu_loop_exit(cs);
+ }
+}
+
+void s390_ipl_get_reset_request(CPUState **cs, enum s390_reset *reset_type)
+{
+ S390IPLState *ipl = get_ipl_device();
+
+ *cs = qemu_get_cpu(ipl->reset_cpu_index);
+ if (!*cs) {
+ /* use any CPU */
+ *cs = first_cpu;
+ }
+ *reset_type = ipl->reset_type;
+}
+
+void s390_ipl_clear_reset_request(void)
+{
+ S390IPLState *ipl = get_ipl_device();
+
+ ipl->reset_type = S390_RESET_EXTERNAL;
+ /* use CPU 0 for full resets */
+ ipl->reset_cpu_index = 0;
+}
+
+static void s390_ipl_prepare_qipl(S390CPU *cpu)
+{
+ S390IPLState *ipl = get_ipl_device();
+ uint8_t *addr;
+ uint64_t len = 4096;
+
+ addr = cpu_physical_memory_map(cpu->env.psa, &len, 1);
+ if (!addr || len < QIPL_ADDRESS + sizeof(QemuIplParameters)) {
+ error_report("Cannot set QEMU IPL parameters");
+ return;
+ }
+ memcpy(addr + QIPL_ADDRESS, &ipl->qipl, sizeof(QemuIplParameters));
+ cpu_physical_memory_unmap(addr, len, 1, len);