Skip to contentSkip to conversation

a few trivial dma-mapping header cleanups

PATCH In review Christoph Hellwig 3 participants 7 messages Sep 22, 2020 – Sep 25, 2020

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH 1/3 dma-mapping: remove DMA_MASK_NONE

This value is only used by a PCMCIA driver and not very useful.

---
 drivers/pcmcia/ds.c         | 2 +-
 include/linux/dma-mapping.h | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)
drivers/pcmcia/ds.c +1 -1
index 09d06b082f8b8c..72114907c0e4d2 100644
@@ -516,7 +516,7 @@ static struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
 	p_dev->dev.parent = s->dev.parent;
 	p_dev->dev.release = pcmcia_release_dev;
 	/* by default don't allow DMA */
-	p_dev->dma_mask = DMA_MASK_NONE;
+	p_dev->dma_mask = 0;
 	p_dev->dev.dma_mask = &p_dev->dma_mask;
 	dev_set_name(&p_dev->dev, "%d.%d", p_dev->socket->sock, p_dev->device_no);
 	if (!dev_name(&p_dev->dev))
include/linux/dma-mapping.h +0 -2
index bb138ac6f5e63e..e074588d753ff6 100644
@@ -138,8 +138,6 @@ extern const struct dma_map_ops dma_dummy_ops;
 
 #define DMA_BIT_MASK(n)	(((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
 
-#define DMA_MASK_NONE	0x0ULL
-
 static inline int valid_dma_direction(int dma_direction)
 {
 	return ((dma_direction == DMA_BIDIRECTIONAL) ||
Signature · 6 lines
2.28.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#3 lore raw

PATCH 2/3 dma-mapping: move valid_dma_direction to dma-direction.h

In reply to Christoph Hellwig

Move the valid_dma_direction helper to a more suitable header, and clean it up to use the proper enum as well as removing pointless braces.

---
 include/linux/dma-direction.h | 8 +++++++-
 include/linux/dma-mapping.h   | 7 -------
 2 files changed, 7 insertions(+), 8 deletions(-)
include/linux/dma-direction.h +7 -1
index 9c96e30e6a0bb0..a2fe4571bc9279 100644
@@ -9,4 +9,10 @@ enum dma_data_direction {
 	DMA_NONE = 3,
 };
 
-#endif
+static inline int valid_dma_direction(enum dma_data_direction dir)
+{
+	return dir == DMA_BIDIRECTIONAL || dir == DMA_TO_DEVICE ||
+		dir == DMA_FROM_DEVICE;
+}
+
+#endif /* _LINUX_DMA_DIRECTION_H */
include/linux/dma-mapping.h +0 -7
index e074588d753ff6..51e93d44b826c8 100644
@@ -138,13 +138,6 @@ extern const struct dma_map_ops dma_dummy_ops;
 
 #define DMA_BIT_MASK(n)	(((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
 
-static inline int valid_dma_direction(int dma_direction)
-{
-	return ((dma_direction == DMA_BIDIRECTIONAL) ||
-		(dma_direction == DMA_TO_DEVICE) ||
-		(dma_direction == DMA_FROM_DEVICE));
-}
-
 #ifdef CONFIG_DMA_DECLARE_COHERENT
 /*
  * These three functions are only for dma allocator.
Signature · 6 lines
2.28.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#4 lore raw

PATCH 3/3 dma-mapping: better document dma_addr_t and DMA_MAPPING_ERROR

In reply to Christoph Hellwig

Move the comment documenting dma_addr_t away from the dma_map_ops definition which isn't very related to it, and toward DMA_MAPPING_ERROR, which is somewhat related. Add a little blurb about DMA_MAPPING_ERROR as well.

---
 include/linux/dma-mapping.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
include/linux/dma-mapping.h +10 -6
index 51e93d44b826c8..c4395cf7e265dd 100644
@@ -67,12 +67,6 @@
  */
 #define DMA_ATTR_PRIVILEGED		(1UL << 9)
 
-/*
- * A dma_addr_t can hold any valid DMA or bus address for the platform.
- * It can be given to a device to use as a DMA source or target.  A CPU cannot
- * reference a dma_addr_t directly because there may be translation between
- * its physical address space and the bus address space.
- */
 struct dma_map_ops {
 	void* (*alloc)(struct device *dev, size_t size,
 				dma_addr_t *dma_handle, gfp_t gfp,
@@ -131,6 +125,16 @@ struct dma_map_ops {
 	unsigned long (*get_merge_boundary)(struct device *dev);
 };
 
+/*
+ * A dma_addr_t can hold any valid DMA or bus address for the platform.  It can
+ * be given to a device to use as a DMA source or target.  A CPU cannot
+ * reference a dma_addr_t directly because there may be translation between its
+ * physical address space and the bus address space.
+ *
+ * DMA_MAPPING_ERROR is the magic error code if a mapping failed.  It should not
+ * be used directly in drivers, but checked for using dma_mapping_error()
+ * instead.
+ */
 #define DMA_MAPPING_ERROR		(~(dma_addr_t)0)
 
 extern const struct dma_map_ops dma_virt_ops;
Signature · 1 line
2.28.0
#5 lore raw

RE: [PATCH 3/3] dma-mapping: better document dma_addr_t and DMA_MAPPING_ERROR

From: Christoph Hellwig

Quoted 1 line

Sent: 22 September 2020 14:40

...

include/linux/dma-mapping.h struct dma_map_ops { · line 132

Quoted 9 lines
include/linux/dma-mapping.h +5 -0
@@ -131,6 +125,16 @@ struct dma_map_ops {
 	unsigned long (*get_merge_boundary)(struct device *dev);
 };
 
+/*
+ * A dma_addr_t can hold any valid DMA or bus address for the platform.  It can
+ * be given to a device to use as a DMA source or target.  A CPU cannot
+ * reference a dma_addr_t directly because there may be translation between its
+ * physical address space and the bus address space.

It can't access it 'directly' because it isn't a virtual address....

include/linux/dma-mapping.h struct dma_map_ops { · line 137

Quoted 5 lines
include/linux/dma-mapping.h +5 -0
+ *
+ * DMA_MAPPING_ERROR is the magic error code if a mapping failed.  It should not
+ * be used directly in drivers, but checked for using dma_mapping_error()
+ * instead.
+ */

I think it might be worth adding:

A dma_addr_t value may be device dependant and differ from the 'physical address' of the memory.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#6 lore raw

Re: [PATCH 3/3] dma-mapping: better document dma_addr_t and DMA_MAPPING_ERROR

Quoted 14 lines · David Laight
Quoted 5 lines

+/*
+ * A dma_addr_t can hold any valid DMA or bus address for the platform. It can
+ * be given to a device to use as a DMA source or target. A CPU cannot
+ * reference a dma_addr_t directly because there may be translation between its
+ * physical address space and the bus address space.

It can't access it 'directly' because it isn't a virtual address....

Quoted 5 lines

+ *
+ * DMA_MAPPING_ERROR is the magic error code if a mapping failed. It should not
+ * be used directly in drivers, but checked for using dma_mapping_error()
+ * instead.
+ */

Quoted 4 lines

I think it might be worth adding:

A dma_addr_t value may be device dependant and differ from the 'physical address' of the memory.

This is what I've committed:

* A dma_addr_t can hold any valid DMA or bus address for the platform. It can
* be given to a device to use as a DMA source or target. It is specific to a
* given device and there may be a translation between the CPU physical address
* space and the bus address space.