diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-10-25 14:21:27 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-10-25 14:21:27 +0100 |
commit | abfa7c3ab1323967c38b11d4732b2d27ecf2f094 (patch) | |
tree | 790cbe7d64883a4c6bdf94d58e06ed26ccb74bf1 /src/include/ipxe | |
parent | 33d80b1cd8dd73580c7843d4a1fb8b6b3f458e22 (diff) | |
download | ipxe-abfa7c3ab1323967c38b11d4732b2d27ecf2f094.tar.gz |
[uaccess] Rename UACCESS_EFI to UACCESS_FLAT
Running with flat physical addressing is a fairly common early boot
environment. Rename UACCESS_EFI to UACCESS_FLAT so that this code may
be reused in non-UEFI boot environments that also use flat physical
addressing.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe')
-rw-r--r-- | src/include/ipxe/efi/efi_uaccess.h | 103 | ||||
-rw-r--r-- | src/include/ipxe/uaccess.h | 76 |
2 files changed, 75 insertions, 104 deletions
diff --git a/src/include/ipxe/efi/efi_uaccess.h b/src/include/ipxe/efi/efi_uaccess.h deleted file mode 100644 index 3cc750405..000000000 --- a/src/include/ipxe/efi/efi_uaccess.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef _IPXE_EFI_UACCESS_H -#define _IPXE_EFI_UACCESS_H - -/** @file - * - * iPXE user access 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. - */ - -FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); - -#ifdef UACCESS_EFI -#define UACCESS_PREFIX_efi -#else -#define UACCESS_PREFIX_efi __efi_ -#endif - -/** - * Convert physical address to user pointer - * - * @v phys_addr Physical address - * @ret userptr User pointer - */ -static inline __always_inline userptr_t -UACCESS_INLINE ( efi, phys_to_user ) ( unsigned long phys_addr ) { - return phys_addr; -} - -/** - * Convert user buffer to physical address - * - * @v userptr User pointer - * @v offset Offset from user pointer - * @ret phys_addr Physical address - */ -static inline __always_inline unsigned long -UACCESS_INLINE ( efi, user_to_phys ) ( userptr_t userptr, off_t offset ) { - return ( userptr + offset ); -} - -static inline __always_inline userptr_t -UACCESS_INLINE ( efi, virt_to_user ) ( volatile const void *addr ) { - return trivial_virt_to_user ( addr ); -} - -static inline __always_inline void * -UACCESS_INLINE ( efi, user_to_virt ) ( userptr_t userptr, off_t offset ) { - return trivial_user_to_virt ( userptr, offset ); -} - -static inline __always_inline userptr_t -UACCESS_INLINE ( efi, userptr_add ) ( userptr_t userptr, off_t offset ) { - return trivial_userptr_add ( userptr, offset ); -} - -static inline __always_inline off_t -UACCESS_INLINE ( efi, userptr_sub ) ( userptr_t userptr, - userptr_t subtrahend ) { - return trivial_userptr_sub ( userptr, subtrahend ); -} - -static inline __always_inline void -UACCESS_INLINE ( efi, memcpy_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memcpy_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline void -UACCESS_INLINE ( efi, memmove_user ) ( userptr_t dest, off_t dest_off, - userptr_t src, off_t src_off, - size_t len ) { - trivial_memmove_user ( dest, dest_off, src, src_off, len ); -} - -static inline __always_inline int -UACCESS_INLINE ( efi, memcmp_user ) ( userptr_t first, off_t first_off, - userptr_t second, off_t second_off, - size_t len ) { - return trivial_memcmp_user ( first, first_off, second, second_off, len); -} - -static inline __always_inline void -UACCESS_INLINE ( efi, memset_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - trivial_memset_user ( buffer, offset, c, len ); -} - -static inline __always_inline size_t -UACCESS_INLINE ( efi, strlen_user ) ( userptr_t buffer, off_t offset ) { - return trivial_strlen_user ( buffer, offset ); -} - -static inline __always_inline off_t -UACCESS_INLINE ( efi, memchr_user ) ( userptr_t buffer, off_t offset, - int c, size_t len ) { - return trivial_memchr_user ( buffer, offset, c, len ); -} - -#endif /* _IPXE_EFI_UACCESS_H */ diff --git a/src/include/ipxe/uaccess.h b/src/include/ipxe/uaccess.h index a3f78566a..b71361cab 100644 --- a/src/include/ipxe/uaccess.h +++ b/src/include/ipxe/uaccess.h @@ -26,6 +26,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include <ipxe/api.h> #include <config/ioapi.h> +#ifdef UACCESS_FLAT +#define UACCESS_PREFIX_flat +#else +#define UACCESS_PREFIX_flat __flat_ +#endif + /** * A pointer to a user buffer * @@ -216,8 +222,76 @@ trivial_memchr_user ( userptr_t buffer, off_t offset, int c, size_t len ) { #define PROVIDE_UACCESS_INLINE( _subsys, _api_func ) \ PROVIDE_SINGLE_API_INLINE ( UACCESS_PREFIX_ ## _subsys, _api_func ) +static inline __always_inline userptr_t +UACCESS_INLINE ( flat, phys_to_user ) ( unsigned long phys_addr ) { + return phys_addr; +} + +static inline __always_inline unsigned long +UACCESS_INLINE ( flat, user_to_phys ) ( userptr_t userptr, off_t offset ) { + return ( userptr + offset ); +} + +static inline __always_inline userptr_t +UACCESS_INLINE ( flat, virt_to_user ) ( volatile const void *addr ) { + return trivial_virt_to_user ( addr ); +} + +static inline __always_inline void * +UACCESS_INLINE ( flat, user_to_virt ) ( userptr_t userptr, off_t offset ) { + return trivial_user_to_virt ( userptr, offset ); +} + +static inline __always_inline userptr_t +UACCESS_INLINE ( flat, userptr_add ) ( userptr_t userptr, off_t offset ) { + return trivial_userptr_add ( userptr, offset ); +} + +static inline __always_inline off_t +UACCESS_INLINE ( flat, userptr_sub ) ( userptr_t userptr, + userptr_t subtrahend ) { + return trivial_userptr_sub ( userptr, subtrahend ); +} + +static inline __always_inline void +UACCESS_INLINE ( flat, memcpy_user ) ( userptr_t dest, off_t dest_off, + userptr_t src, off_t src_off, + size_t len ) { + trivial_memcpy_user ( dest, dest_off, src, src_off, len ); +} + +static inline __always_inline void +UACCESS_INLINE ( flat, memmove_user ) ( userptr_t dest, off_t dest_off, + userptr_t src, off_t src_off, + size_t len ) { + trivial_memmove_user ( dest, dest_off, src, src_off, len ); +} + +static inline __always_inline int +UACCESS_INLINE ( flat, memcmp_user ) ( userptr_t first, off_t first_off, + userptr_t second, off_t second_off, + size_t len ) { + return trivial_memcmp_user ( first, first_off, second, second_off, len); +} + +static inline __always_inline void +UACCESS_INLINE ( flat, memset_user ) ( userptr_t buffer, off_t offset, + int c, size_t len ) { + trivial_memset_user ( buffer, offset, c, len ); +} + +static inline __always_inline size_t +UACCESS_INLINE ( flat, strlen_user ) ( userptr_t buffer, off_t offset ) { + return trivial_strlen_user ( buffer, offset ); +} + +static inline __always_inline off_t +UACCESS_INLINE ( flat, memchr_user ) ( userptr_t buffer, off_t offset, + int c, size_t len ) { + return trivial_memchr_user ( buffer, offset, c, len ); +} + /* Include all architecture-independent user access API headers */ -#include <ipxe/efi/efi_uaccess.h> #include <ipxe/linux/linux_uaccess.h> /* Include all architecture-dependent user access API headers */ |