Skip to content

Commit

Permalink
[uaccess] Rename UACCESS_EFI to UACCESS_FLAT
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mcb30 committed Oct 25, 2024
1 parent 33d80b1 commit abfa7c3
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 118 deletions.
2 changes: 1 addition & 1 deletion src/config/defaults/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#define UACCESS_EFI
#define UACCESS_FLAT
#define IOMAP_VIRT
#define PCIAPI_EFI
#define DMAAPI_OP
Expand Down
26 changes: 13 additions & 13 deletions src/interface/efi/efi_uaccess.c → src/core/uaccess.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Michael Brown <[email protected]>.
* Copyright (C) 2024 Michael Brown <[email protected]>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
Expand All @@ -24,21 +24,21 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <ipxe/uaccess.h>
#include <ipxe/efi/efi.h>

/** @file
*
* iPXE user access API for EFI
* iPXE user access API
*
*/

PROVIDE_UACCESS_INLINE ( efi, phys_to_user );
PROVIDE_UACCESS_INLINE ( efi, user_to_phys );
PROVIDE_UACCESS_INLINE ( efi, virt_to_user );
PROVIDE_UACCESS_INLINE ( efi, user_to_virt );
PROVIDE_UACCESS_INLINE ( efi, userptr_add );
PROVIDE_UACCESS_INLINE ( efi, memcpy_user );
PROVIDE_UACCESS_INLINE ( efi, memmove_user );
PROVIDE_UACCESS_INLINE ( efi, memset_user );
PROVIDE_UACCESS_INLINE ( efi, strlen_user );
PROVIDE_UACCESS_INLINE ( efi, memchr_user );
/* Flat address space user access API */
PROVIDE_UACCESS_INLINE ( flat, phys_to_user );
PROVIDE_UACCESS_INLINE ( flat, user_to_phys );
PROVIDE_UACCESS_INLINE ( flat, virt_to_user );
PROVIDE_UACCESS_INLINE ( flat, user_to_virt );
PROVIDE_UACCESS_INLINE ( flat, userptr_add );
PROVIDE_UACCESS_INLINE ( flat, memcpy_user );
PROVIDE_UACCESS_INLINE ( flat, memmove_user );
PROVIDE_UACCESS_INLINE ( flat, memset_user );
PROVIDE_UACCESS_INLINE ( flat, strlen_user );
PROVIDE_UACCESS_INLINE ( flat, memchr_user );
103 changes: 0 additions & 103 deletions src/include/ipxe/efi/efi_uaccess.h

This file was deleted.

76 changes: 75 additions & 1 deletion src/include/ipxe/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit abfa7c3

Please sign in to comment.