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