diff options
author | Jonas Bonn <jonas@southpole.se> | 2011-06-04 04:06:11 -0400 |
---|---|---|
committer | Jonas Bonn <jonas@southpole.se> | 2011-07-22 12:46:28 -0400 |
commit | 61e85e367535a7b6385b404bef93928768140f96 (patch) | |
tree | a0b8cb40dff683d3d09268f55080b5539d25b9a5 /arch/openrisc/include/asm | |
parent | 4f246ba30e1a9a31fcfd91d2ab8f5c75f1362bbf (diff) |
OpenRISC: Memory management
Signed-off-by: Jonas Bonn <jonas@southpole.se>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/openrisc/include/asm')
-rw-r--r-- | arch/openrisc/include/asm/cache.h | 29 | ||||
-rw-r--r-- | arch/openrisc/include/asm/fixmap.h | 87 | ||||
-rw-r--r-- | arch/openrisc/include/asm/memblock.h | 24 | ||||
-rw-r--r-- | arch/openrisc/include/asm/mmu.h | 26 | ||||
-rw-r--r-- | arch/openrisc/include/asm/mmu_context.h | 43 | ||||
-rw-r--r-- | arch/openrisc/include/asm/page.h | 110 | ||||
-rw-r--r-- | arch/openrisc/include/asm/pgalloc.h | 102 | ||||
-rw-r--r-- | arch/openrisc/include/asm/pgtable.h | 463 | ||||
-rw-r--r-- | arch/openrisc/include/asm/tlb.h | 34 | ||||
-rw-r--r-- | arch/openrisc/include/asm/tlbflush.h | 55 | ||||
-rw-r--r-- | arch/openrisc/include/asm/uaccess.h | 355 |
11 files changed, 1328 insertions, 0 deletions
diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h new file mode 100644 index 000000000000..4ce7a01a252d --- /dev/null +++ b/arch/openrisc/include/asm/cache.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_CACHE_H | ||
20 | #define __ASM_OPENRISC_CACHE_H | ||
21 | |||
22 | /* FIXME: How can we replace these with values from the CPU... | ||
23 | * they shouldn't be hard-coded! | ||
24 | */ | ||
25 | |||
26 | #define L1_CACHE_BYTES 16 | ||
27 | #define L1_CACHE_SHIFT 4 | ||
28 | |||
29 | #endif /* __ASM_OPENRISC_CACHE_H */ | ||
diff --git a/arch/openrisc/include/asm/fixmap.h b/arch/openrisc/include/asm/fixmap.h new file mode 100644 index 000000000000..52733416c1f3 --- /dev/null +++ b/arch/openrisc/include/asm/fixmap.h | |||
@@ -0,0 +1,87 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_FIXMAP_H | ||
20 | #define __ASM_OPENRISC_FIXMAP_H | ||
21 | |||
22 | /* Why exactly do we need 2 empty pages between the top of the fixed | ||
23 | * addresses and the top of virtual memory? Something is using that | ||
24 | * memory space but not sure what right now... If you find it, leave | ||
25 | * a comment here. | ||
26 | */ | ||
27 | #define FIXADDR_TOP ((unsigned long) (-2*PAGE_SIZE)) | ||
28 | |||
29 | #include <linux/kernel.h> | ||
30 | #include <asm/page.h> | ||
31 | |||
32 | /* | ||
33 | * On OpenRISC we use these special fixed_addresses for doing ioremap | ||
34 | * early in the boot process before memory initialization is complete. | ||
35 | * This is used, in particular, by the early serial console code. | ||
36 | * | ||
37 | * It's not really 'fixmap', per se, but fits loosely into the same | ||
38 | * paradigm. | ||
39 | */ | ||
40 | enum fixed_addresses { | ||
41 | /* | ||
42 | * FIX_IOREMAP entries are useful for mapping physical address | ||
43 | * space before ioremap() is useable, e.g. really early in boot | ||
44 | * before kmalloc() is working. | ||
45 | */ | ||
46 | #define FIX_N_IOREMAPS 32 | ||
47 | FIX_IOREMAP_BEGIN, | ||
48 | FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1, | ||
49 | __end_of_fixed_addresses | ||
50 | }; | ||
51 | |||
52 | #define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) | ||
53 | /* FIXADDR_BOTTOM might be a better name here... */ | ||
54 | #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) | ||
55 | |||
56 | #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT)) | ||
57 | #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) | ||
58 | |||
59 | /* | ||
60 | * 'index to address' translation. If anyone tries to use the idx | ||
61 | * directly without tranlation, we catch the bug with a NULL-deference | ||
62 | * kernel oops. Illegal ranges of incoming indices are caught too. | ||
63 | */ | ||
64 | static __always_inline unsigned long fix_to_virt(const unsigned int idx) | ||
65 | { | ||
66 | /* | ||
67 | * this branch gets completely eliminated after inlining, | ||
68 | * except when someone tries to use fixaddr indices in an | ||
69 | * illegal way. (such as mixing up address types or using | ||
70 | * out-of-range indices). | ||
71 | * | ||
72 | * If it doesn't get removed, the linker will complain | ||
73 | * loudly with a reasonably clear error message.. | ||
74 | */ | ||
75 | if (idx >= __end_of_fixed_addresses) | ||
76 | BUG(); | ||
77 | |||
78 | return __fix_to_virt(idx); | ||
79 | } | ||
80 | |||
81 | static inline unsigned long virt_to_fix(const unsigned long vaddr) | ||
82 | { | ||
83 | BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); | ||
84 | return __virt_to_fix(vaddr); | ||
85 | } | ||
86 | |||
87 | #endif | ||
diff --git a/arch/openrisc/include/asm/memblock.h b/arch/openrisc/include/asm/memblock.h new file mode 100644 index 000000000000..bbe5a1c788cb --- /dev/null +++ b/arch/openrisc/include/asm/memblock.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_MEMBLOCK_H | ||
20 | #define __ASM_OPENRISC_MEMBLOCK_H | ||
21 | |||
22 | /* empty */ | ||
23 | |||
24 | #endif /* __ASM_OPENRISC_MEMBLOCK_H */ | ||
diff --git a/arch/openrisc/include/asm/mmu.h b/arch/openrisc/include/asm/mmu.h new file mode 100644 index 000000000000..d069bc2ddfa4 --- /dev/null +++ b/arch/openrisc/include/asm/mmu.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_MMU_H | ||
20 | #define __ASM_OPENRISC_MMU_H | ||
21 | |||
22 | #ifndef __ASSEMBLY__ | ||
23 | typedef unsigned long mm_context_t; | ||
24 | #endif | ||
25 | |||
26 | #endif | ||
diff --git a/arch/openrisc/include/asm/mmu_context.h b/arch/openrisc/include/asm/mmu_context.h new file mode 100644 index 000000000000..e94b814d2e3c --- /dev/null +++ b/arch/openrisc/include/asm/mmu_context.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_MMU_CONTEXT_H | ||
20 | #define __ASM_OPENRISC_MMU_CONTEXT_H | ||
21 | |||
22 | #include <asm-generic/mm_hooks.h> | ||
23 | |||
24 | extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm); | ||
25 | extern void destroy_context(struct mm_struct *mm); | ||
26 | extern void switch_mm(struct mm_struct *prev, struct mm_struct *next, | ||
27 | struct task_struct *tsk); | ||
28 | |||
29 | #define deactivate_mm(tsk, mm) do { } while (0) | ||
30 | |||
31 | #define activate_mm(prev, next) switch_mm((prev), (next), NULL) | ||
32 | |||
33 | /* current active pgd - this is similar to other processors pgd | ||
34 | * registers like cr3 on the i386 | ||
35 | */ | ||
36 | |||
37 | extern volatile pgd_t *current_pgd; /* defined in arch/openrisc/mm/fault.c */ | ||
38 | |||
39 | static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | #endif | ||
diff --git a/arch/openrisc/include/asm/page.h b/arch/openrisc/include/asm/page.h new file mode 100644 index 000000000000..b041b344b229 --- /dev/null +++ b/arch/openrisc/include/asm/page.h | |||
@@ -0,0 +1,110 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_PAGE_H | ||
20 | #define __ASM_OPENRISC_PAGE_H | ||
21 | |||
22 | |||
23 | /* PAGE_SHIFT determines the page size */ | ||
24 | |||
25 | #define PAGE_SHIFT 13 | ||
26 | #ifdef __ASSEMBLY__ | ||
27 | #define PAGE_SIZE (1 << PAGE_SHIFT) | ||
28 | #else | ||
29 | #define PAGE_SIZE (1UL << PAGE_SHIFT) | ||
30 | #endif | ||
31 | #define PAGE_MASK (~(PAGE_SIZE-1)) | ||
32 | |||
33 | #define PAGE_OFFSET 0xc0000000 | ||
34 | #define KERNELBASE PAGE_OFFSET | ||
35 | |||
36 | /* This is not necessarily the right place for this, but it's needed by | ||
37 | * drivers/of/fdt.c | ||
38 | */ | ||
39 | #include <asm/setup.h> | ||
40 | |||
41 | #ifndef __ASSEMBLY__ | ||
42 | |||
43 | #define get_user_page(vaddr) __get_free_page(GFP_KERNEL) | ||
44 | #define free_user_page(page, addr) free_page(addr) | ||
45 | |||
46 | #define clear_page(page) memset((page), 0, PAGE_SIZE) | ||
47 | #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) | ||
48 | |||
49 | #define clear_user_page(page, vaddr, pg) clear_page(page) | ||
50 | #define copy_user_page(to, from, vaddr, pg) copy_page(to, from) | ||
51 | |||
52 | /* | ||
53 | * These are used to make use of C type-checking.. | ||
54 | */ | ||
55 | typedef struct { | ||
56 | unsigned long pte; | ||
57 | } pte_t; | ||
58 | typedef struct { | ||
59 | unsigned long pgd; | ||
60 | } pgd_t; | ||
61 | typedef struct { | ||
62 | unsigned long pgprot; | ||
63 | } pgprot_t; | ||
64 | typedef struct page *pgtable_t; | ||
65 | |||
66 | #define pte_val(x) ((x).pte) | ||
67 | #define pgd_val(x) ((x).pgd) | ||
68 | #define pgprot_val(x) ((x).pgprot) | ||
69 | |||
70 | #define __pte(x) ((pte_t) { (x) }) | ||
71 | #define __pgd(x) ((pgd_t) { (x) }) | ||
72 | #define __pgprot(x) ((pgprot_t) { (x) }) | ||
73 | |||
74 | extern unsigned long memory_start; | ||
75 | extern unsigned long memory_end; | ||
76 | |||
77 | #endif /* !__ASSEMBLY__ */ | ||
78 | |||
79 | |||
80 | #ifndef __ASSEMBLY__ | ||
81 | |||
82 | #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET)) | ||
83 | #define __pa(x) ((unsigned long) (x) - PAGE_OFFSET) | ||
84 | |||
85 | #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) | ||
86 | #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) | ||
87 | |||
88 | #define virt_to_page(addr) \ | ||
89 | (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT)) | ||
90 | #define page_to_virt(page) \ | ||
91 | ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET) | ||
92 | |||
93 | #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT) | ||
94 | |||
95 | #define pfn_valid(pfn) ((pfn) < max_mapnr) | ||
96 | |||
97 | #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \ | ||
98 | ((void *)(kaddr) < (void *)memory_end)) | ||
99 | |||
100 | #endif /* __ASSEMBLY__ */ | ||
101 | |||
102 | |||
103 | #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ | ||
104 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | ||
105 | |||
106 | |||
107 | #include <asm-generic/memory_model.h> | ||
108 | #include <asm-generic/getorder.h> | ||
109 | |||
110 | #endif /* __ASM_OPENRISC_PAGE_H */ | ||
diff --git a/arch/openrisc/include/asm/pgalloc.h b/arch/openrisc/include/asm/pgalloc.h new file mode 100644 index 000000000000..05c39ecd2efd --- /dev/null +++ b/arch/openrisc/include/asm/pgalloc.h | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_PGALLOC_H | ||
20 | #define __ASM_OPENRISC_PGALLOC_H | ||
21 | |||
22 | #include <asm/page.h> | ||
23 | #include <linux/threads.h> | ||
24 | #include <linux/mm.h> | ||
25 | #include <linux/memblock.h> | ||
26 | #include <linux/bootmem.h> | ||
27 | |||
28 | extern int mem_init_done; | ||
29 | |||
30 | #define pmd_populate_kernel(mm, pmd, pte) \ | ||
31 | set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte))) | ||
32 | |||
33 | static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, | ||
34 | struct page *pte) | ||
35 | { | ||
36 | set_pmd(pmd, __pmd(_KERNPG_TABLE + | ||
37 | ((unsigned long)page_to_pfn(pte) << | ||
38 | (unsigned long) PAGE_SHIFT))); | ||
39 | } | ||
40 | |||
41 | /* | ||
42 | * Allocate and free page tables. | ||
43 | */ | ||
44 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) | ||
45 | { | ||
46 | pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL); | ||
47 | |||
48 | if (ret) { | ||
49 | memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); | ||
50 | memcpy(ret + USER_PTRS_PER_PGD, | ||
51 | swapper_pg_dir + USER_PTRS_PER_PGD, | ||
52 | (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); | ||
53 | |||
54 | } | ||
55 | return ret; | ||
56 | } | ||
57 | |||
58 | #if 0 | ||
59 | /* FIXME: This seems to be the preferred style, but we are using | ||
60 | * current_pgd (from mm->pgd) to load kernel pages so we need it | ||
61 | * initialized. This needs to be looked into. | ||
62 | */ | ||
63 | extern inline pgd_t *pgd_alloc(struct mm_struct *mm) | ||
64 | { | ||
65 | return (pgd_t *)get_zeroed_page(GFP_KERNEL); | ||
66 | } | ||
67 | #endif | ||
68 | |||
69 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) | ||
70 | { | ||
71 | free_page((unsigned long)pgd); | ||
72 | } | ||
73 | |||
74 | extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address); | ||
75 | |||
76 | static inline struct page *pte_alloc_one(struct mm_struct *mm, | ||
77 | unsigned long address) | ||
78 | { | ||
79 | struct page *pte; | ||
80 | pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0); | ||
81 | if (pte) | ||
82 | clear_page(page_address(pte)); | ||
83 | return pte; | ||
84 | } | ||
85 | |||
86 | static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) | ||
87 | { | ||
88 | free_page((unsigned long)pte); | ||
89 | } | ||
90 | |||
91 | static inline void pte_free(struct mm_struct *mm, struct page *pte) | ||
92 | { | ||
93 | __free_page(pte); | ||
94 | } | ||
95 | |||
96 | |||
97 | #define __pte_free_tlb(tlb, pte, addr) tlb_remove_page((tlb), (pte)) | ||
98 | #define pmd_pgtable(pmd) pmd_page(pmd) | ||
99 | |||
100 | #define check_pgt_cache() do { } while (0) | ||
101 | |||
102 | #endif | ||
diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h new file mode 100644 index 000000000000..043505d7f684 --- /dev/null +++ b/arch/openrisc/include/asm/pgtable.h | |||
@@ -0,0 +1,463 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | /* or32 pgtable.h - macros and functions to manipulate page tables | ||
20 | * | ||
21 | * Based on: | ||
22 | * include/asm-cris/pgtable.h | ||
23 | */ | ||
24 | |||
25 | #ifndef __ASM_OPENRISC_PGTABLE_H | ||
26 | #define __ASM_OPENRISC_PGTABLE_H | ||
27 | |||
28 | #include <asm-generic/pgtable-nopmd.h> | ||
29 | |||
30 | #ifndef __ASSEMBLY__ | ||
31 | #include <asm/mmu.h> | ||
32 | #include <asm/fixmap.h> | ||
33 | |||
34 | /* | ||
35 | * The Linux memory management assumes a three-level page table setup. On | ||
36 | * or32, we use that, but "fold" the mid level into the top-level page | ||
37 | * table. Since the MMU TLB is software loaded through an interrupt, it | ||
38 | * supports any page table structure, so we could have used a three-level | ||
39 | * setup, but for the amounts of memory we normally use, a two-level is | ||
40 | * probably more efficient. | ||
41 | * | ||
42 | * This file contains the functions and defines necessary to modify and use | ||
43 | * the or32 page table tree. | ||
44 | */ | ||
45 | |||
46 | extern void paging_init(void); | ||
47 | |||
48 | /* Certain architectures need to do special things when pte's | ||
49 | * within a page table are directly modified. Thus, the following | ||
50 | * hook is made available. | ||
51 | */ | ||
52 | #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval)) | ||
53 | #define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval) | ||
54 | /* | ||
55 | * (pmds are folded into pgds so this doesn't get actually called, | ||
56 | * but the define is needed for a generic inline function.) | ||
57 | */ | ||
58 | #define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval) | ||
59 | |||
60 | #define PGDIR_SHIFT (PAGE_SHIFT + (PAGE_SHIFT-2)) | ||
61 | #define PGDIR_SIZE (1UL << PGDIR_SHIFT) | ||
62 | #define PGDIR_MASK (~(PGDIR_SIZE-1)) | ||
63 | |||
64 | /* | ||
65 | * entries per page directory level: we use a two-level, so | ||
66 | * we don't really have any PMD directory physically. | ||
67 | * pointers are 4 bytes so we can use the page size and | ||
68 | * divide it by 4 (shift by 2). | ||
69 | */ | ||
70 | #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-2)) | ||
71 | |||
72 | #define PTRS_PER_PGD (1UL << (PAGE_SHIFT-2)) | ||
73 | |||
74 | /* calculate how many PGD entries a user-level program can use | ||
75 | * the first mappable virtual address is 0 | ||
76 | * (TASK_SIZE is the maximum virtual address space) | ||
77 | */ | ||
78 | |||
79 | #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE) | ||
80 | #define FIRST_USER_ADDRESS 0 | ||
81 | |||
82 | /* | ||
83 | * Kernels own virtual memory area. | ||
84 | */ | ||
85 | |||
86 | /* | ||
87 | * The size and location of the vmalloc area are chosen so that modules | ||
88 | * placed in this area aren't more than a 28-bit signed offset from any | ||
89 | * kernel functions that they may need. This greatly simplifies handling | ||
90 | * of the relocations for l.j and l.jal instructions as we don't need to | ||
91 | * introduce any trampolines for reaching "distant" code. | ||
92 | * | ||
93 | * 64 MB of vmalloc area is comparable to what's available on other arches. | ||
94 | */ | ||
95 | |||
96 | #define VMALLOC_START (PAGE_OFFSET-0x04000000) | ||
97 | #define VMALLOC_END (PAGE_OFFSET) | ||
98 | #define VMALLOC_VMADDR(x) ((unsigned long)(x)) | ||
99 | |||
100 | /* Define some higher level generic page attributes. | ||
101 | * | ||
102 | * If you change _PAGE_CI definition be sure to change it in | ||
103 | * io.h for ioremap_nocache() too. | ||
104 | */ | ||
105 | |||
106 | /* | ||
107 | * An OR32 PTE looks like this: | ||
108 | * | ||
109 | * | 31 ... 10 | 9 | 8 ... 6 | 5 | 4 | 3 | 2 | 1 | 0 | | ||
110 | * Phys pg.num L PP Index D A WOM WBC CI CC | ||
111 | * | ||
112 | * L : link | ||
113 | * PPI: Page protection index | ||
114 | * D : Dirty | ||
115 | * A : Accessed | ||
116 | * WOM: Weakly ordered memory | ||
117 | * WBC: Write-back cache | ||
118 | * CI : Cache inhibit | ||
119 | * CC : Cache coherent | ||
120 | * | ||
121 | * The protection bits below should correspond to the layout of the actual | ||
122 | * PTE as per above | ||
123 | */ | ||
124 | |||
125 | #define _PAGE_CC 0x001 /* software: pte contains a translation */ | ||
126 | #define _PAGE_CI 0x002 /* cache inhibit */ | ||
127 | #define _PAGE_WBC 0x004 /* write back cache */ | ||
128 | #define _PAGE_FILE 0x004 /* set: pagecache, unset: swap (when !PRESENT) */ | ||
129 | #define _PAGE_WOM 0x008 /* weakly ordered memory */ | ||
130 | |||
131 | #define _PAGE_A 0x010 /* accessed */ | ||
132 | #define _PAGE_D 0x020 /* dirty */ | ||
133 | #define _PAGE_URE 0x040 /* user read enable */ | ||
134 | #define _PAGE_UWE 0x080 /* user write enable */ | ||
135 | |||
136 | #define _PAGE_SRE 0x100 /* superuser read enable */ | ||
137 | #define _PAGE_SWE 0x200 /* superuser write enable */ | ||
138 | #define _PAGE_EXEC 0x400 /* software: page is executable */ | ||
139 | #define _PAGE_U_SHARED 0x800 /* software: page is shared in user space */ | ||
140 | |||
141 | /* 0x001 is cache coherency bit, which should always be set to | ||
142 | * 1 - for SMP (when we support it) | ||
143 | * 0 - otherwise | ||
144 | * | ||
145 | * we just reuse this bit in software for _PAGE_PRESENT and | ||
146 | * force it to 0 when loading it into TLB. | ||
147 | */ | ||
148 | #define _PAGE_PRESENT _PAGE_CC | ||
149 | #define _PAGE_USER _PAGE_URE | ||
150 | #define _PAGE_WRITE (_PAGE_UWE | _PAGE_SWE) | ||
151 | #define _PAGE_DIRTY _PAGE_D | ||
152 | #define _PAGE_ACCESSED _PAGE_A | ||
153 | #define _PAGE_NO_CACHE _PAGE_CI | ||
154 | #define _PAGE_SHARED _PAGE_U_SHARED | ||
155 | #define _PAGE_READ (_PAGE_URE | _PAGE_SRE) | ||
156 | |||
157 | #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) | ||
158 | #define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED) | ||
159 | #define _PAGE_ALL (_PAGE_PRESENT | _PAGE_ACCESSED) | ||
160 | #define _KERNPG_TABLE \ | ||
161 | (_PAGE_BASE | _PAGE_SRE | _PAGE_SWE | _PAGE_ACCESSED | _PAGE_DIRTY) | ||
162 | |||
163 | #define PAGE_NONE __pgprot(_PAGE_ALL) | ||
164 | #define PAGE_READONLY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE) | ||
165 | #define PAGE_READONLY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC) | ||
166 | #define PAGE_SHARED \ | ||
167 | __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE \ | ||
168 | | _PAGE_SHARED) | ||
169 | #define PAGE_SHARED_X \ | ||
170 | __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE \ | ||
171 | | _PAGE_SHARED | _PAGE_EXEC) | ||
172 | #define PAGE_COPY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE) | ||
173 | #define PAGE_COPY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC) | ||
174 | |||
175 | #define PAGE_KERNEL \ | ||
176 | __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \ | ||
177 | | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC) | ||
178 | #define PAGE_KERNEL_RO \ | ||
179 | __pgprot(_PAGE_ALL | _PAGE_SRE \ | ||
180 | | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC) | ||
181 | #define PAGE_KERNEL_NOCACHE \ | ||
182 | __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE \ | ||
183 | | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC | _PAGE_CI) | ||
184 | |||
185 | #define __P000 PAGE_NONE | ||
186 | #define __P001 PAGE_READONLY_X | ||
187 | #define __P010 PAGE_COPY | ||
188 | #define __P011 PAGE_COPY_X | ||
189 | #define __P100 PAGE_READONLY | ||
190 | #define __P101 PAGE_READONLY_X | ||
191 | #define __P110 PAGE_COPY | ||
192 | #define __P111 PAGE_COPY_X | ||
193 | |||
194 | #define __S000 PAGE_NONE | ||
195 | #define __S001 PAGE_READONLY_X | ||
196 | #define __S010 PAGE_SHARED | ||
197 | #define __S011 PAGE_SHARED_X | ||
198 | #define __S100 PAGE_READONLY | ||
199 | #define __S101 PAGE_READONLY_X | ||
200 | #define __S110 PAGE_SHARED | ||
201 | #define __S111 PAGE_SHARED_X | ||
202 | |||
203 | /* zero page used for uninitialized stuff */ | ||
204 | extern unsigned long empty_zero_page[2048]; | ||
205 | #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) | ||
206 | |||
207 | /* number of bits that fit into a memory pointer */ | ||
208 | #define BITS_PER_PTR (8*sizeof(unsigned long)) | ||
209 | |||
210 | /* to align the pointer to a pointer address */ | ||
211 | #define PTR_MASK (~(sizeof(void *)-1)) | ||
212 | |||
213 | /* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */ | ||
214 | /* 64-bit machines, beware! SRB. */ | ||
215 | #define SIZEOF_PTR_LOG2 2 | ||
216 | |||
217 | /* to find an entry in a page-table */ | ||
218 | #define PAGE_PTR(address) \ | ||
219 | ((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK) | ||
220 | |||
221 | /* to set the page-dir */ | ||
222 | #define SET_PAGE_DIR(tsk, pgdir) | ||
223 | |||
224 | #define pte_none(x) (!pte_val(x)) | ||
225 | #define pte_present(x) (pte_val(x) & _PAGE_PRESENT) | ||
226 | #define pte_clear(mm, addr, xp) do { pte_val(*(xp)) = 0; } while (0) | ||
227 | |||
228 | #define pmd_none(x) (!pmd_val(x)) | ||
229 | #define pmd_bad(x) ((pmd_val(x) & (~PAGE_MASK)) != _KERNPG_TABLE) | ||
230 | #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT) | ||
231 | #define pmd_clear(xp) do { pmd_val(*(xp)) = 0; } while (0) | ||
232 | |||
233 | /* | ||
234 | * The following only work if pte_present() is true. | ||
235 | * Undefined behaviour if not.. | ||
236 | */ | ||
237 | |||
238 | static inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_READ; } | ||
239 | static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITE; } | ||
240 | static inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; } | ||
241 | static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } | ||
242 | static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } | ||
243 | static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } | ||
244 | static inline int pte_special(pte_t pte) { return 0; } | ||
245 | static inline pte_t pte_mkspecial(pte_t pte) { return pte; } | ||
246 | |||
247 | static inline pte_t pte_wrprotect(pte_t pte) | ||
248 | { | ||
249 | pte_val(pte) &= ~(_PAGE_WRITE); | ||
250 | return pte; | ||
251 | } | ||
252 | |||
253 | static inline pte_t pte_rdprotect(pte_t pte) | ||
254 | { | ||
255 | pte_val(pte) &= ~(_PAGE_READ); | ||
256 | return pte; | ||
257 | } | ||
258 | |||
259 | static inline pte_t pte_exprotect(pte_t pte) | ||
260 | { | ||
261 | pte_val(pte) &= ~(_PAGE_EXEC); | ||
262 | return pte; | ||
263 | } | ||
264 | |||
265 | static inline pte_t pte_mkclean(pte_t pte) | ||
266 | { | ||
267 | pte_val(pte) &= ~(_PAGE_DIRTY); | ||
268 | return pte; | ||
269 | } | ||
270 | |||
271 | static inline pte_t pte_mkold(pte_t pte) | ||
272 | { | ||
273 | pte_val(pte) &= ~(_PAGE_ACCESSED); | ||
274 | return pte; | ||
275 | } | ||
276 | |||
277 | static inline pte_t pte_mkwrite(pte_t pte) | ||
278 | { | ||
279 | pte_val(pte) |= _PAGE_WRITE; | ||
280 | return pte; | ||
281 | } | ||
282 | |||
283 | static inline pte_t pte_mkread(pte_t pte) | ||
284 | { | ||
285 | pte_val(pte) |= _PAGE_READ; | ||
286 | return pte; | ||
287 | } | ||
288 | |||
289 | static inline pte_t pte_mkexec(pte_t pte) | ||
290 | { | ||
291 | pte_val(pte) |= _PAGE_EXEC; | ||
292 | return pte; | ||
293 | } | ||
294 | |||
295 | static inline pte_t pte_mkdirty(pte_t pte) | ||
296 | { | ||
297 | pte_val(pte) |= _PAGE_DIRTY; | ||
298 | return pte; | ||
299 | } | ||
300 | |||
301 | static inline pte_t pte_mkyoung(pte_t pte) | ||
302 | { | ||
303 | pte_val(pte) |= _PAGE_ACCESSED; | ||
304 | return pte; | ||
305 | } | ||
306 | |||
307 | /* | ||
308 | * Conversion functions: convert a page and protection to a page entry, | ||
309 | * and a page entry and page directory to the page they refer to. | ||
310 | */ | ||
311 | |||
312 | /* What actually goes as arguments to the various functions is less than | ||
313 | * obvious, but a rule of thumb is that struct page's goes as struct page *, | ||
314 | * really physical DRAM addresses are unsigned long's, and DRAM "virtual" | ||
315 | * addresses (the 0xc0xxxxxx's) goes as void *'s. | ||
316 | */ | ||
317 | |||
318 | static inline pte_t __mk_pte(void *page, pgprot_t pgprot) | ||
319 | { | ||
320 | pte_t pte; | ||
321 | /* the PTE needs a physical address */ | ||
322 | pte_val(pte) = __pa(page) | pgprot_val(pgprot); | ||
323 | return pte; | ||
324 | } | ||
325 | |||
326 | #define mk_pte(page, pgprot) __mk_pte(page_address(page), (pgprot)) | ||
327 | |||
328 | #define mk_pte_phys(physpage, pgprot) \ | ||
329 | ({ \ | ||
330 | pte_t __pte; \ | ||
331 | \ | ||
332 | pte_val(__pte) = (physpage) + pgprot_val(pgprot); \ | ||
333 | __pte; \ | ||
334 | }) | ||
335 | |||
336 | static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) | ||
337 | { | ||
338 | pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); | ||
339 | return pte; | ||
340 | } | ||
341 | |||
342 | |||
343 | /* | ||
344 | * pte_val refers to a page in the 0x0xxxxxxx physical DRAM interval | ||
345 | * __pte_page(pte_val) refers to the "virtual" DRAM interval | ||
346 | * pte_pagenr refers to the page-number counted starting from the virtual | ||
347 | * DRAM start | ||
348 | */ | ||
349 | |||
350 | static inline unsigned long __pte_page(pte_t pte) | ||
351 | { | ||
352 | /* the PTE contains a physical address */ | ||
353 | return (unsigned long)__va(pte_val(pte) & PAGE_MASK); | ||
354 | } | ||
355 | |||
356 | #define pte_pagenr(pte) ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT) | ||
357 | |||
358 | /* permanent address of a page */ | ||
359 | |||
360 | #define __page_address(page) (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT)) | ||
361 | #define pte_page(pte) (mem_map+pte_pagenr(pte)) | ||
362 | |||
363 | /* | ||
364 | * only the pte's themselves need to point to physical DRAM (see above) | ||
365 | * the pagetable links are purely handled within the kernel SW and thus | ||
366 | * don't need the __pa and __va transformations. | ||
367 | */ | ||
368 | static inline void pmd_set(pmd_t *pmdp, pte_t *ptep) | ||
369 | { | ||
370 | pmd_val(*pmdp) = _KERNPG_TABLE | (unsigned long) ptep; | ||
371 | } | ||
372 | |||
373 | #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)) | ||
374 | #define pmd_page_kernel(pmd) ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK)) | ||
375 | |||
376 | /* to find an entry in a page-table-directory. */ | ||
377 | #define pgd_index(address) ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1)) | ||
378 | |||
379 | #define __pgd_offset(address) pgd_index(address) | ||
380 | |||
381 | #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address)) | ||
382 | |||
383 | /* to find an entry in a kernel page-table-directory */ | ||
384 | #define pgd_offset_k(address) pgd_offset(&init_mm, address) | ||
385 | |||
386 | #define __pmd_offset(address) \ | ||
387 | (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) | ||
388 | |||
389 | /* | ||
390 | * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE] | ||
391 | * | ||
392 | * this macro returns the index of the entry in the pte page which would | ||
393 | * control the given virtual address | ||
394 | */ | ||
395 | #define __pte_offset(address) \ | ||
396 | (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) | ||
397 | #define pte_offset_kernel(dir, address) \ | ||
398 | ((pte_t *) pmd_page_kernel(*(dir)) + __pte_offset(address)) | ||
399 | #define pte_offset_map(dir, address) \ | ||
400 | ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address)) | ||
401 | #define pte_offset_map_nested(dir, address) \ | ||
402 | pte_offset_map(dir, address) | ||
403 | |||
404 | #define pte_unmap(pte) do { } while (0) | ||
405 | #define pte_unmap_nested(pte) do { } while (0) | ||
406 | #define pte_pfn(x) ((unsigned long)(((x).pte)) >> PAGE_SHIFT) | ||
407 | #define pfn_pte(pfn, prot) __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(prot)) | ||
408 | |||
409 | #define pte_ERROR(e) \ | ||
410 | printk(KERN_ERR "%s:%d: bad pte %p(%08lx).\n", \ | ||
411 | __FILE__, __LINE__, &(e), pte_val(e)) | ||
412 | #define pgd_ERROR(e) \ | ||
413 | printk(KERN_ERR "%s:%d: bad pgd %p(%08lx).\n", \ | ||
414 | __FILE__, __LINE__, &(e), pgd_val(e)) | ||
415 | |||
416 | extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */ | ||
417 | |||
418 | /* | ||
419 | * or32 doesn't have any external MMU info: the kernel page | ||
420 | * tables contain all the necessary information. | ||
421 | * | ||
422 | * Actually I am not sure on what this could be used for. | ||
423 | */ | ||
424 | static inline void update_mmu_cache(struct vm_area_struct *vma, | ||
425 | unsigned long address, pte_t *pte) | ||
426 | { | ||
427 | } | ||
428 | |||
429 | /* __PHX__ FIXME, SWAP, this probably doesn't work */ | ||
430 | |||
431 | /* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */ | ||
432 | /* Since the PAGE_PRESENT bit is bit 4, we can use the bits above */ | ||
433 | |||
434 | #define __swp_type(x) (((x).val >> 5) & 0x7f) | ||
435 | #define __swp_offset(x) ((x).val >> 12) | ||
436 | #define __swp_entry(type, offset) \ | ||
437 | ((swp_entry_t) { ((type) << 5) | ((offset) << 12) }) | ||
438 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) | ||
439 | #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) | ||
440 | |||
441 | /* Encode and decode a nonlinear file mapping entry */ | ||
442 | |||
443 | #define PTE_FILE_MAX_BITS 26 | ||
444 | #define pte_to_pgoff(x) (pte_val(x) >> 6) | ||
445 | #define pgoff_to_pte(x) __pte(((x) << 6) | _PAGE_FILE) | ||
446 | |||
447 | #define kern_addr_valid(addr) (1) | ||
448 | |||
449 | #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ | ||
450 | remap_pfn_range(vma, vaddr, pfn, size, prot) | ||
451 | |||
452 | #include <asm-generic/pgtable.h> | ||
453 | |||
454 | /* | ||
455 | * No page table caches to initialise | ||
456 | */ | ||
457 | #define pgtable_cache_init() do { } while (0) | ||
458 | #define io_remap_page_range remap_page_range | ||
459 | |||
460 | typedef pte_t *pte_addr_t; | ||
461 | |||
462 | #endif /* __ASSEMBLY__ */ | ||
463 | #endif /* __ASM_OPENRISC_PGTABLE_H */ | ||
diff --git a/arch/openrisc/include/asm/tlb.h b/arch/openrisc/include/asm/tlb.h new file mode 100644 index 000000000000..fa4376a4515d --- /dev/null +++ b/arch/openrisc/include/asm/tlb.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_TLB_H__ | ||
20 | #define __ASM_OPENRISC_TLB_H__ | ||
21 | |||
22 | /* | ||
23 | * or32 doesn't need any special per-pte or | ||
24 | * per-vma handling.. | ||
25 | */ | ||
26 | #define tlb_start_vma(tlb, vma) do { } while (0) | ||
27 | #define tlb_end_vma(tlb, vma) do { } while (0) | ||
28 | #define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0) | ||
29 | |||
30 | #define tlb_flush(tlb) flush_tlb_mm((tlb)->mm) | ||
31 | #include <linux/pagemap.h> | ||
32 | #include <asm-generic/tlb.h> | ||
33 | |||
34 | #endif /* __ASM_OPENRISC_TLB_H__ */ | ||
diff --git a/arch/openrisc/include/asm/tlbflush.h b/arch/openrisc/include/asm/tlbflush.h new file mode 100644 index 000000000000..6a2accd6cb67 --- /dev/null +++ b/arch/openrisc/include/asm/tlbflush.h | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_TLBFLUSH_H | ||
20 | #define __ASM_OPENRISC_TLBFLUSH_H | ||
21 | |||
22 | #include <linux/mm.h> | ||
23 | #include <asm/processor.h> | ||
24 | #include <asm/pgtable.h> | ||
25 | #include <asm/pgalloc.h> | ||
26 | #include <asm/current.h> | ||
27 | #include <linux/sched.h> | ||
28 | |||
29 | /* | ||
30 | * - flush_tlb() flushes the current mm struct TLBs | ||
31 | * - flush_tlb_all() flushes all processes TLBs | ||
32 | * - flush_tlb_mm(mm) flushes the specified mm context TLB's | ||
33 | * - flush_tlb_page(vma, vmaddr) flushes one page | ||
34 | * - flush_tlb_range(mm, start, end) flushes a range of pages | ||
35 | */ | ||
36 | |||
37 | void flush_tlb_all(void); | ||
38 | void flush_tlb_mm(struct mm_struct *mm); | ||
39 | void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); | ||
40 | void flush_tlb_range(struct vm_area_struct *vma, | ||
41 | unsigned long start, | ||
42 | unsigned long end); | ||
43 | |||
44 | static inline void flush_tlb(void) | ||
45 | { | ||
46 | flush_tlb_mm(current->mm); | ||
47 | } | ||
48 | |||
49 | static inline void flush_tlb_kernel_range(unsigned long start, | ||
50 | unsigned long end) | ||
51 | { | ||
52 | flush_tlb_range(NULL, start, end); | ||
53 | } | ||
54 | |||
55 | #endif /* __ASM_OPENRISC_TLBFLUSH_H */ | ||
diff --git a/arch/openrisc/include/asm/uaccess.h b/arch/openrisc/include/asm/uaccess.h new file mode 100644 index 000000000000..c310e45b538e --- /dev/null +++ b/arch/openrisc/include/asm/uaccess.h | |||
@@ -0,0 +1,355 @@ | |||
1 | /* | ||
2 | * OpenRISC Linux | ||
3 | * | ||
4 | * Linux architectural port borrowing liberally from similar works of | ||
5 | * others. All original copyrights apply as per the original source | ||
6 | * declaration. | ||
7 | * | ||
8 | * OpenRISC implementation: | ||
9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> | ||
10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> | ||
11 | * et al. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify | ||
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | */ | ||
18 | |||
19 | #ifndef __ASM_OPENRISC_UACCESS_H | ||
20 | #define __ASM_OPENRISC_UACCESS_H | ||
21 | |||
22 | /* | ||
23 | * User space memory access functions | ||
24 | */ | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/thread_info.h> | ||
27 | #include <linux/prefetch.h> | ||
28 | #include <linux/string.h> | ||
29 | #include <linux/thread_info.h> | ||
30 | #include <asm/page.h> | ||
31 | |||
32 | #define VERIFY_READ 0 | ||
33 | #define VERIFY_WRITE 1 | ||
34 | |||
35 | /* | ||
36 | * The fs value determines whether argument validity checking should be | ||
37 | * performed or not. If get_fs() == USER_DS, checking is performed, with | ||
38 | * get_fs() == KERNEL_DS, checking is bypassed. | ||
39 | * | ||
40 | * For historical reasons, these macros are grossly misnamed. | ||
41 | */ | ||
42 | |||
43 | /* addr_limit is the maximum accessible address for the task. we misuse | ||
44 | * the KERNEL_DS and USER_DS values to both assign and compare the | ||
45 | * addr_limit values through the equally misnamed get/set_fs macros. | ||
46 | * (see above) | ||
47 | */ | ||
48 | |||
49 | #define KERNEL_DS (~0UL) | ||
50 | #define get_ds() (KERNEL_DS) | ||
51 | |||
52 | #define USER_DS (TASK_SIZE) | ||
53 | #define get_fs() (current_thread_info()->addr_limit) | ||
54 | #define set_fs(x) (current_thread_info()->addr_limit = (x)) | ||
55 | |||
56 | #define segment_eq(a, b) ((a) == (b)) | ||
57 | |||
58 | /* Ensure that the range from addr to addr+size is all within the process' | ||
59 | * address space | ||
60 | */ | ||
61 | #define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs()-size)) | ||
62 | |||
63 | /* Ensure that addr is below task's addr_limit */ | ||
64 | #define __addr_ok(addr) ((unsigned long) addr < get_fs()) | ||
65 | |||
66 | #define access_ok(type, addr, size) \ | ||
67 | __range_ok((unsigned long)addr, (unsigned long)size) | ||
68 | |||
69 | /* | ||
70 | * The exception table consists of pairs of addresses: the first is the | ||
71 | * address of an instruction that is allowed to fault, and the second is | ||
72 | * the address at which the program should continue. No registers are | ||
73 | * modified, so it is entirely up to the continuation code to figure out | ||
74 | * what to do. | ||
75 | * | ||
76 | * All the routines below use bits of fixup code that are out of line | ||
77 | * with the main instruction path. This means when everything is well, | ||
78 | * we don't even have to jump over them. Further, they do not intrude | ||
79 | * on our cache or tlb entries. | ||
80 | */ | ||
81 | |||
82 | struct exception_table_entry { | ||
83 | unsigned long insn, fixup; | ||
84 | }; | ||
85 | |||
86 | /* Returns 0 if exception not found and fixup otherwise. */ | ||
87 | extern unsigned long search_exception_table(unsigned long); | ||
88 | extern void sort_exception_table(void); | ||
89 | |||
90 | /* | ||
91 | * These are the main single-value transfer routines. They automatically | ||
92 | * use the right size if we just have the right pointer type. | ||
93 | * | ||
94 | * This gets kind of ugly. We want to return _two_ values in "get_user()" | ||
95 | * and yet we don't want to do any pointers, because that is too much | ||
96 | * of a performance impact. Thus we have a few rather ugly macros here, | ||
97 | * and hide all the uglyness from the user. | ||
98 | * | ||
99 | * The "__xxx" versions of the user access functions are versions that | ||
100 | * do not verify the address space, that must have been done previously | ||
101 | * with a separate "access_ok()" call (this is used when we do multiple | ||
102 | * accesses to the same area of user memory). | ||
103 | * | ||
104 | * As we use the same address space for kernel and user data on the | ||
105 | * PowerPC, we can just do these as direct assignments. (Of course, the | ||
106 | * exception handling means that it's no longer "just"...) | ||
107 | */ | ||
108 | #define get_user(x, ptr) \ | ||
109 | __get_user_check((x), (ptr), sizeof(*(ptr))) | ||
110 | #define put_user(x, ptr) \ | ||
111 | __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr))) | ||
112 | |||
113 | #define __get_user(x, ptr) \ | ||
114 | __get_user_nocheck((x), (ptr), sizeof(*(ptr))) | ||
115 | #define __put_user(x, ptr) \ | ||
116 | __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr))) | ||
117 | |||
118 | extern long __put_user_bad(void); | ||
119 | |||
120 | #define __put_user_nocheck(x, ptr, size) \ | ||
121 | ({ \ | ||
122 | long __pu_err; \ | ||
123 | __put_user_size((x), (ptr), (size), __pu_err); \ | ||
124 | __pu_err; \ | ||
125 | }) | ||
126 | |||
127 | #define __put_user_check(x, ptr, size) \ | ||
128 | ({ \ | ||
129 | long __pu_err = -EFAULT; \ | ||
130 | __typeof__(*(ptr)) *__pu_addr = (ptr); \ | ||
131 | if (access_ok(VERIFY_WRITE, __pu_addr, size)) \ | ||
132 | __put_user_size((x), __pu_addr, (size), __pu_err); \ | ||
133 | __pu_err; \ | ||
134 | }) | ||
135 | |||
136 | #define __put_user_size(x, ptr, size, retval) \ | ||
137 | do { \ | ||
138 | retval = 0; \ | ||
139 | switch (size) { \ | ||
140 | case 1: __put_user_asm(x, ptr, retval, "l.sb"); break; \ | ||
141 | case 2: __put_user_asm(x, ptr, retval, "l.sh"); break; \ | ||
142 | case 4: __put_user_asm(x, ptr, retval, "l.sw"); break; \ | ||
143 | case 8: __put_user_asm2(x, ptr, retval); break; \ | ||
144 | default: __put_user_bad(); \ | ||
145 | } \ | ||
146 | } while (0) | ||
147 | |||
148 | struct __large_struct { | ||
149 | unsigned long buf[100]; | ||
150 | }; | ||
151 | #define __m(x) (*(struct __large_struct *)(x)) | ||
152 | |||
153 | /* | ||
154 | * We don't tell gcc that we are accessing memory, but this is OK | ||
155 | * because we do not write to any memory gcc knows about, so there | ||
156 | * are no aliasing issues. | ||
157 | */ | ||
158 | #define __put_user_asm(x, addr, err, op) \ | ||
159 | __asm__ __volatile__( \ | ||
160 | "1: "op" 0(%2),%1\n" \ | ||
161 | "2:\n" \ | ||
162 | ".section .fixup,\"ax\"\n" \ | ||
163 | "3: l.addi %0,r0,%3\n" \ | ||
164 | " l.j 2b\n" \ | ||
165 | " l.nop\n" \ | ||
166 | ".previous\n" \ | ||
167 | ".section __ex_table,\"a\"\n" \ | ||
168 | " .align 2\n" \ | ||
169 | " .long 1b,3b\n" \ | ||
170 | ".previous" \ | ||
171 | : "=r"(err) \ | ||
172 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err)) | ||
173 | |||
174 | #define __put_user_asm2(x, addr, err) \ | ||
175 | __asm__ __volatile__( \ | ||
176 | "1: l.sw 0(%2),%1\n" \ | ||
177 | "2: l.sw 4(%2),%H1\n" \ | ||
178 | "3:\n" \ | ||
179 | ".section .fixup,\"ax\"\n" \ | ||
180 | "4: l.addi %0,r0,%3\n" \ | ||
181 | " l.j 3b\n" \ | ||
182 | " l.nop\n" \ | ||
183 | ".previous\n" \ | ||
184 | ".section __ex_table,\"a\"\n" \ | ||
185 | " .align 2\n" \ | ||
186 | " .long 1b,4b\n" \ | ||
187 | " .long 2b,4b\n" \ | ||
188 | ".previous" \ | ||
189 | : "=r"(err) \ | ||
190 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err)) | ||
191 | |||
192 | #define __get_user_nocheck(x, ptr, size) \ | ||
193 | ({ \ | ||
194 | long __gu_err, __gu_val; \ | ||
195 | __get_user_size(__gu_val, (ptr), (size), __gu_err); \ | ||
196 | (x) = (__typeof__(*(ptr)))__gu_val; \ | ||
197 | __gu_err; \ | ||
198 | }) | ||
199 | |||
200 | #define __get_user_check(x, ptr, size) \ | ||
201 | ({ \ | ||
202 | long __gu_err = -EFAULT, __gu_val = 0; \ | ||
203 | const __typeof__(*(ptr)) * __gu_addr = (ptr); \ | ||
204 | if (access_ok(VERIFY_READ, __gu_addr, size)) \ | ||
205 | __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \ | ||
206 | (x) = (__typeof__(*(ptr)))__gu_val; \ | ||
207 | __gu_err; \ | ||
208 | }) | ||
209 | |||
210 | extern long __get_user_bad(void); | ||
211 | |||
212 | #define __get_user_size(x, ptr, size, retval) \ | ||
213 | do { \ | ||
214 | retval = 0; \ | ||
215 | switch (size) { \ | ||
216 | case 1: __get_user_asm(x, ptr, retval, "l.lbz"); break; \ | ||
217 | case 2: __get_user_asm(x, ptr, retval, "l.lhz"); break; \ | ||
218 | case 4: __get_user_asm(x, ptr, retval, "l.lwz"); break; \ | ||
219 | case 8: __get_user_asm2(x, ptr, retval); \ | ||
220 | default: (x) = __get_user_bad(); \ | ||
221 | } \ | ||
222 | } while (0) | ||
223 | |||
224 | #define __get_user_asm(x, addr, err, op) \ | ||
225 | __asm__ __volatile__( \ | ||
226 | "1: "op" %1,0(%2)\n" \ | ||
227 | "2:\n" \ | ||
228 | ".section .fixup,\"ax\"\n" \ | ||
229 | "3: l.addi %0,r0,%3\n" \ | ||
230 | " l.addi %1,r0,0\n" \ | ||
231 | " l.j 2b\n" \ | ||
232 | " l.nop\n" \ | ||
233 | ".previous\n" \ | ||
234 | ".section __ex_table,\"a\"\n" \ | ||
235 | " .align 2\n" \ | ||
236 | " .long 1b,3b\n" \ | ||
237 | ".previous" \ | ||
238 | : "=r"(err), "=r"(x) \ | ||
239 | : "r"(addr), "i"(-EFAULT), "0"(err)) | ||
240 | |||
241 | #define __get_user_asm2(x, addr, err) \ | ||
242 | __asm__ __volatile__( \ | ||
243 | "1: l.lwz %1,0(%2)\n" \ | ||
244 | "2: l.lwz %H1,4(%2)\n" \ | ||
245 | "3:\n" \ | ||
246 | ".section .fixup,\"ax\"\n" \ | ||
247 | "4: l.addi %0,r0,%3\n" \ | ||
248 | " l.addi %1,r0,0\n" \ | ||
249 | " l.addi %H1,r0,0\n" \ | ||
250 | " l.j 3b\n" \ | ||
251 | " l.nop\n" \ | ||
252 | ".previous\n" \ | ||
253 | ".section __ex_table,\"a\"\n" \ | ||
254 | " .align 2\n" \ | ||
255 | " .long 1b,4b\n" \ | ||
256 | " .long 2b,4b\n" \ | ||
257 | ".previous" \ | ||
258 | : "=r"(err), "=&r"(x) \ | ||
259 | : "r"(addr), "i"(-EFAULT), "0"(err)) | ||
260 | |||
261 | /* more complex routines */ | ||
262 | |||
263 | extern unsigned long __must_check | ||
264 | __copy_tofrom_user(void *to, const void *from, unsigned long size); | ||
265 | |||
266 | #define __copy_from_user(to, from, size) \ | ||
267 | __copy_tofrom_user(to, from, size) | ||
268 | #define __copy_to_user(to, from, size) \ | ||
269 | __copy_tofrom_user(to, from, size) | ||
270 | |||
271 | #define __copy_to_user_inatomic __copy_to_user | ||
272 | #define __copy_from_user_inatomic __copy_from_user | ||
273 | |||
274 | static inline unsigned long | ||
275 | copy_from_user(void *to, const void *from, unsigned long n) | ||
276 | { | ||
277 | unsigned long over; | ||
278 | |||
279 | if (access_ok(VERIFY_READ, from, n)) | ||
280 | return __copy_tofrom_user(to, from, n); | ||
281 | if ((unsigned long)from < TASK_SIZE) { | ||
282 | over = (unsigned long)from + n - TASK_SIZE; | ||
283 | return __copy_tofrom_user(to, from, n - over) + over; | ||
284 | } | ||
285 | return n; | ||
286 | } | ||
287 | |||
288 | static inline unsigned long | ||
289 | copy_to_user(void *to, const void *from, unsigned long n) | ||
290 | { | ||
291 | unsigned long over; | ||
292 | |||
293 | if (access_ok(VERIFY_WRITE, to, n)) | ||
294 | return __copy_tofrom_user(to, from, n); | ||
295 | if ((unsigned long)to < TASK_SIZE) { | ||
296 | over = (unsigned long)to + n - TASK_SIZE; | ||
297 | return __copy_tofrom_user(to, from, n - over) + over; | ||
298 | } | ||
299 | return n; | ||
300 | } | ||
301 | |||
302 | extern unsigned long __clear_user(void *addr, unsigned long size); | ||
303 | |||
304 | static inline __must_check unsigned long | ||
305 | clear_user(void *addr, unsigned long size) | ||
306 | { | ||
307 | |||
308 | if (access_ok(VERIFY_WRITE, addr, size)) | ||
309 | return __clear_user(addr, size); | ||
310 | if ((unsigned long)addr < TASK_SIZE) { | ||
311 | unsigned long over = (unsigned long)addr + size - TASK_SIZE; | ||
312 | return __clear_user(addr, size - over) + over; | ||
313 | } | ||
314 | return size; | ||
315 | } | ||
316 | |||
317 | extern int __strncpy_from_user(char *dst, const char *src, long count); | ||
318 | |||
319 | static inline long strncpy_from_user(char *dst, const char *src, long count) | ||
320 | { | ||
321 | if (access_ok(VERIFY_READ, src, 1)) | ||
322 | return __strncpy_from_user(dst, src, count); | ||
323 | return -EFAULT; | ||
324 | } | ||
325 | |||
326 | /* | ||
327 | * Return the size of a string (including the ending 0) | ||
328 | * | ||
329 | * Return 0 for error | ||
330 | */ | ||
331 | |||
332 | extern int __strnlen_user(const char *str, long len, unsigned long top); | ||
333 | |||
334 | /* | ||
335 | * Returns the length of the string at str (including the null byte), | ||
336 | * or 0 if we hit a page we can't access, | ||
337 | * or something > len if we didn't find a null byte. | ||
338 | * | ||
339 | * The `top' parameter to __strnlen_user is to make sure that | ||
340 | * we can never overflow from the user area into kernel space. | ||
341 | */ | ||
342 | static inline long strnlen_user(const char __user *str, long len) | ||
343 | { | ||
344 | unsigned long top = (unsigned long)get_fs(); | ||
345 | unsigned long res = 0; | ||
346 | |||
347 | if (__addr_ok(str)) | ||
348 | res = __strnlen_user(str, len, top); | ||
349 | |||
350 | return res; | ||
351 | } | ||
352 | |||
353 | #define strlen_user(str) strnlen_user(str, TASK_SIZE-1) | ||
354 | |||
355 | #endif /* __ASM_OPENRISC_UACCESS_H */ | ||