Skip to content

Commit 5a3e068

Browse files
committed
hw/intc/loongarch_extioi: Get cpu number from possible_cpu_arch_ids
Supported CPU number can be acquired from function possible_cpu_arch_ids(), cpu-num property is not necessary. Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Bibo Mao <[email protected]>
1 parent 38adceb commit 5a3e068

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

hw/intc/loongarch_extioi.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,6 @@ static void loongarch_extioi_realize(DeviceState *dev, Error **errp)
347347
s->status |= BIT(EXTIOI_ENABLE);
348348
}
349349

350-
s->cpu = g_new0(ExtIOICore, s->num_cpu);
351-
if (s->cpu == NULL) {
352-
error_setg(errp, "Memory allocation for ExtIOICore faile");
353-
return;
354-
}
355-
356350
for (i = 0; i < s->num_cpu; i++) {
357351
for (pin = 0; pin < LS3A_INTC_IP; pin++) {
358352
qdev_init_gpio_out(dev, &s->cpu[i].parent_irq[pin], 1);

hw/intc/loongarch_extioi_common.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313
static void loongarch_extioi_common_realize(DeviceState *dev, Error **errp)
1414
{
1515
LoongArchExtIOICommonState *s = (LoongArchExtIOICommonState *)dev;
16+
MachineState *machine = MACHINE(qdev_get_machine());
17+
MachineClass *mc = MACHINE_GET_CLASS(machine);
18+
const CPUArchIdList *id_list;
19+
int i;
1620

17-
if (s->num_cpu == 0) {
18-
error_setg(errp, "num-cpu must be at least 1");
21+
assert(mc->possible_cpu_arch_ids);
22+
id_list = mc->possible_cpu_arch_ids(machine);
23+
s->num_cpu = id_list->len;
24+
s->cpu = g_new0(ExtIOICore, s->num_cpu);
25+
if (s->cpu == NULL) {
26+
error_setg(errp, "Memory allocation for ExtIOICore faile");
1927
return;
2028
}
29+
30+
for (i = 0; i < s->num_cpu; i++) {
31+
s->cpu[i].arch_id = id_list->cpus[i].arch_id;
32+
s->cpu[i].cpu = CPU(id_list->cpus[i].cpu);
33+
}
2134
}
2235

2336
static int loongarch_extioi_common_pre_save(void *opaque)

include/hw/intc/loongarch_extioi_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ typedef struct ExtIOICore {
6565
uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT];
6666
DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS);
6767
qemu_irq parent_irq[LS3A_INTC_IP];
68+
uint64_t arch_id;
69+
CPUState *cpu;
6870
} ExtIOICore;
6971

7072
struct LoongArchExtIOICommonState {

0 commit comments

Comments
 (0)