page.h 6.7 KB

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