1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * ucall support. A ucall is a "hypercall to userspace". 4 * 5 * Copyright (C) 2021 Western Digital Corporation or its affiliates. 6 */ 7 8 #include <linux/kvm.h> 9 10 #include "kvm_util.h" 11 #include "processor.h" 12 #include "sbi.h" 13 ucall_arch_get_ucall(struct kvm_vcpu * vcpu)14void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu) 15 { 16 struct kvm_run *run = vcpu->run; 17 18 if (run->exit_reason == KVM_EXIT_RISCV_SBI && 19 run->riscv_sbi.extension_id == KVM_RISCV_SELFTESTS_SBI_EXT) { 20 switch (run->riscv_sbi.function_id) { 21 case KVM_RISCV_SELFTESTS_SBI_UCALL: 22 return (void *)run->riscv_sbi.args[0]; 23 case KVM_RISCV_SELFTESTS_SBI_UNEXP: 24 vcpu_dump(stderr, vcpu, 2); 25 TEST_ASSERT(0, "Unexpected trap taken by guest"); 26 break; 27 default: 28 break; 29 } 30 } 31 return NULL; 32 } 33