Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright 2012 Calxeda, Inc.
0004  */
0005 #ifndef _ASM_ARM_PERCPU_H_
0006 #define _ASM_ARM_PERCPU_H_
0007 
0008 #include <asm/insn.h>
0009 
0010 register unsigned long current_stack_pointer asm ("sp");
0011 
0012 /*
0013  * Same as asm-generic/percpu.h, except that we store the per cpu offset
0014  * in the TPIDRPRW. TPIDRPRW only exists on V6K and V7
0015  */
0016 #ifdef CONFIG_SMP
0017 static inline void set_my_cpu_offset(unsigned long off)
0018 {
0019     extern unsigned int smp_on_up;
0020 
0021     if (IS_ENABLED(CONFIG_CPU_V6) && !smp_on_up)
0022         return;
0023 
0024     /* Set TPIDRPRW */
0025     asm volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (off) : "memory");
0026 }
0027 
0028 static __always_inline unsigned long __my_cpu_offset(void)
0029 {
0030     unsigned long off;
0031 
0032     /*
0033      * Read TPIDRPRW.
0034      * We want to allow caching the value, so avoid using volatile and
0035      * instead use a fake stack read to hazard against barrier().
0036      */
0037     asm("0: mrc p15, 0, %0, c13, c0, 4          \n\t"
0038 #ifdef CONFIG_CPU_V6
0039         "1:                         \n\t"
0040         "   .subsection 1                   \n\t"
0041 #if defined(CONFIG_ARM_HAS_GROUP_RELOCS) && \
0042     !(defined(MODULE) && defined(CONFIG_ARM_MODULE_PLTS))
0043         "2: " LOAD_SYM_ARMV6(%0, __per_cpu_offset) "    \n\t"
0044         "   b   1b                  \n\t"
0045 #else
0046         "2: ldr %0, 3f                  \n\t"
0047         "   ldr %0, [%0]                \n\t"
0048         "   b   1b                  \n\t"
0049         "3: .long   __per_cpu_offset            \n\t"
0050 #endif
0051         "   .previous                   \n\t"
0052         "   .pushsection \".alt.smp.init\", \"a\"       \n\t"
0053         "   .long   0b - .                  \n\t"
0054         "   b   . + (2b - 0b)               \n\t"
0055         "   .popsection                 \n\t"
0056 #endif
0057          : "=r" (off)
0058          : "Q" (*(const unsigned long *)current_stack_pointer));
0059 
0060     return off;
0061 }
0062 #define __my_cpu_offset __my_cpu_offset()
0063 #else
0064 #define set_my_cpu_offset(x)    do {} while(0)
0065 
0066 #endif /* CONFIG_SMP */
0067 
0068 #include <asm-generic/percpu.h>
0069 
0070 #endif /* _ASM_ARM_PERCPU_H_ */