Skip to content

Commit 2e1aecb

Browse files
author
Greentime Hu
committed
nds32: MMU definitions
This patch includes virtual memory layout, PHYS_OFFSET is defined as 0x0. It also includes the 4KB/8KB page size configurations and pte operations. Signed-off-by: Vincent Chen <vincentc@andestech.com> Signed-off-by: Greentime Hu <greentime@andestech.com> Acked-by: Arnd Bergmann <arnd@arndb.de>
1 parent 2923f5e commit 2e1aecb

8 files changed

Lines changed: 802 additions & 0 deletions

File tree

‎arch/nds32/include/asm/fixmap.h‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2005-2017 Andes Technology Corporation
3+
4+
#ifndef __ASM_NDS32_FIXMAP_H
5+
#define __ASM_NDS32_FIXMAP_H
6+
7+
#ifdef CONFIG_HIGHMEM
8+
#include <linux/threads.h>
9+
#include <asm/kmap_types.h>
10+
#endif
11+
12+
enum fixed_addresses {
13+
FIX_HOLE,
14+
FIX_KMAP_RESERVED,
15+
FIX_KMAP_BEGIN,
16+
#ifdef CONFIG_HIGHMEM
17+
FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS),
18+
#endif
19+
FIX_EARLYCON_MEM_BASE,
20+
__end_of_fixed_addresses
21+
};
22+
#define FIXADDR_TOP ((unsigned long) (-(16 * PAGE_SIZE)))
23+
#define FIXADDR_SIZE ((__end_of_fixed_addresses) << PAGE_SHIFT)
24+
#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
25+
#define FIXMAP_PAGE_IO __pgprot(PAGE_DEVICE)
26+
void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot);
27+
28+
#include <asm-generic/fixmap.h>
29+
#endif /* __ASM_NDS32_FIXMAP_H */

‎arch/nds32/include/asm/highmem.h‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2005-2017 Andes Technology Corporation
3+
4+
#ifndef _ASM_HIGHMEM_H
5+
#define _ASM_HIGHMEM_H
6+
7+
#include <asm/proc-fns.h>
8+
#include <asm/kmap_types.h>
9+
#include <asm/fixmap.h>
10+
#include <asm/pgtable.h>
11+
12+
/*
13+
* Right now we initialize only a single pte table. It can be extended
14+
* easily, subsequent pte tables have to be allocated in one physical
15+
* chunk of RAM.
16+
*/
17+
/*
18+
* Ordering is (from lower to higher memory addresses):
19+
*
20+
* high_memory
21+
* Persistent kmap area
22+
* PKMAP_BASE
23+
* fixed_addresses
24+
* FIXADDR_START
25+
* FIXADDR_TOP
26+
* Vmalloc area
27+
* VMALLOC_START
28+
* VMALLOC_END
29+
*/
30+
#define PKMAP_BASE ((FIXADDR_START - PGDIR_SIZE) & (PGDIR_MASK))
31+
#define LAST_PKMAP PTRS_PER_PTE
32+
#define LAST_PKMAP_MASK (LAST_PKMAP - 1)
33+
#define PKMAP_NR(virt) (((virt) - (PKMAP_BASE)) >> PAGE_SHIFT)
34+
#define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT))
35+
#define kmap_prot PAGE_KERNEL
36+
37+
static inline void flush_cache_kmaps(void)
38+
{
39+
cpu_dcache_wbinval_all();
40+
}
41+
42+
/* declarations for highmem.c */
43+
extern unsigned long highstart_pfn, highend_pfn;
44+
45+
extern pte_t *pkmap_page_table;
46+
47+
extern void *kmap_high(struct page *page);
48+
extern void kunmap_high(struct page *page);
49+
50+
extern void kmap_init(void);
51+
52+
/*
53+
* The following functions are already defined by <linux/highmem.h>
54+
* when CONFIG_HIGHMEM is not set.
55+
*/
56+
#ifdef CONFIG_HIGHMEM
57+
extern void *kmap(struct page *page);
58+
extern void kunmap(struct page *page);
59+
extern void *kmap_atomic(struct page *page);
60+
extern void __kunmap_atomic(void *kvaddr);
61+
extern void *kmap_atomic_pfn(unsigned long pfn);
62+
extern struct page *kmap_atomic_to_page(void *ptr);
63+
#endif
64+
65+
#endif

‎arch/nds32/include/asm/memory.h‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2005-2017 Andes Technology Corporation
3+
4+
#ifndef __ASM_NDS32_MEMORY_H
5+
#define __ASM_NDS32_MEMORY_H
6+
7+
#include <linux/compiler.h>
8+
#include <linux/sizes.h>
9+
10+
#ifndef __ASSEMBLY__
11+
#include <asm/page.h>
12+
#endif
13+
14+
#ifndef PHYS_OFFSET
15+
#define PHYS_OFFSET (0x0)
16+
#endif
17+
18+
#ifndef __virt_to_bus
19+
#define __virt_to_bus __virt_to_phys
20+
#endif
21+
22+
#ifndef __bus_to_virt
23+
#define __bus_to_virt __phys_to_virt
24+
#endif
25+
26+
/*
27+
* TASK_SIZE - the maximum size of a user space task.
28+
* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
29+
*/
30+
#define TASK_SIZE ((CONFIG_PAGE_OFFSET) - (SZ_32M))
31+
#define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_32M)
32+
#define PAGE_OFFSET (CONFIG_PAGE_OFFSET)
33+
34+
/*
35+
* Physical vs virtual RAM address space conversion. These are
36+
* private definitions which should NOT be used outside memory.h
37+
* files. Use virt_to_phys/phys_to_virt/__pa/__va instead.
38+
*/
39+
#ifndef __virt_to_phys
40+
#define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET)
41+
#define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET)
42+
#endif
43+
44+
/*
45+
* The module space lives between the addresses given by TASK_SIZE
46+
* and PAGE_OFFSET - it must be within 32MB of the kernel text.
47+
*/
48+
#define MODULES_END (PAGE_OFFSET)
49+
#define MODULES_VADDR (MODULES_END - SZ_32M)
50+
51+
#if TASK_SIZE > MODULES_VADDR
52+
#error Top of user space clashes with start of module space
53+
#endif
54+
55+
#ifndef __ASSEMBLY__
56+
57+
/*
58+
* PFNs are used to describe any physical page; this means
59+
* PFN 0 == physical address 0.
60+
*
61+
* This is the PFN of the first RAM page in the kernel
62+
* direct-mapped view. We assume this is the first page
63+
* of RAM in the mem_map as well.
64+
*/
65+
#define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
66+
67+
/*
68+
* Drivers should NOT use these either.
69+
*/
70+
#define __pa(x) __virt_to_phys((unsigned long)(x))
71+
#define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
72+
73+
/*
74+
* Conversion between a struct page and a physical address.
75+
*
76+
* Note: when converting an unknown physical address to a
77+
* struct page, the resulting pointer must be validated
78+
* using VALID_PAGE(). It must return an invalid struct page
79+
* for any physical address not corresponding to a system
80+
* RAM address.
81+
*
82+
* pfn_valid(pfn) indicates whether a PFN number is valid
83+
*
84+
* virt_to_page(k) convert a _valid_ virtual address to struct page *
85+
* virt_addr_valid(k) indicates whether a virtual address is valid
86+
*/
87+
#ifndef CONFIG_DISCONTIGMEM
88+
89+
#define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
90+
#define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
91+
92+
#define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
93+
#define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
94+
95+
#else /* CONFIG_DISCONTIGMEM */
96+
#error CONFIG_DISCONTIGMEM is not supported yet.
97+
#endif /* !CONFIG_DISCONTIGMEM */
98+
99+
#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
100+
101+
#endif
102+
103+
#include <asm-generic/memory_model.h>
104+
105+
#endif

‎arch/nds32/include/asm/mmu.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2005-2017 Andes Technology Corporation
3+
4+
#ifndef __NDS32_MMU_H
5+
#define __NDS32_MMU_H
6+
7+
typedef struct {
8+
unsigned int id;
9+
void *vdso;
10+
} mm_context_t;
11+
12+
#endif

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-2.0
3+
* Copyright (C) 2005-2017 Andes Technology Corporation
4+
*/
5+
6+
#ifndef _ASMNDS32_PAGE_H
7+
#define _ASMNDS32_PAGE_H
8+
9+
#ifdef CONFIG_ANDES_PAGE_SIZE_4KB
10+
#define PAGE_SHIFT 12
11+
#endif
12+
#ifdef CONFIG_ANDES_PAGE_SIZE_8KB
13+
#define PAGE_SHIFT 13
14+
#endif
15+
#include <linux/const.h>
16+
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
17+
#define PAGE_MASK (~(PAGE_SIZE-1))
18+
19+
#ifdef __KERNEL__
20+
21+
#ifndef __ASSEMBLY__
22+
23+
struct page;
24+
struct vm_area_struct;
25+
#ifdef CONFIG_CPU_CACHE_ALIASING
26+
extern void copy_user_highpage(struct page *to, struct page *from,
27+
unsigned long vaddr, struct vm_area_struct *vma);
28+
extern void clear_user_highpage(struct page *page, unsigned long vaddr);
29+
30+
#define __HAVE_ARCH_COPY_USER_HIGHPAGE
31+
#define clear_user_highpage clear_user_highpage
32+
#else
33+
#define clear_user_page(page, vaddr, pg) clear_page(page)
34+
#define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
35+
#endif
36+
37+
void clear_page(void *page);
38+
void copy_page(void *to, void *from);
39+
40+
typedef unsigned long pte_t;
41+
typedef unsigned long pmd_t;
42+
typedef unsigned long pgd_t;
43+
typedef unsigned long pgprot_t;
44+
45+
#define pte_val(x) (x)
46+
#define pmd_val(x) (x)
47+
#define pgd_val(x) (x)
48+
#define pgprot_val(x) (x)
49+
50+
#define __pte(x) (x)
51+
#define __pmd(x) (x)
52+
#define __pgd(x) (x)
53+
#define __pgprot(x) (x)
54+
55+
typedef struct page *pgtable_t;
56+
57+
#include <asm/memory.h>
58+
#include <asm-generic/getorder.h>
59+
60+
#endif /* !__ASSEMBLY__ */
61+
62+
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
63+
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
64+
65+
#endif /* __KERNEL__ */
66+
67+
#endif

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (C) 2005-2017 Andes Technology Corporation
3+
4+
#ifndef _ASMNDS32_PGALLOC_H
5+
#define _ASMNDS32_PGALLOC_H
6+
7+
#include <asm/processor.h>
8+
#include <asm/cacheflush.h>
9+
#include <asm/tlbflush.h>
10+
#include <asm/proc-fns.h>
11+
12+
/*
13+
* Since we have only two-level page tables, these are trivial
14+
*/
15+
#define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
16+
#define pmd_free(mm, pmd) do { } while (0)
17+
#define pgd_populate(mm, pmd, pte) BUG()
18+
#define pmd_pgtable(pmd) pmd_page(pmd)
19+
20+
extern pgd_t *pgd_alloc(struct mm_struct *mm);
21+
extern void pgd_free(struct mm_struct *mm, pgd_t * pgd);
22+
23+
#define check_pgt_cache() do { } while (0)
24+
25+
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
26+
unsigned long addr)
27+
{
28+
pte_t *pte;
29+
30+
pte =
31+
(pte_t *) __get_free_page(GFP_KERNEL | __GFP_RETRY_MAYFAIL |
32+
__GFP_ZERO);
33+
34+
return pte;
35+
}
36+
37+
static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr)
38+
{
39+
pgtable_t pte;
40+
41+
pte = alloc_pages(GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_ZERO, 0);
42+
if (pte)
43+
cpu_dcache_wb_page((unsigned long)page_address(pte));
44+
45+
return pte;
46+
}
47+
48+
/*
49+
* Free one PTE table.
50+
*/
51+
static inline void pte_free_kernel(struct mm_struct *mm, pte_t * pte)
52+
{
53+
if (pte) {
54+
free_page((unsigned long)pte);
55+
}
56+
}
57+
58+
static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
59+
{
60+
__free_page(pte);
61+
}
62+
63+
/*
64+
* Populate the pmdp entry with a pointer to the pte. This pmd is part
65+
* of the mm address space.
66+
*
67+
* Ensure that we always set both PMD entries.
68+
*/
69+
static inline void
70+
pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmdp, pte_t * ptep)
71+
{
72+
unsigned long pte_ptr = (unsigned long)ptep;
73+
unsigned long pmdval;
74+
75+
BUG_ON(mm != &init_mm);
76+
77+
/*
78+
* The pmd must be loaded with the physical
79+
* address of the PTE table
80+
*/
81+
pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE;
82+
set_pmd(pmdp, __pmd(pmdval));
83+
}
84+
85+
static inline void
86+
pmd_populate(struct mm_struct *mm, pmd_t * pmdp, pgtable_t ptep)
87+
{
88+
unsigned long pmdval;
89+
90+
BUG_ON(mm == &init_mm);
91+
92+
pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE;
93+
set_pmd(pmdp, __pmd(pmdval));
94+
}
95+
96+
#endif

0 commit comments

Comments
 (0)