page.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. #ifdef __KERNEL__
  12. #include <linux/config.h>
  13. #include <asm/asm-compat.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. #define PAGE_OFFSET ASM_CONST(CONFIG_KERNEL_START)
  34. #define KERNELBASE PAGE_OFFSET
  35. #ifdef CONFIG_DISCONTIGMEM
  36. #define page_to_pfn(page) discontigmem_page_to_pfn(page)
  37. #define pfn_to_page(pfn) discontigmem_pfn_to_page(pfn)
  38. #define pfn_valid(pfn) discontigmem_pfn_valid(pfn)
  39. #endif
  40. #ifdef CONFIG_FLATMEM
  41. #define pfn_to_page(pfn) (mem_map + (pfn))
  42. #define page_to_pfn(page) ((unsigned long)((page) - mem_map))
  43. #define pfn_valid(pfn) ((pfn) < max_mapnr)
  44. #endif
  45. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  46. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  47. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  48. #define __va(x) ((void *)((unsigned long)(x) + KERNELBASE))
  49. #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET)
  50. /*
  51. * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI,
  52. * and needs to be executable. This means the whole heap ends
  53. * up being executable.
  54. */
  55. #define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
  56. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  57. #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
  58. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  59. #ifdef __powerpc64__
  60. #include <asm/page_64.h>
  61. #else
  62. #include <asm/page_32.h>
  63. #endif
  64. /* align addr on a size boundary - adjust address up/down if needed */
  65. #define _ALIGN_UP(addr,size) (((addr)+((size)-1))&(~((size)-1)))
  66. #define _ALIGN_DOWN(addr,size) ((addr)&(~((size)-1)))
  67. /* align addr on a size boundary - adjust address up if needed */
  68. #define _ALIGN(addr,size) _ALIGN_UP(addr,size)
  69. /* to align the pointer to the (next) page boundary */
  70. #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE)
  71. #ifndef __ASSEMBLY__
  72. #undef STRICT_MM_TYPECHECKS
  73. #ifdef STRICT_MM_TYPECHECKS
  74. /* These are used to make use of C type-checking. */
  75. /* PTE level */
  76. typedef struct { pte_basic_t pte; } pte_t;
  77. #define pte_val(x) ((x).pte)
  78. #define __pte(x) ((pte_t) { (x) })
  79. /* 64k pages additionally define a bigger "real PTE" type that gathers
  80. * the "second half" part of the PTE for pseudo 64k pages
  81. */
  82. #ifdef CONFIG_PPC_64K_PAGES
  83. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  84. #else
  85. typedef struct { pte_t pte; } real_pte_t;
  86. #endif
  87. /* PMD level */
  88. typedef struct { unsigned long pmd; } pmd_t;
  89. #define pmd_val(x) ((x).pmd)
  90. #define __pmd(x) ((pmd_t) { (x) })
  91. /* PUD level exusts only on 4k pages */
  92. #ifndef CONFIG_PPC_64K_PAGES
  93. typedef struct { unsigned long pud; } pud_t;
  94. #define pud_val(x) ((x).pud)
  95. #define __pud(x) ((pud_t) { (x) })
  96. #endif
  97. /* PGD level */
  98. typedef struct { unsigned long pgd; } pgd_t;
  99. #define pgd_val(x) ((x).pgd)
  100. #define __pgd(x) ((pgd_t) { (x) })
  101. /* Page protection bits */
  102. typedef struct { unsigned long pgprot; } pgprot_t;
  103. #define pgprot_val(x) ((x).pgprot)
  104. #define __pgprot(x) ((pgprot_t) { (x) })
  105. #else
  106. /*
  107. * .. while these make it easier on the compiler
  108. */
  109. typedef pte_basic_t pte_t;
  110. #define pte_val(x) (x)
  111. #define __pte(x) (x)
  112. #ifdef CONFIG_PPC_64K_PAGES
  113. typedef struct { pte_t pte; unsigned long hidx; } real_pte_t;
  114. #else
  115. typedef unsigned long real_pte_t;
  116. #endif
  117. typedef unsigned long pmd_t;
  118. #define pmd_val(x) (x)
  119. #define __pmd(x) (x)
  120. #ifndef CONFIG_PPC_64K_PAGES
  121. typedef unsigned long pud_t;
  122. #define pud_val(x) (x)
  123. #define __pud(x) (x)
  124. #endif
  125. typedef unsigned long pgd_t;
  126. #define pgd_val(x) (x)
  127. #define pgprot_val(x) (x)
  128. typedef unsigned long pgprot_t;
  129. #define __pgd(x) (x)
  130. #define __pgprot(x) (x)
  131. #endif
  132. struct page;
  133. extern void clear_user_page(void *page, unsigned long vaddr, struct page *pg);
  134. extern void copy_user_page(void *to, void *from, unsigned long vaddr,
  135. struct page *p);
  136. extern int page_is_ram(unsigned long pfn);
  137. #endif /* __ASSEMBLY__ */
  138. #endif /* __KERNEL__ */
  139. #endif /* _ASM_POWERPC_PAGE_H */