Linux-2.6.12-rc2
[deliverable/linux.git] / include / asm-parisc / io.h
1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3
4 #include <linux/config.h>
5 #include <linux/types.h>
6 #include <asm/pgtable.h>
7
8 extern unsigned long parisc_vmerge_boundary;
9 extern unsigned long parisc_vmerge_max_size;
10
11 #define BIO_VMERGE_BOUNDARY parisc_vmerge_boundary
12 #define BIO_VMERGE_MAX_SIZE parisc_vmerge_max_size
13
14 #define virt_to_phys(a) ((unsigned long)__pa(a))
15 #define phys_to_virt(a) __va(a)
16 #define virt_to_bus virt_to_phys
17 #define bus_to_virt phys_to_virt
18
19 /*
20 * Memory mapped I/O
21 *
22 * readX()/writeX() do byteswapping and take an ioremapped address
23 * __raw_readX()/__raw_writeX() don't byteswap and take an ioremapped address.
24 * gsc_*() don't byteswap and operate on physical addresses;
25 * eg dev->hpa or 0xfee00000.
26 */
27
28 #ifdef CONFIG_DEBUG_IOREMAP
29 #ifdef CONFIG_64BIT
30 #define NYBBLE_SHIFT 60
31 #else
32 #define NYBBLE_SHIFT 28
33 #endif
34 extern void gsc_bad_addr(unsigned long addr);
35 extern void __raw_bad_addr(const volatile void __iomem *addr);
36 #define gsc_check_addr(addr) \
37 if ((addr >> NYBBLE_SHIFT) != 0xf) { \
38 gsc_bad_addr(addr); \
39 addr |= 0xfUL << NYBBLE_SHIFT; \
40 }
41 #define __raw_check_addr(addr) \
42 if (((unsigned long)addr >> NYBBLE_SHIFT) != 0xe) \
43 __raw_bad_addr(addr); \
44 addr = (void *)((unsigned long)addr | (0xfUL << NYBBLE_SHIFT));
45 #else
46 #define gsc_check_addr(addr)
47 #define __raw_check_addr(addr)
48 #endif
49
50 static inline unsigned char gsc_readb(unsigned long addr)
51 {
52 long flags;
53 unsigned char ret;
54
55 gsc_check_addr(addr);
56
57 __asm__ __volatile__(
58 " rsm 2,%0\n"
59 " ldbx 0(%2),%1\n"
60 " mtsm %0\n"
61 : "=&r" (flags), "=r" (ret) : "r" (addr) );
62
63 return ret;
64 }
65
66 static inline unsigned short gsc_readw(unsigned long addr)
67 {
68 long flags;
69 unsigned short ret;
70
71 gsc_check_addr(addr);
72
73 __asm__ __volatile__(
74 " rsm 2,%0\n"
75 " ldhx 0(%2),%1\n"
76 " mtsm %0\n"
77 : "=&r" (flags), "=r" (ret) : "r" (addr) );
78
79 return ret;
80 }
81
82 static inline unsigned int gsc_readl(unsigned long addr)
83 {
84 u32 ret;
85
86 gsc_check_addr(addr);
87
88 __asm__ __volatile__(
89 " ldwax 0(%1),%0\n"
90 : "=r" (ret) : "r" (addr) );
91
92 return ret;
93 }
94
95 static inline unsigned long long gsc_readq(unsigned long addr)
96 {
97 unsigned long long ret;
98 gsc_check_addr(addr);
99
100 #ifdef __LP64__
101 __asm__ __volatile__(
102 " ldda 0(%1),%0\n"
103 : "=r" (ret) : "r" (addr) );
104 #else
105 /* two reads may have side effects.. */
106 ret = ((u64) gsc_readl(addr)) << 32;
107 ret |= gsc_readl(addr+4);
108 #endif
109 return ret;
110 }
111
112 static inline void gsc_writeb(unsigned char val, unsigned long addr)
113 {
114 long flags;
115 gsc_check_addr(addr);
116
117 __asm__ __volatile__(
118 " rsm 2,%0\n"
119 " stbs %1,0(%2)\n"
120 " mtsm %0\n"
121 : "=&r" (flags) : "r" (val), "r" (addr) );
122 }
123
124 static inline void gsc_writew(unsigned short val, unsigned long addr)
125 {
126 long flags;
127 gsc_check_addr(addr);
128
129 __asm__ __volatile__(
130 " rsm 2,%0\n"
131 " sths %1,0(%2)\n"
132 " mtsm %0\n"
133 : "=&r" (flags) : "r" (val), "r" (addr) );
134 }
135
136 static inline void gsc_writel(unsigned int val, unsigned long addr)
137 {
138 gsc_check_addr(addr);
139
140 __asm__ __volatile__(
141 " stwas %0,0(%1)\n"
142 : : "r" (val), "r" (addr) );
143 }
144
145 static inline void gsc_writeq(unsigned long long val, unsigned long addr)
146 {
147 gsc_check_addr(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 gsc_writel(val >> 32, addr);
156 gsc_writel(val, addr+4);
157 #endif
158 }
159
160 /*
161 * The standard PCI ioremap interfaces
162 */
163
164 extern void __iomem * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
165
166 extern inline void __iomem * ioremap(unsigned long offset, unsigned long size)
167 {
168 return __ioremap(offset, size, 0);
169 }
170
171 /*
172 * This one maps high address device memory and turns off caching for that area.
173 * it's useful if some control registers are in such an area and write combining
174 * or read caching is not desirable:
175 */
176 extern inline void * ioremap_nocache(unsigned long offset, unsigned long size)
177 {
178 return __ioremap(offset, size, _PAGE_NO_CACHE /* _PAGE_PCD */);
179 }
180
181 extern void iounmap(void __iomem *addr);
182
183 /*
184 * USE_HPPA_IOREMAP is the magic flag to enable or disable real ioremap()
185 * functionality. It's currently disabled because it may not work on some
186 * machines.
187 */
188 #define USE_HPPA_IOREMAP 0
189
190 #if USE_HPPA_IOREMAP
191 static inline unsigned char __raw_readb(const volatile void __iomem *addr)
192 {
193 return (*(volatile unsigned char __force *) (addr));
194 }
195 static inline unsigned short __raw_readw(const volatile void __iomem *addr)
196 {
197 return *(volatile unsigned short __force *) addr;
198 }
199 static inline unsigned int __raw_readl(const volatile void __iomem *addr)
200 {
201 return *(volatile unsigned int __force *) addr;
202 }
203 static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
204 {
205 return *(volatile unsigned long long __force *) addr;
206 }
207
208 static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
209 {
210 *(volatile unsigned char __force *) addr = b;
211 }
212 static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
213 {
214 *(volatile unsigned short __force *) addr = b;
215 }
216 static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
217 {
218 *(volatile unsigned int __force *) addr = b;
219 }
220 static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
221 {
222 *(volatile unsigned long long __force *) addr = b;
223 }
224 #else /* !USE_HPPA_IOREMAP */
225 static inline unsigned char __raw_readb(const volatile void __iomem *addr)
226 {
227 __raw_check_addr(addr);
228
229 return gsc_readb((unsigned long) addr);
230 }
231 static inline unsigned short __raw_readw(const volatile void __iomem *addr)
232 {
233 __raw_check_addr(addr);
234
235 return gsc_readw((unsigned long) addr);
236 }
237 static inline unsigned int __raw_readl(const volatile void __iomem *addr)
238 {
239 __raw_check_addr(addr);
240
241 return gsc_readl((unsigned long) addr);
242 }
243 static inline unsigned long long __raw_readq(const volatile void __iomem *addr)
244 {
245 __raw_check_addr(addr);
246
247 return gsc_readq((unsigned long) addr);
248 }
249
250 static inline void __raw_writeb(unsigned char b, volatile void __iomem *addr)
251 {
252 __raw_check_addr(addr);
253
254 gsc_writeb(b, (unsigned long) addr);
255 }
256 static inline void __raw_writew(unsigned short b, volatile void __iomem *addr)
257 {
258 __raw_check_addr(addr);
259
260 gsc_writew(b, (unsigned long) addr);
261 }
262 static inline void __raw_writel(unsigned int b, volatile void __iomem *addr)
263 {
264 __raw_check_addr(addr);
265
266 gsc_writel(b, (unsigned long) addr);
267 }
268 static inline void __raw_writeq(unsigned long long b, volatile void __iomem *addr)
269 {
270 __raw_check_addr(addr);
271
272 gsc_writeq(b, (unsigned long) addr);
273 }
274 #endif /* !USE_HPPA_IOREMAP */
275
276 /* readb can never be const, so use __fswab instead of le*_to_cpu */
277 #define readb(addr) __raw_readb(addr)
278 #define readw(addr) __fswab16(__raw_readw(addr))
279 #define readl(addr) __fswab32(__raw_readl(addr))
280 #define readq(addr) __fswab64(__raw_readq(addr))
281 #define writeb(b, addr) __raw_writeb(b, addr)
282 #define writew(b, addr) __raw_writew(cpu_to_le16(b), addr)
283 #define writel(b, addr) __raw_writel(cpu_to_le32(b), addr)
284 #define writeq(b, addr) __raw_writeq(cpu_to_le64(b), addr)
285
286 #define readb_relaxed(addr) readb(addr)
287 #define readw_relaxed(addr) readw(addr)
288 #define readl_relaxed(addr) readl(addr)
289 #define readq_relaxed(addr) readq(addr)
290
291 #define mmiowb() do { } while (0)
292
293 void memset_io(volatile void __iomem *addr, unsigned char val, int count);
294 void memcpy_fromio(void *dst, const volatile void __iomem *src, int count);
295 void memcpy_toio(volatile void __iomem *dst, const void *src, int count);
296
297 /* Support old drivers which don't ioremap.
298 * NB this interface is scheduled to disappear in 2.5
299 */
300
301 #define __isa_addr(x) (void __iomem *)(F_EXTEND(0xfc000000) | (x))
302 #define isa_readb(a) readb(__isa_addr(a))
303 #define isa_readw(a) readw(__isa_addr(a))
304 #define isa_readl(a) readl(__isa_addr(a))
305 #define isa_writeb(b,a) writeb((b), __isa_addr(a))
306 #define isa_writew(b,a) writew((b), __isa_addr(a))
307 #define isa_writel(b,a) writel((b), __isa_addr(a))
308 #define isa_memset_io(a,b,c) memset_io(__isa_addr(a), (b), (c))
309 #define isa_memcpy_fromio(a,b,c) memcpy_fromio((a), __isa_addr(b), (c))
310 #define isa_memcpy_toio(a,b,c) memcpy_toio(__isa_addr(a), (b), (c))
311
312
313 /*
314 * XXX - We don't have csum_partial_copy_fromio() yet, so we cheat here and
315 * just copy it. The net code will then do the checksum later. Presently
316 * only used by some shared memory 8390 Ethernet cards anyway.
317 */
318
319 #define eth_io_copy_and_sum(skb,src,len,unused) \
320 memcpy_fromio((skb)->data,(src),(len))
321 #define isa_eth_io_copy_and_sum(skb,src,len,unused) \
322 isa_memcpy_fromio((skb)->data,(src),(len))
323
324 /* Port-space IO */
325
326 #define inb_p inb
327 #define inw_p inw
328 #define inl_p inl
329 #define outb_p outb
330 #define outw_p outw
331 #define outl_p outl
332
333 extern unsigned char eisa_in8(unsigned short port);
334 extern unsigned short eisa_in16(unsigned short port);
335 extern unsigned int eisa_in32(unsigned short port);
336 extern void eisa_out8(unsigned char data, unsigned short port);
337 extern void eisa_out16(unsigned short data, unsigned short port);
338 extern void eisa_out32(unsigned int data, unsigned short port);
339
340 #if defined(CONFIG_PCI)
341 extern unsigned char inb(int addr);
342 extern unsigned short inw(int addr);
343 extern unsigned int inl(int addr);
344
345 extern void outb(unsigned char b, int addr);
346 extern void outw(unsigned short b, int addr);
347 extern void outl(unsigned int b, int addr);
348 #elif defined(CONFIG_EISA)
349 #define inb eisa_in8
350 #define inw eisa_in16
351 #define inl eisa_in32
352 #define outb eisa_out8
353 #define outw eisa_out16
354 #define outl eisa_out32
355 #else
356 static inline char inb(unsigned long addr)
357 {
358 BUG();
359 return -1;
360 }
361
362 static inline short inw(unsigned long addr)
363 {
364 BUG();
365 return -1;
366 }
367
368 static inline int inl(unsigned long addr)
369 {
370 BUG();
371 return -1;
372 }
373
374 #define outb(x, y) BUG()
375 #define outw(x, y) BUG()
376 #define outl(x, y) BUG()
377 #endif
378
379 /*
380 * String versions of in/out ops:
381 */
382 extern void insb (unsigned long port, void *dst, unsigned long count);
383 extern void insw (unsigned long port, void *dst, unsigned long count);
384 extern void insl (unsigned long port, void *dst, unsigned long count);
385 extern void outsb (unsigned long port, const void *src, unsigned long count);
386 extern void outsw (unsigned long port, const void *src, unsigned long count);
387 extern void outsl (unsigned long port, const void *src, unsigned long count);
388
389
390 /* IO Port space is : BBiiii where BB is HBA number. */
391 #define IO_SPACE_LIMIT 0x00ffffff
392
393
394 #define dma_cache_inv(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
395 #define dma_cache_wback(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
396 #define dma_cache_wback_inv(_start,_size) do { flush_kernel_dcache_range(_start,_size); } while (0)
397
398 /* PA machines have an MM I/O space from 0xf0000000-0xffffffff in 32
399 * bit mode and from 0xfffffffff0000000-0xfffffffffffffff in 64 bit
400 * mode (essentially just sign extending. This macro takes in a 32
401 * bit I/O address (still with the leading f) and outputs the correct
402 * value for either 32 or 64 bit mode */
403 #define F_EXTEND(x) ((unsigned long)((x) | (0xffffffff00000000ULL)))
404
405 #include <asm-generic/iomap.h>
406
407 /*
408 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
409 * access
410 */
411 #define xlate_dev_mem_ptr(p) __va(p)
412
413 /*
414 * Convert a virtual cached pointer to an uncached pointer
415 */
416 #define xlate_dev_kmem_ptr(p) p
417
418 #endif
This page took 0.049679 seconds and 5 git commands to generate.