pgalloc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Page table support for the Hexagon architecture
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #ifndef _ASM_PGALLOC_H
  21. #define _ASM_PGALLOC_H
  22. #include <asm/mem-layout.h>
  23. #include <asm/atomic.h>
  24. #define check_pgt_cache() do {} while (0)
  25. extern unsigned long long kmap_generation;
  26. /*
  27. * Page table creation interface
  28. */
  29. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  30. {
  31. pgd_t *pgd;
  32. pgd = (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
  33. /*
  34. * There may be better ways to do this, but to ensure
  35. * that new address spaces always contain the kernel
  36. * base mapping, and to ensure that the user area is
  37. * initially marked invalid, initialize the new map
  38. * map with a copy of the kernel's persistent map.
  39. */
  40. memcpy(pgd, swapper_pg_dir, PTRS_PER_PGD*sizeof(pgd_t));
  41. mm->context.generation = kmap_generation;
  42. /* Physical version is what is passed to virtual machine on switch */
  43. mm->context.ptbase = __pa(pgd);
  44. return pgd;
  45. }
  46. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  47. {
  48. free_page((unsigned long) pgd);
  49. }
  50. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  51. unsigned long address)
  52. {
  53. struct page *pte;
  54. pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  55. if (!pte)
  56. return NULL;
  57. if (!pgtable_page_ctor(pte)) {
  58. __free_page(pte);
  59. return NULL;
  60. }
  61. return pte;
  62. }
  63. /* _kernel variant gets to use a different allocator */
  64. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  65. unsigned long address)
  66. {
  67. gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
  68. return (pte_t *) __get_free_page(flags);
  69. }
  70. static inline void pte_free(struct mm_struct *mm, struct page *pte)
  71. {
  72. pgtable_page_dtor(pte);
  73. __free_page(pte);
  74. }
  75. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  76. {
  77. free_page((unsigned long)pte);
  78. }
  79. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  80. pgtable_t pte)
  81. {
  82. /*
  83. * Conveniently, zero in 3 LSB means indirect 4K page table.
  84. * Not so convenient when you're trying to vary the page size.
  85. */
  86. set_pmd(pmd, __pmd(((unsigned long)page_to_pfn(pte) << PAGE_SHIFT) |
  87. HEXAGON_L1_PTE_SIZE));
  88. }
  89. /*
  90. * Other architectures seem to have ways of making all processes
  91. * share the same pmd's for their kernel mappings, but the v0.3
  92. * Hexagon VM spec has a "monolithic" L1 table for user and kernel
  93. * segments. We track "generations" of the kernel map to minimize
  94. * overhead, and update the "slave" copies of the kernel mappings
  95. * as part of switch_mm. However, we still need to update the
  96. * kernel map of the active thread who's calling pmd_populate_kernel...
  97. */
  98. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  99. pte_t *pte)
  100. {
  101. extern spinlock_t kmap_gen_lock;
  102. pmd_t *ppmd;
  103. int pmdindex;
  104. spin_lock(&kmap_gen_lock);
  105. kmap_generation++;
  106. mm->context.generation = kmap_generation;
  107. current->active_mm->context.generation = kmap_generation;
  108. spin_unlock(&kmap_gen_lock);
  109. set_pmd(pmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
  110. /*
  111. * Now the "slave" copy of the current thread.
  112. * This is pointer arithmetic, not byte addresses!
  113. */
  114. pmdindex = (pgd_t *)pmd - mm->pgd;
  115. ppmd = (pmd_t *)current->active_mm->pgd + pmdindex;
  116. set_pmd(ppmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
  117. if (pmdindex > max_kernel_seg)
  118. max_kernel_seg = pmdindex;
  119. }
  120. #define __pte_free_tlb(tlb, pte, addr) \
  121. do { \
  122. pgtable_page_dtor((pte)); \
  123. tlb_remove_page((tlb), (pte)); \
  124. } while (0)
  125. #endif