|
3 | 3 | * Copyright (c) 2023 Ventana Micro Systems Inc. |
4 | 4 | */ |
5 | 5 |
|
| 6 | +#include <linux/kconfig.h> |
| 7 | +#include <linux/kernel.h> |
6 | 8 | #include <linux/kvm_host.h> |
7 | 9 |
|
8 | 10 | #include <asm/kvm_vcpu_sbi.h> |
@@ -59,3 +61,56 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta = { |
59 | 61 | .handler = kvm_sbi_ext_sta_handler, |
60 | 62 | .probe = kvm_sbi_ext_sta_probe, |
61 | 63 | }; |
| 64 | + |
| 65 | +int kvm_riscv_vcpu_get_reg_sbi_sta(struct kvm_vcpu *vcpu, |
| 66 | + unsigned long reg_num, |
| 67 | + unsigned long *reg_val) |
| 68 | +{ |
| 69 | + switch (reg_num) { |
| 70 | + case KVM_REG_RISCV_SBI_STA_REG(shmem_lo): |
| 71 | + *reg_val = (unsigned long)vcpu->arch.sta.shmem; |
| 72 | + break; |
| 73 | + case KVM_REG_RISCV_SBI_STA_REG(shmem_hi): |
| 74 | + if (IS_ENABLED(CONFIG_32BIT)) |
| 75 | + *reg_val = upper_32_bits(vcpu->arch.sta.shmem); |
| 76 | + else |
| 77 | + *reg_val = 0; |
| 78 | + break; |
| 79 | + default: |
| 80 | + return -EINVAL; |
| 81 | + } |
| 82 | + |
| 83 | + return 0; |
| 84 | +} |
| 85 | + |
| 86 | +int kvm_riscv_vcpu_set_reg_sbi_sta(struct kvm_vcpu *vcpu, |
| 87 | + unsigned long reg_num, |
| 88 | + unsigned long reg_val) |
| 89 | +{ |
| 90 | + switch (reg_num) { |
| 91 | + case KVM_REG_RISCV_SBI_STA_REG(shmem_lo): |
| 92 | + if (IS_ENABLED(CONFIG_32BIT)) { |
| 93 | + gpa_t hi = upper_32_bits(vcpu->arch.sta.shmem); |
| 94 | + |
| 95 | + vcpu->arch.sta.shmem = reg_val; |
| 96 | + vcpu->arch.sta.shmem |= hi << 32; |
| 97 | + } else { |
| 98 | + vcpu->arch.sta.shmem = reg_val; |
| 99 | + } |
| 100 | + break; |
| 101 | + case KVM_REG_RISCV_SBI_STA_REG(shmem_hi): |
| 102 | + if (IS_ENABLED(CONFIG_32BIT)) { |
| 103 | + gpa_t lo = lower_32_bits(vcpu->arch.sta.shmem); |
| 104 | + |
| 105 | + vcpu->arch.sta.shmem = ((gpa_t)reg_val << 32); |
| 106 | + vcpu->arch.sta.shmem |= lo; |
| 107 | + } else if (reg_val != 0) { |
| 108 | + return -EINVAL; |
| 109 | + } |
| 110 | + break; |
| 111 | + default: |
| 112 | + return -EINVAL; |
| 113 | + } |
| 114 | + |
| 115 | + return 0; |
| 116 | +} |
0 commit comments