pgalloc.h 1.9 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 <asm/processor.h>
  11. #include <linux/threads.h>
  12. #include <linux/slab.h>
  13. #include <linux/mm.h>
  14. #define pmd_populate_kernel(mm, pmd, pte) \
  15. set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
  16. static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  17. struct page *pte)
  18. {
  19. set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
  20. }
  21. /*
  22. * Allocate and free page tables
  23. */
  24. static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
  25. {
  26. unsigned int pgd_size = (USER_PTRS_PER_PGD * sizeof(pgd_t));
  27. pgd_t *pgd = (pgd_t *)kmalloc(pgd_size, GFP_KERNEL);
  28. if (pgd)
  29. memset(pgd, 0, pgd_size);
  30. return pgd;
  31. }
  32. static inline void pgd_free(pgd_t *pgd)
  33. {
  34. kfree(pgd);
  35. }
  36. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  37. unsigned long address)
  38. {
  39. int count = 0;
  40. pte_t *pte;
  41. do {
  42. pte = (pte_t *) __get_free_page(GFP_KERNEL | __GFP_REPEAT);
  43. if (pte)
  44. clear_page(pte);
  45. else {
  46. current->state = TASK_UNINTERRUPTIBLE;
  47. schedule_timeout(HZ);
  48. }
  49. } while (!pte && (count++ < 10));
  50. return pte;
  51. }
  52. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  53. unsigned long address)
  54. {
  55. int count = 0;
  56. struct page *pte;
  57. do {
  58. pte = alloc_pages(GFP_KERNEL, 0);
  59. if (pte)
  60. clear_page(page_address(pte));
  61. else {
  62. current->state = TASK_UNINTERRUPTIBLE;
  63. schedule_timeout(HZ);
  64. }
  65. } while (!pte && (count++ < 10));
  66. return pte;
  67. }
  68. static inline void pte_free_kernel(pte_t *pte)
  69. {
  70. free_page((unsigned long)pte);
  71. }
  72. static inline void pte_free(struct page *pte)
  73. {
  74. __free_page(pte);
  75. }
  76. #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
  77. #define check_pgt_cache() do { } while(0)
  78. #endif /* __ASM_AVR32_PGALLOC_H */