1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#ifndef ARCH_I386_IO_H
#define ARCH_I386_IO_H
#include <stdint.h>
/* Helper functions for directly doing I/O */
static inline __attribute__((__always_inline__))
uint8_t inb(uint16_t port)
{
uint8_t result;
__asm__ __volatile__ (
"inb %w1,%0"
:"=a" (result)
:"Nd" (port));
return result;
}
static inline __attribute__((__always_inline__))
uint16_t inw(uint16_t port)
{
uint16_t result;
__asm__ __volatile__ (
"inw %w1,%0"
:"=a" (result)
:"Nd" (port));
return result;
}
static inline __attribute__((__always_inline__))
uint32_t inl(uint32_t port)
{
uint32_t result;
__asm__ __volatile__ (
"inl %w1,%0"
:"=a" (result)
:"Nd" (port));
return result;
}
static inline __attribute__((__always_inline__))
void outb (uint8_t value, uint16_t port)
{
__asm__ __volatile__ (
"outb %b0,%w1"
:
:"a" (value), "Nd" (port));
}
static inline __attribute__((__always_inline__))
void outw (uint16_t value, uint16_t port)
{
__asm__ __volatile__ (
"outw %w0,%w1"
:
:"a" (value), "Nd" (port));
}
static inline __attribute__((__always_inline__))
void outl (uint32_t value, uint16_t port)
{
__asm__ __volatile__ (
"outl %0,%w1"
:
:"a" (value), "Nd" (port));
}
/*
* readX/writeX() are used to access memory mapped devices. On some
* architectures the memory mapped IO stuff needs to be accessed
* differently. On the x86 architecture, we just read/write the
* memory location directly.
*/
static inline __attribute__((__always_inline__))
unsigned char readb(const volatile void *addr)
{
return *(volatile unsigned char *) addr;
}
static inline __attribute__((__always_inline__))
unsigned short readw(const volatile void *addr)
{
return *(volatile unsigned short *) addr;
}
static inline __attribute__((__always_inline__))
unsigned int readl(const volatile void *addr)
{
return *(volatile unsigned int *) addr;
}
static inline __attribute__((__always_inline__))
void writeb(unsigned char b, volatile void *addr)
{
*(volatile unsigned char *) addr = b;
}
static inline __attribute__((__always_inline__))
void writew(unsigned short b, volatile void *addr)
{
*(volatile unsigned short *) addr = b;
}
static inline __attribute__((__always_inline__))
void writel(unsigned int b, volatile void *addr)
{
*(volatile unsigned int *) addr = b;
}
#endif /* ARCH_I386_IO_H */
|