pgalloc.h 2.2 KB

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