2021-09-27 17:10:01 +05:30
|
|
|
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Western Digital Corporation or its affiliates.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_KVM_RISCV_H
|
|
|
|
#define __LINUX_KVM_RISCV_H
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
|
|
|
|
#define __KVM_HAVE_READONLY_MEM
|
|
|
|
|
|
|
|
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
|
|
|
|
|
2021-09-27 17:10:03 +05:30
|
|
|
#define KVM_INTERRUPT_SET -1U
|
|
|
|
#define KVM_INTERRUPT_UNSET -2U
|
|
|
|
|
2021-09-27 17:10:01 +05:30
|
|
|
/* for KVM_GET_REGS and KVM_SET_REGS */
|
|
|
|
struct kvm_regs {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* for KVM_GET_FPU and KVM_SET_FPU */
|
|
|
|
struct kvm_fpu {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* KVM Debug exit structure */
|
|
|
|
struct kvm_debug_exit_arch {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* for KVM_SET_GUEST_DEBUG */
|
|
|
|
struct kvm_guest_debug_arch {
|
|
|
|
};
|
|
|
|
|
|
|
|
/* definition of registers in kvm_run */
|
|
|
|
struct kvm_sync_regs {
|
|
|
|
};
|
|
|
|
|
RISC-V: KVM: Implement KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls
For KVM RISC-V, we use KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls to access
VCPU config and registers from user-space.
We have three types of VCPU registers:
1. CONFIG - these are VCPU config and capabilities
2. CORE - these are VCPU general purpose registers
3. CSR - these are VCPU control and status registers
The CONFIG register available to user-space is ISA. The ISA register is
a read and write register where user-space can only write the desired
VCPU ISA capabilities before running the VCPU.
The CORE registers available to user-space are PC, RA, SP, GP, TP, A0-A7,
T0-T6, S0-S11 and MODE. Most of these are RISC-V general registers except
PC and MODE. The PC register represents program counter whereas the MODE
register represent VCPU privilege mode (i.e. S/U-mode).
The CSRs available to user-space are SSTATUS, SIE, STVEC, SSCRATCH, SEPC,
SCAUSE, STVAL, SIP, and SATP. All of these are read/write registers.
In future, more VCPU register types will be added (such as FP) for the
KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-27 17:10:04 +05:30
|
|
|
/* for KVM_GET_SREGS and KVM_SET_SREGS */
|
2021-09-27 17:10:01 +05:30
|
|
|
struct kvm_sregs {
|
|
|
|
};
|
|
|
|
|
RISC-V: KVM: Implement KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls
For KVM RISC-V, we use KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls to access
VCPU config and registers from user-space.
We have three types of VCPU registers:
1. CONFIG - these are VCPU config and capabilities
2. CORE - these are VCPU general purpose registers
3. CSR - these are VCPU control and status registers
The CONFIG register available to user-space is ISA. The ISA register is
a read and write register where user-space can only write the desired
VCPU ISA capabilities before running the VCPU.
The CORE registers available to user-space are PC, RA, SP, GP, TP, A0-A7,
T0-T6, S0-S11 and MODE. Most of these are RISC-V general registers except
PC and MODE. The PC register represents program counter whereas the MODE
register represent VCPU privilege mode (i.e. S/U-mode).
The CSRs available to user-space are SSTATUS, SIE, STVEC, SSCRATCH, SEPC,
SCAUSE, STVAL, SIP, and SATP. All of these are read/write registers.
In future, more VCPU register types will be added (such as FP) for the
KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-27 17:10:04 +05:30
|
|
|
/* CONFIG registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_config {
|
|
|
|
unsigned long isa;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_core {
|
|
|
|
struct user_regs_struct regs;
|
|
|
|
unsigned long mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Possible privilege modes for kvm_riscv_core */
|
|
|
|
#define KVM_RISCV_MODE_S 1
|
|
|
|
#define KVM_RISCV_MODE_U 0
|
|
|
|
|
|
|
|
/* CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_csr {
|
|
|
|
unsigned long sstatus;
|
|
|
|
unsigned long sie;
|
|
|
|
unsigned long stvec;
|
|
|
|
unsigned long sscratch;
|
|
|
|
unsigned long sepc;
|
|
|
|
unsigned long scause;
|
|
|
|
unsigned long stval;
|
|
|
|
unsigned long sip;
|
|
|
|
unsigned long satp;
|
|
|
|
unsigned long scounteren;
|
|
|
|
};
|
|
|
|
|
2021-09-27 17:10:11 +05:30
|
|
|
/* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_timer {
|
|
|
|
__u64 frequency;
|
|
|
|
__u64 time;
|
|
|
|
__u64 compare;
|
|
|
|
__u64 state;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Possible states for kvm_riscv_timer */
|
|
|
|
#define KVM_RISCV_TIMER_STATE_OFF 0
|
|
|
|
#define KVM_RISCV_TIMER_STATE_ON 1
|
|
|
|
|
RISC-V: KVM: Implement KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls
For KVM RISC-V, we use KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls to access
VCPU config and registers from user-space.
We have three types of VCPU registers:
1. CONFIG - these are VCPU config and capabilities
2. CORE - these are VCPU general purpose registers
3. CSR - these are VCPU control and status registers
The CONFIG register available to user-space is ISA. The ISA register is
a read and write register where user-space can only write the desired
VCPU ISA capabilities before running the VCPU.
The CORE registers available to user-space are PC, RA, SP, GP, TP, A0-A7,
T0-T6, S0-S11 and MODE. Most of these are RISC-V general registers except
PC and MODE. The PC register represents program counter whereas the MODE
register represent VCPU privilege mode (i.e. S/U-mode).
The CSRs available to user-space are SSTATUS, SIE, STVEC, SSCRATCH, SEPC,
SCAUSE, STVAL, SIP, and SATP. All of these are read/write registers.
In future, more VCPU register types will be added (such as FP) for the
KVM_GET_ONE_REG/KVM_SET_ONE_REG ioctls.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-27 17:10:04 +05:30
|
|
|
#define KVM_REG_SIZE(id) \
|
|
|
|
(1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
|
|
|
|
|
|
|
|
/* If you need to interpret the index values, here is the key: */
|
|
|
|
#define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000
|
|
|
|
#define KVM_REG_RISCV_TYPE_SHIFT 24
|
|
|
|
|
|
|
|
/* Config registers are mapped as type 1 */
|
|
|
|
#define KVM_REG_RISCV_CONFIG (0x01 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_CONFIG_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_config, name) / sizeof(unsigned long))
|
|
|
|
|
|
|
|
/* Core registers are mapped as type 2 */
|
|
|
|
#define KVM_REG_RISCV_CORE (0x02 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_CORE_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_core, name) / sizeof(unsigned long))
|
|
|
|
|
|
|
|
/* Control and status registers are mapped as type 3 */
|
|
|
|
#define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_CSR_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))
|
|
|
|
|
2021-09-27 17:10:11 +05:30
|
|
|
/* Timer registers are mapped as type 4 */
|
|
|
|
#define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_TIMER_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_timer, name) / sizeof(__u64))
|
|
|
|
|
2021-09-27 17:10:13 +05:30
|
|
|
/* F extension registers are mapped as type 5 */
|
|
|
|
#define KVM_REG_RISCV_FP_F (0x05 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_FP_F_REG(name) \
|
|
|
|
(offsetof(struct __riscv_f_ext_state, name) / sizeof(__u32))
|
|
|
|
|
|
|
|
/* D extension registers are mapped as type 6 */
|
|
|
|
#define KVM_REG_RISCV_FP_D (0x06 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_FP_D_REG(name) \
|
|
|
|
(offsetof(struct __riscv_d_ext_state, name) / sizeof(__u64))
|
|
|
|
|
2021-09-27 17:10:01 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __LINUX_KVM_RISCV_H */
|