From: John Ernberg <john.ernberg@actia.se>
To: Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"imx@lists.linux.dev" <imx@lists.linux.dev>,
John Ernberg <john.ernberg@actia.se>
Subject: [PATCH 2/2] xen: swiotlb: Implement map_resource callback
Date: Fri, 2 May 2025 11:40:56 +0000 [thread overview]
Message-ID: <20250502114043.1968976-3-john.ernberg@actia.se> (raw)
In-Reply-To: <20250502114043.1968976-1-john.ernberg@actia.se>
Needed by the eDMA v3 DMA engine found in iommu-less SoCs such as iMX8QXP
to be able to perform DMA operations as a Xen Hardware Domain, which needs
to be able to do DMA in MMIO space.
The callback implementation is basically the same as the one for direct
mapping of resources, except this also takes into account Xen page
mappings.
There is nothing to do for unmap, just like with direct, so the unmap
callback is not needed.
Signed-off-by: John Ernberg <john.ernberg@actia.se>
---
I originally exported dma_direct_map_resource() and used that which
appeared to work, but it felt like not checking Xen page mappings wasn't
fully correct and I went with this. But if dma_direct_map_resource() is
the correct approach here then I can submit that isntead.
---
drivers/xen/swiotlb-xen.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index ef56a2500ed6..0f02fdd9128d 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -285,6 +285,20 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
attrs, pool);
}
+static dma_addr_t xen_swiotlb_map_resource(struct device *dev, phys_addr_t phys,
+ size_t size, enum dma_data_direction dir,
+ unsigned long attrs)
+{
+ dma_addr_t dev_addr = xen_phys_to_dma(dev, phys);
+
+ BUG_ON(dir == DMA_NONE);
+
+ if (!dma_capable(dev, dev_addr, size, false))
+ return DMA_MAPPING_ERROR;
+
+ return dev_addr;
+}
+
static void
xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr,
size_t size, enum dma_data_direction dir)
@@ -426,4 +440,5 @@ const struct dma_map_ops xen_swiotlb_dma_ops = {
.alloc_pages_op = dma_common_alloc_pages,
.free_pages = dma_common_free_pages,
.max_mapping_size = swiotlb_max_mapping_size,
+ .map_resource = xen_swiotlb_map_resource,
};
--
2.49.0
next prev parent reply other threads:[~2025-05-02 11:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 11:40 [PATCH 0/2] xen: swiotlb: 2 fixes SoCs w/o IOMMU (e.g. iMX8QXP) John Ernberg
2025-05-02 11:40 ` [PATCH 1/2] xen: swiotlb: Use swiotlb bouncing if kmalloc allocation demands it John Ernberg
2025-05-02 17:07 ` Stefano Stabellini
2025-05-08 15:21 ` Catalin Marinas
2025-05-02 11:40 ` John Ernberg [this message]
2025-05-02 17:20 ` [PATCH 2/2] xen: swiotlb: Implement map_resource callback Stefano Stabellini
2025-05-06 12:22 ` John Ernberg
2025-05-07 23:09 ` Stefano Stabellini
2025-05-08 4:14 ` Christoph Hellwig
2025-05-08 23:14 ` Stefano Stabellini
2025-05-09 7:48 ` John Ernberg
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=20250502114043.1968976-3-john.ernberg@actia.se \
--to=john.ernberg@actia.se \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=imx@lists.linux.dev \
--cc=iommu@lists.linux.dev \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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