Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / arch / sparc / include / asm / io_32.h
blob2006e5d359dfb5f602ab004208ea60d610e15a6d
1 #ifndef __SPARC_IO_H
2 #define __SPARC_IO_H
4 #include <linux/kernel.h>
5 #include <linux/types.h>
6 #include <linux/ioport.h> /* struct resource */
8 #include <asm/page.h> /* IO address mapping routines need this */
9 #include <asm/system.h>
10 #include <asm-generic/pci_iomap.h>
12 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
14 static inline u32 flip_dword (u32 l)
16 return ((l&0xff)<<24) | (((l>>8)&0xff)<<16) | (((l>>16)&0xff)<<8)| ((l>>24)&0xff);
19 static inline u16 flip_word (u16 w)
21 return ((w&0xff) << 8) | ((w>>8)&0xff);
24 #define mmiowb()
27 * Memory mapped I/O to PCI
30 static inline u8 __raw_readb(const volatile void __iomem *addr)
32 return *(__force volatile u8 *)addr;
35 static inline u16 __raw_readw(const volatile void __iomem *addr)
37 return *(__force volatile u16 *)addr;
40 static inline u32 __raw_readl(const volatile void __iomem *addr)
42 return *(__force volatile u32 *)addr;
45 static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
47 *(__force volatile u8 *)addr = b;
50 static inline void __raw_writew(u16 w, volatile void __iomem *addr)
52 *(__force volatile u16 *)addr = w;
55 static inline void __raw_writel(u32 l, volatile void __iomem *addr)
57 *(__force volatile u32 *)addr = l;
60 static inline u8 __readb(const volatile void __iomem *addr)
62 return *(__force volatile u8 *)addr;
65 static inline u16 __readw(const volatile void __iomem *addr)
67 return flip_word(*(__force volatile u16 *)addr);
70 static inline u32 __readl(const volatile void __iomem *addr)
72 return flip_dword(*(__force volatile u32 *)addr);
75 static inline void __writeb(u8 b, volatile void __iomem *addr)
77 *(__force volatile u8 *)addr = b;
80 static inline void __writew(u16 w, volatile void __iomem *addr)
82 *(__force volatile u16 *)addr = flip_word(w);
85 static inline void __writel(u32 l, volatile void __iomem *addr)
87 *(__force volatile u32 *)addr = flip_dword(l);
90 #define readb(__addr) __readb(__addr)
91 #define readw(__addr) __readw(__addr)
92 #define readl(__addr) __readl(__addr)
93 #define readb_relaxed(__addr) readb(__addr)
94 #define readw_relaxed(__addr) readw(__addr)
95 #define readl_relaxed(__addr) readl(__addr)
97 #define writeb(__b, __addr) __writeb((__b),(__addr))
98 #define writew(__w, __addr) __writew((__w),(__addr))
99 #define writel(__l, __addr) __writel((__l),(__addr))
102 * I/O space operations
104 * Arrangement on a Sun is somewhat complicated.
106 * First of all, we want to use standard Linux drivers
107 * for keyboard, PC serial, etc. These drivers think
108 * they access I/O space and use inb/outb.
109 * On the other hand, EBus bridge accepts PCI *memory*
110 * cycles and converts them into ISA *I/O* cycles.
111 * Ergo, we want inb & outb to generate PCI memory cycles.
113 * If we want to issue PCI *I/O* cycles, we do this
114 * with a low 64K fixed window in PCIC. This window gets
115 * mapped somewhere into virtual kernel space and we
116 * can use inb/outb again.
118 #define inb_local(__addr) __readb((void __iomem *)(unsigned long)(__addr))
119 #define inb(__addr) __readb((void __iomem *)(unsigned long)(__addr))
120 #define inw(__addr) __readw((void __iomem *)(unsigned long)(__addr))
121 #define inl(__addr) __readl((void __iomem *)(unsigned long)(__addr))
123 #define outb_local(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
124 #define outb(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
125 #define outw(__w, __addr) __writew(__w, (void __iomem *)(unsigned long)(__addr))
126 #define outl(__l, __addr) __writel(__l, (void __iomem *)(unsigned long)(__addr))
128 #define inb_p(__addr) inb(__addr)
129 #define outb_p(__b, __addr) outb(__b, __addr)
130 #define inw_p(__addr) inw(__addr)
131 #define outw_p(__w, __addr) outw(__w, __addr)
132 #define inl_p(__addr) inl(__addr)
133 #define outl_p(__l, __addr) outl(__l, __addr)
135 void outsb(unsigned long addr, const void *src, unsigned long cnt);
136 void outsw(unsigned long addr, const void *src, unsigned long cnt);
137 void outsl(unsigned long addr, const void *src, unsigned long cnt);
138 void insb(unsigned long addr, void *dst, unsigned long count);
139 void insw(unsigned long addr, void *dst, unsigned long count);
140 void insl(unsigned long addr, void *dst, unsigned long count);
142 #define IO_SPACE_LIMIT 0xffffffff
145 * SBus accessors.
147 * SBus has only one, memory mapped, I/O space.
148 * We do not need to flip bytes for SBus of course.
150 static inline u8 _sbus_readb(const volatile void __iomem *addr)
152 return *(__force volatile u8 *)addr;
155 static inline u16 _sbus_readw(const volatile void __iomem *addr)
157 return *(__force volatile u16 *)addr;
160 static inline u32 _sbus_readl(const volatile void __iomem *addr)
162 return *(__force volatile u32 *)addr;
165 static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
167 *(__force volatile u8 *)addr = b;
170 static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
172 *(__force volatile u16 *)addr = w;
175 static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
177 *(__force volatile u32 *)addr = l;
181 * The only reason for #define's is to hide casts to unsigned long.
183 #define sbus_readb(__addr) _sbus_readb(__addr)
184 #define sbus_readw(__addr) _sbus_readw(__addr)
185 #define sbus_readl(__addr) _sbus_readl(__addr)
186 #define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
187 #define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
188 #define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
190 static inline void sbus_memset_io(volatile void __iomem *__dst, int c, __kernel_size_t n)
192 while(n--) {
193 sbus_writeb(c, __dst);
194 __dst++;
198 static inline void
199 _memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
201 volatile void __iomem *d = dst;
203 while (n--) {
204 writeb(c, d);
205 d++;
209 #define memset_io(d,c,sz) _memset_io(d,c,sz)
211 static inline void
212 _sbus_memcpy_fromio(void *dst, const volatile void __iomem *src,
213 __kernel_size_t n)
215 char *d = dst;
217 while (n--) {
218 char tmp = sbus_readb(src);
219 *d++ = tmp;
220 src++;
224 #define sbus_memcpy_fromio(d, s, sz) _sbus_memcpy_fromio(d, s, sz)
226 static inline void
227 _memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
229 char *d = dst;
231 while (n--) {
232 char tmp = readb(src);
233 *d++ = tmp;
234 src++;
238 #define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
240 static inline void
241 _sbus_memcpy_toio(volatile void __iomem *dst, const void *src,
242 __kernel_size_t n)
244 const char *s = src;
245 volatile void __iomem *d = dst;
247 while (n--) {
248 char tmp = *s++;
249 sbus_writeb(tmp, d);
250 d++;
254 #define sbus_memcpy_toio(d, s, sz) _sbus_memcpy_toio(d, s, sz)
256 static inline void
257 _memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
259 const char *s = src;
260 volatile void __iomem *d = dst;
262 while (n--) {
263 char tmp = *s++;
264 writeb(tmp, d);
265 d++;
269 #define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
271 #ifdef __KERNEL__
274 * Bus number may be embedded in the higher bits of the physical address.
275 * This is why we have no bus number argument to ioremap().
277 extern void __iomem *ioremap(unsigned long offset, unsigned long size);
278 #define ioremap_nocache(X,Y) ioremap((X),(Y))
279 #define ioremap_wc(X,Y) ioremap((X),(Y))
280 extern void iounmap(volatile void __iomem *addr);
282 #define ioread8(X) readb(X)
283 #define ioread16(X) readw(X)
284 #define ioread16be(X) __raw_readw(X)
285 #define ioread32(X) readl(X)
286 #define ioread32be(X) __raw_readl(X)
287 #define iowrite8(val,X) writeb(val,X)
288 #define iowrite16(val,X) writew(val,X)
289 #define iowrite16be(val,X) __raw_writew(val,X)
290 #define iowrite32(val,X) writel(val,X)
291 #define iowrite32be(val,X) __raw_writel(val,X)
293 static inline void ioread8_rep(void __iomem *port, void *buf, unsigned long count)
295 insb((unsigned long __force)port, buf, count);
297 static inline void ioread16_rep(void __iomem *port, void *buf, unsigned long count)
299 insw((unsigned long __force)port, buf, count);
302 static inline void ioread32_rep(void __iomem *port, void *buf, unsigned long count)
304 insl((unsigned long __force)port, buf, count);
307 static inline void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count)
309 outsb((unsigned long __force)port, buf, count);
312 static inline void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count)
314 outsw((unsigned long __force)port, buf, count);
317 static inline void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count)
319 outsl((unsigned long __force)port, buf, count);
322 /* Create a virtual mapping cookie for an IO port range */
323 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
324 extern void ioport_unmap(void __iomem *);
326 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
327 struct pci_dev;
328 extern void pci_iounmap(struct pci_dev *dev, void __iomem *);
331 * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
332 * so rtc_port is static in it. This should not change unless a new
333 * hardware pops up.
335 #define RTC_PORT(x) (rtc_port + (x))
336 #define RTC_ALWAYS_BCD 0
338 static inline int sbus_can_dma_64bit(void)
340 return 0; /* actually, sparc_cpu_model==sun4d */
342 static inline int sbus_can_burst64(void)
344 return 0; /* actually, sparc_cpu_model==sun4d */
346 struct device;
347 extern void sbus_set_sbus64(struct device *, int);
349 #endif
351 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED 1
354 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
355 * access
357 #define xlate_dev_mem_ptr(p) __va(p)
360 * Convert a virtual cached pointer to an uncached pointer
362 #define xlate_dev_kmem_ptr(p) p
364 #endif /* !(__SPARC_IO_H) */