pgalloc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_PGALLOC_H
  15. #define _ASM_TILE_PGALLOC_H
  16. #include <linux/threads.h>
  17. #include <linux/mm.h>
  18. #include <linux/mmzone.h>
  19. #include <asm/fixmap.h>
  20. #include <asm/page.h>
  21. #include <hv/hypervisor.h>
  22. /* Bits for the size of the second-level page table. */
  23. #define L2_KERNEL_PGTABLE_SHIFT _HV_LOG2_L2_SIZE(HPAGE_SHIFT, PAGE_SHIFT)
  24. /* How big is a kernel L2 page table? */
  25. #define L2_KERNEL_PGTABLE_SIZE (1UL << L2_KERNEL_PGTABLE_SHIFT)
  26. /* We currently allocate user L2 page tables by page (unlike kernel L2s). */
  27. #if L2_KERNEL_PGTABLE_SHIFT < PAGE_SHIFT
  28. #define L2_USER_PGTABLE_SHIFT PAGE_SHIFT
  29. #else
  30. #define L2_USER_PGTABLE_SHIFT L2_KERNEL_PGTABLE_SHIFT
  31. #endif
  32. /* How many pages do we need, as an "order", for a user L2 page table? */
  33. #define L2_USER_PGTABLE_ORDER (L2_USER_PGTABLE_SHIFT - PAGE_SHIFT)
  34. static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
  35. {
  36. #ifdef CONFIG_64BIT
  37. set_pte(pmdp, pmd);
  38. #else
  39. set_pte(&pmdp->pud.pgd, pmd.pud.pgd);
  40. #endif
  41. }
  42. static inline void pmd_populate_kernel(struct mm_struct *mm,
  43. pmd_t *pmd, pte_t *ptep)
  44. {
  45. set_pmd(pmd, ptfn_pmd(HV_CPA_TO_PTFN(__pa(ptep)),
  46. __pgprot(_PAGE_PRESENT)));
  47. }
  48. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  49. pgtable_t page)
  50. {
  51. set_pmd(pmd, ptfn_pmd(HV_CPA_TO_PTFN(PFN_PHYS(page_to_pfn(page))),
  52. __pgprot(_PAGE_PRESENT)));
  53. }
  54. /*
  55. * Allocate and free page tables.
  56. */
  57. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  58. extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
  59. extern pgtable_t pgtable_alloc_one(struct mm_struct *mm, unsigned long address,
  60. int order);
  61. extern void pgtable_free(struct mm_struct *mm, struct page *pte, int order);
  62. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  63. unsigned long address)
  64. {
  65. return pgtable_alloc_one(mm, address, L2_USER_PGTABLE_ORDER);
  66. }
  67. static inline void pte_free(struct mm_struct *mm, struct page *pte)
  68. {
  69. pgtable_free(mm, pte, L2_USER_PGTABLE_ORDER);
  70. }
  71. #define pmd_pgtable(pmd) pmd_page(pmd)
  72. static inline pte_t *
  73. pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
  74. {
  75. return pfn_to_kaddr(page_to_pfn(pte_alloc_one(mm, address)));
  76. }
  77. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  78. {
  79. BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
  80. pte_free(mm, virt_to_page(pte));
  81. }
  82. extern void __pgtable_free_tlb(struct mmu_gather *tlb, struct page *pte,
  83. unsigned long address, int order);
  84. static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte,
  85. unsigned long address)
  86. {
  87. __pgtable_free_tlb(tlb, pte, address, L2_USER_PGTABLE_ORDER);
  88. }
  89. #define check_pgt_cache() do { } while (0)
  90. /*
  91. * Get the small-page pte_t lowmem entry for a given pfn.
  92. * This may or may not be in use, depending on whether the initial
  93. * huge-page entry for the page has already been shattered.
  94. */
  95. pte_t *get_prealloc_pte(unsigned long pfn);
  96. /* During init, we can shatter kernel huge pages if needed. */
  97. void shatter_pmd(pmd_t *pmd);
  98. /* After init, a more complex technique is required. */
  99. void shatter_huge_page(unsigned long addr);
  100. #ifdef __tilegx__
  101. #define pud_populate(mm, pud, pmd) \
  102. pmd_populate_kernel((mm), (pmd_t *)(pud), (pte_t *)(pmd))
  103. /* Bits for the size of the L1 (intermediate) page table. */
  104. #define L1_KERNEL_PGTABLE_SHIFT _HV_LOG2_L1_SIZE(HPAGE_SHIFT)
  105. /* How big is a kernel L2 page table? */
  106. #define L1_KERNEL_PGTABLE_SIZE (1UL << L1_KERNEL_PGTABLE_SHIFT)
  107. /* We currently allocate L1 page tables by page. */
  108. #if L1_KERNEL_PGTABLE_SHIFT < PAGE_SHIFT
  109. #define L1_USER_PGTABLE_SHIFT PAGE_SHIFT
  110. #else
  111. #define L1_USER_PGTABLE_SHIFT L1_KERNEL_PGTABLE_SHIFT
  112. #endif
  113. /* How many pages do we need, as an "order", for an L1 page table? */
  114. #define L1_USER_PGTABLE_ORDER (L1_USER_PGTABLE_SHIFT - PAGE_SHIFT)
  115. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  116. {
  117. struct page *p = pgtable_alloc_one(mm, address, L1_USER_PGTABLE_ORDER);
  118. return (pmd_t *)page_to_virt(p);
  119. }
  120. static inline void pmd_free(struct mm_struct *mm, pmd_t *pmdp)
  121. {
  122. pgtable_free(mm, virt_to_page(pmdp), L1_USER_PGTABLE_ORDER);
  123. }
  124. static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
  125. unsigned long address)
  126. {
  127. __pgtable_free_tlb(tlb, virt_to_page(pmdp), address,
  128. L1_USER_PGTABLE_ORDER);
  129. }
  130. #endif /* __tilegx__ */
  131. #endif /* _ASM_TILE_PGALLOC_H */