pgalloc.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __ASM_SH64_PGALLOC_H
  2. #define __ASM_SH64_PGALLOC_H
  3. /*
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * include/asm-sh64/pgalloc.h
  9. *
  10. * Copyright (C) 2000, 2001 Paolo Alberelli
  11. * Copyright (C) 2003, 2004 Paul Mundt
  12. * Copyright (C) 2003, 2004 Richard Curnow
  13. *
  14. */
  15. #include <linux/mm.h>
  16. #include <linux/quicklist.h>
  17. #include <asm/page.h>
  18. static inline void pgd_init(unsigned long page)
  19. {
  20. unsigned long *pgd = (unsigned long *)page;
  21. extern pte_t empty_bad_pte_table[PTRS_PER_PTE];
  22. int i;
  23. for (i = 0; i < USER_PTRS_PER_PGD; i++)
  24. pgd[i] = (unsigned long)empty_bad_pte_table;
  25. }
  26. /*
  27. * Allocate and free page tables. The xxx_kernel() versions are
  28. * used to allocate a kernel page table - this turns on ASN bits
  29. * if any.
  30. */
  31. static inline pgd_t *get_pgd_slow(void)
  32. {
  33. unsigned int pgd_size = (USER_PTRS_PER_PGD * sizeof(pgd_t));
  34. pgd_t *ret = kmalloc(pgd_size, GFP_KERNEL);
  35. return ret;
  36. }
  37. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  38. {
  39. return quicklist_alloc(0, GFP_KERNEL, NULL);
  40. }
  41. static inline void pgd_free(pgd_t *pgd)
  42. {
  43. quicklist_free(0, NULL, pgd);
  44. }
  45. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  46. unsigned long address)
  47. {
  48. void *pg = quicklist_alloc(0, GFP_KERNEL, NULL);
  49. return pg ? virt_to_page(pg) : NULL;
  50. }
  51. static inline void pte_free_kernel(pte_t *pte)
  52. {
  53. quicklist_free(0, NULL, pte);
  54. }
  55. static inline void pte_free(struct page *pte)
  56. {
  57. quicklist_free_page(0, NULL, pte);
  58. }
  59. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  60. unsigned long address)
  61. {
  62. return quicklist_alloc(0, GFP_KERNEL, NULL);
  63. }
  64. #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
  65. /*
  66. * allocating and freeing a pmd is trivial: the 1-entry pmd is
  67. * inside the pgd, so has no extra memory associated with it.
  68. */
  69. #if defined(CONFIG_SH64_PGTABLE_2_LEVEL)
  70. #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
  71. #define pmd_free(x) do { } while (0)
  72. #define pgd_populate(mm, pmd, pte) BUG()
  73. #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
  74. #define __pmd_free_tlb(tlb,pmd) do { } while (0)
  75. #elif defined(CONFIG_SH64_PGTABLE_3_LEVEL)
  76. static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
  77. {
  78. return quicklist_alloc(0, GFP_KERNEL, NULL);
  79. }
  80. static inline void pmd_free(pmd_t *pmd)
  81. {
  82. quicklist_free(0, NULL, pmd);
  83. }
  84. #define pgd_populate(mm, pgd, pmd) pgd_set(pgd, pmd)
  85. #define __pmd_free_tlb(tlb,pmd) pmd_free(pmd)
  86. #else
  87. #error "No defined page table size"
  88. #endif
  89. #define pmd_populate_kernel(mm, pmd, pte) \
  90. set_pmd(pmd, __pmd(_PAGE_TABLE + (unsigned long) (pte)))
  91. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  92. struct page *pte)
  93. {
  94. set_pmd(pmd, __pmd(_PAGE_TABLE + (unsigned long) page_address (pte)));
  95. }
  96. static inline void check_pgt_cache(void)
  97. {
  98. quicklist_trim(0, NULL, 25, 16);
  99. }
  100. #endif /* __ASM_SH64_PGALLOC_H */