VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-ia64 / sn / sn2 / io.h
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) 2000-2003 Silicon Graphics, Inc. All rights reserved.
7  */
8
9 #ifndef _ASM_SN_SN2_IO_H
10 #define _ASM_SN_SN2_IO_H
11 #include <linux/compiler.h>
12 #include <asm/intrinsics.h>
13
14 extern void * sn_io_addr(unsigned long port) __attribute_const__; /* Forward definition */
15 extern void sn_mmiob(void); /* Forward definition */
16
17 #define __sn_mf_a()   ia64_mfa()
18
19 extern void sn_dma_flush(unsigned long);
20
21 #define __sn_inb ___sn_inb
22 #define __sn_inw ___sn_inw
23 #define __sn_inl ___sn_inl
24 #define __sn_outb ___sn_outb
25 #define __sn_outw ___sn_outw
26 #define __sn_outl ___sn_outl
27 #define __sn_readb ___sn_readb
28 #define __sn_readw ___sn_readw
29 #define __sn_readl ___sn_readl
30 #define __sn_readq ___sn_readq
31 #define __sn_readb_relaxed ___sn_readb_relaxed
32 #define __sn_readw_relaxed ___sn_readw_relaxed
33 #define __sn_readl_relaxed ___sn_readl_relaxed
34 #define __sn_readq_relaxed ___sn_readq_relaxed
35
36 /*
37  * The following routines are SN Platform specific, called when
38  * a reference is made to inX/outX set macros.  SN Platform
39  * inX set of macros ensures that Posted DMA writes on the
40  * Bridge is flushed.
41  *
42  * The routines should be self explainatory.
43  */
44
45 static inline unsigned int
46 ___sn_inb (unsigned long port)
47 {
48         volatile unsigned char *addr;
49         unsigned char ret = -1;
50
51         if ((addr = sn_io_addr(port))) {
52                 ret = *addr;
53                 __sn_mf_a();
54                 sn_dma_flush((unsigned long)addr);
55         }
56         return ret;
57 }
58
59 static inline unsigned int
60 ___sn_inw (unsigned long port)
61 {
62         volatile unsigned short *addr;
63         unsigned short ret = -1;
64
65         if ((addr = sn_io_addr(port))) {
66                 ret = *addr;
67                 __sn_mf_a();
68                 sn_dma_flush((unsigned long)addr);
69         }
70         return ret;
71 }
72
73 static inline unsigned int
74 ___sn_inl (unsigned long port)
75 {
76         volatile unsigned int *addr;
77         unsigned int ret = -1;
78
79         if ((addr = sn_io_addr(port))) {
80                 ret = *addr;
81                 __sn_mf_a();
82                 sn_dma_flush((unsigned long)addr);
83         }
84         return ret;
85 }
86
87 static inline void
88 ___sn_outb (unsigned char val, unsigned long port)
89 {
90         volatile unsigned char *addr;
91
92         if ((addr = sn_io_addr(port))) {
93                 *addr = val;
94                 sn_mmiob();
95         }
96 }
97
98 static inline void
99 ___sn_outw (unsigned short val, unsigned long port)
100 {
101         volatile unsigned short *addr;
102
103         if ((addr = sn_io_addr(port))) {
104                 *addr = val;
105                 sn_mmiob();
106         }
107 }
108
109 static inline void
110 ___sn_outl (unsigned int val, unsigned long port)
111 {
112         volatile unsigned int *addr;
113
114         if ((addr = sn_io_addr(port))) {
115                 *addr = val;
116                 sn_mmiob();
117         }
118 }
119
120 /*
121  * The following routines are SN Platform specific, called when 
122  * a reference is made to readX/writeX set macros.  SN Platform 
123  * readX set of macros ensures that Posted DMA writes on the 
124  * Bridge is flushed.
125  * 
126  * The routines should be self explainatory.
127  */
128
129 static inline unsigned char
130 ___sn_readb (void *addr)
131 {
132         unsigned char val;
133
134         val = *(volatile unsigned char *)addr;
135         __sn_mf_a();
136         sn_dma_flush((unsigned long)addr);
137         return val;
138 }
139
140 static inline unsigned short
141 ___sn_readw (void *addr)
142 {
143         unsigned short val;
144
145         val = *(volatile unsigned short *)addr;
146         __sn_mf_a();
147         sn_dma_flush((unsigned long)addr);
148         return val;
149 }
150
151 static inline unsigned int
152 ___sn_readl (void *addr)
153 {
154         unsigned int val;
155
156         val = *(volatile unsigned int *) addr;
157         __sn_mf_a();
158         sn_dma_flush((unsigned long)addr);
159         return val;
160 }
161
162 static inline unsigned long
163 ___sn_readq (void *addr)
164 {
165         unsigned long val;
166
167         val = *(volatile unsigned long *) addr;
168         __sn_mf_a();
169         sn_dma_flush((unsigned long)addr);
170         return val;
171 }
172
173 /*
174  * For generic and SN2 kernels, we have a set of fast access
175  * PIO macros.  These macros are provided on SN Platform
176  * because the normal inX and readX macros perform an
177  * additional task of flushing Post DMA request on the Bridge.
178  *
179  * These routines should be self explainatory.
180  */
181
182 static inline unsigned int
183 sn_inb_fast (unsigned long port)
184 {
185         volatile unsigned char *addr = (unsigned char *)port;
186         unsigned char ret;
187
188         ret = *addr;
189         __sn_mf_a();
190         return ret;
191 }
192
193 static inline unsigned int
194 sn_inw_fast (unsigned long port)
195 {
196         volatile unsigned short *addr = (unsigned short *)port;
197         unsigned short ret;
198
199         ret = *addr;
200         __sn_mf_a();
201         return ret;
202 }
203
204 static inline unsigned int
205 sn_inl_fast (unsigned long port)
206 {
207         volatile unsigned int *addr = (unsigned int *)port;
208         unsigned int ret;
209
210         ret = *addr;
211         __sn_mf_a();
212         return ret;
213 }
214
215 static inline unsigned char
216 ___sn_readb_relaxed (void *addr)
217 {
218         return *(volatile unsigned char *)addr;
219 }
220
221 static inline unsigned short
222 ___sn_readw_relaxed (void *addr)
223 {
224         return *(volatile unsigned short *)addr;
225 }
226
227 static inline unsigned int
228 ___sn_readl_relaxed (void *addr)
229 {
230         return *(volatile unsigned int *) addr;
231 }
232
233 static inline unsigned long
234 ___sn_readq_relaxed (void *addr)
235 {
236         return *(volatile unsigned long *) addr;
237 }
238
239 #endif