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