2 * Copyright (C) 2010 Piotr JaroszyĆski <p.jaroszynski@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef _IPXE_LINUX_UACCESS_H
20 #define _IPXE_LINUX_UACCESS_H
22 FILE_LICENCE(GPL2_OR_LATER);
26 * iPXE user access API for linux
28 * In linux userspace virtual == user == phys addresses.
29 * Physical addresses also being the same is wrong, but there is no general way
30 * of converting userspace addresses to physical as what appears to be
31 * contiguous in userspace is physically fragmented.
32 * Currently only the DMA memory is special-cased, but its conversion to bus
33 * addresses is done in phys_to_bus.
34 * This is known to break virtio as it is passing phys addresses to the virtual
39 #define UACCESS_PREFIX_linux
41 #define UACCESS_PREFIX_linux __linux_
44 static inline __always_inline userptr_t
45 UACCESS_INLINE(linux, phys_to_user)(unsigned long phys_addr)
50 static inline __always_inline unsigned long
51 UACCESS_INLINE(linux, user_to_phys)(userptr_t userptr, off_t offset)
53 return userptr + offset;
56 static inline __always_inline userptr_t
57 UACCESS_INLINE(linux, virt_to_user)(volatile const void *addr)
59 return trivial_virt_to_user(addr);
62 static inline __always_inline void *
63 UACCESS_INLINE(linux, user_to_virt)(userptr_t userptr, off_t offset)
65 return trivial_user_to_virt(userptr, offset);
68 static inline __always_inline userptr_t
69 UACCESS_INLINE(linux, userptr_add)(userptr_t userptr, off_t offset)
71 return trivial_userptr_add(userptr, offset);
74 static inline __always_inline off_t
75 UACCESS_INLINE(linux, userptr_sub)(userptr_t userptr, userptr_t subtrahend)
77 return trivial_userptr_sub ( userptr, subtrahend );
80 static inline __always_inline void
81 UACCESS_INLINE(linux, memcpy_user)(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
83 trivial_memcpy_user(dest, dest_off, src, src_off, len);
86 static inline __always_inline void
87 UACCESS_INLINE(linux, memmove_user)(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
89 trivial_memmove_user(dest, dest_off, src, src_off, len);
92 static inline __always_inline int
93 UACCESS_INLINE(linux, memcmp_user)(userptr_t first, off_t first_off, userptr_t second, off_t second_off, size_t len)
95 return trivial_memcmp_user(first, first_off, second, second_off, len);
98 static inline __always_inline void
99 UACCESS_INLINE(linux, memset_user)(userptr_t buffer, off_t offset, int c, size_t len)
101 trivial_memset_user(buffer, offset, c, len);
104 static inline __always_inline size_t
105 UACCESS_INLINE(linux, strlen_user)(userptr_t buffer, off_t offset)
107 return trivial_strlen_user(buffer, offset);
110 static inline __always_inline off_t
111 UACCESS_INLINE(linux, memchr_user)(userptr_t buffer, off_t offset, int c, size_t len)
113 return trivial_memchr_user(buffer, offset, c, len);
116 #endif /* _IPXE_LINUX_UACCESS_H */