1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * ucall support. A ucall is a "hypercall to userspace".
4  *
5  * Copyright (C) 2018, Red Hat, Inc.
6  */
7 #include "kvm_util.h"
8 
9 #define UCALL_PIO_PORT ((uint16_t)0x1000)
10 
11 void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa)
12 {
13 }
14 
15 void ucall_arch_do_ucall(vm_vaddr_t uc)
16 {
17 	asm volatile("in %[port], %%al"
18 		: : [port] "d" (UCALL_PIO_PORT), "D" (uc) : "rax", "memory");
19 }
20 
21 void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu)
22 {
23 	struct kvm_run *run = vcpu->run;
24 
25 	if (run->exit_reason == KVM_EXIT_IO && run->io.port == UCALL_PIO_PORT) {
26 		struct kvm_regs regs;
27 
28 		vcpu_regs_get(vcpu, &regs);
29 		return (void *)regs.rdi;
30 	}
31 	return NULL;
32 }
33