Skip to content

Commit 5dda4dc

Browse files
committed
ARC: Page Table Management
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
1 parent 95d6976 commit 5dda4dc

3 files changed

Lines changed: 627 additions & 0 deletions

File tree

‎arch/arc/include/asm/page.h‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,98 @@
3535

3636
#define PAGE_MASK (~(PAGE_SIZE-1))
3737

38+
#ifdef __KERNEL__
39+
40+
#ifndef __ASSEMBLY__
41+
42+
#define get_user_page(vaddr) __get_free_page(GFP_KERNEL)
43+
#define free_user_page(page, addr) free_page(addr)
44+
45+
/* TBD: for now don't worry about VIPT D$ aliasing */
46+
#define clear_page(paddr) memset((paddr), 0, PAGE_SIZE)
47+
#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
48+
49+
#define clear_user_page(addr, vaddr, pg) clear_page(addr)
50+
#define copy_user_page(vto, vfrom, vaddr, pg) copy_page(vto, vfrom)
51+
52+
#undef STRICT_MM_TYPECHECKS
53+
54+
#ifdef STRICT_MM_TYPECHECKS
55+
/*
56+
* These are used to make use of C type-checking..
57+
*/
58+
typedef struct {
59+
unsigned long pte;
60+
} pte_t;
61+
typedef struct {
62+
unsigned long pgd;
63+
} pgd_t;
64+
typedef struct {
65+
unsigned long pgprot;
66+
} pgprot_t;
67+
typedef unsigned long pgtable_t;
68+
69+
#define pte_val(x) ((x).pte)
70+
#define pgd_val(x) ((x).pgd)
71+
#define pgprot_val(x) ((x).pgprot)
72+
73+
#define __pte(x) ((pte_t) { (x) })
74+
#define __pgd(x) ((pgd_t) { (x) })
75+
#define __pgprot(x) ((pgprot_t) { (x) })
76+
77+
#else /* !STRICT_MM_TYPECHECKS */
78+
79+
typedef unsigned long pte_t;
80+
typedef unsigned long pgd_t;
81+
typedef unsigned long pgprot_t;
82+
typedef unsigned long pgtable_t;
83+
84+
#define pte_val(x) (x)
85+
#define pgd_val(x) (x)
86+
#define pgprot_val(x) (x)
87+
#define __pte(x) (x)
88+
#define __pgprot(x) (x)
89+
90+
#endif
91+
92+
#define ARCH_PFN_OFFSET (CONFIG_LINUX_LINK_BASE >> PAGE_SHIFT)
93+
94+
#define pfn_valid(pfn) (((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
95+
96+
/*
97+
* __pa, __va, virt_to_page (ALERT: deprecated, don't use them)
98+
*
99+
* These macros have historically been misnamed
100+
* virt here means link-address/program-address as embedded in object code.
101+
* So if kernel img is linked at 0x8000_0000 onwards, 0x8010_0000 will be
102+
* 128th page, and virt_to_page( ) will return the struct page corresp to it.
103+
* mem_map[ ] is an array of struct page for each page frame in the system
104+
*
105+
* Independent of where linux is linked at, link-addr = physical address
106+
* So the old macro __pa = vaddr + PAGE_OFFSET - CONFIG_LINUX_LINK_BASE
107+
* would have been wrong in case kernel is not at 0x8zs
108+
*/
109+
#define __pa(vaddr) ((unsigned long)vaddr)
110+
#define __va(paddr) ((void *)((unsigned long)(paddr)))
111+
112+
#define virt_to_page(kaddr) \
113+
(mem_map + ((__pa(kaddr) - CONFIG_LINUX_LINK_BASE) >> PAGE_SHIFT))
114+
115+
#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
116+
117+
/* Default Permissions for page, used in mmap.c */
118+
#ifdef CONFIG_ARC_STACK_NONEXEC
119+
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE)
120+
#else
121+
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
122+
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
123+
#endif
124+
125+
#define WANT_PAGE_VIRTUAL 1
126+
127+
#include <asm-generic/memory_model.h> /* page_to_pfn, pfn_to_page */
128+
#include <asm-generic/getorder.h>
129+
38130
#endif /* !__ASSEMBLY__ */
39131

40132
#endif /* __KERNEL__ */

‎arch/arc/include/asm/pgalloc.h‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* vineetg: June 2011
9+
* -"/proc/meminfo | grep PageTables" kept on increasing
10+
* Recently added pgtable dtor was not getting called.
11+
*
12+
* vineetg: May 2011
13+
* -Variable pg-sz means that Page Tables could be variable sized themselves
14+
* So calculate it based on addr traversal split [pgd-bits:pte-bits:xxx]
15+
* -Page Table size capped to max 1 to save memory - hence verified.
16+
* -Since these deal with constants, gcc compile-time optimizes them.
17+
*
18+
* vineetg: Nov 2010
19+
* -Added pgtable ctor/dtor used for pgtable mem accounting
20+
*
21+
* vineetg: April 2010
22+
* -Switched pgtable_t from being struct page * to unsigned long
23+
* =Needed so that Page Table allocator (pte_alloc_one) is not forced to
24+
* to deal with struct page. Thay way in future we can make it allocate
25+
* multiple PG Tbls in one Page Frame
26+
* =sweet side effect is avoiding calls to ugly page_address( ) from the
27+
* pg-tlb allocator sub-sys (pte_alloc_one, ptr_free, pmd_populate
28+
*
29+
* Amit Bhor, Sameer Dhavale: Codito Technologies 2004
30+
*/
31+
32+
#ifndef _ASM_ARC_PGALLOC_H
33+
#define _ASM_ARC_PGALLOC_H
34+
35+
#include <linux/mm.h>
36+
#include <linux/log2.h>
37+
38+
static inline void
39+
pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
40+
{
41+
pmd_set(pmd, pte);
42+
}
43+
44+
static inline void
45+
pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t ptep)
46+
{
47+
pmd_set(pmd, (pte_t *) ptep);
48+
}
49+
50+
static inline int __get_order_pgd(void)
51+
{
52+
return get_order(PTRS_PER_PGD * 4);
53+
}
54+
55+
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
56+
{
57+
int num, num2;
58+
pgd_t *ret = (pgd_t *) __get_free_pages(GFP_KERNEL, __get_order_pgd());
59+
60+
if (ret) {
61+
num = USER_PTRS_PER_PGD + USER_KERNEL_GUTTER / PGDIR_SIZE;
62+
memzero(ret, num * sizeof(pgd_t));
63+
64+
num2 = VMALLOC_SIZE / PGDIR_SIZE;
65+
memcpy(ret + num, swapper_pg_dir + num, num2 * sizeof(pgd_t));
66+
67+
memzero(ret + num + num2,
68+
(PTRS_PER_PGD - num - num2) * sizeof(pgd_t));
69+
70+
}
71+
return ret;
72+
}
73+
74+
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
75+
{
76+
free_pages((unsigned long)pgd, __get_order_pgd());
77+
}
78+
79+
80+
/*
81+
* With software-only page-tables, addr-split for traversal is tweakable and
82+
* that directly governs how big tables would be at each level.
83+
* Further, the MMU page size is configurable.
84+
* Thus we need to programatically assert the size constraint
85+
* All of this is const math, allowing gcc to do constant folding/propagation.
86+
*/
87+
88+
static inline int __get_order_pte(void)
89+
{
90+
return get_order(PTRS_PER_PTE * 4);
91+
}
92+
93+
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
94+
unsigned long address)
95+
{
96+
pte_t *pte;
97+
98+
pte = (pte_t *) __get_free_pages(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO,
99+
__get_order_pte());
100+
101+
return pte;
102+
}
103+
104+
static inline pgtable_t
105+
pte_alloc_one(struct mm_struct *mm, unsigned long address)
106+
{
107+
pgtable_t pte_pg;
108+
109+
pte_pg = __get_free_pages(GFP_KERNEL | __GFP_REPEAT, __get_order_pte());
110+
if (pte_pg) {
111+
memzero((void *)pte_pg, PTRS_PER_PTE * 4);
112+
pgtable_page_ctor(virt_to_page(pte_pg));
113+
}
114+
115+
return pte_pg;
116+
}
117+
118+
static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
119+
{
120+
free_pages((unsigned long)pte, __get_order_pte()); /* takes phy addr */
121+
}
122+
123+
static inline void pte_free(struct mm_struct *mm, pgtable_t ptep)
124+
{
125+
pgtable_page_dtor(virt_to_page(ptep));
126+
free_pages(ptep, __get_order_pte());
127+
}
128+
129+
#define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, pte)
130+
131+
#define check_pgt_cache() do { } while (0)
132+
#define pmd_pgtable(pmd) pmd_page_vaddr(pmd)
133+
134+
#endif /* _ASM_ARC_PGALLOC_H */

0 commit comments

Comments
 (0)