Skip to content

Commit 5b82177

Browse files
committed
hw/intc/loongson_ipi: Remove num_cpu from loongson_ipi_common
With mips64 loongson ipi, num_cpu property is used. With loongarch ipi, num_cpu can be acquired from possible_cpu_arch_ids. Here remove num_cpu setting from loongson_ipi_common, and this piece of code is put into loongson and loongarch ipi separately. Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Bibo Mao <[email protected]>
1 parent 59c54c1 commit 5b82177

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

hw/intc/loongarch_ipi.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,27 @@ static CPUState *loongarch_cpu_by_arch_id(int64_t arch_id)
5252

5353
static void loongarch_ipi_realize(DeviceState *dev, Error **errp)
5454
{
55+
LoongsonIPICommonState *lics = LOONGSON_IPI_COMMON(dev);
5556
LoongarchIPIClass *lic = LOONGARCH_IPI_GET_CLASS(dev);
5657
Error *local_err = NULL;
58+
int i;
5759

5860
lic->parent_realize(dev, &local_err);
5961
if (local_err) {
6062
error_propagate(errp, local_err);
6163
return;
6264
}
65+
66+
if (lics->num_cpu == 0) {
67+
error_setg(errp, "num-cpu must be at least 1");
68+
return;
69+
}
70+
71+
lics->cpu = g_new0(IPICore, lics->num_cpu);
72+
for (i = 0; i < lics->num_cpu; i++) {
73+
lics->cpu[i].ipi = lics;
74+
qdev_init_gpio_out(dev, &lics->cpu[i].irq, 1);
75+
}
6376
}
6477

6578
static void loongarch_ipi_class_init(ObjectClass *klass, void *data)

hw/intc/loongson_ipi.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,27 @@ static void loongson_ipi_realize(DeviceState *dev, Error **errp)
3636
LoongsonIPIClass *lic = LOONGSON_IPI_GET_CLASS(dev);
3737
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
3838
Error *local_err = NULL;
39+
int i;
3940

4041
lic->parent_realize(dev, &local_err);
4142
if (local_err) {
4243
error_propagate(errp, local_err);
4344
return;
4445
}
4546

47+
if (sc->num_cpu == 0) {
48+
error_setg(errp, "num-cpu must be at least 1");
49+
return;
50+
}
51+
52+
sc->cpu = g_new0(IPICore, sc->num_cpu);
53+
for (i = 0; i < sc->num_cpu; i++) {
54+
sc->cpu[i].ipi = sc;
55+
qdev_init_gpio_out(dev, &sc->cpu[i].irq, 1);
56+
}
57+
4658
s->ipi_mmio_mem = g_new0(MemoryRegion, sc->num_cpu);
47-
for (unsigned i = 0; i < sc->num_cpu; i++) {
59+
for (i = 0; i < sc->num_cpu; i++) {
4860
g_autofree char *name = g_strdup_printf("loongson_ipi_cpu%d_mmio", i);
4961

5062
memory_region_init_io(&s->ipi_mmio_mem[i], OBJECT(dev),

hw/intc/loongson_ipi_common.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "hw/intc/loongson_ipi_common.h"
1111
#include "hw/irq.h"
1212
#include "hw/qdev-properties.h"
13-
#include "qapi/error.h"
1413
#include "qemu/log.h"
1514
#include "migration/vmstate.h"
1615
#include "trace.h"
@@ -253,12 +252,6 @@ static void loongson_ipi_common_realize(DeviceState *dev, Error **errp)
253252
{
254253
LoongsonIPICommonState *s = LOONGSON_IPI_COMMON(dev);
255254
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
256-
int i;
257-
258-
if (s->num_cpu == 0) {
259-
error_setg(errp, "num-cpu must be at least 1");
260-
return;
261-
}
262255

263256
memory_region_init_io(&s->ipi_iocsr_mem, OBJECT(dev),
264257
&loongson_ipi_iocsr_ops,
@@ -273,13 +266,6 @@ static void loongson_ipi_common_realize(DeviceState *dev, Error **errp)
273266
&loongson_ipi64_ops,
274267
s, "loongson_ipi64_iocsr", 0x118);
275268
sysbus_init_mmio(sbd, &s->ipi64_iocsr_mem);
276-
277-
s->cpu = g_new0(IPICore, s->num_cpu);
278-
for (i = 0; i < s->num_cpu; i++) {
279-
s->cpu[i].ipi = s;
280-
281-
qdev_init_gpio_out(dev, &s->cpu[i].irq, 1);
282-
}
283269
}
284270

285271
static void loongson_ipi_common_unrealize(DeviceState *dev)

0 commit comments

Comments
 (0)