1
The following changes since commit a5ba0a7e4e150d1350a041f0d0ef9ca6c8d7c307:
1
The following changes since commit 92ec7805190313c9e628f8fc4eb4f932c15247bd:
2
2
3
Merge tag 'pull-aspeed-20241211' of https://github.com/legoater/qemu into staging (2024-12-11 15:16:47 +0000)
3
Merge tag 'pull-riscv-to-apply-20241031-1' of https://github.com/alistair23/qemu into staging (2024-10-31 16:34:25 +0000)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://gitlab.com/bibo-mao/qemu.git pull-loongarch-20241213
7
https://gitlab.com/gaosong/qemu.git tags/pull-loongarch-20241102
8
8
9
for you to fetch changes up to 78aa256571aa06f32001bd80635a1858187c609b:
9
for you to fetch changes up to 47b54e15bbe78722c62dfafc3e04deded820c05e:
10
10
11
hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic (2024-12-13 14:39:39 +0800)
11
target/loongarch: Add steal time support on migration (2024-11-02 15:45:45 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
pull-loongarch-20241213
14
pull-loongarch-20241102
15
15
16
V2: Fix no 'asm/unistd_64.h' build error.
17
Add a new patch (hw/loongarch/boot: Use warn_report when no kernel filename).
16
----------------------------------------------------------------
18
----------------------------------------------------------------
17
Bibo Mao (8):
19
Bibo Mao (7):
18
include: Add loongarch_pic_common header file
20
target/loongarch: Add loongson binary translation feature
19
include: Move struct LoongArchPCHPIC to loongarch_pic_common header file
21
target/loongarch: Implement lbt registers save/restore function
20
hw/intc/loongarch_pch: Merge instance_init() into realize()
22
target/loongarch/kvm: Implement LoongArch PMU extension
21
hw/intc/loongarch_pch: Rename LoongArchPCHPIC with LoongArchPICCommonState
23
linux-headers: Add unistd_64.h
22
hw/intc/loongarch_pch: Move some functions to file loongarch_pic_common
24
linux-headers: loongarch: Add kvm_para.h
23
hw/intc/loongarch_pch: Inherit from loongarch_pic_common
25
linux-headers: Update to Linux v6.12-rc5
24
hw/intc/loongarch_pch: Add pre_save and post_load interfaces
26
target/loongarch: Add steal time support on migration
25
hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic
26
27
27
hw/intc/loongarch_pch_pic.c | 106 +++++++++++----------------------
28
Song Gao (1):
28
hw/intc/loongarch_pic_common.c | 97 ++++++++++++++++++++++++++++++
29
hw/loongarch/boot: Use warn_report when no kernel filename
29
hw/intc/meson.build | 2 +-
30
30
hw/loongarch/virt.c | 2 +-
31
hw/loongarch/boot.c | 5 +-
31
include/hw/intc/loongarch_pch_pic.h | 70 +++++-----------------
32
include/standard-headers/drm/drm_fourcc.h | 43 +++
32
include/hw/intc/loongarch_pic_common.h | 82 +++++++++++++++++++++++++
33
include/standard-headers/linux/const.h | 17 ++
33
6 files changed, 230 insertions(+), 129 deletions(-)
34
include/standard-headers/linux/ethtool.h | 226 ++++++++++++++
34
create mode 100644 hw/intc/loongarch_pic_common.c
35
include/standard-headers/linux/fuse.h | 22 +-
35
create mode 100644 include/hw/intc/loongarch_pic_common.h
36
include/standard-headers/linux/input-event-codes.h | 2 +
37
include/standard-headers/linux/pci_regs.h | 41 ++-
38
include/standard-headers/linux/virtio_balloon.h | 16 +-
39
include/standard-headers/linux/virtio_gpu.h | 1 +
40
linux-headers/asm-arm64/mman.h | 9 +
41
linux-headers/asm-arm64/unistd.h | 25 +-
42
linux-headers/asm-arm64/unistd_64.h | 324 ++++++++++++++++++++
43
linux-headers/asm-generic/unistd.h | 6 +-
44
linux-headers/asm-loongarch/kvm.h | 24 ++
45
linux-headers/asm-loongarch/kvm_para.h | 21 ++
46
linux-headers/asm-loongarch/unistd.h | 4 +-
47
linux-headers/asm-loongarch/unistd_64.h | 320 ++++++++++++++++++++
48
linux-headers/asm-riscv/kvm.h | 7 +
49
linux-headers/asm-riscv/unistd.h | 41 +--
50
linux-headers/asm-riscv/unistd_32.h | 315 ++++++++++++++++++++
51
linux-headers/asm-riscv/unistd_64.h | 325 +++++++++++++++++++++
52
linux-headers/asm-x86/kvm.h | 2 +
53
linux-headers/asm-x86/unistd_64.h | 1 +
54
linux-headers/asm-x86/unistd_x32.h | 1 +
55
linux-headers/linux/bits.h | 3 +
56
linux-headers/linux/const.h | 17 ++
57
linux-headers/linux/iommufd.h | 143 +++++++--
58
linux-headers/linux/kvm.h | 23 +-
59
linux-headers/linux/mman.h | 1 +
60
linux-headers/linux/psp-sev.h | 28 ++
61
scripts/update-linux-headers.sh | 7 +
62
target/loongarch/cpu.c | 43 +++
63
target/loongarch/cpu.h | 23 ++
64
target/loongarch/kvm/kvm.c | 225 +++++++++++++-
65
target/loongarch/loongarch-qmp-cmds.c | 2 +-
66
target/loongarch/machine.c | 30 +-
67
36 files changed, 2243 insertions(+), 100 deletions(-)
68
create mode 100644 linux-headers/asm-arm64/unistd_64.h
69
create mode 100644 linux-headers/asm-loongarch/kvm_para.h
70
create mode 100644 linux-headers/asm-loongarch/unistd_64.h
71
create mode 100644 linux-headers/asm-riscv/unistd_32.h
72
create mode 100644 linux-headers/asm-riscv/unistd_64.h
diff view generated by jsdifflib
Deleted patch
1
Add common header file hw/intc/loongarch_pic_common.h, and move
2
some macro definition from hw/intc/loongarch_pch_pic.h to the common
3
header file.
4
1
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
---
8
include/hw/intc/loongarch_pch_pic.h | 36 +++-------------------
9
include/hw/intc/loongarch_pic_common.h | 42 ++++++++++++++++++++++++++
10
2 files changed, 47 insertions(+), 31 deletions(-)
11
create mode 100644 include/hw/intc/loongarch_pic_common.h
12
13
diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/intc/loongarch_pch_pic.h
16
+++ b/include/hw/intc/loongarch_pch_pic.h
17
@@ -XXX,XX +XXX,XX @@
18
* Copyright (c) 2021 Loongson Technology Corporation Limited
19
*/
20
21
-#include "hw/sysbus.h"
22
+#ifndef HW_LOONGARCH_PCH_PIC_H
23
+#define HW_LOONGARCH_PCH_PIC_H
24
+
25
+#include "hw/intc/loongarch_pic_common.h"
26
27
#define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic"
28
#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name
29
OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC)
30
31
-#define PCH_PIC_INT_ID_VAL 0x7000000UL
32
-#define PCH_PIC_INT_ID_VER 0x1UL
33
-
34
-#define PCH_PIC_INT_ID_LO 0x00
35
-#define PCH_PIC_INT_ID_HI 0x04
36
-#define PCH_PIC_INT_MASK_LO 0x20
37
-#define PCH_PIC_INT_MASK_HI 0x24
38
-#define PCH_PIC_HTMSI_EN_LO 0x40
39
-#define PCH_PIC_HTMSI_EN_HI 0x44
40
-#define PCH_PIC_INT_EDGE_LO 0x60
41
-#define PCH_PIC_INT_EDGE_HI 0x64
42
-#define PCH_PIC_INT_CLEAR_LO 0x80
43
-#define PCH_PIC_INT_CLEAR_HI 0x84
44
-#define PCH_PIC_AUTO_CTRL0_LO 0xc0
45
-#define PCH_PIC_AUTO_CTRL0_HI 0xc4
46
-#define PCH_PIC_AUTO_CTRL1_LO 0xe0
47
-#define PCH_PIC_AUTO_CTRL1_HI 0xe4
48
-#define PCH_PIC_ROUTE_ENTRY_OFFSET 0x100
49
-#define PCH_PIC_ROUTE_ENTRY_END 0x13f
50
-#define PCH_PIC_HTMSI_VEC_OFFSET 0x200
51
-#define PCH_PIC_HTMSI_VEC_END 0x23f
52
-#define PCH_PIC_INT_STATUS_LO 0x3a0
53
-#define PCH_PIC_INT_STATUS_HI 0x3a4
54
-#define PCH_PIC_INT_POL_LO 0x3e0
55
-#define PCH_PIC_INT_POL_HI 0x3e4
56
-
57
-#define STATUS_LO_START 0
58
-#define STATUS_HI_START 0x4
59
-#define POL_LO_START 0x40
60
-#define POL_HI_START 0x44
61
struct LoongArchPCHPIC {
62
SysBusDevice parent_obj;
63
qemu_irq parent_irq[64];
64
@@ -XXX,XX +XXX,XX @@ struct LoongArchPCHPIC {
65
MemoryRegion iomem8;
66
unsigned int irq_num;
67
};
68
+#endif /* HW_LOONGARCH_PCH_PIC_H */
69
diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h
70
new file mode 100644
71
index XXXXXXX..XXXXXXX
72
--- /dev/null
73
+++ b/include/hw/intc/loongarch_pic_common.h
74
@@ -XXX,XX +XXX,XX @@
75
+/* SPDX-License-Identifier: GPL-2.0-or-later */
76
+/*
77
+ * LoongArch 7A1000 I/O interrupt controller definitions
78
+ * Copyright (c) 2024 Loongson Technology Corporation Limited
79
+ */
80
+
81
+#ifndef HW_LOONGARCH_PIC_COMMON_H
82
+#define HW_LOONGARCH_PIC_COMMON_H
83
+
84
+#include "hw/pci-host/ls7a.h"
85
+#include "hw/sysbus.h"
86
+
87
+#define PCH_PIC_INT_ID_VAL 0x7000000UL
88
+#define PCH_PIC_INT_ID_VER 0x1UL
89
+#define PCH_PIC_INT_ID_LO 0x00
90
+#define PCH_PIC_INT_ID_HI 0x04
91
+#define PCH_PIC_INT_MASK_LO 0x20
92
+#define PCH_PIC_INT_MASK_HI 0x24
93
+#define PCH_PIC_HTMSI_EN_LO 0x40
94
+#define PCH_PIC_HTMSI_EN_HI 0x44
95
+#define PCH_PIC_INT_EDGE_LO 0x60
96
+#define PCH_PIC_INT_EDGE_HI 0x64
97
+#define PCH_PIC_INT_CLEAR_LO 0x80
98
+#define PCH_PIC_INT_CLEAR_HI 0x84
99
+#define PCH_PIC_AUTO_CTRL0_LO 0xc0
100
+#define PCH_PIC_AUTO_CTRL0_HI 0xc4
101
+#define PCH_PIC_AUTO_CTRL1_LO 0xe0
102
+#define PCH_PIC_AUTO_CTRL1_HI 0xe4
103
+#define PCH_PIC_ROUTE_ENTRY_OFFSET 0x100
104
+#define PCH_PIC_ROUTE_ENTRY_END 0x13f
105
+#define PCH_PIC_HTMSI_VEC_OFFSET 0x200
106
+#define PCH_PIC_HTMSI_VEC_END 0x23f
107
+#define PCH_PIC_INT_STATUS_LO 0x3a0
108
+#define PCH_PIC_INT_STATUS_HI 0x3a4
109
+#define PCH_PIC_INT_POL_LO 0x3e0
110
+#define PCH_PIC_INT_POL_HI 0x3e4
111
+
112
+#define STATUS_LO_START 0
113
+#define STATUS_HI_START 0x4
114
+#define POL_LO_START 0x40
115
+#define POL_HI_START 0x44
116
+#endif /* HW_LOONGARCH_PIC_COMMON_H */
117
--
118
2.43.5
diff view generated by jsdifflib
Deleted patch
1
Move structure LoongArchPCHPIC from header file loongarch_pch_pic.h
2
to file loongarch_pic_common.h, and rename structure name with
3
LoongArchPICCommonState.
4
1
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
---
8
include/hw/intc/loongarch_pch_pic.h | 27 +------------------------
9
include/hw/intc/loongarch_pic_common.h | 28 ++++++++++++++++++++++++++
10
2 files changed, 29 insertions(+), 26 deletions(-)
11
12
diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/intc/loongarch_pch_pic.h
15
+++ b/include/hw/intc/loongarch_pch_pic.h
16
@@ -XXX,XX +XXX,XX @@
17
18
#include "hw/intc/loongarch_pic_common.h"
19
20
+#define LoongArchPCHPIC LoongArchPICCommonState
21
#define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic"
22
#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name
23
OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC)
24
25
-struct LoongArchPCHPIC {
26
- SysBusDevice parent_obj;
27
- qemu_irq parent_irq[64];
28
- uint64_t int_mask; /*0x020 interrupt mask register*/
29
- uint64_t htmsi_en; /*0x040 1=msi*/
30
- uint64_t intedge; /*0x060 edge=1 level =0*/
31
- uint64_t intclr; /*0x080 for clean edge int,set 1 clean,set 0 is noused*/
32
- uint64_t auto_crtl0; /*0x0c0*/
33
- uint64_t auto_crtl1; /*0x0e0*/
34
- uint64_t last_intirr; /* edge detection */
35
- uint64_t intirr; /* 0x380 interrupt request register */
36
- uint64_t intisr; /* 0x3a0 interrupt service register */
37
- /*
38
- * 0x3e0 interrupt level polarity selection
39
- * register 0 for high level trigger
40
- */
41
- uint64_t int_polarity;
42
-
43
- uint8_t route_entry[64]; /*0x100 - 0x138*/
44
- uint8_t htmsi_vector[64]; /*0x200 - 0x238*/
45
-
46
- MemoryRegion iomem32_low;
47
- MemoryRegion iomem32_high;
48
- MemoryRegion iomem8;
49
- unsigned int irq_num;
50
-};
51
#endif /* HW_LOONGARCH_PCH_PIC_H */
52
diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h
53
index XXXXXXX..XXXXXXX 100644
54
--- a/include/hw/intc/loongarch_pic_common.h
55
+++ b/include/hw/intc/loongarch_pic_common.h
56
@@ -XXX,XX +XXX,XX @@
57
#define STATUS_HI_START 0x4
58
#define POL_LO_START 0x40
59
#define POL_HI_START 0x44
60
+
61
+struct LoongArchPICCommonState {
62
+ SysBusDevice parent_obj;
63
+
64
+ qemu_irq parent_irq[64];
65
+ uint64_t int_mask; /* 0x020 interrupt mask register */
66
+ uint64_t htmsi_en; /* 0x040 1=msi */
67
+ uint64_t intedge; /* 0x060 edge=1 level=0 */
68
+ uint64_t intclr; /* 0x080 clean edge int, set 1 clean, 0 noused */
69
+ uint64_t auto_crtl0; /* 0x0c0 */
70
+ uint64_t auto_crtl1; /* 0x0e0 */
71
+ uint64_t last_intirr; /* edge detection */
72
+ uint64_t intirr; /* 0x380 interrupt request register */
73
+ uint64_t intisr; /* 0x3a0 interrupt service register */
74
+ /*
75
+ * 0x3e0 interrupt level polarity selection
76
+ * register 0 for high level trigger
77
+ */
78
+ uint64_t int_polarity;
79
+
80
+ uint8_t route_entry[64]; /* 0x100 - 0x138 */
81
+ uint8_t htmsi_vector[64]; /* 0x200 - 0x238 */
82
+
83
+ MemoryRegion iomem32_low;
84
+ MemoryRegion iomem32_high;
85
+ MemoryRegion iomem8;
86
+ unsigned int irq_num;
87
+};
88
#endif /* HW_LOONGARCH_PIC_COMMON_H */
89
--
90
2.43.5
diff view generated by jsdifflib
1
With pic vmstate, rename structure name vmstate_loongarch_pch_pic with
1
From: Bibo Mao <maobibo@loongson.cn>
2
vmstate_loongarch_pic_common, and with pic property rename
2
3
loongarch_pch_pic_properties with loongarch_pic_common_properties.
3
Loongson Binary Translation (LBT) is used to accelerate binary
4
translation, which contains 4 scratch registers (scr0 to scr3), x86/ARM
5
eflags (eflags) and x87 fpu stack pointer (ftop).
6
7
Now LBT feature is added in kvm mode, not supported in TCG mode since
8
it is not emulated. Feature variable lbt is added with OnOffAuto type,
9
If lbt feature is not supported with KVM host, it reports error if there
10
is lbt=on command line.
11
12
If there is no any command line about lbt parameter, it checks whether
13
KVM host supports lbt feature and set the corresponding value in cpucfg.
4
14
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
15
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
16
Reviewed-by: Song Gao <gaosong@loongson.cn>
17
Message-Id: <20240929070405.235200-2-maobibo@loongson.cn>
18
Signed-off-by: Song Gao <gaosong@loongson.cn>
7
---
19
---
8
hw/intc/loongarch_pch_pic.c | 52 +++++++++++++++++++++++--------------
20
target/loongarch/cpu.c | 24 +++++++++++
9
1 file changed, 32 insertions(+), 20 deletions(-)
21
target/loongarch/cpu.h | 6 +++
22
target/loongarch/kvm/kvm.c | 57 ++++++++++++++++++++++++++-
23
target/loongarch/loongarch-qmp-cmds.c | 2 +-
24
4 files changed, 87 insertions(+), 2 deletions(-)
10
25
11
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
26
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
12
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/intc/loongarch_pch_pic.c
28
--- a/target/loongarch/cpu.c
14
+++ b/hw/intc/loongarch_pch_pic.c
29
+++ b/target/loongarch/cpu.c
15
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d)
30
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lasx(Object *obj, bool value, Error **errp)
16
s->int_polarity = 0x0;
31
}
17
}
32
}
18
33
19
+static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
34
+static bool loongarch_get_lbt(Object *obj, Error **errp)
20
+{
35
+{
21
+ LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev);
36
+ return LOONGARCH_CPU(obj)->lbt != ON_OFF_AUTO_OFF;
37
+}
22
+
38
+
23
+ if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) {
39
+static void loongarch_set_lbt(Object *obj, bool value, Error **errp)
24
+ error_setg(errp, "Invalid 'pic_irq_num'");
40
+{
25
+ return;
41
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
42
+
43
+ cpu->lbt = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
44
+}
45
+
46
void loongarch_cpu_post_init(Object *obj)
47
{
48
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
49
+
50
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
51
loongarch_set_lsx);
52
object_property_add_bool(obj, "lasx", loongarch_get_lasx,
53
loongarch_set_lasx);
54
+ /* lbt is enabled only in kvm mode, not supported in tcg mode */
55
+ if (kvm_enabled()) {
56
+ cpu->lbt = ON_OFF_AUTO_AUTO;
57
+ object_property_add_bool(obj, "lbt", loongarch_get_lbt,
58
+ loongarch_set_lbt);
59
+ object_property_set_description(obj, "lbt",
60
+ "Set off to disable Binary Tranlation.");
61
+ } else {
62
+ cpu->lbt = ON_OFF_AUTO_OFF;
63
+ }
64
}
65
66
static void loongarch_cpu_init(Object *obj)
67
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
68
index XXXXXXX..XXXXXXX 100644
69
--- a/target/loongarch/cpu.h
70
+++ b/target/loongarch/cpu.h
71
@@ -XXX,XX +XXX,XX @@ FIELD(CPUCFG2, LLFTP_VER, 15, 3)
72
FIELD(CPUCFG2, LBT_X86, 18, 1)
73
FIELD(CPUCFG2, LBT_ARM, 19, 1)
74
FIELD(CPUCFG2, LBT_MIPS, 20, 1)
75
+FIELD(CPUCFG2, LBT_ALL, 18, 3)
76
FIELD(CPUCFG2, LSPW, 21, 1)
77
FIELD(CPUCFG2, LAM, 22, 1)
78
79
@@ -XXX,XX +XXX,XX @@ struct LoongArchTLB {
80
typedef struct LoongArchTLB LoongArchTLB;
81
#endif
82
83
+enum loongarch_features {
84
+ LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
85
+};
86
+
87
typedef struct CPUArchState {
88
uint64_t gpr[32];
89
uint64_t pc;
90
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
91
CPULoongArchState env;
92
QEMUTimer timer;
93
uint32_t phy_id;
94
+ OnOffAuto lbt;
95
96
/* 'compatible' string for this CPU for Linux device trees */
97
const char *dtb_compatible;
98
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
99
index XXXXXXX..XXXXXXX 100644
100
--- a/target/loongarch/kvm/kvm.c
101
+++ b/target/loongarch/kvm/kvm.c
102
@@ -XXX,XX +XXX,XX @@
103
#include <sys/ioctl.h>
104
#include <linux/kvm.h>
105
106
+#include "qapi/error.h"
107
#include "qemu/timer.h"
108
#include "qemu/error-report.h"
109
#include "qemu/main-loop.h"
110
@@ -XXX,XX +XXX,XX @@ static void kvm_loongarch_vm_stage_change(void *opaque, bool running,
111
}
112
}
113
114
+static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
115
+{
116
+ int ret;
117
+ struct kvm_device_attr attr;
118
+
119
+ switch (feature) {
120
+ case LOONGARCH_FEATURE_LBT:
121
+ /*
122
+ * Return all if all the LBT features are supported such as:
123
+ * KVM_LOONGARCH_VM_FEAT_X86BT
124
+ * KVM_LOONGARCH_VM_FEAT_ARMBT
125
+ * KVM_LOONGARCH_VM_FEAT_MIPSBT
126
+ */
127
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
128
+ attr.attr = KVM_LOONGARCH_VM_FEAT_X86BT;
129
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
130
+ attr.attr = KVM_LOONGARCH_VM_FEAT_ARMBT;
131
+ ret |= kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
132
+ attr.attr = KVM_LOONGARCH_VM_FEAT_MIPSBT;
133
+ ret |= kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
134
+ return (ret == 0);
135
+ default:
136
+ return false;
26
+ }
137
+ }
27
+}
138
+}
28
+
139
+
29
static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
140
+static int kvm_cpu_check_lbt(CPUState *cs, Error **errp)
141
+{
142
+ CPULoongArchState *env = cpu_env(cs);
143
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
144
+ bool kvm_supported;
145
+
146
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_LBT);
147
+ if (cpu->lbt == ON_OFF_AUTO_ON) {
148
+ if (kvm_supported) {
149
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LBT_ALL, 7);
150
+ } else {
151
+ error_setg(errp, "'lbt' feature not supported by KVM on this host");
152
+ return -ENOTSUP;
153
+ }
154
+ } else if ((cpu->lbt == ON_OFF_AUTO_AUTO) && kvm_supported) {
155
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LBT_ALL, 7);
156
+ }
157
+
158
+ return 0;
159
+}
160
+
161
int kvm_arch_init_vcpu(CPUState *cs)
30
{
162
{
31
LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev);
163
uint64_t val;
32
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
164
+ int ret;
33
+ Error *local_err = NULL;
165
+ Error *local_err = NULL;
34
166
35
- if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) {
167
+ ret = 0;
36
- error_setg(errp, "Invalid 'pic_irq_num'");
168
qemu_add_vm_change_state_handler(kvm_loongarch_vm_stage_change, cs);
37
+ loongarch_pic_common_realize(dev, &local_err);
169
38
+ if (local_err) {
170
if (!kvm_get_one_reg(cs, KVM_REG_LOONGARCH_DEBUG_INST, &val)) {
39
+ error_propagate(errp, local_err);
171
brk_insn = val;
40
return;
41
}
172
}
42
173
43
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
174
- return 0;
44
175
+ ret = kvm_cpu_check_lbt(cs, &local_err);
176
+ if (ret < 0) {
177
+ error_report_err(local_err);
178
+ }
179
+ return ret;
45
}
180
}
46
181
47
-static Property loongarch_pch_pic_properties[] = {
182
int kvm_arch_destroy_vcpu(CPUState *cs)
48
- DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPCHPIC, irq_num, 0),
183
diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loongarch-qmp-cmds.c
49
+static Property loongarch_pic_common_properties[] = {
184
index XXXXXXX..XXXXXXX 100644
50
+ DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0),
185
--- a/target/loongarch/loongarch-qmp-cmds.c
51
DEFINE_PROP_END_OF_LIST(),
186
+++ b/target/loongarch/loongarch-qmp-cmds.c
187
@@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
188
}
189
190
static const char *cpu_model_advertised_features[] = {
191
- "lsx", "lasx", NULL
192
+ "lsx", "lasx", "lbt", NULL
52
};
193
};
53
194
54
-static const VMStateDescription vmstate_loongarch_pch_pic = {
195
CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
55
- .name = TYPE_LOONGARCH_PCH_PIC,
56
+static const VMStateDescription vmstate_loongarch_pic_common = {
57
+ .name = "loongarch_pch_pic",
58
.version_id = 1,
59
.minimum_version_id = 1,
60
.fields = (const VMStateField[]) {
61
- VMSTATE_UINT64(int_mask, LoongArchPCHPIC),
62
- VMSTATE_UINT64(htmsi_en, LoongArchPCHPIC),
63
- VMSTATE_UINT64(intedge, LoongArchPCHPIC),
64
- VMSTATE_UINT64(intclr, LoongArchPCHPIC),
65
- VMSTATE_UINT64(auto_crtl0, LoongArchPCHPIC),
66
- VMSTATE_UINT64(auto_crtl1, LoongArchPCHPIC),
67
- VMSTATE_UINT8_ARRAY(route_entry, LoongArchPCHPIC, 64),
68
- VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPCHPIC, 64),
69
- VMSTATE_UINT64(last_intirr, LoongArchPCHPIC),
70
- VMSTATE_UINT64(intirr, LoongArchPCHPIC),
71
- VMSTATE_UINT64(intisr, LoongArchPCHPIC),
72
- VMSTATE_UINT64(int_polarity, LoongArchPCHPIC),
73
+ VMSTATE_UINT64(int_mask, LoongArchPICCommonState),
74
+ VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState),
75
+ VMSTATE_UINT64(intedge, LoongArchPICCommonState),
76
+ VMSTATE_UINT64(intclr, LoongArchPICCommonState),
77
+ VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState),
78
+ VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState),
79
+ VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64),
80
+ VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64),
81
+ VMSTATE_UINT64(last_intirr, LoongArchPICCommonState),
82
+ VMSTATE_UINT64(intirr, LoongArchPICCommonState),
83
+ VMSTATE_UINT64(intisr, LoongArchPICCommonState),
84
+ VMSTATE_UINT64(int_polarity, LoongArchPICCommonState),
85
VMSTATE_END_OF_LIST()
86
}
87
};
88
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data)
89
90
dc->realize = loongarch_pch_pic_realize;
91
device_class_set_legacy_reset(dc, loongarch_pch_pic_reset);
92
- dc->vmsd = &vmstate_loongarch_pch_pic;
93
- device_class_set_props(dc, loongarch_pch_pic_properties);
94
+ dc->vmsd = &vmstate_loongarch_pic_common;
95
+ device_class_set_props(dc, loongarch_pic_common_properties);
96
}
97
98
static const TypeInfo loongarch_pch_pic_info = {
99
--
196
--
100
2.43.5
197
2.34.1
diff view generated by jsdifflib
1
Move some common functions to file loongarch_pic_common.c, the common
1
From: Bibo Mao <maobibo@loongson.cn>
2
functions include loongarch_pic_common_realize(), property structure
2
3
loongarch_pic_common_properties and vmstate structure
3
Six registers scr0 - scr3, eflags and ftop are added in percpu vmstate.
4
vmstate_loongarch_pic_common.
4
And two functions kvm_loongarch_get_lbt/kvm_loongarch_put_lbt are added
5
to save/restore lbt registers.
5
6
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
7
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
7
Reviewed-by: Song Gao <gaosong@loongson.cn>
8
Reviewed-by: Song Gao <gaosong@loongson.cn>
9
Message-Id: <20240929070405.235200-3-maobibo@loongson.cn>
10
Signed-off-by: Song Gao <gaosong@loongson.cn>
8
---
11
---
9
hw/intc/loongarch_pch_pic.c | 37 +-----------------------------
12
target/loongarch/cpu.h | 12 ++++++++
10
hw/intc/loongarch_pic_common.c | 41 ++++++++++++++++++++++++++++++++++
13
target/loongarch/kvm/kvm.c | 62 ++++++++++++++++++++++++++++++++++++++
11
2 files changed, 42 insertions(+), 36 deletions(-)
14
target/loongarch/machine.c | 24 +++++++++++++++
12
create mode 100644 hw/intc/loongarch_pic_common.c
15
3 files changed, 98 insertions(+)
13
16
14
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
17
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
15
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/intc/loongarch_pch_pic.c
19
--- a/target/loongarch/cpu.h
17
+++ b/hw/intc/loongarch_pch_pic.c
20
+++ b/target/loongarch/cpu.h
18
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d)
21
@@ -XXX,XX +XXX,XX @@ enum loongarch_features {
19
s->int_polarity = 0x0;
22
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
23
};
24
25
+typedef struct LoongArchBT {
26
+ /* scratch registers */
27
+ uint64_t scr0;
28
+ uint64_t scr1;
29
+ uint64_t scr2;
30
+ uint64_t scr3;
31
+ /* loongarch eflags */
32
+ uint32_t eflags;
33
+ uint32_t ftop;
34
+} lbt_t;
35
+
36
typedef struct CPUArchState {
37
uint64_t gpr[32];
38
uint64_t pc;
39
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState {
40
fpr_t fpr[32];
41
bool cf[8];
42
uint32_t fcsr0;
43
+ lbt_t lbt;
44
45
uint32_t cpucfg[21];
46
47
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/target/loongarch/kvm/kvm.c
50
+++ b/target/loongarch/kvm/kvm.c
51
@@ -XXX,XX +XXX,XX @@ static int kvm_loongarch_put_regs_fp(CPUState *cs)
52
return ret;
20
}
53
}
21
54
22
-static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
55
+static int kvm_loongarch_put_lbt(CPUState *cs)
23
-{
56
+{
24
- LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev);
57
+ CPULoongArchState *env = cpu_env(cs);
25
-
58
+ uint64_t val;
26
- if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) {
59
+ int ret;
27
- error_setg(errp, "Invalid 'pic_irq_num'");
28
- return;
29
- }
30
-}
31
-
32
+#include "loongarch_pic_common.c"
33
static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
34
{
35
LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev);
36
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
37
38
}
39
40
-static Property loongarch_pic_common_properties[] = {
41
- DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0),
42
- DEFINE_PROP_END_OF_LIST(),
43
-};
44
-
45
-static const VMStateDescription vmstate_loongarch_pic_common = {
46
- .name = "loongarch_pch_pic",
47
- .version_id = 1,
48
- .minimum_version_id = 1,
49
- .fields = (const VMStateField[]) {
50
- VMSTATE_UINT64(int_mask, LoongArchPICCommonState),
51
- VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState),
52
- VMSTATE_UINT64(intedge, LoongArchPICCommonState),
53
- VMSTATE_UINT64(intclr, LoongArchPICCommonState),
54
- VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState),
55
- VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState),
56
- VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64),
57
- VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64),
58
- VMSTATE_UINT64(last_intirr, LoongArchPICCommonState),
59
- VMSTATE_UINT64(intirr, LoongArchPICCommonState),
60
- VMSTATE_UINT64(intisr, LoongArchPICCommonState),
61
- VMSTATE_UINT64(int_polarity, LoongArchPICCommonState),
62
- VMSTATE_END_OF_LIST()
63
- }
64
-};
65
-
66
static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data)
67
{
68
DeviceClass *dc = DEVICE_CLASS(klass);
69
diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c
70
new file mode 100644
71
index XXXXXXX..XXXXXXX
72
--- /dev/null
73
+++ b/hw/intc/loongarch_pic_common.c
74
@@ -XXX,XX +XXX,XX @@
75
+/* SPDX-License-Identifier: GPL-2.0-or-later */
76
+/*
77
+ * QEMU Loongson 7A1000 I/O interrupt controller.
78
+ * Copyright (C) 2024 Loongson Technology Corporation Limited
79
+ */
80
+
60
+
81
+static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
61
+ /* check whether vm support LBT firstly */
82
+{
62
+ if (FIELD_EX32(env->cpucfg[2], CPUCFG2, LBT_ALL) != 7) {
83
+ LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev);
63
+ return 0;
64
+ }
84
+
65
+
85
+ if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) {
66
+ /* set six LBT registers including scr0-scr3, eflags, ftop */
86
+ error_setg(errp, "Invalid 'pic_irq_num'");
67
+ ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR0, &env->lbt.scr0);
87
+ return;
68
+ ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR1, &env->lbt.scr1);
88
+ }
69
+ ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR2, &env->lbt.scr2);
70
+ ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR3, &env->lbt.scr3);
71
+ /*
72
+ * Be cautious, KVM_REG_LOONGARCH_LBT_FTOP is defined as 64-bit however
73
+ * lbt.ftop is 32-bit; the same with KVM_REG_LOONGARCH_LBT_EFLAGS register
74
+ */
75
+ val = env->lbt.eflags;
76
+ ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_EFLAGS, &val);
77
+ val = env->lbt.ftop;
78
+ ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_FTOP, &val);
79
+
80
+ return ret;
89
+}
81
+}
90
+
82
+
91
+static Property loongarch_pic_common_properties[] = {
83
+static int kvm_loongarch_get_lbt(CPUState *cs)
92
+ DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0),
84
+{
93
+ DEFINE_PROP_END_OF_LIST(),
85
+ CPULoongArchState *env = cpu_env(cs);
86
+ uint64_t val;
87
+ int ret;
88
+
89
+ /* check whether vm support LBT firstly */
90
+ if (FIELD_EX32(env->cpucfg[2], CPUCFG2, LBT_ALL) != 7) {
91
+ return 0;
92
+ }
93
+
94
+ /* get six LBT registers including scr0-scr3, eflags, ftop */
95
+ ret = kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR0, &env->lbt.scr0);
96
+ ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR1, &env->lbt.scr1);
97
+ ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR2, &env->lbt.scr2);
98
+ ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR3, &env->lbt.scr3);
99
+ ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_EFLAGS, &val);
100
+ env->lbt.eflags = (uint32_t)val;
101
+ ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_FTOP, &val);
102
+ env->lbt.ftop = (uint32_t)val;
103
+
104
+ return ret;
105
+}
106
+
107
void kvm_arch_reset_vcpu(CPUState *cs)
108
{
109
CPULoongArchState *env = cpu_env(cs);
110
@@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs, Error **errp)
111
return ret;
112
}
113
114
+ ret = kvm_loongarch_get_lbt(cs);
115
+ if (ret) {
116
+ return ret;
117
+ }
118
+
119
ret = kvm_loongarch_get_mpstate(cs);
120
return ret;
121
}
122
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level, Error **errp)
123
return ret;
124
}
125
126
+ ret = kvm_loongarch_put_lbt(cs);
127
+ if (ret) {
128
+ return ret;
129
+ }
130
+
131
ret = kvm_loongarch_put_mpstate(cs);
132
return ret;
133
}
134
diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c
135
index XXXXXXX..XXXXXXX 100644
136
--- a/target/loongarch/machine.c
137
+++ b/target/loongarch/machine.c
138
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_lasx = {
139
},
140
};
141
142
+static bool lbt_needed(void *opaque)
143
+{
144
+ LoongArchCPU *cpu = opaque;
145
+
146
+ return !!FIELD_EX64(cpu->env.cpucfg[2], CPUCFG2, LBT_ALL);
147
+}
148
+
149
+static const VMStateDescription vmstate_lbt = {
150
+ .name = "cpu/lbt",
151
+ .version_id = 0,
152
+ .minimum_version_id = 0,
153
+ .needed = lbt_needed,
154
+ .fields = (const VMStateField[]) {
155
+ VMSTATE_UINT64(env.lbt.scr0, LoongArchCPU),
156
+ VMSTATE_UINT64(env.lbt.scr1, LoongArchCPU),
157
+ VMSTATE_UINT64(env.lbt.scr2, LoongArchCPU),
158
+ VMSTATE_UINT64(env.lbt.scr3, LoongArchCPU),
159
+ VMSTATE_UINT32(env.lbt.eflags, LoongArchCPU),
160
+ VMSTATE_UINT32(env.lbt.ftop, LoongArchCPU),
161
+ VMSTATE_END_OF_LIST()
162
+ },
94
+};
163
+};
95
+
164
+
96
+static const VMStateDescription vmstate_loongarch_pic_common = {
165
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
97
+ .name = "loongarch_pch_pic",
166
static bool tlb_needed(void *opaque)
98
+ .version_id = 1,
167
{
99
+ .minimum_version_id = 1,
168
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_loongarch_cpu = {
100
+ .fields = (const VMStateField[]) {
169
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
101
+ VMSTATE_UINT64(int_mask, LoongArchPICCommonState),
170
&vmstate_tlb,
102
+ VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState),
171
#endif
103
+ VMSTATE_UINT64(intedge, LoongArchPICCommonState),
172
+ &vmstate_lbt,
104
+ VMSTATE_UINT64(intclr, LoongArchPICCommonState),
173
NULL
105
+ VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState),
174
}
106
+ VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState),
175
};
107
+ VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64),
108
+ VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64),
109
+ VMSTATE_UINT64(last_intirr, LoongArchPICCommonState),
110
+ VMSTATE_UINT64(intirr, LoongArchPICCommonState),
111
+ VMSTATE_UINT64(intisr, LoongArchPICCommonState),
112
+ VMSTATE_UINT64(int_polarity, LoongArchPICCommonState),
113
+ VMSTATE_END_OF_LIST()
114
+ }
115
+};
116
--
176
--
117
2.43.5
177
2.34.1
diff view generated by jsdifflib
1
With some structure such as vmstate and property, rename LoongArchExtIOI
1
From: Bibo Mao <maobibo@loongson.cn>
2
with LoongArchExtIOICommonState, these common structure will be moved
3
to common file.
4
2
3
Implement PMU extension for LoongArch kvm mode. Use OnOffAuto type
4
variable pmu to check the PMU feature. If the PMU Feature is not supported
5
with KVM host, it reports error if there is pmu=on command line.
6
7
If there is no any command line about pmu parameter, it checks whether
8
KVM host supports the PMU Feature and set the corresponding value in cpucfg.
9
10
This patch is based on lbt patch located at
11
https://lore.kernel.org/qemu-devel/20240904061859.86615-1-maobibo@loongson.cn
12
13
Co-developed-by: Song Gao <gaosong@loongson.cn>
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
14
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
15
Reviewed-by: Song Gao <gaosong@loongson.cn>
16
Message-Id: <20240918082315.2345034-1-maobibo@loongson.cn>
17
Signed-off-by: Song Gao <gaosong@loongson.cn>
7
---
18
---
8
hw/intc/loongarch_extioi.c | 41 +++++++++++++++++++++++---------------
19
target/loongarch/cpu.c | 19 +++++++++++++
9
1 file changed, 25 insertions(+), 16 deletions(-)
20
target/loongarch/cpu.h | 2 ++
21
target/loongarch/kvm/kvm.c | 41 +++++++++++++++++++++++++++
22
target/loongarch/loongarch-qmp-cmds.c | 2 +-
23
4 files changed, 63 insertions(+), 1 deletion(-)
10
24
11
diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
25
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
12
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/intc/loongarch_extioi.c
27
--- a/target/loongarch/cpu.c
14
+++ b/hw/intc/loongarch_extioi.c
28
+++ b/target/loongarch/cpu.c
15
@@ -XXX,XX +XXX,XX @@ static int vmstate_extioi_post_load(void *opaque, int version_id)
29
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lbt(Object *obj, bool value, Error **errp)
30
cpu->lbt = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
31
}
32
33
+static bool loongarch_get_pmu(Object *obj, Error **errp)
34
+{
35
+ return LOONGARCH_CPU(obj)->pmu != ON_OFF_AUTO_OFF;
36
+}
37
+
38
+static void loongarch_set_pmu(Object *obj, bool value, Error **errp)
39
+{
40
+ LoongArchCPU *cpu = LOONGARCH_CPU(obj);
41
+
42
+ cpu->pmu = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
43
+}
44
+
45
void loongarch_cpu_post_init(Object *obj)
46
{
47
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
48
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
49
loongarch_set_lbt);
50
object_property_set_description(obj, "lbt",
51
"Set off to disable Binary Tranlation.");
52
+
53
+ cpu->pmu = ON_OFF_AUTO_AUTO;
54
+ object_property_add_bool(obj, "pmu", loongarch_get_pmu,
55
+ loongarch_set_pmu);
56
+ object_property_set_description(obj, "pmu",
57
+ "Set off to performance monitor unit.");
58
+
59
} else {
60
cpu->lbt = ON_OFF_AUTO_OFF;
61
}
62
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
63
index XXXXXXX..XXXXXXX 100644
64
--- a/target/loongarch/cpu.h
65
+++ b/target/loongarch/cpu.h
66
@@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB;
67
68
enum loongarch_features {
69
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
70
+ LOONGARCH_FEATURE_PMU,
71
};
72
73
typedef struct LoongArchBT {
74
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
75
QEMUTimer timer;
76
uint32_t phy_id;
77
OnOffAuto lbt;
78
+ OnOffAuto pmu;
79
80
/* 'compatible' string for this CPU for Linux device trees */
81
const char *dtb_compatible;
82
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
83
index XXXXXXX..XXXXXXX 100644
84
--- a/target/loongarch/kvm/kvm.c
85
+++ b/target/loongarch/kvm/kvm.c
86
@@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
87
attr.attr = KVM_LOONGARCH_VM_FEAT_MIPSBT;
88
ret |= kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
89
return (ret == 0);
90
+
91
+ case LOONGARCH_FEATURE_PMU:
92
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
93
+ attr.attr = KVM_LOONGARCH_VM_FEAT_PMU;
94
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
95
+ return (ret == 0);
96
+
97
default:
98
return false;
99
}
100
+
101
+ return false;
102
}
103
104
static int kvm_cpu_check_lbt(CPUState *cs, Error **errp)
105
@@ -XXX,XX +XXX,XX @@ static int kvm_cpu_check_lbt(CPUState *cs, Error **errp)
16
return 0;
106
return 0;
17
}
107
}
18
108
19
+static int loongarch_extioi_common_post_load(void *opaque, int version_id)
109
+static int kvm_cpu_check_pmu(CPUState *cs, Error **errp)
20
+{
110
+{
21
+ return vmstate_extioi_post_load(opaque, version_id);
111
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
112
+ CPULoongArchState *env = cpu_env(cs);
113
+ bool kvm_supported;
114
+
115
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PMU);
116
+ if (cpu->pmu == ON_OFF_AUTO_ON) {
117
+ if (!kvm_supported) {
118
+ error_setg(errp, "'pmu' feature not supported by KVM on the host");
119
+ return -ENOTSUP;
120
+ }
121
+ } else if (cpu->pmu != ON_OFF_AUTO_AUTO) {
122
+ /* disable pmu if ON_OFF_AUTO_OFF is set */
123
+ kvm_supported = false;
124
+ }
125
+
126
+ if (kvm_supported) {
127
+ env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, PMP, 1);
128
+ env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, PMNUM, 3);
129
+ env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, PMBITS, 63);
130
+ env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, UPM, 1);
131
+ }
132
+ return 0;
22
+}
133
+}
23
+
134
+
24
static const VMStateDescription vmstate_extioi_core = {
135
int kvm_arch_init_vcpu(CPUState *cs)
25
.name = "extioi-core",
136
{
26
.version_id = 1,
137
uint64_t val;
27
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_extioi_core = {
138
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
139
if (ret < 0) {
140
error_report_err(local_err);
141
}
142
+
143
+ ret = kvm_cpu_check_pmu(cs, &local_err);
144
+ if (ret < 0) {
145
+ error_report_err(local_err);
146
+ }
147
+
148
return ret;
149
}
150
151
diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loongarch-qmp-cmds.c
152
index XXXXXXX..XXXXXXX 100644
153
--- a/target/loongarch/loongarch-qmp-cmds.c
154
+++ b/target/loongarch/loongarch-qmp-cmds.c
155
@@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
156
}
157
158
static const char *cpu_model_advertised_features[] = {
159
- "lsx", "lasx", "lbt", NULL
160
+ "lsx", "lasx", "lbt", "pmu", NULL
28
};
161
};
29
162
30
static const VMStateDescription vmstate_loongarch_extioi = {
163
CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
31
- .name = TYPE_LOONGARCH_EXTIOI,
32
+ .name = "loongarch.extioi",
33
.version_id = 3,
34
.minimum_version_id = 3,
35
- .post_load = vmstate_extioi_post_load,
36
+ .post_load = loongarch_extioi_common_post_load,
37
.fields = (const VMStateField[]) {
38
- VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOI, EXTIOI_IRQS_GROUP_COUNT),
39
- VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOI,
40
+ VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOICommonState,
41
+ EXTIOI_IRQS_GROUP_COUNT),
42
+ VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOICommonState,
43
EXTIOI_IRQS_NODETYPE_COUNT / 2),
44
- VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOI, EXTIOI_IRQS / 32),
45
- VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOI, EXTIOI_IRQS / 32),
46
- VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE / 4),
47
- VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOI, EXTIOI_IRQS / 4),
48
-
49
- VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOI, num_cpu,
50
- vmstate_extioi_core, ExtIOICore),
51
- VMSTATE_UINT32(features, LoongArchExtIOI),
52
- VMSTATE_UINT32(status, LoongArchExtIOI),
53
+ VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOICommonState,
54
+ EXTIOI_IRQS / 32),
55
+ VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOICommonState,
56
+ EXTIOI_IRQS / 32),
57
+ VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOICommonState,
58
+ EXTIOI_IRQS_IPMAP_SIZE / 4),
59
+ VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOICommonState,
60
+ EXTIOI_IRQS / 4),
61
+ VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOICommonState,
62
+ num_cpu, vmstate_extioi_core, ExtIOICore),
63
+ VMSTATE_UINT32(features, LoongArchExtIOICommonState),
64
+ VMSTATE_UINT32(status, LoongArchExtIOICommonState),
65
VMSTATE_END_OF_LIST()
66
}
67
};
68
69
static Property extioi_properties[] = {
70
- DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOI, num_cpu, 1),
71
- DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOI, features,
72
- EXTIOI_HAS_VIRT_EXTENSION, 0),
73
+ DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOICommonState, num_cpu, 1),
74
+ DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOICommonState,
75
+ features, EXTIOI_HAS_VIRT_EXTENSION, 0),
76
DEFINE_PROP_END_OF_LIST(),
77
};
78
79
--
164
--
80
2.43.5
165
2.34.1
diff view generated by jsdifflib
1
Rename structure LoongArchExtIOI with LoongArchExtIOICommonState,
1
From: Bibo Mao <maobibo@loongson.cn>
2
since it is defined in file loongarch_extioi_common.h
2
3
since 6.11, unistd.h includes header file unistd_64.h directly on
4
some platforms, here add unistd_64.h on these platforms. Affected
5
platforms are ARM64, LoongArch64 and Riscv. Otherwise there will
6
be compiling error such as:
7
8
linux-headers/asm/unistd.h:3:10: fatal error: asm/unistd_64.h: No such file or directory
9
#include <asm/unistd_64.h>
3
10
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
11
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Song Gao <gaosong@loongson.cn>
12
Acked-by: Song Gao <gaosong@loongson.cn>
13
Message-Id: <20241028023809.1554405-2-maobibo@loongson.cn>
14
Signed-off-by: Song Gao <gaosong@loongson.cn>
6
---
15
---
7
include/hw/intc/loongarch_extioi.h | 1 +
16
scripts/update-linux-headers.sh | 6 ++++++
8
include/hw/intc/loongarch_extioi_common.h | 2 +-
17
1 file changed, 6 insertions(+)
9
2 files changed, 2 insertions(+), 1 deletion(-)
10
18
11
diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
19
diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
12
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100755
13
--- a/include/hw/intc/loongarch_extioi.h
21
--- a/scripts/update-linux-headers.sh
14
+++ b/include/hw/intc/loongarch_extioi.h
22
+++ b/scripts/update-linux-headers.sh
15
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ EOF
16
24
fi
17
#include "hw/intc/loongarch_extioi_common.h"
25
if [ $arch = arm64 ]; then
18
26
cp "$hdrdir/include/asm/sve_context.h" "$output/linux-headers/asm-arm64/"
19
+#define LoongArchExtIOI LoongArchExtIOICommonState
27
+ cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-arm64/"
20
#define TYPE_LOONGARCH_EXTIOI "loongarch.extioi"
28
fi
21
OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI)
29
if [ $arch = x86 ]; then
22
#endif /* LOONGARCH_EXTIOI_H */
30
cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/"
23
diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h
31
@@ -XXX,XX +XXX,XX @@ EOF
24
index XXXXXXX..XXXXXXX 100644
32
fi
25
--- a/include/hw/intc/loongarch_extioi_common.h
33
if [ $arch = riscv ]; then
26
+++ b/include/hw/intc/loongarch_extioi_common.h
34
cp "$hdrdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/"
27
@@ -XXX,XX +XXX,XX @@ typedef struct ExtIOICore {
35
+ cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-riscv/"
28
qemu_irq parent_irq[LS3A_INTC_IP];
36
+ cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-riscv/"
29
} ExtIOICore;
37
+ fi
30
38
+ if [ $arch = loongarch ]; then
31
-struct LoongArchExtIOI {
39
+ cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-loongarch/"
32
+struct LoongArchExtIOICommonState {
40
fi
33
SysBusDevice parent_obj;
41
done
34
uint32_t num_cpu;
42
arch=
35
uint32_t features;
36
--
43
--
37
2.43.5
44
2.34.1
diff view generated by jsdifflib
1
Move definiton of structure LoongArchExtIOI from header file loongarch_extioi.h
1
From: Bibo Mao <maobibo@loongson.cn>
2
to file loongarch_extioi_common.h.
2
3
KVM LBT supports on LoongArch depends on the linux-header file
4
kvm_para.h, add header file kvm_para.h here.
3
5
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
Acked-by: Song Gao <gaosong@loongson.cn>
8
Message-Id: <20241028023809.1554405-3-maobibo@loongson.cn>
9
Signed-off-by: Song Gao <gaosong@loongson.cn>
6
---
10
---
7
include/hw/intc/loongarch_extioi.h | 26 ----------------------
11
scripts/update-linux-headers.sh | 1 +
8
include/hw/intc/loongarch_extioi_common.h | 27 +++++++++++++++++++++++
12
1 file changed, 1 insertion(+)
9
2 files changed, 27 insertions(+), 26 deletions(-)
10
13
11
diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
14
diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
12
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100755
13
--- a/include/hw/intc/loongarch_extioi.h
16
--- a/scripts/update-linux-headers.sh
14
+++ b/include/hw/intc/loongarch_extioi.h
17
+++ b/scripts/update-linux-headers.sh
15
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ EOF
16
19
cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-riscv/"
17
#include "hw/intc/loongarch_extioi_common.h"
20
fi
18
21
if [ $arch = loongarch ]; then
19
-typedef struct ExtIOICore {
22
+ cp "$hdrdir/include/asm/kvm_para.h" "$output/linux-headers/asm-loongarch/"
20
- uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
23
cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-loongarch/"
21
- DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS);
24
fi
22
- qemu_irq parent_irq[LS3A_INTC_IP];
25
done
23
-} ExtIOICore;
24
-
25
#define TYPE_LOONGARCH_EXTIOI "loongarch.extioi"
26
OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI)
27
-struct LoongArchExtIOI {
28
- SysBusDevice parent_obj;
29
- uint32_t num_cpu;
30
- uint32_t features;
31
- uint32_t status;
32
- /* hardware state */
33
- uint32_t nodetype[EXTIOI_IRQS_NODETYPE_COUNT / 2];
34
- uint32_t bounce[EXTIOI_IRQS_GROUP_COUNT];
35
- uint32_t isr[EXTIOI_IRQS / 32];
36
- uint32_t enable[EXTIOI_IRQS / 32];
37
- uint32_t ipmap[EXTIOI_IRQS_IPMAP_SIZE / 4];
38
- uint32_t coremap[EXTIOI_IRQS / 4];
39
- uint32_t sw_pending[EXTIOI_IRQS / 32];
40
- uint8_t sw_ipmap[EXTIOI_IRQS_IPMAP_SIZE];
41
- uint8_t sw_coremap[EXTIOI_IRQS];
42
- qemu_irq irq[EXTIOI_IRQS];
43
- ExtIOICore *cpu;
44
- MemoryRegion extioi_system_mem;
45
- MemoryRegion virt_extend;
46
-};
47
#endif /* LOONGARCH_EXTIOI_H */
48
diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h
49
index XXXXXXX..XXXXXXX 100644
50
--- a/include/hw/intc/loongarch_extioi_common.h
51
+++ b/include/hw/intc/loongarch_extioi_common.h
52
@@ -XXX,XX +XXX,XX @@
53
#define EXTIOI_ENABLE_CPU_ENCODE (3)
54
#define EXTIOI_VIRT_COREMAP_START (0x40)
55
#define EXTIOI_VIRT_COREMAP_END (0x240)
56
+
57
+typedef struct ExtIOICore {
58
+ uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
59
+ DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS);
60
+ qemu_irq parent_irq[LS3A_INTC_IP];
61
+} ExtIOICore;
62
+
63
+struct LoongArchExtIOI {
64
+ SysBusDevice parent_obj;
65
+ uint32_t num_cpu;
66
+ uint32_t features;
67
+ uint32_t status;
68
+ /* hardware state */
69
+ uint32_t nodetype[EXTIOI_IRQS_NODETYPE_COUNT / 2];
70
+ uint32_t bounce[EXTIOI_IRQS_GROUP_COUNT];
71
+ uint32_t isr[EXTIOI_IRQS / 32];
72
+ uint32_t enable[EXTIOI_IRQS / 32];
73
+ uint32_t ipmap[EXTIOI_IRQS_IPMAP_SIZE / 4];
74
+ uint32_t coremap[EXTIOI_IRQS / 4];
75
+ uint32_t sw_pending[EXTIOI_IRQS / 32];
76
+ uint8_t sw_ipmap[EXTIOI_IRQS_IPMAP_SIZE];
77
+ uint8_t sw_coremap[EXTIOI_IRQS];
78
+ qemu_irq irq[EXTIOI_IRQS];
79
+ ExtIOICore *cpu;
80
+ MemoryRegion extioi_system_mem;
81
+ MemoryRegion virt_extend;
82
+};
83
#endif /* LOONGARCH_EXTIOI_H */
84
--
26
--
85
2.43.5
27
2.34.1
diff view generated by jsdifflib
1
Memory region is created in instance_init(), merge it into function
1
When we run “qemu-system-loongarch64 -qmp stdio -vnc none -S”,
2
realize(). There is no special class_init() for loongarch_pch object.
2
we get an error message “Need kernel filename” and then we can't use qmp cmd to query some information.
3
So, we just throw a warning and then the cpus starts running from address VIRT_FLASH0_BASE.
3
4
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Signed-off-by: Song Gao <gaosong@loongson.cn>
5
Reviewed-by: Song Gao <gaosong@loongson.cn>
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Message-Id: <20241030012359.4040817-1-gaosong@loongson.cn>
6
---
8
---
7
hw/intc/loongarch_pch_pic.c | 15 ++++-----------
9
hw/loongarch/boot.c | 5 ++---
8
1 file changed, 4 insertions(+), 11 deletions(-)
10
1 file changed, 2 insertions(+), 3 deletions(-)
9
11
10
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
12
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
11
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/intc/loongarch_pch_pic.c
14
--- a/hw/loongarch/boot.c
13
+++ b/hw/intc/loongarch_pch_pic.c
15
+++ b/hw/loongarch/boot.c
14
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d)
16
@@ -XXX,XX +XXX,XX @@ static void init_boot_rom(struct loongarch_boot_info *info, void *p)
15
static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
17
static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
16
{
18
{
17
LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev);
19
void *p, *bp;
18
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
20
- int64_t kernel_addr = 0;
19
21
+ int64_t kernel_addr = VIRT_FLASH0_BASE;
20
if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) {
22
LoongArchCPU *lacpu;
21
error_setg(errp, "Invalid 'pic_irq_num'");
23
CPUState *cs;
22
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
24
23
25
@@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info)
24
qdev_init_gpio_out(dev, s->parent_irq, s->irq_num);
26
kernel_addr = load_kernel_info(info);
25
qdev_init_gpio_in(dev, pch_pic_irq_handler, s->irq_num);
27
} else {
26
-}
28
if(!qtest_enabled()) {
27
-
29
- error_report("Need kernel filename\n");
28
-static void loongarch_pch_pic_init(Object *obj)
30
- exit(1);
29
-{
31
+ warn_report("No kernel provided, booting from flash drive.");
30
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(obj);
32
}
31
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
33
}
32
-
33
- memory_region_init_io(&s->iomem32_low, obj,
34
+ memory_region_init_io(&s->iomem32_low, OBJECT(dev),
35
&loongarch_pch_pic_reg32_low_ops,
36
s, PCH_PIC_NAME(.reg32_part1), 0x100);
37
- memory_region_init_io(&s->iomem8, obj, &loongarch_pch_pic_reg8_ops,
38
+ memory_region_init_io(&s->iomem8, OBJECT(dev), &loongarch_pch_pic_reg8_ops,
39
s, PCH_PIC_NAME(.reg8), 0x2a0);
40
- memory_region_init_io(&s->iomem32_high, obj,
41
+ memory_region_init_io(&s->iomem32_high, OBJECT(dev),
42
&loongarch_pch_pic_reg32_high_ops,
43
s, PCH_PIC_NAME(.reg32_part2), 0xc60);
44
sysbus_init_mmio(sbd, &s->iomem32_low);
45
@@ -XXX,XX +XXX,XX @@ static const TypeInfo loongarch_pch_pic_info = {
46
.name = TYPE_LOONGARCH_PCH_PIC,
47
.parent = TYPE_SYS_BUS_DEVICE,
48
.instance_size = sizeof(LoongArchPCHPIC),
49
- .instance_init = loongarch_pch_pic_init,
50
.class_init = loongarch_pch_pic_class_init,
51
};
52
34
53
--
35
--
54
2.43.5
36
2.34.1
37
38
diff view generated by jsdifflib
Deleted patch
1
Set TYPE_LOONGARCH_PIC inherit from TYPE_LOONGARCH_PIC_COMMON object,
2
it shares vmsate and property of TYPE_LOONGARCH_PIC_COMMON, and has
3
its own realize() function.
4
1
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
---
8
hw/intc/loongarch_pch_pic.c | 38 ++++++++++++--------------
9
hw/intc/loongarch_pic_common.c | 32 +++++++++++++++++++++-
10
hw/intc/meson.build | 2 +-
11
include/hw/intc/loongarch_pch_pic.h | 21 +++++++++++---
12
include/hw/intc/loongarch_pic_common.h | 10 +++++++
13
5 files changed, 77 insertions(+), 26 deletions(-)
14
15
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/intc/loongarch_pch_pic.c
18
+++ b/hw/intc/loongarch_pch_pic.c
19
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d)
20
s->int_polarity = 0x0;
21
}
22
23
-#include "loongarch_pic_common.c"
24
-static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
25
+static void loongarch_pic_realize(DeviceState *dev, Error **errp)
26
{
27
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev);
28
- SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
29
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev);
30
+ LoongarchPICClass *lpc = LOONGARCH_PIC_GET_CLASS(dev);
31
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
32
Error *local_err = NULL;
33
34
- loongarch_pic_common_realize(dev, &local_err);
35
+ lpc->parent_realize(dev, &local_err);
36
if (local_err) {
37
error_propagate(errp, local_err);
38
return;
39
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp)
40
41
}
42
43
-static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data)
44
+static void loongarch_pic_class_init(ObjectClass *klass, void *data)
45
{
46
DeviceClass *dc = DEVICE_CLASS(klass);
47
+ LoongarchPICClass *lpc = LOONGARCH_PIC_CLASS(klass);
48
49
- dc->realize = loongarch_pch_pic_realize;
50
device_class_set_legacy_reset(dc, loongarch_pch_pic_reset);
51
- dc->vmsd = &vmstate_loongarch_pic_common;
52
- device_class_set_props(dc, loongarch_pic_common_properties);
53
+ device_class_set_parent_realize(dc, loongarch_pic_realize,
54
+ &lpc->parent_realize);
55
}
56
57
-static const TypeInfo loongarch_pch_pic_info = {
58
- .name = TYPE_LOONGARCH_PCH_PIC,
59
- .parent = TYPE_SYS_BUS_DEVICE,
60
- .instance_size = sizeof(LoongArchPCHPIC),
61
- .class_init = loongarch_pch_pic_class_init,
62
+static const TypeInfo loongarch_pic_types[] = {
63
+ {
64
+ .name = TYPE_LOONGARCH_PIC,
65
+ .parent = TYPE_LOONGARCH_PIC_COMMON,
66
+ .instance_size = sizeof(LoongarchPICState),
67
+ .class_size = sizeof(LoongarchPICClass),
68
+ .class_init = loongarch_pic_class_init,
69
+ }
70
};
71
72
-static void loongarch_pch_pic_register_types(void)
73
-{
74
- type_register_static(&loongarch_pch_pic_info);
75
-}
76
-
77
-type_init(loongarch_pch_pic_register_types)
78
+DEFINE_TYPES(loongarch_pic_types)
79
diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/hw/intc/loongarch_pic_common.c
82
+++ b/hw/intc/loongarch_pic_common.c
83
@@ -XXX,XX +XXX,XX @@
84
* Copyright (C) 2024 Loongson Technology Corporation Limited
85
*/
86
87
+#include "qemu/osdep.h"
88
+#include "qapi/error.h"
89
+#include "hw/intc/loongarch_pic_common.h"
90
+#include "hw/qdev-properties.h"
91
+#include "migration/vmstate.h"
92
+
93
static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
94
{
95
- LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev);
96
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev);
97
98
if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) {
99
error_setg(errp, "Invalid 'pic_irq_num'");
100
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_pic_common = {
101
VMSTATE_END_OF_LIST()
102
}
103
};
104
+
105
+static void loongarch_pic_common_class_init(ObjectClass *klass, void *data)
106
+{
107
+ DeviceClass *dc = DEVICE_CLASS(klass);
108
+ LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_CLASS(klass);
109
+
110
+ device_class_set_parent_realize(dc, loongarch_pic_common_realize,
111
+ &lpcc->parent_realize);
112
+ device_class_set_props(dc, loongarch_pic_common_properties);
113
+ dc->vmsd = &vmstate_loongarch_pic_common;
114
+}
115
+
116
+static const TypeInfo loongarch_pic_common_types[] = {
117
+ {
118
+ .name = TYPE_LOONGARCH_PIC_COMMON,
119
+ .parent = TYPE_SYS_BUS_DEVICE,
120
+ .instance_size = sizeof(LoongArchPICCommonState),
121
+ .class_size = sizeof(LoongArchPICCommonClass),
122
+ .class_init = loongarch_pic_common_class_init,
123
+ .abstract = true,
124
+ }
125
+};
126
+
127
+DEFINE_TYPES(loongarch_pic_common_types)
128
diff --git a/hw/intc/meson.build b/hw/intc/meson.build
129
index XXXXXXX..XXXXXXX 100644
130
--- a/hw/intc/meson.build
131
+++ b/hw/intc/meson.build
132
@@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c'))
133
specific_ss.add(when: 'CONFIG_LOONGSON_IPI_COMMON', if_true: files('loongson_ipi_common.c'))
134
specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.c'))
135
specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c'))
136
-specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c'))
137
+specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c', 'loongarch_pic_common.c'))
138
specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c'))
139
specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c'))
140
diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h
141
index XXXXXXX..XXXXXXX 100644
142
--- a/include/hw/intc/loongarch_pch_pic.h
143
+++ b/include/hw/intc/loongarch_pch_pic.h
144
@@ -XXX,XX +XXX,XX @@
145
146
#include "hw/intc/loongarch_pic_common.h"
147
148
-#define LoongArchPCHPIC LoongArchPICCommonState
149
-#define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic"
150
-#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name
151
-OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC)
152
+#define TYPE_LOONGARCH_PIC "loongarch_pic"
153
+#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PIC#name
154
+OBJECT_DECLARE_TYPE(LoongarchPICState, LoongarchPICClass, LOONGARCH_PIC)
155
+
156
+struct LoongarchPICState {
157
+ LoongArchPICCommonState parent_obj;
158
+};
159
+
160
+struct LoongarchPICClass {
161
+ LoongArchPICCommonClass parent_class;
162
+
163
+ DeviceRealize parent_realize;
164
+};
165
+
166
+#define TYPE_LOONGARCH_PCH_PIC TYPE_LOONGARCH_PIC
167
+typedef struct LoongArchPICCommonState LoongArchPCHPIC;
168
+#define LOONGARCH_PCH_PIC(obj) ((struct LoongArchPICCommonState *)(obj))
169
170
#endif /* HW_LOONGARCH_PCH_PIC_H */
171
diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h
172
index XXXXXXX..XXXXXXX 100644
173
--- a/include/hw/intc/loongarch_pic_common.h
174
+++ b/include/hw/intc/loongarch_pic_common.h
175
@@ -XXX,XX +XXX,XX @@
176
#define POL_LO_START 0x40
177
#define POL_HI_START 0x44
178
179
+#define TYPE_LOONGARCH_PIC_COMMON "loongarch_pic_common"
180
+OBJECT_DECLARE_TYPE(LoongArchPICCommonState,
181
+ LoongArchPICCommonClass, LOONGARCH_PIC_COMMON)
182
+
183
struct LoongArchPICCommonState {
184
SysBusDevice parent_obj;
185
186
@@ -XXX,XX +XXX,XX @@ struct LoongArchPICCommonState {
187
MemoryRegion iomem8;
188
unsigned int irq_num;
189
};
190
+
191
+struct LoongArchPICCommonClass {
192
+ SysBusDeviceClass parent_class;
193
+
194
+ DeviceRealize parent_realize;
195
+};
196
#endif /* HW_LOONGARCH_PIC_COMMON_H */
197
--
198
2.43.5
diff view generated by jsdifflib
1
Add vmstate pre_save and post_load interfaces, which can be used
1
From: Bibo Mao <maobibo@loongson.cn>
2
by pic kvm driver in future.
2
3
With pv steal time supported, VM machine needs get physical address
4
of each vcpu and notify new host during migration. Here two
5
functions kvm_get_stealtime/kvm_set_stealtime, and guest steal time
6
physical address is only updated on KVM_PUT_FULL_STATE stage.
3
7
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
8
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Song Gao <gaosong@loongson.cn>
9
Reviewed-by: Song Gao <gaosong@loongson.cn>
10
Message-Id: <20240930064040.753929-1-maobibo@loongson.cn>
11
Signed-off-by: Song Gao <gaosong@loongson.cn>
6
---
12
---
7
hw/intc/loongarch_pic_common.c | 26 ++++++++++++++++++++++++++
13
target/loongarch/cpu.h | 3 ++
8
include/hw/intc/loongarch_pic_common.h | 2 ++
14
target/loongarch/kvm/kvm.c | 65 ++++++++++++++++++++++++++++++++++++++
9
2 files changed, 28 insertions(+)
15
target/loongarch/machine.c | 6 ++--
16
3 files changed, 72 insertions(+), 2 deletions(-)
10
17
11
diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c
18
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
12
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/intc/loongarch_pic_common.c
20
--- a/target/loongarch/cpu.h
14
+++ b/hw/intc/loongarch_pic_common.c
21
+++ b/target/loongarch/cpu.h
15
@@ -XXX,XX +XXX,XX @@
22
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState {
16
#include "hw/qdev-properties.h"
23
uint64_t CSR_DBG;
17
#include "migration/vmstate.h"
24
uint64_t CSR_DERA;
18
25
uint64_t CSR_DSAVE;
19
+static int loongarch_pic_pre_save(void *opaque)
26
+ struct {
27
+ uint64_t guest_addr;
28
+ } stealtime;
29
30
#ifdef CONFIG_TCG
31
float_status fp_status;
32
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/target/loongarch/kvm/kvm.c
35
+++ b/target/loongarch/kvm/kvm.c
36
@@ -XXX,XX +XXX,XX @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
37
KVM_CAP_LAST_INFO
38
};
39
40
+static int kvm_get_stealtime(CPUState *cs)
20
+{
41
+{
21
+ LoongArchPICCommonState *s = (LoongArchPICCommonState *)opaque;
42
+ CPULoongArchState *env = cpu_env(cs);
22
+ LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_GET_CLASS(s);
43
+ int err;
44
+ struct kvm_device_attr attr = {
45
+ .group = KVM_LOONGARCH_VCPU_PVTIME_CTRL,
46
+ .attr = KVM_LOONGARCH_VCPU_PVTIME_GPA,
47
+ .addr = (uint64_t)&env->stealtime.guest_addr,
48
+ };
23
+
49
+
24
+ if (lpcc->pre_save) {
50
+ err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr);
25
+ return lpcc->pre_save(s);
51
+ if (err) {
52
+ return 0;
53
+ }
54
+
55
+ err = kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, attr);
56
+ if (err) {
57
+ error_report("PVTIME: KVM_GET_DEVICE_ATTR: %s", strerror(errno));
58
+ return err;
26
+ }
59
+ }
27
+
60
+
28
+ return 0;
61
+ return 0;
29
+}
62
+}
30
+
63
+
31
+static int loongarch_pic_post_load(void *opaque, int version_id)
64
+static int kvm_set_stealtime(CPUState *cs)
32
+{
65
+{
33
+ LoongArchPICCommonState *s = (LoongArchPICCommonState *)opaque;
66
+ CPULoongArchState *env = cpu_env(cs);
34
+ LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_GET_CLASS(s);
67
+ int err;
68
+ struct kvm_device_attr attr = {
69
+ .group = KVM_LOONGARCH_VCPU_PVTIME_CTRL,
70
+ .attr = KVM_LOONGARCH_VCPU_PVTIME_GPA,
71
+ .addr = (uint64_t)&env->stealtime.guest_addr,
72
+ };
35
+
73
+
36
+ if (lpcc->post_load) {
74
+ err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr);
37
+ return lpcc->post_load(s, version_id);
75
+ if (err) {
76
+ return 0;
77
+ }
78
+
79
+ err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr);
80
+ if (err) {
81
+ error_report("PVTIME: KVM_SET_DEVICE_ATTR %s with gpa "TARGET_FMT_lx,
82
+ strerror(errno), env->stealtime.guest_addr);
83
+ return err;
38
+ }
84
+ }
39
+
85
+
40
+ return 0;
86
+ return 0;
41
+}
87
+}
42
+
88
+
43
static void loongarch_pic_common_realize(DeviceState *dev, Error **errp)
89
static int kvm_loongarch_get_regs_core(CPUState *cs)
44
{
90
{
45
LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev);
91
int ret = 0;
46
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_pic_common = {
92
@@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs, Error **errp)
47
.name = "loongarch_pch_pic",
93
return ret;
48
.version_id = 1,
94
}
49
.minimum_version_id = 1,
95
50
+ .pre_save = loongarch_pic_pre_save,
96
+ ret = kvm_get_stealtime(cs);
51
+ .post_load = loongarch_pic_post_load,
97
+ if (ret) {
98
+ return ret;
99
+ }
100
+
101
ret = kvm_loongarch_get_mpstate(cs);
102
return ret;
103
}
104
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level, Error **errp)
105
return ret;
106
}
107
108
+ if (level >= KVM_PUT_FULL_STATE) {
109
+ /*
110
+ * only KVM_PUT_FULL_STATE is required, kvm kernel will clear
111
+ * guest_addr for KVM_PUT_RESET_STATE
112
+ */
113
+ ret = kvm_set_stealtime(cs);
114
+ if (ret) {
115
+ return ret;
116
+ }
117
+ }
118
+
119
ret = kvm_loongarch_put_mpstate(cs);
120
return ret;
121
}
122
diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c
123
index XXXXXXX..XXXXXXX 100644
124
--- a/target/loongarch/machine.c
125
+++ b/target/loongarch/machine.c
126
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_tlb = {
127
/* LoongArch CPU state */
128
const VMStateDescription vmstate_loongarch_cpu = {
129
.name = "cpu",
130
- .version_id = 2,
131
- .minimum_version_id = 2,
132
+ .version_id = 3,
133
+ .minimum_version_id = 3,
52
.fields = (const VMStateField[]) {
134
.fields = (const VMStateField[]) {
53
VMSTATE_UINT64(int_mask, LoongArchPICCommonState),
135
VMSTATE_UINTTL_ARRAY(env.gpr, LoongArchCPU, 32),
54
VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState),
136
VMSTATE_UINTTL(env.pc, LoongArchCPU),
55
diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h
137
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_loongarch_cpu = {
56
index XXXXXXX..XXXXXXX 100644
138
VMSTATE_UINT64(env.CSR_DSAVE, LoongArchCPU),
57
--- a/include/hw/intc/loongarch_pic_common.h
139
58
+++ b/include/hw/intc/loongarch_pic_common.h
140
VMSTATE_UINT64(kvm_state_counter, LoongArchCPU),
59
@@ -XXX,XX +XXX,XX @@ struct LoongArchPICCommonClass {
141
+ /* PV steal time */
60
SysBusDeviceClass parent_class;
142
+ VMSTATE_UINT64(env.stealtime.guest_addr, LoongArchCPU),
61
143
62
DeviceRealize parent_realize;
144
VMSTATE_END_OF_LIST()
63
+ int (*pre_save)(LoongArchPICCommonState *s);
145
},
64
+ int (*post_load)(LoongArchPICCommonState *s, int version_id);
65
};
66
#endif /* HW_LOONGARCH_PIC_COMMON_H */
67
--
146
--
68
2.43.5
147
2.34.1
diff view generated by jsdifflib
Deleted patch
1
Remove definition about LoongArchPCHPIC and LOONGARCH_PCH_PIC, and
2
replace them with LoongArchPICCommonState and LOONGARCH_PIC_COMMON
3
separately. Also remove unnecessary header files.
4
1
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
---
8
hw/intc/loongarch_pch_pic.c | 24 ++++++++++--------------
9
hw/loongarch/virt.c | 2 +-
10
include/hw/intc/loongarch_pch_pic.h | 4 ----
11
3 files changed, 11 insertions(+), 19 deletions(-)
12
13
diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/intc/loongarch_pch_pic.c
16
+++ b/hw/intc/loongarch_pch_pic.c
17
@@ -XXX,XX +XXX,XX @@
18
19
#include "qemu/osdep.h"
20
#include "qemu/bitops.h"
21
-#include "hw/sysbus.h"
22
-#include "hw/loongarch/virt.h"
23
-#include "hw/pci-host/ls7a.h"
24
#include "hw/irq.h"
25
#include "hw/intc/loongarch_pch_pic.h"
26
-#include "hw/qdev-properties.h"
27
-#include "migration/vmstate.h"
28
#include "trace.h"
29
#include "qapi/error.h"
30
31
-static void pch_pic_update_irq(LoongArchPCHPIC *s, uint64_t mask, int level)
32
+static void pch_pic_update_irq(LoongArchPICCommonState *s, uint64_t mask,
33
+ int level)
34
{
35
uint64_t val;
36
int irq;
37
@@ -XXX,XX +XXX,XX @@ static void pch_pic_update_irq(LoongArchPCHPIC *s, uint64_t mask, int level)
38
39
static void pch_pic_irq_handler(void *opaque, int irq, int level)
40
{
41
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
42
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
43
uint64_t mask = 1ULL << irq;
44
45
assert(irq < s->irq_num);
46
@@ -XXX,XX +XXX,XX @@ static void pch_pic_irq_handler(void *opaque, int irq, int level)
47
static uint64_t loongarch_pch_pic_low_readw(void *opaque, hwaddr addr,
48
unsigned size)
49
{
50
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
51
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
52
uint64_t val = 0;
53
uint32_t offset = addr & 0xfff;
54
55
@@ -XXX,XX +XXX,XX @@ static uint64_t get_writew_val(uint64_t value, uint32_t target, bool hi)
56
static void loongarch_pch_pic_low_writew(void *opaque, hwaddr addr,
57
uint64_t value, unsigned size)
58
{
59
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
60
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
61
uint32_t offset, old_valid, data = (uint32_t)value;
62
uint64_t old, int_mask;
63
offset = addr & 0xfff;
64
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_low_writew(void *opaque, hwaddr addr,
65
static uint64_t loongarch_pch_pic_high_readw(void *opaque, hwaddr addr,
66
unsigned size)
67
{
68
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
69
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
70
uint64_t val = 0;
71
uint32_t offset = addr & 0xfff;
72
73
@@ -XXX,XX +XXX,XX @@ static uint64_t loongarch_pch_pic_high_readw(void *opaque, hwaddr addr,
74
static void loongarch_pch_pic_high_writew(void *opaque, hwaddr addr,
75
uint64_t value, unsigned size)
76
{
77
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
78
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
79
uint32_t offset, data = (uint32_t)value;
80
offset = addr & 0xfff;
81
82
@@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_high_writew(void *opaque, hwaddr addr,
83
static uint64_t loongarch_pch_pic_readb(void *opaque, hwaddr addr,
84
unsigned size)
85
{
86
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
87
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
88
uint64_t val = 0;
89
uint32_t offset = (addr & 0xfff) + PCH_PIC_ROUTE_ENTRY_OFFSET;
90
int64_t offset_tmp;
91
@@ -XXX,XX +XXX,XX @@ static uint64_t loongarch_pch_pic_readb(void *opaque, hwaddr addr,
92
static void loongarch_pch_pic_writeb(void *opaque, hwaddr addr,
93
uint64_t data, unsigned size)
94
{
95
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque);
96
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque);
97
int32_t offset_tmp;
98
uint32_t offset = (addr & 0xfff) + PCH_PIC_ROUTE_ENTRY_OFFSET;
99
100
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps loongarch_pch_pic_reg8_ops = {
101
102
static void loongarch_pch_pic_reset(DeviceState *d)
103
{
104
- LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(d);
105
+ LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(d);
106
int i;
107
108
s->int_mask = -1;
109
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
110
index XXXXXXX..XXXXXXX 100644
111
--- a/hw/loongarch/virt.c
112
+++ b/hw/loongarch/virt.c
113
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
114
/* Add Extend I/O Interrupt Controller node */
115
fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle);
116
117
- pch_pic = qdev_new(TYPE_LOONGARCH_PCH_PIC);
118
+ pch_pic = qdev_new(TYPE_LOONGARCH_PIC);
119
num = VIRT_PCH_PIC_IRQ_NUM;
120
qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num);
121
d = SYS_BUS_DEVICE(pch_pic);
122
diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h
123
index XXXXXXX..XXXXXXX 100644
124
--- a/include/hw/intc/loongarch_pch_pic.h
125
+++ b/include/hw/intc/loongarch_pch_pic.h
126
@@ -XXX,XX +XXX,XX @@ struct LoongarchPICClass {
127
DeviceRealize parent_realize;
128
};
129
130
-#define TYPE_LOONGARCH_PCH_PIC TYPE_LOONGARCH_PIC
131
-typedef struct LoongArchPICCommonState LoongArchPCHPIC;
132
-#define LOONGARCH_PCH_PIC(obj) ((struct LoongArchPICCommonState *)(obj))
133
-
134
#endif /* HW_LOONGARCH_PCH_PIC_H */
135
--
136
2.43.5
diff view generated by jsdifflib
Deleted patch
1
Add common header file include/hw/intc/loongarch_extioi_common.h, and
2
move some macro definition from include/hw/intc/loongarch_extioi.h to
3
the common header file.
4
1
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Song Gao <gaosong@loongson.cn>
7
---
8
include/hw/intc/loongarch_extioi.h | 50 +------------------
9
include/hw/intc/loongarch_extioi_common.h | 58 +++++++++++++++++++++++
10
2 files changed, 59 insertions(+), 49 deletions(-)
11
create mode 100644 include/hw/intc/loongarch_extioi_common.h
12
13
diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/intc/loongarch_extioi.h
16
+++ b/include/hw/intc/loongarch_extioi.h
17
@@ -XXX,XX +XXX,XX @@
18
* Copyright (C) 2021 Loongson Technology Corporation Limited
19
*/
20
21
-#include "hw/sysbus.h"
22
-#include "hw/loongarch/virt.h"
23
-
24
#ifndef LOONGARCH_EXTIOI_H
25
#define LOONGARCH_EXTIOI_H
26
27
-#define LS3A_INTC_IP 8
28
-#define EXTIOI_IRQS (256)
29
-#define EXTIOI_IRQS_BITMAP_SIZE (256 / 8)
30
-/* irq from EXTIOI is routed to no more than 4 cpus */
31
-#define EXTIOI_CPUS (4)
32
-/* map to ipnum per 32 irqs */
33
-#define EXTIOI_IRQS_IPMAP_SIZE (256 / 32)
34
-#define EXTIOI_IRQS_COREMAP_SIZE 256
35
-#define EXTIOI_IRQS_NODETYPE_COUNT 16
36
-#define EXTIOI_IRQS_GROUP_COUNT 8
37
-
38
-#define APIC_OFFSET 0x400
39
-#define APIC_BASE (0x1000ULL + APIC_OFFSET)
40
-
41
-#define EXTIOI_NODETYPE_START (0x4a0 - APIC_OFFSET)
42
-#define EXTIOI_NODETYPE_END (0x4c0 - APIC_OFFSET)
43
-#define EXTIOI_IPMAP_START (0x4c0 - APIC_OFFSET)
44
-#define EXTIOI_IPMAP_END (0x4c8 - APIC_OFFSET)
45
-#define EXTIOI_ENABLE_START (0x600 - APIC_OFFSET)
46
-#define EXTIOI_ENABLE_END (0x620 - APIC_OFFSET)
47
-#define EXTIOI_BOUNCE_START (0x680 - APIC_OFFSET)
48
-#define EXTIOI_BOUNCE_END (0x6a0 - APIC_OFFSET)
49
-#define EXTIOI_ISR_START (0x700 - APIC_OFFSET)
50
-#define EXTIOI_ISR_END (0x720 - APIC_OFFSET)
51
-#define EXTIOI_COREISR_START (0x800 - APIC_OFFSET)
52
-#define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET)
53
-#define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET)
54
-#define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET)
55
-#define EXTIOI_SIZE 0x800
56
-
57
-#define EXTIOI_VIRT_BASE (0x40000000)
58
-#define EXTIOI_VIRT_SIZE (0x1000)
59
-#define EXTIOI_VIRT_FEATURES (0x0)
60
-#define EXTIOI_HAS_VIRT_EXTENSION (0)
61
-#define EXTIOI_HAS_ENABLE_OPTION (1)
62
-#define EXTIOI_HAS_INT_ENCODE (2)
63
-#define EXTIOI_HAS_CPU_ENCODE (3)
64
-#define EXTIOI_VIRT_HAS_FEATURES (BIT(EXTIOI_HAS_VIRT_EXTENSION) \
65
- | BIT(EXTIOI_HAS_ENABLE_OPTION) \
66
- | BIT(EXTIOI_HAS_CPU_ENCODE))
67
-#define EXTIOI_VIRT_CONFIG (0x4)
68
-#define EXTIOI_ENABLE (1)
69
-#define EXTIOI_ENABLE_INT_ENCODE (2)
70
-#define EXTIOI_ENABLE_CPU_ENCODE (3)
71
-#define EXTIOI_VIRT_COREMAP_START (0x40)
72
-#define EXTIOI_VIRT_COREMAP_END (0x240)
73
+#include "hw/intc/loongarch_extioi_common.h"
74
75
typedef struct ExtIOICore {
76
uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
77
diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h
78
new file mode 100644
79
index XXXXXXX..XXXXXXX
80
--- /dev/null
81
+++ b/include/hw/intc/loongarch_extioi_common.h
82
@@ -XXX,XX +XXX,XX @@
83
+/* SPDX-License-Identifier: GPL-2.0-or-later */
84
+/*
85
+ * LoongArch 3A5000 ext interrupt controller definitions
86
+ * Copyright (C) 2024 Loongson Technology Corporation Limited
87
+ */
88
+
89
+#ifndef LOONGARCH_EXTIOI_COMMON_H
90
+#define LOONGARCH_EXTIOI_COMMON_H
91
+
92
+#include "hw/sysbus.h"
93
+#include "hw/loongarch/virt.h"
94
+
95
+#define LS3A_INTC_IP 8
96
+#define EXTIOI_IRQS (256)
97
+#define EXTIOI_IRQS_BITMAP_SIZE (256 / 8)
98
+/* irq from EXTIOI is routed to no more than 4 cpus */
99
+#define EXTIOI_CPUS (4)
100
+/* map to ipnum per 32 irqs */
101
+#define EXTIOI_IRQS_IPMAP_SIZE (256 / 32)
102
+#define EXTIOI_IRQS_COREMAP_SIZE 256
103
+#define EXTIOI_IRQS_NODETYPE_COUNT 16
104
+#define EXTIOI_IRQS_GROUP_COUNT 8
105
+
106
+#define APIC_OFFSET 0x400
107
+#define APIC_BASE (0x1000ULL + APIC_OFFSET)
108
+#define EXTIOI_NODETYPE_START (0x4a0 - APIC_OFFSET)
109
+#define EXTIOI_NODETYPE_END (0x4c0 - APIC_OFFSET)
110
+#define EXTIOI_IPMAP_START (0x4c0 - APIC_OFFSET)
111
+#define EXTIOI_IPMAP_END (0x4c8 - APIC_OFFSET)
112
+#define EXTIOI_ENABLE_START (0x600 - APIC_OFFSET)
113
+#define EXTIOI_ENABLE_END (0x620 - APIC_OFFSET)
114
+#define EXTIOI_BOUNCE_START (0x680 - APIC_OFFSET)
115
+#define EXTIOI_BOUNCE_END (0x6a0 - APIC_OFFSET)
116
+#define EXTIOI_ISR_START (0x700 - APIC_OFFSET)
117
+#define EXTIOI_ISR_END (0x720 - APIC_OFFSET)
118
+#define EXTIOI_COREISR_START (0x800 - APIC_OFFSET)
119
+#define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET)
120
+#define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET)
121
+#define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET)
122
+#define EXTIOI_SIZE 0x800
123
+
124
+#define EXTIOI_VIRT_BASE (0x40000000)
125
+#define EXTIOI_VIRT_SIZE (0x1000)
126
+#define EXTIOI_VIRT_FEATURES (0x0)
127
+#define EXTIOI_HAS_VIRT_EXTENSION (0)
128
+#define EXTIOI_HAS_ENABLE_OPTION (1)
129
+#define EXTIOI_HAS_INT_ENCODE (2)
130
+#define EXTIOI_HAS_CPU_ENCODE (3)
131
+#define EXTIOI_VIRT_HAS_FEATURES (BIT(EXTIOI_HAS_VIRT_EXTENSION) \
132
+ | BIT(EXTIOI_HAS_ENABLE_OPTION) \
133
+ | BIT(EXTIOI_HAS_CPU_ENCODE))
134
+#define EXTIOI_VIRT_CONFIG (0x4)
135
+#define EXTIOI_ENABLE (1)
136
+#define EXTIOI_ENABLE_INT_ENCODE (2)
137
+#define EXTIOI_ENABLE_CPU_ENCODE (3)
138
+#define EXTIOI_VIRT_COREMAP_START (0x40)
139
+#define EXTIOI_VIRT_COREMAP_END (0x240)
140
+#endif /* LOONGARCH_EXTIOI_H */
141
--
142
2.43.5
diff view generated by jsdifflib