xref: /openbmc/linux/arch/mips/include/asm/paccess.h (revision 20e2fc42)
1 /*
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
4  * for more details.
5  *
6  * Copyright (C) 1996, 1997, 1998, 1999, 2000 by Ralf Baechle
7  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
8  *
9  * Protected memory access.  Used for everything that might take revenge
10  * by sending a DBE error like accessing possibly non-existent memory or
11  * devices.
12  */
13 #ifndef _ASM_PACCESS_H
14 #define _ASM_PACCESS_H
15 
16 #include <linux/errno.h>
17 
18 #ifdef CONFIG_32BIT
19 #define __PA_ADDR	".word"
20 #endif
21 #ifdef CONFIG_64BIT
22 #define __PA_ADDR	".dword"
23 #endif
24 
25 extern asmlinkage void handle_ibe(void);
26 extern asmlinkage void handle_dbe(void);
27 
28 #define put_dbe(x, ptr) __put_dbe((x), (ptr), sizeof(*(ptr)))
29 #define get_dbe(x, ptr) __get_dbe((x), (ptr), sizeof(*(ptr)))
30 
31 struct __large_pstruct { unsigned long buf[100]; };
32 #define __mp(x) (*(struct __large_pstruct *)(x))
33 
34 #define __get_dbe(x, ptr, size)						\
35 ({									\
36 	long __gu_err;							\
37 	__typeof__(*(ptr)) __gu_val;					\
38 	unsigned long __gu_addr;					\
39 	__asm__("":"=r" (__gu_val));					\
40 	__gu_addr = (unsigned long) (ptr);				\
41 	__asm__("":"=r" (__gu_err));					\
42 	switch (size) {							\
43 	case 1: __get_dbe_asm("lb"); break;				\
44 	case 2: __get_dbe_asm("lh"); break;				\
45 	case 4: __get_dbe_asm("lw"); break;				\
46 	case 8:	 __get_dbe_asm("ld"); break;				\
47 	default: __get_dbe_unknown(); break;				\
48 	}								\
49 	x = (__typeof__(*(ptr))) __gu_val;				\
50 	__gu_err;							\
51 })
52 
53 #define __get_dbe_asm(insn)						\
54 {									\
55 	__asm__ __volatile__(						\
56 	"1:\t" insn "\t%1,%2\n\t"					\
57 	"move\t%0,$0\n"							\
58 	"2:\n\t"							\
59 	".insn\n\t"							\
60 	".section\t.fixup,\"ax\"\n"					\
61 	"3:\tli\t%0,%3\n\t"						\
62 	"move\t%1,$0\n\t"						\
63 	"j\t2b\n\t"							\
64 	".previous\n\t"							\
65 	".section\t__dbe_table,\"a\"\n\t"				\
66 	__PA_ADDR "\t1b, 3b\n\t"					\
67 	".previous"							\
68 	:"=r" (__gu_err), "=r" (__gu_val)				\
69 	:"o" (__mp(__gu_addr)), "i" (-EFAULT));				\
70 }
71 
72 extern void __get_dbe_unknown(void);
73 
74 #define __put_dbe(x, ptr, size)						\
75 ({									\
76 	long __pu_err;							\
77 	__typeof__(*(ptr)) __pu_val;					\
78 	long __pu_addr;							\
79 	__pu_val = (x);							\
80 	__pu_addr = (long) (ptr);					\
81 	__asm__("":"=r" (__pu_err));					\
82 	switch (size) {							\
83 	case 1: __put_dbe_asm("sb"); break;				\
84 	case 2: __put_dbe_asm("sh"); break;				\
85 	case 4: __put_dbe_asm("sw"); break;				\
86 	case 8: __put_dbe_asm("sd"); break;				\
87 	default: __put_dbe_unknown(); break;				\
88 	}								\
89 	__pu_err;							\
90 })
91 
92 #define __put_dbe_asm(insn)						\
93 {									\
94 	__asm__ __volatile__(						\
95 	"1:\t" insn "\t%1,%2\n\t"					\
96 	"move\t%0,$0\n"							\
97 	"2:\n\t"							\
98 	".insn\n\t"							\
99 	".section\t.fixup,\"ax\"\n"					\
100 	"3:\tli\t%0,%3\n\t"						\
101 	"j\t2b\n\t"							\
102 	".previous\n\t"							\
103 	".section\t__dbe_table,\"a\"\n\t"				\
104 	__PA_ADDR "\t1b, 3b\n\t"					\
105 	".previous"							\
106 	: "=r" (__pu_err)						\
107 	: "r" (__pu_val), "o" (__mp(__pu_addr)), "i" (-EFAULT));	\
108 }
109 
110 extern void __put_dbe_unknown(void);
111 
112 extern unsigned long search_dbe_table(unsigned long addr);
113 
114 #endif /* _ASM_PACCESS_H */
115