pgalloc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. pgtable_page_ctor(pte);
  57. return pte;
  58. }
  59. /* _kernel variant gets to use a different allocator */
  60. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  61. unsigned long address)
  62. {
  63. gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
  64. return (pte_t *) __get_free_page(flags);
  65. }
  66. static inline void pte_free(struct mm_struct *mm, struct page *pte)
  67. {
  68. pgtable_page_dtor(pte);
  69. __free_page(pte);
  70. }
  71. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  72. {
  73. free_page((unsigned long)pte);
  74. }
  75. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  76. pgtable_t pte)
  77. {
  78. /*
  79. * Conveniently, zero in 3 LSB means indirect 4K page table.
  80. * Not so convenient when you're trying to vary the page size.
  81. */
  82. set_pmd(pmd, __pmd(((unsigned long)page_to_pfn(pte) << PAGE_SHIFT) |
  83. HEXAGON_L1_PTE_SIZE));
  84. }
  85. /*
  86. * Other architectures seem to have ways of making all processes
  87. * share the same pmd's for their kernel mappings, but the v0.3
  88. * Hexagon VM spec has a "monolithic" L1 table for user and kernel
  89. * segments. We track "generations" of the kernel map to minimize
  90. * overhead, and update the "slave" copies of the kernel mappings
  91. * as part of switch_mm. However, we still need to update the
  92. * kernel map of the active thread who's calling pmd_populate_kernel...
  93. */
  94. static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
  95. pte_t *pte)
  96. {
  97. extern spinlock_t kmap_gen_lock;
  98. pmd_t *ppmd;
  99. int pmdindex;
  100. spin_lock(&kmap_gen_lock);
  101. kmap_generation++;
  102. mm->context.generation = kmap_generation;
  103. current->active_mm->context.generation = kmap_generation;
  104. spin_unlock(&kmap_gen_lock);
  105. set_pmd(pmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
  106. /*
  107. * Now the "slave" copy of the current thread.
  108. * This is pointer arithmetic, not byte addresses!
  109. */
  110. pmdindex = (pgd_t *)pmd - mm->pgd;
  111. ppmd = (pmd_t *)current->active_mm->pgd + pmdindex;
  112. set_pmd(ppmd, __pmd(((unsigned long)__pa(pte)) | HEXAGON_L1_PTE_SIZE));
  113. if (pmdindex > max_kernel_seg)
  114. max_kernel_seg = pmdindex;
  115. }
  116. #define __pte_free_tlb(tlb, pte, addr) \
  117. do { \
  118. pgtable_page_dtor((pte)); \
  119. tlb_remove_page((tlb), (pte)); \
  120. } while (0)
  121. #endif