1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/compiler.h>
6 #include <asm/thread_info.h>
9 #include <asm/asm-offsets.h>
10 .macro switch_tls_none
, base
, tp
, tpuser
, tmp1
, tmp2
13 .macro switch_tls_v6k
, base
, tp
, tpuser
, tmp1
, tmp2
14 mrc p15
, 0, \tmp
2, c13
, c0
, 2 @ get the user r
/w
register
15 mcr p15
, 0, \tp
, c13
, c0
, 3 @ set TLS
register
16 mcr p15
, 0, \tpuser
, c13
, c0
, 2 @
and the user r
/w
register
17 str
\tmp
2, [\base
, #TI_TP_VALUE + 4] @ save it
20 .macro switch_tls_v6
, base
, tp
, tpuser
, tmp1
, tmp2
22 ldr
\tmp
1, [\tmp
1, #0]
23 mov
\tmp
2, #0xffff0fff
24 tst
\tmp
1, #HWCAP_TLS @ hardware TLS available?
25 streq
\tp
, [\tmp
2, #-15] @ set TLS value at 0xffff0ff0
26 mrcne p15
, 0, \tmp
2, c13
, c0
, 2 @ get the user r
/w
register
27 mcrne p15
, 0, \tp
, c13
, c0
, 3 @ yes
, set TLS
register
28 mcrne p15
, 0, \tpuser
, c13
, c0
, 2 @ set user r
/w
register
29 strne
\tmp
2, [\base
, #TI_TP_VALUE + 4] @ save it
32 .macro switch_tls_software
, base
, tp
, tpuser
, tmp1
, tmp2
33 mov
\tmp
1, #0xffff0fff
34 str
\tp
, [\tmp
1, #-15] @ set TLS value at 0xffff0ff0
38 #ifdef CONFIG_TLS_REG_EMUL
41 #define switch_tls switch_tls_none
42 #elif defined(CONFIG_CPU_V6)
44 #define has_tls_reg (elf_hwcap & HWCAP_TLS)
45 #define switch_tls switch_tls_v6
46 #elif defined(CONFIG_CPU_32v6K)
49 #define switch_tls switch_tls_v6k
53 #define switch_tls switch_tls_software
58 static inline void set_tls(unsigned long val
)
60 struct thread_info
*thread
;
62 thread
= current_thread_info();
64 thread
->tp_value
[0] = val
;
67 * This code runs with preemption enabled and therefore must
68 * be reentrant with respect to switch_tls.
70 * We need to ensure ordering between the shadow state and the
71 * hardware state, so that we don't corrupt the hardware state
72 * with a stale shadow state during context switch.
74 * If we're preempted here, switch_tls will load TPIDRURO from
75 * thread_info upon resuming execution and the following mcr
76 * is merely redundant.
82 asm("mcr p15, 0, %0, c13, c0, 3"
85 #ifdef CONFIG_KUSER_HELPERS
87 * User space must never try to access this
88 * directly. Expect your app to break
89 * eventually if you do so. The user helper
90 * at 0xffff0fe0 must be used instead. (see
91 * entry-armv.S for details)
93 *((unsigned int *)0xffff0ff0) = val
;
100 static inline unsigned long get_tpuser(void)
102 unsigned long reg
= 0;
104 if (has_tls_reg
&& !tls_emu
)
105 __asm__("mrc p15, 0, %0, c13, c0, 2" : "=r" (reg
));
110 static inline void set_tpuser(unsigned long val
)
112 /* Since TPIDRURW is fully context-switched (unlike TPIDRURO),
113 * we need not update thread_info.
115 if (has_tls_reg
&& !tls_emu
) {
116 asm("mcr p15, 0, %0, c13, c0, 2"
121 static inline void flush_tls(void)
128 #endif /* __ASMARM_TLS_H */