pgalloc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * OpenRISC Linux
  3. *
  4. * Linux architectural port borrowing liberally from similar works of
  5. * others. All original copyrights apply as per the original source
  6. * declaration.
  7. *
  8. * OpenRISC implementation:
  9. * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
  10. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  11. * et al.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. */
  18. #ifndef __ASM_OPENRISC_PGALLOC_H
  19. #define __ASM_OPENRISC_PGALLOC_H
  20. #include <asm/page.h>
  21. #include <linux/threads.h>
  22. #include <linux/mm.h>
  23. #include <linux/memblock.h>
  24. extern int mem_init_done;
  25. #define pmd_populate_kernel(mm, pmd, pte) \
  26. set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte)))
  27. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  28. struct page *pte)
  29. {
  30. set_pmd(pmd, __pmd(_KERNPG_TABLE +
  31. ((unsigned long)page_to_pfn(pte) <<
  32. (unsigned long) PAGE_SHIFT)));
  33. }
  34. /*
  35. * Allocate and free page tables.
  36. */
  37. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  38. {
  39. pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL);
  40. if (ret) {
  41. memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  42. memcpy(ret + USER_PTRS_PER_PGD,
  43. swapper_pg_dir + USER_PTRS_PER_PGD,
  44. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  45. }
  46. return ret;
  47. }
  48. #if 0
  49. /* FIXME: This seems to be the preferred style, but we are using
  50. * current_pgd (from mm->pgd) to load kernel pages so we need it
  51. * initialized. This needs to be looked into.
  52. */
  53. extern inline pgd_t *pgd_alloc(struct mm_struct *mm)
  54. {
  55. return (pgd_t *)get_zeroed_page(GFP_KERNEL);
  56. }
  57. #endif
  58. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  59. {
  60. free_page((unsigned long)pgd);
  61. }
  62. extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
  63. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  64. unsigned long address)
  65. {
  66. struct page *pte;
  67. pte = alloc_pages(GFP_KERNEL, 0);
  68. if (!pte)
  69. return NULL;
  70. clear_page(page_address(pte));
  71. if (!pgtable_page_ctor(pte)) {
  72. __free_page(pte);
  73. return NULL;
  74. }
  75. return pte;
  76. }
  77. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  78. {
  79. free_page((unsigned long)pte);
  80. }
  81. static inline void pte_free(struct mm_struct *mm, struct page *pte)
  82. {
  83. pgtable_page_dtor(pte);
  84. __free_page(pte);
  85. }
  86. #define __pte_free_tlb(tlb, pte, addr) \
  87. do { \
  88. pgtable_page_dtor(pte); \
  89. tlb_remove_page((tlb), (pte)); \
  90. } while (0)
  91. #define pmd_pgtable(pmd) pmd_page(pmd)
  92. #define check_pgt_cache() do { } while (0)
  93. #endif