* dma-mapping: use bit macros
@ 2019-11-29 20:27 Heiner Kallweit
2019-11-30 8:18 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Heiner Kallweit @ 2019-11-29 20:27 UTC (permalink / raw)
To: Christoph Hellwig, Marek Szyprowski, Robin Murphy
Cc: open list:AMD IOMMU (AMD-VI), Linux Kernel Mailing List
Not necessarily a big leap for mankind, but using bit macros makes
the code better readable, especially the definition of DMA_BIT_MASK
is more intuitive.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
include/linux/dma-mapping.h | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index a4930310d..a39a6a8d5 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -2,6 +2,7 @@
#ifndef _LINUX_DMA_MAPPING_H
#define _LINUX_DMA_MAPPING_H
+#include <linux/bits.h>
#include <linux/sizes.h>
#include <linux/string.h>
#include <linux/device.h>
@@ -21,51 +22,51 @@
* DMA_ATTR_WEAK_ORDERING: Specifies that reads and writes to the mapping
* may be weakly ordered, that is that reads and writes may pass each other.
*/
-#define DMA_ATTR_WEAK_ORDERING (1UL << 1)
+#define DMA_ATTR_WEAK_ORDERING BIT(1)
/*
* DMA_ATTR_WRITE_COMBINE: Specifies that writes to the mapping may be
* buffered to improve performance.
*/
-#define DMA_ATTR_WRITE_COMBINE (1UL << 2)
+#define DMA_ATTR_WRITE_COMBINE BIT(2)
/*
* DMA_ATTR_NON_CONSISTENT: Lets the platform to choose to return either
* consistent or non-consistent memory as it sees fit.
*/
-#define DMA_ATTR_NON_CONSISTENT (1UL << 3)
+#define DMA_ATTR_NON_CONSISTENT BIT(3)
/*
* DMA_ATTR_NO_KERNEL_MAPPING: Lets the platform to avoid creating a kernel
* virtual mapping for the allocated buffer.
*/
-#define DMA_ATTR_NO_KERNEL_MAPPING (1UL << 4)
+#define DMA_ATTR_NO_KERNEL_MAPPING BIT(4)
/*
* DMA_ATTR_SKIP_CPU_SYNC: Allows platform code to skip synchronization of
* the CPU cache for the given buffer assuming that it has been already
* transferred to 'device' domain.
*/
-#define DMA_ATTR_SKIP_CPU_SYNC (1UL << 5)
+#define DMA_ATTR_SKIP_CPU_SYNC BIT(5)
/*
* DMA_ATTR_FORCE_CONTIGUOUS: Forces contiguous allocation of the buffer
* in physical memory.
*/
-#define DMA_ATTR_FORCE_CONTIGUOUS (1UL << 6)
+#define DMA_ATTR_FORCE_CONTIGUOUS BIT(6)
/*
* DMA_ATTR_ALLOC_SINGLE_PAGES: This is a hint to the DMA-mapping subsystem
* that it's probably not worth the time to try to allocate memory to in a way
* that gives better TLB efficiency.
*/
-#define DMA_ATTR_ALLOC_SINGLE_PAGES (1UL << 7)
+#define DMA_ATTR_ALLOC_SINGLE_PAGES BIT(7)
/*
* DMA_ATTR_NO_WARN: This tells the DMA-mapping subsystem to suppress
* allocation failure reports (similarly to __GFP_NOWARN).
*/
-#define DMA_ATTR_NO_WARN (1UL << 8)
+#define DMA_ATTR_NO_WARN BIT(8)
/*
* DMA_ATTR_PRIVILEGED: used to indicate that the buffer is fully
* accessible at an elevated privilege level (and ideally inaccessible or
* at least read-only at lesser-privileged levels).
*/
-#define DMA_ATTR_PRIVILEGED (1UL << 9)
+#define DMA_ATTR_PRIVILEGED BIT(9)
/*
* A dma_addr_t can hold any valid DMA or bus address for the platform.
@@ -136,7 +137,7 @@ struct dma_map_ops {
extern const struct dma_map_ops dma_virt_ops;
extern const struct dma_map_ops dma_dummy_ops;
-#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
+#define DMA_BIT_MASK(n) GENMASK_ULL(n - 1, 0)
#define DMA_MASK_NONE 0x0ULL
--
2.24.0
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: dma-mapping: use bit macros
2019-11-29 20:27 dma-mapping: use bit macros Heiner Kallweit
@ 2019-11-30 8:18 ` Christoph Hellwig
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2019-11-30 8:18 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Linux Kernel Mailing List, open list:AMD IOMMU (AMD-VI),
Robin Murphy, Christoph Hellwig
On Fri, Nov 29, 2019 at 09:27:26PM +0100, Heiner Kallweit wrote:
> Not necessarily a big leap for mankind, but using bit macros makes
> the code better readable, especially the definition of DMA_BIT_MASK
> is more intuitive.
NAK, I'm against this pointless obsfucation.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-30 8:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 20:27 dma-mapping: use bit macros Heiner Kallweit
2019-11-30 8:18 ` Christoph Hellwig
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).