From: Song Gao <gaosong@loongson.cn>
To: qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, peter.maydell@linaro.org,
philmd@linaro.org, imammedo@redhat.com, anisinha@redhat.com,
mst@redhat.com, alex.bennee@linaro.org, maobibo@loongson.cn,
yangxiaojuan@loongson.cn
Subject: [PATCH v1 2/2] hw/intc: Set physical cpuid route for LoongArch ipi device
Date: Thu, 18 May 2023 09:41:15 +0800 [thread overview]
Message-ID: <20230518014115.117869-3-gaosong@loongson.cn> (raw)
In-Reply-To: <20230518014115.117869-1-gaosong@loongson.cn>
LoongArch ipi device uses physical cpuid to route to different
vcpus rather logical cpuid, and the physical cpuid is the same
with cpuid in acpi dsdt and srat table.
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
hw/intc/loongarch_ipi.c | 44 ++++++++++++++++++++++++++++++++++-------
hw/loongarch/virt.c | 1 +
target/loongarch/cpu.h | 2 ++
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
index d6ab91721e..e5f396ca75 100644
--- a/hw/intc/loongarch_ipi.c
+++ b/hw/intc/loongarch_ipi.c
@@ -17,6 +17,8 @@
#include "target/loongarch/internals.h"
#include "trace.h"
+static void loongarch_ipi_writel(void *, hwaddr, uint64_t, unsigned);
+
static uint64_t loongarch_ipi_readl(void *opaque, hwaddr addr, unsigned size)
{
IPICore *s = opaque;
@@ -75,13 +77,42 @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr)
data, MEMTXATTRS_UNSPECIFIED, NULL);
}
+static int archid_cmp(const void *a, const void *b)
+{
+ CPUArchId *archid_a = (CPUArchId *)a;
+ CPUArchId *archid_b = (CPUArchId *)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;
+}
+
+static CPUState *ipi_getcpu(int arch_id)
+{
+ MachineState *machine = MACHINE(qdev_get_machine());
+ CPUArchId *archid;
+
+ archid = find_cpu_by_archid(machine, arch_id);
+ return CPU(archid->cpu);
+}
+
static void ipi_send(uint64_t val)
{
uint32_t cpuid;
uint8_t vector;
- CPULoongArchState *env;
CPUState *cs;
LoongArchCPU *cpu;
+ LoongArchIPI *s;
cpuid = extract32(val, 16, 10);
if (cpuid >= LOONGARCH_MAX_CPUS) {
@@ -92,11 +123,10 @@ static void ipi_send(uint64_t val)
/* IPI status vector */
vector = extract8(val, 0, 5);
- cs = qemu_get_cpu(cpuid);
+ cs = ipi_getcpu(cpuid);
cpu = LOONGARCH_CPU(cs);
- env = &cpu->env;
- address_space_stl(&env->address_space_iocsr, 0x1008,
- BIT(vector), MEMTXATTRS_UNSPECIFIED, NULL);
+ s = LOONGARCH_IPI(cpu->env.ipistate);
+ loongarch_ipi_writel(&s->ipi_core, CORE_SET_OFF, BIT(vector), 4);
}
static void mail_send(uint64_t val)
@@ -114,7 +144,7 @@ static void mail_send(uint64_t val)
}
addr = 0x1020 + (val & 0x1c);
- cs = qemu_get_cpu(cpuid);
+ cs = ipi_getcpu(cpuid);
cpu = LOONGARCH_CPU(cs);
env = &cpu->env;
send_ipi_data(env, val, addr);
@@ -135,7 +165,7 @@ static void any_send(uint64_t val)
}
addr = val & 0xffff;
- cs = qemu_get_cpu(cpuid);
+ cs = ipi_getcpu(cpuid);
cpu = LOONGARCH_CPU(cs);
env = &cpu->env;
send_ipi_data(env, val, addr);
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 83c1e43ff5..6e1c42fb2b 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -616,6 +616,7 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
memory_region_add_subregion(&env->system_iocsr, APIC_BASE,
sysbus_mmio_get_region(SYS_BUS_DEVICE(extioi),
cpu));
+ env->ipistate = ipi;
}
/*
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 1f37e36b7c..b23f38c3d5 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -351,6 +351,8 @@ typedef struct CPUArchState {
MemoryRegion iocsr_mem;
bool load_elf;
uint64_t elf_address;
+ /* Store ipistate to access from this struct */
+ DeviceState *ipistate;
#endif
} CPULoongArchState;
--
2.39.1
next prev parent reply other threads:[~2023-05-18 1:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 1:41 [PATCH v1 0/2] Add LoongArch cpu arch_id support Song Gao
2023-05-18 1:41 ` [PATCH v1 1/2] hw/loongarch/virt: Add " Song Gao
2023-05-30 11:53 ` Tianrui Zhao
2023-05-30 12:23 ` Song Gao
2023-05-18 1:41 ` Song Gao [this message]
2023-05-30 8:40 ` [PATCH v1 0/2] Add LoongArch " Song Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230518014115.117869-3-gaosong@loongson.cn \
--to=gaosong@loongson.cn \
--cc=alex.bennee@linaro.org \
--cc=anisinha@redhat.com \
--cc=imammedo@redhat.com \
--cc=maobibo@loongson.cn \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=yangxiaojuan@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).