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 extern unsigned long virt_to_bus_not_defined_use_pci_map(volatile void *addr
);
18 #define virt_to_bus virt_to_bus_not_defined_use_pci_map
19 extern unsigned long bus_to_virt_not_defined_use_pci_map(volatile void *addr
);
20 #define bus_to_virt bus_to_virt_not_defined_use_pci_map
22 /* BIO layer definitions. */
23 extern unsigned long kern_base
, kern_size
;
24 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
25 #define BIO_VMERGE_BOUNDARY 8192
27 /* Different PCI controllers we support have their PCI MEM space
28 * mapped to an either 2GB (Psycho) or 4GB (Sabre) aligned area,
29 * so need to chop off the top 33 or 32 bits.
31 extern unsigned long pci_memspace_mask
;
33 #define bus_dvma_to_mem(__vaddr) ((__vaddr) & pci_memspace_mask)
35 static __inline__ u8
_inb(unsigned long addr
)
39 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_inb */"
41 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
46 static __inline__ u16
_inw(unsigned long addr
)
50 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_inw */"
52 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
57 static __inline__ u32
_inl(unsigned long addr
)
61 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_inl */"
63 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
68 static __inline__
void _outb(u8 b
, unsigned long addr
)
70 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_outb */"
72 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
75 static __inline__
void _outw(u16 w
, unsigned long addr
)
77 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_outw */"
79 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
82 static __inline__
void _outl(u32 l
, unsigned long addr
)
84 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_outl */"
86 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
89 #define inb(__addr) (_inb((unsigned long)(__addr)))
90 #define inw(__addr) (_inw((unsigned long)(__addr)))
91 #define inl(__addr) (_inl((unsigned long)(__addr)))
92 #define outb(__b, __addr) (_outb((u8)(__b), (unsigned long)(__addr)))
93 #define outw(__w, __addr) (_outw((u16)(__w), (unsigned long)(__addr)))
94 #define outl(__l, __addr) (_outl((u32)(__l), (unsigned long)(__addr)))
96 #define inb_p(__addr) inb(__addr)
97 #define outb_p(__b, __addr) outb(__b, __addr)
98 #define inw_p(__addr) inw(__addr)
99 #define outw_p(__w, __addr) outw(__w, __addr)
100 #define inl_p(__addr) inl(__addr)
101 #define outl_p(__l, __addr) outl(__l, __addr)
103 extern void outsb(void __iomem
*addr
, const void *src
, unsigned long count
);
104 extern void outsw(void __iomem
*addr
, const void *src
, unsigned long count
);
105 extern void outsl(void __iomem
*addr
, const void *src
, unsigned long count
);
106 extern void insb(void __iomem
*addr
, void *dst
, unsigned long count
);
107 extern void insw(void __iomem
*addr
, void *dst
, unsigned long count
);
108 extern void insl(void __iomem
*addr
, void *dst
, unsigned long count
);
109 #define ioread8_rep(a,d,c) insb(a,d,c)
110 #define ioread16_rep(a,d,c) insw(a,d,c)
111 #define ioread32_rep(a,d,c) insl(a,d,c)
112 #define iowrite8_rep(a,s,c) outsb(a,s,c)
113 #define iowrite16_rep(a,s,c) outsw(a,s,c)
114 #define iowrite32_rep(a,s,c) outsl(a,s,c)
116 /* Memory functions, same as I/O accesses on Ultra. */
117 static inline u8
_readb(const volatile void __iomem
*addr
)
120 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
122 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
126 static inline u16
_readw(const volatile void __iomem
*addr
)
129 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
131 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
136 static inline u32
_readl(const volatile void __iomem
*addr
)
139 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
141 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
146 static inline u64
_readq(const volatile void __iomem
*addr
)
149 __asm__
__volatile__("ldxa\t[%1] %2, %0\t/* pci_readq */"
151 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
156 static inline void _writeb(u8 b
, volatile void __iomem
*addr
)
158 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
160 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
163 static inline void _writew(u16 w
, volatile void __iomem
*addr
)
165 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
167 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
170 static inline void _writel(u32 l
, volatile void __iomem
*addr
)
172 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
174 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
177 static inline void _writeq(u64 q
, volatile void __iomem
*addr
)
179 __asm__
__volatile__("stxa\t%r0, [%1] %2\t/* pci_writeq */"
181 : "Jr" (q
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
184 #define readb(__addr) _readb(__addr)
185 #define readw(__addr) _readw(__addr)
186 #define readl(__addr) _readl(__addr)
187 #define readq(__addr) _readq(__addr)
188 #define readb_relaxed(__addr) _readb(__addr)
189 #define readw_relaxed(__addr) _readw(__addr)
190 #define readl_relaxed(__addr) _readl(__addr)
191 #define readq_relaxed(__addr) _readq(__addr)
192 #define writeb(__b, __addr) _writeb(__b, __addr)
193 #define writew(__w, __addr) _writew(__w, __addr)
194 #define writel(__l, __addr) _writel(__l, __addr)
195 #define writeq(__q, __addr) _writeq(__q, __addr)
197 /* Now versions without byte-swapping. */
198 static __inline__ u8
_raw_readb(unsigned long addr
)
202 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
204 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
209 static __inline__ u16
_raw_readw(unsigned long addr
)
213 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
215 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
220 static __inline__ u32
_raw_readl(unsigned long addr
)
224 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
226 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
231 static __inline__ u64
_raw_readq(unsigned long addr
)
235 __asm__
__volatile__("ldxa\t[%1] %2, %0\t/* pci_raw_readq */"
237 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
242 static __inline__
void _raw_writeb(u8 b
, unsigned long addr
)
244 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
246 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
249 static __inline__
void _raw_writew(u16 w
, unsigned long addr
)
251 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
253 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
256 static __inline__
void _raw_writel(u32 l
, unsigned long addr
)
258 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
260 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
263 static __inline__
void _raw_writeq(u64 q
, unsigned long addr
)
265 __asm__
__volatile__("stxa\t%r0, [%1] %2\t/* pci_raw_writeq */"
267 : "Jr" (q
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
270 #define __raw_readb(__addr) (_raw_readb((unsigned long)(__addr)))
271 #define __raw_readw(__addr) (_raw_readw((unsigned long)(__addr)))
272 #define __raw_readl(__addr) (_raw_readl((unsigned long)(__addr)))
273 #define __raw_readq(__addr) (_raw_readq((unsigned long)(__addr)))
274 #define __raw_writeb(__b, __addr) (_raw_writeb((u8)(__b), (unsigned long)(__addr)))
275 #define __raw_writew(__w, __addr) (_raw_writew((u16)(__w), (unsigned long)(__addr)))
276 #define __raw_writel(__l, __addr) (_raw_writel((u32)(__l), (unsigned long)(__addr)))
277 #define __raw_writeq(__q, __addr) (_raw_writeq((u64)(__q), (unsigned long)(__addr)))
279 /* Valid I/O Space regions are anywhere, because each PCI bus supported
280 * can live in an arbitrary area of the physical address range.
282 #define IO_SPACE_LIMIT 0xffffffffffffffffUL
284 /* Now, SBUS variants, only difference from PCI is that we do
285 * not use little-endian ASIs.
287 static inline u8
_sbus_readb(const volatile void __iomem
*addr
)
291 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* sbus_readb */"
293 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
298 static inline u16
_sbus_readw(const volatile void __iomem
*addr
)
302 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* sbus_readw */"
304 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
309 static inline u32
_sbus_readl(const volatile void __iomem
*addr
)
313 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* sbus_readl */"
315 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
320 static inline u64
_sbus_readq(const volatile void __iomem
*addr
)
324 __asm__
__volatile__("ldxa\t[%1] %2, %0\t/* sbus_readq */"
326 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
331 static inline void _sbus_writeb(u8 b
, volatile void __iomem
*addr
)
333 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* sbus_writeb */"
335 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
338 static inline void _sbus_writew(u16 w
, volatile void __iomem
*addr
)
340 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* sbus_writew */"
342 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
345 static inline void _sbus_writel(u32 l
, volatile void __iomem
*addr
)
347 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* sbus_writel */"
349 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
352 static inline void _sbus_writeq(u64 l
, volatile void __iomem
*addr
)
354 __asm__
__volatile__("stxa\t%r0, [%1] %2\t/* sbus_writeq */"
356 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
359 #define sbus_readb(__addr) _sbus_readb(__addr)
360 #define sbus_readw(__addr) _sbus_readw(__addr)
361 #define sbus_readl(__addr) _sbus_readl(__addr)
362 #define sbus_readq(__addr) _sbus_readq(__addr)
363 #define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
364 #define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
365 #define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
366 #define sbus_writeq(__l, __addr) _sbus_writeq(__l, __addr)
368 static inline void _sbus_memset_io(volatile void __iomem
*dst
, int c
, __kernel_size_t n
)
376 #define sbus_memset_io(d,c,sz) _sbus_memset_io(d,c,sz)
379 _memset_io(volatile void __iomem
*dst
, int c
, __kernel_size_t n
)
381 volatile void __iomem
*d
= dst
;
389 #define memset_io(d,c,sz) _memset_io(d,c,sz)
392 _memcpy_fromio(void *dst
, const volatile void __iomem
*src
, __kernel_size_t n
)
397 char tmp
= readb(src
);
403 #define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
406 _memcpy_toio(volatile void __iomem
*dst
, const void *src
, __kernel_size_t n
)
409 volatile void __iomem
*d
= dst
;
418 #define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
420 static inline int check_signature(void __iomem
*io_addr
,
421 const unsigned char *signature
,
426 if (readb(io_addr
) != *signature
++)
439 /* On sparc64 we have the whole physical IO address space accessible
440 * using physically addressed loads and stores, so this does nothing.
442 static inline void __iomem
*ioremap(unsigned long offset
, unsigned long size
)
444 return (void __iomem
*)offset
;
447 #define ioremap_nocache(X,Y) ioremap((X),(Y))
449 static inline void iounmap(volatile void __iomem
*addr
)
453 #define ioread8(X) readb(X)
454 #define ioread16(X) readw(X)
455 #define ioread32(X) readl(X)
456 #define iowrite8(val,X) writeb(val,X)
457 #define iowrite16(val,X) writew(val,X)
458 #define iowrite32(val,X) writel(val,X)
460 /* Create a virtual mapping cookie for an IO port range */
461 extern void __iomem
*ioport_map(unsigned long port
, unsigned int nr
);
462 extern void ioport_unmap(void __iomem
*);
464 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
466 extern void __iomem
*pci_iomap(struct pci_dev
*dev
, int bar
, unsigned long max
);
467 extern void pci_iounmap(struct pci_dev
*dev
, void __iomem
*);
469 /* Similarly for SBUS. */
470 #define sbus_ioremap(__res, __offset, __size, __name) \
471 ({ unsigned long __ret; \
472 __ret = (__res)->start + (((__res)->flags & 0x1ffUL) << 32UL); \
473 __ret += (unsigned long) (__offset); \
474 if (! request_region((__ret), (__size), (__name))) \
476 (void __iomem *) __ret; \
479 #define sbus_iounmap(__addr, __size) \
480 release_region((unsigned long)(__addr), (__size))
484 #define dma_cache_inv(_start,_size) do { } while (0)
485 #define dma_cache_wback(_start,_size) do { } while (0)
486 #define dma_cache_wback_inv(_start,_size) do { } while (0)
489 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
492 #define xlate_dev_mem_ptr(p) __va(p)
495 * Convert a virtual cached pointer to an uncached pointer
497 #define xlate_dev_kmem_ptr(p) p
501 #endif /* !(__SPARC64_IO_H) */