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 /*
21  * for KVM_GET_REGS and KVM_SET_REGS
22  */
23 struct kvm_regs {
24 	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
25 	__u64 gpr[32];
26 	__u64 pc;
27 };
28 
29 /*
30  * for KVM_GET_FPU and KVM_SET_FPU
31  */
32 struct kvm_fpu {
33 	__u32 fcsr;
34 	__u64 fcc;    /* 8x8 */
35 	struct kvm_fpureg {
36 		__u64 val64[4];
37 	} fpr[32];
38 };
39 
40 /*
41  * For LoongArch, we use KVM_SET_ONE_REG and KVM_GET_ONE_REG to access various
42  * registers.  The id field is broken down as follows:
43  *
44  *  bits[63..52] - As per linux/kvm.h
45  *  bits[51..32] - Must be zero.
46  *  bits[31..16] - Register set.
47  *
48  * Register set = 0: GP registers from kvm_regs (see definitions below).
49  *
50  * Register set = 1: CSR registers.
51  *
52  * Register set = 2: KVM specific registers (see definitions below).
53  *
54  * Register set = 3: FPU / SIMD registers (see definitions below).
55  *
56  * Other sets registers may be added in the future.  Each set would
57  * have its own identifier in bits[31..16].
58  */
59 
60 #define KVM_REG_LOONGARCH_GPR		(KVM_REG_LOONGARCH | 0x00000ULL)
61 #define KVM_REG_LOONGARCH_CSR		(KVM_REG_LOONGARCH | 0x10000ULL)
62 #define KVM_REG_LOONGARCH_KVM		(KVM_REG_LOONGARCH | 0x20000ULL)
63 #define KVM_REG_LOONGARCH_FPSIMD	(KVM_REG_LOONGARCH | 0x30000ULL)
64 #define KVM_REG_LOONGARCH_CPUCFG	(KVM_REG_LOONGARCH | 0x40000ULL)
65 #define KVM_REG_LOONGARCH_MASK		(KVM_REG_LOONGARCH | 0x70000ULL)
66 #define KVM_CSR_IDX_MASK		0x7fff
67 #define KVM_CPUCFG_IDX_MASK		0x7fff
68 
69 /*
70  * KVM_REG_LOONGARCH_KVM - KVM specific control registers.
71  */
72 
73 #define KVM_REG_LOONGARCH_COUNTER	(KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 1)
74 #define KVM_REG_LOONGARCH_VCPU_RESET	(KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 2)
75 
76 #define LOONGARCH_REG_SHIFT		3
77 #define LOONGARCH_REG_64(TYPE, REG)	(TYPE | KVM_REG_SIZE_U64 | (REG << LOONGARCH_REG_SHIFT))
78 #define KVM_IOC_CSRID(REG)		LOONGARCH_REG_64(KVM_REG_LOONGARCH_CSR, REG)
79 #define KVM_IOC_CPUCFG(REG)		LOONGARCH_REG_64(KVM_REG_LOONGARCH_CPUCFG, REG)
80 #define KVM_LOONGARCH_VCPU_CPUCFG	0
81 
82 struct kvm_debug_exit_arch {
83 };
84 
85 /* for KVM_SET_GUEST_DEBUG */
86 struct kvm_guest_debug_arch {
87 };
88 
89 /* definition of registers in kvm_run */
90 struct kvm_sync_regs {
91 };
92 
93 /* dummy definition */
94 struct kvm_sregs {
95 };
96 
97 struct kvm_iocsr_entry {
98 	__u32 addr;
99 	__u32 pad;
100 	__u64 data;
101 };
102 
103 #define KVM_NR_IRQCHIPS		1
104 #define KVM_IRQCHIP_NUM_PINS	64
105 #define KVM_MAX_CORES		256
106 
107 #endif /* __UAPI_ASM_LOONGARCH_KVM_H */
108