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>
|
2022-11-28 11:43:16 +05:30
|
|
|
#include <asm/bitsperlong.h>
|
2021-09-27 17:10:01 +05:30
|
|
|
#include <asm/ptrace.h>
|
|
|
|
|
2023-06-15 13:03:48 +05:30
|
|
|
#define __KVM_HAVE_IRQ_LINE
|
2021-09-27 17:10:01 +05:30
|
|
|
|
|
|
|
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
|
2025-06-13 19:29:57 +08:00
|
|
|
#define KVM_DIRTY_LOG_PAGE_OFFSET 64
|
2021-09-27 17:10:01 +05:30
|
|
|
|
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;
|
2022-10-02 10:18:59 +05:30
|
|
|
unsigned long zicbom_block_size;
|
2022-12-07 09:17:49 +05:30
|
|
|
unsigned long mvendorid;
|
|
|
|
unsigned long marchid;
|
|
|
|
unsigned long mimpid;
|
2023-02-24 17:26:30 +01:00
|
|
|
unsigned long zicboz_block_size;
|
2023-07-28 18:01:22 -03:00
|
|
|
unsigned long satp_mode;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
2023-03-31 19:56:56 +05:30
|
|
|
/* General CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
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
|
|
|
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;
|
2023-09-13 22:09:03 +05:30
|
|
|
unsigned long senvcfg;
|
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
|
|
|
};
|
|
|
|
|
2023-03-31 20:06:18 +05:30
|
|
|
/* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_aia_csr {
|
2023-01-11 11:26:10 +05:30
|
|
|
unsigned long siselect;
|
|
|
|
unsigned long iprio1;
|
|
|
|
unsigned long iprio2;
|
|
|
|
unsigned long sieh;
|
|
|
|
unsigned long siph;
|
|
|
|
unsigned long iprio1h;
|
|
|
|
unsigned long iprio2h;
|
2023-03-31 20:06:18 +05:30
|
|
|
};
|
|
|
|
|
2023-09-13 22:09:05 +05:30
|
|
|
/* Smstateen CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_smstateen_csr {
|
|
|
|
unsigned long sstateen0;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-05-09 11:29:37 -07:00
|
|
|
/*
|
|
|
|
* ISA extension IDs specific to KVM. This is not the same as the host ISA
|
|
|
|
* extension IDs as that is internal to the host and should not be exposed
|
|
|
|
* to the guest. This should always be contiguous to keep the mapping simple
|
|
|
|
* in KVM implementation.
|
|
|
|
*/
|
|
|
|
enum KVM_RISCV_ISA_EXT_ID {
|
|
|
|
KVM_RISCV_ISA_EXT_A = 0,
|
|
|
|
KVM_RISCV_ISA_EXT_C,
|
|
|
|
KVM_RISCV_ISA_EXT_D,
|
|
|
|
KVM_RISCV_ISA_EXT_F,
|
|
|
|
KVM_RISCV_ISA_EXT_H,
|
|
|
|
KVM_RISCV_ISA_EXT_I,
|
|
|
|
KVM_RISCV_ISA_EXT_M,
|
2022-07-29 17:15:18 +05:30
|
|
|
KVM_RISCV_ISA_EXT_SVPBMT,
|
2022-07-22 09:50:47 -07:00
|
|
|
KVM_RISCV_ISA_EXT_SSTC,
|
2022-10-02 10:18:42 +05:30
|
|
|
KVM_RISCV_ISA_EXT_SVINVAL,
|
2022-10-02 10:18:48 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZIHINTPAUSE,
|
2022-10-02 10:19:05 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZICBOM,
|
2023-02-24 17:26:31 +01:00
|
|
|
KVM_RISCV_ISA_EXT_ZICBOZ,
|
2023-04-01 15:21:34 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZBB,
|
2023-03-31 20:06:18 +05:30
|
|
|
KVM_RISCV_ISA_EXT_SSAIA,
|
2023-06-05 11:07:15 +00:00
|
|
|
KVM_RISCV_ISA_EXT_V,
|
2023-06-12 16:40:44 +05:30
|
|
|
KVM_RISCV_ISA_EXT_SVNAPOT,
|
2023-07-12 12:38:11 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZBA,
|
|
|
|
KVM_RISCV_ISA_EXT_ZBS,
|
2023-07-12 12:53:50 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZICNTR,
|
|
|
|
KVM_RISCV_ISA_EXT_ZICSR,
|
|
|
|
KVM_RISCV_ISA_EXT_ZIFENCEI,
|
|
|
|
KVM_RISCV_ISA_EXT_ZIHPM,
|
2023-09-13 22:09:02 +05:30
|
|
|
KVM_RISCV_ISA_EXT_SMSTATEEN,
|
2023-09-15 17:51:10 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZICOND,
|
2023-11-27 16:11:09 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZBC,
|
2023-11-27 20:36:36 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZBKB,
|
|
|
|
KVM_RISCV_ISA_EXT_ZBKC,
|
|
|
|
KVM_RISCV_ISA_EXT_ZBKX,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKND,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKNE,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKNH,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKR,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKSED,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKSH,
|
|
|
|
KVM_RISCV_ISA_EXT_ZKT,
|
2023-11-27 21:38:43 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZVBB,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVBC,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKB,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKG,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKNED,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKNHA,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKNHB,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKSED,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKSH,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVKT,
|
2023-11-27 22:01:55 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZFH,
|
|
|
|
KVM_RISCV_ISA_EXT_ZFHMIN,
|
2023-11-27 22:15:10 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZIHINTNTL,
|
2023-11-27 22:26:05 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZVFH,
|
|
|
|
KVM_RISCV_ISA_EXT_ZVFHMIN,
|
2023-11-27 22:43:12 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZFA,
|
2024-02-13 10:32:26 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZTSO,
|
2024-02-13 13:35:45 +05:30
|
|
|
KVM_RISCV_ISA_EXT_ZACAS,
|
2024-04-20 08:17:30 -07:00
|
|
|
KVM_RISCV_ISA_EXT_SSCOFPMF,
|
2024-06-19 13:35:14 +02:00
|
|
|
KVM_RISCV_ISA_EXT_ZIMOP,
|
2024-06-19 13:35:20 +02:00
|
|
|
KVM_RISCV_ISA_EXT_ZCA,
|
|
|
|
KVM_RISCV_ISA_EXT_ZCB,
|
|
|
|
KVM_RISCV_ISA_EXT_ZCD,
|
|
|
|
KVM_RISCV_ISA_EXT_ZCF,
|
2024-06-19 13:35:25 +02:00
|
|
|
KVM_RISCV_ISA_EXT_ZCMOP,
|
2024-04-26 12:08:25 +02:00
|
|
|
KVM_RISCV_ISA_EXT_ZAWRS,
|
2024-10-16 13:27:50 -07:00
|
|
|
KVM_RISCV_ISA_EXT_SMNPM,
|
|
|
|
KVM_RISCV_ISA_EXT_SSNPM,
|
2024-07-26 16:49:28 +08:00
|
|
|
KVM_RISCV_ISA_EXT_SVADE,
|
|
|
|
KVM_RISCV_ISA_EXT_SVADU,
|
2024-12-02 11:21:38 +08:00
|
|
|
KVM_RISCV_ISA_EXT_SVVPTC,
|
2024-12-02 11:21:49 +08:00
|
|
|
KVM_RISCV_ISA_EXT_ZABHA,
|
2024-12-02 11:22:01 +08:00
|
|
|
KVM_RISCV_ISA_EXT_ZICCRSE,
|
2024-06-19 17:39:11 +02:00
|
|
|
KVM_RISCV_ISA_EXT_ZAAMO,
|
|
|
|
KVM_RISCV_ISA_EXT_ZALRSC,
|
2022-05-09 11:29:37 -07:00
|
|
|
KVM_RISCV_ISA_EXT_MAX,
|
|
|
|
};
|
|
|
|
|
2022-11-28 11:43:16 +05:30
|
|
|
/*
|
|
|
|
* SBI extension IDs specific to KVM. This is not the same as the SBI
|
|
|
|
* extension IDs defined by the RISC-V SBI specification.
|
|
|
|
*/
|
|
|
|
enum KVM_RISCV_SBI_EXT_ID {
|
|
|
|
KVM_RISCV_SBI_EXT_V01 = 0,
|
|
|
|
KVM_RISCV_SBI_EXT_TIME,
|
|
|
|
KVM_RISCV_SBI_EXT_IPI,
|
|
|
|
KVM_RISCV_SBI_EXT_RFENCE,
|
|
|
|
KVM_RISCV_SBI_EXT_SRST,
|
|
|
|
KVM_RISCV_SBI_EXT_HSM,
|
|
|
|
KVM_RISCV_SBI_EXT_PMU,
|
|
|
|
KVM_RISCV_SBI_EXT_EXPERIMENTAL,
|
|
|
|
KVM_RISCV_SBI_EXT_VENDOR,
|
2022-07-22 19:46:24 +05:30
|
|
|
KVM_RISCV_SBI_EXT_DBCN,
|
2023-12-20 17:00:17 +01:00
|
|
|
KVM_RISCV_SBI_EXT_STA,
|
2024-10-17 09:45:40 +02:00
|
|
|
KVM_RISCV_SBI_EXT_SUSP,
|
2022-11-28 11:43:16 +05:30
|
|
|
KVM_RISCV_SBI_EXT_MAX,
|
|
|
|
};
|
|
|
|
|
2023-12-20 17:00:21 +01:00
|
|
|
/* SBI STA extension registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
|
|
|
|
struct kvm_riscv_sbi_sta {
|
|
|
|
unsigned long shmem_lo;
|
|
|
|
unsigned long shmem_hi;
|
|
|
|
};
|
|
|
|
|
2021-09-27 17:10:11 +05:30
|
|
|
/* 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
|
|
|
/* 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
|
2022-11-28 11:43:16 +05:30
|
|
|
#define KVM_REG_RISCV_SUBTYPE_MASK 0x0000000000FF0000
|
|
|
|
#define KVM_REG_RISCV_SUBTYPE_SHIFT 16
|
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 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)
|
2023-03-31 19:56:56 +05:30
|
|
|
#define KVM_REG_RISCV_CSR_GENERAL (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
2023-03-31 20:06:18 +05:30
|
|
|
#define KVM_REG_RISCV_CSR_AIA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
2023-09-13 22:09:05 +05:30
|
|
|
#define KVM_REG_RISCV_CSR_SMSTATEEN (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
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_RISCV_CSR_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long))
|
2023-03-31 20:06:18 +05:30
|
|
|
#define KVM_REG_RISCV_CSR_AIA_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long))
|
2023-09-13 22:09:05 +05:30
|
|
|
#define KVM_REG_RISCV_CSR_SMSTATEEN_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long))
|
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
|
|
|
|
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))
|
|
|
|
|
2022-05-09 11:29:37 -07:00
|
|
|
/* ISA Extension registers are mapped as type 7 */
|
|
|
|
#define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT)
|
2023-07-11 22:11:16 +05:30
|
|
|
#define KVM_REG_RISCV_ISA_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_ISA_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_ISA_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_ISA_MULTI_REG(__ext_id) \
|
|
|
|
((__ext_id) / __BITS_PER_LONG)
|
|
|
|
#define KVM_REG_RISCV_ISA_MULTI_MASK(__ext_id) \
|
|
|
|
(1UL << ((__ext_id) % __BITS_PER_LONG))
|
|
|
|
#define KVM_REG_RISCV_ISA_MULTI_REG_LAST \
|
|
|
|
KVM_REG_RISCV_ISA_MULTI_REG(KVM_RISCV_ISA_EXT_MAX - 1)
|
2022-05-09 11:29:37 -07:00
|
|
|
|
2022-11-28 11:43:16 +05:30
|
|
|
/* SBI extension registers are mapped as type 8 */
|
|
|
|
#define KVM_REG_RISCV_SBI_EXT (0x08 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_SBI_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_SBI_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_SBI_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_SBI_MULTI_REG(__ext_id) \
|
|
|
|
((__ext_id) / __BITS_PER_LONG)
|
|
|
|
#define KVM_REG_RISCV_SBI_MULTI_MASK(__ext_id) \
|
|
|
|
(1UL << ((__ext_id) % __BITS_PER_LONG))
|
|
|
|
#define KVM_REG_RISCV_SBI_MULTI_REG_LAST \
|
|
|
|
KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1)
|
|
|
|
|
2023-06-05 11:07:16 +00:00
|
|
|
/* V extension registers are mapped as type 9 */
|
|
|
|
#define KVM_REG_RISCV_VECTOR (0x09 << KVM_REG_RISCV_TYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_VECTOR_CSR_REG(name) \
|
|
|
|
(offsetof(struct __riscv_v_ext_state, name) / sizeof(unsigned long))
|
|
|
|
#define KVM_REG_RISCV_VECTOR_REG(n) \
|
|
|
|
((n) + sizeof(struct __riscv_v_ext_state) / sizeof(unsigned long))
|
|
|
|
|
2023-12-20 17:00:20 +01:00
|
|
|
/* Registers for specific SBI extensions are mapped as type 10 */
|
|
|
|
#define KVM_REG_RISCV_SBI_STATE (0x0a << KVM_REG_RISCV_TYPE_SHIFT)
|
2023-12-20 17:00:21 +01:00
|
|
|
#define KVM_REG_RISCV_SBI_STA (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT)
|
|
|
|
#define KVM_REG_RISCV_SBI_STA_REG(name) \
|
|
|
|
(offsetof(struct kvm_riscv_sbi_sta, name) / sizeof(unsigned long))
|
2023-12-20 17:00:20 +01:00
|
|
|
|
2023-06-15 13:03:49 +05:30
|
|
|
/* Device Control API: RISC-V AIA */
|
|
|
|
#define KVM_DEV_RISCV_APLIC_ALIGN 0x1000
|
|
|
|
#define KVM_DEV_RISCV_APLIC_SIZE 0x4000
|
|
|
|
#define KVM_DEV_RISCV_APLIC_MAX_HARTS 0x4000
|
|
|
|
#define KVM_DEV_RISCV_IMSIC_ALIGN 0x1000
|
|
|
|
#define KVM_DEV_RISCV_IMSIC_SIZE 0x1000
|
|
|
|
|
|
|
|
#define KVM_DEV_RISCV_AIA_GRP_CONFIG 0
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_MODE 0
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_IDS 1
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_SRCS 2
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS 3
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT 4
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_HART_BITS 5
|
|
|
|
#define KVM_DEV_RISCV_AIA_CONFIG_GUEST_BITS 6
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modes of RISC-V AIA device:
|
|
|
|
* 1) EMUL (aka Emulation): Trap-n-emulate IMSIC
|
|
|
|
* 2) HWACCEL (aka HW Acceleration): Virtualize IMSIC using IMSIC guest files
|
|
|
|
* 3) AUTO (aka Automatic): Virtualize IMSIC using IMSIC guest files whenever
|
|
|
|
* available otherwise fallback to trap-n-emulation
|
|
|
|
*/
|
|
|
|
#define KVM_DEV_RISCV_AIA_MODE_EMUL 0
|
|
|
|
#define KVM_DEV_RISCV_AIA_MODE_HWACCEL 1
|
|
|
|
#define KVM_DEV_RISCV_AIA_MODE_AUTO 2
|
|
|
|
|
|
|
|
#define KVM_DEV_RISCV_AIA_IDS_MIN 63
|
|
|
|
#define KVM_DEV_RISCV_AIA_IDS_MAX 2048
|
|
|
|
#define KVM_DEV_RISCV_AIA_SRCS_MAX 1024
|
|
|
|
#define KVM_DEV_RISCV_AIA_GROUP_BITS_MAX 8
|
|
|
|
#define KVM_DEV_RISCV_AIA_GROUP_SHIFT_MIN 24
|
|
|
|
#define KVM_DEV_RISCV_AIA_GROUP_SHIFT_MAX 56
|
|
|
|
#define KVM_DEV_RISCV_AIA_HART_BITS_MAX 16
|
|
|
|
#define KVM_DEV_RISCV_AIA_GUEST_BITS_MAX 8
|
|
|
|
|
|
|
|
#define KVM_DEV_RISCV_AIA_GRP_ADDR 1
|
|
|
|
#define KVM_DEV_RISCV_AIA_ADDR_APLIC 0
|
|
|
|
#define KVM_DEV_RISCV_AIA_ADDR_IMSIC(__vcpu) (1 + (__vcpu))
|
|
|
|
#define KVM_DEV_RISCV_AIA_ADDR_MAX \
|
|
|
|
(1 + KVM_DEV_RISCV_APLIC_MAX_HARTS)
|
|
|
|
|
|
|
|
#define KVM_DEV_RISCV_AIA_GRP_CTRL 2
|
|
|
|
#define KVM_DEV_RISCV_AIA_CTRL_INIT 0
|
|
|
|
|
2023-06-15 13:03:51 +05:30
|
|
|
/*
|
|
|
|
* The device attribute type contains the memory mapped offset of the
|
|
|
|
* APLIC register (range 0x0000-0x3FFF) and it must be 4-byte aligned.
|
|
|
|
*/
|
|
|
|
#define KVM_DEV_RISCV_AIA_GRP_APLIC 3
|
|
|
|
|
2023-06-15 13:03:53 +05:30
|
|
|
/*
|
|
|
|
* The lower 12-bits of the device attribute type contains the iselect
|
|
|
|
* value of the IMSIC register (range 0x70-0xFF) whereas the higher order
|
|
|
|
* bits contains the VCPU id.
|
|
|
|
*/
|
|
|
|
#define KVM_DEV_RISCV_AIA_GRP_IMSIC 4
|
|
|
|
#define KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS 12
|
|
|
|
#define KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK \
|
|
|
|
((1U << KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) - 1)
|
|
|
|
#define KVM_DEV_RISCV_AIA_IMSIC_MKATTR(__vcpu, __isel) \
|
|
|
|
(((__vcpu) << KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) | \
|
|
|
|
((__isel) & KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK))
|
|
|
|
#define KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(__attr) \
|
|
|
|
((__attr) & KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK)
|
|
|
|
#define KVM_DEV_RISCV_AIA_IMSIC_GET_VCPU(__attr) \
|
|
|
|
((__attr) >> KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS)
|
|
|
|
|
2023-06-15 13:03:48 +05:30
|
|
|
/* One single KVM irqchip, ie. the AIA */
|
|
|
|
#define KVM_NR_IRQCHIPS 1
|
|
|
|
|
2021-09-27 17:10:01 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __LINUX_KVM_RISCV_H */
|