From nobody Sat Sep 21 08:40:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17049726840241013.4656358860489; Thu, 11 Jan 2024 03:31:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNtFr-0008Dm-Lf; Thu, 11 Jan 2024 06:29:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rNtFS-0007na-Fa for qemu-devel@nongnu.org; Thu, 11 Jan 2024 06:29:22 -0500 Received: from mail.loongson.cn ([114.242.206.163]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNtFO-0006rn-M1 for qemu-devel@nongnu.org; Thu, 11 Jan 2024 06:29:22 -0500 Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8CxrOgB0Z9loD8EAA--.4334S3; Thu, 11 Jan 2024 19:29:05 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx34f80J9l6+4PAA--.41647S13; Thu, 11 Jan 2024 19:29:04 +0800 (CST) From: Song Gao To: Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, Bibo Mao Subject: [PULL 11/14] hw/intc/loongarch_ipi: Use MemTxAttrs interface for ipi ops Date: Thu, 11 Jan 2024 19:16:06 +0800 Message-Id: <20240111111609.899183-12-gaosong@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240111111609.899183-1-gaosong@loongson.cn> References: <20240111111609.899183-1-gaosong@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: AQAAf8Bx34f80J9l6+4PAA--.41647S13 X-CM-SenderInfo: 5jdr20tqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=114.242.206.163; envelope-from=gaosong@loongson.cn; helo=mail.loongson.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1704972684717100001 Content-Type: text/plain; charset="utf-8" From: Bibo Mao There are two interface pairs for MemoryRegionOps, read/write and read_with_attrs/write_with_attrs. The later is better for ipi device emulation since initial cpu can be parsed from attrs.requester_id. And requester_id can be overrided for IOCSR_IPI_SEND and mail_send function when it is to forward message to another vcpu. Signed-off-by: Bibo Mao Reviewed-by: Song Gao Message-Id: <20231215100333.3933632-2-maobibo@loongson.cn> Signed-off-by: Song Gao --- hw/intc/loongarch_ipi.c | 136 +++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 59 deletions(-) diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c index a155c16509..4e104df71b 100644 --- a/hw/intc/loongarch_ipi.c +++ b/hw/intc/loongarch_ipi.c @@ -17,14 +17,16 @@ #include "target/loongarch/internals.h" #include "trace.h" =20 -static void loongarch_ipi_writel(void *, hwaddr, uint64_t, unsigned); - -static uint64_t loongarch_ipi_readl(void *opaque, hwaddr addr, unsigned si= ze) +static MemTxResult loongarch_ipi_readl(void *opaque, hwaddr addr, + uint64_t *data, + unsigned size, MemTxAttrs attrs) { - IPICore *s =3D opaque; + IPICore *s; + LoongArchIPI *ipi =3D opaque; uint64_t ret =3D 0; int index =3D 0; =20 + s =3D &ipi->ipi_core; addr &=3D 0xff; switch (addr) { case CORE_STATUS_OFF: @@ -49,10 +51,12 @@ static uint64_t loongarch_ipi_readl(void *opaque, hwadd= r addr, unsigned size) } =20 trace_loongarch_ipi_read(size, (uint64_t)addr, ret); - return ret; + *data =3D ret; + return MEMTX_OK; } =20 -static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr add= r) +static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr add= r, + MemTxAttrs attrs) { int i, mask =3D 0, data =3D 0; =20 @@ -62,7 +66,7 @@ static void send_ipi_data(CPULoongArchState *env, uint64_= t val, hwaddr addr) */ if ((val >> 27) & 0xf) { data =3D address_space_ldl(&env->address_space_iocsr, addr, - MEMTXATTRS_UNSPECIFIED, NULL); + attrs, NULL); for (i =3D 0; i < 4; i++) { /* get mask for byte writing */ if (val & (0x1 << (27 + i))) { @@ -74,7 +78,7 @@ static void send_ipi_data(CPULoongArchState *env, uint64_= t val, hwaddr addr) data &=3D mask; data |=3D (val >> 32) & ~mask; address_space_stl(&env->address_space_iocsr, addr, - data, MEMTXATTRS_UNSPECIFIED, NULL); + data, attrs, NULL); } =20 static int archid_cmp(const void *a, const void *b) @@ -103,80 +107,72 @@ static CPUState *ipi_getcpu(int arch_id) CPUArchId *archid; =20 archid =3D find_cpu_by_archid(machine, arch_id); - return CPU(archid->cpu); -} - -static void ipi_send(uint64_t val) -{ - uint32_t cpuid; - uint8_t vector; - CPUState *cs; - LoongArchCPU *cpu; - LoongArchIPI *s; - - cpuid =3D extract32(val, 16, 10); - if (cpuid >=3D LOONGARCH_MAX_CPUS) { - trace_loongarch_ipi_unsupported_cpuid("IOCSR_IPI_SEND", cpuid); - return; + if (archid) { + return CPU(archid->cpu); } =20 - /* IPI status vector */ - vector =3D extract8(val, 0, 5); - - cs =3D ipi_getcpu(cpuid); - cpu =3D LOONGARCH_CPU(cs); - s =3D LOONGARCH_IPI(cpu->env.ipistate); - loongarch_ipi_writel(&s->ipi_core, CORE_SET_OFF, BIT(vector), 4); + return NULL; } =20 -static void mail_send(uint64_t val) +static MemTxResult mail_send(uint64_t val, MemTxAttrs attrs) { uint32_t cpuid; hwaddr addr; - CPULoongArchState *env; CPUState *cs; - LoongArchCPU *cpu; =20 cpuid =3D extract32(val, 16, 10); if (cpuid >=3D LOONGARCH_MAX_CPUS) { trace_loongarch_ipi_unsupported_cpuid("IOCSR_MAIL_SEND", cpuid); - return; + return MEMTX_DECODE_ERROR; } =20 - addr =3D 0x1020 + (val & 0x1c); cs =3D ipi_getcpu(cpuid); - cpu =3D LOONGARCH_CPU(cs); - env =3D &cpu->env; - send_ipi_data(env, val, addr); + if (cs =3D=3D NULL) { + return MEMTX_DECODE_ERROR; + } + + /* override requester_id */ + addr =3D SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c); + attrs.requester_id =3D cs->cpu_index; + send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs); + return MEMTX_OK; } =20 -static void any_send(uint64_t val) +static MemTxResult any_send(uint64_t val, MemTxAttrs attrs) { uint32_t cpuid; hwaddr addr; - CPULoongArchState *env; CPUState *cs; - LoongArchCPU *cpu; =20 cpuid =3D extract32(val, 16, 10); if (cpuid >=3D LOONGARCH_MAX_CPUS) { trace_loongarch_ipi_unsupported_cpuid("IOCSR_ANY_SEND", cpuid); - return; + return MEMTX_DECODE_ERROR; } =20 - addr =3D val & 0xffff; cs =3D ipi_getcpu(cpuid); - cpu =3D LOONGARCH_CPU(cs); - env =3D &cpu->env; - send_ipi_data(env, val, addr); + if (cs =3D=3D NULL) { + return MEMTX_DECODE_ERROR; + } + + /* override requester_id */ + addr =3D val & 0xffff; + attrs.requester_id =3D cs->cpu_index; + send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs); + return MEMTX_OK; } =20 -static void loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_t val, - unsigned size) +static MemTxResult loongarch_ipi_writel(void *opaque, hwaddr addr, uint64_= t val, + unsigned size, MemTxAttrs attrs) { - IPICore *s =3D opaque; + LoongArchIPI *ipi =3D opaque; + IPICore *s; int index =3D 0; + uint32_t cpuid; + uint8_t vector; + CPUState *cs; =20 + s =3D &ipi->ipi_core; addr &=3D 0xff; trace_loongarch_ipi_write(size, (uint64_t)addr, val); switch (addr) { @@ -203,17 +199,35 @@ static void loongarch_ipi_writel(void *opaque, hwaddr= addr, uint64_t val, s->buf[index] =3D val; break; case IOCSR_IPI_SEND: - ipi_send(val); + cpuid =3D extract32(val, 16, 10); + if (cpuid >=3D LOONGARCH_MAX_CPUS) { + trace_loongarch_ipi_unsupported_cpuid("IOCSR_IPI_SEND", cpuid); + return MEMTX_DECODE_ERROR; + } + + /* IPI status vector */ + vector =3D extract8(val, 0, 5); + cs =3D ipi_getcpu(cpuid); + if (cs =3D=3D NULL) { + return MEMTX_DECODE_ERROR; + } + + /* override requester_id */ + attrs.requester_id =3D cs->cpu_index; + ipi =3D LOONGARCH_IPI(LOONGARCH_CPU(cs)->env.ipistate); + loongarch_ipi_writel(ipi, CORE_SET_OFF, BIT(vector), 4, attrs); break; default: qemu_log_mask(LOG_UNIMP, "invalid write: %x", (uint32_t)addr); break; } + + return MEMTX_OK; } =20 static const MemoryRegionOps loongarch_ipi_ops =3D { - .read =3D loongarch_ipi_readl, - .write =3D loongarch_ipi_writel, + .read_with_attrs =3D loongarch_ipi_readl, + .write_with_attrs =3D loongarch_ipi_writel, .impl.min_access_size =3D 4, .impl.max_access_size =3D 4, .valid.min_access_size =3D 4, @@ -222,24 +236,28 @@ static const MemoryRegionOps loongarch_ipi_ops =3D { }; =20 /* mail send and any send only support writeq */ -static void loongarch_ipi_writeq(void *opaque, hwaddr addr, uint64_t val, - unsigned size) +static MemTxResult loongarch_ipi_writeq(void *opaque, hwaddr addr, uint64_= t val, + unsigned size, MemTxAttrs attrs) { + MemTxResult ret =3D MEMTX_OK; + addr &=3D 0xfff; switch (addr) { case MAIL_SEND_OFFSET: - mail_send(val); + ret =3D mail_send(val, attrs); break; case ANY_SEND_OFFSET: - any_send(val); + ret =3D any_send(val, attrs); break; default: break; } + + return ret; } =20 static const MemoryRegionOps loongarch_ipi64_ops =3D { - .write =3D loongarch_ipi_writeq, + .write_with_attrs =3D loongarch_ipi_writeq, .impl.min_access_size =3D 8, .impl.max_access_size =3D 8, .valid.min_access_size =3D 8, @@ -253,7 +271,7 @@ static void loongarch_ipi_init(Object *obj) SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); =20 memory_region_init_io(&s->ipi_iocsr_mem, obj, &loongarch_ipi_ops, - &s->ipi_core, "loongarch_ipi_iocsr", 0x48); + s, "loongarch_ipi_iocsr", 0x48); =20 /* loongarch_ipi_iocsr performs re-entrant IO through ipi_send */ s->ipi_iocsr_mem.disable_reentrancy_guard =3D true; @@ -261,7 +279,7 @@ static void loongarch_ipi_init(Object *obj) sysbus_init_mmio(sbd, &s->ipi_iocsr_mem); =20 memory_region_init_io(&s->ipi64_iocsr_mem, obj, &loongarch_ipi64_ops, - &s->ipi_core, "loongarch_ipi64_iocsr", 0x118); + s, "loongarch_ipi64_iocsr", 0x118); sysbus_init_mmio(sbd, &s->ipi64_iocsr_mem); qdev_init_gpio_out(DEVICE(obj), &s->ipi_core.irq, 1); } --=20 2.25.1