powerpc: add setclrbits macros
PATCH 1/1 powerpc: add setclrbits macros
This patch adds the setclrbits_xxx() macros, which are used to set and clear multiple bits in a single read-modify-write operation. Specify the bits to set in the 'set' parameter and the bits to clear in the 'clear' 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. There are big-endian and little-endian versions for 8, 16, 32, and 64 bits.
---
Changed the macros from setmaskedbits_xxx to setclrbits_xxx and added a comment indicating the expanded functionality.
include/asm-powerpc/io.h | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-)
include/asm-powerpc/io.h +27 -0
@@ -734,6 +734,33 @@ static inline void * bus_to_virt(unsigned long address)#define setbits16 (_addr, _v) out_be16((_addr), in_be16(_addr) | (_v))#define clrbits16 (_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v)) +/* Set and clear bits in one shot. These macros can be used to clear and +* set multiple bits in a register using a single read-modify-write. 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. +*/ + +#ifdef __powerpc64__ +#define setclrbits_be64 (addr, set, clear) \ + out_be64((addr), (in_be64(addr) & ~(clear)) | (set)) +#define setclrbits_le64 (addr, set, clear) \ + out_le64((addr), (in_le64(addr) & ~(clear)) | (set)) +#endif + +#define setclrbits_be32 (addr, set, clear) \ + out_be32((addr), (in_be32(addr) & ~(clear)) | (set)) +#define setclrbits_be16 (addr, set, clear) \ + out_be16((addr), (in_be16(addr) & ~(clear)) | (set)) + +#define setclrbits_le32 (addr, set, clear) \ + out_le32((addr), (in_le32(addr) & ~(clear)) | (set)) +#define setclrbits_le16 (addr, set, clear) \ + out_le16((addr), (in_le16(addr) & ~(clear)) | (set)) + +#define setclrbits_8 (addr, set, clear) \ + out_8((addr), (in_8(addr) & ~(clear)) | (set)) +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_IO_H */
Signature · 1 line
1.5.2.4
Quoted 7 lines · Timur Tabi
This patch adds the
setclrbits_xxx()macros, which are used to set and clear multiple bits in a single read-modify-write operation. Specify the bits to set in the 'set' parameter and the bits to clear in the 'clear' 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. There are big-endian and little-endian versions for 8, 16, 32, and 64 bits.
Sorry for nitpicking again, but since the clear is done before the set (cfr. the expanded functionality), perhaps they should be changed to clrsetbits_X(addr, clear, set)?
Quoted 50 lines
Signed-off-by Timur Tabi <[email protected]>---
Changed the macros from
setmaskedbits_xxxtosetclrbits_xxxand added a comment indicating the expanded functionality.include/asm-powerpc/io.h | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-)include/asm-powerpc/io.h +27
-0@@ -734,6 +734,33 @@ static inline void * bus_to_virt(unsigned long address)#define setbits16 (_addr, _v) out_be16((_addr), in_be16(_addr) | (_v))#define clrbits16 (_addr, _v) out_be16((_addr), in_be16(_addr) & ~(_v)) +/* Set and clear bits in one shot. These macros can be used to clear and +* set multiple bits in a register using a single read-modify-write. 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. +*/ + +#ifdef __powerpc64__ +#define setclrbits_be64 (addr, set, clear) \ + out_be64((addr), (in_be64(addr) & ~(clear)) | (set)) +#define setclrbits_le64 (addr, set, clear) \ + out_le64((addr), (in_le64(addr) & ~(clear)) | (set)) +#endif + +#define setclrbits_be32 (addr, set, clear) \ + out_be32((addr), (in_be32(addr) & ~(clear)) | (set)) +#define setclrbits_be16 (addr, set, clear) \ + out_be16((addr), (in_be16(addr) & ~(clear)) | (set)) + +#define setclrbits_le32 (addr, set, clear) \ + out_le32((addr), (in_le32(addr) & ~(clear)) | (set)) +#define setclrbits_le16 (addr, set, clear) \ + out_le16((addr), (in_le16(addr) & ~(clear)) | (set)) + +#define setclrbits_8 (addr, set, clear) \ + out_8((addr), (in_8(addr) & ~(clear)) | (set)) +#endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_IO_H */ Signature · 1 line
1.5.2.4
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453 Fax: +32 (0)2 700 8622 E-mail: [email protected] Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V. Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
Quoted 3 lines · Geert Uytterhoeven
Sorry for nitpicking again, but since the clear is done before the set (cfr. the expanded functionality), perhaps they should be changed to
clrsetbits_X(addr, clear, set)?
*sigh*
You're right. New patch coming soon.
Signature · 2 lines
Timur Tabi Linux Kernel Developer @ Freescale