[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 7/7] hw/intc/loongarch_ipi: Use alternative function cpu_by_ar
From: |
Bibo Mao |
Subject: |
[PATCH v3 7/7] hw/intc/loongarch_ipi: Use alternative function cpu_by_arch_id |
Date: |
Tue, 7 Jan 2025 11:08:19 +0800 |
There is arch_id and CPUState pointer in IPICore object, with function
cpu_by_arch_id() it can be implemented by parsing IPICore array.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
hw/intc/loongarch_ipi.c | 36 +++++++++++-------------------------
1 file changed, 11 insertions(+), 25 deletions(-)
diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
index 515549e8a5..5376f1e084 100644
--- a/hw/intc/loongarch_ipi.c
+++ b/hw/intc/loongarch_ipi.c
@@ -17,43 +17,29 @@ static AddressSpace *get_iocsr_as(CPUState *cpu)
return LOONGARCH_CPU(cpu)->env.address_space_iocsr;
}
-static int archid_cmp(const void *a, const void *b)
+static int loongarch_ipi_cmp(const void *a, const void *b)
{
- CPUArchId *archid_a = (CPUArchId *)a;
- CPUArchId *archid_b = (CPUArchId *)b;
+ IPICore *ipi_a = (IPICore *)a;
+ IPICore *ipi_b = (IPICore *)b;
- return archid_a->arch_id - archid_b->arch_id;
-}
-
-static CPUArchId *find_cpu_by_archid(MachineState *ms, uint32_t id)
-{
- CPUArchId apic_id, *found_cpu;
-
- apic_id.arch_id = id;
- found_cpu = bsearch(&apic_id, ms->possible_cpus->cpus,
- ms->possible_cpus->len,
- sizeof(*ms->possible_cpus->cpus),
- archid_cmp);
-
- return found_cpu;
+ return ipi_a->arch_id - ipi_b->arch_id;
}
static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics,
int64_t arch_id, int *index, CPUState
**pcs)
{
- MachineState *machine = MACHINE(qdev_get_machine());
- CPUArchId *archid;
- CPUState *cs;
+ IPICore ipi, *found;
- archid = find_cpu_by_archid(machine, arch_id);
- if (archid && archid->cpu) {
- cs = archid->cpu;
+ ipi.arch_id = arch_id;
+ found = bsearch(&ipi, lics->cpu, lics->num_cpu, sizeof(IPICore),
+ loongarch_ipi_cmp);
+ if (found && found->cpu) {
if (index) {
- *index = cs->cpu_index;
+ *index = found - lics->cpu;
}
if (pcs) {
- *pcs = cs;
+ *pcs = found->cpu;
}
return MEMTX_OK;
--
2.39.3
- [PATCH v3 0/7] hw/intc/loongson_ipi: Remove property num_cpu, Bibo Mao, 2025/01/06
- [PATCH v3 5/7] hw/intc/loongarch_ipi: Remove num-cpu property, Bibo Mao, 2025/01/06
- [PATCH v3 2/7] hw/intc/loongson_ipi: Remove num_cpu from loongson_ipi_common, Bibo Mao, 2025/01/06
- [PATCH v3 7/7] hw/intc/loongarch_ipi: Use alternative function cpu_by_arch_id,
Bibo Mao <=
- [PATCH v3 1/7] hw/intc/loongarch_ipi: Implement realize interface, Bibo Mao, 2025/01/06
- [PATCH v3 6/7] hw/intc/loongson_ipi: Add more output parameter for cpu_by_arch_id, Bibo Mao, 2025/01/06
- [PATCH v3 3/7] hw/intc/loongson_ipi: Remove property num_cpu from loongson_ipi_common, Bibo Mao, 2025/01/06
- [PATCH v3 4/7] hw/intc/loongarch_ipi: Get cpu number from possible_cpu_arch_ids, Bibo Mao, 2025/01/06