1 #ifndef __ASM_SH_IO_H
2 #define __ASM_SH_IO_H
3
4 /*
5 * Convention:
6 * read{b,w,l}/write{b,w,l} are for PCI,
7 * while in{b,w,l}/out{b,w,l} are for ISA
8 * These may (will) be platform specific function.
9 * In addition we have 'pausing' versions: in{b,w,l}_p/out{b,w,l}_p
10 * and 'string' versions: ins{b,w,l}/outs{b,w,l}
11 * For read{b,w,l} and write{b,w,l} there are also __raw versions, which
12 * do not have a memory barrier after them.
13 *
14 * In addition, we have
15 * ctrl_in{b,w,l}/ctrl_out{b,w,l} for SuperH specific I/O.
16 * which are processor specific.
17 */
18
19 /*
20 * We follow the Alpha convention here:
21 * __inb expands to an inline function call (which either calls via the
22 * mach_vec if generic, or a machine specific implementation)
23 * _inb is a real function call (note ___raw fns are _ version of __raw)
24 * inb by default expands to _inb, but the machine specif code may
25 * define it to __inb if it chooses.
26 */
27
28 #include <asm/cache.h>
29 #include <asm/system.h>
30 #include <linux/config.h>
31
32 /*
33 * Depending on which platform we are running on, we need different
34 * I/O functions.
35 */
36
37 #ifdef __KERNEL__
38 #ifdef CONFIG_SH_GENERIC
39
40 /* In a generic kernel, we always go through the machine vector. */
41
42 #include <asm/machvec.h>
43
44 # define __inb(p) sh_mv.mv_inb((p))
45 # define __inw(p) sh_mv.mv_inw((p))
46 # define __inl(p) sh_mv.mv_inl((p))
47 # define __outb(x,p) sh_mv.mv_outb((x),(p))
48 # define __outw(x,p) sh_mv.mv_outw((x),(p))
49 # define __outl(x,p) sh_mv.mv_outl((x),(p))
50
51 # define __inb_p(p) sh_mv.mv_inb_p((p))
52 # define __inw_p(p) sh_mv.mv_inw_p((p))
53 # define __inl_p(p) sh_mv.mv_inl_p((p))
54 # define __outb_p(x,p) sh_mv.mv_outb_p((x),(p))
55 # define __outw_p(x,p) sh_mv.mv_outw_p((x),(p))
56 # define __outl_p(x,p) sh_mv.mv_outl_p((x),(p))
57
58 #define __insb(p,b,c) sh_mv.mv_insb((p), (b), (c))
59 #define __insw(p,b,c) sh_mv.mv_insw((p), (b), (c))
60 #define __insl(p,b,c) sh_mv.mv_insl((p), (b), (c))
61 #define __outsb(p,b,c) sh_mv.mv_outsb((p), (b), (c))
62 #define __outsw(p,b,c) sh_mv.mv_outsw((p), (b), (c))
63 #define __outsl(p,b,c) sh_mv.mv_outsl((p), (b), (c))
64
65 # define __readb(a) sh_mv.mv_readb((a))
66 # define __readw(a) sh_mv.mv_readw((a))
67 # define __readl(a) sh_mv.mv_readl((a))
68 # define __writeb(v,a) sh_mv.mv_writeb((v),(a))
69 # define __writew(v,a) sh_mv.mv_writew((v),(a))
70 # define __writel(v,a) sh_mv.mv_writel((v),(a))
71
72 # define __ioremap(a,s) sh_mv.mv_ioremap((a), (s))
73 # define __ioremap_nocache(a,s) sh_mv.mv_ioremap_nocache((a), (s))
74 # define __iounmap(a) sh_mv.mv_iounmap((a))
75
76 # define __isa_port2addr(a) sh_mv.mv_isa_port2addr(a)
77
78 # define inb __inb
79 # define inw __inw
80 # define inl __inl
81 # define outb __outb
82 # define outw __outw
83 # define outl __outl
84
85 # define inb_p __inb_p
86 # define inw_p __inw_p
87 # define inl_p __inl_p
88 # define outb_p __outb_p
89 # define outw_p __outw_p
90 # define outl_p __outl_p
91
92 # define insb __insb
93 # define insw __insw
94 # define insl __insl
95 # define outsb __outsb
96 # define outsw __outsw
97 # define outsl __outsl
98
99 # define __raw_readb __readb
100 # define __raw_readw __readw
101 # define __raw_readl __readl
102 # define __raw_writeb __writeb
103 # define __raw_writew __writew
104 # define __raw_writel __writel
105
106 #else
107
108 /* Control operations through platform specific headers */
109 # define __WANT_IO_DEF
110
111 # if defined(CONFIG_SH_HP600)
112 # include <asm/io_hd64461.h>
113 # elif defined(CONFIG_SH_OVERDRIVE)
114 # include <asm/io_od.h>
115 # elif defined(CONFIG_SH_SOLUTION_ENGINE)
116 # include <asm/io_se.h>
117 # elif defined(CONFIG_SH_UNKNOWN)
118 # include <asm/io_unknown.h>
119 # else
120 # error "What system is this?"
121 #endif
122
123 #undef __WANT_IO_DEF
124
125 #endif /* GENERIC */
126 #endif /* __KERNEL__ */
127
128 /* These are always function calls, in both kernel and user space */
129 extern unsigned int _inb (unsigned long port);
130 extern unsigned int _inw (unsigned long port);
131 extern unsigned int _inl (unsigned long port);
132 extern void _outb (unsigned char b,unsigned long port);
133 extern void _outw (unsigned short w,unsigned long port);
134 extern void _outl (unsigned int l,unsigned long port);
135 extern unsigned int _inb_p (unsigned long port);
136 extern unsigned int _inw_p (unsigned long port);
137 extern unsigned int _inl_p (unsigned long port);
138 extern void _outb_p (unsigned char b,unsigned long port);
139 extern void _outw_p (unsigned short w,unsigned long port);
140 extern void _outl_p (unsigned int l,unsigned long port);
141 extern void _insb (unsigned long port, void *dst, unsigned long count);
142 extern void _insw (unsigned long port, void *dst, unsigned long count);
143 extern void _insl (unsigned long port, void *dst, unsigned long count);
144 extern void _outsb (unsigned long port, const void *src, unsigned long count);
145 extern void _outsw (unsigned long port, const void *src, unsigned long count);
146 extern void _outsl (unsigned long port, const void *src, unsigned long count);
147 extern unsigned long _readb(unsigned long addr);
148 extern unsigned long _readw(unsigned long addr);
149 extern unsigned long _readl(unsigned long addr);
150 extern void _writeb(unsigned char b, unsigned long addr);
151 extern void _writew(unsigned short b, unsigned long addr);
152 extern void _writel(unsigned int b, unsigned long addr);
153
154 #ifdef __KERNEL__
155 extern unsigned long ___raw_readb(unsigned long addr);
156 extern unsigned long ___raw_readw(unsigned long addr);
157 extern unsigned long ___raw_readl(unsigned long addr);
158 extern unsigned long ___raw_readq(unsigned long addr);
159 extern void ___raw_writeb(unsigned char b, unsigned long addr);
160 extern void ___raw_writew(unsigned short b, unsigned long addr);
161 extern void ___raw_writel(unsigned int b, unsigned long addr);
162 extern void ___raw_writeq(unsigned long b, unsigned long addr);
163 #endif
164
165 #ifdef __KERNEL__
166 /*
167 * The platform header files may define some of these macros to use
168 * the inlined versions where appropriate. These macros may also be
169 * redefined by userlevel programs.
170 */
171 #ifndef inb
172 # define inb(p) _inb(p)
173 #endif
174 #ifndef inw
175 # define inw(p) _inw(p)
176 #endif
177 #ifndef inl
178 # define inl(p) _inl(p)
179 #endif
180
181 #ifndef outb
182 # define outb(b,p) _outb((b),(p))
183 #endif
184 #ifndef outw
185 # define outw(w,p) _outw((w),(p))
186 #endif
187 #ifndef outl
188 # define outl(l,p) _outl((l),(p))
189 #endif
190
191 #ifndef inb_p
192 # define inb_p _inb_p
193 #endif
194 #ifndef inw_p
195 # define inw_p _inw_p
196 #endif
197 #ifndef inl_p
198 # define inl_p _inl_p
199 #endif
200
201 #ifndef outb_p
202 # define outb_p _outb_p
203 #endif
204 #ifndef outw_p
205 # define outw_p _outw_p
206 #endif
207 #ifndef outl_p
208 # define outl_p _outl_p
209 #endif
210
211 #ifndef insb
212 # define insb(p,d,c) _insb((p),(d),(c))
213 #endif
214 #ifndef insw
215 # define insw(p,d,c) _insw((p),(d),(c))
216 #endif
217 #ifndef insl
218 # define insl(p,d,c) _insl((p),(d),(c))
219 #endif
220 #ifndef outsb
221 # define outsb(p,s,c) _outsb((p),(s),(c))
222 #endif
223 #ifndef outsw
224 # define outsw(p,s,c) _outsw((p),(s),(c))
225 #endif
226 #ifndef outsl
227 # define outsl(p,s,c) _outsl((p),(s),(c))
228 #endif
229
230 #ifdef __raw_readb
231 # define readb(a) ({ unsigned long r_ = __raw_readb(a); mb(); r_; })
232 #endif
233 #ifdef __raw_readw
234 # define readw(a) ({ unsigned long r_ = __raw_readw(a); mb(); r_; })
235 #endif
236 #ifdef __raw_readl
237 # define readl(a) ({ unsigned long r_ = __raw_readl(a); mb(); r_; })
238 #endif
239
240 #ifdef __raw_writeb
241 # define writeb(v,a) ({ __raw_writeb((v),(a)); mb(); })
242 #endif
243 #ifdef __raw_writew
244 # define writew(v,a) ({ __raw_writew((v),(a)); mb(); })
245 #endif
246 #ifdef __raw_writel
247 # define writel(v,a) ({ __raw_writel((v),(a)); mb(); })
248 #endif
249
250 #ifndef __raw_readb
251 # define __raw_readb(a) ___raw_readb((unsigned long)(a))
252 #endif
253 #ifndef __raw_readw
254 # define __raw_readw(a) ___raw_readw((unsigned long)(a))
255 #endif
256 #ifndef __raw_readl
257 # define __raw_readl(a) ___raw_readl((unsigned long)(a))
258 #endif
259
260 #ifndef __raw_writeb
261 # define __raw_writeb(v,a) ___raw_writeb((v),(unsigned long)(a))
262 #endif
263 #ifndef __raw_writew
264 # define __raw_writew(v,a) ___raw_writew((v),(unsigned long)(a))
265 #endif
266 #ifndef __raw_writel
267 # define __raw_writel(v,a) ___raw_writel((v),(unsigned long)(a))
268 #endif
269
270 #ifndef readb
271 # define readb(a) _readb((unsigned long)(a))
272 #endif
273 #ifndef readw
274 # define readw(a) _readw((unsigned long)(a))
275 #endif
276 #ifndef readl
277 # define readl(a) _readl((unsigned long)(a))
278 #endif
279
280 #ifndef writeb
281 # define writeb(v,a) _writeb((v),(unsigned long)(a))
282 #endif
283 #ifndef writew
284 # define writew(v,a) _writew((v),(unsigned long)(a))
285 #endif
286 #ifndef writel
287 # define writel(v,a) _writel((v),(unsigned long)(a))
288 #endif
289
290 #else
291
292 /* Userspace declarations. */
293
294 extern unsigned int inb(unsigned long port);
295 extern unsigned int inw(unsigned long port);
296 extern unsigned int inl(unsigned long port);
297 extern void outb(unsigned char b,unsigned long port);
298 extern void outw(unsigned short w,unsigned long port);
299 extern void outl(unsigned int l,unsigned long port);
300 extern void insb (unsigned long port, void *dst, unsigned long count);
301 extern void insw (unsigned long port, void *dst, unsigned long count);
302 extern void insl (unsigned long port, void *dst, unsigned long count);
303 extern void outsb (unsigned long port, const void *src, unsigned long count);
304 extern void outsw (unsigned long port, const void *src, unsigned long count);
305 extern void outsl (unsigned long port, const void *src, unsigned long count);
306 extern unsigned long readb(unsigned long addr);
307 extern unsigned long readw(unsigned long addr);
308 extern unsigned long readl(unsigned long addr);
309 extern void writeb(unsigned char b, unsigned long addr);
310 extern void writew(unsigned short b, unsigned long addr);
311 extern void writel(unsigned int b, unsigned long addr);
312
313 #endif /* __KERNEL__ */
314
315 #ifdef __KERNEL__
316
317 /*
318 * If the platform has PC-like I/O, this function converts the offset into
319 * an address.
320 */
321 extern __inline__ unsigned long isa_port2addr(unsigned long offset)
322 {
323 return __isa_port2addr(offset);
324 }
325
326 #define isa_readb(a) readb(isa_port2addr(a))
327 #define isa_readw(a) readw(isa_port2addr(a))
328 #define isa_readl(a) readl(isa_port2addr(a))
329 #define isa_writeb(b,a) writeb(b,isa_port2addr(a))
330 #define isa_writew(w,a) writew(w,isa_port2addr(a))
331 #define isa_writel(l,a) writel(l,isa_port2addr(a))
332 #define isa_memset_io(a,b,c) \
333 memset((void *)(isa_port2addr((unsigned long)a)),(b),(c))
334 #define isa_memcpy_fromio(a,b,c) \
335 memcpy((a),(void *)(isa_port2addr((unsigned long)(b))),(c))
336 #define isa_memcpy_toio(a,b,c) \
337 memcpy((void *)(isa_port2addr((unsigned long)(a))),(b),(c))
338
339 /* We really want to try and get these to memcpy etc */
340 extern void memcpy_fromio(void *, unsigned long, unsigned long);
341 extern void memcpy_toio(unsigned long, const void *, unsigned long);
342 extern void memset_io(unsigned long, int, unsigned long);
343
344 /* SuperH on-chip I/O functions */
345 extern __inline__ unsigned long ctrl_inb(unsigned long addr)
346 {
347 return *(volatile unsigned char*)addr;
348 }
349
350 extern __inline__ unsigned long ctrl_inw(unsigned long addr)
351 {
352 return *(volatile unsigned short*)addr;
353 }
354
355 extern __inline__ unsigned long ctrl_inl(unsigned long addr)
356 {
357 return *(volatile unsigned long*)addr;
358 }
359
360 extern __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
361 {
362 *(volatile unsigned char*)addr = b;
363 }
364
365 extern __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
366 {
367 *(volatile unsigned short*)addr = b;
368 }
369
370 extern __inline__ void ctrl_outl(unsigned int b, unsigned long addr)
371 {
372 *(volatile unsigned long*)addr = b;
373 }
374
375 #define IO_SPACE_LIMIT 0xffffffff
376
377 #include <asm/addrspace.h>
378
379 /*
380 * Change virtual addresses to physical addresses and vv.
381 * These are trivial on the 1:1 Linux/SuperH mapping
382 */
383 extern __inline__ unsigned long virt_to_phys(volatile void * address)
384 {
385 return PHYSADDR(address);
386 }
387
388 extern __inline__ void * phys_to_virt(unsigned long address)
389 {
390 return (void *)P1SEGADDR(address);
391 }
392
393 #define virt_to_bus virt_to_phys
394 #define bus_to_virt phys_to_virt
395
396 /*
397 * readX/writeX() are used to access memory mapped devices. On some
398 * architectures the memory mapped IO stuff needs to be accessed
399 * differently. On the x86 architecture, we just read/write the
400 * memory location directly.
401 *
402 * On SH, we have the whole physical address space mapped at all times
403 * (as MIPS does), so "ioremap()" and "iounmap()" do not need to do
404 * anything. (This isn't true for all machines but we still handle
405 * these cases with wired TLB entries anyway ...)
406 *
407 * We cheat a bit and always return uncachable areas until we've fixed
408 * the drivers to handle caching properly.
409 */
410 static __inline__ void * ioremap(unsigned long offset, unsigned long size)
411 {
412 return __ioremap(offset, size);
413 }
414
415 /*
416 * This one maps high address device memory and turns off caching for that area.
417 * it's useful if some control registers are in such an area and write combining
418 * or read caching is not desirable:
419 */
420 static __inline__ void * ioremap_nocache (unsigned long offset, unsigned long size)
421 {
422 return __ioremap_nocache(offset, size);
423 }
424
425 static __inline__ void iounmap(void *addr)
426 {
427 return __iounmap(addr);
428 }
429
430 static __inline__ int check_signature(unsigned long io_addr,
431 const unsigned char *signature, int length)
432 {
433 int retval = 0;
434 do {
435 if (readb(io_addr) != *signature)
436 goto out;
437 io_addr++;
438 signature++;
439 length--;
440 } while (length);
441 retval = 1;
442 out:
443 return retval;
444 }
445
446 /*
447 * The caches on some architectures aren't dma-coherent and have need to
448 * handle this in software. There are three types of operations that
449 * can be applied to dma buffers.
450 *
451 * - dma_cache_wback_inv(start, size) makes caches and RAM coherent by
452 * writing the content of the caches back to memory, if necessary.
453 * The function also invalidates the affected part of the caches as
454 * necessary before DMA transfers from outside to memory.
455 * - dma_cache_inv(start, size) invalidates the affected parts of the
456 * caches. Dirty lines of the caches may be written back or simply
457 * be discarded. This operation is necessary before dma operations
458 * to the memory.
459 * - dma_cache_wback(start, size) writes back any dirty lines but does
460 * not invalidate the cache. This can be used before DMA reads from
461 * memory,
462 */
463
464 #define dma_cache_wback_inv(_start,_size) \
465 cache_flush_area((unsigned long)(_start),((unsigned long)(_start)+(_size)))
466 #define dma_cache_inv(_start,_size) \
467 cache_purge_area((unsigned long)(_start),((unsigned long)(_start)+(_size)))
468 #define dma_cache_wback(_start,_size) \
469 cache_wback_area((unsigned long)(_start),((unsigned long)(_start)+(_size)))
470
471 #endif /* __KERNEL__ */
472 #endif /* __ASM_SH_IO_H */
473
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.