1
The following changes since commit 3f8bcbba3b320c610689576fc47595f1076198dd:
1
The following changes since commit 38d0939b86e2eef6f6a622c6f1f7befda0146595:
2
2
3
Merge tag 'pull-request-2025-01-08' of https://gitlab.com/thuth/qemu into staging (2025-01-08 11:38:21 -0500)
3
Merge tag 'pull-vfio-20241226' of https://github.com/legoater/qemu into staging (2024-12-26 04:38:38 -0500)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20250109
7
https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20241227
8
8
9
for you to fetch changes up to c3afa714bcea4c8b014fec99881bd0bdbe8262b8:
9
for you to fetch changes up to 5e360dabedb1ab1f15cce27a134ccbe4b8e18424:
10
10
11
hw/intc/loongarch_extioi: Add irq routing support from physical id (2025-01-09 14:13:41 +0800)
11
target/loongarch: Use auto method with LASX feature (2024-12-27 11:33:06 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
pull-loongarch-20250109
14
pull-loongarch-20241227
15
v1 ... v2
16
1. Modify patch auther inconsistent with SOB
15
17
16
----------------------------------------------------------------
18
----------------------------------------------------------------
17
Bibo Mao (4):
19
Bibo Mao (5):
18
target/loongarch: Only support 64bit pte width
20
target/loongarch: Use actual operand size with vbsrl check
19
hw/intc/loongarch_extioi: Get cpu number from possible_cpu_arch_ids
21
hw/loongarch/virt: Create fdt table on machine creation done notification
20
hw/intc/loongarch_extioi: Remove num-cpu property
22
hw/loongarch/virt: Improve fdt table creation for CPU object
21
hw/intc/loongarch_extioi: Add irq routing support from physical id
23
target/loongarch: Use auto method with LSX feature
24
target/loongarch: Use auto method with LASX feature
22
25
23
Jiaxun Yang (2):
26
Guo Hongyu (1):
24
hw/core/loader: Use ssize_t for efi zboot unpacker
27
target/loongarch: Fix vldi inst
25
hw/loongarch/boot: Support Linux raw boot image
26
28
27
hw/arm/boot.c | 2 +-
29
hw/loongarch/virt.c | 142 ++++++++++++++----------
28
hw/core/loader.c | 4 +-
30
target/loongarch/cpu.c | 86 ++++++++------
29
hw/intc/loongarch_extioi.c | 36 +++++++----
31
target/loongarch/cpu.h | 4 +
30
hw/intc/loongarch_extioi_common.c | 18 +++++-
32
target/loongarch/kvm/kvm.c | 107 ++++++++++++++++++
31
hw/loongarch/boot.c | 69 ++++++++++++++++++++++
33
target/loongarch/tcg/insn_trans/trans_vec.c.inc | 4 +-
32
hw/loongarch/virt.c | 1 -
34
5 files changed, 249 insertions(+), 94 deletions(-)
33
include/hw/intc/loongarch_extioi_common.h | 2 +
34
include/hw/loader.h | 2 +-
35
target/loongarch/helper.h | 1 +
36
target/loongarch/tcg/csr_helper.c | 21 +++++++
37
.../tcg/insn_trans/trans_privileged.c.inc | 2 +-
38
target/loongarch/tcg/tlb_helper.c | 17 +-----
39
12 files changed, 142 insertions(+), 33 deletions(-)
diff view generated by jsdifflib
1
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
1
From: Guo Hongyu <guohongyu24@mails.ucas.ac.cn>
2
2
3
Support booting such image by parsing header as per Linux's
3
Refer to the link below for a description of the vldi instructions:
4
specification [1].
4
https://jia.je/unofficial-loongarch-intrinsics-guide/lsx/misc/#synopsis_88
5
Fixed errors in vldi instruction implementation.
5
6
6
This enabled booting vmlinux.efi/vmlinuz.efi shipped by
7
Signed-off-by: Guo Hongyu <guohongyu24@mails.ucas.ac.cn>
7
distros without supplying BIOS.
8
Tested-by: Xianglai Li <lixianglai@loongson.cn>
9
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
10
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
11
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
12
---
13
target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +-
14
1 file changed, 1 insertion(+), 1 deletion(-)
8
15
9
[1]: https://docs.kernel.org/arch/loongarch/booting.html
16
diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
10
11
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
12
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
13
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
14
---
15
hw/loongarch/boot.c | 69 +++++++++++++++++++++++++++++++++++++++++++++
16
1 file changed, 69 insertions(+)
17
18
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/loongarch/boot.c
18
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
21
+++ b/hw/loongarch/boot.c
19
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
22
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm)
23
#include "system/reset.h"
21
break;
24
#include "system/qtest.h"
22
case 1:
25
23
/* data: {2{16'0, imm[7:0], 8'0}} */
26
+/*
24
- data = (t << 24) | (t << 8);
27
+ * Linux Image Format
25
+ data = (t << 40) | (t << 8);
28
+ * https://docs.kernel.org/arch/loongarch/booting.html
26
break;
29
+ */
27
case 2:
30
+#define LINUX_PE_MAGIC 0x818223cd
28
/* data: {2{8'0, imm[7:0], 16'0}} */
31
+#define MZ_MAGIC 0x5a4d /* "MZ" */
32
+
33
+struct loongarch_linux_hdr {
34
+ uint32_t mz_magic;
35
+ uint32_t res0;
36
+ uint64_t kernel_entry;
37
+ uint64_t kernel_size;
38
+ uint64_t load_offset;
39
+ uint64_t res1;
40
+ uint64_t res2;
41
+ uint64_t res3;
42
+ uint32_t linux_pe_magic;
43
+ uint32_t pe_header_offset;
44
+} QEMU_PACKED;
45
+
46
struct memmap_entry *memmap_table;
47
unsigned memmap_entries;
48
49
@@ -XXX,XX +XXX,XX @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
50
return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
51
}
52
53
+static int64_t load_loongarch_linux_image(const char *filename,
54
+ uint64_t *kernel_entry,
55
+ uint64_t *kernel_low,
56
+ uint64_t *kernel_high)
57
+{
58
+ gsize len;
59
+ ssize_t size;
60
+ uint8_t *buffer;
61
+ struct loongarch_linux_hdr *hdr;
62
+
63
+ /* Load as raw file otherwise */
64
+ if (!g_file_get_contents(filename, (char **)&buffer, &len, NULL)) {
65
+ return -1;
66
+ }
67
+ size = len;
68
+
69
+ /* Unpack the image if it is a EFI zboot image */
70
+ if (unpack_efi_zboot_image(&buffer, &size) < 0) {
71
+ g_free(buffer);
72
+ return -1;
73
+ }
74
+
75
+ hdr = (struct loongarch_linux_hdr *)buffer;
76
+
77
+ if (extract32(le32_to_cpu(hdr->mz_magic), 0, 16) != MZ_MAGIC ||
78
+ le32_to_cpu(hdr->linux_pe_magic) != LINUX_PE_MAGIC) {
79
+ g_free(buffer);
80
+ return -1;
81
+ }
82
+
83
+ /* Early kernel versions may have those fields in virtual address */
84
+ *kernel_entry = extract64(le64_to_cpu(hdr->kernel_entry),
85
+ 0, TARGET_PHYS_ADDR_SPACE_BITS);
86
+ *kernel_low = extract64(le64_to_cpu(hdr->load_offset),
87
+ 0, TARGET_PHYS_ADDR_SPACE_BITS);
88
+ *kernel_high = *kernel_low + size;
89
+
90
+ rom_add_blob_fixed(filename, buffer, size, *kernel_low);
91
+
92
+ g_free(buffer);
93
+
94
+ return size;
95
+}
96
+
97
static int64_t load_kernel_info(struct loongarch_boot_info *info)
98
{
99
uint64_t kernel_entry, kernel_low, kernel_high;
100
@@ -XXX,XX +XXX,XX @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
101
&kernel_entry, &kernel_low,
102
&kernel_high, NULL, 0,
103
EM_LOONGARCH, 1, 0);
104
+ if (kernel_size < 0) {
105
+ kernel_size = load_loongarch_linux_image(info->kernel_filename,
106
+ &kernel_entry, &kernel_low,
107
+ &kernel_high);
108
+ }
109
110
if (kernel_size < 0) {
111
error_report("could not load kernel '%s': %s",
112
--
29
--
113
2.43.5
30
2.43.5
diff view generated by jsdifflib
1
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
1
Hardcoded 32 bytes is used for vbsrl emulation check, there is
2
problem when options lsx=on,lasx=off is used for vbsrl.v instruction
3
in TCG mode. It injects LASX exception rather LSX exception.
2
4
3
Convert to use sszie_t to represent size internally to avoid
5
Here actual operand size is used.
4
large image overflowing the size.
5
6
6
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
7
Cc: qemu-stable@nongnu.org
7
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
8
Fixes: df97f338076 ("target/loongarch: Implement xvreplve xvinsve0 xvpickve")
8
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
9
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
9
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
---
12
---
11
hw/arm/boot.c | 2 +-
13
target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +-
12
hw/core/loader.c | 4 ++--
14
1 file changed, 1 insertion(+), 1 deletion(-)
13
include/hw/loader.h | 2 +-
14
3 files changed, 4 insertions(+), 4 deletions(-)
15
15
16
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
16
diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
17
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/boot.c
18
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
19
+++ b/hw/arm/boot.c
19
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
20
@@ -XXX,XX +XXX,XX @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
20
@@ -XXX,XX +XXX,XX @@ static bool do_vbsrl_v(DisasContext *ctx, arg_vv_i *a, uint32_t oprsz)
21
hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
22
uint64_t kernel_size = 0;
23
uint8_t *buffer;
24
- int size;
25
+ ssize_t size;
26
27
/* On aarch64, it's the bootloader's job to uncompress the kernel. */
28
size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES,
29
diff --git a/hw/core/loader.c b/hw/core/loader.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/hw/core/loader.c
32
+++ b/hw/core/loader.c
33
@@ -XXX,XX +XXX,XX @@ struct linux_efi_zboot_header {
34
*
35
* If the image is not a Linux EFI zboot image, do nothing and return success.
36
*/
37
-ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size)
38
+ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
39
{
21
{
40
const struct linux_efi_zboot_header *header;
22
int i, ofs;
41
uint8_t *data = NULL;
23
42
- int ploff, plsize;
24
- if (!check_vec(ctx, 32)) {
43
+ ssize_t ploff, plsize;
25
+ if (!check_vec(ctx, oprsz)) {
44
ssize_t bytes;
26
return true;
45
27
}
46
/* ignore if this is too small to be a EFI zboot image */
28
47
diff --git a/include/hw/loader.h b/include/hw/loader.h
48
index XXXXXXX..XXXXXXX 100644
49
--- a/include/hw/loader.h
50
+++ b/include/hw/loader.h
51
@@ -XXX,XX +XXX,XX @@ ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
52
* Returns the size of the decompressed payload if decompression was performed
53
* successfully.
54
*/
55
-ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size);
56
+ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size);
57
58
#define ELF_LOAD_FAILED -1
59
#define ELF_LOAD_NOT_ELF -2
60
--
29
--
61
2.43.5
30
2.43.5
31
32
diff view generated by jsdifflib
1
iFrom LoongArch Reference Manual pte width can be 64bit, 128bit
1
The same with ACPI table, fdt table is created on machine done
2
or more. Instead real hardware only supports 64bit pte width.
2
notification. Some objects like CPU objects can be created with cold-plug
3
For 12bit pte, there is no detail definition for all 128bit
3
method with command such as -smp x, -device la464-loongarch-cpu, so all
4
from manual.
4
objects finish to create when machine is done.
5
6
Here only 64bit pte width is supported for simplicity, will add
7
this in later if real hw support it and there is definition for
8
all the bits from manual.
9
5
10
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
11
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
7
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
12
---
8
---
13
target/loongarch/helper.h | 1 +
9
hw/loongarch/virt.c | 103 ++++++++++++++++++++++++--------------------
14
target/loongarch/tcg/csr_helper.c | 21 +++++++++++++++++++
10
1 file changed, 57 insertions(+), 46 deletions(-)
15
.../tcg/insn_trans/trans_privileged.c.inc | 2 +-
16
target/loongarch/tcg/tlb_helper.c | 17 +++------------
17
4 files changed, 26 insertions(+), 15 deletions(-)
18
11
19
diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h
12
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
20
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
21
--- a/target/loongarch/helper.h
14
--- a/hw/loongarch/virt.c
22
+++ b/target/loongarch/helper.h
15
+++ b/hw/loongarch/virt.c
23
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(csrwr_estat, i64, env, tl)
16
@@ -XXX,XX +XXX,XX @@ static void virt_build_smbios(LoongArchVirtMachineState *lvms)
24
DEF_HELPER_2(csrwr_asid, i64, env, tl)
17
}
25
DEF_HELPER_2(csrwr_tcfg, i64, env, tl)
18
}
26
DEF_HELPER_2(csrwr_ticlr, i64, env, tl)
19
27
+DEF_HELPER_2(csrwr_pwcl, i64, env, tl)
20
+static void virt_fdt_setup(LoongArchVirtMachineState *lvms)
28
DEF_HELPER_2(iocsrrd_b, i64, env, tl)
29
DEF_HELPER_2(iocsrrd_h, i64, env, tl)
30
DEF_HELPER_2(iocsrrd_w, i64, env, tl)
31
diff --git a/target/loongarch/tcg/csr_helper.c b/target/loongarch/tcg/csr_helper.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/loongarch/tcg/csr_helper.c
34
+++ b/target/loongarch/tcg/csr_helper.c
35
@@ -XXX,XX +XXX,XX @@
36
*/
37
38
#include "qemu/osdep.h"
39
+#include "qemu/log.h"
40
#include "qemu/main-loop.h"
41
#include "cpu.h"
42
#include "internals.h"
43
@@ -XXX,XX +XXX,XX @@ target_ulong helper_csrwr_ticlr(CPULoongArchState *env, target_ulong val)
44
}
45
return old_v;
46
}
47
+
48
+target_ulong helper_csrwr_pwcl(CPULoongArchState *env, target_ulong val)
49
+{
21
+{
50
+ int shift;
22
+ MachineState *machine = MACHINE(lvms);
51
+ int64_t old_v = env->CSR_PWCL;
23
+ uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle;
24
+ int i;
25
+
26
+ create_fdt(lvms);
27
+ fdt_add_cpu_nodes(lvms);
28
+ fdt_add_memory_nodes(machine);
29
+ fdt_add_fw_cfg_node(lvms);
30
+ fdt_add_flash_node(lvms);
31
+
32
+ /* Add cpu interrupt-controller */
33
+ fdt_add_cpuic_node(lvms, &cpuintc_phandle);
34
+ /* Add Extend I/O Interrupt Controller node */
35
+ fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle);
36
+ /* Add PCH PIC node */
37
+ fdt_add_pch_pic_node(lvms, &eiointc_phandle, &pch_pic_phandle);
38
+ /* Add PCH MSI node */
39
+ fdt_add_pch_msi_node(lvms, &eiointc_phandle, &pch_msi_phandle);
40
+ /* Add pcie node */
41
+ fdt_add_pcie_node(lvms, &pch_pic_phandle, &pch_msi_phandle);
52
+
42
+
53
+ /*
43
+ /*
54
+ * The real hardware only supports 64bit PTE width now, 128bit or others
44
+ * Create uart fdt node in reverse order so that they appear
55
+ * treated as illegal.
45
+ * in the finished device tree lowest address first
56
+ */
46
+ */
57
+ shift = FIELD_EX64(val, CSR_PWCL, PTEWIDTH);
47
+ for (i = VIRT_UART_COUNT; i-- > 0;) {
58
+ if (shift) {
48
+ hwaddr base = VIRT_UART_BASE + i * VIRT_UART_SIZE;
59
+ qemu_log_mask(LOG_GUEST_ERROR,
49
+ int irq = VIRT_UART_IRQ + i - VIRT_GSI_BASE;
60
+ "Attempted set pte width with %d bit\n", 64 << shift);
50
+ fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
61
+ val = FIELD_DP64(val, CSR_PWCL, PTEWIDTH, 0);
62
+ }
51
+ }
63
+
52
+
64
+ env->CSR_PWCL = val;
53
+ fdt_add_rtc_node(lvms, &pch_pic_phandle);
65
+ return old_v;
54
+ fdt_add_ged_reset(lvms);
55
+ platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
56
+ VIRT_PLATFORM_BUS_BASEADDRESS,
57
+ VIRT_PLATFORM_BUS_SIZE,
58
+ VIRT_PLATFORM_BUS_IRQ);
59
+
60
+ /*
61
+ * Since lowmem region starts from 0 and Linux kernel legacy start address
62
+ * at 2 MiB, FDT base address is located at 1 MiB to avoid NULL pointer
63
+ * access. FDT size limit with 1 MiB.
64
+ * Put the FDT into the memory map as a ROM image: this will ensure
65
+ * the FDT is copied again upon reset, even if addr points into RAM.
66
+ */
67
+ qemu_fdt_dumpdtb(machine->fdt, lvms->fdt_size);
68
+ rom_add_blob_fixed_as("fdt", machine->fdt, lvms->fdt_size, FDT_BASE,
69
+ &address_space_memory);
70
+ qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds,
71
+ rom_ptr_for_as(&address_space_memory, FDT_BASE, lvms->fdt_size));
66
+}
72
+}
67
diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
73
+
68
index XXXXXXX..XXXXXXX 100644
74
static void virt_done(Notifier *notifier, void *data)
69
--- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
70
+++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
71
@@ -XXX,XX +XXX,XX @@ static const CSRInfo csr_info[] = {
72
CSR_OFF(PGDL),
73
CSR_OFF(PGDH),
74
CSR_OFF_FUNCS(PGD, CSRFL_READONLY, gen_helper_csrrd_pgd, NULL),
75
- CSR_OFF(PWCL),
76
+ CSR_OFF_FUNCS(PWCL, 0, NULL, gen_helper_csrwr_pwcl),
77
CSR_OFF(PWCH),
78
CSR_OFF(STLBPS),
79
CSR_OFF(RVACFG),
80
diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c
81
index XXXXXXX..XXXXXXX 100644
82
--- a/target/loongarch/tcg/tlb_helper.c
83
+++ b/target/loongarch/tcg/tlb_helper.c
84
@@ -XXX,XX +XXX,XX @@ target_ulong helper_lddir(CPULoongArchState *env, target_ulong base,
85
{
75
{
86
CPUState *cs = env_cpu(env);
76
LoongArchVirtMachineState *lvms = container_of(notifier,
87
target_ulong badvaddr, index, phys, ret;
77
LoongArchVirtMachineState, machine_done);
88
- int shift;
78
virt_build_smbios(lvms);
89
uint64_t dir_base, dir_width;
79
loongarch_acpi_setup(lvms);
90
80
+ virt_fdt_setup(lvms);
91
if (unlikely((level == 0) || (level > 4))) {
81
}
92
@@ -XXX,XX +XXX,XX @@ target_ulong helper_lddir(CPULoongArchState *env, target_ulong base,
82
93
83
static void virt_powerdown_req(Notifier *notifier, void *opaque)
94
badvaddr = env->CSR_TLBRBADV;
84
@@ -XXX,XX +XXX,XX @@ static DeviceState *create_platform_bus(DeviceState *pch_pic)
95
base = base & TARGET_PHYS_MASK;
85
}
96
-
86
97
- /* 0:64bit, 1:128bit, 2:192bit, 3:256bit */
87
static void virt_devices_init(DeviceState *pch_pic,
98
- shift = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTEWIDTH);
88
- LoongArchVirtMachineState *lvms,
99
- shift = (shift + 1) * 3;
89
- uint32_t *pch_pic_phandle,
100
-
90
- uint32_t *pch_msi_phandle)
101
get_dir_base_width(env, &dir_base, &dir_width, level);
91
+ LoongArchVirtMachineState *lvms)
102
index = (badvaddr >> dir_base) & ((1 << dir_width) - 1);
103
- phys = base | index << shift;
104
+ phys = base | index << 3;
105
ret = ldq_phys(cs->as, phys) & TARGET_PHYS_MASK;
106
return ret;
107
}
108
@@ -XXX,XX +XXX,XX @@ void helper_ldpte(CPULoongArchState *env, target_ulong base, target_ulong odd,
109
{
92
{
110
CPUState *cs = env_cpu(env);
93
MachineClass *mc = MACHINE_GET_CLASS(lvms);
111
target_ulong phys, tmp0, ptindex, ptoffset0, ptoffset1, ps, badv;
94
DeviceState *gpex_dev;
112
- int shift;
95
@@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic,
113
uint64_t ptbase = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTBASE);
96
gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i);
114
uint64_t ptwidth = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTWIDTH);
97
}
115
uint64_t dir_base, dir_width;
98
116
@@ -XXX,XX +XXX,XX @@ void helper_ldpte(CPULoongArchState *env, target_ulong base, target_ulong odd,
99
- /* Add pcie node */
117
tmp0 += MAKE_64BIT_MASK(ps, 1);
100
- fdt_add_pcie_node(lvms, pch_pic_phandle, pch_msi_phandle);
101
-
102
/*
103
* Create uart fdt node in reverse order so that they appear
104
* in the finished device tree lowest address first
105
@@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic,
106
serial_mm_init(get_system_memory(), base, 0,
107
qdev_get_gpio_in(pch_pic, irq),
108
115200, serial_hd(i), DEVICE_LITTLE_ENDIAN);
109
- fdt_add_uart_node(lvms, pch_pic_phandle, base, irq, i == 0);
110
}
111
112
/* Network init */
113
@@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic,
114
sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE,
115
qdev_get_gpio_in(pch_pic,
116
VIRT_RTC_IRQ - VIRT_GSI_BASE));
117
- fdt_add_rtc_node(lvms, pch_pic_phandle);
118
- fdt_add_ged_reset(lvms);
119
120
/* acpi ged */
121
lvms->acpi_ged = create_acpi_ged(pch_pic, lvms);
122
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
123
CPULoongArchState *env;
124
CPUState *cpu_state;
125
int cpu, pin, i, start, num;
126
- uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle;
127
128
/*
129
* Extended IRQ model.
130
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
131
memory_region_add_subregion(&lvms->system_iocsr, MAIL_SEND_ADDR,
132
sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 1));
133
134
- /* Add cpu interrupt-controller */
135
- fdt_add_cpuic_node(lvms, &cpuintc_phandle);
136
-
137
for (cpu = 0; cpu < ms->smp.cpus; cpu++) {
138
cpu_state = qemu_get_cpu(cpu);
139
cpudev = DEVICE(cpu_state);
140
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
118
}
141
}
119
} else {
142
}
120
- /* 0:64bit, 1:128bit, 2:192bit, 3:256bit */
143
121
- shift = FIELD_EX64(env->CSR_PWCL, CSR_PWCL, PTEWIDTH);
144
- /* Add Extend I/O Interrupt Controller node */
122
- shift = (shift + 1) * 3;
145
- fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle);
123
badv = env->CSR_TLBRBADV;
146
-
124
147
pch_pic = qdev_new(TYPE_LOONGARCH_PIC);
125
ptindex = (badv >> ptbase) & ((1 << ptwidth) - 1);
148
num = VIRT_PCH_PIC_IRQ_NUM;
126
ptindex = ptindex & ~0x1; /* clear bit 0 */
149
qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num);
127
- ptoffset0 = ptindex << shift;
150
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
128
- ptoffset1 = (ptindex + 1) << shift;
151
qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i));
129
-
152
}
130
+ ptoffset0 = ptindex << 3;
153
131
+ ptoffset1 = (ptindex + 1) << 3;
154
- /* Add PCH PIC node */
132
phys = base | (odd ? ptoffset1 : ptoffset0);
155
- fdt_add_pch_pic_node(lvms, &eiointc_phandle, &pch_pic_phandle);
133
tmp0 = ldq_phys(cs->as, phys) & TARGET_PHYS_MASK;
156
-
134
ps = ptbase;
157
pch_msi = qdev_new(TYPE_LOONGARCH_PCH_MSI);
158
start = num;
159
num = EXTIOI_IRQS - start;
160
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
161
qdev_get_gpio_in(extioi, i + start));
162
}
163
164
- /* Add PCH MSI node */
165
- fdt_add_pch_msi_node(lvms, &eiointc_phandle, &pch_msi_phandle);
166
-
167
- virt_devices_init(pch_pic, lvms, &pch_pic_phandle, &pch_msi_phandle);
168
+ virt_devices_init(pch_pic, lvms);
169
}
170
171
static void virt_firmware_init(LoongArchVirtMachineState *lvms)
172
@@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine)
173
cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
174
}
175
176
- create_fdt(lvms);
177
-
178
/* Create IOCSR space */
179
memory_region_init_io(&lvms->system_iocsr, OBJECT(machine), NULL,
180
machine, "iocsr", UINT64_MAX);
181
@@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine)
182
lacpu = LOONGARCH_CPU(cpu);
183
lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id;
184
}
185
- fdt_add_cpu_nodes(lvms);
186
- fdt_add_memory_nodes(machine);
187
fw_cfg_add_memory(machine);
188
189
/* Node0 memory */
190
@@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine)
191
memmap_table,
192
sizeof(struct memmap_entry) * (memmap_entries));
193
}
194
- fdt_add_fw_cfg_node(lvms);
195
- fdt_add_flash_node(lvms);
196
197
/* Initialize the IO interrupt subsystem */
198
virt_irq_init(lvms);
199
- platform_bus_add_all_fdt_nodes(machine->fdt, "/platic",
200
- VIRT_PLATFORM_BUS_BASEADDRESS,
201
- VIRT_PLATFORM_BUS_SIZE,
202
- VIRT_PLATFORM_BUS_IRQ);
203
lvms->machine_done.notify = virt_done;
204
qemu_add_machine_init_done_notifier(&lvms->machine_done);
205
/* connect powerdown request */
206
lvms->powerdown_notifier.notify = virt_powerdown_req;
207
qemu_register_powerdown_notifier(&lvms->powerdown_notifier);
208
209
- /*
210
- * Since lowmem region starts from 0 and Linux kernel legacy start address
211
- * at 2 MiB, FDT base address is located at 1 MiB to avoid NULL pointer
212
- * access. FDT size limit with 1 MiB.
213
- * Put the FDT into the memory map as a ROM image: this will ensure
214
- * the FDT is copied again upon reset, even if addr points into RAM.
215
- */
216
- qemu_fdt_dumpdtb(machine->fdt, lvms->fdt_size);
217
- rom_add_blob_fixed_as("fdt", machine->fdt, lvms->fdt_size, FDT_BASE,
218
- &address_space_memory);
219
- qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds,
220
- rom_ptr_for_as(&address_space_memory, FDT_BASE, lvms->fdt_size));
221
-
222
lvms->bootinfo.ram_size = ram_size;
223
loongarch_load_kernel(machine, &lvms->bootinfo);
224
}
135
--
225
--
136
2.43.5
226
2.43.5
diff view generated by jsdifflib
1
Since cpu number can be acquired from possible_cpu_arch_ids(),
1
For CPU object, possible_cpu_arch_ids() function is used rather than
2
num-cpu property is not necessary. Here remove num-cpu property
2
smp.cpus. With command -smp x, -device la464-loongarch-cpu, smp.cpus
3
for object TYPE_LOONGARCH_EXTIOI_COMMON object.
3
is not accurate for all possible CPU objects, possible_cpu_arch_ids()
4
is used here.
4
5
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
7
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
7
---
8
---
8
hw/intc/loongarch_extioi_common.c | 1 -
9
hw/loongarch/virt.c | 39 +++++++++++++++++++++++++--------------
9
hw/loongarch/virt.c | 1 -
10
1 file changed, 25 insertions(+), 14 deletions(-)
10
2 files changed, 2 deletions(-)
11
11
12
diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_common.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/intc/loongarch_extioi_common.c
15
+++ b/hw/intc/loongarch_extioi_common.c
16
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_extioi = {
17
};
18
19
static const Property extioi_properties[] = {
20
- DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOICommonState, num_cpu, 1),
21
DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOICommonState,
22
features, EXTIOI_HAS_VIRT_EXTENSION, 0),
23
};
24
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
12
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
25
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/loongarch/virt.c
14
--- a/hw/loongarch/virt.c
27
+++ b/hw/loongarch/virt.c
15
+++ b/hw/loongarch/virt.c
28
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
16
@@ -XXX,XX +XXX,XX @@ static void create_fdt(LoongArchVirtMachineState *lvms)
29
17
static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
30
/* Create EXTIOI device */
18
{
31
extioi = qdev_new(TYPE_LOONGARCH_EXTIOI);
19
int num;
32
- qdev_prop_set_uint32(extioi, "num-cpu", ms->smp.cpus);
20
- const MachineState *ms = MACHINE(lvms);
33
if (virt_is_veiointc_enabled(lvms)) {
21
- int smp_cpus = ms->smp.cpus;
34
qdev_prop_set_bit(extioi, "has-virtualization-extension", true);
22
+ MachineState *ms = MACHINE(lvms);
23
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
24
+ const CPUArchIdList *possible_cpus;
25
+ LoongArchCPU *cpu;
26
+ CPUState *cs;
27
+ char *nodename, *map_path;
28
29
qemu_fdt_add_subnode(ms->fdt, "/cpus");
30
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1);
31
qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0);
32
33
/* cpu nodes */
34
- for (num = smp_cpus - 1; num >= 0; num--) {
35
- char *nodename = g_strdup_printf("/cpus/cpu@%d", num);
36
- LoongArchCPU *cpu = LOONGARCH_CPU(qemu_get_cpu(num));
37
- CPUState *cs = CPU(cpu);
38
+ possible_cpus = mc->possible_cpu_arch_ids(ms);
39
+ for (num = 0; num < possible_cpus->len; num++) {
40
+ cs = possible_cpus->cpus[num].cpu;
41
+ if (cs == NULL) {
42
+ continue;
43
+ }
44
+
45
+ nodename = g_strdup_printf("/cpus/cpu@%d", num);
46
+ cpu = LOONGARCH_CPU(cs);
47
48
qemu_fdt_add_subnode(ms->fdt, nodename);
49
qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu");
50
qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
51
cpu->dtb_compatible);
52
- if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
53
+ if (possible_cpus->cpus[num].props.has_node_id) {
54
qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id",
55
- ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
56
+ possible_cpus->cpus[num].props.node_id);
57
}
58
qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num);
59
qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle",
60
@@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
61
62
/*cpu map */
63
qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map");
64
+ for (num = 0; num < possible_cpus->len; num++) {
65
+ cs = possible_cpus->cpus[num].cpu;
66
+ if (cs == NULL) {
67
+ continue;
68
+ }
69
70
- for (num = smp_cpus - 1; num >= 0; num--) {
71
- char *cpu_path = g_strdup_printf("/cpus/cpu@%d", num);
72
- char *map_path;
73
-
74
+ nodename = g_strdup_printf("/cpus/cpu@%d", num);
75
if (ms->smp.threads > 1) {
76
map_path = g_strdup_printf(
77
"/cpus/cpu-map/socket%d/core%d/thread%d",
78
@@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
79
num % ms->smp.cores);
80
}
81
qemu_fdt_add_path(ms->fdt, map_path);
82
- qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", cpu_path);
83
+ qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", nodename);
84
85
g_free(map_path);
86
- g_free(cpu_path);
87
+ g_free(nodename);
35
}
88
}
89
}
90
36
--
91
--
37
2.43.5
92
2.43.5
diff view generated by jsdifflib
1
The simliar with IPI interrupt controller, physical cpu id is used
1
Like LBT feature, add type OnOffAuto for LSX feature setting. Also
2
for irq routing for extioi interrupt controller.
2
add LSX feature detection with new VM ioctl command, fallback to old
3
method if it is not supported.
3
4
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
---
7
---
7
hw/intc/loongarch_extioi.c | 30 ++++++++++++++++++++++++++----
8
target/loongarch/cpu.c | 38 +++++++++++++++------------
8
1 file changed, 26 insertions(+), 4 deletions(-)
9
target/loongarch/cpu.h | 2 ++
10
target/loongarch/kvm/kvm.c | 54 ++++++++++++++++++++++++++++++++++++++
11
3 files changed, 77 insertions(+), 17 deletions(-)
9
12
10
diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
13
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
11
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/intc/loongarch_extioi.c
15
--- a/target/loongarch/cpu.c
13
+++ b/hw/intc/loongarch_extioi.c
16
+++ b/target/loongarch/cpu.c
14
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj)
15
#include "hw/intc/loongarch_extioi.h"
18
{
16
#include "trace.h"
19
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
17
20
CPULoongArchState *env = &cpu->env;
18
+static int extioi_get_index_from_archid(LoongArchExtIOICommonState *s,
21
+ uint32_t data = 0;
19
+ uint64_t arch_id)
22
int i;
23
24
for (i = 0; i < 21; i++) {
25
@@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj)
26
cpu->dtb_compatible = "loongarch,Loongson-3A5000";
27
env->cpucfg[0] = 0x14c010; /* PRID */
28
29
- uint32_t data = 0;
30
data = FIELD_DP32(data, CPUCFG1, ARCH, 2);
31
data = FIELD_DP32(data, CPUCFG1, PGMMU, 1);
32
data = FIELD_DP32(data, CPUCFG1, IOCSR, 1);
33
@@ -XXX,XX +XXX,XX @@ static void loongarch_la132_initfn(Object *obj)
34
{
35
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
36
CPULoongArchState *env = &cpu->env;
37
-
38
+ uint32_t data = 0;
39
int i;
40
41
for (i = 0; i < 21; i++) {
42
@@ -XXX,XX +XXX,XX @@ static void loongarch_la132_initfn(Object *obj)
43
cpu->dtb_compatible = "loongarch,Loongson-1C103";
44
env->cpucfg[0] = 0x148042; /* PRID */
45
46
- uint32_t data = 0;
47
data = FIELD_DP32(data, CPUCFG1, ARCH, 1); /* LA32 */
48
data = FIELD_DP32(data, CPUCFG1, PGMMU, 1);
49
data = FIELD_DP32(data, CPUCFG1, IOCSR, 1);
50
@@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)
51
52
static bool loongarch_get_lsx(Object *obj, Error **errp)
53
{
54
- LoongArchCPU *cpu = LOONGARCH_CPU(obj);
55
- bool ret;
56
-
57
- if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
58
- ret = true;
59
- } else {
60
- ret = false;
61
- }
62
- return ret;
63
+ return LOONGARCH_CPU(obj)->lsx != ON_OFF_AUTO_OFF;
64
}
65
66
static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
67
{
68
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
69
+ uint32_t val;
70
71
- if (value) {
72
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 1);
73
- } else {
74
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 0);
75
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 0);
76
+ cpu->lsx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
77
+ if (kvm_enabled()) {
78
+ /* kvm feature detection in function kvm_arch_init_vcpu */
79
+ return;
80
}
81
+
82
+ /* LSX feature detection in TCG mode */
83
+ val = cpu->env.cpucfg[2];
84
+ if (cpu->lsx == ON_OFF_AUTO_ON) {
85
+ if (FIELD_EX32(val, CPUCFG2, LSX) == 0) {
86
+ error_setg(errp, "Failed to enable LSX in TCG mode");
87
+ return;
88
+ }
89
+ }
90
+
91
+ cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value);
92
}
93
94
static bool loongarch_get_lasx(Object *obj, Error **errp)
95
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
96
{
97
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
98
99
+ cpu->lsx = ON_OFF_AUTO_AUTO;
100
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
101
loongarch_set_lsx);
102
object_property_add_bool(obj, "lasx", loongarch_get_lasx,
103
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
104
105
} else {
106
cpu->lbt = ON_OFF_AUTO_OFF;
107
+ cpu->pmu = ON_OFF_AUTO_OFF;
108
}
109
}
110
111
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
112
index XXXXXXX..XXXXXXX 100644
113
--- a/target/loongarch/cpu.h
114
+++ b/target/loongarch/cpu.h
115
@@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB;
116
#endif
117
118
enum loongarch_features {
119
+ LOONGARCH_FEATURE_LSX,
120
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
121
LOONGARCH_FEATURE_PMU,
122
};
123
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
124
uint32_t phy_id;
125
OnOffAuto lbt;
126
OnOffAuto pmu;
127
+ OnOffAuto lsx;
128
129
/* 'compatible' string for this CPU for Linux device trees */
130
const char *dtb_compatible;
131
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
132
index XXXXXXX..XXXXXXX 100644
133
--- a/target/loongarch/kvm/kvm.c
134
+++ b/target/loongarch/kvm/kvm.c
135
@@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
136
{
137
int ret;
138
struct kvm_device_attr attr;
139
+ uint64_t val;
140
141
switch (feature) {
142
+ case LOONGARCH_FEATURE_LSX:
143
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
144
+ attr.attr = KVM_LOONGARCH_VM_FEAT_LSX;
145
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
146
+ if (ret == 0) {
147
+ return true;
148
+ }
149
+
150
+ /* Fallback to old kernel detect interface */
151
+ val = 0;
152
+ attr.group = KVM_LOONGARCH_VCPU_CPUCFG;
153
+ /* Cpucfg2 */
154
+ attr.attr = 2;
155
+ attr.addr = (uint64_t)&val;
156
+ ret = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr);
157
+ if (!ret) {
158
+ ret = kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr);
159
+ if (ret) {
160
+ return false;
161
+ }
162
+
163
+ ret = FIELD_EX32((uint32_t)val, CPUCFG2, LSX);
164
+ return (ret != 0);
165
+ }
166
+ return false;
167
+
168
case LOONGARCH_FEATURE_LBT:
169
/*
170
* Return all if all the LBT features are supported such as:
171
@@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
172
return false;
173
}
174
175
+static int kvm_cpu_check_lsx(CPUState *cs, Error **errp)
20
+{
176
+{
21
+ int i;
177
+ CPULoongArchState *env = cpu_env(cs);
22
+
178
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
23
+ for (i = 0; i < s->num_cpu; i++) {
179
+ bool kvm_supported;
24
+ if (s->cpu[i].arch_id == arch_id) {
180
+
25
+ break;
181
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_LSX);
26
+ }
182
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LSX, 0);
183
+ if (cpu->lsx == ON_OFF_AUTO_ON) {
184
+ if (kvm_supported) {
185
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LSX, 1);
186
+ } else {
187
+ error_setg(errp, "'lsx' feature not supported by KVM on this host");
188
+ return -ENOTSUP;
189
+ }
190
+ } else if ((cpu->lsx == ON_OFF_AUTO_AUTO) && kvm_supported) {
191
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LSX, 1);
27
+ }
192
+ }
28
+
193
+
29
+ if ((i < s->num_cpu) && s->cpu[i].cpu) {
194
+ return 0;
30
+ return i;
195
+}
196
+
197
static int kvm_cpu_check_lbt(CPUState *cs, Error **errp)
198
{
199
CPULoongArchState *env = cpu_env(cs);
200
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
201
brk_insn = val;
202
}
203
204
+ ret = kvm_cpu_check_lsx(cs, &local_err);
205
+ if (ret < 0) {
206
+ error_report_err(local_err);
31
+ }
207
+ }
32
+
208
+
33
+ return -1;
209
ret = kvm_cpu_check_lbt(cs, &local_err);
34
+}
210
if (ret < 0) {
35
211
error_report_err(local_err);
36
static void extioi_update_irq(LoongArchExtIOICommonState *s, int irq, int level)
37
{
38
@@ -XXX,XX +XXX,XX @@ static inline void extioi_enable_irq(LoongArchExtIOICommonState *s, int index,\
39
static inline void extioi_update_sw_coremap(LoongArchExtIOICommonState *s,
40
int irq, uint64_t val, bool notify)
41
{
42
- int i, cpu;
43
+ int i, cpu, cpuid;
44
45
/*
46
* loongarch only support little endian,
47
@@ -XXX,XX +XXX,XX @@ static inline void extioi_update_sw_coremap(LoongArchExtIOICommonState *s,
48
val = cpu_to_le64(val);
49
50
for (i = 0; i < 4; i++) {
51
- cpu = val & 0xff;
52
+ cpuid = val & 0xff;
53
val = val >> 8;
54
55
if (!(s->status & BIT(EXTIOI_ENABLE_CPU_ENCODE))) {
56
- cpu = ctz32(cpu);
57
- cpu = (cpu >= 4) ? 0 : cpu;
58
+ cpuid = ctz32(cpuid);
59
+ cpuid = (cpuid >= 4) ? 0 : cpuid;
60
+ }
61
+
62
+ cpu = extioi_get_index_from_archid(s, cpuid);
63
+ if (cpu < 0) {
64
+ continue;
65
}
66
67
if (s->sw_coremap[irq + i] == cpu) {
68
--
212
--
69
2.43.5
213
2.43.5
diff view generated by jsdifflib
1
Supported CPU number can be acquired from function
1
Like LSX feature, add type OnOffAuto for LASX feature setting.
2
possible_cpu_arch_ids(), cpu-num property is not necessary.
3
2
4
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
3
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
5
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
4
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
6
---
5
---
7
hw/intc/loongarch_extioi.c | 6 ------
6
target/loongarch/cpu.c | 50 +++++++++++++++++++++++------------
8
hw/intc/loongarch_extioi_common.c | 17 +++++++++++++++--
7
target/loongarch/cpu.h | 2 ++
9
include/hw/intc/loongarch_extioi_common.h | 2 ++
8
target/loongarch/kvm/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++
10
3 files changed, 17 insertions(+), 8 deletions(-)
9
3 files changed, 89 insertions(+), 16 deletions(-)
11
10
12
diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
11
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
13
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/intc/loongarch_extioi.c
13
--- a/target/loongarch/cpu.c
15
+++ b/hw/intc/loongarch_extioi.c
14
+++ b/target/loongarch/cpu.c
16
@@ -XXX,XX +XXX,XX @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
15
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
17
s->status |= BIT(EXTIOI_ENABLE);
16
uint32_t val;
17
18
cpu->lsx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
19
+ if (cpu->lsx == ON_OFF_AUTO_OFF) {
20
+ cpu->lasx = ON_OFF_AUTO_OFF;
21
+ if (cpu->lasx == ON_OFF_AUTO_ON) {
22
+ error_setg(errp, "Failed to disable LSX since LASX is enabled");
23
+ return;
24
+ }
25
+ }
26
+
27
if (kvm_enabled()) {
28
/* kvm feature detection in function kvm_arch_init_vcpu */
29
return;
30
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
31
error_setg(errp, "Failed to enable LSX in TCG mode");
32
return;
33
}
34
+ } else {
35
+ cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, 0);
36
+ val = cpu->env.cpucfg[2];
18
}
37
}
19
38
20
- s->cpu = g_new0(ExtIOICore, s->num_cpu);
39
cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value);
21
- if (s->cpu == NULL) {
40
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
22
- error_setg(errp, "Memory allocation for ExtIOICore faile");
41
23
- return;
42
static bool loongarch_get_lasx(Object *obj, Error **errp)
43
{
44
- LoongArchCPU *cpu = LOONGARCH_CPU(obj);
45
- bool ret;
46
-
47
- if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
48
- ret = true;
49
- } else {
50
- ret = false;
24
- }
51
- }
25
-
52
- return ret;
26
for (i = 0; i < s->num_cpu; i++) {
53
+ return LOONGARCH_CPU(obj)->lasx != ON_OFF_AUTO_OFF;
27
for (pin = 0; pin < LS3A_INTC_IP; pin++) {
54
}
28
qdev_init_gpio_out(dev, &s->cpu[i].parent_irq[pin], 1);
55
29
diff --git a/hw/intc/loongarch_extioi_common.c b/hw/intc/loongarch_extioi_common.c
56
static void loongarch_set_lasx(Object *obj, bool value, Error **errp)
30
index XXXXXXX..XXXXXXX 100644
31
--- a/hw/intc/loongarch_extioi_common.c
32
+++ b/hw/intc/loongarch_extioi_common.c
33
@@ -XXX,XX +XXX,XX @@
34
static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
35
{
57
{
36
LoongArchExtIOICommonState *s = (LoongArchExtIOICommonState *)dev;
58
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
37
+ MachineState *machine = MACHINE(qdev_get_machine());
59
+ uint32_t val;
38
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
60
39
+ const CPUArchIdList *id_list;
61
- if (value) {
40
+ int i;
62
-    if (!FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
41
63
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 1);
42
- if (s->num_cpu == 0) {
64
-    }
43
- error_setg(errp, "num-cpu must be at least 1");
65
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 1);
44
+ assert(mc->possible_cpu_arch_ids);
66
- } else {
45
+ id_list = mc->possible_cpu_arch_ids(machine);
67
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 0);
46
+ s->num_cpu = id_list->len;
68
+ cpu->lasx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
47
+ s->cpu = g_new0(ExtIOICore, s->num_cpu);
69
+ if ((cpu->lsx == ON_OFF_AUTO_OFF) && (cpu->lasx == ON_OFF_AUTO_ON)) {
48
+ if (s->cpu == NULL) {
70
+ error_setg(errp, "Failed to enable LASX since lSX is disabled");
49
+ error_setg(errp, "Memory allocation for ExtIOICore faile");
71
+ return;
50
return;
72
+ }
73
+
74
+ if (kvm_enabled()) {
75
+ /* kvm feature detection in function kvm_arch_init_vcpu */
76
+ return;
51
}
77
}
52
+
78
+
53
+ for (i = 0; i < s->num_cpu; i++) {
79
+ /* LASX feature detection in TCG mode */
54
+ s->cpu[i].arch_id = id_list->cpus[i].arch_id;
80
+ val = cpu->env.cpucfg[2];
55
+ s->cpu[i].cpu = CPU(id_list->cpus[i].cpu);
81
+ if (cpu->lasx == ON_OFF_AUTO_ON) {
82
+ if (FIELD_EX32(val, CPUCFG2, LASX) == 0) {
83
+ error_setg(errp, "Failed to enable LASX in TCG mode");
84
+ return;
85
+ }
56
+ }
86
+ }
87
+
88
+ cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, value);
57
}
89
}
58
90
59
static int loongarch_extioi_common_pre_save(void *opaque)
91
static bool loongarch_get_lbt(Object *obj, Error **errp)
60
diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h
92
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
93
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
94
95
cpu->lsx = ON_OFF_AUTO_AUTO;
96
+ cpu->lasx = ON_OFF_AUTO_AUTO;
97
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
98
loongarch_set_lsx);
99
object_property_add_bool(obj, "lasx", loongarch_get_lasx,
100
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
61
index XXXXXXX..XXXXXXX 100644
101
index XXXXXXX..XXXXXXX 100644
62
--- a/include/hw/intc/loongarch_extioi_common.h
102
--- a/target/loongarch/cpu.h
63
+++ b/include/hw/intc/loongarch_extioi_common.h
103
+++ b/target/loongarch/cpu.h
64
@@ -XXX,XX +XXX,XX @@ typedef struct ExtIOICore {
104
@@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB;
65
uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
105
66
DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS);
106
enum loongarch_features {
67
qemu_irq parent_irq[LS3A_INTC_IP];
107
LOONGARCH_FEATURE_LSX,
68
+ uint64_t arch_id;
108
+ LOONGARCH_FEATURE_LASX,
69
+ CPUState *cpu;
109
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
70
} ExtIOICore;
110
LOONGARCH_FEATURE_PMU,
71
111
};
72
struct LoongArchExtIOICommonState {
112
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
113
OnOffAuto lbt;
114
OnOffAuto pmu;
115
OnOffAuto lsx;
116
+ OnOffAuto lasx;
117
118
/* 'compatible' string for this CPU for Linux device trees */
119
const char *dtb_compatible;
120
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
121
index XXXXXXX..XXXXXXX 100644
122
--- a/target/loongarch/kvm/kvm.c
123
+++ b/target/loongarch/kvm/kvm.c
124
@@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
125
}
126
return false;
127
128
+ case LOONGARCH_FEATURE_LASX:
129
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
130
+ attr.attr = KVM_LOONGARCH_VM_FEAT_LASX;
131
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
132
+ if (ret == 0) {
133
+ return true;
134
+ }
135
+
136
+ /* Fallback to old kernel detect interface */
137
+ val = 0;
138
+ attr.group = KVM_LOONGARCH_VCPU_CPUCFG;
139
+ /* Cpucfg2 */
140
+ attr.attr = 2;
141
+ attr.addr = (uint64_t)&val;
142
+ ret = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr);
143
+ if (!ret) {
144
+ ret = kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr);
145
+ if (ret) {
146
+ return false;
147
+ }
148
+
149
+ ret = FIELD_EX32((uint32_t)val, CPUCFG2, LASX);
150
+ return (ret != 0);
151
+ }
152
+ return false;
153
+
154
case LOONGARCH_FEATURE_LBT:
155
/*
156
* Return all if all the LBT features are supported such as:
157
@@ -XXX,XX +XXX,XX @@ static int kvm_cpu_check_lsx(CPUState *cs, Error **errp)
158
return 0;
159
}
160
161
+static int kvm_cpu_check_lasx(CPUState *cs, Error **errp)
162
+{
163
+ CPULoongArchState *env = cpu_env(cs);
164
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
165
+ bool kvm_supported;
166
+
167
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_LASX);
168
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LASX, 0);
169
+ if (cpu->lasx == ON_OFF_AUTO_ON) {
170
+ if (kvm_supported) {
171
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LASX, 1);
172
+ } else {
173
+ error_setg(errp, "'lasx' feature not supported by KVM on host");
174
+ return -ENOTSUP;
175
+ }
176
+ } else if ((cpu->lasx == ON_OFF_AUTO_AUTO) && kvm_supported) {
177
+ env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LASX, 1);
178
+ }
179
+
180
+ return 0;
181
+}
182
+
183
static int kvm_cpu_check_lbt(CPUState *cs, Error **errp)
184
{
185
CPULoongArchState *env = cpu_env(cs);
186
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
187
error_report_err(local_err);
188
}
189
190
+ ret = kvm_cpu_check_lasx(cs, &local_err);
191
+ if (ret < 0) {
192
+ error_report_err(local_err);
193
+ }
194
+
195
ret = kvm_cpu_check_lbt(cs, &local_err);
196
if (ret < 0) {
197
error_report_err(local_err);
73
--
198
--
74
2.43.5
199
2.43.5
diff view generated by jsdifflib