1*50596b75SArd Biesheuvel /* SPDX-License-Identifier: GPL-2.0-only */ 2*50596b75SArd Biesheuvel /* 3*50596b75SArd Biesheuvel * Copyright (c) 2021 Keith Packard <keithp@keithp.com> 4*50596b75SArd Biesheuvel * Copyright (c) 2021 Google, LLC <ardb@kernel.org> 5*50596b75SArd Biesheuvel */ 6*50596b75SArd Biesheuvel 7*50596b75SArd Biesheuvel #ifndef _ASM_ARM_CURRENT_H 8*50596b75SArd Biesheuvel #define _ASM_ARM_CURRENT_H 9*50596b75SArd Biesheuvel 10*50596b75SArd Biesheuvel #ifndef __ASSEMBLY__ 11*50596b75SArd Biesheuvel 12*50596b75SArd Biesheuvel struct task_struct; 13*50596b75SArd Biesheuvel 14*50596b75SArd Biesheuvel static inline void set_current(struct task_struct *cur) 15*50596b75SArd Biesheuvel { 16*50596b75SArd Biesheuvel if (!IS_ENABLED(CONFIG_CURRENT_POINTER_IN_TPIDRURO)) 17*50596b75SArd Biesheuvel return; 18*50596b75SArd Biesheuvel 19*50596b75SArd Biesheuvel /* Set TPIDRURO */ 20*50596b75SArd Biesheuvel asm("mcr p15, 0, %0, c13, c0, 3" :: "r"(cur) : "memory"); 21*50596b75SArd Biesheuvel } 22*50596b75SArd Biesheuvel 23*50596b75SArd Biesheuvel #ifdef CONFIG_CURRENT_POINTER_IN_TPIDRURO 24*50596b75SArd Biesheuvel 25*50596b75SArd Biesheuvel static inline struct task_struct *get_current(void) 26*50596b75SArd Biesheuvel { 27*50596b75SArd Biesheuvel struct task_struct *cur; 28*50596b75SArd Biesheuvel 29*50596b75SArd Biesheuvel #if __has_builtin(__builtin_thread_pointer) 30*50596b75SArd Biesheuvel /* 31*50596b75SArd Biesheuvel * Use the __builtin helper when available - this results in better 32*50596b75SArd Biesheuvel * code, especially when using GCC in combination with the per-task 33*50596b75SArd Biesheuvel * stack protector, as the compiler will recognize that it needs to 34*50596b75SArd Biesheuvel * load the TLS register only once in every function. 35*50596b75SArd Biesheuvel */ 36*50596b75SArd Biesheuvel cur = __builtin_thread_pointer(); 37*50596b75SArd Biesheuvel #else 38*50596b75SArd Biesheuvel asm("mrc p15, 0, %0, c13, c0, 3" : "=r"(cur)); 39*50596b75SArd Biesheuvel #endif 40*50596b75SArd Biesheuvel return cur; 41*50596b75SArd Biesheuvel } 42*50596b75SArd Biesheuvel 43*50596b75SArd Biesheuvel #define current get_current() 44*50596b75SArd Biesheuvel #else 45*50596b75SArd Biesheuvel #include <asm-generic/current.h> 46*50596b75SArd Biesheuvel #endif /* CONFIG_CURRENT_POINTER_IN_TPIDRURO */ 47*50596b75SArd Biesheuvel 48*50596b75SArd Biesheuvel #endif /* __ASSEMBLY__ */ 49*50596b75SArd Biesheuvel 50*50596b75SArd Biesheuvel #endif /* _ASM_ARM_CURRENT_H */ 51