1 | The following changes since commit 6af8037c42fdc3d20d5aa2686799ab356a9ee1a9: | 1 | The following changes since commit 38d0939b86e2eef6f6a622c6f1f7befda0146595: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-vfio-20240522' of https://github.com/legoater/qemu into staging (2024-05-22 06:02:06 -0700) | 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-20240523 | 7 | https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20241227 |
8 | 8 | ||
9 | for you to fetch changes up to 6204af704a071ea68d3af55c0502b112a7af9546: | 9 | for you to fetch changes up to 5e360dabedb1ab1f15cce27a134ccbe4b8e18424: |
10 | 10 | ||
11 | hw/loongarch/virt: Fix FDT memory node address width (2024-05-23 09:30: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-20240523 | 14 | pull-loongarch-20241227 |
15 | v1 ... v2 | ||
16 | 1. Modify patch auther inconsistent with SOB | ||
15 | 17 | ||
16 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
17 | Bibo Mao (7): | 19 | Bibo Mao (5): |
18 | hw/loongarch: Add VM mode in IOCSR feature register in kvm mode | 20 | target/loongarch: Use actual operand size with vbsrl check |
19 | hw/loongarch: Refine acpi srat table for numa memory | 21 | hw/loongarch/virt: Create fdt table on machine creation done notification |
20 | hw/loongarch: Refine fadt memory table for numa memory | 22 | hw/loongarch/virt: Improve fdt table creation for CPU object |
21 | hw/loongarch: Refine fwcfg memory map | 23 | target/loongarch: Use auto method with LSX feature |
22 | hw/loongarch: Refine system dram memory region | 24 | target/loongarch: Use auto method with LASX feature |
23 | hw/loongarch: Remove minimum and default memory size | ||
24 | target/loongarch: Add loongarch vector property unconditionally | ||
25 | 25 | ||
26 | Jiaxun Yang (1): | 26 | Guo Hongyu (1): |
27 | hw/loongarch/virt: Fix FDT memory node address width | 27 | target/loongarch: Fix vldi inst |
28 | 28 | ||
29 | Song Gao (2): | 29 | hw/loongarch/virt.c | 142 ++++++++++++++---------- |
30 | target/loongarch/kvm: Fix VM recovery from disk failures | 30 | target/loongarch/cpu.c | 86 ++++++++------ |
31 | target/loongarch/kvm: fpu save the vreg registers high 192bit | 31 | target/loongarch/cpu.h | 4 + |
32 | 32 | target/loongarch/kvm/kvm.c | 107 ++++++++++++++++++ | |
33 | hw/loongarch/acpi-build.c | 58 +++++++++------ | 33 | target/loongarch/tcg/insn_trans/trans_vec.c.inc | 4 +- |
34 | hw/loongarch/virt.c | 179 ++++++++++++++++++++++++++++++++------------- | 34 | 5 files changed, 249 insertions(+), 94 deletions(-) |
35 | target/loongarch/cpu.c | 14 +--- | ||
36 | target/loongarch/kvm/kvm.c | 6 ++ | ||
37 | target/loongarch/machine.c | 6 +- | ||
38 | 5 files changed, 176 insertions(+), 87 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 | Higher bits for memory nodes were omitted at qemu_fdt_setprop_cells. | 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. | ||
4 | 6 | ||
5 | Cc: qemu-stable@nongnu.org | 7 | Signed-off-by: Guo Hongyu <guohongyu24@mails.ucas.ac.cn> |
6 | Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> | 8 | Tested-by: Xianglai Li <lixianglai@loongson.cn> |
7 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 9 | Signed-off-by: Xianglai Li <lixianglai@loongson.cn> |
8 | Message-Id: <20240520-loongarch-fdt-memnode-v1-1-5ea9be93911e@flygoat.com> | 10 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
9 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 11 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
10 | --- | 12 | --- |
11 | hw/loongarch/virt.c | 3 ++- | 13 | target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +- |
12 | 1 file changed, 2 insertions(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 15 | ||
14 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 16 | diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/loongarch/virt.c | 18 | --- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
17 | +++ b/hw/loongarch/virt.c | 19 | +++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
18 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_memory_node(MachineState *ms, | 20 | @@ -XXX,XX +XXX,XX @@ static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm) |
19 | char *nodename = g_strdup_printf("/memory@%" PRIx64, base); | 21 | break; |
20 | 22 | case 1: | |
21 | qemu_fdt_add_subnode(ms->fdt, nodename); | 23 | /* data: {2{16'0, imm[7:0], 8'0}} */ |
22 | - qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, base, 0, size); | 24 | - data = (t << 24) | (t << 8); |
23 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", base >> 32, base, | 25 | + data = (t << 40) | (t << 8); |
24 | + size >> 32, size); | 26 | break; |
25 | qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "memory"); | 27 | case 2: |
26 | 28 | /* data: {2{8'0, imm[7:0], 16'0}} */ | |
27 | if (ms->numa_state && ms->numa_state->num_nodes) { | ||
28 | -- | 29 | -- |
29 | 2.34.1 | 30 | 2.43.5 | diff view generated by jsdifflib |
1 | vmstate does not save kvm_state_conter, | 1 | Hardcoded 32 bytes is used for vbsrl emulation check, there is |
---|---|---|---|
2 | which can cause VM recovery from disk to fail. | 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. | ||
4 | |||
5 | Here actual operand size is used. | ||
3 | 6 | ||
4 | Cc: qemu-stable@nongnu.org | 7 | Cc: qemu-stable@nongnu.org |
5 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 8 | Fixes: df97f338076 ("target/loongarch: Implement xvreplve xvinsve0 xvpickve") |
6 | Acked-by: Peter Xu <peterx@redhat.com> | 9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
7 | Message-Id: <20240508024732.3127792-1-gaosong@loongson.cn> | 10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
8 | --- | 12 | --- |
9 | target/loongarch/machine.c | 6 ++++-- | 13 | target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +- |
10 | 1 file changed, 4 insertions(+), 2 deletions(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 15 | ||
12 | diff --git a/target/loongarch/machine.c b/target/loongarch/machine.c | 16 | diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
13 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/loongarch/machine.c | 18 | --- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
15 | +++ b/target/loongarch/machine.c | 19 | +++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
16 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_tlb = { | 20 | @@ -XXX,XX +XXX,XX @@ static bool do_vbsrl_v(DisasContext *ctx, arg_vv_i *a, uint32_t oprsz) |
17 | /* LoongArch CPU state */ | 21 | { |
18 | const VMStateDescription vmstate_loongarch_cpu = { | 22 | int i, ofs; |
19 | .name = "cpu", | 23 | |
20 | - .version_id = 1, | 24 | - if (!check_vec(ctx, 32)) { |
21 | - .minimum_version_id = 1, | 25 | + if (!check_vec(ctx, oprsz)) { |
22 | + .version_id = 2, | 26 | return true; |
23 | + .minimum_version_id = 2, | 27 | } |
24 | .fields = (const VMStateField[]) { | 28 | |
25 | VMSTATE_UINTTL_ARRAY(env.gpr, LoongArchCPU, 32), | ||
26 | VMSTATE_UINTTL(env.pc, LoongArchCPU), | ||
27 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_loongarch_cpu = { | ||
28 | VMSTATE_UINT64(env.CSR_DERA, LoongArchCPU), | ||
29 | VMSTATE_UINT64(env.CSR_DSAVE, LoongArchCPU), | ||
30 | |||
31 | + VMSTATE_UINT64(kvm_state_counter, LoongArchCPU), | ||
32 | + | ||
33 | VMSTATE_END_OF_LIST() | ||
34 | }, | ||
35 | .subsections = (const VMStateDescription * const []) { | ||
36 | -- | 29 | -- |
37 | 2.34.1 | 30 | 2.43.5 |
31 | |||
32 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | On kvm side, get_fpu/set_fpu save the vreg registers high 192bits, | ||
2 | but QEMU missing. | ||
3 | 1 | ||
4 | Cc: qemu-stable@nongnu.org | ||
5 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
7 | Message-Id: <20240514110752.989572-1-gaosong@loongson.cn> | ||
8 | --- | ||
9 | target/loongarch/kvm/kvm.c | 6 ++++++ | ||
10 | 1 file changed, 6 insertions(+) | ||
11 | |||
12 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/loongarch/kvm/kvm.c | ||
15 | +++ b/target/loongarch/kvm/kvm.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static int kvm_loongarch_get_regs_fp(CPUState *cs) | ||
17 | env->fcsr0 = fpu.fcsr; | ||
18 | for (i = 0; i < 32; i++) { | ||
19 | env->fpr[i].vreg.UD[0] = fpu.fpr[i].val64[0]; | ||
20 | + env->fpr[i].vreg.UD[1] = fpu.fpr[i].val64[1]; | ||
21 | + env->fpr[i].vreg.UD[2] = fpu.fpr[i].val64[2]; | ||
22 | + env->fpr[i].vreg.UD[3] = fpu.fpr[i].val64[3]; | ||
23 | } | ||
24 | for (i = 0; i < 8; i++) { | ||
25 | env->cf[i] = fpu.fcc & 0xFF; | ||
26 | @@ -XXX,XX +XXX,XX @@ static int kvm_loongarch_put_regs_fp(CPUState *cs) | ||
27 | fpu.fcc = 0; | ||
28 | for (i = 0; i < 32; i++) { | ||
29 | fpu.fpr[i].val64[0] = env->fpr[i].vreg.UD[0]; | ||
30 | + fpu.fpr[i].val64[1] = env->fpr[i].vreg.UD[1]; | ||
31 | + fpu.fpr[i].val64[2] = env->fpr[i].vreg.UD[2]; | ||
32 | + fpu.fpr[i].val64[3] = env->fpr[i].vreg.UD[3]; | ||
33 | } | ||
34 | |||
35 | for (i = 0; i < 8; i++) { | ||
36 | -- | ||
37 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bibo Mao <maobibo@loongson.cn> | ||
2 | 1 | ||
3 | If VM runs in kvm mode, VM mode is added in IOCSR feature register. | ||
4 | So guest can detect kvm hypervisor type and enable possible pv functions. | ||
5 | |||
6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
7 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
8 | Message-Id: <20240514025109.3238398-1-maobibo@loongson.cn> | ||
9 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
10 | --- | ||
11 | hw/loongarch/virt.c | 12 +++++++++--- | ||
12 | 1 file changed, 9 insertions(+), 3 deletions(-) | ||
13 | |||
14 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/loongarch/virt.c | ||
17 | +++ b/hw/loongarch/virt.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #include "qapi/error.h" | ||
20 | #include "hw/boards.h" | ||
21 | #include "hw/char/serial.h" | ||
22 | +#include "sysemu/kvm.h" | ||
23 | #include "sysemu/sysemu.h" | ||
24 | #include "sysemu/qtest.h" | ||
25 | #include "sysemu/runstate.h" | ||
26 | @@ -XXX,XX +XXX,XX @@ static void virt_iocsr_misc_write(void *opaque, hwaddr addr, | ||
27 | |||
28 | static uint64_t virt_iocsr_misc_read(void *opaque, hwaddr addr, unsigned size) | ||
29 | { | ||
30 | + uint64_t ret; | ||
31 | + | ||
32 | switch (addr) { | ||
33 | case VERSION_REG: | ||
34 | return 0x11ULL; | ||
35 | case FEATURE_REG: | ||
36 | - return 1ULL << IOCSRF_MSI | 1ULL << IOCSRF_EXTIOI | | ||
37 | - 1ULL << IOCSRF_CSRIPI; | ||
38 | + ret = BIT(IOCSRF_MSI) | BIT(IOCSRF_EXTIOI) | BIT(IOCSRF_CSRIPI); | ||
39 | + if (kvm_enabled()) { | ||
40 | + ret |= BIT(IOCSRF_VM); | ||
41 | + } | ||
42 | + return ret; | ||
43 | case VENDOR_REG: | ||
44 | return 0x6e6f73676e6f6f4cULL; /* "Loongson" */ | ||
45 | case CPUNAME_REG: | ||
46 | return 0x303030354133ULL; /* "3A5000" */ | ||
47 | case MISC_FUNC_REG: | ||
48 | - return 1ULL << IOCSRM_EXTIOI_EN; | ||
49 | + return BIT_ULL(IOCSRM_EXTIOI_EN); | ||
50 | } | ||
51 | return 0ULL; | ||
52 | } | ||
53 | -- | ||
54 | 2.34.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bibo Mao <maobibo@loongson.cn> | ||
2 | 1 | ||
3 | One LoongArch virt machine platform, there is limitation for memory | ||
4 | map information. The minimum memory size is 256M and minimum memory | ||
5 | size for numa node0 is 256M also. With qemu numa qtest, it is possible | ||
6 | that memory size of numa node0 is 128M. | ||
7 | |||
8 | Limitations for minimum memory size for both total memory and numa | ||
9 | node0 is removed for acpi srat table creation. | ||
10 | |||
11 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
12 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
13 | Message-Id: <20240515093927.3453674-2-maobibo@loongson.cn> | ||
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
15 | --- | ||
16 | hw/loongarch/acpi-build.c | 58 +++++++++++++++++++++++---------------- | ||
17 | 1 file changed, 34 insertions(+), 24 deletions(-) | ||
18 | |||
19 | diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/hw/loongarch/acpi-build.c | ||
22 | +++ b/hw/loongarch/acpi-build.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static void | ||
24 | build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) | ||
25 | { | ||
26 | int i, arch_id, node_id; | ||
27 | - uint64_t mem_len, mem_base; | ||
28 | - int nb_numa_nodes = machine->numa_state->num_nodes; | ||
29 | + hwaddr len, base, gap; | ||
30 | + NodeInfo *numa_info; | ||
31 | + int nodes, nb_numa_nodes = machine->numa_state->num_nodes; | ||
32 | LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(machine); | ||
33 | MachineClass *mc = MACHINE_GET_CLASS(lvms); | ||
34 | const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(machine); | ||
35 | @@ -XXX,XX +XXX,XX @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) | ||
36 | build_append_int_noprefix(table_data, 0, 4); /* Reserved */ | ||
37 | } | ||
38 | |||
39 | - /* Node0 */ | ||
40 | - build_srat_memory(table_data, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, | ||
41 | - 0, MEM_AFFINITY_ENABLED); | ||
42 | - mem_base = VIRT_HIGHMEM_BASE; | ||
43 | - if (!nb_numa_nodes) { | ||
44 | - mem_len = machine->ram_size - VIRT_LOWMEM_SIZE; | ||
45 | - } else { | ||
46 | - mem_len = machine->numa_state->nodes[0].node_mem - VIRT_LOWMEM_SIZE; | ||
47 | + base = VIRT_LOWMEM_BASE; | ||
48 | + gap = VIRT_LOWMEM_SIZE; | ||
49 | + numa_info = machine->numa_state->nodes; | ||
50 | + nodes = nb_numa_nodes; | ||
51 | + if (!nodes) { | ||
52 | + nodes = 1; | ||
53 | } | ||
54 | - if (mem_len) | ||
55 | - build_srat_memory(table_data, mem_base, mem_len, 0, MEM_AFFINITY_ENABLED); | ||
56 | - | ||
57 | - /* Node1 - Nodemax */ | ||
58 | - if (nb_numa_nodes) { | ||
59 | - mem_base += mem_len; | ||
60 | - for (i = 1; i < nb_numa_nodes; ++i) { | ||
61 | - if (machine->numa_state->nodes[i].node_mem > 0) { | ||
62 | - build_srat_memory(table_data, mem_base, | ||
63 | - machine->numa_state->nodes[i].node_mem, i, | ||
64 | - MEM_AFFINITY_ENABLED); | ||
65 | - mem_base += machine->numa_state->nodes[i].node_mem; | ||
66 | - } | ||
67 | + | ||
68 | + for (i = 0; i < nodes; i++) { | ||
69 | + if (nb_numa_nodes) { | ||
70 | + len = numa_info[i].node_mem; | ||
71 | + } else { | ||
72 | + len = machine->ram_size; | ||
73 | + } | ||
74 | + | ||
75 | + /* | ||
76 | + * memory for the node splited into two part | ||
77 | + * lowram: [base, +gap) | ||
78 | + * highram: [VIRT_HIGHMEM_BASE, +(len - gap)) | ||
79 | + */ | ||
80 | + if (len >= gap) { | ||
81 | + build_srat_memory(table_data, base, len, i, MEM_AFFINITY_ENABLED); | ||
82 | + len -= gap; | ||
83 | + base = VIRT_HIGHMEM_BASE; | ||
84 | + gap = machine->ram_size - VIRT_LOWMEM_SIZE; | ||
85 | + } | ||
86 | + | ||
87 | + if (len) { | ||
88 | + build_srat_memory(table_data, base, len, i, MEM_AFFINITY_ENABLED); | ||
89 | + base += len; | ||
90 | + gap -= len; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | if (machine->device_memory) { | ||
95 | build_srat_memory(table_data, machine->device_memory->base, | ||
96 | memory_region_size(&machine->device_memory->mr), | ||
97 | - nb_numa_nodes - 1, | ||
98 | + nodes - 1, | ||
99 | MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED); | ||
100 | } | ||
101 | |||
102 | -- | ||
103 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | The same with ACPI table, fdt table is created on machine done |
---|---|---|---|
2 | 2 | notification. Some objects like CPU objects can be created with cold-plug | |
3 | Some qtest test cases such as numa use default memory size of generic | 3 | method with command such as -smp x, -device la464-loongarch-cpu, so all |
4 | machine class, which is 128M by fault. | 4 | objects finish to create when machine is done. |
5 | |||
6 | Here generic default memory size is used, and also remove minimum memory | ||
7 | size which is 1G originally. | ||
8 | 5 | ||
9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
10 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 7 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
11 | Message-Id: <20240515093927.3453674-6-maobibo@loongson.cn> | ||
12 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
13 | --- | 8 | --- |
14 | hw/loongarch/virt.c | 5 ----- | 9 | hw/loongarch/virt.c | 103 ++++++++++++++++++++++++-------------------- |
15 | 1 file changed, 5 deletions(-) | 10 | 1 file changed, 57 insertions(+), 46 deletions(-) |
16 | 11 | ||
17 | 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 |
18 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/loongarch/virt.c | 14 | --- a/hw/loongarch/virt.c |
20 | +++ b/hw/loongarch/virt.c | 15 | +++ b/hw/loongarch/virt.c |
16 | @@ -XXX,XX +XXX,XX @@ static void virt_build_smbios(LoongArchVirtMachineState *lvms) | ||
17 | } | ||
18 | } | ||
19 | |||
20 | +static void virt_fdt_setup(LoongArchVirtMachineState *lvms) | ||
21 | +{ | ||
22 | + MachineState *machine = MACHINE(lvms); | ||
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); | ||
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) | ||
21 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | 172 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) |
22 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); | 173 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); |
23 | } | 174 | } |
24 | 175 | ||
25 | - if (ram_size < 1 * GiB) { | 176 | - create_fdt(lvms); |
26 | - error_report("ram_size must be greater than 1G."); | 177 | - |
27 | - exit(1); | ||
28 | - } | ||
29 | create_fdt(lvms); | ||
30 | |||
31 | /* Create IOCSR space */ | 178 | /* Create IOCSR space */ |
32 | @@ -XXX,XX +XXX,XX @@ static void virt_class_init(ObjectClass *oc, void *data) | 179 | memory_region_init_io(&lvms->system_iocsr, OBJECT(machine), NULL, |
33 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); | 180 | machine, "iocsr", UINT64_MAX); |
34 | 181 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | |
35 | mc->init = virt_init; | 182 | lacpu = LOONGARCH_CPU(cpu); |
36 | - mc->default_ram_size = 1 * GiB; | 183 | lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id; |
37 | mc->default_cpu_type = LOONGARCH_CPU_TYPE_NAME("la464"); | 184 | } |
38 | mc->default_ram_id = "loongarch.ram"; | 185 | - fdt_add_cpu_nodes(lvms); |
39 | mc->max_cpus = LOONGARCH_MAX_CPUS; | 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 | } | ||
40 | -- | 225 | -- |
41 | 2.34.1 | 226 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | For CPU object, possible_cpu_arch_ids() function is used rather than |
---|---|---|---|
2 | 2 | smp.cpus. With command -smp x, -device la464-loongarch-cpu, smp.cpus | |
3 | One LoongArch virt machine platform, there is limitation for memory | 3 | is not accurate for all possible CPU objects, possible_cpu_arch_ids() |
4 | map information. The minimum memory size is 256M and minimum memory | 4 | is used here. |
5 | size for numa node0 is 256M also. With qemu numa qtest, it is possible | ||
6 | that memory size of numa node0 is 128M. | ||
7 | |||
8 | Limitations for minimum memory size for both total memory and numa | ||
9 | node0 is removed for fadt numa memory table creation. | ||
10 | 5 | ||
11 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
12 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 7 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
13 | Message-Id: <20240515093927.3453674-3-maobibo@loongson.cn> | ||
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
15 | --- | 8 | --- |
16 | hw/loongarch/virt.c | 46 ++++++++++++++++++++++++++++++++++++++++++--- | 9 | hw/loongarch/virt.c | 39 +++++++++++++++++++++++++-------------- |
17 | 1 file changed, 43 insertions(+), 3 deletions(-) | 10 | 1 file changed, 25 insertions(+), 14 deletions(-) |
18 | 11 | ||
19 | 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 |
20 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/loongarch/virt.c | 14 | --- a/hw/loongarch/virt.c |
22 | +++ b/hw/loongarch/virt.c | 15 | +++ b/hw/loongarch/virt.c |
23 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_memory_node(MachineState *ms, | 16 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(LoongArchVirtMachineState *lvms) |
24 | g_free(nodename); | 17 | static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms) |
25 | } | 18 | { |
26 | 19 | int num; | |
27 | +static void fdt_add_memory_nodes(MachineState *ms) | 20 | - const MachineState *ms = MACHINE(lvms); |
28 | +{ | 21 | - int smp_cpus = ms->smp.cpus; |
29 | + hwaddr base, size, ram_size, gap; | 22 | + MachineState *ms = MACHINE(lvms); |
30 | + int i, nb_numa_nodes, nodes; | 23 | + MachineClass *mc = MACHINE_GET_CLASS(ms); |
31 | + NodeInfo *numa_info; | 24 | + const CPUArchIdList *possible_cpus; |
32 | + | 25 | + LoongArchCPU *cpu; |
33 | + ram_size = ms->ram_size; | 26 | + CPUState *cs; |
34 | + base = VIRT_LOWMEM_BASE; | 27 | + char *nodename, *map_path; |
35 | + gap = VIRT_LOWMEM_SIZE; | 28 | |
36 | + nodes = nb_numa_nodes = ms->numa_state->num_nodes; | 29 | qemu_fdt_add_subnode(ms->fdt, "/cpus"); |
37 | + numa_info = ms->numa_state->nodes; | 30 | qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1); |
38 | + if (!nodes) { | 31 | qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0); |
39 | + nodes = 1; | 32 | |
40 | + } | 33 | /* cpu nodes */ |
41 | + | 34 | - for (num = smp_cpus - 1; num >= 0; num--) { |
42 | + for (i = 0; i < nodes; i++) { | 35 | - char *nodename = g_strdup_printf("/cpus/cpu@%d", num); |
43 | + if (nb_numa_nodes) { | 36 | - LoongArchCPU *cpu = LOONGARCH_CPU(qemu_get_cpu(num)); |
44 | + size = numa_info[i].node_mem; | 37 | - CPUState *cs = CPU(cpu); |
45 | + } else { | 38 | + possible_cpus = mc->possible_cpu_arch_ids(ms); |
46 | + size = ram_size; | 39 | + for (num = 0; num < possible_cpus->len; num++) { |
40 | + cs = possible_cpus->cpus[num].cpu; | ||
41 | + if (cs == NULL) { | ||
42 | + continue; | ||
47 | + } | 43 | + } |
48 | + | 44 | + |
49 | + /* | 45 | + nodename = g_strdup_printf("/cpus/cpu@%d", num); |
50 | + * memory for the node splited into two part | 46 | + cpu = LOONGARCH_CPU(cs); |
51 | + * lowram: [base, +gap) | 47 | |
52 | + * highram: [VIRT_HIGHMEM_BASE, +(len - gap)) | 48 | qemu_fdt_add_subnode(ms->fdt, nodename); |
53 | + */ | 49 | qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu"); |
54 | + if (size >= gap) { | 50 | qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", |
55 | + fdt_add_memory_node(ms, base, gap, i); | 51 | cpu->dtb_compatible); |
56 | + size -= gap; | 52 | - if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) { |
57 | + base = VIRT_HIGHMEM_BASE; | 53 | + if (possible_cpus->cpus[num].props.has_node_id) { |
58 | + gap = ram_size - VIRT_LOWMEM_SIZE; | 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; | ||
59 | + } | 68 | + } |
60 | + | 69 | |
61 | + if (size) { | 70 | - for (num = smp_cpus - 1; num >= 0; num--) { |
62 | + fdt_add_memory_node(ms, base, size, i); | 71 | - char *cpu_path = g_strdup_printf("/cpus/cpu@%d", num); |
63 | + base += size; | 72 | - char *map_path; |
64 | + gap -= size; | 73 | - |
65 | + } | 74 | + nodename = g_strdup_printf("/cpus/cpu@%d", num); |
66 | + } | 75 | if (ms->smp.threads > 1) { |
67 | +} | 76 | map_path = g_strdup_printf( |
68 | + | 77 | "/cpus/cpu-map/socket%d/core%d/thread%d", |
69 | static void virt_build_smbios(LoongArchVirtMachineState *lvms) | 78 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms) |
70 | { | 79 | num % ms->smp.cores); |
71 | MachineState *ms = MACHINE(lvms); | 80 | } |
72 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | 81 | qemu_fdt_add_path(ms->fdt, map_path); |
73 | lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id; | 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); | ||
74 | } | 88 | } |
75 | fdt_add_cpu_nodes(lvms); | 89 | } |
76 | + fdt_add_memory_nodes(machine); | 90 | |
77 | |||
78 | /* Node0 memory */ | ||
79 | memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1); | ||
80 | - fdt_add_memory_node(machine, VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 0); | ||
81 | memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.node0.lowram", | ||
82 | machine->ram, offset, VIRT_LOWMEM_SIZE); | ||
83 | memory_region_add_subregion(address_space_mem, phyAddr, &lvms->lowmem); | ||
84 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
85 | } | ||
86 | phyAddr = VIRT_HIGHMEM_BASE; | ||
87 | memmap_add_entry(phyAddr, highram_size, 1); | ||
88 | - fdt_add_memory_node(machine, phyAddr, highram_size, 0); | ||
89 | memory_region_init_alias(&lvms->highmem, NULL, "loongarch.node0.highram", | ||
90 | machine->ram, offset, highram_size); | ||
91 | memory_region_add_subregion(address_space_mem, phyAddr, &lvms->highmem); | ||
92 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
93 | offset, numa_info[i].node_mem); | ||
94 | memory_region_add_subregion(address_space_mem, phyAddr, nodemem); | ||
95 | memmap_add_entry(phyAddr, numa_info[i].node_mem, 1); | ||
96 | - fdt_add_memory_node(machine, phyAddr, numa_info[i].node_mem, i); | ||
97 | offset += numa_info[i].node_mem; | ||
98 | phyAddr += numa_info[i].node_mem; | ||
99 | } | ||
100 | -- | 91 | -- |
101 | 2.34.1 | 92 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | Like LBT feature, add type OnOffAuto for LSX feature setting. Also |
---|---|---|---|
2 | 2 | add LSX feature detection with new VM ioctl command, fallback to old | |
3 | Currently LSX/LASX vector property is decided by the default value. | 3 | method if it is not supported. |
4 | Instead vector property should be added unconditionally, and it is | ||
5 | irrelative with its default value. If vector is disabled by default, | ||
6 | vector also can be enabled from command line. | ||
7 | 4 | ||
8 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
9 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
10 | Message-Id: <20240521080549.434197-2-maobibo@loongson.cn> | ||
11 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
12 | --- | 7 | --- |
13 | target/loongarch/cpu.c | 14 ++++---------- | 8 | target/loongarch/cpu.c | 38 +++++++++++++++------------ |
14 | 1 file changed, 4 insertions(+), 10 deletions(-) | 9 | target/loongarch/cpu.h | 2 ++ |
10 | target/loongarch/kvm/kvm.c | 54 ++++++++++++++++++++++++++++++++++++++ | ||
11 | 3 files changed, 77 insertions(+), 17 deletions(-) | ||
15 | 12 | ||
16 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | 13 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
17 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/loongarch/cpu.c | 15 | --- a/target/loongarch/cpu.c |
19 | +++ b/target/loongarch/cpu.c | 16 | +++ b/target/loongarch/cpu.c |
20 | @@ -XXX,XX +XXX,XX @@ static void loongarch_set_lasx(Object *obj, bool value, Error **errp) | 17 | @@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj) |
21 | 18 | { | |
22 | void loongarch_cpu_post_init(Object *obj) | 19 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); |
20 | CPULoongArchState *env = &cpu->env; | ||
21 | + uint32_t data = 0; | ||
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) | ||
23 | { | 53 | { |
24 | - LoongArchCPU *cpu = LOONGARCH_CPU(obj); | 54 | - LoongArchCPU *cpu = LOONGARCH_CPU(obj); |
55 | - bool ret; | ||
25 | - | 56 | - |
26 | - if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { | 57 | - if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { |
27 | - object_property_add_bool(obj, "lsx", loongarch_get_lsx, | 58 | - ret = true; |
28 | - loongarch_set_lsx); | 59 | - } else { |
60 | - ret = false; | ||
29 | - } | 61 | - } |
30 | - if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { | 62 | - return ret; |
31 | - object_property_add_bool(obj, "lasx", loongarch_get_lasx, | 63 | + return LOONGARCH_CPU(obj)->lsx != ON_OFF_AUTO_OFF; |
32 | - loongarch_set_lasx); | 64 | } |
33 | - } | 65 | |
34 | + object_property_add_bool(obj, "lsx", loongarch_get_lsx, | 66 | static void loongarch_set_lsx(Object *obj, bool value, Error **errp) |
35 | + loongarch_set_lsx); | 67 | { |
36 | + object_property_add_bool(obj, "lasx", loongarch_get_lasx, | 68 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); |
37 | + loongarch_set_lasx); | 69 | + uint32_t val; |
38 | } | 70 | |
39 | 71 | - if (value) { | |
40 | static void loongarch_cpu_init(Object *obj) | 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) | ||
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; | ||
202 | } | ||
203 | |||
204 | + ret = kvm_cpu_check_lsx(cs, &local_err); | ||
205 | + if (ret < 0) { | ||
206 | + error_report_err(local_err); | ||
207 | + } | ||
208 | + | ||
209 | ret = kvm_cpu_check_lbt(cs, &local_err); | ||
210 | if (ret < 0) { | ||
211 | error_report_err(local_err); | ||
41 | -- | 212 | -- |
42 | 2.34.1 | 213 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Bibo Mao <maobibo@loongson.cn> | 1 | Like LSX feature, add type OnOffAuto for LASX feature setting. |
---|---|---|---|
2 | |||
3 | Memory map table for fwcfg is used for UEFI BIOS, UEFI BIOS uses the first | ||
4 | entry from fwcfg memory map as the first memory HOB, the second memory HOB | ||
5 | will be used if the first memory HOB is used up. | ||
6 | |||
7 | Memory map table for fwcfg does not care about numa node, however in | ||
8 | generic the first memory HOB is part of numa node0, so that runtime | ||
9 | memory of UEFI which is allocated from the first memory HOB is located | ||
10 | at numa node0. | ||
11 | 2 | ||
12 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 3 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
13 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
14 | Message-Id: <20240515093927.3453674-4-maobibo@loongson.cn> | ||
15 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
16 | --- | 5 | --- |
17 | hw/loongarch/virt.c | 60 ++++++++++++++++++++++++++++++++++++++++++--- | 6 | target/loongarch/cpu.c | 50 +++++++++++++++++++++++------------ |
18 | 1 file changed, 57 insertions(+), 3 deletions(-) | 7 | target/loongarch/cpu.h | 2 ++ |
8 | target/loongarch/kvm/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++ | ||
9 | 3 files changed, 89 insertions(+), 16 deletions(-) | ||
19 | 10 | ||
20 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 11 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
21 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/hw/loongarch/virt.c | 13 | --- a/target/loongarch/cpu.c |
23 | +++ b/hw/loongarch/virt.c | 14 | +++ b/target/loongarch/cpu.c |
24 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps virt_iocsr_misc_ops = { | 15 | @@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp) |
25 | }, | 16 | uint32_t val; |
26 | }; | 17 | |
27 | 18 | cpu->lsx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; | |
28 | +static void fw_cfg_add_memory(MachineState *ms) | 19 | + if (cpu->lsx == ON_OFF_AUTO_OFF) { |
29 | +{ | 20 | + cpu->lasx = ON_OFF_AUTO_OFF; |
30 | + hwaddr base, size, ram_size, gap; | 21 | + if (cpu->lasx == ON_OFF_AUTO_ON) { |
31 | + int nb_numa_nodes, nodes; | 22 | + error_setg(errp, "Failed to disable LSX since LASX is enabled"); |
32 | + NodeInfo *numa_info; | 23 | + return; |
33 | + | 24 | + } |
34 | + ram_size = ms->ram_size; | ||
35 | + base = VIRT_LOWMEM_BASE; | ||
36 | + gap = VIRT_LOWMEM_SIZE; | ||
37 | + nodes = nb_numa_nodes = ms->numa_state->num_nodes; | ||
38 | + numa_info = ms->numa_state->nodes; | ||
39 | + if (!nodes) { | ||
40 | + nodes = 1; | ||
41 | + } | 25 | + } |
42 | + | 26 | + |
43 | + /* add fw_cfg memory map of node0 */ | 27 | if (kvm_enabled()) { |
44 | + if (nb_numa_nodes) { | 28 | /* kvm feature detection in function kvm_arch_init_vcpu */ |
45 | + size = numa_info[0].node_mem; | 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 | } | ||
46 | + } else { | 34 | + } else { |
47 | + size = ram_size; | 35 | + cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, 0); |
48 | + } | 36 | + val = cpu->env.cpucfg[2]; |
49 | + | 37 | } |
50 | + if (size >= gap) { | 38 | |
51 | + memmap_add_entry(base, gap, 1); | 39 | cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value); |
52 | + size -= gap; | 40 | @@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp) |
53 | + base = VIRT_HIGHMEM_BASE; | 41 | |
54 | + gap = ram_size - VIRT_LOWMEM_SIZE; | 42 | static bool loongarch_get_lasx(Object *obj, Error **errp) |
55 | + } | 43 | { |
56 | + | 44 | - LoongArchCPU *cpu = LOONGARCH_CPU(obj); |
57 | + if (size) { | 45 | - bool ret; |
58 | + memmap_add_entry(base, size, 1); | 46 | - |
59 | + base += size; | 47 | - if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { |
60 | + } | 48 | - ret = true; |
61 | + | 49 | - } else { |
62 | + if (nodes < 2) { | 50 | - ret = false; |
51 | - } | ||
52 | - return ret; | ||
53 | + return LOONGARCH_CPU(obj)->lasx != ON_OFF_AUTO_OFF; | ||
54 | } | ||
55 | |||
56 | static void loongarch_set_lasx(Object *obj, bool value, Error **errp) | ||
57 | { | ||
58 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
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"); | ||
63 | + return; | 71 | + return; |
64 | + } | 72 | + } |
65 | + | 73 | + |
66 | + /* add fw_cfg memory map of other nodes */ | 74 | + if (kvm_enabled()) { |
67 | + size = ram_size - numa_info[0].node_mem; | 75 | + /* kvm feature detection in function kvm_arch_init_vcpu */ |
68 | + gap = VIRT_LOWMEM_BASE + VIRT_LOWMEM_SIZE; | 76 | + return; |
69 | + if (base < gap && (base + size) > gap) { | 77 | } |
70 | + /* | 78 | + |
71 | + * memory map for the maining nodes splited into two part | 79 | + /* LASX feature detection in TCG mode */ |
72 | + * lowram: [base, +(gap - base)) | 80 | + val = cpu->env.cpucfg[2]; |
73 | + * highram: [VIRT_HIGHMEM_BASE, +(size - (gap - base))) | 81 | + if (cpu->lasx == ON_OFF_AUTO_ON) { |
74 | + */ | 82 | + if (FIELD_EX32(val, CPUCFG2, LASX) == 0) { |
75 | + memmap_add_entry(base, gap - base, 1); | 83 | + error_setg(errp, "Failed to enable LASX in TCG mode"); |
76 | + size -= gap - base; | 84 | + return; |
77 | + base = VIRT_HIGHMEM_BASE; | 85 | + } |
78 | + } | 86 | + } |
79 | + | 87 | + |
80 | + if (size) | 88 | + cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, value); |
81 | + memmap_add_entry(base, size, 1); | 89 | } |
90 | |||
91 | static bool loongarch_get_lbt(Object *obj, Error **errp) | ||
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 | ||
101 | index XXXXXXX..XXXXXXX 100644 | ||
102 | --- a/target/loongarch/cpu.h | ||
103 | +++ b/target/loongarch/cpu.h | ||
104 | @@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB; | ||
105 | |||
106 | enum loongarch_features { | ||
107 | LOONGARCH_FEATURE_LSX, | ||
108 | + LOONGARCH_FEATURE_LASX, | ||
109 | LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */ | ||
110 | LOONGARCH_FEATURE_PMU, | ||
111 | }; | ||
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; | ||
82 | +} | 181 | +} |
83 | + | 182 | + |
84 | static void virt_init(MachineState *machine) | 183 | static int kvm_cpu_check_lbt(CPUState *cs, Error **errp) |
85 | { | 184 | { |
86 | LoongArchCPU *lacpu; | 185 | CPULoongArchState *env = cpu_env(cs); |
87 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | 186 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) |
187 | error_report_err(local_err); | ||
88 | } | 188 | } |
89 | fdt_add_cpu_nodes(lvms); | 189 | |
90 | fdt_add_memory_nodes(machine); | 190 | + ret = kvm_cpu_check_lasx(cs, &local_err); |
91 | + fw_cfg_add_memory(machine); | 191 | + if (ret < 0) { |
92 | 192 | + error_report_err(local_err); | |
93 | /* Node0 memory */ | 193 | + } |
94 | - memmap_add_entry(VIRT_LOWMEM_BASE, VIRT_LOWMEM_SIZE, 1); | 194 | + |
95 | memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.node0.lowram", | 195 | ret = kvm_cpu_check_lbt(cs, &local_err); |
96 | machine->ram, offset, VIRT_LOWMEM_SIZE); | 196 | if (ret < 0) { |
97 | memory_region_add_subregion(address_space_mem, phyAddr, &lvms->lowmem); | 197 | error_report_err(local_err); |
98 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
99 | highram_size = ram_size - VIRT_LOWMEM_SIZE; | ||
100 | } | ||
101 | phyAddr = VIRT_HIGHMEM_BASE; | ||
102 | - memmap_add_entry(phyAddr, highram_size, 1); | ||
103 | memory_region_init_alias(&lvms->highmem, NULL, "loongarch.node0.highram", | ||
104 | machine->ram, offset, highram_size); | ||
105 | memory_region_add_subregion(address_space_mem, phyAddr, &lvms->highmem); | ||
106 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
107 | memory_region_init_alias(nodemem, NULL, ramName, machine->ram, | ||
108 | offset, numa_info[i].node_mem); | ||
109 | memory_region_add_subregion(address_space_mem, phyAddr, nodemem); | ||
110 | - memmap_add_entry(phyAddr, numa_info[i].node_mem, 1); | ||
111 | offset += numa_info[i].node_mem; | ||
112 | phyAddr += numa_info[i].node_mem; | ||
113 | } | ||
114 | -- | 198 | -- |
115 | 2.34.1 | 199 | 2.43.5 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Bibo Mao <maobibo@loongson.cn> | ||
2 | 1 | ||
3 | For system dram memory region, it is not necessary to use numa node | ||
4 | information. There is only low memory region and high memory region. | ||
5 | |||
6 | Remove numa node information for ddr memory region here, it can reduce | ||
7 | memory region number on LoongArch virt machine. | ||
8 | |||
9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
10 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
11 | Message-Id: <20240515093927.3453674-5-maobibo@loongson.cn> | ||
12 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
13 | --- | ||
14 | hw/loongarch/virt.c | 53 +++++++++++++++------------------------------ | ||
15 | 1 file changed, 17 insertions(+), 36 deletions(-) | ||
16 | |||
17 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/loongarch/virt.c | ||
20 | +++ b/hw/loongarch/virt.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
22 | { | ||
23 | LoongArchCPU *lacpu; | ||
24 | const char *cpu_model = machine->cpu_type; | ||
25 | - ram_addr_t offset = 0; | ||
26 | - ram_addr_t ram_size = machine->ram_size; | ||
27 | - uint64_t highram_size = 0, phyAddr = 0; | ||
28 | MemoryRegion *address_space_mem = get_system_memory(); | ||
29 | LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(machine); | ||
30 | - int nb_numa_nodes = machine->numa_state->num_nodes; | ||
31 | - NodeInfo *numa_info = machine->numa_state->nodes; | ||
32 | int i; | ||
33 | + hwaddr base, size, ram_size = machine->ram_size; | ||
34 | const CPUArchIdList *possible_cpus; | ||
35 | MachineClass *mc = MACHINE_GET_CLASS(machine); | ||
36 | CPUState *cpu; | ||
37 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
38 | fw_cfg_add_memory(machine); | ||
39 | |||
40 | /* Node0 memory */ | ||
41 | - memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.node0.lowram", | ||
42 | - machine->ram, offset, VIRT_LOWMEM_SIZE); | ||
43 | - memory_region_add_subregion(address_space_mem, phyAddr, &lvms->lowmem); | ||
44 | - | ||
45 | - offset += VIRT_LOWMEM_SIZE; | ||
46 | - if (nb_numa_nodes > 0) { | ||
47 | - assert(numa_info[0].node_mem > VIRT_LOWMEM_SIZE); | ||
48 | - highram_size = numa_info[0].node_mem - VIRT_LOWMEM_SIZE; | ||
49 | - } else { | ||
50 | - highram_size = ram_size - VIRT_LOWMEM_SIZE; | ||
51 | + size = ram_size; | ||
52 | + base = VIRT_LOWMEM_BASE; | ||
53 | + if (size > VIRT_LOWMEM_SIZE) { | ||
54 | + size = VIRT_LOWMEM_SIZE; | ||
55 | } | ||
56 | - phyAddr = VIRT_HIGHMEM_BASE; | ||
57 | - memory_region_init_alias(&lvms->highmem, NULL, "loongarch.node0.highram", | ||
58 | - machine->ram, offset, highram_size); | ||
59 | - memory_region_add_subregion(address_space_mem, phyAddr, &lvms->highmem); | ||
60 | - | ||
61 | - /* Node1 - Nodemax memory */ | ||
62 | - offset += highram_size; | ||
63 | - phyAddr += highram_size; | ||
64 | - | ||
65 | - for (i = 1; i < nb_numa_nodes; i++) { | ||
66 | - MemoryRegion *nodemem = g_new(MemoryRegion, 1); | ||
67 | - g_autofree char *ramName = g_strdup_printf("loongarch.node%d.ram", i); | ||
68 | - memory_region_init_alias(nodemem, NULL, ramName, machine->ram, | ||
69 | - offset, numa_info[i].node_mem); | ||
70 | - memory_region_add_subregion(address_space_mem, phyAddr, nodemem); | ||
71 | - offset += numa_info[i].node_mem; | ||
72 | - phyAddr += numa_info[i].node_mem; | ||
73 | + | ||
74 | + memory_region_init_alias(&lvms->lowmem, NULL, "loongarch.lowram", | ||
75 | + machine->ram, base, size); | ||
76 | + memory_region_add_subregion(address_space_mem, base, &lvms->lowmem); | ||
77 | + base += size; | ||
78 | + if (ram_size - size) { | ||
79 | + base = VIRT_HIGHMEM_BASE; | ||
80 | + memory_region_init_alias(&lvms->highmem, NULL, "loongarch.highram", | ||
81 | + machine->ram, VIRT_LOWMEM_BASE + size, ram_size - size); | ||
82 | + memory_region_add_subregion(address_space_mem, base, &lvms->highmem); | ||
83 | + base += ram_size - size; | ||
84 | } | ||
85 | |||
86 | /* initialize device memory address space */ | ||
87 | if (machine->ram_size < machine->maxram_size) { | ||
88 | ram_addr_t device_mem_size = machine->maxram_size - machine->ram_size; | ||
89 | - hwaddr device_mem_base; | ||
90 | |||
91 | if (machine->ram_slots > ACPI_MAX_RAM_SLOTS) { | ||
92 | error_report("unsupported amount of memory slots: %"PRIu64, | ||
93 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
94 | "%d bytes", TARGET_PAGE_SIZE); | ||
95 | exit(EXIT_FAILURE); | ||
96 | } | ||
97 | - /* device memory base is the top of high memory address. */ | ||
98 | - device_mem_base = ROUND_UP(VIRT_HIGHMEM_BASE + highram_size, 1 * GiB); | ||
99 | - machine_memory_devices_init(machine, device_mem_base, device_mem_size); | ||
100 | + machine_memory_devices_init(machine, base, device_mem_size); | ||
101 | } | ||
102 | |||
103 | /* load the BIOS image. */ | ||
104 | -- | ||
105 | 2.34.1 | diff view generated by jsdifflib |