|
@@ -137,112 +137,139 @@ struct addr_64_st {
|
137
|
137
|
|
138
|
138
|
/* Remaining code Copyright Fen Systems Ltd. 2007 */
|
139
|
139
|
|
|
140
|
+/**
|
|
141
|
+ * Wrapper structure for pseudo_bit_t structures
|
|
142
|
+ *
|
|
143
|
+ * This structure provides a wrapper around the autogenerated
|
|
144
|
+ * pseudo_bit_t structures. It has the correct size, and also
|
|
145
|
+ * encapsulates type information about the underlying pseudo_bit_t
|
|
146
|
+ * structure, which allows the MLX_POPULATE etc. macros to work
|
|
147
|
+ * without requiring explicit type information.
|
|
148
|
+ */
|
|
149
|
+#define MLX_DECLARE_STRUCT( _structure ) \
|
|
150
|
+ _structure { \
|
|
151
|
+ union { \
|
|
152
|
+ uint8_t bytes[ sizeof ( struct _structure ## _st ) / 8 ]; \
|
|
153
|
+ uint32_t dwords[ sizeof ( struct _structure ## _st ) / 32 ]; \
|
|
154
|
+ struct _structure ## _st *dummy[0]; \
|
|
155
|
+ } u; \
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+/** Get pseudo_bit_t structure type from wrapper structure pointer */
|
|
159
|
+#define MLX_PSEUDO_STRUCT( _ptr ) \
|
|
160
|
+ typeof ( *((_ptr)->u.dummy[0]) )
|
|
161
|
+
|
140
|
162
|
/** Bit offset of a field within a pseudo_bit_t structure */
|
141
|
|
-#define MLX_BIT_OFFSET( _structure, _field ) \
|
142
|
|
- offsetof ( struct _structure, _field )
|
|
163
|
+#define MLX_BIT_OFFSET( _structure_st, _field ) \
|
|
164
|
+ offsetof ( _structure_st, _field )
|
143
|
165
|
|
144
|
166
|
/** Dword offset of a field within a pseudo_bit_t structure */
|
145
|
|
-#define MLX_DWORD_OFFSET( _structure, _field ) \
|
146
|
|
- ( MLX_BIT_OFFSET ( _structure, _field ) / 32 )
|
|
167
|
+#define MLX_DWORD_OFFSET( _structure_st, _field ) \
|
|
168
|
+ ( MLX_BIT_OFFSET ( _structure_st, _field ) / 32 )
|
147
|
169
|
|
148
|
170
|
/** Dword bit offset of a field within a pseudo_bit_t structure
|
149
|
171
|
*
|
150
|
172
|
* Yes, using mod-32 would work, but would lose the check for the
|
151
|
173
|
* error of specifying a mismatched field name and dword index.
|
152
|
174
|
*/
|
153
|
|
-#define MLX_DWORD_BIT_OFFSET( _structure, _index, _field ) \
|
154
|
|
- ( MLX_BIT_OFFSET ( _structure, _field ) - ( 32 * (_index) ) )
|
|
175
|
+#define MLX_DWORD_BIT_OFFSET( _structure_st, _index, _field ) \
|
|
176
|
+ ( MLX_BIT_OFFSET ( _structure_st, _field ) - ( 32 * (_index) ) )
|
155
|
177
|
|
156
|
178
|
/** Bit width of a field within a pseudo_bit_t structure */
|
157
|
|
-#define MLX_BIT_WIDTH( _structure, _field ) \
|
158
|
|
- sizeof ( ( ( struct _structure * ) NULL )->_field )
|
|
179
|
+#define MLX_BIT_WIDTH( _structure_st, _field ) \
|
|
180
|
+ sizeof ( ( ( _structure_st * ) NULL )->_field )
|
159
|
181
|
|
160
|
182
|
/** Bit mask for a field within a pseudo_bit_t structure */
|
161
|
|
-#define MLX_BIT_MASK( _structure, _field ) \
|
162
|
|
- ( ( 1 << MLX_BIT_WIDTH ( _structure, _field ) ) - 1 )
|
|
183
|
+#define MLX_BIT_MASK( _structure_st, _field ) \
|
|
184
|
+ ( ( 1 << MLX_BIT_WIDTH ( _structure_st, _field ) ) - 1 )
|
163
|
185
|
|
164
|
186
|
/*
|
165
|
187
|
* Assemble native-endian dword from named fields and values
|
166
|
188
|
*
|
167
|
189
|
*/
|
168
|
190
|
|
169
|
|
-#define MLX_ASSEMBLE_1( _structure, _index, _field, _value ) \
|
170
|
|
- ( (_value) << MLX_DWORD_BIT_OFFSET ( _structure, _index, _field ) )
|
|
191
|
+#define MLX_ASSEMBLE_1( _structure_st, _index, _field, _value ) \
|
|
192
|
+ ( (_value) << MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) )
|
171
|
193
|
|
172
|
|
-#define MLX_ASSEMBLE_2( _structure, _index, _field, _value, ... ) \
|
173
|
|
- ( MLX_ASSEMBLE_1 ( _structure, _index, _field, _value ) | \
|
174
|
|
- MLX_ASSEMBLE_1 ( _structure, _index, __VA_ARGS__ ) )
|
|
194
|
+#define MLX_ASSEMBLE_2( _structure_st, _index, _field, _value, ... ) \
|
|
195
|
+ ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
|
|
196
|
+ MLX_ASSEMBLE_1 ( _structure_st, _index, __VA_ARGS__ ) )
|
175
|
197
|
|
176
|
|
-#define MLX_ASSEMBLE_3( _structure, _index, _field, _value, ... ) \
|
177
|
|
- ( MLX_ASSEMBLE_1 ( _structure, _index, _field, _value ) | \
|
178
|
|
- MLX_ASSEMBLE_2 ( _structure, _index, __VA_ARGS__ ) )
|
|
198
|
+#define MLX_ASSEMBLE_3( _structure_st, _index, _field, _value, ... ) \
|
|
199
|
+ ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
|
|
200
|
+ MLX_ASSEMBLE_2 ( _structure_st, _index, __VA_ARGS__ ) )
|
179
|
201
|
|
180
|
|
-#define MLX_ASSEMBLE_4( _structure, _index, _field, _value, ... ) \
|
181
|
|
- ( MLX_ASSEMBLE_1 ( _structure, _index, _field, _value ) | \
|
182
|
|
- MLX_ASSEMBLE_3 ( _structure, _index, __VA_ARGS__ ) )
|
|
202
|
+#define MLX_ASSEMBLE_4( _structure_st, _index, _field, _value, ... ) \
|
|
203
|
+ ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \
|
|
204
|
+ MLX_ASSEMBLE_3 ( _structure_st, _index, __VA_ARGS__ ) )
|
183
|
205
|
|
184
|
206
|
/*
|
185
|
207
|
* Build native-endian (positive) dword bitmasks from named fields
|
186
|
208
|
*
|
187
|
209
|
*/
|
188
|
210
|
|
189
|
|
-#define MLX_MASK_1( _structure, _index, _field ) \
|
190
|
|
- ( MLX_BIT_MASK ( _structure, _field ) << \
|
191
|
|
- MLX_DWORD_BIT_OFFSET ( _structure, _index, _field ) )
|
|
211
|
+#define MLX_MASK_1( _structure_st, _index, _field ) \
|
|
212
|
+ ( MLX_BIT_MASK ( _structure_st, _field ) << \
|
|
213
|
+ MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) )
|
192
|
214
|
|
193
|
|
-#define MLX_MASK_2( _structure, _index, _field, ... ) \
|
194
|
|
- ( MLX_MASK_1 ( _structure, _index, _field ) | \
|
195
|
|
- MLX_MASK_1 ( _structure, _index, __VA_ARGS__ ) )
|
|
215
|
+#define MLX_MASK_2( _structure_st, _index, _field, ... ) \
|
|
216
|
+ ( MLX_MASK_1 ( _structure_st, _index, _field ) | \
|
|
217
|
+ MLX_MASK_1 ( _structure_st, _index, __VA_ARGS__ ) )
|
196
|
218
|
|
197
|
|
-#define MLX_MASK_3( _structure, _index, _field, ... ) \
|
198
|
|
- ( MLX_MASK_1 ( _structure, _index, _field ) | \
|
199
|
|
- MLX_MASK_2 ( _structure, _index, __VA_ARGS__ ) )
|
|
219
|
+#define MLX_MASK_3( _structure_st, _index, _field, ... ) \
|
|
220
|
+ ( MLX_MASK_1 ( _structure_st, _index, _field ) | \
|
|
221
|
+ MLX_MASK_2 ( _structure_st, _index, __VA_ARGS__ ) )
|
200
|
222
|
|
201
|
|
-#define MLX_MASK_4( _structure, _index, _field, ... ) \
|
202
|
|
- ( MLX_MASK_1 ( _structure, _index, _field ) | \
|
203
|
|
- MLX_MASK_3 ( _structure, _index, __VA_ARGS__ ) )
|
|
223
|
+#define MLX_MASK_4( _structure_st, _index, _field, ... ) \
|
|
224
|
+ ( MLX_MASK_1 ( _structure_st, _index, _field ) | \
|
|
225
|
+ MLX_MASK_3 ( _structure_st, _index, __VA_ARGS__ ) )
|
204
|
226
|
|
205
|
227
|
/*
|
206
|
228
|
* Populate big-endian dwords from named fields and values
|
207
|
229
|
*
|
208
|
230
|
*/
|
209
|
231
|
|
210
|
|
-#define MLX_POPULATE( _base, _index, _assembled ) \
|
211
|
|
- do { \
|
212
|
|
- uint32_t *__ptr = ( ( (uint32_t *) (_base) ) + (_index) ); \
|
213
|
|
- uint32_t __assembled = (_assembled); \
|
214
|
|
- *__ptr = cpu_to_be32 ( __assembled ); \
|
|
232
|
+#define MLX_POPULATE( _ptr, _index, _assembled ) \
|
|
233
|
+ do { \
|
|
234
|
+ uint32_t *__ptr = &(_ptr)->u.dwords[(_index)]; \
|
|
235
|
+ uint32_t __assembled = (_assembled); \
|
|
236
|
+ *__ptr = cpu_to_be32 ( __assembled ); \
|
215
|
237
|
} while ( 0 )
|
216
|
238
|
|
217
|
|
-#define MLX_POPULATE_1( _base, _structure, _index, ... ) \
|
218
|
|
- MLX_POPULATE ( _base, _index, \
|
219
|
|
- MLX_ASSEMBLE_1 ( _structure, _index, __VA_ARGS__ ) )
|
|
239
|
+#define MLX_POPULATE_1( _ptr, _index, ... ) \
|
|
240
|
+ MLX_POPULATE ( _ptr, _index, \
|
|
241
|
+ MLX_ASSEMBLE_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
242
|
+ _index, __VA_ARGS__ ) )
|
220
|
243
|
|
221
|
|
-#define MLX_POPULATE_2( _base, _structure, _index, ... ) \
|
222
|
|
- MLX_POPULATE ( _base, _index, \
|
223
|
|
- MLX_ASSEMBLE_2 ( _structure, _index, __VA_ARGS__ ) )
|
|
244
|
+#define MLX_POPULATE_2( _ptr, _index, ... ) \
|
|
245
|
+ MLX_POPULATE ( _ptr, _index, \
|
|
246
|
+ MLX_ASSEMBLE_2 ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
247
|
+ _index, __VA_ARGS__ ) )
|
224
|
248
|
|
225
|
|
-#define MLX_POPULATE_3( _base, _structure, _index, ... ) \
|
226
|
|
- MLX_POPULATE ( _base, _index, \
|
227
|
|
- MLX_ASSEMBLE_3 ( _structure, _index, __VA_ARGS__ ) )
|
|
249
|
+#define MLX_POPULATE_3( _ptr, _index, ... ) \
|
|
250
|
+ MLX_POPULATE ( _ptr, _index, \
|
|
251
|
+ MLX_ASSEMBLE_3 ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
252
|
+ _index, __VA_ARGS__ ) )
|
228
|
253
|
|
229
|
|
-#define MLX_POPULATE_4( _base, _structure, _index, ... ) \
|
230
|
|
- MLX_POPULATE ( _base, _index, \
|
231
|
|
- MLX_ASSEMBLE_4 ( _structure, _index, __VA_ARGS__ ) )
|
|
254
|
+#define MLX_POPULATE_4( _ptr, _index, ... ) \
|
|
255
|
+ MLX_POPULATE ( _ptr, _index, \
|
|
256
|
+ MLX_ASSEMBLE_4 ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
257
|
+ _index, __VA_ARGS__ ) )
|
232
|
258
|
|
233
|
259
|
/*
|
234
|
260
|
* Modify big-endian dword using named field and value
|
235
|
261
|
*
|
236
|
262
|
*/
|
237
|
263
|
|
238
|
|
-#define MLX_MODIFY( _base, _structure, _index, _field, _value ) \
|
239
|
|
- do { \
|
240
|
|
- uint32_t *__ptr = ( ( (uint32_t *) (_base) ) + (_index) ); \
|
241
|
|
- uint32_t __value = be32_to_cpu ( *__ptr ); \
|
242
|
|
- __value &= ~( MLX_MASK_1 ( _structure, _index, _field ) ); \
|
243
|
|
- __value |= MLX_ASSEMBLE_1 ( _structure, _index, \
|
244
|
|
- _field, _value ); \
|
245
|
|
- *__ptr = cpu_to_be32 ( __value ); \
|
|
264
|
+#define MLX_MODIFY( _ptr, _index, _field, _value ) \
|
|
265
|
+ do { \
|
|
266
|
+ uint32_t *__ptr = &(_ptr)->u.dwords[(_index)]; \
|
|
267
|
+ uint32_t __value = be32_to_cpu ( *__ptr ); \
|
|
268
|
+ __value &= ~( MLX_MASK_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
269
|
+ _index, _field ) ); \
|
|
270
|
+ __value |= MLX_ASSEMBLE_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
271
|
+ _index, _field, _value ); \
|
|
272
|
+ *__ptr = cpu_to_be32 ( __value ); \
|
246
|
273
|
} while ( 0 )
|
247
|
274
|
|
248
|
275
|
/*
|
|
@@ -250,16 +277,18 @@ struct addr_64_st {
|
250
|
277
|
*
|
251
|
278
|
*/
|
252
|
279
|
|
253
|
|
-#define MLX_EXTRACT( _base, _structure, _field ) \
|
254
|
|
- ( { \
|
255
|
|
- unsigned int __index = \
|
256
|
|
- MLX_DWORD_OFFSET ( _structure, _field ); \
|
257
|
|
- uint32_t *__ptr = ( ( (uint32_t *) (_base) ) + __index ); \
|
258
|
|
- uint32_t __value = be32_to_cpu ( *__ptr ); \
|
259
|
|
- __value >>= MLX_DWORD_BIT_OFFSET ( _structure, __index, \
|
260
|
|
- _field ); \
|
261
|
|
- __value &= MLX_BIT_MASK ( _structure, _field ); \
|
262
|
|
- __value; \
|
|
280
|
+#define MLX_EXTRACT( _ptr, _field ) \
|
|
281
|
+ ( { \
|
|
282
|
+ unsigned int __index = \
|
|
283
|
+ MLX_DWORD_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \
|
|
284
|
+ uint32_t *__ptr = &(_ptr)->u.dwords[__index]; \
|
|
285
|
+ uint32_t __value = be32_to_cpu ( *__ptr ); \
|
|
286
|
+ __value >>= \
|
|
287
|
+ MLX_DWORD_BIT_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), \
|
|
288
|
+ __index, _field ); \
|
|
289
|
+ __value &= \
|
|
290
|
+ MLX_BIT_MASK ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \
|
|
291
|
+ __value; \
|
263
|
292
|
} )
|
264
|
293
|
|
265
|
294
|
#endif /* __bit_ops_h__ */
|