Skip to content

Commit

Permalink
virtio: add low-level APIs for feature bits
Browse files Browse the repository at this point in the history
Add low level APIs to test/set/clear feature bits.
For use by transports, to make it easier to
write code independent of feature bit array format.

Note: APIs is prefixed with __ and has _bit suffix
to stress its low level nature.  It's for use by transports only:
drivers should use virtio_has_feature and never need to set/clear
features.

Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: Cornelia Huck <[email protected]>
  • Loading branch information
mstsirkin committed Dec 9, 2014
1 parent b2776bf commit d4024af
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions include/linux/virtio_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,47 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
unsigned int fbit);

/**
* virtio_has_feature - helper to determine if this device has this feature.
* __virtio_test_bit - helper to test feature bits. For use by transports.
* Devices should normally use virtio_has_feature,
* which includes more checks.
* @vdev: the device
* @fbit: the feature bit
*/
static inline bool virtio_has_feature(const struct virtio_device *vdev,
static inline bool __virtio_test_bit(const struct virtio_device *vdev,
unsigned int fbit)
{
/* Did you forget to fix assumptions on max features? */
if (__builtin_constant_p(fbit))
BUILD_BUG_ON(fbit >= 32);
else
BUG_ON(fbit >= 32);

return test_bit(fbit, vdev->features);
}

/**
* __virtio_set_bit - helper to set feature bits. For use by transports.
* @vdev: the device
* @fbit: the feature bit
*/
static inline void __virtio_set_bit(struct virtio_device *vdev,
unsigned int fbit)
{
/* Did you forget to fix assumptions on max features? */
if (__builtin_constant_p(fbit))
BUILD_BUG_ON(fbit >= 32);
else
BUG_ON(fbit >= 32);

set_bit(fbit, vdev->features);
}

/**
* __virtio_clear_bit - helper to clear feature bits. For use by transports.
* @vdev: the device
* @fbit: the feature bit
*/
static inline void __virtio_clear_bit(struct virtio_device *vdev,
unsigned int fbit)
{
/* Did you forget to fix assumptions on max features? */
Expand All @@ -90,10 +126,21 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev,
else
BUG_ON(fbit >= 32);

clear_bit(fbit, vdev->features);
}

/**
* virtio_has_feature - helper to determine if this device has this feature.
* @vdev: the device
* @fbit: the feature bit
*/
static inline bool virtio_has_feature(const struct virtio_device *vdev,
unsigned int fbit)
{
if (fbit < VIRTIO_TRANSPORT_F_START)
virtio_check_driver_offered_feature(vdev, fbit);

return test_bit(fbit, vdev->features);
return __virtio_test_bit(vdev, fbit);
}

static inline
Expand Down

0 comments on commit d4024af

Please sign in to comment.