On 26/05/2023 8:22 pm, Catalin Marinas wrote:
On Sat, May 27, 2023 at 12:36:30AM +0800, Jisheng Zhang wrote:
On Wed, May 24, 2023 at 06:19:02PM +0100, Catalin Marinas wrote:
diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index 87aaf8b5cdb4..330a157c5501 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -248,6 +248,29 @@ static inline void sg_unmark_end(struct scatterlist *sg)
sg->page_link &= ~SG_END;
}
+#define SG_DMA_BUS_ADDRESS (1 << 0)
+#define SG_DMA_USE_SWIOTLB (1 << 1)
+
+#ifdef CONFIG_SWIOTLB
s/CONFIG_SWIOTLB/CONFIG_NEED_SG_DMA_FLAGS ?
Otherwise, there's compiler error if SWIOTLB=y but IOMMU=n
Yes, I pushed a fixup to the kmalloc-minalign branch.
I'd agree that CONFIG_NEED_SG_DMA_FLAGS is the better option.
+static inline bool sg_is_dma_use_swiotlb(struct scatterlist *sg)
+{
+ return sg->dma_flags & SG_DMA_USE_SWIOTLB;
+}
+
+static inline void sg_dma_mark_use_swiotlb(struct scatterlist *sg)
+{
+ sg->dma_flags |= SG_DMA_USE_SWIOTLB;
+}
+#else
+static inline bool sg_is_dma_use_swiotlb(struct scatterlist *sg)
+{
+ return false;
+}
+static inline void sg_dma_mark_use_swiotlb(struct scatterlist *sg)
+{
+}
+#endif
And I wonder whether we should keep these accessors in the scatterlist.h
file. They are only used by the dma-iommu.c code.
Nah, logically they belong with the definition of the flag itself, which
certainly should be here. Also once this does land, dma-direct and
possibly others will be able to take advantage if it too (as a small win
over repeating the is_swiotlb_buffer() check a lot).
Thanks,
Robin.