pgalloc.h 2.1 KB

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