|
@@ -89,6 +89,15 @@ extern const unsigned long virt_offset;
|
89
|
89
|
*/
|
90
|
90
|
static inline __always_inline userptr_t
|
91
|
91
|
UACCESS_INLINE ( librm, phys_to_user ) ( unsigned long phys_addr ) {
|
|
92
|
+
|
|
93
|
+ /* In a 64-bit build, any valid physical address is directly
|
|
94
|
+ * usable as a virtual address, since the low 4GB is
|
|
95
|
+ * identity-mapped.
|
|
96
|
+ */
|
|
97
|
+ if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) )
|
|
98
|
+ return phys_addr;
|
|
99
|
+
|
|
100
|
+ /* In a 32-bit build, subtract virt_offset */
|
92
|
101
|
return ( phys_addr - virt_offset );
|
93
|
102
|
}
|
94
|
103
|
|
|
@@ -101,7 +110,20 @@ UACCESS_INLINE ( librm, phys_to_user ) ( unsigned long phys_addr ) {
|
101
|
110
|
*/
|
102
|
111
|
static inline __always_inline unsigned long
|
103
|
112
|
UACCESS_INLINE ( librm, user_to_phys ) ( userptr_t userptr, off_t offset ) {
|
104
|
|
- return ( userptr + offset + virt_offset );
|
|
113
|
+ unsigned long addr = ( userptr + offset );
|
|
114
|
+
|
|
115
|
+ /* In a 64-bit build, any virtual address in the low 4GB is
|
|
116
|
+ * directly usable as a physical address, since the low 4GB is
|
|
117
|
+ * identity-mapped.
|
|
118
|
+ */
|
|
119
|
+ if ( ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) &&
|
|
120
|
+ ( addr <= 0xffffffffUL ) )
|
|
121
|
+ return addr;
|
|
122
|
+
|
|
123
|
+ /* In a 32-bit build or in a 64-bit build with a virtual
|
|
124
|
+ * address above 4GB: add virt_offset
|
|
125
|
+ */
|
|
126
|
+ return ( addr + virt_offset );
|
105
|
127
|
}
|
106
|
128
|
|
107
|
129
|
static inline __always_inline userptr_t
|