1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * Copyright (C) 2020-2023 Loongson Technology Corporation Limited 4 */ 5 6 #ifndef __UAPI_ASM_LOONGARCH_KVM_H 7 #define __UAPI_ASM_LOONGARCH_KVM_H 8 9 #include <linux/types.h> 10 11 #define __KVM_HAVE_IRQ_LINE 12 13 /* 14 * KVM LoongArch specific structures and definitions. 15 * 16 * Some parts derived from the x86 version of this file. 17 */ 18 19 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1 20 #define KVM_DIRTY_LOG_PAGE_OFFSET 64 21 22 #define KVM_GUESTDBG_USE_SW_BP 0x00010000 23 24 /* 25 * for KVM_GET_REGS and KVM_SET_REGS 26 */ 27 struct kvm_regs { 28 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ 29 __u64 gpr[32]; 30 __u64 pc; 31 }; 32 33 /* 34 * for KVM_GET_FPU and KVM_SET_FPU 35 */ 36 struct kvm_fpu { 37 __u32 fcsr; 38 __u64 fcc; /* 8x8 */ 39 struct kvm_fpureg { 40 __u64 val64[4]; 41 } fpr[32]; 42 }; 43 44 /* 45 * For LoongArch, we use KVM_SET_ONE_REG and KVM_GET_ONE_REG to access various 46 * registers. The id field is broken down as follows: 47 * 48 * bits[63..52] - As per linux/kvm.h 49 * bits[51..32] - Must be zero. 50 * bits[31..16] - Register set. 51 * 52 * Register set = 0: GP registers from kvm_regs (see definitions below). 53 * 54 * Register set = 1: CSR registers. 55 * 56 * Register set = 2: KVM specific registers (see definitions below). 57 * 58 * Register set = 3: FPU / SIMD registers (see definitions below). 59 * 60 * Other sets registers may be added in the future. Each set would 61 * have its own identifier in bits[31..16]. 62 */ 63 64 #define KVM_REG_LOONGARCH_GPR (KVM_REG_LOONGARCH | 0x00000ULL) 65 #define KVM_REG_LOONGARCH_CSR (KVM_REG_LOONGARCH | 0x10000ULL) 66 #define KVM_REG_LOONGARCH_KVM (KVM_REG_LOONGARCH | 0x20000ULL) 67 #define KVM_REG_LOONGARCH_FPSIMD (KVM_REG_LOONGARCH | 0x30000ULL) 68 #define KVM_REG_LOONGARCH_CPUCFG (KVM_REG_LOONGARCH | 0x40000ULL) 69 #define KVM_REG_LOONGARCH_LBT (KVM_REG_LOONGARCH | 0x50000ULL) 70 #define KVM_REG_LOONGARCH_MASK (KVM_REG_LOONGARCH | 0x70000ULL) 71 #define KVM_CSR_IDX_MASK 0x7fff 72 #define KVM_CPUCFG_IDX_MASK 0x7fff 73 74 /* 75 * KVM_REG_LOONGARCH_KVM - KVM specific control registers. 76 */ 77 78 #define KVM_REG_LOONGARCH_COUNTER (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 1) 79 #define KVM_REG_LOONGARCH_VCPU_RESET (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 2) 80 /* Debugging: Special instruction for software breakpoint */ 81 #define KVM_REG_LOONGARCH_DEBUG_INST (KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 3) 82 83 /* LBT registers */ 84 #define KVM_REG_LOONGARCH_LBT_SCR0 (KVM_REG_LOONGARCH_LBT | KVM_REG_SIZE_U64 | 1) 85 #define KVM_REG_LOONGARCH_LBT_SCR1 (KVM_REG_LOONGARCH_LBT | KVM_REG_SIZE_U64 | 2) 86 #define KVM_REG_LOONGARCH_LBT_SCR2 (KVM_REG_LOONGARCH_LBT | KVM_REG_SIZE_U64 | 3) 87 #define KVM_REG_LOONGARCH_LBT_SCR3 (KVM_REG_LOONGARCH_LBT | KVM_REG_SIZE_U64 | 4) 88 #define KVM_REG_LOONGARCH_LBT_EFLAGS (KVM_REG_LOONGARCH_LBT | KVM_REG_SIZE_U64 | 5) 89 #define KVM_REG_LOONGARCH_LBT_FTOP (KVM_REG_LOONGARCH_LBT | KVM_REG_SIZE_U64 | 6) 90 91 #define LOONGARCH_REG_SHIFT 3 92 #define LOONGARCH_REG_64(TYPE, REG) (TYPE | KVM_REG_SIZE_U64 | (REG << LOONGARCH_REG_SHIFT)) 93 #define KVM_IOC_CSRID(REG) LOONGARCH_REG_64(KVM_REG_LOONGARCH_CSR, REG) 94 #define KVM_IOC_CPUCFG(REG) LOONGARCH_REG_64(KVM_REG_LOONGARCH_CPUCFG, REG) 95 96 /* Device Control API on vm fd */ 97 #define KVM_LOONGARCH_VM_FEAT_CTRL 0 98 #define KVM_LOONGARCH_VM_FEAT_LSX 0 99 #define KVM_LOONGARCH_VM_FEAT_LASX 1 100 #define KVM_LOONGARCH_VM_FEAT_X86BT 2 101 #define KVM_LOONGARCH_VM_FEAT_ARMBT 3 102 #define KVM_LOONGARCH_VM_FEAT_MIPSBT 4 103 #define KVM_LOONGARCH_VM_FEAT_PMU 5 104 #define KVM_LOONGARCH_VM_FEAT_PV_IPI 6 105 #define KVM_LOONGARCH_VM_FEAT_PV_STEALTIME 7 106 107 /* Device Control API on vcpu fd */ 108 #define KVM_LOONGARCH_VCPU_CPUCFG 0 109 #define KVM_LOONGARCH_VCPU_PVTIME_CTRL 1 110 #define KVM_LOONGARCH_VCPU_PVTIME_GPA 0 111 112 struct kvm_debug_exit_arch { 113 }; 114 115 /* for KVM_SET_GUEST_DEBUG */ 116 struct kvm_guest_debug_arch { 117 }; 118 119 /* definition of registers in kvm_run */ 120 struct kvm_sync_regs { 121 }; 122 123 /* dummy definition */ 124 struct kvm_sregs { 125 }; 126 127 struct kvm_iocsr_entry { 128 __u32 addr; 129 __u32 pad; 130 __u64 data; 131 }; 132 133 #define KVM_NR_IRQCHIPS 1 134 #define KVM_IRQCHIP_NUM_PINS 64 135 #define KVM_MAX_CORES 256 136 137 #define KVM_DEV_LOONGARCH_IPI_GRP_REGS 0x40000001 138 139 #define KVM_DEV_LOONGARCH_EXTIOI_GRP_REGS 0x40000002 140 141 #define KVM_DEV_LOONGARCH_EXTIOI_GRP_SW_STATUS 0x40000003 142 #define KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_NUM_CPU 0x0 143 #define KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_FEATURE 0x1 144 #define KVM_DEV_LOONGARCH_EXTIOI_SW_STATUS_STATE 0x2 145 146 #define KVM_DEV_LOONGARCH_EXTIOI_GRP_CTRL 0x40000004 147 #define KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_NUM_CPU 0x0 148 #define KVM_DEV_LOONGARCH_EXTIOI_CTRL_INIT_FEATURE 0x1 149 #define KVM_DEV_LOONGARCH_EXTIOI_CTRL_LOAD_FINISHED 0x3 150 151 #define KVM_DEV_LOONGARCH_PCH_PIC_GRP_REGS 0x40000005 152 #define KVM_DEV_LOONGARCH_PCH_PIC_GRP_CTRL 0x40000006 153 #define KVM_DEV_LOONGARCH_PCH_PIC_CTRL_INIT 0 154 155 #endif /* __UAPI_ASM_LOONGARCH_KVM_H */ 156