1 #ifndef __ARM_CPUERRATA_H__
2 #define __ARM_CPUERRATA_H__
3 
4 #include <asm/cpufeature.h>
5 #include <asm/alternative.h>
6 
7 void check_local_cpu_errata(void);
8 void enable_errata_workarounds(void);
9 
10 #define CHECK_WORKAROUND_HELPER(erratum, feature, arch)         \
11 static inline bool check_workaround_##erratum(void)             \
12 {                                                               \
13     if ( !IS_ENABLED(arch) )                                    \
14         return false;                                           \
15     else                                                        \
16     {                                                           \
17         register_t ret;                                         \
18                                                                 \
19         asm volatile (ALTERNATIVE("mov %0, #0",                 \
20                                   "mov %0, #1",                 \
21                                   feature)                      \
22                       : "=r" (ret));                            \
23                                                                 \
24         return unlikely(ret);                                   \
25     }                                                           \
26 }
27 
28 CHECK_WORKAROUND_HELPER(766422, ARM32_WORKAROUND_766422, CONFIG_ARM_32)
29 CHECK_WORKAROUND_HELPER(834220, ARM64_WORKAROUND_834220, CONFIG_ARM_64)
30 CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)
31 
32 #undef CHECK_WORKAROUND_HELPER
33 
34 enum ssbd_state
35 {
36     ARM_SSBD_UNKNOWN,
37     ARM_SSBD_FORCE_DISABLE,
38     ARM_SSBD_RUNTIME,
39     ARM_SSBD_FORCE_ENABLE,
40     ARM_SSBD_MITIGATED,
41 };
42 
43 #ifdef CONFIG_ARM_SSBD
44 
45 #include <asm/current.h>
46 
47 extern enum ssbd_state ssbd_state;
48 
get_ssbd_state(void)49 static inline enum ssbd_state get_ssbd_state(void)
50 {
51     return ssbd_state;
52 }
53 
54 DECLARE_PER_CPU(register_t, ssbd_callback_required);
55 
cpu_require_ssbd_mitigation(void)56 static inline bool cpu_require_ssbd_mitigation(void)
57 {
58     return this_cpu(ssbd_callback_required);
59 }
60 
61 #else
62 
cpu_require_ssbd_mitigation(void)63 static inline bool cpu_require_ssbd_mitigation(void)
64 {
65     return false;
66 }
67 
get_ssbd_state(void)68 static inline enum ssbd_state get_ssbd_state(void)
69 {
70     return ARM_SSBD_UNKNOWN;
71 }
72 
73 #endif
74 
75 #endif /* __ARM_CPUERRATA_H__ */
76 /*
77  * Local variables:
78  * mode: C
79  * c-file-style: "BSD"
80  * c-basic-offset: 4
81  * indent-tabs-mode: nil
82  * End:
83  */
84