From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.98 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796176394; b=NfBZRa/LI9hZ15UD6hVmQxicKfRxIgNDMD3dxVwptuerfg9UIohuJYUmuM7xA3Jivsfn sMb1ejoB26Iynzr5CtjyWZs86JY8f6M2LuLLRefINELuhTxXr4VXnBbD9bexRqtWrIEoZ jk+S3CsRZi4biXrQKFVdkCXn9NMx+dja1DeH/JO2T+O3HspV/zduOvbHjy4ktef4ZA3iA trfSevwashlAEyKS1L0hVz6zbAYNWb8YAsww0wI7Icd3xUnKAVF8DzFy0Is1o6yzpw4xm DcjCR4XyvYOS9gpJ8g5YFsZ7ujWa9RVfyUzS9/j+Xk25GfSgnI3sfVBxw81DWQAtdxg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796176394; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=mWXNOvhboE28uuw8KmsuRmOH/B4uUZFEHKsYuEYtdWM=; b=bzPXVg4rmI+mItbDVogDBwNWaau2SXE3xmzaKVXw3UJbVHMIe2szue8REbe6aWgGy3tc eoEzmh1OUaPLjXZrb+TS1ccJLiEbWRQtZBA2+BF1GgsK2p5yi00fryPBROCWtx3/hDr6g c2Slbl1bGYOhPABC/EjNNQzabCq9f5qCx+l6OM0pvrPi69I3lRsEOi3t8uYDxlYB44V8h 8VVwFSTm5yAAKmogx48ziD76KKyDl17Ht0JWTfCUlm6FwhcztZaHO1cDql1A3yrrgmbe5 gVpySl1QI85gG2mqEomIaRIE9JdVa/hWcrgxqHYsYgxi8kNad4jZ+uaRl/8gq7xc+Sg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=Y5I6hodG; arc=none smtp.remote-ip=115.124.30.98 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83F09606A337; Wed, 2 Dec 2026 01:53:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83F09606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=Y5I6hodG DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796176388; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=mWXNOvhboE28uuw8KmsuRmOH/B4uUZFEHKsYuEYtdWM=; b=Y5I6hodGMnfdBP4w6dv5xhivlmVXVZPbNCfP3CzijYLwvgAQz3pzSKo5EbaE39V9LzkSQBF3tA44qsM/wYSAsRvqLJamH04XdLl8TM4HXlHVmYl9rBZf7zsPmQqefr7gZjgG8h+OznLbaOLF2oXtz7JoE47JFoWsA37dDUPN8MU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=jianjun.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0XG53H4O_1796176386; Received: from L-F9NL024XF6(mailfrom:jianjun.wang@linux.alibaba.com fp:SMTPD_---0XG53H4O_1796176386 cluster:ay36) by smtp.aliyun-inc.com; Wed, 02 Dec 2026 09:53:07 +0800 From: Jianjun Wang To: Sunil V L Cc: "Rafael J . Wysocki" , Len Brown , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , 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 Message-ID: <20261202015303.5695-1-jianjun.wang@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 +#include +#include + +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 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4A0E606A31A for ; Wed, 2 Dec 2026 01:53:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=g385POwg; dkim=fail reason="signature verification failed" (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=Y5I6hodG DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=B53CxWrhVDK4P8q0ajzZuTh5XN58sJHXXKbrN6sR3d0=; b=g385POwg7ZyOMonQMy52n9H3S2 YiByXh6bINMiVLwUrrxw3XlZLcbSRIzUzAmdWqZdQDUbztA2iiJ/9x/Qq2MkVeZMGOEal9Z7HOI15 nl/ElIMaXlpufKohoof+3VKI5NQx894rm6AOxUA0dwvwLp/QcHZWU1gjeHf/ZGj7YRlA3mFFAeVGU jGiORfs74n/+UWjM9rpQAsS8rByybpNlZ9H3FtO60kaPYbwcfy1caG1+N73LCGlOHXDbTuWDN9JQV CR9ynXw9qeVyti87WwhO6yi/3f5EwNDrc12G/cEqFy1DfKoZ8b66gQR+S7y3CohHFGWL+eUVZsjLo AywFtJpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYZX3-00000009uxh-2bEI; Wed, 02 Dec 2026 01:53:17 +0000 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYZX0-00000009uxJ-0ySj for linux-riscv@lists.infradead.org; Wed, 02 Dec 2026 01:53:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796176388; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=mWXNOvhboE28uuw8KmsuRmOH/B4uUZFEHKsYuEYtdWM=; b=Y5I6hodGMnfdBP4w6dv5xhivlmVXVZPbNCfP3CzijYLwvgAQz3pzSKo5EbaE39V9LzkSQBF3tA44qsM/wYSAsRvqLJamH04XdLl8TM4HXlHVmYl9rBZf7zsPmQqefr7gZjgG8h+OznLbaOLF2oXtz7JoE47JFoWsA37dDUPN8MU= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=jianjun.wang@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0XG53H4O_1796176386; Received: from L-F9NL024XF6(mailfrom:jianjun.wang@linux.alibaba.com fp:SMTPD_---0XG53H4O_1796176386 cluster:ay36) by smtp.aliyun-inc.com; Wed, 02 Dec 2026 09:53:07 +0800 From: Jianjun Wang To: Sunil V L Cc: "Rafael J . Wysocki" , Len Brown , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , 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 Message-ID: <20261202015303.5695-1-jianjun.wang@linux.alibaba.com> X-Mailer: git-send-email 2.50.1 X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_175314_818189_6037EADA X-CRM114-Status: GOOD ( 13.94 ) X-Spam-Score: -17.6 (-----------------) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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 +#include +#include + +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