page.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. # define __pfn_to_phys(pfn) PFN_PHYS(pfn)
  90. #else
  91. # include <asm-generic/memory_model.h>
  92. #endif
  93. #else
  94. # include <asm-generic/memory_model.h>
  95. #endif
  96. #ifdef CONFIG_FLATMEM
  97. # define pfn_valid(pfn) (((pfn) < max_mapnr) && ia64_pfn_valid(pfn))
  98. #elif defined(CONFIG_DISCONTIGMEM)
  99. extern unsigned long min_low_pfn;
  100. extern unsigned long max_low_pfn;
  101. # define pfn_valid(pfn) (((pfn) >= min_low_pfn) && ((pfn) < max_low_pfn) && ia64_pfn_valid(pfn))
  102. #endif
  103. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  104. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  105. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  106. typedef union ia64_va {
  107. struct {
  108. unsigned long off : 61; /* intra-region offset */
  109. unsigned long reg : 3; /* region number */
  110. } f;
  111. unsigned long l;
  112. void *p;
  113. } ia64_va;
  114. /*
  115. * Note: These macros depend on the fact that PAGE_OFFSET has all
  116. * region bits set to 1 and all other bits set to zero. They are
  117. * expressed in this way to ensure they result in a single "dep"
  118. * instruction.
  119. */
  120. #define __pa(x) ({ia64_va _v; _v.l = (long) (x); _v.f.reg = 0; _v.l;})
  121. #define __va(x) ({ia64_va _v; _v.l = (long) (x); _v.f.reg = -1; _v.p;})
  122. #define REGION_NUMBER(x) ({ia64_va _v; _v.l = (long) (x); _v.f.reg;})
  123. #define REGION_OFFSET(x) ({ia64_va _v; _v.l = (long) (x); _v.f.off;})
  124. #ifdef CONFIG_HUGETLB_PAGE
  125. # define htlbpage_to_page(x) (((unsigned long) REGION_NUMBER(x) << 61) \
  126. | (REGION_OFFSET(x) >> (HPAGE_SHIFT-PAGE_SHIFT)))
  127. # define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  128. extern unsigned int hpage_shift;
  129. #endif
  130. static __inline__ int
  131. get_order (unsigned long size)
  132. {
  133. long double d = size - 1;
  134. long order;
  135. order = ia64_getf_exp(d);
  136. order = order - PAGE_SHIFT - 0xffff + 1;
  137. if (order < 0)
  138. order = 0;
  139. return order;
  140. }
  141. #endif /* !__ASSEMBLY__ */
  142. #ifdef STRICT_MM_TYPECHECKS
  143. /*
  144. * These are used to make use of C type-checking..
  145. */
  146. typedef struct { unsigned long pte; } pte_t;
  147. typedef struct { unsigned long pmd; } pmd_t;
  148. #if CONFIG_PGTABLE_LEVELS == 4
  149. typedef struct { unsigned long pud; } pud_t;
  150. #endif
  151. typedef struct { unsigned long pgd; } pgd_t;
  152. typedef struct { unsigned long pgprot; } pgprot_t;
  153. typedef struct page *pgtable_t;
  154. # define pte_val(x) ((x).pte)
  155. # define pmd_val(x) ((x).pmd)
  156. #if CONFIG_PGTABLE_LEVELS == 4
  157. # define pud_val(x) ((x).pud)
  158. #endif
  159. # define pgd_val(x) ((x).pgd)
  160. # define pgprot_val(x) ((x).pgprot)
  161. # define __pte(x) ((pte_t) { (x) } )
  162. # define __pmd(x) ((pmd_t) { (x) } )
  163. # define __pgprot(x) ((pgprot_t) { (x) } )
  164. #else /* !STRICT_MM_TYPECHECKS */
  165. /*
  166. * .. while these make it easier on the compiler
  167. */
  168. # ifndef __ASSEMBLY__
  169. typedef unsigned long pte_t;
  170. typedef unsigned long pmd_t;
  171. typedef unsigned long pgd_t;
  172. typedef unsigned long pgprot_t;
  173. typedef struct page *pgtable_t;
  174. # endif
  175. # define pte_val(x) (x)
  176. # define pmd_val(x) (x)
  177. # define pgd_val(x) (x)
  178. # define pgprot_val(x) (x)
  179. # define __pte(x) (x)
  180. # define __pgd(x) (x)
  181. # define __pgprot(x) (x)
  182. #endif /* !STRICT_MM_TYPECHECKS */
  183. #define PAGE_OFFSET RGN_BASE(RGN_KERNEL)
  184. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
  185. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | \
  186. (((current->personality & READ_IMPLIES_EXEC) != 0) \
  187. ? VM_EXEC : 0))
  188. #define GATE_ADDR RGN_BASE(RGN_GATE)
  189. /*
  190. * 0xa000000000000000+2*PERCPU_PAGE_SIZE
  191. * - 0xa000000000000000+3*PERCPU_PAGE_SIZE remain unmapped (guard page)
  192. */
  193. #define KERNEL_START (GATE_ADDR+__IA64_UL_CONST(0x100000000))
  194. #define PERCPU_ADDR (-PERCPU_PAGE_SIZE)
  195. #define LOAD_OFFSET (KERNEL_START - KERNEL_TR_PAGE_SIZE)
  196. #define __HAVE_ARCH_GATE_AREA 1
  197. #endif /* _ASM_IA64_PAGE_H */