page.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. /*
  105. * Don't compare things with KERNELBASE or PAGE_OFFSET to test for
  106. * "kernelness", use is_kernel_addr() - it should do what you want.
  107. */
  108. #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
  109. #ifndef __ASSEMBLY__
  110. #undef STRICT_MM_TYPECHECKS
  111. #ifdef STRICT_MM_TYPECHECKS
  112. /* These are used to make use of C type-checking. */
  113. /* PTE level */
  114. typedef struct { pte_basic_t pte; } pte_t;
  115. #define pte_val(x) ((x).pte)
  116. #define __pte(x) ((pte_t) { (x) })
  117. /* 64k pages additionally define a bigger "real PTE" type that gathers
  118. * the "second half" part of the PTE for pseudo 64k pages
  119. */
  120. #ifdef CONFIG_PPC_64K_PAGES
  121. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  122. #else
  123. typedef struct { pte_t pte; } real_pte_t;
  124. #endif
  125. /* PMD level */
  126. #ifdef CONFIG_PPC64
  127. typedef struct { unsigned long pmd; } pmd_t;
  128. #define pmd_val(x) ((x).pmd)
  129. #define __pmd(x) ((pmd_t) { (x) })
  130. /* PUD level exusts only on 4k pages */
  131. #ifndef CONFIG_PPC_64K_PAGES
  132. typedef struct { unsigned long pud; } pud_t;
  133. #define pud_val(x) ((x).pud)
  134. #define __pud(x) ((pud_t) { (x) })
  135. #endif /* !CONFIG_PPC_64K_PAGES */
  136. #endif /* CONFIG_PPC64 */
  137. /* PGD level */
  138. typedef struct { unsigned long pgd; } pgd_t;
  139. #define pgd_val(x) ((x).pgd)
  140. #define __pgd(x) ((pgd_t) { (x) })
  141. /* Page protection bits */
  142. typedef struct { unsigned long pgprot; } pgprot_t;
  143. #define pgprot_val(x) ((x).pgprot)
  144. #define __pgprot(x) ((pgprot_t) { (x) })
  145. #else
  146. /*
  147. * .. while these make it easier on the compiler
  148. */
  149. typedef pte_basic_t pte_t;
  150. #define pte_val(x) (x)
  151. #define __pte(x) (x)
  152. #ifdef CONFIG_PPC_64K_PAGES
  153. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  154. #else
  155. typedef unsigned long real_pte_t;
  156. #endif
  157. #ifdef CONFIG_PPC64
  158. typedef unsigned long pmd_t;
  159. #define pmd_val(x) (x)
  160. #define __pmd(x) (x)
  161. #ifndef CONFIG_PPC_64K_PAGES
  162. typedef unsigned long pud_t;
  163. #define pud_val(x) (x)
  164. #define __pud(x) (x)
  165. #endif /* !CONFIG_PPC_64K_PAGES */
  166. #endif /* CONFIG_PPC64 */
  167. typedef unsigned long pgd_t;
  168. #define pgd_val(x) (x)
  169. #define pgprot_val(x) (x)
  170. typedef unsigned long pgprot_t;
  171. #define __pgd(x) (x)
  172. #define __pgprot(x) (x)
  173. #endif
  174. struct page;
  175. extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
  176. extern void copy_user_page(void *to, void *from, unsigned long vaddr,
  177. struct page *p);
  178. extern int page_is_ram(unsigned long pfn);
  179. struct vm_area_struct;
  180. typedef struct page *pgtable_t;
  181. #include <asm-generic/memory_model.h>
  182. #endif /* __ASSEMBLY__ */
  183. #endif /* _ASM_POWERPC_PAGE_H */