1
The following changes since commit 7efd65423ab22e6f5890ca08ae40c84d6660242f:
1
The following changes since commit 38d0939b86e2eef6f6a622c6f1f7befda0146595:
2
2
3
Merge tag 'pull-riscv-to-apply-20230614' of https://github.com/alistair23/qemu into staging (2023-06-14 05:28:51 +0200)
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/gaosong/qemu.git tags/pull-loongarch-20230616
7
https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20241227
8
8
9
for you to fetch changes up to 505aa8d8f29b79fcef77563bb4124208badbd8d4:
9
for you to fetch changes up to 5e360dabedb1ab1f15cce27a134ccbe4b8e18424:
10
10
11
target/loongarch: Fix CSR.DMW0-3.VSEG check (2023-06-16 17:58:46 +0800)
11
target/loongarch: Use auto method with LASX feature (2024-12-27 11:33:06 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
pull-loongarch-20230616
14
pull-loongarch-20241227
15
15
v1 ... v2
16
* Fix CSR.DMW0-3.VSEG check
16
1. Modify patch auther inconsistent with SOB
17
* Add cpu arch_id support
18
* Set physical cpuid route for LoongArch ipi device
19
* Add numa support
20
* Supplement cpu topology arguments
21
17
22
----------------------------------------------------------------
18
----------------------------------------------------------------
23
Jiajie Chen (1):
19
Bibo Mao (5):
24
target/loongarch: Fix CSR.DMW0-3.VSEG check
20
target/loongarch: Use actual operand size with vbsrl check
21
hw/loongarch/virt: Create fdt table on machine creation done notification
22
hw/loongarch/virt: Improve fdt table creation for CPU object
23
target/loongarch: Use auto method with LSX feature
24
target/loongarch: Use auto method with LASX feature
25
25
26
Tianrui Zhao (4):
26
Guo Hongyu (1):
27
hw/loongarch/virt: Add cpu arch_id support
27
target/loongarch: Fix vldi inst
28
hw/intc: Set physical cpuid route for LoongArch ipi device
29
hw/loongarch: Add numa support
30
hw/loongarch: Supplement cpu topology arguments
31
28
32
hw/intc/loongarch_ipi.c | 44 +++++++++++--
29
hw/loongarch/virt.c | 142 ++++++++++++++----------
33
hw/loongarch/Kconfig | 1 +
30
target/loongarch/cpu.c | 86 ++++++++------
34
hw/loongarch/acpi-build.c | 78 ++++++++++++++++++-----
31
target/loongarch/cpu.h | 4 +
35
hw/loongarch/virt.c | 144 ++++++++++++++++++++++++++++++++++++++----
32
target/loongarch/kvm/kvm.c | 107 ++++++++++++++++++
36
target/loongarch/cpu.h | 2 +
33
target/loongarch/tcg/insn_trans/trans_vec.c.inc | 4 +-
37
target/loongarch/tlb_helper.c | 4 +-
34
5 files changed, 249 insertions(+), 94 deletions(-)
38
6 files changed, 235 insertions(+), 38 deletions(-)
diff view generated by jsdifflib
New patch
1
From: Guo Hongyu <guohongyu24@mails.ucas.ac.cn>
1
2
3
Refer to the link below for a description of the vldi instructions:
4
https://jia.je/unofficial-loongarch-intrinsics-guide/lsx/misc/#synopsis_88
5
Fixed errors in vldi instruction implementation.
6
7
Signed-off-by: Guo Hongyu <guohongyu24@mails.ucas.ac.cn>
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(-)
15
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
18
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
19
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
20
@@ -XXX,XX +XXX,XX @@ static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm)
21
break;
22
case 1:
23
/* data: {2{16'0, imm[7:0], 8'0}} */
24
- data = (t << 24) | (t << 8);
25
+ data = (t << 40) | (t << 8);
26
break;
27
case 2:
28
/* data: {2{8'0, imm[7:0], 16'0}} */
29
--
30
2.43.5
diff view generated by jsdifflib
1
From: Jiajie Chen <c@jia.je>
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
The previous code checks whether the highest 16 bits of virtual address
5
Here actual operand size is used.
4
equal to that of CSR.DMW0-3. This is incorrect according to the spec,
5
and is corrected to compare only the highest four bits instead.
6
6
7
Signed-off-by: Jiajie Chen <c@jia.je>
7
Cc: qemu-stable@nongnu.org
8
Reviewed-by: Song Gao <gaosong@loongson.cn>
8
Fixes: df97f338076 ("target/loongarch: Implement xvreplve xvinsve0 xvpickve")
9
Message-Id: <20230614065556.2397513-1-c@jia.je>
9
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
10
Signed-off-by: Song Gao <gaosong@loongson.cn>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
---
12
---
12
target/loongarch/tlb_helper.c | 4 ++--
13
target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +-
13
1 file changed, 2 insertions(+), 2 deletions(-)
14
1 file changed, 1 insertion(+), 1 deletion(-)
14
15
15
diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c
16
diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
16
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
17
--- a/target/loongarch/tlb_helper.c
18
--- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc
18
+++ b/target/loongarch/tlb_helper.c
19
+++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc
19
@@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPULoongArchState *env, hwaddr *physical,
20
@@ -XXX,XX +XXX,XX @@ static bool do_vbsrl_v(DisasContext *ctx, arg_vv_i *a, uint32_t oprsz)
21
{
22
int i, ofs;
23
24
- if (!check_vec(ctx, 32)) {
25
+ if (!check_vec(ctx, oprsz)) {
26
return true;
20
}
27
}
21
28
22
plv = kernel_mode | (user_mode << R_CSR_DMW_PLV3_SHIFT);
23
- base_v = address >> TARGET_VIRT_ADDR_SPACE_BITS;
24
+ base_v = address >> R_CSR_DMW_VSEG_SHIFT;
25
/* Check direct map window */
26
for (int i = 0; i < 4; i++) {
27
- base_c = env->CSR_DMW[i] >> TARGET_VIRT_ADDR_SPACE_BITS;
28
+ base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW, VSEG);
29
if ((plv & env->CSR_DMW[i]) && (base_c == base_v)) {
30
*physical = dmw_va2pa(address);
31
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
32
--
29
--
33
2.39.1
30
2.43.5
31
32
diff view generated by jsdifflib
1
From: Tianrui Zhao <zhaotianrui@loongson.cn>
1
The same with ACPI table, fdt table is created on machine done
2
notification. Some objects like CPU objects can be created with cold-plug
3
method with command such as -smp x, -device la464-loongarch-cpu, so all
4
objects finish to create when machine is done.
2
5
3
Supplement LoongArch cpu topology arguments, including support socket
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
and threads per core.
7
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
8
---
9
hw/loongarch/virt.c | 103 ++++++++++++++++++++++++--------------------
10
1 file changed, 57 insertions(+), 46 deletions(-)
5
11
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Reviewed-by: Song Gao <gaosong@loongson.cn>
8
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
9
Signed-off-by: Song Gao <gaosong@loongson.cn>
10
Message-Id: <20230613123251.2471878-1-zhaotianrui@loongson.cn>
11
---
12
hw/loongarch/acpi-build.c | 4 ++++
13
hw/loongarch/virt.c | 9 ++++++++-
14
2 files changed, 12 insertions(+), 1 deletion(-)
15
16
diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/loongarch/acpi-build.c
19
+++ b/hw/loongarch/acpi-build.c
20
@@ -XXX,XX +XXX,XX @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine)
21
acpi_add_table(table_offsets, tables_blob);
22
build_madt(tables_blob, tables->linker, lams);
23
24
+ acpi_add_table(table_offsets, tables_blob);
25
+ build_pptt(tables_blob, tables->linker, machine,
26
+ lams->oem_id, lams->oem_table_id);
27
+
28
acpi_add_table(table_offsets, tables_blob);
29
build_srat(tables_blob, tables->linker, machine);
30
31
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
32
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/loongarch/virt.c
14
--- a/hw/loongarch/virt.c
34
+++ b/hw/loongarch/virt.c
15
+++ b/hw/loongarch/virt.c
35
@@ -XXX,XX +XXX,XX @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)
16
@@ -XXX,XX +XXX,XX @@ static void virt_build_smbios(LoongArchVirtMachineState *lvms)
36
for (n = 0; n < ms->possible_cpus->len; n++) {
17
}
37
ms->possible_cpus->cpus[n].type = ms->cpu_type;
18
}
38
ms->possible_cpus->cpus[n].arch_id = n;
19
39
+
20
+static void virt_fdt_setup(LoongArchVirtMachineState *lvms)
40
+ ms->possible_cpus->cpus[n].props.has_socket_id = true;
21
+{
41
+ ms->possible_cpus->cpus[n].props.socket_id =
22
+ MachineState *machine = MACHINE(lvms);
42
+ n / (ms->smp.cores * ms->smp.threads);
23
+ uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle;
43
ms->possible_cpus->cpus[n].props.has_core_id = true;
24
+ int i;
44
- ms->possible_cpus->cpus[n].props.core_id = n % ms->smp.cores;
25
+
45
+ ms->possible_cpus->cpus[n].props.core_id =
26
+ create_fdt(lvms);
46
+ n / ms->smp.threads % ms->smp.cores;
27
+ fdt_add_cpu_nodes(lvms);
47
+ ms->possible_cpus->cpus[n].props.has_thread_id = true;
28
+ fdt_add_memory_nodes(machine);
48
+ ms->possible_cpus->cpus[n].props.thread_id = n % ms->smp.threads;
29
+ fdt_add_fw_cfg_node(lvms);
49
}
30
+ fdt_add_flash_node(lvms);
50
return ms->possible_cpus;
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);
42
+
43
+ /*
44
+ * Create uart fdt node in reverse order so that they appear
45
+ * in the finished device tree lowest address first
46
+ */
47
+ for (i = VIRT_UART_COUNT; i-- > 0;) {
48
+ hwaddr base = VIRT_UART_BASE + i * VIRT_UART_SIZE;
49
+ int irq = VIRT_UART_IRQ + i - VIRT_GSI_BASE;
50
+ fdt_add_uart_node(lvms, &pch_pic_phandle, base, irq, i == 0);
51
+ }
52
+
53
+ fdt_add_rtc_node(lvms, &pch_pic_phandle);
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));
72
+}
73
+
74
static void virt_done(Notifier *notifier, void *data)
75
{
76
LoongArchVirtMachineState *lvms = container_of(notifier,
77
LoongArchVirtMachineState, machine_done);
78
virt_build_smbios(lvms);
79
loongarch_acpi_setup(lvms);
80
+ virt_fdt_setup(lvms);
81
}
82
83
static void virt_powerdown_req(Notifier *notifier, void *opaque)
84
@@ -XXX,XX +XXX,XX @@ static DeviceState *create_platform_bus(DeviceState *pch_pic)
85
}
86
87
static void virt_devices_init(DeviceState *pch_pic,
88
- LoongArchVirtMachineState *lvms,
89
- uint32_t *pch_pic_phandle,
90
- uint32_t *pch_msi_phandle)
91
+ LoongArchVirtMachineState *lvms)
92
{
93
MachineClass *mc = MACHINE_GET_CLASS(lvms);
94
DeviceState *gpex_dev;
95
@@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic,
96
gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i);
97
}
98
99
- /* Add pcie node */
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)
141
}
142
}
143
144
- /* Add Extend I/O Interrupt Controller node */
145
- fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle);
146
-
147
pch_pic = qdev_new(TYPE_LOONGARCH_PIC);
148
num = VIRT_PCH_PIC_IRQ_NUM;
149
qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num);
150
@@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms)
151
qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i));
152
}
153
154
- /* Add PCH PIC node */
155
- fdt_add_pch_pic_node(lvms, &eiointc_phandle, &pch_pic_phandle);
156
-
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);
51
}
224
}
52
--
225
--
53
2.39.1
226
2.43.5
54
55
diff view generated by jsdifflib
1
From: Tianrui Zhao <zhaotianrui@loongson.cn>
1
For CPU object, possible_cpu_arch_ids() function is used rather than
2
smp.cpus. With command -smp x, -device la464-loongarch-cpu, smp.cpus
3
is not accurate for all possible CPU objects, possible_cpu_arch_ids()
4
is used here.
2
5
3
1. Implement some functions for LoongArch numa support;
6
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
2. Implement fdt_add_memory_node() for fdt;
7
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
5
3. build_srat() fills node_id and adds build numa memory.
8
---
9
hw/loongarch/virt.c | 39 +++++++++++++++++++++++++--------------
10
1 file changed, 25 insertions(+), 14 deletions(-)
6
11
7
Reviewed-by: Song Gao <gaosong@loongson.cn>
8
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
9
Signed-off-by: Song Gao <gaosong@loongson.cn>
10
Message-Id: <20230613122613.2471743-1-zhaotianrui@loongson.cn>
11
---
12
hw/loongarch/Kconfig | 1 +
13
hw/loongarch/acpi-build.c | 60 +++++++++++++++++-----
14
hw/loongarch/virt.c | 102 +++++++++++++++++++++++++++++++++-----
15
3 files changed, 139 insertions(+), 24 deletions(-)
16
17
diff --git a/hw/loongarch/Kconfig b/hw/loongarch/Kconfig
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/loongarch/Kconfig
20
+++ b/hw/loongarch/Kconfig
21
@@ -XXX,XX +XXX,XX @@ config LOONGARCH_VIRT
22
select FW_CFG_DMA
23
select DIMM
24
select PFLASH_CFI01
25
+ select ACPI_HMAT
26
diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/loongarch/acpi-build.c
29
+++ b/hw/loongarch/acpi-build.c
30
@@ -XXX,XX +XXX,XX @@
31
#include "sysemu/tpm.h"
32
#include "hw/platform-bus.h"
33
#include "hw/acpi/aml-build.h"
34
+#include "hw/acpi/hmat.h"
35
36
#define ACPI_BUILD_ALIGN_SIZE 0x1000
37
#define ACPI_BUILD_TABLE_SIZE 0x20000
38
@@ -XXX,XX +XXX,XX @@ build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams)
39
static void
40
build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
41
{
42
- int i, arch_id;
43
+ int i, arch_id, node_id;
44
+ uint64_t mem_len, mem_base;
45
+ int nb_numa_nodes = machine->numa_state->num_nodes;
46
LoongArchMachineState *lams = LOONGARCH_MACHINE(machine);
47
- MachineState *ms = MACHINE(lams);
48
- MachineClass *mc = MACHINE_GET_CLASS(ms);
49
- const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms);
50
+ MachineClass *mc = MACHINE_GET_CLASS(lams);
51
+ const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(machine);
52
AcpiTable table = { .sig = "SRAT", .rev = 1, .oem_id = lams->oem_id,
53
.oem_table_id = lams->oem_table_id };
54
55
@@ -XXX,XX +XXX,XX @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
56
57
for (i = 0; i < arch_ids->len; ++i) {
58
arch_id = arch_ids->cpus[i].arch_id;
59
+ node_id = arch_ids->cpus[i].props.node_id;
60
61
/* Processor Local APIC/SAPIC Affinity Structure */
62
build_append_int_noprefix(table_data, 0, 1); /* Type */
63
build_append_int_noprefix(table_data, 16, 1); /* Length */
64
/* Proximity Domain [7:0] */
65
- build_append_int_noprefix(table_data, 0, 1);
66
+ build_append_int_noprefix(table_data, node_id, 1);
67
build_append_int_noprefix(table_data, arch_id, 1); /* APIC ID */
68
/* Flags, Table 5-36 */
69
build_append_int_noprefix(table_data, 1, 4);
70
@@ -XXX,XX +XXX,XX @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
71
build_append_int_noprefix(table_data, 0, 4); /* Reserved */
72
}
73
74
+ /* Node0 */
75
build_srat_memory(table_data, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE,
76
0, MEM_AFFINITY_ENABLED);
77
+ mem_base = VIRT_HIGHMEM_BASE;
78
+ if (!nb_numa_nodes) {
79
+ mem_len = machine->ram_size - VIRT_LOWMEM_SIZE;
80
+ } else {
81
+ mem_len = machine->numa_state->nodes[0].node_mem - VIRT_LOWMEM_SIZE;
82
+ }
83
+ if (mem_len)
84
+ build_srat_memory(table_data, mem_base, mem_len, 0, MEM_AFFINITY_ENABLED);
85
+
86
+ /* Node1 - Nodemax */
87
+ if (nb_numa_nodes) {
88
+ mem_base += mem_len;
89
+ for (i = 1; i < nb_numa_nodes; ++i) {
90
+ if (machine->numa_state->nodes[i].node_mem > 0) {
91
+ build_srat_memory(table_data, mem_base,
92
+ machine->numa_state->nodes[i].node_mem, i,
93
+ MEM_AFFINITY_ENABLED);
94
+ mem_base += machine->numa_state->nodes[i].node_mem;
95
+ }
96
+ }
97
+ }
98
99
- build_srat_memory(table_data, VIRT_HIGHMEM_BASE, machine->ram_size - VIRT_LOWMEM_SIZE,
100
- 0, MEM_AFFINITY_ENABLED);
101
-
102
- if (ms->device_memory) {
103
- build_srat_memory(table_data, ms->device_memory->base,
104
- memory_region_size(&ms->device_memory->mr),
105
- 0, MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);
106
+ if (machine->device_memory) {
107
+ build_srat_memory(table_data, machine->device_memory->base,
108
+ memory_region_size(&machine->device_memory->mr),
109
+ nb_numa_nodes - 1,
110
+ MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED);
111
}
112
113
acpi_table_end(linker, &table);
114
@@ -XXX,XX +XXX,XX @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine)
115
acpi_add_table(table_offsets, tables_blob);
116
build_srat(tables_blob, tables->linker, machine);
117
118
+ if (machine->numa_state->num_nodes) {
119
+ if (machine->numa_state->have_numa_distance) {
120
+ acpi_add_table(table_offsets, tables_blob);
121
+ build_slit(tables_blob, tables->linker, machine, lams->oem_id,
122
+ lams->oem_table_id);
123
+ }
124
+ if (machine->numa_state->hmat_enabled) {
125
+ acpi_add_table(table_offsets, tables_blob);
126
+ build_hmat(tables_blob, tables->linker, machine->numa_state,
127
+ lams->oem_id, lams->oem_table_id);
128
+ }
129
+ }
130
+
131
acpi_add_table(table_offsets, tables_blob);
132
{
133
AcpiMcfgInfo mcfg = {
134
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
135
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
136
--- a/hw/loongarch/virt.c
14
--- a/hw/loongarch/virt.c
137
+++ b/hw/loongarch/virt.c
15
+++ b/hw/loongarch/virt.c
138
@@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchMachineState *lams)
16
@@ -XXX,XX +XXX,XX @@ static void create_fdt(LoongArchVirtMachineState *lvms)
139
for (num = smp_cpus - 1; num >= 0; num--) {
17
static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
140
char *nodename = g_strdup_printf("/cpus/cpu@%d", num);
18
{
141
LoongArchCPU *cpu = LOONGARCH_CPU(qemu_get_cpu(num));
19
int num;
142
+ CPUState *cs = CPU(cpu);
20
- const MachineState *ms = MACHINE(lvms);
21
- int smp_cpus = ms->smp.cpus;
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);
143
47
144
qemu_fdt_add_subnode(ms->fdt, nodename);
48
qemu_fdt_add_subnode(ms->fdt, nodename);
145
qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu");
49
qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu");
146
qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
50
qemu_fdt_setprop_string(ms->fdt, nodename, "compatible",
147
cpu->dtb_compatible);
51
cpu->dtb_compatible);
148
+ if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
52
- if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
149
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id",
53
+ if (possible_cpus->cpus[num].props.has_node_id) {
150
+ ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
54
qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id",
151
+ }
55
- ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
56
+ possible_cpus->cpus[num].props.node_id);
57
}
152
qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num);
58
qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num);
153
qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle",
59
qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle",
154
qemu_fdt_alloc_phandle(ms->fdt));
60
@@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms)
155
@@ -XXX,XX +XXX,XX @@ static void fdt_add_irqchip_node(LoongArchMachineState *lams)
61
156
g_free(nodename);
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);
88
}
157
}
89
}
158
90
159
+static void fdt_add_memory_node(MachineState *ms,
160
+ uint64_t base, uint64_t size, int node_id)
161
+{
162
+ char *nodename = g_strdup_printf("/memory@%" PRIx64, base);
163
+
164
+ qemu_fdt_add_subnode(ms->fdt, nodename);
165
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
166
+ qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "memory");
167
+
168
+ if (ms->numa_state && ms->numa_state->num_nodes) {
169
+ qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id", node_id);
170
+ }
171
+
172
+ g_free(nodename);
173
+}
174
+
175
#define PM_BASE 0x10080000
176
#define PM_SIZE 0x100
177
#define PM_CTRL 0x10
178
@@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine)
179
const char *cpu_model = machine->cpu_type;
180
ram_addr_t offset = 0;
181
ram_addr_t ram_size = machine->ram_size;
182
- uint64_t highram_size = 0;
183
+ uint64_t highram_size = 0, phyAddr = 0;
184
MemoryRegion *address_space_mem = get_system_memory();
185
LoongArchMachineState *lams = LOONGARCH_MACHINE(machine);
186
+ int nb_numa_nodes = machine->numa_state->num_nodes;
187
+ NodeInfo *numa_info = machine->numa_state->nodes;
188
int i;
189
hwaddr fdt_base;
190
const CPUArchIdList *possible_cpus;
191
MachineClass *mc = MACHINE_GET_CLASS(machine);
192
CPUState *cpu;
193
+ char *ramName = NULL;
194
195
if (!cpu_model) {
196
cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
197
@@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine)
198
machine->possible_cpus->cpus[i].cpu = OBJECT(cpu);
199
}
200
fdt_add_cpu_nodes(lams);
201
- /* Add memory region */
202
- memory_region_init_alias(&lams->lowmem, NULL, "loongarch.lowram",
203
- machine->ram, 0, 256 * MiB);
204
- memory_region_add_subregion(address_space_mem, offset, &lams->lowmem);
205
- offset += 256 * MiB;
206
- memmap_add_entry(0, 256 * MiB, 1);
207
- highram_size = ram_size - 256 * MiB;
208
- memory_region_init_alias(&lams->highmem, NULL, "loongarch.highmem",
209
- machine->ram, offset, highram_size);
210
- memory_region_add_subregion(address_space_mem, 0x90000000, &lams->highmem);
211
- memmap_add_entry(0x90000000, highram_size, 1);
212
+
213
+ /* Node0 memory */
214
+ memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1);
215
+ fdt_add_memory_node(machine, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 0);
216
+ memory_region_init_alias(&lams->lowmem, NULL, "loongarch.node0.lowram",
217
+ machine->ram, offset, VIRT_LOWMEM_SIZE);
218
+ memory_region_add_subregion(address_space_mem, phyAddr, &lams->lowmem);
219
+
220
+ offset += VIRT_LOWMEM_SIZE;
221
+ if (nb_numa_nodes > 0) {
222
+ assert(numa_info[0].node_mem > VIRT_LOWMEM_SIZE);
223
+ highram_size = numa_info[0].node_mem - VIRT_LOWMEM_SIZE;
224
+ } else {
225
+ highram_size = ram_size - VIRT_LOWMEM_SIZE;
226
+ }
227
+ phyAddr = VIRT_HIGHMEM_BASE;
228
+ memmap_add_entry(phyAddr, highram_size, 1);
229
+ fdt_add_memory_node(machine, phyAddr, highram_size, 0);
230
+ memory_region_init_alias(&lams->highmem, NULL, "loongarch.node0.highram",
231
+ machine->ram, offset, highram_size);
232
+ memory_region_add_subregion(address_space_mem, phyAddr, &lams->highmem);
233
+
234
+ /* Node1 - Nodemax memory */
235
+ offset += highram_size;
236
+ phyAddr += highram_size;
237
+
238
+ for (i = 1; i < nb_numa_nodes; i++) {
239
+ MemoryRegion *nodemem = g_new(MemoryRegion, 1);
240
+ ramName = g_strdup_printf("loongarch.node%d.ram", i);
241
+ memory_region_init_alias(nodemem, NULL, ramName, machine->ram,
242
+ offset, numa_info[i].node_mem);
243
+ memory_region_add_subregion(address_space_mem, phyAddr, nodemem);
244
+ memmap_add_entry(phyAddr, numa_info[i].node_mem, 1);
245
+ fdt_add_memory_node(machine, phyAddr, numa_info[i].node_mem, i);
246
+ offset += numa_info[i].node_mem;
247
+ phyAddr += numa_info[i].node_mem;
248
+ }
249
250
/* initialize device memory address space */
251
if (machine->ram_size < machine->maxram_size) {
252
@@ -XXX,XX +XXX,XX @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)
253
return ms->possible_cpus;
254
}
255
256
+static CpuInstanceProperties
257
+virt_cpu_index_to_props(MachineState *ms, unsigned cpu_index)
258
+{
259
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
260
+ const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
261
+
262
+ assert(cpu_index < possible_cpus->len);
263
+ return possible_cpus->cpus[cpu_index].props;
264
+}
265
+
266
+static int64_t virt_get_default_cpu_node_id(const MachineState *ms, int idx)
267
+{
268
+ int64_t nidx = 0;
269
+
270
+ if (ms->numa_state->num_nodes) {
271
+ nidx = idx / (ms->smp.cpus / ms->numa_state->num_nodes);
272
+ if (ms->numa_state->num_nodes <= nidx) {
273
+ nidx = ms->numa_state->num_nodes - 1;
274
+ }
275
+ }
276
+ return nidx;
277
+}
278
+
279
static void loongarch_class_init(ObjectClass *oc, void *data)
280
{
281
MachineClass *mc = MACHINE_CLASS(oc);
282
@@ -XXX,XX +XXX,XX @@ static void loongarch_class_init(ObjectClass *oc, void *data)
283
mc->default_boot_order = "c";
284
mc->no_cdrom = 1;
285
mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
286
+ mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
287
+ mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
288
+ mc->numa_mem_supported = true;
289
+ mc->auto_enable_numa_with_memhp = true;
290
+ mc->auto_enable_numa_with_memdev = true;
291
mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
292
mc->default_nic = "virtio-net-pci";
293
hc->plug = loongarch_machine_device_plug_cb;
294
--
91
--
295
2.39.1
92
2.43.5
diff view generated by jsdifflib
1
From: Tianrui Zhao <zhaotianrui@loongson.cn>
1
Like LBT feature, add type OnOffAuto for LSX feature setting. Also
2
add LSX feature detection with new VM ioctl command, fallback to old
3
method if it is not supported.
2
4
3
With acpi madt table, there is cpu physical coreid, which may
5
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
be different with logical id in qemu. This patch adds cpu arch_id
6
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
5
support, and fill madt table with arch_id. For the present cpu
7
---
6
arch_id is still equal to logical id.
8
target/loongarch/cpu.c | 38 +++++++++++++++------------
9
target/loongarch/cpu.h | 2 ++
10
target/loongarch/kvm/kvm.c | 54 ++++++++++++++++++++++++++++++++++++++
11
3 files changed, 77 insertions(+), 17 deletions(-)
7
12
8
Reviewed-by: Song Gao <gaosong@loongson.cn>
13
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
9
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
10
Signed-off-by: Song Gao <gaosong@loongson.cn>
11
Message-Id: <20230613120552.2471420-2-zhaotianrui@loongson.cn>
12
---
13
hw/loongarch/acpi-build.c | 20 ++++++++++++++------
14
hw/loongarch/virt.c | 34 ++++++++++++++++++++++++++++++++--
15
2 files changed, 46 insertions(+), 8 deletions(-)
16
17
diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
18
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/loongarch/acpi-build.c
15
--- a/target/loongarch/cpu.c
20
+++ b/hw/loongarch/acpi-build.c
16
+++ b/target/loongarch/cpu.c
21
@@ -XXX,XX +XXX,XX @@ static void
17
@@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj)
22
build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams)
18
{
23
{
19
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
24
MachineState *ms = MACHINE(lams);
20
CPULoongArchState *env = &cpu->env;
25
- int i;
21
+ uint32_t data = 0;
26
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
22
int i;
27
+ const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms);
23
28
+ int i, arch_id;
24
for (i = 0; i < 21; i++) {
29
AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = lams->oem_id,
25
@@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj)
30
.oem_table_id = lams->oem_table_id };
26
cpu->dtb_compatible = "loongarch,Loongson-3A5000";
31
27
env->cpucfg[0] = 0x14c010; /* PRID */
32
@@ -XXX,XX +XXX,XX @@ build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams)
28
33
build_append_int_noprefix(table_data, 0, 4);
29
- uint32_t data = 0;
34
build_append_int_noprefix(table_data, 1 /* PCAT_COMPAT */, 4); /* Flags */
30
data = FIELD_DP32(data, CPUCFG1, ARCH, 2);
35
31
data = FIELD_DP32(data, CPUCFG1, PGMMU, 1);
36
- for (i = 0; i < ms->smp.cpus; i++) {
32
data = FIELD_DP32(data, CPUCFG1, IOCSR, 1);
37
+ for (i = 0; i < arch_ids->len; i++) {
33
@@ -XXX,XX +XXX,XX @@ static void loongarch_la132_initfn(Object *obj)
38
/* Processor Core Interrupt Controller Structure */
34
{
39
+ arch_id = arch_ids->cpus[i].arch_id;
35
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
40
+
36
CPULoongArchState *env = &cpu->env;
41
build_append_int_noprefix(table_data, 17, 1); /* Type */
37
-
42
build_append_int_noprefix(table_data, 15, 1); /* Length */
38
+ uint32_t data = 0;
43
build_append_int_noprefix(table_data, 1, 1); /* Version */
39
int i;
44
build_append_int_noprefix(table_data, i + 1, 4); /* ACPI Processor ID */
40
45
- build_append_int_noprefix(table_data, i, 4); /* Core ID */
41
for (i = 0; i < 21; i++) {
46
+ build_append_int_noprefix(table_data, arch_id, 4); /* Core ID */
42
@@ -XXX,XX +XXX,XX @@ static void loongarch_la132_initfn(Object *obj)
47
build_append_int_noprefix(table_data, 1, 4); /* Flags */
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;
48
}
80
}
49
81
+
50
@@ -XXX,XX +XXX,XX @@ build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams)
82
+ /* LSX feature detection in TCG mode */
51
static void
83
+ val = cpu->env.cpucfg[2];
52
build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
84
+ if (cpu->lsx == ON_OFF_AUTO_ON) {
53
{
85
+ if (FIELD_EX32(val, CPUCFG2, LSX) == 0) {
54
- uint64_t i;
86
+ error_setg(errp, "Failed to enable LSX in TCG mode");
55
+ int i, arch_id;
87
+ return;
56
LoongArchMachineState *lams = LOONGARCH_MACHINE(machine);
88
+ }
57
MachineState *ms = MACHINE(lams);
89
+ }
58
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
90
+
59
+ const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms);
91
+ cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value);
60
AcpiTable table = { .sig = "SRAT", .rev = 1, .oem_id = lams->oem_id,
92
}
61
.oem_table_id = lams->oem_table_id };
93
62
94
static bool loongarch_get_lasx(Object *obj, Error **errp)
63
@@ -XXX,XX +XXX,XX @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine)
95
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
64
build_append_int_noprefix(table_data, 1, 4); /* Reserved */
96
{
65
build_append_int_noprefix(table_data, 0, 8); /* Reserved */
97
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
66
98
67
- for (i = 0; i < ms->smp.cpus; ++i) {
99
+ cpu->lsx = ON_OFF_AUTO_AUTO;
68
+ for (i = 0; i < arch_ids->len; ++i) {
100
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
69
+ arch_id = arch_ids->cpus[i].arch_id;
101
loongarch_set_lsx);
70
+
102
object_property_add_bool(obj, "lasx", loongarch_get_lasx,
71
/* Processor Local APIC/SAPIC Affinity Structure */
103
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
72
build_append_int_noprefix(table_data, 0, 1); /* Type */
104
73
build_append_int_noprefix(table_data, 16, 1); /* Length */
105
} else {
74
/* Proximity Domain [7:0] */
106
cpu->lbt = ON_OFF_AUTO_OFF;
75
build_append_int_noprefix(table_data, 0, 1);
107
+ cpu->pmu = ON_OFF_AUTO_OFF;
76
- build_append_int_noprefix(table_data, i, 1); /* APIC ID */
108
}
77
+ build_append_int_noprefix(table_data, arch_id, 1); /* APIC ID */
109
}
78
/* Flags, Table 5-36 */
110
79
build_append_int_noprefix(table_data, 1, 4);
111
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
80
build_append_int_noprefix(table_data, 0, 1); /* Local SAPIC EID */
81
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
82
index XXXXXXX..XXXXXXX 100644
112
index XXXXXXX..XXXXXXX 100644
83
--- a/hw/loongarch/virt.c
113
--- a/target/loongarch/cpu.h
84
+++ b/hw/loongarch/virt.c
114
+++ b/target/loongarch/cpu.h
85
@@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine)
115
@@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB;
86
LoongArchMachineState *lams = LOONGARCH_MACHINE(machine);
116
#endif
87
int i;
117
88
hwaddr fdt_base;
118
enum loongarch_features {
89
+ const CPUArchIdList *possible_cpus;
119
+ LOONGARCH_FEATURE_LSX,
90
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
120
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
91
+ CPUState *cpu;
121
LOONGARCH_FEATURE_PMU,
92
122
};
93
if (!cpu_model) {
123
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
94
cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
124
uint32_t phy_id;
95
@@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine)
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)
176
+{
177
+ CPULoongArchState *env = cpu_env(cs);
178
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
179
+ bool kvm_supported;
180
+
181
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_LSX);
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);
192
+ }
193
+
194
+ return 0;
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;
96
}
202
}
97
create_fdt(lams);
203
98
/* Init CPUs */
204
+ ret = kvm_cpu_check_lsx(cs, &local_err);
99
- for (i = 0; i < machine->smp.cpus; i++) {
205
+ if (ret < 0) {
100
- cpu_create(machine->cpu_type);
206
+ error_report_err(local_err);
101
+
102
+ possible_cpus = mc->possible_cpu_arch_ids(machine);
103
+ for (i = 0; i < possible_cpus->len; i++) {
104
+ cpu = cpu_create(machine->cpu_type);
105
+ cpu->cpu_index = i;
106
+ machine->possible_cpus->cpus[i].cpu = OBJECT(cpu);
107
}
108
fdt_add_cpu_nodes(lams);
109
/* Add memory region */
110
@@ -XXX,XX +XXX,XX @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
111
return NULL;
112
}
113
114
+static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)
115
+{
116
+ int n;
117
+ unsigned int max_cpus = ms->smp.max_cpus;
118
+
119
+ if (ms->possible_cpus) {
120
+ assert(ms->possible_cpus->len == max_cpus);
121
+ return ms->possible_cpus;
122
+ }
207
+ }
123
+
208
+
124
+ ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
209
ret = kvm_cpu_check_lbt(cs, &local_err);
125
+ sizeof(CPUArchId) * max_cpus);
210
if (ret < 0) {
126
+ ms->possible_cpus->len = max_cpus;
211
error_report_err(local_err);
127
+ for (n = 0; n < ms->possible_cpus->len; n++) {
128
+ ms->possible_cpus->cpus[n].type = ms->cpu_type;
129
+ ms->possible_cpus->cpus[n].arch_id = n;
130
+ ms->possible_cpus->cpus[n].props.has_core_id = true;
131
+ ms->possible_cpus->cpus[n].props.core_id = n % ms->smp.cores;
132
+ }
133
+ return ms->possible_cpus;
134
+}
135
+
136
static void loongarch_class_init(ObjectClass *oc, void *data)
137
{
138
MachineClass *mc = MACHINE_CLASS(oc);
139
@@ -XXX,XX +XXX,XX @@ static void loongarch_class_init(ObjectClass *oc, void *data)
140
mc->block_default_type = IF_VIRTIO;
141
mc->default_boot_order = "c";
142
mc->no_cdrom = 1;
143
+ mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
144
mc->get_hotplug_handler = virt_machine_get_hotplug_handler;
145
mc->default_nic = "virtio-net-pci";
146
hc->plug = loongarch_machine_device_plug_cb;
147
--
212
--
148
2.39.1
213
2.43.5
diff view generated by jsdifflib
1
From: Tianrui Zhao <zhaotianrui@loongson.cn>
1
Like LSX feature, add type OnOffAuto for LASX feature setting.
2
2
3
LoongArch ipi device uses physical cpuid to route to different
3
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
4
vcpus rather logical cpuid, and the physical cpuid is the same
4
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
5
with cpuid in acpi dsdt and srat table.
5
---
6
target/loongarch/cpu.c | 50 +++++++++++++++++++++++------------
7
target/loongarch/cpu.h | 2 ++
8
target/loongarch/kvm/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++
9
3 files changed, 89 insertions(+), 16 deletions(-)
6
10
7
Reviewed-by: Song Gao <gaosong@loongson.cn>
11
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
8
Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
9
Signed-off-by: Song Gao <gaosong@loongson.cn>
10
Message-Id: <20230613120552.2471420-3-zhaotianrui@loongson.cn>
11
---
12
hw/intc/loongarch_ipi.c | 44 ++++++++++++++++++++++++++++++++++-------
13
hw/loongarch/virt.c | 1 +
14
target/loongarch/cpu.h | 2 ++
15
3 files changed, 40 insertions(+), 7 deletions(-)
16
17
diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
18
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/intc/loongarch_ipi.c
13
--- a/target/loongarch/cpu.c
20
+++ b/hw/intc/loongarch_ipi.c
14
+++ b/target/loongarch/cpu.c
21
@@ -XXX,XX +XXX,XX @@
15
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
22
#include "target/loongarch/internals.h"
16
uint32_t val;
23
#include "trace.h"
17
24
18
cpu->lsx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
25
+static void loongarch_ipi_writel(void *, hwaddr, uint64_t, unsigned);
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
+
26
+
27
static uint64_t loongarch_ipi_readl(void *opaque, hwaddr addr, unsigned size)
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];
37
}
38
39
cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value);
40
@@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp)
41
42
static bool loongarch_get_lasx(Object *obj, Error **errp)
28
{
43
{
29
IPICore *s = opaque;
44
- LoongArchCPU *cpu = LOONGARCH_CPU(obj);
30
@@ -XXX,XX +XXX,XX @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr)
45
- bool ret;
31
data, MEMTXATTRS_UNSPECIFIED, NULL);
46
-
47
- if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
48
- ret = true;
49
- } else {
50
- ret = false;
51
- }
52
- return ret;
53
+ return LOONGARCH_CPU(obj)->lasx != ON_OFF_AUTO_OFF;
32
}
54
}
33
55
34
+static int archid_cmp(const void *a, const void *b)
56
static void loongarch_set_lasx(Object *obj, bool value, Error **errp)
35
+{
57
{
36
+ CPUArchId *archid_a = (CPUArchId *)a;
58
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
37
+ CPUArchId *archid_b = (CPUArchId *)b;
59
+ uint32_t val;
60
61
- if (value) {
62
-    if (!FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
63
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 1);
64
-    }
65
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 1);
66
- } else {
67
- cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 0);
68
+ cpu->lasx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
69
+ if ((cpu->lsx == ON_OFF_AUTO_OFF) && (cpu->lasx == ON_OFF_AUTO_ON)) {
70
+ error_setg(errp, "Failed to enable LASX since lSX is disabled");
71
+ return;
72
+ }
38
+
73
+
39
+ return archid_a->arch_id - archid_b->arch_id;
74
+ if (kvm_enabled()) {
40
+}
75
+ /* kvm feature detection in function kvm_arch_init_vcpu */
76
+ return;
77
}
41
+
78
+
42
+static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id)
79
+ /* LASX feature detection in TCG mode */
43
+{
80
+ val = cpu->env.cpucfg[2];
44
+ CPUArchId apic_id, *found_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
+ }
86
+ }
45
+
87
+
46
+ apic_id.arch_id = id;
88
+ cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, value);
47
+ found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus,
48
+ ms->possible_cpus->len, sizeof(*ms->possible_cpus->cpus),
49
+ archid_cmp);
50
+
51
+ return found_cpu;
52
+}
53
+
54
+static CPUState *ipi_getcpu(int arch_id)
55
+{
56
+ MachineState *machine = MACHINE(qdev_get_machine());
57
+ CPUArchId *archid;
58
+
59
+ archid = find_cpu_by_archid(machine, arch_id);
60
+ return CPU(archid->cpu);
61
+}
62
+
63
static void ipi_send(uint64_t val)
64
{
65
uint32_t cpuid;
66
uint8_t vector;
67
- CPULoongArchState *env;
68
CPUState *cs;
69
LoongArchCPU *cpu;
70
+ LoongArchIPI *s;
71
72
cpuid = extract32(val, 16, 10);
73
if (cpuid >= LOONGARCH_MAX_CPUS) {
74
@@ -XXX,XX +XXX,XX @@ static void ipi_send(uint64_t val)
75
/* IPI status vector */
76
vector = extract8(val, 0, 5);
77
78
- cs = qemu_get_cpu(cpuid);
79
+ cs = ipi_getcpu(cpuid);
80
cpu = LOONGARCH_CPU(cs);
81
- env = &cpu->env;
82
- address_space_stl(&env->address_space_iocsr, 0x1008,
83
- BIT(vector), MEMTXATTRS_UNSPECIFIED, NULL);
84
+ s = LOONGARCH_IPI(cpu->env.ipistate);
85
+ loongarch_ipi_writel(&s->ipi_core, CORE_SET_OFF, BIT(vector), 4);
86
}
89
}
87
90
88
static void mail_send(uint64_t val)
91
static bool loongarch_get_lbt(Object *obj, Error **errp)
89
@@ -XXX,XX +XXX,XX @@ static void mail_send(uint64_t val)
92
@@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj)
90
}
93
LoongArchCPU *cpu = LOONGARCH_CPU(obj);
91
94
92
addr = 0x1020 + (val & 0x1c);
95
cpu->lsx = ON_OFF_AUTO_AUTO;
93
- cs = qemu_get_cpu(cpuid);
96
+ cpu->lasx = ON_OFF_AUTO_AUTO;
94
+ cs = ipi_getcpu(cpuid);
97
object_property_add_bool(obj, "lsx", loongarch_get_lsx,
95
cpu = LOONGARCH_CPU(cs);
98
loongarch_set_lsx);
96
env = &cpu->env;
99
object_property_add_bool(obj, "lasx", loongarch_get_lasx,
97
send_ipi_data(env, val, addr);
98
@@ -XXX,XX +XXX,XX @@ static void any_send(uint64_t val)
99
}
100
101
addr = val & 0xffff;
102
- cs = qemu_get_cpu(cpuid);
103
+ cs = ipi_getcpu(cpuid);
104
cpu = LOONGARCH_CPU(cs);
105
env = &cpu->env;
106
send_ipi_data(env, val, addr);
107
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
108
index XXXXXXX..XXXXXXX 100644
109
--- a/hw/loongarch/virt.c
110
+++ b/hw/loongarch/virt.c
111
@@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams)
112
memory_region_add_subregion(&env->system_iocsr, APIC_BASE,
113
sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi),
114
cpu));
115
+ env->ipistate = ipi;
116
}
117
118
/*
119
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
100
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
120
index XXXXXXX..XXXXXXX 100644
101
index XXXXXXX..XXXXXXX 100644
121
--- a/target/loongarch/cpu.h
102
--- a/target/loongarch/cpu.h
122
+++ b/target/loongarch/cpu.h
103
+++ b/target/loongarch/cpu.h
123
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState {
104
@@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB;
124
MemoryRegion iocsr_mem;
105
125
bool load_elf;
106
enum loongarch_features {
126
uint64_t elf_address;
107
LOONGARCH_FEATURE_LSX,
127
+ /* Store ipistate to access from this struct */
108
+ LOONGARCH_FEATURE_LASX,
128
+ DeviceState *ipistate;
109
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
129
#endif
110
LOONGARCH_FEATURE_PMU,
130
} CPULoongArchState;
111
};
131
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);
132
--
198
--
133
2.39.1
199
2.43.5
diff view generated by jsdifflib