xref: /openbmc/linux/arch/s390/kvm/diag.c (revision b8e660b83d505148c83ddc6d5ba69c29d0eab1e3)
1e28acfeaSChristian Borntraeger /*
2e28acfeaSChristian Borntraeger  * diag.c - handling diagnose instructions
3e28acfeaSChristian Borntraeger  *
4e28acfeaSChristian Borntraeger  * Copyright IBM Corp. 2008
5e28acfeaSChristian Borntraeger  *
6e28acfeaSChristian Borntraeger  * This program is free software; you can redistribute it and/or modify
7e28acfeaSChristian Borntraeger  * it under the terms of the GNU General Public License (version 2 only)
8e28acfeaSChristian Borntraeger  * as published by the Free Software Foundation.
9e28acfeaSChristian Borntraeger  *
10e28acfeaSChristian Borntraeger  *    Author(s): Carsten Otte <cotte@de.ibm.com>
11e28acfeaSChristian Borntraeger  *               Christian Borntraeger <borntraeger@de.ibm.com>
12e28acfeaSChristian Borntraeger  */
13e28acfeaSChristian Borntraeger 
14e28acfeaSChristian Borntraeger #include <linux/kvm.h>
15e28acfeaSChristian Borntraeger #include <linux/kvm_host.h>
16e28acfeaSChristian Borntraeger #include "kvm-s390.h"
17e28acfeaSChristian Borntraeger 
18e28acfeaSChristian Borntraeger static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
19e28acfeaSChristian Borntraeger {
20e28acfeaSChristian Borntraeger 	VCPU_EVENT(vcpu, 5, "%s", "diag time slice end");
21e28acfeaSChristian Borntraeger 	vcpu->stat.diagnose_44++;
22e28acfeaSChristian Borntraeger 	vcpu_put(vcpu);
23b8cee18cSChristian Borntraeger 	yield();
24e28acfeaSChristian Borntraeger 	vcpu_load(vcpu);
25e28acfeaSChristian Borntraeger 	return 0;
26e28acfeaSChristian Borntraeger }
27e28acfeaSChristian Borntraeger 
28e28acfeaSChristian Borntraeger static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
29e28acfeaSChristian Borntraeger {
30e28acfeaSChristian Borntraeger 	unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
31e28acfeaSChristian Borntraeger 	unsigned long subcode = vcpu->arch.guest_gprs[reg] & 0xffff;
32e28acfeaSChristian Borntraeger 
33e28acfeaSChristian Borntraeger 	VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
34e28acfeaSChristian Borntraeger 	switch (subcode) {
35e28acfeaSChristian Borntraeger 	case 3:
36e28acfeaSChristian Borntraeger 		vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
37e28acfeaSChristian Borntraeger 		break;
38e28acfeaSChristian Borntraeger 	case 4:
39e28acfeaSChristian Borntraeger 		vcpu->run->s390_reset_flags = 0;
40e28acfeaSChristian Borntraeger 		break;
41e28acfeaSChristian Borntraeger 	default:
42*b8e660b8SHeiko Carstens 		return -EOPNOTSUPP;
43e28acfeaSChristian Borntraeger 	}
44e28acfeaSChristian Borntraeger 
45e28acfeaSChristian Borntraeger 	atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
46e28acfeaSChristian Borntraeger 	vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
47e28acfeaSChristian Borntraeger 	vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL;
48e28acfeaSChristian Borntraeger 	vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
49e28acfeaSChristian Borntraeger 	vcpu->run->exit_reason = KVM_EXIT_S390_RESET;
5033e19115SHeiko Carstens 	VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx",
51e28acfeaSChristian Borntraeger 	  vcpu->run->s390_reset_flags);
52e28acfeaSChristian Borntraeger 	return -EREMOTE;
53e28acfeaSChristian Borntraeger }
54e28acfeaSChristian Borntraeger 
55e28acfeaSChristian Borntraeger int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
56e28acfeaSChristian Borntraeger {
57e28acfeaSChristian Borntraeger 	int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
58e28acfeaSChristian Borntraeger 
59e28acfeaSChristian Borntraeger 	switch (code) {
60e28acfeaSChristian Borntraeger 	case 0x44:
61e28acfeaSChristian Borntraeger 		return __diag_time_slice_end(vcpu);
62e28acfeaSChristian Borntraeger 	case 0x308:
63e28acfeaSChristian Borntraeger 		return __diag_ipl_functions(vcpu);
64e28acfeaSChristian Borntraeger 	default:
65*b8e660b8SHeiko Carstens 		return -EOPNOTSUPP;
66e28acfeaSChristian Borntraeger 	}
67e28acfeaSChristian Borntraeger }
68