diff mbox series

[RFC,v1,01/10] linux-headers: Add KVM headers for loongarch

Message ID 20230420093606.3366969-2-zhaotianrui@loongson.cn
State New
Headers show
Series Add loongarch kvm accel support | expand

Commit Message

Tianrui Zhao April 20, 2023, 9:35 a.m. UTC
Add asm-loongarch/kvm.h for loongarch KVM, and update
the linux/kvm.h about loongarch part. The structures in
the header are used as kvm_ioctl arguments.

Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
 linux-headers/asm-loongarch/kvm.h | 99 +++++++++++++++++++++++++++++++
 linux-headers/linux/kvm.h         |  9 +++
 2 files changed, 108 insertions(+)
 create mode 100644 linux-headers/asm-loongarch/kvm.h

Comments

Cornelia Huck April 20, 2023, 9:49 a.m. UTC | #1
On Thu, Apr 20 2023, Tianrui Zhao <zhaotianrui@loongson.cn> wrote:

> Add asm-loongarch/kvm.h for loongarch KVM, and update
> the linux/kvm.h about loongarch part. The structures in
> the header are used as kvm_ioctl arguments.

Just a procedural note: It's probably best to explicitly mark this as a
placeholder patch until you can replace it with a full headers update.

>
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
>  linux-headers/asm-loongarch/kvm.h | 99 +++++++++++++++++++++++++++++++
>  linux-headers/linux/kvm.h         |  9 +++
>  2 files changed, 108 insertions(+)
>  create mode 100644 linux-headers/asm-loongarch/kvm.h
Tianrui Zhao April 20, 2023, 12:59 p.m. UTC | #2
在 2023年04月20日 17:49, Cornelia Huck 写道:
> On Thu, Apr 20 2023, Tianrui Zhao <zhaotianrui@loongson.cn> wrote:
>
>> Add asm-loongarch/kvm.h for loongarch KVM, and update
>> the linux/kvm.h about loongarch part. The structures in
>> the header are used as kvm_ioctl arguments.
> Just a procedural note: It's probably best to explicitly mark this as a
> placeholder patch until you can replace it with a full headers update.
Thanks, I will mark this as a placeholder patch until it can be merged.

Thanks
Tianrui Zhao
>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> ---
>>   linux-headers/asm-loongarch/kvm.h | 99 +++++++++++++++++++++++++++++++
>>   linux-headers/linux/kvm.h         |  9 +++
>>   2 files changed, 108 insertions(+)
>>   create mode 100644 linux-headers/asm-loongarch/kvm.h
Tianrui Zhao April 23, 2023, 6:59 a.m. UTC | #3
在 2023年04月20日 20:59, Tianrui Zhao 写道:
>
>
> 在 2023年04月20日 17:49, Cornelia Huck 写道:
>> On Thu, Apr 20 2023, Tianrui Zhao <zhaotianrui@loongson.cn> wrote:
>>
>>> Add asm-loongarch/kvm.h for loongarch KVM, and update
>>> the linux/kvm.h about loongarch part. The structures in
>>> the header are used as kvm_ioctl arguments.
>> Just a procedural note: It's probably best to explicitly mark this as a
>> placeholder patch until you can replace it with a full headers update.
> Thanks, I will mark this as a placeholder patch until it can be merged.
>
> Thanks
> Tianrui Zhao
I will use update-linux-headers.sh to generate the kvm related headers 
until the linux kvm patches are accepted. And now this patch is only a 
placeholder to show some kvm structures and macros for reviewers.

Thanks
Tianrui Zhao
>>
>>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>>> ---
>>>   linux-headers/asm-loongarch/kvm.h | 99 
>>> +++++++++++++++++++++++++++++++
>>>   linux-headers/linux/kvm.h         |  9 +++
>>>   2 files changed, 108 insertions(+)
>>>   create mode 100644 linux-headers/asm-loongarch/kvm.h
>
diff mbox series

Patch

diff --git a/linux-headers/asm-loongarch/kvm.h b/linux-headers/asm-loongarch/kvm.h
new file mode 100644
index 0000000000..6420f59f9e
--- /dev/null
+++ b/linux-headers/asm-loongarch/kvm.h
@@ -0,0 +1,99 @@ 
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2023 Loongson Technology Corporation Limited
+ */
+
+#ifndef __UAPI_ASM_LOONGARCH_KVM_H
+#define __UAPI_ASM_LOONGARCH_KVM_H
+
+#include <linux/types.h>
+
+/*
+ * KVM Loongarch specific structures and definitions.
+ */
+
+#define __KVM_HAVE_READONLY_MEM
+
+#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
+
+/*
+ * for KVM_GET_REGS and KVM_SET_REGS
+ */
+struct kvm_regs {
+	/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
+	__u64 gpr[32];
+	__u64 pc;
+};
+
+/*
+ * for KVM_GET_FPU and KVM_SET_FPU
+ */
+struct kvm_fpu {
+	__u32 fcsr;
+	__u32 none;
+	__u64 fcc;    /* 8x8 */
+	struct kvm_fpureg {
+		__u64 val64[4];
+	} fpr[32];
+};
+
+/*
+ * For LoongArch, we use KVM_SET_ONE_REG and KVM_GET_ONE_REG to access various
+ * registers.  The id field is broken down as follows:
+ *
+ *  bits[63..52] - As per linux/kvm.h
+ *  bits[51..32] - Must be zero.
+ *  bits[31..16] - Register set.
+ *
+ * Register set = 0: GP registers from kvm_regs (see definitions below).
+ *
+ * Register set = 1: CSR registers.
+ *
+ * Register set = 2: KVM specific registers (see definitions below).
+ *
+ * Register set = 3: FPU / SIMD registers (see definitions below).
+ *
+ * Other sets registers may be added in the future.  Each set would
+ * have its own identifier in bits[31..16].
+ */
+
+#define KVM_REG_LOONGARCH_GP		(KVM_REG_LOONGARCH | 0x00000ULL)
+#define KVM_REG_LOONGARCH_CSR		(KVM_REG_LOONGARCH | 0x10000ULL)
+#define KVM_REG_LOONGARCH_KVM		(KVM_REG_LOONGARCH | 0x20000ULL)
+#define KVM_REG_LOONGARCH_FPU		(KVM_REG_LOONGARCH | 0x30000ULL)
+#define KVM_REG_LOONGARCH_MASK		(KVM_REG_LOONGARCH | 0x30000ULL)
+#define KVM_CSR_IDX_MASK		(0x10000 - 1)
+
+/*
+ * KVM_REG_LOONGARCH_KVM - KVM specific control registers.
+ */
+
+#define KVM_REG_LOONGARCH_COUNTER	(KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 3)
+#define KVM_REG_LOONGARCH_VCPU_RESET	(KVM_REG_LOONGARCH_KVM | KVM_REG_SIZE_U64 | 4)
+
+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 {
+};
+
+/* dummy definition */
+struct kvm_sregs {
+};
+
+struct kvm_loongarch_interrupt {
+	/* in */
+	__u32 cpu;
+	__u32 irq;
+};
+
+#define KVM_NR_IRQCHIPS		1
+#define KVM_IRQCHIP_NUM_PINS	64
+#define KVM_MAX_CORES		256
+
+#endif /* __UAPI_ASM_LOONGARCH_KVM_H */
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 1e2c16cfe3..8d72bb6810 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -264,6 +264,7 @@  struct kvm_xen_exit {
 #define KVM_EXIT_RISCV_SBI        35
 #define KVM_EXIT_RISCV_CSR        36
 #define KVM_EXIT_NOTIFY           37
+#define KVM_EXIT_LOONGARCH_IOCSR  38
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -336,6 +337,13 @@  struct kvm_run {
 			__u32 len;
 			__u8  is_write;
 		} mmio;
+		/* KVM_EXIT_LOONGARCH_IOCSR */
+		struct {
+			__u64 phys_addr;
+			__u8  data[8];
+			__u32 len;
+			__u8  is_write;
+		} iocsr_io;
 		/* KVM_EXIT_HYPERCALL */
 		struct {
 			__u64 nr;
@@ -1343,6 +1351,7 @@  struct kvm_dirty_tlb {
 #define KVM_REG_ARM64		0x6000000000000000ULL
 #define KVM_REG_MIPS		0x7000000000000000ULL
 #define KVM_REG_RISCV		0x8000000000000000ULL
+#define KVM_REG_LOONGARCH	0x9000000000000000ULL
 
 #define KVM_REG_SIZE_SHIFT	52
 #define KVM_REG_SIZE_MASK	0x00f0000000000000ULL