1 #ifndef __ARM_ARM64_PAGE_H__
2 #define __ARM_ARM64_PAGE_H__
3 
4 #ifndef __ASSEMBLY__
5 
6 #include <asm/alternative.h>
7 
8 /* Inline ASM to invalidate dcache on register R (may be an inline asm operand) */
9 #define __invalidate_dcache_one(R) "dc ivac, %" #R ";"
10 
11 /* Inline ASM to flush dcache on register R (may be an inline asm operand) */
12 #define __clean_dcache_one(R)                   \
13     ALTERNATIVE("dc cvac, %" #R ";",            \
14                 "dc civac, %" #R ";",           \
15                 ARM64_WORKAROUND_CLEAN_CACHE)   \
16 
17 /* Inline ASM to clean and invalidate dcache on register R (may be an
18  * inline asm operand) */
19 #define __clean_and_invalidate_dcache_one(R) "dc  civac, %" #R ";"
20 
21 /* Invalidate all instruction caches in Inner Shareable domain to PoU */
invalidate_icache(void)22 static inline void invalidate_icache(void)
23 {
24     asm volatile ("ic ialluis");
25     dsb(ish);               /* Ensure completion of the flush I-cache */
26     isb();
27 }
28 
29 /* Invalidate all instruction caches on the local processor to PoU */
invalidate_icache_local(void)30 static inline void invalidate_icache_local(void)
31 {
32     asm volatile ("ic iallu");
33     dsb(nsh);               /* Ensure completion of the I-cache flush */
34     isb();
35 }
36 
37 /* Ask the MMU to translate a VA for us */
__va_to_par(vaddr_t va)38 static inline uint64_t __va_to_par(vaddr_t va)
39 {
40     uint64_t par, tmp = read_sysreg_par();
41 
42     asm volatile ("at s1e2r, %0;" : : "r" (va));
43     isb();
44     par = read_sysreg_par();
45     WRITE_SYSREG64(tmp, PAR_EL1);
46     return par;
47 }
48 
49 /* Ask the MMU to translate a Guest VA for us */
gva_to_ma_par(vaddr_t va,unsigned int flags)50 static inline uint64_t gva_to_ma_par(vaddr_t va, unsigned int flags)
51 {
52     uint64_t par, tmp = read_sysreg_par();
53 
54     if ( (flags & GV2M_WRITE) == GV2M_WRITE )
55         asm volatile ("at s12e1w, %0;" : : "r" (va));
56     else
57         asm volatile ("at s12e1r, %0;" : : "r" (va));
58     isb();
59     par = read_sysreg_par();
60     WRITE_SYSREG64(tmp, PAR_EL1);
61     return par;
62 }
63 
gva_to_ipa_par(vaddr_t va,unsigned int flags)64 static inline uint64_t gva_to_ipa_par(vaddr_t va, unsigned int flags)
65 {
66     uint64_t par, tmp = read_sysreg_par();
67 
68     if ( (flags & GV2M_WRITE) == GV2M_WRITE )
69         asm volatile ("at s1e1w, %0;" : : "r" (va));
70     else
71         asm volatile ("at s1e1r, %0;" : : "r" (va));
72     isb();
73     par = read_sysreg_par();
74     WRITE_SYSREG64(tmp, PAR_EL1);
75     return par;
76 }
77 
78 extern void clear_page(void *to);
79 
80 #endif /* __ASSEMBLY__ */
81 
82 #endif /* __ARM_ARM64_PAGE_H__ */
83 
84 /*
85  * Local variables:
86  * mode: C
87  * c-file-style: "BSD"
88  * c-basic-offset: 4
89  * tab-width: 4
90  * indent-tabs-mode: nil
91  * End:
92  */
93