1b91a0fa7SYifei Jiang /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2b91a0fa7SYifei Jiang /* 3b91a0fa7SYifei Jiang * Copyright (C) 2019 Western Digital Corporation or its affiliates. 4b91a0fa7SYifei Jiang * 5b91a0fa7SYifei Jiang * Authors: 6b91a0fa7SYifei Jiang * Anup Patel <anup.patel@wdc.com> 7b91a0fa7SYifei Jiang */ 8b91a0fa7SYifei Jiang 9b91a0fa7SYifei Jiang #ifndef __LINUX_KVM_RISCV_H 10b91a0fa7SYifei Jiang #define __LINUX_KVM_RISCV_H 11b91a0fa7SYifei Jiang 12b91a0fa7SYifei Jiang #ifndef __ASSEMBLY__ 13b91a0fa7SYifei Jiang 14b91a0fa7SYifei Jiang #include <linux/types.h> 15d0bf492fSCédric Le Goater #include <asm/bitsperlong.h> 16b91a0fa7SYifei Jiang #include <asm/ptrace.h> 17b91a0fa7SYifei Jiang 18d0bf492fSCédric Le Goater #define __KVM_HAVE_IRQ_LINE 19b91a0fa7SYifei Jiang 20b91a0fa7SYifei Jiang #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 21b91a0fa7SYifei Jiang 22b91a0fa7SYifei Jiang #define KVM_INTERRUPT_SET -1U 23b91a0fa7SYifei Jiang #define KVM_INTERRUPT_UNSET -2U 24b91a0fa7SYifei Jiang 25b91a0fa7SYifei Jiang /* for KVM_GET_REGS and KVM_SET_REGS */ 26b91a0fa7SYifei Jiang struct kvm_regs { 27b91a0fa7SYifei Jiang }; 28b91a0fa7SYifei Jiang 29b91a0fa7SYifei Jiang /* for KVM_GET_FPU and KVM_SET_FPU */ 30b91a0fa7SYifei Jiang struct kvm_fpu { 31b91a0fa7SYifei Jiang }; 32b91a0fa7SYifei Jiang 33b91a0fa7SYifei Jiang /* KVM Debug exit structure */ 34b91a0fa7SYifei Jiang struct kvm_debug_exit_arch { 35b91a0fa7SYifei Jiang }; 36b91a0fa7SYifei Jiang 37b91a0fa7SYifei Jiang /* for KVM_SET_GUEST_DEBUG */ 38b91a0fa7SYifei Jiang struct kvm_guest_debug_arch { 39b91a0fa7SYifei Jiang }; 40b91a0fa7SYifei Jiang 41b91a0fa7SYifei Jiang /* definition of registers in kvm_run */ 42b91a0fa7SYifei Jiang struct kvm_sync_regs { 43b91a0fa7SYifei Jiang }; 44b91a0fa7SYifei Jiang 45b91a0fa7SYifei Jiang /* for KVM_GET_SREGS and KVM_SET_SREGS */ 46b91a0fa7SYifei Jiang struct kvm_sregs { 47b91a0fa7SYifei Jiang }; 48b91a0fa7SYifei Jiang 49b91a0fa7SYifei Jiang /* CONFIG registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 50b91a0fa7SYifei Jiang struct kvm_riscv_config { 51b91a0fa7SYifei Jiang unsigned long isa; 5293e0932bSPeter Xu unsigned long zicbom_block_size; 5393d7620cSAvihai Horon unsigned long mvendorid; 5493d7620cSAvihai Horon unsigned long marchid; 5593d7620cSAvihai Horon unsigned long mimpid; 56d0bf492fSCédric Le Goater unsigned long zicboz_block_size; 57da3c22c7SThomas Huth unsigned long satp_mode; 58b91a0fa7SYifei Jiang }; 59b91a0fa7SYifei Jiang 60b91a0fa7SYifei Jiang /* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 61b91a0fa7SYifei Jiang struct kvm_riscv_core { 62b91a0fa7SYifei Jiang struct user_regs_struct regs; 63b91a0fa7SYifei Jiang unsigned long mode; 64b91a0fa7SYifei Jiang }; 65b91a0fa7SYifei Jiang 66b91a0fa7SYifei Jiang /* Possible privilege modes for kvm_riscv_core */ 67b91a0fa7SYifei Jiang #define KVM_RISCV_MODE_S 1 68b91a0fa7SYifei Jiang #define KVM_RISCV_MODE_U 0 69b91a0fa7SYifei Jiang 70d0bf492fSCédric Le Goater /* General CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 71b91a0fa7SYifei Jiang struct kvm_riscv_csr { 72b91a0fa7SYifei Jiang unsigned long sstatus; 73b91a0fa7SYifei Jiang unsigned long sie; 74b91a0fa7SYifei Jiang unsigned long stvec; 75b91a0fa7SYifei Jiang unsigned long sscratch; 76b91a0fa7SYifei Jiang unsigned long sepc; 77b91a0fa7SYifei Jiang unsigned long scause; 78b91a0fa7SYifei Jiang unsigned long stval; 79b91a0fa7SYifei Jiang unsigned long sip; 80b91a0fa7SYifei Jiang unsigned long satp; 81b91a0fa7SYifei Jiang unsigned long scounteren; 82efb91426SDaniel Henrique Barboza unsigned long senvcfg; 83b91a0fa7SYifei Jiang }; 84b91a0fa7SYifei Jiang 85d0bf492fSCédric Le Goater /* AIA CSR registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 86d0bf492fSCédric Le Goater struct kvm_riscv_aia_csr { 87d0bf492fSCédric Le Goater unsigned long siselect; 88d0bf492fSCédric Le Goater unsigned long iprio1; 89d0bf492fSCédric Le Goater unsigned long iprio2; 90d0bf492fSCédric Le Goater unsigned long sieh; 91d0bf492fSCédric Le Goater unsigned long siph; 92d0bf492fSCédric Le Goater unsigned long iprio1h; 93d0bf492fSCédric Le Goater unsigned long iprio2h; 94d0bf492fSCédric Le Goater }; 95d0bf492fSCédric Le Goater 96efb91426SDaniel Henrique Barboza /* Smstateen CSR for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 97efb91426SDaniel Henrique Barboza struct kvm_riscv_smstateen_csr { 98efb91426SDaniel Henrique Barboza unsigned long sstateen0; 99efb91426SDaniel Henrique Barboza }; 100efb91426SDaniel Henrique Barboza 101b91a0fa7SYifei Jiang /* TIMER registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 102b91a0fa7SYifei Jiang struct kvm_riscv_timer { 103b91a0fa7SYifei Jiang __u64 frequency; 104b91a0fa7SYifei Jiang __u64 time; 105b91a0fa7SYifei Jiang __u64 compare; 106b91a0fa7SYifei Jiang __u64 state; 107b91a0fa7SYifei Jiang }; 108b91a0fa7SYifei Jiang 109d525f73fSChenyi Qiang /* 110d525f73fSChenyi Qiang * ISA extension IDs specific to KVM. This is not the same as the host ISA 111d525f73fSChenyi Qiang * extension IDs as that is internal to the host and should not be exposed 112d525f73fSChenyi Qiang * to the guest. This should always be contiguous to keep the mapping simple 113d525f73fSChenyi Qiang * in KVM implementation. 114d525f73fSChenyi Qiang */ 115d525f73fSChenyi Qiang enum KVM_RISCV_ISA_EXT_ID { 116d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_A = 0, 117d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_C, 118d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_D, 119d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_F, 120d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_H, 121d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_I, 122d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_M, 123d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_SVPBMT, 124d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_SSTC, 12593e0932bSPeter Xu KVM_RISCV_ISA_EXT_SVINVAL, 12693e0932bSPeter Xu KVM_RISCV_ISA_EXT_ZIHINTPAUSE, 12793e0932bSPeter Xu KVM_RISCV_ISA_EXT_ZICBOM, 128d0bf492fSCédric Le Goater KVM_RISCV_ISA_EXT_ZICBOZ, 129d0bf492fSCédric Le Goater KVM_RISCV_ISA_EXT_ZBB, 130d0bf492fSCédric Le Goater KVM_RISCV_ISA_EXT_SSAIA, 131d0bf492fSCédric Le Goater KVM_RISCV_ISA_EXT_V, 132d0bf492fSCédric Le Goater KVM_RISCV_ISA_EXT_SVNAPOT, 133da3c22c7SThomas Huth KVM_RISCV_ISA_EXT_ZBA, 134da3c22c7SThomas Huth KVM_RISCV_ISA_EXT_ZBS, 135da3c22c7SThomas Huth KVM_RISCV_ISA_EXT_ZICNTR, 136da3c22c7SThomas Huth KVM_RISCV_ISA_EXT_ZICSR, 137da3c22c7SThomas Huth KVM_RISCV_ISA_EXT_ZIFENCEI, 138da3c22c7SThomas Huth KVM_RISCV_ISA_EXT_ZIHPM, 139efb91426SDaniel Henrique Barboza KVM_RISCV_ISA_EXT_SMSTATEEN, 140efb91426SDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZICOND, 1416a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZBC, 1426a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZBKB, 1436a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZBKC, 1446a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZBKX, 1456a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKND, 1466a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKNE, 1476a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKNH, 1486a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKR, 1496a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKSED, 1506a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKSH, 1516a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZKT, 1526a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVBB, 1536a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVBC, 1546a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKB, 1556a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKG, 1566a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKNED, 1576a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKNHA, 1586a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKNHB, 1596a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKSED, 1606a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKSH, 1616a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVKT, 1626a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZFH, 1636a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZFHMIN, 1646a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZIHINTNTL, 1656a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVFH, 1666a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZVFHMIN, 1676a02465fSDaniel Henrique Barboza KVM_RISCV_ISA_EXT_ZFA, 168ab0c7fb2SPaolo Bonzini KVM_RISCV_ISA_EXT_ZTSO, 169ab0c7fb2SPaolo Bonzini KVM_RISCV_ISA_EXT_ZACAS, 1705f69e42dSPankaj Gupta KVM_RISCV_ISA_EXT_SSCOFPMF, 171*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZIMOP, 172*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZCA, 173*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZCB, 174*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZCD, 175*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZCF, 176*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZCMOP, 177*0d2eeef7SBibo Mao KVM_RISCV_ISA_EXT_ZAWRS, 178d525f73fSChenyi Qiang KVM_RISCV_ISA_EXT_MAX, 179d525f73fSChenyi Qiang }; 180d525f73fSChenyi Qiang 181d0bf492fSCédric Le Goater /* 182d0bf492fSCédric Le Goater * SBI extension IDs specific to KVM. This is not the same as the SBI 183d0bf492fSCédric Le Goater * extension IDs defined by the RISC-V SBI specification. 184d0bf492fSCédric Le Goater */ 185d0bf492fSCédric Le Goater enum KVM_RISCV_SBI_EXT_ID { 186d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_V01 = 0, 187d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_TIME, 188d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_IPI, 189d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_RFENCE, 190d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_SRST, 191d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_HSM, 192d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_PMU, 193d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_EXPERIMENTAL, 194d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_VENDOR, 195efb91426SDaniel Henrique Barboza KVM_RISCV_SBI_EXT_DBCN, 1966a02465fSDaniel Henrique Barboza KVM_RISCV_SBI_EXT_STA, 197d0bf492fSCédric Le Goater KVM_RISCV_SBI_EXT_MAX, 198d0bf492fSCédric Le Goater }; 199d0bf492fSCédric Le Goater 2006a02465fSDaniel Henrique Barboza /* SBI STA extension registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ 2016a02465fSDaniel Henrique Barboza struct kvm_riscv_sbi_sta { 2026a02465fSDaniel Henrique Barboza unsigned long shmem_lo; 2036a02465fSDaniel Henrique Barboza unsigned long shmem_hi; 2046a02465fSDaniel Henrique Barboza }; 2056a02465fSDaniel Henrique Barboza 206b91a0fa7SYifei Jiang /* Possible states for kvm_riscv_timer */ 207b91a0fa7SYifei Jiang #define KVM_RISCV_TIMER_STATE_OFF 0 208b91a0fa7SYifei Jiang #define KVM_RISCV_TIMER_STATE_ON 1 209b91a0fa7SYifei Jiang 210b91a0fa7SYifei Jiang #define KVM_REG_SIZE(id) \ 211b91a0fa7SYifei Jiang (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT)) 212b91a0fa7SYifei Jiang 213b91a0fa7SYifei Jiang /* If you need to interpret the index values, here is the key: */ 214b91a0fa7SYifei Jiang #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000 215b91a0fa7SYifei Jiang #define KVM_REG_RISCV_TYPE_SHIFT 24 216d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SUBTYPE_MASK 0x0000000000FF0000 217d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SUBTYPE_SHIFT 16 218b91a0fa7SYifei Jiang 219b91a0fa7SYifei Jiang /* Config registers are mapped as type 1 */ 220b91a0fa7SYifei Jiang #define KVM_REG_RISCV_CONFIG (0x01 << KVM_REG_RISCV_TYPE_SHIFT) 221b91a0fa7SYifei Jiang #define KVM_REG_RISCV_CONFIG_REG(name) \ 222b91a0fa7SYifei Jiang (offsetof(struct kvm_riscv_config, name) / sizeof(unsigned long)) 223b91a0fa7SYifei Jiang 224b91a0fa7SYifei Jiang /* Core registers are mapped as type 2 */ 225b91a0fa7SYifei Jiang #define KVM_REG_RISCV_CORE (0x02 << KVM_REG_RISCV_TYPE_SHIFT) 226b91a0fa7SYifei Jiang #define KVM_REG_RISCV_CORE_REG(name) \ 227b91a0fa7SYifei Jiang (offsetof(struct kvm_riscv_core, name) / sizeof(unsigned long)) 228b91a0fa7SYifei Jiang 229b91a0fa7SYifei Jiang /* Control and status registers are mapped as type 3 */ 230b91a0fa7SYifei Jiang #define KVM_REG_RISCV_CSR (0x03 << KVM_REG_RISCV_TYPE_SHIFT) 231d0bf492fSCédric Le Goater #define KVM_REG_RISCV_CSR_GENERAL (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) 232d0bf492fSCédric Le Goater #define KVM_REG_RISCV_CSR_AIA (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) 233efb91426SDaniel Henrique Barboza #define KVM_REG_RISCV_CSR_SMSTATEEN (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT) 234b91a0fa7SYifei Jiang #define KVM_REG_RISCV_CSR_REG(name) \ 235b91a0fa7SYifei Jiang (offsetof(struct kvm_riscv_csr, name) / sizeof(unsigned long)) 236d0bf492fSCédric Le Goater #define KVM_REG_RISCV_CSR_AIA_REG(name) \ 237d0bf492fSCédric Le Goater (offsetof(struct kvm_riscv_aia_csr, name) / sizeof(unsigned long)) 238efb91426SDaniel Henrique Barboza #define KVM_REG_RISCV_CSR_SMSTATEEN_REG(name) \ 239efb91426SDaniel Henrique Barboza (offsetof(struct kvm_riscv_smstateen_csr, name) / sizeof(unsigned long)) 240b91a0fa7SYifei Jiang 241b91a0fa7SYifei Jiang /* Timer registers are mapped as type 4 */ 242b91a0fa7SYifei Jiang #define KVM_REG_RISCV_TIMER (0x04 << KVM_REG_RISCV_TYPE_SHIFT) 243b91a0fa7SYifei Jiang #define KVM_REG_RISCV_TIMER_REG(name) \ 244b91a0fa7SYifei Jiang (offsetof(struct kvm_riscv_timer, name) / sizeof(__u64)) 245b91a0fa7SYifei Jiang 246b91a0fa7SYifei Jiang /* F extension registers are mapped as type 5 */ 247b91a0fa7SYifei Jiang #define KVM_REG_RISCV_FP_F (0x05 << KVM_REG_RISCV_TYPE_SHIFT) 248b91a0fa7SYifei Jiang #define KVM_REG_RISCV_FP_F_REG(name) \ 249b91a0fa7SYifei Jiang (offsetof(struct __riscv_f_ext_state, name) / sizeof(__u32)) 250b91a0fa7SYifei Jiang 251b91a0fa7SYifei Jiang /* D extension registers are mapped as type 6 */ 252b91a0fa7SYifei Jiang #define KVM_REG_RISCV_FP_D (0x06 << KVM_REG_RISCV_TYPE_SHIFT) 253b91a0fa7SYifei Jiang #define KVM_REG_RISCV_FP_D_REG(name) \ 254b91a0fa7SYifei Jiang (offsetof(struct __riscv_d_ext_state, name) / sizeof(__u64)) 255b91a0fa7SYifei Jiang 256d525f73fSChenyi Qiang /* ISA Extension registers are mapped as type 7 */ 257d525f73fSChenyi Qiang #define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT) 258da3c22c7SThomas Huth #define KVM_REG_RISCV_ISA_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) 259da3c22c7SThomas Huth #define KVM_REG_RISCV_ISA_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) 260da3c22c7SThomas Huth #define KVM_REG_RISCV_ISA_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT) 261da3c22c7SThomas Huth #define KVM_REG_RISCV_ISA_MULTI_REG(__ext_id) \ 262da3c22c7SThomas Huth ((__ext_id) / __BITS_PER_LONG) 263da3c22c7SThomas Huth #define KVM_REG_RISCV_ISA_MULTI_MASK(__ext_id) \ 264da3c22c7SThomas Huth (1UL << ((__ext_id) % __BITS_PER_LONG)) 265da3c22c7SThomas Huth #define KVM_REG_RISCV_ISA_MULTI_REG_LAST \ 266da3c22c7SThomas Huth KVM_REG_RISCV_ISA_MULTI_REG(KVM_RISCV_ISA_EXT_MAX - 1) 267d525f73fSChenyi Qiang 268d0bf492fSCédric Le Goater /* SBI extension registers are mapped as type 8 */ 269d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_EXT (0x08 << KVM_REG_RISCV_TYPE_SHIFT) 270d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_SINGLE (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) 271d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_MULTI_EN (0x1 << KVM_REG_RISCV_SUBTYPE_SHIFT) 272d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_MULTI_DIS (0x2 << KVM_REG_RISCV_SUBTYPE_SHIFT) 273d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_MULTI_REG(__ext_id) \ 274d0bf492fSCédric Le Goater ((__ext_id) / __BITS_PER_LONG) 275d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_MULTI_MASK(__ext_id) \ 276d0bf492fSCédric Le Goater (1UL << ((__ext_id) % __BITS_PER_LONG)) 277d0bf492fSCédric Le Goater #define KVM_REG_RISCV_SBI_MULTI_REG_LAST \ 278d0bf492fSCédric Le Goater KVM_REG_RISCV_SBI_MULTI_REG(KVM_RISCV_SBI_EXT_MAX - 1) 279d0bf492fSCédric Le Goater 280d0bf492fSCédric Le Goater /* V extension registers are mapped as type 9 */ 281d0bf492fSCédric Le Goater #define KVM_REG_RISCV_VECTOR (0x09 << KVM_REG_RISCV_TYPE_SHIFT) 282d0bf492fSCédric Le Goater #define KVM_REG_RISCV_VECTOR_CSR_REG(name) \ 283d0bf492fSCédric Le Goater (offsetof(struct __riscv_v_ext_state, name) / sizeof(unsigned long)) 284d0bf492fSCédric Le Goater #define KVM_REG_RISCV_VECTOR_REG(n) \ 285d0bf492fSCédric Le Goater ((n) + sizeof(struct __riscv_v_ext_state) / sizeof(unsigned long)) 286d0bf492fSCédric Le Goater 2876a02465fSDaniel Henrique Barboza /* Registers for specific SBI extensions are mapped as type 10 */ 2886a02465fSDaniel Henrique Barboza #define KVM_REG_RISCV_SBI_STATE (0x0a << KVM_REG_RISCV_TYPE_SHIFT) 2896a02465fSDaniel Henrique Barboza #define KVM_REG_RISCV_SBI_STA (0x0 << KVM_REG_RISCV_SUBTYPE_SHIFT) 2906a02465fSDaniel Henrique Barboza #define KVM_REG_RISCV_SBI_STA_REG(name) \ 2916a02465fSDaniel Henrique Barboza (offsetof(struct kvm_riscv_sbi_sta, name) / sizeof(unsigned long)) 2926a02465fSDaniel Henrique Barboza 293d0bf492fSCédric Le Goater /* Device Control API: RISC-V AIA */ 294d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_APLIC_ALIGN 0x1000 295d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_APLIC_SIZE 0x4000 296d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_APLIC_MAX_HARTS 0x4000 297d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_IMSIC_ALIGN 0x1000 298d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_IMSIC_SIZE 0x1000 299d0bf492fSCédric Le Goater 300d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GRP_CONFIG 0 301d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_MODE 0 302d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_IDS 1 303d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_SRCS 2 304d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_GROUP_BITS 3 305d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_GROUP_SHIFT 4 306d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_HART_BITS 5 307d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CONFIG_GUEST_BITS 6 308d0bf492fSCédric Le Goater 309d0bf492fSCédric Le Goater /* 310d0bf492fSCédric Le Goater * Modes of RISC-V AIA device: 311d0bf492fSCédric Le Goater * 1) EMUL (aka Emulation): Trap-n-emulate IMSIC 312d0bf492fSCédric Le Goater * 2) HWACCEL (aka HW Acceleration): Virtualize IMSIC using IMSIC guest files 313d0bf492fSCédric Le Goater * 3) AUTO (aka Automatic): Virtualize IMSIC using IMSIC guest files whenever 314d0bf492fSCédric Le Goater * available otherwise fallback to trap-n-emulation 315d0bf492fSCédric Le Goater */ 316d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_MODE_EMUL 0 317d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_MODE_HWACCEL 1 318d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_MODE_AUTO 2 319d0bf492fSCédric Le Goater 320d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IDS_MIN 63 321d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IDS_MAX 2048 322d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_SRCS_MAX 1024 323d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GROUP_BITS_MAX 8 324d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GROUP_SHIFT_MIN 24 325d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GROUP_SHIFT_MAX 56 326d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_HART_BITS_MAX 16 327d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GUEST_BITS_MAX 8 328d0bf492fSCédric Le Goater 329d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GRP_ADDR 1 330d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_ADDR_APLIC 0 331d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_ADDR_IMSIC(__vcpu) (1 + (__vcpu)) 332d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_ADDR_MAX \ 333d0bf492fSCédric Le Goater (1 + KVM_DEV_RISCV_APLIC_MAX_HARTS) 334d0bf492fSCédric Le Goater 335d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GRP_CTRL 2 336d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_CTRL_INIT 0 337d0bf492fSCédric Le Goater 338d0bf492fSCédric Le Goater /* 339d0bf492fSCédric Le Goater * The device attribute type contains the memory mapped offset of the 340d0bf492fSCédric Le Goater * APLIC register (range 0x0000-0x3FFF) and it must be 4-byte aligned. 341d0bf492fSCédric Le Goater */ 342d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GRP_APLIC 3 343d0bf492fSCédric Le Goater 344d0bf492fSCédric Le Goater /* 345d0bf492fSCédric Le Goater * The lower 12-bits of the device attribute type contains the iselect 346d0bf492fSCédric Le Goater * value of the IMSIC register (range 0x70-0xFF) whereas the higher order 347d0bf492fSCédric Le Goater * bits contains the VCPU id. 348d0bf492fSCédric Le Goater */ 349d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_GRP_IMSIC 4 350d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS 12 351d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK \ 352d0bf492fSCédric Le Goater ((1U << KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) - 1) 353d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IMSIC_MKATTR(__vcpu, __isel) \ 354d0bf492fSCédric Le Goater (((__vcpu) << KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) | \ 355d0bf492fSCédric Le Goater ((__isel) & KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK)) 356d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IMSIC_GET_ISEL(__attr) \ 357d0bf492fSCédric Le Goater ((__attr) & KVM_DEV_RISCV_AIA_IMSIC_ISEL_MASK) 358d0bf492fSCédric Le Goater #define KVM_DEV_RISCV_AIA_IMSIC_GET_VCPU(__attr) \ 359d0bf492fSCédric Le Goater ((__attr) >> KVM_DEV_RISCV_AIA_IMSIC_ISEL_BITS) 360d0bf492fSCédric Le Goater 361d0bf492fSCédric Le Goater /* One single KVM irqchip, ie. the AIA */ 362d0bf492fSCédric Le Goater #define KVM_NR_IRQCHIPS 1 363d0bf492fSCédric Le Goater 364b91a0fa7SYifei Jiang #endif 365b91a0fa7SYifei Jiang 366b91a0fa7SYifei Jiang #endif /* __LINUX_KVM_RISCV_H */ 367