2 * linux/arch/arm/mm/pgd.c
4 * Copyright (C) 1998-2005 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/gfp.h>
12 #include <linux/highmem.h>
14 #include <asm/pgalloc.h>
16 #include <asm/tlbflush.h>
21 * need to get a 16k page for level 1
23 pgd_t
*pgd_alloc(struct mm_struct
*mm
)
25 pgd_t
*new_pgd
, *init_pgd
;
26 pud_t
*new_pud
, *init_pud
;
27 pmd_t
*new_pmd
, *init_pmd
;
28 pte_t
*new_pte
, *init_pte
;
30 new_pgd
= (pgd_t
*)__get_free_pages(GFP_KERNEL
, 2);
34 memset(new_pgd
, 0, USER_PTRS_PER_PGD
* sizeof(pgd_t
));
37 * Copy over the kernel and IO PGD entries
39 init_pgd
= pgd_offset_k(0);
40 memcpy(new_pgd
+ USER_PTRS_PER_PGD
, init_pgd
+ USER_PTRS_PER_PGD
,
41 (PTRS_PER_PGD
- USER_PTRS_PER_PGD
) * sizeof(pgd_t
));
43 clean_dcache_area(new_pgd
, PTRS_PER_PGD
* sizeof(pgd_t
));
45 if (!vectors_high()) {
47 * On ARM, first page must always be allocated since it
48 * contains the machine vectors.
50 new_pud
= pud_alloc(mm
, new_pgd
, 0);
54 new_pmd
= pmd_alloc(mm
, new_pud
, 0);
58 new_pte
= pte_alloc_map(mm
, NULL
, new_pmd
, 0);
62 init_pud
= pud_offset(init_pgd
, 0);
63 init_pmd
= pmd_offset(init_pud
, 0);
64 init_pte
= pte_offset_map(init_pmd
, 0);
65 set_pte_ext(new_pte
, *init_pte
, 0);
73 pmd_free(mm
, new_pmd
);
75 pud_free(mm
, new_pud
);
77 free_pages((unsigned long)new_pgd
, 2);
82 void pgd_free(struct mm_struct
*mm
, pgd_t
*pgd_base
)
92 pgd
= pgd_base
+ pgd_index(0);
93 if (pgd_none_or_clear_bad(pgd
))
96 pud
= pud_offset(pgd
, 0);
97 if (pud_none_or_clear_bad(pud
))
100 pmd
= pmd_offset(pud
, 0);
101 if (pmd_none_or_clear_bad(pmd
))
104 pte
= pmd_pgtable(*pmd
);
114 free_pages((unsigned long) pgd_base
, 2);