page.h 6.5 KB

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