1 /* $Id: io.h,v 1.35 2000/04/13 04:45:59 davem Exp $ */
5 #include <linux/kernel.h>
6 #include <linux/types.h>
8 #include <asm/page.h> /* IO address mapping routines need this */
9 #include <asm/system.h>
13 #define __SLOW_DOWN_IO do { } while (0)
14 #define SLOW_DOWN_IO do { } while (0)
16 extern unsigned long virt_to_bus_not_defined_use_pci_map(volatile void *addr
);
17 #define virt_to_bus virt_to_bus_not_defined_use_pci_map
18 extern unsigned long bus_to_virt_not_defined_use_pci_map(volatile void *addr
);
19 #define bus_to_virt bus_to_virt_not_defined_use_pci_map
21 /* Different PCI controllers we support have their PCI MEM space
22 * mapped to an either 2GB (Psycho) or 4GB (Sabre) aligned area,
23 * so need to chop off the top 33 or 32 bits.
25 extern unsigned long pci_memspace_mask
;
27 #define bus_dvma_to_mem(__vaddr) ((__vaddr) & pci_memspace_mask)
29 extern __inline__
unsigned int inb(unsigned long addr
)
33 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_inb */"
35 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
40 extern __inline__
unsigned int inw(unsigned long addr
)
44 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_inw */"
46 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
51 extern __inline__
unsigned int inl(unsigned long addr
)
55 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_inl */"
57 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
62 extern __inline__
void outb(unsigned char b
, unsigned long addr
)
64 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_outb */"
66 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
69 extern __inline__
void outw(unsigned short w
, unsigned long addr
)
71 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_outw */"
73 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
76 extern __inline__
void outl(unsigned int l
, unsigned long addr
)
78 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_outl */"
80 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
90 extern void outsb(unsigned long addr
, const void *src
, unsigned long count
);
91 extern void outsw(unsigned long addr
, const void *src
, unsigned long count
);
92 extern void outsl(unsigned long addr
, const void *src
, unsigned long count
);
93 extern void insb(unsigned long addr
, void *dst
, unsigned long count
);
94 extern void insw(unsigned long addr
, void *dst
, unsigned long count
);
95 extern void insl(unsigned long addr
, void *dst
, unsigned long count
);
97 /* Memory functions, same as I/O accesses on Ultra. */
98 extern __inline__
unsigned int _readb(unsigned long addr
)
102 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
104 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
109 extern __inline__
unsigned int _readw(unsigned long addr
)
113 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
115 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
120 extern __inline__
unsigned int _readl(unsigned long addr
)
124 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
126 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
131 extern __inline__
void _writeb(unsigned char b
, unsigned long addr
)
133 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
135 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
138 extern __inline__
void _writew(unsigned short w
, unsigned long addr
)
140 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
142 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
145 extern __inline__
void _writel(unsigned int l
, unsigned long addr
)
147 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
149 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E_L
));
152 #define readb(__addr) (_readb((unsigned long)(__addr)))
153 #define readw(__addr) (_readw((unsigned long)(__addr)))
154 #define readl(__addr) (_readl((unsigned long)(__addr)))
155 #define writeb(__b, __addr) (_writeb((__b), (unsigned long)(__addr)))
156 #define writew(__w, __addr) (_writew((__w), (unsigned long)(__addr)))
157 #define writel(__l, __addr) (_writel((__l), (unsigned long)(__addr)))
159 /* Now versions without byte-swapping. */
160 extern __inline__
unsigned int _raw_readb(unsigned long addr
)
164 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
166 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
171 extern __inline__
unsigned int _raw_readw(unsigned long addr
)
175 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
177 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
182 extern __inline__
unsigned int _raw_readl(unsigned long addr
)
186 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
188 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
193 extern __inline__
void _raw_writeb(unsigned char b
, unsigned long addr
)
195 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
197 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
200 extern __inline__
void _raw_writew(unsigned short w
, unsigned long addr
)
202 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
204 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
207 extern __inline__
void _raw_writel(unsigned int l
, unsigned long addr
)
209 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
211 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
214 #define __raw_readb(__addr) (_raw_readb((unsigned long)(__addr)))
215 #define __raw_readw(__addr) (_raw_readw((unsigned long)(__addr)))
216 #define __raw_readl(__addr) (_raw_readl((unsigned long)(__addr)))
217 #define __raw_writeb(__b, __addr) (_raw_writeb((__b), (unsigned long)(__addr)))
218 #define __raw_writew(__w, __addr) (_raw_writew((__w), (unsigned long)(__addr)))
219 #define __raw_writel(__l, __addr) (_raw_writel((__l), (unsigned long)(__addr)))
221 /* Valid I/O Space regions are anywhere, because each PCI bus supported
222 * can live in an arbitrary area of the physical address range.
224 #define IO_SPACE_LIMIT 0xffffffffffffffffUL
226 /* Now, SBUS variants, only difference from PCI is that we do
227 * not use little-endian ASIs.
229 extern __inline__
unsigned int _sbus_readb(unsigned long addr
)
233 __asm__
__volatile__("lduba\t[%1] %2, %0\t/* sbus_readb */"
235 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
240 extern __inline__
unsigned int _sbus_readw(unsigned long addr
)
244 __asm__
__volatile__("lduha\t[%1] %2, %0\t/* sbus_readw */"
246 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
251 extern __inline__
unsigned int _sbus_readl(unsigned long addr
)
255 __asm__
__volatile__("lduwa\t[%1] %2, %0\t/* sbus_readl */"
257 : "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
262 extern __inline__
void _sbus_writeb(unsigned char b
, unsigned long addr
)
264 __asm__
__volatile__("stba\t%r0, [%1] %2\t/* sbus_writeb */"
266 : "Jr" (b
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
269 extern __inline__
void _sbus_writew(unsigned short w
, unsigned long addr
)
271 __asm__
__volatile__("stha\t%r0, [%1] %2\t/* sbus_writew */"
273 : "Jr" (w
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
276 extern __inline__
void _sbus_writel(unsigned int l
, unsigned long addr
)
278 __asm__
__volatile__("stwa\t%r0, [%1] %2\t/* sbus_writel */"
280 : "Jr" (l
), "r" (addr
), "i" (ASI_PHYS_BYPASS_EC_E
));
283 #define sbus_readb(__addr) (_sbus_readb((unsigned long)(__addr)))
284 #define sbus_readw(__addr) (_sbus_readw((unsigned long)(__addr)))
285 #define sbus_readl(__addr) (_sbus_readl((unsigned long)(__addr)))
286 #define sbus_writeb(__b, __addr) (_sbus_writeb((__b), (unsigned long)(__addr)))
287 #define sbus_writew(__w, __addr) (_sbus_writew((__w), (unsigned long)(__addr)))
288 #define sbus_writel(__l, __addr) (_sbus_writel((__l), (unsigned long)(__addr)))
290 static inline void *_sbus_memset_io(unsigned long dst
, int c
, __kernel_size_t n
)
299 #define sbus_memset_io(d,c,sz) \
300 _sbus_memset_io((unsigned long)d,(int)c,(__kernel_size_t)sz)
303 _memset_io(void *dst
, int c
, __kernel_size_t n
)
315 #define memset_io(d,c,sz) \
316 _memset_io((void *)d,(int)c,(__kernel_size_t)sz)
319 _memcpy_fromio(void *dst
, unsigned long src
, __kernel_size_t n
)
324 char tmp
= readb(src
);
332 #define memcpy_fromio(d,s,sz) \
333 _memcpy_fromio((void *)d,(unsigned long)s,(__kernel_size_t)sz)
336 _memcpy_toio(unsigned long dst
, const void *src
, __kernel_size_t n
)
339 unsigned long d
= dst
;
349 #define memcpy_toio(d,s,sz) \
350 _memcpy_toio((unsigned long)d,(const void *)s,(__kernel_size_t)sz)
352 static inline int check_signature(unsigned long io_addr
,
353 const unsigned char *signature
,
358 if (readb(io_addr
++) != *signature
++)
366 /* On sparc64 we have the whole physical IO address space accessible
367 * using physically addressed loads and stores, so this does nothing.
369 #define ioremap(__offset, __size) ((void *)(__offset))
370 #define ioremap_nocache(X,Y) ioremap((X),(Y))
371 #define iounmap(__addr) do { } while(0)
373 /* Similarly for SBUS. */
374 #define sbus_ioremap(__res, __offset, __size, __name) \
375 ({ unsigned long __ret; \
376 __ret = (__res)->start + (((__res)->flags & 0x1ffUL) << 32UL); \
377 __ret += (unsigned long) (__offset); \
378 if (! request_region((__ret), (__size), (__name))) \
383 #define sbus_iounmap(__addr, __size) \
384 release_region((__addr), (__size))
388 #define dma_cache_inv(_start,_size) do { } while (0)
389 #define dma_cache_wback(_start,_size) do { } while (0)
390 #define dma_cache_wback_inv(_start,_size) do { } while (0)
392 #endif /* !(__SPARC64_IO_H) */