Skip to content

Commit

Permalink
virtio.h: add new api virtio_has_feature()
Browse files Browse the repository at this point in the history
virtio_has_feature() can be easily used to check if the virtio device
support a specific feature.

And assgin feature to vdev->feature for virtio device role when get
features, so the virtio device side can use virtio_has_featrue() to
check weather the virtio device support a feature.

Signed-off-by: Bowen Wang <[email protected]>
  • Loading branch information
CV-Bowen committed Nov 21, 2024
1 parent fb8a3ae commit 1b4cb95
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/include/openamp/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ static inline int virtio_get_features(struct virtio_device *vdev,
return -ENXIO;

*features = vdev->func->get_features(vdev);
if (VIRTIO_ROLE_IS_DEVICE(vdev))
vdev->features = *features;

return 0;
}

Expand Down Expand Up @@ -565,6 +568,28 @@ static inline int virtio_free_buf(struct virtio_device *vdev, void *buf)
return 0;
}

/**
* @brief Check if the virtio device support a specific feature.
*
* @param vdev Pointer to device structure.
* @param feature_bit Feature bit to check.
*
* @return true if the feature is supported, otherwise false.
*/
static inline bool virtio_has_feature(struct virtio_device *vdev,
unsigned int feature_bit)
{
uint32_t features;

if (!vdev)
return false;

if (!vdev->features)
virtio_get_features(vdev, &features);

return (vdev->features & (1UL << feature_bit)) != 0;
}

#if defined __cplusplus
}
#endif
Expand Down

0 comments on commit 1b4cb95

Please sign in to comment.