VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-parisc / io.h
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4 /* USE_HPPA_IOREMAP IS THE MAGIC FLAG TO ENABLE OR DISABLE REAL IOREMAP() FUNCTIONALITY */
5 /* FOR 712 or 715 MACHINES THIS SHOULD BE ENABLED, 
6    NEWER MACHINES STILL HAVE SOME ISSUES IN THE SCSI AND/OR NETWORK DRIVERS AND 
7    BECAUSE OF THAT I WILL LEAVE IT DISABLED FOR NOW <deller@gmx.de> */
8 /* WHEN THOSE ISSUES ARE SOLVED, USE_HPPA_IOREMAP WILL GO AWAY */
9 #define USE_HPPA_IOREMAP 0
10
11
12 #include <linux/config.h>
13 #include <linux/types.h>
14 #include <asm/pgtable.h>
15
16 extern unsigned long parisc_vmerge_boundary;
17 extern unsigned long parisc_vmerge_max_size;
18
19 #define BIO_VMERGE_BOUNDARY     parisc_vmerge_boundary
20 #define BIO_VMERGE_MAX_SIZE     parisc_vmerge_max_size
21
22 #define virt_to_phys(a) ((unsigned long)__pa(a))
23 #define phys_to_virt(a) __va(a)
24 #define virt_to_bus virt_to_phys
25 #define bus_to_virt phys_to_virt
26
27 /* Memory mapped IO */
28
29 extern void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
30
31 extern inline void * ioremap(unsigned long offset, unsigned long size)
32 {
33         return __ioremap(offset, size, 0);
34 }
35
36 /*
37  * This one maps high address device memory and turns off caching for that area.
38  * it's useful if some control registers are in such an area and write combining
39  * or read caching is not desirable:
40  */
41 extern inline void * ioremap_nocache(unsigned long offset, unsigned long size)
42 {
43         return __ioremap(offset, size, _PAGE_NO_CACHE /* _PAGE_PCD */);
44 }
45
46 extern void iounmap(void *addr);
47
48 /*
49  * __raw_ variants have no defined meaning.  on hppa, it means `i was
50  * too lazy to ioremap first'.  kind of like isa_, except that there's
51  * no additional base address to add on.
52  */
53 #define __raw_readb(a) ___raw_readb((unsigned long)(a))
54 extern __inline__ unsigned char ___raw_readb(unsigned long addr)
55 {
56         long flags;
57         unsigned char ret;
58
59         __asm__ __volatile__(
60         "       rsm     2,%0\n"
61         "       ldbx    0(%2),%1\n"
62         "       mtsm    %0\n"
63         : "=&r" (flags), "=r" (ret) : "r" (addr) );
64
65         return ret;
66 }
67
68 #define __raw_readw(a) ___raw_readw((unsigned long)(a))
69 extern __inline__ unsigned short ___raw_readw(unsigned long addr)
70 {
71         long flags;
72         unsigned short ret;
73
74         __asm__ __volatile__(
75         "       rsm     2,%0\n"
76         "       ldhx    0(%2),%1\n"
77         "       mtsm    %0\n"
78         : "=&r" (flags), "=r" (ret) : "r" (addr) );
79
80         return ret;
81 }
82
83 #define __raw_readl(a) ___raw_readl((unsigned long)(a))
84 extern __inline__ unsigned int ___raw_readl(unsigned long addr)
85 {
86         u32 ret;
87
88         __asm__ __volatile__(
89         "       ldwax   0(%1),%0\n"
90         : "=r" (ret) : "r" (addr) );
91
92         return ret;
93 }
94
95 #define __raw_readq(a) ___raw_readq((unsigned long)(a))
96 extern __inline__ unsigned long long ___raw_readq(unsigned long addr)
97 {
98         unsigned long long ret;
99 #ifdef __LP64__
100         __asm__ __volatile__(
101         "       ldda    0(%1),%0\n"
102         :  "=r" (ret) : "r" (addr) );
103 #else
104         /* two reads may have side effects.. */
105         ret = ((u64) __raw_readl(addr)) << 32;
106         ret |= __raw_readl(addr+4);
107 #endif
108         return ret;
109 }
110
111 #define __raw_writeb(a,b) ___raw_writeb(a, (unsigned long)(b))
112 extern __inline__ void ___raw_writeb(unsigned char val, unsigned long addr)
113 {
114         long flags;
115         __asm__ __volatile__(
116         "       rsm     2,%0\n"
117         "       stbs    %1,0(%2)\n"
118         "       mtsm    %0\n"
119         : "=&r" (flags) :  "r" (val), "r" (addr) );
120 }
121
122 #define __raw_writew(a,b) ___raw_writew(a, (unsigned long)(b))
123 extern __inline__ void ___raw_writew(unsigned short val, unsigned long addr)
124 {
125         long flags;
126         __asm__ __volatile__(
127         "       rsm     2,%0\n"
128         "       sths    %1,0(%2)\n"
129         "       mtsm    %0\n"
130         : "=&r" (flags) :  "r" (val), "r" (addr) );
131 }
132
133 #define __raw_writel(a,b) ___raw_writel(a, (unsigned long)(b))
134 extern __inline__ void ___raw_writel(unsigned int val, unsigned long addr)
135 {
136         __asm__ __volatile__(
137         "       stwas   %0,0(%1)\n"
138         : :  "r" (val), "r" (addr) );
139 }
140
141 #define __raw_writeq(a,b) ___raw_writeq(a, (unsigned long)(b))
142 extern __inline__ void ___raw_writeq(unsigned long long val, unsigned long addr)
143 {
144 #ifdef __LP64__
145         __asm__ __volatile__(
146         "       stda    %0,0(%1)\n"
147         : :  "r" (val), "r" (addr) );
148 #else
149         /* two writes may have side effects.. */
150         __raw_writel(val >> 32, addr);
151         __raw_writel(val, addr+4);
152 #endif
153 }
154
155 #if USE_HPPA_IOREMAP
156 #define readb(addr) (*(volatile unsigned char *) (addr))
157 #define readw(addr) (*(volatile unsigned short *) (addr))
158 #define readl(addr) (*(volatile unsigned int *) (addr))
159 #define readq(addr) (*(volatile u64 *) (addr))
160 #define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
161 #define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
162 #define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
163 #define writeq(b,addr) (*(volatile u64 *) (addr) = (b))
164 #else /* !USE_HPPA_IOREMAP */
165 #define readb(addr) __raw_readb(addr)
166 #define readw(addr) le16_to_cpu(__raw_readw(addr))
167 #define readl(addr) le32_to_cpu(__raw_readl(addr))
168 #define readq(addr) le64_to_cpu(__raw_readq(addr))
169 #define writeb(b,addr) __raw_writeb(b,addr)
170 #define writew(b,addr) __raw_writew(cpu_to_le16(b),addr)
171 #define writel(b,addr) __raw_writel(cpu_to_le32(b),addr)
172 #define writeq(b,addr) __raw_writeq(cpu_to_le64(b),addr)
173 #endif /* !USE_HPPA_IOREMAP */
174
175 #define readb_relaxed(addr) readb(addr)
176 #define readw_relaxed(addr) readw(addr)
177 #define readl_relaxed(addr) readl(addr)
178 #define readq_relaxed(addr) readq(addr)
179
180 extern void __memcpy_fromio(unsigned long dest, unsigned long src, int count);
181 extern void __memcpy_toio(unsigned long dest, unsigned long src, int count);
182 extern void __memset_io(unsigned long dest, char fill, int count);
183
184 #define memcpy_fromio(a,b,c) __memcpy_fromio((unsigned long)(a), (unsigned long)(b), (c))
185 #define memcpy_toio(a,b,c)   __memcpy_toio((unsigned long)(a), (unsigned long)(b), (c))
186 #define memset_io(a,b,c)     __memset_io((unsigned long)(a), (b), (c))
187
188 /* Support old drivers which don't ioremap.
189  * NB this interface is scheduled to disappear in 2.5
190  */
191
192 #define EISA_BASE 0xfffffffffc000000UL
193 #define isa_readb(a) readb(EISA_BASE | (a))
194 #define isa_readw(a) readw(EISA_BASE | (a))
195 #define isa_readl(a) readl(EISA_BASE | (a))
196 #define isa_writeb(b,a) writeb((b), EISA_BASE | (a))
197 #define isa_writew(b,a) writew((b), EISA_BASE | (a))
198 #define isa_writel(b,a) writel((b), EISA_BASE | (a))
199 #define isa_memset_io(a,b,c) memset_io(EISA_BASE | (a), (b), (c))
200 #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a), EISA_BASE | (b), (c))
201 #define isa_memcpy_toio(a,b,c) memcpy_toio(EISA_BASE | (a), (b), (c))
202
203 /* 
204  * These functions support PA-RISC drivers which don't yet call ioremap().
205  * They will disappear once the last of these drivers is gone.
206  */
207 #define gsc_readb(x) __raw_readb(x)
208 #define gsc_readw(x) __raw_readw(x)
209 #define gsc_readl(x) __raw_readl(x)
210 #define gsc_writeb(x, y) __raw_writeb(x, y)
211 #define gsc_writew(x, y) __raw_writew(x, y)
212 #define gsc_writel(x, y) __raw_writel(x, y)
213
214
215 /*
216  * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and 
217  * just copy it. The net code will then do the checksum later. Presently 
218  * only used by some shared memory 8390 Ethernet cards anyway.
219  */
220
221 #define eth_io_copy_and_sum(skb,src,len,unused) \
222   memcpy_fromio((skb)->data,(src),(len))
223 #define isa_eth_io_copy_and_sum(skb,src,len,unused) \
224   isa_memcpy_fromio((skb)->data,(src),(len))
225
226 /* Port-space IO */
227
228 #define inb_p inb
229 #define inw_p inw
230 #define inl_p inl
231 #define outb_p outb
232 #define outw_p outw
233 #define outl_p outl
234
235 extern unsigned char eisa_in8(unsigned short port);
236 extern unsigned short eisa_in16(unsigned short port);
237 extern unsigned int eisa_in32(unsigned short port);
238 extern void eisa_out8(unsigned char data, unsigned short port);
239 extern void eisa_out16(unsigned short data, unsigned short port);
240 extern void eisa_out32(unsigned int data, unsigned short port);
241
242 #if defined(CONFIG_PCI)
243 extern unsigned char inb(int addr);
244 extern unsigned short inw(int addr);
245 extern unsigned int inl(int addr);
246
247 extern void outb(unsigned char b, int addr);
248 extern void outw(unsigned short b, int addr);
249 extern void outl(unsigned int b, int addr);
250 #elif defined(CONFIG_EISA)
251 #define inb eisa_in8
252 #define inw eisa_in16
253 #define inl eisa_in32
254 #define outb eisa_out8
255 #define outw eisa_out16
256 #define outl eisa_out32
257 #else
258 static inline char inb(unsigned long addr)
259 {
260         BUG();
261         return -1;
262 }
263
264 static inline short inw(unsigned long addr)
265 {
266         BUG();
267         return -1;
268 }
269
270 static inline int inl(unsigned long addr)
271 {
272         BUG();
273         return -1;
274 }
275
276 #define outb(x, y)      BUG()
277 #define outw(x, y)      BUG()
278 #define outl(x, y)      BUG()
279 #endif
280
281 /*
282  * String versions of in/out ops:
283  */
284 extern void insb (unsigned long port, void *dst, unsigned long count);
285 extern void insw (unsigned long port, void *dst, unsigned long count);
286 extern void insl (unsigned long port, void *dst, unsigned long count);
287 extern void outsb (unsigned long port, const void *src, unsigned long count);
288 extern void outsw (unsigned long port, const void *src, unsigned long count);
289 extern void outsl (unsigned long port, const void *src, unsigned long count);
290
291
292 /* IO Port space is :      BBiiii   where BB is HBA number. */
293 #define IO_SPACE_LIMIT 0x00ffffff
294
295
296 #define dma_cache_inv(_start,_size)             do { flush_kernel_dcache_range(_start,_size); } while (0)
297 #define dma_cache_wback(_start,_size)           do { flush_kernel_dcache_range(_start,_size); } while (0)
298 #define dma_cache_wback_inv(_start,_size)       do { flush_kernel_dcache_range(_start,_size); } while (0)
299
300 /* PA machines have an MM I/O space from 0xf0000000-0xffffffff in 32
301  * bit mode and from 0xfffffffff0000000-0xfffffffffffffff in 64 bit
302  * mode (essentially just sign extending.  This macro takes in a 32
303  * bit I/O address (still with the leading f) and outputs the correct
304  * value for either 32 or 64 bit mode */
305 #define F_EXTEND(x) ((unsigned long)((x) | (0xffffffff00000000ULL)))
306
307 #endif