Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / linux / linux_uaccess.h
1 /*
2  * Copyright (C) 2010 Piotr JaroszyƄski <p.jaroszynski@gmail.com>
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #ifndef _IPXE_LINUX_UACCESS_H
20 #define _IPXE_LINUX_UACCESS_H
21
22 FILE_LICENCE(GPL2_OR_LATER);
23
24 /** @file
25  *
26  * iPXE user access API for linux
27  *
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
35  * device.
36  */
37
38 #ifdef UACCESS_LINUX
39 #define UACCESS_PREFIX_linux
40 #else
41 #define UACCESS_PREFIX_linux __linux_
42 #endif
43
44 static inline __always_inline userptr_t
45 UACCESS_INLINE(linux, phys_to_user)(unsigned long phys_addr)
46 {
47         return phys_addr;
48 }
49
50 static inline __always_inline unsigned long
51 UACCESS_INLINE(linux, user_to_phys)(userptr_t userptr, off_t offset)
52 {
53         return userptr + offset;
54 }
55
56 static inline __always_inline userptr_t
57 UACCESS_INLINE(linux, virt_to_user)(volatile const void *addr)
58 {
59         return trivial_virt_to_user(addr);
60 }
61
62 static inline __always_inline void *
63 UACCESS_INLINE(linux, user_to_virt)(userptr_t userptr, off_t offset)
64 {
65         return trivial_user_to_virt(userptr, offset);
66 }
67
68 static inline __always_inline userptr_t
69 UACCESS_INLINE(linux, userptr_add)(userptr_t userptr, off_t offset)
70 {
71         return trivial_userptr_add(userptr, offset);
72 }
73
74 static inline __always_inline off_t
75 UACCESS_INLINE(linux, userptr_sub)(userptr_t userptr, userptr_t subtrahend)
76 {
77         return trivial_userptr_sub ( userptr, subtrahend );
78 }
79
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)
82 {
83         trivial_memcpy_user(dest, dest_off, src, src_off, len);
84 }
85
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)
88 {
89         trivial_memmove_user(dest, dest_off, src, src_off, len);
90 }
91
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)
94 {
95         return trivial_memcmp_user(first, first_off, second, second_off, len);
96 }
97
98 static inline __always_inline void
99 UACCESS_INLINE(linux, memset_user)(userptr_t buffer, off_t offset, int c, size_t len)
100 {
101         trivial_memset_user(buffer, offset, c, len);
102 }
103
104 static inline __always_inline size_t
105 UACCESS_INLINE(linux, strlen_user)(userptr_t buffer, off_t offset)
106 {
107         return trivial_strlen_user(buffer, offset);
108 }
109
110 static inline __always_inline off_t
111 UACCESS_INLINE(linux, memchr_user)(userptr_t buffer, off_t offset, int c, size_t len)
112 {
113         return trivial_memchr_user(buffer, offset, c, len);
114 }
115
116 #endif /* _IPXE_LINUX_UACCESS_H */