qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 25/26] hw/intc/loongson_ipi: Implement IOCSR address space for MIPS
Date: Wed,  8 May 2024 19:45:09 +0200	[thread overview]
Message-ID: <20240508174510.60470-26-philmd@linaro.org> (raw)
In-Reply-To: <20240508174510.60470-1-philmd@linaro.org>

From: Jiaxun Yang <jiaxun.yang@flygoat.com>

Implement IOCSR address space get functions for MIPS/Loongson CPUs.

For MIPS/Loongson without IOCSR (i.e. Loongson-3A1000), get_cpu_iocsr_as
will return as null, and send_ipi_data will fail with MEMTX_DECODE_ERROR,
which matches expected behavior on hardware.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20240508-loongson3-ipi-v1-3-1a7b67704664@flygoat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/intc/loongson_ipi.c | 39 ++++++++++++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 9 deletions(-)

diff --git a/hw/intc/loongson_ipi.c b/hw/intc/loongson_ipi.c
index 8c888da3b2..93cc50a37a 100644
--- a/hw/intc/loongson_ipi.c
+++ b/hw/intc/loongson_ipi.c
@@ -15,7 +15,12 @@
 #include "qemu/log.h"
 #include "exec/address-spaces.h"
 #include "migration/vmstate.h"
+#ifdef TARGET_LOONGARCH64
 #include "target/loongarch/cpu.h"
+#endif
+#ifdef TARGET_MIPS
+#include "target/mips/cpu.h"
+#endif
 #include "trace.h"
 
 static MemTxResult loongson_ipi_readl(void *opaque, hwaddr addr,
@@ -56,18 +61,35 @@ static MemTxResult loongson_ipi_readl(void *opaque, hwaddr addr,
     return MEMTX_OK;
 }
 
-static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr,
+static AddressSpace *get_cpu_iocsr_as(CPUState *cpu)
+{
+#ifdef TARGET_LOONGARCH64
+    return LOONGARCH_CPU(cpu)->env.address_space_iocsr;
+#endif
+#ifdef TARGET_MIPS
+    if (ase_lcsr_available(&MIPS_CPU(cpu)->env)) {
+        return &MIPS_CPU(cpu)->env.iocsr.as;
+    }
+#endif
+    return NULL;
+}
+
+static MemTxResult send_ipi_data(CPUState *cpu, uint64_t val, hwaddr addr,
                           MemTxAttrs attrs)
 {
     int i, mask = 0, data = 0;
+    AddressSpace *iocsr_as = get_cpu_iocsr_as(cpu);
+
+    if (!iocsr_as) {
+        return MEMTX_DECODE_ERROR;
+    }
 
     /*
      * bit 27-30 is mask for byte writing,
      * if the mask is 0, we need not to do anything.
      */
     if ((val >> 27) & 0xf) {
-        data = address_space_ldl(env->address_space_iocsr, addr,
-                                 attrs, NULL);
+        data = address_space_ldl(iocsr_as, addr, attrs, NULL);
         for (i = 0; i < 4; i++) {
             /* get mask for byte writing */
             if (val & (0x1 << (27 + i))) {
@@ -78,8 +100,9 @@ static void send_ipi_data(CPULoongArchState *env, uint64_t val, hwaddr addr,
 
     data &= mask;
     data |= (val >> 32) & ~mask;
-    address_space_stl(env->address_space_iocsr, addr,
-                      data, attrs, NULL);
+    address_space_stl(iocsr_as, addr, data, attrs, NULL);
+
+    return MEMTX_OK;
 }
 
 static int archid_cmp(const void *a, const void *b)
@@ -130,8 +153,7 @@ static MemTxResult mail_send(uint64_t val, MemTxAttrs attrs)
     /* override requester_id */
     addr = SMP_IPI_MAILBOX + CORE_BUF_20 + (val & 0x1c);
     attrs.requester_id = cs->cpu_index;
-    send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs);
-    return MEMTX_OK;
+    return send_ipi_data(cs, val, addr, attrs);
 }
 
 static MemTxResult any_send(uint64_t val, MemTxAttrs attrs)
@@ -149,8 +171,7 @@ static MemTxResult any_send(uint64_t val, MemTxAttrs attrs)
     /* override requester_id */
     addr = val & 0xffff;
     attrs.requester_id = cs->cpu_index;
-    send_ipi_data(&LOONGARCH_CPU(cs)->env, val, addr, attrs);
-    return MEMTX_OK;
+    return send_ipi_data(cs, val, addr, attrs);
 }
 
 static MemTxResult loongson_ipi_writel(void *opaque, hwaddr addr, uint64_t val,
-- 
2.41.0



  parent reply	other threads:[~2024-05-08 17:48 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 17:44 [PULL 00/26] Misc HW patches for 2024-05-08 Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 01/26] block/qcow2-bitmap: Replace g_memdup() by g_memdup2() Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 02/26] target/ppc: " Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 03/26] hw/hppa/machine: " Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 04/26] hw/ppc/spapr_pci: " Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 05/26] hw/remote/vfio-user: Fix config space access byte order Philippe Mathieu-Daudé
2024-05-10  8:18   ` Michael Tokarev
2024-05-10  9:54     ` Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 06/26] system/physmem: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 07/26] system/physmem: Propagate AddressSpace to MapClient helpers Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 08/26] system/physmem: Per-AddressSpace bounce buffering Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 09/26] hw/i386/pc: Allow to compile without CONFIG_FDC_ISA Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 10/26] hw/i386/Kconfig: Allow to compile Q35 without FDC_ISA Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 11/26] hw/i386: Add the possibility to use i440fx and isapc without FDC Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 12/26] hw/i386/x86: Eliminate two if statements in x86_bios_rom_init() Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 13/26] hw/i386: Have x86_bios_rom_init() take X86MachineState rather than MachineState Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 14/26] hw/i386/x86: Don't leak "isa-bios" memory regions Philippe Mathieu-Daudé
2024-05-08 17:44 ` [PULL 15/26] hw/usb/dev-network: Remove unused struct 'rndis_config_parameter' Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 16/26] hw/gpio: Handle clock migration in STM32L4x5 gpios Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 17/26] hw/ppc: Deprecate 'ref405ep' machine and 405 CPUs Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 18/26] hw/loongarch: move memory map to boot.c Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 19/26] hw/loongarch/virt: Fix memory leak Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 20/26] hw/loongarch: Rename LOONGARCH_MACHINE with LOONGARCH_VIRT_MACHINE Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 21/26] hw/loongarch: Rename LoongArchMachineState with LoongArchVirtMachineState Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 22/26] hw/mips/loongson3_virt: Emulate suspend function Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 23/26] hw/intc/loongarch_ipi: Remove pointless MAX_CPU check Philippe Mathieu-Daudé
2024-05-08 17:45 ` [PULL 24/26] hw/intc/loongarch_ipi: Rename as loongson_ipi Philippe Mathieu-Daudé
2024-05-08 17:45 ` Philippe Mathieu-Daudé [this message]
2024-05-08 17:45 ` [PULL 26/26] misc: Use QEMU header path relative to include/ directory Philippe Mathieu-Daudé

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=20240508174510.60470-26-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=qemu-devel@nongnu.org \
    /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).