page.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. */
  9. #ifndef _ASM_PAGE_H
  10. #define _ASM_PAGE_H
  11. #include <spaces.h>
  12. #include <linux/const.h>
  13. #include <linux/kernel.h>
  14. #include <asm/mipsregs.h>
  15. /*
  16. * PAGE_SHIFT determines the page size
  17. */
  18. #ifdef CONFIG_PAGE_SIZE_4KB
  19. #define PAGE_SHIFT 12
  20. #endif
  21. #ifdef CONFIG_PAGE_SIZE_8KB
  22. #define PAGE_SHIFT 13
  23. #endif
  24. #ifdef CONFIG_PAGE_SIZE_16KB
  25. #define PAGE_SHIFT 14
  26. #endif
  27. #ifdef CONFIG_PAGE_SIZE_32KB
  28. #define PAGE_SHIFT 15
  29. #endif
  30. #ifdef CONFIG_PAGE_SIZE_64KB
  31. #define PAGE_SHIFT 16
  32. #endif
  33. #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
  34. #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1))
  35. /*
  36. * This is used for calculating the real page sizes
  37. * for FTLB or VTLB + FTLB configurations.
  38. */
  39. static inline unsigned int page_size_ftlb(unsigned int mmuextdef)
  40. {
  41. switch (mmuextdef) {
  42. case MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT:
  43. if (PAGE_SIZE == (1 << 30))
  44. return 5;
  45. if (PAGE_SIZE == (1llu << 32))
  46. return 6;
  47. if (PAGE_SIZE > (256 << 10))
  48. return 7; /* reserved */
  49. /* fall through */
  50. case MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT:
  51. return (PAGE_SHIFT - 10) / 2;
  52. default:
  53. panic("Invalid FTLB configuration with Conf4_mmuextdef=%d value\n",
  54. mmuextdef >> 14);
  55. }
  56. }
  57. #ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
  58. #define HPAGE_SHIFT (PAGE_SHIFT + PAGE_SHIFT - 3)
  59. #define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT)
  60. #define HPAGE_MASK (~(HPAGE_SIZE - 1))
  61. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  62. #else /* !CONFIG_MIPS_HUGE_TLB_SUPPORT */
  63. #define HPAGE_SHIFT ({BUILD_BUG(); 0; })
  64. #define HPAGE_SIZE ({BUILD_BUG(); 0; })
  65. #define HPAGE_MASK ({BUILD_BUG(); 0; })
  66. #define HUGETLB_PAGE_ORDER ({BUILD_BUG(); 0; })
  67. #endif /* CONFIG_MIPS_HUGE_TLB_SUPPORT */
  68. #include <linux/pfn.h>
  69. extern void build_clear_page(void);
  70. extern void build_copy_page(void);
  71. /*
  72. * It's normally defined only for FLATMEM config but it's
  73. * used in our early mem init code for all memory models.
  74. * So always define it.
  75. */
  76. #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
  77. extern unsigned long ARCH_PFN_OFFSET;
  78. # define ARCH_PFN_OFFSET ARCH_PFN_OFFSET
  79. #else
  80. # define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET)
  81. #endif
  82. extern void clear_page(void * page);
  83. extern void copy_page(void * to, void * from);
  84. extern unsigned long shm_align_mask;
  85. static inline unsigned long pages_do_alias(unsigned long addr1,
  86. unsigned long addr2)
  87. {
  88. return (addr1 ^ addr2) & shm_align_mask;
  89. }
  90. struct page;
  91. static inline void clear_user_page(void *addr, unsigned long vaddr,
  92. struct page *page)
  93. {
  94. extern void (*flush_data_cache_page)(unsigned long addr);
  95. clear_page(addr);
  96. if (pages_do_alias((unsigned long) addr, vaddr & PAGE_MASK))
  97. flush_data_cache_page((unsigned long)addr);
  98. }
  99. struct vm_area_struct;
  100. extern void copy_user_highpage(struct page *to, struct page *from,
  101. unsigned long vaddr, struct vm_area_struct *vma);
  102. #define __HAVE_ARCH_COPY_USER_HIGHPAGE
  103. /*
  104. * These are used to make use of C type-checking..
  105. */
  106. #ifdef CONFIG_PHYS_ADDR_T_64BIT
  107. #ifdef CONFIG_CPU_MIPS32
  108. typedef struct { unsigned long pte_low, pte_high; } pte_t;
  109. #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
  110. #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
  111. #else
  112. typedef struct { unsigned long long pte; } pte_t;
  113. #define pte_val(x) ((x).pte)
  114. #define __pte(x) ((pte_t) { (x) } )
  115. #endif
  116. #else
  117. typedef struct { unsigned long pte; } pte_t;
  118. #define pte_val(x) ((x).pte)
  119. #define __pte(x) ((pte_t) { (x) } )
  120. #endif
  121. typedef struct page *pgtable_t;
  122. /*
  123. * Right now we don't support 4-level pagetables, so all pud-related
  124. * definitions come from <asm-generic/pgtable-nopud.h>.
  125. */
  126. /*
  127. * Finall the top of the hierarchy, the pgd
  128. */
  129. typedef struct { unsigned long pgd; } pgd_t;
  130. #define pgd_val(x) ((x).pgd)
  131. #define __pgd(x) ((pgd_t) { (x) } )
  132. /*
  133. * Manipulate page protection bits
  134. */
  135. typedef struct { unsigned long pgprot; } pgprot_t;
  136. #define pgprot_val(x) ((x).pgprot)
  137. #define __pgprot(x) ((pgprot_t) { (x) } )
  138. /*
  139. * On R4000-style MMUs where a TLB entry is mapping a adjacent even / odd
  140. * pair of pages we only have a single global bit per pair of pages. When
  141. * writing to the TLB make sure we always have the bit set for both pages
  142. * or none. This macro is used to access the `buddy' of the pte we're just
  143. * working on.
  144. */
  145. #define ptep_buddy(x) ((pte_t *)((unsigned long)(x) ^ sizeof(pte_t)))
  146. /*
  147. * __pa()/__va() should be used only during mem init.
  148. */
  149. static inline unsigned long ___pa(unsigned long x)
  150. {
  151. if (IS_ENABLED(CONFIG_64BIT)) {
  152. /*
  153. * For MIPS64 the virtual address may either be in one of
  154. * the compatibility segements ckseg0 or ckseg1, or it may
  155. * be in xkphys.
  156. */
  157. return x < CKSEG0 ? XPHYSADDR(x) : CPHYSADDR(x);
  158. }
  159. if (!IS_ENABLED(CONFIG_EVA)) {
  160. /*
  161. * We're using the standard MIPS32 legacy memory map, ie.
  162. * the address x is going to be in kseg0 or kseg1. We can
  163. * handle either case by masking out the desired bits using
  164. * CPHYSADDR.
  165. */
  166. return CPHYSADDR(x);
  167. }
  168. /*
  169. * EVA is in use so the memory map could be anything, making it not
  170. * safe to just mask out bits.
  171. */
  172. return x - PAGE_OFFSET + PHYS_OFFSET;
  173. }
  174. #define __pa(x) ___pa((unsigned long)(x))
  175. #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
  176. #include <asm/io.h>
  177. /*
  178. * RELOC_HIDE was originally added by 6007b903dfe5f1d13e0c711ac2894bdd4a61b1ad
  179. * (lmo) rsp. 8431fd094d625b94d364fe393076ccef88e6ce18 (kernel.org). The
  180. * discussion can be found in lkml posting
  181. * <a2ebde260608230500o3407b108hc03debb9da6e62c@mail.gmail.com> which is
  182. * archived at http://lists.linuxcoding.com/kernel/2006-q3/msg17360.html
  183. *
  184. * It is unclear if the misscompilations mentioned in
  185. * http://lkml.org/lkml/2010/8/8/138 also affect MIPS so we keep this one
  186. * until GCC 3.x has been retired before we can apply
  187. * https://patchwork.linux-mips.org/patch/1541/
  188. */
  189. #ifndef __pa_symbol
  190. #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
  191. #endif
  192. #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
  193. #ifdef CONFIG_FLATMEM
  194. static inline int pfn_valid(unsigned long pfn)
  195. {
  196. /* avoid <linux/mm.h> include hell */
  197. extern unsigned long max_mapnr;
  198. unsigned long pfn_offset = ARCH_PFN_OFFSET;
  199. return pfn >= pfn_offset && pfn < max_mapnr;
  200. }
  201. #elif defined(CONFIG_SPARSEMEM)
  202. /* pfn_valid is defined in linux/mmzone.h */
  203. #elif defined(CONFIG_NEED_MULTIPLE_NODES)
  204. #define pfn_valid(pfn) \
  205. ({ \
  206. unsigned long __pfn = (pfn); \
  207. int __n = pfn_to_nid(__pfn); \
  208. ((__n >= 0) ? (__pfn < NODE_DATA(__n)->node_start_pfn + \
  209. NODE_DATA(__n)->node_spanned_pages) \
  210. : 0); \
  211. })
  212. #endif
  213. #define virt_to_pfn(kaddr) PFN_DOWN(virt_to_phys((void *)(kaddr)))
  214. #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
  215. extern int __virt_addr_valid(const volatile void *kaddr);
  216. #define virt_addr_valid(kaddr) \
  217. __virt_addr_valid((const volatile void *) (kaddr))
  218. #define VM_DATA_DEFAULT_FLAGS \
  219. (VM_READ | VM_WRITE | \
  220. ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
  221. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  222. #define UNCAC_ADDR(addr) (UNCAC_BASE + __pa(addr))
  223. #define CAC_ADDR(addr) ((unsigned long)__va((addr) - UNCAC_BASE))
  224. #include <asm-generic/memory_model.h>
  225. #include <asm-generic/getorder.h>
  226. #endif /* _ASM_PAGE_H */