1 | The following changes since commit 7efd65423ab22e6f5890ca08ae40c84d6660242f: | 1 | The following changes since commit cf86770c7aa31ebd6e56f4eeb25c34107f92c51e: |
---|---|---|---|
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-request-2025-01-21v2' of https://gitlab.com/thuth/qemu into staging (2025-01-22 09:59:02 -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-20250124 |
8 | 8 | ||
9 | for you to fetch changes up to 505aa8d8f29b79fcef77563bb4124208badbd8d4: | 9 | for you to fetch changes up to 3215fe8528de45a1794f0314623cc10bd8e8e19f: |
10 | 10 | ||
11 | target/loongarch: Fix CSR.DMW0-3.VSEG check (2023-06-16 17:58:46 +0800) | 11 | target/loongarch: Dump all generic CSR registers (2025-01-24 14:49:24 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | pull-loongarch-20230616 | 14 | pull-loongarch-20250124 queue |
15 | |||
16 | * Fix CSR.DMW0-3.VSEG check | ||
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 | 15 | ||
22 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
23 | Jiajie Chen (1): | 17 | Bibo Mao (7): |
24 | target/loongarch: Fix CSR.DMW0-3.VSEG check | 18 | target/loongarch: Add dynamic function access with CSR register |
19 | target/loongarch: Remove static CSR function setting | ||
20 | target/loongarch: Add generic csr function type | ||
21 | target/loongarch: Add common header file for CSR registers | ||
22 | target/loongarch: Add common source file for CSR register | ||
23 | target/loongarch: Set unused flag with CSR registers | ||
24 | target/loongarch: Dump all generic CSR registers | ||
25 | 25 | ||
26 | Tianrui Zhao (4): | 26 | target/loongarch/cpu.c | 96 +++++++++--- |
27 | hw/loongarch/virt: Add cpu arch_id support | 27 | target/loongarch/csr.c | 129 +++++++++++++++++ |
28 | hw/intc: Set physical cpuid route for LoongArch ipi device | 28 | target/loongarch/csr.h | 29 ++++ |
29 | hw/loongarch: Add numa support | 29 | target/loongarch/meson.build | 1 + |
30 | hw/loongarch: Supplement cpu topology arguments | 30 | .../tcg/insn_trans/trans_privileged.c.inc | 161 +++++---------------- |
31 | 31 | target/loongarch/tcg/tcg_loongarch.h | 12 ++ | |
32 | hw/intc/loongarch_ipi.c | 44 +++++++++++-- | 32 | target/loongarch/tcg/translate.c | 5 + |
33 | hw/loongarch/Kconfig | 1 + | 33 | 7 files changed, 294 insertions(+), 139 deletions(-) |
34 | hw/loongarch/acpi-build.c | 78 ++++++++++++++++++----- | 34 | create mode 100644 target/loongarch/csr.c |
35 | hw/loongarch/virt.c | 144 ++++++++++++++++++++++++++++++++++++++---- | 35 | create mode 100644 target/loongarch/csr.h |
36 | target/loongarch/cpu.h | 2 + | 36 | create mode 100644 target/loongarch/tcg/tcg_loongarch.h |
37 | target/loongarch/tlb_helper.c | 4 +- | ||
38 | 6 files changed, 235 insertions(+), 38 deletions(-) | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | With CSR register, dynamic function access is used for CSR register |
---|---|---|---|
2 | access in TCG mode, so that csr info can be used by other modules. | ||
2 | 3 | ||
3 | Supplement LoongArch cpu topology arguments, including support socket | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | and threads per core. | 5 | --- |
6 | .../tcg/insn_trans/trans_privileged.c.inc | 37 +++++++++++++++++-- | ||
7 | target/loongarch/tcg/tcg_loongarch.h | 12 ++++++ | ||
8 | target/loongarch/tcg/translate.c | 5 +++ | ||
9 | 3 files changed, 51 insertions(+), 3 deletions(-) | ||
10 | create mode 100644 target/loongarch/tcg/tcg_loongarch.h | ||
5 | 11 | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 12 | diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
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 | 13 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/loongarch/acpi-build.c | 14 | --- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
19 | +++ b/hw/loongarch/acpi-build.c | 15 | +++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine) | 16 | @@ -XXX,XX +XXX,XX @@ enum { |
21 | acpi_add_table(table_offsets, tables_blob); | 17 | #define CSR_OFF(NAME) \ |
22 | build_madt(tables_blob, tables->linker, lams); | 18 | CSR_OFF_FLAGS(NAME, 0) |
23 | 19 | ||
24 | + acpi_add_table(table_offsets, tables_blob); | 20 | -static const CSRInfo csr_info[] = { |
25 | + build_pptt(tables_blob, tables->linker, machine, | 21 | +static CSRInfo csr_info[] = { |
26 | + lams->oem_id, lams->oem_table_id); | 22 | CSR_OFF_FLAGS(CRMD, CSRFL_EXITTB), |
23 | CSR_OFF(PRMD), | ||
24 | CSR_OFF_FLAGS(EUEN, CSRFL_EXITTB), | ||
25 | @@ -XXX,XX +XXX,XX @@ static bool check_plv(DisasContext *ctx) | ||
26 | return false; | ||
27 | } | ||
28 | |||
29 | -static const CSRInfo *get_csr(unsigned csr_num) | ||
30 | +static CSRInfo *get_csr(unsigned csr_num) | ||
31 | { | ||
32 | - const CSRInfo *csr; | ||
33 | + CSRInfo *csr; | ||
34 | |||
35 | if (csr_num >= ARRAY_SIZE(csr_info)) { | ||
36 | return NULL; | ||
37 | @@ -XXX,XX +XXX,XX @@ static const CSRInfo *get_csr(unsigned csr_num) | ||
38 | return csr; | ||
39 | } | ||
40 | |||
41 | +static bool set_csr_trans_func(unsigned int csr_num, GenCSRRead readfn, | ||
42 | + GenCSRWrite writefn) | ||
43 | +{ | ||
44 | + CSRInfo *csr; | ||
27 | + | 45 | + |
28 | acpi_add_table(table_offsets, tables_blob); | 46 | + csr = get_csr(csr_num); |
29 | build_srat(tables_blob, tables->linker, machine); | 47 | + if (!csr) { |
30 | 48 | + return false; | |
31 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 49 | + } |
50 | + | ||
51 | + csr->readfn = readfn; | ||
52 | + csr->writefn = writefn; | ||
53 | + return true; | ||
54 | +} | ||
55 | + | ||
56 | +#define SET_CSR_FUNC(NAME, read, write) \ | ||
57 | + set_csr_trans_func(LOONGARCH_CSR_##NAME, read, write) | ||
58 | + | ||
59 | +void loongarch_csr_translate_init(void) | ||
60 | +{ | ||
61 | + SET_CSR_FUNC(ESTAT, NULL, gen_helper_csrwr_estat); | ||
62 | + SET_CSR_FUNC(ASID, NULL, gen_helper_csrwr_asid); | ||
63 | + SET_CSR_FUNC(PGD, gen_helper_csrrd_pgd, NULL); | ||
64 | + SET_CSR_FUNC(PWCL, NULL, gen_helper_csrwr_pwcl); | ||
65 | + SET_CSR_FUNC(CPUID, gen_helper_csrrd_cpuid, NULL); | ||
66 | + SET_CSR_FUNC(TCFG, NULL, gen_helper_csrwr_tcfg); | ||
67 | + SET_CSR_FUNC(TVAL, gen_helper_csrrd_tval, NULL); | ||
68 | + SET_CSR_FUNC(TICLR, NULL, gen_helper_csrwr_ticlr); | ||
69 | +} | ||
70 | +#undef SET_CSR_FUNC | ||
71 | + | ||
72 | static bool check_csr_flags(DisasContext *ctx, const CSRInfo *csr, bool write) | ||
73 | { | ||
74 | if ((csr->flags & CSRFL_READONLY) && write) { | ||
75 | diff --git a/target/loongarch/tcg/tcg_loongarch.h b/target/loongarch/tcg/tcg_loongarch.h | ||
76 | new file mode 100644 | ||
77 | index XXXXXXX..XXXXXXX | ||
78 | --- /dev/null | ||
79 | +++ b/target/loongarch/tcg/tcg_loongarch.h | ||
80 | @@ -XXX,XX +XXX,XX @@ | ||
81 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
82 | +/* | ||
83 | + * QEMU LoongArch TCG interface | ||
84 | + * | ||
85 | + * Copyright (c) 2025 Loongson Technology Corporation Limited | ||
86 | + */ | ||
87 | +#ifndef TARGET_LOONGARCH_TCG_LOONGARCH_H | ||
88 | +#define TARGET_LOONGARCH_TCG_LOONGARCH_H | ||
89 | + | ||
90 | +void loongarch_csr_translate_init(void); | ||
91 | + | ||
92 | +#endif /* TARGET_LOONGARCH_TCG_LOONGARCH_H */ | ||
93 | diff --git a/target/loongarch/tcg/translate.c b/target/loongarch/tcg/translate.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | 94 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/hw/loongarch/virt.c | 95 | --- a/target/loongarch/tcg/translate.c |
34 | +++ b/hw/loongarch/virt.c | 96 | +++ b/target/loongarch/tcg/translate.c |
35 | @@ -XXX,XX +XXX,XX @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms) | 97 | @@ -XXX,XX +XXX,XX @@ |
36 | for (n = 0; n < ms->possible_cpus->len; n++) { | 98 | #include "exec/log.h" |
37 | ms->possible_cpus->cpus[n].type = ms->cpu_type; | 99 | #include "qemu/qemu-print.h" |
38 | ms->possible_cpus->cpus[n].arch_id = n; | 100 | #include "fpu/softfloat.h" |
101 | +#include "tcg_loongarch.h" | ||
102 | #include "translate.h" | ||
103 | #include "internals.h" | ||
104 | #include "vec.h" | ||
105 | @@ -XXX,XX +XXX,XX @@ void loongarch_translate_init(void) | ||
106 | offsetof(CPULoongArchState, lladdr), "lladdr"); | ||
107 | cpu_llval = tcg_global_mem_new(tcg_env, | ||
108 | offsetof(CPULoongArchState, llval), "llval"); | ||
39 | + | 109 | + |
40 | + ms->possible_cpus->cpus[n].props.has_socket_id = true; | 110 | +#ifndef CONFIG_USER_ONLY |
41 | + ms->possible_cpus->cpus[n].props.socket_id = | 111 | + loongarch_csr_translate_init(); |
42 | + n / (ms->smp.cores * ms->smp.threads); | 112 | +#endif |
43 | ms->possible_cpus->cpus[n].props.has_core_id = true; | ||
44 | - ms->possible_cpus->cpus[n].props.core_id = n % ms->smp.cores; | ||
45 | + ms->possible_cpus->cpus[n].props.core_id = | ||
46 | + n / ms->smp.threads % ms->smp.cores; | ||
47 | + ms->possible_cpus->cpus[n].props.has_thread_id = true; | ||
48 | + ms->possible_cpus->cpus[n].props.thread_id = n % ms->smp.threads; | ||
49 | } | ||
50 | return ms->possible_cpus; | ||
51 | } | 113 | } |
52 | -- | 114 | -- |
53 | 2.39.1 | 115 | 2.43.5 |
54 | |||
55 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Since CSR function setting is done dynamically in TCG mode, remove | ||
2 | static CSR function setting here. | ||
1 | 3 | ||
4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
5 | --- | ||
6 | .../tcg/insn_trans/trans_privileged.c.inc | 16 ++++++++-------- | ||
7 | 1 file changed, 8 insertions(+), 8 deletions(-) | ||
8 | |||
9 | diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
12 | +++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
13 | @@ -XXX,XX +XXX,XX @@ static CSRInfo csr_info[] = { | ||
14 | CSR_OFF_FLAGS(EUEN, CSRFL_EXITTB), | ||
15 | CSR_OFF_FLAGS(MISC, CSRFL_READONLY), | ||
16 | CSR_OFF(ECFG), | ||
17 | - CSR_OFF_FUNCS(ESTAT, CSRFL_EXITTB, NULL, gen_helper_csrwr_estat), | ||
18 | + CSR_OFF_FLAGS(ESTAT, CSRFL_EXITTB), | ||
19 | CSR_OFF(ERA), | ||
20 | CSR_OFF(BADV), | ||
21 | CSR_OFF_FLAGS(BADI, CSRFL_READONLY), | ||
22 | @@ -XXX,XX +XXX,XX @@ static CSRInfo csr_info[] = { | ||
23 | CSR_OFF(TLBEHI), | ||
24 | CSR_OFF(TLBELO0), | ||
25 | CSR_OFF(TLBELO1), | ||
26 | - CSR_OFF_FUNCS(ASID, CSRFL_EXITTB, NULL, gen_helper_csrwr_asid), | ||
27 | + CSR_OFF_FLAGS(ASID, CSRFL_EXITTB), | ||
28 | CSR_OFF(PGDL), | ||
29 | CSR_OFF(PGDH), | ||
30 | - CSR_OFF_FUNCS(PGD, CSRFL_READONLY, gen_helper_csrrd_pgd, NULL), | ||
31 | - CSR_OFF_FUNCS(PWCL, 0, NULL, gen_helper_csrwr_pwcl), | ||
32 | + CSR_OFF_FLAGS(PGD, CSRFL_READONLY), | ||
33 | + CSR_OFF(PWCL), | ||
34 | CSR_OFF(PWCH), | ||
35 | CSR_OFF(STLBPS), | ||
36 | CSR_OFF(RVACFG), | ||
37 | - CSR_OFF_FUNCS(CPUID, CSRFL_READONLY, gen_helper_csrrd_cpuid, NULL), | ||
38 | + CSR_OFF_FLAGS(CPUID, CSRFL_READONLY), | ||
39 | CSR_OFF_FLAGS(PRCFG1, CSRFL_READONLY), | ||
40 | CSR_OFF_FLAGS(PRCFG2, CSRFL_READONLY), | ||
41 | CSR_OFF_FLAGS(PRCFG3, CSRFL_READONLY), | ||
42 | @@ -XXX,XX +XXX,XX @@ static CSRInfo csr_info[] = { | ||
43 | CSR_OFF_ARRAY(SAVE, 14), | ||
44 | CSR_OFF_ARRAY(SAVE, 15), | ||
45 | CSR_OFF(TID), | ||
46 | - CSR_OFF_FUNCS(TCFG, CSRFL_IO, NULL, gen_helper_csrwr_tcfg), | ||
47 | - CSR_OFF_FUNCS(TVAL, CSRFL_READONLY | CSRFL_IO, gen_helper_csrrd_tval, NULL), | ||
48 | + CSR_OFF_FLAGS(TCFG, CSRFL_IO), | ||
49 | + CSR_OFF_FLAGS(TVAL, CSRFL_READONLY | CSRFL_IO), | ||
50 | CSR_OFF(CNTC), | ||
51 | - CSR_OFF_FUNCS(TICLR, CSRFL_IO, NULL, gen_helper_csrwr_ticlr), | ||
52 | + CSR_OFF_FLAGS(TICLR, CSRFL_IO), | ||
53 | CSR_OFF(LLBCTL), | ||
54 | CSR_OFF(IMPCTL1), | ||
55 | CSR_OFF(IMPCTL2), | ||
56 | -- | ||
57 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Jiajie Chen <c@jia.je> | 1 | Parameter type TCGv and TCGv_ptr for function GenCSRRead and GenCSRWrite |
---|---|---|---|
2 | is not used in non-TCG mode. Generic csr function type is added here | ||
3 | with parameter void type, so that it passes to compile with non-TCG mode. | ||
2 | 4 | ||
3 | The previous code checks whether the highest 16 bits of virtual address | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | equal to that of CSR.DMW0-3. This is incorrect according to the spec, | 6 | --- |
5 | and is corrected to compare only the highest four bits instead. | 7 | .../tcg/insn_trans/trans_privileged.c.inc | 27 ++++++++++++------- |
8 | 1 file changed, 17 insertions(+), 10 deletions(-) | ||
6 | 9 | ||
7 | Signed-off-by: Jiajie Chen <c@jia.je> | 10 | diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
8 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
9 | Message-Id: <20230614065556.2397513-1-c@jia.je> | ||
10 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
11 | --- | ||
12 | target/loongarch/tlb_helper.c | 4 ++-- | ||
13 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/loongarch/tlb_helper.c | 12 | --- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
18 | +++ b/target/loongarch/tlb_helper.c | 13 | +++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPULoongArchState *env, hwaddr *physical, | 14 | @@ -XXX,XX +XXX,XX @@ GEN_FALSE_TRANS(idle) |
15 | |||
16 | typedef void (*GenCSRRead)(TCGv dest, TCGv_ptr env); | ||
17 | typedef void (*GenCSRWrite)(TCGv dest, TCGv_ptr env, TCGv src); | ||
18 | +typedef void (*GenCSRFunc)(void); | ||
19 | |||
20 | typedef struct { | ||
21 | int offset; | ||
22 | int flags; | ||
23 | - GenCSRRead readfn; | ||
24 | - GenCSRWrite writefn; | ||
25 | + GenCSRFunc readfn; | ||
26 | + GenCSRFunc writefn; | ||
27 | } CSRInfo; | ||
28 | |||
29 | enum { | ||
30 | @@ -XXX,XX +XXX,XX @@ static bool set_csr_trans_func(unsigned int csr_num, GenCSRRead readfn, | ||
31 | return false; | ||
20 | } | 32 | } |
21 | 33 | ||
22 | plv = kernel_mode | (user_mode << R_CSR_DMW_PLV3_SHIFT); | 34 | - csr->readfn = readfn; |
23 | - base_v = address >> TARGET_VIRT_ADDR_SPACE_BITS; | 35 | - csr->writefn = writefn; |
24 | + base_v = address >> R_CSR_DMW_VSEG_SHIFT; | 36 | + csr->readfn = (GenCSRFunc)readfn; |
25 | /* Check direct map window */ | 37 | + csr->writefn = (GenCSRFunc)writefn; |
26 | for (int i = 0; i < 4; i++) { | 38 | return true; |
27 | - base_c = env->CSR_DMW[i] >> TARGET_VIRT_ADDR_SPACE_BITS; | 39 | } |
28 | + base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW, VSEG); | 40 | |
29 | if ((plv & env->CSR_DMW[i]) && (base_c == base_v)) { | 41 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrrd(DisasContext *ctx, arg_csrrd *a) |
30 | *physical = dmw_va2pa(address); | 42 | { |
31 | *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; | 43 | TCGv dest; |
44 | const CSRInfo *csr; | ||
45 | + GenCSRRead readfn; | ||
46 | |||
47 | if (check_plv(ctx)) { | ||
48 | return false; | ||
49 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrrd(DisasContext *ctx, arg_csrrd *a) | ||
50 | } else { | ||
51 | check_csr_flags(ctx, csr, false); | ||
52 | dest = gpr_dst(ctx, a->rd, EXT_NONE); | ||
53 | - if (csr->readfn) { | ||
54 | - csr->readfn(dest, tcg_env); | ||
55 | + readfn = (GenCSRRead)csr->readfn; | ||
56 | + if (readfn) { | ||
57 | + readfn(dest, tcg_env); | ||
58 | } else { | ||
59 | tcg_gen_ld_tl(dest, tcg_env, csr->offset); | ||
60 | } | ||
61 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrwr(DisasContext *ctx, arg_csrwr *a) | ||
62 | { | ||
63 | TCGv dest, src1; | ||
64 | const CSRInfo *csr; | ||
65 | + GenCSRWrite writefn; | ||
66 | |||
67 | if (check_plv(ctx)) { | ||
68 | return false; | ||
69 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrwr(DisasContext *ctx, arg_csrwr *a) | ||
70 | return false; | ||
71 | } | ||
72 | src1 = gpr_src(ctx, a->rd, EXT_NONE); | ||
73 | - if (csr->writefn) { | ||
74 | + writefn = (GenCSRWrite)csr->writefn; | ||
75 | + if (writefn) { | ||
76 | dest = gpr_dst(ctx, a->rd, EXT_NONE); | ||
77 | - csr->writefn(dest, tcg_env, src1); | ||
78 | + writefn(dest, tcg_env, src1); | ||
79 | } else { | ||
80 | dest = tcg_temp_new(); | ||
81 | tcg_gen_ld_tl(dest, tcg_env, csr->offset); | ||
82 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrxchg(DisasContext *ctx, arg_csrxchg *a) | ||
83 | { | ||
84 | TCGv src1, mask, oldv, newv, temp; | ||
85 | const CSRInfo *csr; | ||
86 | + GenCSRWrite writefn; | ||
87 | |||
88 | if (check_plv(ctx)) { | ||
89 | return false; | ||
90 | @@ -XXX,XX +XXX,XX @@ static bool trans_csrxchg(DisasContext *ctx, arg_csrxchg *a) | ||
91 | tcg_gen_andc_tl(temp, oldv, mask); | ||
92 | tcg_gen_or_tl(newv, newv, temp); | ||
93 | |||
94 | - if (csr->writefn) { | ||
95 | - csr->writefn(oldv, tcg_env, newv); | ||
96 | + writefn = (GenCSRWrite)csr->writefn; | ||
97 | + if (writefn) { | ||
98 | + writefn(oldv, tcg_env, newv); | ||
99 | } else { | ||
100 | tcg_gen_st_tl(newv, tcg_env, csr->offset); | ||
101 | } | ||
32 | -- | 102 | -- |
33 | 2.39.1 | 103 | 2.43.5 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Common header file csr.h is added here, it can be used by both | ||
2 | TCG mode and kvm mode. | ||
1 | 3 | ||
4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
5 | --- | ||
6 | target/loongarch/csr.h | 25 +++++++++++++++++++ | ||
7 | .../tcg/insn_trans/trans_privileged.c.inc | 16 +----------- | ||
8 | 2 files changed, 26 insertions(+), 15 deletions(-) | ||
9 | create mode 100644 target/loongarch/csr.h | ||
10 | |||
11 | diff --git a/target/loongarch/csr.h b/target/loongarch/csr.h | ||
12 | new file mode 100644 | ||
13 | index XXXXXXX..XXXXXXX | ||
14 | --- /dev/null | ||
15 | +++ b/target/loongarch/csr.h | ||
16 | @@ -XXX,XX +XXX,XX @@ | ||
17 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
18 | +/* | ||
19 | + * Copyright (c) 2025 Loongson Technology Corporation Limited | ||
20 | + */ | ||
21 | + | ||
22 | +#ifndef TARGET_LOONGARCH_CSR_H | ||
23 | +#define TARGET_LOONGARCH_CSR_H | ||
24 | + | ||
25 | +#include "cpu-csr.h" | ||
26 | + | ||
27 | +typedef void (*GenCSRFunc)(void); | ||
28 | +enum { | ||
29 | + CSRFL_READONLY = (1 << 0), | ||
30 | + CSRFL_EXITTB = (1 << 1), | ||
31 | + CSRFL_IO = (1 << 2), | ||
32 | +}; | ||
33 | + | ||
34 | +typedef struct { | ||
35 | + int offset; | ||
36 | + int flags; | ||
37 | + GenCSRFunc readfn; | ||
38 | + GenCSRFunc writefn; | ||
39 | +} CSRInfo; | ||
40 | + | ||
41 | +#endif /* TARGET_LOONGARCH_CSR_H */ | ||
42 | diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
45 | +++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | * LoongArch translation routines for the privileged instructions. | ||
48 | */ | ||
49 | |||
50 | -#include "cpu-csr.h" | ||
51 | +#include "csr.h" | ||
52 | |||
53 | #ifdef CONFIG_USER_ONLY | ||
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ GEN_FALSE_TRANS(idle) | ||
56 | |||
57 | typedef void (*GenCSRRead)(TCGv dest, TCGv_ptr env); | ||
58 | typedef void (*GenCSRWrite)(TCGv dest, TCGv_ptr env, TCGv src); | ||
59 | -typedef void (*GenCSRFunc)(void); | ||
60 | - | ||
61 | -typedef struct { | ||
62 | - int offset; | ||
63 | - int flags; | ||
64 | - GenCSRFunc readfn; | ||
65 | - GenCSRFunc writefn; | ||
66 | -} CSRInfo; | ||
67 | - | ||
68 | -enum { | ||
69 | - CSRFL_READONLY = (1 << 0), | ||
70 | - CSRFL_EXITTB = (1 << 1), | ||
71 | - CSRFL_IO = (1 << 2), | ||
72 | -}; | ||
73 | |||
74 | #define CSR_OFF_FUNCS(NAME, FL, RD, WR) \ | ||
75 | [LOONGARCH_CSR_##NAME] = { \ | ||
76 | -- | ||
77 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | Common source file csr.c is added here, it can be used by both |
---|---|---|---|
2 | TCG mode and kvm mode. The common code is removed from file | ||
3 | tcg/insn_trans/trans_privileged.c.inc to csrc.c | ||
2 | 4 | ||
3 | 1. Implement some functions for LoongArch numa support; | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | 2. Implement fdt_add_memory_node() for fdt; | 6 | --- |
5 | 3. build_srat() fills node_id and adds build numa memory. | 7 | target/loongarch/csr.c | 114 ++++++++++++++++++ |
8 | target/loongarch/csr.h | 1 + | ||
9 | target/loongarch/meson.build | 1 + | ||
10 | .../tcg/insn_trans/trans_privileged.c.inc | 107 ---------------- | ||
11 | 4 files changed, 116 insertions(+), 107 deletions(-) | ||
12 | create mode 100644 target/loongarch/csr.c | ||
6 | 13 | ||
7 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 14 | diff --git a/target/loongarch/csr.c b/target/loongarch/csr.c |
8 | Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn> | 15 | new file mode 100644 |
9 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 16 | index XXXXXXX..XXXXXXX |
10 | Message-Id: <20230613122613.2471743-1-zhaotianrui@loongson.cn> | 17 | --- /dev/null |
11 | --- | 18 | +++ b/target/loongarch/csr.c |
12 | hw/loongarch/Kconfig | 1 + | 19 | @@ -XXX,XX +XXX,XX @@ |
13 | hw/loongarch/acpi-build.c | 60 +++++++++++++++++----- | 20 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
14 | hw/loongarch/virt.c | 102 +++++++++++++++++++++++++++++++++----- | 21 | +/* |
15 | 3 files changed, 139 insertions(+), 24 deletions(-) | 22 | + * Copyright (c) 2025 Loongson Technology Corporation Limited |
16 | 23 | + */ | |
17 | diff --git a/hw/loongarch/Kconfig b/hw/loongarch/Kconfig | 24 | +#include <stddef.h> |
25 | +#include "qemu/osdep.h" | ||
26 | +#include "cpu.h" | ||
27 | +#include "csr.h" | ||
28 | + | ||
29 | +#define CSR_OFF_FUNCS(NAME, FL, RD, WR) \ | ||
30 | + [LOONGARCH_CSR_##NAME] = { \ | ||
31 | + .offset = offsetof(CPULoongArchState, CSR_##NAME), \ | ||
32 | + .flags = FL, .readfn = RD, .writefn = WR \ | ||
33 | + } | ||
34 | + | ||
35 | +#define CSR_OFF_ARRAY(NAME, N) \ | ||
36 | + [LOONGARCH_CSR_##NAME(N)] = { \ | ||
37 | + .offset = offsetof(CPULoongArchState, CSR_##NAME[N]), \ | ||
38 | + .flags = 0, .readfn = NULL, .writefn = NULL \ | ||
39 | + } | ||
40 | + | ||
41 | +#define CSR_OFF_FLAGS(NAME, FL) CSR_OFF_FUNCS(NAME, FL, NULL, NULL) | ||
42 | +#define CSR_OFF(NAME) CSR_OFF_FLAGS(NAME, 0) | ||
43 | + | ||
44 | +static CSRInfo csr_info[] = { | ||
45 | + CSR_OFF_FLAGS(CRMD, CSRFL_EXITTB), | ||
46 | + CSR_OFF(PRMD), | ||
47 | + CSR_OFF_FLAGS(EUEN, CSRFL_EXITTB), | ||
48 | + CSR_OFF_FLAGS(MISC, CSRFL_READONLY), | ||
49 | + CSR_OFF(ECFG), | ||
50 | + CSR_OFF_FLAGS(ESTAT, CSRFL_EXITTB), | ||
51 | + CSR_OFF(ERA), | ||
52 | + CSR_OFF(BADV), | ||
53 | + CSR_OFF_FLAGS(BADI, CSRFL_READONLY), | ||
54 | + CSR_OFF(EENTRY), | ||
55 | + CSR_OFF(TLBIDX), | ||
56 | + CSR_OFF(TLBEHI), | ||
57 | + CSR_OFF(TLBELO0), | ||
58 | + CSR_OFF(TLBELO1), | ||
59 | + CSR_OFF_FLAGS(ASID, CSRFL_EXITTB), | ||
60 | + CSR_OFF(PGDL), | ||
61 | + CSR_OFF(PGDH), | ||
62 | + CSR_OFF_FLAGS(PGD, CSRFL_READONLY), | ||
63 | + CSR_OFF(PWCL), | ||
64 | + CSR_OFF(PWCH), | ||
65 | + CSR_OFF(STLBPS), | ||
66 | + CSR_OFF(RVACFG), | ||
67 | + CSR_OFF_FLAGS(CPUID, CSRFL_READONLY), | ||
68 | + CSR_OFF_FLAGS(PRCFG1, CSRFL_READONLY), | ||
69 | + CSR_OFF_FLAGS(PRCFG2, CSRFL_READONLY), | ||
70 | + CSR_OFF_FLAGS(PRCFG3, CSRFL_READONLY), | ||
71 | + CSR_OFF_ARRAY(SAVE, 0), | ||
72 | + CSR_OFF_ARRAY(SAVE, 1), | ||
73 | + CSR_OFF_ARRAY(SAVE, 2), | ||
74 | + CSR_OFF_ARRAY(SAVE, 3), | ||
75 | + CSR_OFF_ARRAY(SAVE, 4), | ||
76 | + CSR_OFF_ARRAY(SAVE, 5), | ||
77 | + CSR_OFF_ARRAY(SAVE, 6), | ||
78 | + CSR_OFF_ARRAY(SAVE, 7), | ||
79 | + CSR_OFF_ARRAY(SAVE, 8), | ||
80 | + CSR_OFF_ARRAY(SAVE, 9), | ||
81 | + CSR_OFF_ARRAY(SAVE, 10), | ||
82 | + CSR_OFF_ARRAY(SAVE, 11), | ||
83 | + CSR_OFF_ARRAY(SAVE, 12), | ||
84 | + CSR_OFF_ARRAY(SAVE, 13), | ||
85 | + CSR_OFF_ARRAY(SAVE, 14), | ||
86 | + CSR_OFF_ARRAY(SAVE, 15), | ||
87 | + CSR_OFF(TID), | ||
88 | + CSR_OFF_FLAGS(TCFG, CSRFL_IO), | ||
89 | + CSR_OFF_FLAGS(TVAL, CSRFL_READONLY | CSRFL_IO), | ||
90 | + CSR_OFF(CNTC), | ||
91 | + CSR_OFF_FLAGS(TICLR, CSRFL_IO), | ||
92 | + CSR_OFF(LLBCTL), | ||
93 | + CSR_OFF(IMPCTL1), | ||
94 | + CSR_OFF(IMPCTL2), | ||
95 | + CSR_OFF(TLBRENTRY), | ||
96 | + CSR_OFF(TLBRBADV), | ||
97 | + CSR_OFF(TLBRERA), | ||
98 | + CSR_OFF(TLBRSAVE), | ||
99 | + CSR_OFF(TLBRELO0), | ||
100 | + CSR_OFF(TLBRELO1), | ||
101 | + CSR_OFF(TLBREHI), | ||
102 | + CSR_OFF(TLBRPRMD), | ||
103 | + CSR_OFF(MERRCTL), | ||
104 | + CSR_OFF(MERRINFO1), | ||
105 | + CSR_OFF(MERRINFO2), | ||
106 | + CSR_OFF(MERRENTRY), | ||
107 | + CSR_OFF(MERRERA), | ||
108 | + CSR_OFF(MERRSAVE), | ||
109 | + CSR_OFF(CTAG), | ||
110 | + CSR_OFF_ARRAY(DMW, 0), | ||
111 | + CSR_OFF_ARRAY(DMW, 1), | ||
112 | + CSR_OFF_ARRAY(DMW, 2), | ||
113 | + CSR_OFF_ARRAY(DMW, 3), | ||
114 | + CSR_OFF(DBG), | ||
115 | + CSR_OFF(DERA), | ||
116 | + CSR_OFF(DSAVE), | ||
117 | +}; | ||
118 | + | ||
119 | +CSRInfo *get_csr(unsigned int csr_num) | ||
120 | +{ | ||
121 | + CSRInfo *csr; | ||
122 | + | ||
123 | + if (csr_num >= ARRAY_SIZE(csr_info)) { | ||
124 | + return NULL; | ||
125 | + } | ||
126 | + | ||
127 | + csr = &csr_info[csr_num]; | ||
128 | + if (csr->offset == 0) { | ||
129 | + return NULL; | ||
130 | + } | ||
131 | + | ||
132 | + return csr; | ||
133 | +} | ||
134 | diff --git a/target/loongarch/csr.h b/target/loongarch/csr.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | 135 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/loongarch/Kconfig | 136 | --- a/target/loongarch/csr.h |
20 | +++ b/hw/loongarch/Kconfig | 137 | +++ b/target/loongarch/csr.h |
21 | @@ -XXX,XX +XXX,XX @@ config LOONGARCH_VIRT | 138 | @@ -XXX,XX +XXX,XX @@ typedef struct { |
22 | select FW_CFG_DMA | 139 | GenCSRFunc writefn; |
23 | select DIMM | 140 | } CSRInfo; |
24 | select PFLASH_CFI01 | 141 | |
25 | + select ACPI_HMAT | 142 | +CSRInfo *get_csr(unsigned int csr_num); |
26 | diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c | 143 | #endif /* TARGET_LOONGARCH_CSR_H */ |
144 | diff --git a/target/loongarch/meson.build b/target/loongarch/meson.build | ||
27 | index XXXXXXX..XXXXXXX 100644 | 145 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/loongarch/acpi-build.c | 146 | --- a/target/loongarch/meson.build |
29 | +++ b/hw/loongarch/acpi-build.c | 147 | +++ b/target/loongarch/meson.build |
30 | @@ -XXX,XX +XXX,XX @@ | 148 | @@ -XXX,XX +XXX,XX @@ loongarch_system_ss = ss.source_set() |
31 | #include "sysemu/tpm.h" | 149 | loongarch_system_ss.add(files( |
32 | #include "hw/platform-bus.h" | 150 | 'arch_dump.c', |
33 | #include "hw/acpi/aml-build.h" | 151 | 'cpu_helper.c', |
34 | +#include "hw/acpi/hmat.h" | 152 | + 'csr.c', |
35 | 153 | 'loongarch-qmp-cmds.c', | |
36 | #define ACPI_BUILD_ALIGN_SIZE 0x1000 | 154 | 'machine.c', |
37 | #define ACPI_BUILD_TABLE_SIZE 0x20000 | 155 | )) |
38 | @@ -XXX,XX +XXX,XX @@ build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams) | 156 | diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
39 | static void | 157 | index XXXXXXX..XXXXXXX 100644 |
40 | build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) | 158 | --- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc |
159 | +++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc | ||
160 | @@ -XXX,XX +XXX,XX @@ GEN_FALSE_TRANS(idle) | ||
161 | typedef void (*GenCSRRead)(TCGv dest, TCGv_ptr env); | ||
162 | typedef void (*GenCSRWrite)(TCGv dest, TCGv_ptr env, TCGv src); | ||
163 | |||
164 | -#define CSR_OFF_FUNCS(NAME, FL, RD, WR) \ | ||
165 | - [LOONGARCH_CSR_##NAME] = { \ | ||
166 | - .offset = offsetof(CPULoongArchState, CSR_##NAME), \ | ||
167 | - .flags = FL, .readfn = RD, .writefn = WR \ | ||
168 | - } | ||
169 | - | ||
170 | -#define CSR_OFF_ARRAY(NAME, N) \ | ||
171 | - [LOONGARCH_CSR_##NAME(N)] = { \ | ||
172 | - .offset = offsetof(CPULoongArchState, CSR_##NAME[N]), \ | ||
173 | - .flags = 0, .readfn = NULL, .writefn = NULL \ | ||
174 | - } | ||
175 | - | ||
176 | -#define CSR_OFF_FLAGS(NAME, FL) \ | ||
177 | - CSR_OFF_FUNCS(NAME, FL, NULL, NULL) | ||
178 | - | ||
179 | -#define CSR_OFF(NAME) \ | ||
180 | - CSR_OFF_FLAGS(NAME, 0) | ||
181 | - | ||
182 | -static CSRInfo csr_info[] = { | ||
183 | - CSR_OFF_FLAGS(CRMD, CSRFL_EXITTB), | ||
184 | - CSR_OFF(PRMD), | ||
185 | - CSR_OFF_FLAGS(EUEN, CSRFL_EXITTB), | ||
186 | - CSR_OFF_FLAGS(MISC, CSRFL_READONLY), | ||
187 | - CSR_OFF(ECFG), | ||
188 | - CSR_OFF_FLAGS(ESTAT, CSRFL_EXITTB), | ||
189 | - CSR_OFF(ERA), | ||
190 | - CSR_OFF(BADV), | ||
191 | - CSR_OFF_FLAGS(BADI, CSRFL_READONLY), | ||
192 | - CSR_OFF(EENTRY), | ||
193 | - CSR_OFF(TLBIDX), | ||
194 | - CSR_OFF(TLBEHI), | ||
195 | - CSR_OFF(TLBELO0), | ||
196 | - CSR_OFF(TLBELO1), | ||
197 | - CSR_OFF_FLAGS(ASID, CSRFL_EXITTB), | ||
198 | - CSR_OFF(PGDL), | ||
199 | - CSR_OFF(PGDH), | ||
200 | - CSR_OFF_FLAGS(PGD, CSRFL_READONLY), | ||
201 | - CSR_OFF(PWCL), | ||
202 | - CSR_OFF(PWCH), | ||
203 | - CSR_OFF(STLBPS), | ||
204 | - CSR_OFF(RVACFG), | ||
205 | - CSR_OFF_FLAGS(CPUID, CSRFL_READONLY), | ||
206 | - CSR_OFF_FLAGS(PRCFG1, CSRFL_READONLY), | ||
207 | - CSR_OFF_FLAGS(PRCFG2, CSRFL_READONLY), | ||
208 | - CSR_OFF_FLAGS(PRCFG3, CSRFL_READONLY), | ||
209 | - CSR_OFF_ARRAY(SAVE, 0), | ||
210 | - CSR_OFF_ARRAY(SAVE, 1), | ||
211 | - CSR_OFF_ARRAY(SAVE, 2), | ||
212 | - CSR_OFF_ARRAY(SAVE, 3), | ||
213 | - CSR_OFF_ARRAY(SAVE, 4), | ||
214 | - CSR_OFF_ARRAY(SAVE, 5), | ||
215 | - CSR_OFF_ARRAY(SAVE, 6), | ||
216 | - CSR_OFF_ARRAY(SAVE, 7), | ||
217 | - CSR_OFF_ARRAY(SAVE, 8), | ||
218 | - CSR_OFF_ARRAY(SAVE, 9), | ||
219 | - CSR_OFF_ARRAY(SAVE, 10), | ||
220 | - CSR_OFF_ARRAY(SAVE, 11), | ||
221 | - CSR_OFF_ARRAY(SAVE, 12), | ||
222 | - CSR_OFF_ARRAY(SAVE, 13), | ||
223 | - CSR_OFF_ARRAY(SAVE, 14), | ||
224 | - CSR_OFF_ARRAY(SAVE, 15), | ||
225 | - CSR_OFF(TID), | ||
226 | - CSR_OFF_FLAGS(TCFG, CSRFL_IO), | ||
227 | - CSR_OFF_FLAGS(TVAL, CSRFL_READONLY | CSRFL_IO), | ||
228 | - CSR_OFF(CNTC), | ||
229 | - CSR_OFF_FLAGS(TICLR, CSRFL_IO), | ||
230 | - CSR_OFF(LLBCTL), | ||
231 | - CSR_OFF(IMPCTL1), | ||
232 | - CSR_OFF(IMPCTL2), | ||
233 | - CSR_OFF(TLBRENTRY), | ||
234 | - CSR_OFF(TLBRBADV), | ||
235 | - CSR_OFF(TLBRERA), | ||
236 | - CSR_OFF(TLBRSAVE), | ||
237 | - CSR_OFF(TLBRELO0), | ||
238 | - CSR_OFF(TLBRELO1), | ||
239 | - CSR_OFF(TLBREHI), | ||
240 | - CSR_OFF(TLBRPRMD), | ||
241 | - CSR_OFF(MERRCTL), | ||
242 | - CSR_OFF(MERRINFO1), | ||
243 | - CSR_OFF(MERRINFO2), | ||
244 | - CSR_OFF(MERRENTRY), | ||
245 | - CSR_OFF(MERRERA), | ||
246 | - CSR_OFF(MERRSAVE), | ||
247 | - CSR_OFF(CTAG), | ||
248 | - CSR_OFF_ARRAY(DMW, 0), | ||
249 | - CSR_OFF_ARRAY(DMW, 1), | ||
250 | - CSR_OFF_ARRAY(DMW, 2), | ||
251 | - CSR_OFF_ARRAY(DMW, 3), | ||
252 | - CSR_OFF(DBG), | ||
253 | - CSR_OFF(DERA), | ||
254 | - CSR_OFF(DSAVE), | ||
255 | -}; | ||
256 | - | ||
257 | static bool check_plv(DisasContext *ctx) | ||
41 | { | 258 | { |
42 | - int i, arch_id; | 259 | if (ctx->plv == MMU_PLV_USER) { |
43 | + int i, arch_id, node_id; | 260 | @@ -XXX,XX +XXX,XX @@ static bool check_plv(DisasContext *ctx) |
44 | + uint64_t mem_len, mem_base; | 261 | return false; |
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 | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/hw/loongarch/virt.c | ||
137 | +++ b/hw/loongarch/virt.c | ||
138 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchMachineState *lams) | ||
139 | for (num = smp_cpus - 1; num >= 0; num--) { | ||
140 | char *nodename = g_strdup_printf("/cpus/cpu@%d", num); | ||
141 | LoongArchCPU *cpu = LOONGARCH_CPU(qemu_get_cpu(num)); | ||
142 | + CPUState *cs = CPU(cpu); | ||
143 | |||
144 | qemu_fdt_add_subnode(ms->fdt, nodename); | ||
145 | qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu"); | ||
146 | qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | ||
147 | cpu->dtb_compatible); | ||
148 | + if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) { | ||
149 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id", | ||
150 | + ms->possible_cpus->cpus[cs->cpu_index].props.node_id); | ||
151 | + } | ||
152 | qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num); | ||
153 | qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", | ||
154 | qemu_fdt_alloc_phandle(ms->fdt)); | ||
155 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_irqchip_node(LoongArchMachineState *lams) | ||
156 | g_free(nodename); | ||
157 | } | 262 | } |
158 | 263 | ||
159 | +static void fdt_add_memory_node(MachineState *ms, | 264 | -static CSRInfo *get_csr(unsigned csr_num) |
160 | + uint64_t base, uint64_t size, int node_id) | 265 | -{ |
161 | +{ | 266 | - CSRInfo *csr; |
162 | + char *nodename = g_strdup_printf("/memory@%" PRIx64, base); | 267 | - |
163 | + | 268 | - if (csr_num >= ARRAY_SIZE(csr_info)) { |
164 | + qemu_fdt_add_subnode(ms->fdt, nodename); | 269 | - return NULL; |
165 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 2, base, 2, size); | 270 | - } |
166 | + qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "memory"); | 271 | - csr = &csr_info[csr_num]; |
167 | + | 272 | - if (csr->offset == 0) { |
168 | + if (ms->numa_state && ms->numa_state->num_nodes) { | 273 | - return NULL; |
169 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id", node_id); | 274 | - } |
170 | + } | 275 | - return csr; |
171 | + | 276 | -} |
172 | + g_free(nodename); | 277 | - |
173 | +} | 278 | static bool set_csr_trans_func(unsigned int csr_num, GenCSRRead readfn, |
174 | + | 279 | GenCSRWrite writefn) |
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 | { | 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 | -- | 281 | -- |
295 | 2.39.1 | 282 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | On LA464, some CSR registers are not used such as CSR_SAVE8 - |
---|---|---|---|
2 | CSR_SAVE15, also CSR registers relative with MCE is not used now. | ||
2 | 3 | ||
3 | With acpi madt table, there is cpu physical coreid, which may | 4 | Flag CSRFL_UNUSED is added for these registers, so that it will |
4 | be different with logical id in qemu. This patch adds cpu arch_id | 5 | not dumped. In order to keep compatiblity, these CSR registers are |
5 | support, and fill madt table with arch_id. For the present cpu | 6 | not removed since it is used in vmstate already. |
6 | arch_id is still equal to logical id. | ||
7 | 7 | ||
8 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 8 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
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 | --- | 9 | --- |
13 | hw/loongarch/acpi-build.c | 20 ++++++++++++++------ | 10 | target/loongarch/cpu.c | 30 +++++++++++++++++++++++++++++- |
14 | hw/loongarch/virt.c | 34 ++++++++++++++++++++++++++++++++-- | 11 | target/loongarch/csr.c | 13 +++++++++++++ |
15 | 2 files changed, 46 insertions(+), 8 deletions(-) | 12 | target/loongarch/csr.h | 2 ++ |
13 | 3 files changed, 44 insertions(+), 1 deletion(-) | ||
16 | 14 | ||
17 | diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c | 15 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/loongarch/acpi-build.c | 17 | --- a/target/loongarch/cpu.c |
20 | +++ b/hw/loongarch/acpi-build.c | 18 | +++ b/target/loongarch/cpu.c |
21 | @@ -XXX,XX +XXX,XX @@ static void | 19 | @@ -XXX,XX +XXX,XX @@ |
22 | build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams) | 20 | #include "cpu.h" |
21 | #include "internals.h" | ||
22 | #include "fpu/softfloat-helpers.h" | ||
23 | -#include "cpu-csr.h" | ||
24 | +#include "csr.h" | ||
25 | #ifndef CONFIG_USER_ONLY | ||
26 | #include "system/reset.h" | ||
27 | #endif | ||
28 | @@ -XXX,XX +XXX,XX @@ static int loongarch_cpu_mmu_index(CPUState *cs, bool ifetch) | ||
29 | return MMU_DA_IDX; | ||
30 | } | ||
31 | |||
32 | +static void loongarch_la464_init_csr(Object *obj) | ||
33 | +{ | ||
34 | +#ifndef CONFIG_USER_ONLY | ||
35 | + static bool initialized; | ||
36 | + LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
37 | + CPULoongArchState *env = &cpu->env; | ||
38 | + int i, num; | ||
39 | + | ||
40 | + if (!initialized) { | ||
41 | + initialized = true; | ||
42 | + num = FIELD_EX64(env->CSR_PRCFG1, CSR_PRCFG1, SAVE_NUM); | ||
43 | + for (i = num; i < 16; i++) { | ||
44 | + set_csr_flag(LOONGARCH_CSR_SAVE(i), CSRFL_UNUSED); | ||
45 | + } | ||
46 | + set_csr_flag(LOONGARCH_CSR_IMPCTL1, CSRFL_UNUSED); | ||
47 | + set_csr_flag(LOONGARCH_CSR_IMPCTL2, CSRFL_UNUSED); | ||
48 | + set_csr_flag(LOONGARCH_CSR_MERRCTL, CSRFL_UNUSED); | ||
49 | + set_csr_flag(LOONGARCH_CSR_MERRINFO1, CSRFL_UNUSED); | ||
50 | + set_csr_flag(LOONGARCH_CSR_MERRINFO2, CSRFL_UNUSED); | ||
51 | + set_csr_flag(LOONGARCH_CSR_MERRENTRY, CSRFL_UNUSED); | ||
52 | + set_csr_flag(LOONGARCH_CSR_MERRERA, CSRFL_UNUSED); | ||
53 | + set_csr_flag(LOONGARCH_CSR_MERRSAVE, CSRFL_UNUSED); | ||
54 | + set_csr_flag(LOONGARCH_CSR_CTAG, CSRFL_UNUSED); | ||
55 | + } | ||
56 | +#endif | ||
57 | +} | ||
58 | + | ||
59 | static void loongarch_la464_initfn(Object *obj) | ||
23 | { | 60 | { |
24 | MachineState *ms = MACHINE(lams); | 61 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); |
25 | - int i; | 62 | @@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj) |
26 | + MachineClass *mc = MACHINE_GET_CLASS(ms); | 63 | env->CSR_PRCFG3 = FIELD_DP64(env->CSR_PRCFG3, CSR_PRCFG3, STLB_WAYS, 7); |
27 | + const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms); | 64 | env->CSR_PRCFG3 = FIELD_DP64(env->CSR_PRCFG3, CSR_PRCFG3, STLB_SETS, 8); |
28 | + int i, arch_id; | 65 | |
29 | AcpiTable table = { .sig = "APIC", .rev = 1, .oem_id = lams->oem_id, | 66 | + loongarch_la464_init_csr(obj); |
30 | .oem_table_id = lams->oem_table_id }; | 67 | loongarch_cpu_post_init(obj); |
31 | 68 | } | |
32 | @@ -XXX,XX +XXX,XX @@ build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams) | 69 | |
33 | build_append_int_noprefix(table_data, 0, 4); | 70 | diff --git a/target/loongarch/csr.c b/target/loongarch/csr.c |
34 | build_append_int_noprefix(table_data, 1 /* PCAT_COMPAT */, 4); /* Flags */ | 71 | index XXXXXXX..XXXXXXX 100644 |
35 | 72 | --- a/target/loongarch/csr.c | |
36 | - for (i = 0; i < ms->smp.cpus; i++) { | 73 | +++ b/target/loongarch/csr.c |
37 | + for (i = 0; i < arch_ids->len; i++) { | 74 | @@ -XXX,XX +XXX,XX @@ CSRInfo *get_csr(unsigned int csr_num) |
38 | /* Processor Core Interrupt Controller Structure */ | 75 | |
39 | + arch_id = arch_ids->cpus[i].arch_id; | 76 | return csr; |
77 | } | ||
40 | + | 78 | + |
41 | build_append_int_noprefix(table_data, 17, 1); /* Type */ | 79 | +bool set_csr_flag(unsigned int csr_num, int flag) |
42 | build_append_int_noprefix(table_data, 15, 1); /* Length */ | 80 | +{ |
43 | build_append_int_noprefix(table_data, 1, 1); /* Version */ | 81 | + CSRInfo *csr; |
44 | build_append_int_noprefix(table_data, i + 1, 4); /* ACPI Processor ID */ | ||
45 | - build_append_int_noprefix(table_data, i, 4); /* Core ID */ | ||
46 | + build_append_int_noprefix(table_data, arch_id, 4); /* Core ID */ | ||
47 | build_append_int_noprefix(table_data, 1, 4); /* Flags */ | ||
48 | } | ||
49 | |||
50 | @@ -XXX,XX +XXX,XX @@ build_madt(GArray *table_data, BIOSLinker *linker, LoongArchMachineState *lams) | ||
51 | static void | ||
52 | build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) | ||
53 | { | ||
54 | - uint64_t i; | ||
55 | + int i, arch_id; | ||
56 | LoongArchMachineState *lams = LOONGARCH_MACHINE(machine); | ||
57 | MachineState *ms = MACHINE(lams); | ||
58 | + MachineClass *mc = MACHINE_GET_CLASS(ms); | ||
59 | + const CPUArchIdList *arch_ids = mc->possible_cpu_arch_ids(ms); | ||
60 | AcpiTable table = { .sig = "SRAT", .rev = 1, .oem_id = lams->oem_id, | ||
61 | .oem_table_id = lams->oem_table_id }; | ||
62 | |||
63 | @@ -XXX,XX +XXX,XX @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) | ||
64 | build_append_int_noprefix(table_data, 1, 4); /* Reserved */ | ||
65 | build_append_int_noprefix(table_data, 0, 8); /* Reserved */ | ||
66 | |||
67 | - for (i = 0; i < ms->smp.cpus; ++i) { | ||
68 | + for (i = 0; i < arch_ids->len; ++i) { | ||
69 | + arch_id = arch_ids->cpus[i].arch_id; | ||
70 | + | 82 | + |
71 | /* Processor Local APIC/SAPIC Affinity Structure */ | 83 | + csr = get_csr(csr_num); |
72 | build_append_int_noprefix(table_data, 0, 1); /* Type */ | 84 | + if (!csr) { |
73 | build_append_int_noprefix(table_data, 16, 1); /* Length */ | 85 | + return false; |
74 | /* Proximity Domain [7:0] */ | ||
75 | build_append_int_noprefix(table_data, 0, 1); | ||
76 | - build_append_int_noprefix(table_data, i, 1); /* APIC ID */ | ||
77 | + build_append_int_noprefix(table_data, arch_id, 1); /* APIC ID */ | ||
78 | /* Flags, Table 5-36 */ | ||
79 | build_append_int_noprefix(table_data, 1, 4); | ||
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 | ||
83 | --- a/hw/loongarch/virt.c | ||
84 | +++ b/hw/loongarch/virt.c | ||
85 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
86 | LoongArchMachineState *lams = LOONGARCH_MACHINE(machine); | ||
87 | int i; | ||
88 | hwaddr fdt_base; | ||
89 | + const CPUArchIdList *possible_cpus; | ||
90 | + MachineClass *mc = MACHINE_GET_CLASS(machine); | ||
91 | + CPUState *cpu; | ||
92 | |||
93 | if (!cpu_model) { | ||
94 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); | ||
95 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
96 | } | ||
97 | create_fdt(lams); | ||
98 | /* Init CPUs */ | ||
99 | - for (i = 0; i < machine->smp.cpus; i++) { | ||
100 | - cpu_create(machine->cpu_type); | ||
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 | + } | 86 | + } |
123 | + | 87 | + |
124 | + ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) + | 88 | + csr->flags |= flag; |
125 | + sizeof(CPUArchId) * max_cpus); | 89 | + return true; |
126 | + ms->possible_cpus->len = max_cpus; | ||
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 | +} | 90 | +} |
135 | + | 91 | diff --git a/target/loongarch/csr.h b/target/loongarch/csr.h |
136 | static void loongarch_class_init(ObjectClass *oc, void *data) | 92 | index XXXXXXX..XXXXXXX 100644 |
137 | { | 93 | --- a/target/loongarch/csr.h |
138 | MachineClass *mc = MACHINE_CLASS(oc); | 94 | +++ b/target/loongarch/csr.h |
139 | @@ -XXX,XX +XXX,XX @@ static void loongarch_class_init(ObjectClass *oc, void *data) | 95 | @@ -XXX,XX +XXX,XX @@ enum { |
140 | mc->block_default_type = IF_VIRTIO; | 96 | CSRFL_READONLY = (1 << 0), |
141 | mc->default_boot_order = "c"; | 97 | CSRFL_EXITTB = (1 << 1), |
142 | mc->no_cdrom = 1; | 98 | CSRFL_IO = (1 << 2), |
143 | + mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids; | 99 | + CSRFL_UNUSED = (1 << 3), |
144 | mc->get_hotplug_handler = virt_machine_get_hotplug_handler; | 100 | }; |
145 | mc->default_nic = "virtio-net-pci"; | 101 | |
146 | hc->plug = loongarch_machine_device_plug_cb; | 102 | typedef struct { |
103 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
104 | } CSRInfo; | ||
105 | |||
106 | CSRInfo *get_csr(unsigned int csr_num); | ||
107 | +bool set_csr_flag(unsigned int csr_num, int flag); | ||
108 | #endif /* TARGET_LOONGARCH_CSR_H */ | ||
147 | -- | 109 | -- |
148 | 2.39.1 | 110 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Tianrui Zhao <zhaotianrui@loongson.cn> | 1 | CSR registers is import system control registers, it had better |
---|---|---|---|
2 | dump all CSR registers when VM is running in system mode. | ||
2 | 3 | ||
3 | LoongArch ipi device uses physical cpuid to route to different | 4 | Here is dump output example of CSR registers: |
4 | vcpus rather logical cpuid, and the physical cpuid is the same | 5 | CSR000: CRMD b4 PRMD 4 EUEN 0 MISC 0 |
5 | with cpuid in acpi dsdt and srat table. | 6 | CSR004: ECFG 71c1c ESTAT 0 ERA 9000000002c31300 BADV 12022c0e0 |
7 | CSR008: BADI 2b0000 | ||
8 | CSR012: EENTRY 90000000046b0000 | ||
9 | CSR016: TLBIDX ffffffff8e000228 TLBEHI 120228000 TLBELO0 400000016f19001f TLBELO1 400000016f1a401f | ||
10 | CSR024: ASID a0004 PGDL 90000001016f0000 PGDH 9000000004680000 PGD 0 | ||
11 | CSR028: PWCL 5e56e PWCH 2e4 STLBPS e RVACFG 0 | ||
12 | CSR032: CPUID 0 PRCFG1 72f8 PRCFG2 3ffff000 PRCFG3 8073f2 | ||
13 | CSR048: SAVE0 0 SAVE1 af9c SAVE2 12010d6a8 SAVE3 8300000 | ||
14 | CSR052: SAVE4 0 SAVE5 0 SAVE6 0 SAVE7 0 | ||
15 | CSR064: TID 0 TCFG 8f0ca15 TVAL 4cefd8b CNTC fffffffffe688aaa | ||
16 | CSR068: TICLR 0 | ||
17 | CSR096: LLBCTL 1 | ||
18 | CSR136: TLBRENTRY 46ba000 TLBRBADV ffff8000130d81e2 TLBRERA 9000000003585cb8 TLBRSAVE ffff8000130d81e0 | ||
19 | CSR140: TLBRELO0 1fe00043 TLBRELO1 40 TLBREHI ffff8000130d800e TLBRPRMD 0 | ||
20 | CSR384: DMW0 8000000000000001 DMW1 9000000000000011 DMW2 0 DMW3 0 | ||
6 | 21 | ||
7 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 22 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
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 | --- | 23 | --- |
12 | hw/intc/loongarch_ipi.c | 44 ++++++++++++++++++++++++++++++++++------- | 24 | target/loongarch/cpu.c | 66 ++++++++++++++++++++++++++++++++---------- |
13 | hw/loongarch/virt.c | 1 + | 25 | target/loongarch/csr.c | 2 ++ |
14 | target/loongarch/cpu.h | 2 ++ | 26 | target/loongarch/csr.h | 1 + |
15 | 3 files changed, 40 insertions(+), 7 deletions(-) | 27 | 3 files changed, 53 insertions(+), 16 deletions(-) |
16 | 28 | ||
17 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 29 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
18 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/intc/loongarch_ipi.c | 31 | --- a/target/loongarch/cpu.c |
20 | +++ b/hw/intc/loongarch_ipi.c | 32 | +++ b/target/loongarch/cpu.c |
21 | @@ -XXX,XX +XXX,XX @@ | 33 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model) |
22 | #include "target/loongarch/internals.h" | 34 | return oc; |
23 | #include "trace.h" | 35 | } |
24 | 36 | ||
25 | +static void loongarch_ipi_writel(void *, hwaddr, uint64_t, unsigned); | 37 | +static void loongarch_cpu_dump_csr(CPUState *cs, FILE *f) |
38 | +{ | ||
39 | +#ifndef CONFIG_USER_ONLY | ||
40 | + CPULoongArchState *env = cpu_env(cs); | ||
41 | + CSRInfo *csr_info; | ||
42 | + int64_t *addr; | ||
43 | + int i, j, len, col = 0; | ||
26 | + | 44 | + |
27 | static uint64_t loongarch_ipi_readl(void *opaque, hwaddr addr, unsigned size) | 45 | + qemu_fprintf(f, "\n"); |
28 | { | ||
29 | IPICore *s = opaque; | ||
30 | @@ -XXX,XX +XXX,XX @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr) | ||
31 | data, MEMTXATTRS_UNSPECIFIED, NULL); | ||
32 | } | ||
33 | |||
34 | +static int archid_cmp(const void *a, const void *b) | ||
35 | +{ | ||
36 | + CPUArchId *archid_a = (CPUArchId *)a; | ||
37 | + CPUArchId *archid_b = (CPUArchId *)b; | ||
38 | + | 46 | + |
39 | + return archid_a->arch_id - archid_b->arch_id; | 47 | + /* Dump all generic CSR register */ |
48 | + for (i = 0; i < LOONGARCH_CSR_DBG; i++) { | ||
49 | + csr_info = get_csr(i); | ||
50 | + if (!csr_info || (csr_info->flags & CSRFL_UNUSED)) { | ||
51 | + if (i == (col + 3)) { | ||
52 | + qemu_fprintf(f, "\n"); | ||
53 | + } | ||
54 | + | ||
55 | + continue; | ||
56 | + } | ||
57 | + | ||
58 | + if ((i > (col + 3)) || (i == col)) { | ||
59 | + col = i & ~3; | ||
60 | + qemu_fprintf(f, " CSR%03d:", col); | ||
61 | + } | ||
62 | + | ||
63 | + addr = (void *)env + csr_info->offset; | ||
64 | + qemu_fprintf(f, " %s ", csr_info->name); | ||
65 | + len = strlen(csr_info->name); | ||
66 | + for (; len < 6; len++) { | ||
67 | + qemu_fprintf(f, " "); | ||
68 | + } | ||
69 | + | ||
70 | + qemu_fprintf(f, "%" PRIx64, *addr); | ||
71 | + j = find_last_bit((void *)addr, BITS_PER_LONG) & (BITS_PER_LONG - 1); | ||
72 | + len += j / 4 + 1; | ||
73 | + for (; len < 22; len++) { | ||
74 | + qemu_fprintf(f, " "); | ||
75 | + } | ||
76 | + | ||
77 | + if (i == (col + 3)) { | ||
78 | + qemu_fprintf(f, "\n"); | ||
79 | + } | ||
80 | + } | ||
81 | + qemu_fprintf(f, "\n"); | ||
82 | +#endif | ||
40 | +} | 83 | +} |
41 | + | 84 | + |
42 | +static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id) | 85 | static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags) |
43 | +{ | ||
44 | + CPUArchId apic_id, *found_cpu; | ||
45 | + | ||
46 | + apic_id.arch_id = id; | ||
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 | { | 86 | { |
65 | uint32_t cpuid; | 87 | CPULoongArchState *env = cpu_env(cs); |
66 | uint8_t vector; | 88 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags) |
67 | - CPULoongArchState *env; | 89 | } |
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 | } | ||
87 | |||
88 | static void mail_send(uint64_t val) | ||
89 | @@ -XXX,XX +XXX,XX @@ static void mail_send(uint64_t val) | ||
90 | } | 90 | } |
91 | 91 | ||
92 | addr = 0x1020 + (val & 0x1c); | 92 | - qemu_fprintf(f, "CRMD=%016" PRIx64 "\n", env->CSR_CRMD); |
93 | - cs = qemu_get_cpu(cpuid); | 93 | - qemu_fprintf(f, "PRMD=%016" PRIx64 "\n", env->CSR_PRMD); |
94 | + cs = ipi_getcpu(cpuid); | 94 | - qemu_fprintf(f, "EUEN=%016" PRIx64 "\n", env->CSR_EUEN); |
95 | cpu = LOONGARCH_CPU(cs); | 95 | - qemu_fprintf(f, "ESTAT=%016" PRIx64 "\n", env->CSR_ESTAT); |
96 | env = &cpu->env; | 96 | - qemu_fprintf(f, "ERA=%016" PRIx64 "\n", env->CSR_ERA); |
97 | send_ipi_data(env, val, addr); | 97 | - qemu_fprintf(f, "BADV=%016" PRIx64 "\n", env->CSR_BADV); |
98 | @@ -XXX,XX +XXX,XX @@ static void any_send(uint64_t val) | 98 | - qemu_fprintf(f, "BADI=%016" PRIx64 "\n", env->CSR_BADI); |
99 | - qemu_fprintf(f, "EENTRY=%016" PRIx64 "\n", env->CSR_EENTRY); | ||
100 | - qemu_fprintf(f, "PRCFG1=%016" PRIx64 ", PRCFG2=%016" PRIx64 "," | ||
101 | - " PRCFG3=%016" PRIx64 "\n", | ||
102 | - env->CSR_PRCFG1, env->CSR_PRCFG2, env->CSR_PRCFG3); | ||
103 | - qemu_fprintf(f, "TLBRENTRY=%016" PRIx64 "\n", env->CSR_TLBRENTRY); | ||
104 | - qemu_fprintf(f, "TLBRBADV=%016" PRIx64 "\n", env->CSR_TLBRBADV); | ||
105 | - qemu_fprintf(f, "TLBRERA=%016" PRIx64 "\n", env->CSR_TLBRERA); | ||
106 | - qemu_fprintf(f, "TCFG=%016" PRIx64 "\n", env->CSR_TCFG); | ||
107 | - qemu_fprintf(f, "TVAL=%016" PRIx64 "\n", env->CSR_TVAL); | ||
108 | + /* csr */ | ||
109 | + loongarch_cpu_dump_csr(cs, f); | ||
110 | |||
111 | /* fpr */ | ||
112 | if (flags & CPU_DUMP_FPU) { | ||
113 | diff --git a/target/loongarch/csr.c b/target/loongarch/csr.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/loongarch/csr.c | ||
116 | +++ b/target/loongarch/csr.c | ||
117 | @@ -XXX,XX +XXX,XX @@ | ||
118 | |||
119 | #define CSR_OFF_FUNCS(NAME, FL, RD, WR) \ | ||
120 | [LOONGARCH_CSR_##NAME] = { \ | ||
121 | + .name = (stringify(NAME)), \ | ||
122 | .offset = offsetof(CPULoongArchState, CSR_##NAME), \ | ||
123 | .flags = FL, .readfn = RD, .writefn = WR \ | ||
99 | } | 124 | } |
100 | 125 | ||
101 | addr = val & 0xffff; | 126 | #define CSR_OFF_ARRAY(NAME, N) \ |
102 | - cs = qemu_get_cpu(cpuid); | 127 | [LOONGARCH_CSR_##NAME(N)] = { \ |
103 | + cs = ipi_getcpu(cpuid); | 128 | + .name = (stringify(NAME##N)), \ |
104 | cpu = LOONGARCH_CPU(cs); | 129 | .offset = offsetof(CPULoongArchState, CSR_##NAME[N]), \ |
105 | env = &cpu->env; | 130 | .flags = 0, .readfn = NULL, .writefn = NULL \ |
106 | send_ipi_data(env, val, addr); | 131 | } |
107 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 132 | diff --git a/target/loongarch/csr.h b/target/loongarch/csr.h |
108 | index XXXXXXX..XXXXXXX 100644 | 133 | index XXXXXXX..XXXXXXX 100644 |
109 | --- a/hw/loongarch/virt.c | 134 | --- a/target/loongarch/csr.h |
110 | +++ b/hw/loongarch/virt.c | 135 | +++ b/target/loongarch/csr.h |
111 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | 136 | @@ -XXX,XX +XXX,XX @@ enum { |
112 | memory_region_add_subregion(&env->system_iocsr, APIC_BASE, | 137 | }; |
113 | sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi), | 138 | |
114 | cpu)); | 139 | typedef struct { |
115 | + env->ipistate = ipi; | 140 | + const char *name; |
116 | } | 141 | int offset; |
117 | 142 | int flags; | |
118 | /* | 143 | GenCSRFunc readfn; |
119 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/target/loongarch/cpu.h | ||
122 | +++ b/target/loongarch/cpu.h | ||
123 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
124 | MemoryRegion iocsr_mem; | ||
125 | bool load_elf; | ||
126 | uint64_t elf_address; | ||
127 | + /* Store ipistate to access from this struct */ | ||
128 | + DeviceState *ipistate; | ||
129 | #endif | ||
130 | } CPULoongArchState; | ||
131 | |||
132 | -- | 144 | -- |
133 | 2.39.1 | 145 | 2.43.5 | diff view generated by jsdifflib |