pgalloc.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * OpenRISC Linux
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * OpenRISC implementation:
  10. * Copyright (C) 2003 Matjaz Breskvar <[email protected]>
  11. * Copyright (C) 2010-2011 Jonas Bonn <[email protected]>
  12. * et al.
  13. */
  14. #ifndef __ASM_OPENRISC_PGALLOC_H
  15. #define __ASM_OPENRISC_PGALLOC_H
  16. #include <asm/page.h>
  17. #include <linux/threads.h>
  18. #include <linux/mm.h>
  19. #include <linux/memblock.h>
  20. #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
  21. #include <asm-generic/pgalloc.h>
  22. extern int mem_init_done;
  23. #define pmd_populate_kernel(mm, pmd, pte) \
  24. set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte)))
  25. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  26. struct page *pte)
  27. {
  28. set_pmd(pmd, __pmd(_KERNPG_TABLE +
  29. ((unsigned long)page_to_pfn(pte) <<
  30. (unsigned long) PAGE_SHIFT)));
  31. }
  32. /*
  33. * Allocate and free page tables.
  34. */
  35. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  36. {
  37. pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL);
  38. if (ret) {
  39. memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  40. memcpy(ret + USER_PTRS_PER_PGD,
  41. swapper_pg_dir + USER_PTRS_PER_PGD,
  42. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  43. }
  44. return ret;
  45. }
  46. #if 0
  47. /* FIXME: This seems to be the preferred style, but we are using
  48. * current_pgd (from mm->pgd) to load kernel pages so we need it
  49. * initialized. This needs to be looked into.
  50. */
  51. extern inline pgd_t *pgd_alloc(struct mm_struct *mm)
  52. {
  53. return (pgd_t *)get_zeroed_page(GFP_KERNEL);
  54. }
  55. #endif
  56. extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm);
  57. #define __pte_free_tlb(tlb, pte, addr) \
  58. do { \
  59. pgtable_pte_page_dtor(pte); \
  60. tlb_remove_page((tlb), (pte)); \
  61. } while (0)
  62. #endif