Commit 39757e7351f874a614a46d634c415ca69e154e53
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
Merge tag 'nios2-fixes-v3.19' of git://git.rocketboards.org/linux-socfpga-next
Pull arch/nios2 fixes from Ley Foon Tan: - add definition of ioremap_wc to io.h to fix build error from make allmodconfig - fix make defconfig - fix sparse error * tag 'nios2-fixes-v3.19' of git://git.rocketboards.org/linux-socfpga-next: nios2/uaccess: fix sparse errors nios2: enable "make defconfig" nios2: add definition of ioremap_wc to io.h
Showing 3 changed files Inline Diff
arch/nios2/Makefile
1 | # | 1 | # |
2 | # This file is subject to the terms and conditions of the GNU General Public | 2 | # This file is subject to the terms and conditions of the GNU General Public |
3 | # License. See the file "COPYING" in the main directory of this archive | 3 | # License. See the file "COPYING" in the main directory of this archive |
4 | # for more details. | 4 | # for more details. |
5 | # | 5 | # |
6 | # Copyright (C) 2013 Altera Corporation | 6 | # Copyright (C) 2013 Altera Corporation |
7 | # Copyright (C) 1994, 95, 96, 2003 by Wind River Systems | 7 | # Copyright (C) 1994, 95, 96, 2003 by Wind River Systems |
8 | # Written by Fredrik Markstrom | 8 | # Written by Fredrik Markstrom |
9 | # | 9 | # |
10 | # This file is included by the global makefile so that you can add your own | 10 | # This file is included by the global makefile so that you can add your own |
11 | # architecture-specific flags and dependencies. Remember to do have actions | 11 | # architecture-specific flags and dependencies. Remember to do have actions |
12 | # for "archclean" cleaning up for this architecture. | 12 | # for "archclean" cleaning up for this architecture. |
13 | # | 13 | # |
14 | # Nios2 port by Wind River Systems Inc trough: | 14 | # Nios2 port by Wind River Systems Inc trough: |
15 | # fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com | 15 | # fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com |
16 | 16 | ||
17 | KBUILD_DEFCONFIG := 3c120_defconfig | ||
18 | |||
17 | UTS_SYSNAME = Linux | 19 | UTS_SYSNAME = Linux |
18 | 20 | ||
19 | export MMU | 21 | export MMU |
20 | 22 | ||
21 | LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name) | 23 | LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name) |
22 | 24 | ||
23 | KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__ | 25 | KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__ |
24 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MUL_SUPPORT),-mhw-mul,-mno-hw-mul) | 26 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MUL_SUPPORT),-mhw-mul,-mno-hw-mul) |
25 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MULX_SUPPORT),-mhw-mulx,-mno-hw-mulx) | 27 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MULX_SUPPORT),-mhw-mulx,-mno-hw-mulx) |
26 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_DIV_SUPPORT),-mhw-div,-mno-hw-div) | 28 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_DIV_SUPPORT),-mhw-div,-mno-hw-div) |
27 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_FPU_SUPPORT),-mcustom-fpu-cfg=60-1,) | 29 | KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_FPU_SUPPORT),-mcustom-fpu-cfg=60-1,) |
28 | 30 | ||
29 | KBUILD_CFLAGS += -fno-optimize-sibling-calls | 31 | KBUILD_CFLAGS += -fno-optimize-sibling-calls |
30 | KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\" | 32 | KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\" |
31 | KBUILD_CFLAGS += -fno-builtin | 33 | KBUILD_CFLAGS += -fno-builtin |
32 | KBUILD_CFLAGS += -G 0 | 34 | KBUILD_CFLAGS += -G 0 |
33 | 35 | ||
34 | head-y := arch/nios2/kernel/head.o | 36 | head-y := arch/nios2/kernel/head.o |
35 | libs-y += arch/nios2/lib/ $(LIBGCC) | 37 | libs-y += arch/nios2/lib/ $(LIBGCC) |
36 | core-y += arch/nios2/kernel/ arch/nios2/mm/ | 38 | core-y += arch/nios2/kernel/ arch/nios2/mm/ |
37 | core-y += arch/nios2/platform/ | 39 | core-y += arch/nios2/platform/ |
38 | 40 | ||
39 | INSTALL_PATH ?= /tftpboot | 41 | INSTALL_PATH ?= /tftpboot |
40 | nios2-boot := arch/$(ARCH)/boot | 42 | nios2-boot := arch/$(ARCH)/boot |
41 | BOOT_TARGETS = vmImage zImage | 43 | BOOT_TARGETS = vmImage zImage |
42 | PHONY += $(BOOT_TARGETS) install | 44 | PHONY += $(BOOT_TARGETS) install |
43 | KBUILD_IMAGE := $(nios2-boot)/vmImage | 45 | KBUILD_IMAGE := $(nios2-boot)/vmImage |
44 | 46 | ||
45 | ifneq ($(CONFIG_NIOS2_DTB_SOURCE),"") | 47 | ifneq ($(CONFIG_NIOS2_DTB_SOURCE),"") |
46 | core-y += $(nios2-boot)/ | 48 | core-y += $(nios2-boot)/ |
47 | endif | 49 | endif |
48 | 50 | ||
49 | all: vmImage | 51 | all: vmImage |
50 | 52 | ||
51 | archclean: | 53 | archclean: |
52 | $(Q)$(MAKE) $(clean)=$(nios2-boot) | 54 | $(Q)$(MAKE) $(clean)=$(nios2-boot) |
53 | 55 | ||
54 | %.dtb: | 56 | %.dtb: |
55 | $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ | 57 | $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ |
56 | 58 | ||
57 | dtbs: | 59 | dtbs: |
58 | $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ | 60 | $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ |
59 | 61 | ||
60 | $(BOOT_TARGETS): vmlinux | 62 | $(BOOT_TARGETS): vmlinux |
61 | $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ | 63 | $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@ |
62 | 64 | ||
63 | install: | 65 | install: |
64 | $(Q)$(MAKE) $(build)=$(nios2-boot) BOOTIMAGE=$(KBUILD_IMAGE) install | 66 | $(Q)$(MAKE) $(build)=$(nios2-boot) BOOTIMAGE=$(KBUILD_IMAGE) install |
65 | 67 | ||
66 | define archhelp | 68 | define archhelp |
67 | echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))' | 69 | echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))' |
68 | echo ' install - Install kernel using' | 70 | echo ' install - Install kernel using' |
69 | echo ' (your) ~/bin/$(INSTALLKERNEL) or' | 71 | echo ' (your) ~/bin/$(INSTALLKERNEL) or' |
70 | echo ' (distribution) /sbin/$(INSTALLKERNEL) or' | 72 | echo ' (distribution) /sbin/$(INSTALLKERNEL) or' |
71 | echo ' install to $$(INSTALL_PATH)' | 73 | echo ' install to $$(INSTALL_PATH)' |
72 | echo ' dtbs - Build device tree blobs for enabled boards' | 74 | echo ' dtbs - Build device tree blobs for enabled boards' |
73 | endef | 75 | endef |
74 | 76 |
arch/nios2/include/asm/io.h
1 | /* | 1 | /* |
2 | * Copyright (C) 2014 Altera Corporation | 2 | * Copyright (C) 2014 Altera Corporation |
3 | * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch> | 3 | * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch> |
4 | * Copyright (C) 2004 Microtronix Datacom Ltd. | 4 | * Copyright (C) 2004 Microtronix Datacom Ltd. |
5 | * | 5 | * |
6 | * This file is subject to the terms and conditions of the GNU General Public | 6 | * This file is subject to the terms and conditions of the GNU General Public |
7 | * License. See the file "COPYING" in the main directory of this archive | 7 | * License. See the file "COPYING" in the main directory of this archive |
8 | * for more details. | 8 | * for more details. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #ifndef _ASM_NIOS2_IO_H | 11 | #ifndef _ASM_NIOS2_IO_H |
12 | #define _ASM_NIOS2_IO_H | 12 | #define _ASM_NIOS2_IO_H |
13 | 13 | ||
14 | #include <linux/types.h> | 14 | #include <linux/types.h> |
15 | #include <asm/pgtable-bits.h> | 15 | #include <asm/pgtable-bits.h> |
16 | 16 | ||
17 | /* PCI is not supported in nios2, set this to 0. */ | 17 | /* PCI is not supported in nios2, set this to 0. */ |
18 | #define IO_SPACE_LIMIT 0 | 18 | #define IO_SPACE_LIMIT 0 |
19 | 19 | ||
20 | #define readb_relaxed(addr) readb(addr) | 20 | #define readb_relaxed(addr) readb(addr) |
21 | #define readw_relaxed(addr) readw(addr) | 21 | #define readw_relaxed(addr) readw(addr) |
22 | #define readl_relaxed(addr) readl(addr) | 22 | #define readl_relaxed(addr) readl(addr) |
23 | 23 | ||
24 | #define writeb_relaxed(x, addr) writeb(x, addr) | 24 | #define writeb_relaxed(x, addr) writeb(x, addr) |
25 | #define writew_relaxed(x, addr) writew(x, addr) | 25 | #define writew_relaxed(x, addr) writew(x, addr) |
26 | #define writel_relaxed(x, addr) writel(x, addr) | 26 | #define writel_relaxed(x, addr) writel(x, addr) |
27 | 27 | ||
28 | extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size, | 28 | extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size, |
29 | unsigned long cacheflag); | 29 | unsigned long cacheflag); |
30 | extern void __iounmap(void __iomem *addr); | 30 | extern void __iounmap(void __iomem *addr); |
31 | 31 | ||
32 | static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size) | 32 | static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size) |
33 | { | 33 | { |
34 | return __ioremap(physaddr, size, 0); | 34 | return __ioremap(physaddr, size, 0); |
35 | } | 35 | } |
36 | 36 | ||
37 | static inline void __iomem *ioremap_nocache(unsigned long physaddr, | 37 | static inline void __iomem *ioremap_nocache(unsigned long physaddr, |
38 | unsigned long size) | 38 | unsigned long size) |
39 | { | 39 | { |
40 | return __ioremap(physaddr, size, 0); | 40 | return __ioremap(physaddr, size, 0); |
41 | } | 41 | } |
42 | 42 | ||
43 | static inline void iounmap(void __iomem *addr) | 43 | static inline void iounmap(void __iomem *addr) |
44 | { | 44 | { |
45 | __iounmap(addr); | 45 | __iounmap(addr); |
46 | } | 46 | } |
47 | 47 | ||
48 | #define ioremap_wc ioremap_nocache | ||
49 | |||
48 | /* Pages to physical address... */ | 50 | /* Pages to physical address... */ |
49 | #define page_to_phys(page) virt_to_phys(page_to_virt(page)) | 51 | #define page_to_phys(page) virt_to_phys(page_to_virt(page)) |
50 | #define page_to_bus(page) page_to_virt(page) | 52 | #define page_to_bus(page) page_to_virt(page) |
51 | 53 | ||
52 | /* Macros used for converting between virtual and physical mappings. */ | 54 | /* Macros used for converting between virtual and physical mappings. */ |
53 | #define phys_to_virt(vaddr) \ | 55 | #define phys_to_virt(vaddr) \ |
54 | ((void *)((unsigned long)(vaddr) | CONFIG_NIOS2_KERNEL_REGION_BASE)) | 56 | ((void *)((unsigned long)(vaddr) | CONFIG_NIOS2_KERNEL_REGION_BASE)) |
55 | /* Clear top 3 bits */ | 57 | /* Clear top 3 bits */ |
56 | #define virt_to_phys(vaddr) \ | 58 | #define virt_to_phys(vaddr) \ |
57 | ((unsigned long)((unsigned long)(vaddr) & ~0xE0000000)) | 59 | ((unsigned long)((unsigned long)(vaddr) & ~0xE0000000)) |
58 | 60 | ||
59 | #include <asm-generic/io.h> | 61 | #include <asm-generic/io.h> |
60 | 62 | ||
61 | #endif /* _ASM_NIOS2_IO_H */ | 63 | #endif /* _ASM_NIOS2_IO_H */ |
62 | 64 |
arch/nios2/include/asm/uaccess.h
1 | /* | 1 | /* |
2 | * User space memory access functions for Nios II | 2 | * User space memory access functions for Nios II |
3 | * | 3 | * |
4 | * Copyright (C) 2010-2011, Tobias Klauser <tklauser@distanz.ch> | 4 | * Copyright (C) 2010-2011, Tobias Klauser <tklauser@distanz.ch> |
5 | * Copyright (C) 2009, Wind River Systems Inc | 5 | * Copyright (C) 2009, Wind River Systems Inc |
6 | * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com | 6 | * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com |
7 | * | 7 | * |
8 | * This file is subject to the terms and conditions of the GNU General Public | 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 | 9 | * License. See the file "COPYING" in the main directory of this archive |
10 | * for more details. | 10 | * for more details. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #ifndef _ASM_NIOS2_UACCESS_H | 13 | #ifndef _ASM_NIOS2_UACCESS_H |
14 | #define _ASM_NIOS2_UACCESS_H | 14 | #define _ASM_NIOS2_UACCESS_H |
15 | 15 | ||
16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
17 | #include <linux/thread_info.h> | 17 | #include <linux/thread_info.h> |
18 | #include <linux/string.h> | 18 | #include <linux/string.h> |
19 | 19 | ||
20 | #include <asm/page.h> | 20 | #include <asm/page.h> |
21 | 21 | ||
22 | #define VERIFY_READ 0 | 22 | #define VERIFY_READ 0 |
23 | #define VERIFY_WRITE 1 | 23 | #define VERIFY_WRITE 1 |
24 | 24 | ||
25 | /* | 25 | /* |
26 | * The exception table consists of pairs of addresses: the first is the | 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 | 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 | 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 | 29 | * modified, so it is entirely up to the continuation code to figure out |
30 | * what to do. | 30 | * what to do. |
31 | * | 31 | * |
32 | * All the routines below use bits of fixup code that are out of line | 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, | 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 | 34 | * we don't even have to jump over them. Further, they do not intrude |
35 | * on our cache or tlb entries. | 35 | * on our cache or tlb entries. |
36 | */ | 36 | */ |
37 | struct exception_table_entry { | 37 | struct exception_table_entry { |
38 | unsigned long insn; | 38 | unsigned long insn; |
39 | unsigned long fixup; | 39 | unsigned long fixup; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | extern int fixup_exception(struct pt_regs *regs); | 42 | extern int fixup_exception(struct pt_regs *regs); |
43 | 43 | ||
44 | /* | 44 | /* |
45 | * Segment stuff | 45 | * Segment stuff |
46 | */ | 46 | */ |
47 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) | 47 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) |
48 | #define USER_DS MAKE_MM_SEG(0x80000000UL) | 48 | #define USER_DS MAKE_MM_SEG(0x80000000UL) |
49 | #define KERNEL_DS MAKE_MM_SEG(0) | 49 | #define KERNEL_DS MAKE_MM_SEG(0) |
50 | 50 | ||
51 | #define get_ds() (KERNEL_DS) | 51 | #define get_ds() (KERNEL_DS) |
52 | 52 | ||
53 | #define get_fs() (current_thread_info()->addr_limit) | 53 | #define get_fs() (current_thread_info()->addr_limit) |
54 | #define set_fs(seg) (current_thread_info()->addr_limit = (seg)) | 54 | #define set_fs(seg) (current_thread_info()->addr_limit = (seg)) |
55 | 55 | ||
56 | #define segment_eq(a, b) ((a).seg == (b).seg) | 56 | #define segment_eq(a, b) ((a).seg == (b).seg) |
57 | 57 | ||
58 | #define __access_ok(addr, len) \ | 58 | #define __access_ok(addr, len) \ |
59 | (((signed long)(((long)get_fs().seg) & \ | 59 | (((signed long)(((long)get_fs().seg) & \ |
60 | ((long)(addr) | (((long)(addr)) + (len)) | (len)))) == 0) | 60 | ((long)(addr) | (((long)(addr)) + (len)) | (len)))) == 0) |
61 | 61 | ||
62 | #define access_ok(type, addr, len) \ | 62 | #define access_ok(type, addr, len) \ |
63 | likely(__access_ok((unsigned long)(addr), (unsigned long)(len))) | 63 | likely(__access_ok((unsigned long)(addr), (unsigned long)(len))) |
64 | 64 | ||
65 | # define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n" | 65 | # define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n" |
66 | 66 | ||
67 | /* | 67 | /* |
68 | * Zero Userspace | 68 | * Zero Userspace |
69 | */ | 69 | */ |
70 | 70 | ||
71 | static inline unsigned long __must_check __clear_user(void __user *to, | 71 | static inline unsigned long __must_check __clear_user(void __user *to, |
72 | unsigned long n) | 72 | unsigned long n) |
73 | { | 73 | { |
74 | __asm__ __volatile__ ( | 74 | __asm__ __volatile__ ( |
75 | "1: stb zero, 0(%1)\n" | 75 | "1: stb zero, 0(%1)\n" |
76 | " addi %0, %0, -1\n" | 76 | " addi %0, %0, -1\n" |
77 | " addi %1, %1, 1\n" | 77 | " addi %1, %1, 1\n" |
78 | " bne %0, zero, 1b\n" | 78 | " bne %0, zero, 1b\n" |
79 | "2:\n" | 79 | "2:\n" |
80 | __EX_TABLE_SECTION | 80 | __EX_TABLE_SECTION |
81 | ".word 1b, 2b\n" | 81 | ".word 1b, 2b\n" |
82 | ".previous\n" | 82 | ".previous\n" |
83 | : "=r" (n), "=r" (to) | 83 | : "=r" (n), "=r" (to) |
84 | : "0" (n), "1" (to) | 84 | : "0" (n), "1" (to) |
85 | ); | 85 | ); |
86 | 86 | ||
87 | return n; | 87 | return n; |
88 | } | 88 | } |
89 | 89 | ||
90 | static inline unsigned long __must_check clear_user(void __user *to, | 90 | static inline unsigned long __must_check clear_user(void __user *to, |
91 | unsigned long n) | 91 | unsigned long n) |
92 | { | 92 | { |
93 | if (!access_ok(VERIFY_WRITE, to, n)) | 93 | if (!access_ok(VERIFY_WRITE, to, n)) |
94 | return n; | 94 | return n; |
95 | return __clear_user(to, n); | 95 | return __clear_user(to, n); |
96 | } | 96 | } |
97 | 97 | ||
98 | extern long __copy_from_user(void *to, const void __user *from, | 98 | extern long __copy_from_user(void *to, const void __user *from, |
99 | unsigned long n); | 99 | unsigned long n); |
100 | extern long __copy_to_user(void __user *to, const void *from, unsigned long n); | 100 | extern long __copy_to_user(void __user *to, const void *from, unsigned long n); |
101 | 101 | ||
102 | static inline long copy_from_user(void *to, const void __user *from, | 102 | static inline long copy_from_user(void *to, const void __user *from, |
103 | unsigned long n) | 103 | unsigned long n) |
104 | { | 104 | { |
105 | if (!access_ok(VERIFY_READ, from, n)) | 105 | if (!access_ok(VERIFY_READ, from, n)) |
106 | return n; | 106 | return n; |
107 | return __copy_from_user(to, from, n); | 107 | return __copy_from_user(to, from, n); |
108 | } | 108 | } |
109 | 109 | ||
110 | static inline long copy_to_user(void __user *to, const void *from, | 110 | static inline long copy_to_user(void __user *to, const void *from, |
111 | unsigned long n) | 111 | unsigned long n) |
112 | { | 112 | { |
113 | if (!access_ok(VERIFY_WRITE, to, n)) | 113 | if (!access_ok(VERIFY_WRITE, to, n)) |
114 | return n; | 114 | return n; |
115 | return __copy_to_user(to, from, n); | 115 | return __copy_to_user(to, from, n); |
116 | } | 116 | } |
117 | 117 | ||
118 | extern long strncpy_from_user(char *__to, const char __user *__from, | 118 | extern long strncpy_from_user(char *__to, const char __user *__from, |
119 | long __len); | 119 | long __len); |
120 | extern long strnlen_user(const char __user *s, long n); | 120 | extern long strnlen_user(const char __user *s, long n); |
121 | 121 | ||
122 | #define __copy_from_user_inatomic __copy_from_user | 122 | #define __copy_from_user_inatomic __copy_from_user |
123 | #define __copy_to_user_inatomic __copy_to_user | 123 | #define __copy_to_user_inatomic __copy_to_user |
124 | 124 | ||
125 | /* Optimized macros */ | 125 | /* Optimized macros */ |
126 | #define __get_user_asm(val, insn, addr, err) \ | 126 | #define __get_user_asm(val, insn, addr, err) \ |
127 | { \ | 127 | { \ |
128 | __asm__ __volatile__( \ | 128 | __asm__ __volatile__( \ |
129 | " movi %0, %3\n" \ | 129 | " movi %0, %3\n" \ |
130 | "1: " insn " %1, 0(%2)\n" \ | 130 | "1: " insn " %1, 0(%2)\n" \ |
131 | " movi %0, 0\n" \ | 131 | " movi %0, 0\n" \ |
132 | "2:\n" \ | 132 | "2:\n" \ |
133 | " .section __ex_table,\"a\"\n" \ | 133 | " .section __ex_table,\"a\"\n" \ |
134 | " .word 1b, 2b\n" \ | 134 | " .word 1b, 2b\n" \ |
135 | " .previous" \ | 135 | " .previous" \ |
136 | : "=&r" (err), "=r" (val) \ | 136 | : "=&r" (err), "=r" (val) \ |
137 | : "r" (addr), "i" (-EFAULT)); \ | 137 | : "r" (addr), "i" (-EFAULT)); \ |
138 | } | 138 | } |
139 | 139 | ||
140 | #define __get_user_unknown(val, size, ptr, err) do { \ | 140 | #define __get_user_unknown(val, size, ptr, err) do { \ |
141 | err = 0; \ | 141 | err = 0; \ |
142 | if (copy_from_user(&(val), ptr, size)) { \ | 142 | if (copy_from_user(&(val), ptr, size)) { \ |
143 | err = -EFAULT; \ | 143 | err = -EFAULT; \ |
144 | } \ | 144 | } \ |
145 | } while (0) | 145 | } while (0) |
146 | 146 | ||
147 | #define __get_user_common(val, size, ptr, err) \ | 147 | #define __get_user_common(val, size, ptr, err) \ |
148 | do { \ | 148 | do { \ |
149 | switch (size) { \ | 149 | switch (size) { \ |
150 | case 1: \ | 150 | case 1: \ |
151 | __get_user_asm(val, "ldbu", ptr, err); \ | 151 | __get_user_asm(val, "ldbu", ptr, err); \ |
152 | break; \ | 152 | break; \ |
153 | case 2: \ | 153 | case 2: \ |
154 | __get_user_asm(val, "ldhu", ptr, err); \ | 154 | __get_user_asm(val, "ldhu", ptr, err); \ |
155 | break; \ | 155 | break; \ |
156 | case 4: \ | 156 | case 4: \ |
157 | __get_user_asm(val, "ldw", ptr, err); \ | 157 | __get_user_asm(val, "ldw", ptr, err); \ |
158 | break; \ | 158 | break; \ |
159 | default: \ | 159 | default: \ |
160 | __get_user_unknown(val, size, ptr, err); \ | 160 | __get_user_unknown(val, size, ptr, err); \ |
161 | break; \ | 161 | break; \ |
162 | } \ | 162 | } \ |
163 | } while (0) | 163 | } while (0) |
164 | 164 | ||
165 | #define __get_user(x, ptr) \ | 165 | #define __get_user(x, ptr) \ |
166 | ({ \ | 166 | ({ \ |
167 | long __gu_err = -EFAULT; \ | 167 | long __gu_err = -EFAULT; \ |
168 | const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ | 168 | const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ |
169 | unsigned long __gu_val; \ | 169 | unsigned long __gu_val; \ |
170 | __get_user_common(__gu_val, sizeof(*(ptr)), __gu_ptr, __gu_err);\ | 170 | __get_user_common(__gu_val, sizeof(*(ptr)), __gu_ptr, __gu_err);\ |
171 | (x) = (__typeof__(x))__gu_val; \ | 171 | (x) = (__force __typeof__(x))__gu_val; \ |
172 | __gu_err; \ | 172 | __gu_err; \ |
173 | }) | 173 | }) |
174 | 174 | ||
175 | #define get_user(x, ptr) \ | 175 | #define get_user(x, ptr) \ |
176 | ({ \ | 176 | ({ \ |
177 | long __gu_err = -EFAULT; \ | 177 | long __gu_err = -EFAULT; \ |
178 | const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ | 178 | const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \ |
179 | unsigned long __gu_val = 0; \ | 179 | unsigned long __gu_val = 0; \ |
180 | if (access_ok(VERIFY_READ, __gu_ptr, sizeof(*__gu_ptr))) \ | 180 | if (access_ok(VERIFY_READ, __gu_ptr, sizeof(*__gu_ptr))) \ |
181 | __get_user_common(__gu_val, sizeof(*__gu_ptr), \ | 181 | __get_user_common(__gu_val, sizeof(*__gu_ptr), \ |
182 | __gu_ptr, __gu_err); \ | 182 | __gu_ptr, __gu_err); \ |
183 | (x) = (__typeof__(x))__gu_val; \ | 183 | (x) = (__force __typeof__(x))__gu_val; \ |
184 | __gu_err; \ | 184 | __gu_err; \ |
185 | }) | 185 | }) |
186 | 186 | ||
187 | #define __put_user_asm(val, insn, ptr, err) \ | 187 | #define __put_user_asm(val, insn, ptr, err) \ |
188 | { \ | 188 | { \ |
189 | __asm__ __volatile__( \ | 189 | __asm__ __volatile__( \ |
190 | " movi %0, %3\n" \ | 190 | " movi %0, %3\n" \ |
191 | "1: " insn " %1, 0(%2)\n" \ | 191 | "1: " insn " %1, 0(%2)\n" \ |
192 | " movi %0, 0\n" \ | 192 | " movi %0, 0\n" \ |
193 | "2:\n" \ | 193 | "2:\n" \ |
194 | " .section __ex_table,\"a\"\n" \ | 194 | " .section __ex_table,\"a\"\n" \ |
195 | " .word 1b, 2b\n" \ | 195 | " .word 1b, 2b\n" \ |
196 | " .previous\n" \ | 196 | " .previous\n" \ |
197 | : "=&r" (err) \ | 197 | : "=&r" (err) \ |
198 | : "r" (val), "r" (ptr), "i" (-EFAULT)); \ | 198 | : "r" (val), "r" (ptr), "i" (-EFAULT)); \ |
199 | } | 199 | } |
200 | 200 | ||
201 | #define put_user(x, ptr) \ | 201 | #define put_user(x, ptr) \ |
202 | ({ \ | 202 | ({ \ |
203 | long __pu_err = -EFAULT; \ | 203 | long __pu_err = -EFAULT; \ |
204 | __typeof__(*(ptr)) __user *__pu_ptr = (ptr); \ | 204 | __typeof__(*(ptr)) __user *__pu_ptr = (ptr); \ |
205 | __typeof__(*(ptr)) __pu_val = (__typeof(*ptr))(x); \ | 205 | __typeof__(*(ptr)) __pu_val = (__typeof(*ptr))(x); \ |
206 | if (access_ok(VERIFY_WRITE, __pu_ptr, sizeof(*__pu_ptr))) { \ | 206 | if (access_ok(VERIFY_WRITE, __pu_ptr, sizeof(*__pu_ptr))) { \ |
207 | switch (sizeof(*__pu_ptr)) { \ | 207 | switch (sizeof(*__pu_ptr)) { \ |
208 | case 1: \ | 208 | case 1: \ |
209 | __put_user_asm(__pu_val, "stb", __pu_ptr, __pu_err); \ | 209 | __put_user_asm(__pu_val, "stb", __pu_ptr, __pu_err); \ |
210 | break; \ | 210 | break; \ |
211 | case 2: \ | 211 | case 2: \ |
212 | __put_user_asm(__pu_val, "sth", __pu_ptr, __pu_err); \ | 212 | __put_user_asm(__pu_val, "sth", __pu_ptr, __pu_err); \ |
213 | break; \ | 213 | break; \ |
214 | case 4: \ | 214 | case 4: \ |
215 | __put_user_asm(__pu_val, "stw", __pu_ptr, __pu_err); \ | 215 | __put_user_asm(__pu_val, "stw", __pu_ptr, __pu_err); \ |
216 | break; \ | 216 | break; \ |
217 | default: \ | 217 | default: \ |
218 | /* XXX: This looks wrong... */ \ | 218 | /* XXX: This looks wrong... */ \ |
219 | __pu_err = 0; \ | 219 | __pu_err = 0; \ |
220 | if (copy_to_user(__pu_ptr, &(__pu_val), \ | 220 | if (copy_to_user(__pu_ptr, &(__pu_val), \ |
221 | sizeof(*__pu_ptr))) \ | 221 | sizeof(*__pu_ptr))) \ |
222 | __pu_err = -EFAULT; \ | 222 | __pu_err = -EFAULT; \ |
223 | break; \ | 223 | break; \ |
224 | } \ | 224 | } \ |
225 | } \ | 225 | } \ |
226 | __pu_err; \ | 226 | __pu_err; \ |
227 | }) | 227 | }) |
228 | 228 | ||
229 | #define __put_user(x, ptr) put_user(x, ptr) | 229 | #define __put_user(x, ptr) put_user(x, ptr) |
230 | 230 | ||
231 | #endif /* _ASM_NIOS2_UACCESS_H */ | 231 | #endif /* _ASM_NIOS2_UACCESS_H */ |
232 | 232 |