xref: /linux/tools/testing/selftests/kvm/lib/s390x/ucall.c (revision dd093fb0)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * ucall support. A ucall is a "hypercall to userspace".
4  *
5  * Copyright (C) 2019 Red Hat, Inc.
6  */
7 #include "kvm_util.h"
8 
9 void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa)
10 {
11 }
12 
13 void ucall_arch_do_ucall(vm_vaddr_t uc)
14 {
15 	/* Exit via DIAGNOSE 0x501 (normally used for breakpoints) */
16 	asm volatile ("diag 0,%0,0x501" : : "a"(uc) : "memory");
17 }
18 
19 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu)
20 {
21 	struct kvm_run *run = vcpu->run;
22 
23 	if (run->exit_reason == KVM_EXIT_S390_SIEIC &&
24 	    run->s390_sieic.icptcode == 4 &&
25 	    (run->s390_sieic.ipa >> 8) == 0x83 &&    /* 0x83 means DIAGNOSE */
26 	    (run->s390_sieic.ipb >> 16) == 0x501) {
27 		int reg = run->s390_sieic.ipa & 0xf;
28 
29 		return (void *)run->s.regs.gprs[reg];
30 	}
31 	return NULL;
32 }
33