These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / linux / linux_uaccess.h
1 #ifndef _IPXE_LINUX_UACCESS_H
2 #define _IPXE_LINUX_UACCESS_H
3
4 /** @file
5  *
6  * iPXE user access API for Linux
7  *
8  * We run with no distinction between internal and external addresses,
9  * so can use trivial_virt_to_user() et al.
10  *
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.
17  */
18
19 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
20
21 #ifdef UACCESS_LINUX
22 #define UACCESS_PREFIX_linux
23 #else
24 #define UACCESS_PREFIX_linux __linux_
25 #endif
26
27 /**
28  * Convert user buffer to physical address
29  *
30  * @v userptr           User pointer
31  * @v offset            Offset from user pointer
32  * @ret phys_addr       Physical address
33  */
34 static inline __always_inline unsigned long
35 UACCESS_INLINE ( linux, user_to_phys ) ( userptr_t userptr, off_t offset ) {
36
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
44          * alignment.
45          */
46         return ( userptr + offset );
47 }
48
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 );
52 }
53
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 );
57 }
58
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 );
62 }
63
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 );
68 }
69
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,
73                                         size_t len ) {
74         trivial_memcpy_user ( dest, dest_off, src, src_off, len );
75 }
76
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,
80                                          size_t len ) {
81         trivial_memmove_user ( dest, dest_off, src, src_off, len );
82 }
83
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,
87                                         size_t len ) {
88         return trivial_memcmp_user ( first, first_off, second, second_off, len);
89 }
90
91 static inline __always_inline void
92 UACCESS_INLINE ( linux, memset_user ) ( userptr_t buffer, off_t offset,
93                                         int c, size_t len ) {
94         trivial_memset_user ( buffer, offset, c, len );
95 }
96
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 );
100 }
101
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 );
106 }
107
108 #endif /* _IPXE_LINUX_UACCESS_H */