1 #ifndef _IPXE_EFI_UACCESS_H
2 #define _IPXE_EFI_UACCESS_H
3 
4 /** @file
5  *
6  * iPXE user access API for EFI
7  *
8  * EFI runs with flat physical addressing, so the various mappings
9  * between virtual addresses, I/O addresses and bus addresses are all
10  * no-ops.
11  */
12 
13 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
14 
15 #ifdef UACCESS_EFI
16 #define UACCESS_PREFIX_efi
17 #else
18 #define UACCESS_PREFIX_efi __efi_
19 #endif
20 
21 /**
22  * Convert physical address to user pointer
23  *
24  * @v phys_addr		Physical address
25  * @ret userptr		User pointer
26  */
27 static inline __always_inline userptr_t
UACCESS_INLINE(efi,phys_to_user)28 UACCESS_INLINE ( efi, phys_to_user ) ( unsigned long phys_addr ) {
29 	return phys_addr;
30 }
31 
32 /**
33  * Convert user buffer to physical address
34  *
35  * @v userptr		User pointer
36  * @v offset		Offset from user pointer
37  * @ret phys_addr	Physical address
38  */
39 static inline __always_inline unsigned long
UACCESS_INLINE(efi,user_to_phys)40 UACCESS_INLINE ( efi, user_to_phys ) ( userptr_t userptr, off_t offset ) {
41 	return ( userptr + offset );
42 }
43 
44 static inline __always_inline userptr_t
UACCESS_INLINE(efi,virt_to_user)45 UACCESS_INLINE ( efi, virt_to_user ) ( volatile const void *addr ) {
46 	return trivial_virt_to_user ( addr );
47 }
48 
49 static inline __always_inline void *
UACCESS_INLINE(efi,user_to_virt)50 UACCESS_INLINE ( efi, user_to_virt ) ( userptr_t userptr, off_t offset ) {
51 	return trivial_user_to_virt ( userptr, offset );
52 }
53 
54 static inline __always_inline userptr_t
UACCESS_INLINE(efi,userptr_add)55 UACCESS_INLINE ( efi, userptr_add ) ( userptr_t userptr, off_t offset ) {
56 	return trivial_userptr_add ( userptr, offset );
57 }
58 
59 static inline __always_inline off_t
UACCESS_INLINE(efi,userptr_sub)60 UACCESS_INLINE ( efi, userptr_sub ) ( userptr_t userptr,
61 				      userptr_t subtrahend ) {
62 	return trivial_userptr_sub ( userptr, subtrahend );
63 }
64 
65 static inline __always_inline void
UACCESS_INLINE(efi,memcpy_user)66 UACCESS_INLINE ( efi, memcpy_user ) ( userptr_t dest, off_t dest_off,
67 					userptr_t src, off_t src_off,
68 					size_t len ) {
69 	trivial_memcpy_user ( dest, dest_off, src, src_off, len );
70 }
71 
72 static inline __always_inline void
UACCESS_INLINE(efi,memmove_user)73 UACCESS_INLINE ( efi, memmove_user ) ( userptr_t dest, off_t dest_off,
74 					 userptr_t src, off_t src_off,
75 					 size_t len ) {
76 	trivial_memmove_user ( dest, dest_off, src, src_off, len );
77 }
78 
79 static inline __always_inline int
UACCESS_INLINE(efi,memcmp_user)80 UACCESS_INLINE ( efi, memcmp_user ) ( userptr_t first, off_t first_off,
81 				      userptr_t second, off_t second_off,
82 				      size_t len ) {
83 	return trivial_memcmp_user ( first, first_off, second, second_off, len);
84 }
85 
86 static inline __always_inline void
UACCESS_INLINE(efi,memset_user)87 UACCESS_INLINE ( efi, memset_user ) ( userptr_t buffer, off_t offset,
88 					int c, size_t len ) {
89 	trivial_memset_user ( buffer, offset, c, len );
90 }
91 
92 static inline __always_inline size_t
UACCESS_INLINE(efi,strlen_user)93 UACCESS_INLINE ( efi, strlen_user ) ( userptr_t buffer, off_t offset ) {
94 	return trivial_strlen_user ( buffer, offset );
95 }
96 
97 static inline __always_inline off_t
UACCESS_INLINE(efi,memchr_user)98 UACCESS_INLINE ( efi, memchr_user ) ( userptr_t buffer, off_t offset,
99 					int c, size_t len ) {
100 	return trivial_memchr_user ( buffer, offset, c, len );
101 }
102 
103 #endif /* _IPXE_EFI_UACCESS_H */
104