blob: 84a638da78df17ca46d8c62c4750d17bc6d97d28 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001#ifndef _ASM_IO_H
2#define _ASM_IO_H
3
wdenk591dda52002-11-18 00:14:45 +00004/*
5 * This file contains the definitions for the x86 IO instructions
6 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
7 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
8 * versions of the single-IO instructions (inb_p/inw_p/..).
9 *
10 * This file is not meant to be obfuscating: it's just complicated
11 * to (a) handle it all in a way that makes gcc able to optimize it
12 * as well as possible and (b) trying to avoid writing the same thing
13 * over and over again with slight variations and possibly making a
14 * mistake somewhere.
15 */
16
17/*
18 * Thanks to James van Artsdalen for a better timing-fix than
19 * the two short jumps: using outb's to a nonexistent port seems
20 * to guarantee better timings even on fast machines.
21 *
22 * On the other hand, I'd like to be sure of a non-existent port:
23 * I feel a bit unsafe about using 0x80 (should be safe, though)
24 *
25 * Linus
26 */
27
28 /*
29 * Bit simplified and optimized by Jan Hubicka
30 * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999.
31 *
32 * isa_memset_io, isa_memcpy_fromio, isa_memcpy_toio added,
33 * isa_read[wl] and isa_write[wl] fixed
34 * - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
35 */
36
37#define IO_SPACE_LIMIT 0xffff
38
Gabe Blackb74308d2012-10-20 12:33:13 +000039#include <asm/types.h>
40
wdenk591dda52002-11-18 00:14:45 +000041
42#ifdef __KERNEL__
43
44
45/*
46 * readX/writeX() are used to access memory mapped devices. On some
47 * architectures the memory mapped IO stuff needs to be accessed
48 * differently. On the x86 architecture, we just read/write the
49 * memory location directly.
50 */
51
52#define readb(addr) (*(volatile unsigned char *) (addr))
53#define readw(addr) (*(volatile unsigned short *) (addr))
54#define readl(addr) (*(volatile unsigned int *) (addr))
55#define __raw_readb readb
56#define __raw_readw readw
57#define __raw_readl readl
58
59#define writeb(b,addr) (*(volatile unsigned char *) (addr) = (b))
60#define writew(b,addr) (*(volatile unsigned short *) (addr) = (b))
61#define writel(b,addr) (*(volatile unsigned int *) (addr) = (b))
62#define __raw_writeb writeb
63#define __raw_writew writew
64#define __raw_writel writel
65
66#define memset_io(a,b,c) memset((a),(b),(c))
67#define memcpy_fromio(a,b,c) memcpy((a),(b),(c))
68#define memcpy_toio(a,b,c) memcpy((a),(b),(c))
69
70/*
71 * ISA space is 'always mapped' on a typical x86 system, no need to
72 * explicitly ioremap() it. The fact that the ISA IO space is mapped
73 * to PAGE_OFFSET is pure coincidence - it does not mean ISA values
74 * are physical addresses. The following constant pointer can be
75 * used as the IO-area pointer (it can be iounmapped as well, so the
76 * analogy with PCI is quite large):
77 */
78#define isa_readb(a) readb((a))
79#define isa_readw(a) readw((a))
80#define isa_readl(a) readl((a))
81#define isa_writeb(b,a) writeb(b,(a))
82#define isa_writew(w,a) writew(w,(a))
83#define isa_writel(l,a) writel(l,(a))
84#define isa_memset_io(a,b,c) memset_io((a),(b),(c))
85#define isa_memcpy_fromio(a,b,c) memcpy_fromio((a),(b),(c))
86#define isa_memcpy_toio(a,b,c) memcpy_toio((a),(b),(c))
87
88
wdenk591dda52002-11-18 00:14:45 +000089static inline int check_signature(unsigned long io_addr,
90 const unsigned char *signature, int length)
91{
92 int retval = 0;
93 do {
94 if (readb(io_addr) != *signature)
95 goto out;
96 io_addr++;
97 signature++;
98 length--;
99 } while (length);
100 retval = 1;
101out:
102 return retval;
103}
104
105/**
106 * isa_check_signature - find BIOS signatures
wdenk57b2d802003-06-27 21:31:46 +0000107 * @io_addr: mmio address to check
wdenk591dda52002-11-18 00:14:45 +0000108 * @signature: signature block
109 * @length: length of signature
110 *
111 * Perform a signature comparison with the ISA mmio address io_addr.
112 * Returns 1 on a match.
113 *
114 * This function is deprecated. New drivers should use ioremap and
115 * check_signature.
116 */
wdenk57b2d802003-06-27 21:31:46 +0000117
wdenk591dda52002-11-18 00:14:45 +0000118
119static inline int isa_check_signature(unsigned long io_addr,
120 const unsigned char *signature, int length)
121{
122 int retval = 0;
123 do {
124 if (isa_readb(io_addr) != *signature)
125 goto out;
126 io_addr++;
127 signature++;
128 length--;
129 } while (length);
130 retval = 1;
131out:
132 return retval;
133}
134
135#endif /* __KERNEL__ */
136
137#ifdef SLOW_IO_BY_JUMPING
138#define __SLOW_DOWN_IO "\njmp 1f\n1:\tjmp 1f\n1:"
139#else
Stefan Reinauer87583072012-10-20 12:33:16 +0000140#define __SLOW_DOWN_IO "\noutb %%al,$0xed"
wdenk591dda52002-11-18 00:14:45 +0000141#endif
142
143#ifdef REALLY_SLOW_IO
144#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO __SLOW_DOWN_IO
145#else
146#define __FULL_SLOW_DOWN_IO __SLOW_DOWN_IO
147#endif
148
149
150/*
151 * Talk about misusing macros..
152 */
153#define __OUT1(s,x) \
154static inline void out##s(unsigned x value, unsigned short port) {
155
156#define __OUT2(s,s1,s2) \
157__asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
158
159
160#define __OUT(s,s1,x) \
161__OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
wdenk57b2d802003-06-27 21:31:46 +0000162__OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));}
wdenk591dda52002-11-18 00:14:45 +0000163
164#define __IN1(s) \
165static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
166
167#define __IN2(s,s1,s2) \
168__asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
169
170#define __IN(s,s1,i...) \
171__IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
wdenk57b2d802003-06-27 21:31:46 +0000172__IN1(s##_p) __IN2(s,s1,"w") __FULL_SLOW_DOWN_IO : "=a" (_v) : "Nd" (port) ,##i ); return _v; }
wdenk591dda52002-11-18 00:14:45 +0000173
174#define __INS(s) \
175static inline void ins##s(unsigned short port, void * addr, unsigned long count) \
176{ __asm__ __volatile__ ("rep ; ins" #s \
177: "=D" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
178
179#define __OUTS(s) \
180static inline void outs##s(unsigned short port, const void * addr, unsigned long count) \
181{ __asm__ __volatile__ ("rep ; outs" #s \
182: "=S" (addr), "=c" (count) : "d" (port),"0" (addr),"1" (count)); }
183
184#define RETURN_TYPE unsigned char
185__IN(b,"")
186#undef RETURN_TYPE
187#define RETURN_TYPE unsigned short
188__IN(w,"")
189#undef RETURN_TYPE
190#define RETURN_TYPE unsigned int
191__IN(l,"")
192#undef RETURN_TYPE
193
194__OUT(b,"b",char)
195__OUT(w,"w",short)
196__OUT(l,,int)
197
198__INS(b)
199__INS(w)
200__INS(l)
201
202__OUTS(b)
203__OUTS(w)
204__OUTS(l)
205
Haiying Wangc123a382007-02-21 16:52:31 +0100206static inline void sync(void)
207{
208}
209
Haavard Skinnemoenf9855512007-12-13 12:56:33 +0100210/*
211 * Given a physical address and a length, return a virtual address
212 * that can be used to access the memory range with the caching
213 * properties specified by "flags".
214 */
Haavard Skinnemoenf9855512007-12-13 12:56:33 +0100215#define MAP_NOCACHE (0)
216#define MAP_WRCOMBINE (0)
217#define MAP_WRBACK (0)
218#define MAP_WRTHROUGH (0)
219
220static inline void *
221map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
222{
223 return (void *)paddr;
224}
225
226/*
227 * Take down a mapping set up by map_physmem().
228 */
229static inline void unmap_physmem(void *vaddr, unsigned long flags)
230{
231
232}
233
Kumar Gala9364a672008-12-13 17:20:27 -0600234static inline phys_addr_t virt_to_phys(void * vaddr)
235{
236 return (phys_addr_t)(vaddr);
237}
238
Simon Glassbc474092012-10-10 13:12:53 +0000239/*
240 * TODO: The kernel offers some more advanced versions of barriers, it might
241 * have some advantages to use them instead of the simple one here.
242 */
243#define dmb() __asm__ __volatile__ ("" : : : "memory")
244#define __iormb() dmb()
245#define __iowmb() dmb()
246
wdenk591dda52002-11-18 00:14:45 +0000247#endif