Browse Source

[bitops] Fix definitions for big-endian devices

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
4957285b22
1 changed files with 13 additions and 6 deletions
  1. 13
    6
      src/include/ipxe/bitops.h

+ 13
- 6
src/include/ipxe/bitops.h View File

38
 
38
 
39
 /* Endianness selection.
39
 /* Endianness selection.
40
  *
40
  *
41
- * This is a property of the NIC, not a property of the host CPU.
41
+ * This is a property of the device, not a property of the host CPU.
42
  */
42
  */
43
 #ifdef BITOPS_LITTLE_ENDIAN
43
 #ifdef BITOPS_LITTLE_ENDIAN
44
 #define cpu_to_BIT64	cpu_to_le64
44
 #define cpu_to_BIT64	cpu_to_le64
45
 #define cpu_to_BIT32	cpu_to_le32
45
 #define cpu_to_BIT32	cpu_to_le32
46
 #define BIT64_to_cpu	le64_to_cpu
46
 #define BIT64_to_cpu	le64_to_cpu
47
 #define BIT32_to_cpu	le32_to_cpu
47
 #define BIT32_to_cpu	le32_to_cpu
48
+#define QWORD_SHIFT( offset, width ) (offset)
48
 #endif
49
 #endif
49
 #ifdef BITOPS_BIG_ENDIAN
50
 #ifdef BITOPS_BIG_ENDIAN
50
 #define cpu_to_BIT64	cpu_to_be64
51
 #define cpu_to_BIT64	cpu_to_be64
51
 #define cpu_to_BIT32	cpu_to_be32
52
 #define cpu_to_BIT32	cpu_to_be32
52
 #define BIT64_to_cpu	be64_to_cpu
53
 #define BIT64_to_cpu	be64_to_cpu
53
 #define BIT32_to_cpu	be32_to_cpu
54
 #define BIT32_to_cpu	be32_to_cpu
55
+#define QWORD_SHIFT( offset, width ) ( 64 - (offset) - (width) )
54
 #endif
56
 #endif
55
 
57
 
56
 /** Datatype used to represent a bit in the pseudo-structures */
58
 /** Datatype used to represent a bit in the pseudo-structures */
93
 #define QWORD_BIT_OFFSET( _ptr, _index, _field )			      \
95
 #define QWORD_BIT_OFFSET( _ptr, _index, _field )			      \
94
 	( BIT_OFFSET ( _ptr, _field ) - ( 64 * (_index) ) )
96
 	( BIT_OFFSET ( _ptr, _field ) - ( 64 * (_index) ) )
95
 
97
 
98
+/** Qword bit shift for a field within a pseudo_bit_t structure */
99
+#define QWORD_BIT_SHIFT( _ptr, _index, _field )				      \
100
+	QWORD_SHIFT ( QWORD_BIT_OFFSET ( _ptr, _index, _field ),	      \
101
+		      BIT_WIDTH ( _ptr, _field ) )
102
+
96
 /** Bit mask for a field within a pseudo_bit_t structure */
103
 /** Bit mask for a field within a pseudo_bit_t structure */
97
 #define BIT_MASK( _ptr, _field )					      \
104
 #define BIT_MASK( _ptr, _field )					      \
98
 	( ( ~( ( uint64_t ) 0 ) ) >>					      \
105
 	( ( ~( ( uint64_t ) 0 ) ) >>					      \
105
 
112
 
106
 #define BIT_ASSEMBLE_1( _ptr, _index, _field, _value )			      \
113
 #define BIT_ASSEMBLE_1( _ptr, _index, _field, _value )			      \
107
 	( ( ( uint64_t) (_value) ) <<					      \
114
 	( ( ( uint64_t) (_value) ) <<					      \
108
-	  QWORD_BIT_OFFSET ( _ptr, _index, _field ) )
115
+	  QWORD_BIT_SHIFT ( _ptr, _index, _field ) )
109
 
116
 
110
 #define BIT_ASSEMBLE_2( _ptr, _index, _field, _value, ... )		      \
117
 #define BIT_ASSEMBLE_2( _ptr, _index, _field, _value, ... )		      \
111
 	( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) |		      \
118
 	( BIT_ASSEMBLE_1 ( _ptr, _index, _field, _value ) |		      \
138
 
145
 
139
 #define BIT_MASK_1( _ptr, _index, _field )				      \
146
 #define BIT_MASK_1( _ptr, _index, _field )				      \
140
 	( BIT_MASK ( _ptr, _field ) <<					      \
147
 	( BIT_MASK ( _ptr, _field ) <<					      \
141
-	  QWORD_BIT_OFFSET ( _ptr, _index, _field ) )
148
+	  QWORD_BIT_SHIFT ( _ptr, _index, _field ) )
142
 
149
 
143
 #define BIT_MASK_2( _ptr, _index, _field, ... )				      \
150
 #define BIT_MASK_2( _ptr, _index, _field, ... )				      \
144
 	( BIT_MASK_1 ( _ptr, _index, _field ) |				      \
151
 	( BIT_MASK_1 ( _ptr, _index, _field ) |				      \
165
 	  BIT_MASK_6 ( _ptr, _index, __VA_ARGS__ ) )
172
 	  BIT_MASK_6 ( _ptr, _index, __VA_ARGS__ ) )
166
 
173
 
167
 /*
174
 /*
168
- * Populate little-endian qwords from named fields and values
175
+ * Populate device-endian qwords from named fields and values
169
  *
176
  *
170
  */
177
  */
171
 
178
 
212
 		uint64_t *__ptr = &(_ptr)->u.qwords[__index];		      \
219
 		uint64_t *__ptr = &(_ptr)->u.qwords[__index];		      \
213
 		uint64_t __value = BIT64_to_cpu ( *__ptr );		      \
220
 		uint64_t __value = BIT64_to_cpu ( *__ptr );		      \
214
 		__value >>=						      \
221
 		__value >>=						      \
215
-		    QWORD_BIT_OFFSET ( _ptr, __index, _field );		      \
222
+		    QWORD_BIT_SHIFT ( _ptr, __index, _field );		      \
216
 		__value &= BIT_MASK ( _ptr, _field );			      \
223
 		__value &= BIT_MASK ( _ptr, _field );			      \
217
 		__value;						      \
224
 		__value;						      \
218
 	} )
225
 	} )
225
 		unsigned int __index = QWORD_OFFSET ( _ptr, _field );	      \
232
 		unsigned int __index = QWORD_OFFSET ( _ptr, _field );	      \
226
 		uint64_t *__ptr = &(_ptr)->u.qwords[__index];		      \
233
 		uint64_t *__ptr = &(_ptr)->u.qwords[__index];		      \
227
 		unsigned int __shift =					      \
234
 		unsigned int __shift =					      \
228
-			QWORD_BIT_OFFSET ( _ptr, __index, _field );	      \
235
+			QWORD_BIT_SHIFT ( _ptr, __index, _field );	      \
229
 		uint64_t __value = (_value);				      \
236
 		uint64_t __value = (_value);				      \
230
 		*__ptr &= cpu_to_BIT64 ( ~( BIT_MASK ( _ptr, _field ) <<      \
237
 		*__ptr &= cpu_to_BIT64 ( ~( BIT_MASK ( _ptr, _field ) <<      \
231
 					    __shift ) );		      \
238
 					    __shift ) );		      \

Loading…
Cancel
Save