pgalloc.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  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. #ifndef __ASM_AVR32_PGALLOC_H
  9. #define __ASM_AVR32_PGALLOC_H
  10. #include <linux/mm.h>
  11. #include <linux/quicklist.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable.h>
  14. #define QUICK_PGD 0 /* Preserve kernel mappings over free */
  15. #define QUICK_PT 1 /* Zero on free */
  16. static inline void pmd_populate_kernel(struct mm_struct *mm,
  17. pmd_t *pmd, pte_t *pte)
  18. {
  19. set_pmd(pmd, __pmd((unsigned long)pte));
  20. }
  21. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  22. pgtable_t pte)
  23. {
  24. set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
  25. }
  26. #define pmd_pgtable(pmd) pmd_page(pmd)
  27. static inline void pgd_ctor(void *x)
  28. {
  29. pgd_t *pgd = x;
  30. memcpy(pgd + USER_PTRS_PER_PGD,
  31. swapper_pg_dir + USER_PTRS_PER_PGD,
  32. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  33. }
  34. /*
  35. * Allocate and free page tables
  36. */
  37. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  38. {
  39. return quicklist_alloc(QUICK_PGD, GFP_KERNEL, pgd_ctor);
  40. }
  41. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  42. {
  43. quicklist_free(QUICK_PGD, NULL, pgd);
  44. }
  45. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  46. unsigned long address)
  47. {
  48. return quicklist_alloc(QUICK_PT, GFP_KERNEL, NULL);
  49. }
  50. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  51. unsigned long address)
  52. {
  53. struct page *page;
  54. void *pg;
  55. pg = quicklist_alloc(QUICK_PT, GFP_KERNEL, NULL);
  56. if (!pg)
  57. return NULL;
  58. page = virt_to_page(pg);
  59. if (!pgtable_page_ctor(page)) {
  60. quicklist_free(QUICK_PT, NULL, pg);
  61. return NULL;
  62. }
  63. return page;
  64. }
  65. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  66. {
  67. quicklist_free(QUICK_PT, NULL, pte);
  68. }
  69. static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  70. {
  71. pgtable_page_dtor(pte);
  72. quicklist_free_page(QUICK_PT, NULL, pte);
  73. }
  74. #define __pte_free_tlb(tlb,pte,addr) \
  75. do { \
  76. pgtable_page_dtor(pte); \
  77. tlb_remove_page((tlb), pte); \
  78. } while (0)
  79. static inline void check_pgt_cache(void)
  80. {
  81. quicklist_trim(QUICK_PGD, NULL, 25, 16);
  82. quicklist_trim(QUICK_PT, NULL, 25, 16);
  83. }
  84. #endif /* __ASM_AVR32_PGALLOC_H */