1 | The following changes since commit 34eac35f893664eb8545b98142e23d9954722766: | 1 | The following changes since commit a5ba0a7e4e150d1350a041f0d0ef9ca6c8d7c307: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-riscv-to-apply-20240110' of https://github.com/alistair23/qemu into staging (2024-01-10 11:41:56 +0000) | 3 | Merge tag 'pull-aspeed-20241211' of https://github.com/legoater/qemu into staging (2024-12-11 15:16:47 +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/gaosong/qemu.git tags/pull-loongarch-20240111 | 7 | https://gitlab.com/bibo-mao/qemu.git pull-loongarch-20241213 |
8 | 8 | ||
9 | for you to fetch changes up to 428a6ef4396aa910c86e16c1e4409e3927a3698e: | 9 | for you to fetch changes up to 78aa256571aa06f32001bd80635a1858187c609b: |
10 | 10 | ||
11 | hw/intc/loongarch_extioi: Add vmstate post_load support (2024-01-11 19:22:47 +0800) | 11 | hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic (2024-12-13 14:39:39 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | pull-loongarch-20240111 | 14 | pull-loongarch-20241213 |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Bibo Mao (4): | 17 | Bibo Mao (8): |
18 | hw/intc/loongarch_ipi: Use MemTxAttrs interface for ipi ops | 18 | include: Add loongarch_pic_common header file |
19 | hw/loongarch/virt: Set iocsr address space per-board rather than percpu | 19 | include: Move struct LoongArchPCHPIC to loongarch_pic_common header file |
20 | hw/intc/loongarch_extioi: Add dynamic cpu number support | 20 | hw/intc/loongarch_pch: Merge instance_init() into realize() |
21 | hw/intc/loongarch_extioi: Add vmstate post_load support | 21 | hw/intc/loongarch_pch: Rename LoongArchPCHPIC with LoongArchPICCommonState |
22 | hw/intc/loongarch_pch: Move some functions to file loongarch_pic_common | ||
23 | hw/intc/loongarch_pch: Inherit from loongarch_pic_common | ||
24 | hw/intc/loongarch_pch: Add pre_save and post_load interfaces | ||
25 | hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic | ||
22 | 26 | ||
23 | Tianrui Zhao (10): | 27 | hw/intc/loongarch_pch_pic.c | 106 +++++++++++---------------------- |
24 | linux-headers: Synchronize linux headers from linux v6.7.0-rc8 | 28 | hw/intc/loongarch_pic_common.c | 97 ++++++++++++++++++++++++++++++ |
25 | target/loongarch: Define some kvm_arch interfaces | 29 | hw/intc/meson.build | 2 +- |
26 | target/loongarch: Supplement vcpu env initial when vcpu reset | 30 | hw/loongarch/virt.c | 2 +- |
27 | target/loongarch: Implement kvm get/set registers | 31 | include/hw/intc/loongarch_pch_pic.h | 70 +++++----------------- |
28 | target/loongarch: Implement kvm_arch_init function | 32 | include/hw/intc/loongarch_pic_common.h | 82 +++++++++++++++++++++++++ |
29 | target/loongarch: Implement kvm_arch_init_vcpu | 33 | 6 files changed, 230 insertions(+), 129 deletions(-) |
30 | target/loongarch: Implement kvm_arch_handle_exit | 34 | create mode 100644 hw/intc/loongarch_pic_common.c |
31 | target/loongarch: Restrict TCG-specific code | 35 | create mode 100644 include/hw/intc/loongarch_pic_common.h |
32 | target/loongarch: Implement set vcpu intr for kvm | ||
33 | target/loongarch: Add loongarch kvm into meson build | ||
34 | |||
35 | hw/intc/loongarch_extioi.c | 230 ++++++---- | ||
36 | hw/intc/loongarch_ipi.c | 191 +++++---- | ||
37 | hw/loongarch/virt.c | 94 +++-- | ||
38 | include/hw/intc/loongarch_extioi.h | 12 +- | ||
39 | include/hw/intc/loongarch_ipi.h | 3 +- | ||
40 | include/hw/loongarch/virt.h | 3 + | ||
41 | include/standard-headers/linux/fuse.h | 10 +- | ||
42 | meson.build | 3 + | ||
43 | target/loongarch/cpu.c | 90 ++-- | ||
44 | target/loongarch/cpu.h | 9 +- | ||
45 | target/loongarch/internals.h | 5 +- | ||
46 | target/loongarch/kvm/kvm.c | 768 ++++++++++++++++++++++++++++++++++ | ||
47 | target/loongarch/kvm/kvm_loongarch.h | 16 + | ||
48 | target/loongarch/kvm/meson.build | 1 + | ||
49 | target/loongarch/meson.build | 1 + | ||
50 | target/loongarch/tcg/iocsr_helper.c | 16 +- | ||
51 | target/loongarch/trace-events | 15 + | ||
52 | target/loongarch/trace.h | 1 + | ||
53 | 18 files changed, 1210 insertions(+), 258 deletions(-) | ||
54 | create mode 100644 target/loongarch/kvm/kvm.c | ||
55 | create mode 100644 target/loongarch/kvm/kvm_loongarch.h | ||
56 | create mode 100644 target/loongarch/kvm/meson.build | ||
57 | create mode 100644 target/loongarch/trace-events | ||
58 | create mode 100644 target/loongarch/trace.h | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | ||
2 | 1 | ||
3 | Use the scripts/update-linux-headers.sh to synchronize linux | ||
4 | headers from linux v6.7.0-rc8. We mainly want to add the | ||
5 | loongarch linux headers and then add the loongarch kvm support | ||
6 | based on it. | ||
7 | |||
8 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | ||
9 | Acked-by: Song Gao <gaosong@loongson.cn> | ||
10 | Message-Id: <20240105075804.1228596-2-zhaotianrui@loongson.cn> | ||
11 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
12 | --- | ||
13 | include/standard-headers/linux/fuse.h | 10 ++++++---- | ||
14 | 1 file changed, 6 insertions(+), 4 deletions(-) | ||
15 | |||
16 | diff --git a/include/standard-headers/linux/fuse.h b/include/standard-headers/linux/fuse.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/standard-headers/linux/fuse.h | ||
19 | +++ b/include/standard-headers/linux/fuse.h | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | * - add FUSE_HAS_EXPIRE_ONLY | ||
22 | * | ||
23 | * 7.39 | ||
24 | - * - add FUSE_DIRECT_IO_RELAX | ||
25 | + * - add FUSE_DIRECT_IO_ALLOW_MMAP | ||
26 | * - add FUSE_STATX and related structures | ||
27 | */ | ||
28 | |||
29 | @@ -XXX,XX +XXX,XX @@ struct fuse_file_lock { | ||
30 | * FUSE_CREATE_SUPP_GROUP: add supplementary group info to create, mkdir, | ||
31 | * symlink and mknod (single group that matches parent) | ||
32 | * FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation | ||
33 | - * FUSE_DIRECT_IO_RELAX: relax restrictions in FOPEN_DIRECT_IO mode, for now | ||
34 | - * allow shared mmap | ||
35 | + * FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode. | ||
36 | */ | ||
37 | #define FUSE_ASYNC_READ (1 << 0) | ||
38 | #define FUSE_POSIX_LOCKS (1 << 1) | ||
39 | @@ -XXX,XX +XXX,XX @@ struct fuse_file_lock { | ||
40 | #define FUSE_HAS_INODE_DAX (1ULL << 33) | ||
41 | #define FUSE_CREATE_SUPP_GROUP (1ULL << 34) | ||
42 | #define FUSE_HAS_EXPIRE_ONLY (1ULL << 35) | ||
43 | -#define FUSE_DIRECT_IO_RELAX (1ULL << 36) | ||
44 | +#define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36) | ||
45 | + | ||
46 | +/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */ | ||
47 | +#define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP | ||
48 | |||
49 | /** | ||
50 | * CUSE INIT request/reply flags | ||
51 | -- | ||
52 | 2.25.1 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 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. | ||
2 | 4 | ||
3 | Add kvm.c into meson.build to compile it when kvm | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | is configed. Meanwhile in meson.build, we set the | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | kvm_targets to loongarch64-softmmu when the cpu is | 7 | --- |
6 | loongarch. And fix the compiling error when config | 8 | include/hw/intc/loongarch_pch_pic.h | 36 +++------------------- |
7 | is enable-kvm,disable-tcg. | 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 | ||
8 | 12 | ||
9 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 13 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h |
10 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
13 | Message-Id: <20240105075804.1228596-10-zhaotianrui@loongson.cn> | ||
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
15 | --- | ||
16 | meson.build | 2 ++ | ||
17 | target/loongarch/kvm/meson.build | 1 + | ||
18 | target/loongarch/meson.build | 1 + | ||
19 | 3 files changed, 4 insertions(+) | ||
20 | create mode 100644 target/loongarch/kvm/meson.build | ||
21 | |||
22 | diff --git a/meson.build b/meson.build | ||
23 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/meson.build | 15 | --- a/include/hw/intc/loongarch_pch_pic.h |
25 | +++ b/meson.build | 16 | +++ b/include/hw/intc/loongarch_pch_pic.h |
26 | @@ -XXX,XX +XXX,XX @@ elif cpu in ['riscv32'] | 17 | @@ -XXX,XX +XXX,XX @@ |
27 | kvm_targets = ['riscv32-softmmu'] | 18 | * Copyright (c) 2021 Loongson Technology Corporation Limited |
28 | elif cpu in ['riscv64'] | 19 | */ |
29 | kvm_targets = ['riscv64-softmmu'] | 20 | |
30 | +elif cpu in ['loongarch64'] | 21 | -#include "hw/sysbus.h" |
31 | + kvm_targets = ['loongarch64-softmmu'] | 22 | +#ifndef HW_LOONGARCH_PCH_PIC_H |
32 | else | 23 | +#define HW_LOONGARCH_PCH_PIC_H |
33 | kvm_targets = [] | 24 | + |
34 | endif | 25 | +#include "hw/intc/loongarch_pic_common.h" |
35 | diff --git a/target/loongarch/kvm/meson.build b/target/loongarch/kvm/meson.build | 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 | ||
36 | new file mode 100644 | 70 | new file mode 100644 |
37 | index XXXXXXX..XXXXXXX | 71 | index XXXXXXX..XXXXXXX |
38 | --- /dev/null | 72 | --- /dev/null |
39 | +++ b/target/loongarch/kvm/meson.build | 73 | +++ b/include/hw/intc/loongarch_pic_common.h |
40 | @@ -0,0 +1 @@ | 74 | @@ -XXX,XX +XXX,XX @@ |
41 | +loongarch_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) | 75 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
42 | diff --git a/target/loongarch/meson.build b/target/loongarch/meson.build | 76 | +/* |
43 | index XXXXXXX..XXXXXXX 100644 | 77 | + * LoongArch 7A1000 I/O interrupt controller definitions |
44 | --- a/target/loongarch/meson.build | 78 | + * Copyright (c) 2024 Loongson Technology Corporation Limited |
45 | +++ b/target/loongarch/meson.build | 79 | + */ |
46 | @@ -XXX,XX +XXX,XX @@ subdir('tcg') | 80 | + |
47 | 81 | +#ifndef HW_LOONGARCH_PIC_COMMON_H | |
48 | target_arch += {'loongarch': loongarch_ss} | 82 | +#define HW_LOONGARCH_PIC_COMMON_H |
49 | target_system_arch += {'loongarch': loongarch_system_ss} | 83 | + |
50 | +subdir('kvm') | 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 */ | ||
51 | -- | 117 | -- |
52 | 2.25.1 | 118 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 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. | ||
2 | 4 | ||
3 | In preparation of supporting KVM in the next commit. | 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(-) | ||
4 | 11 | ||
5 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 12 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h |
6 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
7 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
8 | Message-ID: <20240105075804.1228596-9-zhaotianrui@loongson.cn> | ||
9 | [PMD: Split from bigger patch, part 1] | ||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
11 | Message-Id: <20240110094152.52138-1-philmd@linaro.org> | ||
12 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
13 | --- | ||
14 | target/loongarch/cpu.c | 30 +++++++++++++++++++++--------- | ||
15 | 1 file changed, 21 insertions(+), 9 deletions(-) | ||
16 | |||
17 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/loongarch/cpu.c | 14 | --- a/include/hw/intc/loongarch_pch_pic.h |
20 | +++ b/target/loongarch/cpu.c | 15 | +++ b/include/hw/intc/loongarch_pch_pic.h |
21 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -XXX,XX +XXX,XX @@ |
22 | #include "qapi/error.h" | 17 | |
23 | #include "qemu/module.h" | 18 | #include "hw/intc/loongarch_pic_common.h" |
24 | #include "sysemu/qtest.h" | 19 | |
25 | -#include "exec/cpu_ldst.h" | 20 | +#define LoongArchPCHPIC LoongArchPICCommonState |
26 | +#include "sysemu/tcg.h" | 21 | #define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic" |
27 | #include "exec/exec-all.h" | 22 | #define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name |
28 | #include "cpu.h" | 23 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC) |
29 | #include "internals.h" | 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 | ||
30 | @@ -XXX,XX +XXX,XX @@ | 56 | @@ -XXX,XX +XXX,XX @@ |
31 | #ifndef CONFIG_USER_ONLY | 57 | #define STATUS_HI_START 0x4 |
32 | #include "sysemu/reset.h" | 58 | #define POL_LO_START 0x40 |
33 | #endif | 59 | #define POL_HI_START 0x44 |
34 | -#include "tcg/tcg.h" | 60 | + |
35 | #include "vec.h" | 61 | +struct LoongArchPICCommonState { |
36 | +#ifdef CONFIG_TCG | 62 | + SysBusDevice parent_obj; |
37 | +#include "exec/cpu_ldst.h" | 63 | + |
38 | +#include "tcg/tcg.h" | 64 | + qemu_irq parent_irq[64]; |
39 | +#endif | 65 | + uint64_t int_mask; /* 0x020 interrupt mask register */ |
40 | 66 | + uint64_t htmsi_en; /* 0x040 1=msi */ | |
41 | const char * const regnames[32] = { | 67 | + uint64_t intedge; /* 0x060 edge=1 level=0 */ |
42 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | 68 | + uint64_t intclr; /* 0x080 clean edge int, set 1 clean, 0 noused */ |
43 | @@ -XXX,XX +XXX,XX @@ void loongarch_cpu_set_irq(void *opaque, int irq, int level) | 69 | + uint64_t auto_crtl0; /* 0x0c0 */ |
44 | return; | 70 | + uint64_t auto_crtl1; /* 0x0e0 */ |
45 | } | 71 | + uint64_t last_intirr; /* edge detection */ |
46 | 72 | + uint64_t intirr; /* 0x380 interrupt request register */ | |
47 | - env->CSR_ESTAT = deposit64(env->CSR_ESTAT, irq, 1, level != 0); | 73 | + uint64_t intisr; /* 0x3a0 interrupt service register */ |
48 | - | 74 | + /* |
49 | - if (FIELD_EX64(env->CSR_ESTAT, CSR_ESTAT, IS)) { | 75 | + * 0x3e0 interrupt level polarity selection |
50 | - cpu_interrupt(cs, CPU_INTERRUPT_HARD); | 76 | + * register 0 for high level trigger |
51 | - } else { | 77 | + */ |
52 | - cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); | 78 | + uint64_t int_polarity; |
53 | + if (tcg_enabled()) { | 79 | + |
54 | + env->CSR_ESTAT = deposit64(env->CSR_ESTAT, irq, 1, level != 0); | 80 | + uint8_t route_entry[64]; /* 0x100 - 0x138 */ |
55 | + if (FIELD_EX64(env->CSR_ESTAT, CSR_ESTAT, IS)) { | 81 | + uint8_t htmsi_vector[64]; /* 0x200 - 0x238 */ |
56 | + cpu_interrupt(cs, CPU_INTERRUPT_HARD); | 82 | + |
57 | + } else { | 83 | + MemoryRegion iomem32_low; |
58 | + cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); | 84 | + MemoryRegion iomem32_high; |
59 | + } | 85 | + MemoryRegion iomem8; |
60 | } | 86 | + unsigned int irq_num; |
61 | } | 87 | +}; |
62 | 88 | #endif /* HW_LOONGARCH_PIC_COMMON_H */ | |
63 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env) | ||
64 | |||
65 | return (pending & status) != 0; | ||
66 | } | ||
67 | +#endif | ||
68 | |||
69 | +#ifdef CONFIG_TCG | ||
70 | +#ifndef CONFIG_USER_ONLY | ||
71 | static void loongarch_cpu_do_interrupt(CPUState *cs) | ||
72 | { | ||
73 | LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
74 | @@ -XXX,XX +XXX,XX @@ static bool loongarch_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
75 | } | ||
76 | #endif | ||
77 | |||
78 | -#ifdef CONFIG_TCG | ||
79 | static void loongarch_cpu_synchronize_from_tb(CPUState *cs, | ||
80 | const TranslationBlock *tb) | ||
81 | { | ||
82 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_reset_hold(Object *obj) | ||
83 | } | ||
84 | #endif | ||
85 | |||
86 | +#ifdef CONFIG_TCG | ||
87 | restore_fp_status(env); | ||
88 | +#endif | ||
89 | cs->exception_index = -1; | ||
90 | } | ||
91 | |||
92 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_init(Object *obj) | ||
93 | CPULoongArchState *env = &cpu->env; | ||
94 | |||
95 | qdev_init_gpio_in(DEVICE(cpu), loongarch_cpu_set_irq, N_IRQS); | ||
96 | +#ifdef CONFIG_TCG | ||
97 | timer_init_ns(&cpu->timer, QEMU_CLOCK_VIRTUAL, | ||
98 | &loongarch_constant_timer_cb, cpu); | ||
99 | +#endif | ||
100 | memory_region_init_io(&env->system_iocsr, OBJECT(cpu), NULL, | ||
101 | env, "iocsr", UINT64_MAX); | ||
102 | address_space_init(&env->address_space_iocsr, &env->system_iocsr, "IOCSR"); | ||
103 | @@ -XXX,XX +XXX,XX @@ static struct TCGCPUOps loongarch_tcg_ops = { | ||
104 | #include "hw/core/sysemu-cpu-ops.h" | ||
105 | |||
106 | static const struct SysemuCPUOps loongarch_sysemu_ops = { | ||
107 | +#ifdef CONFIG_TCG | ||
108 | .get_phys_page_debug = loongarch_cpu_get_phys_page_debug, | ||
109 | +#endif | ||
110 | }; | ||
111 | |||
112 | static int64_t loongarch_cpu_get_arch_id(CPUState *cs) | ||
113 | -- | 89 | -- |
114 | 2.25.1 | 90 | 2.43.5 |
115 | |||
116 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | Memory region is created in instance_init(), merge it into function |
---|---|---|---|
2 | realize(). There is no special class_init() for loongarch_pch object. | ||
2 | 3 | ||
3 | Implement the kvm_arch_init of loongarch, in the function, the | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | KVM_CAP_MP_STATE cap is checked by kvm ioctl. | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
6 | --- | ||
7 | hw/intc/loongarch_pch_pic.c | 15 ++++----------- | ||
8 | 1 file changed, 4 insertions(+), 11 deletions(-) | ||
5 | 9 | ||
6 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 10 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
7 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
10 | Message-Id: <20240105075804.1228596-6-zhaotianrui@loongson.cn> | ||
11 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
12 | --- | ||
13 | target/loongarch/kvm/kvm.c | 1 + | ||
14 | 1 file changed, 1 insertion(+) | ||
15 | |||
16 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/loongarch/kvm/kvm.c | 12 | --- a/hw/intc/loongarch_pch_pic.c |
19 | +++ b/target/loongarch/kvm/kvm.c | 13 | +++ b/hw/intc/loongarch_pch_pic.c |
20 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_default_type(MachineState *ms) | 14 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
21 | 15 | static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | |
22 | int kvm_arch_init(MachineState *ms, KVMState *s) | ||
23 | { | 16 | { |
24 | + cap_has_mp_state = kvm_check_extension(s, KVM_CAP_MP_STATE); | 17 | LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); |
25 | return 0; | 18 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
26 | } | 19 | |
20 | if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { | ||
21 | error_setg(errp, "Invalid 'pic_irq_num'"); | ||
22 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
23 | |||
24 | qdev_init_gpio_out(dev, s->parent_irq, s->irq_num); | ||
25 | qdev_init_gpio_in(dev, pch_pic_irq_handler, s->irq_num); | ||
26 | -} | ||
27 | - | ||
28 | -static void loongarch_pch_pic_init(Object *obj) | ||
29 | -{ | ||
30 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(obj); | ||
31 | - SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
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 | }; | ||
27 | 52 | ||
28 | -- | 53 | -- |
29 | 2.25.1 | 54 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | With pic vmstate, rename structure name vmstate_loongarch_pch_pic with |
---|---|---|---|
2 | vmstate_loongarch_pic_common, and with pic property rename | ||
3 | loongarch_pch_pic_properties with loongarch_pic_common_properties. | ||
2 | 4 | ||
3 | Implement kvm_arch_init_vcpu interface for loongarch, | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | in this function, we register VM change state handler. | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | And when VM state changes to running, the counter value | 7 | --- |
6 | should be put into kvm to keep consistent with kvm, | 8 | hw/intc/loongarch_pch_pic.c | 52 +++++++++++++++++++++++-------------- |
7 | and when state change to stop, counter value should be | 9 | 1 file changed, 32 insertions(+), 20 deletions(-) |
8 | refreshed from kvm. | ||
9 | 10 | ||
10 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 11 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
11 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
12 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
13 | Message-Id: <20240105075804.1228596-7-zhaotianrui@loongson.cn> | ||
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
15 | --- | ||
16 | target/loongarch/cpu.h | 2 ++ | ||
17 | target/loongarch/kvm/kvm.c | 23 +++++++++++++++++++++++ | ||
18 | target/loongarch/trace-events | 2 ++ | ||
19 | 3 files changed, 27 insertions(+) | ||
20 | |||
21 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/loongarch/cpu.h | 13 | --- a/hw/intc/loongarch_pch_pic.c |
24 | +++ b/target/loongarch/cpu.h | 14 | +++ b/hw/intc/loongarch_pch_pic.c |
25 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { | 15 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
26 | 16 | s->int_polarity = 0x0; | |
27 | /* 'compatible' string for this CPU for Linux device trees */ | ||
28 | const char *dtb_compatible; | ||
29 | + /* used by KVM_REG_LOONGARCH_COUNTER ioctl to access guest time counters */ | ||
30 | + uint64_t kvm_state_counter; | ||
31 | }; | ||
32 | |||
33 | /** | ||
34 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/loongarch/kvm/kvm.c | ||
37 | +++ b/target/loongarch/kvm/kvm.c | ||
38 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level) | ||
39 | return ret; | ||
40 | } | 17 | } |
41 | 18 | ||
42 | +static void kvm_loongarch_vm_stage_change(void *opaque, bool running, | 19 | +static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
43 | + RunState state) | ||
44 | +{ | 20 | +{ |
45 | + int ret; | 21 | + LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); |
46 | + CPUState *cs = opaque; | ||
47 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
48 | + | 22 | + |
49 | + if (running) { | 23 | + if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
50 | + ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_COUNTER, | 24 | + error_setg(errp, "Invalid 'pic_irq_num'"); |
51 | + &cpu->kvm_state_counter); | 25 | + return; |
52 | + if (ret < 0) { | ||
53 | + trace_kvm_failed_put_counter(strerror(errno)); | ||
54 | + } | ||
55 | + } else { | ||
56 | + ret = kvm_get_one_reg(cs, KVM_REG_LOONGARCH_COUNTER, | ||
57 | + &cpu->kvm_state_counter); | ||
58 | + if (ret < 0) { | ||
59 | + trace_kvm_failed_get_counter(strerror(errno)); | ||
60 | + } | ||
61 | + } | 26 | + } |
62 | +} | 27 | +} |
63 | + | 28 | + |
64 | int kvm_arch_init_vcpu(CPUState *cs) | 29 | static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) |
65 | { | 30 | { |
66 | + qemu_add_vm_change_state_handler(kvm_loongarch_vm_stage_change, cs); | 31 | LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); |
67 | return 0; | 32 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
33 | + Error *local_err = NULL; | ||
34 | |||
35 | - if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { | ||
36 | - error_setg(errp, "Invalid 'pic_irq_num'"); | ||
37 | + loongarch_pic_common_realize(dev, &local_err); | ||
38 | + if (local_err) { | ||
39 | + error_propagate(errp, local_err); | ||
40 | return; | ||
41 | } | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
44 | |||
68 | } | 45 | } |
69 | 46 | ||
70 | diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events | 47 | -static Property loongarch_pch_pic_properties[] = { |
71 | index XXXXXXX..XXXXXXX 100644 | 48 | - DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPCHPIC, irq_num, 0), |
72 | --- a/target/loongarch/trace-events | 49 | +static Property loongarch_pic_common_properties[] = { |
73 | +++ b/target/loongarch/trace-events | 50 | + DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0), |
74 | @@ -XXX,XX +XXX,XX @@ kvm_failed_get_fpu(const char *msg) "Failed to get fpu from KVM: %s" | 51 | DEFINE_PROP_END_OF_LIST(), |
75 | kvm_failed_put_fpu(const char *msg) "Failed to put fpu into KVM: %s" | 52 | }; |
76 | kvm_failed_get_mpstate(const char *msg) "Failed to get mp_state from KVM: %s" | 53 | |
77 | kvm_failed_put_mpstate(const char *msg) "Failed to put mp_state into KVM: %s" | 54 | -static const VMStateDescription vmstate_loongarch_pch_pic = { |
78 | +kvm_failed_get_counter(const char *msg) "Failed to get counter from KVM: %s" | 55 | - .name = TYPE_LOONGARCH_PCH_PIC, |
79 | +kvm_failed_put_counter(const char *msg) "Failed to put counter into KVM: %s" | 56 | +static const VMStateDescription vmstate_loongarch_pic_common = { |
80 | kvm_failed_get_cpucfg(const char *msg) "Failed to get cpucfg from KVM: %s" | 57 | + .name = "loongarch_pch_pic", |
81 | kvm_failed_put_cpucfg(const char *msg) "Failed to put cpucfg into KVM: %s" | 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 = { | ||
82 | -- | 99 | -- |
83 | 2.25.1 | 100 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | Move some common functions to file loongarch_pic_common.c, the common |
---|---|---|---|
2 | functions include loongarch_pic_common_realize(), property structure | ||
3 | loongarch_pic_common_properties and vmstate structure | ||
4 | vmstate_loongarch_pic_common. | ||
2 | 5 | ||
3 | Implement loongarch kvm set vcpu interrupt interface, | 6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | when a irq is set in vcpu, we use the KVM_INTERRUPT | 7 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | ioctl to set intr into kvm. | 8 | --- |
9 | hw/intc/loongarch_pch_pic.c | 37 +----------------------------- | ||
10 | hw/intc/loongarch_pic_common.c | 41 ++++++++++++++++++++++++++++++++++ | ||
11 | 2 files changed, 42 insertions(+), 36 deletions(-) | ||
12 | create mode 100644 hw/intc/loongarch_pic_common.c | ||
6 | 13 | ||
7 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 14 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
8 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
9 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
10 | Message-ID: <20240105075804.1228596-9-zhaotianrui@loongson.cn> | ||
11 | [PMD: Split from bigger patch, part 2] | ||
12 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
13 | Message-Id: <20240110094152.52138-2-philmd@linaro.org> | ||
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
15 | --- | ||
16 | target/loongarch/cpu.c | 9 ++++++++- | ||
17 | target/loongarch/kvm/kvm.c | 15 +++++++++++++++ | ||
18 | target/loongarch/kvm/kvm_loongarch.h | 16 ++++++++++++++++ | ||
19 | target/loongarch/trace-events | 1 + | ||
20 | 4 files changed, 40 insertions(+), 1 deletion(-) | ||
21 | create mode 100644 target/loongarch/kvm/kvm_loongarch.h | ||
22 | |||
23 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/loongarch/cpu.c | 16 | --- a/hw/intc/loongarch_pch_pic.c |
26 | +++ b/target/loongarch/cpu.c | 17 | +++ b/hw/intc/loongarch_pch_pic.c |
27 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
28 | #include "qemu/module.h" | 19 | s->int_polarity = 0x0; |
29 | #include "sysemu/qtest.h" | ||
30 | #include "sysemu/tcg.h" | ||
31 | +#include "sysemu/kvm.h" | ||
32 | +#include "kvm/kvm_loongarch.h" | ||
33 | #include "exec/exec-all.h" | ||
34 | #include "cpu.h" | ||
35 | #include "internals.h" | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #include "sysemu/reset.h" | ||
38 | #endif | ||
39 | #include "vec.h" | ||
40 | +#ifdef CONFIG_KVM | ||
41 | +#include <linux/kvm.h> | ||
42 | +#endif | ||
43 | #ifdef CONFIG_TCG | ||
44 | #include "exec/cpu_ldst.h" | ||
45 | #include "tcg/tcg.h" | ||
46 | @@ -XXX,XX +XXX,XX @@ void loongarch_cpu_set_irq(void *opaque, int irq, int level) | ||
47 | return; | ||
48 | } | ||
49 | |||
50 | - if (tcg_enabled()) { | ||
51 | + if (kvm_enabled()) { | ||
52 | + kvm_loongarch_set_interrupt(cpu, irq, level); | ||
53 | + } else if (tcg_enabled()) { | ||
54 | env->CSR_ESTAT = deposit64(env->CSR_ESTAT, irq, 1, level != 0); | ||
55 | if (FIELD_EX64(env->CSR_ESTAT, CSR_ESTAT, IS)) { | ||
56 | cpu_interrupt(cs, CPU_INTERRUPT_HARD); | ||
57 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/target/loongarch/kvm/kvm.c | ||
60 | +++ b/target/loongarch/kvm/kvm.c | ||
61 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
62 | return ret; | ||
63 | } | 20 | } |
64 | 21 | ||
65 | +int kvm_loongarch_set_interrupt(LoongArchCPU *cpu, int irq, int level) | 22 | -static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
66 | +{ | 23 | -{ |
67 | + struct kvm_interrupt intr; | 24 | - LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); |
68 | + CPUState *cs = CPU(cpu); | 25 | - |
69 | + | 26 | - if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
70 | + if (level) { | 27 | - error_setg(errp, "Invalid 'pic_irq_num'"); |
71 | + intr.irq = irq; | 28 | - return; |
72 | + } else { | 29 | - } |
73 | + intr.irq = -irq; | 30 | -} |
74 | + } | 31 | - |
75 | + | 32 | +#include "loongarch_pic_common.c" |
76 | + trace_kvm_set_intr(irq, level); | 33 | static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) |
77 | + return kvm_vcpu_ioctl(cs, KVM_INTERRUPT, &intr); | ||
78 | +} | ||
79 | + | ||
80 | void kvm_arch_accel_class_init(ObjectClass *oc) | ||
81 | { | 34 | { |
35 | LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); | ||
36 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
37 | |||
82 | } | 38 | } |
83 | diff --git a/target/loongarch/kvm/kvm_loongarch.h b/target/loongarch/kvm/kvm_loongarch.h | 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 | ||
84 | new file mode 100644 | 70 | new file mode 100644 |
85 | index XXXXXXX..XXXXXXX | 71 | index XXXXXXX..XXXXXXX |
86 | --- /dev/null | 72 | --- /dev/null |
87 | +++ b/target/loongarch/kvm/kvm_loongarch.h | 73 | +++ b/hw/intc/loongarch_pic_common.c |
88 | @@ -XXX,XX +XXX,XX @@ | 74 | @@ -XXX,XX +XXX,XX @@ |
89 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | 75 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
90 | +/* | 76 | +/* |
91 | + * QEMU LoongArch kvm interface | 77 | + * QEMU Loongson 7A1000 I/O interrupt controller. |
92 | + * | 78 | + * Copyright (C) 2024 Loongson Technology Corporation Limited |
93 | + * Copyright (c) 2023 Loongson Technology Corporation Limited | ||
94 | + */ | 79 | + */ |
95 | + | 80 | + |
96 | +#include "cpu.h" | 81 | +static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
82 | +{ | ||
83 | + LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); | ||
97 | + | 84 | + |
98 | +#ifndef QEMU_KVM_LOONGARCH_H | 85 | + if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
99 | +#define QEMU_KVM_LOONGARCH_H | 86 | + error_setg(errp, "Invalid 'pic_irq_num'"); |
87 | + return; | ||
88 | + } | ||
89 | +} | ||
100 | + | 90 | + |
101 | +int kvm_loongarch_set_interrupt(LoongArchCPU *cpu, int irq, int level); | 91 | +static Property loongarch_pic_common_properties[] = { |
102 | +void kvm_arch_reset_vcpu(CPULoongArchState *env); | 92 | + DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0), |
93 | + DEFINE_PROP_END_OF_LIST(), | ||
94 | +}; | ||
103 | + | 95 | + |
104 | +#endif | 96 | +static const VMStateDescription vmstate_loongarch_pic_common = { |
105 | diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events | 97 | + .name = "loongarch_pch_pic", |
106 | index XXXXXXX..XXXXXXX 100644 | 98 | + .version_id = 1, |
107 | --- a/target/loongarch/trace-events | 99 | + .minimum_version_id = 1, |
108 | +++ b/target/loongarch/trace-events | 100 | + .fields = (const VMStateField[]) { |
109 | @@ -XXX,XX +XXX,XX @@ kvm_failed_put_counter(const char *msg) "Failed to put counter into KVM: %s" | 101 | + VMSTATE_UINT64(int_mask, LoongArchPICCommonState), |
110 | kvm_failed_get_cpucfg(const char *msg) "Failed to get cpucfg from KVM: %s" | 102 | + VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState), |
111 | kvm_failed_put_cpucfg(const char *msg) "Failed to put cpucfg into KVM: %s" | 103 | + VMSTATE_UINT64(intedge, LoongArchPICCommonState), |
112 | kvm_arch_handle_exit(int num) "kvm arch handle exit, the reason number: %d" | 104 | + VMSTATE_UINT64(intclr, LoongArchPICCommonState), |
113 | +kvm_set_intr(int irq, int level) "kvm set interrupt, irq num: %d, level: %d" | 105 | + VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState), |
106 | + VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState), | ||
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 | +}; | ||
114 | -- | 116 | -- |
115 | 2.25.1 | 117 | 2.43.5 |
116 | |||
117 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | Set TYPE_LOONGARCH_PIC inherit from TYPE_LOONGARCH_PIC_COMMON object, |
---|---|---|---|
2 | 2 | it shares vmsate and property of TYPE_LOONGARCH_PIC_COMMON, and has | |
3 | There are two interface pairs for MemoryRegionOps, read/write and | 3 | its own realize() function. |
4 | read_with_attrs/write_with_attrs. The later is better for ipi device | ||
5 | emulation since initial cpu can be parsed from attrs.requester_id. | ||
6 | |||
7 | And requester_id can be overrided for IOCSR_IPI_SEND and mail_send | ||
8 | function when it is to forward message to another vcpu. | ||
9 | 4 | ||
10 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
11 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
12 | Message-Id: <20231215100333.3933632-2-maobibo@loongson.cn> | ||
13 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
14 | --- | 7 | --- |
15 | hw/intc/loongarch_ipi.c | 136 +++++++++++++++++++++++----------------- | 8 | hw/intc/loongarch_pch_pic.c | 38 ++++++++++++-------------- |
16 | 1 file changed, 77 insertions(+), 59 deletions(-) | 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(-) | ||
17 | 14 | ||
18 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 15 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
19 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/intc/loongarch_ipi.c | 17 | --- a/hw/intc/loongarch_pch_pic.c |
21 | +++ b/hw/intc/loongarch_ipi.c | 18 | +++ b/hw/intc/loongarch_pch_pic.c |
22 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
23 | #include "target/loongarch/internals.h" | 20 | s->int_polarity = 0x0; |
24 | #include "trace.h" | 21 | } |
25 | 22 | ||
26 | -static void loongarch_ipi_writel(void *, hwaddr, uint64_t, unsigned); | 23 | -#include "loongarch_pic_common.c" |
27 | - | 24 | -static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) |
28 | -static uint64_t loongarch_ipi_readl(void *opaque, hwaddr addr, unsigned size) | 25 | +static void loongarch_pic_realize(DeviceState *dev, Error **errp) |
29 | +static MemTxResult loongarch_ipi_readl(void *opaque, hwaddr addr, | ||
30 | + uint64_t *data, | ||
31 | + unsigned size, MemTxAttrs attrs) | ||
32 | { | 26 | { |
33 | - IPICore *s = opaque; | 27 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); |
34 | + IPICore *s; | 28 | - SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
35 | + LoongArchIPI *ipi = opaque; | 29 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev); |
36 | uint64_t ret = 0; | 30 | + LoongarchPICClass *lpc = LOONGARCH_PIC_GET_CLASS(dev); |
37 | int index = 0; | 31 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
38 | 32 | Error *local_err = NULL; | |
39 | + s = &ipi->ipi_core; | 33 | |
40 | addr &= 0xff; | 34 | - loongarch_pic_common_realize(dev, &local_err); |
41 | switch (addr) { | 35 | + lpc->parent_realize(dev, &local_err); |
42 | case CORE_STATUS_OFF: | 36 | if (local_err) { |
43 | @@ -XXX,XX +XXX,XX @@ static uint64_t loongarch_ipi_readl(void *opaque, hwaddr addr, unsigned size) | 37 | error_propagate(errp, local_err); |
44 | } | 38 | return; |
45 | 39 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | |
46 | trace_loongarch_ipi_read(size, (uint64_t)addr, ret); | 40 | |
47 | - return ret; | ||
48 | + *data = ret; | ||
49 | + return MEMTX_OK; | ||
50 | } | 41 | } |
51 | 42 | ||
52 | -static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr) | 43 | -static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data) |
53 | +static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr, | 44 | +static void loongarch_pic_class_init(ObjectClass *klass, void *data) |
54 | + MemTxAttrs attrs) | ||
55 | { | 45 | { |
56 | int i, mask = 0, data = 0; | 46 | DeviceClass *dc = DEVICE_CLASS(klass); |
57 | 47 | + LoongarchPICClass *lpc = LOONGARCH_PIC_CLASS(klass); | |
58 | @@ -XXX,XX +XXX,XX @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr) | 48 | |
59 | */ | 49 | - dc->realize = loongarch_pch_pic_realize; |
60 | if ((val >> 27) & 0xf) { | 50 | device_class_set_legacy_reset(dc, loongarch_pch_pic_reset); |
61 | data = address_space_ldl(&env->address_space_iocsr, addr, | 51 | - dc->vmsd = &vmstate_loongarch_pic_common; |
62 | - MEMTXATTRS_UNSPECIFIED, NULL); | 52 | - device_class_set_props(dc, loongarch_pic_common_properties); |
63 | + attrs, NULL); | 53 | + device_class_set_parent_realize(dc, loongarch_pic_realize, |
64 | for (i = 0; i < 4; i++) { | 54 | + &lpc->parent_realize); |
65 | /* get mask for byte writing */ | ||
66 | if (val & (0x1 << (27 + i))) { | ||
67 | @@ -XXX,XX +XXX,XX @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr) | ||
68 | data &= mask; | ||
69 | data |= (val >> 32) & ~mask; | ||
70 | address_space_stl(&env->address_space_iocsr, addr, | ||
71 | - data, MEMTXATTRS_UNSPECIFIED, NULL); | ||
72 | + data, attrs, NULL); | ||
73 | } | 55 | } |
74 | 56 | ||
75 | static int archid_cmp(const void *a, const void *b) | 57 | -static const TypeInfo loongarch_pch_pic_info = { |
76 | @@ -XXX,XX +XXX,XX @@ static CPUState *ipi_getcpu(int arch_id) | 58 | - .name = TYPE_LOONGARCH_PCH_PIC, |
77 | CPUArchId *archid; | 59 | - .parent = TYPE_SYS_BUS_DEVICE, |
78 | 60 | - .instance_size = sizeof(LoongArchPCHPIC), | |
79 | archid = find_cpu_by_archid(machine, arch_id); | 61 | - .class_init = loongarch_pch_pic_class_init, |
80 | - return CPU(archid->cpu); | 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); | ||
81 | -} | 75 | -} |
82 | - | 76 | - |
83 | -static void ipi_send(uint64_t val) | 77 | -type_init(loongarch_pch_pic_register_types) |
84 | -{ | 78 | +DEFINE_TYPES(loongarch_pic_types) |
85 | - uint32_t cpuid; | 79 | diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c |
86 | - uint8_t vector; | 80 | index XXXXXXX..XXXXXXX 100644 |
87 | - CPUState *cs; | 81 | --- a/hw/intc/loongarch_pic_common.c |
88 | - LoongArchCPU *cpu; | 82 | +++ b/hw/intc/loongarch_pic_common.c |
89 | - LoongArchIPI *s; | 83 | @@ -XXX,XX +XXX,XX @@ |
90 | - | 84 | * Copyright (C) 2024 Loongson Technology Corporation Limited |
91 | - cpuid = extract32(val, 16, 10); | 85 | */ |
92 | - if (cpuid >= LOONGARCH_MAX_CPUS) { | 86 | |
93 | - trace_loongarch_ipi_unsupported_cpuid("IOCSR_IPI_SEND", cpuid); | 87 | +#include "qemu/osdep.h" |
94 | - return; | 88 | +#include "qapi/error.h" |
95 | + if (archid) { | 89 | +#include "hw/intc/loongarch_pic_common.h" |
96 | + return CPU(archid->cpu); | 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() | ||
97 | } | 102 | } |
98 | 103 | }; | |
99 | - /* IPI status vector */ | 104 | + |
100 | - vector = extract8(val, 0, 5); | 105 | +static void loongarch_pic_common_class_init(ObjectClass *klass, void *data) |
101 | - | 106 | +{ |
102 | - cs = ipi_getcpu(cpuid); | 107 | + DeviceClass *dc = DEVICE_CLASS(klass); |
103 | - cpu = LOONGARCH_CPU(cs); | 108 | + LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_CLASS(klass); |
104 | - s = LOONGARCH_IPI(cpu->env.ipistate); | 109 | + |
105 | - loongarch_ipi_writel(&s->ipi_core, CORE_SET_OFF, BIT(vector), 4); | 110 | + device_class_set_parent_realize(dc, loongarch_pic_common_realize, |
106 | + return NULL; | 111 | + &lpcc->parent_realize); |
107 | } | 112 | + device_class_set_props(dc, loongarch_pic_common_properties); |
108 | 113 | + dc->vmsd = &vmstate_loongarch_pic_common; | |
109 | -static void mail_send(uint64_t val) | 114 | +} |
110 | +static MemTxResult mail_send(uint64_t val, MemTxAttrs attrs) | 115 | + |
111 | { | 116 | +static const TypeInfo loongarch_pic_common_types[] = { |
112 | uint32_t cpuid; | 117 | + { |
113 | hwaddr addr; | 118 | + .name = TYPE_LOONGARCH_PIC_COMMON, |
114 | - CPULoongArchState *env; | 119 | + .parent = TYPE_SYS_BUS_DEVICE, |
115 | CPUState *cs; | 120 | + .instance_size = sizeof(LoongArchPICCommonState), |
116 | - LoongArchCPU *cpu; | 121 | + .class_size = sizeof(LoongArchPICCommonClass), |
117 | 122 | + .class_init = loongarch_pic_common_class_init, | |
118 | cpuid = extract32(val, 16, 10); | 123 | + .abstract = true, |
119 | if (cpuid >= LOONGARCH_MAX_CPUS) { | ||
120 | trace_loongarch_ipi_unsupported_cpuid("IOCSR_MAIL_SEND", cpuid); | ||
121 | - return; | ||
122 | + return MEMTX_DECODE_ERROR; | ||
123 | } | ||
124 | |||
125 | - addr = 0x1020 + (val & 0x1c); | ||
126 | cs = ipi_getcpu(cpuid); | ||
127 | - cpu = LOONGARCH_CPU(cs); | ||
128 | - env = &cpu->env; | ||
129 | - send_ipi_data(env, val, addr); | ||
130 | + if (cs == NULL) { | ||
131 | + return MEMTX_DECODE_ERROR; | ||
132 | + } | 124 | + } |
125 | +}; | ||
133 | + | 126 | + |
134 | + /* override requester_id */ | 127 | +DEFINE_TYPES(loongarch_pic_common_types) |
135 | + addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c); | 128 | diff --git a/hw/intc/meson.build b/hw/intc/meson.build |
136 | + attrs.requester_id = cs->cpu_index; | 129 | index XXXXXXX..XXXXXXX 100644 |
137 | + send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs); | 130 | --- a/hw/intc/meson.build |
138 | + return MEMTX_OK; | 131 | +++ b/hw/intc/meson.build |
139 | } | 132 | @@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) |
140 | 133 | specific_ss.add(when: 'CONFIG_LOONGSON_IPI_COMMON', if_true: files('loongson_ipi_common.c')) | |
141 | -static void any_send(uint64_t val) | 134 | specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.c')) |
142 | +static MemTxResult any_send(uint64_t val, MemTxAttrs attrs) | 135 | specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c')) |
143 | { | 136 | -specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c')) |
144 | uint32_t cpuid; | 137 | +specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c', 'loongarch_pic_common.c')) |
145 | hwaddr addr; | 138 | specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c')) |
146 | - CPULoongArchState *env; | 139 | specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c')) |
147 | CPUState *cs; | 140 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h |
148 | - LoongArchCPU *cpu; | 141 | index XXXXXXX..XXXXXXX 100644 |
149 | 142 | --- a/include/hw/intc/loongarch_pch_pic.h | |
150 | cpuid = extract32(val, 16, 10); | 143 | +++ b/include/hw/intc/loongarch_pch_pic.h |
151 | if (cpuid >= LOONGARCH_MAX_CPUS) { | 144 | @@ -XXX,XX +XXX,XX @@ |
152 | trace_loongarch_ipi_unsupported_cpuid("IOCSR_ANY_SEND", cpuid); | 145 | |
153 | - return; | 146 | #include "hw/intc/loongarch_pic_common.h" |
154 | + return MEMTX_DECODE_ERROR; | 147 | |
155 | } | 148 | -#define LoongArchPCHPIC LoongArchPICCommonState |
156 | 149 | -#define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic" | |
157 | - addr = val & 0xffff; | 150 | -#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name |
158 | cs = ipi_getcpu(cpuid); | 151 | -OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC) |
159 | - cpu = LOONGARCH_CPU(cs); | 152 | +#define TYPE_LOONGARCH_PIC "loongarch_pic" |
160 | - env = &cpu->env; | 153 | +#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PIC#name |
161 | - send_ipi_data(env, val, addr); | 154 | +OBJECT_DECLARE_TYPE(LoongarchPICState, LoongarchPICClass, LOONGARCH_PIC) |
162 | + if (cs == NULL) { | ||
163 | + return MEMTX_DECODE_ERROR; | ||
164 | + } | ||
165 | + | 155 | + |
166 | + /* override requester_id */ | 156 | +struct LoongarchPICState { |
167 | + addr = val & 0xffff; | 157 | + LoongArchPICCommonState parent_obj; |
168 | + attrs.requester_id = cs->cpu_index; | 158 | +}; |
169 | + send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs); | ||
170 | + return MEMTX_OK; | ||
171 | } | ||
172 | |||
173 | -static void loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val, | ||
174 | - unsigned size) | ||
175 | +static MemTxResult loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val, | ||
176 | + unsigned size, MemTxAttrs attrs) | ||
177 | { | ||
178 | - IPICore *s = opaque; | ||
179 | + LoongArchIPI *ipi = opaque; | ||
180 | + IPICore *s; | ||
181 | int index = 0; | ||
182 | + uint32_t cpuid; | ||
183 | + uint8_t vector; | ||
184 | + CPUState *cs; | ||
185 | |||
186 | + s = &ipi->ipi_core; | ||
187 | addr &= 0xff; | ||
188 | trace_loongarch_ipi_write(size, (uint64_t)addr, val); | ||
189 | switch (addr) { | ||
190 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val, | ||
191 | s->buf[index] = val; | ||
192 | break; | ||
193 | case IOCSR_IPI_SEND: | ||
194 | - ipi_send(val); | ||
195 | + cpuid = extract32(val, 16, 10); | ||
196 | + if (cpuid >= LOONGARCH_MAX_CPUS) { | ||
197 | + trace_loongarch_ipi_unsupported_cpuid("IOCSR_IPI_SEND", cpuid); | ||
198 | + return MEMTX_DECODE_ERROR; | ||
199 | + } | ||
200 | + | 159 | + |
201 | + /* IPI status vector */ | 160 | +struct LoongarchPICClass { |
202 | + vector = extract8(val, 0, 5); | 161 | + LoongArchPICCommonClass parent_class; |
203 | + cs = ipi_getcpu(cpuid); | ||
204 | + if (cs == NULL) { | ||
205 | + return MEMTX_DECODE_ERROR; | ||
206 | + } | ||
207 | + | 162 | + |
208 | + /* override requester_id */ | 163 | + DeviceRealize parent_realize; |
209 | + attrs.requester_id = cs->cpu_index; | 164 | +}; |
210 | + ipi = LOONGARCH_IPI(LOONGARCH_CPU(cs)->env.ipistate); | ||
211 | + loongarch_ipi_writel(ipi, CORE_SET_OFF, BIT(vector), 4, attrs); | ||
212 | break; | ||
213 | default: | ||
214 | qemu_log_mask(LOG_UNIMP, "invalid write: %x", (uint32_t)addr); | ||
215 | break; | ||
216 | } | ||
217 | + | 165 | + |
218 | + return MEMTX_OK; | 166 | +#define TYPE_LOONGARCH_PCH_PIC TYPE_LOONGARCH_PIC |
219 | } | 167 | +typedef struct LoongArchPICCommonState LoongArchPCHPIC; |
220 | 168 | +#define LOONGARCH_PCH_PIC(obj) ((struct LoongArchPICCommonState *)(obj)) | |
221 | static const MemoryRegionOps loongarch_ipi_ops = { | 169 | |
222 | - .read = loongarch_ipi_readl, | 170 | #endif /* HW_LOONGARCH_PCH_PIC_H */ |
223 | - .write = loongarch_ipi_writel, | 171 | diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h |
224 | + .read_with_attrs = loongarch_ipi_readl, | 172 | index XXXXXXX..XXXXXXX 100644 |
225 | + .write_with_attrs = loongarch_ipi_writel, | 173 | --- a/include/hw/intc/loongarch_pic_common.h |
226 | .impl.min_access_size = 4, | 174 | +++ b/include/hw/intc/loongarch_pic_common.h |
227 | .impl.max_access_size = 4, | 175 | @@ -XXX,XX +XXX,XX @@ |
228 | .valid.min_access_size = 4, | 176 | #define POL_LO_START 0x40 |
229 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps loongarch_ipi_ops = { | 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; | ||
230 | }; | 189 | }; |
231 | |||
232 | /* mail send and any send only support writeq */ | ||
233 | -static void loongarch_ipi_writeq(void *opaque, hwaddr addr, uint64_t val, | ||
234 | - unsigned size) | ||
235 | +static MemTxResult loongarch_ipi_writeq(void *opaque, hwaddr addr, uint64_t val, | ||
236 | + unsigned size, MemTxAttrs attrs) | ||
237 | { | ||
238 | + MemTxResult ret = MEMTX_OK; | ||
239 | + | 190 | + |
240 | addr &= 0xfff; | 191 | +struct LoongArchPICCommonClass { |
241 | switch (addr) { | 192 | + SysBusDeviceClass parent_class; |
242 | case MAIL_SEND_OFFSET: | ||
243 | - mail_send(val); | ||
244 | + ret = mail_send(val, attrs); | ||
245 | break; | ||
246 | case ANY_SEND_OFFSET: | ||
247 | - any_send(val); | ||
248 | + ret = any_send(val, attrs); | ||
249 | break; | ||
250 | default: | ||
251 | break; | ||
252 | } | ||
253 | + | 193 | + |
254 | + return ret; | 194 | + DeviceRealize parent_realize; |
255 | } | 195 | +}; |
256 | 196 | #endif /* HW_LOONGARCH_PIC_COMMON_H */ | |
257 | static const MemoryRegionOps loongarch_ipi64_ops = { | ||
258 | - .write = loongarch_ipi_writeq, | ||
259 | + .write_with_attrs = loongarch_ipi_writeq, | ||
260 | .impl.min_access_size = 8, | ||
261 | .impl.max_access_size = 8, | ||
262 | .valid.min_access_size = 8, | ||
263 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_init(Object *obj) | ||
264 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
265 | |||
266 | memory_region_init_io(&s->ipi_iocsr_mem, obj, &loongarch_ipi_ops, | ||
267 | - &s->ipi_core, "loongarch_ipi_iocsr", 0x48); | ||
268 | + s, "loongarch_ipi_iocsr", 0x48); | ||
269 | |||
270 | /* loongarch_ipi_iocsr performs re-entrant IO through ipi_send */ | ||
271 | s->ipi_iocsr_mem.disable_reentrancy_guard = true; | ||
272 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_init(Object *obj) | ||
273 | sysbus_init_mmio(sbd, &s->ipi_iocsr_mem); | ||
274 | |||
275 | memory_region_init_io(&s->ipi64_iocsr_mem, obj, &loongarch_ipi64_ops, | ||
276 | - &s->ipi_core, "loongarch_ipi64_iocsr", 0x118); | ||
277 | + s, "loongarch_ipi64_iocsr", 0x118); | ||
278 | sysbus_init_mmio(sbd, &s->ipi64_iocsr_mem); | ||
279 | qdev_init_gpio_out(DEVICE(obj), &s->ipi_core.irq, 1); | ||
280 | } | ||
281 | -- | 197 | -- |
282 | 2.25.1 | 198 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | Add vmstate pre_save and post_load interfaces, which can be used |
---|---|---|---|
2 | by pic kvm driver in future. | ||
2 | 3 | ||
3 | Implement kvm_arch_get/set_registers interfaces, many regs | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | can be get/set in the function, such as core regs, csr regs, | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | fpu regs, mp state, etc. | 6 | --- |
7 | hw/intc/loongarch_pic_common.c | 26 ++++++++++++++++++++++++++ | ||
8 | include/hw/intc/loongarch_pic_common.h | 2 ++ | ||
9 | 2 files changed, 28 insertions(+) | ||
6 | 10 | ||
7 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 11 | diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c |
8 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
9 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
10 | Change-Id: Ia8fc48fe08b1768853f7729e77d37cdf270031e4 | ||
11 | Message-Id: <20240105075804.1228596-5-zhaotianrui@loongson.cn> | ||
12 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
13 | --- | ||
14 | meson.build | 1 + | ||
15 | target/loongarch/cpu.c | 3 + | ||
16 | target/loongarch/cpu.h | 1 + | ||
17 | target/loongarch/internals.h | 5 +- | ||
18 | target/loongarch/kvm/kvm.c | 580 +++++++++++++++++++++++++++++++++- | ||
19 | target/loongarch/trace-events | 11 + | ||
20 | target/loongarch/trace.h | 1 + | ||
21 | 7 files changed, 599 insertions(+), 3 deletions(-) | ||
22 | create mode 100644 target/loongarch/trace-events | ||
23 | create mode 100644 target/loongarch/trace.h | ||
24 | |||
25 | diff --git a/meson.build b/meson.build | ||
26 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/meson.build | 13 | --- a/hw/intc/loongarch_pic_common.c |
28 | +++ b/meson.build | 14 | +++ b/hw/intc/loongarch_pic_common.c |
29 | @@ -XXX,XX +XXX,XX @@ if have_system or have_user | ||
30 | 'target/hppa', | ||
31 | 'target/i386', | ||
32 | 'target/i386/kvm', | ||
33 | + 'target/loongarch', | ||
34 | 'target/mips/tcg', | ||
35 | 'target/nios2', | ||
36 | 'target/ppc', | ||
37 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/loongarch/cpu.c | ||
40 | +++ b/target/loongarch/cpu.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_reset_hold(Object *obj) | ||
42 | #ifndef CONFIG_USER_ONLY | ||
43 | env->pc = 0x1c000000; | ||
44 | memset(env->tlb, 0, sizeof(env->tlb)); | ||
45 | + if (kvm_enabled()) { | ||
46 | + kvm_arch_reset_vcpu(env); | ||
47 | + } | ||
48 | #endif | ||
49 | |||
50 | restore_fp_status(env); | ||
51 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/loongarch/cpu.h | ||
54 | +++ b/target/loongarch/cpu.h | ||
55 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
56 | MemoryRegion iocsr_mem; | ||
57 | bool load_elf; | ||
58 | uint64_t elf_address; | ||
59 | + uint32_t mp_state; | ||
60 | /* Store ipistate to access from this struct */ | ||
61 | DeviceState *ipistate; | ||
62 | #endif | ||
63 | diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/target/loongarch/internals.h | ||
66 | +++ b/target/loongarch/internals.h | ||
67 | @@ -XXX,XX +XXX,XX @@ void G_NORETURN do_raise_exception(CPULoongArchState *env, | ||
68 | |||
69 | const char *loongarch_exception_name(int32_t exception); | ||
70 | |||
71 | +#ifdef CONFIG_TCG | ||
72 | int ieee_ex_to_loongarch(int xcpt); | ||
73 | void restore_fp_status(CPULoongArchState *env); | ||
74 | +#endif | ||
75 | |||
76 | #ifndef CONFIG_USER_ONLY | ||
77 | extern const VMStateDescription vmstate_loongarch_cpu; | ||
78 | @@ -XXX,XX +XXX,XX @@ uint64_t cpu_loongarch_get_constant_timer_counter(LoongArchCPU *cpu); | ||
79 | uint64_t cpu_loongarch_get_constant_timer_ticks(LoongArchCPU *cpu); | ||
80 | void cpu_loongarch_store_constant_timer_config(LoongArchCPU *cpu, | ||
81 | uint64_t value); | ||
82 | - | ||
83 | +#ifdef CONFIG_TCG | ||
84 | bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
85 | MMUAccessType access_type, int mmu_idx, | ||
86 | bool probe, uintptr_t retaddr); | ||
87 | |||
88 | hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); | ||
89 | +#endif | ||
90 | #endif /* !CONFIG_USER_ONLY */ | ||
91 | |||
92 | uint64_t read_fcc(CPULoongArchState *env); | ||
93 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/target/loongarch/kvm/kvm.c | ||
96 | +++ b/target/loongarch/kvm/kvm.c | ||
97 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ |
98 | #include "sysemu/runstate.h" | 16 | #include "hw/qdev-properties.h" |
99 | #include "cpu-csr.h" | 17 | #include "migration/vmstate.h" |
100 | #include "kvm_loongarch.h" | 18 | |
101 | +#include "trace.h" | 19 | +static int loongarch_pic_pre_save(void *opaque) |
102 | |||
103 | static bool cap_has_mp_state; | ||
104 | const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | ||
105 | KVM_CAP_LAST_INFO | ||
106 | }; | ||
107 | |||
108 | +static int kvm_loongarch_get_regs_core(CPUState *cs) | ||
109 | +{ | 20 | +{ |
110 | + int ret = 0; | 21 | + LoongArchPICCommonState *s = (LoongArchPICCommonState *)opaque; |
111 | + int i; | 22 | + LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_GET_CLASS(s); |
112 | + struct kvm_regs regs; | ||
113 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
114 | + CPULoongArchState *env = &cpu->env; | ||
115 | + | 23 | + |
116 | + /* Get the current register set as KVM seems it */ | 24 | + if (lpcc->pre_save) { |
117 | + ret = kvm_vcpu_ioctl(cs, KVM_GET_REGS, ®s); | 25 | + return lpcc->pre_save(s); |
118 | + if (ret < 0) { | ||
119 | + trace_kvm_failed_get_regs_core(strerror(errno)); | ||
120 | + return ret; | ||
121 | + } | ||
122 | + /* gpr[0] value is always 0 */ | ||
123 | + env->gpr[0] = 0; | ||
124 | + for (i = 1; i < 32; i++) { | ||
125 | + env->gpr[i] = regs.gpr[i]; | ||
126 | + } | 26 | + } |
127 | + | 27 | + |
128 | + env->pc = regs.pc; | 28 | + return 0; |
129 | + return ret; | ||
130 | +} | 29 | +} |
131 | + | 30 | + |
132 | +static int kvm_loongarch_put_regs_core(CPUState *cs) | 31 | +static int loongarch_pic_post_load(void *opaque, int version_id) |
133 | +{ | 32 | +{ |
134 | + int ret = 0; | 33 | + LoongArchPICCommonState *s = (LoongArchPICCommonState *)opaque; |
135 | + int i; | 34 | + LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_GET_CLASS(s); |
136 | + struct kvm_regs regs; | ||
137 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
138 | + CPULoongArchState *env = &cpu->env; | ||
139 | + | 35 | + |
140 | + /* Set the registers based on QEMU's view of things */ | 36 | + if (lpcc->post_load) { |
141 | + for (i = 0; i < 32; i++) { | 37 | + return lpcc->post_load(s, version_id); |
142 | + regs.gpr[i] = env->gpr[i]; | ||
143 | + } | 38 | + } |
144 | + | 39 | + |
145 | + regs.pc = env->pc; | 40 | + return 0; |
146 | + ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, ®s); | ||
147 | + if (ret < 0) { | ||
148 | + trace_kvm_failed_put_regs_core(strerror(errno)); | ||
149 | + } | ||
150 | + | ||
151 | + return ret; | ||
152 | +} | 41 | +} |
153 | + | 42 | + |
154 | +static int kvm_loongarch_get_csr(CPUState *cs) | 43 | static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
155 | +{ | ||
156 | + int ret = 0; | ||
157 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
158 | + CPULoongArchState *env = &cpu->env; | ||
159 | + | ||
160 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CRMD), | ||
161 | + &env->CSR_CRMD); | ||
162 | + | ||
163 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRMD), | ||
164 | + &env->CSR_PRMD); | ||
165 | + | ||
166 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EUEN), | ||
167 | + &env->CSR_EUEN); | ||
168 | + | ||
169 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_MISC), | ||
170 | + &env->CSR_MISC); | ||
171 | + | ||
172 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ECFG), | ||
173 | + &env->CSR_ECFG); | ||
174 | + | ||
175 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ESTAT), | ||
176 | + &env->CSR_ESTAT); | ||
177 | + | ||
178 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ERA), | ||
179 | + &env->CSR_ERA); | ||
180 | + | ||
181 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADV), | ||
182 | + &env->CSR_BADV); | ||
183 | + | ||
184 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADI), | ||
185 | + &env->CSR_BADI); | ||
186 | + | ||
187 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EENTRY), | ||
188 | + &env->CSR_EENTRY); | ||
189 | + | ||
190 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBIDX), | ||
191 | + &env->CSR_TLBIDX); | ||
192 | + | ||
193 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBEHI), | ||
194 | + &env->CSR_TLBEHI); | ||
195 | + | ||
196 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO0), | ||
197 | + &env->CSR_TLBELO0); | ||
198 | + | ||
199 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO1), | ||
200 | + &env->CSR_TLBELO1); | ||
201 | + | ||
202 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ASID), | ||
203 | + &env->CSR_ASID); | ||
204 | + | ||
205 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDL), | ||
206 | + &env->CSR_PGDL); | ||
207 | + | ||
208 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDH), | ||
209 | + &env->CSR_PGDH); | ||
210 | + | ||
211 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGD), | ||
212 | + &env->CSR_PGD); | ||
213 | + | ||
214 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCL), | ||
215 | + &env->CSR_PWCL); | ||
216 | + | ||
217 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCH), | ||
218 | + &env->CSR_PWCH); | ||
219 | + | ||
220 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_STLBPS), | ||
221 | + &env->CSR_STLBPS); | ||
222 | + | ||
223 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_RVACFG), | ||
224 | + &env->CSR_RVACFG); | ||
225 | + | ||
226 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID), | ||
227 | + &env->CSR_CPUID); | ||
228 | + | ||
229 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG1), | ||
230 | + &env->CSR_PRCFG1); | ||
231 | + | ||
232 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG2), | ||
233 | + &env->CSR_PRCFG2); | ||
234 | + | ||
235 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG3), | ||
236 | + &env->CSR_PRCFG3); | ||
237 | + | ||
238 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(0)), | ||
239 | + &env->CSR_SAVE[0]); | ||
240 | + | ||
241 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(1)), | ||
242 | + &env->CSR_SAVE[1]); | ||
243 | + | ||
244 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(2)), | ||
245 | + &env->CSR_SAVE[2]); | ||
246 | + | ||
247 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(3)), | ||
248 | + &env->CSR_SAVE[3]); | ||
249 | + | ||
250 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(4)), | ||
251 | + &env->CSR_SAVE[4]); | ||
252 | + | ||
253 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(5)), | ||
254 | + &env->CSR_SAVE[5]); | ||
255 | + | ||
256 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(6)), | ||
257 | + &env->CSR_SAVE[6]); | ||
258 | + | ||
259 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(7)), | ||
260 | + &env->CSR_SAVE[7]); | ||
261 | + | ||
262 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TID), | ||
263 | + &env->CSR_TID); | ||
264 | + | ||
265 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CNTC), | ||
266 | + &env->CSR_CNTC); | ||
267 | + | ||
268 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TICLR), | ||
269 | + &env->CSR_TICLR); | ||
270 | + | ||
271 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_LLBCTL), | ||
272 | + &env->CSR_LLBCTL); | ||
273 | + | ||
274 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL1), | ||
275 | + &env->CSR_IMPCTL1); | ||
276 | + | ||
277 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL2), | ||
278 | + &env->CSR_IMPCTL2); | ||
279 | + | ||
280 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRENTRY), | ||
281 | + &env->CSR_TLBRENTRY); | ||
282 | + | ||
283 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRBADV), | ||
284 | + &env->CSR_TLBRBADV); | ||
285 | + | ||
286 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRERA), | ||
287 | + &env->CSR_TLBRERA); | ||
288 | + | ||
289 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRSAVE), | ||
290 | + &env->CSR_TLBRSAVE); | ||
291 | + | ||
292 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO0), | ||
293 | + &env->CSR_TLBRELO0); | ||
294 | + | ||
295 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO1), | ||
296 | + &env->CSR_TLBRELO1); | ||
297 | + | ||
298 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBREHI), | ||
299 | + &env->CSR_TLBREHI); | ||
300 | + | ||
301 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRPRMD), | ||
302 | + &env->CSR_TLBRPRMD); | ||
303 | + | ||
304 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(0)), | ||
305 | + &env->CSR_DMW[0]); | ||
306 | + | ||
307 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(1)), | ||
308 | + &env->CSR_DMW[1]); | ||
309 | + | ||
310 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(2)), | ||
311 | + &env->CSR_DMW[2]); | ||
312 | + | ||
313 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(3)), | ||
314 | + &env->CSR_DMW[3]); | ||
315 | + | ||
316 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TVAL), | ||
317 | + &env->CSR_TVAL); | ||
318 | + | ||
319 | + ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TCFG), | ||
320 | + &env->CSR_TCFG); | ||
321 | + | ||
322 | + return ret; | ||
323 | +} | ||
324 | + | ||
325 | +static int kvm_loongarch_put_csr(CPUState *cs) | ||
326 | +{ | ||
327 | + int ret = 0; | ||
328 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
329 | + CPULoongArchState *env = &cpu->env; | ||
330 | + | ||
331 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CRMD), | ||
332 | + &env->CSR_CRMD); | ||
333 | + | ||
334 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRMD), | ||
335 | + &env->CSR_PRMD); | ||
336 | + | ||
337 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EUEN), | ||
338 | + &env->CSR_EUEN); | ||
339 | + | ||
340 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_MISC), | ||
341 | + &env->CSR_MISC); | ||
342 | + | ||
343 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ECFG), | ||
344 | + &env->CSR_ECFG); | ||
345 | + | ||
346 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ESTAT), | ||
347 | + &env->CSR_ESTAT); | ||
348 | + | ||
349 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ERA), | ||
350 | + &env->CSR_ERA); | ||
351 | + | ||
352 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADV), | ||
353 | + &env->CSR_BADV); | ||
354 | + | ||
355 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADI), | ||
356 | + &env->CSR_BADI); | ||
357 | + | ||
358 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EENTRY), | ||
359 | + &env->CSR_EENTRY); | ||
360 | + | ||
361 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBIDX), | ||
362 | + &env->CSR_TLBIDX); | ||
363 | + | ||
364 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBEHI), | ||
365 | + &env->CSR_TLBEHI); | ||
366 | + | ||
367 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO0), | ||
368 | + &env->CSR_TLBELO0); | ||
369 | + | ||
370 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO1), | ||
371 | + &env->CSR_TLBELO1); | ||
372 | + | ||
373 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ASID), | ||
374 | + &env->CSR_ASID); | ||
375 | + | ||
376 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDL), | ||
377 | + &env->CSR_PGDL); | ||
378 | + | ||
379 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDH), | ||
380 | + &env->CSR_PGDH); | ||
381 | + | ||
382 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGD), | ||
383 | + &env->CSR_PGD); | ||
384 | + | ||
385 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCL), | ||
386 | + &env->CSR_PWCL); | ||
387 | + | ||
388 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCH), | ||
389 | + &env->CSR_PWCH); | ||
390 | + | ||
391 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_STLBPS), | ||
392 | + &env->CSR_STLBPS); | ||
393 | + | ||
394 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_RVACFG), | ||
395 | + &env->CSR_RVACFG); | ||
396 | + | ||
397 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID), | ||
398 | + &env->CSR_CPUID); | ||
399 | + | ||
400 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG1), | ||
401 | + &env->CSR_PRCFG1); | ||
402 | + | ||
403 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG2), | ||
404 | + &env->CSR_PRCFG2); | ||
405 | + | ||
406 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG3), | ||
407 | + &env->CSR_PRCFG3); | ||
408 | + | ||
409 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(0)), | ||
410 | + &env->CSR_SAVE[0]); | ||
411 | + | ||
412 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(1)), | ||
413 | + &env->CSR_SAVE[1]); | ||
414 | + | ||
415 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(2)), | ||
416 | + &env->CSR_SAVE[2]); | ||
417 | + | ||
418 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(3)), | ||
419 | + &env->CSR_SAVE[3]); | ||
420 | + | ||
421 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(4)), | ||
422 | + &env->CSR_SAVE[4]); | ||
423 | + | ||
424 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(5)), | ||
425 | + &env->CSR_SAVE[5]); | ||
426 | + | ||
427 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(6)), | ||
428 | + &env->CSR_SAVE[6]); | ||
429 | + | ||
430 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(7)), | ||
431 | + &env->CSR_SAVE[7]); | ||
432 | + | ||
433 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TID), | ||
434 | + &env->CSR_TID); | ||
435 | + | ||
436 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CNTC), | ||
437 | + &env->CSR_CNTC); | ||
438 | + | ||
439 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TICLR), | ||
440 | + &env->CSR_TICLR); | ||
441 | + | ||
442 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_LLBCTL), | ||
443 | + &env->CSR_LLBCTL); | ||
444 | + | ||
445 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL1), | ||
446 | + &env->CSR_IMPCTL1); | ||
447 | + | ||
448 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL2), | ||
449 | + &env->CSR_IMPCTL2); | ||
450 | + | ||
451 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRENTRY), | ||
452 | + &env->CSR_TLBRENTRY); | ||
453 | + | ||
454 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRBADV), | ||
455 | + &env->CSR_TLBRBADV); | ||
456 | + | ||
457 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRERA), | ||
458 | + &env->CSR_TLBRERA); | ||
459 | + | ||
460 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRSAVE), | ||
461 | + &env->CSR_TLBRSAVE); | ||
462 | + | ||
463 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO0), | ||
464 | + &env->CSR_TLBRELO0); | ||
465 | + | ||
466 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO1), | ||
467 | + &env->CSR_TLBRELO1); | ||
468 | + | ||
469 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBREHI), | ||
470 | + &env->CSR_TLBREHI); | ||
471 | + | ||
472 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRPRMD), | ||
473 | + &env->CSR_TLBRPRMD); | ||
474 | + | ||
475 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(0)), | ||
476 | + &env->CSR_DMW[0]); | ||
477 | + | ||
478 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(1)), | ||
479 | + &env->CSR_DMW[1]); | ||
480 | + | ||
481 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(2)), | ||
482 | + &env->CSR_DMW[2]); | ||
483 | + | ||
484 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(3)), | ||
485 | + &env->CSR_DMW[3]); | ||
486 | + /* | ||
487 | + * timer cfg must be put at last since it is used to enable | ||
488 | + * guest timer | ||
489 | + */ | ||
490 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TVAL), | ||
491 | + &env->CSR_TVAL); | ||
492 | + | ||
493 | + ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TCFG), | ||
494 | + &env->CSR_TCFG); | ||
495 | + return ret; | ||
496 | +} | ||
497 | + | ||
498 | +static int kvm_loongarch_get_regs_fp(CPUState *cs) | ||
499 | +{ | ||
500 | + int ret, i; | ||
501 | + struct kvm_fpu fpu; | ||
502 | + | ||
503 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
504 | + CPULoongArchState *env = &cpu->env; | ||
505 | + | ||
506 | + ret = kvm_vcpu_ioctl(cs, KVM_GET_FPU, &fpu); | ||
507 | + if (ret < 0) { | ||
508 | + trace_kvm_failed_get_fpu(strerror(errno)); | ||
509 | + return ret; | ||
510 | + } | ||
511 | + | ||
512 | + env->fcsr0 = fpu.fcsr; | ||
513 | + for (i = 0; i < 32; i++) { | ||
514 | + env->fpr[i].vreg.UD[0] = fpu.fpr[i].val64[0]; | ||
515 | + } | ||
516 | + for (i = 0; i < 8; i++) { | ||
517 | + env->cf[i] = fpu.fcc & 0xFF; | ||
518 | + fpu.fcc = fpu.fcc >> 8; | ||
519 | + } | ||
520 | + | ||
521 | + return ret; | ||
522 | +} | ||
523 | + | ||
524 | +static int kvm_loongarch_put_regs_fp(CPUState *cs) | ||
525 | +{ | ||
526 | + int ret, i; | ||
527 | + struct kvm_fpu fpu; | ||
528 | + | ||
529 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
530 | + CPULoongArchState *env = &cpu->env; | ||
531 | + | ||
532 | + fpu.fcsr = env->fcsr0; | ||
533 | + fpu.fcc = 0; | ||
534 | + for (i = 0; i < 32; i++) { | ||
535 | + fpu.fpr[i].val64[0] = env->fpr[i].vreg.UD[0]; | ||
536 | + } | ||
537 | + | ||
538 | + for (i = 0; i < 8; i++) { | ||
539 | + fpu.fcc |= env->cf[i] << (8 * i); | ||
540 | + } | ||
541 | + | ||
542 | + ret = kvm_vcpu_ioctl(cs, KVM_SET_FPU, &fpu); | ||
543 | + if (ret < 0) { | ||
544 | + trace_kvm_failed_put_fpu(strerror(errno)); | ||
545 | + } | ||
546 | + | ||
547 | + return ret; | ||
548 | +} | ||
549 | + | ||
550 | +void kvm_arch_reset_vcpu(CPULoongArchState *env) | ||
551 | +{ | ||
552 | + env->mp_state = KVM_MP_STATE_RUNNABLE; | ||
553 | +} | ||
554 | + | ||
555 | +static int kvm_loongarch_get_mpstate(CPUState *cs) | ||
556 | +{ | ||
557 | + int ret = 0; | ||
558 | + struct kvm_mp_state mp_state; | ||
559 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
560 | + CPULoongArchState *env = &cpu->env; | ||
561 | + | ||
562 | + if (cap_has_mp_state) { | ||
563 | + ret = kvm_vcpu_ioctl(cs, KVM_GET_MP_STATE, &mp_state); | ||
564 | + if (ret) { | ||
565 | + trace_kvm_failed_get_mpstate(strerror(errno)); | ||
566 | + return ret; | ||
567 | + } | ||
568 | + env->mp_state = mp_state.mp_state; | ||
569 | + } | ||
570 | + | ||
571 | + return ret; | ||
572 | +} | ||
573 | + | ||
574 | +static int kvm_loongarch_put_mpstate(CPUState *cs) | ||
575 | +{ | ||
576 | + int ret = 0; | ||
577 | + | ||
578 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
579 | + CPULoongArchState *env = &cpu->env; | ||
580 | + | ||
581 | + struct kvm_mp_state mp_state = { | ||
582 | + .mp_state = env->mp_state | ||
583 | + }; | ||
584 | + | ||
585 | + if (cap_has_mp_state) { | ||
586 | + ret = kvm_vcpu_ioctl(cs, KVM_SET_MP_STATE, &mp_state); | ||
587 | + if (ret) { | ||
588 | + trace_kvm_failed_put_mpstate(strerror(errno)); | ||
589 | + } | ||
590 | + } | ||
591 | + | ||
592 | + return ret; | ||
593 | +} | ||
594 | + | ||
595 | +static int kvm_loongarch_get_cpucfg(CPUState *cs) | ||
596 | +{ | ||
597 | + int i, ret = 0; | ||
598 | + uint64_t val; | ||
599 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
600 | + CPULoongArchState *env = &cpu->env; | ||
601 | + | ||
602 | + for (i = 0; i < 21; i++) { | ||
603 | + ret = kvm_get_one_reg(cs, KVM_IOC_CPUCFG(i), &val); | ||
604 | + if (ret < 0) { | ||
605 | + trace_kvm_failed_get_cpucfg(strerror(errno)); | ||
606 | + } | ||
607 | + env->cpucfg[i] = (uint32_t)val; | ||
608 | + } | ||
609 | + return ret; | ||
610 | +} | ||
611 | + | ||
612 | +static int kvm_loongarch_put_cpucfg(CPUState *cs) | ||
613 | +{ | ||
614 | + int i, ret = 0; | ||
615 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
616 | + CPULoongArchState *env = &cpu->env; | ||
617 | + uint64_t val; | ||
618 | + | ||
619 | + for (i = 0; i < 21; i++) { | ||
620 | + val = env->cpucfg[i]; | ||
621 | + /* LSX and LASX and LBT are not supported in kvm now */ | ||
622 | + if (i == 2) { | ||
623 | + val &= ~(BIT(R_CPUCFG2_LSX_SHIFT) | BIT(R_CPUCFG2_LASX_SHIFT)); | ||
624 | + val &= ~(BIT(R_CPUCFG2_LBT_X86_SHIFT) | | ||
625 | + BIT(R_CPUCFG2_LBT_ARM_SHIFT) | | ||
626 | + BIT(R_CPUCFG2_LBT_MIPS_SHIFT)); | ||
627 | + } | ||
628 | + ret = kvm_set_one_reg(cs, KVM_IOC_CPUCFG(i), &val); | ||
629 | + if (ret < 0) { | ||
630 | + trace_kvm_failed_put_cpucfg(strerror(errno)); | ||
631 | + } | ||
632 | + } | ||
633 | + return ret; | ||
634 | +} | ||
635 | + | ||
636 | int kvm_arch_get_registers(CPUState *cs) | ||
637 | { | 44 | { |
638 | - return 0; | 45 | LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev); |
639 | + int ret; | 46 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_pic_common = { |
640 | + | 47 | .name = "loongarch_pch_pic", |
641 | + ret = kvm_loongarch_get_regs_core(cs); | 48 | .version_id = 1, |
642 | + if (ret) { | 49 | .minimum_version_id = 1, |
643 | + return ret; | 50 | + .pre_save = loongarch_pic_pre_save, |
644 | + } | 51 | + .post_load = loongarch_pic_post_load, |
645 | + | 52 | .fields = (const VMStateField[]) { |
646 | + ret = kvm_loongarch_get_csr(cs); | 53 | VMSTATE_UINT64(int_mask, LoongArchPICCommonState), |
647 | + if (ret) { | 54 | VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState), |
648 | + return ret; | 55 | diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h |
649 | + } | 56 | index XXXXXXX..XXXXXXX 100644 |
650 | + | 57 | --- a/include/hw/intc/loongarch_pic_common.h |
651 | + ret = kvm_loongarch_get_regs_fp(cs); | 58 | +++ b/include/hw/intc/loongarch_pic_common.h |
652 | + if (ret) { | 59 | @@ -XXX,XX +XXX,XX @@ struct LoongArchPICCommonClass { |
653 | + return ret; | 60 | SysBusDeviceClass parent_class; |
654 | + } | 61 | |
655 | + | 62 | DeviceRealize parent_realize; |
656 | + ret = kvm_loongarch_get_mpstate(cs); | 63 | + int (*pre_save)(LoongArchPICCommonState *s); |
657 | + if (ret) { | 64 | + int (*post_load)(LoongArchPICCommonState *s, int version_id); |
658 | + return ret; | 65 | }; |
659 | + } | 66 | #endif /* HW_LOONGARCH_PIC_COMMON_H */ |
660 | + | ||
661 | + ret = kvm_loongarch_get_cpucfg(cs); | ||
662 | + return ret; | ||
663 | } | ||
664 | + | ||
665 | int kvm_arch_put_registers(CPUState *cs, int level) | ||
666 | { | ||
667 | - return 0; | ||
668 | + int ret; | ||
669 | + | ||
670 | + ret = kvm_loongarch_put_regs_core(cs); | ||
671 | + if (ret) { | ||
672 | + return ret; | ||
673 | + } | ||
674 | + | ||
675 | + ret = kvm_loongarch_put_csr(cs); | ||
676 | + if (ret) { | ||
677 | + return ret; | ||
678 | + } | ||
679 | + | ||
680 | + ret = kvm_loongarch_put_regs_fp(cs); | ||
681 | + if (ret) { | ||
682 | + return ret; | ||
683 | + } | ||
684 | + | ||
685 | + ret = kvm_loongarch_put_mpstate(cs); | ||
686 | + if (ret) { | ||
687 | + return ret; | ||
688 | + } | ||
689 | + | ||
690 | + ret = kvm_loongarch_put_cpucfg(cs); | ||
691 | + return ret; | ||
692 | } | ||
693 | |||
694 | int kvm_arch_init_vcpu(CPUState *cs) | ||
695 | diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events | ||
696 | new file mode 100644 | ||
697 | index XXXXXXX..XXXXXXX | ||
698 | --- /dev/null | ||
699 | +++ b/target/loongarch/trace-events | ||
700 | @@ -XXX,XX +XXX,XX @@ | ||
701 | +# See docs/devel/tracing.rst for syntax documentation. | ||
702 | + | ||
703 | +#kvm.c | ||
704 | +kvm_failed_get_regs_core(const char *msg) "Failed to get core regs from KVM: %s" | ||
705 | +kvm_failed_put_regs_core(const char *msg) "Failed to put core regs into KVM: %s" | ||
706 | +kvm_failed_get_fpu(const char *msg) "Failed to get fpu from KVM: %s" | ||
707 | +kvm_failed_put_fpu(const char *msg) "Failed to put fpu into KVM: %s" | ||
708 | +kvm_failed_get_mpstate(const char *msg) "Failed to get mp_state from KVM: %s" | ||
709 | +kvm_failed_put_mpstate(const char *msg) "Failed to put mp_state into KVM: %s" | ||
710 | +kvm_failed_get_cpucfg(const char *msg) "Failed to get cpucfg from KVM: %s" | ||
711 | +kvm_failed_put_cpucfg(const char *msg) "Failed to put cpucfg into KVM: %s" | ||
712 | diff --git a/target/loongarch/trace.h b/target/loongarch/trace.h | ||
713 | new file mode 100644 | ||
714 | index XXXXXXX..XXXXXXX | ||
715 | --- /dev/null | ||
716 | +++ b/target/loongarch/trace.h | ||
717 | @@ -0,0 +1 @@ | ||
718 | +#include "trace/trace-target_loongarch.h" | ||
719 | -- | 67 | -- |
720 | 2.25.1 | 68 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 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. | ||
2 | 4 | ||
3 | Implement kvm_arch_handle_exit for loongarch. In this | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | function, the KVM_EXIT_LOONGARCH_IOCSR is handled, | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | we read or write the iocsr address space by the addr, | 7 | --- |
6 | length and is_write argument in kvm_run. | 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(-) | ||
7 | 12 | ||
8 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 13 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
9 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
12 | Message-Id: <20240105075804.1228596-8-zhaotianrui@loongson.cn> | ||
13 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
14 | --- | ||
15 | target/loongarch/kvm/kvm.c | 24 +++++++++++++++++++++++- | ||
16 | target/loongarch/trace-events | 1 + | ||
17 | 2 files changed, 24 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/loongarch/kvm/kvm.c | 15 | --- a/hw/intc/loongarch_pch_pic.c |
22 | +++ b/target/loongarch/kvm/kvm.c | 16 | +++ b/hw/intc/loongarch_pch_pic.c |
23 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_cpu_check_are_resettable(void) | 17 | @@ -XXX,XX +XXX,XX @@ |
24 | 18 | ||
25 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | 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) | ||
26 | { | 34 | { |
27 | - return 0; | 35 | uint64_t val; |
28 | + int ret = 0; | 36 | int irq; |
29 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); | 37 | @@ -XXX,XX +XXX,XX @@ static void pch_pic_update_irq(LoongArchPCHPIC *s, uint64_t mask, int level) |
30 | + CPULoongArchState *env = &cpu->env; | 38 | |
31 | + MemTxAttrs attrs = {}; | 39 | static void pch_pic_irq_handler(void *opaque, int irq, int level) |
32 | + | 40 | { |
33 | + attrs.requester_id = env_cpu(env)->cpu_index; | 41 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); |
34 | + | 42 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); |
35 | + trace_kvm_arch_handle_exit(run->exit_reason); | 43 | uint64_t mask = 1ULL << irq; |
36 | + switch (run->exit_reason) { | 44 | |
37 | + case KVM_EXIT_LOONGARCH_IOCSR: | 45 | assert(irq < s->irq_num); |
38 | + address_space_rw(&env->address_space_iocsr, | 46 | @@ -XXX,XX +XXX,XX @@ static void pch_pic_irq_handler(void *opaque, int irq, int level) |
39 | + run->iocsr_io.phys_addr, | 47 | static uint64_t loongarch_pch_pic_low_readw(void *opaque, hwaddr addr, |
40 | + attrs, | 48 | unsigned size) |
41 | + run->iocsr_io.data, | 49 | { |
42 | + run->iocsr_io.len, | 50 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); |
43 | + run->iocsr_io.is_write); | 51 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); |
44 | + break; | 52 | uint64_t val = 0; |
45 | + default: | 53 | uint32_t offset = addr & 0xfff; |
46 | + ret = -1; | 54 | |
47 | + warn_report("KVM: unknown exit reason %d", run->exit_reason); | 55 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_writew_val(uint64_t value, uint32_t target, bool hi) |
48 | + break; | 56 | static void loongarch_pch_pic_low_writew(void *opaque, hwaddr addr, |
49 | + } | 57 | uint64_t value, unsigned size) |
50 | + return ret; | 58 | { |
51 | } | 59 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); |
52 | 60 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | |
53 | void kvm_arch_accel_class_init(ObjectClass *oc) | 61 | uint32_t offset, old_valid, data = (uint32_t)value; |
54 | diff --git a/target/loongarch/trace-events b/target/loongarch/trace-events | 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 | ||
55 | index XXXXXXX..XXXXXXX 100644 | 110 | index XXXXXXX..XXXXXXX 100644 |
56 | --- a/target/loongarch/trace-events | 111 | --- a/hw/loongarch/virt.c |
57 | +++ b/target/loongarch/trace-events | 112 | +++ b/hw/loongarch/virt.c |
58 | @@ -XXX,XX +XXX,XX @@ kvm_failed_get_counter(const char *msg) "Failed to get counter from KVM: %s" | 113 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) |
59 | kvm_failed_put_counter(const char *msg) "Failed to put counter into KVM: %s" | 114 | /* Add Extend I/O Interrupt Controller node */ |
60 | kvm_failed_get_cpucfg(const char *msg) "Failed to get cpucfg from KVM: %s" | 115 | fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle); |
61 | kvm_failed_put_cpucfg(const char *msg) "Failed to put cpucfg into KVM: %s" | 116 | |
62 | +kvm_arch_handle_exit(int num) "kvm arch handle exit, the reason number: %d" | 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 */ | ||
63 | -- | 135 | -- |
64 | 2.25.1 | 136 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 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. | ||
2 | 4 | ||
3 | Define some functions in target/loongarch/kvm/kvm.c, | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | such as kvm_arch_put_registers, kvm_arch_get_registers | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | and kvm_arch_handle_exit, etc. which are needed by | 7 | --- |
6 | kvm/kvm-all.c. Now the most functions has no content | 8 | include/hw/intc/loongarch_extioi.h | 50 +------------------ |
7 | and they will be implemented in the next patches. | 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 | ||
8 | 12 | ||
9 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 13 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h |
10 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | 14 | index XXXXXXX..XXXXXXX 100644 |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 15 | --- a/include/hw/intc/loongarch_extioi.h |
12 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 16 | +++ b/include/hw/intc/loongarch_extioi.h |
13 | Message-Id: <20240105075804.1228596-3-zhaotianrui@loongson.cn> | 17 | @@ -XXX,XX +XXX,XX @@ |
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 18 | * Copyright (C) 2021 Loongson Technology Corporation Limited |
15 | --- | 19 | */ |
16 | target/loongarch/kvm/kvm.c | 131 +++++++++++++++++++++++++++++++++++++ | 20 | |
17 | 1 file changed, 131 insertions(+) | 21 | -#include "hw/sysbus.h" |
18 | create mode 100644 target/loongarch/kvm/kvm.c | 22 | -#include "hw/loongarch/virt.h" |
19 | 23 | - | |
20 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | 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 | ||
21 | new file mode 100644 | 78 | new file mode 100644 |
22 | index XXXXXXX..XXXXXXX | 79 | index XXXXXXX..XXXXXXX |
23 | --- /dev/null | 80 | --- /dev/null |
24 | +++ b/target/loongarch/kvm/kvm.c | 81 | +++ b/include/hw/intc/loongarch_extioi_common.h |
25 | @@ -XXX,XX +XXX,XX @@ | 82 | @@ -XXX,XX +XXX,XX @@ |
26 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | 83 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
27 | +/* | 84 | +/* |
28 | + * QEMU LoongArch KVM | 85 | + * LoongArch 3A5000 ext interrupt controller definitions |
29 | + * | 86 | + * Copyright (C) 2024 Loongson Technology Corporation Limited |
30 | + * Copyright (c) 2023 Loongson Technology Corporation Limited | ||
31 | + */ | 87 | + */ |
32 | + | 88 | + |
33 | +#include "qemu/osdep.h" | 89 | +#ifndef LOONGARCH_EXTIOI_COMMON_H |
34 | +#include <sys/ioctl.h> | 90 | +#define LOONGARCH_EXTIOI_COMMON_H |
35 | +#include <linux/kvm.h> | ||
36 | + | 91 | + |
37 | +#include "qemu/timer.h" | 92 | +#include "hw/sysbus.h" |
38 | +#include "qemu/error-report.h" | 93 | +#include "hw/loongarch/virt.h" |
39 | +#include "qemu/main-loop.h" | ||
40 | +#include "sysemu/sysemu.h" | ||
41 | +#include "sysemu/kvm.h" | ||
42 | +#include "sysemu/kvm_int.h" | ||
43 | +#include "hw/pci/pci.h" | ||
44 | +#include "exec/memattrs.h" | ||
45 | +#include "exec/address-spaces.h" | ||
46 | +#include "hw/boards.h" | ||
47 | +#include "hw/irq.h" | ||
48 | +#include "qemu/log.h" | ||
49 | +#include "hw/loader.h" | ||
50 | +#include "migration/migration.h" | ||
51 | +#include "sysemu/runstate.h" | ||
52 | +#include "cpu-csr.h" | ||
53 | +#include "kvm_loongarch.h" | ||
54 | + | 94 | + |
55 | +static bool cap_has_mp_state; | 95 | +#define LS3A_INTC_IP 8 |
56 | +const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | 96 | +#define EXTIOI_IRQS (256) |
57 | + KVM_CAP_LAST_INFO | 97 | +#define EXTIOI_IRQS_BITMAP_SIZE (256 / 8) |
58 | +}; | 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 | ||
59 | + | 105 | + |
60 | +int kvm_arch_get_registers(CPUState *cs) | 106 | +#define APIC_OFFSET 0x400 |
61 | +{ | 107 | +#define APIC_BASE (0x1000ULL + APIC_OFFSET) |
62 | + return 0; | 108 | +#define EXTIOI_NODETYPE_START (0x4a0 - APIC_OFFSET) |
63 | +} | 109 | +#define EXTIOI_NODETYPE_END (0x4c0 - APIC_OFFSET) |
64 | +int kvm_arch_put_registers(CPUState *cs, int level) | 110 | +#define EXTIOI_IPMAP_START (0x4c0 - APIC_OFFSET) |
65 | +{ | 111 | +#define EXTIOI_IPMAP_END (0x4c8 - APIC_OFFSET) |
66 | + return 0; | 112 | +#define EXTIOI_ENABLE_START (0x600 - APIC_OFFSET) |
67 | +} | 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 | ||
68 | + | 123 | + |
69 | +int kvm_arch_init_vcpu(CPUState *cs) | 124 | +#define EXTIOI_VIRT_BASE (0x40000000) |
70 | +{ | 125 | +#define EXTIOI_VIRT_SIZE (0x1000) |
71 | + return 0; | 126 | +#define EXTIOI_VIRT_FEATURES (0x0) |
72 | +} | 127 | +#define EXTIOI_HAS_VIRT_EXTENSION (0) |
73 | + | 128 | +#define EXTIOI_HAS_ENABLE_OPTION (1) |
74 | +int kvm_arch_destroy_vcpu(CPUState *cs) | 129 | +#define EXTIOI_HAS_INT_ENCODE (2) |
75 | +{ | 130 | +#define EXTIOI_HAS_CPU_ENCODE (3) |
76 | + return 0; | 131 | +#define EXTIOI_VIRT_HAS_FEATURES (BIT(EXTIOI_HAS_VIRT_EXTENSION) \ |
77 | +} | 132 | + | BIT(EXTIOI_HAS_ENABLE_OPTION) \ |
78 | + | 133 | + | BIT(EXTIOI_HAS_CPU_ENCODE)) |
79 | +unsigned long kvm_arch_vcpu_id(CPUState *cs) | 134 | +#define EXTIOI_VIRT_CONFIG (0x4) |
80 | +{ | 135 | +#define EXTIOI_ENABLE (1) |
81 | + return cs->cpu_index; | 136 | +#define EXTIOI_ENABLE_INT_ENCODE (2) |
82 | +} | 137 | +#define EXTIOI_ENABLE_CPU_ENCODE (3) |
83 | + | 138 | +#define EXTIOI_VIRT_COREMAP_START (0x40) |
84 | +int kvm_arch_release_virq_post(int virq) | 139 | +#define EXTIOI_VIRT_COREMAP_END (0x240) |
85 | +{ | 140 | +#endif /* LOONGARCH_EXTIOI_H */ |
86 | + return 0; | ||
87 | +} | ||
88 | + | ||
89 | +int kvm_arch_msi_data_to_gsi(uint32_t data) | ||
90 | +{ | ||
91 | + abort(); | ||
92 | +} | ||
93 | + | ||
94 | +int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, | ||
95 | + uint64_t address, uint32_t data, PCIDevice *dev) | ||
96 | +{ | ||
97 | + return 0; | ||
98 | +} | ||
99 | + | ||
100 | +int kvm_arch_add_msi_route_post(struct kvm_irq_routing_entry *route, | ||
101 | + int vector, PCIDevice *dev) | ||
102 | +{ | ||
103 | + return 0; | ||
104 | +} | ||
105 | + | ||
106 | +void kvm_arch_init_irq_routing(KVMState *s) | ||
107 | +{ | ||
108 | +} | ||
109 | + | ||
110 | +int kvm_arch_get_default_type(MachineState *ms) | ||
111 | +{ | ||
112 | + return 0; | ||
113 | +} | ||
114 | + | ||
115 | +int kvm_arch_init(MachineState *ms, KVMState *s) | ||
116 | +{ | ||
117 | + return 0; | ||
118 | +} | ||
119 | + | ||
120 | +int kvm_arch_irqchip_create(KVMState *s) | ||
121 | +{ | ||
122 | + return 0; | ||
123 | +} | ||
124 | + | ||
125 | +void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) | ||
126 | +{ | ||
127 | +} | ||
128 | + | ||
129 | +MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) | ||
130 | +{ | ||
131 | + return MEMTXATTRS_UNSPECIFIED; | ||
132 | +} | ||
133 | + | ||
134 | +int kvm_arch_process_async_events(CPUState *cs) | ||
135 | +{ | ||
136 | + return cs->halted; | ||
137 | +} | ||
138 | + | ||
139 | +bool kvm_arch_stop_on_emulation_error(CPUState *cs) | ||
140 | +{ | ||
141 | + return true; | ||
142 | +} | ||
143 | + | ||
144 | +bool kvm_arch_cpu_check_are_resettable(void) | ||
145 | +{ | ||
146 | + return true; | ||
147 | +} | ||
148 | + | ||
149 | +int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
150 | +{ | ||
151 | + return 0; | ||
152 | +} | ||
153 | + | ||
154 | +void kvm_arch_accel_class_init(ObjectClass *oc) | ||
155 | +{ | ||
156 | +} | ||
157 | -- | 141 | -- |
158 | 2.25.1 | 142 | 2.43.5 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | ||
2 | 1 | ||
3 | Supplement vcpu env initial when vcpu reset, including | ||
4 | init vcpu CSR_CPUID,CSR_TID to cpu->cpu_index. The two | ||
5 | regs will be used in kvm_get/set_csr_ioctl. | ||
6 | |||
7 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | ||
8 | Signed-off-by: xianglai li <lixianglai@loongson.cn> | ||
9 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
10 | Message-Id: <20240105075804.1228596-4-zhaotianrui@loongson.cn> | ||
11 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
12 | --- | ||
13 | target/loongarch/cpu.c | 2 ++ | ||
14 | target/loongarch/cpu.h | 2 +- | ||
15 | 2 files changed, 3 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/loongarch/cpu.c | ||
20 | +++ b/target/loongarch/cpu.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_reset_hold(Object *obj) | ||
22 | |||
23 | env->CSR_ESTAT = env->CSR_ESTAT & (~MAKE_64BIT_MASK(0, 2)); | ||
24 | env->CSR_RVACFG = FIELD_DP64(env->CSR_RVACFG, CSR_RVACFG, RBITS, 0); | ||
25 | + env->CSR_CPUID = cs->cpu_index; | ||
26 | env->CSR_TCFG = FIELD_DP64(env->CSR_TCFG, CSR_TCFG, EN, 0); | ||
27 | env->CSR_LLBCTL = FIELD_DP64(env->CSR_LLBCTL, CSR_LLBCTL, KLO, 0); | ||
28 | env->CSR_TLBRERA = FIELD_DP64(env->CSR_TLBRERA, CSR_TLBRERA, ISTLBR, 0); | ||
29 | env->CSR_MERRCTL = FIELD_DP64(env->CSR_MERRCTL, CSR_MERRCTL, ISMERR, 0); | ||
30 | + env->CSR_TID = cs->cpu_index; | ||
31 | |||
32 | env->CSR_PRCFG3 = FIELD_DP64(env->CSR_PRCFG3, CSR_PRCFG3, TLB_TYPE, 2); | ||
33 | env->CSR_PRCFG3 = FIELD_DP64(env->CSR_PRCFG3, CSR_PRCFG3, MTLB_ENTRY, 63); | ||
34 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/loongarch/cpu.h | ||
37 | +++ b/target/loongarch/cpu.h | ||
38 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
39 | uint64_t CSR_PWCH; | ||
40 | uint64_t CSR_STLBPS; | ||
41 | uint64_t CSR_RVACFG; | ||
42 | + uint64_t CSR_CPUID; | ||
43 | uint64_t CSR_PRCFG1; | ||
44 | uint64_t CSR_PRCFG2; | ||
45 | uint64_t CSR_PRCFG3; | ||
46 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
47 | uint64_t CSR_DBG; | ||
48 | uint64_t CSR_DERA; | ||
49 | uint64_t CSR_DSAVE; | ||
50 | - uint64_t CSR_CPUID; | ||
51 | |||
52 | #ifndef CONFIG_USER_ONLY | ||
53 | LoongArchTLB tlb[LOONGARCH_TLB_MAX]; | ||
54 | -- | ||
55 | 2.25.1 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | Move definiton of structure LoongArchExtIOI from header file loongarch_extioi.h |
---|---|---|---|
2 | 2 | to file loongarch_extioi_common.h. | |
3 | On LoongArch physical machine, one extioi interrupt controller only | ||
4 | supports 4 cpus. With processor more than 4 cpus, there are multiple | ||
5 | extioi interrupt controllers; if interrupts need to be routed to | ||
6 | other cpus, they are forwarded from extioi node0 to other extioi nodes. | ||
7 | |||
8 | On virt machine model, there is simple extioi interrupt device model. | ||
9 | All cpus can access register of extioi interrupt controller, however | ||
10 | interrupt can only be route to 4 vcpu for compatible with old kernel. | ||
11 | |||
12 | This patch adds dynamic cpu number support about extioi interrupt. | ||
13 | With old kernel legacy extioi model is used, however kernel can detect | ||
14 | and choose new route method in future, so that interrupt can be routed to | ||
15 | all vcpus. | ||
16 | 3 | ||
17 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
18 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
19 | Message-Id: <20231215100333.3933632-4-maobibo@loongson.cn> | ||
20 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
21 | --- | 6 | --- |
22 | hw/intc/loongarch_extioi.c | 107 +++++++++++++++++++---------- | 7 | include/hw/intc/loongarch_extioi.h | 26 ---------------------- |
23 | hw/loongarch/virt.c | 3 +- | 8 | include/hw/intc/loongarch_extioi_common.h | 27 +++++++++++++++++++++++ |
24 | include/hw/intc/loongarch_extioi.h | 11 ++- | 9 | 2 files changed, 27 insertions(+), 26 deletions(-) |
25 | 3 files changed, 81 insertions(+), 40 deletions(-) | ||
26 | 10 | ||
27 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/hw/intc/loongarch_extioi.c | ||
30 | +++ b/hw/intc/loongarch_extioi.c | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | #include "qemu/osdep.h" | ||
33 | #include "qemu/module.h" | ||
34 | #include "qemu/log.h" | ||
35 | +#include "qapi/error.h" | ||
36 | #include "hw/irq.h" | ||
37 | #include "hw/sysbus.h" | ||
38 | #include "hw/loongarch/virt.h" | ||
39 | @@ -XXX,XX +XXX,XX @@ static void extioi_update_irq(LoongArchExtIOI *s, int irq, int level) | ||
40 | if (((s->enable[irq_index]) & irq_mask) == 0) { | ||
41 | return; | ||
42 | } | ||
43 | - s->coreisr[cpu][irq_index] |= irq_mask; | ||
44 | - found = find_first_bit(s->sw_isr[cpu][ipnum], EXTIOI_IRQS); | ||
45 | - set_bit(irq, s->sw_isr[cpu][ipnum]); | ||
46 | + s->cpu[cpu].coreisr[irq_index] |= irq_mask; | ||
47 | + found = find_first_bit(s->cpu[cpu].sw_isr[ipnum], EXTIOI_IRQS); | ||
48 | + set_bit(irq, s->cpu[cpu].sw_isr[ipnum]); | ||
49 | if (found < EXTIOI_IRQS) { | ||
50 | /* other irq is handling, need not update parent irq level */ | ||
51 | return; | ||
52 | } | ||
53 | } else { | ||
54 | - s->coreisr[cpu][irq_index] &= ~irq_mask; | ||
55 | - clear_bit(irq, s->sw_isr[cpu][ipnum]); | ||
56 | - found = find_first_bit(s->sw_isr[cpu][ipnum], EXTIOI_IRQS); | ||
57 | + s->cpu[cpu].coreisr[irq_index] &= ~irq_mask; | ||
58 | + clear_bit(irq, s->cpu[cpu].sw_isr[ipnum]); | ||
59 | + found = find_first_bit(s->cpu[cpu].sw_isr[ipnum], EXTIOI_IRQS); | ||
60 | if (found < EXTIOI_IRQS) { | ||
61 | /* other irq is handling, need not update parent irq level */ | ||
62 | return; | ||
63 | } | ||
64 | } | ||
65 | - qemu_set_irq(s->parent_irq[cpu][ipnum], level); | ||
66 | + qemu_set_irq(s->cpu[cpu].parent_irq[ipnum], level); | ||
67 | } | ||
68 | |||
69 | static void extioi_setirq(void *opaque, int irq, int level) | ||
70 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data, | ||
71 | index = (offset - EXTIOI_COREISR_START) >> 2; | ||
72 | /* using attrs to get current cpu index */ | ||
73 | cpu = attrs.requester_id; | ||
74 | - *data = s->coreisr[cpu][index]; | ||
75 | + *data = s->cpu[cpu].coreisr[index]; | ||
76 | break; | ||
77 | case EXTIOI_COREMAP_START ... EXTIOI_COREMAP_END - 1: | ||
78 | index = (offset - EXTIOI_COREMAP_START) >> 2; | ||
79 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_writew(void *opaque, hwaddr addr, | ||
80 | index = (offset - EXTIOI_COREISR_START) >> 2; | ||
81 | /* using attrs to get current cpu index */ | ||
82 | cpu = attrs.requester_id; | ||
83 | - old_data = s->coreisr[cpu][index]; | ||
84 | - s->coreisr[cpu][index] = old_data & ~val; | ||
85 | + old_data = s->cpu[cpu].coreisr[index]; | ||
86 | + s->cpu[cpu].coreisr[index] = old_data & ~val; | ||
87 | /* write 1 to clear interrupt */ | ||
88 | old_data &= val; | ||
89 | irq = ctz32(old_data); | ||
90 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps extioi_ops = { | ||
91 | .endianness = DEVICE_LITTLE_ENDIAN, | ||
92 | }; | ||
93 | |||
94 | -static const VMStateDescription vmstate_loongarch_extioi = { | ||
95 | - .name = TYPE_LOONGARCH_EXTIOI, | ||
96 | +static void loongarch_extioi_realize(DeviceState *dev, Error **errp) | ||
97 | +{ | ||
98 | + LoongArchExtIOI *s = LOONGARCH_EXTIOI(dev); | ||
99 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
100 | + int i, pin; | ||
101 | + | ||
102 | + if (s->num_cpu == 0) { | ||
103 | + error_setg(errp, "num-cpu must be at least 1"); | ||
104 | + return; | ||
105 | + } | ||
106 | + | ||
107 | + for (i = 0; i < EXTIOI_IRQS; i++) { | ||
108 | + sysbus_init_irq(sbd, &s->irq[i]); | ||
109 | + } | ||
110 | + | ||
111 | + qdev_init_gpio_in(dev, extioi_setirq, EXTIOI_IRQS); | ||
112 | + memory_region_init_io(&s->extioi_system_mem, OBJECT(s), &extioi_ops, | ||
113 | + s, "extioi_system_mem", 0x900); | ||
114 | + sysbus_init_mmio(sbd, &s->extioi_system_mem); | ||
115 | + s->cpu = g_new0(ExtIOICore, s->num_cpu); | ||
116 | + if (s->cpu == NULL) { | ||
117 | + error_setg(errp, "Memory allocation for ExtIOICore faile"); | ||
118 | + return; | ||
119 | + } | ||
120 | + | ||
121 | + for (i = 0; i < s->num_cpu; i++) { | ||
122 | + for (pin = 0; pin < LS3A_INTC_IP; pin++) { | ||
123 | + qdev_init_gpio_out(dev, &s->cpu[i].parent_irq[pin], 1); | ||
124 | + } | ||
125 | + } | ||
126 | +} | ||
127 | + | ||
128 | +static void loongarch_extioi_finalize(Object *obj) | ||
129 | +{ | ||
130 | + LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj); | ||
131 | + | ||
132 | + g_free(s->cpu); | ||
133 | +} | ||
134 | + | ||
135 | +static const VMStateDescription vmstate_extioi_core = { | ||
136 | + .name = "extioi-core", | ||
137 | .version_id = 1, | ||
138 | .minimum_version_id = 1, | ||
139 | + .fields = (const VMStateField[]) { | ||
140 | + VMSTATE_UINT32_ARRAY(coreisr, ExtIOICore, EXTIOI_IRQS_GROUP_COUNT), | ||
141 | + VMSTATE_END_OF_LIST() | ||
142 | + } | ||
143 | +}; | ||
144 | + | ||
145 | +static const VMStateDescription vmstate_loongarch_extioi = { | ||
146 | + .name = TYPE_LOONGARCH_EXTIOI, | ||
147 | + .version_id = 2, | ||
148 | + .minimum_version_id = 2, | ||
149 | .fields = (const VMStateField[]) { | ||
150 | VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOI, EXTIOI_IRQS_GROUP_COUNT), | ||
151 | - VMSTATE_UINT32_2DARRAY(coreisr, LoongArchExtIOI, EXTIOI_CPUS, | ||
152 | - EXTIOI_IRQS_GROUP_COUNT), | ||
153 | VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOI, | ||
154 | EXTIOI_IRQS_NODETYPE_COUNT / 2), | ||
155 | VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOI, EXTIOI_IRQS / 32), | ||
156 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_extioi = { | ||
157 | VMSTATE_UINT8_ARRAY(sw_ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE), | ||
158 | VMSTATE_UINT8_ARRAY(sw_coremap, LoongArchExtIOI, EXTIOI_IRQS), | ||
159 | |||
160 | + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOI, num_cpu, | ||
161 | + vmstate_extioi_core, ExtIOICore), | ||
162 | VMSTATE_END_OF_LIST() | ||
163 | } | ||
164 | }; | ||
165 | |||
166 | -static void loongarch_extioi_instance_init(Object *obj) | ||
167 | -{ | ||
168 | - SysBusDevice *dev = SYS_BUS_DEVICE(obj); | ||
169 | - LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj); | ||
170 | - int i, cpu, pin; | ||
171 | - | ||
172 | - for (i = 0; i < EXTIOI_IRQS; i++) { | ||
173 | - sysbus_init_irq(dev, &s->irq[i]); | ||
174 | - } | ||
175 | - | ||
176 | - qdev_init_gpio_in(DEVICE(obj), extioi_setirq, EXTIOI_IRQS); | ||
177 | - | ||
178 | - for (cpu = 0; cpu < EXTIOI_CPUS; cpu++) { | ||
179 | - for (pin = 0; pin < LS3A_INTC_IP; pin++) { | ||
180 | - qdev_init_gpio_out(DEVICE(obj), &s->parent_irq[cpu][pin], 1); | ||
181 | - } | ||
182 | - } | ||
183 | - memory_region_init_io(&s->extioi_system_mem, OBJECT(s), &extioi_ops, | ||
184 | - s, "extioi_system_mem", 0x900); | ||
185 | - sysbus_init_mmio(dev, &s->extioi_system_mem); | ||
186 | -} | ||
187 | +static Property extioi_properties[] = { | ||
188 | + DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOI, num_cpu, 1), | ||
189 | + DEFINE_PROP_END_OF_LIST(), | ||
190 | +}; | ||
191 | |||
192 | static void loongarch_extioi_class_init(ObjectClass *klass, void *data) | ||
193 | { | ||
194 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
195 | |||
196 | + dc->realize = loongarch_extioi_realize; | ||
197 | + device_class_set_props(dc, extioi_properties); | ||
198 | dc->vmsd = &vmstate_loongarch_extioi; | ||
199 | } | ||
200 | |||
201 | static const TypeInfo loongarch_extioi_info = { | ||
202 | .name = TYPE_LOONGARCH_EXTIOI, | ||
203 | .parent = TYPE_SYS_BUS_DEVICE, | ||
204 | - .instance_init = loongarch_extioi_instance_init, | ||
205 | .instance_size = sizeof(struct LoongArchExtIOI), | ||
206 | .class_init = loongarch_extioi_class_init, | ||
207 | + .instance_finalize = loongarch_extioi_finalize, | ||
208 | }; | ||
209 | |||
210 | static void loongarch_extioi_register_types(void) | ||
211 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
212 | index XXXXXXX..XXXXXXX 100644 | ||
213 | --- a/hw/loongarch/virt.c | ||
214 | +++ b/hw/loongarch/virt.c | ||
215 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
216 | |||
217 | /* Create EXTIOI device */ | ||
218 | extioi = qdev_new(TYPE_LOONGARCH_EXTIOI); | ||
219 | + qdev_prop_set_uint32(extioi, "num-cpu", ms->smp.cpus); | ||
220 | sysbus_realize_and_unref(SYS_BUS_DEVICE(extioi), &error_fatal); | ||
221 | memory_region_add_subregion(&lams->system_iocsr, APIC_BASE, | ||
222 | sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi), 0)); | ||
223 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
224 | * connect ext irq to the cpu irq | ||
225 | * cpu_pin[9:2] <= intc_pin[7:0] | ||
226 | */ | ||
227 | - for (cpu = 0; cpu < MIN(ms->smp.cpus, EXTIOI_CPUS); cpu++) { | ||
228 | + for (cpu = 0; cpu < ms->smp.cpus; cpu++) { | ||
229 | cpudev = DEVICE(qemu_get_cpu(cpu)); | ||
230 | for (pin = 0; pin < LS3A_INTC_IP; pin++) { | ||
231 | qdev_connect_gpio_out(extioi, (cpu * 8 + pin), | ||
232 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h | 11 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h |
233 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
234 | --- a/include/hw/intc/loongarch_extioi.h | 13 | --- a/include/hw/intc/loongarch_extioi.h |
235 | +++ b/include/hw/intc/loongarch_extioi.h | 14 | +++ b/include/hw/intc/loongarch_extioi.h |
236 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ |
237 | #define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET) | 16 | |
238 | #define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET) | 17 | #include "hw/intc/loongarch_extioi_common.h" |
239 | 18 | ||
19 | -typedef struct ExtIOICore { | ||
20 | - uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; | ||
21 | - DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); | ||
22 | - qemu_irq parent_irq[LS3A_INTC_IP]; | ||
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 | + | ||
240 | +typedef struct ExtIOICore { | 57 | +typedef struct ExtIOICore { |
241 | + uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; | 58 | + uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; |
242 | + DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); | 59 | + DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); |
243 | + qemu_irq parent_irq[LS3A_INTC_IP]; | 60 | + qemu_irq parent_irq[LS3A_INTC_IP]; |
244 | +} ExtIOICore; | 61 | +} ExtIOICore; |
245 | + | 62 | + |
246 | #define TYPE_LOONGARCH_EXTIOI "loongarch.extioi" | 63 | +struct LoongArchExtIOI { |
247 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI) | 64 | + SysBusDevice parent_obj; |
248 | struct LoongArchExtIOI { | ||
249 | SysBusDevice parent_obj; | ||
250 | + uint32_t num_cpu; | 65 | + uint32_t num_cpu; |
251 | /* hardware state */ | 66 | + uint32_t features; |
252 | uint32_t nodetype[EXTIOI_IRQS_NODETYPE_COUNT / 2]; | 67 | + uint32_t status; |
253 | uint32_t bounce[EXTIOI_IRQS_GROUP_COUNT]; | 68 | + /* hardware state */ |
254 | uint32_t isr[EXTIOI_IRQS / 32]; | 69 | + uint32_t nodetype[EXTIOI_IRQS_NODETYPE_COUNT / 2]; |
255 | - uint32_t coreisr[EXTIOI_CPUS][EXTIOI_IRQS_GROUP_COUNT]; | 70 | + uint32_t bounce[EXTIOI_IRQS_GROUP_COUNT]; |
256 | uint32_t enable[EXTIOI_IRQS / 32]; | 71 | + uint32_t isr[EXTIOI_IRQS / 32]; |
257 | uint32_t ipmap[EXTIOI_IRQS_IPMAP_SIZE / 4]; | 72 | + uint32_t enable[EXTIOI_IRQS / 32]; |
258 | uint32_t coremap[EXTIOI_IRQS / 4]; | 73 | + uint32_t ipmap[EXTIOI_IRQS_IPMAP_SIZE / 4]; |
259 | uint32_t sw_pending[EXTIOI_IRQS / 32]; | 74 | + uint32_t coremap[EXTIOI_IRQS / 4]; |
260 | - DECLARE_BITMAP(sw_isr[EXTIOI_CPUS][LS3A_INTC_IP], EXTIOI_IRQS); | 75 | + uint32_t sw_pending[EXTIOI_IRQS / 32]; |
261 | uint8_t sw_ipmap[EXTIOI_IRQS_IPMAP_SIZE]; | 76 | + uint8_t sw_ipmap[EXTIOI_IRQS_IPMAP_SIZE]; |
262 | uint8_t sw_coremap[EXTIOI_IRQS]; | 77 | + uint8_t sw_coremap[EXTIOI_IRQS]; |
263 | - qemu_irq parent_irq[EXTIOI_CPUS][LS3A_INTC_IP]; | 78 | + qemu_irq irq[EXTIOI_IRQS]; |
264 | qemu_irq irq[EXTIOI_IRQS]; | ||
265 | + ExtIOICore *cpu; | 79 | + ExtIOICore *cpu; |
266 | MemoryRegion extioi_system_mem; | 80 | + MemoryRegion extioi_system_mem; |
267 | }; | 81 | + MemoryRegion virt_extend; |
82 | +}; | ||
268 | #endif /* LOONGARCH_EXTIOI_H */ | 83 | #endif /* LOONGARCH_EXTIOI_H */ |
269 | -- | 84 | -- |
270 | 2.25.1 | 85 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | Rename structure LoongArchExtIOI with LoongArchExtIOICommonState, |
---|---|---|---|
2 | 2 | since it is defined in file loongarch_extioi_common.h | |
3 | LoongArch system has iocsr address space, most iocsr registers are | ||
4 | per-board, however some iocsr register spaces banked for percpu such | ||
5 | as ipi mailbox and extioi interrupt status. For banked iocsr space, | ||
6 | each cpu has the same iocsr space, but separate data. | ||
7 | |||
8 | This patch changes iocsr address space per-board rather percpu, | ||
9 | for iocsr registers specified for cpu, MemTxAttrs.requester_id | ||
10 | can be parsed for the cpu. With this patches, the total address space | ||
11 | on board will be simple, only iocsr address space and system memory, | ||
12 | rather than the number of cpu and system memory. | ||
13 | 3 | ||
14 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
15 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
16 | Message-Id: <20231215100333.3933632-3-maobibo@loongson.cn> | ||
17 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
18 | --- | 6 | --- |
19 | hw/intc/loongarch_extioi.c | 3 - | 7 | include/hw/intc/loongarch_extioi.h | 1 + |
20 | hw/intc/loongarch_ipi.c | 61 ++++++++++++++----- | 8 | include/hw/intc/loongarch_extioi_common.h | 2 +- |
21 | hw/loongarch/virt.c | 91 +++++++++++++++++++++-------- | 9 | 2 files changed, 2 insertions(+), 1 deletion(-) |
22 | include/hw/intc/loongarch_extioi.h | 1 - | ||
23 | include/hw/intc/loongarch_ipi.h | 3 +- | ||
24 | include/hw/loongarch/virt.h | 3 + | ||
25 | target/loongarch/cpu.c | 48 --------------- | ||
26 | target/loongarch/cpu.h | 4 +- | ||
27 | target/loongarch/kvm/kvm.c | 2 +- | ||
28 | target/loongarch/tcg/iocsr_helper.c | 16 ++--- | ||
29 | 10 files changed, 128 insertions(+), 104 deletions(-) | ||
30 | 10 | ||
31 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/hw/intc/loongarch_extioi.c | ||
34 | +++ b/hw/intc/loongarch_extioi.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static void loongarch_extioi_instance_init(Object *obj) | ||
36 | qdev_init_gpio_in(DEVICE(obj), extioi_setirq, EXTIOI_IRQS); | ||
37 | |||
38 | for (cpu = 0; cpu < EXTIOI_CPUS; cpu++) { | ||
39 | - memory_region_init_io(&s->extioi_iocsr_mem[cpu], OBJECT(s), &extioi_ops, | ||
40 | - s, "extioi_iocsr", 0x900); | ||
41 | - sysbus_init_mmio(dev, &s->extioi_iocsr_mem[cpu]); | ||
42 | for (pin = 0; pin < LS3A_INTC_IP; pin++) { | ||
43 | qdev_init_gpio_out(DEVICE(obj), &s->parent_irq[cpu][pin], 1); | ||
44 | } | ||
45 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/hw/intc/loongarch_ipi.c | ||
48 | +++ b/hw/intc/loongarch_ipi.c | ||
49 | @@ -XXX,XX +XXX,XX @@ | ||
50 | #include "hw/sysbus.h" | ||
51 | #include "hw/intc/loongarch_ipi.h" | ||
52 | #include "hw/irq.h" | ||
53 | +#include "hw/qdev-properties.h" | ||
54 | #include "qapi/error.h" | ||
55 | #include "qemu/log.h" | ||
56 | #include "exec/address-spaces.h" | ||
57 | @@ -XXX,XX +XXX,XX @@ static MemTxResult loongarch_ipi_readl(void *opaque, hwaddr addr, | ||
58 | uint64_t ret = 0; | ||
59 | int index = 0; | ||
60 | |||
61 | - s = &ipi->ipi_core; | ||
62 | + s = &ipi->cpu[attrs.requester_id]; | ||
63 | addr &= 0xff; | ||
64 | switch (addr) { | ||
65 | case CORE_STATUS_OFF: | ||
66 | @@ -XXX,XX +XXX,XX @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr, | ||
67 | * if the mask is 0, we need not to do anything. | ||
68 | */ | ||
69 | if ((val >> 27) & 0xf) { | ||
70 | - data = address_space_ldl(&env->address_space_iocsr, addr, | ||
71 | + data = address_space_ldl(env->address_space_iocsr, addr, | ||
72 | attrs, NULL); | ||
73 | for (i = 0; i < 4; i++) { | ||
74 | /* get mask for byte writing */ | ||
75 | @@ -XXX,XX +XXX,XX @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr, | ||
76 | |||
77 | data &= mask; | ||
78 | data |= (val >> 32) & ~mask; | ||
79 | - address_space_stl(&env->address_space_iocsr, addr, | ||
80 | + address_space_stl(env->address_space_iocsr, addr, | ||
81 | data, attrs, NULL); | ||
82 | } | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static MemTxResult loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val, | ||
85 | uint8_t vector; | ||
86 | CPUState *cs; | ||
87 | |||
88 | - s = &ipi->ipi_core; | ||
89 | + s = &ipi->cpu[attrs.requester_id]; | ||
90 | addr &= 0xff; | ||
91 | trace_loongarch_ipi_write(size, (uint64_t)addr, val); | ||
92 | switch (addr) { | ||
93 | @@ -XXX,XX +XXX,XX @@ static MemTxResult loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val, | ||
94 | |||
95 | /* override requester_id */ | ||
96 | attrs.requester_id = cs->cpu_index; | ||
97 | - ipi = LOONGARCH_IPI(LOONGARCH_CPU(cs)->env.ipistate); | ||
98 | loongarch_ipi_writel(ipi, CORE_SET_OFF, BIT(vector), 4, attrs); | ||
99 | break; | ||
100 | default: | ||
101 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps loongarch_ipi64_ops = { | ||
102 | .endianness = DEVICE_LITTLE_ENDIAN, | ||
103 | }; | ||
104 | |||
105 | -static void loongarch_ipi_init(Object *obj) | ||
106 | +static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
107 | { | ||
108 | - LoongArchIPI *s = LOONGARCH_IPI(obj); | ||
109 | - SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
110 | + LoongArchIPI *s = LOONGARCH_IPI(dev); | ||
111 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
112 | + int i; | ||
113 | + | ||
114 | + if (s->num_cpu == 0) { | ||
115 | + error_setg(errp, "num-cpu must be at least 1"); | ||
116 | + return; | ||
117 | + } | ||
118 | |||
119 | - memory_region_init_io(&s->ipi_iocsr_mem, obj, &loongarch_ipi_ops, | ||
120 | + memory_region_init_io(&s->ipi_iocsr_mem, OBJECT(dev), &loongarch_ipi_ops, | ||
121 | s, "loongarch_ipi_iocsr", 0x48); | ||
122 | |||
123 | /* loongarch_ipi_iocsr performs re-entrant IO through ipi_send */ | ||
124 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_init(Object *obj) | ||
125 | |||
126 | sysbus_init_mmio(sbd, &s->ipi_iocsr_mem); | ||
127 | |||
128 | - memory_region_init_io(&s->ipi64_iocsr_mem, obj, &loongarch_ipi64_ops, | ||
129 | + memory_region_init_io(&s->ipi64_iocsr_mem, OBJECT(dev), | ||
130 | + &loongarch_ipi64_ops, | ||
131 | s, "loongarch_ipi64_iocsr", 0x118); | ||
132 | sysbus_init_mmio(sbd, &s->ipi64_iocsr_mem); | ||
133 | - qdev_init_gpio_out(DEVICE(obj), &s->ipi_core.irq, 1); | ||
134 | + | ||
135 | + s->cpu = g_new0(IPICore, s->num_cpu); | ||
136 | + if (s->cpu == NULL) { | ||
137 | + error_setg(errp, "Memory allocation for ExtIOICore faile"); | ||
138 | + return; | ||
139 | + } | ||
140 | + | ||
141 | + for (i = 0; i < s->num_cpu; i++) { | ||
142 | + qdev_init_gpio_out(dev, &s->cpu[i].irq, 1); | ||
143 | + } | ||
144 | } | ||
145 | |||
146 | static const VMStateDescription vmstate_ipi_core = { | ||
147 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_ipi_core = { | ||
148 | |||
149 | static const VMStateDescription vmstate_loongarch_ipi = { | ||
150 | .name = TYPE_LOONGARCH_IPI, | ||
151 | - .version_id = 1, | ||
152 | - .minimum_version_id = 1, | ||
153 | + .version_id = 2, | ||
154 | + .minimum_version_id = 2, | ||
155 | .fields = (const VMStateField[]) { | ||
156 | - VMSTATE_STRUCT(ipi_core, LoongArchIPI, 0, vmstate_ipi_core, IPICore), | ||
157 | + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchIPI, num_cpu, | ||
158 | + vmstate_ipi_core, IPICore), | ||
159 | VMSTATE_END_OF_LIST() | ||
160 | } | ||
161 | }; | ||
162 | |||
163 | +static Property ipi_properties[] = { | ||
164 | + DEFINE_PROP_UINT32("num-cpu", LoongArchIPI, num_cpu, 1), | ||
165 | + DEFINE_PROP_END_OF_LIST(), | ||
166 | +}; | ||
167 | + | ||
168 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
169 | { | ||
170 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
171 | |||
172 | + dc->realize = loongarch_ipi_realize; | ||
173 | + device_class_set_props(dc, ipi_properties); | ||
174 | dc->vmsd = &vmstate_loongarch_ipi; | ||
175 | } | ||
176 | |||
177 | +static void loongarch_ipi_finalize(Object *obj) | ||
178 | +{ | ||
179 | + LoongArchIPI *s = LOONGARCH_IPI(obj); | ||
180 | + | ||
181 | + g_free(s->cpu); | ||
182 | +} | ||
183 | + | ||
184 | static const TypeInfo loongarch_ipi_info = { | ||
185 | .name = TYPE_LOONGARCH_IPI, | ||
186 | .parent = TYPE_SYS_BUS_DEVICE, | ||
187 | .instance_size = sizeof(LoongArchIPI), | ||
188 | - .instance_init = loongarch_ipi_init, | ||
189 | .class_init = loongarch_ipi_class_init, | ||
190 | + .instance_finalize = loongarch_ipi_finalize, | ||
191 | }; | ||
192 | |||
193 | static void loongarch_ipi_register_types(void) | ||
194 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
195 | index XXXXXXX..XXXXXXX 100644 | ||
196 | --- a/hw/loongarch/virt.c | ||
197 | +++ b/hw/loongarch/virt.c | ||
198 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
199 | CPUState *cpu_state; | ||
200 | int cpu, pin, i, start, num; | ||
201 | |||
202 | - extioi = qdev_new(TYPE_LOONGARCH_EXTIOI); | ||
203 | - sysbus_realize_and_unref(SYS_BUS_DEVICE(extioi), &error_fatal); | ||
204 | - | ||
205 | /* | ||
206 | * The connection of interrupts: | ||
207 | * +-----+ +---------+ +-------+ | ||
208 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
209 | * | UARTs | | Devices | | Devices | | ||
210 | * +--------+ +---------+ +---------+ | ||
211 | */ | ||
212 | + | ||
213 | + /* Create IPI device */ | ||
214 | + ipi = qdev_new(TYPE_LOONGARCH_IPI); | ||
215 | + qdev_prop_set_uint32(ipi, "num-cpu", ms->smp.cpus); | ||
216 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(ipi), &error_fatal); | ||
217 | + | ||
218 | + /* IPI iocsr memory region */ | ||
219 | + memory_region_add_subregion(&lams->system_iocsr, SMP_IPI_MAILBOX, | ||
220 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 0)); | ||
221 | + memory_region_add_subregion(&lams->system_iocsr, MAIL_SEND_ADDR, | ||
222 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 1)); | ||
223 | + | ||
224 | for (cpu = 0; cpu < ms->smp.cpus; cpu++) { | ||
225 | cpu_state = qemu_get_cpu(cpu); | ||
226 | cpudev = DEVICE(cpu_state); | ||
227 | lacpu = LOONGARCH_CPU(cpu_state); | ||
228 | env = &(lacpu->env); | ||
229 | - | ||
230 | - ipi = qdev_new(TYPE_LOONGARCH_IPI); | ||
231 | - sysbus_realize_and_unref(SYS_BUS_DEVICE(ipi), &error_fatal); | ||
232 | + env->address_space_iocsr = &lams->as_iocsr; | ||
233 | |||
234 | /* connect ipi irq to cpu irq */ | ||
235 | - qdev_connect_gpio_out(ipi, 0, qdev_get_gpio_in(cpudev, IRQ_IPI)); | ||
236 | - /* IPI iocsr memory region */ | ||
237 | - memory_region_add_subregion(&env->system_iocsr, SMP_IPI_MAILBOX, | ||
238 | - sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), | ||
239 | - 0)); | ||
240 | - memory_region_add_subregion(&env->system_iocsr, MAIL_SEND_ADDR, | ||
241 | - sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), | ||
242 | - 1)); | ||
243 | - /* | ||
244 | - * extioi iocsr memory region | ||
245 | - * only one extioi is added on loongarch virt machine | ||
246 | - * external device interrupt can only be routed to cpu 0-3 | ||
247 | - */ | ||
248 | - if (cpu < EXTIOI_CPUS) | ||
249 | - memory_region_add_subregion(&env->system_iocsr, APIC_BASE, | ||
250 | - sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi), | ||
251 | - cpu)); | ||
252 | + qdev_connect_gpio_out(ipi, cpu, qdev_get_gpio_in(cpudev, IRQ_IPI)); | ||
253 | env->ipistate = ipi; | ||
254 | } | ||
255 | |||
256 | + /* Create EXTIOI device */ | ||
257 | + extioi = qdev_new(TYPE_LOONGARCH_EXTIOI); | ||
258 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(extioi), &error_fatal); | ||
259 | + memory_region_add_subregion(&lams->system_iocsr, APIC_BASE, | ||
260 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi), 0)); | ||
261 | + | ||
262 | /* | ||
263 | * connect ext irq to the cpu irq | ||
264 | * cpu_pin[9:2] <= intc_pin[7:0] | ||
265 | @@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(LoongArchMachineState *lams, | ||
266 | } | ||
267 | } | ||
268 | |||
269 | +static void loongarch_qemu_write(void *opaque, hwaddr addr, | ||
270 | + uint64_t val, unsigned size) | ||
271 | +{ | ||
272 | +} | ||
273 | + | ||
274 | +static uint64_t loongarch_qemu_read(void *opaque, hwaddr addr, unsigned size) | ||
275 | +{ | ||
276 | + switch (addr) { | ||
277 | + case VERSION_REG: | ||
278 | + return 0x11ULL; | ||
279 | + case FEATURE_REG: | ||
280 | + return 1ULL << IOCSRF_MSI | 1ULL << IOCSRF_EXTIOI | | ||
281 | + 1ULL << IOCSRF_CSRIPI; | ||
282 | + case VENDOR_REG: | ||
283 | + return 0x6e6f73676e6f6f4cULL; /* "Loongson" */ | ||
284 | + case CPUNAME_REG: | ||
285 | + return 0x303030354133ULL; /* "3A5000" */ | ||
286 | + case MISC_FUNC_REG: | ||
287 | + return 1ULL << IOCSRM_EXTIOI_EN; | ||
288 | + } | ||
289 | + return 0ULL; | ||
290 | +} | ||
291 | + | ||
292 | +static const MemoryRegionOps loongarch_qemu_ops = { | ||
293 | + .read = loongarch_qemu_read, | ||
294 | + .write = loongarch_qemu_write, | ||
295 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
296 | + .valid = { | ||
297 | + .min_access_size = 4, | ||
298 | + .max_access_size = 8, | ||
299 | + }, | ||
300 | + .impl = { | ||
301 | + .min_access_size = 8, | ||
302 | + .max_access_size = 8, | ||
303 | + }, | ||
304 | +}; | ||
305 | + | ||
306 | static void loongarch_init(MachineState *machine) | ||
307 | { | ||
308 | LoongArchCPU *lacpu; | ||
309 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
310 | exit(1); | ||
311 | } | ||
312 | create_fdt(lams); | ||
313 | - /* Init CPUs */ | ||
314 | |||
315 | + /* Create IOCSR space */ | ||
316 | + memory_region_init_io(&lams->system_iocsr, OBJECT(machine), NULL, | ||
317 | + machine, "iocsr", UINT64_MAX); | ||
318 | + address_space_init(&lams->as_iocsr, &lams->system_iocsr, "IOCSR"); | ||
319 | + memory_region_init_io(&lams->iocsr_mem, OBJECT(machine), | ||
320 | + &loongarch_qemu_ops, | ||
321 | + machine, "iocsr_misc", 0x428); | ||
322 | + memory_region_add_subregion(&lams->system_iocsr, 0, &lams->iocsr_mem); | ||
323 | + | ||
324 | + /* Init CPUs */ | ||
325 | possible_cpus = mc->possible_cpu_arch_ids(machine); | ||
326 | for (i = 0; i < possible_cpus->len; i++) { | ||
327 | cpu = cpu_create(machine->cpu_type); | ||
328 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h | 11 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h |
329 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
330 | --- a/include/hw/intc/loongarch_extioi.h | 13 | --- a/include/hw/intc/loongarch_extioi.h |
331 | +++ b/include/hw/intc/loongarch_extioi.h | 14 | +++ b/include/hw/intc/loongarch_extioi.h |
332 | @@ -XXX,XX +XXX,XX @@ struct LoongArchExtIOI { | 15 | @@ -XXX,XX +XXX,XX @@ |
333 | uint8_t sw_coremap[EXTIOI_IRQS]; | 16 | |
334 | qemu_irq parent_irq[EXTIOI_CPUS][LS3A_INTC_IP]; | 17 | #include "hw/intc/loongarch_extioi_common.h" |
335 | qemu_irq irq[EXTIOI_IRQS]; | 18 | |
336 | - MemoryRegion extioi_iocsr_mem[EXTIOI_CPUS]; | 19 | +#define LoongArchExtIOI LoongArchExtIOICommonState |
337 | MemoryRegion extioi_system_mem; | 20 | #define TYPE_LOONGARCH_EXTIOI "loongarch.extioi" |
338 | }; | 21 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI) |
339 | #endif /* LOONGARCH_EXTIOI_H */ | 22 | #endif /* LOONGARCH_EXTIOI_H */ |
340 | diff --git a/include/hw/intc/loongarch_ipi.h b/include/hw/intc/loongarch_ipi.h | 23 | diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h |
341 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
342 | --- a/include/hw/intc/loongarch_ipi.h | 25 | --- a/include/hw/intc/loongarch_extioi_common.h |
343 | +++ b/include/hw/intc/loongarch_ipi.h | 26 | +++ b/include/hw/intc/loongarch_extioi_common.h |
344 | @@ -XXX,XX +XXX,XX @@ struct LoongArchIPI { | 27 | @@ -XXX,XX +XXX,XX @@ typedef struct ExtIOICore { |
28 | qemu_irq parent_irq[LS3A_INTC_IP]; | ||
29 | } ExtIOICore; | ||
30 | |||
31 | -struct LoongArchExtIOI { | ||
32 | +struct LoongArchExtIOICommonState { | ||
345 | SysBusDevice parent_obj; | 33 | SysBusDevice parent_obj; |
346 | MemoryRegion ipi_iocsr_mem; | 34 | uint32_t num_cpu; |
347 | MemoryRegion ipi64_iocsr_mem; | 35 | uint32_t features; |
348 | - IPICore ipi_core; | ||
349 | + uint32_t num_cpu; | ||
350 | + IPICore *cpu; | ||
351 | }; | ||
352 | |||
353 | #endif | ||
354 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | ||
355 | index XXXXXXX..XXXXXXX 100644 | ||
356 | --- a/include/hw/loongarch/virt.h | ||
357 | +++ b/include/hw/loongarch/virt.h | ||
358 | @@ -XXX,XX +XXX,XX @@ struct LoongArchMachineState { | ||
359 | DeviceState *platform_bus_dev; | ||
360 | PCIBus *pci_bus; | ||
361 | PFlashCFI01 *flash; | ||
362 | + MemoryRegion system_iocsr; | ||
363 | + MemoryRegion iocsr_mem; | ||
364 | + AddressSpace as_iocsr; | ||
365 | }; | ||
366 | |||
367 | #define TYPE_LOONGARCH_MACHINE MACHINE_TYPE_NAME("virt") | ||
368 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
369 | index XXXXXXX..XXXXXXX 100644 | ||
370 | --- a/target/loongarch/cpu.c | ||
371 | +++ b/target/loongarch/cpu.c | ||
372 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp) | ||
373 | lacc->parent_realize(dev, errp); | ||
374 | } | ||
375 | |||
376 | -#ifndef CONFIG_USER_ONLY | ||
377 | -static void loongarch_qemu_write(void *opaque, hwaddr addr, | ||
378 | - uint64_t val, unsigned size) | ||
379 | -{ | ||
380 | - qemu_log_mask(LOG_UNIMP, "[%s]: Unimplemented reg 0x%" HWADDR_PRIx "\n", | ||
381 | - __func__, addr); | ||
382 | -} | ||
383 | - | ||
384 | -static uint64_t loongarch_qemu_read(void *opaque, hwaddr addr, unsigned size) | ||
385 | -{ | ||
386 | - switch (addr) { | ||
387 | - case VERSION_REG: | ||
388 | - return 0x11ULL; | ||
389 | - case FEATURE_REG: | ||
390 | - return 1ULL << IOCSRF_MSI | 1ULL << IOCSRF_EXTIOI | | ||
391 | - 1ULL << IOCSRF_CSRIPI; | ||
392 | - case VENDOR_REG: | ||
393 | - return 0x6e6f73676e6f6f4cULL; /* "Loongson" */ | ||
394 | - case CPUNAME_REG: | ||
395 | - return 0x303030354133ULL; /* "3A5000" */ | ||
396 | - case MISC_FUNC_REG: | ||
397 | - return 1ULL << IOCSRM_EXTIOI_EN; | ||
398 | - } | ||
399 | - return 0ULL; | ||
400 | -} | ||
401 | - | ||
402 | -static const MemoryRegionOps loongarch_qemu_ops = { | ||
403 | - .read = loongarch_qemu_read, | ||
404 | - .write = loongarch_qemu_write, | ||
405 | - .endianness = DEVICE_LITTLE_ENDIAN, | ||
406 | - .valid = { | ||
407 | - .min_access_size = 4, | ||
408 | - .max_access_size = 8, | ||
409 | - }, | ||
410 | - .impl = { | ||
411 | - .min_access_size = 8, | ||
412 | - .max_access_size = 8, | ||
413 | - }, | ||
414 | -}; | ||
415 | -#endif | ||
416 | - | ||
417 | static bool loongarch_get_lsx(Object *obj, Error **errp) | ||
418 | { | ||
419 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
420 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_init(Object *obj) | ||
421 | { | ||
422 | #ifndef CONFIG_USER_ONLY | ||
423 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
424 | - CPULoongArchState *env = &cpu->env; | ||
425 | |||
426 | qdev_init_gpio_in(DEVICE(cpu), loongarch_cpu_set_irq, N_IRQS); | ||
427 | #ifdef CONFIG_TCG | ||
428 | timer_init_ns(&cpu->timer, QEMU_CLOCK_VIRTUAL, | ||
429 | &loongarch_constant_timer_cb, cpu); | ||
430 | #endif | ||
431 | - memory_region_init_io(&env->system_iocsr, OBJECT(cpu), NULL, | ||
432 | - env, "iocsr", UINT64_MAX); | ||
433 | - address_space_init(&env->address_space_iocsr, &env->system_iocsr, "IOCSR"); | ||
434 | - memory_region_init_io(&env->iocsr_mem, OBJECT(cpu), &loongarch_qemu_ops, | ||
435 | - NULL, "iocsr_misc", 0x428); | ||
436 | - memory_region_add_subregion(&env->system_iocsr, 0, &env->iocsr_mem); | ||
437 | #endif | ||
438 | } | ||
439 | |||
440 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | ||
441 | index XXXXXXX..XXXXXXX 100644 | ||
442 | --- a/target/loongarch/cpu.h | ||
443 | +++ b/target/loongarch/cpu.h | ||
444 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
445 | #ifndef CONFIG_USER_ONLY | ||
446 | LoongArchTLB tlb[LOONGARCH_TLB_MAX]; | ||
447 | |||
448 | - AddressSpace address_space_iocsr; | ||
449 | - MemoryRegion system_iocsr; | ||
450 | - MemoryRegion iocsr_mem; | ||
451 | + AddressSpace *address_space_iocsr; | ||
452 | bool load_elf; | ||
453 | uint64_t elf_address; | ||
454 | uint32_t mp_state; | ||
455 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
456 | index XXXXXXX..XXXXXXX 100644 | ||
457 | --- a/target/loongarch/kvm/kvm.c | ||
458 | +++ b/target/loongarch/kvm/kvm.c | ||
459 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
460 | trace_kvm_arch_handle_exit(run->exit_reason); | ||
461 | switch (run->exit_reason) { | ||
462 | case KVM_EXIT_LOONGARCH_IOCSR: | ||
463 | - address_space_rw(&env->address_space_iocsr, | ||
464 | + address_space_rw(env->address_space_iocsr, | ||
465 | run->iocsr_io.phys_addr, | ||
466 | attrs, | ||
467 | run->iocsr_io.data, | ||
468 | diff --git a/target/loongarch/tcg/iocsr_helper.c b/target/loongarch/tcg/iocsr_helper.c | ||
469 | index XXXXXXX..XXXXXXX 100644 | ||
470 | --- a/target/loongarch/tcg/iocsr_helper.c | ||
471 | +++ b/target/loongarch/tcg/iocsr_helper.c | ||
472 | @@ -XXX,XX +XXX,XX @@ | ||
473 | |||
474 | uint64_t helper_iocsrrd_b(CPULoongArchState *env, target_ulong r_addr) | ||
475 | { | ||
476 | - return address_space_ldub(&env->address_space_iocsr, r_addr, | ||
477 | + return address_space_ldub(env->address_space_iocsr, r_addr, | ||
478 | GET_MEMTXATTRS(env), NULL); | ||
479 | } | ||
480 | |||
481 | uint64_t helper_iocsrrd_h(CPULoongArchState *env, target_ulong r_addr) | ||
482 | { | ||
483 | - return address_space_lduw(&env->address_space_iocsr, r_addr, | ||
484 | + return address_space_lduw(env->address_space_iocsr, r_addr, | ||
485 | GET_MEMTXATTRS(env), NULL); | ||
486 | } | ||
487 | |||
488 | uint64_t helper_iocsrrd_w(CPULoongArchState *env, target_ulong r_addr) | ||
489 | { | ||
490 | - return address_space_ldl(&env->address_space_iocsr, r_addr, | ||
491 | + return address_space_ldl(env->address_space_iocsr, r_addr, | ||
492 | GET_MEMTXATTRS(env), NULL); | ||
493 | } | ||
494 | |||
495 | uint64_t helper_iocsrrd_d(CPULoongArchState *env, target_ulong r_addr) | ||
496 | { | ||
497 | - return address_space_ldq(&env->address_space_iocsr, r_addr, | ||
498 | + return address_space_ldq(env->address_space_iocsr, r_addr, | ||
499 | GET_MEMTXATTRS(env), NULL); | ||
500 | } | ||
501 | |||
502 | void helper_iocsrwr_b(CPULoongArchState *env, target_ulong w_addr, | ||
503 | target_ulong val) | ||
504 | { | ||
505 | - address_space_stb(&env->address_space_iocsr, w_addr, | ||
506 | + address_space_stb(env->address_space_iocsr, w_addr, | ||
507 | val, GET_MEMTXATTRS(env), NULL); | ||
508 | } | ||
509 | |||
510 | void helper_iocsrwr_h(CPULoongArchState *env, target_ulong w_addr, | ||
511 | target_ulong val) | ||
512 | { | ||
513 | - address_space_stw(&env->address_space_iocsr, w_addr, | ||
514 | + address_space_stw(env->address_space_iocsr, w_addr, | ||
515 | val, GET_MEMTXATTRS(env), NULL); | ||
516 | } | ||
517 | |||
518 | void helper_iocsrwr_w(CPULoongArchState *env, target_ulong w_addr, | ||
519 | target_ulong val) | ||
520 | { | ||
521 | - address_space_stl(&env->address_space_iocsr, w_addr, | ||
522 | + address_space_stl(env->address_space_iocsr, w_addr, | ||
523 | val, GET_MEMTXATTRS(env), NULL); | ||
524 | } | ||
525 | |||
526 | void helper_iocsrwr_d(CPULoongArchState *env, target_ulong w_addr, | ||
527 | target_ulong val) | ||
528 | { | ||
529 | - address_space_stq(&env->address_space_iocsr, w_addr, | ||
530 | + address_space_stq(env->address_space_iocsr, w_addr, | ||
531 | val, GET_MEMTXATTRS(env), NULL); | ||
532 | } | ||
533 | -- | 36 | -- |
534 | 2.25.1 | 37 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | With some structure such as vmstate and property, rename LoongArchExtIOI |
---|---|---|---|
2 | 2 | with LoongArchExtIOICommonState, these common structure will be moved | |
3 | There are elements sw_ipmap and sw_coremap, which is usd to speed | 3 | to common file. |
4 | up irq injection flow. They are saved and restored in vmstate during | ||
5 | migration, indeed they can calculated from hw registers. Here | ||
6 | post_load is added for get sw_ipmap and sw_coremap from extioi hw | ||
7 | state. | ||
8 | 4 | ||
9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
10 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
11 | Message-Id: <20231215100333.3933632-5-maobibo@loongson.cn> | ||
12 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
13 | --- | 7 | --- |
14 | hw/intc/loongarch_extioi.c | 120 +++++++++++++++++++++++-------------- | 8 | hw/intc/loongarch_extioi.c | 41 +++++++++++++++++++++++--------------- |
15 | 1 file changed, 76 insertions(+), 44 deletions(-) | 9 | 1 file changed, 25 insertions(+), 16 deletions(-) |
16 | 10 | ||
17 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c | 11 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c |
18 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/intc/loongarch_extioi.c | 13 | --- a/hw/intc/loongarch_extioi.c |
20 | +++ b/hw/intc/loongarch_extioi.c | 14 | +++ b/hw/intc/loongarch_extioi.c |
21 | @@ -XXX,XX +XXX,XX @@ static inline void extioi_enable_irq(LoongArchExtIOI *s, int index,\ | 15 | @@ -XXX,XX +XXX,XX @@ static int vmstate_extioi_post_load(void *opaque, int version_id) |
22 | } | 16 | return 0; |
23 | } | 17 | } |
24 | 18 | ||
25 | +static inline void extioi_update_sw_coremap(LoongArchExtIOI *s, int irq, | 19 | +static int loongarch_extioi_common_post_load(void *opaque, int version_id) |
26 | + uint64_t val, bool notify) | ||
27 | +{ | 20 | +{ |
28 | + int i, cpu; | 21 | + return vmstate_extioi_post_load(opaque, version_id); |
29 | + | ||
30 | + /* | ||
31 | + * loongarch only support little endian, | ||
32 | + * so we paresd the value with little endian. | ||
33 | + */ | ||
34 | + val = cpu_to_le64(val); | ||
35 | + | ||
36 | + for (i = 0; i < 4; i++) { | ||
37 | + cpu = val & 0xff; | ||
38 | + cpu = ctz32(cpu); | ||
39 | + cpu = (cpu >= 4) ? 0 : cpu; | ||
40 | + val = val >> 8; | ||
41 | + | ||
42 | + if (s->sw_coremap[irq + i] == cpu) { | ||
43 | + continue; | ||
44 | + } | ||
45 | + | ||
46 | + if (notify && test_bit(irq, (unsigned long *)s->isr)) { | ||
47 | + /* | ||
48 | + * lower irq at old cpu and raise irq at new cpu | ||
49 | + */ | ||
50 | + extioi_update_irq(s, irq + i, 0); | ||
51 | + s->sw_coremap[irq + i] = cpu; | ||
52 | + extioi_update_irq(s, irq + i, 1); | ||
53 | + } else { | ||
54 | + s->sw_coremap[irq + i] = cpu; | ||
55 | + } | ||
56 | + } | ||
57 | +} | ||
58 | + | ||
59 | +static inline void extioi_update_sw_ipmap(LoongArchExtIOI *s, int index, | ||
60 | + uint64_t val) | ||
61 | +{ | ||
62 | + int i; | ||
63 | + uint8_t ipnum; | ||
64 | + | ||
65 | + /* | ||
66 | + * loongarch only support little endian, | ||
67 | + * so we paresd the value with little endian. | ||
68 | + */ | ||
69 | + val = cpu_to_le64(val); | ||
70 | + for (i = 0; i < 4; i++) { | ||
71 | + ipnum = val & 0xff; | ||
72 | + ipnum = ctz32(ipnum); | ||
73 | + ipnum = (ipnum >= 4) ? 0 : ipnum; | ||
74 | + s->sw_ipmap[index * 4 + i] = ipnum; | ||
75 | + val = val >> 8; | ||
76 | + } | ||
77 | +} | ||
78 | + | ||
79 | static MemTxResult extioi_writew(void *opaque, hwaddr addr, | ||
80 | uint64_t val, unsigned size, | ||
81 | MemTxAttrs attrs) | ||
82 | { | ||
83 | LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); | ||
84 | - int i, cpu, index, old_data, irq; | ||
85 | + int cpu, index, old_data, irq; | ||
86 | uint32_t offset; | ||
87 | |||
88 | trace_loongarch_extioi_writew(addr, val); | ||
89 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_writew(void *opaque, hwaddr addr, | ||
90 | */ | ||
91 | index = (offset - EXTIOI_IPMAP_START) >> 2; | ||
92 | s->ipmap[index] = val; | ||
93 | - /* | ||
94 | - * loongarch only support little endian, | ||
95 | - * so we paresd the value with little endian. | ||
96 | - */ | ||
97 | - val = cpu_to_le64(val); | ||
98 | - for (i = 0; i < 4; i++) { | ||
99 | - uint8_t ipnum; | ||
100 | - ipnum = val & 0xff; | ||
101 | - ipnum = ctz32(ipnum); | ||
102 | - ipnum = (ipnum >= 4) ? 0 : ipnum; | ||
103 | - s->sw_ipmap[index * 4 + i] = ipnum; | ||
104 | - val = val >> 8; | ||
105 | - } | ||
106 | - | ||
107 | + extioi_update_sw_ipmap(s, index, val); | ||
108 | break; | ||
109 | case EXTIOI_ENABLE_START ... EXTIOI_ENABLE_END - 1: | ||
110 | index = (offset - EXTIOI_ENABLE_START) >> 2; | ||
111 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_writew(void *opaque, hwaddr addr, | ||
112 | irq = offset - EXTIOI_COREMAP_START; | ||
113 | index = irq / 4; | ||
114 | s->coremap[index] = val; | ||
115 | - /* | ||
116 | - * loongarch only support little endian, | ||
117 | - * so we paresd the value with little endian. | ||
118 | - */ | ||
119 | - val = cpu_to_le64(val); | ||
120 | - | ||
121 | - for (i = 0; i < 4; i++) { | ||
122 | - cpu = val & 0xff; | ||
123 | - cpu = ctz32(cpu); | ||
124 | - cpu = (cpu >= 4) ? 0 : cpu; | ||
125 | - val = val >> 8; | ||
126 | - | ||
127 | - if (s->sw_coremap[irq + i] == cpu) { | ||
128 | - continue; | ||
129 | - } | ||
130 | - | ||
131 | - if (test_bit(irq, (unsigned long *)s->isr)) { | ||
132 | - /* | ||
133 | - * lower irq at old cpu and raise irq at new cpu | ||
134 | - */ | ||
135 | - extioi_update_irq(s, irq + i, 0); | ||
136 | - s->sw_coremap[irq + i] = cpu; | ||
137 | - extioi_update_irq(s, irq + i, 1); | ||
138 | - } else { | ||
139 | - s->sw_coremap[irq + i] = cpu; | ||
140 | - } | ||
141 | - } | ||
142 | + | ||
143 | + extioi_update_sw_coremap(s, irq, val, true); | ||
144 | break; | ||
145 | default: | ||
146 | break; | ||
147 | @@ -XXX,XX +XXX,XX @@ static void loongarch_extioi_finalize(Object *obj) | ||
148 | g_free(s->cpu); | ||
149 | } | ||
150 | |||
151 | +static int vmstate_extioi_post_load(void *opaque, int version_id) | ||
152 | +{ | ||
153 | + LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); | ||
154 | + int i, start_irq; | ||
155 | + | ||
156 | + for (i = 0; i < (EXTIOI_IRQS / 4); i++) { | ||
157 | + start_irq = i * 4; | ||
158 | + extioi_update_sw_coremap(s, start_irq, s->coremap[i], false); | ||
159 | + } | ||
160 | + | ||
161 | + for (i = 0; i < (EXTIOI_IRQS_IPMAP_SIZE / 4); i++) { | ||
162 | + extioi_update_sw_ipmap(s, i, s->ipmap[i]); | ||
163 | + } | ||
164 | + | ||
165 | + return 0; | ||
166 | +} | 22 | +} |
167 | + | 23 | + |
168 | static const VMStateDescription vmstate_extioi_core = { | 24 | static const VMStateDescription vmstate_extioi_core = { |
169 | .name = "extioi-core", | 25 | .name = "extioi-core", |
170 | .version_id = 1, | 26 | .version_id = 1, |
171 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_extioi = { | 27 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_extioi_core = { |
172 | .name = TYPE_LOONGARCH_EXTIOI, | 28 | }; |
173 | .version_id = 2, | 29 | |
174 | .minimum_version_id = 2, | 30 | static const VMStateDescription vmstate_loongarch_extioi = { |
175 | + .post_load = vmstate_extioi_post_load, | 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, | ||
176 | .fields = (const VMStateField[]) { | 37 | .fields = (const VMStateField[]) { |
177 | VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOI, EXTIOI_IRQS_GROUP_COUNT), | 38 | - VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOI, EXTIOI_IRQS_GROUP_COUNT), |
178 | VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOI, | 39 | - VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOI, |
179 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_extioi = { | 40 | + VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOICommonState, |
180 | VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOI, EXTIOI_IRQS / 32), | 41 | + EXTIOI_IRQS_GROUP_COUNT), |
181 | VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE / 4), | 42 | + VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOICommonState, |
182 | VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOI, EXTIOI_IRQS / 4), | 43 | EXTIOI_IRQS_NODETYPE_COUNT / 2), |
183 | - VMSTATE_UINT8_ARRAY(sw_ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE), | 44 | - VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOI, EXTIOI_IRQS / 32), |
184 | - VMSTATE_UINT8_ARRAY(sw_coremap, LoongArchExtIOI, EXTIOI_IRQS), | 45 | - VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOI, EXTIOI_IRQS / 32), |
185 | 46 | - VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE / 4), | |
186 | VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOI, num_cpu, | 47 | - VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOI, EXTIOI_IRQS / 4), |
187 | vmstate_extioi_core, ExtIOICore), | 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 | |||
188 | -- | 79 | -- |
189 | 2.25.1 | 80 | 2.43.5 | diff view generated by jsdifflib |