Skip to contentSkip to conversation

MIPS: add readl/write_be

PATCH Applied Florian Fainelli 6 participants 10 messages Dec 12, 2009 – Jan 13, 2010 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 MIPS: add readl/write_be

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

---

arch/mips/include/asm/io.h +3 -0
index 436878e..65cb4e4 100644
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
 #define readl_relaxed			readl
 #define readq_relaxed			readq
 
+#define readl_be(addr)			__raw_readl((__force unsigned *)addr)
+#define writel_be(val, addr)		__raw_writel(val, (__force unsigned *)addr)
+
 /*
  * Some code tests for these symbols
  */
#1 lore raw

arch/mips/include/asm/io.h __BUILDIO(q, u64) · line 451

Quoted 2 lines · Florian Fainelli
arch/mips/include/asm/io.h +2 -0
+#define readl_be(addr)			__raw_readl((__force unsigned *)addr)
+#define writel_be(val, addr)		__raw_writel(val, (__force unsigned *)addr)

looks broken for little endian machines. __raw_XXX doesn't do any swapping, so IMHO the correct thing would be to use be32_to_cpu/cpu_to_be32.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessary a
good idea.                                                [ RFC1925, 2.3 ]
#2 lore raw

Hello Thomas,

Quoted 7 lines · On Saturday 12 December 2009 20:31:14 Thomas Bogendoerfer wrote:
Quoted 3 lines · Florian Fainelli
(quoted diff) +2 -0
+#define readl_be(addr)			__raw_readl((__force unsigned *)addr)
+#define writel_be(val, addr)		__raw_writel(val, (__force unsigned

*)addr)

looks broken for little endian machines. __raw_XXX doesn't do any swapping, so IMHO the correct thing would be to use be32_to_cpu/cpu_to_be32.

Yeah, I missed that point. Please find below version 2 of the patch which also addresses David's comment. --
From: Florian Fainelli <[email protected]>
Subject: [PATCH v2] MIPS: add readl_be/writel_be

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

Changes from v1:
- make it work on little-endian machines
- protect macros arguments with parenthesis

---

arch/mips/include/asm/io.h +3 -0
index 436878e..4a76d39 100644
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
 #define readl_relaxed			readl
 #define readq_relaxed			readq
 
+#define readl_be(addr)			cpu_to_be32(__raw_readl((__force unsigned *)(addr)))
+#define writel_be(val, addr)		__raw_writel(be32_to_cpu((val)), (__force unsigned *)(addr))
+
 /*
  * Some code tests for these symbols
  */
#3 lore raw
Quoted 30 lines · Florian Fainelli
Quoted 7 lines · On Saturday 12 December 2009 20:31:14 Thomas Bogendoerfer wrote:
Quoted 3 lines · Florian Fainelli
(quoted diff) +2 -0
+#define readl_be(addr)                     __raw_readl((__force unsigned *)addr)
+#define writel_be(val, addr)               __raw_writel(val, (__force unsigned

*)addr)

looks broken for little endian machines. __raw_XXX doesn't do any swapping, so IMHO the correct thing would be to use be32_to_cpu/cpu_to_be32.

Yeah, I missed that point. Please find below version 2 of the patch which also addresses David's comment. --
From: Florian Fainelli <[email protected]>
Subject: [PATCH v2] MIPS: add readl_be/writel_be

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

Changes from v1:
- make it work on little-endian machines
- protect macros arguments with parenthesis

---

arch/mips/include/asm/io.h +0 -0
index 436878e..4a76d39 100644

arch/mips/include/asm/io.h __BUILDIO(q, u64) · line 451

Quoted 5 lines
arch/mips/include/asm/io.h +2 -0
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
  #define readl_relaxed                  readl
  #define readq_relaxed                  readq
 
+#define readl_be(addr)                 cpu_to_be32(__raw_readl((__force unsigned *)(addr)))
+#define writel_be(val, addr)           __raw_writel(be32_to_cpu((val)), (__force unsigned *)(addr))

Shouldn't it be the other way around (cpu <-> be32), i.e.

#define readl_be(addr) be32_to_cpu(__raw_readl((__force unsigned *)(addr))) #define writel_be(val, addr) __raw_writel(cpu_to_be32((val)), (__force unsigned *)(addr))

? I know it'll work both ways, though...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#4 lore raw

Hi Geert,

Quoted 41 lines · Geert Uytterhoeven
Quoted 31 lines · Florian Fainelli
Quoted 8 lines · On Saturday 12 December 2009 20:31:14 Thomas Bogendoerfer wrote:
Quoted 3 lines · Florian Fainelli

+#define readl_be(addr) __raw_readl((__force
unsigned *)addr) +#define writel_be(val, addr)
__raw_writel(val, (__force unsigned *)addr)

looks broken for little endian machines. __raw_XXX doesn't do any swapping, so IMHO the correct thing would be to use be32_to_cpu/cpu_to_be32.

Yeah, I missed that point. Please find below version 2 of the patch which also addresses David's comment. --
From: Florian Fainelli <[email protected]>
Subject: [PATCH v2] MIPS: add readl_be/writel_be

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

Changes from v1:
- make it work on little-endian machines
- protect macros arguments with parenthesis

---

arch/mips/include/asm/io.h +0 -0
index 436878e..4a76d39 100644

arch/mips/include/asm/io.h __BUILDIO(q, u64) · line 452

Quoted 6 lines
arch/mips/include/asm/io.h +1 -0
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
 #define readl_relaxed                  readl
 #define readq_relaxed                  readq
 
+#define readl_be(addr)                 cpu_to_be32(__raw_readl((__force
 unsigned *)(addr))) +#define writel_be(val, addr)          
 __raw_writel(be32_to_cpu((val)), (__force unsigned *)(addr))

Shouldn't it be the other way around (cpu <-> be32), i.e.

Quoted 4 lines

#define readl_be(addr) be32_to_cpu(__raw_readl((__force unsigned *)(addr))) #define writel_be(val, addr) __raw_writel(cpu_to_be32((val)), (__force unsigned *)(addr))

It should, I inverted the semantics. I should think twice before sending stuff :) --
From: Florian Fainelli <[email protected]>
Subject: [PATCH v3] MIPS: add readl/write_be accessors

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

Changes from v2:
- fixed the be/cpu endianness inversion

Changes from v1:
- make it work on little-endian machines
- protect macros arguments with parenthesis

---

arch/mips/include/asm/io.h +3 -0
index 436878e..65d7843 100644
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
 #define readl_relaxed			readl
 #define readq_relaxed			readq
 
+#define readl_be(addr)			be32_to_cpu(__raw_readl((__force unsigned *)(addr)))
+#define writel_be(val, addr)		__raw_writel(cpu_to_be32((val)), (__force unsigned *)(addr))
+
 /*
  * Some code tests for these symbols
  */
#5 lore raw
Quoted 1 line · Florian Fainelli

It should, I inverted the semantics. I should think twice before sending stuff :)

That should include Documentation/SubmittingPatches :-)

Ralf

#6 lore raw

From: Florian Fainelli <[email protected]>
Subject: [PATCH v3] MIPS: add readl/write_be accessors

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

---

arch/mips/include/asm/io.h +3 -0
index 436878e..65d7843 100644
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
 #define readl_relaxed			readl
 #define readq_relaxed			readq
 
+#define readl_be(addr)			be32_to_cpu(__raw_readl((__force unsigned *)(addr)))
+#define writel_be(val, addr)		__raw_writel(cpu_to_be32((val)), (__force unsigned *)(addr))
+
 /*
  * Some code tests for these symbols
  */
Applied
#7 lore raw
Quoted 7 lines · Florian Fainelli

From: Florian Fainelli <[email protected]>
Subject: [PATCH v3] MIPS: add readl/write_be accessors

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

Queued; I've added the b, w and q variants to make the patch feature complete even though there are probably no users atm.

Ralf

#8 lore raw
In reply to Florian Fainelli

Hello.

Quoted 8 lines · Florian Fainelli

From: Florian Fainelli <[email protected]>
Subject: [PATCH v3] MIPS: add readl/write_be accessors

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

Quoted 7 lines

Changes from v2:
- fixed the be/cpu endianness inversion

Changes from v1:
- make it work on little-endian machines
- protect macros arguments with parenthesis

You should have put the description of changes under --- tearline,
not in the patch description itself.

Quoted 2 lines

---

WBR, Sergei

#9 lore raw
In reply to Florian Fainelli
Quoted 12 lines · Florian Fainelli

MIPS currently lacks the readl_be and writel_be accessors which are required by BCM63xx for OHCI and EHCI support. Let's define them globally for MIPS. This also fixes the compilation of the bcm63xx defconfig against USB.

---

arch/mips/include/asm/io.h +0 -0
index 436878e..65cb4e4 100644

arch/mips/include/asm/io.h __BUILDIO(q, u64) · line 452

Quoted 6 lines
arch/mips/include/asm/io.h +3 -0
@@ -447,6 +447,9 @@ __BUILDIO(q, u64)
 #define readl_relaxed			readl
 #define readq_relaxed			readq
 
+#define readl_be(addr)			__raw_readl((__force unsigned *)addr)
+#define writel_be(val, addr)		__raw_writel(val, (__force unsigned *)addr)
+

Without addressing the need for the patch, as a technical matter, the macro parameters should probably be protected by parenthesis. I.E.:

#define readl_be(addr) __raw_readl((__force unsigned *)(addr))
#define writel_be(val, addr) __raw_writel((val), (__force unsigned *)(addr))