1 /* $Id: io.h,v 1.47 2001/12/13 10:36:02 davem Exp $ */
5 #include <linux/kernel.h>
6 #include <linux/compiler.h>
7 #include <linux/types.h>
9 #include <asm/page.h> /* IO address mapping routines need this */
10 #include <asm/system.h>
14 #define __SLOW_DOWN_IO do { } while (0)
15 #define SLOW_DOWN_IO do { } while (0)
17 /* BIO layer definitions. */
18 extern unsigned long kern_base
, kern_size
;
19 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
20 #define BIO_VMERGE_BOUNDARY 8192
22 static __inline__ u8
_inb(unsigned long addr
)
26 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_inb */"
28 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
33 static __inline__ u16
_inw(unsigned long addr
)
37 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_inw */"
39 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
44 static __inline__ u32
_inl(unsigned long addr
)
48 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_inl */"
50 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
55 static __inline__
void _outb(u8 b
, unsigned long addr
)
57 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_outb */"
59 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
62 static __inline__
void _outw(u16 w
, unsigned long addr
)
64 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_outw */"
66 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
69 static __inline__
void _outl(u32 l
, unsigned long addr
)
71 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_outl */"
73 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
76 #define inb(__addr) (_inb((unsigned long)(__addr)))
77 #define inw(__addr) (_inw((unsigned long)(__addr)))
78 #define inl(__addr) (_inl((unsigned long)(__addr)))
79 #define outb(__b, __addr) (_outb((u8)(__b), (unsigned long)(__addr)))
80 #define outw(__w, __addr) (_outw((u16)(__w), (unsigned long)(__addr)))
81 #define outl(__l, __addr) (_outl((u32)(__l), (unsigned long)(__addr)))
83 #define inb_p(__addr) inb(__addr)
84 #define outb_p(__b, __addr) outb(__b, __addr)
85 #define inw_p(__addr) inw(__addr)
86 #define outw_p(__w, __addr) outw(__w, __addr)
87 #define inl_p(__addr) inl(__addr)
88 #define outl_p(__l, __addr) outl(__l, __addr)
90 extern void outsb(unsigned long, const void *, unsigned long);
91 extern void outsw(unsigned long, const void *, unsigned long);
92 extern void outsl(unsigned long, const void *, unsigned long);
93 extern void insb(unsigned long, void *, unsigned long);
94 extern void insw(unsigned long, void *, unsigned long);
95 extern void insl(unsigned long, void *, unsigned long);
97 static inline void ioread8_rep(void __iomem
*port
, void *buf
, unsigned long count
)
99 insb((unsigned long __force
)port
, buf
, count
);
101 static inline void ioread16_rep(void __iomem
*port
, void *buf
, unsigned long count
)
103 insw((unsigned long __force
)port
, buf
, count
);
106 static inline void ioread32_rep(void __iomem
*port
, void *buf
, unsigned long count
)
108 insl((unsigned long __force
)port
, buf
, count
);
111 static inline void iowrite8_rep(void __iomem
*port
, const void *buf
, unsigned long count
)
113 outsb((unsigned long __force
)port
, buf
, count
);
116 static inline void iowrite16_rep(void __iomem
*port
, const void *buf
, unsigned long count
)
118 outsw((unsigned long __force
)port
, buf
, count
);
121 static inline void iowrite32_rep(void __iomem
*port
, const void *buf
, unsigned long count
)
123 outsl((unsigned long __force
)port
, buf
, count
);
126 /* Memory functions, same as I/O accesses on Ultra. */
127 static inline u8
_readb(const volatile void __iomem
*addr
)
130 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
132 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
136 static inline u16
_readw(const volatile void __iomem
*addr
)
139 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
141 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
146 static inline u32
_readl(const volatile void __iomem
*addr
)
149 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
151 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
156 static inline u64
_readq(const volatile void __iomem
*addr
)
159 __asm__
__volatile__("ldxa\t[%1] %2, %0\t/* pci_readq */"
161 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
166 static inline void _writeb(u8 b
, volatile void __iomem
*addr
)
168 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
170 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
173 static inline void _writew(u16 w
, volatile void __iomem
*addr
)
175 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
177 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
180 static inline void _writel(u32 l
, volatile void __iomem
*addr
)
182 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
184 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
187 static inline void _writeq(u64 q
, volatile void __iomem
*addr
)
189 __asm__
__volatile__("stxa\t%r0, [%1] %2\t/* pci_writeq */"
191 : "Jr" (q
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
194 #define readb(__addr) _readb(__addr)
195 #define readw(__addr) _readw(__addr)
196 #define readl(__addr) _readl(__addr)
197 #define readq(__addr) _readq(__addr)
198 #define readb_relaxed(__addr) _readb(__addr)
199 #define readw_relaxed(__addr) _readw(__addr)
200 #define readl_relaxed(__addr) _readl(__addr)
201 #define readq_relaxed(__addr) _readq(__addr)
202 #define writeb(__b, __addr) _writeb(__b, __addr)
203 #define writew(__w, __addr) _writew(__w, __addr)
204 #define writel(__l, __addr) _writel(__l, __addr)
205 #define writeq(__q, __addr) _writeq(__q, __addr)
207 /* Now versions without byte-swapping. */
208 static __inline__ u8
_raw_readb(unsigned long addr
)
212 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
214 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
219 static __inline__ u16
_raw_readw(unsigned long addr
)
223 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
225 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
230 static __inline__ u32
_raw_readl(unsigned long addr
)
234 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
236 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
241 static __inline__ u64
_raw_readq(unsigned long addr
)
245 __asm__
__volatile__("ldxa\t[%1] %2, %0\t/* pci_raw_readq */"
247 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
252 static __inline__
void _raw_writeb(u8 b
, unsigned long addr
)
254 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
256 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
259 static __inline__
void _raw_writew(u16 w
, unsigned long addr
)
261 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
263 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
266 static __inline__
void _raw_writel(u32 l
, unsigned long addr
)
268 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
270 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
273 static __inline__
void _raw_writeq(u64 q
, unsigned long addr
)
275 __asm__
__volatile__("stxa\t%r0, [%1] %2\t/* pci_raw_writeq */"
277 : "Jr" (q
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
280 #define __raw_readb(__addr) (_raw_readb((unsigned long)(__addr)))
281 #define __raw_readw(__addr) (_raw_readw((unsigned long)(__addr)))
282 #define __raw_readl(__addr) (_raw_readl((unsigned long)(__addr)))
283 #define __raw_readq(__addr) (_raw_readq((unsigned long)(__addr)))
284 #define __raw_writeb(__b, __addr) (_raw_writeb((u8)(__b), (unsigned long)(__addr)))
285 #define __raw_writew(__w, __addr) (_raw_writew((u16)(__w), (unsigned long)(__addr)))
286 #define __raw_writel(__l, __addr) (_raw_writel((u32)(__l), (unsigned long)(__addr)))
287 #define __raw_writeq(__q, __addr) (_raw_writeq((u64)(__q), (unsigned long)(__addr)))
289 /* Valid I/O Space regions are anywhere, because each PCI bus supported
290 * can live in an arbitrary area of the physical address range.
292 #define IO_SPACE_LIMIT 0xffffffffffffffffUL
294 /* Now, SBUS variants, only difference from PCI is that we do
295 * not use little-endian ASIs.
297 static inline u8
_sbus_readb(const volatile void __iomem
*addr
)
301 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* sbus_readb */"
303 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
308 static inline u16
_sbus_readw(const volatile void __iomem
*addr
)
312 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* sbus_readw */"
314 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
319 static inline u32
_sbus_readl(const volatile void __iomem
*addr
)
323 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* sbus_readl */"
325 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
330 static inline u64
_sbus_readq(const volatile void __iomem
*addr
)
334 __asm__
__volatile__("ldxa\t[%1] %2, %0\t/* sbus_readq */"
336 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
341 static inline void _sbus_writeb(u8 b
, volatile void __iomem
*addr
)
343 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* sbus_writeb */"
345 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
348 static inline void _sbus_writew(u16 w
, volatile void __iomem
*addr
)
350 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* sbus_writew */"
352 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
355 static inline void _sbus_writel(u32 l
, volatile void __iomem
*addr
)
357 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* sbus_writel */"
359 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
362 static inline void _sbus_writeq(u64 l
, volatile void __iomem
*addr
)
364 __asm__
__volatile__("stxa\t%r0, [%1] %2\t/* sbus_writeq */"
366 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
369 #define sbus_readb(__addr) _sbus_readb(__addr)
370 #define sbus_readw(__addr) _sbus_readw(__addr)
371 #define sbus_readl(__addr) _sbus_readl(__addr)
372 #define sbus_readq(__addr) _sbus_readq(__addr)
373 #define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
374 #define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
375 #define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
376 #define sbus_writeq(__l, __addr) _sbus_writeq(__l, __addr)
378 static inline void _sbus_memset_io(volatile void __iomem
*dst
, int c
, __kernel_size_t n
)
386 #define sbus_memset_io(d,c,sz) _sbus_memset_io(d,c,sz)
389 _memset_io(volatile void __iomem
*dst
, int c
, __kernel_size_t n
)
391 volatile void __iomem
*d
= dst
;
399 #define memset_io(d,c,sz) _memset_io(d,c,sz)
402 _memcpy_fromio(void *dst
, const volatile void __iomem
*src
, __kernel_size_t n
)
407 char tmp
= readb(src
);
413 #define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
416 _memcpy_toio(volatile void __iomem
*dst
, const void *src
, __kernel_size_t n
)
419 volatile void __iomem
*d
= dst
;
428 #define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
434 /* On sparc64 we have the whole physical IO address space accessible
435 * using physically addressed loads and stores, so this does nothing.
437 static inline void __iomem
*ioremap(unsigned long offset
, unsigned long size
)
439 return (void __iomem
*)offset
;
442 #define ioremap_nocache(X,Y) ioremap((X),(Y))
444 static inline void iounmap(volatile void __iomem
*addr
)
448 #define ioread8(X) readb(X)
449 #define ioread16(X) readw(X)
450 #define ioread32(X) readl(X)
451 #define iowrite8(val,X) writeb(val,X)
452 #define iowrite16(val,X) writew(val,X)
453 #define iowrite32(val,X) writel(val,X)
455 /* Create a virtual mapping cookie for an IO port range */
456 extern void __iomem
*ioport_map(unsigned long port
, unsigned int nr
);
457 extern void ioport_unmap(void __iomem
*);
459 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
461 extern void __iomem
*pci_iomap(struct pci_dev
*dev
, int bar
, unsigned long max
);
462 extern void pci_iounmap(struct pci_dev
*dev
, void __iomem
*);
464 /* Similarly for SBUS. */
465 #define sbus_ioremap(__res, __offset, __size, __name) \
466 ({ unsigned long __ret; \
467 __ret = (__res)->start + (((__res)->flags & 0x1ffUL) << 32UL); \
468 __ret += (unsigned long) (__offset); \
469 if (! request_region((__ret), (__size), (__name))) \
471 (void __iomem *) __ret; \
474 #define sbus_iounmap(__addr, __size) \
475 release_region((unsigned long)(__addr), (__size))
479 #define dma_cache_inv(_start,_size) do { } while (0)
480 #define dma_cache_wback(_start,_size) do { } while (0)
481 #define dma_cache_wback_inv(_start,_size) do { } while (0)
484 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
487 #define xlate_dev_mem_ptr(p) __va(p)
490 * Convert a virtual cached pointer to an uncached pointer
492 #define xlate_dev_kmem_ptr(p) p
496 #endif /* !(__SPARC64_IO_H) */