1 #ifndef _IPXE_LINUX_UACCESS_H
2 #define _IPXE_LINUX_UACCESS_H
6 * iPXE user access API for Linux
8 * We run with no distinction between internal and external addresses,
9 * so can use trivial_virt_to_user() et al.
11 * We have no concept of the underlying physical addresses, since
12 * these are not exposed to userspace. We provide a stub
13 * implementation of user_to_phys() since this is required by
14 * alloc_memblock(). We provide no implementation of phys_to_user();
15 * any code attempting to access physical addresses will therefore
16 * (correctly) fail to link.
19 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
22 #define UACCESS_PREFIX_linux
24 #define UACCESS_PREFIX_linux __linux_
28 * Convert user buffer to physical address
30 * @v userptr User pointer
31 * @v offset Offset from user pointer
32 * @ret phys_addr Physical address
34 static inline __always_inline unsigned long
35 UACCESS_INLINE ( linux, user_to_phys ) ( userptr_t userptr, off_t offset ) {
37 /* We do not know the real underlying physical address. We
38 * provide this stub implementation only because it is
39 * required by alloc_memblock() (which allocates memory with
40 * specified physical address alignment). We assume that the
41 * low-order bits of virtual addresses match the low-order
42 * bits of physical addresses, and so simply returning the
43 * virtual address will suffice for the purpose of determining
46 return ( userptr + offset );
49 static inline __always_inline userptr_t
50 UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) {
51 return trivial_virt_to_user ( addr );
54 static inline __always_inline void *
55 UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
56 return trivial_user_to_virt ( userptr, offset );
59 static inline __always_inline userptr_t
60 UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
61 return trivial_userptr_add ( userptr, offset );
64 static inline __always_inline off_t
65 UACCESS_INLINE ( linux, userptr_sub ) ( userptr_t userptr,
66 userptr_t subtrahend ) {
67 return trivial_userptr_sub ( userptr, subtrahend );
70 static inline __always_inline void
71 UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off,
72 userptr_t src, off_t src_off,
74 trivial_memcpy_user ( dest, dest_off, src, src_off, len );
77 static inline __always_inline void
78 UACCESS_INLINE ( linux, memmove_user ) ( userptr_t dest, off_t dest_off,
79 userptr_t src, off_t src_off,
81 trivial_memmove_user ( dest, dest_off, src, src_off, len );
84 static inline __always_inline int
85 UACCESS_INLINE ( linux, memcmp_user ) ( userptr_t first, off_t first_off,
86 userptr_t second, off_t second_off,
88 return trivial_memcmp_user ( first, first_off, second, second_off, len);
91 static inline __always_inline void
92 UACCESS_INLINE ( linux, memset_user ) ( userptr_t buffer, off_t offset,
94 trivial_memset_user ( buffer, offset, c, len );
97 static inline __always_inline size_t
98 UACCESS_INLINE ( linux, strlen_user ) ( userptr_t buffer, off_t offset ) {
99 return trivial_strlen_user ( buffer, offset );
102 static inline __always_inline off_t
103 UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset,
104 int c, size_t len ) {
105 return trivial_memchr_user ( buffer, offset, c, len );
108 #endif /* _IPXE_LINUX_UACCESS_H */