mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-19 08:02:15 -06:00
hw/intc/loongarch_ipi: Use alternative implemation for cpu_by_arch_id
There is arch_id and CPUState pointer in IPICore object. With function cpu_by_arch_id() it can be implemented by parsing IPICore array inside, rather than possible_cpus array. Signed-off-by: Bibo Mao <maobibo@loongson.cn> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
This commit is contained in:
parent
999b112d90
commit
bb81f23740
1 changed files with 11 additions and 25 deletions
|
@ -17,43 +17,29 @@ static AddressSpace *get_iocsr_as(CPUState *cpu)
|
||||||
return LOONGARCH_CPU(cpu)->env.address_space_iocsr;
|
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;
|
IPICore *ipi_a = (IPICore *)a;
|
||||||
CPUArchId *archid_b = (CPUArchId *)b;
|
IPICore *ipi_b = (IPICore *)b;
|
||||||
|
|
||||||
return archid_a->arch_id - archid_b->arch_id;
|
return ipi_a->arch_id - ipi_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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics,
|
static int loongarch_cpu_by_arch_id(LoongsonIPICommonState *lics,
|
||||||
int64_t arch_id, int *index, CPUState **pcs)
|
int64_t arch_id, int *index, CPUState **pcs)
|
||||||
{
|
{
|
||||||
MachineState *machine = MACHINE(qdev_get_machine());
|
IPICore ipi, *found;
|
||||||
CPUArchId *archid;
|
|
||||||
CPUState *cs;
|
|
||||||
|
|
||||||
archid = find_cpu_by_archid(machine, arch_id);
|
ipi.arch_id = arch_id;
|
||||||
if (archid && archid->cpu) {
|
found = bsearch(&ipi, lics->cpu, lics->num_cpu, sizeof(IPICore),
|
||||||
cs = archid->cpu;
|
loongarch_ipi_cmp);
|
||||||
|
if (found && found->cpu) {
|
||||||
if (index) {
|
if (index) {
|
||||||
*index = cs->cpu_index;
|
*index = found - lics->cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pcs) {
|
if (pcs) {
|
||||||
*pcs = cs;
|
*pcs = found->cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MEMTX_OK;
|
return MEMTX_OK;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue