xref: /linux/arch/riscv/kvm/vcpu_sbi_sta.c (revision 38b3390ee4880140b6245fe3273fe9ce53f65bde)
15fed84a8SAndrew Jones // SPDX-License-Identifier: GPL-2.0
25fed84a8SAndrew Jones /*
35fed84a8SAndrew Jones  * Copyright (c) 2023 Ventana Micro Systems Inc.
45fed84a8SAndrew Jones  */
55fed84a8SAndrew Jones 
65fed84a8SAndrew Jones #include <linux/kvm_host.h>
75fed84a8SAndrew Jones 
85fed84a8SAndrew Jones #include <asm/kvm_vcpu_sbi.h>
95fed84a8SAndrew Jones #include <asm/sbi.h>
105fed84a8SAndrew Jones 
11*38b3390eSAndrew Jones void kvm_riscv_vcpu_sbi_sta_reset(struct kvm_vcpu *vcpu)
12*38b3390eSAndrew Jones {
13*38b3390eSAndrew Jones 	vcpu->arch.sta.shmem = INVALID_GPA;
14*38b3390eSAndrew Jones 	vcpu->arch.sta.last_steal = 0;
15*38b3390eSAndrew Jones }
16*38b3390eSAndrew Jones 
172a1f6bf0SAndrew Jones void kvm_riscv_vcpu_record_steal_time(struct kvm_vcpu *vcpu)
182a1f6bf0SAndrew Jones {
19*38b3390eSAndrew Jones 	gpa_t shmem = vcpu->arch.sta.shmem;
20*38b3390eSAndrew Jones 
21*38b3390eSAndrew Jones 	if (shmem == INVALID_GPA)
22*38b3390eSAndrew Jones 		return;
232a1f6bf0SAndrew Jones }
242a1f6bf0SAndrew Jones 
255fed84a8SAndrew Jones static int kvm_sbi_sta_steal_time_set_shmem(struct kvm_vcpu *vcpu)
265fed84a8SAndrew Jones {
275fed84a8SAndrew Jones 	return SBI_ERR_FAILURE;
285fed84a8SAndrew Jones }
295fed84a8SAndrew Jones 
305fed84a8SAndrew Jones static int kvm_sbi_ext_sta_handler(struct kvm_vcpu *vcpu, struct kvm_run *run,
315fed84a8SAndrew Jones 				   struct kvm_vcpu_sbi_return *retdata)
325fed84a8SAndrew Jones {
335fed84a8SAndrew Jones 	struct kvm_cpu_context *cp = &vcpu->arch.guest_context;
345fed84a8SAndrew Jones 	unsigned long funcid = cp->a6;
355fed84a8SAndrew Jones 	int ret;
365fed84a8SAndrew Jones 
375fed84a8SAndrew Jones 	switch (funcid) {
385fed84a8SAndrew Jones 	case SBI_EXT_STA_STEAL_TIME_SET_SHMEM:
395fed84a8SAndrew Jones 		ret = kvm_sbi_sta_steal_time_set_shmem(vcpu);
405fed84a8SAndrew Jones 		break;
415fed84a8SAndrew Jones 	default:
425fed84a8SAndrew Jones 		ret = SBI_ERR_NOT_SUPPORTED;
435fed84a8SAndrew Jones 		break;
445fed84a8SAndrew Jones 	}
455fed84a8SAndrew Jones 
465fed84a8SAndrew Jones 	retdata->err_val = ret;
475fed84a8SAndrew Jones 
485fed84a8SAndrew Jones 	return 0;
495fed84a8SAndrew Jones }
505fed84a8SAndrew Jones 
515fed84a8SAndrew Jones static unsigned long kvm_sbi_ext_sta_probe(struct kvm_vcpu *vcpu)
525fed84a8SAndrew Jones {
535fed84a8SAndrew Jones 	return 0;
545fed84a8SAndrew Jones }
555fed84a8SAndrew Jones 
565fed84a8SAndrew Jones const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = {
575fed84a8SAndrew Jones 	.extid_start = SBI_EXT_STA,
585fed84a8SAndrew Jones 	.extid_end = SBI_EXT_STA,
595fed84a8SAndrew Jones 	.handler = kvm_sbi_ext_sta_handler,
605fed84a8SAndrew Jones 	.probe = kvm_sbi_ext_sta_probe,
615fed84a8SAndrew Jones };
62