page.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #ifndef _ASM_POWERPC_PAGE_H
  2. #define _ASM_POWERPC_PAGE_H
  3. /*
  4. * Copyright (C) 2001,2005 IBM Corporation.
  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. #ifndef __ASSEMBLY__
  12. #include <linux/types.h>
  13. #else
  14. #include <asm/types.h>
  15. #endif
  16. #include <asm/asm-compat.h>
  17. #include <asm/kdump.h>
  18. /*
  19. * On regular PPC32 page size is 4K (but we support 4K/16K/64K/256K pages
  20. * on PPC44x). For PPC64 we support either 4K or 64K software
  21. * page size. When using 64K pages however, whether we are really supporting
  22. * 64K pages in HW or not is irrelevant to those definitions.
  23. */
  24. #if defined(CONFIG_PPC_256K_PAGES)
  25. #define PAGE_SHIFT 18
  26. #elif defined(CONFIG_PPC_64K_PAGES)
  27. #define PAGE_SHIFT 16
  28. #elif defined(CONFIG_PPC_16K_PAGES)
  29. #define PAGE_SHIFT 14
  30. #else
  31. #define PAGE_SHIFT 12
  32. #endif
  33. #define PAGE_SIZE (ASM_CONST(1) << PAGE_SHIFT)
  34. #ifndef __ASSEMBLY__
  35. #ifdef CONFIG_HUGETLB_PAGE
  36. extern unsigned int HPAGE_SHIFT;
  37. #else
  38. #define HPAGE_SHIFT PAGE_SHIFT
  39. #endif
  40. #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
  41. #define HPAGE_MASK (~(HPAGE_SIZE - 1))
  42. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  43. #define HUGE_MAX_HSTATE (MMU_PAGE_COUNT-1)
  44. #endif
  45. /* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
  46. #define __HAVE_ARCH_GATE_AREA 1
  47. /*
  48. * Subtle: (1 << PAGE_SHIFT) is an int, not an unsigned long. So if we
  49. * assign PAGE_MASK to a larger type it gets extended the way we want
  50. * (i.e. with 1s in the high bits)
  51. */
  52. #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
  53. /*
  54. * KERNELBASE is the virtual address of the start of the kernel, it's often
  55. * the same as PAGE_OFFSET, but _might not be_.
  56. *
  57. * The kdump dump kernel is one example where KERNELBASE != PAGE_OFFSET.
  58. *
  59. * PAGE_OFFSET is the virtual address of the start of lowmem.
  60. *
  61. * PHYSICAL_START is the physical address of the start of the kernel.
  62. *
  63. * MEMORY_START is the physical address of the start of lowmem.
  64. *
  65. * KERNELBASE, PAGE_OFFSET, and PHYSICAL_START are all configurable on
  66. * ppc32 and based on how they are set we determine MEMORY_START.
  67. *
  68. * For the linear mapping the following equation should be true:
  69. * KERNELBASE - PAGE_OFFSET = PHYSICAL_START - MEMORY_START
  70. *
  71. * Also, KERNELBASE >= PAGE_OFFSET and PHYSICAL_START >= MEMORY_START
  72. *
  73. * There are two was to determine a physical address from a virtual one:
  74. * va = pa + PAGE_OFFSET - MEMORY_START
  75. * va = pa + KERNELBASE - PHYSICAL_START
  76. *
  77. * If you want to know something's offset from the start of the kernel you
  78. * should subtract KERNELBASE.
  79. *
  80. * If you want to test if something's a kernel address, use is_kernel_addr().
  81. */
  82. #define KERNELBASE ASM_CONST(CONFIG_KERNEL_START)
  83. #define PAGE_OFFSET ASM_CONST(CONFIG_PAGE_OFFSET)
  84. #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_PHYSICAL_START))
  85. #if defined(CONFIG_NONSTATIC_KERNEL)
  86. #ifndef __ASSEMBLY__
  87. extern phys_addr_t memstart_addr;
  88. extern phys_addr_t kernstart_addr;
  89. #endif
  90. #define PHYSICAL_START kernstart_addr
  91. #else
  92. #define PHYSICAL_START ASM_CONST(CONFIG_PHYSICAL_START)
  93. #endif
  94. #ifdef CONFIG_PPC64
  95. #define MEMORY_START 0UL
  96. #elif defined(CONFIG_NONSTATIC_KERNEL)
  97. #define MEMORY_START memstart_addr
  98. #else
  99. #define MEMORY_START (PHYSICAL_START + PAGE_OFFSET - KERNELBASE)
  100. #endif
  101. #ifdef CONFIG_FLATMEM
  102. #define ARCH_PFN_OFFSET ((unsigned long)(MEMORY_START >> PAGE_SHIFT))
  103. #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr)
  104. #endif
  105. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  106. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  107. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  108. /*
  109. * On Book-E parts we need __va to parse the device tree and we can't
  110. * determine MEMORY_START until then. However we can determine PHYSICAL_START
  111. * from information at hand (program counter, TLB lookup).
  112. *
  113. * On non-Book-E PPC64 PAGE_OFFSET and MEMORY_START are constants so use
  114. * the other definitions for __va & __pa.
  115. */
  116. #ifdef CONFIG_BOOKE
  117. #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) - PHYSICAL_START + KERNELBASE))
  118. #define __pa(x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE)
  119. #else
  120. #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START))
  121. #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START)
  122. #endif
  123. /*
  124. * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
  125. * and needs to be executable. This means the whole heap ends
  126. * up being executable.
  127. */
  128. #define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  129. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  130. #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  131. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  132. #ifdef __powerpc64__
  133. #include <asm/page_64.h>
  134. #else
  135. #include <asm/page_32.h>
  136. #endif
  137. /* align addr on a size boundary - adjust address up/down if needed */
  138. #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
  139. #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
  140. /* align addr on a size boundary - adjust address up if needed */
  141. #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
  142. /*
  143. * Don't compare things with KERNELBASE or PAGE_OFFSET to test for
  144. * "kernelness", use is_kernel_addr() - it should do what you want.
  145. */
  146. #ifdef CONFIG_PPC_BOOK3E_64
  147. #define is_kernel_addr(x) ((x) >= 0x8000000000000000ul)
  148. #else
  149. #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
  150. #endif
  151. /*
  152. * Use the top bit of the higher-level page table entries to indicate whether
  153. * the entries we point to contain hugepages. This works because we know that
  154. * the page tables live in kernel space. If we ever decide to support having
  155. * page tables at arbitrary addresses, this breaks and will have to change.
  156. */
  157. #ifdef CONFIG_PPC64
  158. #define PD_HUGE 0x8000000000000000
  159. #else
  160. #define PD_HUGE 0x80000000
  161. #endif
  162. /*
  163. * Some number of bits at the level of the page table that points to
  164. * a hugepte are used to encode the size. This masks those bits.
  165. */
  166. #define HUGEPD_SHIFT_MASK 0x3f
  167. #ifndef __ASSEMBLY__
  168. #undef STRICT_MM_TYPECHECKS
  169. #ifdef STRICT_MM_TYPECHECKS
  170. /* These are used to make use of C type-checking. */
  171. /* PTE level */
  172. typedef struct { pte_basic_t pte; } pte_t;
  173. #define pte_val(x) ((x).pte)
  174. #define __pte(x) ((pte_t) { (x) })
  175. /* 64k pages additionally define a bigger "real PTE" type that gathers
  176. * the "second half" part of the PTE for pseudo 64k pages
  177. */
  178. #if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC_STD_MMU_64)
  179. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  180. #else
  181. typedef struct { pte_t pte; } real_pte_t;
  182. #endif
  183. /* PMD level */
  184. #ifdef CONFIG_PPC64
  185. typedef struct { unsigned long pmd; } pmd_t;
  186. #define pmd_val(x) ((x).pmd)
  187. #define __pmd(x) ((pmd_t) { (x) })
  188. /* PUD level exusts only on 4k pages */
  189. #ifndef CONFIG_PPC_64K_PAGES
  190. typedef struct { unsigned long pud; } pud_t;
  191. #define pud_val(x) ((x).pud)
  192. #define __pud(x) ((pud_t) { (x) })
  193. #endif /* !CONFIG_PPC_64K_PAGES */
  194. #endif /* CONFIG_PPC64 */
  195. /* PGD level */
  196. typedef struct { unsigned long pgd; } pgd_t;
  197. #define pgd_val(x) ((x).pgd)
  198. #define __pgd(x) ((pgd_t) { (x) })
  199. /* Page protection bits */
  200. typedef struct { unsigned long pgprot; } pgprot_t;
  201. #define pgprot_val(x) ((x).pgprot)
  202. #define __pgprot(x) ((pgprot_t) { (x) })
  203. #else
  204. /*
  205. * .. while these make it easier on the compiler
  206. */
  207. typedef pte_basic_t pte_t;
  208. #define pte_val(x) (x)
  209. #define __pte(x) (x)
  210. #if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC_STD_MMU_64)
  211. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  212. #else
  213. typedef pte_t real_pte_t;
  214. #endif
  215. #ifdef CONFIG_PPC64
  216. typedef unsigned long pmd_t;
  217. #define pmd_val(x) (x)
  218. #define __pmd(x) (x)
  219. #ifndef CONFIG_PPC_64K_PAGES
  220. typedef unsigned long pud_t;
  221. #define pud_val(x) (x)
  222. #define __pud(x) (x)
  223. #endif /* !CONFIG_PPC_64K_PAGES */
  224. #endif /* CONFIG_PPC64 */
  225. typedef unsigned long pgd_t;
  226. #define pgd_val(x) (x)
  227. #define pgprot_val(x) (x)
  228. typedef unsigned long pgprot_t;
  229. #define __pgd(x) (x)
  230. #define __pgprot(x) (x)
  231. #endif
  232. typedef struct { signed long pd; } hugepd_t;
  233. #ifdef CONFIG_HUGETLB_PAGE
  234. static inline int hugepd_ok(hugepd_t hpd)
  235. {
  236. return (hpd.pd > 0);
  237. }
  238. #define is_hugepd(pdep) (hugepd_ok(*((hugepd_t *)(pdep))))
  239. #else /* CONFIG_HUGETLB_PAGE */
  240. #define is_hugepd(pdep) 0
  241. #endif /* CONFIG_HUGETLB_PAGE */
  242. struct page;
  243. extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
  244. extern void copy_user_page(void *to, void *from, unsigned long vaddr,
  245. struct page *p);
  246. extern int page_is_ram(unsigned long pfn);
  247. extern int devmem_is_allowed(unsigned long pfn);
  248. #ifdef CONFIG_PPC_SMLPAR
  249. void arch_free_page(struct page *page, int order);
  250. #define HAVE_ARCH_FREE_PAGE
  251. #endif
  252. struct vm_area_struct;
  253. typedef struct page *pgtable_t;
  254. #include <asm-generic/memory_model.h>
  255. #endif /* __ASSEMBLY__ */
  256. #endif /* _ASM_POWERPC_PAGE_H */