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>
13 #include <linux/slab.h>
16 #include <asm/pgalloc.h>
18 #include <asm/tlbflush.h>
22 #ifdef CONFIG_ARM_LPAE
23 #define __pgd_alloc() kmalloc(PTRS_PER_PGD * sizeof(pgd_t), GFP_KERNEL)
24 #define __pgd_free(pgd) kfree(pgd)
26 #define __pgd_alloc() (pgd_t *)__get_free_pages(GFP_KERNEL, 2)
27 #define __pgd_free(pgd) free_pages((unsigned long)pgd, 2)
31 * need to get a 16k page for level 1
33 pgd_t
*pgd_alloc(struct mm_struct
*mm
)
35 pgd_t
*new_pgd
, *init_pgd
;
36 pud_t
*new_pud
, *init_pud
;
37 pmd_t
*new_pmd
, *init_pmd
;
38 pte_t
*new_pte
, *init_pte
;
40 new_pgd
= __pgd_alloc();
44 memset(new_pgd
, 0, USER_PTRS_PER_PGD
* sizeof(pgd_t
));
47 * Copy over the kernel and IO PGD entries
49 init_pgd
= pgd_offset_k(0);
50 memcpy(new_pgd
+ USER_PTRS_PER_PGD
, init_pgd
+ USER_PTRS_PER_PGD
,
51 (PTRS_PER_PGD
- USER_PTRS_PER_PGD
) * sizeof(pgd_t
));
53 clean_dcache_area(new_pgd
, PTRS_PER_PGD
* sizeof(pgd_t
));
55 #ifdef CONFIG_ARM_LPAE
57 * Allocate PMD table for modules and pkmap mappings.
59 new_pud
= pud_alloc(mm
, new_pgd
+ pgd_index(MODULES_VADDR
),
64 new_pmd
= pmd_alloc(mm
, new_pud
, 0);
69 if (!vectors_high()) {
71 * On ARM, first page must always be allocated since it
72 * contains the machine vectors. The vectors are always high
75 new_pud
= pud_alloc(mm
, new_pgd
, 0);
79 new_pmd
= pmd_alloc(mm
, new_pud
, 0);
83 new_pte
= pte_alloc_map(mm
, new_pmd
, 0);
87 #ifndef CONFIG_ARM_LPAE
89 * Modify the PTE pointer to have the correct domain. This
90 * needs to be the vectors domain to avoid the low vectors
93 pmd_val(*new_pmd
) &= ~PMD_DOMAIN_MASK
;
94 pmd_val(*new_pmd
) |= PMD_DOMAIN(DOMAIN_VECTORS
);
97 init_pud
= pud_offset(init_pgd
, 0);
98 init_pmd
= pmd_offset(init_pud
, 0);
99 init_pte
= pte_offset_map(init_pmd
, 0);
100 set_pte_ext(new_pte
+ 0, init_pte
[0], 0);
101 set_pte_ext(new_pte
+ 1, init_pte
[1], 0);
109 pmd_free(mm
, new_pmd
);
112 pud_free(mm
, new_pud
);
119 void pgd_free(struct mm_struct
*mm
, pgd_t
*pgd_base
)
129 pgd
= pgd_base
+ pgd_index(0);
130 if (pgd_none_or_clear_bad(pgd
))
133 pud
= pud_offset(pgd
, 0);
134 if (pud_none_or_clear_bad(pud
))
137 pmd
= pmd_offset(pud
, 0);
138 if (pmd_none_or_clear_bad(pmd
))
141 pte
= pmd_pgtable(*pmd
);
144 atomic_long_dec(&mm
->nr_ptes
);
153 #ifdef CONFIG_ARM_LPAE
155 * Free modules/pkmap or identity pmd tables.
157 for (pgd
= pgd_base
; pgd
< pgd_base
+ PTRS_PER_PGD
; pgd
++) {
158 if (pgd_none_or_clear_bad(pgd
))
160 if (pgd_val(*pgd
) & L_PGD_SWAPPER
)
162 pud
= pud_offset(pgd
, 0);
163 if (pud_none_or_clear_bad(pud
))
165 pmd
= pmd_offset(pud
, 0);
173 __pgd_free(pgd_base
);