[PATCH 1/2] iosys-map: Add a helper for pointer difference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Siva Mullati <siva.mullati@xxxxxxxxx>

iosys_map_ptrdiff to get the difference in address of
same memory type.

Signed-off-by: Siva Mullati <siva.mullati@xxxxxxxxx>
---
 include/linux/iosys-map.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/linux/iosys-map.h b/include/linux/iosys-map.h
index e69a002d5aa4..8987f69ec1e9 100644
--- a/include/linux/iosys-map.h
+++ b/include/linux/iosys-map.h
@@ -8,6 +8,7 @@
 
 #include <linux/io.h>
 #include <linux/string.h>
+#include <linux/types.h>
 
 /**
  * DOC: overview
@@ -208,6 +209,26 @@ static inline bool iosys_map_is_equal(const struct iosys_map *lhs,
 		return lhs->vaddr == rhs->vaddr;
 }
 
+/**
+ * iosys_map_ptrdiff - Difference of two iosys mapping addresses of same memory type
+ * @lhs:       The iosys_map structure
+ * @rhs:       A iosys_map structure to compare with
+ *
+ * Two iosys mapping structures of same memory type with the differences
+ * in address within that memory.
+ *
+ * Returns:
+ * Address difference of two memory locations with same memory type.
+ */
+static inline ptrdiff_t iosys_map_ptrdiff(const struct iosys_map *lhs,
+					  const struct iosys_map *rhs)
+{
+	if (lhs->is_iomem)
+		return lhs->vaddr_iomem - rhs->vaddr_iomem;
+	else
+		return lhs->vaddr - rhs->vaddr;
+}
+
 /**
  * iosys_map_is_null - Tests for a iosys mapping to be NULL
  * @map:	The iosys_map structure
-- 
2.33.0




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux