44 #define MLX_DECLARE_STRUCT( _structure ) \ 47 uint8_t bytes[ sizeof ( struct _structure ## _st ) / 8 ]; \ 48 uint32_t dwords[ sizeof ( struct _structure ## _st ) / 32 ]; \ 49 struct _structure ## _st *dummy[0]; \ 50 } __attribute__ (( packed )) u; \ 51 } __attribute__ (( packed )) 54 #define MLX_PSEUDO_STRUCT( _ptr ) \ 55 typeof ( *((_ptr)->u.dummy[0]) ) 58 #define MLX_BIT_OFFSET( _structure_st, _field ) \ 59 offsetof ( _structure_st, _field ) 62 #define MLX_DWORD_OFFSET( _structure_st, _field ) \ 63 ( MLX_BIT_OFFSET ( _structure_st, _field ) / 32 ) 70 #define MLX_DWORD_BIT_OFFSET( _structure_st, _index, _field ) \ 71 ( MLX_BIT_OFFSET ( _structure_st, _field ) - ( 32 * (_index) ) ) 74 #define MLX_BIT_WIDTH( _structure_st, _field ) \ 75 sizeof ( ( ( _structure_st * ) NULL )->_field ) 78 #define MLX_BIT_MASK( _structure_st, _field ) \ 79 ( ( ~( ( uint32_t ) 0 ) ) >> \ 80 ( 32 - MLX_BIT_WIDTH ( _structure_st, _field ) ) ) 87 #define MLX_ASSEMBLE_1( _structure_st, _index, _field, _value ) \ 88 ( (_value) << MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) ) 90 #define MLX_ASSEMBLE_2( _structure_st, _index, _field, _value, ... ) \ 91 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 92 MLX_ASSEMBLE_1 ( _structure_st, _index, __VA_ARGS__ ) ) 94 #define MLX_ASSEMBLE_3( _structure_st, _index, _field, _value, ... ) \ 95 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 96 MLX_ASSEMBLE_2 ( _structure_st, _index, __VA_ARGS__ ) ) 98 #define MLX_ASSEMBLE_4( _structure_st, _index, _field, _value, ... ) \ 99 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 100 MLX_ASSEMBLE_3 ( _structure_st, _index, __VA_ARGS__ ) ) 102 #define MLX_ASSEMBLE_5( _structure_st, _index, _field, _value, ... ) \ 103 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 104 MLX_ASSEMBLE_4 ( _structure_st, _index, __VA_ARGS__ ) ) 106 #define MLX_ASSEMBLE_6( _structure_st, _index, _field, _value, ... ) \ 107 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 108 MLX_ASSEMBLE_5 ( _structure_st, _index, __VA_ARGS__ ) ) 110 #define MLX_ASSEMBLE_7( _structure_st, _index, _field, _value, ... ) \ 111 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 112 MLX_ASSEMBLE_6 ( _structure_st, _index, __VA_ARGS__ ) ) 114 #define MLX_ASSEMBLE_8( _structure_st, _index, _field, _value, ... ) \ 115 ( MLX_ASSEMBLE_1 ( _structure_st, _index, _field, _value ) | \ 116 MLX_ASSEMBLE_7 ( _structure_st, _index, __VA_ARGS__ ) ) 123 #define MLX_MASK_1( _structure_st, _index, _field ) \ 124 ( MLX_BIT_MASK ( _structure_st, _field ) << \ 125 MLX_DWORD_BIT_OFFSET ( _structure_st, _index, _field ) ) 127 #define MLX_MASK_2( _structure_st, _index, _field, ... ) \ 128 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 129 MLX_MASK_1 ( _structure_st, _index, __VA_ARGS__ ) ) 131 #define MLX_MASK_3( _structure_st, _index, _field, ... ) \ 132 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 133 MLX_MASK_2 ( _structure_st, _index, __VA_ARGS__ ) ) 135 #define MLX_MASK_4( _structure_st, _index, _field, ... ) \ 136 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 137 MLX_MASK_3 ( _structure_st, _index, __VA_ARGS__ ) ) 139 #define MLX_MASK_5( _structure_st, _index, _field, ... ) \ 140 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 141 MLX_MASK_4 ( _structure_st, _index, __VA_ARGS__ ) ) 143 #define MLX_MASK_6( _structure_st, _index, _field, ... ) \ 144 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 145 MLX_MASK_5 ( _structure_st, _index, __VA_ARGS__ ) ) 147 #define MLX_MASK_7( _structure_st, _index, _field, ... ) \ 148 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 149 MLX_MASK_6 ( _structure_st, _index, __VA_ARGS__ ) ) 151 #define MLX_MASK_8( _structure_st, _index, _field, ... ) \ 152 ( MLX_MASK_1 ( _structure_st, _index, _field ) | \ 153 MLX_MASK_7 ( _structure_st, _index, __VA_ARGS__ ) ) 160 #define MLX_FILL( _ptr, _index, _assembled ) \ 162 uint32_t *__ptr = &(_ptr)->u.dwords[(_index)]; \ 163 uint32_t __assembled = (_assembled); \ 164 *__ptr = cpu_to_be32 ( __assembled ); \ 167 #define MLX_FILL_1( _ptr, _index, ... ) \ 168 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_1 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 169 _index, __VA_ARGS__ ) ) 171 #define MLX_FILL_2( _ptr, _index, ... ) \ 172 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_2 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 173 _index, __VA_ARGS__ ) ) 175 #define MLX_FILL_3( _ptr, _index, ... ) \ 176 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_3 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 177 _index, __VA_ARGS__ ) ) 179 #define MLX_FILL_4( _ptr, _index, ... ) \ 180 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_4 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 181 _index, __VA_ARGS__ ) ) 183 #define MLX_FILL_5( _ptr, _index, ... ) \ 184 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_5 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 185 _index, __VA_ARGS__ ) ) 187 #define MLX_FILL_6( _ptr, _index, ... ) \ 188 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_6 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 189 _index, __VA_ARGS__ ) ) 191 #define MLX_FILL_7( _ptr, _index, ... ) \ 192 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_7 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 193 _index, __VA_ARGS__ ) ) 195 #define MLX_FILL_8( _ptr, _index, ... ) \ 196 MLX_FILL ( _ptr, _index, MLX_ASSEMBLE_8 ( MLX_PSEUDO_STRUCT ( _ptr ),\ 197 _index, __VA_ARGS__ ) ) 204 #define MLX_SET( _ptr, _field, _value ) \ 206 unsigned int __index = \ 207 MLX_DWORD_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \ 208 uint32_t *__ptr = &(_ptr)->u.dwords[__index]; \ 209 uint32_t __value = be32_to_cpu ( *__ptr ); \ 210 __value &= ~( MLX_MASK_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \ 211 __index, _field ) ); \ 212 __value |= MLX_ASSEMBLE_1 ( MLX_PSEUDO_STRUCT ( _ptr ), \ 213 __index, _field, _value ); \ 214 *__ptr = cpu_to_be32 ( __value ); \ 222 #define MLX_GET( _ptr, _field ) \ 224 unsigned int __index = \ 225 MLX_DWORD_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \ 226 uint32_t *__ptr = &(_ptr)->u.dwords[__index]; \ 227 uint32_t __value = be32_to_cpu ( *__ptr ); \ 229 MLX_DWORD_BIT_OFFSET ( MLX_PSEUDO_STRUCT ( _ptr ), \ 232 MLX_BIT_MASK ( MLX_PSEUDO_STRUCT ( _ptr ), _field ); \ 240 #define MLX_FILL_H( _structure_st, _index, _field, _address ) do { \ 241 if ( sizeof ( physaddr_t ) > sizeof ( uint32_t ) ) { \ 242 MLX_FILL_1 ( _structure_st, _index, _field, \ 243 ( ( ( uint64_t ) (_address) ) >> 32 ) ); \ FILE_LICENCE(GPL2_OR_LATER)
unsigned char pseudo_bit_t