From: Jianjun Wang <jianjun.wang@linux.alibaba.com>
To: Sunil V L <sunilvl@ventanamicro.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-acpi@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, jianjun.wang@linux.alibaba.com,
yanhui.wjj@alibaba-inc.com
Subject: [PATCH] ACPI: RISC-V: Set up DMA ranges from _DMA
Date: Wed, 2 Dec 2026 09:53:03 +0800 [thread overview]
Message-ID: <20261202015303.5695-1-jianjun.wang@linux.alibaba.com> (raw)
RISC-V uses the empty acpi_arch_dma_setup() stub and does not install
DMA range maps from _DMA. On systems where a host bridge translates
DMA addresses, dma-direct therefore lacks the translation between
CPU physical addresses and device-visible DMA addresses.
Implement the RISC-V hook using acpi_dma_get_range(). Install the
returned map, set bus_dma_limit to the highest DMA address covered
by the windows, and constrain the existing streaming and coherent
DMA masks without widening them.
Preserve an existing map across repeated DMA configuration calls.
Leave the addressing configuration unchanged when no map is returned.
Signed-off-by: Jianjun Wang <jianjun.wang@linux.alibaba.com>
---
drivers/acpi/riscv/Makefile | 2 +-
drivers/acpi/riscv/dma.c | 32 ++++++++++++++++++++++++++++++++
include/linux/acpi.h | 2 +-
3 files changed, 34 insertions(+), 2 deletions(-)
create mode 100644 drivers/acpi/riscv/dma.c
diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile
index 1284a076fa88..779d654bb0ee 100644
--- a/drivers/acpi/riscv/Makefile
+++ b/drivers/acpi/riscv/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
-obj-y += rhct.o init.o irq.o
+obj-y += rhct.o init.o irq.o dma.o
obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o
obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o
obj-$(CONFIG_ACPI_RIMT) += rimt.o
diff --git a/drivers/acpi/riscv/dma.c b/drivers/acpi/riscv/dma.c
new file mode 100644
index 000000000000..7caac6f56fe4
--- /dev/null
+++ b/drivers/acpi/riscv/dma.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/dma-direct.h>
+
+void acpi_arch_dma_setup(struct device *dev)
+{
+ const struct bus_dma_region *map = NULL;
+ u64 end, mask;
+ int ret;
+
+ if (dev->dma_range_map) {
+ dev_dbg(dev, "dma_range_map already set\n");
+ return;
+ }
+
+ ret = acpi_dma_get_range(dev, &map);
+ if (ret || !map)
+ return;
+
+ if (!dev->dma_mask) {
+ dev_warn(dev, "DMA mask not set\n");
+ dev->dma_mask = &dev->coherent_dma_mask;
+ }
+
+ end = dma_range_map_max(map);
+ mask = DMA_BIT_MASK(ilog2(end) + 1);
+ dev->bus_dma_limit = end;
+ dev->dma_range_map = map;
+ dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
+ *dev->dma_mask = min(*dev->dma_mask, mask);
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9d3f039ebd94..ecca64f2cdd4 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -266,7 +266,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { }
void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
-#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
+#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV)
void acpi_arch_dma_setup(struct device *dev);
#else
static inline void acpi_arch_dma_setup(struct device *dev) { }
--
2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Jianjun Wang <jianjun.wang@linux.alibaba.com>
To: Sunil V L <sunilvl@ventanamicro.com>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-acpi@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org, jianjun.wang@linux.alibaba.com,
yanhui.wjj@alibaba-inc.com
Subject: [PATCH] ACPI: RISC-V: Set up DMA ranges from _DMA
Date: Wed, 2 Dec 2026 09:53:03 +0800 [thread overview]
Message-ID: <20261202015303.5695-1-jianjun.wang@linux.alibaba.com> (raw)
RISC-V uses the empty acpi_arch_dma_setup() stub and does not install
DMA range maps from _DMA. On systems where a host bridge translates
DMA addresses, dma-direct therefore lacks the translation between
CPU physical addresses and device-visible DMA addresses.
Implement the RISC-V hook using acpi_dma_get_range(). Install the
returned map, set bus_dma_limit to the highest DMA address covered
by the windows, and constrain the existing streaming and coherent
DMA masks without widening them.
Preserve an existing map across repeated DMA configuration calls.
Leave the addressing configuration unchanged when no map is returned.
Signed-off-by: Jianjun Wang <jianjun.wang@linux.alibaba.com>
---
drivers/acpi/riscv/Makefile | 2 +-
drivers/acpi/riscv/dma.c | 32 ++++++++++++++++++++++++++++++++
include/linux/acpi.h | 2 +-
3 files changed, 34 insertions(+), 2 deletions(-)
create mode 100644 drivers/acpi/riscv/dma.c
diff --git a/drivers/acpi/riscv/Makefile b/drivers/acpi/riscv/Makefile
index 1284a076fa88..779d654bb0ee 100644
--- a/drivers/acpi/riscv/Makefile
+++ b/drivers/acpi/riscv/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
-obj-y += rhct.o init.o irq.o
+obj-y += rhct.o init.o irq.o dma.o
obj-$(CONFIG_ACPI_PROCESSOR_IDLE) += cpuidle.o
obj-$(CONFIG_ACPI_CPPC_LIB) += cppc.o
obj-$(CONFIG_ACPI_RIMT) += rimt.o
diff --git a/drivers/acpi/riscv/dma.c b/drivers/acpi/riscv/dma.c
new file mode 100644
index 000000000000..7caac6f56fe4
--- /dev/null
+++ b/drivers/acpi/riscv/dma.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/dma-direct.h>
+
+void acpi_arch_dma_setup(struct device *dev)
+{
+ const struct bus_dma_region *map = NULL;
+ u64 end, mask;
+ int ret;
+
+ if (dev->dma_range_map) {
+ dev_dbg(dev, "dma_range_map already set\n");
+ return;
+ }
+
+ ret = acpi_dma_get_range(dev, &map);
+ if (ret || !map)
+ return;
+
+ if (!dev->dma_mask) {
+ dev_warn(dev, "DMA mask not set\n");
+ dev->dma_mask = &dev->coherent_dma_mask;
+ }
+
+ end = dma_range_map_max(map);
+ mask = DMA_BIT_MASK(ilog2(end) + 1);
+ dev->bus_dma_limit = end;
+ dev->dma_range_map = map;
+ dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
+ *dev->dma_mask = min(*dev->dma_mask, mask);
+}
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9d3f039ebd94..ecca64f2cdd4 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -266,7 +266,7 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { }
void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
-#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
+#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH) || defined(CONFIG_RISCV)
void acpi_arch_dma_setup(struct device *dev);
#else
static inline void acpi_arch_dma_setup(struct device *dev) { }
--
2.25.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2026-12-02 1:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 1:53 Jianjun Wang [this message]
2026-12-02 1:53 ` [PATCH] ACPI: RISC-V: Set up DMA ranges from _DMA Jianjun Wang
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=20261202015303.5695-1-jianjun.wang@linux.alibaba.com \
--to=jianjun.wang@linux.alibaba.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rafael@kernel.org \
--cc=sunilvl@ventanamicro.com \
--cc=yanhui.wjj@alibaba-inc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.