pgalloc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * vineetg: June 2011
  9. * -"/proc/meminfo | grep PageTables" kept on increasing
  10. * Recently added pgtable dtor was not getting called.
  11. *
  12. * vineetg: May 2011
  13. * -Variable pg-sz means that Page Tables could be variable sized themselves
  14. * So calculate it based on addr traversal split [pgd-bits:pte-bits:xxx]
  15. * -Page Table size capped to max 1 to save memory - hence verified.
  16. * -Since these deal with constants, gcc compile-time optimizes them.
  17. *
  18. * vineetg: Nov 2010
  19. * -Added pgtable ctor/dtor used for pgtable mem accounting
  20. *
  21. * vineetg: April 2010
  22. * -Switched pgtable_t from being struct page * to unsigned long
  23. * =Needed so that Page Table allocator (pte_alloc_one) is not forced to
  24. * to deal with struct page. Thay way in future we can make it allocate
  25. * multiple PG Tbls in one Page Frame
  26. * =sweet side effect is avoiding calls to ugly page_address( ) from the
  27. * pg-tlb allocator sub-sys (pte_alloc_one, ptr_free, pmd_populate
  28. *
  29. * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
  30. */
  31. #ifndef _ASM_ARC_PGALLOC_H
  32. #define _ASM_ARC_PGALLOC_H
  33. #include <linux/mm.h>
  34. #include <linux/log2.h>
  35. static inline void
  36. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
  37. {
  38. pmd_set(pmd, pte);
  39. }
  40. static inline void
  41. pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t ptep)
  42. {
  43. pmd_set(pmd, (pte_t *) ptep);
  44. }
  45. static inline int __get_order_pgd(void)
  46. {
  47. return get_order(PTRS_PER_PGD * 4);
  48. }
  49. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  50. {
  51. int num, num2;
  52. pgd_t *ret = (pgd_t *) __get_free_pages(GFP_KERNEL, __get_order_pgd());
  53. if (ret) {
  54. num = USER_PTRS_PER_PGD + USER_KERNEL_GUTTER / PGDIR_SIZE;
  55. memzero(ret, num * sizeof(pgd_t));
  56. num2 = VMALLOC_SIZE / PGDIR_SIZE;
  57. memcpy(ret + num, swapper_pg_dir + num, num2 * sizeof(pgd_t));
  58. memzero(ret + num + num2,
  59. (PTRS_PER_PGD - num - num2) * sizeof(pgd_t));
  60. }
  61. return ret;
  62. }
  63. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  64. {
  65. free_pages((unsigned long)pgd, __get_order_pgd());
  66. }
  67. /*
  68. * With software-only page-tables, addr-split for traversal is tweakable and
  69. * that directly governs how big tables would be at each level.
  70. * Further, the MMU page size is configurable.
  71. * Thus we need to programatically assert the size constraint
  72. * All of this is const math, allowing gcc to do constant folding/propagation.
  73. */
  74. static inline int __get_order_pte(void)
  75. {
  76. return get_order(PTRS_PER_PTE * 4);
  77. }
  78. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  79. unsigned long address)
  80. {
  81. pte_t *pte;
  82. pte = (pte_t *) __get_free_pages(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO,
  83. __get_order_pte());
  84. return pte;
  85. }
  86. static inline pgtable_t
  87. pte_alloc_one(struct mm_struct *mm, unsigned long address)
  88. {
  89. pgtable_t pte_pg;
  90. struct page *page;
  91. pte_pg = __get_free_pages(GFP_KERNEL | __GFP_REPEAT, __get_order_pte());
  92. if (!pte_pg)
  93. return 0;
  94. memzero((void *)pte_pg, PTRS_PER_PTE * 4);
  95. page = virt_to_page(pte_pg);
  96. if (!pgtable_page_ctor(page)) {
  97. __free_page(page);
  98. return 0;
  99. }
  100. return pte_pg;
  101. }
  102. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  103. {
  104. free_pages((unsigned long)pte, __get_order_pte()); /* takes phy addr */
  105. }
  106. static inline void pte_free(struct mm_struct *mm, pgtable_t ptep)
  107. {
  108. pgtable_page_dtor(virt_to_page(ptep));
  109. free_pages(ptep, __get_order_pte());
  110. }
  111. #define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, pte)
  112. #define check_pgt_cache() do { } while (0)
  113. #define pmd_pgtable(pmd) pmd_page_vaddr(pmd)
  114. #endif /* _ASM_ARC_PGALLOC_H */