1 | The following changes since commit 7433709a147706ad7d1956b15669279933d0f82b: | 1 | The following changes since commit ece5f8374d0416a339f0c0a9399faa2c42d4ad6f: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'hw-misc-20250113' of https://github.com/philmd/qemu into staging (2025-01-14 12:46:56 -0500) | 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) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20250116 | 7 | https://gitlab.com/gaosong/qemu.git tags/pull-loongarch-20221104 |
8 | 8 | ||
9 | for you to fetch changes up to bb81f237401b5f89f6bba21d9d4f50e0073372a6: | 9 | for you to fetch changes up to 2419978cb09e11bc53a07d4de5621424d2a6a86d: |
10 | 10 | ||
11 | hw/intc/loongarch_ipi: Use alternative implemation for cpu_by_arch_id (2025-01-15 14:36:19 +0800) | 11 | target/loongarch: Fix emulation of float-point disable exception (2022-11-04 17:10:53 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | pull-loongarch-20250116 queue | 14 | pull-loongarch-20221104 |
15 | |||
16 | v2: | ||
17 | - fix win32/win64 complie error; | ||
18 | - Add Rui Wang' patches. | ||
15 | 19 | ||
16 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
17 | Bibo Mao (7): | 21 | Rui Wang (2): |
18 | hw/intc/loongarch_ipi: Implement realize interface | 22 | target/loongarch: Adjust the layout of hardware flags bit fields |
19 | hw/intc/loongson_ipi: Remove num_cpu from loongson_ipi_common | 23 | target/loongarch: Fix emulation of float-point disable exception |
20 | hw/intc/loongson_ipi: Remove property num_cpu from loongson_ipi_common | ||
21 | hw/intc/loongarch_ipi: Get cpu number from possible_cpu_arch_ids | ||
22 | hw/intc/loongarch_ipi: Remove property num-cpu | ||
23 | hw/intc/loongson_ipi: Add more input parameter for cpu_by_arch_id | ||
24 | hw/intc/loongarch_ipi: Use alternative implemation for cpu_by_arch_id | ||
25 | 24 | ||
26 | Miao Hao (1): | 25 | Song Gao (2): |
27 | target/loongarch: Add page table walker support for debugger usage | 26 | target/loongarch: Add exception subcode |
27 | target/loongarch: Fix raise_mmu_exception() set wrong exception_index | ||
28 | 28 | ||
29 | hw/intc/loongarch_ipi.c | 69 ++++++++++++++++++------- | 29 | Xiaojuan Yang (5): |
30 | hw/intc/loongson_ipi.c | 43 +++++++++++++++- | 30 | hw/intc: Convert the memops to with_attrs in LoongArch extioi |
31 | hw/intc/loongson_ipi_common.c | 41 +++++---------- | 31 | hw/intc: Fix LoongArch extioi coreisr accessing |
32 | hw/loongarch/virt.c | 1 - | 32 | hw/loongarch: Load FDT table into dram memory space |
33 | include/hw/intc/loongarch_ipi.h | 1 + | 33 | hw/loongarch: Improve fdt for LoongArch virt machine |
34 | include/hw/intc/loongson_ipi_common.h | 5 +- | 34 | hw/loongarch: Add TPM device for LoongArch virt machine |
35 | target/loongarch/cpu_helper.c | 94 +++++++++++++++++++++++++++++++++-- | 35 | |
36 | target/loongarch/internals.h | 4 +- | 36 | hw/intc/loongarch_extioi.c | 41 +++++++------ |
37 | target/loongarch/tcg/tlb_helper.c | 4 +- | 37 | hw/intc/trace-events | 3 +- |
38 | 9 files changed, 203 insertions(+), 59 deletions(-) | 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 | With mips64 loongson ipi, num_cpu property is used. With loongarch | 1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
---|---|---|---|
2 | ipi, num_cpu can be acquired from possible_cpu_arch_ids. | ||
3 | 2 | ||
4 | Here remove property num_cpu from loongson_ipi_common, and put it into | 3 | Converting the MemoryRegionOps read/write handlers to |
5 | loongson and loongarch ipi separately. | 4 | with_attrs in LoongArch extioi emulation. |
6 | 5 | ||
7 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 6 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
8 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 7 | 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> | ||
9 | --- | 11 | --- |
10 | hw/intc/loongarch_ipi.c | 6 ++++++ | 12 | hw/intc/loongarch_extioi.c | 31 +++++++++++++++++-------------- |
11 | hw/intc/loongson_ipi.c | 6 ++++++ | 13 | hw/intc/trace-events | 3 +-- |
12 | hw/intc/loongson_ipi_common.c | 6 ------ | 14 | 2 files changed, 18 insertions(+), 16 deletions(-) |
13 | 3 files changed, 12 insertions(+), 6 deletions(-) | ||
14 | 15 | ||
15 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 16 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/intc/loongarch_ipi.c | 18 | --- a/hw/intc/loongarch_extioi.c |
18 | +++ b/hw/intc/loongarch_ipi.c | 19 | +++ b/hw/intc/loongarch_extioi.c |
19 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ static void extioi_setirq(void *opaque, int irq, int level) |
20 | #include "hw/boards.h" | 21 | extioi_update_irq(s, irq, level); |
21 | #include "qapi/error.h" | 22 | } |
22 | #include "hw/intc/loongarch_ipi.h" | 23 | |
23 | +#include "hw/qdev-properties.h" | 24 | -static uint64_t extioi_readw(void *opaque, hwaddr addr, unsigned size) |
24 | #include "target/loongarch/cpu.h" | 25 | +static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data, |
25 | 26 | + unsigned size, MemTxAttrs attrs) | |
26 | static AddressSpace *get_iocsr_as(CPUState *cpu) | 27 | { |
27 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | 28 | LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); |
29 | unsigned long offset = addr & 0xffff; | ||
30 | - uint32_t index, cpu, ret = 0; | ||
31 | + uint32_t index, cpu; | ||
32 | |||
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 | } | ||
68 | |||
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,\ | ||
28 | } | 77 | } |
29 | } | 78 | } |
30 | 79 | ||
31 | +static const Property loongarch_ipi_properties[] = { | 80 | -static void extioi_writew(void *opaque, hwaddr addr, |
32 | + DEFINE_PROP_UINT32("num-cpu", LoongsonIPICommonState, num_cpu, 1), | 81 | - uint64_t val, unsigned size) |
33 | +}; | 82 | +static MemTxResult extioi_writew(void *opaque, hwaddr addr, |
34 | + | 83 | + uint64_t val, unsigned size, |
35 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | 84 | + MemTxAttrs attrs) |
36 | { | 85 | { |
37 | LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass); | 86 | LoongArchExtIOI *s = LOONGARCH_EXTIOI(opaque); |
38 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | 87 | int i, cpu, index, old_data, irq; |
39 | 88 | @@ -XXX,XX +XXX,XX @@ static void extioi_writew(void *opaque, hwaddr addr, | |
40 | device_class_set_parent_realize(dc, loongarch_ipi_realize, | 89 | default: |
41 | &lic->parent_realize); | 90 | break; |
42 | + device_class_set_props(dc, loongarch_ipi_properties); | 91 | } |
43 | licc->get_iocsr_as = get_iocsr_as; | 92 | + return MEMTX_OK; |
44 | licc->cpu_by_arch_id = loongarch_cpu_by_arch_id; | ||
45 | } | 93 | } |
46 | diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c | 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 | ||
47 | index XXXXXXX..XXXXXXX 100644 | 104 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/hw/intc/loongson_ipi.c | 105 | --- a/hw/intc/trace-events |
49 | +++ b/hw/intc/loongson_ipi.c | 106 | +++ b/hw/intc/trace-events |
50 | @@ -XXX,XX +XXX,XX @@ | 107 | @@ -XXX,XX +XXX,XX @@ loongarch_msi_set_irq(int irq_num) "set msi irq %d" |
51 | 108 | ||
52 | #include "qemu/osdep.h" | 109 | # loongarch_extioi.c |
53 | #include "hw/intc/loongson_ipi.h" | 110 | loongarch_extioi_setirq(int irq, int level) "set extirq irq %d level %d" |
54 | +#include "hw/qdev-properties.h" | 111 | -loongarch_extioi_readw(uint64_t addr, uint32_t val) "addr: 0x%"PRIx64 "val: 0x%x" |
55 | #include "qapi/error.h" | 112 | +loongarch_extioi_readw(uint64_t addr, uint64_t val) "addr: 0x%"PRIx64 "val: 0x%" PRIx64 |
56 | #include "target/mips/cpu.h" | 113 | loongarch_extioi_writew(uint64_t addr, uint64_t val) "addr: 0x%"PRIx64 "val: 0x%" PRIx64 |
57 | |||
58 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_unrealize(DeviceState *dev) | ||
59 | k->parent_unrealize(dev); | ||
60 | } | ||
61 | |||
62 | +static const Property loongson_ipi_properties[] = { | ||
63 | + DEFINE_PROP_UINT32("num-cpu", LoongsonIPICommonState, num_cpu, 1), | ||
64 | +}; | ||
65 | + | ||
66 | static void loongson_ipi_class_init(ObjectClass *klass, void *data) | ||
67 | { | ||
68 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
69 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_class_init(ObjectClass *klass, void *data) | ||
70 | &lic->parent_realize); | ||
71 | device_class_set_parent_unrealize(dc, loongson_ipi_unrealize, | ||
72 | &lic->parent_unrealize); | ||
73 | + device_class_set_props(dc, loongson_ipi_properties); | ||
74 | licc->get_iocsr_as = get_iocsr_as; | ||
75 | licc->cpu_by_arch_id = cpu_by_arch_id; | ||
76 | } | ||
77 | diff --git a/hw/intc/loongson_ipi_common.c b/hw/intc/loongson_ipi_common.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/hw/intc/loongson_ipi_common.c | ||
80 | +++ b/hw/intc/loongson_ipi_common.c | ||
81 | @@ -XXX,XX +XXX,XX @@ | ||
82 | #include "hw/sysbus.h" | ||
83 | #include "hw/intc/loongson_ipi_common.h" | ||
84 | #include "hw/irq.h" | ||
85 | -#include "hw/qdev-properties.h" | ||
86 | #include "qemu/log.h" | ||
87 | #include "migration/vmstate.h" | ||
88 | #include "trace.h" | ||
89 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongson_ipi_common = { | ||
90 | } | ||
91 | }; | ||
92 | |||
93 | -static const Property ipi_common_properties[] = { | ||
94 | - DEFINE_PROP_UINT32("num-cpu", LoongsonIPICommonState, num_cpu, 1), | ||
95 | -}; | ||
96 | - | 114 | - |
97 | static void loongson_ipi_common_class_init(ObjectClass *klass, void *data) | ||
98 | { | ||
99 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
100 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_common_class_init(ObjectClass *klass, void *data) | ||
101 | &licc->parent_realize); | ||
102 | device_class_set_parent_unrealize(dc, loongson_ipi_common_unrealize, | ||
103 | &licc->parent_unrealize); | ||
104 | - device_class_set_props(dc, ipi_common_properties); | ||
105 | dc->vmsd = &vmstate_loongson_ipi_common; | ||
106 | } | ||
107 | |||
108 | -- | 115 | -- |
109 | 2.43.5 | 116 | 2.31.1 |
117 | |||
118 | diff view generated by jsdifflib |
1 | Add logic cpu index input parameter for function cpu_by_arch_id, | 1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
---|---|---|---|
2 | CPUState::cpu_index is logic cpu slot index for possible_cpus. | ||
3 | 2 | ||
4 | At the same time it is logic index with LoongsonIPICommonState::IPICore, | 3 | 1. When cpu read or write extioi COREISR reg, it should access |
5 | here hide access for CPUState::cpu_index directly, it comes from | 4 | the reg belonged to itself, so the cpu index of 's->coreisr' |
6 | function cpu_by_arch_id(). | 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. | ||
7 | 8 | ||
8 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 9 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
9 | Reviewed-by: Bibo Mao <maobibo@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> | ||
10 | --- | 13 | --- |
11 | hw/intc/loongarch_ipi.c | 19 +++++++++++++++---- | 14 | hw/intc/loongarch_extioi.c | 10 ++++++---- |
12 | hw/intc/loongson_ipi.c | 23 ++++++++++++++++++++++- | 15 | target/loongarch/iocsr_helper.c | 19 +++++++++++-------- |
13 | hw/intc/loongson_ipi_common.c | 21 ++++++++++++--------- | 16 | 2 files changed, 17 insertions(+), 12 deletions(-) |
14 | include/hw/intc/loongson_ipi_common.h | 3 ++- | ||
15 | 4 files changed, 51 insertions(+), 15 deletions(-) | ||
16 | 17 | ||
17 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 18 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c |
18 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/intc/loongarch_ipi.c | 20 | --- a/hw/intc/loongarch_extioi.c |
20 | +++ b/hw/intc/loongarch_ipi.c | 21 | +++ b/hw/intc/loongarch_extioi.c |
21 | @@ -XXX,XX +XXX,XX @@ static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id) | 22 | @@ -XXX,XX +XXX,XX @@ static MemTxResult extioi_readw(void *opaque, hwaddr addr, uint64_t *data, |
22 | return found_cpu; | 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); | ||
23 | } | 62 | } |
24 | 63 | ||
25 | -static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id) | 64 | uint64_t helper_iocsrrd_h(CPULoongArchState *env, target_ulong r_addr) |
26 | +static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics, | ||
27 | + int64_t arch_id, int *index, CPUState **pcs) | ||
28 | { | 65 | { |
29 | MachineState *machine = MACHINE(qdev_get_machine()); | 66 | return address_space_lduw(&env->address_space_iocsr, r_addr, |
30 | CPUArchId *archid; | 67 | - MEMTXATTRS_UNSPECIFIED, NULL); |
31 | + CPUState *cs; | 68 | + GET_MEMTXATTRS(env), NULL); |
32 | |||
33 | archid = find_cpu_by_archid(machine, arch_id); | ||
34 | - if (archid) { | ||
35 | - return CPU(archid->cpu); | ||
36 | + if (archid && archid->cpu) { | ||
37 | + cs = archid->cpu; | ||
38 | + if (index) { | ||
39 | + *index = cs->cpu_index; | ||
40 | + } | ||
41 | + | ||
42 | + if (pcs) { | ||
43 | + *pcs = cs; | ||
44 | + } | ||
45 | + | ||
46 | + return MEMTX_OK; | ||
47 | } | ||
48 | |||
49 | - return NULL; | ||
50 | + return MEMTX_ERROR; | ||
51 | } | 69 | } |
52 | 70 | ||
53 | static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | 71 | uint64_t helper_iocsrrd_w(CPULoongArchState *env, target_ulong r_addr) |
54 | diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c | 72 | { |
55 | index XXXXXXX..XXXXXXX 100644 | 73 | return address_space_ldl(&env->address_space_iocsr, r_addr, |
56 | --- a/hw/intc/loongson_ipi.c | 74 | - MEMTXATTRS_UNSPECIFIED, NULL); |
57 | +++ b/hw/intc/loongson_ipi.c | 75 | + GET_MEMTXATTRS(env), NULL); |
58 | @@ -XXX,XX +XXX,XX @@ static AddressSpace *get_iocsr_as(CPUState *cpu) | ||
59 | return NULL; | ||
60 | } | 76 | } |
61 | 77 | ||
62 | +static int loongson_cpu_by_arch_id(LoongsonIPICommonState *lics, | 78 | uint64_t helper_iocsrrd_d(CPULoongArchState *env, target_ulong r_addr) |
63 | + int64_t arch_id, int *index, CPUState **pcs) | 79 | { |
64 | +{ | 80 | return address_space_ldq(&env->address_space_iocsr, r_addr, |
65 | + CPUState *cs; | 81 | - MEMTXATTRS_UNSPECIFIED, NULL); |
66 | + | 82 | + GET_MEMTXATTRS(env), NULL); |
67 | + cs = cpu_by_arch_id(arch_id); | ||
68 | + if (cs == NULL) { | ||
69 | + return MEMTX_ERROR; | ||
70 | + } | ||
71 | + | ||
72 | + if (index) { | ||
73 | + *index = cs->cpu_index; | ||
74 | + } | ||
75 | + | ||
76 | + if (pcs) { | ||
77 | + *pcs = cs; | ||
78 | + } | ||
79 | + | ||
80 | + return MEMTX_OK; | ||
81 | +} | ||
82 | + | ||
83 | static const MemoryRegionOps loongson_ipi_core_ops = { | ||
84 | .read_with_attrs = loongson_ipi_core_readl, | ||
85 | .write_with_attrs = loongson_ipi_core_writel, | ||
86 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_class_init(ObjectClass *klass, void *data) | ||
87 | &lic->parent_unrealize); | ||
88 | device_class_set_props(dc, loongson_ipi_properties); | ||
89 | licc->get_iocsr_as = get_iocsr_as; | ||
90 | - licc->cpu_by_arch_id = cpu_by_arch_id; | ||
91 | + licc->cpu_by_arch_id = loongson_cpu_by_arch_id; | ||
92 | } | 83 | } |
93 | 84 | ||
94 | static const TypeInfo loongson_ipi_types[] = { | 85 | void helper_iocsrwr_b(CPULoongArchState *env, target_ulong w_addr, |
95 | diff --git a/hw/intc/loongson_ipi_common.c b/hw/intc/loongson_ipi_common.c | 86 | target_ulong val) |
96 | index XXXXXXX..XXXXXXX 100644 | 87 | { |
97 | --- a/hw/intc/loongson_ipi_common.c | 88 | address_space_stb(&env->address_space_iocsr, w_addr, |
98 | +++ b/hw/intc/loongson_ipi_common.c | 89 | - val, MEMTXATTRS_UNSPECIFIED, NULL); |
99 | @@ -XXX,XX +XXX,XX @@ static MemTxResult mail_send(LoongsonIPICommonState *ipi, | 90 | + val, GET_MEMTXATTRS(env), NULL); |
100 | uint32_t cpuid; | ||
101 | hwaddr addr; | ||
102 | CPUState *cs; | ||
103 | + int cpu, ret; | ||
104 | |||
105 | cpuid = extract32(val, 16, 10); | ||
106 | - cs = licc->cpu_by_arch_id(cpuid); | ||
107 | - if (cs == NULL) { | ||
108 | + ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs); | ||
109 | + if (ret != MEMTX_OK) { | ||
110 | return MEMTX_DECODE_ERROR; | ||
111 | } | ||
112 | |||
113 | /* override requester_id */ | ||
114 | addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c); | ||
115 | - attrs.requester_id = cs->cpu_index; | ||
116 | + attrs.requester_id = cpu; | ||
117 | return send_ipi_data(ipi, cs, val, addr, attrs); | ||
118 | } | 91 | } |
119 | 92 | ||
120 | @@ -XXX,XX +XXX,XX @@ static MemTxResult any_send(LoongsonIPICommonState *ipi, | 93 | void helper_iocsrwr_h(CPULoongArchState *env, target_ulong w_addr, |
121 | uint32_t cpuid; | 94 | target_ulong val) |
122 | hwaddr addr; | 95 | { |
123 | CPUState *cs; | 96 | address_space_stw(&env->address_space_iocsr, w_addr, |
124 | + int cpu, ret; | 97 | - val, MEMTXATTRS_UNSPECIFIED, NULL); |
125 | 98 | + val, GET_MEMTXATTRS(env), NULL); | |
126 | cpuid = extract32(val, 16, 10); | ||
127 | - cs = licc->cpu_by_arch_id(cpuid); | ||
128 | - if (cs == NULL) { | ||
129 | + ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs); | ||
130 | + if (ret != MEMTX_OK) { | ||
131 | return MEMTX_DECODE_ERROR; | ||
132 | } | ||
133 | |||
134 | /* override requester_id */ | ||
135 | addr = val & 0xffff; | ||
136 | - attrs.requester_id = cs->cpu_index; | ||
137 | + attrs.requester_id = cpu; | ||
138 | return send_ipi_data(ipi, cs, val, addr, attrs); | ||
139 | } | 99 | } |
140 | 100 | ||
141 | @@ -XXX,XX +XXX,XX @@ MemTxResult loongson_ipi_core_writel(void *opaque, hwaddr addr, uint64_t val, | 101 | void helper_iocsrwr_w(CPULoongArchState *env, target_ulong w_addr, |
142 | uint32_t cpuid; | 102 | target_ulong val) |
143 | uint8_t vector; | 103 | { |
144 | CPUState *cs; | 104 | address_space_stl(&env->address_space_iocsr, w_addr, |
145 | + int cpu, ret; | 105 | - val, MEMTXATTRS_UNSPECIFIED, NULL); |
146 | 106 | + val, GET_MEMTXATTRS(env), NULL); | |
147 | addr &= 0xff; | 107 | } |
148 | trace_loongson_ipi_write(size, (uint64_t)addr, val); | 108 | |
149 | @@ -XXX,XX +XXX,XX @@ MemTxResult loongson_ipi_core_writel(void *opaque, hwaddr addr, uint64_t val, | 109 | void helper_iocsrwr_d(CPULoongArchState *env, target_ulong w_addr, |
150 | cpuid = extract32(val, 16, 10); | 110 | target_ulong val) |
151 | /* IPI status vector */ | 111 | { |
152 | vector = extract8(val, 0, 5); | 112 | address_space_stq(&env->address_space_iocsr, w_addr, |
153 | - cs = licc->cpu_by_arch_id(cpuid); | 113 | - val, MEMTXATTRS_UNSPECIFIED, NULL); |
154 | - if (cs == NULL || cs->cpu_index >= ipi->num_cpu) { | 114 | + val, GET_MEMTXATTRS(env), NULL); |
155 | + ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs); | 115 | } |
156 | + if (ret != MEMTX_OK || cpu >= ipi->num_cpu) { | ||
157 | return MEMTX_DECODE_ERROR; | ||
158 | } | ||
159 | - loongson_ipi_core_writel(&ipi->cpu[cs->cpu_index], CORE_SET_OFF, | ||
160 | + loongson_ipi_core_writel(&ipi->cpu[cpu], CORE_SET_OFF, | ||
161 | BIT(vector), 4, attrs); | ||
162 | break; | ||
163 | default: | ||
164 | diff --git a/include/hw/intc/loongson_ipi_common.h b/include/hw/intc/loongson_ipi_common.h | ||
165 | index XXXXXXX..XXXXXXX 100644 | ||
166 | --- a/include/hw/intc/loongson_ipi_common.h | ||
167 | +++ b/include/hw/intc/loongson_ipi_common.h | ||
168 | @@ -XXX,XX +XXX,XX @@ struct LoongsonIPICommonClass { | ||
169 | DeviceRealize parent_realize; | ||
170 | DeviceUnrealize parent_unrealize; | ||
171 | AddressSpace *(*get_iocsr_as)(CPUState *cpu); | ||
172 | - CPUState *(*cpu_by_arch_id)(int64_t id); | ||
173 | + int (*cpu_by_arch_id)(LoongsonIPICommonState *lics, int64_t id, | ||
174 | + int *index, CPUState **pcs); | ||
175 | }; | ||
176 | |||
177 | MemTxResult loongson_ipi_core_readl(void *opaque, hwaddr addr, uint64_t *data, | ||
178 | -- | 116 | -- |
179 | 2.43.5 | 117 | 2.31.1 | diff view generated by jsdifflib |
1 | Since cpu number can be acquired from possible_cpu_arch_ids(), | 1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
---|---|---|---|
2 | num-cpu property is not necessary. Here remove num-cpu property | ||
3 | for object TYPE_LOONGARCH_IPI object. | ||
4 | 2 | ||
5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 3 | Load FDT table into dram memory space, and the addr is 2 MiB. |
6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 4 | Since lowmem region starts from 0, FDT base address is located |
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> | ||
7 | --- | 11 | --- |
8 | hw/intc/loongarch_ipi.c | 5 ----- | 12 | hw/loongarch/virt.c | 18 +++++++++++------- |
9 | hw/loongarch/virt.c | 1 - | 13 | include/hw/loongarch/virt.h | 3 --- |
10 | 2 files changed, 6 deletions(-) | 14 | 2 files changed, 11 insertions(+), 10 deletions(-) |
11 | 15 | ||
12 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/intc/loongarch_ipi.c | ||
15 | +++ b/hw/intc/loongarch_ipi.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
17 | } | ||
18 | } | ||
19 | |||
20 | -static const Property loongarch_ipi_properties[] = { | ||
21 | - DEFINE_PROP_UINT32("num-cpu", LoongsonIPICommonState, num_cpu, 1), | ||
22 | -}; | ||
23 | - | ||
24 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
25 | { | ||
26 | LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass); | ||
27 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
28 | |||
29 | device_class_set_parent_realize(dc, loongarch_ipi_realize, | ||
30 | &lic->parent_realize); | ||
31 | - device_class_set_props(dc, loongarch_ipi_properties); | ||
32 | licc->get_iocsr_as = get_iocsr_as; | ||
33 | licc->cpu_by_arch_id = loongarch_cpu_by_arch_id; | ||
34 | } | ||
35 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 16 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c |
36 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/hw/loongarch/virt.c | 18 | --- a/hw/loongarch/virt.c |
38 | +++ b/hw/loongarch/virt.c | 19 | +++ b/hw/loongarch/virt.c |
39 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) | 20 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams) |
40 | 21 | 1, FDT_PCI_RANGE_MMIO, 2, base_mmio, | |
41 | /* Create IPI device */ | 22 | 2, base_mmio, 2, size_mmio); |
42 | ipi = qdev_new(TYPE_LOONGARCH_IPI); | 23 | g_free(nodename); |
43 | - qdev_prop_set_uint32(ipi, "num-cpu", ms->smp.cpus); | 24 | - qemu_fdt_dumpdtb(ms->fdt, lams->fdt_size); |
44 | sysbus_realize_and_unref(SYS_BUS_DEVICE(ipi), &error_fatal); | 25 | } |
45 | 26 | ||
46 | /* IPI iocsr memory region */ | 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; | ||
47 | -- | 73 | -- |
48 | 2.43.5 | 74 | 2.31.1 | diff view generated by jsdifflib |
1 | Add realize interface for loongarch ipi device. | 1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 3 | Add new items into LoongArch FDT, including rtc and uart info. |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 4 | |
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> | ||
5 | --- | 9 | --- |
6 | hw/intc/loongarch_ipi.c | 19 +++++++++++++++++++ | 10 | hw/loongarch/virt.c | 31 +++++++++++++++++++++++++++++++ |
7 | include/hw/intc/loongarch_ipi.h | 1 + | 11 | include/hw/pci-host/ls7a.h | 1 + |
8 | 2 files changed, 20 insertions(+) | 12 | 2 files changed, 32 insertions(+) |
9 | 13 | ||
10 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 14 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c |
11 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/hw/intc/loongarch_ipi.c | 16 | --- a/hw/loongarch/virt.c |
13 | +++ b/hw/intc/loongarch_ipi.c | 17 | +++ b/hw/loongarch/virt.c |
14 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ |
15 | 19 | #include "hw/display/ramfb.h" | |
16 | #include "qemu/osdep.h" | 20 | #include "hw/mem/pc-dimm.h" |
17 | #include "hw/boards.h" | 21 | |
18 | +#include "qapi/error.h" | 22 | +static void fdt_add_rtc_node(LoongArchMachineState *lams) |
19 | #include "hw/intc/loongarch_ipi.h" | ||
20 | #include "target/loongarch/cpu.h" | ||
21 | |||
22 | @@ -XXX,XX +XXX,XX @@ static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id) | ||
23 | return NULL; | ||
24 | } | ||
25 | |||
26 | +static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
27 | +{ | 23 | +{ |
28 | + LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev); | 24 | + char *nodename; |
29 | + Error *local_err = NULL; | 25 | + hwaddr base = VIRT_RTC_REG_BASE; |
26 | + hwaddr size = VIRT_RTC_LEN; | ||
27 | + MachineState *ms = MACHINE(lams); | ||
30 | + | 28 | + |
31 | + lic->parent_realize(dev, &local_err); | 29 | + nodename = g_strdup_printf("/rtc@%" PRIx64, base); |
32 | + if (local_err) { | 30 | + qemu_fdt_add_subnode(ms->fdt, nodename); |
33 | + error_propagate(errp, local_err); | 31 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "loongson,ls7a-rtc"); |
34 | + return; | 32 | + qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 0x0, base, size); |
35 | + } | 33 | + g_free(nodename); |
36 | +} | 34 | +} |
37 | + | 35 | + |
38 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | 36 | +static void fdt_add_uart_node(LoongArchMachineState *lams) |
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) | ||
39 | { | 52 | { |
40 | LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass); | 53 | MachineState *ms = MACHINE(lams); |
41 | + LoongarchIPIClass *lic = LOONGARCH_IPI_CLASS(klass); | 54 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState * |
42 | + DeviceClass *dc = DEVICE_CLASS(klass); | 55 | qdev_get_gpio_in(pch_pic, |
43 | 56 | VIRT_UART_IRQ - PCH_PIC_IRQ_OFFSET), | |
44 | + device_class_set_parent_realize(dc, loongarch_ipi_realize, | 57 | 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN); |
45 | + &lic->parent_realize); | 58 | + fdt_add_uart_node(lams); |
46 | licc->get_iocsr_as = get_iocsr_as; | 59 | |
47 | licc->cpu_by_arch_id = loongarch_cpu_by_arch_id; | 60 | /* Network init */ |
48 | } | 61 | for (i = 0; i < nb_nics; i++) { |
49 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo loongarch_ipi_types[] = { | 62 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState * |
50 | { | 63 | sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE, |
51 | .name = TYPE_LOONGARCH_IPI, | 64 | qdev_get_gpio_in(pch_pic, |
52 | .parent = TYPE_LOONGSON_IPI_COMMON, | 65 | VIRT_RTC_IRQ - PCH_PIC_IRQ_OFFSET)); |
53 | + .instance_size = sizeof(LoongarchIPIState), | 66 | + fdt_add_rtc_node(lams); |
54 | + .class_size = sizeof(LoongarchIPIClass), | 67 | |
55 | .class_init = loongarch_ipi_class_init, | 68 | pm_mem = g_new(MemoryRegion, 1); |
56 | } | 69 | memory_region_init_io(pm_mem, NULL, &loongarch_virt_pm_ops, |
57 | }; | 70 | diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h |
58 | diff --git a/include/hw/intc/loongarch_ipi.h b/include/hw/intc/loongarch_ipi.h | ||
59 | index XXXXXXX..XXXXXXX 100644 | 71 | index XXXXXXX..XXXXXXX 100644 |
60 | --- a/include/hw/intc/loongarch_ipi.h | 72 | --- a/include/hw/pci-host/ls7a.h |
61 | +++ b/include/hw/intc/loongarch_ipi.h | 73 | +++ b/include/hw/pci-host/ls7a.h |
62 | @@ -XXX,XX +XXX,XX @@ struct LoongarchIPIState { | 74 | @@ -XXX,XX +XXX,XX @@ |
63 | 75 | #define VIRT_PCI_IRQS 48 | |
64 | struct LoongarchIPIClass { | 76 | #define VIRT_UART_IRQ (PCH_PIC_IRQ_OFFSET + 2) |
65 | LoongsonIPICommonClass parent_class; | 77 | #define VIRT_UART_BASE 0x1fe001e0 |
66 | + DeviceRealize parent_realize; | 78 | +#define VIRT_UART_SIZE 0X100 |
67 | }; | 79 | #define VIRT_RTC_IRQ (PCH_PIC_IRQ_OFFSET + 3) |
68 | 80 | #define VIRT_MISC_REG_BASE (VIRT_PCH_REG_BASE + 0x00080000) | |
69 | #endif | 81 | #define VIRT_RTC_REG_BASE (VIRT_MISC_REG_BASE + 0x00050100) |
70 | -- | 82 | -- |
71 | 2.43.5 | 83 | 2.31.1 | diff view generated by jsdifflib |
1 | With mips64 loongson ipi, num_cpu property is used. With loongarch | 1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
---|---|---|---|
2 | ipi, num_cpu can be acquired from possible_cpu_arch_ids. | ||
3 | 2 | ||
4 | Here remove num_cpu setting from loongson_ipi_common, and this piece | 3 | Add TPM device for LoongArch virt machine, including |
5 | of code is put into loongson and loongarch ipi separately. | 4 | establish TPM acpi info and add TYPE_TPM_TIS_SYSBUS |
5 | to dynamic_sysbus_devices list. | ||
6 | 6 | ||
7 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 7 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> |
8 | Reviewed-by: Bibo Mao <maobibo@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> | ||
9 | --- | 11 | --- |
10 | hw/intc/loongarch_ipi.c | 13 +++++++++++++ | 12 | hw/loongarch/acpi-build.c | 51 ++++++++++++++++++++++++++++++++++++++- |
11 | hw/intc/loongson_ipi.c | 14 +++++++++++++- | 13 | hw/loongarch/virt.c | 4 +++ |
12 | hw/intc/loongson_ipi_common.c | 14 -------------- | 14 | 2 files changed, 54 insertions(+), 1 deletion(-) |
13 | 3 files changed, 26 insertions(+), 15 deletions(-) | ||
14 | 15 | ||
15 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 16 | diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/intc/loongarch_ipi.c | 18 | --- a/hw/loongarch/acpi-build.c |
18 | +++ b/hw/intc/loongarch_ipi.c | 19 | +++ b/hw/loongarch/acpi-build.c |
19 | @@ -XXX,XX +XXX,XX @@ static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id) | 20 | @@ -XXX,XX +XXX,XX @@ |
20 | 21 | ||
21 | static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | 22 | #include "hw/acpi/generic_event_device.h" |
22 | { | 23 | #include "hw/pci-host/gpex.h" |
23 | + LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(dev); | 24 | +#include "sysemu/tpm.h" |
24 | LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev); | 25 | +#include "hw/platform-bus.h" |
25 | Error *local_err = NULL; | 26 | +#include "hw/acpi/aml-build.h" |
26 | + int i; | 27 | |
27 | 28 | #define ACPI_BUILD_ALIGN_SIZE 0x1000 | |
28 | lic->parent_realize(dev, &local_err); | 29 | #define ACPI_BUILD_TABLE_SIZE 0x20000 |
29 | if (local_err) { | 30 | @@ -XXX,XX +XXX,XX @@ static void build_pci_device_aml(Aml *scope, LoongArchMachineState *lams) |
30 | error_propagate(errp, local_err); | 31 | acpi_dsdt_add_gpex(scope, &cfg); |
31 | return; | 32 | } |
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; | ||
33 | + | 42 | + |
34 | + if (lics->num_cpu == 0) { | 43 | + if (!sbdev) { |
35 | + error_setg(errp, "num-cpu must be at least 1"); | ||
36 | + return; | 44 | + return; |
37 | + } | 45 | + } |
38 | + | 46 | + |
39 | + lics->cpu = g_new0(IPICore, lics->num_cpu); | 47 | + tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0); |
40 | + for (i = 0; i < lics->num_cpu; i++) { | 48 | + assert(tpm_base != -1); |
41 | + lics->cpu[i].ipi = lics; | 49 | + |
42 | + qdev_init_gpio_out(dev, &lics->cpu[i].irq, 1); | 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); | ||
43 | + } | 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 | ||
44 | } | 118 | } |
45 | 119 | ||
46 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | 120 | static const TypeInfo loongarch_machine_types[] = { |
47 | diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/intc/loongson_ipi.c | ||
50 | +++ b/hw/intc/loongson_ipi.c | ||
51 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_realize(DeviceState *dev, Error **errp) | ||
52 | LoongsonIPIClass *lic = LOONGSON_IPI_GET_CLASS(dev); | ||
53 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
54 | Error *local_err = NULL; | ||
55 | + int i; | ||
56 | |||
57 | lic->parent_realize(dev, &local_err); | ||
58 | if (local_err) { | ||
59 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_realize(DeviceState *dev, Error **errp) | ||
60 | return; | ||
61 | } | ||
62 | |||
63 | + if (sc->num_cpu == 0) { | ||
64 | + error_setg(errp, "num-cpu must be at least 1"); | ||
65 | + return; | ||
66 | + } | ||
67 | + | ||
68 | + sc->cpu = g_new0(IPICore, sc->num_cpu); | ||
69 | + for (i = 0; i < sc->num_cpu; i++) { | ||
70 | + sc->cpu[i].ipi = sc; | ||
71 | + qdev_init_gpio_out(dev, &sc->cpu[i].irq, 1); | ||
72 | + } | ||
73 | + | ||
74 | s->ipi_mmio_mem = g_new0(MemoryRegion, sc->num_cpu); | ||
75 | - for (unsigned i = 0; i < sc->num_cpu; i++) { | ||
76 | + for (i = 0; i < sc->num_cpu; i++) { | ||
77 | g_autofree char *name = g_strdup_printf("loongson_ipi_cpu%d_mmio", i); | ||
78 | |||
79 | memory_region_init_io(&s->ipi_mmio_mem[i], OBJECT(dev), | ||
80 | diff --git a/hw/intc/loongson_ipi_common.c b/hw/intc/loongson_ipi_common.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/hw/intc/loongson_ipi_common.c | ||
83 | +++ b/hw/intc/loongson_ipi_common.c | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | #include "hw/intc/loongson_ipi_common.h" | ||
86 | #include "hw/irq.h" | ||
87 | #include "hw/qdev-properties.h" | ||
88 | -#include "qapi/error.h" | ||
89 | #include "qemu/log.h" | ||
90 | #include "migration/vmstate.h" | ||
91 | #include "trace.h" | ||
92 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_common_realize(DeviceState *dev, Error **errp) | ||
93 | { | ||
94 | LoongsonIPICommonState *s = LOONGSON_IPI_COMMON(dev); | ||
95 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
96 | - int i; | ||
97 | - | ||
98 | - if (s->num_cpu == 0) { | ||
99 | - error_setg(errp, "num-cpu must be at least 1"); | ||
100 | - return; | ||
101 | - } | ||
102 | |||
103 | memory_region_init_io(&s->ipi_iocsr_mem, OBJECT(dev), | ||
104 | &loongson_ipi_iocsr_ops, | ||
105 | @@ -XXX,XX +XXX,XX @@ static void loongson_ipi_common_realize(DeviceState *dev, Error **errp) | ||
106 | &loongson_ipi64_ops, | ||
107 | s, "loongson_ipi64_iocsr", 0x118); | ||
108 | sysbus_init_mmio(sbd, &s->ipi64_iocsr_mem); | ||
109 | - | ||
110 | - s->cpu = g_new0(IPICore, s->num_cpu); | ||
111 | - for (i = 0; i < s->num_cpu; i++) { | ||
112 | - s->cpu[i].ipi = s; | ||
113 | - | ||
114 | - qdev_init_gpio_out(dev, &s->cpu[i].irq, 1); | ||
115 | - } | ||
116 | } | ||
117 | |||
118 | static void loongson_ipi_common_unrealize(DeviceState *dev) | ||
119 | -- | 121 | -- |
120 | 2.43.5 | 122 | 2.31.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We need subcodes to distinguish the same excode cs->exception_indexs, | ||
2 | such as EXCCODE_ADEF/EXCCODE_ADEM. | ||
1 | 3 | ||
4 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-ID: <20221101073210.3934280-1-gaosong@loongson.cn> | ||
7 | --- | ||
8 | target/loongarch/cpu.c | 7 +++-- | ||
9 | target/loongarch/cpu.h | 58 ++++++++++++++++++++++-------------------- | ||
10 | 2 files changed, 36 insertions(+), 29 deletions(-) | ||
11 | |||
12 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/loongarch/cpu.c | ||
15 | +++ b/target/loongarch/cpu.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) | ||
17 | env->CSR_TLBRERA = FIELD_DP64(env->CSR_TLBRERA, CSR_TLBRERA, | ||
18 | PC, (env->pc >> 2)); | ||
19 | } else { | ||
20 | - env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ECODE, cause); | ||
21 | + env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ECODE, | ||
22 | + EXCODE_MCODE(cause)); | ||
23 | + env->CSR_ESTAT = FIELD_DP64(env->CSR_ESTAT, CSR_ESTAT, ESUBCODE, | ||
24 | + EXCODE_SUBCODE(cause)); | ||
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 | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/loongarch/cpu.h | ||
40 | +++ b/target/loongarch/cpu.h | ||
41 | @@ -XXX,XX +XXX,XX @@ FIELD(FCSR0, CAUSE, 24, 5) | ||
42 | #define FP_DIV0 8 | ||
43 | #define FP_INVALID 16 | ||
44 | |||
45 | -#define EXCCODE_EXTERNAL_INT 64 /* plus external interrupt number */ | ||
46 | -#define EXCCODE_INT 0 | ||
47 | -#define EXCCODE_PIL 1 | ||
48 | -#define EXCCODE_PIS 2 | ||
49 | -#define EXCCODE_PIF 3 | ||
50 | -#define EXCCODE_PME 4 | ||
51 | -#define EXCCODE_PNR 5 | ||
52 | -#define EXCCODE_PNX 6 | ||
53 | -#define EXCCODE_PPI 7 | ||
54 | -#define EXCCODE_ADEF 8 /* Different exception subcode */ | ||
55 | -#define EXCCODE_ADEM 8 | ||
56 | -#define EXCCODE_ALE 9 | ||
57 | -#define EXCCODE_BCE 10 | ||
58 | -#define EXCCODE_SYS 11 | ||
59 | -#define EXCCODE_BRK 12 | ||
60 | -#define EXCCODE_INE 13 | ||
61 | -#define EXCCODE_IPE 14 | ||
62 | -#define EXCCODE_FPD 15 | ||
63 | -#define EXCCODE_SXD 16 | ||
64 | -#define EXCCODE_ASXD 17 | ||
65 | -#define EXCCODE_FPE 18 /* Different exception subcode */ | ||
66 | -#define EXCCODE_VFPE 18 | ||
67 | -#define EXCCODE_WPEF 19 /* Different exception subcode */ | ||
68 | -#define EXCCODE_WPEM 19 | ||
69 | -#define EXCCODE_BTD 20 | ||
70 | -#define EXCCODE_BTE 21 | ||
71 | -#define EXCCODE_DBP 26 /* Reserved subcode used for debug */ | ||
72 | +#define EXCODE(code, subcode) ( ((subcode) << 6) | (code) ) | ||
73 | +#define EXCODE_MCODE(code) ( (code) & 0x3f ) | ||
74 | +#define EXCODE_SUBCODE(code) ( (code) >> 6 ) | ||
75 | + | ||
76 | +#define EXCCODE_EXTERNAL_INT 64 /* plus external interrupt number */ | ||
77 | +#define EXCCODE_INT EXCODE(0, 0) | ||
78 | +#define EXCCODE_PIL EXCODE(1, 0) | ||
79 | +#define EXCCODE_PIS EXCODE(2, 0) | ||
80 | +#define EXCCODE_PIF EXCODE(3, 0) | ||
81 | +#define EXCCODE_PME EXCODE(4, 0) | ||
82 | +#define EXCCODE_PNR EXCODE(5, 0) | ||
83 | +#define EXCCODE_PNX EXCODE(6, 0) | ||
84 | +#define EXCCODE_PPI EXCODE(7, 0) | ||
85 | +#define EXCCODE_ADEF EXCODE(8, 0) /* Different exception subcode */ | ||
86 | +#define EXCCODE_ADEM EXCODE(8, 1) | ||
87 | +#define EXCCODE_ALE EXCODE(9, 0) | ||
88 | +#define EXCCODE_BCE EXCODE(10, 0) | ||
89 | +#define EXCCODE_SYS EXCODE(11, 0) | ||
90 | +#define EXCCODE_BRK EXCODE(12, 0) | ||
91 | +#define EXCCODE_INE EXCODE(13, 0) | ||
92 | +#define EXCCODE_IPE EXCODE(14, 0) | ||
93 | +#define EXCCODE_FPD EXCODE(15, 0) | ||
94 | +#define EXCCODE_SXD EXCODE(16, 0) | ||
95 | +#define EXCCODE_ASXD EXCODE(17, 0) | ||
96 | +#define EXCCODE_FPE EXCODE(18, 0) /* Different exception subcode */ | ||
97 | +#define EXCCODE_VFPE EXCODE(18, 1) | ||
98 | +#define EXCCODE_WPEF EXCODE(19, 0) /* Different exception subcode */ | ||
99 | +#define EXCCODE_WPEM EXCODE(19, 1) | ||
100 | +#define EXCCODE_BTD EXCODE(20, 0) | ||
101 | +#define EXCCODE_BTE EXCODE(21, 0) | ||
102 | +#define EXCCODE_DBP EXCODE(26, 0) /* Reserved subcode used for debug */ | ||
103 | |||
104 | /* cpucfg[0] bits */ | ||
105 | FIELD(CPUCFG0, PRID, 0, 32) | ||
106 | -- | ||
107 | 2.31.1 | diff view generated by jsdifflib |
1 | From: Miao Hao <haomiao23s@ict.ac.cn> | 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> | ||
2 | 7 | ||
3 | When dump memory content with gva address, software page table walker is | 8 | void (*func)(int *); |
4 | necessary to get responding gpa address. | ||
5 | 9 | ||
6 | Here page table walker is added for debugger usage. | 10 | int main() |
11 | { | ||
12 | int i = 8; | ||
13 | void *ptr = (void *)0x4000000000000000; | ||
14 | func = ptr; | ||
15 | func(&i); | ||
16 | return 0; | ||
17 | } | ||
7 | 18 | ||
8 | Signed-off-by: Miao Hao <haomiao23s@ict.ac.cn> | 19 | Signed-off-by: Song Gao <gaosong@loongson.cn> |
9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 21 | Message-ID: <20221101073210.3934280-2-gaosong@loongson.cn> |
11 | --- | 22 | --- |
12 | target/loongarch/cpu_helper.c | 94 +++++++++++++++++++++++++++++-- | 23 | target/loongarch/cpu.c | 1 + |
13 | target/loongarch/internals.h | 4 +- | 24 | target/loongarch/tlb_helper.c | 5 +++-- |
14 | target/loongarch/tcg/tlb_helper.c | 4 +- | 25 | 2 files changed, 4 insertions(+), 2 deletions(-) |
15 | 3 files changed, 94 insertions(+), 8 deletions(-) | ||
16 | 26 | ||
17 | diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c | 27 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
18 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/loongarch/cpu_helper.c | 29 | --- a/target/loongarch/cpu.c |
20 | +++ b/target/loongarch/cpu_helper.c | 30 | +++ b/target/loongarch/cpu.c |
21 | @@ -XXX,XX +XXX,XX @@ bool loongarch_tlb_search(CPULoongArchState *env, target_ulong vaddr, | 31 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) |
22 | return false; | 32 | } |
23 | } | 33 | QEMU_FALLTHROUGH; |
24 | 34 | case EXCCODE_PIF: | |
25 | +static int loongarch_page_table_walker(CPULoongArchState *env, hwaddr *physical, | 35 | + case EXCCODE_ADEF: |
26 | + int *prot, target_ulong address) | 36 | cause = cs->exception_index; |
27 | +{ | 37 | update_badinstr = 0; |
28 | + CPUState *cs = env_cpu(env); | 38 | break; |
29 | + target_ulong index, phys; | 39 | diff --git a/target/loongarch/tlb_helper.c b/target/loongarch/tlb_helper.c |
30 | + uint64_t dir_base, dir_width; | 40 | index XXXXXXX..XXXXXXX 100644 |
31 | + uint64_t base; | 41 | --- a/target/loongarch/tlb_helper.c |
32 | + int level; | 42 | +++ b/target/loongarch/tlb_helper.c |
33 | + | 43 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPULoongArchState *env, target_ulong address, |
34 | + if ((address >> 63) & 0x1) { | 44 | switch (tlb_error) { |
35 | + base = env->CSR_PGDH; | 45 | default: |
36 | + } else { | 46 | case TLBRET_BADADDR: |
37 | + base = env->CSR_PGDL; | 47 | - cs->exception_index = EXCCODE_ADEM; |
38 | + } | 48 | + cs->exception_index = access_type == MMU_INST_FETCH |
39 | + base &= TARGET_PHYS_MASK; | 49 | + ? EXCCODE_ADEF : EXCCODE_ADEM; |
40 | + | 50 | break; |
41 | + for (level = 4; level > 0; level--) { | 51 | case TLBRET_NOMATCH: |
42 | + get_dir_base_width(env, &dir_base, &dir_width, level); | 52 | /* No TLB match for a mapped address */ |
43 | + | 53 | @@ -XXX,XX +XXX,XX @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
44 | + if (dir_width == 0) { | 54 | CPULoongArchState *env = &cpu->env; |
45 | + continue; | 55 | hwaddr physical; |
46 | + } | ||
47 | + | ||
48 | + /* get next level page directory */ | ||
49 | + index = (address >> dir_base) & ((1 << dir_width) - 1); | ||
50 | + phys = base | index << 3; | ||
51 | + base = ldq_phys(cs->as, phys) & TARGET_PHYS_MASK; | ||
52 | + if (FIELD_EX64(base, TLBENTRY, HUGE)) { | ||
53 | + /* base is a huge pte */ | ||
54 | + break; | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
58 | + /* pte */ | ||
59 | + if (FIELD_EX64(base, TLBENTRY, HUGE)) { | ||
60 | + /* Huge Page. base is pte */ | ||
61 | + base = FIELD_DP64(base, TLBENTRY, LEVEL, 0); | ||
62 | + base = FIELD_DP64(base, TLBENTRY, HUGE, 0); | ||
63 | + if (FIELD_EX64(base, TLBENTRY, HGLOBAL)) { | ||
64 | + base = FIELD_DP64(base, TLBENTRY, HGLOBAL, 0); | ||
65 | + base = FIELD_DP64(base, TLBENTRY, G, 1); | ||
66 | + } | ||
67 | + } else { | ||
68 | + /* Normal Page. base points to pte */ | ||
69 | + get_dir_base_width(env, &dir_base, &dir_width, 0); | ||
70 | + index = (address >> dir_base) & ((1 << dir_width) - 1); | ||
71 | + phys = base | index << 3; | ||
72 | + base = ldq_phys(cs->as, phys); | ||
73 | + } | ||
74 | + | ||
75 | + /* TODO: check plv and other bits? */ | ||
76 | + | ||
77 | + /* base is pte, in normal pte format */ | ||
78 | + if (!FIELD_EX64(base, TLBENTRY, V)) { | ||
79 | + return TLBRET_NOMATCH; | ||
80 | + } | ||
81 | + | ||
82 | + if (!FIELD_EX64(base, TLBENTRY, D)) { | ||
83 | + *prot = PAGE_READ; | ||
84 | + } else { | ||
85 | + *prot = PAGE_READ | PAGE_WRITE; | ||
86 | + } | ||
87 | + | ||
88 | + /* get TARGET_PAGE_SIZE aligned physical address */ | ||
89 | + base += (address & TARGET_PHYS_MASK) & ((1 << dir_base) - 1); | ||
90 | + /* mask RPLV, NX, NR bits */ | ||
91 | + base = FIELD_DP64(base, TLBENTRY_64, RPLV, 0); | ||
92 | + base = FIELD_DP64(base, TLBENTRY_64, NX, 0); | ||
93 | + base = FIELD_DP64(base, TLBENTRY_64, NR, 0); | ||
94 | + /* mask other attribute bits */ | ||
95 | + *physical = base & TARGET_PAGE_MASK; | ||
96 | + | ||
97 | + return 0; | ||
98 | +} | ||
99 | + | ||
100 | static int loongarch_map_address(CPULoongArchState *env, hwaddr *physical, | ||
101 | int *prot, target_ulong address, | ||
102 | - MMUAccessType access_type, int mmu_idx) | ||
103 | + MMUAccessType access_type, int mmu_idx, | ||
104 | + int is_debug) | ||
105 | { | ||
106 | int index, match; | ||
107 | |||
108 | @@ -XXX,XX +XXX,XX @@ static int loongarch_map_address(CPULoongArchState *env, hwaddr *physical, | ||
109 | if (match) { | ||
110 | return loongarch_map_tlb_entry(env, physical, prot, | ||
111 | address, access_type, index, mmu_idx); | ||
112 | + } else if (is_debug) { | ||
113 | + /* | ||
114 | + * For debugger memory access, we want to do the map when there is a | ||
115 | + * legal mapping, even if the mapping is not yet in TLB. return 0 if | ||
116 | + * there is a valid map, else none zero. | ||
117 | + */ | ||
118 | + return loongarch_page_table_walker(env, physical, prot, address); | ||
119 | } | ||
120 | |||
121 | return TLBRET_NOMATCH; | ||
122 | @@ -XXX,XX +XXX,XX @@ static int loongarch_map_address(CPULoongArchState *env, hwaddr *physical, | ||
123 | #else | ||
124 | static int loongarch_map_address(CPULoongArchState *env, hwaddr *physical, | ||
125 | int *prot, target_ulong address, | ||
126 | - MMUAccessType access_type, int mmu_idx) | ||
127 | + MMUAccessType access_type, int mmu_idx, | ||
128 | + int is_debug) | ||
129 | { | ||
130 | return TLBRET_NOMATCH; | ||
131 | } | ||
132 | @@ -XXX,XX +XXX,XX @@ static hwaddr dmw_va2pa(CPULoongArchState *env, target_ulong va, | ||
133 | |||
134 | int get_physical_address(CPULoongArchState *env, hwaddr *physical, | ||
135 | int *prot, target_ulong address, | ||
136 | - MMUAccessType access_type, int mmu_idx) | ||
137 | + MMUAccessType access_type, int mmu_idx, int is_debug) | ||
138 | { | ||
139 | int user_mode = mmu_idx == MMU_USER_IDX; | ||
140 | int kernel_mode = mmu_idx == MMU_KERNEL_IDX; | ||
141 | @@ -XXX,XX +XXX,XX @@ int get_physical_address(CPULoongArchState *env, hwaddr *physical, | ||
142 | |||
143 | /* Mapped address */ | ||
144 | return loongarch_map_address(env, physical, prot, address, | ||
145 | - access_type, mmu_idx); | ||
146 | + access_type, mmu_idx, is_debug); | ||
147 | } | ||
148 | |||
149 | hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | ||
150 | @@ -XXX,XX +XXX,XX @@ hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | ||
151 | int prot; | 56 | int prot; |
152 | 57 | - int ret = TLBRET_BADADDR; | |
153 | if (get_physical_address(env, &phys_addr, &prot, addr, MMU_DATA_LOAD, | 58 | + int ret; |
154 | - cpu_mmu_index(cs, false)) != 0) { | ||
155 | + cpu_mmu_index(cs, false), 1) != 0) { | ||
156 | return -1; | ||
157 | } | ||
158 | return phys_addr; | ||
159 | diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/target/loongarch/internals.h | ||
162 | +++ b/target/loongarch/internals.h | ||
163 | @@ -XXX,XX +XXX,XX @@ bool loongarch_tlb_search(CPULoongArchState *env, target_ulong vaddr, | ||
164 | int *index); | ||
165 | int get_physical_address(CPULoongArchState *env, hwaddr *physical, | ||
166 | int *prot, target_ulong address, | ||
167 | - MMUAccessType access_type, int mmu_idx); | ||
168 | + MMUAccessType access_type, int mmu_idx, int is_debug); | ||
169 | +void get_dir_base_width(CPULoongArchState *env, uint64_t *dir_base, | ||
170 | + uint64_t *dir_width, target_ulong level); | ||
171 | hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); | ||
172 | |||
173 | #ifdef CONFIG_TCG | ||
174 | diff --git a/target/loongarch/tcg/tlb_helper.c b/target/loongarch/tcg/tlb_helper.c | ||
175 | index XXXXXXX..XXXXXXX 100644 | ||
176 | --- a/target/loongarch/tcg/tlb_helper.c | ||
177 | +++ b/target/loongarch/tcg/tlb_helper.c | ||
178 | @@ -XXX,XX +XXX,XX @@ | ||
179 | #include "exec/log.h" | ||
180 | #include "cpu-csr.h" | ||
181 | |||
182 | -static void get_dir_base_width(CPULoongArchState *env, uint64_t *dir_base, | ||
183 | +void get_dir_base_width(CPULoongArchState *env, uint64_t *dir_base, | ||
184 | uint64_t *dir_width, target_ulong level) | ||
185 | { | ||
186 | switch (level) { | ||
187 | @@ -XXX,XX +XXX,XX @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
188 | 59 | ||
189 | /* Data access */ | 60 | /* Data access */ |
190 | ret = get_physical_address(env, &physical, &prot, address, | 61 | ret = get_physical_address(env, &physical, &prot, address, |
191 | - access_type, mmu_idx); | ||
192 | + access_type, mmu_idx, 0); | ||
193 | |||
194 | if (ret == TLBRET_MATCH) { | ||
195 | tlb_set_page(cs, address & TARGET_PAGE_MASK, | ||
196 | -- | 62 | -- |
197 | 2.43.5 | 63 | 2.31.1 | diff view generated by jsdifflib |
1 | There is arch_id and CPUState pointer in IPICore object. With function | 1 | From: Rui Wang <wangrui@loongson.cn> |
---|---|---|---|
2 | cpu_by_arch_id() it can be implemented by parsing IPICore array inside, | ||
3 | rather than possible_cpus array. | ||
4 | 2 | ||
5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 3 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 4 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Signed-off-by: Rui Wang <wangrui@loongson.cn> | ||
6 | Message-Id: <20221104040517.222059-2-wangrui@loongson.cn> | ||
7 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
7 | --- | 8 | --- |
8 | hw/intc/loongarch_ipi.c | 36 +++++++++++------------------------- | 9 | target/loongarch/cpu.h | 9 ++++++++- |
9 | 1 file changed, 11 insertions(+), 25 deletions(-) | 10 | target/loongarch/insn_trans/trans_privileged.c.inc | 2 +- |
11 | target/loongarch/translate.c | 6 +++++- | ||
12 | 3 files changed, 14 insertions(+), 3 deletions(-) | ||
10 | 13 | ||
11 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 14 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/hw/intc/loongarch_ipi.c | 16 | --- a/target/loongarch/cpu.h |
14 | +++ b/hw/intc/loongarch_ipi.c | 17 | +++ b/target/loongarch/cpu.h |
15 | @@ -XXX,XX +XXX,XX @@ static AddressSpace *get_iocsr_as(CPUState *cpu) | 18 | @@ -XXX,XX +XXX,XX @@ |
16 | return LOONGARCH_CPU(cpu)->env.address_space_iocsr; | 19 | #include "qemu/timer.h" |
20 | #include "exec/memory.h" | ||
21 | #include "hw/sysbus.h" | ||
22 | +#include "cpu-csr.h" | ||
23 | |||
24 | #define IOCSRF_TEMP 0 | ||
25 | #define IOCSRF_NODECNT 1 | ||
26 | @@ -XXX,XX +XXX,XX @@ static inline int cpu_mmu_index(CPULoongArchState *env, bool ifetch) | ||
27 | #endif | ||
17 | } | 28 | } |
18 | 29 | ||
19 | -static int archid_cmp(const void *a, const void *b) | 30 | +/* |
20 | +static int loongarch_ipi_cmp(const void *a, const void *b) | 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, | ||
21 | { | 40 | { |
22 | - CPUArchId *archid_a = (CPUArchId *)a; | 41 | *pc = env->pc; |
23 | - CPUArchId *archid_b = (CPUArchId *)b; | 42 | *cs_base = 0; |
24 | + IPICore *ipi_a = (IPICore *)a; | 43 | - *flags = cpu_mmu_index(env, false); |
25 | + IPICore *ipi_b = (IPICore *)b; | 44 | + *flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK); |
26 | |||
27 | - return archid_a->arch_id - archid_b->arch_id; | ||
28 | -} | ||
29 | - | ||
30 | -static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id) | ||
31 | -{ | ||
32 | - CPUArchId apic_id, *found_cpu; | ||
33 | - | ||
34 | - apic_id.arch_id = id; | ||
35 | - found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus, | ||
36 | - ms->possible_cpus->len, | ||
37 | - sizeof(*ms->possible_cpus->cpus), | ||
38 | - archid_cmp); | ||
39 | - | ||
40 | - return found_cpu; | ||
41 | + return ipi_a->arch_id - ipi_b->arch_id; | ||
42 | } | 45 | } |
43 | 46 | ||
44 | static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics, | 47 | void loongarch_cpu_list(void); |
45 | int64_t arch_id, int *index, CPUState **pcs) | 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) | ||
46 | { | 55 | { |
47 | - MachineState *machine = MACHINE(qdev_get_machine()); | 56 | - if (ctx->base.tb->flags == MMU_USER_IDX) { |
48 | - CPUArchId *archid; | 57 | + if (ctx->mem_idx == MMU_USER_IDX) { |
49 | - CPUState *cs; | 58 | generate_exception(ctx, EXCCODE_IPE); |
50 | + IPICore ipi, *found; | 59 | return true; |
51 | 60 | } | |
52 | - archid = find_cpu_by_archid(machine, arch_id); | 61 | diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c |
53 | - if (archid && archid->cpu) { | 62 | index XXXXXXX..XXXXXXX 100644 |
54 | - cs = archid->cpu; | 63 | --- a/target/loongarch/translate.c |
55 | + ipi.arch_id = arch_id; | 64 | +++ b/target/loongarch/translate.c |
56 | + found = bsearch(&ipi, lics->cpu, lics->num_cpu, sizeof(IPICore), | 65 | @@ -XXX,XX +XXX,XX @@ static void loongarch_tr_init_disas_context(DisasContextBase *dcbase, |
57 | + loongarch_ipi_cmp); | 66 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
58 | + if (found && found->cpu) { | 67 | |
59 | if (index) { | 68 | ctx->page_start = ctx->base.pc_first & TARGET_PAGE_MASK; |
60 | - *index = cs->cpu_index; | 69 | - ctx->mem_idx = ctx->base.tb->flags; |
61 | + *index = found - lics->cpu; | 70 | + if (ctx->base.tb->flags & HW_FLAGS_CRMD_PG) { |
62 | } | 71 | + ctx->mem_idx = ctx->base.tb->flags & HW_FLAGS_PLV_MASK; |
63 | 72 | + } else { | |
64 | if (pcs) { | 73 | + ctx->mem_idx = MMU_DA_IDX; |
65 | - *pcs = cs; | 74 | + } |
66 | + *pcs = found->cpu; | 75 | |
67 | } | 76 | /* Bound the number of insns to execute to those left on the page. */ |
68 | 77 | bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; | |
69 | return MEMTX_OK; | ||
70 | -- | 78 | -- |
71 | 2.43.5 | 79 | 2.31.1 | diff view generated by jsdifflib |
1 | Supported CPU number can be acquired from function | 1 | From: Rui Wang <wangrui@loongson.cn> |
---|---|---|---|
2 | possible_cpu_arch_ids(), cpu-num property is not necessary and can | ||
3 | be removed. | ||
4 | 2 | ||
5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | 3 | We need to emulate it to generate a floating point disable exception |
6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 4 | when CSR.EUEN.FPE is zero. |
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> | ||
7 | --- | 11 | --- |
8 | hw/intc/loongarch_ipi.c | 13 ++++++++----- | 12 | target/loongarch/cpu.c | 2 ++ |
9 | include/hw/intc/loongson_ipi_common.h | 2 ++ | 13 | target/loongarch/cpu.h | 2 ++ |
10 | 2 files changed, 10 insertions(+), 5 deletions(-) | 14 | .../loongarch/insn_trans/trans_farith.c.inc | 30 ++++++++++++++++ |
15 | target/loongarch/insn_trans/trans_fcmp.c.inc | 11 ++++-- | ||
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(-) | ||
11 | 19 | ||
12 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 20 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
13 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/intc/loongarch_ipi.c | 22 | --- a/target/loongarch/cpu.c |
15 | +++ b/hw/intc/loongarch_ipi.c | 23 | +++ b/target/loongarch/cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | 24 | @@ -XXX,XX +XXX,XX @@ static const char * const excp_names[] = { |
17 | { | 25 | [EXCCODE_BRK] = "Break", |
18 | LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(dev); | 26 | [EXCCODE_INE] = "Instruction Non-Existent", |
19 | LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev); | 27 | [EXCCODE_IPE] = "Instruction privilege error", |
20 | + MachineState *machine = MACHINE(qdev_get_machine()); | 28 | + [EXCCODE_FPD] = "Floating Point Disabled", |
21 | + MachineClass *mc = MACHINE_GET_CLASS(machine); | 29 | [EXCCODE_FPE] = "Floating Point Exception", |
22 | + const CPUArchIdList *id_list; | 30 | [EXCCODE_DBP] = "Debug breakpoint", |
23 | Error *local_err = NULL; | 31 | [EXCCODE_BCE] = "Bound Check Exception", |
24 | int i; | 32 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_do_interrupt(CPUState *cs) |
25 | 33 | case EXCCODE_BRK: | |
26 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | 34 | case EXCCODE_INE: |
27 | return; | 35 | case EXCCODE_IPE: |
28 | } | 36 | + case EXCCODE_FPD: |
29 | 37 | case EXCCODE_FPE: | |
30 | - if (lics->num_cpu == 0) { | 38 | case EXCCODE_BCE: |
31 | - error_setg(errp, "num-cpu must be at least 1"); | 39 | env->CSR_BADV = env->pc; |
32 | - return; | 40 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h |
33 | - } | 41 | index XXXXXXX..XXXXXXX 100644 |
34 | - | 42 | --- a/target/loongarch/cpu.h |
35 | + assert(mc->possible_cpu_arch_ids); | 43 | +++ b/target/loongarch/cpu.h |
36 | + id_list = mc->possible_cpu_arch_ids(machine); | 44 | @@ -XXX,XX +XXX,XX @@ static inline int cpu_mmu_index(CPULoongArchState *env, bool ifetch) |
37 | + lics->num_cpu = id_list->len; | 45 | */ |
38 | lics->cpu = g_new0(IPICore, lics->num_cpu); | 46 | #define HW_FLAGS_PLV_MASK R_CSR_CRMD_PLV_MASK /* 0x03 */ |
39 | for (i = 0; i < lics->num_cpu; i++) { | 47 | #define HW_FLAGS_CRMD_PG R_CSR_CRMD_PG_MASK /* 0x10 */ |
40 | + lics->cpu[i].arch_id = id_list->cpus[i].arch_id; | 48 | +#define HW_FLAGS_EUEN_FPE 0x04 |
41 | + lics->cpu[i].cpu = CPU(id_list->cpus[i].cpu); | 49 | |
42 | lics->cpu[i].ipi = lics; | 50 | static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, |
43 | qdev_init_gpio_out(dev, &lics->cpu[i].irq, 1); | 51 | target_ulong *pc, |
44 | } | 52 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPULoongArchState *env, |
45 | diff --git a/include/hw/intc/loongson_ipi_common.h b/include/hw/intc/loongson_ipi_common.h | 53 | *pc = env->pc; |
46 | index XXXXXXX..XXXXXXX 100644 | 54 | *cs_base = 0; |
47 | --- a/include/hw/intc/loongson_ipi_common.h | 55 | *flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK); |
48 | +++ b/include/hw/intc/loongson_ipi_common.h | 56 | + *flags |= FIELD_EX64(env->CSR_EUEN, CSR_EUEN, FPE) * HW_FLAGS_EUEN_FPE; |
49 | @@ -XXX,XX +XXX,XX @@ typedef struct IPICore { | 57 | } |
50 | /* 64bit buf divide into 2 32-bit buf */ | 58 | |
51 | uint32_t buf[IPI_MBX_NUM * 2]; | 59 | void loongarch_cpu_list(void); |
52 | qemu_irq irq; | 60 | diff --git a/target/loongarch/insn_trans/trans_farith.c.inc b/target/loongarch/insn_trans/trans_farith.c.inc |
53 | + uint64_t arch_id; | 61 | index XXXXXXX..XXXXXXX 100644 |
54 | + CPUState *cpu; | 62 | --- a/target/loongarch/insn_trans/trans_farith.c.inc |
55 | } IPICore; | 63 | +++ b/target/loongarch/insn_trans/trans_farith.c.inc |
56 | 64 | @@ -XXX,XX +XXX,XX @@ | |
57 | struct LoongsonIPICommonState { | 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 | + | ||
79 | static bool gen_fff(DisasContext *ctx, arg_fff *a, | ||
80 | void (*func)(TCGv, TCGv_env, TCGv, TCGv)) | ||
81 | { | ||
82 | + CHECK_FPE; | ||
83 | + | ||
84 | func(cpu_fpr[a->fd], cpu_env, cpu_fpr[a->fj], cpu_fpr[a->fk]); | ||
85 | return true; | ||
86 | } | ||
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; | ||
58 | -- | 397 | -- |
59 | 2.43.5 | 398 | 2.31.1 | diff view generated by jsdifflib |