pgalloc.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_PGALLOC_H
  3. #define _ASM_POWERPC_PGALLOC_H
  4. #include <linux/mm.h>
  5. #ifndef MODULE
  6. static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
  7. {
  8. if (unlikely(mm == &init_mm))
  9. return gfp;
  10. return gfp | __GFP_ACCOUNT;
  11. }
  12. #else /* !MODULE */
  13. static inline gfp_t pgtable_gfp_flags(struct mm_struct *mm, gfp_t gfp)
  14. {
  15. return gfp | __GFP_ACCOUNT;
  16. }
  17. #endif /* MODULE */
  18. #define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO)
  19. pte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel);
  20. static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
  21. {
  22. return (pte_t *)pte_fragment_alloc(mm, 1);
  23. }
  24. static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
  25. {
  26. return (pgtable_t)pte_fragment_alloc(mm, 0);
  27. }
  28. void pte_frag_destroy(void *pte_frag);
  29. void pte_fragment_free(unsigned long *table, int kernel);
  30. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  31. {
  32. pte_fragment_free((unsigned long *)pte, 1);
  33. }
  34. static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  35. {
  36. pte_fragment_free((unsigned long *)ptepage, 0);
  37. }
  38. /*
  39. * Functions that deal with pagetables that could be at any level of
  40. * the table need to be passed an "index_size" so they know how to
  41. * handle allocation. For PTE pages, the allocation size will be
  42. * (2^index_size * sizeof(pointer)) and allocations are drawn from
  43. * the kmem_cache in PGT_CACHE(index_size).
  44. *
  45. * The maximum index size needs to be big enough to allow any
  46. * pagetable sizes we need, but small enough to fit in the low bits of
  47. * any page table pointer. In other words all pagetables, even tiny
  48. * ones, must be aligned to allow at least enough low 0 bits to
  49. * contain this value. This value is also used as a mask, so it must
  50. * be one less than a power of two.
  51. */
  52. #define MAX_PGTABLE_INDEX_SIZE 0xf
  53. extern struct kmem_cache *pgtable_cache[];
  54. #define PGT_CACHE(shift) pgtable_cache[shift]
  55. #ifdef CONFIG_PPC_BOOK3S
  56. #include <asm/book3s/pgalloc.h>
  57. #else
  58. #include <asm/nohash/pgalloc.h>
  59. #endif
  60. #endif /* _ASM_POWERPC_PGALLOC_H */