page.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. /* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
  35. #define __HAVE_ARCH_GATE_AREA 1
  36. /*
  37. * Subtle: (1 << PAGE_SHIFT) is an int, not an unsigned long. So if we
  38. * assign PAGE_MASK to a larger type it gets extended the way we want
  39. * (i.e. with 1s in the high bits)
  40. */
  41. #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
  42. /*
  43. * KERNELBASE is the virtual address of the start of the kernel, it's often
  44. * the same as PAGE_OFFSET, but _might not be_.
  45. *
  46. * The kdump dump kernel is one example where KERNELBASE != PAGE_OFFSET.
  47. *
  48. * PAGE_OFFSET is the virtual address of the start of lowmem.
  49. *
  50. * PHYSICAL_START is the physical address of the start of the kernel.
  51. *
  52. * MEMORY_START is the physical address of the start of lowmem.
  53. *
  54. * KERNELBASE, PAGE_OFFSET, and PHYSICAL_START are all configurable on
  55. * ppc32 and based on how they are set we determine MEMORY_START.
  56. *
  57. * For the linear mapping the following equation should be true:
  58. * KERNELBASE - PAGE_OFFSET = PHYSICAL_START - MEMORY_START
  59. *
  60. * Also, KERNELBASE >= PAGE_OFFSET and PHYSICAL_START >= MEMORY_START
  61. *
  62. * There are two was to determine a physical address from a virtual one:
  63. * va = pa + PAGE_OFFSET - MEMORY_START
  64. * va = pa + KERNELBASE - PHYSICAL_START
  65. *
  66. * If you want to know something's offset from the start of the kernel you
  67. * should subtract KERNELBASE.
  68. *
  69. * If you want to test if something's a kernel address, use is_kernel_addr().
  70. */
  71. #define KERNELBASE ASM_CONST(CONFIG_KERNEL_START)
  72. #define PAGE_OFFSET ASM_CONST(CONFIG_PAGE_OFFSET)
  73. #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_PHYSICAL_START))
  74. #if defined(CONFIG_RELOCATABLE)
  75. #ifndef __ASSEMBLY__
  76. extern phys_addr_t memstart_addr;
  77. extern phys_addr_t kernstart_addr;
  78. #endif
  79. #define PHYSICAL_START kernstart_addr
  80. #else
  81. #define PHYSICAL_START ASM_CONST(CONFIG_PHYSICAL_START)
  82. #endif
  83. #ifdef CONFIG_PPC64
  84. #define MEMORY_START 0UL
  85. #elif defined(CONFIG_RELOCATABLE)
  86. #define MEMORY_START memstart_addr
  87. #else
  88. #define MEMORY_START (PHYSICAL_START + PAGE_OFFSET - KERNELBASE)
  89. #endif
  90. #ifdef CONFIG_FLATMEM
  91. #define ARCH_PFN_OFFSET (MEMORY_START >> PAGE_SHIFT)
  92. #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < (ARCH_PFN_OFFSET + max_mapnr))
  93. #endif
  94. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  95. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  96. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  97. #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - MEMORY_START))
  98. #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START)
  99. /*
  100. * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
  101. * and needs to be executable. This means the whole heap ends
  102. * up being executable.
  103. */
  104. #define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  105. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  106. #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  107. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  108. #ifdef __powerpc64__
  109. #include <asm/page_64.h>
  110. #else
  111. #include <asm/page_32.h>
  112. #endif
  113. /* align addr on a size boundary - adjust address up/down if needed */
  114. #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
  115. #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
  116. /* align addr on a size boundary - adjust address up if needed */
  117. #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
  118. /*
  119. * Don't compare things with KERNELBASE or PAGE_OFFSET to test for
  120. * "kernelness", use is_kernel_addr() - it should do what you want.
  121. */
  122. #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
  123. #ifndef __ASSEMBLY__
  124. #undef STRICT_MM_TYPECHECKS
  125. #ifdef STRICT_MM_TYPECHECKS
  126. /* These are used to make use of C type-checking. */
  127. /* PTE level */
  128. typedef struct { pte_basic_t pte; } pte_t;
  129. #define pte_val(x) ((x).pte)
  130. #define __pte(x) ((pte_t) { (x) })
  131. /* 64k pages additionally define a bigger "real PTE" type that gathers
  132. * the "second half" part of the PTE for pseudo 64k pages
  133. */
  134. #if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC_STD_MMU_64)
  135. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  136. #else
  137. typedef struct { pte_t pte; } real_pte_t;
  138. #endif
  139. /* PMD level */
  140. #ifdef CONFIG_PPC64
  141. typedef struct { unsigned long pmd; } pmd_t;
  142. #define pmd_val(x) ((x).pmd)
  143. #define __pmd(x) ((pmd_t) { (x) })
  144. /* PUD level exusts only on 4k pages */
  145. #ifndef CONFIG_PPC_64K_PAGES
  146. typedef struct { unsigned long pud; } pud_t;
  147. #define pud_val(x) ((x).pud)
  148. #define __pud(x) ((pud_t) { (x) })
  149. #endif /* !CONFIG_PPC_64K_PAGES */
  150. #endif /* CONFIG_PPC64 */
  151. /* PGD level */
  152. typedef struct { unsigned long pgd; } pgd_t;
  153. #define pgd_val(x) ((x).pgd)
  154. #define __pgd(x) ((pgd_t) { (x) })
  155. /* Page protection bits */
  156. typedef struct { unsigned long pgprot; } pgprot_t;
  157. #define pgprot_val(x) ((x).pgprot)
  158. #define __pgprot(x) ((pgprot_t) { (x) })
  159. #else
  160. /*
  161. * .. while these make it easier on the compiler
  162. */
  163. typedef pte_basic_t pte_t;
  164. #define pte_val(x) (x)
  165. #define __pte(x) (x)
  166. #if defined(CONFIG_PPC_64K_PAGES) && defined(CONFIG_PPC_STD_MMU_64)
  167. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  168. #else
  169. typedef pte_t real_pte_t;
  170. #endif
  171. #ifdef CONFIG_PPC64
  172. typedef unsigned long pmd_t;
  173. #define pmd_val(x) (x)
  174. #define __pmd(x) (x)
  175. #ifndef CONFIG_PPC_64K_PAGES
  176. typedef unsigned long pud_t;
  177. #define pud_val(x) (x)
  178. #define __pud(x) (x)
  179. #endif /* !CONFIG_PPC_64K_PAGES */
  180. #endif /* CONFIG_PPC64 */
  181. typedef unsigned long pgd_t;
  182. #define pgd_val(x) (x)
  183. #define pgprot_val(x) (x)
  184. typedef unsigned long pgprot_t;
  185. #define __pgd(x) (x)
  186. #define __pgprot(x) (x)
  187. #endif
  188. struct page;
  189. extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
  190. extern void copy_user_page(void *to, void *from, unsigned long vaddr,
  191. struct page *p);
  192. extern int page_is_ram(unsigned long pfn);
  193. struct vm_area_struct;
  194. typedef struct page *pgtable_t;
  195. #include <asm-generic/memory_model.h>
  196. #endif /* __ASSEMBLY__ */
  197. #endif /* _ASM_POWERPC_PAGE_H */