1 | The following changes since commit ece5f8374d0416a339f0c0a9399faa2c42d4ad6f: | 1 | The following changes since commit 38d0939b86e2eef6f6a622c6f1f7befda0146595: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'linux-user-for-7.2-pull-request' of https://gitlab.com/laurent_vivier/qemu into staging (2022-11-03 10:55:05 -0400) | 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-20221104 | 7 | https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20241227 |
8 | 8 | ||
9 | for you to fetch changes up to 2419978cb09e11bc53a07d4de5621424d2a6a86d: | 9 | for you to fetch changes up to 5e360dabedb1ab1f15cce27a134ccbe4b8e18424: |
10 | 10 | ||
11 | target/loongarch: Fix emulation of float-point disable exception (2022-11-04 17:10:53 +0800) | 11 | target/loongarch: Use auto method with LASX feature (2024-12-27 11:33:06 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | pull-loongarch-20221104 | 14 | pull-loongarch-20241227 |
15 | 15 | v1 ... v2 | |
16 | v2: | 16 | 1. Modify patch auther inconsistent with SOB |
17 | - fix win32/win64 complie error; | ||
18 | - Add Rui Wang' patches. | ||
19 | 17 | ||
20 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
21 | Rui Wang (2): | 19 | Bibo Mao (5): |
22 | target/loongarch: Adjust the layout of hardware flags bit fields | 20 | target/loongarch: Use actual operand size with vbsrl check |
23 | target/loongarch: Fix emulation of float-point disable exception | 21 | hw/loongarch/virt: Create fdt table on machine creation done notification |
22 | hw/loongarch/virt: Improve fdt table creation for CPU object | ||
23 | target/loongarch: Use auto method with LSX feature | ||
24 | target/loongarch: Use auto method with LASX feature | ||
24 | 25 | ||
25 | Song Gao (2): | 26 | Guo Hongyu (1): |
26 | target/loongarch: Add exception subcode | 27 | target/loongarch: Fix vldi inst |
27 | target/loongarch: Fix raise_mmu_exception() set wrong exception_index | ||
28 | 28 | ||
29 | Xiaojuan Yang (5): | 29 | hw/loongarch/virt.c | 142 ++++++++++++++---------- |
30 | hw/intc: Convert the memops to with_attrs in LoongArch extioi | 30 | target/loongarch/cpu.c | 86 ++++++++------ |
31 | hw/intc: Fix LoongArch extioi coreisr accessing | 31 | target/loongarch/cpu.h | 4 + |
32 | hw/loongarch: Load FDT table into dram memory space | 32 | target/loongarch/kvm/kvm.c | 107 ++++++++++++++++++ |
33 | hw/loongarch: Improve fdt for LoongArch virt machine | 33 | target/loongarch/tcg/insn_trans/trans_vec.c.inc | 4 +- |
34 | hw/loongarch: Add TPM device for LoongArch virt machine | 34 | 5 files changed, 249 insertions(+), 94 deletions(-) |
35 | |||
36 | hw/intc/loongarch_extioi.c | 41 +++++++------ | ||
37 | hw/intc/trace-events | 3 +- | ||
38 | hw/loongarch/acpi-build.c | 51 +++++++++++++++- | ||
39 | hw/loongarch/virt.c | 53 ++++++++++++++--- | ||
40 | include/hw/loongarch/virt.h | 3 - | ||
41 | include/hw/pci-host/ls7a.h | 1 + | ||
42 | target/loongarch/cpu.c | 10 +++- | ||
43 | target/loongarch/cpu.h | 69 +++++++++++++--------- | ||
44 | target/loongarch/insn_trans/trans_farith.c.inc | 30 ++++++++++ | ||
45 | target/loongarch/insn_trans/trans_fcmp.c.inc | 11 +++- | ||
46 | target/loongarch/insn_trans/trans_fmemory.c.inc | 34 +++++++++-- | ||
47 | target/loongarch/insn_trans/trans_fmov.c.inc | 29 ++++++++- | ||
48 | target/loongarch/insn_trans/trans_privileged.c.inc | 2 +- | ||
49 | target/loongarch/iocsr_helper.c | 19 +++--- | ||
50 | target/loongarch/tlb_helper.c | 5 +- | ||
51 | target/loongarch/translate.c | 6 +- | ||
52 | 16 files changed, 283 insertions(+), 84 deletions(-) | diff view generated by jsdifflib |
1 | From: Rui Wang <wangrui@loongson.cn> | 1 | From: Guo Hongyu <guohongyu24@mails.ucas.ac.cn> |
---|---|---|---|
2 | 2 | ||
3 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Refer to the link below for a description of the vldi instructions: |
4 | Reviewed-by: Song Gao <gaosong@loongson.cn> | 4 | https://jia.je/unofficial-loongarch-intrinsics-guide/lsx/misc/#synopsis_88 |
5 | Signed-off-by: Rui Wang <wangrui@loongson.cn> | 5 | Fixed errors in vldi instruction implementation. |
6 | Message-Id: <20221104040517.222059-2-wangrui@loongson.cn> | 6 | |
7 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 7 | Signed-off-by: Guo Hongyu <guohongyu24@mails.ucas.ac.cn> |
8 | Tested-by: Xianglai Li <lixianglai@loongson.cn> | ||
9 | Signed-off-by: Xianglai Li <lixianglai@loongson.cn> | ||
10 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
11 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
8 | --- | 12 | --- |
9 | target/loongarch/cpu.h | 9 ++++++++- | 13 | target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +- |
10 | target/loongarch/insn_trans/trans_privileged.c.inc | 2 +- | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | target/loongarch/translate.c | 6 +++++- | ||
12 | 3 files changed, 14 insertions(+), 3 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | 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/target/loongarch/cpu.h | 18 | --- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
17 | +++ b/target/loongarch/cpu.h | 19 | +++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
18 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ static uint64_t vldi_get_value(DisasContext *ctx, uint32_t imm) |
19 | #include "qemu/timer.h" | 21 | break; |
20 | #include "exec/memory.h" | 22 | case 1: |
21 | #include "hw/sysbus.h" | 23 | /* data: {2{16'0, imm[7:0], 8'0}} */ |
22 | +#include "cpu-csr.h" | 24 | - data = (t << 24) | (t << 8); |
23 | 25 | + data = (t << 40) | (t << 8); | |
24 | #define IOCSRF_TEMP 0 | 26 | break; |
25 | #define IOCSRF_NODECNT 1 | 27 | case 2: |
26 | @@ -XXX,XX +XXX,XX @@ static inline int cpu_mmu_index(CPULoongArchState *env, bool ifetch) | 28 | /* data: {2{8'0, imm[7:0], 16'0}} */ |
27 | #endif | ||
28 | } | ||
29 | |||
30 | +/* | ||
31 | + * LoongArch CPUs hardware flags. | ||
32 | + */ | ||
33 | +#define HW_FLAGS_PLV_MASK R_CSR_CRMD_PLV_MASK /* 0x03 */ | ||
34 | +#define HW_FLAGS_CRMD_PG R_CSR_CRMD_PG_MASK /* 0x10 */ | ||
35 | + | ||
36 | static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, | ||
37 | target_ulong *pc, | ||
38 | target_ulong *cs_base, | ||
39 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, | ||
40 | { | ||
41 | *pc = env->pc; | ||
42 | *cs_base = 0; | ||
43 | - *flags = cpu_mmu_index(env, false); | ||
44 | + *flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK); | ||
45 | } | ||
46 | |||
47 | void loongarch_cpu_list(void); | ||
48 | diff --git a/target/loongarch/insn_trans/trans_privileged.c.inc b/target/loongarch/insn_trans/trans_privileged.c.inc | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/loongarch/insn_trans/trans_privileged.c.inc | ||
51 | +++ b/target/loongarch/insn_trans/trans_privileged.c.inc | ||
52 | @@ -XXX,XX +XXX,XX @@ static const CSRInfo csr_info[] = { | ||
53 | |||
54 | static bool check_plv(DisasContext *ctx) | ||
55 | { | ||
56 | - if (ctx->base.tb->flags == MMU_USER_IDX) { | ||
57 | + if (ctx->mem_idx == MMU_USER_IDX) { | ||
58 | generate_exception(ctx, EXCCODE_IPE); | ||
59 | return true; | ||
60 | } | ||
61 | diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/target/loongarch/translate.c | ||
64 | +++ b/target/loongarch/translate.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static void loongarch_tr_init_disas_context(DisasContextBase *dcbase, | ||
66 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | ||
67 | |||
68 | ctx->page_start = ctx->base.pc_first & TARGET_PAGE_MASK; | ||
69 | - ctx->mem_idx = ctx->base.tb->flags; | ||
70 | + if (ctx->base.tb->flags & HW_FLAGS_CRMD_PG) { | ||
71 | + ctx->mem_idx = ctx->base.tb->flags & HW_FLAGS_PLV_MASK; | ||
72 | + } else { | ||
73 | + ctx->mem_idx = MMU_DA_IDX; | ||
74 | + } | ||
75 | |||
76 | /* Bound the number of insns to execute to those left on the page. */ | ||
77 | bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; | ||
78 | -- | 29 | -- |
79 | 2.31.1 | 30 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> | 1 | Hardcoded 32 bytes is used for vbsrl emulation check, there is |
---|---|---|---|
2 | problem when options lsx=on,lasx=off is used for vbsrl.v instruction | ||
3 | in TCG mode. It injects LASX exception rather LSX exception. | ||
2 | 4 | ||
3 | Converting the MemoryRegionOps read/write handlers to | 5 | Here actual operand size is used. |
4 | with_attrs in LoongArch extioi emulation. | ||
5 | 6 | ||
6 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> | 7 | Cc: qemu-stable@nongnu.org |
8 | Fixes: df97f338076 ("target/loongarch: Implement xvreplve xvinsve0 xvpickve") | ||
9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-Id: <20221021015307.2570844-2-yangxiaojuan@loongson.cn> | ||
10 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
11 | --- | 12 | --- |
12 | hw/intc/loongarch_extioi.c | 31 +++++++++++++++++-------------- | 13 | target/loongarch/tcg/insn_trans/trans_vec.c.inc | 2 +- |
13 | hw/intc/trace-events | 3 +-- | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 2 files changed, 18 insertions(+), 16 deletions(-) | ||
15 | 15 | ||
16 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c | 16 | diff --git a/target/loongarch/tcg/insn_trans/trans_vec.c.inc b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/intc/loongarch_extioi.c | 18 | --- a/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
19 | +++ b/hw/intc/loongarch_extioi.c | 19 | +++ b/target/loongarch/tcg/insn_trans/trans_vec.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ static void extioi_setirq(void *opaque, int irq, int level) | 20 | @@ -XXX,XX +XXX,XX @@ static bool do_vbsrl_v(DisasContext *ctx, arg_vv_i *a, uint32_t oprsz) |
21 | extioi_update_irq(s, irq, level); | ||
22 | } | ||
23 | |||
24 | -static uint64_t extioi_readw(void *opaque, hwaddr addr, unsigned size) | ||
25 | +static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data, | ||
26 | + unsigned size, MemTxAttrs attrs) | ||
27 | { | 21 | { |
28 | LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); | 22 | int i, ofs; |
29 | unsigned long offset = addr & 0xffff; | 23 | |
30 | - uint32_t index, cpu, ret = 0; | 24 | - if (!check_vec(ctx, 32)) { |
31 | + uint32_t index, cpu; | 25 | + if (!check_vec(ctx, oprsz)) { |
32 | 26 | return true; | |
33 | switch (offset) { | ||
34 | case EXTIOI_NODETYPE_START ... EXTIOI_NODETYPE_END - 1: | ||
35 | index = (offset - EXTIOI_NODETYPE_START) >> 2; | ||
36 | - ret = s->nodetype[index]; | ||
37 | + *data = s->nodetype[index]; | ||
38 | break; | ||
39 | case EXTIOI_IPMAP_START ... EXTIOI_IPMAP_END - 1: | ||
40 | index = (offset - EXTIOI_IPMAP_START) >> 2; | ||
41 | - ret = s->ipmap[index]; | ||
42 | + *data = s->ipmap[index]; | ||
43 | break; | ||
44 | case EXTIOI_ENABLE_START ... EXTIOI_ENABLE_END - 1: | ||
45 | index = (offset - EXTIOI_ENABLE_START) >> 2; | ||
46 | - ret = s->enable[index]; | ||
47 | + *data = s->enable[index]; | ||
48 | break; | ||
49 | case EXTIOI_BOUNCE_START ... EXTIOI_BOUNCE_END - 1: | ||
50 | index = (offset - EXTIOI_BOUNCE_START) >> 2; | ||
51 | - ret = s->bounce[index]; | ||
52 | + *data = s->bounce[index]; | ||
53 | break; | ||
54 | case EXTIOI_COREISR_START ... EXTIOI_COREISR_END - 1: | ||
55 | index = ((offset - EXTIOI_COREISR_START) & 0x1f) >> 2; | ||
56 | cpu = ((offset - EXTIOI_COREISR_START) >> 8) & 0x3; | ||
57 | - ret = s->coreisr[cpu][index]; | ||
58 | + *data = s->coreisr[cpu][index]; | ||
59 | break; | ||
60 | case EXTIOI_COREMAP_START ... EXTIOI_COREMAP_END - 1: | ||
61 | index = (offset - EXTIOI_COREMAP_START) >> 2; | ||
62 | - ret = s->coremap[index]; | ||
63 | + *data = s->coremap[index]; | ||
64 | break; | ||
65 | default: | ||
66 | break; | ||
67 | } | 27 | } |
68 | 28 | ||
69 | - trace_loongarch_extioi_readw(addr, ret); | ||
70 | - return ret; | ||
71 | + trace_loongarch_extioi_readw(addr, *data); | ||
72 | + return MEMTX_OK; | ||
73 | } | ||
74 | |||
75 | static inline void extioi_enable_irq(LoongArchExtIOI *s, int index,\ | ||
76 | @@ -XXX,XX +XXX,XX @@ static inline void extioi_enable_irq(LoongArchExtIOI *s, int index,\ | ||
77 | } | ||
78 | } | ||
79 | |||
80 | -static void extioi_writew(void *opaque, hwaddr addr, | ||
81 | - uint64_t val, unsigned size) | ||
82 | +static MemTxResult extioi_writew(void *opaque, hwaddr addr, | ||
83 | + uint64_t val, unsigned size, | ||
84 | + MemTxAttrs attrs) | ||
85 | { | ||
86 | LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); | ||
87 | int i, cpu, index, old_data, irq; | ||
88 | @@ -XXX,XX +XXX,XX @@ static void extioi_writew(void *opaque, hwaddr addr, | ||
89 | default: | ||
90 | break; | ||
91 | } | ||
92 | + return MEMTX_OK; | ||
93 | } | ||
94 | |||
95 | static const MemoryRegionOps extioi_ops = { | ||
96 | - .read = extioi_readw, | ||
97 | - .write = extioi_writew, | ||
98 | + .read_with_attrs = extioi_readw, | ||
99 | + .write_with_attrs = extioi_writew, | ||
100 | .impl.min_access_size = 4, | ||
101 | .impl.max_access_size = 4, | ||
102 | .valid.min_access_size = 4, | ||
103 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/hw/intc/trace-events | ||
106 | +++ b/hw/intc/trace-events | ||
107 | @@ -XXX,XX +XXX,XX @@ loongarch_msi_set_irq(int irq_num) "set msi irq %d" | ||
108 | |||
109 | # loongarch_extioi.c | ||
110 | loongarch_extioi_setirq(int irq, int level) "set extirq irq %d level %d" | ||
111 | -loongarch_extioi_readw(uint64_t addr, uint32_t val) "addr: 0x%"PRIx64 "val: 0x%x" | ||
112 | +loongarch_extioi_readw(uint64_t addr, uint64_t val) "addr: 0x%"PRIx64 "val: 0x%" PRIx64 | ||
113 | loongarch_extioi_writew(uint64_t addr, uint64_t val) "addr: 0x%"PRIx64 "val: 0x%" PRIx64 | ||
114 | - | ||
115 | -- | 29 | -- |
116 | 2.31.1 | 30 | 2.43.5 |
117 | 31 | ||
118 | 32 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
2 | 1 | ||
3 | 1. When cpu read or write extioi COREISR reg, it should access | ||
4 | the reg belonged to itself, so the cpu index of 's->coreisr' | ||
5 | is current cpu number. Using MemTxAttrs' requester_id to get | ||
6 | the cpu index. | ||
7 | 2. it need not to mask 0x1f when calculate the coreisr array index. | ||
8 | |||
9 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-Id: <20221021015307.2570844-3-yangxiaojuan@loongson.cn> | ||
12 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
13 | --- | ||
14 | hw/intc/loongarch_extioi.c | 10 ++++++---- | ||
15 | target/loongarch/iocsr_helper.c | 19 +++++++++++-------- | ||
16 | 2 files changed, 17 insertions(+), 12 deletions(-) | ||
17 | |||
18 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/intc/loongarch_extioi.c | ||
21 | +++ b/hw/intc/loongarch_extioi.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data, | ||
23 | *data = s->bounce[index]; | ||
24 | break; | ||
25 | case EXTIOI_COREISR_START ... EXTIOI_COREISR_END - 1: | ||
26 | - index = ((offset - EXTIOI_COREISR_START) & 0x1f) >> 2; | ||
27 | - cpu = ((offset - EXTIOI_COREISR_START) >> 8) & 0x3; | ||
28 | + index = (offset - EXTIOI_COREISR_START) >> 2; | ||
29 | + /* using attrs to get current cpu index */ | ||
30 | + cpu = attrs.requester_id; | ||
31 | *data = s->coreisr[cpu][index]; | ||
32 | break; | ||
33 | case EXTIOI_COREMAP_START ... EXTIOI_COREMAP_END - 1: | ||
34 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_writew(void *opaque, hwaddr addr, | ||
35 | s->bounce[index] = val; | ||
36 | break; | ||
37 | case EXTIOI_COREISR_START ... EXTIOI_COREISR_END - 1: | ||
38 | - index = ((offset - EXTIOI_COREISR_START) & 0x1f) >> 2; | ||
39 | - cpu = ((offset - EXTIOI_COREISR_START) >> 8) & 0x3; | ||
40 | + index = (offset - EXTIOI_COREISR_START) >> 2; | ||
41 | + /* using attrs to get current cpu index */ | ||
42 | + cpu = attrs.requester_id; | ||
43 | old_data = s->coreisr[cpu][index]; | ||
44 | s->coreisr[cpu][index] = old_data & ~val; | ||
45 | /* write 1 to clear interrrupt */ | ||
46 | diff --git a/target/loongarch/iocsr_helper.c b/target/loongarch/iocsr_helper.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/loongarch/iocsr_helper.c | ||
49 | +++ b/target/loongarch/iocsr_helper.c | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | #include "exec/cpu_ldst.h" | ||
52 | #include "tcg/tcg-ldst.h" | ||
53 | |||
54 | +#define GET_MEMTXATTRS(cas) \ | ||
55 | + ((MemTxAttrs){.requester_id = env_cpu(cas)->cpu_index}) | ||
56 | + | ||
57 | uint64_t helper_iocsrrd_b(CPULoongArchState *env, target_ulong r_addr) | ||
58 | { | ||
59 | return address_space_ldub(&env->address_space_iocsr, r_addr, | ||
60 | - MEMTXATTRS_UNSPECIFIED, NULL); | ||
61 | + GET_MEMTXATTRS(env), NULL); | ||
62 | } | ||
63 | |||
64 | uint64_t helper_iocsrrd_h(CPULoongArchState *env, target_ulong r_addr) | ||
65 | { | ||
66 | return address_space_lduw(&env->address_space_iocsr, r_addr, | ||
67 | - MEMTXATTRS_UNSPECIFIED, NULL); | ||
68 | + GET_MEMTXATTRS(env), NULL); | ||
69 | } | ||
70 | |||
71 | uint64_t helper_iocsrrd_w(CPULoongArchState *env, target_ulong r_addr) | ||
72 | { | ||
73 | return address_space_ldl(&env->address_space_iocsr, r_addr, | ||
74 | - MEMTXATTRS_UNSPECIFIED, NULL); | ||
75 | + GET_MEMTXATTRS(env), NULL); | ||
76 | } | ||
77 | |||
78 | uint64_t helper_iocsrrd_d(CPULoongArchState *env, target_ulong r_addr) | ||
79 | { | ||
80 | return address_space_ldq(&env->address_space_iocsr, r_addr, | ||
81 | - MEMTXATTRS_UNSPECIFIED, NULL); | ||
82 | + GET_MEMTXATTRS(env), NULL); | ||
83 | } | ||
84 | |||
85 | void helper_iocsrwr_b(CPULoongArchState *env, target_ulong w_addr, | ||
86 | target_ulong val) | ||
87 | { | ||
88 | address_space_stb(&env->address_space_iocsr, w_addr, | ||
89 | - val, MEMTXATTRS_UNSPECIFIED, NULL); | ||
90 | + val, GET_MEMTXATTRS(env), NULL); | ||
91 | } | ||
92 | |||
93 | void helper_iocsrwr_h(CPULoongArchState *env, target_ulong w_addr, | ||
94 | target_ulong val) | ||
95 | { | ||
96 | address_space_stw(&env->address_space_iocsr, w_addr, | ||
97 | - val, MEMTXATTRS_UNSPECIFIED, NULL); | ||
98 | + val, GET_MEMTXATTRS(env), NULL); | ||
99 | } | ||
100 | |||
101 | void helper_iocsrwr_w(CPULoongArchState *env, target_ulong w_addr, | ||
102 | target_ulong val) | ||
103 | { | ||
104 | address_space_stl(&env->address_space_iocsr, w_addr, | ||
105 | - val, MEMTXATTRS_UNSPECIFIED, NULL); | ||
106 | + val, GET_MEMTXATTRS(env), NULL); | ||
107 | } | ||
108 | |||
109 | void helper_iocsrwr_d(CPULoongArchState *env, target_ulong w_addr, | ||
110 | target_ulong val) | ||
111 | { | ||
112 | address_space_stq(&env->address_space_iocsr, w_addr, | ||
113 | - val, MEMTXATTRS_UNSPECIFIED, NULL); | ||
114 | + val, GET_MEMTXATTRS(env), NULL); | ||
115 | } | ||
116 | -- | ||
117 | 2.31.1 | diff view generated by jsdifflib |
1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> | 1 | The same with ACPI table, fdt table is created on machine done |
---|---|---|---|
2 | notification. Some objects like CPU objects can be created with cold-plug | ||
3 | method with command such as -smp x, -device la464-loongarch-cpu, so all | ||
4 | objects finish to create when machine is done. | ||
2 | 5 | ||
3 | Add new items into LoongArch FDT, including rtc and uart info. | 6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | 7 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | |
5 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
6 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
7 | Message-Id: <20221028014007.2718352-3-yangxiaojuan@loongson.cn> | ||
8 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
9 | --- | 8 | --- |
10 | hw/loongarch/virt.c | 31 +++++++++++++++++++++++++++++++ | 9 | hw/loongarch/virt.c | 103 ++++++++++++++++++++++++-------------------- |
11 | include/hw/pci-host/ls7a.h | 1 + | 10 | 1 file changed, 57 insertions(+), 46 deletions(-) |
12 | 2 files changed, 32 insertions(+) | ||
13 | 11 | ||
14 | 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 |
15 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/loongarch/virt.c | 14 | --- a/hw/loongarch/virt.c |
17 | +++ b/hw/loongarch/virt.c | 15 | +++ b/hw/loongarch/virt.c |
18 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -XXX,XX +XXX,XX @@ static void virt_build_smbios(LoongArchVirtMachineState *lvms) |
19 | #include "hw/display/ramfb.h" | 17 | } |
20 | #include "hw/mem/pc-dimm.h" | 18 | } |
21 | 19 | ||
22 | +static void fdt_add_rtc_node(LoongArchMachineState *lams) | 20 | +static void virt_fdt_setup(LoongArchVirtMachineState *lvms) |
23 | +{ | 21 | +{ |
24 | + char *nodename; | 22 | + MachineState *machine = MACHINE(lvms); |
25 | + hwaddr base = VIRT_RTC_REG_BASE; | 23 | + uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle; |
26 | + hwaddr size = VIRT_RTC_LEN; | 24 | + int i; |
27 | + MachineState *ms = MACHINE(lams); | 25 | + |
28 | + | 26 | + create_fdt(lvms); |
29 | + nodename = g_strdup_printf("/rtc@%" PRIx64, base); | 27 | + fdt_add_cpu_nodes(lvms); |
30 | + qemu_fdt_add_subnode(ms->fdt, nodename); | 28 | + fdt_add_memory_nodes(machine); |
31 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "loongson,ls7a-rtc"); | 29 | + fdt_add_fw_cfg_node(lvms); |
32 | + qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 0x0, base, size); | 30 | + fdt_add_flash_node(lvms); |
33 | + g_free(nodename); | 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)); | ||
34 | +} | 72 | +} |
35 | + | 73 | + |
36 | +static void fdt_add_uart_node(LoongArchMachineState *lams) | 74 | static void virt_done(Notifier *notifier, void *data) |
37 | +{ | ||
38 | + char *nodename; | ||
39 | + hwaddr base = VIRT_UART_BASE; | ||
40 | + hwaddr size = VIRT_UART_SIZE; | ||
41 | + MachineState *ms = MACHINE(lams); | ||
42 | + | ||
43 | + nodename = g_strdup_printf("/serial@%" PRIx64, base); | ||
44 | + qemu_fdt_add_subnode(ms->fdt, nodename); | ||
45 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "ns16550a"); | ||
46 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, base, 0x0, size); | ||
47 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 100000000); | ||
48 | + g_free(nodename); | ||
49 | +} | ||
50 | + | ||
51 | static void create_fdt(LoongArchMachineState *lams) | ||
52 | { | 75 | { |
53 | MachineState *ms = MACHINE(lams); | 76 | LoongArchVirtMachineState *lvms = container_of(notifier, |
54 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState * | 77 | LoongArchVirtMachineState, machine_done); |
55 | qdev_get_gpio_in(pch_pic, | 78 | virt_build_smbios(lvms); |
56 | VIRT_UART_IRQ - PCH_PIC_IRQ_OFFSET), | 79 | loongarch_acpi_setup(lvms); |
57 | 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN); | 80 | + virt_fdt_setup(lvms); |
58 | + fdt_add_uart_node(lams); | 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 | } | ||
59 | 111 | ||
60 | /* Network init */ | 112 | /* Network init */ |
61 | for (i = 0; i < nb_nics; i++) { | 113 | @@ -XXX,XX +XXX,XX @@ static void virt_devices_init(DeviceState *pch_pic, |
62 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState * | ||
63 | sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE, | 114 | sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE, |
64 | qdev_get_gpio_in(pch_pic, | 115 | qdev_get_gpio_in(pch_pic, |
65 | VIRT_RTC_IRQ - PCH_PIC_IRQ_OFFSET)); | 116 | VIRT_RTC_IRQ - VIRT_GSI_BASE)); |
66 | + fdt_add_rtc_node(lams); | 117 | - fdt_add_rtc_node(lvms, pch_pic_phandle); |
67 | 118 | - fdt_add_ged_reset(lvms); | |
68 | pm_mem = g_new(MemoryRegion, 1); | 119 | |
69 | memory_region_init_io(pm_mem, NULL, &loongarch_virt_pm_ops, | 120 | /* acpi ged */ |
70 | diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h | 121 | lvms->acpi_ged = create_acpi_ged(pch_pic, lvms); |
71 | index XXXXXXX..XXXXXXX 100644 | 122 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) |
72 | --- a/include/hw/pci-host/ls7a.h | 123 | CPULoongArchState *env; |
73 | +++ b/include/hw/pci-host/ls7a.h | 124 | CPUState *cpu_state; |
74 | @@ -XXX,XX +XXX,XX @@ | 125 | int cpu, pin, i, start, num; |
75 | #define VIRT_PCI_IRQS 48 | 126 | - uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle; |
76 | #define VIRT_UART_IRQ (PCH_PIC_IRQ_OFFSET + 2) | 127 | |
77 | #define VIRT_UART_BASE 0x1fe001e0 | 128 | /* |
78 | +#define VIRT_UART_SIZE 0X100 | 129 | * Extended IRQ model. |
79 | #define VIRT_RTC_IRQ (PCH_PIC_IRQ_OFFSET + 3) | 130 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) |
80 | #define VIRT_MISC_REG_BASE (VIRT_PCH_REG_BASE + 0x00080000) | 131 | memory_region_add_subregion(&lvms->system_iocsr, MAIL_SEND_ADDR, |
81 | #define VIRT_RTC_REG_BASE (VIRT_MISC_REG_BASE + 0x00050100) | 132 | sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 1)); |
133 | |||
134 | - /* Add cpu interrupt-controller */ | ||
135 | - fdt_add_cpuic_node(lvms, &cpuintc_phandle); | ||
136 | - | ||
137 | for (cpu = 0; cpu < ms->smp.cpus; cpu++) { | ||
138 | cpu_state = qemu_get_cpu(cpu); | ||
139 | cpudev = DEVICE(cpu_state); | ||
140 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) | ||
141 | } | ||
142 | } | ||
143 | |||
144 | - /* Add Extend I/O Interrupt Controller node */ | ||
145 | - fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle); | ||
146 | - | ||
147 | pch_pic = qdev_new(TYPE_LOONGARCH_PIC); | ||
148 | num = VIRT_PCH_PIC_IRQ_NUM; | ||
149 | qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num); | ||
150 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) | ||
151 | qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i)); | ||
152 | } | ||
153 | |||
154 | - /* Add PCH PIC node */ | ||
155 | - fdt_add_pch_pic_node(lvms, &eiointc_phandle, &pch_pic_phandle); | ||
156 | - | ||
157 | pch_msi = qdev_new(TYPE_LOONGARCH_PCH_MSI); | ||
158 | start = num; | ||
159 | num = EXTIOI_IRQS - start; | ||
160 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) | ||
161 | qdev_get_gpio_in(extioi, i + start)); | ||
162 | } | ||
163 | |||
164 | - /* Add PCH MSI node */ | ||
165 | - fdt_add_pch_msi_node(lvms, &eiointc_phandle, &pch_msi_phandle); | ||
166 | - | ||
167 | - virt_devices_init(pch_pic, lvms, &pch_pic_phandle, &pch_msi_phandle); | ||
168 | + virt_devices_init(pch_pic, lvms); | ||
169 | } | ||
170 | |||
171 | static void virt_firmware_init(LoongArchVirtMachineState *lvms) | ||
172 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
173 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); | ||
174 | } | ||
175 | |||
176 | - create_fdt(lvms); | ||
177 | - | ||
178 | /* Create IOCSR space */ | ||
179 | memory_region_init_io(&lvms->system_iocsr, OBJECT(machine), NULL, | ||
180 | machine, "iocsr", UINT64_MAX); | ||
181 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
182 | lacpu = LOONGARCH_CPU(cpu); | ||
183 | lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id; | ||
184 | } | ||
185 | - fdt_add_cpu_nodes(lvms); | ||
186 | - fdt_add_memory_nodes(machine); | ||
187 | fw_cfg_add_memory(machine); | ||
188 | |||
189 | /* Node0 memory */ | ||
190 | @@ -XXX,XX +XXX,XX @@ static void virt_init(MachineState *machine) | ||
191 | memmap_table, | ||
192 | sizeof(struct memmap_entry) * (memmap_entries)); | ||
193 | } | ||
194 | - fdt_add_fw_cfg_node(lvms); | ||
195 | - fdt_add_flash_node(lvms); | ||
196 | |||
197 | /* Initialize the IO interrupt subsystem */ | ||
198 | virt_irq_init(lvms); | ||
199 | - platform_bus_add_all_fdt_nodes(machine->fdt, "/platic", | ||
200 | - VIRT_PLATFORM_BUS_BASEADDRESS, | ||
201 | - VIRT_PLATFORM_BUS_SIZE, | ||
202 | - VIRT_PLATFORM_BUS_IRQ); | ||
203 | lvms->machine_done.notify = virt_done; | ||
204 | qemu_add_machine_init_done_notifier(&lvms->machine_done); | ||
205 | /* connect powerdown request */ | ||
206 | lvms->powerdown_notifier.notify = virt_powerdown_req; | ||
207 | qemu_register_powerdown_notifier(&lvms->powerdown_notifier); | ||
208 | |||
209 | - /* | ||
210 | - * Since lowmem region starts from 0 and Linux kernel legacy start address | ||
211 | - * at 2 MiB, FDT base address is located at 1 MiB to avoid NULL pointer | ||
212 | - * access. FDT size limit with 1 MiB. | ||
213 | - * Put the FDT into the memory map as a ROM image: this will ensure | ||
214 | - * the FDT is copied again upon reset, even if addr points into RAM. | ||
215 | - */ | ||
216 | - qemu_fdt_dumpdtb(machine->fdt, lvms->fdt_size); | ||
217 | - rom_add_blob_fixed_as("fdt", machine->fdt, lvms->fdt_size, FDT_BASE, | ||
218 | - &address_space_memory); | ||
219 | - qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, | ||
220 | - rom_ptr_for_as(&address_space_memory, FDT_BASE, lvms->fdt_size)); | ||
221 | - | ||
222 | lvms->bootinfo.ram_size = ram_size; | ||
223 | loongarch_load_kernel(machine, &lvms->bootinfo); | ||
224 | } | ||
82 | -- | 225 | -- |
83 | 2.31.1 | 226 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> | 1 | For CPU object, possible_cpu_arch_ids() function is used rather than |
---|---|---|---|
2 | smp.cpus. With command -smp x, -device la464-loongarch-cpu, smp.cpus | ||
3 | is not accurate for all possible CPU objects, possible_cpu_arch_ids() | ||
4 | is used here. | ||
2 | 5 | ||
3 | Load FDT table into dram memory space, and the addr is 2 MiB. | 6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Since lowmem region starts from 0, FDT base address is located | 7 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
5 | at 2 MiB to avoid NULL pointer access. | ||
6 | |||
7 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
8 | Acked-by: Song Gao <gaosong@loongson.cn> | ||
9 | Message-Id: <20221028014007.2718352-2-yangxiaojuan@loongson.cn> | ||
10 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
11 | --- | 8 | --- |
12 | hw/loongarch/virt.c | 18 +++++++++++------- | 9 | hw/loongarch/virt.c | 39 +++++++++++++++++++++++++-------------- |
13 | include/hw/loongarch/virt.h | 3 --- | 10 | 1 file changed, 25 insertions(+), 14 deletions(-) |
14 | 2 files changed, 11 insertions(+), 10 deletions(-) | ||
15 | 11 | ||
16 | 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 |
17 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/loongarch/virt.c | 14 | --- a/hw/loongarch/virt.c |
19 | +++ b/hw/loongarch/virt.c | 15 | +++ b/hw/loongarch/virt.c |
20 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams) | 16 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(LoongArchVirtMachineState *lvms) |
21 | 1, FDT_PCI_RANGE_MMIO, 2, base_mmio, | 17 | static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms) |
22 | 2, base_mmio, 2, size_mmio); | 18 | { |
23 | g_free(nodename); | 19 | int num; |
24 | - qemu_fdt_dumpdtb(ms->fdt, lams->fdt_size); | 20 | - const MachineState *ms = MACHINE(lvms); |
21 | - int smp_cpus = ms->smp.cpus; | ||
22 | + MachineState *ms = MACHINE(lvms); | ||
23 | + MachineClass *mc = MACHINE_GET_CLASS(ms); | ||
24 | + const CPUArchIdList *possible_cpus; | ||
25 | + LoongArchCPU *cpu; | ||
26 | + CPUState *cs; | ||
27 | + char *nodename, *map_path; | ||
28 | |||
29 | qemu_fdt_add_subnode(ms->fdt, "/cpus"); | ||
30 | qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#address-cells", 0x1); | ||
31 | qemu_fdt_setprop_cell(ms->fdt, "/cpus", "#size-cells", 0x0); | ||
32 | |||
33 | /* cpu nodes */ | ||
34 | - for (num = smp_cpus - 1; num >= 0; num--) { | ||
35 | - char *nodename = g_strdup_printf("/cpus/cpu@%d", num); | ||
36 | - LoongArchCPU *cpu = LOONGARCH_CPU(qemu_get_cpu(num)); | ||
37 | - CPUState *cs = CPU(cpu); | ||
38 | + possible_cpus = mc->possible_cpu_arch_ids(ms); | ||
39 | + for (num = 0; num < possible_cpus->len; num++) { | ||
40 | + cs = possible_cpus->cpus[num].cpu; | ||
41 | + if (cs == NULL) { | ||
42 | + continue; | ||
43 | + } | ||
44 | + | ||
45 | + nodename = g_strdup_printf("/cpus/cpu@%d", num); | ||
46 | + cpu = LOONGARCH_CPU(cs); | ||
47 | |||
48 | qemu_fdt_add_subnode(ms->fdt, nodename); | ||
49 | qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "cpu"); | ||
50 | qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | ||
51 | cpu->dtb_compatible); | ||
52 | - if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) { | ||
53 | + if (possible_cpus->cpus[num].props.has_node_id) { | ||
54 | qemu_fdt_setprop_cell(ms->fdt, nodename, "numa-node-id", | ||
55 | - ms->possible_cpus->cpus[cs->cpu_index].props.node_id); | ||
56 | + possible_cpus->cpus[num].props.node_id); | ||
57 | } | ||
58 | qemu_fdt_setprop_cell(ms->fdt, nodename, "reg", num); | ||
59 | qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", | ||
60 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms) | ||
61 | |||
62 | /*cpu map */ | ||
63 | qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map"); | ||
64 | + for (num = 0; num < possible_cpus->len; num++) { | ||
65 | + cs = possible_cpus->cpus[num].cpu; | ||
66 | + if (cs == NULL) { | ||
67 | + continue; | ||
68 | + } | ||
69 | |||
70 | - for (num = smp_cpus - 1; num >= 0; num--) { | ||
71 | - char *cpu_path = g_strdup_printf("/cpus/cpu@%d", num); | ||
72 | - char *map_path; | ||
73 | - | ||
74 | + nodename = g_strdup_printf("/cpus/cpu@%d", num); | ||
75 | if (ms->smp.threads > 1) { | ||
76 | map_path = g_strdup_printf( | ||
77 | "/cpus/cpu-map/socket%d/core%d/thread%d", | ||
78 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const LoongArchVirtMachineState *lvms) | ||
79 | num % ms->smp.cores); | ||
80 | } | ||
81 | qemu_fdt_add_path(ms->fdt, map_path); | ||
82 | - qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", cpu_path); | ||
83 | + qemu_fdt_setprop_phandle(ms->fdt, map_path, "cpu", nodename); | ||
84 | |||
85 | g_free(map_path); | ||
86 | - g_free(cpu_path); | ||
87 | + g_free(nodename); | ||
88 | } | ||
25 | } | 89 | } |
26 | 90 | ||
27 | static void fdt_add_irqchip_node(LoongArchMachineState *lams) | ||
28 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
29 | MemoryRegion *address_space_mem = get_system_memory(); | ||
30 | LoongArchMachineState *lams = LOONGARCH_MACHINE(machine); | ||
31 | int i; | ||
32 | + hwaddr fdt_base; | ||
33 | |||
34 | if (!cpu_model) { | ||
35 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); | ||
36 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
37 | lams->machine_done.notify = virt_machine_done; | ||
38 | qemu_add_machine_init_done_notifier(&lams->machine_done); | ||
39 | fdt_add_pcie_node(lams); | ||
40 | - | ||
41 | - /* load fdt */ | ||
42 | - MemoryRegion *fdt_rom = g_new(MemoryRegion, 1); | ||
43 | - memory_region_init_rom(fdt_rom, NULL, "fdt", VIRT_FDT_SIZE, &error_fatal); | ||
44 | - memory_region_add_subregion(get_system_memory(), VIRT_FDT_BASE, fdt_rom); | ||
45 | - rom_add_blob_fixed("fdt", machine->fdt, lams->fdt_size, VIRT_FDT_BASE); | ||
46 | + /* | ||
47 | + * Since lowmem region starts from 0, FDT base address is located | ||
48 | + * at 2 MiB to avoid NULL pointer access. | ||
49 | + * | ||
50 | + * Put the FDT into the memory map as a ROM image: this will ensure | ||
51 | + * the FDT is copied again upon reset, even if addr points into RAM. | ||
52 | + */ | ||
53 | + fdt_base = 2 * MiB; | ||
54 | + qemu_fdt_dumpdtb(machine->fdt, lams->fdt_size); | ||
55 | + rom_add_blob_fixed("fdt", machine->fdt, lams->fdt_size, fdt_base); | ||
56 | } | ||
57 | |||
58 | bool loongarch_is_acpi_enabled(LoongArchMachineState *lams) | ||
59 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/include/hw/loongarch/virt.h | ||
62 | +++ b/include/hw/loongarch/virt.h | ||
63 | @@ -XXX,XX +XXX,XX @@ | ||
64 | #define VIRT_GED_MEM_ADDR (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN) | ||
65 | #define VIRT_GED_REG_ADDR (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN) | ||
66 | |||
67 | -#define VIRT_FDT_BASE 0x1c400000 | ||
68 | -#define VIRT_FDT_SIZE 0x100000 | ||
69 | - | ||
70 | struct LoongArchMachineState { | ||
71 | /*< private >*/ | ||
72 | MachineState parent_obj; | ||
73 | -- | 91 | -- |
74 | 2.31.1 | 92 | 2.43.5 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
2 | 1 | ||
3 | Add TPM device for LoongArch virt machine, including | ||
4 | establish TPM acpi info and add TYPE_TPM_TIS_SYSBUS | ||
5 | to dynamic_sysbus_devices list. | ||
6 | |||
7 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
8 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
9 | Message-Id: <20221028014007.2718352-4-yangxiaojuan@loongson.cn> | ||
10 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
11 | --- | ||
12 | hw/loongarch/acpi-build.c | 51 ++++++++++++++++++++++++++++++++++++++- | ||
13 | hw/loongarch/virt.c | 4 +++ | ||
14 | 2 files changed, 54 insertions(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/loongarch/acpi-build.c | ||
19 | +++ b/hw/loongarch/acpi-build.c | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | |||
22 | #include "hw/acpi/generic_event_device.h" | ||
23 | #include "hw/pci-host/gpex.h" | ||
24 | +#include "sysemu/tpm.h" | ||
25 | +#include "hw/platform-bus.h" | ||
26 | +#include "hw/acpi/aml-build.h" | ||
27 | |||
28 | #define ACPI_BUILD_ALIGN_SIZE 0x1000 | ||
29 | #define ACPI_BUILD_TABLE_SIZE 0x20000 | ||
30 | @@ -XXX,XX +XXX,XX @@ static void build_pci_device_aml(Aml *scope, LoongArchMachineState *lams) | ||
31 | acpi_dsdt_add_gpex(scope, &cfg); | ||
32 | } | ||
33 | |||
34 | +#ifdef CONFIG_TPM | ||
35 | +static void acpi_dsdt_add_tpm(Aml *scope, LoongArchMachineState *vms) | ||
36 | +{ | ||
37 | + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev); | ||
38 | + hwaddr pbus_base = VIRT_PLATFORM_BUS_BASEADDRESS; | ||
39 | + SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find()); | ||
40 | + MemoryRegion *sbdev_mr; | ||
41 | + hwaddr tpm_base; | ||
42 | + | ||
43 | + if (!sbdev) { | ||
44 | + return; | ||
45 | + } | ||
46 | + | ||
47 | + tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0); | ||
48 | + assert(tpm_base != -1); | ||
49 | + | ||
50 | + tpm_base += pbus_base; | ||
51 | + | ||
52 | + sbdev_mr = sysbus_mmio_get_region(sbdev, 0); | ||
53 | + | ||
54 | + Aml *dev = aml_device("TPM0"); | ||
55 | + aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101"))); | ||
56 | + aml_append(dev, aml_name_decl("_STR", aml_string("TPM 2.0 Device"))); | ||
57 | + aml_append(dev, aml_name_decl("_UID", aml_int(0))); | ||
58 | + | ||
59 | + Aml *crs = aml_resource_template(); | ||
60 | + aml_append(crs, | ||
61 | + aml_memory32_fixed(tpm_base, | ||
62 | + (uint32_t)memory_region_size(sbdev_mr), | ||
63 | + AML_READ_WRITE)); | ||
64 | + aml_append(dev, aml_name_decl("_CRS", crs)); | ||
65 | + aml_append(scope, dev); | ||
66 | +} | ||
67 | +#endif | ||
68 | + | ||
69 | /* build DSDT */ | ||
70 | static void | ||
71 | build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine) | ||
72 | @@ -XXX,XX +XXX,XX @@ build_dsdt(GArray *table_data, BIOSLinker *linker, MachineState *machine) | ||
73 | build_uart_device_aml(dsdt); | ||
74 | build_pci_device_aml(dsdt, lams); | ||
75 | build_la_ged_aml(dsdt, machine); | ||
76 | - | ||
77 | +#ifdef CONFIG_TPM | ||
78 | + acpi_dsdt_add_tpm(dsdt, lams); | ||
79 | +#endif | ||
80 | /* System State Package */ | ||
81 | scope = aml_scope("\\"); | ||
82 | pkg = aml_package(4); | ||
83 | @@ -XXX,XX +XXX,XX @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine) | ||
84 | lams->oem_table_id); | ||
85 | } | ||
86 | |||
87 | +#ifdef CONFIG_TPM | ||
88 | + /* TPM info */ | ||
89 | + if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) { | ||
90 | + acpi_add_table(table_offsets, tables_blob); | ||
91 | + build_tpm2(tables_blob, tables->linker, | ||
92 | + tables->tcpalog, lams->oem_id, | ||
93 | + lams->oem_table_id); | ||
94 | + } | ||
95 | +#endif | ||
96 | /* Add tables supplied by user (if any) */ | ||
97 | for (u = acpi_table_first(); u; u = acpi_table_next(u)) { | ||
98 | unsigned len = acpi_table_len(u); | ||
99 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/hw/loongarch/virt.c | ||
102 | +++ b/hw/loongarch/virt.c | ||
103 | @@ -XXX,XX +XXX,XX @@ | ||
104 | #include "hw/platform-bus.h" | ||
105 | #include "hw/display/ramfb.h" | ||
106 | #include "hw/mem/pc-dimm.h" | ||
107 | +#include "sysemu/tpm.h" | ||
108 | |||
109 | static void fdt_add_rtc_node(LoongArchMachineState *lams) | ||
110 | { | ||
111 | @@ -XXX,XX +XXX,XX @@ static void loongarch_class_init(ObjectClass *oc, void *data) | ||
112 | object_class_property_set_description(oc, "acpi", | ||
113 | "Enable ACPI"); | ||
114 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); | ||
115 | +#ifdef CONFIG_TPM | ||
116 | + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); | ||
117 | +#endif | ||
118 | } | ||
119 | |||
120 | static const TypeInfo loongarch_machine_types[] = { | ||
121 | -- | ||
122 | 2.31.1 | diff view generated by jsdifflib |
1 | We need subcodes to distinguish the same excode cs->exception_indexs, | 1 | Like LBT feature, add type OnOffAuto for LSX feature setting. Also |
---|---|---|---|
2 | such as EXCCODE_ADEF/EXCCODE_ADEM. | 2 | add LSX feature detection with new VM ioctl command, fallback to old |
3 | method if it is not supported. | ||
3 | 4 | ||
4 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
6 | Message-ID: <20221101073210.3934280-1-gaosong@loongson.cn> | ||
7 | --- | 7 | --- |
8 | target/loongarch/cpu.c | 7 +++-- | 8 | target/loongarch/cpu.c | 38 +++++++++++++++------------ |
9 | target/loongarch/cpu.h | 58 ++++++++++++++++++++++-------------------- | 9 | target/loongarch/cpu.h | 2 ++ |
10 | 2 files changed, 36 insertions(+), 29 deletions(-) | 10 | target/loongarch/kvm/kvm.c | 54 ++++++++++++++++++++++++++++++++++++++ |
11 | 3 files changed, 77 insertions(+), 17 deletions(-) | ||
11 | 12 | ||
12 | 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 |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/loongarch/cpu.c | 15 | --- a/target/loongarch/cpu.c |
15 | +++ b/target/loongarch/cpu.c | 16 | +++ b/target/loongarch/cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) | 17 | @@ -XXX,XX +XXX,XX @@ static void loongarch_la464_initfn(Object *obj) |
17 | env->CSR_TLBRERA = FIELD_DP64(env->CSR_TLBRERA, CSR_TLBRERA, | 18 | { |
18 | PC, (env->pc >> 2)); | 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) | ||
53 | { | ||
54 | - LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
55 | - bool ret; | ||
56 | - | ||
57 | - if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { | ||
58 | - ret = true; | ||
59 | - } else { | ||
60 | - ret = false; | ||
61 | - } | ||
62 | - return ret; | ||
63 | + return LOONGARCH_CPU(obj)->lsx != ON_OFF_AUTO_OFF; | ||
64 | } | ||
65 | |||
66 | static void loongarch_set_lsx(Object *obj, bool value, Error **errp) | ||
67 | { | ||
68 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
69 | + uint32_t val; | ||
70 | |||
71 | - if (value) { | ||
72 | - cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 1); | ||
73 | - } else { | ||
74 | - cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LSX, 0); | ||
75 | - cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, LASX, 0); | ||
76 | + cpu->lsx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; | ||
77 | + if (kvm_enabled()) { | ||
78 | + /* kvm feature detection in function kvm_arch_init_vcpu */ | ||
79 | + return; | ||
80 | } | ||
81 | + | ||
82 | + /* LSX feature detection in TCG mode */ | ||
83 | + val = cpu->env.cpucfg[2]; | ||
84 | + if (cpu->lsx == ON_OFF_AUTO_ON) { | ||
85 | + if (FIELD_EX32(val, CPUCFG2, LSX) == 0) { | ||
86 | + error_setg(errp, "Failed to enable LSX in TCG mode"); | ||
87 | + return; | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | + cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value); | ||
92 | } | ||
93 | |||
94 | static bool loongarch_get_lasx(Object *obj, Error **errp) | ||
95 | @@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj) | ||
96 | { | ||
97 | LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
98 | |||
99 | + cpu->lsx = ON_OFF_AUTO_AUTO; | ||
100 | object_property_add_bool(obj, "lsx", loongarch_get_lsx, | ||
101 | loongarch_set_lsx); | ||
102 | object_property_add_bool(obj, "lasx", loongarch_get_lasx, | ||
103 | @@ -XXX,XX +XXX,XX @@ void loongarch_cpu_post_init(Object *obj) | ||
104 | |||
19 | } else { | 105 | } else { |
20 | - env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ECODE, cause); | 106 | cpu->lbt = ON_OFF_AUTO_OFF; |
21 | + env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ECODE, | 107 | + cpu->pmu = ON_OFF_AUTO_OFF; |
22 | + EXCODE_MCODE(cause)); | 108 | } |
23 | + env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ESUBCODE, | 109 | } |
24 | + EXCODE_SUBCODE(cause)); | 110 | |
25 | env->CSR_PRMD = FIELD_DP64(env->CSR_PRMD, CSR_PRMD, PPLV, | ||
26 | FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PLV)); | ||
27 | env->CSR_PRMD = FIELD_DP64(env->CSR_PRMD, CSR_PRMD, PIE, | ||
28 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) | ||
29 | env->pc = env->CSR_TLBRENTRY; | ||
30 | } else { | ||
31 | env->pc = env->CSR_EENTRY; | ||
32 | - env->pc += cause * vec_size; | ||
33 | + env->pc += EXCODE_MCODE(cause) * vec_size; | ||
34 | } | ||
35 | qemu_log_mask(CPU_LOG_INT, | ||
36 | "%s: PC " TARGET_FMT_lx " ERA " TARGET_FMT_lx | ||
37 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | 111 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h |
38 | index XXXXXXX..XXXXXXX 100644 | 112 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/loongarch/cpu.h | 113 | --- a/target/loongarch/cpu.h |
40 | +++ b/target/loongarch/cpu.h | 114 | +++ b/target/loongarch/cpu.h |
41 | @@ -XXX,XX +XXX,XX @@ FIELD(FCSR0, CAUSE, 24, 5) | 115 | @@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB; |
42 | #define FP_DIV0 8 | 116 | #endif |
43 | #define FP_INVALID 16 | 117 | |
44 | 118 | enum loongarch_features { | |
45 | -#define EXCCODE_EXTERNAL_INT 64 /* plus external interrupt number */ | 119 | + LOONGARCH_FEATURE_LSX, |
46 | -#define EXCCODE_INT 0 | 120 | LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */ |
47 | -#define EXCCODE_PIL 1 | 121 | LOONGARCH_FEATURE_PMU, |
48 | -#define EXCCODE_PIS 2 | 122 | }; |
49 | -#define EXCCODE_PIF 3 | 123 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
50 | -#define EXCCODE_PME 4 | 124 | uint32_t phy_id; |
51 | -#define EXCCODE_PNR 5 | 125 | OnOffAuto lbt; |
52 | -#define EXCCODE_PNX 6 | 126 | OnOffAuto pmu; |
53 | -#define EXCCODE_PPI 7 | 127 | + OnOffAuto lsx; |
54 | -#define EXCCODE_ADEF 8 /* Different exception subcode */ | 128 | |
55 | -#define EXCCODE_ADEM 8 | 129 | /* 'compatible' string for this CPU for Linux device trees */ |
56 | -#define EXCCODE_ALE 9 | 130 | const char *dtb_compatible; |
57 | -#define EXCCODE_BCE 10 | 131 | diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c |
58 | -#define EXCCODE_SYS 11 | 132 | index XXXXXXX..XXXXXXX 100644 |
59 | -#define EXCCODE_BRK 12 | 133 | --- a/target/loongarch/kvm/kvm.c |
60 | -#define EXCCODE_INE 13 | 134 | +++ b/target/loongarch/kvm/kvm.c |
61 | -#define EXCCODE_IPE 14 | 135 | @@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature) |
62 | -#define EXCCODE_FPD 15 | 136 | { |
63 | -#define EXCCODE_SXD 16 | 137 | int ret; |
64 | -#define EXCCODE_ASXD 17 | 138 | struct kvm_device_attr attr; |
65 | -#define EXCCODE_FPE 18 /* Different exception subcode */ | 139 | + uint64_t val; |
66 | -#define EXCCODE_VFPE 18 | 140 | |
67 | -#define EXCCODE_WPEF 19 /* Different exception subcode */ | 141 | switch (feature) { |
68 | -#define EXCCODE_WPEM 19 | 142 | + case LOONGARCH_FEATURE_LSX: |
69 | -#define EXCCODE_BTD 20 | 143 | + attr.group = KVM_LOONGARCH_VM_FEAT_CTRL; |
70 | -#define EXCCODE_BTE 21 | 144 | + attr.attr = KVM_LOONGARCH_VM_FEAT_LSX; |
71 | -#define EXCCODE_DBP 26 /* Reserved subcode used for debug */ | 145 | + ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr); |
72 | +#define EXCODE(code, subcode) ( ((subcode) << 6) | (code) ) | 146 | + if (ret == 0) { |
73 | +#define EXCODE_MCODE(code) ( (code) & 0x3f ) | 147 | + return true; |
74 | +#define EXCODE_SUBCODE(code) ( (code) >> 6 ) | 148 | + } |
75 | + | 149 | + |
76 | +#define EXCCODE_EXTERNAL_INT 64 /* plus external interrupt number */ | 150 | + /* Fallback to old kernel detect interface */ |
77 | +#define EXCCODE_INT EXCODE(0, 0) | 151 | + val = 0; |
78 | +#define EXCCODE_PIL EXCODE(1, 0) | 152 | + attr.group = KVM_LOONGARCH_VCPU_CPUCFG; |
79 | +#define EXCCODE_PIS EXCODE(2, 0) | 153 | + /* Cpucfg2 */ |
80 | +#define EXCCODE_PIF EXCODE(3, 0) | 154 | + attr.attr = 2; |
81 | +#define EXCCODE_PME EXCODE(4, 0) | 155 | + attr.addr = (uint64_t)&val; |
82 | +#define EXCCODE_PNR EXCODE(5, 0) | 156 | + ret = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr); |
83 | +#define EXCCODE_PNX EXCODE(6, 0) | 157 | + if (!ret) { |
84 | +#define EXCCODE_PPI EXCODE(7, 0) | 158 | + ret = kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr); |
85 | +#define EXCCODE_ADEF EXCODE(8, 0) /* Different exception subcode */ | 159 | + if (ret) { |
86 | +#define EXCCODE_ADEM EXCODE(8, 1) | 160 | + return false; |
87 | +#define EXCCODE_ALE EXCODE(9, 0) | 161 | + } |
88 | +#define EXCCODE_BCE EXCODE(10, 0) | 162 | + |
89 | +#define EXCCODE_SYS EXCODE(11, 0) | 163 | + ret = FIELD_EX32((uint32_t)val, CPUCFG2, LSX); |
90 | +#define EXCCODE_BRK EXCODE(12, 0) | 164 | + return (ret != 0); |
91 | +#define EXCCODE_INE EXCODE(13, 0) | 165 | + } |
92 | +#define EXCCODE_IPE EXCODE(14, 0) | 166 | + return false; |
93 | +#define EXCCODE_FPD EXCODE(15, 0) | 167 | + |
94 | +#define EXCCODE_SXD EXCODE(16, 0) | 168 | case LOONGARCH_FEATURE_LBT: |
95 | +#define EXCCODE_ASXD EXCODE(17, 0) | 169 | /* |
96 | +#define EXCCODE_FPE EXCODE(18, 0) /* Different exception subcode */ | 170 | * Return all if all the LBT features are supported such as: |
97 | +#define EXCCODE_VFPE EXCODE(18, 1) | 171 | @@ -XXX,XX +XXX,XX @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature) |
98 | +#define EXCCODE_WPEF EXCODE(19, 0) /* Different exception subcode */ | 172 | return false; |
99 | +#define EXCCODE_WPEM EXCODE(19, 1) | 173 | } |
100 | +#define EXCCODE_BTD EXCODE(20, 0) | 174 | |
101 | +#define EXCCODE_BTE EXCODE(21, 0) | 175 | +static int kvm_cpu_check_lsx(CPUState *cs, Error **errp) |
102 | +#define EXCCODE_DBP EXCODE(26, 0) /* Reserved subcode used for debug */ | 176 | +{ |
103 | 177 | + CPULoongArchState *env = cpu_env(cs); | |
104 | /* cpucfg[0] bits */ | 178 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); |
105 | FIELD(CPUCFG0, PRID, 0, 32) | 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); | ||
106 | -- | 212 | -- |
107 | 2.31.1 | 213 | 2.43.5 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | When the address is invalid address, We should set exception_index | ||
2 | according to MMUAccessType, and EXCCODE_ADEF need't update badinstr. | ||
3 | Otherwise, The system enters an infinite loop. e.g: | ||
4 | run test.c on system mode | ||
5 | test.c: | ||
6 | #include<stdio.h> | ||
7 | 1 | ||
8 | void (*func)(int *); | ||
9 | |||
10 | int main() | ||
11 | { | ||
12 | int i = 8; | ||
13 | void *ptr = (void *)0x4000000000000000; | ||
14 | func = ptr; | ||
15 | func(&i); | ||
16 | return 0; | ||
17 | } | ||
18 | |||
19 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Message-ID: <20221101073210.3934280-2-gaosong@loongson.cn> | ||
22 | --- | ||
23 | target/loongarch/cpu.c | 1 + | ||
24 | target/loongarch/tlb_helper.c | 5 +++-- | ||
25 | 2 files changed, 4 insertions(+), 2 deletions(-) | ||
26 | |||
27 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/loongarch/cpu.c | ||
30 | +++ b/target/loongarch/cpu.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) | ||
32 | } | ||
33 | QEMU_FALLTHROUGH; | ||
34 | case EXCCODE_PIF: | ||
35 | + case EXCCODE_ADEF: | ||
36 | cause = cs->exception_index; | ||
37 | update_badinstr = 0; | ||
38 | break; | ||
39 | diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/loongarch/tlb_helper.c | ||
42 | +++ b/target/loongarch/tlb_helper.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPULoongArchState *env, target_ulong address, | ||
44 | switch (tlb_error) { | ||
45 | default: | ||
46 | case TLBRET_BADADDR: | ||
47 | - cs->exception_index = EXCCODE_ADEM; | ||
48 | + cs->exception_index = access_type == MMU_INST_FETCH | ||
49 | + ? EXCCODE_ADEF : EXCCODE_ADEM; | ||
50 | break; | ||
51 | case TLBRET_NOMATCH: | ||
52 | /* No TLB match for a mapped address */ | ||
53 | @@ -XXX,XX +XXX,XX @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
54 | CPULoongArchState *env = &cpu->env; | ||
55 | hwaddr physical; | ||
56 | int prot; | ||
57 | - int ret = TLBRET_BADADDR; | ||
58 | + int ret; | ||
59 | |||
60 | /* Data access */ | ||
61 | ret = get_physical_address(env, &physical, &prot, address, | ||
62 | -- | ||
63 | 2.31.1 | diff view generated by jsdifflib |
1 | From: Rui Wang <wangrui@loongson.cn> | 1 | Like LSX feature, add type OnOffAuto for LASX feature setting. |
---|---|---|---|
2 | 2 | ||
3 | We need to emulate it to generate a floating point disable exception | 3 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | when CSR.EUEN.FPE is zero. | 4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
5 | |||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Song Gao <gaosong@loongson.cn> | ||
8 | Signed-off-by: Rui Wang <wangrui@loongson.cn> | ||
9 | Message-Id: <20221104040517.222059-3-wangrui@loongson.cn> | ||
10 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
11 | --- | 5 | --- |
12 | target/loongarch/cpu.c | 2 ++ | 6 | target/loongarch/cpu.c | 50 +++++++++++++++++++++++------------ |
13 | target/loongarch/cpu.h | 2 ++ | 7 | target/loongarch/cpu.h | 2 ++ |
14 | .../loongarch/insn_trans/trans_farith.c.inc | 30 ++++++++++++++++ | 8 | target/loongarch/kvm/kvm.c | 53 ++++++++++++++++++++++++++++++++++++++ |
15 | target/loongarch/insn_trans/trans_fcmp.c.inc | 11 ++++-- | 9 | 3 files changed, 89 insertions(+), 16 deletions(-) |
16 | .../loongarch/insn_trans/trans_fmemory.c.inc | 34 +++++++++++++++---- | ||
17 | target/loongarch/insn_trans/trans_fmov.c.inc | 29 ++++++++++++++-- | ||
18 | 6 files changed, 97 insertions(+), 11 deletions(-) | ||
19 | 10 | ||
20 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.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/target/loongarch/cpu.c | 13 | --- a/target/loongarch/cpu.c |
23 | +++ b/target/loongarch/cpu.c | 14 | +++ b/target/loongarch/cpu.c |
24 | @@ -XXX,XX +XXX,XX @@ static const char * const excp_names[] = { | 15 | @@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp) |
25 | [EXCCODE_BRK] = "Break", | 16 | uint32_t val; |
26 | [EXCCODE_INE] = "Instruction Non-Existent", | 17 | |
27 | [EXCCODE_IPE] = "Instruction privilege error", | 18 | cpu->lsx = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; |
28 | + [EXCCODE_FPD] = "Floating Point Disabled", | 19 | + if (cpu->lsx == ON_OFF_AUTO_OFF) { |
29 | [EXCCODE_FPE] = "Floating Point Exception", | 20 | + cpu->lasx = ON_OFF_AUTO_OFF; |
30 | [EXCCODE_DBP] = "Debug breakpoint", | 21 | + if (cpu->lasx == ON_OFF_AUTO_ON) { |
31 | [EXCCODE_BCE] = "Bound Check Exception", | 22 | + error_setg(errp, "Failed to disable LSX since LASX is enabled"); |
32 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) | 23 | + return; |
33 | case EXCCODE_BRK: | 24 | + } |
34 | case EXCCODE_INE: | 25 | + } |
35 | case EXCCODE_IPE: | 26 | + |
36 | + case EXCCODE_FPD: | 27 | if (kvm_enabled()) { |
37 | case EXCCODE_FPE: | 28 | /* kvm feature detection in function kvm_arch_init_vcpu */ |
38 | case EXCCODE_BCE: | 29 | return; |
39 | env->CSR_BADV = env->pc; | 30 | @@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp) |
31 | error_setg(errp, "Failed to enable LSX in TCG mode"); | ||
32 | return; | ||
33 | } | ||
34 | + } else { | ||
35 | + cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, 0); | ||
36 | + val = cpu->env.cpucfg[2]; | ||
37 | } | ||
38 | |||
39 | cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LSX, value); | ||
40 | @@ -XXX,XX +XXX,XX @@ static void loongarch_set_lsx(Object *obj, bool value, Error **errp) | ||
41 | |||
42 | static bool loongarch_get_lasx(Object *obj, Error **errp) | ||
43 | { | ||
44 | - LoongArchCPU *cpu = LOONGARCH_CPU(obj); | ||
45 | - bool ret; | ||
46 | - | ||
47 | - if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { | ||
48 | - ret = true; | ||
49 | - } else { | ||
50 | - ret = false; | ||
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"); | ||
71 | + return; | ||
72 | + } | ||
73 | + | ||
74 | + if (kvm_enabled()) { | ||
75 | + /* kvm feature detection in function kvm_arch_init_vcpu */ | ||
76 | + return; | ||
77 | } | ||
78 | + | ||
79 | + /* LASX feature detection in TCG mode */ | ||
80 | + val = cpu->env.cpucfg[2]; | ||
81 | + if (cpu->lasx == ON_OFF_AUTO_ON) { | ||
82 | + if (FIELD_EX32(val, CPUCFG2, LASX) == 0) { | ||
83 | + error_setg(errp, "Failed to enable LASX in TCG mode"); | ||
84 | + return; | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + cpu->env.cpucfg[2] = FIELD_DP32(val, CPUCFG2, LASX, value); | ||
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, | ||
40 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | 100 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h |
41 | index XXXXXXX..XXXXXXX 100644 | 101 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/target/loongarch/cpu.h | 102 | --- a/target/loongarch/cpu.h |
43 | +++ b/target/loongarch/cpu.h | 103 | +++ b/target/loongarch/cpu.h |
44 | @@ -XXX,XX +XXX,XX @@ static inline int cpu_mmu_index(CPULoongArchState *env, bool ifetch) | 104 | @@ -XXX,XX +XXX,XX @@ typedef struct LoongArchTLB LoongArchTLB; |
45 | */ | 105 | |
46 | #define HW_FLAGS_PLV_MASK R_CSR_CRMD_PLV_MASK /* 0x03 */ | 106 | enum loongarch_features { |
47 | #define HW_FLAGS_CRMD_PG R_CSR_CRMD_PG_MASK /* 0x10 */ | 107 | LOONGARCH_FEATURE_LSX, |
48 | +#define HW_FLAGS_EUEN_FPE 0x04 | 108 | + LOONGARCH_FEATURE_LASX, |
49 | 109 | LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */ | |
50 | static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, | 110 | LOONGARCH_FEATURE_PMU, |
51 | target_ulong *pc, | 111 | }; |
52 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, | 112 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
53 | *pc = env->pc; | 113 | OnOffAuto lbt; |
54 | *cs_base = 0; | 114 | OnOffAuto pmu; |
55 | *flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK); | 115 | OnOffAuto lsx; |
56 | + *flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, FPE) * HW_FLAGS_EUEN_FPE; | 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; | ||
57 | } | 159 | } |
58 | 160 | ||
59 | void loongarch_cpu_list(void); | 161 | +static int kvm_cpu_check_lasx(CPUState *cs, Error **errp) |
60 | diff --git a/target/loongarch/insn_trans/trans_farith.c.inc b/target/loongarch/insn_trans/trans_farith.c.inc | 162 | +{ |
61 | index XXXXXXX..XXXXXXX 100644 | 163 | + CPULoongArchState *env = cpu_env(cs); |
62 | --- a/target/loongarch/insn_trans/trans_farith.c.inc | 164 | + LoongArchCPU *cpu = LOONGARCH_CPU(cs); |
63 | +++ b/target/loongarch/insn_trans/trans_farith.c.inc | 165 | + bool kvm_supported; |
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | * Copyright (c) 2021 Loongson Technology Corporation Limited | ||
66 | */ | ||
67 | |||
68 | +#ifndef CONFIG_USER_ONLY | ||
69 | +#define CHECK_FPE do { \ | ||
70 | + if ((ctx->base.tb->flags & HW_FLAGS_EUEN_FPE) == 0) { \ | ||
71 | + generate_exception(ctx, EXCCODE_FPD); \ | ||
72 | + return false; \ | ||
73 | + } \ | ||
74 | +} while (0) | ||
75 | +#else | ||
76 | +#define CHECK_FPE | ||
77 | +#endif | ||
78 | + | 166 | + |
79 | static bool gen_fff(DisasContext *ctx, arg_fff *a, | 167 | + kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_LASX); |
80 | void (*func)(TCGv, TCGv_env, TCGv, TCGv)) | 168 | + env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LASX, 0); |
169 | + if (cpu->lasx == ON_OFF_AUTO_ON) { | ||
170 | + if (kvm_supported) { | ||
171 | + env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LASX, 1); | ||
172 | + } else { | ||
173 | + error_setg(errp, "'lasx' feature not supported by KVM on host"); | ||
174 | + return -ENOTSUP; | ||
175 | + } | ||
176 | + } else if ((cpu->lasx == ON_OFF_AUTO_AUTO) && kvm_supported) { | ||
177 | + env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LASX, 1); | ||
178 | + } | ||
179 | + | ||
180 | + return 0; | ||
181 | +} | ||
182 | + | ||
183 | static int kvm_cpu_check_lbt(CPUState *cs, Error **errp) | ||
81 | { | 184 | { |
82 | + CHECK_FPE; | 185 | CPULoongArchState *env = cpu_env(cs); |
186 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
187 | error_report_err(local_err); | ||
188 | } | ||
189 | |||
190 | + ret = kvm_cpu_check_lasx(cs, &local_err); | ||
191 | + if (ret < 0) { | ||
192 | + error_report_err(local_err); | ||
193 | + } | ||
83 | + | 194 | + |
84 | func(cpu_fpr[a->fd], cpu_env, cpu_fpr[a->fj], cpu_fpr[a->fk]); | 195 | ret = kvm_cpu_check_lbt(cs, &local_err); |
85 | return true; | 196 | if (ret < 0) { |
86 | } | 197 | error_report_err(local_err); |
87 | @@ -XXX,XX +XXX,XX @@ static bool gen_fff(DisasContext *ctx, arg_fff *a, | ||
88 | static bool gen_ff(DisasContext *ctx, arg_ff *a, | ||
89 | void (*func)(TCGv, TCGv_env, TCGv)) | ||
90 | { | ||
91 | + CHECK_FPE; | ||
92 | + | ||
93 | func(cpu_fpr[a->fd], cpu_env, cpu_fpr[a->fj]); | ||
94 | return true; | ||
95 | } | ||
96 | @@ -XXX,XX +XXX,XX @@ static bool gen_muladd(DisasContext *ctx, arg_ffff *a, | ||
97 | int flag) | ||
98 | { | ||
99 | TCGv_i32 tflag = tcg_constant_i32(flag); | ||
100 | + | ||
101 | + CHECK_FPE; | ||
102 | + | ||
103 | func(cpu_fpr[a->fd], cpu_env, cpu_fpr[a->fj], | ||
104 | cpu_fpr[a->fk], cpu_fpr[a->fa], tflag); | ||
105 | return true; | ||
106 | @@ -XXX,XX +XXX,XX @@ static bool gen_muladd(DisasContext *ctx, arg_ffff *a, | ||
107 | |||
108 | static bool trans_fcopysign_s(DisasContext *ctx, arg_fcopysign_s *a) | ||
109 | { | ||
110 | + CHECK_FPE; | ||
111 | + | ||
112 | tcg_gen_deposit_i64(cpu_fpr[a->fd], cpu_fpr[a->fk], cpu_fpr[a->fj], 0, 31); | ||
113 | return true; | ||
114 | } | ||
115 | |||
116 | static bool trans_fcopysign_d(DisasContext *ctx, arg_fcopysign_d *a) | ||
117 | { | ||
118 | + CHECK_FPE; | ||
119 | + | ||
120 | tcg_gen_deposit_i64(cpu_fpr[a->fd], cpu_fpr[a->fk], cpu_fpr[a->fj], 0, 63); | ||
121 | return true; | ||
122 | } | ||
123 | |||
124 | static bool trans_fabs_s(DisasContext *ctx, arg_fabs_s *a) | ||
125 | { | ||
126 | + CHECK_FPE; | ||
127 | + | ||
128 | tcg_gen_andi_i64(cpu_fpr[a->fd], cpu_fpr[a->fj], MAKE_64BIT_MASK(0, 31)); | ||
129 | gen_nanbox_s(cpu_fpr[a->fd], cpu_fpr[a->fd]); | ||
130 | return true; | ||
131 | @@ -XXX,XX +XXX,XX @@ static bool trans_fabs_s(DisasContext *ctx, arg_fabs_s *a) | ||
132 | |||
133 | static bool trans_fabs_d(DisasContext *ctx, arg_fabs_d *a) | ||
134 | { | ||
135 | + CHECK_FPE; | ||
136 | + | ||
137 | tcg_gen_andi_i64(cpu_fpr[a->fd], cpu_fpr[a->fj], MAKE_64BIT_MASK(0, 63)); | ||
138 | return true; | ||
139 | } | ||
140 | |||
141 | static bool trans_fneg_s(DisasContext *ctx, arg_fneg_s *a) | ||
142 | { | ||
143 | + CHECK_FPE; | ||
144 | + | ||
145 | tcg_gen_xori_i64(cpu_fpr[a->fd], cpu_fpr[a->fj], 0x80000000); | ||
146 | gen_nanbox_s(cpu_fpr[a->fd], cpu_fpr[a->fd]); | ||
147 | return true; | ||
148 | @@ -XXX,XX +XXX,XX @@ static bool trans_fneg_s(DisasContext *ctx, arg_fneg_s *a) | ||
149 | |||
150 | static bool trans_fneg_d(DisasContext *ctx, arg_fneg_d *a) | ||
151 | { | ||
152 | + CHECK_FPE; | ||
153 | + | ||
154 | tcg_gen_xori_i64(cpu_fpr[a->fd], cpu_fpr[a->fj], 0x8000000000000000LL); | ||
155 | return true; | ||
156 | } | ||
157 | diff --git a/target/loongarch/insn_trans/trans_fcmp.c.inc b/target/loongarch/insn_trans/trans_fcmp.c.inc | ||
158 | index XXXXXXX..XXXXXXX 100644 | ||
159 | --- a/target/loongarch/insn_trans/trans_fcmp.c.inc | ||
160 | +++ b/target/loongarch/insn_trans/trans_fcmp.c.inc | ||
161 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_fcmp_flags(int cond) | ||
162 | |||
163 | static bool trans_fcmp_cond_s(DisasContext *ctx, arg_fcmp_cond_s *a) | ||
164 | { | ||
165 | - TCGv var = tcg_temp_new(); | ||
166 | + TCGv var; | ||
167 | uint32_t flags; | ||
168 | void (*fn)(TCGv, TCGv_env, TCGv, TCGv, TCGv_i32); | ||
169 | |||
170 | + CHECK_FPE; | ||
171 | + | ||
172 | + var = tcg_temp_new(); | ||
173 | fn = (a->fcond & 1 ? gen_helper_fcmp_s_s : gen_helper_fcmp_c_s); | ||
174 | flags = get_fcmp_flags(a->fcond >> 1); | ||
175 | |||
176 | @@ -XXX,XX +XXX,XX @@ static bool trans_fcmp_cond_s(DisasContext *ctx, arg_fcmp_cond_s *a) | ||
177 | |||
178 | static bool trans_fcmp_cond_d(DisasContext *ctx, arg_fcmp_cond_d *a) | ||
179 | { | ||
180 | - TCGv var = tcg_temp_new(); | ||
181 | + TCGv var; | ||
182 | uint32_t flags; | ||
183 | void (*fn)(TCGv, TCGv_env, TCGv, TCGv, TCGv_i32); | ||
184 | + | ||
185 | + CHECK_FPE; | ||
186 | + | ||
187 | + var = tcg_temp_new(); | ||
188 | fn = (a->fcond & 1 ? gen_helper_fcmp_s_d : gen_helper_fcmp_c_d); | ||
189 | flags = get_fcmp_flags(a->fcond >> 1); | ||
190 | |||
191 | diff --git a/target/loongarch/insn_trans/trans_fmemory.c.inc b/target/loongarch/insn_trans/trans_fmemory.c.inc | ||
192 | index XXXXXXX..XXXXXXX 100644 | ||
193 | --- a/target/loongarch/insn_trans/trans_fmemory.c.inc | ||
194 | +++ b/target/loongarch/insn_trans/trans_fmemory.c.inc | ||
195 | @@ -XXX,XX +XXX,XX @@ static bool gen_fload_i(DisasContext *ctx, arg_fr_i *a, MemOp mop) | ||
196 | TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); | ||
197 | TCGv temp = NULL; | ||
198 | |||
199 | + CHECK_FPE; | ||
200 | + | ||
201 | if (a->imm) { | ||
202 | temp = tcg_temp_new(); | ||
203 | tcg_gen_addi_tl(temp, addr, a->imm); | ||
204 | @@ -XXX,XX +XXX,XX @@ static bool gen_fstore_i(DisasContext *ctx, arg_fr_i *a, MemOp mop) | ||
205 | TCGv addr = gpr_src(ctx, a->rj, EXT_NONE); | ||
206 | TCGv temp = NULL; | ||
207 | |||
208 | + CHECK_FPE; | ||
209 | + | ||
210 | if (a->imm) { | ||
211 | temp = tcg_temp_new(); | ||
212 | tcg_gen_addi_tl(temp, addr, a->imm); | ||
213 | @@ -XXX,XX +XXX,XX @@ static bool gen_floadx(DisasContext *ctx, arg_frr *a, MemOp mop) | ||
214 | { | ||
215 | TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | ||
216 | TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); | ||
217 | - TCGv addr = tcg_temp_new(); | ||
218 | + TCGv addr; | ||
219 | |||
220 | + CHECK_FPE; | ||
221 | + | ||
222 | + addr = tcg_temp_new(); | ||
223 | tcg_gen_add_tl(addr, src1, src2); | ||
224 | tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); | ||
225 | maybe_nanbox_load(cpu_fpr[a->fd], mop); | ||
226 | @@ -XXX,XX +XXX,XX @@ static bool gen_fstorex(DisasContext *ctx, arg_frr *a, MemOp mop) | ||
227 | { | ||
228 | TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | ||
229 | TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); | ||
230 | - TCGv addr = tcg_temp_new(); | ||
231 | + TCGv addr; | ||
232 | + | ||
233 | + CHECK_FPE; | ||
234 | |||
235 | + addr = tcg_temp_new(); | ||
236 | tcg_gen_add_tl(addr, src1, src2); | ||
237 | tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); | ||
238 | tcg_temp_free(addr); | ||
239 | @@ -XXX,XX +XXX,XX @@ static bool gen_fload_gt(DisasContext *ctx, arg_frr *a, MemOp mop) | ||
240 | { | ||
241 | TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | ||
242 | TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); | ||
243 | - TCGv addr = tcg_temp_new(); | ||
244 | + TCGv addr; | ||
245 | |||
246 | + CHECK_FPE; | ||
247 | + | ||
248 | + addr = tcg_temp_new(); | ||
249 | gen_helper_asrtgt_d(cpu_env, src1, src2); | ||
250 | tcg_gen_add_tl(addr, src1, src2); | ||
251 | tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); | ||
252 | @@ -XXX,XX +XXX,XX @@ static bool gen_fstore_gt(DisasContext *ctx, arg_frr *a, MemOp mop) | ||
253 | { | ||
254 | TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | ||
255 | TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); | ||
256 | - TCGv addr = tcg_temp_new(); | ||
257 | + TCGv addr; | ||
258 | + | ||
259 | + CHECK_FPE; | ||
260 | |||
261 | + addr = tcg_temp_new(); | ||
262 | gen_helper_asrtgt_d(cpu_env, src1, src2); | ||
263 | tcg_gen_add_tl(addr, src1, src2); | ||
264 | tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); | ||
265 | @@ -XXX,XX +XXX,XX @@ static bool gen_fload_le(DisasContext *ctx, arg_frr *a, MemOp mop) | ||
266 | { | ||
267 | TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | ||
268 | TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); | ||
269 | - TCGv addr = tcg_temp_new(); | ||
270 | + TCGv addr; | ||
271 | |||
272 | + CHECK_FPE; | ||
273 | + | ||
274 | + addr = tcg_temp_new(); | ||
275 | gen_helper_asrtle_d(cpu_env, src1, src2); | ||
276 | tcg_gen_add_tl(addr, src1, src2); | ||
277 | tcg_gen_qemu_ld_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); | ||
278 | @@ -XXX,XX +XXX,XX @@ static bool gen_fstore_le(DisasContext *ctx, arg_frr *a, MemOp mop) | ||
279 | { | ||
280 | TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | ||
281 | TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE); | ||
282 | - TCGv addr = tcg_temp_new(); | ||
283 | + TCGv addr; | ||
284 | + | ||
285 | + CHECK_FPE; | ||
286 | |||
287 | + addr = tcg_temp_new(); | ||
288 | gen_helper_asrtle_d(cpu_env, src1, src2); | ||
289 | tcg_gen_add_tl(addr, src1, src2); | ||
290 | tcg_gen_qemu_st_tl(cpu_fpr[a->fd], addr, ctx->mem_idx, mop); | ||
291 | diff --git a/target/loongarch/insn_trans/trans_fmov.c.inc b/target/loongarch/insn_trans/trans_fmov.c.inc | ||
292 | index XXXXXXX..XXXXXXX 100644 | ||
293 | --- a/target/loongarch/insn_trans/trans_fmov.c.inc | ||
294 | +++ b/target/loongarch/insn_trans/trans_fmov.c.inc | ||
295 | @@ -XXX,XX +XXX,XX @@ static const uint32_t fcsr_mask[4] = { | ||
296 | static bool trans_fsel(DisasContext *ctx, arg_fsel *a) | ||
297 | { | ||
298 | TCGv zero = tcg_constant_tl(0); | ||
299 | - TCGv cond = tcg_temp_new(); | ||
300 | + TCGv cond; | ||
301 | |||
302 | + CHECK_FPE; | ||
303 | + | ||
304 | + cond = tcg_temp_new(); | ||
305 | tcg_gen_ld8u_tl(cond, cpu_env, offsetof(CPULoongArchState, cf[a->ca])); | ||
306 | tcg_gen_movcond_tl(TCG_COND_EQ, cpu_fpr[a->fd], cond, zero, | ||
307 | cpu_fpr[a->fj], cpu_fpr[a->fk]); | ||
308 | @@ -XXX,XX +XXX,XX @@ static bool gen_f2f(DisasContext *ctx, arg_ff *a, | ||
309 | TCGv dest = cpu_fpr[a->fd]; | ||
310 | TCGv src = cpu_fpr[a->fj]; | ||
311 | |||
312 | + CHECK_FPE; | ||
313 | + | ||
314 | func(dest, src); | ||
315 | if (nanbox) { | ||
316 | gen_nanbox_s(cpu_fpr[a->fd], cpu_fpr[a->fd]); | ||
317 | @@ -XXX,XX +XXX,XX @@ static bool gen_r2f(DisasContext *ctx, arg_fr *a, | ||
318 | { | ||
319 | TCGv src = gpr_src(ctx, a->rj, EXT_NONE); | ||
320 | |||
321 | + CHECK_FPE; | ||
322 | + | ||
323 | func(cpu_fpr[a->fd], src); | ||
324 | return true; | ||
325 | } | ||
326 | @@ -XXX,XX +XXX,XX @@ static bool gen_f2r(DisasContext *ctx, arg_rf *a, | ||
327 | { | ||
328 | TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); | ||
329 | |||
330 | + CHECK_FPE; | ||
331 | + | ||
332 | func(dest, cpu_fpr[a->fj]); | ||
333 | gen_set_gpr(a->rd, dest, EXT_NONE); | ||
334 | |||
335 | @@ -XXX,XX +XXX,XX @@ static bool trans_movgr2fcsr(DisasContext *ctx, arg_movgr2fcsr *a) | ||
336 | uint32_t mask = fcsr_mask[a->fcsrd]; | ||
337 | TCGv Rj = gpr_src(ctx, a->rj, EXT_NONE); | ||
338 | |||
339 | + CHECK_FPE; | ||
340 | + | ||
341 | if (mask == UINT32_MAX) { | ||
342 | tcg_gen_st32_i64(Rj, cpu_env, offsetof(CPULoongArchState, fcsr0)); | ||
343 | } else { | ||
344 | @@ -XXX,XX +XXX,XX @@ static bool trans_movfcsr2gr(DisasContext *ctx, arg_movfcsr2gr *a) | ||
345 | { | ||
346 | TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); | ||
347 | |||
348 | + CHECK_FPE; | ||
349 | + | ||
350 | tcg_gen_ld32u_i64(dest, cpu_env, offsetof(CPULoongArchState, fcsr0)); | ||
351 | tcg_gen_andi_i64(dest, dest, fcsr_mask[a->fcsrs]); | ||
352 | gen_set_gpr(a->rd, dest, EXT_NONE); | ||
353 | @@ -XXX,XX +XXX,XX @@ static void gen_movfrh2gr_s(TCGv dest, TCGv src) | ||
354 | |||
355 | static bool trans_movfr2cf(DisasContext *ctx, arg_movfr2cf *a) | ||
356 | { | ||
357 | - TCGv t0 = tcg_temp_new(); | ||
358 | + TCGv t0; | ||
359 | + | ||
360 | + CHECK_FPE; | ||
361 | |||
362 | + t0 = tcg_temp_new(); | ||
363 | tcg_gen_andi_tl(t0, cpu_fpr[a->fj], 0x1); | ||
364 | tcg_gen_st8_tl(t0, cpu_env, offsetof(CPULoongArchState, cf[a->cd & 0x7])); | ||
365 | tcg_temp_free(t0); | ||
366 | @@ -XXX,XX +XXX,XX @@ static bool trans_movfr2cf(DisasContext *ctx, arg_movfr2cf *a) | ||
367 | |||
368 | static bool trans_movcf2fr(DisasContext *ctx, arg_movcf2fr *a) | ||
369 | { | ||
370 | + CHECK_FPE; | ||
371 | + | ||
372 | tcg_gen_ld8u_tl(cpu_fpr[a->fd], cpu_env, | ||
373 | offsetof(CPULoongArchState, cf[a->cj & 0x7])); | ||
374 | return true; | ||
375 | @@ -XXX,XX +XXX,XX @@ static bool trans_movcf2fr(DisasContext *ctx, arg_movcf2fr *a) | ||
376 | |||
377 | static bool trans_movgr2cf(DisasContext *ctx, arg_movgr2cf *a) | ||
378 | { | ||
379 | - TCGv t0 = tcg_temp_new(); | ||
380 | + TCGv t0; | ||
381 | |||
382 | + CHECK_FPE; | ||
383 | + | ||
384 | + t0 = tcg_temp_new(); | ||
385 | tcg_gen_andi_tl(t0, gpr_src(ctx, a->rj, EXT_NONE), 0x1); | ||
386 | tcg_gen_st8_tl(t0, cpu_env, offsetof(CPULoongArchState, cf[a->cd & 0x7])); | ||
387 | tcg_temp_free(t0); | ||
388 | @@ -XXX,XX +XXX,XX @@ static bool trans_movgr2cf(DisasContext *ctx, arg_movgr2cf *a) | ||
389 | |||
390 | static bool trans_movcf2gr(DisasContext *ctx, arg_movcf2gr *a) | ||
391 | { | ||
392 | + CHECK_FPE; | ||
393 | + | ||
394 | tcg_gen_ld8u_tl(gpr_dst(ctx, a->rd, EXT_NONE), cpu_env, | ||
395 | offsetof(CPULoongArchState, cf[a->cj & 0x7])); | ||
396 | return true; | ||
397 | -- | 198 | -- |
398 | 2.31.1 | 199 | 2.43.5 | diff view generated by jsdifflib |