page_64.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. #ifndef _ASM_POWERPC_PAGE_64_H
  2. #define _ASM_POWERPC_PAGE_64_H
  3. #ifdef __KERNEL__
  4. /*
  5. * Copyright (C) 2001 PPC64 Team, IBM Corp
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. /*
  13. * We always define HW_PAGE_SHIFT to 12 as use of 64K pages remains Linux
  14. * specific, every notion of page number shared with the firmware, TCEs,
  15. * iommu, etc... still uses a page size of 4K.
  16. */
  17. #define HW_PAGE_SHIFT 12
  18. #define HW_PAGE_SIZE (ASM_CONST(1) << HW_PAGE_SHIFT)
  19. #define HW_PAGE_MASK (~(HW_PAGE_SIZE-1))
  20. /*
  21. * PAGE_FACTOR is the number of bits factor between PAGE_SHIFT and
  22. * HW_PAGE_SHIFT, that is 4K pages.
  23. */
  24. #define PAGE_FACTOR (PAGE_SHIFT - HW_PAGE_SHIFT)
  25. /* Segment size; normal 256M segments */
  26. #define SID_SHIFT 28
  27. #define SID_MASK ASM_CONST(0xfffffffff)
  28. #define ESID_MASK 0xfffffffff0000000UL
  29. #define GET_ESID(x) (((x) >> SID_SHIFT) & SID_MASK)
  30. /* 1T segments */
  31. #define SID_SHIFT_1T 40
  32. #define SID_MASK_1T 0xffffffUL
  33. #define ESID_MASK_1T 0xffffff0000000000UL
  34. #define GET_ESID_1T(x) (((x) >> SID_SHIFT_1T) & SID_MASK_1T)
  35. #ifndef __ASSEMBLY__
  36. #include <asm/cache.h>
  37. typedef unsigned long pte_basic_t;
  38. static __inline__ void clear_page(void *addr)
  39. {
  40. unsigned long lines, line_size;
  41. line_size = ppc64_caches.dline_size;
  42. lines = ppc64_caches.dlines_per_page;
  43. __asm__ __volatile__(
  44. "mtctr %1 # clear_page\n\
  45. 1: dcbz 0,%0\n\
  46. add %0,%0,%3\n\
  47. bdnz+ 1b"
  48. : "=r" (addr)
  49. : "r" (lines), "0" (addr), "r" (line_size)
  50. : "ctr", "memory");
  51. }
  52. extern void copy_4K_page(void *to, void *from);
  53. #ifdef CONFIG_PPC_64K_PAGES
  54. static inline void copy_page(void *to, void *from)
  55. {
  56. unsigned int i;
  57. for (i=0; i < (1 << (PAGE_SHIFT - 12)); i++) {
  58. copy_4K_page(to, from);
  59. to += 4096;
  60. from += 4096;
  61. }
  62. }
  63. #else /* CONFIG_PPC_64K_PAGES */
  64. static inline void copy_page(void *to, void *from)
  65. {
  66. copy_4K_page(to, from);
  67. }
  68. #endif /* CONFIG_PPC_64K_PAGES */
  69. /* Log 2 of page table size */
  70. extern u64 ppc64_pft_size;
  71. /* Large pages size */
  72. #ifdef CONFIG_HUGETLB_PAGE
  73. extern unsigned int HPAGE_SHIFT;
  74. #else
  75. #define HPAGE_SHIFT PAGE_SHIFT
  76. #endif
  77. #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
  78. #define HPAGE_MASK (~(HPAGE_SIZE - 1))
  79. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  80. #endif /* __ASSEMBLY__ */
  81. #ifdef CONFIG_PPC_MM_SLICES
  82. #define SLICE_LOW_SHIFT 28
  83. #define SLICE_HIGH_SHIFT 40
  84. #define SLICE_LOW_TOP (0x100000000ul)
  85. #define SLICE_NUM_LOW (SLICE_LOW_TOP >> SLICE_LOW_SHIFT)
  86. #define SLICE_NUM_HIGH (PGTABLE_RANGE >> SLICE_HIGH_SHIFT)
  87. #define GET_LOW_SLICE_INDEX(addr) ((addr) >> SLICE_LOW_SHIFT)
  88. #define GET_HIGH_SLICE_INDEX(addr) ((addr) >> SLICE_HIGH_SHIFT)
  89. #ifndef __ASSEMBLY__
  90. struct slice_mask {
  91. u16 low_slices;
  92. u16 high_slices;
  93. };
  94. struct mm_struct;
  95. extern unsigned long slice_get_unmapped_area(unsigned long addr,
  96. unsigned long len,
  97. unsigned long flags,
  98. unsigned int psize,
  99. int topdown,
  100. int use_cache);
  101. extern unsigned int get_slice_psize(struct mm_struct *mm,
  102. unsigned long addr);
  103. extern void slice_init_context(struct mm_struct *mm, unsigned int psize);
  104. extern void slice_set_user_psize(struct mm_struct *mm, unsigned int psize);
  105. #define slice_mm_new_context(mm) ((mm)->context.id == 0)
  106. #define ARCH_HAS_HUGEPAGE_ONLY_RANGE
  107. extern int is_hugepage_only_range(struct mm_struct *m,
  108. unsigned long addr,
  109. unsigned long len);
  110. #endif /* __ASSEMBLY__ */
  111. #else
  112. #define slice_init()
  113. #define slice_set_user_psize(mm, psize) \
  114. do { \
  115. (mm)->context.user_psize = (psize); \
  116. (mm)->context.sllp = SLB_VSID_USER | mmu_psize_defs[(psize)].sllp; \
  117. } while (0)
  118. #define slice_mm_new_context(mm) 1
  119. #endif /* CONFIG_PPC_MM_SLICES */
  120. #ifdef CONFIG_HUGETLB_PAGE
  121. #define ARCH_HAS_HUGETLB_FREE_PGD_RANGE
  122. #define ARCH_HAS_SETCLEAR_HUGE_PTE
  123. #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
  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 /* __KERNEL__ */
  150. #endif /* _ASM_POWERPC_PAGE_64_H */