diff options
| author | Michael Brown | 2016-02-26 16:33:40 +0100 |
|---|---|---|
| committer | Michael Brown | 2016-02-26 16:33:40 +0100 |
| commit | 5bd8427d3dad38993c1f8f175454f7fde0af34ca (patch) | |
| tree | de75a672e177f36fef93b81ada93c96541761310 /src/include | |
| parent | [librm] Add support for running in 64-bit long mode (diff) | |
| download | ipxe-5bd8427d3dad38993c1f8f175454f7fde0af34ca.tar.gz ipxe-5bd8427d3dad38993c1f8f175454f7fde0af34ca.tar.xz ipxe-5bd8427d3dad38993c1f8f175454f7fde0af34ca.zip | |
[ioapi] Split ioremap() out to a separate IOMAP API
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/ipxe/io.h | 26 | ||||
| -rw-r--r-- | src/include/ipxe/iomap.h | 78 | ||||
| -rw-r--r-- | src/include/ipxe/iomap_virt.h | 33 |
3 files changed, 112 insertions, 25 deletions
diff --git a/src/include/ipxe/io.h b/src/include/ipxe/io.h index af767915d..fe1388191 100644 --- a/src/include/ipxe/io.h +++ b/src/include/ipxe/io.h @@ -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 ) @@ -197,30 +197,6 @@ static inline __always_inline void * bus_to_virt ( unsigned long 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 * * @v io_addr I/O address diff --git a/src/include/ipxe/iomap.h b/src/include/ipxe/iomap.h new file mode 100644 index 000000000..b8ded38ef --- /dev/null +++ b/src/include/ipxe/iomap.h @@ -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 index 000000000..4962b7c37 --- /dev/null +++ b/src/include/ipxe/iomap_virt.h @@ -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 */ |
