]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/32s: Simplify calculation of segment register content
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 3 Jun 2021 08:41:40 +0000 (08:41 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 16 Jun 2021 14:09:08 +0000 (00:09 +1000)
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 <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/ddc1cfd2ec8f3b2395c6a4d7f2b0c1aa1b1e64fb.1622708530.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/book3s/32/mmu-hash.h

index 583388399b1b20f4cb40084e44aca64ee4d64cd1..f5be185cbdf8da15df447dd94931e570595367c0 100644 (file)
@@ -115,28 +115,32 @@ extern s32 patch__flush_hash_B;
 #include <asm/reg.h>
 #include <asm/task_size_32.h>
 
-#define UPDATE_TWO_USER_SEGMENTS(n) do {               \
-       if (TASK_SIZE > ((n) << 28))                    \
-               mtsr(val1, (n) << 28);                  \
-       if (TASK_SIZE > (((n) + 1) << 28))              \
-               mtsr(val2, ((n) + 1) << 28);            \
-       val1 = (val1 + 0x222) & 0xf0ffffff;             \
-       val2 = (val2 + 0x222) & 0xf0ffffff;             \
-} while (0)
+static __always_inline void update_user_segment(u32 n, u32 val)
+{
+       if (n << 28 < TASK_SIZE)
+               mtsr(val + n * 0x111, n << 28);
+}
 
 static __always_inline void update_user_segments(u32 val)
 {
-       int val1 = val;
-       int val2 = (val + 0x111) & 0xf0ffffff;
-
-       UPDATE_TWO_USER_SEGMENTS(0);
-       UPDATE_TWO_USER_SEGMENTS(2);
-       UPDATE_TWO_USER_SEGMENTS(4);
-       UPDATE_TWO_USER_SEGMENTS(6);
-       UPDATE_TWO_USER_SEGMENTS(8);
-       UPDATE_TWO_USER_SEGMENTS(10);
-       UPDATE_TWO_USER_SEGMENTS(12);
-       UPDATE_TWO_USER_SEGMENTS(14);
+       val &= 0xf0ffffff;
+
+       update_user_segment(0, val);
+       update_user_segment(1, val);
+       update_user_segment(2, val);
+       update_user_segment(3, val);
+       update_user_segment(4, val);
+       update_user_segment(5, val);
+       update_user_segment(6, val);
+       update_user_segment(7, val);
+       update_user_segment(8, val);
+       update_user_segment(9, val);
+       update_user_segment(10, val);
+       update_user_segment(11, val);
+       update_user_segment(12, val);
+       update_user_segment(13, val);
+       update_user_segment(14, val);
+       update_user_segment(15, val);
 }
 
 #endif /* !__ASSEMBLY__ */