page_64.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef _ASM_POWERPC_PAGE_64_H
  2. #define _ASM_POWERPC_PAGE_64_H
  3. /*
  4. * Copyright (C) 2001 PPC64 Team, IBM Corp
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. /*
  12. * We always define HW_PAGE_SHIFT to 12 as use of 64K pages remains Linux
  13. * specific, every notion of page number shared with the firmware, TCEs,
  14. * iommu, etc... still uses a page size of 4K.
  15. */
  16. #define HW_PAGE_SHIFT 12
  17. #define HW_PAGE_SIZE (ASM_CONST(1) << HW_PAGE_SHIFT)
  18. #define HW_PAGE_MASK (~(HW_PAGE_SIZE-1))
  19. /*
  20. * PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and
  21. * HW_PAGE_SHIFT, that is 4K pages.
  22. */
  23. #define PAGE_FACTOR (PAGE_SHIFT - HW_PAGE_SHIFT)
  24. #define REGION_SIZE 4UL
  25. #define REGION_SHIFT 60UL
  26. #define REGION_MASK (((1UL<<REGION_SIZE)-1UL)<<REGION_SHIFT)
  27. #define VMALLOCBASE ASM_CONST(0xD000000000000000)
  28. #define VMALLOC_REGION_ID (VMALLOCBASE >> REGION_SHIFT)
  29. #define KERNEL_REGION_ID (KERNELBASE >> REGION_SHIFT)
  30. #define USER_REGION_ID (0UL)
  31. #define REGION_ID(ea) (((unsigned long)(ea)) >> REGION_SHIFT)
  32. /* Segment size */
  33. #define SID_SHIFT 28
  34. #define SID_MASK 0xfffffffffUL
  35. #define ESID_MASK 0xfffffffff0000000UL
  36. #define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK)
  37. #ifndef __ASSEMBLY__
  38. #include <asm/cache.h>
  39. typedef unsigned long pte_basic_t;
  40. static __inline__ void clear_page(void *addr)
  41. {
  42. unsigned long lines, line_size;
  43. line_size = ppc64_caches.dline_size;
  44. lines = ppc64_caches.dlines_per_page;
  45. __asm__ __volatile__(
  46. "mtctr %1 # clear_page\n\
  47. 1: dcbz 0,%0\n\
  48. add %0,%0,%3\n\
  49. bdnz+ 1b"
  50. : "=r" (addr)
  51. : "r" (lines), "0" (addr), "r" (line_size)
  52. : "ctr", "memory");
  53. }
  54. extern void copy_4K_page(void *to, void *from);
  55. #ifdef CONFIG_PPC_64K_PAGES
  56. static inline void copy_page(void *to, void *from)
  57. {
  58. unsigned int i;
  59. for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) {
  60. copy_4K_page(to, from);
  61. to += 4096;
  62. from += 4096;
  63. }
  64. }
  65. #else /* CONFIG_PPC_64K_PAGES */
  66. static inline void copy_page(void *to, void *from)
  67. {
  68. copy_4K_page(to, from);
  69. }
  70. #endif /* CONFIG_PPC_64K_PAGES */
  71. /* Log 2 of page table size */
  72. extern u64 ppc64_pft_size;
  73. /* Large pages size */
  74. #ifdef CONFIG_HUGETLB_PAGE
  75. extern unsigned int HPAGE_SHIFT;
  76. #else
  77. #define HPAGE_SHIFT PAGE_SHIFT
  78. #endif
  79. #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
  80. #define HPAGE_MASK (~(HPAGE_SIZE - 1))
  81. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  82. #endif /* __ASSEMBLY__ */
  83. #ifdef CONFIG_HUGETLB_PAGE
  84. #define HTLB_AREA_SHIFT 40
  85. #define HTLB_AREA_SIZE (1UL << HTLB_AREA_SHIFT)
  86. #define GET_HTLB_AREA(x) ((x) >> HTLB_AREA_SHIFT)
  87. #define LOW_ESID_MASK(addr, len) \
  88. (((1U << (GET_ESID(min((addr)+(len)-1, 0x100000000UL))+1)) \
  89. - (1U << GET_ESID(min((addr), 0x100000000UL)))) & 0xffff)
  90. #define HTLB_AREA_MASK(addr, len) (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \
  91. - (1U << GET_HTLB_AREA(addr))) & 0xffff)
  92. #define ARCH_HAS_HUGEPAGE_ONLY_RANGE
  93. #define ARCH_HAS_PREPARE_HUGEPAGE_RANGE
  94. #define ARCH_HAS_SETCLEAR_HUGE_PTE
  95. #define touches_hugepage_low_range(mm, addr, len) \
  96. (((addr) < 0x100000000UL) \
  97. && (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas))
  98. #define touches_hugepage_high_range(mm, addr, len) \
  99. ((((addr) + (len)) > 0x100000000UL) \
  100. && (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas))
  101. #define __within_hugepage_low_range(addr, len, segmask) \
  102. ( (((addr)+(len)) <= 0x100000000UL) \
  103. && ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask)))
  104. #define within_hugepage_low_range(addr, len) \
  105. __within_hugepage_low_range((addr), (len), \
  106. current->mm->context.low_htlb_areas)
  107. #define __within_hugepage_high_range(addr, len, zonemask) \
  108. ( ((addr) >= 0x100000000UL) \
  109. && ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask)))
  110. #define within_hugepage_high_range(addr, len) \
  111. __within_hugepage_high_range((addr), (len), \
  112. current->mm->context.high_htlb_areas)
  113. #define is_hugepage_only_range(mm, addr, len) \
  114. (touches_hugepage_high_range((mm), (addr), (len)) || \
  115. touches_hugepage_low_range((mm), (addr), (len)))
  116. #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
  117. #define in_hugepage_area(context, addr) \
  118. (cpu_has_feature(CPU_FTR_16M_PAGE) && \
  119. ( ( (addr) >= 0x100000000UL) \
  120. ? ((1 << GET_HTLB_AREA(addr)) & (context).high_htlb_areas) \
  121. : ((1 << GET_ESID(addr)) & (context).low_htlb_areas) ) )
  122. #else /* !CONFIG_HUGETLB_PAGE */
  123. #define in_hugepage_area(mm, addr) 0
  124. #endif /* !CONFIG_HUGETLB_PAGE */
  125. #ifdef MODULE
  126. #define __page_aligned __attribute__((__aligned__(PAGE_SIZE)))
  127. #else
  128. #define __page_aligned \
  129. __attribute__((__aligned__(PAGE_SIZE), \
  130. __section__(".data.page_aligned")))
  131. #endif
  132. #define VM_DATA_DEFAULT_FLAGS \
  133. (test_thread_flag(TIF_32BIT) ? \
  134. VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64)
  135. /*
  136. * This is the default if a program doesn't have a PT_GNU_STACK
  137. * program header entry. The PPC64 ELF ABI has a non executable stack
  138. * stack by default, so in the absense of a PT_GNU_STACK program header
  139. * we turn execute permission off.
  140. */
  141. #define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  142. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  143. #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  144. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  145. #define VM_STACK_DEFAULT_FLAGS \
  146. (test_thread_flag(TIF_32BIT) ? \
  147. VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
  148. #include <asm-generic/page.h>
  149. #endif /* _ASM_POWERPC_PAGE_64_H */