Skip to content

Commit 882136f

Browse files
chleroympe
authored andcommitted
powerpc/32s: Simplify calculation of segment register content
segment register has VSID on bits 8-31. Bits 4-7 are reserved, there is no requirement to set them to 0. VSIDs are calculated from VSID of SR0 by adding 0x111. Even with highest possible VSID which would be 0xFFFFF0, adding 16 times 0x111 results in 0x1001100. So, the reserved bits are never overflowed, no need to clear the reserved bits after each calculation. Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/ddc1cfd2ec8f3b2395c6a4d7f2b0c1aa1b1e64fb.1622708530.git.christophe.leroy@csgroup.eu
1 parent 863771a commit 882136f

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

arch/powerpc/include/asm/book3s/32/mmu-hash.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,32 @@ extern s32 patch__flush_hash_B;
115115
#include <asm/reg.h>
116116
#include <asm/task_size_32.h>
117117

118-
#define UPDATE_TWO_USER_SEGMENTS(n) do { \
119-
if (TASK_SIZE > ((n) << 28)) \
120-
mtsr(val1, (n) << 28); \
121-
if (TASK_SIZE > (((n) + 1) << 28)) \
122-
mtsr(val2, ((n) + 1) << 28); \
123-
val1 = (val1 + 0x222) & 0xf0ffffff; \
124-
val2 = (val2 + 0x222) & 0xf0ffffff; \
125-
} while (0)
118+
static __always_inline void update_user_segment(u32 n, u32 val)
119+
{
120+
if (n << 28 < TASK_SIZE)
121+
mtsr(val + n * 0x111, n << 28);
122+
}
126123

127124
static __always_inline void update_user_segments(u32 val)
128125
{
129-
int val1 = val;
130-
int val2 = (val + 0x111) & 0xf0ffffff;
131-
132-
UPDATE_TWO_USER_SEGMENTS(0);
133-
UPDATE_TWO_USER_SEGMENTS(2);
134-
UPDATE_TWO_USER_SEGMENTS(4);
135-
UPDATE_TWO_USER_SEGMENTS(6);
136-
UPDATE_TWO_USER_SEGMENTS(8);
137-
UPDATE_TWO_USER_SEGMENTS(10);
138-
UPDATE_TWO_USER_SEGMENTS(12);
139-
UPDATE_TWO_USER_SEGMENTS(14);
126+
val &= 0xf0ffffff;
127+
128+
update_user_segment(0, val);
129+
update_user_segment(1, val);
130+
update_user_segment(2, val);
131+
update_user_segment(3, val);
132+
update_user_segment(4, val);
133+
update_user_segment(5, val);
134+
update_user_segment(6, val);
135+
update_user_segment(7, val);
136+
update_user_segment(8, val);
137+
update_user_segment(9, val);
138+
update_user_segment(10, val);
139+
update_user_segment(11, val);
140+
update_user_segment(12, val);
141+
update_user_segment(13, val);
142+
update_user_segment(14, val);
143+
update_user_segment(15, val);
140144
}
141145

142146
#endif /* !__ASSEMBLY__ */

0 commit comments

Comments
 (0)