150596b75SArd Biesheuvel /* SPDX-License-Identifier: GPL-2.0-only */ 250596b75SArd Biesheuvel /* 350596b75SArd Biesheuvel * Copyright (c) 2021 Keith Packard <keithp@keithp.com> 450596b75SArd Biesheuvel * Copyright (c) 2021 Google, LLC <ardb@kernel.org> 550596b75SArd Biesheuvel */ 650596b75SArd Biesheuvel 750596b75SArd Biesheuvel #ifndef _ASM_ARM_CURRENT_H 850596b75SArd Biesheuvel #define _ASM_ARM_CURRENT_H 950596b75SArd Biesheuvel 1050596b75SArd Biesheuvel #ifndef __ASSEMBLY__ 119c46929eSArd Biesheuvel #include <asm/insn.h> 1250596b75SArd Biesheuvel 1350596b75SArd Biesheuvel struct task_struct; 1450596b75SArd Biesheuvel 159c46929eSArd Biesheuvel extern struct task_struct *__current; 1650596b75SArd Biesheuvel 174d5a643eSArd Biesheuvel static __always_inline __attribute_const__ struct task_struct *get_current(void) 1850596b75SArd Biesheuvel { 1950596b75SArd Biesheuvel struct task_struct *cur; 2050596b75SArd Biesheuvel 21*19336376SNathan Chancellor #if __has_builtin(__builtin_thread_pointer) && defined(CONFIG_CURRENT_POINTER_IN_TPIDRURO) 2250596b75SArd Biesheuvel /* 2350596b75SArd Biesheuvel * Use the __builtin helper when available - this results in better 2450596b75SArd Biesheuvel * code, especially when using GCC in combination with the per-task 2550596b75SArd Biesheuvel * stack protector, as the compiler will recognize that it needs to 2650596b75SArd Biesheuvel * load the TLS register only once in every function. 2750596b75SArd Biesheuvel */ 2850596b75SArd Biesheuvel cur = __builtin_thread_pointer(); 299c46929eSArd Biesheuvel #elif defined(CONFIG_CURRENT_POINTER_IN_TPIDRURO) || defined(CONFIG_SMP) 309c46929eSArd Biesheuvel asm("0: mrc p15, 0, %0, c13, c0, 3 \n\t" 319c46929eSArd Biesheuvel #ifdef CONFIG_CPU_V6 329c46929eSArd Biesheuvel "1: \n\t" 339c46929eSArd Biesheuvel " .subsection 1 \n\t" 34d6905849SArd Biesheuvel #if defined(CONFIG_ARM_HAS_GROUP_RELOCS) && \ 35d6905849SArd Biesheuvel !(defined(MODULE) && defined(CONFIG_ARM_MODULE_PLTS)) 369c46929eSArd Biesheuvel "2: " LOAD_SYM_ARMV6(%0, __current) " \n\t" 379c46929eSArd Biesheuvel " b 1b \n\t" 385fe41793SArd Biesheuvel #else 395fe41793SArd Biesheuvel "2: ldr %0, 3f \n\t" 405fe41793SArd Biesheuvel " ldr %0, [%0] \n\t" 415fe41793SArd Biesheuvel " b 1b \n\t" 425fe41793SArd Biesheuvel "3: .long __current \n\t" 435fe41793SArd Biesheuvel #endif 449c46929eSArd Biesheuvel " .previous \n\t" 459c46929eSArd Biesheuvel " .pushsection \".alt.smp.init\", \"a\" \n\t" 469c46929eSArd Biesheuvel " .long 0b - . \n\t" 479c46929eSArd Biesheuvel " b . + (2b - 0b) \n\t" 489c46929eSArd Biesheuvel " .popsection \n\t" 499c46929eSArd Biesheuvel #endif 509c46929eSArd Biesheuvel : "=r"(cur)); 519c46929eSArd Biesheuvel #elif __LINUX_ARM_ARCH__>= 7 || \ 52d6905849SArd Biesheuvel !defined(CONFIG_ARM_HAS_GROUP_RELOCS) || \ 53d6905849SArd Biesheuvel (defined(MODULE) && defined(CONFIG_ARM_MODULE_PLTS)) 549c46929eSArd Biesheuvel cur = __current; 5550596b75SArd Biesheuvel #else 569c46929eSArd Biesheuvel asm(LOAD_SYM_ARMV6(%0, __current) : "=r"(cur)); 5750596b75SArd Biesheuvel #endif 5850596b75SArd Biesheuvel return cur; 5950596b75SArd Biesheuvel } 6050596b75SArd Biesheuvel 6150596b75SArd Biesheuvel #define current get_current() 6250596b75SArd Biesheuvel 6350596b75SArd Biesheuvel #endif /* __ASSEMBLY__ */ 6450596b75SArd Biesheuvel 6550596b75SArd Biesheuvel #endif /* _ASM_ARM_CURRENT_H */ 66