blob: c2394f8b0fe131b896ba0898094cb25ed7c9a24d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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-existant memory or
11 * devices.
12 */
13#ifndef _ASM_PACCESS_H
14#define _ASM_PACCESS_H
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/errno.h>
17
Ralf Baechle875d43e2005-09-03 15:56:16 -070018#ifdef CONFIG_32BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#define __PA_ADDR ".word"
20#endif
Ralf Baechle875d43e2005-09-03 15:56:16 -070021#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define __PA_ADDR ".dword"
23#endif
24
25extern asmlinkage void handle_ibe(void);
26extern asmlinkage void handle_dbe(void);
27
Ralf Baechle21a151d2007-10-11 23:46:15 +010028#define put_dbe(x, ptr) __put_dbe((x), (ptr), sizeof(*(ptr)))
29#define get_dbe(x, ptr) __get_dbe((x), (ptr), sizeof(*(ptr)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31struct __large_pstruct { unsigned long buf[100]; };
32#define __mp(x) (*(struct __large_pstruct *)(x))
33
Ralf Baechle21a151d2007-10-11 23:46:15 +010034#define __get_dbe(x, ptr, size) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070035({ \
36 long __gu_err; \
Robert P. J. Daya4c9bb72007-04-10 06:23:27 -040037 __typeof__(*(ptr)) __gu_val; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 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) \
Ralf Baechle77c728c2005-03-04 19:36:51 +000054{ \
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 __asm__ __volatile__( \
56 "1:\t" insn "\t%1,%2\n\t" \
57 "move\t%0,$0\n" \
58 "2:\n\t" \
59 ".section\t.fixup,\"ax\"\n" \
60 "3:\tli\t%0,%3\n\t" \
61 "move\t%1,$0\n\t" \
62 "j\t2b\n\t" \
63 ".previous\n\t" \
64 ".section\t__dbe_table,\"a\"\n\t" \
65 __PA_ADDR "\t1b, 3b\n\t" \
66 ".previous" \
67 :"=r" (__gu_err), "=r" (__gu_val) \
68 :"o" (__mp(__gu_addr)), "i" (-EFAULT)); \
Ralf Baechle77c728c2005-03-04 19:36:51 +000069}
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71extern void __get_dbe_unknown(void);
72
Ralf Baechle21a151d2007-10-11 23:46:15 +010073#define __put_dbe(x, ptr, size) \
Linus Torvalds1da177e2005-04-16 15:20:36 -070074({ \
75 long __pu_err; \
76 __typeof__(*(ptr)) __pu_val; \
77 long __pu_addr; \
78 __pu_val = (x); \
79 __pu_addr = (long) (ptr); \
80 __asm__("":"=r" (__pu_err)); \
81 switch (size) { \
82 case 1: __put_dbe_asm("sb"); break; \
83 case 2: __put_dbe_asm("sh"); break; \
84 case 4: __put_dbe_asm("sw"); break; \
85 case 8: __put_dbe_asm("sd"); break; \
86 default: __put_dbe_unknown(); break; \
87 } \
88 __pu_err; \
89})
90
91#define __put_dbe_asm(insn) \
Ralf Baechle77c728c2005-03-04 19:36:51 +000092{ \
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 __asm__ __volatile__( \
94 "1:\t" insn "\t%1,%2\n\t" \
95 "move\t%0,$0\n" \
96 "2:\n\t" \
97 ".section\t.fixup,\"ax\"\n" \
98 "3:\tli\t%0,%3\n\t" \
99 "j\t2b\n\t" \
100 ".previous\n\t" \
101 ".section\t__dbe_table,\"a\"\n\t" \
102 __PA_ADDR "\t1b, 3b\n\t" \
103 ".previous" \
104 : "=r" (__pu_err) \
105 : "r" (__pu_val), "o" (__mp(__pu_addr)), "i" (-EFAULT)); \
Ralf Baechle77c728c2005-03-04 19:36:51 +0000106}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108extern void __put_dbe_unknown(void);
109
110extern unsigned long search_dbe_table(unsigned long addr);
111
112#endif /* _ASM_PACCESS_H */