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