page.h 6.4 KB

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