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 = 0;
  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. preempt_enable();
  43. } else {
  44. preempt_enable();
  45. ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
  46. }
  47. return ret;
  48. }
  49. static inline void pgtable_quicklist_free(void *pgtable_entry)
  50. {
  51. #ifdef CONFIG_NUMA
  52. unsigned long nid = page_to_nid(virt_to_page(pgtable_entry));
  53. if (unlikely(nid != numa_node_id())) {
  54. free_page((unsigned long)pgtable_entry);
  55. return;
  56. }
  57. #endif
  58. preempt_disable();
  59. *(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist;
  60. pgtable_quicklist = (unsigned long *)pgtable_entry;
  61. ++pgtable_quicklist_size;
  62. preempt_enable();
  63. }
  64. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  65. {
  66. return pgtable_quicklist_alloc();
  67. }
  68. static inline void pgd_free(pgd_t * pgd)
  69. {
  70. pgtable_quicklist_free(pgd);
  71. }
  72. static inline void
  73. pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
  74. {
  75. pud_val(*pud_entry) = __pa(pmd);
  76. }
  77. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  78. {
  79. return pgtable_quicklist_alloc();
  80. }
  81. static inline void pmd_free(pmd_t * pmd)
  82. {
  83. pgtable_quicklist_free(pmd);
  84. }
  85. #define __pmd_free_tlb(tlb, pmd) pmd_free(pmd)
  86. static inline void
  87. pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
  88. {
  89. pmd_val(*pmd_entry) = page_to_phys(pte);
  90. }
  91. static inline void
  92. pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
  93. {
  94. pmd_val(*pmd_entry) = __pa(pte);
  95. }
  96. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  97. unsigned long addr)
  98. {
  99. return virt_to_page(pgtable_quicklist_alloc());
  100. }
  101. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  102. unsigned long addr)
  103. {
  104. return pgtable_quicklist_alloc();
  105. }
  106. static inline void pte_free(struct page *pte)
  107. {
  108. pgtable_quicklist_free(page_address(pte));
  109. }
  110. static inline void pte_free_kernel(pte_t * pte)
  111. {
  112. pgtable_quicklist_free(pte);
  113. }
  114. #define __pte_free_tlb(tlb, pte) pte_free(pte)
  115. extern void check_pgt_cache(void);
  116. #endif /* _ASM_IA64_PGALLOC_H */