virtio: feature bit manipulation helpers

Add virtio_{add,clear}_feature helper functions for manipulating a
feature bits variable. This has some benefits over open coding:
- add check that the bit is in a sane range
- make it obvious at a glance what is going on
- have a central point to change when we want to extend feature bits

Convert existing code manipulating features to use the new helpers.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Cornelia Huck 2014-12-11 14:25:05 +01:00 committed by Michael S. Tsirkin
parent a590fd5ba8
commit 0cd09c3a6c
8 changed files with 44 additions and 32 deletions

View file

@ -219,6 +219,18 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign,
void virtio_queue_notify_vq(VirtQueue *vq);
void virtio_irq(VirtQueue *vq);
static inline void virtio_add_feature(uint32_t *features, unsigned int fbit)
{
assert(fbit < 32);
*features |= (1 << fbit);
}
static inline void virtio_clear_feature(uint32_t *features, unsigned int fbit)
{
assert(fbit < 32);
*features &= ~(1 << fbit);
}
static inline bool virtio_is_big_endian(VirtIODevice *vdev)
{
assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN);