highmem.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_HIGHMEM_H
  3. #define _ASM_HIGHMEM_H
  4. #include <asm/cachetype.h>
  5. #include <asm/fixmap.h>
  6. #define PKMAP_BASE (PAGE_OFFSET - PMD_SIZE)
  7. #define LAST_PKMAP PTRS_PER_PTE
  8. #define LAST_PKMAP_MASK (LAST_PKMAP - 1)
  9. #define PKMAP_NR(virt) (((virt) - PKMAP_BASE) >> PAGE_SHIFT)
  10. #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
  11. #define flush_cache_kmaps() \
  12. do { \
  13. if (cache_is_vivt()) \
  14. flush_cache_all(); \
  15. } while (0)
  16. extern pte_t *pkmap_page_table;
  17. /*
  18. * The reason for kmap_high_get() is to ensure that the currently kmap'd
  19. * page usage count does not decrease to zero while we're using its
  20. * existing virtual mapping in an atomic context. With a VIVT cache this
  21. * is essential to do, but with a VIPT cache this is only an optimization
  22. * so not to pay the price of establishing a second mapping if an existing
  23. * one can be used. However, on platforms without hardware TLB maintenance
  24. * broadcast, we simply cannot use ARCH_NEEDS_KMAP_HIGH_GET at all since
  25. * the locking involved must also disable IRQs which is incompatible with
  26. * the IPI mechanism used by global TLB operations.
  27. */
  28. #define ARCH_NEEDS_KMAP_HIGH_GET
  29. #if defined(CONFIG_SMP) && defined(CONFIG_CPU_TLB_V6)
  30. #undef ARCH_NEEDS_KMAP_HIGH_GET
  31. #if defined(CONFIG_HIGHMEM) && defined(CONFIG_CPU_CACHE_VIVT)
  32. #error "The sum of features in your kernel config cannot be supported together"
  33. #endif
  34. #endif
  35. /*
  36. * Needed to be able to broadcast the TLB invalidation for kmap.
  37. */
  38. #ifdef CONFIG_ARM_ERRATA_798181
  39. #undef ARCH_NEEDS_KMAP_HIGH_GET
  40. #endif
  41. #ifdef ARCH_NEEDS_KMAP_HIGH_GET
  42. extern void *kmap_high_get(struct page *page);
  43. static inline void *arch_kmap_local_high_get(struct page *page)
  44. {
  45. if (IS_ENABLED(CONFIG_DEBUG_HIGHMEM) && !cache_is_vivt())
  46. return NULL;
  47. return kmap_high_get(page);
  48. }
  49. #define arch_kmap_local_high_get arch_kmap_local_high_get
  50. #else /* ARCH_NEEDS_KMAP_HIGH_GET */
  51. static inline void *kmap_high_get(struct page *page)
  52. {
  53. return NULL;
  54. }
  55. #endif /* !ARCH_NEEDS_KMAP_HIGH_GET */
  56. #define arch_kmap_local_post_map(vaddr, pteval) \
  57. local_flush_tlb_kernel_page(vaddr)
  58. #define arch_kmap_local_pre_unmap(vaddr) \
  59. do { \
  60. if (cache_is_vivt()) \
  61. __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE); \
  62. } while (0)
  63. #define arch_kmap_local_post_unmap(vaddr) \
  64. local_flush_tlb_kernel_page(vaddr)
  65. #endif