diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c index be1f5f1061375057bc21bea041ca7a9b3e482ff5..63ccd5c35a37cc04c0910f3ed062b3b09ee8d3d2 100644 --- a/hw/s390-virtio-bus.c +++ b/hw/s390-virtio-bus.c @@ -57,6 +57,29 @@ static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev); /* length of VirtIO device pages */ const target_phys_addr_t virtio_size = S390_DEVICE_PAGES * TARGET_PAGE_SIZE; +static void s390_virtio_bus_reset(void *opaque) +{ + VirtIOS390Bus *bus = opaque; + bus->next_ring = bus->dev_page + TARGET_PAGE_SIZE; +} + +void s390_virtio_reset_idx(VirtIOS390Device *dev) +{ + int i; + target_phys_addr_t idx_addr; + uint8_t num_vq; + + num_vq = s390_virtio_device_num_vq(dev); + for (i = 0; i < num_vq; i++) { + idx_addr = virtio_queue_get_avail_addr(dev->vdev, i) + + VIRTIO_VRING_AVAIL_IDX_OFFS; + stw_phys(idx_addr, 0); + idx_addr = virtio_queue_get_used_addr(dev->vdev, i) + + VIRTIO_VRING_USED_IDX_OFFS; + stw_phys(idx_addr, 0); + } +} + VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size) { VirtIOS390Bus *bus; @@ -82,6 +105,7 @@ VirtIOS390Bus *s390_virtio_bus_init(ram_addr_t *ram_size) /* Allocate RAM for VirtIO device pages (descriptors, queues, rings) */ *ram_size += S390_DEVICE_PAGES * TARGET_PAGE_SIZE; + qemu_register_reset(s390_virtio_bus_reset, bus); return bus; } @@ -114,7 +138,7 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev) virtio_bind_device(vdev, &virtio_s390_bindings, dev); dev->host_features = vdev->get_features(vdev, dev->host_features); s390_virtio_device_sync(dev); - + s390_virtio_reset_idx(dev); if (dev->qdev.hotplugged) { CPUS390XState *env = s390_cpu_addr2state(0); s390_virtio_irq(env, VIRTIO_PARAM_DEV_ADD, dev->dev_offs); diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h index 0e60bc0fa2b5c2199515fe934456101cac66e1c2..49e6c462df321b4cb870ebfb19cc2e7c994abd44 100644 --- a/hw/s390-virtio-bus.h +++ b/hw/s390-virtio-bus.h @@ -34,6 +34,8 @@ #define VIRTIO_VQCONFIG_LEN 24 #define VIRTIO_RING_LEN (TARGET_PAGE_SIZE * 3) +#define VIRTIO_VRING_AVAIL_IDX_OFFS 2 +#define VIRTIO_VRING_USED_IDX_OFFS 2 #define S390_DEVICE_PAGES 512 #define VIRTIO_PARAM_MASK 0xff @@ -90,3 +92,5 @@ VirtIOS390Device *s390_virtio_bus_find_vring(VirtIOS390Bus *bus, ram_addr_t mem, int *vq_num); VirtIOS390Device *s390_virtio_bus_find_mem(VirtIOS390Bus *bus, ram_addr_t mem); void s390_virtio_device_sync(VirtIOS390Device *dev); +void s390_virtio_reset_idx(VirtIOS390Device *dev); + diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c index 1ebe70d0e3e0f58fb8cb58257af9350260384732..c0e19fd66d7549c0026ccb3fa859e83a36e8aa10 100644 --- a/hw/s390-virtio.c +++ b/hw/s390-virtio.c @@ -99,6 +99,7 @@ int s390_virtio_hypercall(CPUS390XState *env, uint64_t mem, uint64_t hypercall) virtio_reset(dev->vdev); stb_phys(dev->dev_offs + VIRTIO_DEV_OFFS_STATUS, 0); s390_virtio_device_sync(dev); + s390_virtio_reset_idx(dev); break; } case KVM_S390_VIRTIO_SET_STATUS: @@ -230,6 +231,11 @@ static void s390_init(ram_addr_t my_ram_size, if (kernel_size == -1UL) { kernel_size = load_image_targphys(kernel_filename, 0, ram_size); } + if (kernel_size == -1UL) { + fprintf(stderr, "qemu: could not load kernel '%s'\n", + kernel_filename); + exit(1); + } /* * we can not rely on the ELF entry point, since up to 3.2 this * value was 0x800 (the SALIPL loader) and it wont work. For @@ -269,12 +275,18 @@ static void s390_init(ram_addr_t my_ram_size, } initrd_size = load_image_targphys(initrd_filename, initrd_offset, ram_size - initrd_offset); + if (initrd_size == -1UL) { + fprintf(stderr, "qemu: could not load initrd '%s'\n", + initrd_filename); + exit(1); + } + /* we have to overwrite values in the kernel image, which are "rom" */ memcpy(rom_ptr(INITRD_PARM_START), &initrd_offset, 8); memcpy(rom_ptr(INITRD_PARM_SIZE), &initrd_size, 8); } - if (kernel_cmdline) { + if (rom_ptr(KERN_PARM_AREA)) { /* we have to overwrite values in the kernel image, which are "rom" */ memcpy(rom_ptr(KERN_PARM_AREA), kernel_cmdline, strlen(kernel_cmdline) + 1); @@ -320,8 +332,11 @@ static QEMUMachine s390_machine = { .alias = "s390", .desc = "VirtIO based S390 machine", .init = s390_init, + .no_cdrom = 1, + .no_floppy = 1, .no_serial = 1, .no_parallel = 1, + .no_sdcard = 1, .use_virtcon = 1, .max_cpus = 255, .is_default = 1, diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 2b6723149de3f3b1200ecd3e98e76835f216267f..90aad61eb09de6b87118e24aa2299324e9b50787 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -407,6 +407,12 @@ static int handle_instruction(CPUS390XState *env, struct kvm_run *run) return 0; } +static bool is_special_wait_psw(CPUS390XState *env) +{ + /* signal quiesce */ + return env->kvm_run->psw_addr == 0xfffUL; +} + static int handle_intercept(CPUS390XState *env) { struct kvm_run *run = env->kvm_run; @@ -420,6 +426,12 @@ static int handle_intercept(CPUS390XState *env) r = handle_instruction(env, run); break; case ICPT_WAITPSW: + if (s390_del_running_cpu(env) == 0 && + is_special_wait_psw(env)) { + qemu_system_shutdown_request(); + } + r = EXCP_HALTED; + break; case ICPT_CPU_STOP: if (s390_del_running_cpu(env) == 0) { qemu_system_shutdown_request(); @@ -452,8 +464,7 @@ int kvm_arch_handle_exit(CPUS390XState *env, struct kvm_run *run) ret = handle_intercept(env); break; case KVM_EXIT_S390_RESET: - fprintf(stderr, "RESET not implemented\n"); - exit(1); + qemu_system_reset_request(); break; default: fprintf(stderr, "Unknown KVM exit: %d\n", run->exit_reason);