[Intel-gfx] [PATCH 2/3] iosys-map: Add per-word write
Lucas De Marchi
lucas.demarchi at intel.com
Fri Jun 10 23:21:29 UTC 2022
Like was done for read, provide the equivalent for write. Even if
current users are not in the hot path, this should future-proof it.
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
include/linux/iosys-map.h | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/include/linux/iosys-map.h b/include/linux/iosys-map.h
index cd28c7a1b79c..793e5cd50dbf 100644
--- a/include/linux/iosys-map.h
+++ b/include/linux/iosys-map.h
@@ -336,8 +336,11 @@ static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
#ifdef CONFIG_64BIT
#define __iosys_map_rd_io_u64_case(val_, vaddr_iomem_) \
u64: val_ = readq(vaddr_iomem_),
+#define __iosys_map_wr_io_u64_case(val_, vaddr_iomem_) \
+ u64: writeq(val_, vaddr_iomem_),
#else
#define __iosys_map_rd_io_u64_case(val_, vaddr_iomem_)
+#define __iosys_map_wr_io_u64_case(val_, vaddr_iomem_)
#endif
#define __iosys_map_rd_io(val__, vaddr_iomem__, type__) _Generic(val__, \
@@ -347,6 +350,13 @@ static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
__iosys_map_rd_io_u64_case(val__, vaddr_iomem__) \
default: memcpy_fromio(&(val__), vaddr_iomem__, sizeof(val__)))
+#define __iosys_map_wr_io(val__, vaddr_iomem__, type__) _Generic(val__, \
+ u8: writeb(val__, vaddr_iomem__), \
+ u16: writew(val__, vaddr_iomem__), \
+ u32: writel(val__, vaddr_iomem__), \
+ __iosys_map_wr_io_u64_case(val__, vaddr_iomem__) \
+ default: memcpy_toio(vaddr_iomem__, &val, sizeof(val)))
+
/**
* iosys_map_rd - Read a C-type value from the iosys_map
*
@@ -381,9 +391,13 @@ static inline void iosys_map_memset(struct iosys_map *dst, size_t offset,
* Write a C-type value to the iosys_map, handling possible un-aligned accesses
* to the mapping.
*/
-#define iosys_map_wr(map__, offset__, type__, val__) ({ \
- type__ val = (val__); \
- iosys_map_memcpy_to(map__, offset__, &val, sizeof(val)); \
+#define iosys_map_wr(map__, offset__, type__, val__) ({ \
+ type__ val = (val__); \
+ if ((map__)->is_iomem) { \
+ __iosys_map_wr_io(val, (map__)->vaddr_iomem + offset__, type__);\
+ } else { \
+ memcpy((map__)->vaddr + offset__, &val, sizeof(val)); \
+ } \
})
/**
--
2.36.1
More information about the Intel-gfx
mailing list