| 1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 |
/** |
| 3 |
* Copyright (c) 2021 Western Digital Corporation or its affiliates. |
| 4 |
* |
| 5 |
* Authors: |
| 6 |
* Atish Patra <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __RISCV_KVM_VCPU_SBI_H__ |
| 10 |
#define __RISCV_KVM_VCPU_SBI_H__ |
| 11 |
|
| 12 |
#define KVM_SBI_IMPID 3 |
| 13 |
|
| 14 |
#define KVM_SBI_VERSION_MAJOR 3 |
| 15 |
#define KVM_SBI_VERSION_MINOR 0 |
| 16 |
|
| 17 |
enum kvm_riscv_sbi_ext_status { |
| 18 |
KVM_RISCV_SBI_EXT_STATUS_UNINITIALIZED, |
| 19 |
KVM_RISCV_SBI_EXT_STATUS_UNAVAILABLE, |
| 20 |
KVM_RISCV_SBI_EXT_STATUS_ENABLED, |
| 21 |
KVM_RISCV_SBI_EXT_STATUS_DISABLED, |
| 22 |
}; |
| 23 |
|
| 24 |
struct kvm_vcpu_sbi_context { |
| 25 |
int return_handled; |
| 26 |
enum kvm_riscv_sbi_ext_status ext_status[KVM_RISCV_SBI_EXT_MAX]; |
| 27 |
}; |
| 28 |
|
| 29 |
struct kvm_vcpu_sbi_return { |
| 30 |
unsigned long out_val; |
| 31 |
unsigned long err_val; |
| 32 |
struct kvm_cpu_trap *utrap; |
| 33 |
bool uexit; |
| 34 |
}; |
| 35 |
|
| 36 |
struct kvm_vcpu_sbi_extension { |
| 37 |
unsigned long extid_start; |
| 38 |
unsigned long extid_end; |
| 39 |
|
| 40 |
bool default_disabled; |
| 41 |
|
| 42 |
/** |
| 43 |
* SBI extension handler. It can be defined for a given extension or group of |
| 44 |
* extension. But it should always return linux error codes rather than SBI |
| 45 |
* specific error codes. |
| 46 |
*/ |
| 47 |
int (*handler)(struct kvm_vcpu *vcpu, struct kvm_run *run, |
| 48 |
struct kvm_vcpu_sbi_return *retdata); |
| 49 |
|
| 50 |
/* Extension specific probe function */ |
| 51 |
unsigned long (*probe)(struct kvm_vcpu *vcpu); |
| 52 |
|
| 53 |
/* |
| 54 |
* Init/deinit function called once during VCPU init/destroy. These |
| 55 |
* might be use if the SBI extensions need to allocate or do specific |
| 56 |
* init time only configuration. |
| 57 |
*/ |
| 58 |
int (*init)(struct kvm_vcpu *vcpu); |
| 59 |
void (*deinit)(struct kvm_vcpu *vcpu); |
| 60 |
|
| 61 |
void (*reset)(struct kvm_vcpu *vcpu); |
| 62 |
|
| 63 |
unsigned long state_reg_subtype; |
| 64 |
unsigned long (*get_state_reg_count)(struct kvm_vcpu *vcpu); |
| 65 |
int (*get_state_reg_id)(struct kvm_vcpu *vcpu, int index, u64 *reg_id); |
| 66 |
int (*get_state_reg)(struct kvm_vcpu *vcpu, unsigned long reg_num, |
| 67 |
unsigned long reg_size, void *reg_val); |
| 68 |
int (*set_state_reg)(struct kvm_vcpu *vcpu, unsigned long reg_num, |
| 69 |
unsigned long reg_size, const void *reg_val); |
| 70 |
}; |
| 71 |
|
| 72 |
int kvm_riscv_vcpu_sbi_forward_handler(struct kvm_vcpu *vcpu, |
| 73 |
struct kvm_run *run, |
| 74 |
struct kvm_vcpu_sbi_return *retdata); |
| 75 |
void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu, |
| 76 |
struct kvm_run *run, |
| 77 |
u32 type, u64 flags); |
| 78 |
void kvm_riscv_vcpu_sbi_request_reset(struct kvm_vcpu *vcpu, |
| 79 |
unsigned long pc, unsigned long a1); |
| 80 |
void kvm_riscv_vcpu_sbi_load_reset_state(struct kvm_vcpu *vcpu); |
| 81 |
int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run); |
| 82 |
int kvm_riscv_vcpu_reg_indices_sbi_ext(struct kvm_vcpu *vcpu, u64 __user *uindices); |
| 83 |
int kvm_riscv_vcpu_set_reg_sbi_ext(struct kvm_vcpu *vcpu, |
| 84 |
const struct kvm_one_reg *reg); |
| 85 |
int kvm_riscv_vcpu_get_reg_sbi_ext(struct kvm_vcpu *vcpu, |
| 86 |
const struct kvm_one_reg *reg); |
| 87 |
int kvm_riscv_vcpu_reg_indices_sbi(struct kvm_vcpu *vcpu, u64 __user *uindices); |
| 88 |
int kvm_riscv_vcpu_set_reg_sbi(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); |
| 89 |
int kvm_riscv_vcpu_get_reg_sbi(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); |
| 90 |
const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext( |
| 91 |
struct kvm_vcpu *vcpu, unsigned long extid); |
| 92 |
int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run); |
| 93 |
void kvm_riscv_vcpu_sbi_init(struct kvm_vcpu *vcpu); |
| 94 |
void kvm_riscv_vcpu_sbi_deinit(struct kvm_vcpu *vcpu); |
| 95 |
void kvm_riscv_vcpu_sbi_reset(struct kvm_vcpu *vcpu); |
| 96 |
|
| 97 |
#ifdef CONFIG_RISCV_SBI_V01 |
| 98 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_v01; |
| 99 |
#endif |
| 100 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base; |
| 101 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time; |
| 102 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi; |
| 103 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence; |
| 104 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst; |
| 105 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; |
| 106 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn; |
| 107 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_susp; |
| 108 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_sta; |
| 109 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft; |
| 110 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_mpxy; |
| 111 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental; |
| 112 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; |
| 113 |
|
| 114 |
#ifdef CONFIG_RISCV_PMU_SBI |
| 115 |
extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_pmu; |
| 116 |
#endif |
| 117 |
#endif /* __RISCV_KVM_VCPU_SBI_H__ */ |