pgalloc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #include <linux/bootmem.h>
  25. extern int mem_init_done;
  26. #define pmd_populate_kernel(mm, pmd, pte) \
  27. set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte)))
  28. static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
  29. struct page *pte)
  30. {
  31. set_pmd(pmd, __pmd(_KERNPG_TABLE +
  32. ((unsigned long)page_to_pfn(pte) <<
  33. (unsigned long) PAGE_SHIFT)));
  34. }
  35. /*
  36. * Allocate and free page tables.
  37. */
  38. static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  39. {
  40. pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL);
  41. if (ret) {
  42. memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  43. memcpy(ret + USER_PTRS_PER_PGD,
  44. swapper_pg_dir + USER_PTRS_PER_PGD,
  45. (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  46. }
  47. return ret;
  48. }
  49. #if 0
  50. /* FIXME: This seems to be the preferred style, but we are using
  51. * current_pgd (from mm->pgd) to load kernel pages so we need it
  52. * initialized. This needs to be looked into.
  53. */
  54. extern inline pgd_t *pgd_alloc(struct mm_struct *mm)
  55. {
  56. return (pgd_t *)get_zeroed_page(GFP_KERNEL);
  57. }
  58. #endif
  59. static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  60. {
  61. free_page((unsigned long)pgd);
  62. }
  63. extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
  64. static inline struct page *pte_alloc_one(struct mm_struct *mm,
  65. unsigned long address)
  66. {
  67. struct page *pte;
  68. pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
  69. if (!pte)
  70. return NULL;
  71. clear_page(page_address(pte));
  72. if (!pgtable_page_ctor(pte)) {
  73. __free_page(pte);
  74. return NULL;
  75. }
  76. return pte;
  77. }
  78. static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  79. {
  80. free_page((unsigned long)pte);
  81. }
  82. static inline void pte_free(struct mm_struct *mm, struct page *pte)
  83. {
  84. pgtable_page_dtor(pte);
  85. __free_page(pte);
  86. }
  87. #define __pte_free_tlb(tlb, pte, addr) tlb_remove_page((tlb), (pte))
  88. #define pmd_pgtable(pmd) pmd_page(pmd)
  89. #define check_pgt_cache() do { } while (0)
  90. #endif