aboutsummaryrefslogtreecommitdiffstats
path: root/gpxe/src/include/gpxe/efi/efi_io.h
blob: 93f559db03dd1d7eefdc2d62b20aba299d319c4d (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef _GPXE_EFI_IO_H
#define _GPXE_EFI_IO_H

/** @file
 *
 * gPXE I/O API for EFI
 *
 * EFI runs with flat physical addressing, so the various mappings
 * between virtual addresses, I/O addresses and bus addresses are all
 * no-ops.  I/O is handled using the EFI_CPU_IO_PROTOCOL.
 */

#ifdef IOAPI_EFI
#define IOAPI_PREFIX_efi
#else
#define IOAPI_PREFIX_efi __efi_
#endif

extern unsigned long long efi_ioread ( volatile void *io_addr,
				       size_t size );
extern void efi_iowrite ( unsigned long long data, volatile void *io_addr,
			  size_t size );
extern void efi_ioreads ( volatile void *io_addr, void *data,
			  size_t size, unsigned int count );
extern void efi_iowrites ( volatile void *io_addr, const void *data,
			  size_t size, unsigned int count );

/*
 * Physical<->Bus and Bus<->I/O address mappings
 *
 * EFI runs with flat physical addressing, so these are all no-ops.
 *
 */

static inline __always_inline unsigned long
IOAPI_INLINE ( efi, phys_to_bus ) ( unsigned long phys_addr ) {
	return phys_addr;
}

static inline __always_inline unsigned long
IOAPI_INLINE ( efi, bus_to_phys ) ( unsigned long bus_addr ) {
	return bus_addr;
}

static inline __always_inline void *
IOAPI_INLINE ( efi, ioremap ) ( unsigned long bus_addr, size_t len __unused ) {
	return ( ( void * ) bus_addr );
}

static inline __always_inline void
IOAPI_INLINE ( efi, iounmap ) ( volatile const void *io_addr __unused ) {
	/* Nothing to do */
}

static inline __always_inline unsigned long
IOAPI_INLINE ( efi, io_to_bus ) ( volatile const void *io_addr ) {
	return ( ( unsigned long ) io_addr );
}

/*
 * I/O functions
 *
 */

static inline __always_inline uint8_t
IOAPI_INLINE ( efi, readb ) ( volatile uint8_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline uint16_t
IOAPI_INLINE ( efi, readw ) ( volatile uint16_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline uint32_t
IOAPI_INLINE ( efi, readl ) ( volatile uint32_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline uint64_t
IOAPI_INLINE ( efi, readq ) ( volatile uint64_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, writeb ) ( uint8_t data, volatile uint8_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, writew ) ( uint16_t data, volatile uint16_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, writel ) ( uint32_t data, volatile uint32_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, writeq ) ( uint64_t data, volatile uint64_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline uint8_t
IOAPI_INLINE ( efi, inb ) ( volatile uint8_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline uint16_t
IOAPI_INLINE ( efi, inw ) ( volatile uint16_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline uint32_t
IOAPI_INLINE ( efi, inl ) ( volatile uint32_t *io_addr ) {
	return efi_ioread ( io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, outb ) ( uint8_t data, volatile uint8_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, outw ) ( uint16_t data, volatile uint16_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, outl ) ( uint32_t data, volatile uint32_t *io_addr ) {
	efi_iowrite ( data, io_addr, sizeof ( *io_addr ) );
}

static inline __always_inline void
IOAPI_INLINE ( efi, insb ) ( volatile uint8_t *io_addr, uint8_t *data,
			     unsigned int count ) {
	efi_ioreads ( io_addr, data, sizeof ( *io_addr ), count );
}

static inline __always_inline void
IOAPI_INLINE ( efi, insw ) ( volatile uint16_t *io_addr, uint16_t *data,
			     unsigned int count ) {
	efi_ioreads ( io_addr, data, sizeof ( *io_addr ), count );
}

static inline __always_inline void
IOAPI_INLINE ( efi, insl ) ( volatile uint32_t *io_addr, uint32_t *data,
			     unsigned int count ) {
	efi_ioreads ( io_addr, data, sizeof ( *io_addr ), count );
}

static inline __always_inline void
IOAPI_INLINE ( efi, outsb ) ( volatile uint8_t *io_addr, const uint8_t *data,
			      unsigned int count ) {
	efi_iowrites ( io_addr, data, sizeof ( *io_addr ), count );
}

static inline __always_inline void
IOAPI_INLINE ( efi, outsw ) ( volatile uint16_t *io_addr, const uint16_t *data,
			      unsigned int count ) {
	efi_iowrites ( io_addr, data, sizeof ( *io_addr ), count );
}

static inline __always_inline void
IOAPI_INLINE ( efi, outsl ) ( volatile uint32_t *io_addr, const uint32_t *data,
			      unsigned int count ) {
	efi_iowrites ( io_addr, data, sizeof ( *io_addr ), count );
}

static inline __always_inline void
IOAPI_INLINE ( efi, mb ) ( void ) {
	/* Do nothing; EFI readl()/writel() calls already act as
	 * memory barriers.
	 */
}

#endif /* _GPXE_EFI_IO_H */