Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
0004  *
0005  * vineetg: June 2011
0006  *  -"/proc/meminfo | grep PageTables" kept on increasing
0007  *   Recently added pgtable dtor was not getting called.
0008  *
0009  * vineetg: May 2011
0010  *  -Variable pg-sz means that Page Tables could be variable sized themselves
0011  *    So calculate it based on addr traversal split [pgd-bits:pte-bits:xxx]
0012  *  -Page Table size capped to max 1 to save memory - hence verified.
0013  *  -Since these deal with constants, gcc compile-time optimizes them.
0014  *
0015  * vineetg: Nov 2010
0016  *  -Added pgtable ctor/dtor used for pgtable mem accounting
0017  *
0018  * vineetg: April 2010
0019  *  -Switched pgtable_t from being struct page * to unsigned long
0020  *      =Needed so that Page Table allocator (pte_alloc_one) is not forced to
0021  *       deal with struct page. That way in future we can make it allocate
0022  *       multiple PG Tbls in one Page Frame
0023  *      =sweet side effect is avoiding calls to ugly page_address( ) from the
0024  *       pg-tlb allocator sub-sys (pte_alloc_one, ptr_free, pmd_populate)
0025  *
0026  *  Amit Bhor, Sameer Dhavale: Codito Technologies 2004
0027  */
0028 
0029 #ifndef _ASM_ARC_PGALLOC_H
0030 #define _ASM_ARC_PGALLOC_H
0031 
0032 #include <linux/mm.h>
0033 #include <linux/log2.h>
0034 #include <asm-generic/pgalloc.h>
0035 
0036 static inline void
0037 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
0038 {
0039     /*
0040      * The cast to long below is OK in 32-bit PAE40 regime with long long pte
0041      * Despite "wider" pte, the pte table needs to be in non-PAE low memory
0042      * as all higher levels can only hold long pointers.
0043      *
0044      * The cast itself is needed given simplistic definition of set_pmd()
0045      */
0046     set_pmd(pmd, __pmd((unsigned long)pte));
0047 }
0048 
0049 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte_page)
0050 {
0051     set_pmd(pmd, __pmd((unsigned long)page_address(pte_page)));
0052 }
0053 
0054 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
0055 {
0056     pgd_t *ret = (pgd_t *) __get_free_page(GFP_KERNEL);
0057 
0058     if (ret) {
0059         int num, num2;
0060         num = USER_PTRS_PER_PGD + USER_KERNEL_GUTTER / PGDIR_SIZE;
0061         memzero(ret, num * sizeof(pgd_t));
0062 
0063         num2 = VMALLOC_SIZE / PGDIR_SIZE;
0064         memcpy(ret + num, swapper_pg_dir + num, num2 * sizeof(pgd_t));
0065 
0066         memzero(ret + num + num2,
0067                    (PTRS_PER_PGD - num - num2) * sizeof(pgd_t));
0068 
0069     }
0070     return ret;
0071 }
0072 
0073 #if CONFIG_PGTABLE_LEVELS > 3
0074 
0075 static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp)
0076 {
0077     set_p4d(p4dp, __p4d((unsigned long)pudp));
0078 }
0079 
0080 #define __pud_free_tlb(tlb, pmd, addr)  pud_free((tlb)->mm, pmd)
0081 
0082 #endif
0083 
0084 #if CONFIG_PGTABLE_LEVELS > 2
0085 
0086 static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
0087 {
0088     set_pud(pudp, __pud((unsigned long)pmdp));
0089 }
0090 
0091 #define __pmd_free_tlb(tlb, pmd, addr)  pmd_free((tlb)->mm, pmd)
0092 
0093 #endif
0094 
0095 #define __pte_free_tlb(tlb, pte, addr)  pte_free((tlb)->mm, pte)
0096 
0097 #endif /* _ASM_ARC_PGALLOC_H */