mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ACPI: RISC-V: Set up DMA ranges from _DMA
@ 2026-12-02  1:53 Jianjun Wang
  0 siblings, 0 replies; only message in thread
From: Jianjun Wang @ 2026-12-02  1:53 UTC (permalink / raw)
  To: Sunil V L
  Cc: Rafael J . Wysocki, Len Brown, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, linux-acpi, linux-riscv,
	linux-kernel, jianjun.wang, yanhui.wjj

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02  1:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  1:53 [PATCH] ACPI: RISC-V: Set up DMA ranges from _DMA Jianjun Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®