pgalloc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #ifndef _ASM_IA64_PGALLOC_H
  2. #define _ASM_IA64_PGALLOC_H
  3. /*
  4. * This file contains the functions and defines necessary to allocate
  5. * page tables.
  6. *
  7. * This hopefully works with any (fixed) ia-64 page-size, as defined
  8. * in <asm/page.h> (currently 8192).
  9. *
  10. * Copyright (C) 1998-2001 Hewlett-Packard Co
  11. * David Mosberger-Tang <davidm@hpl.hp.com>
  12. * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
  13. */
  14. #include <linux/config.h>
  15. #include <linux/compiler.h>
  16. #include <linux/mm.h>
  17. #include <linux/page-flags.h>
  18. #include <linux/threads.h>
  19. #include <asm/mmu_context.h>
  20. DECLARE_PER_CPU(unsigned long *, __pgtable_quicklist);
  21. #define pgtable_quicklist __ia64_per_cpu_var(__pgtable_quicklist)
  22. DECLARE_PER_CPU(long, __pgtable_quicklist_size);
  23. #define pgtable_quicklist_size __ia64_per_cpu_var(__pgtable_quicklist_size)
  24. static inline long pgtable_quicklist_total_size(void)
  25. {
  26. long ql_size;
  27. int cpuid;
  28. for_each_online_cpu(cpuid) {
  29. ql_size += per_cpu(__pgtable_quicklist_size, cpuid);
  30. }
  31. return ql_size;
  32. }
  33. static inline void *pgtable_quicklist_alloc(void)
  34. {
  35. unsigned long *ret = NULL;
  36. preempt_disable();
  37. ret = pgtable_quicklist;
  38. if (likely(ret != NULL)) {
  39. pgtable_quicklist = (unsigned long *)(*ret);
  40. ret[0] = 0;
  41. --pgtable_quicklist_size;
  42. } else {
  43. ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
  44. }
  45. preempt_enable();
  46. return ret;
  47. }
  48. static inline void pgtable_quicklist_free(void *pgtable_entry)
  49. {
  50. #ifdef CONFIG_NUMA
  51. unsigned long nid = page_to_nid(virt_to_page(pgtable_entry));
  52. if (unlikely(nid != numa_node_id())) {
  53. free_page((unsigned long)pgtable_entry);
  54. return;
  55. }
  56. #endif
  57. preempt_disable();
  58. *(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist;
  59. pgtable_quicklist = (unsigned long *)pgtable_entry;
  60. ++pgtable_quicklist_size;
  61. preempt_enable();
  62. }
  63. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  64. {
  65. return pgtable_quicklist_alloc();
  66. }
  67. static inline void pgd_free(pgd_t * pgd)
  68. {
  69. pgtable_quicklist_free(pgd);
  70. }
  71. static inline void
  72. pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
  73. {
  74. pud_val(*pud_entry) = __pa(pmd);
  75. }
  76. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  77. {
  78. return pgtable_quicklist_alloc();
  79. }
  80. static inline void pmd_free(pmd_t * pmd)
  81. {
  82. pgtable_quicklist_free(pmd);
  83. }
  84. #define __pmd_free_tlb(tlb, pmd) pmd_free(pmd)
  85. static inline void
  86. pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
  87. {
  88. pmd_val(*pmd_entry) = page_to_phys(pte);
  89. }
  90. static inline void
  91. pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
  92. {
  93. pmd_val(*pmd_entry) = __pa(pte);
  94. }
  95. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  96. unsigned long addr)
  97. {
  98. return virt_to_page(pgtable_quicklist_alloc());
  99. }
  100. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  101. unsigned long addr)
  102. {
  103. return pgtable_quicklist_alloc();
  104. }
  105. static inline void pte_free(struct page *pte)
  106. {
  107. pgtable_quicklist_free(page_address(pte));
  108. }
  109. static inline void pte_free_kernel(pte_t * pte)
  110. {
  111. pgtable_quicklist_free(pte);
  112. }
  113. #define __pte_free_tlb(tlb, pte) pte_free(pte)
  114. extern void check_pgt_cache(void);
  115. #endif /* _ASM_IA64_PGALLOC_H */