pgalloc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * arch/arm/include/asm/pgalloc.h
  3. *
  4. * Copyright (C) 2000-2001 Russell King
  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 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _ASMARM_PGALLOC_H
  11. #define _ASMARM_PGALLOC_H
  12. #include <linux/pagemap.h>
  13. #include <asm/domain.h>
  14. #include <asm/pgtable-hwdef.h>
  15. #include <asm/processor.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/tlbflush.h>
  18. #define check_pgt_cache() do { } while (0)
  19. #ifdef CONFIG_MMU
  20. #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
  21. #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
  22. /*
  23. * Since we have only two-level page tables, these are trivial
  24. */
  25. #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
  26. #define pmd_free(mm, pmd) do { } while (0)
  27. #define pgd_populate(mm,pmd,pte) BUG()
  28. extern pgd_t *pgd_alloc(struct mm_struct *mm);
  29. extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
  30. #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
  31. static inline void clean_pte_table(pte_t *pte)
  32. {
  33. clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE);
  34. }
  35. /*
  36. * Allocate one PTE table.
  37. *
  38. * This actually allocates two hardware PTE tables, but we wrap this up
  39. * into one table thus:
  40. *
  41. * +------------+
  42. * | Linux pt 0 |
  43. * +------------+
  44. * | Linux pt 1 |
  45. * +------------+
  46. * | h/w pt 0 |
  47. * +------------+
  48. * | h/w pt 1 |
  49. * +------------+
  50. */
  51. static inline pte_t *
  52. pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
  53. {
  54. pte_t *pte;
  55. pte = (pte_t *)__get_free_page(PGALLOC_GFP);
  56. if (pte)
  57. clean_pte_table(pte);
  58. return pte;
  59. }
  60. static inline pgtable_t
  61. pte_alloc_one(struct mm_struct *mm, unsigned long addr)
  62. {
  63. struct page *pte;
  64. #ifdef CONFIG_HIGHPTE
  65. pte = alloc_pages(PGALLOC_GFP | __GFP_HIGHMEM, 0);
  66. #else
  67. pte = alloc_pages(PGALLOC_GFP, 0);
  68. #endif
  69. if (pte) {
  70. if (!PageHighMem(pte))
  71. clean_pte_table(page_address(pte));
  72. pgtable_page_ctor(pte);
  73. }
  74. return pte;
  75. }
  76. /*
  77. * Free one PTE table.
  78. */
  79. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  80. {
  81. if (pte)
  82. free_page((unsigned long)pte);
  83. }
  84. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  85. {
  86. pgtable_page_dtor(pte);
  87. __free_page(pte);
  88. }
  89. static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
  90. unsigned long prot)
  91. {
  92. unsigned long pmdval = (pte + PTE_HWTABLE_OFF) | prot;
  93. pmdp[0] = __pmd(pmdval);
  94. pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
  95. flush_pmd_entry(pmdp);
  96. }
  97. /*
  98. * Populate the pmdp entry with a pointer to the pte. This pmd is part
  99. * of the mm address space.
  100. *
  101. * Ensure that we always set both PMD entries.
  102. */
  103. static inline void
  104. pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
  105. {
  106. /*
  107. * The pmd must be loaded with the physical address of the PTE table
  108. */
  109. __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
  110. }
  111. static inline void
  112. pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
  113. {
  114. __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
  115. }
  116. #define pmd_pgtable(pmd) pmd_page(pmd)
  117. #endif /* CONFIG_MMU */
  118. #endif