pgd.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * linux/arch/unicore32/mm/pgd.c
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/gfp.h>
  14. #include <linux/highmem.h>
  15. #include <asm/pgalloc.h>
  16. #include <asm/page.h>
  17. #include <asm/tlbflush.h>
  18. #include "mm.h"
  19. #define FIRST_KERNEL_PGD_NR (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD)
  20. /*
  21. * need to get a 4k page for level 1
  22. */
  23. pgd_t *get_pgd_slow(struct mm_struct *mm)
  24. {
  25. pgd_t *new_pgd, *init_pgd;
  26. pmd_t *new_pmd, *init_pmd;
  27. pte_t *new_pte, *init_pte;
  28. new_pgd = (pgd_t *)__get_free_pages(GFP_KERNEL, 0);
  29. if (!new_pgd)
  30. goto no_pgd;
  31. memset(new_pgd, 0, FIRST_KERNEL_PGD_NR * sizeof(pgd_t));
  32. /*
  33. * Copy over the kernel and IO PGD entries
  34. */
  35. init_pgd = pgd_offset_k(0);
  36. memcpy(new_pgd + FIRST_KERNEL_PGD_NR, init_pgd + FIRST_KERNEL_PGD_NR,
  37. (PTRS_PER_PGD - FIRST_KERNEL_PGD_NR) * sizeof(pgd_t));
  38. clean_dcache_area(new_pgd, PTRS_PER_PGD * sizeof(pgd_t));
  39. if (!vectors_high()) {
  40. /*
  41. * On UniCore, first page must always be allocated since it
  42. * contains the machine vectors.
  43. */
  44. new_pmd = pmd_alloc(mm, (pud_t *)new_pgd, 0);
  45. if (!new_pmd)
  46. goto no_pmd;
  47. new_pte = pte_alloc_map(mm, NULL, new_pmd, 0);
  48. if (!new_pte)
  49. goto no_pte;
  50. init_pmd = pmd_offset((pud_t *)init_pgd, 0);
  51. init_pte = pte_offset_map(init_pmd, 0);
  52. set_pte(new_pte, *init_pte);
  53. pte_unmap(init_pte);
  54. pte_unmap(new_pte);
  55. }
  56. return new_pgd;
  57. no_pte:
  58. pmd_free(mm, new_pmd);
  59. mm_dec_nr_pmds(mm);
  60. no_pmd:
  61. free_pages((unsigned long)new_pgd, 0);
  62. no_pgd:
  63. return NULL;
  64. }
  65. void free_pgd_slow(struct mm_struct *mm, pgd_t *pgd)
  66. {
  67. pmd_t *pmd;
  68. pgtable_t pte;
  69. if (!pgd)
  70. return;
  71. /* pgd is always present and good */
  72. pmd = pmd_off(pgd, 0);
  73. if (pmd_none(*pmd))
  74. goto free;
  75. if (pmd_bad(*pmd)) {
  76. pmd_ERROR(*pmd);
  77. pmd_clear(pmd);
  78. goto free;
  79. }
  80. pte = pmd_pgtable(*pmd);
  81. pmd_clear(pmd);
  82. pte_free(mm, pte);
  83. atomic_long_dec(&mm->nr_ptes);
  84. pmd_free(mm, pmd);
  85. mm_dec_nr_pmds(mm);
  86. free:
  87. free_pages((unsigned long) pgd, 0);
  88. }