pgalloc.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * include/asm-xtensa/pgalloc.h
  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. * Copyright (C) 2001-2007 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_PGALLOC_H
  11. #define _XTENSA_PGALLOC_H
  12. #ifdef __KERNEL__
  13. #include <linux/highmem.h>
  14. #include <linux/slab.h>
  15. /*
  16. * Allocating and freeing a pmd is trivial: the 1-entry pmd is
  17. * inside the pgd, so has no extra memory associated with it.
  18. */
  19. #define pmd_populate_kernel(mm, pmdp, ptep) \
  20. (pmd_val(*(pmdp)) = ((unsigned long)ptep))
  21. #define pmd_populate(mm, pmdp, page) \
  22. (pmd_val(*(pmdp)) = ((unsigned long)page_to_virt(page)))
  23. #define pmd_pgtable(pmd) pmd_page(pmd)
  24. static inline pgd_t*
  25. pgd_alloc(struct mm_struct *mm)
  26. {
  27. return (pgd_t*) __get_free_pages(GFP_KERNEL | __GFP_ZERO, PGD_ORDER);
  28. }
  29. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  30. {
  31. free_page((unsigned long)pgd);
  32. }
  33. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  34. unsigned long address)
  35. {
  36. pte_t *ptep;
  37. int i;
  38. ptep = (pte_t *)__get_free_page(GFP_KERNEL);
  39. if (!ptep)
  40. return NULL;
  41. for (i = 0; i < 1024; i++)
  42. pte_clear(NULL, 0, ptep + i);
  43. return ptep;
  44. }
  45. static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
  46. unsigned long addr)
  47. {
  48. pte_t *pte;
  49. struct page *page;
  50. pte = pte_alloc_one_kernel(mm, addr);
  51. if (!pte)
  52. return NULL;
  53. page = virt_to_page(pte);
  54. if (!pgtable_page_ctor(page)) {
  55. __free_page(page);
  56. return NULL;
  57. }
  58. return page;
  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 pmd_pgtable(pmd) pmd_page(pmd)
  70. #endif /* __KERNEL__ */
  71. #endif /* _XTENSA_PGALLOC_H */