Browse Source

[ioapi] Split ioremap() out to a separate IOMAP API

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
5bd8427d3d

+ 0
- 3
src/arch/x86/core/x86_io.c View File

74
 
74
 
75
 PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
75
 PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
76
 PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
76
 PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
77
-PROVIDE_IOAPI_INLINE ( x86, ioremap );
78
-PROVIDE_IOAPI_INLINE ( x86, iounmap );
79
-PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
80
 PROVIDE_IOAPI_INLINE ( x86, readb );
77
 PROVIDE_IOAPI_INLINE ( x86, readb );
81
 PROVIDE_IOAPI_INLINE ( x86, readw );
78
 PROVIDE_IOAPI_INLINE ( x86, readw );
82
 PROVIDE_IOAPI_INLINE ( x86, readl );
79
 PROVIDE_IOAPI_INLINE ( x86, readl );

+ 12
- 0
src/arch/x86/include/bits/iomap.h View File

1
+#ifndef _BITS_IOMAP_H
2
+#define _BITS_IOMAP_H
3
+
4
+/** @file
5
+ *
6
+ * x86-specific I/O mapping API implementations
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#endif /* _BITS_IOMAP_H */

+ 1
- 16
src/arch/x86/include/ipxe/x86_io.h View File

32
 #define PAGE_SHIFT 12
32
 #define PAGE_SHIFT 12
33
 
33
 
34
 /*
34
 /*
35
- * Physical<->Bus and Bus<->I/O address mappings
35
+ * Physical<->Bus address mappings
36
  *
36
  *
37
  */
37
  */
38
 
38
 
46
 	return bus_addr;
46
 	return bus_addr;
47
 }
47
 }
48
 
48
 
49
-static inline __always_inline void *
50
-IOAPI_INLINE ( x86, ioremap ) ( unsigned long bus_addr, size_t len __unused ) {
51
-	return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL );
52
-}
53
-
54
-static inline __always_inline void
55
-IOAPI_INLINE ( x86, iounmap ) ( volatile const void *io_addr __unused ) {
56
-	/* Nothing to do */
57
-}
58
-
59
-static inline __always_inline unsigned long
60
-IOAPI_INLINE ( x86, io_to_bus ) ( volatile const void *io_addr ) {
61
-	return virt_to_phys ( io_addr );
62
-}
63
-
64
 /*
49
 /*
65
  * MMIO reads and writes up to native word size
50
  * MMIO reads and writes up to native word size
66
  *
51
  *

+ 1
- 0
src/config/defaults/efi.h View File

11
 
11
 
12
 #define UACCESS_EFI
12
 #define UACCESS_EFI
13
 #define IOAPI_X86
13
 #define IOAPI_X86
14
+#define IOMAP_VIRT
14
 #define PCIAPI_EFI
15
 #define PCIAPI_EFI
15
 #define CONSOLE_EFI
16
 #define CONSOLE_EFI
16
 #define TIMER_EFI
17
 #define TIMER_EFI

+ 1
- 0
src/config/defaults/pcbios.h View File

11
 
11
 
12
 #define UACCESS_LIBRM
12
 #define UACCESS_LIBRM
13
 #define IOAPI_X86
13
 #define IOAPI_X86
14
+#define IOMAP_VIRT
14
 #define PCIAPI_PCBIOS
15
 #define PCIAPI_PCBIOS
15
 #define TIMER_PCBIOS
16
 #define TIMER_PCBIOS
16
 #define CONSOLE_PCBIOS
17
 #define CONSOLE_PCBIOS

+ 36
- 0
src/core/iomap_virt.c View File

1
+/*
2
+ * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or (at your option) any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ *
19
+ * You can also choose to distribute this program under the terms of
20
+ * the Unmodified Binary Distribution Licence (as given in the file
21
+ * COPYING.UBDL), provided that you have satisfied its requirements.
22
+ */
23
+
24
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
+
26
+/** @file
27
+ *
28
+ * iPXE I/O mapping API using phys_to_virt()
29
+ *
30
+ */
31
+
32
+#include <ipxe/iomap.h>
33
+
34
+PROVIDE_IOMAP_INLINE ( virt, ioremap );
35
+PROVIDE_IOMAP_INLINE ( virt, iounmap );
36
+PROVIDE_IOMAP_INLINE ( virt, io_to_bus );

+ 1
- 25
src/include/ipxe/io.h View File

20
 
20
 
21
 #include <stdint.h>
21
 #include <stdint.h>
22
 #include <ipxe/api.h>
22
 #include <ipxe/api.h>
23
+#include <ipxe/iomap.h>
23
 #include <config/ioapi.h>
24
 #include <config/ioapi.h>
24
-#include <ipxe/uaccess.h>
25
 
25
 
26
 /** Page size */
26
 /** Page size */
27
 #define PAGE_SIZE ( 1 << PAGE_SHIFT )
27
 #define PAGE_SIZE ( 1 << PAGE_SHIFT )
196
 	return phys_to_virt ( bus_to_phys ( bus_addr ) );
196
 	return phys_to_virt ( bus_to_phys ( bus_addr ) );
197
 }
197
 }
198
 
198
 
199
-/**
200
- * Map bus address as an I/O address
201
- *
202
- * @v bus_addr		Bus address
203
- * @v len		Length of region
204
- * @ret io_addr		I/O address
205
- */
206
-void * ioremap ( unsigned long bus_addr, size_t len );
207
-
208
-/**
209
- * Unmap I/O address
210
- *
211
- * @v io_addr		I/O address
212
- */
213
-void iounmap ( volatile const void *io_addr );
214
-
215
-/**
216
- * Convert I/O address to bus address (for debug only)
217
- *
218
- * @v io_addr		I/O address
219
- * @ret bus_addr	Bus address
220
- */
221
-unsigned long io_to_bus ( volatile const void *io_addr );
222
-
223
 /**
199
 /**
224
  * Read byte from memory-mapped device
200
  * Read byte from memory-mapped device
225
  *
201
  *

+ 78
- 0
src/include/ipxe/iomap.h View File

1
+#ifndef _IPXE_IOMAP_H
2
+#define _IPXE_IOMAP_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE I/O mapping API
7
+ *
8
+ * The I/O mapping API provides methods for mapping and unmapping I/O
9
+ * devices.
10
+ */
11
+
12
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13
+
14
+#include <stdint.h>
15
+#include <ipxe/api.h>
16
+#include <config/ioapi.h>
17
+#include <ipxe/uaccess.h>
18
+
19
+/**
20
+ * Calculate static inline I/O mapping API function name
21
+ *
22
+ * @v _prefix		Subsystem prefix
23
+ * @v _api_func		API function
24
+ * @ret _subsys_func	Subsystem API function
25
+ */
26
+#define IOMAP_INLINE( _subsys, _api_func ) \
27
+	SINGLE_API_INLINE ( IOMAP_PREFIX_ ## _subsys, _api_func )
28
+
29
+/**
30
+ * Provide an I/O mapping API implementation
31
+ *
32
+ * @v _prefix		Subsystem prefix
33
+ * @v _api_func		API function
34
+ * @v _func		Implementing function
35
+ */
36
+#define PROVIDE_IOMAP( _subsys, _api_func, _func ) \
37
+	PROVIDE_SINGLE_API ( IOMAP_PREFIX_ ## _subsys, _api_func, _func )
38
+
39
+/**
40
+ * Provide a static inline I/O mapping API implementation
41
+ *
42
+ * @v _prefix		Subsystem prefix
43
+ * @v _api_func		API function
44
+ */
45
+#define PROVIDE_IOMAP_INLINE( _subsys, _api_func ) \
46
+	PROVIDE_SINGLE_API_INLINE ( IOMAP_PREFIX_ ## _subsys, _api_func )
47
+
48
+/* Include all architecture-independent I/O API headers */
49
+#include <ipxe/iomap_virt.h>
50
+
51
+/* Include all architecture-dependent I/O API headers */
52
+#include <bits/iomap.h>
53
+
54
+/**
55
+ * Map bus address as an I/O address
56
+ *
57
+ * @v bus_addr		Bus address
58
+ * @v len		Length of region
59
+ * @ret io_addr		I/O address
60
+ */
61
+void * ioremap ( unsigned long bus_addr, size_t len );
62
+
63
+/**
64
+ * Unmap I/O address
65
+ *
66
+ * @v io_addr		I/O address
67
+ */
68
+void iounmap ( volatile const void *io_addr );
69
+
70
+/**
71
+ * Convert I/O address to bus address (for debug only)
72
+ *
73
+ * @v io_addr		I/O address
74
+ * @ret bus_addr	Bus address
75
+ */
76
+unsigned long io_to_bus ( volatile const void *io_addr );
77
+
78
+#endif /* _IPXE_IOMAP_H */

+ 33
- 0
src/include/ipxe/iomap_virt.h View File

1
+#ifndef _IPXE_IOMAP_VIRT_H
2
+#define _IPXE_IOMAP_VIRT_H
3
+
4
+/** @file
5
+ *
6
+ * iPXE I/O mapping API using phys_to_virt()
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
+
12
+#ifdef IOMAP_VIRT
13
+#define IOMAP_PREFIX_virt
14
+#else
15
+#define IOMAP_PREFIX_virt __virt_
16
+#endif
17
+
18
+static inline __always_inline void *
19
+IOMAP_INLINE ( virt, ioremap ) ( unsigned long bus_addr, size_t len __unused ) {
20
+	return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL );
21
+}
22
+
23
+static inline __always_inline void
24
+IOMAP_INLINE ( virt, iounmap ) ( volatile const void *io_addr __unused ) {
25
+	/* Nothing to do */
26
+}
27
+
28
+static inline __always_inline unsigned long
29
+IOMAP_INLINE ( virt, io_to_bus ) ( volatile const void *io_addr ) {
30
+	return virt_to_phys ( io_addr );
31
+}
32
+
33
+#endif /* _IPXE_IOMAP_VIRT_H */

Loading…
Cancel
Save