2 * $Id: io.h,v 1.29 2001/11/10 09:28:34 davem Exp $
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/ioport.h> /* struct resource */
11 #include <asm/page.h> /* IO address mapping routines need this */
12 #include <asm/system.h>
14 #define virt_to_bus virt_to_phys
15 #define bus_to_virt phys_to_virt
16 #define page_to_phys(page) ((((page) - mem_map) << PAGE_SHIFT)+phys_base)
18 static __inline__ u32 flip_dword (u32 d)
20 return ((d&0xff)<<24) | (((d>>8)&0xff)<<16) | (((d>>16)&0xff)<<8)| ((d>>24)&0xff);
23 static __inline__ u16 flip_word (u16 d)
25 return ((d&0xff) << 8) | ((d>>8)&0xff);
29 * Memory mapped I/O to PCI
31 static __inline__ u8 readb(unsigned long addr)
33 return *(volatile u8 *)addr;
36 static __inline__ u16 readw(unsigned long addr)
38 return flip_word(*(volatile u16 *)addr);
41 static __inline__ u32 readl(unsigned long addr)
43 return flip_dword(*(volatile u32 *)addr);
46 static __inline__ void writeb(u8 b, unsigned long addr)
48 *(volatile u8 *)addr = b;
51 static __inline__ void writew(u16 b, unsigned long addr)
53 *(volatile u16 *)addr = flip_word(b);
56 static __inline__ void writel(u32 b, unsigned long addr)
58 *(volatile u32 *)addr = flip_dword(b);
61 /* Now the 'raw' versions. */
62 static __inline__ u8 __raw_readb(unsigned long addr)
64 return *(volatile u8 *)addr;
67 static __inline__ u16 __raw_readw(unsigned long addr)
69 return *(volatile u16 *)addr;
72 static __inline__ u32 __raw_readl(unsigned long addr)
74 return *(volatile u32 *)addr;
77 static __inline__ void __raw_writeb(u8 b, unsigned long addr)
79 *(volatile u8 *)addr = b;
82 static __inline__ void __raw_writew(u16 b, unsigned long addr)
84 *(volatile u16 *)addr = b;
87 static __inline__ void __raw_writel(u32 b, unsigned long addr)
89 *(volatile u32 *)addr = b;
93 * I/O space operations
95 * Arrangement on a Sun is somewhat complicated.
97 * First of all, we want to use standard Linux drivers
98 * for keyboard, PC serial, etc. These drivers think
99 * they access I/O space and use inb/outb.
100 * On the other hand, EBus bridge accepts PCI *memory*
101 * cycles and converts them into ISA *I/O* cycles.
102 * Ergo, we want inb & outb to generate PCI memory cycles.
104 * If we want to issue PCI *I/O* cycles, we do this
105 * with a low 64K fixed window in PCIC. This window gets
106 * mapped somewhere into virtual kernel space and we
107 * can use inb/outb again.
109 #define inb_local(addr) readb(addr)
110 #define inb(addr) readb(addr)
111 #define inw(addr) readw(addr)
112 #define inl(addr) readl(addr)
113 #define inb_p(addr) readb(addr)
115 #define outb_local(b, addr) writeb(b, addr)
116 #define outb(b, addr) writeb(b, addr)
117 #define outw(b, addr) writew(b, addr)
118 #define outl(b, addr) writel(b, addr)
119 #define outb_p(b, addr) writeb(b, addr)
121 extern void outsb(unsigned long addr, const void *src, unsigned long cnt);
122 extern void outsw(unsigned long addr, const void *src, unsigned long cnt);
123 extern void outsl(unsigned long addr, const void *src, unsigned long cnt);
124 extern void insb(unsigned long addr, void *dst, unsigned long count);
125 extern void insw(unsigned long addr, void *dst, unsigned long count);
126 extern void insl(unsigned long addr, void *dst, unsigned long count);
128 #define IO_SPACE_LIMIT 0xffffffff
133 * SBus has only one, memory mapped, I/O space.
134 * We do not need to flip bytes for SBus of course.
136 static __inline__ u8 _sbus_readb(unsigned long addr)
138 return *(volatile u8 *)addr;
141 static __inline__ u16 _sbus_readw(unsigned long addr)
143 return *(volatile u16 *)addr;
146 static __inline__ u32 _sbus_readl(unsigned long addr)
148 return *(volatile u32 *)addr;
151 static __inline__ void _sbus_writeb(u8 b, unsigned long addr)
153 *(volatile u8 *)addr = b;
156 static __inline__ void _sbus_writew(u16 b, unsigned long addr)
158 *(volatile u16 *)addr = b;
161 static __inline__ void _sbus_writel(u32 b, unsigned long addr)
163 *(volatile u32 *)addr = b;
167 * The only reason for #define's is to hide casts to unsigned long.
168 * XXX Rewrite drivers without structures for registers.
170 #define sbus_readb(a) _sbus_readb((unsigned long)(a))
171 #define sbus_readw(a) _sbus_readw((unsigned long)(a))
172 #define sbus_readl(a) _sbus_readl((unsigned long)(a))
173 #define sbus_writeb(v, a) _sbus_writeb(v, (unsigned long)(a))
174 #define sbus_writew(v, a) _sbus_writew(v, (unsigned long)(a))
175 #define sbus_writel(v, a) _sbus_writel(v, (unsigned long)(a))
177 static inline void *sbus_memset_io(void *__dst, int c, __kernel_size_t n)
179 unsigned long dst = (unsigned long)__dst;
191 * Bus number may be embedded in the higher bits of the physical address.
192 * This is why we have no bus number argument to ioremap().
194 extern void *ioremap(unsigned long offset, unsigned long size);
195 #define ioremap_nocache(X,Y) ioremap((X),(Y))
196 extern void iounmap(void *addr);
198 /* P3: talk davem into dropping "name" argument in favor of res->name */
200 * Bus number may be in res->flags... somewhere.
202 extern unsigned long sbus_ioremap(struct resource *res, unsigned long offset,
203 unsigned long size, char *name);
204 /* XXX Partial deallocations? I think not! */
205 extern void sbus_iounmap(unsigned long vaddr, unsigned long size);
208 #define virt_to_phys(x) __pa((unsigned long)(x))
209 #define phys_to_virt(x) __va((unsigned long)(x))
212 * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
213 * so rtc_port is static in it. This should not change unless a new
216 #define RTC_PORT(x) (rtc_port + (x))
217 #define RTC_ALWAYS_BCD 0
220 /* P3: Only IDE DMA may need these. */
222 #define dma_cache_inv(_start,_size) do { } while (0)
223 #define dma_cache_wback(_start,_size) do { } while (0)
224 #define dma_cache_wback_inv(_start,_size) do { } while (0)
228 #endif /* !(__SPARC_IO_H) */