diff options
| author | Ley Foon Tan <lftan@altera.com> | 2014-11-06 02:19:41 -0500 |
|---|---|---|
| committer | Ley Foon Tan <lftan@altera.com> | 2014-12-07 23:55:51 -0500 |
| commit | 5ccc6af5e88efdd0c7facba64078d8d61de9012b (patch) | |
| tree | 88f9375353cfd8ae22f9e844ef01a5c7fd4dd4f8 /arch/nios2/include/asm | |
| parent | 771a0163c0bda4a379b79bd573693aa88c0d47b7 (diff) | |
nios2: Memory management
This patch contains the initialisation of the memory blocks, MMU
attributes and the memory map.
Signed-off-by: Ley Foon Tan <lftan@altera.com>
Diffstat (limited to 'arch/nios2/include/asm')
| -rw-r--r-- | arch/nios2/include/asm/mmu.h | 16 | ||||
| -rw-r--r-- | arch/nios2/include/asm/page.h | 111 | ||||
| -rw-r--r-- | arch/nios2/include/asm/uaccess.h | 231 |
3 files changed, 358 insertions, 0 deletions
diff --git a/arch/nios2/include/asm/mmu.h b/arch/nios2/include/asm/mmu.h new file mode 100644 index 000000000000..d9c0b1010f26 --- /dev/null +++ b/arch/nios2/include/asm/mmu.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch> | ||
| 3 | * Copyright (C) 2004 Microtronix Datacom Ltd. | ||
| 4 | * | ||
| 5 | * This file is subject to the terms and conditions of the GNU General Public | ||
| 6 | * License. See the file "COPYING" in the main directory of this archive | ||
| 7 | * for more details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #ifndef _ASM_NIOS2_MMU_H | ||
| 11 | #define _ASM_NIOS2_MMU_H | ||
| 12 | |||
| 13 | /* Default "unsigned long" context */ | ||
| 14 | typedef unsigned long mm_context_t; | ||
| 15 | |||
| 16 | #endif /* _ASM_NIOS2_MMU_H */ | ||
diff --git a/arch/nios2/include/asm/page.h b/arch/nios2/include/asm/page.h new file mode 100644 index 000000000000..7a0d9bd3a61b --- /dev/null +++ b/arch/nios2/include/asm/page.h | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch> | ||
| 3 | * Copyright (C) 2004 Microtronix Datacom Ltd. | ||
| 4 | * | ||
| 5 | * MMU support based on asm/page.h from mips which is: | ||
| 6 | * | ||
| 7 | * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle | ||
| 8 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. | ||
| 9 | * | ||
| 10 | * This file is subject to the terms and conditions of the GNU General Public | ||
| 11 | * License. See the file "COPYING" in the main directory of this archive | ||
| 12 | * for more details. | ||
| 13 | */ | ||
| 14 | |||
| 15 | #ifndef _ASM_NIOS2_PAGE_H | ||
| 16 | #define _ASM_NIOS2_PAGE_H | ||
| 17 | |||
| 18 | #include <linux/pfn.h> | ||
| 19 | #include <linux/const.h> | ||
| 20 | |||
| 21 | /* | ||
| 22 | * PAGE_SHIFT determines the page size | ||
| 23 | */ | ||
| 24 | #define PAGE_SHIFT 12 | ||
| 25 | #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) | ||
| 26 | #define PAGE_MASK (~(PAGE_SIZE - 1)) | ||
| 27 | |||
| 28 | /* | ||
| 29 | * PAGE_OFFSET -- the first address of the first page of memory. | ||
| 30 | */ | ||
| 31 | #define PAGE_OFFSET \ | ||
| 32 | (CONFIG_NIOS2_MEM_BASE + CONFIG_NIOS2_KERNEL_REGION_BASE) | ||
| 33 | |||
| 34 | #ifndef __ASSEMBLY__ | ||
| 35 | |||
| 36 | /* | ||
| 37 | * This gives the physical RAM offset. | ||
| 38 | */ | ||
| 39 | #define PHYS_OFFSET CONFIG_NIOS2_MEM_BASE | ||
| 40 | |||
| 41 | /* | ||
| 42 | * It's normally defined only for FLATMEM config but it's | ||
| 43 | * used in our early mem init code for all memory models. | ||
| 44 | * So always define it. | ||
| 45 | */ | ||
| 46 | #define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET) | ||
| 47 | |||
| 48 | #define clear_page(page) memset((page), 0, PAGE_SIZE) | ||
| 49 | #define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) | ||
| 50 | |||
| 51 | struct page; | ||
| 52 | |||
| 53 | extern void clear_user_page(void *addr, unsigned long vaddr, struct page *page); | ||
| 54 | extern void copy_user_page(void *vto, void *vfrom, unsigned long vaddr, | ||
| 55 | struct page *to); | ||
| 56 | |||
| 57 | extern unsigned long shm_align_mask; | ||
| 58 | |||
| 59 | /* | ||
| 60 | * These are used to make use of C type-checking. | ||
| 61 | */ | ||
| 62 | typedef struct page *pgtable_t; | ||
| 63 | typedef struct { unsigned long pte; } pte_t; | ||
| 64 | typedef struct { unsigned long pgd; } pgd_t; | ||
| 65 | typedef struct { unsigned long pgprot; } pgprot_t; | ||
| 66 | |||
| 67 | #define pte_val(x) ((x).pte) | ||
| 68 | #define pgd_val(x) ((x).pgd) | ||
| 69 | #define pgprot_val(x) ((x).pgprot) | ||
| 70 | |||
| 71 | #define __pte(x) ((pte_t) { (x) }) | ||
| 72 | #define __pgd(x) ((pgd_t) { (x) }) | ||
| 73 | #define __pgprot(x) ((pgprot_t) { (x) }) | ||
| 74 | |||
| 75 | extern unsigned long memory_start; | ||
| 76 | extern unsigned long memory_end; | ||
| 77 | extern unsigned long memory_size; | ||
| 78 | |||
| 79 | extern struct page *mem_map; | ||
| 80 | |||
| 81 | #endif /* !__ASSEMBLY__ */ | ||
| 82 | |||
| 83 | # define __pa(x) \ | ||
| 84 | ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET) | ||
| 85 | # define __va(x) \ | ||
| 86 | ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET)) | ||
| 87 | |||
| 88 | #define page_to_virt(page) \ | ||
| 89 | ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET) | ||
| 90 | |||
| 91 | # define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) | ||
| 92 | # define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && \ | ||
| 93 | (pfn) < max_mapnr) | ||
| 94 | |||
| 95 | # define virt_to_page(vaddr) pfn_to_page(PFN_DOWN(virt_to_phys(vaddr))) | ||
| 96 | # define virt_addr_valid(vaddr) pfn_valid(PFN_DOWN(virt_to_phys(vaddr))) | ||
| 97 | |||
| 98 | # define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \ | ||
| 99 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) | ||
| 100 | |||
| 101 | # define UNCAC_ADDR(addr) \ | ||
| 102 | ((void *)((unsigned)(addr) | CONFIG_NIOS2_IO_REGION_BASE)) | ||
| 103 | # define CAC_ADDR(addr) \ | ||
| 104 | ((void *)(((unsigned)(addr) & ~CONFIG_NIOS2_IO_REGION_BASE) | \ | ||
| 105 | CONFIG_NIOS2_KERNEL_REGION_BASE)) | ||
| 106 | |||
| 107 | #include <asm-generic/memory_model.h> | ||
| 108 | |||
| 109 | #include <asm-generic/getorder.h> | ||
| 110 | |||
| 111 | #endif /* _ASM_NIOS2_PAGE_H */ | ||
diff --git a/arch/nios2/include/asm/uaccess.h b/arch/nios2/include/asm/uaccess.h new file mode 100644 index 000000000000..acedc0a2860e --- /dev/null +++ b/arch/nios2/include/asm/uaccess.h | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | /* | ||
| 2 | * User space memory access functions for Nios II | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010-2011, Tobias Klauser <tklauser@distanz.ch> | ||
| 5 | * Copyright (C) 2009, Wind River Systems Inc | ||
| 6 | * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com | ||
| 7 | * | ||
| 8 | * This file is subject to the terms and conditions of the GNU General Public | ||
| 9 | * License. See the file "COPYING" in the main directory of this archive | ||
| 10 | * for more details. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #ifndef _ASM_NIOS2_UACCESS_H | ||
| 14 | #define _ASM_NIOS2_UACCESS_H | ||
| 15 | |||
| 16 | #include <linux/errno.h> | ||
| 17 | #include <linux/thread_info.h> | ||
| 18 | #include <linux/string.h> | ||
| 19 | |||
| 20 | #include <asm/page.h> | ||
| 21 | |||
| 22 | #define VERIFY_READ 0 | ||
| 23 | #define VERIFY_WRITE 1 | ||
| 24 | |||
| 25 | /* | ||
| 26 | * The exception table consists of pairs of addresses: the first is the | ||
| 27 | * address of an instruction that is allowed to fault, and the second is | ||
| 28 | * the address at which the program should continue. No registers are | ||
| 29 | * modified, so it is entirely up to the continuation code to figure out | ||
| 30 | * what to do. | ||
| 31 | * | ||
| 32 | * All the routines below use bits of fixup code that are out of line | ||
| 33 | * with the main instruction path. This means when everything is well, | ||
| 34 | * we don't even have to jump over them. Further, they do not intrude | ||
| 35 | * on our cache or tlb entries. | ||
| 36 | */ | ||
| 37 | struct exception_table_entry { | ||
| 38 | unsigned long insn; | ||
| 39 | unsigned long fixup; | ||
| 40 | }; | ||
| 41 | |||
| 42 | extern int fixup_exception(struct pt_regs *regs); | ||
| 43 | |||
| 44 | /* | ||
| 45 | * Segment stuff | ||
| 46 | */ | ||
| 47 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) | ||
| 48 | #define USER_DS MAKE_MM_SEG(0x80000000UL) | ||
| 49 | #define KERNEL_DS MAKE_MM_SEG(0) | ||
| 50 | |||
| 51 | #define get_ds() (KERNEL_DS) | ||
| 52 | |||
| 53 | #define get_fs() (current_thread_info()->addr_limit) | ||
| 54 | #define set_fs(seg) (current_thread_info()->addr_limit = (seg)) | ||
| 55 | |||
| 56 | #define segment_eq(a, b) ((a).seg == (b).seg) | ||
| 57 | |||
| 58 | #define __access_ok(addr, len) \ | ||
| 59 | (((signed long)(((long)get_fs().seg) & \ | ||
| 60 | ((long)(addr) | (((long)(addr)) + (len)) | (len)))) == 0) | ||
| 61 | |||
| 62 | #define access_ok(type, addr, len) \ | ||
| 63 | likely(__access_ok((unsigned long)(addr), (unsigned long)(len))) | ||
| 64 | |||
| 65 | # define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n" | ||
| 66 | |||
| 67 | /* | ||
| 68 | * Zero Userspace | ||
| 69 | */ | ||
| 70 | |||
| 71 | static inline unsigned long __must_check __clear_user(void __user *to, | ||
| 72 | unsigned long n) | ||
| 73 | { | ||
| 74 | __asm__ __volatile__ ( | ||
| 75 | "1: stb zero, 0(%1)\n" | ||
| 76 | " addi %0, %0, -1\n" | ||
| 77 | " addi %1, %1, 1\n" | ||
| 78 | " bne %0, zero, 1b\n" | ||
| 79 | "2:\n" | ||
| 80 | __EX_TABLE_SECTION | ||
| 81 | ".word 1b, 2b\n" | ||
| 82 | ".previous\n" | ||
| 83 | : "=r" (n), "=r" (to) | ||
| 84 | : "0" (n), "1" (to) | ||
| 85 | ); | ||
| 86 | |||
| 87 | return n; | ||
| 88 | } | ||
| 89 | |||
| 90 | static inline unsigned long __must_check clear_user(void __user *to, | ||
| 91 | unsigned long n) | ||
| 92 | { | ||
| 93 | if (!access_ok(VERIFY_WRITE, to, n)) | ||
| 94 | return n; | ||
| 95 | return __clear_user(to, n); | ||
| 96 | } | ||
| 97 | |||
| 98 | extern long __copy_from_user(void *to, const void __user *from, | ||
| 99 | unsigned long n); | ||
| 100 | extern long __copy_to_user(void __user *to, const void *from, unsigned long n); | ||
| 101 | |||
| 102 | static inline long copy_from_user(void *to, const void __user *from, | ||
| 103 | unsigned long n) | ||
| 104 | { | ||
| 105 | if (!access_ok(VERIFY_READ, from, n)) | ||
| 106 | return n; | ||
| 107 | return __copy_from_user(to, from, n); | ||
| 108 | } | ||
| 109 | |||
| 110 | static inline long copy_to_user(void __user *to, const void *from, | ||
| 111 | unsigned long n) | ||
| 112 | { | ||
| 113 | if (!access_ok(VERIFY_WRITE, to, n)) | ||
| 114 | return n; | ||
| 115 | return __copy_to_user(to, from, n); | ||
| 116 | } | ||
| 117 | |||
| 118 | extern long strncpy_from_user(char *__to, const char __user *__from, | ||
| 119 | long __len); | ||
| 120 | extern long strnlen_user(const char __user *s, long n); | ||
| 121 | |||
| 122 | #define __copy_from_user_inatomic __copy_from_user | ||
| 123 | #define __copy_to_user_inatomic __copy_to_user | ||
| 124 | |||
| 125 | /* Optimized macros */ | ||
| 126 | #define __get_user_asm(val, insn, addr, err) \ | ||
| 127 | { \ | ||
| 128 | __asm__ __volatile__( \ | ||
| 129 | " movi %0, %3\n" \ | ||
| 130 | "1: " insn " %1, 0(%2)\n" \ | ||
| 131 | " movi %0, 0\n" \ | ||
| 132 | "2:\n" \ | ||
| 133 | " .section __ex_table,\"a\"\n" \ | ||
| 134 | " .word 1b, 2b\n" \ | ||
| 135 | " .previous" \ | ||
| 136 | : "=&r" (err), "=r" (val) \ | ||
| 137 | : "r" (addr), "i" (-EFAULT)); \ | ||
| 138 | } | ||
| 139 | |||
| 140 | #define __get_user_unknown(val, size, ptr, err) do { \ | ||
| 141 | err = 0; \ | ||
| 142 | if (copy_from_user(&(val), ptr, size)) { \ | ||
| 143 | err = -EFAULT; \ | ||
| 144 | } \ | ||
| 145 | } while (0) | ||
| 146 | |||
| 147 | #define __get_user_common(val, size, ptr, err) \ | ||
| 148 | do { \ | ||
| 149 | switch (size) { \ | ||
| 150 | case 1: \ | ||
| 151 | __get_user_asm(val, "ldbu", ptr, err); \ | ||
| 152 | break; \ | ||
| 153 | case 2: \ | ||
| 154 | __get_user_asm(val, "ldhu", ptr, err); \ | ||
| 155 | break; \ | ||
| 156 | case 4: \ | ||
| 157 | __get_user_asm(val, "ldw", ptr, err); \ | ||
| 158 | break; \ | ||
| 159 | default: \ | ||
| 160 | __get_user_unknown(val, size, ptr, err); \ | ||
| 161 | break; \ | ||
| 162 | } \ | ||
| 163 | } while (0) | ||
| 164 | |||
| 165 | #define __get_user(x, ptr) \ | ||
| 166 | ({ \ | ||
| 167 | long __gu_err = -EFAULT; \ | ||
| 168 | const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ | ||
| 169 | unsigned long __gu_val; \ | ||
| 170 | __get_user_common(__gu_val, sizeof(*(ptr)), __gu_ptr, __gu_err);\ | ||
| 171 | (x) = (__typeof__(x))__gu_val; \ | ||
| 172 | __gu_err; \ | ||
| 173 | }) | ||
| 174 | |||
| 175 | #define get_user(x, ptr) \ | ||
| 176 | ({ \ | ||
| 177 | long __gu_err = -EFAULT; \ | ||
| 178 | const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ | ||
| 179 | unsigned long __gu_val = 0; \ | ||
| 180 | if (access_ok(VERIFY_READ, __gu_ptr, sizeof(*__gu_ptr))) \ | ||
| 181 | __get_user_common(__gu_val, sizeof(*__gu_ptr), \ | ||
| 182 | __gu_ptr, __gu_err); \ | ||
| 183 | (x) = (__typeof__(x))__gu_val; \ | ||
| 184 | __gu_err; \ | ||
| 185 | }) | ||
| 186 | |||
| 187 | #define __put_user_asm(val, insn, ptr, err) \ | ||
| 188 | { \ | ||
| 189 | __asm__ __volatile__( \ | ||
| 190 | " movi %0, %3\n" \ | ||
| 191 | "1: " insn " %1, 0(%2)\n" \ | ||
| 192 | " movi %0, 0\n" \ | ||
| 193 | "2:\n" \ | ||
| 194 | " .section __ex_table,\"a\"\n" \ | ||
| 195 | " .word 1b, 2b\n" \ | ||
| 196 | " .previous\n" \ | ||
| 197 | : "=&r" (err) \ | ||
| 198 | : "r" (val), "r" (ptr), "i" (-EFAULT)); \ | ||
| 199 | } | ||
| 200 | |||
| 201 | #define put_user(x, ptr) \ | ||
| 202 | ({ \ | ||
| 203 | long __pu_err = -EFAULT; \ | ||
| 204 | __typeof__(*(ptr)) __user *__pu_ptr = (ptr); \ | ||
| 205 | __typeof__(*(ptr)) __pu_val = (__typeof(*ptr))(x); \ | ||
| 206 | if (access_ok(VERIFY_WRITE, __pu_ptr, sizeof(*__pu_ptr))) { \ | ||
| 207 | switch (sizeof(*__pu_ptr)) { \ | ||
| 208 | case 1: \ | ||
| 209 | __put_user_asm(__pu_val, "stb", __pu_ptr, __pu_err); \ | ||
| 210 | break; \ | ||
| 211 | case 2: \ | ||
| 212 | __put_user_asm(__pu_val, "sth", __pu_ptr, __pu_err); \ | ||
| 213 | break; \ | ||
| 214 | case 4: \ | ||
| 215 | __put_user_asm(__pu_val, "stw", __pu_ptr, __pu_err); \ | ||
| 216 | break; \ | ||
| 217 | default: \ | ||
| 218 | /* XXX: This looks wrong... */ \ | ||
| 219 | __pu_err = 0; \ | ||
| 220 | if (copy_to_user(__pu_ptr, &(__pu_val), \ | ||
| 221 | sizeof(*__pu_ptr))) \ | ||
| 222 | __pu_err = -EFAULT; \ | ||
| 223 | break; \ | ||
| 224 | } \ | ||
| 225 | } \ | ||
| 226 | __pu_err; \ | ||
| 227 | }) | ||
| 228 | |||
| 229 | #define __put_user(x, ptr) put_user(x, ptr) | ||
| 230 | |||
| 231 | #endif /* _ASM_NIOS2_UACCESS_H */ | ||
