From d4c01528272ea8df0942891b4e7cb6e7664382b2 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Tue, 8 Oct 2024 21:24:53 +0800 Subject: [PATCH] virtio.h: add new api virtio_has_feature() virtio_has_feature() can be easily used to heck 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 --- lib/include/openamp/virtio.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/include/openamp/virtio.h b/lib/include/openamp/virtio.h index 091ba744..f8a051fc 100644 --- a/lib/include/openamp/virtio.h +++ b/lib/include/openamp/virtio.h @@ -437,6 +437,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; } @@ -505,6 +508,23 @@ static inline int virtio_reset_device(struct virtio_device *vdev) 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) +{ + if (!vdev) + return false; + + return (vdev->features & (1UL << feature_bit)) != 0; +} + #if defined __cplusplus } #endif