page.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_IA64_PAGE_H
  3. #define _ASM_IA64_PAGE_H
  4. /*
  5. * Pagetable related stuff.
  6. *
  7. * Copyright (C) 1998, 1999, 2002 Hewlett-Packard Co
  8. * David Mosberger-Tang <davidm@hpl.hp.com>
  9. */
  10. #include <asm/intrinsics.h>
  11. #include <asm/types.h>
  12. /*
  13. * The top three bits of an IA64 address are its Region Number.
  14. * Different regions are assigned to different purposes.
  15. */
  16. #define RGN_SHIFT (61)
  17. #define RGN_BASE(r) (__IA64_UL_CONST(r)<<RGN_SHIFT)
  18. #define RGN_BITS (RGN_BASE(-1))
  19. #define RGN_KERNEL 7 /* Identity mapped region */
  20. #define RGN_UNCACHED 6 /* Identity mapped I/O region */
  21. #define RGN_GATE 5 /* Gate page, Kernel text, etc */
  22. #define RGN_HPAGE 4 /* For Huge TLB pages */
  23. /*
  24. * PAGE_SHIFT determines the actual kernel page size.
  25. */
  26. #if defined(CONFIG_IA64_PAGE_SIZE_4KB)
  27. # define PAGE_SHIFT 12
  28. #elif defined(CONFIG_IA64_PAGE_SIZE_8KB)
  29. # define PAGE_SHIFT 13
  30. #elif defined(CONFIG_IA64_PAGE_SIZE_16KB)
  31. # define PAGE_SHIFT 14
  32. #elif defined(CONFIG_IA64_PAGE_SIZE_64KB)
  33. # define PAGE_SHIFT 16
  34. #else
  35. # error Unsupported page size!
  36. #endif
  37. #define PAGE_SIZE (__IA64_UL_CONST(1) << PAGE_SHIFT)
  38. #define PAGE_MASK (~(PAGE_SIZE - 1))
  39. #define PERCPU_PAGE_SHIFT 18 /* log2() of max. size of per-CPU area */
  40. #define PERCPU_PAGE_SIZE (__IA64_UL_CONST(1) << PERCPU_PAGE_SHIFT)
  41. #ifdef CONFIG_HUGETLB_PAGE
  42. # define HPAGE_REGION_BASE RGN_BASE(RGN_HPAGE)
  43. # define HPAGE_SHIFT hpage_shift
  44. # define HPAGE_SHIFT_DEFAULT 28 /* check ia64 SDM for architecture supported size */
  45. # define HPAGE_SIZE (__IA64_UL_CONST(1) << HPAGE_SHIFT)
  46. # define HPAGE_MASK (~(HPAGE_SIZE - 1))
  47. # define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
  48. #endif /* CONFIG_HUGETLB_PAGE */
  49. #ifdef __ASSEMBLY__
  50. # define __pa(x) ((x) - PAGE_OFFSET)
  51. # define __va(x) ((x) + PAGE_OFFSET)
  52. #else /* !__ASSEMBLY */
  53. # define STRICT_MM_TYPECHECKS
  54. extern void clear_page (void *page);
  55. extern void copy_page (void *to, void *from);
  56. /*
  57. * clear_user_page() and copy_user_page() can't be inline functions because
  58. * flush_dcache_page() can't be defined until later...
  59. */
  60. #define clear_user_page(addr, vaddr, page) \
  61. do { \
  62. clear_page(addr); \
  63. flush_dcache_page(page); \
  64. } while (0)
  65. #define copy_user_page(to, from, vaddr, page) \
  66. do { \
  67. copy_page((to), (from)); \
  68. flush_dcache_page(page); \
  69. } while (0)
  70. #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
  71. ({ \
  72. struct page *page = alloc_page_vma( \
  73. GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr); \
  74. if (page) \
  75. flush_dcache_page(page); \
  76. page; \
  77. })
  78. #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
  79. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  80. #ifdef CONFIG_VIRTUAL_MEM_MAP
  81. extern int ia64_pfn_valid (unsigned long pfn);
  82. #else
  83. # define ia64_pfn_valid(pfn) 1
  84. #endif
  85. #ifdef CONFIG_VIRTUAL_MEM_MAP
  86. extern struct page *vmem_map;
  87. #ifdef CONFIG_DISCONTIGMEM
  88. # define page_to_pfn(page) ((unsigned long) (page - vmem_map))
  89. # define pfn_to_page(pfn) (vmem_map + (pfn))
  90. # define __pfn_to_phys(pfn) PFN_PHYS(pfn)
  91. #else
  92. # include <asm-generic/memory_model.h>
  93. #endif
  94. #else
  95. # include <asm-generic/memory_model.h>
  96. #endif
  97. #ifdef CONFIG_FLATMEM
  98. # define pfn_valid(pfn) (((pfn) < max_mapnr) && ia64_pfn_valid(pfn))
  99. #elif defined(CONFIG_DISCONTIGMEM)
  100. extern unsigned long min_low_pfn;
  101. extern unsigned long max_low_pfn;
  102. # define pfn_valid(pfn) (((pfn) >= min_low_pfn) && ((pfn) < max_low_pfn) && ia64_pfn_valid(pfn))
  103. #endif
  104. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  105. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  106. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  107. typedef union ia64_va {
  108. struct {
  109. unsigned long off : 61; /* intra-region offset */
  110. unsigned long reg : 3; /* region number */
  111. } f;
  112. unsigned long l;
  113. void *p;
  114. } ia64_va;
  115. /*
  116. * Note: These macros depend on the fact that PAGE_OFFSET has all
  117. * region bits set to 1 and all other bits set to zero. They are
  118. * expressed in this way to ensure they result in a single "dep"
  119. * instruction.
  120. */
  121. #define __pa(x) ({ia64_va _v; _v.l = (long) (x); _v.f.reg = 0; _v.l;})
  122. #define __va(x) ({ia64_va _v; _v.l = (long) (x); _v.f.reg = -1; _v.p;})
  123. #define REGION_NUMBER(x) ({ia64_va _v; _v.l = (long) (x); _v.f.reg;})
  124. #define REGION_OFFSET(x) ({ia64_va _v; _v.l = (long) (x); _v.f.off;})
  125. #ifdef CONFIG_HUGETLB_PAGE
  126. # define htlbpage_to_page(x) (((unsigned long) REGION_NUMBER(x) << 61) \
  127. | (REGION_OFFSET(x) >> (HPAGE_SHIFT-PAGE_SHIFT)))
  128. # define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  129. extern unsigned int hpage_shift;
  130. #endif
  131. static __inline__ int
  132. get_order (unsigned long size)
  133. {
  134. long double d = size - 1;
  135. long order;
  136. order = ia64_getf_exp(d);
  137. order = order - PAGE_SHIFT - 0xffff + 1;
  138. if (order < 0)
  139. order = 0;
  140. return order;
  141. }
  142. #endif /* !__ASSEMBLY__ */
  143. #ifdef STRICT_MM_TYPECHECKS
  144. /*
  145. * These are used to make use of C type-checking..
  146. */
  147. typedef struct { unsigned long pte; } pte_t;
  148. typedef struct { unsigned long pmd; } pmd_t;
  149. #if CONFIG_PGTABLE_LEVELS == 4
  150. typedef struct { unsigned long pud; } pud_t;
  151. #endif
  152. typedef struct { unsigned long pgd; } pgd_t;
  153. typedef struct { unsigned long pgprot; } pgprot_t;
  154. typedef struct page *pgtable_t;
  155. # define pte_val(x) ((x).pte)
  156. # define pmd_val(x) ((x).pmd)
  157. #if CONFIG_PGTABLE_LEVELS == 4
  158. # define pud_val(x) ((x).pud)
  159. #endif
  160. # define pgd_val(x) ((x).pgd)
  161. # define pgprot_val(x) ((x).pgprot)
  162. # define __pte(x) ((pte_t) { (x) } )
  163. # define __pmd(x) ((pmd_t) { (x) } )
  164. # define __pgprot(x) ((pgprot_t) { (x) } )
  165. #else /* !STRICT_MM_TYPECHECKS */
  166. /*
  167. * .. while these make it easier on the compiler
  168. */
  169. # ifndef __ASSEMBLY__
  170. typedef unsigned long pte_t;
  171. typedef unsigned long pmd_t;
  172. typedef unsigned long pgd_t;
  173. typedef unsigned long pgprot_t;
  174. typedef struct page *pgtable_t;
  175. # endif
  176. # define pte_val(x) (x)
  177. # define pmd_val(x) (x)
  178. # define pgd_val(x) (x)
  179. # define pgprot_val(x) (x)
  180. # define __pte(x) (x)
  181. # define __pgd(x) (x)
  182. # define __pgprot(x) (x)
  183. #endif /* !STRICT_MM_TYPECHECKS */
  184. #define PAGE_OFFSET RGN_BASE(RGN_KERNEL)
  185. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
  186. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | \
  187. (((current->personality & READ_IMPLIES_EXEC) != 0) \
  188. ? VM_EXEC : 0))
  189. #define GATE_ADDR RGN_BASE(RGN_GATE)
  190. /*
  191. * 0xa000000000000000+2*PERCPU_PAGE_SIZE
  192. * - 0xa000000000000000+3*PERCPU_PAGE_SIZE remain unmapped (guard page)
  193. */
  194. #define KERNEL_START (GATE_ADDR+__IA64_UL_CONST(0x100000000))
  195. #define PERCPU_ADDR (-PERCPU_PAGE_SIZE)
  196. #define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE)
  197. #define __HAVE_ARCH_GATE_AREA 1
  198. #endif /* _ASM_IA64_PAGE_H */