* [POWERPC] add clrsetbits macros
@ 2007-08-22 17:47 Timur Tabi
2007-08-22 20:49 ` Kumar Gala
0 siblings, 1 reply; 3+ messages in thread
From: Timur Tabi @ 2007-08-22 17:47 UTC (permalink / raw)
To: linuxppc-dev; +Cc: 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.
Signed-off-by: Timur Tabi <timur@freescale.com>
---
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(-)
diff --git a/include/asm-powerpc/io.h b/include/asm-powerpc/io.h
index 4c0b550..030ed4e 100644
--- a/include/asm-powerpc/io.h
+++ b/include/asm-powerpc/io.h
@@ -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 */
--
1.5.2.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [POWERPC] add clrsetbits macros
2007-08-22 17:47 Timur Tabi
@ 2007-08-22 20:49 ` Kumar Gala
0 siblings, 0 replies; 3+ messages in thread
From: Kumar Gala @ 2007-08-22 20:49 UTC (permalink / raw)
To: Timur Tabi; +Cc: linuxppc-dev
On Aug 22, 2007, at 12:47 PM, Timur Tabi wrote:
> 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.
>
> Signed-off-by: Timur Tabi <timur@freescale.com>
> ---
>
> 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(-)
>
> diff --git a/include/asm-powerpc/io.h b/include/asm-powerpc/io.h
> index 4c0b550..030ed4e 100644
> --- a/include/asm-powerpc/io.h
> +++ b/include/asm-powerpc/io.h
> @@ -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))
> +
I think we should define the *_le{32,64}, *_be{32,64}, and _8
versions using this.
- k
^ permalink raw reply [flat|nested] 3+ messages in thread
* [POWERPC] add clrsetbits macros
@ 2007-08-23 1:07 Timur Tabi
0 siblings, 0 replies; 3+ messages in thread
From: Timur Tabi @ 2007-08-23 1:07 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Timur Tabi
This patch adds the clrsetbits_xxx() macros, which are 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. There are big-endian and little-endian versions for 8, 16,
32, and 64 bits.
Signed-off-by: Timur Tabi <timur@freescale.com>
---
put back the original functions and just based them off clrsetbits().
include/asm-powerpc/io.h | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/include/asm-powerpc/io.h b/include/asm-powerpc/io.h
index 4c0b550..38f03bc 100644
--- a/include/asm-powerpc/io.h
+++ b/include/asm-powerpc/io.h
@@ -737,6 +737,29 @@ 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. 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.
+ */
+
+#define clrsetbits(type, addr, clear, set) \
+ out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
+
+#ifdef __powerpc64__
+#define clrsetbits_be64(addr, clear, set) clrsetbits(be64, addr, clear, set)
+#define clrsetbits_le64(addr, clear, set) clrsetbits(le64, addr, clear, set)
+#endif
+
+#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
+#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
+
+#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
+#define clrsetbits_le16(addr, clear, set) clrsetbits(le32, addr, clear, set)
+
+#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
+
#endif /* __KERNEL__ */
#endif /* _ASM_POWERPC_IO_H */
--
1.5.2.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-08-23 1:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-23 1:07 [POWERPC] add clrsetbits macros Timur Tabi
-- strict thread matches above, loose matches on Subject: below --
2007-08-22 17:47 Timur Tabi
2007-08-22 20:49 ` Kumar Gala
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).