[PATCH] NFSv4: Fix up races in nfs4_proc_setattr()
[linux-2.6/suspend2-2.6.18.git] / include / asm-h8300 / io.h
blob1773e373e9c6c6c007c90a6d23adff2071e256f8
1 #ifndef _H8300_IO_H
2 #define _H8300_IO_H
4 #ifdef __KERNEL__
6 #include <linux/config.h>
7 #include <asm/virtconvert.h>
9 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
10 #include <asm/regs306x.h>
11 #elif defined(CONFIG_H8S2678)
12 #include <asm/regs267x.h>
13 #else
14 #error UNKNOWN CPU TYPE
15 #endif
19 * These are for ISA/PCI shared memory _only_ and should never be used
20 * on any other type of memory, including Zorro memory. They are meant to
21 * access the bus in the bus byte order which is little-endian!.
23 * readX/writeX() are used to access memory mapped devices. On some
24 * architectures the memory mapped IO stuff needs to be accessed
25 * differently. On the m68k architecture, we just read/write the
26 * memory location directly.
28 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
29 * two accesses to memory, which may be undesireable for some devices.
33 * swap functions are sometimes needed to interface little-endian hardware
36 static inline unsigned short _swapw(volatile unsigned short v)
38 #ifndef H8300_IO_NOSWAP
39 unsigned short r;
40 __asm__("xor.b %w0,%x0\n\t"
41 "xor.b %x0,%w0\n\t"
42 "xor.b %w0,%x0"
43 :"=r"(r)
44 :"0"(v));
45 return r;
46 #else
47 return v;
48 #endif
51 static inline unsigned long _swapl(volatile unsigned long v)
53 #ifndef H8300_IO_NOSWAP
54 unsigned long r;
55 __asm__("xor.b %w0,%x0\n\t"
56 "xor.b %x0,%w0\n\t"
57 "xor.b %w0,%x0\n\t"
58 "xor.w %e0,%f0\n\t"
59 "xor.w %f0,%e0\n\t"
60 "xor.w %e0,%f0\n\t"
61 "xor.b %w0,%x0\n\t"
62 "xor.b %x0,%w0\n\t"
63 "xor.b %w0,%x0"
64 :"=r"(r)
65 :"0"(v));
66 return r;
67 #else
68 return v;
69 #endif
72 #define readb(addr) \
73 ({ unsigned char __v = \
74 *(volatile unsigned char *)((unsigned long)(addr) & 0x00ffffff); \
75 __v; })
76 #define readw(addr) \
77 ({ unsigned short __v = \
78 *(volatile unsigned short *)((unsigned long)(addr) & 0x00ffffff); \
79 __v; })
80 #define readl(addr) \
81 ({ unsigned long __v = \
82 *(volatile unsigned long *)((unsigned long)(addr) & 0x00ffffff); \
83 __v; })
85 #define writeb(b,addr) (void)((*(volatile unsigned char *) \
86 ((unsigned long)(addr) & 0x00ffffff)) = (b))
87 #define writew(b,addr) (void)((*(volatile unsigned short *) \
88 ((unsigned long)(addr) & 0x00ffffff)) = (b))
89 #define writel(b,addr) (void)((*(volatile unsigned long *) \
90 ((unsigned long)(addr) & 0x00ffffff)) = (b))
91 #define readb_relaxed(addr) readb(addr)
92 #define readw_relaxed(addr) readw(addr)
93 #define readl_relaxed(addr) readl(addr)
95 #define __raw_readb readb
96 #define __raw_readw readw
97 #define __raw_readl readl
98 #define __raw_writeb writeb
99 #define __raw_writew writew
100 #define __raw_writel writel
102 static inline int h8300_buswidth(unsigned int addr)
104 return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
107 static inline void io_outsb(unsigned int addr, const void *buf, int len)
109 volatile unsigned char *ap_b = (volatile unsigned char *) addr;
110 volatile unsigned short *ap_w = (volatile unsigned short *) addr;
111 unsigned char *bp = (unsigned char *) buf;
113 if(h8300_buswidth(addr) && (addr & 1)) {
114 while (len--)
115 *ap_w = *bp++;
116 } else {
117 while (len--)
118 *ap_b = *bp++;
122 static inline void io_outsw(unsigned int addr, const void *buf, int len)
124 volatile unsigned short *ap = (volatile unsigned short *) addr;
125 unsigned short *bp = (unsigned short *) buf;
126 while (len--)
127 *ap = _swapw(*bp++);
130 static inline void io_outsl(unsigned int addr, const void *buf, int len)
132 volatile unsigned long *ap = (volatile unsigned long *) addr;
133 unsigned long *bp = (unsigned long *) buf;
134 while (len--)
135 *ap = _swapl(*bp++);
138 static inline void io_outsw_noswap(unsigned int addr, const void *buf, int len)
140 volatile unsigned short *ap = (volatile unsigned short *) addr;
141 unsigned short *bp = (unsigned short *) buf;
142 while (len--)
143 *ap = *bp++;
146 static inline void io_outsl_noswap(unsigned int addr, const void *buf, int len)
148 volatile unsigned long *ap = (volatile unsigned long *) addr;
149 unsigned long *bp = (unsigned long *) buf;
150 while (len--)
151 *ap = *bp++;
154 static inline void io_insb(unsigned int addr, void *buf, int len)
156 volatile unsigned char *ap_b;
157 volatile unsigned short *ap_w;
158 unsigned char *bp = (unsigned char *) buf;
160 if(h8300_buswidth(addr)) {
161 ap_w = (volatile unsigned short *)(addr & ~1);
162 while (len--)
163 *bp++ = *ap_w & 0xff;
164 } else {
165 ap_b = (volatile unsigned char *)addr;
166 while (len--)
167 *bp++ = *ap_b;
171 static inline void io_insw(unsigned int addr, void *buf, int len)
173 volatile unsigned short *ap = (volatile unsigned short *) addr;
174 unsigned short *bp = (unsigned short *) buf;
175 while (len--)
176 *bp++ = _swapw(*ap);
179 static inline void io_insl(unsigned int addr, void *buf, int len)
181 volatile unsigned long *ap = (volatile unsigned long *) addr;
182 unsigned long *bp = (unsigned long *) buf;
183 while (len--)
184 *bp++ = _swapl(*ap);
187 static inline void io_insw_noswap(unsigned int addr, void *buf, int len)
189 volatile unsigned short *ap = (volatile unsigned short *) addr;
190 unsigned short *bp = (unsigned short *) buf;
191 while (len--)
192 *bp++ = *ap;
195 static inline void io_insl_noswap(unsigned int addr, void *buf, int len)
197 volatile unsigned long *ap = (volatile unsigned long *) addr;
198 unsigned long *bp = (unsigned long *) buf;
199 while (len--)
200 *bp++ = *ap;
204 * make the short names macros so specific devices
205 * can override them as required
208 #define memset_io(a,b,c) memset((void *)(a),(b),(c))
209 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
210 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
212 #define mmiowb()
214 #define inb(addr) ((h8300_buswidth(addr))?readw((addr) & ~1) & 0xff:readb(addr))
215 #define inw(addr) _swapw(readw(addr))
216 #define inl(addr) _swapl(readl(addr))
217 #define outb(x,addr) ((void)((h8300_buswidth(addr) && \
218 ((addr) & 1))?writew(x,(addr) & ~1):writeb(x,addr)))
219 #define outw(x,addr) ((void) writew(_swapw(x),addr))
220 #define outl(x,addr) ((void) writel(_swapl(x),addr))
222 #define inb_p(addr) inb(addr)
223 #define inw_p(addr) inw(addr)
224 #define inl_p(addr) inl(addr)
225 #define outb_p(x,addr) outb(x,addr)
226 #define outw_p(x,addr) outw(x,addr)
227 #define outl_p(x,addr) outl(x,addr)
229 #define outsb(a,b,l) io_outsb(a,b,l)
230 #define outsw(a,b,l) io_outsw(a,b,l)
231 #define outsl(a,b,l) io_outsl(a,b,l)
233 #define insb(a,b,l) io_insb(a,b,l)
234 #define insw(a,b,l) io_insw(a,b,l)
235 #define insl(a,b,l) io_insl(a,b,l)
237 #define IO_SPACE_LIMIT 0xffffff
240 /* Values for nocacheflag and cmode */
241 #define IOMAP_FULL_CACHING 0
242 #define IOMAP_NOCACHE_SER 1
243 #define IOMAP_NOCACHE_NONSER 2
244 #define IOMAP_WRITETHROUGH 3
246 extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
247 extern void __iounmap(void *addr, unsigned long size);
249 static inline void *ioremap(unsigned long physaddr, unsigned long size)
251 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
253 static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
255 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
257 static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
259 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
261 static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
263 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
266 extern void iounmap(void *addr);
268 /* Nothing to do */
270 #define dma_cache_inv(_start,_size) do { } while (0)
271 #define dma_cache_wback(_start,_size) do { } while (0)
272 #define dma_cache_wback_inv(_start,_size) do { } while (0)
274 /* H8/300 internal I/O functions */
275 static __inline__ unsigned char ctrl_inb(unsigned long addr)
277 return *(volatile unsigned char*)addr;
280 static __inline__ unsigned short ctrl_inw(unsigned long addr)
282 return *(volatile unsigned short*)addr;
285 static __inline__ unsigned long ctrl_inl(unsigned long addr)
287 return *(volatile unsigned long*)addr;
290 static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
292 *(volatile unsigned char*)addr = b;
295 static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
297 *(volatile unsigned short*)addr = b;
300 static __inline__ void ctrl_outl(unsigned long b, unsigned long addr)
302 *(volatile unsigned long*)addr = b;
305 /* Pages to physical address... */
306 #define page_to_phys(page) ((page - mem_map) << PAGE_SHIFT)
307 #define page_to_bus(page) ((page - mem_map) << PAGE_SHIFT)
310 * Macros used for converting between virtual and physical mappings.
312 #define mm_ptov(vaddr) ((void *) (vaddr))
313 #define mm_vtop(vaddr) ((unsigned long) (vaddr))
314 #define phys_to_virt(vaddr) ((void *) (vaddr))
315 #define virt_to_phys(vaddr) ((unsigned long) (vaddr))
317 #define virt_to_bus virt_to_phys
318 #define bus_to_virt phys_to_virt
321 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
322 * access
324 #define xlate_dev_mem_ptr(p) __va(p)
327 * Convert a virtual cached pointer to an uncached pointer
329 #define xlate_dev_kmem_ptr(p) p
331 #endif /* __KERNEL__ */
333 #endif /* _H8300_IO_H */