Skip to contentSkip to conversation

add clrsetbits macros

POWERPC Timur Tabi 2 participants 2 messages Aug 22, 2007

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

This patch adds the clrsetbits() macro, which is used to set and clear multiple bits in a single read-modify-write operation. Specify the bits to clear in the 'clear' parameter and the bits to set in the 'set' parameter. These macros can also be used to set a multiple-bit bit pattern using a mask, by specifying the mask in the 'clear' parameter and the new bit pattern in the 'set' parameter. The 'type' parameter is used to specify the size and endian.

---

Replace multiple macros with a single one that uses macro concatenation to handle the endian/size.

 include/asm-powerpc/io.h |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
include/asm-powerpc/io.h +13 -0
index 4c0b550..030ed4e 100644
@@ -737,6 +737,19 @@ static inline void * bus_to_virt(unsigned long address)
 #define setbits8(_addr, _v) out_8((_addr), in_8(_addr) |  (_v))
 #define clrbits8(_addr, _v) out_8((_addr), in_8(_addr) & ~(_v))
 
+/* Clear and set bits in one shot.  This macrocan be used to clear and set
+ * multiple bits in a register using a single read-modify-write.  It can
+ * also be used to set a multiple-bit bit pattern using a mask, by
+ * specifying the mask in the 'clear' parameter and the new bit pattern in
+ * the 'set' parameter.
+ *
+ * For 'type', specify 8, le16, be16, le32, be32, le64, or be64.  The latter
+ * two only work on 64-bit PowerPC (__powerpc64__ is defined).
+ */
+
+#define clrsetbits(type, addr, clear, set) \
+	out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
+
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_POWERPC_IO_H */
Signature · 1 line
1.5.2.4
#1 lore raw
Quoted 38 lines · Timur Tabi

This patch adds the clrsetbits() macro, which is used to set and clear multiple bits in a single read-modify-write operation. Specify the bits to clear in the 'clear' parameter and the bits to set in the 'set' parameter. These macros can also be used to set a multiple-bit bit pattern using a mask, by specifying the mask in the 'clear' parameter and the new bit pattern in the 'set' parameter. The 'type' parameter is used to specify the size and endian.

---

Replace multiple macros with a single one that uses macro concatenation to handle the endian/size.

 include/asm-powerpc/io.h |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
include/asm-powerpc/io.h +1 -0
index 4c0b550..030ed4e 100644
@@ -737,6 +737,19 @@ static inline void * bus_to_virt(unsigned long  
 address)
 #define setbits8(_addr, _v) out_8((_addr), in_8(_addr) |  (_v))
 #define clrbits8(_addr, _v) out_8((_addr), in_8(_addr) & ~(_v))
 
+/* Clear and set bits in one shot.  This macrocan be used to clear  

and set
+ * multiple bits in a register using a single read-modify-write. It can
+ * also be used to set a multiple-bit bit pattern using a mask, by
+ * specifying the mask in the 'clear' parameter and the new bit pattern in
+ * the 'set' parameter.
+ *
+ * For 'type', specify 8, le16, be16, le32, be32, le64, or be64. The latter
+ * two only work on 64-bit PowerPC (__powerpc64__ is defined).
+ */

include/asm-powerpc/io.h static inline void * bus_to_virt(unsigned long address) · line 752

Quoted 4 lines
include/asm-powerpc/io.h +4 -0
+
+#define clrsetbits(type, addr, clear, set) \
+	out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
+

I think we should define the *_le{32,64}, *_be{32,64}, and _8 versions using this.

- k