Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64...
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / arch / arm64 / include / asm / mmu_context.h
index 101a42bde728a8b9547bca989b696d473dcd7e42..8ec41e5f56f081b9d65d2ed58769a0f22060716d 100644 (file)
@@ -64,6 +64,49 @@ static inline void cpu_set_reserved_ttbr0(void)
        : "r" (ttbr));
 }
 
+/*
+ * TCR.T0SZ value to use when the ID map is active. Usually equals
+ * TCR_T0SZ(VA_BITS), unless system RAM is positioned very high in
+ * physical memory, in which case it will be smaller.
+ */
+extern u64 idmap_t0sz;
+
+static inline bool __cpu_uses_extended_idmap(void)
+{
+       return (!IS_ENABLED(CONFIG_ARM64_VA_BITS_48) &&
+               unlikely(idmap_t0sz != TCR_T0SZ(VA_BITS)));
+}
+
+static inline void __cpu_set_tcr_t0sz(u64 t0sz)
+{
+       unsigned long tcr;
+
+       if (__cpu_uses_extended_idmap())
+               asm volatile (
+               "       mrs     %0, tcr_el1     ;"
+               "       bfi     %0, %1, %2, %3  ;"
+               "       msr     tcr_el1, %0     ;"
+               "       isb"
+               : "=&r" (tcr)
+               : "r"(t0sz), "I"(TCR_T0SZ_OFFSET), "I"(TCR_TxSZ_WIDTH));
+}
+
+/*
+ * Set TCR.T0SZ to the value appropriate for activating the identity map.
+ */
+static inline void cpu_set_idmap_tcr_t0sz(void)
+{
+       __cpu_set_tcr_t0sz(idmap_t0sz);
+}
+
+/*
+ * Set TCR.T0SZ to its default value (based on VA_BITS)
+ */
+static inline void cpu_set_default_tcr_t0sz(void)
+{
+       __cpu_set_tcr_t0sz(TCR_T0SZ(VA_BITS));
+}
+
 static inline void switch_new_context(struct mm_struct *mm)
 {
        unsigned long flags;