]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[ioapi] Split ioremap() out to a separate IOMAP API
authorMichael Brown <mcb30@ipxe.org>
Fri, 26 Feb 2016 15:33:40 +0000 (15:33 +0000)
committerMichael Brown <mcb30@ipxe.org>
Fri, 26 Feb 2016 15:33:40 +0000 (15:33 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/core/x86_io.c
src/arch/x86/include/bits/iomap.h [new file with mode: 0644]
src/arch/x86/include/ipxe/x86_io.h
src/config/defaults/efi.h
src/config/defaults/pcbios.h
src/core/iomap_virt.c [new file with mode: 0644]
src/include/ipxe/io.h
src/include/ipxe/iomap.h [new file with mode: 0644]
src/include/ipxe/iomap_virt.h [new file with mode: 0644]

index 3081fa8b94c87278071a04db7d7e46f1536d40c1..6c6b6e1e78a95139b0198e85ec41a398ade9eaa7 100644 (file)
@@ -74,9 +74,6 @@ static __unused void i386_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
 
 PROVIDE_IOAPI_INLINE ( x86, phys_to_bus );
 PROVIDE_IOAPI_INLINE ( x86, bus_to_phys );
-PROVIDE_IOAPI_INLINE ( x86, ioremap );
-PROVIDE_IOAPI_INLINE ( x86, iounmap );
-PROVIDE_IOAPI_INLINE ( x86, io_to_bus );
 PROVIDE_IOAPI_INLINE ( x86, readb );
 PROVIDE_IOAPI_INLINE ( x86, readw );
 PROVIDE_IOAPI_INLINE ( x86, readl );
diff --git a/src/arch/x86/include/bits/iomap.h b/src/arch/x86/include/bits/iomap.h
new file mode 100644 (file)
index 0000000..6110e31
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _BITS_IOMAP_H
+#define _BITS_IOMAP_H
+
+/** @file
+ *
+ * x86-specific I/O mapping API implementations
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#endif /* _BITS_IOMAP_H */
index 5214e9fbbfbca8e5fe832291cec91963a10122a7..a6ebe1f4ce5fb4d7da5081a5d4f4d4f6e49aa989 100644 (file)
@@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #define PAGE_SHIFT 12
 
 /*
- * Physical<->Bus and Bus<->I/O address mappings
+ * Physical<->Bus address mappings
  *
  */
 
@@ -46,21 +46,6 @@ IOAPI_INLINE ( x86, bus_to_phys ) ( unsigned long bus_addr ) {
        return bus_addr;
 }
 
-static inline __always_inline void *
-IOAPI_INLINE ( x86, ioremap ) ( unsigned long bus_addr, size_t len __unused ) {
-       return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL );
-}
-
-static inline __always_inline void
-IOAPI_INLINE ( x86, iounmap ) ( volatile const void *io_addr __unused ) {
-       /* Nothing to do */
-}
-
-static inline __always_inline unsigned long
-IOAPI_INLINE ( x86, io_to_bus ) ( volatile const void *io_addr ) {
-       return virt_to_phys ( io_addr );
-}
-
 /*
  * MMIO reads and writes up to native word size
  *
index 502bef1d95d34969128375e9f40759f1a9cb13fb..24b93a02d55970afa0d4b28b66f9637172cda7a5 100644 (file)
@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #define UACCESS_EFI
 #define IOAPI_X86
+#define IOMAP_VIRT
 #define PCIAPI_EFI
 #define CONSOLE_EFI
 #define TIMER_EFI
index 3ed8343ce11d182100eef64ed29291c5dd75d596..56ed007384901161a829c7b87cc8fb7144d941ba 100644 (file)
@@ -11,6 +11,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #define UACCESS_LIBRM
 #define IOAPI_X86
+#define IOMAP_VIRT
 #define PCIAPI_PCBIOS
 #define TIMER_PCBIOS
 #define CONSOLE_PCBIOS
diff --git a/src/core/iomap_virt.c b/src/core/iomap_virt.c
new file mode 100644 (file)
index 0000000..c7f4872
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * iPXE I/O mapping API using phys_to_virt()
+ *
+ */
+
+#include <ipxe/iomap.h>
+
+PROVIDE_IOMAP_INLINE ( virt, ioremap );
+PROVIDE_IOMAP_INLINE ( virt, iounmap );
+PROVIDE_IOMAP_INLINE ( virt, io_to_bus );
index af767915ddc565d590425f719a9711ebb8e05c66..fe138819104728a7ea12ce2a7205294a477fb70a 100644 (file)
@@ -20,8 +20,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <stdint.h>
 #include <ipxe/api.h>
+#include <ipxe/iomap.h>
 #include <config/ioapi.h>
-#include <ipxe/uaccess.h>
 
 /** Page size */
 #define PAGE_SIZE ( 1 << PAGE_SHIFT )
@@ -196,30 +196,6 @@ static inline __always_inline void * bus_to_virt ( unsigned long bus_addr ) {
        return phys_to_virt ( bus_to_phys ( bus_addr ) );
 }
 
-/**
- * Map bus address as an I/O address
- *
- * @v bus_addr         Bus address
- * @v len              Length of region
- * @ret io_addr                I/O address
- */
-void * ioremap ( unsigned long bus_addr, size_t len );
-
-/**
- * Unmap I/O address
- *
- * @v io_addr          I/O address
- */
-void iounmap ( volatile const void *io_addr );
-
-/**
- * Convert I/O address to bus address (for debug only)
- *
- * @v io_addr          I/O address
- * @ret bus_addr       Bus address
- */
-unsigned long io_to_bus ( volatile const void *io_addr );
-
 /**
  * Read byte from memory-mapped device
  *
diff --git a/src/include/ipxe/iomap.h b/src/include/ipxe/iomap.h
new file mode 100644 (file)
index 0000000..b8ded38
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef _IPXE_IOMAP_H
+#define _IPXE_IOMAP_H
+
+/** @file
+ *
+ * iPXE I/O mapping API
+ *
+ * The I/O mapping API provides methods for mapping and unmapping I/O
+ * devices.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/api.h>
+#include <config/ioapi.h>
+#include <ipxe/uaccess.h>
+
+/**
+ * Calculate static inline I/O mapping API function name
+ *
+ * @v _prefix          Subsystem prefix
+ * @v _api_func                API function
+ * @ret _subsys_func   Subsystem API function
+ */
+#define IOMAP_INLINE( _subsys, _api_func ) \
+       SINGLE_API_INLINE ( IOMAP_PREFIX_ ## _subsys, _api_func )
+
+/**
+ * Provide an I/O mapping API implementation
+ *
+ * @v _prefix          Subsystem prefix
+ * @v _api_func                API function
+ * @v _func            Implementing function
+ */
+#define PROVIDE_IOMAP( _subsys, _api_func, _func ) \
+       PROVIDE_SINGLE_API ( IOMAP_PREFIX_ ## _subsys, _api_func, _func )
+
+/**
+ * Provide a static inline I/O mapping API implementation
+ *
+ * @v _prefix          Subsystem prefix
+ * @v _api_func                API function
+ */
+#define PROVIDE_IOMAP_INLINE( _subsys, _api_func ) \
+       PROVIDE_SINGLE_API_INLINE ( IOMAP_PREFIX_ ## _subsys, _api_func )
+
+/* Include all architecture-independent I/O API headers */
+#include <ipxe/iomap_virt.h>
+
+/* Include all architecture-dependent I/O API headers */
+#include <bits/iomap.h>
+
+/**
+ * Map bus address as an I/O address
+ *
+ * @v bus_addr         Bus address
+ * @v len              Length of region
+ * @ret io_addr                I/O address
+ */
+void * ioremap ( unsigned long bus_addr, size_t len );
+
+/**
+ * Unmap I/O address
+ *
+ * @v io_addr          I/O address
+ */
+void iounmap ( volatile const void *io_addr );
+
+/**
+ * Convert I/O address to bus address (for debug only)
+ *
+ * @v io_addr          I/O address
+ * @ret bus_addr       Bus address
+ */
+unsigned long io_to_bus ( volatile const void *io_addr );
+
+#endif /* _IPXE_IOMAP_H */
diff --git a/src/include/ipxe/iomap_virt.h b/src/include/ipxe/iomap_virt.h
new file mode 100644 (file)
index 0000000..4962b7c
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef _IPXE_IOMAP_VIRT_H
+#define _IPXE_IOMAP_VIRT_H
+
+/** @file
+ *
+ * iPXE I/O mapping API using phys_to_virt()
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#ifdef IOMAP_VIRT
+#define IOMAP_PREFIX_virt
+#else
+#define IOMAP_PREFIX_virt __virt_
+#endif
+
+static inline __always_inline void *
+IOMAP_INLINE ( virt, ioremap ) ( unsigned long bus_addr, size_t len __unused ) {
+       return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL );
+}
+
+static inline __always_inline void
+IOMAP_INLINE ( virt, iounmap ) ( volatile const void *io_addr __unused ) {
+       /* Nothing to do */
+}
+
+static inline __always_inline unsigned long
+IOMAP_INLINE ( virt, io_to_bus ) ( volatile const void *io_addr ) {
+       return virt_to_phys ( io_addr );
+}
+
+#endif /* _IPXE_IOMAP_VIRT_H */