patch-2_6_7-vs1_9_1_12
[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         unsigned short r,t;
39         __asm__("mov.b %w2,%x1\n\t"
40                 "mov.b %x2,%w1\n\t"
41                 "mov.w %1,%0"
42                 :"=r"(r),"=r"(t)
43                 :"r"(v));
44         return r;
45 }
46
47 static inline unsigned int _swapl(volatile unsigned long v)
48 {
49         unsigned int r,t;
50         __asm__("mov.b %w2,%x1\n\t"
51                 "mov.b %x2,%w1\n\t"
52                 "mov.w %f1,%e0\n\t"
53                 "mov.w %e2,%f1\n\t"
54                 "mov.b %w1,%x0\n\t"
55                 "mov.b %x1,%w0"
56                 :"=r"(r),"=r"(t)
57                 :"r"(v));
58         return r;
59 }
60
61 #define readb(addr) \
62     ({ unsigned char __v = (*(volatile unsigned char *) ((addr) & 0x00ffffff)); __v; })
63 #define readw(addr) \
64     ({ unsigned short __v = (*(volatile unsigned short *) ((addr) & 0x00ffffff)); __v; })
65 #define readl(addr) \
66     ({ unsigned int __v = (*(volatile unsigned int *) ((addr) & 0x00ffffff)); __v; })
67
68 #define writeb(b,addr) (void)((*(volatile unsigned char *) ((addr) & 0x00ffffff)) = (b))
69 #define writew(b,addr) (void)((*(volatile unsigned short *) ((addr) & 0x00ffffff)) = (b))
70 #define writel(b,addr) (void)((*(volatile unsigned int *) ((addr) & 0x00ffffff)) = (b))
71 #define readb_relaxed(addr) readb(addr)
72 #define readw_relaxed(addr) readw(addr)
73 #define readl_relaxed(addr) readl(addr)
74
75 #define __raw_readb readb
76 #define __raw_readw readw
77 #define __raw_readl readl
78 #define __raw_writeb writeb
79 #define __raw_writew writew
80 #define __raw_writel writel
81
82 static inline int h8300_buswidth(unsigned int addr)
83 {
84         return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
85 }
86
87 static inline void io_outsb(unsigned int addr, const void *buf, int len)
88 {
89         volatile unsigned char  *ap_b = (volatile unsigned char *) addr;
90         volatile unsigned short *ap_w = (volatile unsigned short *) addr;
91         unsigned char *bp = (unsigned char *) buf;
92
93         if(h8300_buswidth(addr) && (addr & 1)) {
94                 while (len--)
95                         *ap_w = *bp++;
96         } else {
97                 while (len--)
98                         *ap_b = *bp++;
99         }
100 }
101
102 static inline void io_outsw(unsigned int addr, const void *buf, int len)
103 {
104         volatile unsigned short *ap = (volatile unsigned short *) addr;
105         unsigned short *bp = (unsigned short *) buf;
106         while (len--)
107                 *ap = _swapw(*bp++);
108 }
109
110 static inline void io_outsl(unsigned int addr, const void *buf, int len)
111 {
112         volatile unsigned int *ap = (volatile unsigned int *) addr;
113         unsigned long *bp = (unsigned long *) buf;
114         while (len--)
115                 *ap = _swapl(*bp++);
116 }
117
118 static inline void io_insb(unsigned int addr, void *buf, int len)
119 {
120         volatile unsigned char  *ap_b;
121         volatile unsigned short *ap_w;
122         unsigned char *bp = (unsigned char *) buf;
123
124         if(h8300_buswidth(addr)) {
125                 ap_w = (volatile unsigned short *)(addr & ~1);
126                 while (len--)
127                         *bp++ = *ap_w & 0xff;
128         } else {
129                 ap_b = (volatile unsigned char *)addr;
130                 while (len--)
131                         *bp++ = *ap_b;
132         }
133 }
134
135 static inline void io_insw(unsigned int addr, void *buf, int len)
136 {
137         volatile unsigned short *ap = (volatile unsigned short *) addr;
138         unsigned short *bp = (unsigned short *) buf;
139         while (len--)
140                 *bp++ = _swapw(*ap);
141 }
142
143 static inline void io_insl(unsigned int addr, void *buf, int len)
144 {
145         volatile unsigned int *ap = (volatile unsigned int *) addr;
146         unsigned long *bp = (unsigned long *) buf;
147         while (len--)
148                 *bp++ = _swapl(*ap);
149 }
150
151 /*
152  *      make the short names macros so specific devices
153  *      can override them as required
154  */
155
156 #define memset_io(a,b,c)        memset((void *)(a),(b),(c))
157 #define memcpy_fromio(a,b,c)    memcpy((a),(void *)(b),(c))
158 #define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
159
160 #define inb(addr)    ((h8300_buswidth(addr))?readw((addr) & ~1) & 0xff:readb(addr))
161 #define inw(addr)    _swapw(readw(addr))
162 #define inl(addr)    _swapl(readl(addr))
163 #define outb(x,addr) ((void)((h8300_buswidth(addr) && ((addr) & 1))?writew(x,(addr) & ~1):writeb(x,addr)))
164 #define outw(x,addr) ((void) writew(_swapw(x),addr))
165 #define outl(x,addr) ((void) writel(_swapl(x),addr))
166
167 #define inb_p(addr)    inb(addr)
168 #define inw_p(addr)    inw(addr)
169 #define inl_p(addr)    inl(addr)
170 #define outb_p(x,addr) outb(x,addr)
171 #define outw_p(x,addr) outw(x,addr)
172 #define outl_p(x,addr) outl(x,addr)
173
174 #define outsb(a,b,l) io_outsb(a,b,l)
175 #define outsw(a,b,l) io_outsw(a,b,l)
176 #define outsl(a,b,l) io_outsl(a,b,l)
177
178 #define insb(a,b,l) io_insb(a,b,l)
179 #define insw(a,b,l) io_insw(a,b,l)
180 #define insl(a,b,l) io_insl(a,b,l)
181
182 #define IO_SPACE_LIMIT 0xffffff
183
184
185 /* Values for nocacheflag and cmode */
186 #define IOMAP_FULL_CACHING              0
187 #define IOMAP_NOCACHE_SER               1
188 #define IOMAP_NOCACHE_NONSER            2
189 #define IOMAP_WRITETHROUGH              3
190
191 extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
192 extern void __iounmap(void *addr, unsigned long size);
193
194 static inline void *ioremap(unsigned long physaddr, unsigned long size)
195 {
196         return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
197 }
198 static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
199 {
200         return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
201 }
202 static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
203 {
204         return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
205 }
206 static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
207 {
208         return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
209 }
210
211 extern void iounmap(void *addr);
212
213 /* Nothing to do */
214
215 #define dma_cache_inv(_start,_size)             do { } while (0)
216 #define dma_cache_wback(_start,_size)           do { } while (0)
217 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
218
219 /* H8/300 internal I/O functions */
220 static __inline__ unsigned char ctrl_inb(unsigned long addr)
221 {
222         return *(volatile unsigned char*)addr;
223 }
224
225 static __inline__ unsigned short ctrl_inw(unsigned long addr)
226 {
227         return *(volatile unsigned short*)addr;
228 }
229
230 static __inline__ unsigned int ctrl_inl(unsigned long addr)
231 {
232         return *(volatile unsigned long*)addr;
233 }
234
235 static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
236 {
237         *(volatile unsigned char*)addr = b;
238 }
239
240 static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
241 {
242         *(volatile unsigned short*)addr = b;
243 }
244
245 static __inline__ void ctrl_outl(unsigned int b, unsigned long addr)
246 {
247         *(volatile unsigned long*)addr = b;
248 }
249
250 /* Pages to physical address... */
251 #define page_to_phys(page)      ((page - mem_map) << PAGE_SHIFT)
252 #define page_to_bus(page)       ((page - mem_map) << PAGE_SHIFT)
253
254 /*
255  * Macros used for converting between virtual and physical mappings.
256  */
257 #define mm_ptov(vaddr)          ((void *) (vaddr))
258 #define mm_vtop(vaddr)          ((unsigned long) (vaddr))
259 #define phys_to_virt(vaddr)     ((void *) (vaddr))
260 #define virt_to_phys(vaddr)     ((unsigned long) (vaddr))
261
262 #define virt_to_bus virt_to_phys
263 #define bus_to_virt phys_to_virt
264
265 #endif /* __KERNEL__ */
266
267 #endif /* _H8300_IO_H */