VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-h8300 / io.h
1 #ifndef _H8300_IO_H
2 #define _H8300_IO_H
3
4 #ifdef __KERNEL__
5
6 #include <linux/config.h>
7 #include <asm/virtconvert.h>
8
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
16
17
18 /*
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!.
22  *
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.
27  */
28 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
29  * two accesses to memory, which may be undesireable for some devices.
30  */
31
32 /*
33  * swap functions are sometimes needed to interface little-endian hardware
34  */
35
36 static inline unsigned short _swapw(volatile unsigned short v)
37 {
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
49 }
50
51 static inline unsigned long _swapl(volatile unsigned long v)
52 {
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
70 }
71
72 #define readb(addr) \
73     ({ unsigned char __v = (*(volatile unsigned char *) ((addr) & 0x00ffffff)); __v; })
74 #define readw(addr) \
75     ({ unsigned short __v = (*(volatile unsigned short *) ((addr) & 0x00ffffff)); __v; })
76 #define readl(addr) \
77     ({ unsigned int __v = (*(volatile unsigned int *) ((addr) & 0x00ffffff)); __v; })
78
79 #define writeb(b,addr) (void)((*(volatile unsigned char *) ((addr) & 0x00ffffff)) = (b))
80 #define writew(b,addr) (void)((*(volatile unsigned short *) ((addr) & 0x00ffffff)) = (b))
81 #define writel(b,addr) (void)((*(volatile unsigned int *) ((addr) & 0x00ffffff)) = (b))
82 #define readb_relaxed(addr) readb(addr)
83 #define readw_relaxed(addr) readw(addr)
84 #define readl_relaxed(addr) readl(addr)
85
86 #define __raw_readb readb
87 #define __raw_readw readw
88 #define __raw_readl readl
89 #define __raw_writeb writeb
90 #define __raw_writew writew
91 #define __raw_writel writel
92
93 static inline int h8300_buswidth(unsigned int addr)
94 {
95         return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
96 }
97
98 static inline void io_outsb(unsigned int addr, const void *buf, int len)
99 {
100         volatile unsigned char  *ap_b = (volatile unsigned char *) addr;
101         volatile unsigned short *ap_w = (volatile unsigned short *) addr;
102         unsigned char *bp = (unsigned char *) buf;
103
104         if(h8300_buswidth(addr) && (addr & 1)) {
105                 while (len--)
106                         *ap_w = *bp++;
107         } else {
108                 while (len--)
109                         *ap_b = *bp++;
110         }
111 }
112
113 static inline void io_outsw(unsigned int addr, const void *buf, int len)
114 {
115         volatile unsigned short *ap = (volatile unsigned short *) addr;
116         unsigned short *bp = (unsigned short *) buf;
117         while (len--)
118                 *ap = _swapw(*bp++);
119 }
120
121 static inline void io_outsl(unsigned int addr, const void *buf, int len)
122 {
123         volatile unsigned long *ap = (volatile unsigned long *) addr;
124         unsigned long *bp = (unsigned long *) buf;
125         while (len--)
126                 *ap = _swapl(*bp++);
127 }
128
129 static inline void io_outsw_noswap(unsigned int addr, const void *buf, int len)
130 {
131         volatile unsigned short *ap = (volatile unsigned short *) addr;
132         unsigned short *bp = (unsigned short *) buf;
133         while (len--)
134                 *ap = *bp++;
135 }
136
137 static inline void io_outsl_noswap(unsigned int addr, const void *buf, int len)
138 {
139         volatile unsigned long *ap = (volatile unsigned long *) addr;
140         unsigned long *bp = (unsigned long *) buf;
141         while (len--)
142                 *ap = *bp++;
143 }
144
145 static inline void io_insb(unsigned int addr, void *buf, int len)
146 {
147         volatile unsigned char  *ap_b;
148         volatile unsigned short *ap_w;
149         unsigned char *bp = (unsigned char *) buf;
150
151         if(h8300_buswidth(addr)) {
152                 ap_w = (volatile unsigned short *)(addr & ~1);
153                 while (len--)
154                         *bp++ = *ap_w & 0xff;
155         } else {
156                 ap_b = (volatile unsigned char *)addr;
157                 while (len--)
158                         *bp++ = *ap_b;
159         }
160 }
161
162 static inline void io_insw(unsigned int addr, void *buf, int len)
163 {
164         volatile unsigned short *ap = (volatile unsigned short *) addr;
165         unsigned short *bp = (unsigned short *) buf;
166         while (len--)
167                 *bp++ = _swapw(*ap);
168 }
169
170 static inline void io_insl(unsigned int addr, void *buf, int len)
171 {
172         volatile unsigned long *ap = (volatile unsigned long *) addr;
173         unsigned long *bp = (unsigned long *) buf;
174         while (len--)
175                 *bp++ = _swapl(*ap);
176 }
177
178 static inline void io_insw_noswap(unsigned int addr, void *buf, int len)
179 {
180         volatile unsigned short *ap = (volatile unsigned short *) addr;
181         unsigned short *bp = (unsigned short *) buf;
182         while (len--)
183                 *bp++ = *ap;
184 }
185
186 static inline void io_insl_noswap(unsigned int addr, void *buf, int len)
187 {
188         volatile unsigned long *ap = (volatile unsigned long *) addr;
189         unsigned long *bp = (unsigned long *) buf;
190         while (len--)
191                 *bp++ = *ap;
192 }
193
194 /*
195  *      make the short names macros so specific devices
196  *      can override them as required
197  */
198
199 #define memset_io(a,b,c)        memset((void *)(a),(b),(c))
200 #define memcpy_fromio(a,b,c)    memcpy((a),(void *)(b),(c))
201 #define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
202
203 #define inb(addr)    ((h8300_buswidth(addr))?readw((addr) & ~1) & 0xff:readb(addr))
204 #define inw(addr)    _swapw(readw(addr))
205 #define inl(addr)    _swapl(readl(addr))
206 #define outb(x,addr) ((void)((h8300_buswidth(addr) && \
207                       ((addr) & 1))?writew(x,(addr) & ~1):writeb(x,addr)))
208 #define outw(x,addr) ((void) writew(_swapw(x),addr))
209 #define outl(x,addr) ((void) writel(_swapl(x),addr))
210
211 #define inb_p(addr)    inb(addr)
212 #define inw_p(addr)    inw(addr)
213 #define inl_p(addr)    inl(addr)
214 #define outb_p(x,addr) outb(x,addr)
215 #define outw_p(x,addr) outw(x,addr)
216 #define outl_p(x,addr) outl(x,addr)
217
218 #define outsb(a,b,l) io_outsb(a,b,l)
219 #define outsw(a,b,l) io_outsw(a,b,l)
220 #define outsl(a,b,l) io_outsl(a,b,l)
221
222 #define insb(a,b,l) io_insb(a,b,l)
223 #define insw(a,b,l) io_insw(a,b,l)
224 #define insl(a,b,l) io_insl(a,b,l)
225
226 #define IO_SPACE_LIMIT 0xffffff
227
228
229 /* Values for nocacheflag and cmode */
230 #define IOMAP_FULL_CACHING              0
231 #define IOMAP_NOCACHE_SER               1
232 #define IOMAP_NOCACHE_NONSER            2
233 #define IOMAP_WRITETHROUGH              3
234
235 extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
236 extern void __iounmap(void *addr, unsigned long size);
237
238 static inline void *ioremap(unsigned long physaddr, unsigned long size)
239 {
240         return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
241 }
242 static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
243 {
244         return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
245 }
246 static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
247 {
248         return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
249 }
250 static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
251 {
252         return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
253 }
254
255 extern void iounmap(void *addr);
256
257 /* Nothing to do */
258
259 #define dma_cache_inv(_start,_size)             do { } while (0)
260 #define dma_cache_wback(_start,_size)           do { } while (0)
261 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
262
263 /* H8/300 internal I/O functions */
264 static __inline__ unsigned char ctrl_inb(unsigned long addr)
265 {
266         return *(volatile unsigned char*)addr;
267 }
268
269 static __inline__ unsigned short ctrl_inw(unsigned long addr)
270 {
271         return *(volatile unsigned short*)addr;
272 }
273
274 static __inline__ unsigned long ctrl_inl(unsigned long addr)
275 {
276         return *(volatile unsigned long*)addr;
277 }
278
279 static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
280 {
281         *(volatile unsigned char*)addr = b;
282 }
283
284 static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
285 {
286         *(volatile unsigned short*)addr = b;
287 }
288
289 static __inline__ void ctrl_outl(unsigned long b, unsigned long addr)
290 {
291         *(volatile unsigned long*)addr = b;
292 }
293
294 /* Pages to physical address... */
295 #define page_to_phys(page)      ((page - mem_map) << PAGE_SHIFT)
296 #define page_to_bus(page)       ((page - mem_map) << PAGE_SHIFT)
297
298 /*
299  * Macros used for converting between virtual and physical mappings.
300  */
301 #define mm_ptov(vaddr)          ((void *) (vaddr))
302 #define mm_vtop(vaddr)          ((unsigned long) (vaddr))
303 #define phys_to_virt(vaddr)     ((void *) (vaddr))
304 #define virt_to_phys(vaddr)     ((unsigned long) (vaddr))
305
306 #define virt_to_bus virt_to_phys
307 #define bus_to_virt phys_to_virt
308
309 #endif /* __KERNEL__ */
310
311 #endif /* _H8300_IO_H */