44
55#include <linux/bits.h>
66
7- #define VIRTIO_FEATURES_DWORDS 2
8- #define VIRTIO_FEATURES_MAX (VIRTIO_FEATURES_DWORDS * 64)
9- #define VIRTIO_FEATURES_WORDS (VIRTIO_FEATURES_DWORDS * 2)
7+ #define VIRTIO_FEATURES_U64S 2
8+ #define VIRTIO_FEATURES_BITS (VIRTIO_FEATURES_U64S * 64)
9+
1010#define VIRTIO_BIT (b ) BIT_ULL((b) & 0x3f)
11- #define VIRTIO_DWORD (b ) ((b) >> 6)
11+ #define VIRTIO_U64 (b ) ((b) >> 6)
12+
1213#define VIRTIO_DECLARE_FEATURES (name ) \
1314 union { \
1415 u64 name; \
15- u64 name##_array[VIRTIO_FEATURES_DWORDS ];\
16+ u64 name##_array[VIRTIO_FEATURES_U64S ];\
1617 }
1718
1819static inline bool virtio_features_chk_bit (unsigned int bit )
@@ -22,9 +23,9 @@ static inline bool virtio_features_chk_bit(unsigned int bit)
2223 * Don't care returning the correct value: the build
2324 * will fail before any bad features access
2425 */
25- BUILD_BUG_ON (bit >= VIRTIO_FEATURES_MAX );
26+ BUILD_BUG_ON (bit >= VIRTIO_FEATURES_BITS );
2627 } else {
27- if (WARN_ON_ONCE (bit >= VIRTIO_FEATURES_MAX ))
28+ if (WARN_ON_ONCE (bit >= VIRTIO_FEATURES_BITS ))
2829 return false;
2930 }
3031 return true;
@@ -34,26 +35,26 @@ static inline bool virtio_features_test_bit(const u64 *features,
3435 unsigned int bit )
3536{
3637 return virtio_features_chk_bit (bit ) &&
37- !!(features [VIRTIO_DWORD (bit )] & VIRTIO_BIT (bit ));
38+ !!(features [VIRTIO_U64 (bit )] & VIRTIO_BIT (bit ));
3839}
3940
4041static inline void virtio_features_set_bit (u64 * features ,
4142 unsigned int bit )
4243{
4344 if (virtio_features_chk_bit (bit ))
44- features [VIRTIO_DWORD (bit )] |= VIRTIO_BIT (bit );
45+ features [VIRTIO_U64 (bit )] |= VIRTIO_BIT (bit );
4546}
4647
4748static inline void virtio_features_clear_bit (u64 * features ,
4849 unsigned int bit )
4950{
5051 if (virtio_features_chk_bit (bit ))
51- features [VIRTIO_DWORD (bit )] &= ~VIRTIO_BIT (bit );
52+ features [VIRTIO_U64 (bit )] &= ~VIRTIO_BIT (bit );
5253}
5354
5455static inline void virtio_features_zero (u64 * features )
5556{
56- memset (features , 0 , sizeof (features [0 ]) * VIRTIO_FEATURES_DWORDS );
57+ memset (features , 0 , sizeof (features [0 ]) * VIRTIO_FEATURES_U64S );
5758}
5859
5960static inline void virtio_features_from_u64 (u64 * features , u64 from )
@@ -66,22 +67,22 @@ static inline bool virtio_features_equal(const u64 *f1, const u64 *f2)
6667{
6768 int i ;
6869
69- for (i = 0 ; i < VIRTIO_FEATURES_DWORDS ; ++ i )
70+ for (i = 0 ; i < VIRTIO_FEATURES_U64S ; ++ i )
7071 if (f1 [i ] != f2 [i ])
7172 return false;
7273 return true;
7374}
7475
7576static inline void virtio_features_copy (u64 * to , const u64 * from )
7677{
77- memcpy (to , from , sizeof (to [0 ]) * VIRTIO_FEATURES_DWORDS );
78+ memcpy (to , from , sizeof (to [0 ]) * VIRTIO_FEATURES_U64S );
7879}
7980
8081static inline void virtio_features_andnot (u64 * to , const u64 * f1 , const u64 * f2 )
8182{
8283 int i ;
8384
84- for (i = 0 ; i < VIRTIO_FEATURES_DWORDS ; i ++ )
85+ for (i = 0 ; i < VIRTIO_FEATURES_U64S ; i ++ )
8586 to [i ] = f1 [i ] & ~f2 [i ];
8687}
8788
0 commit comments