1 #ifndef _ASM_IO_H
2 #define _ASM_IO_H
3 
4 #include <xen/vmap.h>
5 #include <xen/types.h>
6 #include <asm/page.h>
7 
8 #define readb(x) (*(volatile uint8_t  *)(x))
9 #define readw(x) (*(volatile uint16_t *)(x))
10 #define readl(x) (*(volatile uint32_t *)(x))
11 #define readq(x) (*(volatile uint64_t *)(x))
12 #define writeb(d,x) (*(volatile uint8_t  *)(x) = (d))
13 #define writew(d,x) (*(volatile uint16_t *)(x) = (d))
14 #define writel(d,x) (*(volatile uint32_t *)(x) = (d))
15 #define writeq(d,x) (*(volatile uint64_t *)(x) = (d))
16 
17 #define __OUT1(s,x) \
18 static inline void out##s(unsigned x value, unsigned short port) {
19 
20 #define __OUT2(s,s1,s2) \
21 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
22 
23 #define __OUT(s,s1,x) \
24 __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
25 __OUT1(s##_p,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port));}
26 
27 #define __IN1(s) \
28 static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
29 
30 #define __IN2(s,s1,s2) \
31 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
32 
33 #define __IN(s,s1,i...) \
34 __IN1(s) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; } \
35 __IN1(s##_p) __IN2(s,s1,"w") : "=a" (_v) : "Nd" (port) ,##i ); return _v; }
36 
37 #define RETURN_TYPE unsigned char
38 __IN(b,"")
39 #undef RETURN_TYPE
40 #define RETURN_TYPE unsigned short
41 __IN(w,"")
42 #undef RETURN_TYPE
43 #define RETURN_TYPE unsigned int
44 __IN(l,"")
45 #undef RETURN_TYPE
46 
47 __OUT(b,"b",char)
48 __OUT(w,"w",short)
49 __OUT(l,,int)
50 
51 /* Function pointer used to handle platform specific I/O port emulation. */
52 #define IOEMUL_QUIRK_STUB_BYTES 9
53 extern unsigned int (*ioemul_handle_quirk)(
54     u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs);
55 
56 #endif
57