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