From: Christoph Hellwig <hch@lst.de>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Helge Deller <deller@gmx.de>
Cc: linux-parisc@vger.kernel.org, iommu@lists.linux.dev
Subject: [PATCH 1/2] dma-mapping: add a arch_can_dma_alloc_coherent hook
Date: Mon, 21 Nov 2022 14:16:22 +0100 [thread overview]
Message-ID: <20221121131623.228727-2-hch@lst.de> (raw)
In-Reply-To: <20221121131623.228727-1-hch@lst.de>
This hook allows an architecture to reject coherent DMA allocations
entirely if they can't be supported. This will be useful to convert
parisc and m68knommu to the generic dma-direct code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/dma-map-ops.h | 1 +
kernel/dma/Kconfig | 3 +++
kernel/dma/direct.c | 4 ++++
3 files changed, 8 insertions(+)
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index d678afeb8a13a..10272f95cdb64 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -344,6 +344,7 @@ static inline void arch_dma_mark_clean(phys_addr_t paddr, size_t size)
}
#endif /* ARCH_HAS_DMA_MARK_CLEAN */
+bool arch_can_dma_alloc_coherent(void);
void *arch_dma_set_uncached(void *addr, size_t size);
void arch_dma_clear_uncached(void *addr, size_t size);
diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig
index 56866aaa2ae1a..6fd4efe71d136 100644
--- a/kernel/dma/Kconfig
+++ b/kernel/dma/Kconfig
@@ -20,6 +20,9 @@ config DMA_OPS
config DMA_OPS_BYPASS
bool
+config ARCH_HAS_CAN_DMA_ALLOC_COHERENT
+ bool
+
# Lets platform IOMMU driver choose between bypass and IOMMU
config ARCH_HAS_DMA_MAP_DIRECT
bool
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 63859a101ed83..03929482e92f7 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -232,6 +232,10 @@ void *dma_direct_alloc(struct device *dev, size_t size,
return arch_dma_alloc(dev, size, dma_handle, gfp,
attrs);
+ if (IS_ENABLED(CONFIG_ARCH_HAS_CAN_DMA_ALLOC_COHERENT) &&
+ !arch_can_dma_alloc_coherent())
+ return NULL;
+
/*
* If there is a global pool, always allocate from it for
* non-coherent devices.
--
2.30.2
next prev parent reply other threads:[~2022-11-21 13:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 13:16 RFC: switch to use the generic remapping dma-allocator Christoph Hellwig
2022-11-21 13:16 ` Christoph Hellwig [this message]
2022-11-21 13:16 ` [PATCH 2/2] parisc: use the generic remapping dma allocator Christoph Hellwig
2022-11-21 14:22 ` RFC: switch to use the generic remapping dma-allocator Helge Deller
2022-11-21 15:30 ` Helge Deller
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=20221121131623.228727-2-hch@lst.de \
--to=hch@lst.de \
--cc=James.Bottomley@HansenPartnership.com \
--cc=deller@gmx.de \
--cc=iommu@lists.linux.dev \
--cc=linux-parisc@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).