pgalloc.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_NOHASH_PGALLOC_H
  3. #define _ASM_POWERPC_NOHASH_PGALLOC_H
  4. #include <linux/mm.h>
  5. #include <linux/slab.h>
  6. extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
  7. #ifdef CONFIG_PPC64
  8. extern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address);
  9. #else
  10. /* 44x etc which is BOOKE not BOOK3E */
  11. static inline void tlb_flush_pgtable(struct mmu_gather *tlb,
  12. unsigned long address)
  13. {
  14. }
  15. #endif /* !CONFIG_PPC_BOOK3E_64 */
  16. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  17. {
  18. return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
  19. pgtable_gfp_flags(mm, GFP_KERNEL));
  20. }
  21. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  22. {
  23. kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  24. }
  25. #ifdef CONFIG_PPC64
  26. #include <asm/nohash/64/pgalloc.h>
  27. #else
  28. #include <asm/nohash/32/pgalloc.h>
  29. #endif
  30. static inline void pgtable_free(void *table, int shift)
  31. {
  32. if (!shift) {
  33. pte_fragment_free((unsigned long *)table, 0);
  34. } else {
  35. BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
  36. kmem_cache_free(PGT_CACHE(shift), table);
  37. }
  38. }
  39. #define get_hugepd_cache_index(x) (x)
  40. static inline void pgtable_free_tlb(struct mmu_gather *tlb, void *table, int shift)
  41. {
  42. unsigned long pgf = (unsigned long)table;
  43. BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
  44. pgf |= shift;
  45. tlb_remove_table(tlb, (void *)pgf);
  46. }
  47. static inline void __tlb_remove_table(void *_table)
  48. {
  49. void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
  50. unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
  51. pgtable_free(table, shift);
  52. }
  53. static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
  54. unsigned long address)
  55. {
  56. tlb_flush_pgtable(tlb, address);
  57. pgtable_free_tlb(tlb, table, 0);
  58. }
  59. #endif /* _ASM_POWERPC_NOHASH_PGALLOC_H */