1 | The following changes since commit 5c2439a92ce4a1c5a53070bd803d6f7647e702ca: | 1 | The following changes since commit 7433709a147706ad7d1956b15669279933d0f82b: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-riscv-to-apply-20221014' of https://github.com/alistair23/qemu into staging (2022-10-16 15:53:13 -0400) | 3 | Merge tag 'hw-misc-20250113' of https://github.com/philmd/qemu into staging (2025-01-14 12:46:56 -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-20221017 | 7 | https://gitlab.com/bibo-mao/qemu.git tags/pull-loongarch-20250116 |
8 | 8 | ||
9 | for you to fetch changes up to 5ef4a4af8b41fb175374726f379a2aea79929023: | 9 | for you to fetch changes up to bb81f237401b5f89f6bba21d9d4f50e0073372a6: |
10 | 10 | ||
11 | hw/intc: Fix LoongArch ipi device emulation (2022-10-17 10:28:35 +0800) | 11 | hw/intc/loongarch_ipi: Use alternative implemation for cpu_by_arch_id (2025-01-15 14:36:19 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | pull-loongarch-20221017 | 14 | pull-loongarch-20250116 queue |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Song Gao (3): | 17 | Bibo Mao (7): |
18 | target/loongarch: bstrins.w src register need EXT_NONE | 18 | hw/intc/loongarch_ipi: Implement realize interface |
19 | target/loongarch: Fix fnm{sub/add}_{s/d} set wrong flags | 19 | hw/intc/loongson_ipi: Remove num_cpu from loongson_ipi_common |
20 | softfloat: logB(0) should raise divideByZero 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 | ||
21 | 25 | ||
22 | WANG Xuerui (1): | 26 | Miao Hao (1): |
23 | linux-user: Fix struct statfs ABI on loongarch64 | 27 | target/loongarch: Add page table walker support for debugger usage |
24 | 28 | ||
25 | Xiaojuan Yang (1): | 29 | hw/intc/loongarch_ipi.c | 69 ++++++++++++++++++------- |
26 | hw/intc: Fix LoongArch ipi device emulation | 30 | hw/intc/loongson_ipi.c | 43 +++++++++++++++- |
27 | 31 | hw/intc/loongson_ipi_common.c | 41 +++++---------- | |
28 | fpu/softfloat-parts.c.inc | 1 + | 32 | hw/loongarch/virt.c | 1 - |
29 | hw/intc/loongarch_ipi.c | 1 - | 33 | include/hw/intc/loongarch_ipi.h | 1 + |
30 | linux-user/syscall_defs.h | 3 ++- | 34 | include/hw/intc/loongson_ipi_common.h | 5 +- |
31 | target/loongarch/insn_trans/trans_bit.c.inc | 36 ++++++++++++++++---------- | 35 | target/loongarch/cpu_helper.c | 94 +++++++++++++++++++++++++++++++++-- |
32 | target/loongarch/insn_trans/trans_farith.c.inc | 12 ++++----- | 36 | target/loongarch/internals.h | 4 +- |
33 | 5 files changed, 31 insertions(+), 22 deletions(-) | 37 | target/loongarch/tcg/tlb_helper.c | 4 +- |
38 | 9 files changed, 203 insertions(+), 59 deletions(-) | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Miao Hao <haomiao23s@ict.ac.cn> | ||
1 | 2 | ||
3 | When dump memory content with gva address, software page table walker is | ||
4 | necessary to get responding gpa address. | ||
5 | |||
6 | Here page table walker is added for debugger usage. | ||
7 | |||
8 | Signed-off-by: Miao Hao <haomiao23s@ict.ac.cn> | ||
9 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
10 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
11 | --- | ||
12 | target/loongarch/cpu_helper.c | 94 +++++++++++++++++++++++++++++-- | ||
13 | target/loongarch/internals.h | 4 +- | ||
14 | target/loongarch/tcg/tlb_helper.c | 4 +- | ||
15 | 3 files changed, 94 insertions(+), 8 deletions(-) | ||
16 | |||
17 | diff --git a/target/loongarch/cpu_helper.c b/target/loongarch/cpu_helper.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/loongarch/cpu_helper.c | ||
20 | +++ b/target/loongarch/cpu_helper.c | ||
21 | @@ -XXX,XX +XXX,XX @@ bool loongarch_tlb_search(CPULoongArchState *env, target_ulong vaddr, | ||
22 | return false; | ||
23 | } | ||
24 | |||
25 | +static int loongarch_page_table_walker(CPULoongArchState *env, hwaddr *physical, | ||
26 | + int *prot, target_ulong address) | ||
27 | +{ | ||
28 | + CPUState *cs = env_cpu(env); | ||
29 | + target_ulong index, phys; | ||
30 | + uint64_t dir_base, dir_width; | ||
31 | + uint64_t base; | ||
32 | + int level; | ||
33 | + | ||
34 | + if ((address >> 63) & 0x1) { | ||
35 | + base = env->CSR_PGDH; | ||
36 | + } else { | ||
37 | + base = env->CSR_PGDL; | ||
38 | + } | ||
39 | + base &= TARGET_PHYS_MASK; | ||
40 | + | ||
41 | + for (level = 4; level > 0; level--) { | ||
42 | + get_dir_base_width(env, &dir_base, &dir_width, level); | ||
43 | + | ||
44 | + if (dir_width == 0) { | ||
45 | + continue; | ||
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; | ||
152 | |||
153 | if (get_physical_address(env, &phys_addr, &prot, addr, MMU_DATA_LOAD, | ||
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 | |||
189 | /* Data access */ | ||
190 | 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 | -- | ||
197 | 2.43.5 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Add realize interface for loongarch ipi device. | ||
1 | 2 | ||
3 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
5 | --- | ||
6 | hw/intc/loongarch_ipi.c | 19 +++++++++++++++++++ | ||
7 | include/hw/intc/loongarch_ipi.h | 1 + | ||
8 | 2 files changed, 20 insertions(+) | ||
9 | |||
10 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/hw/intc/loongarch_ipi.c | ||
13 | +++ b/hw/intc/loongarch_ipi.c | ||
14 | @@ -XXX,XX +XXX,XX @@ | ||
15 | |||
16 | #include "qemu/osdep.h" | ||
17 | #include "hw/boards.h" | ||
18 | +#include "qapi/error.h" | ||
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 | +{ | ||
28 | + LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev); | ||
29 | + Error *local_err = NULL; | ||
30 | + | ||
31 | + lic->parent_realize(dev, &local_err); | ||
32 | + if (local_err) { | ||
33 | + error_propagate(errp, local_err); | ||
34 | + return; | ||
35 | + } | ||
36 | +} | ||
37 | + | ||
38 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
39 | { | ||
40 | LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass); | ||
41 | + LoongarchIPIClass *lic = LOONGARCH_IPI_CLASS(klass); | ||
42 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
43 | |||
44 | + device_class_set_parent_realize(dc, loongarch_ipi_realize, | ||
45 | + &lic->parent_realize); | ||
46 | licc->get_iocsr_as = get_iocsr_as; | ||
47 | licc->cpu_by_arch_id = loongarch_cpu_by_arch_id; | ||
48 | } | ||
49 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo loongarch_ipi_types[] = { | ||
50 | { | ||
51 | .name = TYPE_LOONGARCH_IPI, | ||
52 | .parent = TYPE_LOONGSON_IPI_COMMON, | ||
53 | + .instance_size = sizeof(LoongarchIPIState), | ||
54 | + .class_size = sizeof(LoongarchIPIClass), | ||
55 | .class_init = loongarch_ipi_class_init, | ||
56 | } | ||
57 | }; | ||
58 | diff --git a/include/hw/intc/loongarch_ipi.h b/include/hw/intc/loongarch_ipi.h | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/include/hw/intc/loongarch_ipi.h | ||
61 | +++ b/include/hw/intc/loongarch_ipi.h | ||
62 | @@ -XXX,XX +XXX,XX @@ struct LoongarchIPIState { | ||
63 | |||
64 | struct LoongarchIPIClass { | ||
65 | LoongsonIPICommonClass parent_class; | ||
66 | + DeviceRealize parent_realize; | ||
67 | }; | ||
68 | |||
69 | #endif | ||
70 | -- | ||
71 | 2.43.5 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | With mips64 loongson ipi, num_cpu property is used. With loongarch | ||
2 | ipi, num_cpu can be acquired from possible_cpu_arch_ids. | ||
1 | 3 | ||
4 | Here remove num_cpu setting from loongson_ipi_common, and this piece | ||
5 | of code is put into loongson and loongarch ipi separately. | ||
6 | |||
7 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
8 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
9 | --- | ||
10 | hw/intc/loongarch_ipi.c | 13 +++++++++++++ | ||
11 | hw/intc/loongson_ipi.c | 14 +++++++++++++- | ||
12 | hw/intc/loongson_ipi_common.c | 14 -------------- | ||
13 | 3 files changed, 26 insertions(+), 15 deletions(-) | ||
14 | |||
15 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/loongarch_ipi.c | ||
18 | +++ b/hw/intc/loongarch_ipi.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id) | ||
20 | |||
21 | static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
22 | { | ||
23 | + LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(dev); | ||
24 | LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev); | ||
25 | Error *local_err = NULL; | ||
26 | + int i; | ||
27 | |||
28 | lic->parent_realize(dev, &local_err); | ||
29 | if (local_err) { | ||
30 | error_propagate(errp, local_err); | ||
31 | return; | ||
32 | } | ||
33 | + | ||
34 | + if (lics->num_cpu == 0) { | ||
35 | + error_setg(errp, "num-cpu must be at least 1"); | ||
36 | + return; | ||
37 | + } | ||
38 | + | ||
39 | + lics->cpu = g_new0(IPICore, lics->num_cpu); | ||
40 | + for (i = 0; i < lics->num_cpu; i++) { | ||
41 | + lics->cpu[i].ipi = lics; | ||
42 | + qdev_init_gpio_out(dev, &lics->cpu[i].irq, 1); | ||
43 | + } | ||
44 | } | ||
45 | |||
46 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
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 | -- | ||
120 | 2.43.5 | diff view generated by jsdifflib |
1 | From: Xiaojuan Yang <yangxiaojuan@loongson.cn> | 1 | With mips64 loongson ipi, num_cpu property is used. With loongarch |
---|---|---|---|
2 | ipi, num_cpu can be acquired from possible_cpu_arch_ids. | ||
2 | 3 | ||
3 | In ipi_send function, it should not to set irq before | 4 | Here remove property num_cpu from loongson_ipi_common, and put it into |
4 | writing data to dest cpu iocsr space, as the irq will | 5 | loongson and loongarch ipi separately. |
5 | trigger after data writing. | ||
6 | When call this function 'address_space_stl()', it will | ||
7 | trigger loongarch_ipi_writel(), the addr arg is 0x1008 | ||
8 | ('CORE_SET_OFF'), and qemu_irq_raise will be called in | ||
9 | this case. | ||
10 | 6 | ||
11 | Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> | 7 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
13 | Message-Id: <20220930095139.867115-3-yangxiaojuan@loongson.cn> | ||
14 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
15 | --- | 9 | --- |
16 | hw/intc/loongarch_ipi.c | 1 - | 10 | hw/intc/loongarch_ipi.c | 6 ++++++ |
17 | 1 file changed, 1 deletion(-) | 11 | hw/intc/loongson_ipi.c | 6 ++++++ |
12 | hw/intc/loongson_ipi_common.c | 6 ------ | ||
13 | 3 files changed, 12 insertions(+), 6 deletions(-) | ||
18 | 14 | ||
19 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c | 15 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c |
20 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/intc/loongarch_ipi.c | 17 | --- a/hw/intc/loongarch_ipi.c |
22 | +++ b/hw/intc/loongarch_ipi.c | 18 | +++ b/hw/intc/loongarch_ipi.c |
23 | @@ -XXX,XX +XXX,XX @@ static void ipi_send(uint64_t val) | 19 | @@ -XXX,XX +XXX,XX @@ |
24 | cs = qemu_get_cpu(cpuid); | 20 | #include "hw/boards.h" |
25 | cpu = LOONGARCH_CPU(cs); | 21 | #include "qapi/error.h" |
26 | env = &cpu->env; | 22 | #include "hw/intc/loongarch_ipi.h" |
27 | - loongarch_cpu_set_irq(cpu, IRQ_IPI, 1); | 23 | +#include "hw/qdev-properties.h" |
28 | address_space_stl(&env->address_space_iocsr, 0x1008, | 24 | #include "target/loongarch/cpu.h" |
29 | data, MEMTXATTRS_UNSPECIFIED, NULL); | 25 | |
26 | static AddressSpace *get_iocsr_as(CPUState *cpu) | ||
27 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
28 | } | ||
29 | } | ||
30 | |||
31 | +static const Property loongarch_ipi_properties[] = { | ||
32 | + DEFINE_PROP_UINT32("num-cpu", LoongsonIPICommonState, num_cpu, 1), | ||
33 | +}; | ||
34 | + | ||
35 | static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
36 | { | ||
37 | LoongsonIPICommonClass *licc = LOONGSON_IPI_COMMON_CLASS(klass); | ||
38 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_class_init(ObjectClass *klass, void *data) | ||
39 | |||
40 | device_class_set_parent_realize(dc, loongarch_ipi_realize, | ||
41 | &lic->parent_realize); | ||
42 | + device_class_set_props(dc, loongarch_ipi_properties); | ||
43 | licc->get_iocsr_as = get_iocsr_as; | ||
44 | licc->cpu_by_arch_id = loongarch_cpu_by_arch_id; | ||
45 | } | ||
46 | diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/hw/intc/loongson_ipi.c | ||
49 | +++ b/hw/intc/loongson_ipi.c | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | |||
52 | #include "qemu/osdep.h" | ||
53 | #include "hw/intc/loongson_ipi.h" | ||
54 | +#include "hw/qdev-properties.h" | ||
55 | #include "qapi/error.h" | ||
56 | #include "target/mips/cpu.h" | ||
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 | - | ||
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 | } | ||
30 | 107 | ||
31 | -- | 108 | -- |
32 | 2.31.1 | 109 | 2.43.5 | diff view generated by jsdifflib |
1 | From: WANG Xuerui <xen0n@gentoo.org> | 1 | Supported CPU number can be acquired from function |
---|---|---|---|
2 | possible_cpu_arch_ids(), cpu-num property is not necessary and can | ||
3 | be removed. | ||
2 | 4 | ||
3 | Previously the 32-bit version was incorrectly chosen, leading to funny | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | but incorrect output from e.g. df(1). Simply select the version | 6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
5 | corresponding to the 64-bit asm-generic definition. | 7 | --- |
8 | hw/intc/loongarch_ipi.c | 13 ++++++++----- | ||
9 | include/hw/intc/loongson_ipi_common.h | 2 ++ | ||
10 | 2 files changed, 10 insertions(+), 5 deletions(-) | ||
6 | 11 | ||
7 | For reference, this program should produce the same output no matter | 12 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c |
8 | natively compiled or not, for loongarch64 or not: | ||
9 | |||
10 | ```c | ||
11 | #include <stdio.h> | ||
12 | #include <sys/statfs.h> | ||
13 | |||
14 | int main(int argc, const char *argv[]) | ||
15 | { | ||
16 | struct statfs b; | ||
17 | if (statfs(argv[0], &b)) | ||
18 | return 1; | ||
19 | |||
20 | printf("f_type = 0x%lx\n", b.f_type); | ||
21 | printf("f_bsize = %ld\n", b.f_bsize); | ||
22 | printf("f_blocks = %ld\n", b.f_blocks); | ||
23 | printf("f_bfree = %ld\n", b.f_bfree); | ||
24 | printf("f_bavail = %ld\n", b.f_bavail); | ||
25 | |||
26 | return 0; | ||
27 | } | ||
28 | |||
29 | // Example output on my amd64 box, with the test binary residing on a | ||
30 | // btrfs partition. | ||
31 | |||
32 | // Native and emulated output after the fix: | ||
33 | // | ||
34 | // f_type = 0x9123683e | ||
35 | // f_bsize = 4096 | ||
36 | // f_blocks = 268435456 | ||
37 | // f_bfree = 168406890 | ||
38 | // f_bavail = 168355058 | ||
39 | |||
40 | // Output before the fix, note the messed layout: | ||
41 | // | ||
42 | // f_type = 0x10009123683e | ||
43 | // f_bsize = 723302085239504896 | ||
44 | // f_blocks = 168355058 | ||
45 | // f_bfree = 2250817541779750912 | ||
46 | // f_bavail = 1099229433104 | ||
47 | ``` | ||
48 | |||
49 | Fixes: 1f63019632 ("linux-user: Add LoongArch syscall support") | ||
50 | Signed-off-by: WANG Xuerui <xen0n@gentoo.org> | ||
51 | Cc: Song Gao <gaosong@loongson.cn> | ||
52 | Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn> | ||
53 | Cc: Andreas K. Hüttel <dilfridge@gentoo.org> | ||
54 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
55 | Tested-by: Andreas K. Huettel <dilfridge@gentoo.org> | ||
56 | Message-Id: <20221006100710.427252-1-xen0n@gentoo.org> | ||
57 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
58 | --- | ||
59 | linux-user/syscall_defs.h | 3 ++- | ||
60 | 1 file changed, 2 insertions(+), 1 deletion(-) | ||
61 | |||
62 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h | ||
63 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
64 | --- a/linux-user/syscall_defs.h | 14 | --- a/hw/intc/loongarch_ipi.c |
65 | +++ b/linux-user/syscall_defs.h | 15 | +++ b/hw/intc/loongarch_ipi.c |
66 | @@ -XXX,XX +XXX,XX @@ struct target_statfs64 { | 16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) |
67 | }; | 17 | { |
68 | #elif (defined(TARGET_PPC64) || defined(TARGET_X86_64) || \ | 18 | LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(dev); |
69 | defined(TARGET_SPARC64) || defined(TARGET_AARCH64) || \ | 19 | LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev); |
70 | - defined(TARGET_RISCV)) && !defined(TARGET_ABI32) | 20 | + MachineState *machine = MACHINE(qdev_get_machine()); |
71 | + defined(TARGET_RISCV) || defined(TARGET_LOONGARCH64)) && \ | 21 | + MachineClass *mc = MACHINE_GET_CLASS(machine); |
72 | + !defined(TARGET_ABI32) | 22 | + const CPUArchIdList *id_list; |
73 | struct target_statfs { | 23 | Error *local_err = NULL; |
74 | abi_long f_type; | 24 | int i; |
75 | abi_long f_bsize; | 25 | |
26 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | - if (lics->num_cpu == 0) { | ||
31 | - error_setg(errp, "num-cpu must be at least 1"); | ||
32 | - return; | ||
33 | - } | ||
34 | - | ||
35 | + assert(mc->possible_cpu_arch_ids); | ||
36 | + id_list = mc->possible_cpu_arch_ids(machine); | ||
37 | + lics->num_cpu = id_list->len; | ||
38 | lics->cpu = g_new0(IPICore, lics->num_cpu); | ||
39 | for (i = 0; i < lics->num_cpu; i++) { | ||
40 | + lics->cpu[i].arch_id = id_list->cpus[i].arch_id; | ||
41 | + lics->cpu[i].cpu = CPU(id_list->cpus[i].cpu); | ||
42 | lics->cpu[i].ipi = lics; | ||
43 | qdev_init_gpio_out(dev, &lics->cpu[i].irq, 1); | ||
44 | } | ||
45 | diff --git a/include/hw/intc/loongson_ipi_common.h b/include/hw/intc/loongson_ipi_common.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/include/hw/intc/loongson_ipi_common.h | ||
48 | +++ b/include/hw/intc/loongson_ipi_common.h | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef struct IPICore { | ||
50 | /* 64bit buf divide into 2 32-bit buf */ | ||
51 | uint32_t buf[IPI_MBX_NUM * 2]; | ||
52 | qemu_irq irq; | ||
53 | + uint64_t arch_id; | ||
54 | + CPUState *cpu; | ||
55 | } IPICore; | ||
56 | |||
57 | struct LoongsonIPICommonState { | ||
76 | -- | 58 | -- |
77 | 2.31.1 | 59 | 2.43.5 |
78 | |||
79 | diff view generated by jsdifflib |
1 | logB(0) should raise divideByZero exception from IEEE 754-2008 spec 7.3 | 1 | Since cpu number can be acquired from possible_cpu_arch_ids(), |
---|---|---|---|
2 | num-cpu property is not necessary. Here remove num-cpu property | ||
3 | for object TYPE_LOONGARCH_IPI object. | ||
2 | 4 | ||
3 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-Id: <20220930024510.800005-4-gaosong@loongson.cn> | ||
7 | --- | 7 | --- |
8 | fpu/softfloat-parts.c.inc | 1 + | 8 | hw/intc/loongarch_ipi.c | 5 ----- |
9 | 1 file changed, 1 insertion(+) | 9 | hw/loongarch/virt.c | 1 - |
10 | 2 files changed, 6 deletions(-) | ||
10 | 11 | ||
11 | diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc | 12 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/fpu/softfloat-parts.c.inc | 14 | --- a/hw/intc/loongarch_ipi.c |
14 | +++ b/fpu/softfloat-parts.c.inc | 15 | +++ b/hw/intc/loongarch_ipi.c |
15 | @@ -XXX,XX +XXX,XX @@ static void partsN(log2)(FloatPartsN *a, float_status *s, const FloatFmt *fmt) | 16 | @@ -XXX,XX +XXX,XX @@ static void loongarch_ipi_realize(DeviceState *dev, Error **errp) |
16 | parts_return_nan(a, s); | 17 | } |
17 | return; | 18 | } |
18 | case float_class_zero: | 19 | |
19 | + float_raise(float_flag_divbyzero, s); | 20 | -static const Property loongarch_ipi_properties[] = { |
20 | /* log2(0) = -inf */ | 21 | - DEFINE_PROP_UINT32("num-cpu", LoongsonIPICommonState, num_cpu, 1), |
21 | a->cls = float_class_inf; | 22 | -}; |
22 | a->sign = 1; | 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 | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/hw/loongarch/virt.c | ||
38 | +++ b/hw/loongarch/virt.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) | ||
40 | |||
41 | /* Create IPI device */ | ||
42 | ipi = qdev_new(TYPE_LOONGARCH_IPI); | ||
43 | - qdev_prop_set_uint32(ipi, "num-cpu", ms->smp.cpus); | ||
44 | sysbus_realize_and_unref(SYS_BUS_DEVICE(ipi), &error_fatal); | ||
45 | |||
46 | /* IPI iocsr memory region */ | ||
23 | -- | 47 | -- |
24 | 2.31.1 | 48 | 2.43.5 | diff view generated by jsdifflib |
1 | use gen_bstrins/gen_bstrpic to replace gen_rr_ms_ls. | 1 | Add logic cpu index input parameter for function cpu_by_arch_id, |
---|---|---|---|
2 | CPUState::cpu_index is logic cpu slot index for possible_cpus. | ||
2 | 3 | ||
3 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | 4 | At the same time it is logic index with LoongsonIPICommonState::IPICore, |
4 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | here hide access for CPUState::cpu_index directly, it comes from |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | function cpu_by_arch_id(). |
6 | Message-Id: <20220930024510.800005-2-gaosong@loongson.cn> | 7 | |
8 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
9 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
7 | --- | 10 | --- |
8 | target/loongarch/insn_trans/trans_bit.c.inc | 36 +++++++++++++-------- | 11 | hw/intc/loongarch_ipi.c | 19 +++++++++++++++---- |
9 | 1 file changed, 22 insertions(+), 14 deletions(-) | 12 | hw/intc/loongson_ipi.c | 23 ++++++++++++++++++++++- |
13 | hw/intc/loongson_ipi_common.c | 21 ++++++++++++--------- | ||
14 | include/hw/intc/loongson_ipi_common.h | 3 ++- | ||
15 | 4 files changed, 51 insertions(+), 15 deletions(-) | ||
10 | 16 | ||
11 | diff --git a/target/loongarch/insn_trans/trans_bit.c.inc b/target/loongarch/insn_trans/trans_bit.c.inc | 17 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c |
12 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/loongarch/insn_trans/trans_bit.c.inc | 19 | --- a/hw/intc/loongarch_ipi.c |
14 | +++ b/target/loongarch/insn_trans/trans_bit.c.inc | 20 | +++ b/hw/intc/loongarch_ipi.c |
15 | @@ -XXX,XX +XXX,XX @@ static void gen_bytepick_d(TCGv dest, TCGv src1, TCGv src2, target_long sa) | 21 | @@ -XXX,XX +XXX,XX @@ static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id) |
16 | tcg_gen_extract2_i64(dest, src1, src2, (64 - sa * 8)); | 22 | return found_cpu; |
17 | } | 23 | } |
18 | 24 | ||
19 | -static void gen_bstrins(TCGv dest, TCGv src1, | 25 | -static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id) |
20 | - unsigned int ls, unsigned int len) | 26 | +static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics, |
21 | +static bool gen_bstrins(DisasContext *ctx, arg_rr_ms_ls *a, | 27 | + int64_t arch_id, int *index, CPUState **pcs) |
22 | + DisasExtend dst_ext) | ||
23 | { | 28 | { |
24 | - tcg_gen_deposit_tl(dest, dest, src1, ls, len); | 29 | MachineState *machine = MACHINE(qdev_get_machine()); |
25 | + TCGv src1 = gpr_src(ctx, a->rd, EXT_NONE); | 30 | CPUArchId *archid; |
26 | + TCGv src2 = gpr_src(ctx, a->rj, EXT_NONE); | 31 | + CPUState *cs; |
27 | + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); | 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 | + } | ||
28 | + | 41 | + |
29 | + if (a->ls > a->ms) { | 42 | + if (pcs) { |
30 | + return false; | 43 | + *pcs = cs; |
44 | + } | ||
45 | + | ||
46 | + return MEMTX_OK; | ||
47 | } | ||
48 | |||
49 | - return NULL; | ||
50 | + return MEMTX_ERROR; | ||
51 | } | ||
52 | |||
53 | static void loongarch_ipi_realize(DeviceState *dev, Error **errp) | ||
54 | diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/hw/intc/loongson_ipi.c | ||
57 | +++ b/hw/intc/loongson_ipi.c | ||
58 | @@ -XXX,XX +XXX,XX @@ static AddressSpace *get_iocsr_as(CPUState *cpu) | ||
59 | return NULL; | ||
60 | } | ||
61 | |||
62 | +static int loongson_cpu_by_arch_id(LoongsonIPICommonState *lics, | ||
63 | + int64_t arch_id, int *index, CPUState **pcs) | ||
64 | +{ | ||
65 | + CPUState *cs; | ||
66 | + | ||
67 | + cs = cpu_by_arch_id(arch_id); | ||
68 | + if (cs == NULL) { | ||
69 | + return MEMTX_ERROR; | ||
31 | + } | 70 | + } |
32 | + | 71 | + |
33 | + tcg_gen_deposit_tl(dest, src1, src2, a->ls, a->ms - a->ls + 1); | 72 | + if (index) { |
34 | + gen_set_gpr(a->rd, dest, dst_ext); | 73 | + *index = cs->cpu_index; |
35 | + return true; | 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; | ||
36 | } | 92 | } |
37 | 93 | ||
38 | -static bool gen_rr_ms_ls(DisasContext *ctx, arg_rr_ms_ls *a, | 94 | static const TypeInfo loongson_ipi_types[] = { |
39 | - DisasExtend src_ext, DisasExtend dst_ext, | 95 | diff --git a/hw/intc/loongson_ipi_common.c b/hw/intc/loongson_ipi_common.c |
40 | - void (*func)(TCGv, TCGv, unsigned int, unsigned int)) | 96 | index XXXXXXX..XXXXXXX 100644 |
41 | +static bool gen_bstrpick(DisasContext *ctx, arg_rr_ms_ls *a, | 97 | --- a/hw/intc/loongson_ipi_common.c |
42 | + DisasExtend dst_ext) | 98 | +++ b/hw/intc/loongson_ipi_common.c |
43 | { | 99 | @@ -XXX,XX +XXX,XX @@ static MemTxResult mail_send(LoongsonIPICommonState *ipi, |
44 | - TCGv dest = gpr_dst(ctx, a->rd, dst_ext); | 100 | uint32_t cpuid; |
45 | - TCGv src1 = gpr_src(ctx, a->rj, src_ext); | 101 | hwaddr addr; |
46 | + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE); | 102 | CPUState *cs; |
47 | + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE); | 103 | + int cpu, ret; |
48 | 104 | ||
49 | if (a->ls > a->ms) { | 105 | cpuid = extract32(val, 16, 10); |
50 | return false; | 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; | ||
51 | } | 111 | } |
52 | 112 | ||
53 | - func(dest, src1, a->ls, a->ms - a->ls + 1); | 113 | /* override requester_id */ |
54 | + tcg_gen_extract_tl(dest, src1, a->ls, a->ms - a->ls + 1); | 114 | addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c); |
55 | gen_set_gpr(a->rd, dest, dst_ext); | 115 | - attrs.requester_id = cs->cpu_index; |
56 | - | 116 | + attrs.requester_id = cpu; |
57 | return true; | 117 | return send_ipi_data(ipi, cs, val, addr, attrs); |
58 | } | 118 | } |
59 | 119 | ||
60 | @@ -XXX,XX +XXX,XX @@ TRANS(maskeqz, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_maskeqz) | 120 | @@ -XXX,XX +XXX,XX @@ static MemTxResult any_send(LoongsonIPICommonState *ipi, |
61 | TRANS(masknez, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_masknez) | 121 | uint32_t cpuid; |
62 | TRANS(bytepick_w, gen_rrr_sa, EXT_NONE, EXT_NONE, gen_bytepick_w) | 122 | hwaddr addr; |
63 | TRANS(bytepick_d, gen_rrr_sa, EXT_NONE, EXT_NONE, gen_bytepick_d) | 123 | CPUState *cs; |
64 | -TRANS(bstrins_w, gen_rr_ms_ls, EXT_NONE, EXT_NONE, gen_bstrins) | 124 | + int cpu, ret; |
65 | -TRANS(bstrins_d, gen_rr_ms_ls, EXT_NONE, EXT_NONE, gen_bstrins) | 125 | |
66 | -TRANS(bstrpick_w, gen_rr_ms_ls, EXT_NONE, EXT_SIGN, tcg_gen_extract_tl) | 126 | cpuid = extract32(val, 16, 10); |
67 | -TRANS(bstrpick_d, gen_rr_ms_ls, EXT_NONE, EXT_NONE, tcg_gen_extract_tl) | 127 | - cs = licc->cpu_by_arch_id(cpuid); |
68 | +TRANS(bstrins_w, gen_bstrins, EXT_SIGN) | 128 | - if (cs == NULL) { |
69 | +TRANS(bstrins_d, gen_bstrins, EXT_NONE) | 129 | + ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs); |
70 | +TRANS(bstrpick_w, gen_bstrpick, EXT_SIGN) | 130 | + if (ret != MEMTX_OK) { |
71 | +TRANS(bstrpick_d, gen_bstrpick, EXT_NONE) | 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 | } | ||
140 | |||
141 | @@ -XXX,XX +XXX,XX @@ MemTxResult loongson_ipi_core_writel(void *opaque, hwaddr addr, uint64_t val, | ||
142 | uint32_t cpuid; | ||
143 | uint8_t vector; | ||
144 | CPUState *cs; | ||
145 | + int cpu, ret; | ||
146 | |||
147 | addr &= 0xff; | ||
148 | trace_loongson_ipi_write(size, (uint64_t)addr, val); | ||
149 | @@ -XXX,XX +XXX,XX @@ MemTxResult loongson_ipi_core_writel(void *opaque, hwaddr addr, uint64_t val, | ||
150 | cpuid = extract32(val, 16, 10); | ||
151 | /* IPI status vector */ | ||
152 | vector = extract8(val, 0, 5); | ||
153 | - cs = licc->cpu_by_arch_id(cpuid); | ||
154 | - if (cs == NULL || cs->cpu_index >= ipi->num_cpu) { | ||
155 | + ret = licc->cpu_by_arch_id(ipi, cpuid, &cpu, &cs); | ||
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, | ||
72 | -- | 178 | -- |
73 | 2.31.1 | 179 | 2.43.5 | diff view generated by jsdifflib |
1 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 1 | There is arch_id and CPUState pointer in IPICore object. With function |
---|---|---|---|
2 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 2 | cpu_by_arch_id() it can be implemented by parsing IPICore array inside, |
3 | Message-Id: <20220930024510.800005-3-gaosong@loongson.cn> | 3 | rather than possible_cpus array. |
4 | |||
5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> | ||
6 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
4 | --- | 7 | --- |
5 | target/loongarch/insn_trans/trans_farith.c.inc | 12 ++++++------ | 8 | hw/intc/loongarch_ipi.c | 36 +++++++++++------------------------- |
6 | 1 file changed, 6 insertions(+), 6 deletions(-) | 9 | 1 file changed, 11 insertions(+), 25 deletions(-) |
7 | 10 | ||
8 | diff --git a/target/loongarch/insn_trans/trans_farith.c.inc b/target/loongarch/insn_trans/trans_farith.c.inc | 11 | diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/target/loongarch/insn_trans/trans_farith.c.inc | 13 | --- a/hw/intc/loongarch_ipi.c |
11 | +++ b/target/loongarch/insn_trans/trans_farith.c.inc | 14 | +++ b/hw/intc/loongarch_ipi.c |
12 | @@ -XXX,XX +XXX,XX @@ TRANS(fmadd_s, gen_muladd, gen_helper_fmuladd_s, 0) | 15 | @@ -XXX,XX +XXX,XX @@ static AddressSpace *get_iocsr_as(CPUState *cpu) |
13 | TRANS(fmadd_d, gen_muladd, gen_helper_fmuladd_d, 0) | 16 | return LOONGARCH_CPU(cpu)->env.address_space_iocsr; |
14 | TRANS(fmsub_s, gen_muladd, gen_helper_fmuladd_s, float_muladd_negate_c) | 17 | } |
15 | TRANS(fmsub_d, gen_muladd, gen_helper_fmuladd_d, float_muladd_negate_c) | 18 | |
16 | -TRANS(fnmadd_s, gen_muladd, gen_helper_fmuladd_s, | 19 | -static int archid_cmp(const void *a, const void *b) |
17 | - float_muladd_negate_product | float_muladd_negate_c) | 20 | +static int loongarch_ipi_cmp(const void *a, const void *b) |
18 | -TRANS(fnmadd_d, gen_muladd, gen_helper_fmuladd_d, | 21 | { |
19 | - float_muladd_negate_product | float_muladd_negate_c) | 22 | - CPUArchId *archid_a = (CPUArchId *)a; |
20 | -TRANS(fnmsub_s, gen_muladd, gen_helper_fmuladd_s, float_muladd_negate_product) | 23 | - CPUArchId *archid_b = (CPUArchId *)b; |
21 | -TRANS(fnmsub_d, gen_muladd, gen_helper_fmuladd_d, float_muladd_negate_product) | 24 | + IPICore *ipi_a = (IPICore *)a; |
22 | +TRANS(fnmadd_s, gen_muladd, gen_helper_fmuladd_s, float_muladd_negate_result) | 25 | + IPICore *ipi_b = (IPICore *)b; |
23 | +TRANS(fnmadd_d, gen_muladd, gen_helper_fmuladd_d, float_muladd_negate_result) | 26 | |
24 | +TRANS(fnmsub_s, gen_muladd, gen_helper_fmuladd_s, | 27 | - return archid_a->arch_id - archid_b->arch_id; |
25 | + float_muladd_negate_c | float_muladd_negate_result) | 28 | -} |
26 | +TRANS(fnmsub_d, gen_muladd, gen_helper_fmuladd_d, | 29 | - |
27 | + float_muladd_negate_c | float_muladd_negate_result) | 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 | } | ||
43 | |||
44 | static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics, | ||
45 | int64_t arch_id, int *index, CPUState **pcs) | ||
46 | { | ||
47 | - MachineState *machine = MACHINE(qdev_get_machine()); | ||
48 | - CPUArchId *archid; | ||
49 | - CPUState *cs; | ||
50 | + IPICore ipi, *found; | ||
51 | |||
52 | - archid = find_cpu_by_archid(machine, arch_id); | ||
53 | - if (archid && archid->cpu) { | ||
54 | - cs = archid->cpu; | ||
55 | + ipi.arch_id = arch_id; | ||
56 | + found = bsearch(&ipi, lics->cpu, lics->num_cpu, sizeof(IPICore), | ||
57 | + loongarch_ipi_cmp); | ||
58 | + if (found && found->cpu) { | ||
59 | if (index) { | ||
60 | - *index = cs->cpu_index; | ||
61 | + *index = found - lics->cpu; | ||
62 | } | ||
63 | |||
64 | if (pcs) { | ||
65 | - *pcs = cs; | ||
66 | + *pcs = found->cpu; | ||
67 | } | ||
68 | |||
69 | return MEMTX_OK; | ||
28 | -- | 70 | -- |
29 | 2.31.1 | 71 | 2.43.5 | diff view generated by jsdifflib |