Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 1994 - 2001, 2003 by Ralf Baechle
0007  * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
0008  */
0009 #ifndef _ASM_PGALLOC_H
0010 #define _ASM_PGALLOC_H
0011 
0012 #include <linux/highmem.h>
0013 #include <linux/mm.h>
0014 #include <linux/sched.h>
0015 
0016 #define __HAVE_ARCH_PMD_ALLOC_ONE
0017 #define __HAVE_ARCH_PUD_ALLOC_ONE
0018 #define __HAVE_ARCH_PGD_FREE
0019 #include <asm-generic/pgalloc.h>
0020 
0021 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
0022     pte_t *pte)
0023 {
0024     set_pmd(pmd, __pmd((unsigned long)pte));
0025 }
0026 
0027 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
0028     pgtable_t pte)
0029 {
0030     set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
0031 }
0032 
0033 /*
0034  * Initialize a new pmd table with invalid pointers.
0035  */
0036 extern void pmd_init(unsigned long page, unsigned long pagetable);
0037 
0038 #ifndef __PAGETABLE_PMD_FOLDED
0039 
0040 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
0041 {
0042     set_pud(pud, __pud((unsigned long)pmd));
0043 }
0044 #endif
0045 
0046 /*
0047  * Initialize a new pgd / pmd table with invalid pointers.
0048  */
0049 extern void pgd_init(unsigned long page);
0050 extern pgd_t *pgd_alloc(struct mm_struct *mm);
0051 
0052 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
0053 {
0054     free_pages((unsigned long)pgd, PGD_TABLE_ORDER);
0055 }
0056 
0057 #define __pte_free_tlb(tlb,pte,address)         \
0058 do {                            \
0059     pgtable_pte_page_dtor(pte);         \
0060     tlb_remove_page((tlb), pte);            \
0061 } while (0)
0062 
0063 #ifndef __PAGETABLE_PMD_FOLDED
0064 
0065 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
0066 {
0067     pmd_t *pmd;
0068     struct page *pg;
0069 
0070     pg = alloc_pages(GFP_KERNEL_ACCOUNT, PMD_TABLE_ORDER);
0071     if (!pg)
0072         return NULL;
0073 
0074     if (!pgtable_pmd_page_ctor(pg)) {
0075         __free_pages(pg, PMD_TABLE_ORDER);
0076         return NULL;
0077     }
0078 
0079     pmd = (pmd_t *)page_address(pg);
0080     pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
0081     return pmd;
0082 }
0083 
0084 #define __pmd_free_tlb(tlb, x, addr)    pmd_free((tlb)->mm, x)
0085 
0086 #endif
0087 
0088 #ifndef __PAGETABLE_PUD_FOLDED
0089 
0090 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
0091 {
0092     pud_t *pud;
0093 
0094     pud = (pud_t *) __get_free_pages(GFP_KERNEL, PUD_TABLE_ORDER);
0095     if (pud)
0096         pud_init((unsigned long)pud, (unsigned long)invalid_pmd_table);
0097     return pud;
0098 }
0099 
0100 static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
0101 {
0102     set_p4d(p4d, __p4d((unsigned long)pud));
0103 }
0104 
0105 #define __pud_free_tlb(tlb, x, addr)    pud_free((tlb)->mm, x)
0106 
0107 #endif /* __PAGETABLE_PUD_FOLDED */
0108 
0109 extern void pagetable_init(void);
0110 
0111 #endif /* _ASM_PGALLOC_H */