FROMLIST: [PATCH 4/6] arm64: compat: Add a 32-bit vDSO
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / arch / arm64 / kernel / vdso32 / compiler.h
1 /*
2 * Userspace implementations of fallback calls
3 *
4 * Copyright (C) 2017 Cavium, Inc.
5 * Copyright (C) 2012 ARM Limited
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Will Deacon <will.deacon@arm.com>
20 * Rewriten into C by: Andrew Pinski <apinski@cavium.com>
21 */
22
23 #ifndef __VDSO_COMPILER_H
24 #define __VDSO_COMPILER_H
25
26 #include <asm/barrier.h> /* for isb() & dmb() */
27 #include <asm/param.h> /* for HZ */
28 #include <asm/unistd32.h>
29 #include <linux/compiler.h>
30
31 #ifdef CONFIG_ARM_ARCH_TIMER
32 #define ARCH_PROVIDES_TIMER
33 #endif
34
35 /* can not include linux/time.h because of too much architectural cruft */
36 #ifndef NSEC_PER_SEC
37 #define NSEC_PER_SEC 1000000000L
38 #endif
39
40 /* can not include linux/jiffies.h because of too much architectural cruft */
41 #ifndef TICK_NSEC
42 #define TICK_NSEC ((NSEC_PER_SEC+HZ/2)/HZ)
43 #endif
44
45 /* can not include linux/hrtimer.h because of too much architectural cruft */
46 #ifndef LOW_RES_NSEC
47 #define LOW_RES_NSEC TICK_NSEC
48 #ifdef ARCH_PROVIDES_TIMER
49 #ifdef CONFIG_HIGH_RES_TIMERS
50 # define HIGH_RES_NSEC 1
51 # define MONOTONIC_RES_NSEC HIGH_RES_NSEC
52 #else
53 # define MONOTONIC_RES_NSEC LOW_RES_NSEC
54 #endif
55 #endif
56 #endif
57
58 #define DEFINE_FALLBACK(name, type_arg1, name_arg1, type_arg2, name_arg2) \
59 static notrace long name##_fallback(type_arg1 _##name_arg1, \
60 type_arg2 _##name_arg2) \
61 { \
62 register type_arg1 name_arg1 asm("r0") = _##name_arg1; \
63 register type_arg2 name_arg2 asm("r1") = _##name_arg2; \
64 register long ret asm ("r0"); \
65 register long nr asm("r7") = __NR_##name; \
66 \
67 asm volatile( \
68 " swi #0\n" \
69 : "=r" (ret) \
70 : "r" (name_arg1), "r" (name_arg2), "r" (nr) \
71 : "memory"); \
72 \
73 return ret; \
74 }
75
76 /*
77 * AArch32 implementation of arch_counter_get_cntvct() suitable for vdso
78 */
79 static __always_inline notrace u64 arch_vdso_read_counter(void)
80 {
81 u64 res;
82
83 /* Read the virtual counter. */
84 isb();
85 asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (res));
86
87 return res;
88 }
89
90 /*
91 * Can not include asm/processor.h to pick this up because of all the
92 * architectural components also included, so we open code a copy.
93 */
94 static inline void cpu_relax(void)
95 {
96 asm volatile("yield" ::: "memory");
97 }
98
99 #undef smp_rmb
100 #if __LINUX_ARM_ARCH__ >= 8
101 #define smp_rmb() dmb(ishld) /* ok on ARMv8 */
102 #else
103 #define smp_rmb() dmb(ish) /* ishld does not exist on ARMv7 */
104 #endif
105
106 /* Avoid unresolved references emitted by GCC */
107
108 void __aeabi_unwind_cpp_pr0(void)
109 {
110 }
111
112 void __aeabi_unwind_cpp_pr1(void)
113 {
114 }
115
116 void __aeabi_unwind_cpp_pr2(void)
117 {
118 }
119
120 #endif /* __VDSO_COMPILER_H */