blob: 1773e373e9c6c6c007c90a6d23adff2071e256f8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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
36static 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
51static 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 = \
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; })
84
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)
94
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
101
102static inline int h8300_buswidth(unsigned int addr)
103{
104 return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
105}
106
107static inline void io_outsb(unsigned int addr, const void *buf, int len)
108{
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;
112
113 if(h8300_buswidth(addr) && (addr & 1)) {
114 while (len--)
115 *ap_w = *bp++;
116 } else {
117 while (len--)
118 *ap_b = *bp++;
119 }
120}
121
122static inline void io_outsw(unsigned int addr, const void *buf, int len)
123{
124 volatile unsigned short *ap = (volatile unsigned short *) addr;
125 unsigned short *bp = (unsigned short *) buf;
126 while (len--)
127 *ap = _swapw(*bp++);
128}
129
130static inline void io_outsl(unsigned int addr, const void *buf, int len)
131{
132 volatile unsigned long *ap = (volatile unsigned long *) addr;
133 unsigned long *bp = (unsigned long *) buf;
134 while (len--)
135 *ap = _swapl(*bp++);
136}
137
138static inline void io_outsw_noswap(unsigned int addr, const void *buf, int len)
139{
140 volatile unsigned short *ap = (volatile unsigned short *) addr;
141 unsigned short *bp = (unsigned short *) buf;
142 while (len--)
143 *ap = *bp++;
144}
145
146static inline void io_outsl_noswap(unsigned int addr, const void *buf, int len)
147{
148 volatile unsigned long *ap = (volatile unsigned long *) addr;
149 unsigned long *bp = (unsigned long *) buf;
150 while (len--)
151 *ap = *bp++;
152}
153
154static inline void io_insb(unsigned int addr, void *buf, int len)
155{
156 volatile unsigned char *ap_b;
157 volatile unsigned short *ap_w;
158 unsigned char *bp = (unsigned char *) buf;
159
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;
168 }
169}
170
171static inline void io_insw(unsigned int addr, void *buf, int len)
172{
173 volatile unsigned short *ap = (volatile unsigned short *) addr;
174 unsigned short *bp = (unsigned short *) buf;
175 while (len--)
176 *bp++ = _swapw(*ap);
177}
178
179static inline void io_insl(unsigned int addr, void *buf, int len)
180{
181 volatile unsigned long *ap = (volatile unsigned long *) addr;
182 unsigned long *bp = (unsigned long *) buf;
183 while (len--)
184 *bp++ = _swapl(*ap);
185}
186
187static inline void io_insw_noswap(unsigned int addr, void *buf, int len)
188{
189 volatile unsigned short *ap = (volatile unsigned short *) addr;
190 unsigned short *bp = (unsigned short *) buf;
191 while (len--)
192 *bp++ = *ap;
193}
194
195static inline void io_insl_noswap(unsigned int addr, void *buf, int len)
196{
197 volatile unsigned long *ap = (volatile unsigned long *) addr;
198 unsigned long *bp = (unsigned long *) buf;
199 while (len--)
200 *bp++ = *ap;
201}
202
203/*
204 * make the short names macros so specific devices
205 * can override them as required
206 */
207
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))
211
212#define mmiowb()
213
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))
221
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)
228
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)
232
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)
236
237#define IO_SPACE_LIMIT 0xffffff
238
239
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
245
246extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
247extern void __iounmap(void *addr, unsigned long size);
248
249static inline void *ioremap(unsigned long physaddr, unsigned long size)
250{
251 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
252}
253static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
254{
255 return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
256}
257static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
258{
259 return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
260}
261static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
262{
263 return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
264}
265
266extern void iounmap(void *addr);
267
268/* Nothing to do */
269
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)
273
274/* H8/300 internal I/O functions */
275static __inline__ unsigned char ctrl_inb(unsigned long addr)
276{
277 return *(volatile unsigned char*)addr;
278}
279
280static __inline__ unsigned short ctrl_inw(unsigned long addr)
281{
282 return *(volatile unsigned short*)addr;
283}
284
285static __inline__ unsigned long ctrl_inl(unsigned long addr)
286{
287 return *(volatile unsigned long*)addr;
288}
289
290static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
291{
292 *(volatile unsigned char*)addr = b;
293}
294
295static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
296{
297 *(volatile unsigned short*)addr = b;
298}
299
300static __inline__ void ctrl_outl(unsigned long b, unsigned long addr)
301{
302 *(volatile unsigned long*)addr = b;
303}
304
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)
308
309/*
310 * Macros used for converting between virtual and physical mappings.
311 */
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))
316
317#define virt_to_bus virt_to_phys
318#define bus_to_virt phys_to_virt
319
320/*
321 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
322 * access
323 */
324#define xlate_dev_mem_ptr(p) __va(p)
325
326/*
327 * Convert a virtual cached pointer to an uncached pointer
328 */
329#define xlate_dev_kmem_ptr(p) p
330
331#endif /* __KERNEL__ */
332
333#endif /* _H8300_IO_H */