patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-parisc / pgalloc.h
1 #ifndef _ASM_PGALLOC_H
2 #define _ASM_PGALLOC_H
3
4 #include <linux/gfp.h>
5 #include <linux/mm.h>
6 #include <linux/threads.h>
7 #include <asm/processor.h>
8 #include <asm/fixmap.h>
9
10 #include <asm/pgtable.h>
11 #include <asm/cache.h>
12
13 /* Allocate the top level pgd (page directory)
14  *
15  * Here (for 64 bit kernels) we implement a Hybrid L2/L3 scheme: we
16  * allocate the first pmd adjacent to the pgd.  This means that we can
17  * subtract a constant offset to get to it.  The pmd and pgd sizes are
18  * arranged so that a single pmd covers 4GB (giving a full LP64
19  * process access to 8TB) so our lookups are effectively L2 for the
20  * first 4GB of the kernel (i.e. for all ILP32 processes and all the
21  * kernel for machines with under 4GB of memory) */
22 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
23 {
24         pgd_t *pgd = (pgd_t *)__get_free_pages(GFP_KERNEL|GFP_DMA,
25                                                PGD_ALLOC_ORDER);
26         pgd_t *actual_pgd = pgd;
27
28         if (likely(pgd != NULL)) {
29                 memset(pgd, 0, PAGE_SIZE<<PGD_ALLOC_ORDER);
30 #ifdef __LP64__
31                 actual_pgd += PTRS_PER_PGD;
32                 /* Populate first pmd with allocated memory.  We mark it
33                  * with _PAGE_GATEWAY as a signal to the system that this
34                  * pmd entry may not be cleared. */
35                 pgd_val(*actual_pgd) = (_PAGE_TABLE | _PAGE_GATEWAY) + 
36                         (__u32)__pa((unsigned long)pgd);
37                 /* The first pmd entry also is marked with _PAGE_GATEWAY as
38                  * a signal that this pmd may not be freed */
39                 pgd_val(*pgd) = _PAGE_GATEWAY;
40 #endif
41         }
42         return actual_pgd;
43 }
44
45 static inline void pgd_free(pgd_t *pgd)
46 {
47 #ifdef __LP64__
48         pgd -= PTRS_PER_PGD;
49 #endif
50         free_pages((unsigned long)pgd, PGD_ALLOC_ORDER);
51 }
52
53 #if PT_NLEVELS == 3
54
55 /* Three Level Page Table Support for pmd's */
56
57 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
58 {
59         pgd_val(*pgd) = _PAGE_TABLE + (__u32)__pa((unsigned long)pmd);
60 }
61
62 /* NOTE: pmd must be in ZONE_DMA (<4GB) so the pgd pointer can be
63  * housed in 32 bits */
64 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
65 {
66         pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT|GFP_DMA,
67                                                PMD_ORDER);
68         if (pmd)
69                 memset(pmd, 0, PAGE_SIZE<<PMD_ORDER);
70         return pmd;
71 }
72
73 static inline void pmd_free(pmd_t *pmd)
74 {
75 #ifdef __LP64__
76         if(pmd_val(*pmd) & _PAGE_GATEWAY)
77                 /* This is the permanent pmd attached to the pgd;
78                  * cannot free it */
79                 return;
80 #endif
81         free_pages((unsigned long)pmd, PMD_ORDER);
82 }
83
84 #else
85
86 /* Two Level Page Table Support for pmd's */
87
88 /*
89  * allocating and freeing a pmd is trivial: the 1-entry pmd is
90  * inside the pgd, so has no extra memory associated with it.
91  */
92
93 #define pmd_alloc_one(mm, addr)         ({ BUG(); ((pmd_t *)2); })
94 #define pmd_free(x)                     do { } while (0)
95 #define pgd_populate(mm, pmd, pte)      BUG()
96
97 #endif
98
99 static inline void
100 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
101 {
102 #ifdef __LP64__
103         /* preserve the gateway marker if this is the beginning of
104          * the permanent pmd */
105         if(pmd_val(*pmd) & _PAGE_GATEWAY)
106                 pmd_val(*pmd) = (_PAGE_TABLE | _PAGE_GATEWAY)
107                         + (__u32)__pa((unsigned long)pte);
108         else
109 #endif
110                 pmd_val(*pmd) = _PAGE_TABLE + (__u32)__pa((unsigned long)pte);
111 }
112
113 #define pmd_populate(mm, pmd, pte_page) \
114         pmd_populate_kernel(mm, pmd, page_address(pte_page))
115
116 /* NOTE: pte must be in ZONE_DMA (<4GB) so that the pmd pointer
117  * can be housed in 32 bits */
118 static inline struct page *
119 pte_alloc_one(struct mm_struct *mm, unsigned long address)
120 {
121         struct page *page = alloc_page(GFP_KERNEL|__GFP_REPEAT|GFP_DMA);
122         if (likely(page != NULL))
123                 clear_page(page_address(page));
124         return page;
125 }
126
127 static inline pte_t *
128 pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
129 {
130         pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|GFP_DMA);
131         if (likely(pte != NULL))
132                 clear_page(pte);
133         return pte;
134 }
135
136 static inline void pte_free_kernel(pte_t *pte)
137 {
138         free_page((unsigned long)pte);
139 }
140
141 #define pte_free(page)  pte_free_kernel(page_address(page))
142
143 extern int do_check_pgt_cache(int, int);
144 #define check_pgt_cache()       do { } while (0)
145
146 #endif