Skip to content

dma: dma_{un}map_{single|sg}_attrs() interface

[email protected] lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest4 patches 5 repliesIn review
  2. v33 patches 19 repliesSuperseded
  3. v21 of 3 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v14 patches7 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4dma: document dma_{un}map_{single|sg}_attrs() interfaceDocumentation/DMA-API.txt Documentation/DMA-attributes.txt+89 -01 reply
2/4swiotlb: introduce swiotlb_*_attrs() functionslib/swiotlb.c+42 -80 replies
3/4dma/ia64: update ia64 machvecsarch/ia64/hp/common/hwsw_iommu.c arch/ia64/hp/common/sba_iommu.c arch/ia64/sn/pci/pci_dma.c +5 more+213 -1250 replies
4/4IB: expand ib_umem_get() prototypedrivers/infiniband/core/umem.c drivers/infiniband/hw/amso1100/c2_provider.c drivers/infiniband/hw/cxgb3/iwch_provider.c +11 more+74 -180 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchJesse BarnesGrant Grundler
SeriesA-b
1/4A-b A-b
2/4A-b
3/4A-b
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH 0/4 v4] dma: dma_{un}map_{single|sg}_attrs() interface

v3-v4 changes:

slight reorganization: split off one arch-independent patch, and moved both new include/linux/*.h files to the first patch in the series.

changed the name DMA_ATTR_SYNC_ON_WRITE to DMA_ATTR_BARRIER.

describe the semantics of DMA_ATTR_BARRIER in a very general, architecture-neutral way.

---
Introduce a new interface for passing architecture-specific attributes when memory is mapped and unmapped for DMA. Give the interface a default implementation which ignores attributes. Also introduce the dma_{set|get}_attr() interface for setting and retrieving individual attributes. Define one attribute DMA_ATTR_BARRIER in anticipation of its use by ia64/sn.

---

 dma-attrs.h   |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dma-mapping.h |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
include/linux/dma-attrs.h +55 -0
index e69de29..05b6e91 100644
@@ -0,0 +1,55 @@
+#ifndef _DMA_ATTR_H
+#define _DMA_ATTR_H
+
+enum dma_attr {
+	DMA_ATTR_BARRIER,
+	DMA_ATTR_MAX,
+};
+
+struct dma_attrs {
+	unsigned flags;
+};
+
+#define __DMA_ATTRS_INIT() { .flags = 0, }
+
+#define DECLARE_DMA_ATTRS(x) struct dma_attrs x = __DMA_ATTRS_INIT()
+
+#define INIT_DMA_ATTRS(x) (x)->flags = 0;
+
+#ifdef ARCH_USES_DMA_ATTRS
+/*
+ * dma_set_attr - set a specific attribute
+ * may be called with a null attrs
+ */
+static inline int dma_set_attr(struct dma_attrs *attrs, enum dma_attr attr)
+{
+	if (!attrs)
+		return 0;
+	if (attr < DMA_ATTR_MAX) {
+		attrs->flags |= (1 << attr);
+		return 0;
+	}
+	return -EINVAL;
+}
+
+/*
+ * dma_get_attr - check for a specific attribute
+ * may be called with a null attrs
+ */
+static inline int dma_get_attr(struct dma_attrs *attrs, enum dma_attr attr)
+{
+	if (!attrs)
+		return 0;
+	if (attr < DMA_ATTR_MAX) {
+		int ret = attrs->flags & (1 << attr);
+		return !!ret;
+	}
+	return -EINVAL;
+}
+#else /* !ARCH_USES_DMA_ATTRS */
+static inline int dma_set_attr(struct dma_attrs *attrs, enum dma_attr attr)
+{
+	return 0;
+}
+#endif /* ARCH_USES_DMA_ATTRS */
+#endif /* _DMA_ATTR_H */
include/linux/dma-mapping.h +35 -0
index 3320307..5a0e924 100644
@@ -146,4 +146,39 @@ static inline void dmam_release_declared_memory(struct device *dev)
 }
 #endif /* ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY */
 
+#ifndef ARCH_USES_DMA_ATTRS
+struct dma_attrs;
+
+static inline dma_addr_t dma_map_single_attrs(struct device *dev,
+					      void *cpu_addr, size_t size,
+					      enum dma_data_direction dir,
+					      struct dma_attrs *attrs)
+{
+	return dma_map_single(dev, cpu_addr, size, dir);
+}
+
+static inline void dma_unmap_single_attrs(struct device *dev,
+					  dma_addr_t dma_addr, size_t size,
+					  enum dma_data_direction dir,
+					  struct dma_attrs *attrs)
+{
+	return dma_unmap_single(dev, dma_addr, size, dir);
+}
+
+static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
+				   int nents, enum dma_data_direction dir,
+				   struct dma_attrs *attrs)
+{
+	return dma_map_sg(dev, sgl, nents, dir);
+}
+
+static inline void dma_unmap_sg_attrs(struct device *dev,
+				      struct scatterlist *sgl, int nents,
+				      enum dma_data_direction dir,
+				      struct dma_attrs *attrs)
+{
+	return dma_unmap_sg(dev, sgl, nents, dir);
+}
+#endif /* ARCH_USES_DMA_ATTRS */
+
 #endif