page.h 6.4 KB

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