page_64.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /* Segment size */
  25. #define SID_SHIFT 28
  26. #define SID_MASK 0xfffffffffUL
  27. #define ESID_MASK 0xfffffffff0000000UL
  28. #define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK)
  29. #ifndef __ASSEMBLY__
  30. #include <asm/cache.h>
  31. typedef unsigned long pte_basic_t;
  32. static __inline__ void clear_page(void *addr)
  33. {
  34. unsigned long lines, line_size;
  35. line_size = ppc64_caches.dline_size;
  36. lines = ppc64_caches.dlines_per_page;
  37. __asm__ __volatile__(
  38. "mtctr %1 # clear_page\n\
  39. 1: dcbz 0,%0\n\
  40. add %0,%0,%3\n\
  41. bdnz+ 1b"
  42. : "=r" (addr)
  43. : "r" (lines), "0" (addr), "r" (line_size)
  44. : "ctr", "memory");
  45. }
  46. extern void copy_4K_page(void *to, void *from);
  47. #ifdef CONFIG_PPC_64K_PAGES
  48. static inline void copy_page(void *to, void *from)
  49. {
  50. unsigned int i;
  51. for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) {
  52. copy_4K_page(to, from);
  53. to += 4096;
  54. from += 4096;
  55. }
  56. }
  57. #else /* CONFIG_PPC_64K_PAGES */
  58. static inline void copy_page(void *to, void *from)
  59. {
  60. copy_4K_page(to, from);
  61. }
  62. #endif /* CONFIG_PPC_64K_PAGES */
  63. /* Log 2 of page table size */
  64. extern u64 ppc64_pft_size;
  65. /* Large pages size */
  66. #ifdef CONFIG_HUGETLB_PAGE
  67. extern unsigned int HPAGE_SHIFT;
  68. #else
  69. #define HPAGE_SHIFT PAGE_SHIFT
  70. #endif
  71. #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
  72. #define HPAGE_MASK (~(HPAGE_SIZE - 1))
  73. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  74. #endif /* __ASSEMBLY__ */
  75. #ifdef CONFIG_HUGETLB_PAGE
  76. #define HTLB_AREA_SHIFT 40
  77. #define HTLB_AREA_SIZE (1UL << HTLB_AREA_SHIFT)
  78. #define GET_HTLB_AREA(x) ((x) >> HTLB_AREA_SHIFT)
  79. #define LOW_ESID_MASK(addr, len) \
  80. (((1U << (GET_ESID(min((addr)+(len)-1, 0x100000000UL))+1)) \
  81. - (1U << GET_ESID(min((addr), 0x100000000UL)))) & 0xffff)
  82. #define HTLB_AREA_MASK(addr, len) (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \
  83. - (1U << GET_HTLB_AREA(addr))) & 0xffff)
  84. #define ARCH_HAS_HUGEPAGE_ONLY_RANGE
  85. #define ARCH_HAS_PREPARE_HUGEPAGE_RANGE
  86. #define ARCH_HAS_SETCLEAR_HUGE_PTE
  87. #define touches_hugepage_low_range(mm, addr, len) \
  88. (((addr) < 0x100000000UL) \
  89. && (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas))
  90. #define touches_hugepage_high_range(mm, addr, len) \
  91. ((((addr) + (len)) > 0x100000000UL) \
  92. && (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas))
  93. #define __within_hugepage_low_range(addr, len, segmask) \
  94. ( (((addr)+(len)) <= 0x100000000UL) \
  95. && ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask)))
  96. #define within_hugepage_low_range(addr, len) \
  97. __within_hugepage_low_range((addr), (len), \
  98. current->mm->context.low_htlb_areas)
  99. #define __within_hugepage_high_range(addr, len, zonemask) \
  100. ( ((addr) >= 0x100000000UL) \
  101. && ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask)))
  102. #define within_hugepage_high_range(addr, len) \
  103. __within_hugepage_high_range((addr), (len), \
  104. current->mm->context.high_htlb_areas)
  105. #define is_hugepage_only_range(mm, addr, len) \
  106. (touches_hugepage_high_range((mm), (addr), (len)) || \
  107. touches_hugepage_low_range((mm), (addr), (len)))
  108. #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
  109. #define in_hugepage_area(context, addr) \
  110. (cpu_has_feature(CPU_FTR_16M_PAGE) && \
  111. ( ( (addr) >= 0x100000000UL) \
  112. ? ((1 << GET_HTLB_AREA(addr)) & (context).high_htlb_areas) \
  113. : ((1 << GET_ESID(addr)) & (context).low_htlb_areas) ) )
  114. #else /* !CONFIG_HUGETLB_PAGE */
  115. #define in_hugepage_area(mm, addr) 0
  116. #endif /* !CONFIG_HUGETLB_PAGE */
  117. #ifdef MODULE
  118. #define __page_aligned __attribute__((__aligned__(PAGE_SIZE)))
  119. #else
  120. #define __page_aligned \
  121. __attribute__((__aligned__(PAGE_SIZE), \
  122. __section__(".data.page_aligned")))
  123. #endif
  124. #define VM_DATA_DEFAULT_FLAGS \
  125. (test_thread_flag(TIF_32BIT) ? \
  126. VM_DATA_DEFAULT_FLAGS32 : VM_DATA_DEFAULT_FLAGS64)
  127. /*
  128. * This is the default if a program doesn't have a PT_GNU_STACK
  129. * program header entry. The PPC64 ELF ABI has a non executable stack
  130. * stack by default, so in the absense of a PT_GNU_STACK program header
  131. * we turn execute permission off.
  132. */
  133. #define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  134. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  135. #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  136. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  137. #define VM_STACK_DEFAULT_FLAGS \
  138. (test_thread_flag(TIF_32BIT) ? \
  139. VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
  140. #include <asm-generic/page.h>
  141. #endif /* _ASM_POWERPC_PAGE_64_H */