xref: /linux/arch/mips/kvm/hypcall.c (revision a976c2951d8f376112361830aa7762beff83a205)
1*955d8dc3SJames Hogan /*
2*955d8dc3SJames Hogan  * This file is subject to the terms and conditions of the GNU General Public
3*955d8dc3SJames Hogan  * License.  See the file "COPYING" in the main directory of this archive
4*955d8dc3SJames Hogan  * for more details.
5*955d8dc3SJames Hogan  *
6*955d8dc3SJames Hogan  * KVM/MIPS: Hypercall handling.
7*955d8dc3SJames Hogan  *
8*955d8dc3SJames Hogan  * Copyright (C) 2015  Imagination Technologies Ltd.
9*955d8dc3SJames Hogan  */
10*955d8dc3SJames Hogan 
11*955d8dc3SJames Hogan #include <linux/kernel.h>
12*955d8dc3SJames Hogan #include <linux/kvm_host.h>
13*955d8dc3SJames Hogan #include <linux/kvm_para.h>
14*955d8dc3SJames Hogan 
15*955d8dc3SJames Hogan #define MAX_HYPCALL_ARGS	4
16*955d8dc3SJames Hogan 
kvm_mips_emul_hypcall(struct kvm_vcpu * vcpu,union mips_instruction inst)17*955d8dc3SJames Hogan enum emulation_result kvm_mips_emul_hypcall(struct kvm_vcpu *vcpu,
18*955d8dc3SJames Hogan 					    union mips_instruction inst)
19*955d8dc3SJames Hogan {
20*955d8dc3SJames Hogan 	unsigned int code = (inst.co_format.code >> 5) & 0x3ff;
21*955d8dc3SJames Hogan 
22*955d8dc3SJames Hogan 	kvm_debug("[%#lx] HYPCALL %#03x\n", vcpu->arch.pc, code);
23*955d8dc3SJames Hogan 
24*955d8dc3SJames Hogan 	switch (code) {
25*955d8dc3SJames Hogan 	case 0:
26*955d8dc3SJames Hogan 		return EMULATE_HYPERCALL;
27*955d8dc3SJames Hogan 	default:
28*955d8dc3SJames Hogan 		return EMULATE_FAIL;
29*955d8dc3SJames Hogan 	};
30*955d8dc3SJames Hogan }
31*955d8dc3SJames Hogan 
kvm_mips_hypercall(struct kvm_vcpu * vcpu,unsigned long num,const unsigned long * args,unsigned long * hret)32*955d8dc3SJames Hogan static int kvm_mips_hypercall(struct kvm_vcpu *vcpu, unsigned long num,
33*955d8dc3SJames Hogan 			      const unsigned long *args, unsigned long *hret)
34*955d8dc3SJames Hogan {
35*955d8dc3SJames Hogan 	/* Report unimplemented hypercall to guest */
36*955d8dc3SJames Hogan 	*hret = -KVM_ENOSYS;
37*955d8dc3SJames Hogan 	return RESUME_GUEST;
38*955d8dc3SJames Hogan }
39*955d8dc3SJames Hogan 
kvm_mips_handle_hypcall(struct kvm_vcpu * vcpu)40*955d8dc3SJames Hogan int kvm_mips_handle_hypcall(struct kvm_vcpu *vcpu)
41*955d8dc3SJames Hogan {
42*955d8dc3SJames Hogan 	unsigned long num, args[MAX_HYPCALL_ARGS];
43*955d8dc3SJames Hogan 
44*955d8dc3SJames Hogan 	/* read hypcall number and arguments */
45*955d8dc3SJames Hogan 	num = vcpu->arch.gprs[2];	/* v0 */
46*955d8dc3SJames Hogan 	args[0] = vcpu->arch.gprs[4];	/* a0 */
47*955d8dc3SJames Hogan 	args[1] = vcpu->arch.gprs[5];	/* a1 */
48*955d8dc3SJames Hogan 	args[2] = vcpu->arch.gprs[6];	/* a2 */
49*955d8dc3SJames Hogan 	args[3] = vcpu->arch.gprs[7];	/* a3 */
50*955d8dc3SJames Hogan 
51*955d8dc3SJames Hogan 	return kvm_mips_hypercall(vcpu, num,
52*955d8dc3SJames Hogan 				  args, &vcpu->arch.gprs[2] /* v0 */);
53*955d8dc3SJames Hogan }
54