Skip to content

Commit 320549a

Browse files
committed
regmap: mmio: Revert to v4.4 endianness handling
Commit 29bb45f (regmap-mmio: Use native endianness for read/write) attempted to fix some long standing bugs in the MMIO implementation for big endian systems caused by duplicate byte swapping in both regmap and readl()/writel() which affected MIPS systems as when they are in big endian mode they flip the endianness of all registers in the system, not just the CPU. MIPS systems had worked around this by declaring regmap using IPs as little endian which is inaccurate, unfortunately the issue had not been reported. Sadly the fix makes things worse rather than better. By changing the behaviour to match the documentation it caused behaviour changes for other IPs which broke them and by using the __raw I/O accessors to avoid the endianness swapping in readl()/writel() it removed some memory ordering guarantees and could potentially generate unvirtualisable instructions on some architectures. Unfortunately sorting out all this mess in any half way sensible fashion was far too invasive to go in during an -rc cycle so instead let's go back to the old broken behaviour for v4.5, the better fixes are already queued for v4.6. This does mean that we keep the broken MIPS DTs for another release but that seems the least bad way of handling the situation. Reported-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 92e963f commit 320549a

File tree

10 files changed

+17
-8
lines changed

10 files changed

+17
-8
lines changed

arch/mips/boot/dts/brcm/bcm6328.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
timer: timer@10000040 {
7575
compatible = "syscon";
7676
reg = <0x10000040 0x2c>;
77+
little-endian;
7778
};
7879

7980
reboot {

arch/mips/boot/dts/brcm/bcm7125.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
sun_top_ctrl: syscon@404000 {
9999
compatible = "brcm,bcm7125-sun-top-ctrl", "syscon";
100100
reg = <0x404000 0x60c>;
101+
little-endian;
101102
};
102103

103104
reboot {

arch/mips/boot/dts/brcm/bcm7346.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
sun_top_ctrl: syscon@404000 {
119119
compatible = "brcm,bcm7346-sun-top-ctrl", "syscon";
120120
reg = <0x404000 0x51c>;
121+
little-endian;
121122
};
122123

123124
reboot {

arch/mips/boot/dts/brcm/bcm7358.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
sun_top_ctrl: syscon@404000 {
113113
compatible = "brcm,bcm7358-sun-top-ctrl", "syscon";
114114
reg = <0x404000 0x51c>;
115+
little-endian;
115116
};
116117

117118
reboot {

arch/mips/boot/dts/brcm/bcm7360.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
sun_top_ctrl: syscon@404000 {
113113
compatible = "brcm,bcm7360-sun-top-ctrl", "syscon";
114114
reg = <0x404000 0x51c>;
115+
little-endian;
115116
};
116117

117118
reboot {

arch/mips/boot/dts/brcm/bcm7362.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
sun_top_ctrl: syscon@404000 {
119119
compatible = "brcm,bcm7362-sun-top-ctrl", "syscon";
120120
reg = <0x404000 0x51c>;
121+
little-endian;
121122
};
122123

123124
reboot {

arch/mips/boot/dts/brcm/bcm7420.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
sun_top_ctrl: syscon@404000 {
100100
compatible = "brcm,bcm7420-sun-top-ctrl", "syscon";
101101
reg = <0x404000 0x60c>;
102+
little-endian;
102103
};
103104

104105
reboot {

arch/mips/boot/dts/brcm/bcm7425.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
sun_top_ctrl: syscon@404000 {
101101
compatible = "brcm,bcm7425-sun-top-ctrl", "syscon";
102102
reg = <0x404000 0x51c>;
103+
little-endian;
103104
};
104105

105106
reboot {

arch/mips/boot/dts/brcm/bcm7435.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
sun_top_ctrl: syscon@404000 {
115115
compatible = "brcm,bcm7425-sun-top-ctrl", "syscon";
116116
reg = <0x404000 0x51c>;
117+
little-endian;
117118
};
118119

119120
reboot {

drivers/base/regmap/regmap-mmio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ static int regmap_mmio_gather_write(void *context,
133133
while (val_size) {
134134
switch (ctx->val_bytes) {
135135
case 1:
136-
__raw_writeb(*(u8 *)val, ctx->regs + offset);
136+
writeb(*(u8 *)val, ctx->regs + offset);
137137
break;
138138
case 2:
139-
__raw_writew(*(u16 *)val, ctx->regs + offset);
139+
writew(*(u16 *)val, ctx->regs + offset);
140140
break;
141141
case 4:
142-
__raw_writel(*(u32 *)val, ctx->regs + offset);
142+
writel(*(u32 *)val, ctx->regs + offset);
143143
break;
144144
#ifdef CONFIG_64BIT
145145
case 8:
146-
__raw_writeq(*(u64 *)val, ctx->regs + offset);
146+
writeq(*(u64 *)val, ctx->regs + offset);
147147
break;
148148
#endif
149149
default:
@@ -193,17 +193,17 @@ static int regmap_mmio_read(void *context,
193193
while (val_size) {
194194
switch (ctx->val_bytes) {
195195
case 1:
196-
*(u8 *)val = __raw_readb(ctx->regs + offset);
196+
*(u8 *)val = readb(ctx->regs + offset);
197197
break;
198198
case 2:
199-
*(u16 *)val = __raw_readw(ctx->regs + offset);
199+
*(u16 *)val = readw(ctx->regs + offset);
200200
break;
201201
case 4:
202-
*(u32 *)val = __raw_readl(ctx->regs + offset);
202+
*(u32 *)val = readl(ctx->regs + offset);
203203
break;
204204
#ifdef CONFIG_64BIT
205205
case 8:
206-
*(u64 *)val = __raw_readq(ctx->regs + offset);
206+
*(u64 *)val = readq(ctx->regs + offset);
207207
break;
208208
#endif
209209
default:

0 commit comments

Comments
 (0)