4 #include <linux/compiler.h>
5 #include <asm/thread_info.h>
8 #include <asm/asm-offsets.h>
9 .macro switch_tls_none, base, tp, tpuser, tmp1, tmp2
12 .macro switch_tls_v6k, base, tp, tpuser, tmp1, tmp2
13 mrc p15, 0, \tmp2, c13, c0, 2 @ get the user r/w register
14 mcr p15, 0, \tp, c13, c0, 3 @ set TLS register
15 mcr p15, 0, \tpuser, c13, c0, 2 @ and the user r/w register
16 str \tmp2, [\base, #TI_TP_VALUE + 4] @ save it
19 .macro switch_tls_v6, base, tp, tpuser, tmp1, tmp2
21 ldr \tmp1, [\tmp1, #0]
22 mov \tmp2, #0xffff0fff
23 tst \tmp1, #HWCAP_TLS @ hardware TLS available?
24 streq \tp, [\tmp2, #-15] @ set TLS value at 0xffff0ff0
25 mrcne p15, 0, \tmp2, c13, c0, 2 @ get the user r/w register
26 mcrne p15, 0, \tp, c13, c0, 3 @ yes, set TLS register
27 mcrne p15, 0, \tpuser, c13, c0, 2 @ set user r/w register
28 strne \tmp2, [\base, #TI_TP_VALUE + 4] @ save it
31 .macro switch_tls_software, base, tp, tpuser, tmp1, tmp2
32 mov \tmp1, #0xffff0fff
33 str \tp, [\tmp1, #-15] @ set TLS value at 0xffff0ff0
37 #ifdef CONFIG_TLS_REG_EMUL
40 #define switch_tls switch_tls_none
41 #elif defined(CONFIG_CPU_V6)
43 #define has_tls_reg (elf_hwcap & HWCAP_TLS)
44 #define switch_tls switch_tls_v6
45 #elif defined(CONFIG_CPU_32v6K)
48 #define switch_tls switch_tls_v6k
52 #define switch_tls switch_tls_software
57 static inline void set_tls(unsigned long val)
59 struct thread_info *thread;
61 thread = current_thread_info();
63 thread->tp_value[0] = val;
66 * This code runs with preemption enabled and therefore must
67 * be reentrant with respect to switch_tls.
69 * We need to ensure ordering between the shadow state and the
70 * hardware state, so that we don't corrupt the hardware state
71 * with a stale shadow state during context switch.
73 * If we're preempted here, switch_tls will load TPIDRURO from
74 * thread_info upon resuming execution and the following mcr
75 * is merely redundant.
81 asm("mcr p15, 0, %0, c13, c0, 3"
85 * User space must never try to access this
86 * directly. Expect your app to break
87 * eventually if you do so. The user helper
88 * at 0xffff0fe0 must be used instead. (see
89 * entry-armv.S for details)
91 *((unsigned int *)0xffff0ff0) = val;
97 static inline unsigned long get_tpuser(void)
99 unsigned long reg = 0;
101 if (has_tls_reg && !tls_emu)
102 __asm__("mrc p15, 0, %0, c13, c0, 2" : "=r" (reg));
107 static inline void set_tpuser(unsigned long val)
109 /* Since TPIDRURW is fully context-switched (unlike TPIDRURO),
110 * we need not update thread_info.
112 if (has_tls_reg && !tls_emu) {
113 asm("mcr p15, 0, %0, c13, c0, 2"
118 static inline void flush_tls(void)
125 #endif /* __ASMARM_TLS_H */