From: Xu Lu <luxu.kernel@bytedance.com>
To: tjeznach@rivosinc.com, joro@8bytes.org, will@kernel.org,
robin.murphy@arm.com, alex@ghiti.fr
Cc: lihangjing@bytedance.com, xieyongji@bytedance.com,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
iommu@lists.linux.dev, Xu Lu <luxu.kernel@bytedance.com>
Subject: [PATCH] iommu: riscv: Split 8-byte accesses on 32 bit I/O bus platform
Date: Tue, 25 Mar 2025 22:42:52 +0800 [thread overview]
Message-ID: <20250325144252.27403-1-luxu.kernel@bytedance.com> (raw)
Introduce a new configuration CONFIG_RISCV_IOMMU_32BIT to enable
splitting 8-byte access into 4-byte transactions for hardware platform
whose I/O bus limits access to 4-byte transfers.
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
drivers/iommu/riscv/Kconfig | 9 +++++++++
drivers/iommu/riscv/iommu.h | 28 +++++++++++++++++++++++-----
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/riscv/Kconfig b/drivers/iommu/riscv/Kconfig
index c071816f59a6..b7c9ea22d969 100644
--- a/drivers/iommu/riscv/Kconfig
+++ b/drivers/iommu/riscv/Kconfig
@@ -18,3 +18,12 @@ config RISCV_IOMMU_PCI
def_bool y if RISCV_IOMMU && PCI_MSI
help
Support for the PCIe implementation of RISC-V IOMMU architecture.
+
+config RISCV_IOMMU_32BIT
+ bool "Support 4-Byte Accesses on RISC-V IOMMU Registers"
+ depends on RISCV_IOMMU
+ default n
+ help
+ Support hardware platform whose I/O bus limits access to 4-byte
+ transfers. When enabled, all accesses to IOMMU registers will be
+ split into 4-byte accesses.
diff --git a/drivers/iommu/riscv/iommu.h b/drivers/iommu/riscv/iommu.h
index 46df79dd5495..0e3552a8142d 100644
--- a/drivers/iommu/riscv/iommu.h
+++ b/drivers/iommu/riscv/iommu.h
@@ -14,6 +14,10 @@
#include <linux/iommu.h>
#include <linux/types.h>
#include <linux/iopoll.h>
+#ifdef CONFIG_RISCV_IOMMU_32BIT
+#include <linux/io-64-nonatomic-hi-lo.h>
+#include <linux/io-64-nonatomic-lo-hi.h>
+#endif
#include "iommu-bits.h"
@@ -69,21 +73,35 @@ void riscv_iommu_disable(struct riscv_iommu_device *iommu);
#define riscv_iommu_readl(iommu, addr) \
readl_relaxed((iommu)->reg + (addr))
-#define riscv_iommu_readq(iommu, addr) \
- readq_relaxed((iommu)->reg + (addr))
-
#define riscv_iommu_writel(iommu, addr, val) \
writel_relaxed((val), (iommu)->reg + (addr))
+#define riscv_iommu_readl_timeout(iommu, addr, val, cond, delay_us, timeout_us) \
+ readx_poll_timeout(readl_relaxed, (iommu)->reg + (addr), val, cond, \
+ delay_us, timeout_us)
+
+#ifndef CONFIG_RISCV_IOMMU_32BIT
+#define riscv_iommu_readq(iommu, addr) \
+ readq_relaxed((iommu)->reg + (addr))
+
#define riscv_iommu_writeq(iommu, addr, val) \
writeq_relaxed((val), (iommu)->reg + (addr))
#define riscv_iommu_readq_timeout(iommu, addr, val, cond, delay_us, timeout_us) \
readx_poll_timeout(readq_relaxed, (iommu)->reg + (addr), val, cond, \
delay_us, timeout_us)
+#else /* CONFIG_RISCV_IOMMU_32BIT */
+#define riscv_iommu_readq(iommu, addr) \
+ hi_lo_readq_relaxed((iommu)->reg + (addr))
-#define riscv_iommu_readl_timeout(iommu, addr, val, cond, delay_us, timeout_us) \
- readx_poll_timeout(readl_relaxed, (iommu)->reg + (addr), val, cond, \
+#define riscv_iommu_writeq(iommu, addr, val) \
+ ((addr == RISCV_IOMMU_REG_IOHPMCYCLES) ? \
+ lo_hi_writeq_relaxed((val), (iommu)->reg + (addr)) : \
+ hi_lo_writeq_relaxed((val), (iommu)->reg + (addr)))
+
+#define riscv_iommu_readq_timeout(iommu, addr, val, cond, delay_us, timeout_us) \
+ readx_poll_timeout(hi_lo_readq_relaxed, (iommu)->reg + (addr), val, cond, \
delay_us, timeout_us)
+#endif /* CONFIG_RISCV_IOMMU_32BIT */
#endif
--
2.20.1
next reply other threads:[~2025-03-25 14:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 14:42 Xu Lu [this message]
2025-03-25 18:50 ` [PATCH] iommu: riscv: Split 8-byte accesses on 32 bit I/O bus platform Jessica Clarke
2025-03-26 3:26 ` [External] " Xu Lu
2025-04-01 15:44 ` Jason Gunthorpe
2025-04-01 21:02 ` David Laight
2025-04-02 12:20 ` Xu Lu
2025-04-02 11:28 ` Robin Murphy
2025-04-02 11:58 ` [External] " Xu Lu
2025-04-02 13:00 ` David Laight
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=20250325144252.27403-1-luxu.kernel@bytedance.com \
--to=luxu.kernel@bytedance.com \
--cc=alex@ghiti.fr \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=lihangjing@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=robin.murphy@arm.com \
--cc=tjeznach@rivosinc.com \
--cc=will@kernel.org \
--cc=xieyongji@bytedance.com \
/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