page.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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) && defined(CONFIG_FLATMEM)
  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. #define MEMORY_START memstart_addr
  72. #else
  73. #define PHYSICAL_START ASM_CONST(CONFIG_PHYSICAL_START)
  74. #define MEMORY_START (PHYSICAL_START + PAGE_OFFSET - KERNELBASE)
  75. #endif
  76. #ifdef CONFIG_FLATMEM
  77. #define ARCH_PFN_OFFSET (MEMORY_START >> PAGE_SHIFT)
  78. #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < (ARCH_PFN_OFFSET + max_mapnr))
  79. #endif
  80. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  81. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  82. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  83. #define __va(x) ((void *)((unsigned long)(x) - PHYSICAL_START + KERNELBASE))
  84. #define __pa(x) ((unsigned long)(x) + PHYSICAL_START - KERNELBASE)
  85. /*
  86. * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
  87. * and needs to be executable. This means the whole heap ends
  88. * up being executable.
  89. */
  90. #define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  91. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  92. #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  93. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  94. #ifdef __powerpc64__
  95. #include <asm/page_64.h>
  96. #else
  97. #include <asm/page_32.h>
  98. #endif
  99. /* align addr on a size boundary - adjust address up/down if needed */
  100. #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
  101. #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
  102. /* align addr on a size boundary - adjust address up if needed */
  103. #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
  104. /* to align the pointer to the (next) page boundary */
  105. #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
  106. /*
  107. * Don't compare things with KERNELBASE or PAGE_OFFSET to test for
  108. * "kernelness", use is_kernel_addr() - it should do what you want.
  109. */
  110. #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
  111. #ifndef __ASSEMBLY__
  112. #undef STRICT_MM_TYPECHECKS
  113. #ifdef STRICT_MM_TYPECHECKS
  114. /* These are used to make use of C type-checking. */
  115. /* PTE level */
  116. typedef struct { pte_basic_t pte; } pte_t;
  117. #define pte_val(x) ((x).pte)
  118. #define __pte(x) ((pte_t) { (x) })
  119. /* 64k pages additionally define a bigger "real PTE" type that gathers
  120. * the "second half" part of the PTE for pseudo 64k pages
  121. */
  122. #ifdef CONFIG_PPC_64K_PAGES
  123. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  124. #else
  125. typedef struct { pte_t pte; } real_pte_t;
  126. #endif
  127. /* PMD level */
  128. #ifdef CONFIG_PPC64
  129. typedef struct { unsigned long pmd; } pmd_t;
  130. #define pmd_val(x) ((x).pmd)
  131. #define __pmd(x) ((pmd_t) { (x) })
  132. /* PUD level exusts only on 4k pages */
  133. #ifndef CONFIG_PPC_64K_PAGES
  134. typedef struct { unsigned long pud; } pud_t;
  135. #define pud_val(x) ((x).pud)
  136. #define __pud(x) ((pud_t) { (x) })
  137. #endif /* !CONFIG_PPC_64K_PAGES */
  138. #endif /* CONFIG_PPC64 */
  139. /* PGD level */
  140. typedef struct { unsigned long pgd; } pgd_t;
  141. #define pgd_val(x) ((x).pgd)
  142. #define __pgd(x) ((pgd_t) { (x) })
  143. /* Page protection bits */
  144. typedef struct { unsigned long pgprot; } pgprot_t;
  145. #define pgprot_val(x) ((x).pgprot)
  146. #define __pgprot(x) ((pgprot_t) { (x) })
  147. #else
  148. /*
  149. * .. while these make it easier on the compiler
  150. */
  151. typedef pte_basic_t pte_t;
  152. #define pte_val(x) (x)
  153. #define __pte(x) (x)
  154. #ifdef CONFIG_PPC_64K_PAGES
  155. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  156. #else
  157. typedef unsigned long real_pte_t;
  158. #endif
  159. #ifdef CONFIG_PPC64
  160. typedef unsigned long pmd_t;
  161. #define pmd_val(x) (x)
  162. #define __pmd(x) (x)
  163. #ifndef CONFIG_PPC_64K_PAGES
  164. typedef unsigned long pud_t;
  165. #define pud_val(x) (x)
  166. #define __pud(x) (x)
  167. #endif /* !CONFIG_PPC_64K_PAGES */
  168. #endif /* CONFIG_PPC64 */
  169. typedef unsigned long pgd_t;
  170. #define pgd_val(x) (x)
  171. #define pgprot_val(x) (x)
  172. typedef unsigned long pgprot_t;
  173. #define __pgd(x) (x)
  174. #define __pgprot(x) (x)
  175. #endif
  176. struct page;
  177. extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
  178. extern void copy_user_page(void *to, void *from, unsigned long vaddr,
  179. struct page *p);
  180. extern int page_is_ram(unsigned long pfn);
  181. struct vm_area_struct;
  182. typedef struct page *pgtable_t;
  183. #include <asm-generic/memory_model.h>
  184. #endif /* __ASSEMBLY__ */
  185. #endif /* _ASM_POWERPC_PAGE_H */